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 4030cbf..5bd169a 100644
19 @@ -125,3 +125,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
25 index 24e9033..fe9a8d4 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 6cb1beb..30efd68 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 6eecb7f..b225c0f 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 f5cb9ba..9ba380c 100644
84 @@ -1114,8 +1114,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 @@ -1131,9 +1131,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 e11d60c..2f32b35 100644
110 --- a/include/linux/fs.h
111 +++ b/include/linux/fs.h
112 @@ -2618,6 +2618,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 da2751d..2e0fca6 100644
122 --- a/include/linux/splice.h
123 +++ b/include/linux/splice.h
124 @@ -83,4 +83,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 eba6e4f..31f0b2d 100644
141 @@ -2460,7 +2460,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..1397181 100644
152 --- a/fs/proc/nommu.c
153 +++ b/fs/proc/nommu.c
154 @@ -45,7 +45,10 @@ 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;
161 + file = vmr_pr_or_file(region);
162 + inode = file_inode(file);
163 dev = inode->i_sb->s_dev;
166 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
167 index cfa63ee..bf4919e 100644
168 --- a/fs/proc/task_mmu.c
169 +++ b/fs/proc/task_mmu.c
170 @@ -265,7 +265,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
171 const char *name = NULL;
174 - struct inode *inode = file_inode(vma->vm_file);
175 + struct inode *inode;
177 + file = vma_pr_or_file(vma);
178 + inode = file_inode(file);
179 dev = inode->i_sb->s_dev;
181 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
182 @@ -1390,7 +1393,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
183 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
184 struct vm_area_struct *vma = v;
185 struct numa_maps *md = &numa_priv->md;
186 - struct file *file = vma->vm_file;
187 + struct file *file = vma_pr_or_file(vma);
188 struct task_struct *task = proc_priv->task;
189 struct mm_struct *mm = vma->vm_mm;
190 struct mm_walk walk = {};
191 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
192 index 678455d..0ef7ef4 100644
193 --- a/fs/proc/task_nommu.c
194 +++ b/fs/proc/task_nommu.c
195 @@ -141,7 +141,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
199 - struct inode *inode = file_inode(vma->vm_file);
200 + struct inode *inode;
202 + file = vma_pr_or_file(file);
203 + inode = file_inode(file);
204 dev = inode->i_sb->s_dev;
206 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
207 diff --git a/include/linux/mm.h b/include/linux/mm.h
208 index e03dd29..dd32624 100644
209 --- a/include/linux/mm.h
210 +++ b/include/linux/mm.h
211 @@ -1184,6 +1184,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
216 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
217 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
219 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
220 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
222 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
224 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
226 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
227 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
229 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
230 +extern void vmr_do_fput(struct vm_region *, const char[], int);
232 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
234 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
235 +#endif /* CONFIG_MMU */
237 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
238 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
239 void *buf, int len, int write);
240 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
241 index 96c5750..a087ecd 100644
242 --- a/include/linux/mm_types.h
243 +++ b/include/linux/mm_types.h
244 @@ -232,6 +232,7 @@ struct vm_region {
245 unsigned long vm_top; /* region allocated to here */
246 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
247 struct file *vm_file; /* the backing file or NULL */
248 + struct file *vm_prfile; /* the virtual backing file or NULL */
250 int vm_usage; /* region usage count (access under nommu_region_sem) */
251 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
252 @@ -300,6 +301,7 @@ struct vm_area_struct {
253 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
254 units, *not* PAGE_CACHE_SIZE */
255 struct file * vm_file; /* File we map to (can be NULL). */
256 + struct file *vm_prfile; /* shadow of vm_file */
257 void * vm_private_data; /* was vm_pte (shared mem) */
260 diff --git a/kernel/fork.c b/kernel/fork.c
261 index 6a13c46..714302c 100644
264 @@ -416,7 +416,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
265 struct inode *inode = file_inode(file);
266 struct address_space *mapping = file->f_mapping;
270 if (tmp->vm_flags & VM_DENYWRITE)
271 atomic_dec(&inode->i_writecount);
272 mutex_lock(&mapping->i_mmap_mutex);
273 diff --git a/mm/Makefile b/mm/Makefile
274 index 4064f3e..0003fdf 100644
277 @@ -18,7 +18,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \
278 mm_init.o mmu_context.o percpu.o slab_common.o \
279 compaction.o balloon_compaction.o vmacache.o \
280 interval_tree.o list_lru.o workingset.o \
281 - iov_iter.o $(mmu-y)
282 + iov_iter.o prfile.o $(mmu-y)
286 diff --git a/mm/filemap.c b/mm/filemap.c
287 index 900edfa..f4dda0c 100644
290 @@ -2040,7 +2040,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
291 int ret = VM_FAULT_LOCKED;
293 sb_start_pagefault(inode->i_sb);
294 - file_update_time(vma->vm_file);
295 + vma_file_update_time(vma);
297 if (page->mapping != inode->i_mapping) {
299 diff --git a/mm/fremap.c b/mm/fremap.c
300 index 72b8fa3..a00bbf0 100644
303 @@ -224,16 +224,28 @@ get_write_lock:
305 if (mapping_cap_account_dirty(mapping)) {
307 - struct file *file = get_file(vma->vm_file);
308 + struct file *file = vma->vm_file,
309 + *prfile = vma->vm_prfile;
311 /* mmap_region may free vma; grab the info now */
312 vm_flags = vma->vm_flags;
315 addr = mmap_region(file, start, size, vm_flags, pgoff);
318 if (IS_ERR_VALUE(addr)) {
321 BUG_ON(addr != start);
323 + struct vm_area_struct *new_vma;
325 + new_vma = find_vma(mm, addr);
326 + if (!new_vma->vm_prfile)
327 + new_vma->vm_prfile = prfile;
328 + if (new_vma != vma)
334 diff --git a/mm/madvise.c b/mm/madvise.c
335 index a402f8f..134e15d 100644
338 @@ -327,12 +327,12 @@ static long madvise_remove(struct vm_area_struct *vma,
339 * vma's reference to the file) can go away as soon as we drop
344 up_read(¤t->mm->mmap_sem);
345 error = do_fallocate(f,
346 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
347 offset, end - start);
350 down_read(¤t->mm->mmap_sem);
353 diff --git a/mm/memory.c b/mm/memory.c
354 index 8b44f76..69a72bf 100644
357 @@ -2161,7 +2161,7 @@ reuse:
358 set_page_dirty_balance(dirty_page);
359 /* file_update_time outside page_lock */
361 - file_update_time(vma->vm_file);
362 + vma_file_update_time(vma);
364 put_page(dirty_page);
366 diff --git a/mm/mmap.c b/mm/mmap.c
367 index 129b847..869d1d7 100644
370 @@ -253,7 +253,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
371 if (vma->vm_ops && vma->vm_ops->close)
372 vma->vm_ops->close(vma);
374 - fput(vma->vm_file);
376 mpol_put(vma_policy(vma));
377 kmem_cache_free(vm_area_cachep, vma);
379 @@ -863,7 +863,7 @@ again: remove_next = 1 + (end > next->vm_end);
382 uprobe_munmap(next, next->vm_start, next->vm_end);
387 anon_vma_merge(vma, next);
388 @@ -1643,8 +1643,8 @@ out:
390 if (vm_flags & VM_DENYWRITE)
391 allow_write_access(file);
396 /* Undo any partial mapping done by a device driver. */
397 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
398 @@ -2434,7 +2434,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
402 - get_file(new->vm_file);
405 if (new->vm_ops && new->vm_ops->open)
406 new->vm_ops->open(new);
407 @@ -2453,7 +2453,7 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
408 if (new->vm_ops && new->vm_ops->close)
409 new->vm_ops->close(new);
411 - fput(new->vm_file);
413 unlink_anon_vmas(new);
415 mpol_put(vma_policy(new));
416 @@ -2842,7 +2842,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
417 if (anon_vma_clone(new_vma, vma))
418 goto out_free_mempol;
419 if (new_vma->vm_file)
420 - get_file(new_vma->vm_file);
421 + vma_get_file(new_vma);
422 if (new_vma->vm_ops && new_vma->vm_ops->open)
423 new_vma->vm_ops->open(new_vma);
424 vma_link(mm, new_vma, prev, rb_link, rb_parent);
425 diff --git a/mm/msync.c b/mm/msync.c
426 index 992a167..ce1915b 100644
429 @@ -84,13 +84,13 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
431 if ((flags & MS_SYNC) && file &&
432 (vma->vm_flags & VM_SHARED)) {
435 up_read(&mm->mmap_sem);
436 if (vma->vm_flags & VM_NONLINEAR)
437 error = vfs_fsync(file, 1);
439 error = vfs_fsync_range(file, fstart, fend, 1);
442 if (error || start >= end)
444 down_read(&mm->mmap_sem);
445 diff --git a/mm/nommu.c b/mm/nommu.c
446 index 4a852f6..b369644 100644
449 @@ -658,7 +658,7 @@ static void __put_nommu_region(struct vm_region *region)
450 up_write(&nommu_region_sem);
453 - fput(region->vm_file);
456 /* IO memory and memory shared directly out of the pagecache
457 * from ramfs/tmpfs mustn't be released here */
458 @@ -823,7 +823,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
459 if (vma->vm_ops && vma->vm_ops->close)
460 vma->vm_ops->close(vma);
462 - fput(vma->vm_file);
464 put_nommu_region(vma->vm_region);
465 kmem_cache_free(vm_area_cachep, vma);
467 @@ -1385,7 +1385,7 @@ unsigned long do_mmap_pgoff(struct file *file,
468 goto error_just_free;
471 - fput(region->vm_file);
473 kmem_cache_free(vm_region_jar, region);
476 @@ -1461,10 +1461,10 @@ error_just_free:
477 up_write(&nommu_region_sem);
480 - fput(region->vm_file);
482 kmem_cache_free(vm_region_jar, region);
484 - fput(vma->vm_file);
486 kmem_cache_free(vm_area_cachep, vma);
487 kleave(" = %d", ret);
489 diff --git a/mm/prfile.c b/mm/prfile.c
491 index 0000000..fc708d2
496 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
497 + * in /proc/PID/maps.
498 + * Call these functions via macros defined in linux/mm.h.
500 + * See Documentation/filesystems/aufs/design/06mmap.txt
502 + * Copyright (c) 2014 Junjro R. Okajima
503 + * Copyright (c) 2014 Ian Campbell
506 +#include <linux/mm.h>
507 +#include <linux/file.h>
508 +#include <linux/fs.h>
510 +/* #define PRFILE_TRACE */
511 +static inline void prfile_trace(struct file *f, struct file *pr,
512 + const char func[], int line, const char func2[])
516 + pr_info("%s:%d: %s, %p\n", func, line, func2,
517 + f ? (char *)f->f_dentry->d_name.name : "(null)");
522 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
525 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
527 + prfile_trace(f, pr, func, line, __func__);
528 + file_update_time(f);
530 + file_update_time(pr);
533 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
536 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
538 + prfile_trace(f, pr, func, line, __func__);
539 + return (f && pr) ? pr : f;
542 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
544 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
546 + prfile_trace(f, pr, func, line, __func__);
552 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
554 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
556 + prfile_trace(f, pr, func, line, __func__);
562 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
565 + struct file *f = region->vm_file, *pr = region->vm_prfile;
567 + prfile_trace(f, pr, func, line, __func__);
568 + return (f && pr) ? pr : f;
571 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
573 + struct file *f = region->vm_file, *pr = region->vm_prfile;
575 + prfile_trace(f, pr, func, line, __func__);
580 +#endif /* CONFIG_MMU */
581 aufs3.16 standalone patch
583 diff --git a/fs/inode.c b/fs/inode.c
584 index b225c0f..73259c8 100644
587 @@ -57,6 +57,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
588 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
590 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
591 +EXPORT_SYMBOL(inode_sb_list_lock);
594 * Empty aops. Can be used for the cases where the user does not
595 @@ -1512,6 +1513,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
596 mark_inode_dirty_sync(inode);
599 +EXPORT_SYMBOL(update_time);
602 * touch_atime - update the access time
603 diff --git a/fs/namespace.c b/fs/namespace.c
604 index 182bc41..c88e101 100644
607 @@ -453,6 +453,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
608 mnt_dec_writers(real_mount(mnt));
611 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
614 * mnt_drop_write - give up write access to a mount
615 @@ -1564,6 +1565,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
619 +EXPORT_SYMBOL(iterate_mounts);
621 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
623 diff --git a/fs/notify/group.c b/fs/notify/group.c
624 index ad19959..adf290d 100644
625 --- a/fs/notify/group.c
626 +++ b/fs/notify/group.c
628 #include <linux/srcu.h>
629 #include <linux/rculist.h>
630 #include <linux/wait.h>
631 +#include <linux/module.h>
633 #include <linux/fsnotify_backend.h>
634 #include "fsnotify.h"
635 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
637 atomic_inc(&group->refcnt);
639 +EXPORT_SYMBOL(fsnotify_get_group);
642 * Drop a reference to a group. Free it if it's through.
643 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
644 if (atomic_dec_and_test(&group->refcnt))
645 fsnotify_final_destroy_group(group);
647 +EXPORT_SYMBOL(fsnotify_put_group);
650 * Create a new fsnotify_group and hold a reference for the group returned.
651 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
655 +EXPORT_SYMBOL(fsnotify_alloc_group);
657 int fsnotify_fasync(int fd, struct file *file, int on)
659 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
660 index d90deaa..60b4239 100644
661 --- a/fs/notify/mark.c
662 +++ b/fs/notify/mark.c
663 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
664 mark->free_mark(mark);
667 +EXPORT_SYMBOL(fsnotify_put_mark);
670 * Any time a mark is getting freed we end up here.
671 @@ -191,6 +192,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
672 fsnotify_destroy_mark_locked(mark, group);
673 mutex_unlock(&group->mark_mutex);
675 +EXPORT_SYMBOL(fsnotify_destroy_mark);
677 void fsnotify_set_mark_mask_locked(struct fsnotify_mark *mark, __u32 mask)
679 @@ -275,6 +277,7 @@ err:
683 +EXPORT_SYMBOL(fsnotify_add_mark);
685 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
686 struct inode *inode, struct vfsmount *mnt, int allow_dups)
687 @@ -336,6 +339,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
688 atomic_set(&mark->refcnt, 1);
689 mark->free_mark = free_mark;
691 +EXPORT_SYMBOL(fsnotify_init_mark);
693 static int fsnotify_mark_destroy(void *ignored)
695 diff --git a/fs/open.c b/fs/open.c
696 index d6fd3ac..5e99d8b 100644
699 @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
700 mutex_unlock(&dentry->d_inode->i_mutex);
703 +EXPORT_SYMBOL(do_truncate);
705 long vfs_truncate(struct path *path, loff_t length)
707 @@ -298,6 +299,7 @@ int do_fallocate(struct file *file, int mode, loff_t offset, loff_t len)
708 sb_end_write(inode->i_sb);
711 +EXPORT_SYMBOL(do_fallocate);
713 SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
715 diff --git a/fs/splice.c b/fs/splice.c
716 index 9ba380c..3419932 100644
719 @@ -1127,6 +1127,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
721 return splice_write(pipe, out, ppos, len, flags);
723 +EXPORT_SYMBOL(do_splice_from);
726 * Attempt to initiate a splice from a file to a pipe.
727 @@ -1153,6 +1154,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
729 return splice_read(in, ppos, pipe, len, flags);
731 +EXPORT_SYMBOL(do_splice_to);
734 * splice_direct_to_actor - splices data directly between two non-pipes
735 diff --git a/security/commoncap.c b/security/commoncap.c
736 index b9d613e..ba3b618 100644
737 --- a/security/commoncap.c
738 +++ b/security/commoncap.c
739 @@ -988,9 +988,11 @@ int cap_mmap_addr(unsigned long addr)
743 +EXPORT_SYMBOL(cap_mmap_addr);
745 int cap_mmap_file(struct file *file, unsigned long reqprot,
746 unsigned long prot, unsigned long flags)
750 +EXPORT_SYMBOL(cap_mmap_file);
751 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
752 index d9d69e6..3f6f471 100644
753 --- a/security/device_cgroup.c
754 +++ b/security/device_cgroup.c
756 #include <linux/device_cgroup.h>
757 #include <linux/cgroup.h>
758 #include <linux/ctype.h>
759 +#include <linux/export.h>
760 #include <linux/list.h>
761 #include <linux/uaccess.h>
762 #include <linux/seq_file.h>
763 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
764 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
767 +EXPORT_SYMBOL(__devcgroup_inode_permission);
769 int devcgroup_inode_mknod(int mode, dev_t dev)
771 diff --git a/security/security.c b/security/security.c
772 index 31614e9..b223a66 100644
773 --- a/security/security.c
774 +++ b/security/security.c
775 @@ -407,6 +407,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
777 return security_ops->path_rmdir(dir, dentry);
779 +EXPORT_SYMBOL(security_path_rmdir);
781 int security_path_unlink(struct path *dir, struct dentry *dentry)
783 @@ -423,6 +424,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
785 return security_ops->path_symlink(dir, dentry, old_name);
787 +EXPORT_SYMBOL(security_path_symlink);
789 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
790 struct dentry *new_dentry)
791 @@ -431,6 +433,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
793 return security_ops->path_link(old_dentry, new_dir, new_dentry);
795 +EXPORT_SYMBOL(security_path_link);
797 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
798 struct path *new_dir, struct dentry *new_dentry,
799 @@ -458,6 +461,7 @@ int security_path_truncate(struct path *path)
801 return security_ops->path_truncate(path);
803 +EXPORT_SYMBOL(security_path_truncate);
805 int security_path_chmod(struct path *path, umode_t mode)
807 @@ -465,6 +469,7 @@ int security_path_chmod(struct path *path, umode_t mode)
809 return security_ops->path_chmod(path, mode);
811 +EXPORT_SYMBOL(security_path_chmod);
813 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
815 @@ -472,6 +477,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
817 return security_ops->path_chown(path, uid, gid);
819 +EXPORT_SYMBOL(security_path_chown);
821 int security_path_chroot(struct path *path)
823 @@ -557,6 +563,7 @@ int security_inode_readlink(struct dentry *dentry)
825 return security_ops->inode_readlink(dentry);
827 +EXPORT_SYMBOL(security_inode_readlink);
829 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
831 @@ -571,6 +578,7 @@ int security_inode_permission(struct inode *inode, int mask)
833 return security_ops->inode_permission(inode, mask);
835 +EXPORT_SYMBOL(security_inode_permission);
837 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
839 @@ -693,6 +701,7 @@ int security_file_permission(struct file *file, int mask)
841 return fsnotify_perm(file, mask);
843 +EXPORT_SYMBOL(security_file_permission);
845 int security_file_alloc(struct file *file)
847 @@ -753,6 +762,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
849 return ima_file_mmap(file, prot);
851 +EXPORT_SYMBOL(security_mmap_file);
853 int security_mmap_addr(unsigned long addr)
855 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
856 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
857 +++ linux/Documentation/ABI/testing/debugfs-aufs 2014-01-30 21:10:02.794146538 +0100
859 +What: /debug/aufs/si_<id>/
861 +Contact: J. R. Okajima <hooanon05g@gmail.com>
863 + Under /debug/aufs, a directory named si_<id> is created
864 + per aufs mount, where <id> is a unique id generated
867 +What: /debug/aufs/si_<id>/plink
869 +Contact: J. R. Okajima <hooanon05g@gmail.com>
871 + It has three lines and shows the information about the
872 + pseudo-link. The first line is a single number
873 + representing a number of buckets. The second line is a
874 + number of pseudo-links per buckets (separated by a
875 + blank). The last line is a single number representing a
876 + total number of psedo-links.
877 + When the aufs mount option 'noplink' is specified, it
878 + will show "1\n0\n0\n".
880 +What: /debug/aufs/si_<id>/xib
882 +Contact: J. R. Okajima <hooanon05g@gmail.com>
884 + It shows the consumed blocks by xib (External Inode Number
885 + Bitmap), its block size and file size.
886 + When the aufs mount option 'noxino' is specified, it
887 + will be empty. About XINO files, see the aufs manual.
889 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
891 +Contact: J. R. Okajima <hooanon05g@gmail.com>
893 + It shows the consumed blocks by xino (External Inode Number
894 + Translation Table), its link count, block size and file
896 + When the aufs mount option 'noxino' is specified, it
897 + will be empty. About XINO files, see the aufs manual.
899 +What: /debug/aufs/si_<id>/xigen
901 +Contact: J. R. Okajima <hooanon05g@gmail.com>
903 + It shows the consumed blocks by xigen (External Inode
904 + Generation Table), its block size and file size.
905 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
907 + When the aufs mount option 'noxino' is specified, it
908 + will be empty. About XINO files, see the aufs manual.
909 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
910 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
911 +++ linux/Documentation/ABI/testing/sysfs-aufs 2014-01-30 21:10:02.794146538 +0100
913 +What: /sys/fs/aufs/si_<id>/
915 +Contact: J. R. Okajima <hooanon05g@gmail.com>
917 + Under /sys/fs/aufs, a directory named si_<id> is created
918 + per aufs mount, where <id> is a unique id generated
921 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
923 +Contact: J. R. Okajima <hooanon05g@gmail.com>
925 + It shows the abolute path of a member directory (which
926 + is called branch) in aufs, and its permission.
928 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
930 +Contact: J. R. Okajima <hooanon05g@gmail.com>
932 + It shows the id of a member directory (which is called
935 +What: /sys/fs/aufs/si_<id>/xi_path
937 +Contact: J. R. Okajima <hooanon05g@gmail.com>
939 + It shows the abolute path of XINO (External Inode Number
940 + Bitmap, Translation Table and Generation Table) file
941 + even if it is the default path.
942 + When the aufs mount option 'noxino' is specified, it
943 + will be empty. About XINO files, see the aufs manual.
944 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
945 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
946 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2014-01-30 21:10:02.807480310 +0100
949 +# Copyright (C) 2005-2014 Junjiro R. Okajima
951 +# This program is free software; you can redistribute it and/or modify
952 +# it under the terms of the GNU General Public License as published by
953 +# the Free Software Foundation; either version 2 of the License, or
954 +# (at your option) any later version.
956 +# This program is distributed in the hope that it will be useful,
957 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
958 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
959 +# GNU General Public License for more details.
961 +# You should have received a copy of the GNU General Public License
962 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
965 +----------------------------------------
967 +aufs [ei ju: ef es] | [a u f s]
968 +1. abbrev. for "advanced multi-layered unification filesystem".
969 +2. abbrev. for "another unionfs".
970 +3. abbrev. for "auf das" in German which means "on the" in English.
971 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
972 + But "Filesystem aufs Filesystem" is hard to understand.
974 +AUFS is a filesystem with features:
975 +- multi layered stackable unification filesystem, the member directory
976 + is called as a branch.
977 +- branch permission and attribute, 'readonly', 'real-readonly',
978 + 'readwrite', 'whiteout-able', 'link-able whiteout' and their
980 +- internal "file copy-on-write".
981 +- logical deletion, whiteout.
982 +- dynamic branch manipulation, adding, deleting and changing permission.
983 +- allow bypassing aufs, user's direct branch access.
984 +- external inode number translation table and bitmap which maintains the
985 + persistent aufs inode number.
986 +- seekable directory, including NFS readdir.
987 +- file mapping, mmap and sharing pages.
988 +- pseudo-link, hardlink over branches.
989 +- loopback mounted filesystem as a branch.
990 +- several policies to select one among multiple writable branches.
991 +- revert a single systemcall when an error occurs in aufs.
995 +Multi Layered Stackable Unification Filesystem
996 +----------------------------------------------------------------------
997 +Most people already knows what it is.
998 +It is a filesystem which unifies several directories and provides a
999 +merged single directory. When users access a file, the access will be
1000 +passed/re-directed/converted (sorry, I am not sure which English word is
1001 +correct) to the real file on the member filesystem. The member
1002 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1003 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1004 +readonly branch is handled by creating 'whiteout' on the upper writable
1007 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1008 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1009 +different approaches to implement the merged-view.
1010 +The former tries putting it into VFS, and the latter implements as a
1011 +separate filesystem.
1012 +(If I misunderstand about these implementations, please let me know and
1013 +I shall correct it. Because it is a long time ago when I read their
1014 +source files last time).
1016 +UnionMount's approach will be able to small, but may be hard to share
1017 +branches between several UnionMount since the whiteout in it is
1018 +implemented in the inode on branch filesystem and always
1019 +shared. According to Bharata's post, readdir does not seems to be
1021 +There are several missing features known in this implementations such as
1022 +- for users, the inode number may change silently. eg. copy-up.
1023 +- link(2) may break by copy-up.
1024 +- read(2) may get an obsoleted filedata (fstat(2) too).
1025 +- fcntl(F_SETLK) may be broken by copy-up.
1026 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1029 +Unionfs has a longer history. When I started implementing a stacking filesystem
1030 +(Aug 2005), it already existed. It has virtual super_block, inode,
1031 +dentry and file objects and they have an array pointing lower same kind
1032 +objects. After contributing many patches for Unionfs, I re-started my
1033 +project AUFS (Jun 2006).
1035 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1036 +implemented my own ideas, approaches and enhancements and it became
1037 +totally different one.
1039 +Comparing DM snapshot and fs based implementation
1040 +- the number of bytes to be copied between devices is much smaller.
1041 +- the type of filesystem must be one and only.
1042 +- the fs must be writable, no readonly fs, even for the lower original
1043 + device. so the compression fs will not be usable. but if we use
1044 + loopback mount, we may address this issue.
1046 + mount /cdrom/squashfs.img /sq
1047 + losetup /sq/ext2.img
1048 + losetup /somewhere/cow
1049 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1050 +- it will be difficult (or needs more operations) to extract the
1051 + difference between the original device and COW.
1052 +- DM snapshot-merge may help a lot when users try merging. in the
1053 + fs-layer union, users will use rsync(1).
1056 +Several characters/aspects of aufs
1057 +----------------------------------------------------------------------
1059 +Aufs has several characters or aspects.
1060 +1. a filesystem, callee of VFS helper
1061 +2. sub-VFS, caller of VFS helper for branches
1062 +3. a virtual filesystem which maintains persistent inode number
1063 +4. reader/writer of files on branches such like an application
1065 +1. Callee of VFS Helper
1066 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1067 +unlink(2) from an application reaches sys_unlink() kernel function and
1068 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1069 +calls filesystem specific unlink operation. Actually aufs implements the
1070 +unlink operation but it behaves like a redirector.
1072 +2. Caller of VFS Helper for Branches
1073 +aufs_unlink() passes the unlink request to the branch filesystem as if
1074 +it were called from VFS. So the called unlink operation of the branch
1075 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1076 +every necessary pre/post operation for the branch filesystem.
1077 +- acquire the lock for the parent dir on a branch
1078 +- lookup in a branch
1079 +- revalidate dentry on a branch
1080 +- mnt_want_write() for a branch
1081 +- vfs_unlink() for a branch
1082 +- mnt_drop_write() for a branch
1083 +- release the lock on a branch
1085 +3. Persistent Inode Number
1086 +One of the most important issue for a filesystem is to maintain inode
1087 +numbers. This is particularly important to support exporting a
1088 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1089 +backend block device for its own. But some storage is necessary to
1090 +maintain inode number. It may be a large space and may not suit to keep
1091 +in memory. Aufs rents some space from its first writable branch
1092 +filesystem (by default) and creates file(s) on it. These files are
1093 +created by aufs internally and removed soon (currently) keeping opened.
1094 +Note: Because these files are removed, they are totally gone after
1095 + unmounting aufs. It means the inode numbers are not persistent
1096 + across unmount or reboot. I have a plan to make them really
1097 + persistent which will be important for aufs on NFS server.
1099 +4. Read/Write Files Internally (copy-on-write)
1100 +Because a branch can be readonly, when you write a file on it, aufs will
1101 +"copy-up" it to the upper writable branch internally. And then write the
1102 +originally requested thing to the file. Generally kernel doesn't
1103 +open/read/write file actively. In aufs, even a single write may cause a
1104 +internal "file copy". This behaviour is very similar to cp(1) command.
1106 +Some people may think it is better to pass such work to user space
1107 +helper, instead of doing in kernel space. Actually I am still thinking
1108 +about it. But currently I have implemented it in kernel space.
1109 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1110 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1111 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2014-08-14 10:15:45.115275734 +0200
1114 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1116 +# This program is free software; you can redistribute it and/or modify
1117 +# it under the terms of the GNU General Public License as published by
1118 +# the Free Software Foundation; either version 2 of the License, or
1119 +# (at your option) any later version.
1121 +# This program is distributed in the hope that it will be useful,
1122 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1123 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1124 +# GNU General Public License for more details.
1126 +# You should have received a copy of the GNU General Public License
1127 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1129 +Basic Aufs Internal Structure
1131 +Superblock/Inode/Dentry/File Objects
1132 +----------------------------------------------------------------------
1133 +As like an ordinary filesystem, aufs has its own
1134 +superblock/inode/dentry/file objects. All these objects have a
1135 +dynamically allocated array and store the same kind of pointers to the
1136 +lower filesystem, branch.
1137 +For example, when you build a union with one readwrite branch and one
1138 +readonly, mounted /au, /rw and /ro respectively.
1140 +- /ro/fileA exists but /rw/fileA
1142 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1143 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1147 +This style of an array is essentially same to the aufs
1148 +superblock/inode/dentry/file objects.
1150 +Because aufs supports manipulating branches, ie. add/delete/change
1151 +dynamically, these objects has its own generation. When branches are
1152 +changed, the generation in aufs superblock is incremented. And a
1153 +generation in other object are compared when it is accessed.
1154 +When a generation in other objects are obsoleted, aufs refreshes the
1159 +----------------------------------------------------------------------
1160 +Additionally aufs superblock has some data for policies to select one
1161 +among multiple writable branches, XIB files, pseudo-links and kobject.
1162 +See below in detail.
1163 +About the policies which supports copy-down a directory, see policy.txt
1167 +Branch and XINO(External Inode Number Translation Table)
1168 +----------------------------------------------------------------------
1169 +Every branch has its own xino (external inode number translation table)
1170 +file. The xino file is created and unlinked by aufs internally. When two
1171 +members of a union exist on the same filesystem, they share the single
1173 +The struct of a xino file is simple, just a sequence of aufs inode
1174 +numbers which is indexed by the lower inode number.
1175 +In the above sample, assume the inode number of /ro/fileA is i111 and
1176 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1177 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1179 +When the inode numbers are not contiguous, the xino file will be sparse
1180 +which has a hole in it and doesn't consume as much disk space as it
1181 +might appear. If your branch filesystem consumes disk space for such
1182 +holes, then you should specify 'xino=' option at mounting aufs.
1184 +Also a writable branch has three kinds of "whiteout bases". All these
1185 +are existed when the branch is joined to aufs and the names are
1186 +whiteout-ed doubly, so that users will never see their names in aufs
1188 +1. a regular file which will be linked to all whiteouts.
1189 +2. a directory to store a pseudo-link.
1190 +3. a directory to store an "orphan-ed" file temporary.
1193 + When you remove a file on a readonly branch, aufs handles it as a
1194 + logical deletion and creates a whiteout on the upper writable branch
1195 + as a hardlink of this file in order not to consume inode on the
1198 + See below, Pseudo-link.
1200 + When "fileC" exists on the lower readonly branch only and it is
1201 + opened and removed with its parent dir, and then user writes
1202 + something into it, then aufs copies-up fileC to this
1203 + directory. Because there is no other dir to store fileC. After
1204 + creating a file under this dir, the file is unlinked.
1206 +Because aufs supports manipulating branches, ie. add/delete/change
1207 +dynamically, a branch has its own id. When the branch order changes, aufs
1208 +finds the new index by searching the branch id.
1212 +----------------------------------------------------------------------
1213 +Assume "fileA" exists on the lower readonly branch only and it is
1214 +hardlinked to "fileB" on the branch. When you write something to fileA,
1215 +aufs copies-up it to the upper writable branch. Additionally aufs
1216 +creates a hardlink under the Pseudo-link Directory of the writable
1217 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1218 +simple list. If fileB is read after unlinking fileA, aufs returns
1219 +filedata from the pseudo-link instead of the lower readonly
1220 +branch. Because the pseudo-link is based upon the inode, to keep the
1221 +inode number by xino (see above) is important.
1223 +All the hardlinks under the Pseudo-link Directory of the writable branch
1224 +should be restored in a proper location later. Aufs provides a utility
1225 +to do this. The userspace helpers executed at remounting and unmounting
1227 +During this utility is running, it puts aufs into the pseudo-link
1228 +maintenance mode. In this mode, only the process which began the
1229 +maintenance mode (and its child processes) is allowed to operate in
1230 +aufs. Some other processes which are not related to the pseudo-link will
1231 +be allowed to run too, but the rest have to return an error or wait
1232 +until the maintenance mode ends. If a process already acquires an inode
1233 +mutex (in VFS), it has to return an error.
1236 +XIB(external inode number bitmap)
1237 +----------------------------------------------------------------------
1238 +Addition to the xino file per a branch, aufs has an external inode number
1239 +bitmap in a superblock object. It is also a file such like a xino file.
1240 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1242 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1244 +Aufs implements a feature to truncate/refresh both of xino and xib to
1245 +reduce the number of consumed disk blocks for these files.
1248 +Virtual or Vertical Dir, and Readdir in Userspace
1249 +----------------------------------------------------------------------
1250 +In order to support multiple layers (branches), aufs readdir operation
1251 +constructs a virtual dir block on memory. For readdir, aufs calls
1252 +vfs_readdir() internally for each dir on branches, merges their entries
1253 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1254 +object. So the file object has its entry list until it is closed. The
1255 +entry list will be updated when the file position is zero and becomes
1256 +old. This decision is made in aufs automatically.
1258 +The dynamically allocated memory block for the name of entries has a
1259 +unit of 512 bytes (by default) and stores the names contiguously (no
1260 +padding). Another block for each entry is handled by kmem_cache too.
1261 +During building dir blocks, aufs creates hash list and judging whether
1262 +the entry is whiteouted by its upper branch or already listed.
1263 +The merged result is cached in the corresponding inode object and
1264 +maintained by a customizable life-time option.
1266 +Some people may call it can be a security hole or invite DoS attack
1267 +since the opened and once readdir-ed dir (file object) holds its entry
1268 +list and becomes a pressure for system memory. But I'd say it is similar
1269 +to files under /proc or /sys. The virtual files in them also holds a
1270 +memory page (generally) while they are opened. When an idea to reduce
1271 +memory for them is introduced, it will be applied to aufs too.
1272 +For those who really hate this situation, I've developed readdir(3)
1273 +library which operates this merging in userspace. You just need to set
1274 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1275 +kernel space for readdir(3).
1279 +----------------------------------------------------------------------
1280 +Aufs sometimes requires privilege access to a branch. For instance,
1281 +in copy-up/down operation. When a user process is going to make changes
1282 +to a file which exists in the lower readonly branch only, and the mode
1283 +of one of ancestor directories may not be writable by a user
1284 +process. Here aufs copy-up the file with its ancestors and they may
1285 +require privilege to set its owner/group/mode/etc.
1286 +This is a typical case of a application character of aufs (see
1289 +Aufs uses workqueue synchronously for this case. It creates its own
1290 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1291 +passes the request to call mkdir or write (for example), and wait for
1292 +its completion. This approach solves a problem of a signal handler
1294 +If aufs didn't adopt the workqueue and changed the privilege of the
1295 +process, and if the mkdir/write call arises SIGXFSZ or other signal,
1296 +then the user process might gain a privilege or the generated core file
1297 +was owned by a superuser.
1299 +Also aufs uses the system global workqueue ("events" kernel thread) too
1300 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1301 +whiteout base and etc. This is unrelated to a privilege.
1302 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1303 +superblock at the beginning, at the same time waits for the completion
1304 +of all queued asynchronous tasks.
1308 +----------------------------------------------------------------------
1309 +The whiteout in aufs is very similar to Unionfs's. That is represented
1310 +by its filename. UnionMount takes an approach of a file mode, but I am
1311 +afraid several utilities (find(1) or something) will have to support it.
1313 +Basically the whiteout represents "logical deletion" which stops aufs to
1314 +lookup further, but also it represents "dir is opaque" which also stop
1317 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1318 +In order to make several functions in a single systemcall to be
1319 +revertible, aufs adopts an approach to rename a directory to a temporary
1320 +unique whiteouted name.
1321 +For example, in rename(2) dir where the target dir already existed, aufs
1322 +renames the target dir to a temporary unique whiteouted name before the
1323 +actual rename on a branch and then handles other actions (make it opaque,
1324 +update the attributes, etc). If an error happens in these actions, aufs
1325 +simply renames the whiteouted name back and returns an error. If all are
1326 +succeeded, aufs registers a function to remove the whiteouted unique
1327 +temporary name completely and asynchronously to the system global
1332 +----------------------------------------------------------------------
1333 +It is a well-known feature or concept.
1334 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1335 +internally and makes change to the new file on the upper writable branch.
1336 +When the trigger systemcall does not update the timestamps of the parent
1337 +dir, aufs reverts it after copy-up.
1340 +Move-down (aufs3.9 and later)
1341 +----------------------------------------------------------------------
1342 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1343 +the lower readonly branch to the upper writable branch when a user
1344 +changes something about the file.
1345 +"Move-down" is an opposite action of copy-up. Basically this action is
1346 +ran manually instead of automatically and internally.
1347 +For desgin and implementation, aufs has to consider these issues.
1348 +- whiteout for the file may exist on the lower branch.
1349 +- ancestor directories may not exist on the lower branch.
1350 +- diropq for the ancestor directories may exist on the upper branch.
1351 +- free space on the lower branch will reduce.
1352 +- another access to the file may happen during moving-down, including
1354 +- the file should not be hard-linked nor pseudo-linked. they should be
1355 + handled by auplink utility later.
1357 +Sometimes users want to move-down a file from the upper writable branch
1358 +to the lower readonly or writable branch. For instance,
1359 +- the free space of the upper writable branch is going to run out.
1360 +- create a new intermediate branch between the upper and lower branch.
1363 +For this purpose, use "aumvdown" command in aufs-util.git.
1364 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1365 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1366 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2014-08-14 10:15:45.118609182 +0200
1369 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1371 +# This program is free software; you can redistribute it and/or modify
1372 +# it under the terms of the GNU General Public License as published by
1373 +# the Free Software Foundation; either version 2 of the License, or
1374 +# (at your option) any later version.
1376 +# This program is distributed in the hope that it will be useful,
1377 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1378 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1379 +# GNU General Public License for more details.
1381 +# You should have received a copy of the GNU General Public License
1382 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1385 +----------------------------------------------------------------------
1386 +Since aufs has a character of sub-VFS (see Introduction), it operates
1387 +lookup for branches as VFS does. It may be a heavy work. Generally
1388 +speaking struct nameidata is a bigger structure and includes many
1389 +information. But almost all lookup operation in aufs is the simplest
1390 +case, ie. lookup only an entry directly connected to its parent. Digging
1391 +down the directory hierarchy is unnecessary.
1393 +VFS has a function lookup_one_len() for that use, but it is not usable
1394 +for a branch filesystem which requires struct nameidata. So aufs
1395 +implements a simple lookup wrapper function. When a branch filesystem
1396 +allows NULL as nameidata, it calls lookup_one_len(). Otherwise it builds
1397 +a simplest nameidata and calls lookup_hash().
1398 +Here aufs applies "a principle in NFSD", ie. if the filesystem supports
1399 +NFS-export, then it has to support NULL as a nameidata parameter for
1400 +->create(), ->lookup() and ->d_revalidate(). So the lookup wrapper in
1401 +aufs tests if ->s_export_op in the branch is NULL or not.
1403 +When a branch is a remote filesystem, aufs basically trusts its
1404 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1406 +For d_revalidate, aufs implements three levels of revalidate tests. See
1407 +"Revalidate Dentry and UDBA" in detail.
1410 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1411 +----------------------------------------------------------------------
1412 +Let's try case study.
1413 +- aufs has two branches, upper readwrite and lower readonly.
1415 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1416 +- user invoked "chmod a+rx /au/dirA"
1417 +- the internal copy-up is activated and "/rw/dirA" is created and its
1418 + permission bits are set to world readble.
1419 +- then "/au/dirA" becomes world readable?
1421 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1422 +or it may be a natively readonly filesystem. If aufs respects the lower
1423 +branch, it should not respond readdir request from other users. But user
1424 +allowed it by chmod. Should really aufs rejects showing the entries
1427 +To be honest, I don't have a best solution for this case. So aufs
1428 +implements 'dirperm1' and 'nodirperm1' and leave it to users.
1429 +When dirperm1 is specified, aufs checks only the highest one for the
1430 +directory permission, and shows the entries. Otherwise, as usual, checks
1431 +every dir existing on all branches and rejects the request.
1433 +As a side effect, dirperm1 option improves the performance of aufs
1434 +because the number of permission check is reduced when the number of
1439 +----------------------------------------------------------------------
1440 +Basically aufs supports any type of filesystem and block device for a
1441 +branch (actually there are some exceptions). But it is prohibited to add
1442 +a loopback mounted one whose backend file exists in a filesystem which is
1443 +already added to aufs. The reason is to protect aufs from a recursive
1444 +lookup. If it was allowed, the aufs lookup operation might re-enter a
1445 +lookup for the loopback mounted branch in the same context, and will
1449 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1450 +----------------------------------------------------------------------
1451 +Generally VFS helpers re-validate a dentry as a part of lookup.
1452 +0. digging down the directory hierarchy.
1453 +1. lock the parent dir by its i_mutex.
1454 +2. lookup the final (child) entry.
1456 +4. call the actual operation (create, unlink, etc.)
1457 +5. unlock the parent dir
1459 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1460 +called. Actually aufs implements it and checks the dentry on a branch is
1462 +But it is not enough. Because aufs has to release the lock for the
1463 +parent dir on a branch at the end of ->lookup() (step 2) and
1464 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1466 +If the file on a branch is changed directly, eg. bypassing aufs, after
1467 +aufs released the lock, then the subsequent operation may cause
1468 +something unpleasant result.
1470 +This situation is a result of VFS architecture, ->lookup() and
1471 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1472 +design from VFS's point of view. It is just not suitable for sub-VFS
1475 +Aufs supports such case by three level of revalidation which is
1476 +selectable by user.
1477 +1. Simple Revalidate
1478 + Addition to the native flow in VFS's, confirm the child-parent
1479 + relationship on the branch just after locking the parent dir on the
1480 + branch in the "actual operation" (step 4). When this validation
1481 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1482 + checks the validation of the dentry on branches.
1483 +2. Monitor Changes Internally by Inotify/Fsnotify
1484 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1485 + the dentry on the branch, and returns EBUSY if it finds different
1487 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1488 + during it is in cache. When the event is notified, aufs registers a
1489 + function to kernel 'events' thread by schedule_work(). And the
1490 + function sets some special status to the cached aufs dentry and inode
1491 + private data. If they are not cached, then aufs has nothing to
1492 + do. When the same file is accessed through aufs (step 0-3) later,
1493 + aufs will detect the status and refresh all necessary data.
1494 + In this mode, aufs has to ignore the event which is fired by aufs
1496 +3. No Extra Validation
1497 + This is the simplest test and doesn't add any additional revalidation
1498 + test, and skip therevalidatin in step 4. It is useful and improves
1499 + aufs performance when system surely hide the aufs branches from user,
1500 + by over-mounting something (or another method).
1501 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1502 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1503 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2014-01-30 21:10:02.807480310 +0100
1506 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1508 +# This program is free software; you can redistribute it and/or modify
1509 +# it under the terms of the GNU General Public License as published by
1510 +# the Free Software Foundation; either version 2 of the License, or
1511 +# (at your option) any later version.
1513 +# This program is distributed in the hope that it will be useful,
1514 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1515 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1516 +# GNU General Public License for more details.
1518 +# You should have received a copy of the GNU General Public License
1519 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1521 +Branch Manipulation
1523 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1524 +and changing its permission/attribute, there are a lot of works to do.
1528 +----------------------------------------------------------------------
1529 +o Confirm the adding dir exists outside of aufs, including loopback
1531 +- and other various attributes...
1532 +o Initialize the xino file and whiteout bases if necessary.
1535 +o Check the owner/group/mode of the directory
1536 + When the owner/group/mode of the adding directory differs from the
1537 + existing branch, aufs issues a warning because it may impose a
1539 + For example, when a upper writable branch has a world writable empty
1540 + top directory, a malicious user can create any files on the writable
1541 + branch directly, like copy-up and modify manually. If something like
1542 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1543 + writable branch, and the writable branch is world-writable, then a
1544 + malicious guy may create /etc/passwd on the writable branch directly
1545 + and the infected file will be valid in aufs.
1546 + I am afraid it can be a security issue, but nothing to do except
1547 + producing a warning.
1551 +----------------------------------------------------------------------
1552 +o Confirm the deleting branch is not busy
1553 + To be general, there is one merit to adopt "remount" interface to
1554 + manipulate branches. It is to discard caches. At deleting a branch,
1555 + aufs checks the still cached (and connected) dentries and inodes. If
1556 + there are any, then they are all in-use. An inode without its
1557 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1559 + For the cached one, aufs checks whether the same named entry exists on
1561 + If the cached one is a directory, because aufs provides a merged view
1562 + to users, as long as one dir is left on any branch aufs can show the
1563 + dir to users. In this case, the branch can be removed from aufs.
1564 + Otherwise aufs rejects deleting the branch.
1566 + If any file on the deleting branch is opened by aufs, then aufs
1570 +Modify the Permission of a Branch
1571 +----------------------------------------------------------------------
1572 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1575 +o rw --> ro: Confirm the modifying branch is not busy
1576 + Aufs rejects the request if any of these conditions are true.
1577 + - a file on the branch is mmap-ed.
1578 + - a regular file on the branch is opened for write and there is no
1579 + same named entry on the upper branch.
1580 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1581 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1582 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2014-01-30 21:10:02.807480310 +0100
1585 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1587 +# This program is free software; you can redistribute it and/or modify
1588 +# it under the terms of the GNU General Public License as published by
1589 +# the Free Software Foundation; either version 2 of the License, or
1590 +# (at your option) any later version.
1592 +# This program is distributed in the hope that it will be useful,
1593 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1594 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1595 +# GNU General Public License for more details.
1597 +# You should have received a copy of the GNU General Public License
1598 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1600 +Policies to Select One among Multiple Writable Branches
1601 +----------------------------------------------------------------------
1602 +When the number of writable branch is more than one, aufs has to decide
1603 +the target branch for file creation or copy-up. By default, the highest
1604 +writable branch which has the parent (or ancestor) dir of the target
1605 +file is chosen (top-down-parent policy).
1606 +By user's request, aufs implements some other policies to select the
1607 +writable branch, for file creation two policies, round-robin and
1608 +most-free-space policies. For copy-up three policies, top-down-parent,
1609 +bottom-up-parent and bottom-up policies.
1611 +As expected, the round-robin policy selects the branch in circular. When
1612 +you have two writable branches and creates 10 new files, 5 files will be
1613 +created for each branch. mkdir(2) systemcall is an exception. When you
1614 +create 10 new directories, all will be created on the same branch.
1615 +And the most-free-space policy selects the one which has most free
1616 +space among the writable branches. The amount of free space will be
1617 +checked by aufs internally, and users can specify its time interval.
1619 +The policies for copy-up is more simple,
1620 +top-down-parent is equivalent to the same named on in create policy,
1621 +bottom-up-parent selects the writable branch where the parent dir
1622 +exists and the nearest upper one from the copyup-source,
1623 +bottom-up selects the nearest upper writable branch from the
1624 +copyup-source, regardless the existence of the parent dir.
1626 +There are some rules or exceptions to apply these policies.
1627 +- If there is a readonly branch above the policy-selected branch and
1628 + the parent dir is marked as opaque (a variation of whiteout), or the
1629 + target (creating) file is whiteout-ed on the upper readonly branch,
1630 + then the result of the policy is ignored and the target file will be
1631 + created on the nearest upper writable branch than the readonly branch.
1632 +- If there is a writable branch above the policy-selected branch and
1633 + the parent dir is marked as opaque or the target file is whiteouted
1634 + on the branch, then the result of the policy is ignored and the target
1635 + file will be created on the highest one among the upper writable
1636 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1638 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1639 + They try selecting the branch where the source exists as possible
1640 + since copyup a large file will take long time. If it can't be,
1641 + ie. the branch where the source exists is readonly, then they will
1642 + follow the copyup policy.
1643 +- There is an exception for rename(2) when the target exists.
1644 + If the rename target exists, aufs compares the index of the branches
1645 + where the source and the target exists and selects the higher
1646 + one. If the selected branch is readonly, then aufs follows the
1648 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1649 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1650 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2014-08-14 10:15:45.118609182 +0200
1653 +# Copyright (C) 2011-2014 Junjiro R. Okajima
1655 +# This program is free software; you can redistribute it and/or modify
1656 +# it under the terms of the GNU General Public License as published by
1657 +# the Free Software Foundation; either version 2 of the License, or
1658 +# (at your option) any later version.
1660 +# This program is distributed in the hope that it will be useful,
1661 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1662 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1663 +# GNU General Public License for more details.
1665 +# You should have received a copy of the GNU General Public License
1666 +# along with this program; if not, write to the Free Software
1667 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1670 +File-based Hierarchical Storage Management (FHSM)
1671 +----------------------------------------------------------------------
1672 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1673 +storage world. Aufs provides this feature as file-based with multiple
1674 +writable branches, based upon the principle of "Colder-Lower".
1675 +Here the word "colder" means that the less used files, and "lower" means
1676 +that the position in the order of the stacked branches.
1677 +These multiple writable branches are prioritized, ie. the topmost one
1678 +should be the fastest drive and be used heavily.
1680 +o Characters in aufs FHSM story
1681 +- aufs itself and a new branch attribute.
1682 +- a new ioctl interface to move-down and to establish a connection with
1683 + the daemon ("move-down" is a converse of "copy-up").
1684 +- userspace tool and daemon.
1686 +The userspace daemon establishes a connection with aufs and waits for
1687 +the notification. The notified information is very similar to struct
1688 +statfs containing the number of consumed blocks and inodes.
1689 +When the consumed blocks/inodes of a branch exceeds the user-specified
1690 +upper watermark, the daemon activates its move-down process until the
1691 +consumed blocks/inodes reaches the user-specified lower watermark.
1693 +The actual move-down is done by aufs based upon the request from
1694 +user-space since we need to maintain the inode number and the internal
1695 +pointer arrays in aufs.
1697 +Currently aufs FHSM handles the regular files only. Additionally they
1698 +must not be hard-linked nor pseudo-linked.
1701 +o Cowork of aufs and the user-space daemon
1702 + During the userspace daemon established the connection, aufs sends a
1703 + small notification to it whenever aufs writes something into the
1704 + writable branch. But it may cost high since aufs issues statfs(2)
1705 + internally. So user can specify a new option to cache the
1706 + info. Actually the notification is controlled by these factors.
1707 + + the specified cache time.
1708 + + classified as "force" by aufs internally.
1709 + Until the specified time expires, aufs doesn't send the info
1710 + except the forced cases. When aufs decide forcing, the info is always
1711 + notified to userspace.
1712 + For example, the number of free inodes is generally large enough and
1713 + the shortage of it happens rarely. So aufs doesn't force the
1714 + notification when creating a new file, directory and others. This is
1715 + the typical case which aufs doesn't force.
1716 + When aufs writes the actual filedata and the files consumes any of new
1717 + blocks, the aufs forces notifying.
1720 +o Interfaces in aufs
1721 +- New branch attribute.
1723 + Specifies that the branch is managed by FHSM feature. In other word,
1724 + participant in the FHSM.
1725 + When nofhsm is set to the branch, it will not be the source/target
1726 + branch of the move-down operation. This attribute is set
1727 + independently from coo and moo attributes, and if you want full
1728 + FHSM, you should specify them as well.
1729 +- New mount option.
1731 + Specifies a second to suppress many less important info to be
1734 + + AUFS_CTL_FHSM_FD
1735 + create a new file descriptor which userspace can read the notification
1736 + (a subset of struct statfs) from aufs.
1737 +- Module parameter 'brs'
1738 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
1740 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
1741 + When there are two or more branches with fhsm attributes,
1742 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
1743 + terminates it. As a result of remounting and branch-manipulation, the
1744 + number of branches with fhsm attribute can be one. In this case,
1745 + /sbin/mount.aufs will terminate the user-space daemon.
1748 +Finally the operation is done as these steps in kernel-space.
1750 + + no one else is using the file.
1751 + + the file is not hard-linked.
1752 + + the file is not pseudo-linked.
1753 + + the file is a regular file.
1754 + + the parent dir is not opaqued.
1755 +- find the target writable branch.
1756 +- make sure the file is not whiteout-ed by the upper (than the target)
1758 +- make the parent dir on the target branch.
1759 +- mutex lock the inode on the branch.
1760 +- unlink the whiteout on the target branch (if exists).
1761 +- lookup and create the whiteout-ed temporary name on the target branch.
1762 +- copy the file as the whiteout-ed temporary name on the target branch.
1763 +- rename the whiteout-ed temporary name to the original name.
1764 +- unlink the file on the source branch.
1765 +- maintain the internal pointer array and the external inode number
1767 +- maintain the timestamps and other attributes of the parent dir and the
1770 +And of course, in every step, an error may happen. So the operation
1771 +should restore the original file state after an error happens.
1772 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1773 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1774 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2014-01-30 21:10:02.807480310 +0100
1777 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1779 +# This program is free software; you can redistribute it and/or modify
1780 +# it under the terms of the GNU General Public License as published by
1781 +# the Free Software Foundation; either version 2 of the License, or
1782 +# (at your option) any later version.
1784 +# This program is distributed in the hope that it will be useful,
1785 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1786 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1787 +# GNU General Public License for more details.
1789 +# You should have received a copy of the GNU General Public License
1790 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1792 +mmap(2) -- File Memory Mapping
1793 +----------------------------------------------------------------------
1794 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1795 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1797 +This approach is simple and good, but there is one problem.
1798 +Under /proc, several entries show the mmap-ped files by its path (with
1799 +device and inode number), and the printed path will be the path on the
1800 +branch fs's instead of virtual aufs's.
1801 +This is not a problem in most cases, but some utilities lsof(1) (and its
1802 +user) may expect the path on aufs.
1804 +To address this issue, aufs adds a new member called vm_prfile in struct
1805 +vm_area_struct (and struct vm_region). The original vm_file points to
1806 +the file on the branch fs in order to handle everything correctly as
1807 +usual. The new vm_prfile points to a virtual file in aufs, and the
1808 +show-functions in procfs refers to vm_prfile if it is set.
1809 +Also we need to maintain several other places where touching vm_file
1811 +- fork()/clone() copies vma and the reference count of vm_file is
1813 +- merging vma maintains the ref count too.
1815 +This is not a good approach. It just faking the printed path. But it
1816 +leaves all behaviour around f_mapping unchanged. This is surely an
1818 +Actually aufs had adopted another complicated approach which calls
1819 +generic_file_mmap() and handles struct vm_operations_struct. In this
1820 +approach, aufs met a hard problem and I could not solve it without
1821 +switching the approach.
1822 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
1823 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
1824 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2014-01-30 21:10:02.807480310 +0100
1827 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1829 +# This program is free software; you can redistribute it and/or modify
1830 +# it under the terms of the GNU General Public License as published by
1831 +# the Free Software Foundation; either version 2 of the License, or
1832 +# (at your option) any later version.
1834 +# This program is distributed in the hope that it will be useful,
1835 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1836 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1837 +# GNU General Public License for more details.
1839 +# You should have received a copy of the GNU General Public License
1840 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1842 +Export Aufs via NFS
1843 +----------------------------------------------------------------------
1844 +Here is an approach.
1845 +- like xino/xib, add a new file 'xigen' which stores aufs inode
1847 +- iget_locked(): initialize aufs inode generation for a new inode, and
1848 + store it in xigen file.
1849 +- destroy_inode(): increment aufs inode generation and store it in xigen
1850 + file. it is necessary even if it is not unlinked, because any data of
1851 + inode may be changed by UDBA.
1852 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
1853 + build file handle by
1854 + + branch id (4 bytes)
1855 + + superblock generation (4 bytes)
1856 + + inode number (4 or 8 bytes)
1857 + + parent dir inode number (4 or 8 bytes)
1858 + + inode generation (4 bytes))
1859 + + return value of exportfs_encode_fh() for the parent on a branch (4
1861 + + file handle for a branch (by exportfs_encode_fh())
1863 + + find the index of a branch from its id in handle, and check it is
1864 + still exist in aufs.
1865 + + 1st level: get the inode number from handle and search it in cache.
1866 + + 2nd level: if not found, get the parent inode number from handle and
1867 + search it in cache. and then open the parent dir, find the matching
1868 + inode number by vfs_readdir() and get its name, and call
1869 + lookup_one_len() for the target dentry.
1870 + + 3rd level: if the parent dir is not cached, call
1871 + exportfs_decode_fh() for a branch and get the parent on a branch,
1872 + build a pathname of it, convert it a pathname in aufs, call
1873 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
1875 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
1876 + for every branch, but not itself. to get this, (currently) aufs
1877 + searches in current->nsproxy->mnt_ns list. it may not be a good
1878 + idea, but I didn't get other approach.
1879 + + test the generation of the gotten inode.
1880 +- every inode operation: they may get EBUSY due to UDBA. in this case,
1881 + convert it into ESTALE for NFSD.
1882 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
1883 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
1884 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
1885 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
1886 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2014-01-30 21:10:02.807480310 +0100
1889 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1891 +# This program is free software; you can redistribute it and/or modify
1892 +# it under the terms of the GNU General Public License as published by
1893 +# the Free Software Foundation; either version 2 of the License, or
1894 +# (at your option) any later version.
1896 +# This program is distributed in the hope that it will be useful,
1897 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1898 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1899 +# GNU General Public License for more details.
1901 +# You should have received a copy of the GNU General Public License
1902 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1904 +Show Whiteout Mode (shwh)
1905 +----------------------------------------------------------------------
1906 +Generally aufs hides the name of whiteouts. But in some cases, to show
1907 +them is very useful for users. For instance, creating a new middle layer
1908 +(branch) by merging existing layers.
1910 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
1911 +When you have three branches,
1912 +- Bottom: 'system', squashfs (underlying base system), read-only
1913 +- Middle: 'mods', squashfs, read-only
1914 +- Top: 'overlay', ram (tmpfs), read-write
1916 +The top layer is loaded at boot time and saved at shutdown, to preserve
1917 +the changes made to the system during the session.
1918 +When larger changes have been made, or smaller changes have accumulated,
1919 +the size of the saved top layer data grows. At this point, it would be
1920 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
1921 +and rewrite the 'mods' squashfs, clearing the top layer and thus
1922 +restoring save and load speed.
1924 +This merging is simplified by the use of another aufs mount, of just the
1925 +two overlay branches using the 'shwh' option.
1926 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
1927 + aufs /livesys/merge_union
1929 +A merged view of these two branches is then available at
1930 +/livesys/merge_union, and the new feature is that the whiteouts are
1932 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
1933 +writing to all branches. Also the default mode for all branches is 'ro'.
1934 +It is now possible to save the combined contents of the two overlay
1935 +branches to a new squashfs, e.g.:
1936 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
1938 +This new squashfs archive can be stored on the boot device and the
1939 +initramfs will use it to replace the old one at the next boot.
1940 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
1941 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
1942 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2014-01-30 21:10:02.807480310 +0100
1945 +# Copyright (C) 2010-2014 Junjiro R. Okajima
1947 +# This program is free software; you can redistribute it and/or modify
1948 +# it under the terms of the GNU General Public License as published by
1949 +# the Free Software Foundation; either version 2 of the License, or
1950 +# (at your option) any later version.
1952 +# This program is distributed in the hope that it will be useful,
1953 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1954 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1955 +# GNU General Public License for more details.
1957 +# You should have received a copy of the GNU General Public License
1958 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1960 +Dynamically customizable FS operations
1961 +----------------------------------------------------------------------
1962 +Generally FS operations (struct inode_operations, struct
1963 +address_space_operations, struct file_operations, etc.) are defined as
1964 +"static const", but it never means that FS have only one set of
1965 +operation. Some FS have multiple sets of them. For instance, ext2 has
1966 +three sets, one for XIP, for NOBH, and for normal.
1967 +Since aufs overrides and redirects these operations, sometimes aufs has
1968 +to change its behaviour according to the branch FS type. More imporantly
1969 +VFS acts differently if a function (member in the struct) is set or
1970 +not. It means aufs should have several sets of operations and select one
1971 +among them according to the branch FS definition.
1973 +In order to solve this problem and not to affect the behavour of VFS,
1974 +aufs defines these operations dynamically. For instance, aufs defines
1975 +aio_read function for struct file_operations, but it may not be set to
1976 +the file_operations. When the branch FS doesn't have it, aufs doesn't
1977 +set it to its file_operations while the function definition itself is
1978 +still alive. So the behaviour of io_submit(2) will not change, and it
1979 +will return an error when aio_read is not defined.
1981 +The lifetime of these dynamically generated operation object is
1982 +maintained by aufs branch object. When the branch is removed from aufs,
1983 +the reference counter of the object is decremented. When it reaches
1984 +zero, the dynamically generated operation object will be freed.
1986 +This approach is designed to support AIO (io_submit), Direcit I/O and
1988 +Currently this approach is applied to file_operations and
1989 +vm_operations_struct for regular files only.
1990 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
1991 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
1992 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2014-08-14 10:15:45.118609182 +0200
1995 +# Copyright (C) 2005-2014 Junjiro R. Okajima
1997 +# This program is free software; you can redistribute it and/or modify
1998 +# it under the terms of the GNU General Public License as published by
1999 +# the Free Software Foundation; either version 2 of the License, or
2000 +# (at your option) any later version.
2002 +# This program is distributed in the hope that it will be useful,
2003 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2004 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2005 +# GNU General Public License for more details.
2007 +# You should have received a copy of the GNU General Public License
2008 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2012 +Restoring some features which was implemented in aufs1.
2013 +They were dropped in aufs2 in order to make source files simpler and
2014 +easier to be reviewed.
2017 +Being Another Aufs's Readonly Branch (robr)
2018 +----------------------------------------------------------------------
2019 +Aufs1 allows aufs to be another aufs's readonly branch.
2020 +This feature was developed by a user's request. But it may not be used
2024 +Refresh the Opened File (refrof)
2025 +----------------------------------------------------------------------
2026 +This option is implemented in aufs1 but incomplete.
2028 +When user reads from a file, he expects to get its latest filedata
2029 +generally. If the file is removed and a new same named file is created,
2030 +the content he gets is unchanged, ie. the unlinked filedata.
2032 +Let's try case study again.
2033 +- aufs has two branches.
2035 +- "fileA" exists under /ro, but /rw.
2036 +- user opened "/au/fileA".
2037 +- he or someone else inserts a branch (/new) between /rw and /ro.
2038 + /au = /rw + /new + /ro
2039 +- the new branch has "fileA".
2040 +- user reads from the opened "fileA"
2041 +- which filedata should aufs return, from /ro or /new?
2043 +Some people says it has to be "from /ro" and it is a semantics of Unix.
2044 +The others say it should be "from /new" because the file is not removed
2045 +and it is equivalent to the case of someone else modifies the file.
2047 +Here again I don't have a best and final answer. I got an idea to
2048 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
2049 +Opened File) is specified (by default), aufs returns the filedata from
2051 +Otherwise from /new.
2052 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2053 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2054 +++ linux/Documentation/filesystems/aufs/README 2014-08-14 10:15:45.115275734 +0200
2057 +Aufs3 -- advanced multi layered unification filesystem version 3.x
2063 +----------------------------------------
2064 +In the early days, aufs was entirely re-designed and re-implemented
2065 +Unionfs Version 1.x series. After many original ideas, approaches,
2066 +improvements and implementations, it becomes totally different from
2067 +Unionfs while keeping the basic features.
2068 +Recently, Unionfs Version 2.x series begin taking some of the same
2069 +approaches to aufs1's.
2070 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2071 +University and his team.
2073 +Aufs3 supports linux-3.0 and later.
2074 +If you want older kernel version support, try aufs2-2.6.git or
2075 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2077 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2078 + According to Christoph Hellwig, linux rejects all union-type
2079 + filesystems but UnionMount.
2080 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2082 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2083 + UnionMount, and he pointed out an issue around a directory mutex
2084 + lock and aufs addressed it. But it is still unsure whether aufs will
2085 + be merged (or any other union solution).
2086 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2090 +----------------------------------------
2091 +- unite several directories into a single virtual filesystem. The member
2092 + directory is called as a branch.
2093 +- you can specify the permission flags to the branch, which are 'readonly',
2094 + 'readwrite' and 'whiteout-able.'
2095 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2096 + readonly branch are modifiable logically.
2097 +- dynamic branch manipulation, add, del.
2100 +Also there are many enhancements in aufs1, such as:
2101 +- readdir(3) in userspace.
2102 +- keep inode number by external inode number table
2103 +- keep the timestamps of file/dir in internal copyup operation
2104 +- seekable directory, supporting NFS readdir.
2105 +- whiteout is hardlinked in order to reduce the consumption of inodes
2107 +- do not copyup, nor create a whiteout when it is unnecessary
2108 +- revert a single systemcall when an error occurs in aufs
2109 +- remount interface instead of ioctl
2110 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2111 +- loopback mounted filesystem as a branch
2112 +- kernel thread for removing the dir who has a plenty of whiteouts
2113 +- support copyup sparse file (a file which has a 'hole' in it)
2114 +- default permission flags for branches
2115 +- selectable permission flags for ro branch, whether whiteout can
2118 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2119 +- support multiple writable branches, some policies to select one
2120 + among multiple writable branches.
2121 +- a new semantics for link(2) and rename(2) to support multiple
2122 + writable branches.
2123 +- no glibc changes are required.
2124 +- pseudo hardlink (hardlink over branches)
2125 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2126 + including NFS or remote filesystem branch.
2127 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2130 +Currently these features are dropped temporary from aufs3.
2131 +See design/08plan.txt in detail.
2132 +- test only the highest one for the directory permission (dirperm1)
2133 +- copyup on open (coo=)
2134 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2136 +- statistics of aufs thread (/sys/fs/aufs/stat)
2137 +- delegation mode (dlgt)
2138 + a delegation of the internal branch access to support task I/O
2139 + accounting, which also supports Linux Security Modules (LSM) mainly
2140 + for Suse AppArmor.
2141 +- intent.open/create (file open in a single lookup)
2143 +Features or just an idea in the future (see also design/*.txt),
2144 +- reorder the branch index without del/re-add.
2145 +- permanent xino files for NFSD
2146 +- an option for refreshing the opened files after add/del branches
2147 +- 'move' policy for copy-up between two writable branches, after
2148 + checking free space.
2149 +- light version, without branch manipulation. (unnecessary?)
2150 +- copyup in userspace
2151 +- inotify in userspace
2157 +----------------------------------------
2158 +There were three GIT trees for aufs3, aufs3-linux.git,
2159 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
2161 +While the aufs-util is always necessary, you need either of aufs3-linux
2162 +or aufs3-standalone.
2164 +The aufs3-linux tree includes the whole linux mainline GIT tree,
2165 +git://git.kernel.org/.../torvalds/linux.git.
2166 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2167 +build aufs3 as an external kernel module.
2169 +On the other hand, the aufs3-standalone tree has only aufs source files
2170 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2172 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
2173 +represents the linux kernel version, "linux-3.x". For instance,
2174 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
2175 +"aufs3.x-rcN" branch.
2178 +$ git clone --reference /your/linux/git/tree \
2179 + git://git.code.sf.net/p/aufs/aufs3-linux aufs-aufs3-linux \
2181 +- if you don't have linux GIT tree, then remove "--reference ..."
2182 +$ cd aufs3-linux.git
2183 +$ git checkout origin/aufs3.0
2185 +o aufs3-standalone tree
2186 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
2187 + aufs3-standalone.git
2188 +$ cd aufs3-standalone.git
2189 +$ git checkout origin/aufs3.0
2192 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
2195 +$ git checkout origin/aufs3.0
2197 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
2198 +The minor version number, 'x' in '3.x', of aufs may not always
2199 +follow the minor version number of the kernel.
2200 +Because changes in the kernel that cause the use of a new
2201 +minor version number do not always require changes to aufs-util.
2203 +Since aufs-util has its own minor version number, you may not be
2204 +able to find a GIT branch in aufs-util for your kernel's
2205 +exact minor version number.
2206 +In this case, you should git-checkout the branch for the
2207 +nearest lower number.
2209 +For (an unreleased) example:
2210 +If you are using "linux-3.10" and the "aufs3.10" branch
2211 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
2212 +or something numerically smaller is the branch for your kernel.
2214 +Also you can view all branches by
2218 +3. Configuration and Compilation
2219 +----------------------------------------
2220 +Make sure you have git-checkout'ed the correct branch.
2222 +For aufs3-linux tree,
2223 +- enable CONFIG_AUFS_FS.
2224 +- set other aufs configurations if necessary.
2226 +For aufs3-standalone tree,
2227 +There are several ways to build.
2230 +- apply ./aufs3-kbuild.patch to your kernel source files.
2231 +- apply ./aufs3-base.patch too.
2232 +- apply ./aufs3-mmap.patch too.
2233 +- apply ./aufs3-standalone.patch too, if you have a plan to set
2234 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
2235 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2236 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2237 +- enable CONFIG_AUFS_FS, you can select either
2239 +- and build your kernel as usual.
2240 +- install the built kernel.
2241 + Note: Since linux-3.9, every filesystem module requires an alias
2242 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2243 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2244 +- install the header files too by "make headers_install" to the
2245 + directory where you specify. By default, it is $PWD/usr.
2246 + "make help" shows a brief note for headers_install.
2247 +- and reboot your system.
2250 +- module only (CONFIG_AUFS_FS=m).
2251 +- apply ./aufs3-base.patch to your kernel source files.
2252 +- apply ./aufs3-mmap.patch too.
2253 +- apply ./aufs3-standalone.patch too.
2254 +- build your kernel, don't forget "make headers_install", and reboot.
2255 +- edit ./config.mk and set other aufs configurations if necessary.
2256 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2257 + every aufs configurations.
2258 +- build the module by simple "make".
2259 + Note: Since linux-3.9, every filesystem module requires an alias
2260 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2261 + modules.aliases file.
2262 +- you can specify ${KDIR} make variable which points to your kernel
2264 +- install the files
2265 + + run "make install" to install the aufs module, or copy the built
2266 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2267 + + run "make install_headers" (instead of headers_install) to install
2268 + the modified aufs header file (you can specify DESTDIR which is
2269 + available in aufs standalone version's Makefile only), or copy
2270 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2271 + you like manually. By default, the target directory is $PWD/usr.
2272 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
2273 + kernel source tree.
2275 +Note: The header file aufs_type.h is necessary to build aufs-util
2276 + as well as "make headers_install" in the kernel source tree.
2277 + headers_install is subject to be forgotten, but it is essentially
2278 + necessary, not only for building aufs-util.
2279 + You may not meet problems without headers_install in some older
2283 +- read README in aufs-util, build and install it
2284 +- note that your distribution may contain an obsoleted version of
2285 + aufs_type.h in /usr/include/linux or something. When you build aufs
2286 + utilities, make sure that your compiler refers the correct aufs header
2287 + file which is built by "make headers_install."
2288 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2289 + then run "make install_ulib" too. And refer to the aufs manual in
2292 +There several other patches in aufs3-standalone.git. They are all
2293 +optional. When you meet some problems, they will help you.
2294 +- aufs3-loopback.patch
2295 + Supports a nested loopback mount in a branch-fs. This patch is
2296 + unnecessary until aufs produces a message like "you may want to try
2297 + another patch for loopback file".
2299 + Modifies a system global kernel internal function get_next_ino() in
2300 + order to stop assigning 0 for an inode-number. Not directly related to
2301 + aufs, but recommended generally.
2303 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2304 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2305 + duplication of inode number, which is important for backup tools and
2306 + other utilities. When you find aufs XINO files for tmpfs branch
2307 + growing too much, try this patch.
2311 +----------------------------------------
2312 +At first, make sure aufs-util are installed, and please read the aufs
2313 +manual, aufs.5 in aufs-util.git tree.
2317 +$ mkdir /tmp/rw /tmp/aufs
2318 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2320 +Here is another example. The result is equivalent.
2321 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2323 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2324 +# mount -o remount,append:${HOME} /tmp/aufs
2326 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2327 +you modify a file under /tmp/aufs, the one on your home directory is
2328 +not affected, instead the same named file will be newly created under
2329 +/tmp/rw. And all of your modification to a file will be applied to
2330 +the one under /tmp/rw. This is called the file based Copy on Write
2332 +Aufs mount options are described in aufs.5.
2333 +If you run chroot or something and make your aufs as a root directory,
2334 +then you need to customize the shutdown script. See the aufs manual in
2337 +Additionally, there are some sample usages of aufs which are a
2338 +diskless system with network booting, and LiveCD over NFS.
2339 +See sample dir in CVS tree on SourceForge.
2343 +----------------------------------------
2344 +When you have any problems or strange behaviour in aufs, please let me
2346 +- /proc/mounts (instead of the output of mount(8))
2347 +- /sys/module/aufs/*
2348 +- /sys/fs/aufs/* (if you have them)
2349 +- /debug/aufs/* (if you have them)
2350 +- linux kernel version
2351 + if your kernel is not plain, for example modified by distributor,
2352 + the url where i can download its source is necessary too.
2353 +- aufs version which was printed at loading the module or booting the
2354 + system, instead of the date you downloaded.
2355 +- configuration (define/undefine CONFIG_AUFS_xxx)
2356 +- kernel configuration or /proc/config.gz (if you have it)
2357 +- behaviour which you think to be incorrect
2358 +- actual operation, reproducible one is better
2359 +- mailto: aufs-users at lists.sourceforge.net
2361 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2362 +and Feature Requests) on SourceForge. Please join and write to
2366 +6. Acknowledgements
2367 +----------------------------------------
2368 +Thanks to everyone who have tried and are using aufs, whoever
2369 +have reported a bug or any feedback.
2371 +Especially donators:
2372 +Tomas Matejicek(slax.org) made a donation (much more than once).
2373 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2374 + scripts) is making "doubling" donations.
2375 + Unfortunately I cannot list all of the donators, but I really
2377 + It ends Aug 2010, but the ordinary donation URL is still available.
2378 + <http://sourceforge.net/donate/index.php?group_id=167503>
2379 +Dai Itasaka made a donation (2007/8).
2380 +Chuck Smith made a donation (2008/4, 10 and 12).
2381 +Henk Schoneveld made a donation (2008/9).
2382 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2383 +Francois Dupoux made a donation (2008/11).
2384 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2385 + aufs2 GIT tree (2009/2).
2386 +William Grant made a donation (2009/3).
2387 +Patrick Lane made a donation (2009/4).
2388 +The Mail Archive (mail-archive.com) made donations (2009/5).
2389 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2390 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2391 +Pavel Pronskiy made a donation (2011/2).
2392 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2393 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2394 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2396 +Sam Liddicott made a donation (2011/9).
2397 +Era Scarecrow made a donation (2013/4).
2398 +Bor Ratajc made a donation (2013/4).
2399 +Alessandro Gorreta made a donation (2013/4).
2400 +POIRETTE Marc made a donation (2013/4).
2401 +Alessandro Gorreta made a donation (2013/4).
2402 +lauri kasvandik made a donation (2013/5).
2403 +"pemasu from Finland" made a donation (2013/7).
2404 +The Parted Magic Project made a donation (2013/9 and 11).
2405 +Pavel Barta made a donation (2013/10).
2406 +Nikolay Pertsev made a donation (2014/5).
2407 +James B made a donation (2014/7).
2408 +Stefano Di Biase made a donation (2014/8).
2410 +Thank you very much.
2411 +Donations are always, including future donations, very important and
2412 +helpful for me to keep on developing aufs.
2416 +----------------------------------------
2417 +If you are an experienced user, no explanation is needed. Aufs is
2418 +just a linux filesystem.
2423 +# Local variables: ;
2426 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2427 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2428 +++ linux/fs/aufs/aufs.h 2014-01-30 21:10:02.827480967 +0100
2431 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2433 + * This program, aufs is free software; you can redistribute it and/or modify
2434 + * it under the terms of the GNU General Public License as published by
2435 + * the Free Software Foundation; either version 2 of the License, or
2436 + * (at your option) any later version.
2438 + * This program is distributed in the hope that it will be useful,
2439 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2440 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2441 + * GNU General Public License for more details.
2443 + * You should have received a copy of the GNU General Public License
2444 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2448 + * all header files
2456 +#define AuStub(type, name, body, ...) \
2457 + static inline type name(__VA_ARGS__) { body; }
2459 +#define AuStubVoid(name, ...) \
2460 + AuStub(void, name, , __VA_ARGS__)
2461 +#define AuStubInt0(name, ...) \
2462 + AuStub(int, name, return 0, __VA_ARGS__)
2466 +#include "branch.h"
2469 +#include "dbgaufs.h"
2470 +#include "dentry.h"
2474 +#include "fstype.h"
2477 +#include "module.h"
2482 +#include "sysaufs.h"
2487 +#endif /* __KERNEL__ */
2488 +#endif /* __AUFS_H__ */
2489 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2490 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2491 +++ linux/fs/aufs/branch.c 2014-08-14 10:16:04.512608923 +0200
2494 + * Copyright (C) 2005-2014 Junjiro R. Okajima
2496 + * This program, aufs is free software; you can redistribute it and/or modify
2497 + * it under the terms of the GNU General Public License as published by
2498 + * the Free Software Foundation; either version 2 of the License, or
2499 + * (at your option) any later version.
2501 + * This program is distributed in the hope that it will be useful,
2502 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2503 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2504 + * GNU General Public License for more details.
2506 + * You should have received a copy of the GNU General Public License
2507 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2511 + * branch management
2514 +#include <linux/compat.h>
2515 +#include <linux/statfs.h>
2519 + * free a single branch
2522 +/* prohibit rmdir to the root of the branch */
2523 +/* todo: another new flag? */
2524 +static void au_br_dflags_force(struct au_branch *br)
2526 + struct dentry *h_dentry;
2528 + h_dentry = au_br_dentry(br);
2529 + spin_lock(&h_dentry->d_lock);
2530 + br->br_dflags = h_dentry->d_flags & DCACHE_MOUNTED;
2531 + h_dentry->d_flags |= DCACHE_MOUNTED;
2532 + spin_unlock(&h_dentry->d_lock);
2535 +/* restore its d_flags */
2536 +static void au_br_dflags_restore(struct au_branch *br)
2538 + struct dentry *h_dentry;
2540 + if (br->br_dflags)
2543 + h_dentry = au_br_dentry(br);
2544 + spin_lock(&h_dentry->d_lock);
2545 + h_dentry->d_flags &= ~DCACHE_MOUNTED;
2546 + spin_unlock(&h_dentry->d_lock);
2549 +static void au_br_do_free(struct au_branch *br)
2552 + struct au_wbr *wbr;
2553 + struct au_dykey **key;
2555 + au_hnotify_fin_br(br);
2557 + if (br->br_xino.xi_file)
2558 + fput(br->br_xino.xi_file);
2559 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2561 + AuDebugOn(atomic_read(&br->br_count));
2565 + for (i = 0; i < AuBrWh_Last; i++)
2566 + dput(wbr->wbr_wh[i]);
2567 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2568 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2571 + if (br->br_fhsm) {
2572 + au_br_fhsm_fin(br->br_fhsm);
2573 + kfree(br->br_fhsm);
2576 + key = br->br_dykey;
2577 + for (i = 0; i < AuBrDynOp; i++, key++)
2583 + au_br_dflags_restore(br);
2585 + /* recursive lock, s_umount of branch's */
2587 + path_put(&br->br_path);
2594 + * frees all branches
2596 +void au_br_free(struct au_sbinfo *sbinfo)
2598 + aufs_bindex_t bmax;
2599 + struct au_branch **br;
2601 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2603 + bmax = sbinfo->si_bend + 1;
2604 + br = sbinfo->si_branch;
2606 + au_br_do_free(*br++);
2610 + * find the index of a branch which is specified by @br_id.
2612 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2614 + aufs_bindex_t bindex, bend;
2616 + bend = au_sbend(sb);
2617 + for (bindex = 0; bindex <= bend; bindex++)
2618 + if (au_sbr_id(sb, bindex) == br_id)
2623 +/* ---------------------------------------------------------------------- */
2629 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2630 + struct dentry *h_root)
2632 + if (unlikely(h_adding == h_root
2633 + || au_test_loopback_overlap(sb, h_adding)))
2635 + if (h_adding->d_sb != h_root->d_sb)
2637 + return au_test_subdir(h_adding, h_root)
2638 + || au_test_subdir(h_root, h_adding);
2642 + * returns a newly allocated branch. @new_nbranch is a number of branches
2643 + * after adding a branch.
2645 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2648 + struct au_branch *add_branch;
2649 + struct dentry *root;
2653 + root = sb->s_root;
2654 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2655 + if (unlikely(!add_branch))
2658 + err = au_hnotify_init_br(add_branch, perm);
2659 + if (unlikely(err))
2662 + add_branch->br_wbr = NULL;
2663 + if (au_br_writable(perm)) {
2664 + /* may be freed separately at changing the branch permission */
2665 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2667 + if (unlikely(!add_branch->br_wbr))
2671 + add_branch->br_fhsm = NULL;
2672 + if (au_br_fhsm(perm)) {
2673 + err = au_fhsm_br_alloc(add_branch);
2674 + if (unlikely(err))
2678 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2680 + err = au_di_realloc(au_di(root), new_nbranch);
2682 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2684 + return add_branch; /* success */
2687 + kfree(add_branch->br_wbr);
2689 + au_hnotify_fin_br(add_branch);
2691 + kfree(add_branch);
2693 + return ERR_PTR(err);
2697 + * test if the branch permission is legal or not.
2699 +static int test_br(struct inode *inode, int brperm, char *path)
2703 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2708 + pr_err("write permission for readonly mount or inode, %s\n", path);
2716 + * 0: success, the caller will add it
2717 + * plus: success, it is already unified, the caller should ignore it
2720 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2723 + aufs_bindex_t bend, bindex;
2724 + struct dentry *root;
2725 + struct inode *inode, *h_inode;
2727 + root = sb->s_root;
2728 + bend = au_sbend(sb);
2729 + if (unlikely(bend >= 0
2730 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2734 + pr_err("%s duplicated\n", add->pathname);
2739 + err = -ENOSPC; /* -E2BIG; */
2740 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2741 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2742 + pr_err("number of branches exceeded %s\n", add->pathname);
2747 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2748 + pr_err("bad index %d\n", add->bindex);
2752 + inode = add->path.dentry->d_inode;
2754 + if (unlikely(!inode->i_nlink)) {
2755 + pr_err("no existence %s\n", add->pathname);
2760 + if (unlikely(inode->i_sb == sb)) {
2761 + pr_err("%s must be outside\n", add->pathname);
2765 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2766 + pr_err("unsupported filesystem, %s (%s)\n",
2767 + add->pathname, au_sbtype(inode->i_sb));
2771 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
2772 + if (unlikely(err))
2776 + return 0; /* success */
2779 + for (bindex = 0; bindex <= bend; bindex++)
2780 + if (unlikely(test_overlap(sb, add->path.dentry,
2781 + au_h_dptr(root, bindex)))) {
2782 + pr_err("%s is overlapped\n", add->pathname);
2787 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
2788 + h_inode = au_h_dptr(root, 0)->d_inode;
2789 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
2790 + || !uid_eq(h_inode->i_uid, inode->i_uid)
2791 + || !gid_eq(h_inode->i_gid, inode->i_gid))
2792 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
2794 + i_uid_read(inode), i_gid_read(inode),
2795 + (inode->i_mode & S_IALLUGO),
2796 + i_uid_read(h_inode), i_gid_read(h_inode),
2797 + (h_inode->i_mode & S_IALLUGO));
2805 + * initialize or clean the whiteouts for an adding branch
2807 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
2810 + int err, old_perm;
2811 + aufs_bindex_t bindex;
2812 + struct mutex *h_mtx;
2813 + struct au_wbr *wbr;
2814 + struct au_hinode *hdir;
2816 + err = vfsub_mnt_want_write(au_br_mnt(br));
2817 + if (unlikely(err))
2821 + old_perm = br->br_perm;
2822 + br->br_perm = new_perm;
2825 + bindex = au_br_index(sb, br->br_id);
2826 + if (0 <= bindex) {
2827 + hdir = au_hi(sb->s_root->d_inode, bindex);
2828 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
2830 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
2831 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
2834 + err = au_wh_init(br, sb);
2836 + wbr_wh_write_lock(wbr);
2837 + err = au_wh_init(br, sb);
2838 + wbr_wh_write_unlock(wbr);
2841 + au_hn_imtx_unlock(hdir);
2843 + mutex_unlock(h_mtx);
2844 + vfsub_mnt_drop_write(au_br_mnt(br));
2845 + br->br_perm = old_perm;
2847 + if (!err && wbr && !au_br_writable(new_perm)) {
2849 + br->br_wbr = NULL;
2856 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
2860 + struct kstatfs kst;
2861 + struct au_wbr *wbr;
2864 + au_rw_init(&wbr->wbr_wh_rwsem);
2865 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
2866 + atomic_set(&wbr->wbr_wh_running, 0);
2867 + wbr->wbr_bytes = 0;
2870 + * a limit for rmdir/rename a dir
2871 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
2873 + err = vfs_statfs(&br->br_path, &kst);
2874 + if (unlikely(err))
2877 + if (kst.f_namelen >= NAME_MAX)
2878 + err = au_br_init_wh(sb, br, perm);
2880 + pr_err("%pd(%s), unsupported namelen %ld\n",
2882 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
2888 +/* intialize a new branch */
2889 +static int au_br_init(struct au_branch *br, struct super_block *sb,
2890 + struct au_opt_add *add)
2895 + memset(&br->br_xino, 0, sizeof(br->br_xino));
2896 + mutex_init(&br->br_xino.xi_nondir_mtx);
2897 + br->br_perm = add->perm;
2898 + BUILD_BUG_ON(sizeof(br->br_dflags)
2899 + != sizeof(br->br_path.dentry->d_flags));
2900 + br->br_dflags = DCACHE_MOUNTED;
2901 + br->br_path = add->path; /* set first, path_get() later */
2902 + spin_lock_init(&br->br_dykey_lock);
2903 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
2904 + atomic_set(&br->br_count, 0);
2905 + atomic_set(&br->br_xino_running, 0);
2906 + br->br_id = au_new_br_id(sb);
2907 + AuDebugOn(br->br_id < 0);
2909 + if (au_br_writable(add->perm)) {
2910 + err = au_wbr_init(br, sb, add->perm);
2911 + if (unlikely(err))
2915 + if (au_opt_test(au_mntflags(sb), XINO)) {
2916 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
2917 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
2918 + if (unlikely(err)) {
2919 + AuDebugOn(br->br_xino.xi_file);
2924 + sysaufs_br_init(br);
2925 + path_get(&br->br_path);
2926 + goto out; /* success */
2929 + memset(&br->br_path, 0, sizeof(br->br_path));
2934 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
2935 + struct au_branch *br, aufs_bindex_t bend,
2936 + aufs_bindex_t amount)
2938 + struct au_branch **brp;
2940 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2942 + brp = sbinfo->si_branch + bindex;
2943 + memmove(brp + 1, brp, sizeof(*brp) * amount);
2945 + sbinfo->si_bend++;
2946 + if (unlikely(bend < 0))
2947 + sbinfo->si_bend = 0;
2950 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
2951 + aufs_bindex_t bend, aufs_bindex_t amount)
2953 + struct au_hdentry *hdp;
2955 + AuRwMustWriteLock(&dinfo->di_rwsem);
2957 + hdp = dinfo->di_hdentry + bindex;
2958 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
2959 + au_h_dentry_init(hdp);
2961 + if (unlikely(bend < 0))
2962 + dinfo->di_bstart = 0;
2965 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
2966 + aufs_bindex_t bend, aufs_bindex_t amount)
2968 + struct au_hinode *hip;
2970 + AuRwMustWriteLock(&iinfo->ii_rwsem);
2972 + hip = iinfo->ii_hinode + bindex;
2973 + memmove(hip + 1, hip, sizeof(*hip) * amount);
2974 + hip->hi_inode = NULL;
2977 + if (unlikely(bend < 0))
2978 + iinfo->ii_bstart = 0;
2981 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
2982 + aufs_bindex_t bindex)
2984 + struct dentry *root, *h_dentry;
2985 + struct inode *root_inode;
2986 + aufs_bindex_t bend, amount;
2988 + au_br_dflags_force(br);
2990 + root = sb->s_root;
2991 + root_inode = root->d_inode;
2992 + bend = au_sbend(sb);
2993 + amount = bend + 1 - bindex;
2994 + h_dentry = au_br_dentry(br);
2995 + au_sbilist_lock();
2996 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
2997 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
2998 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
2999 + au_set_h_dptr(root, bindex, dget(h_dentry));
3000 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
3002 + au_sbilist_unlock();
3005 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3008 + aufs_bindex_t bend, add_bindex;
3009 + struct dentry *root, *h_dentry;
3010 + struct inode *root_inode;
3011 + struct au_branch *add_branch;
3013 + root = sb->s_root;
3014 + root_inode = root->d_inode;
3015 + IMustLock(root_inode);
3016 + err = test_add(sb, add, remount);
3017 + if (unlikely(err < 0))
3021 + goto out; /* success */
3024 + bend = au_sbend(sb);
3025 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
3026 + err = PTR_ERR(add_branch);
3027 + if (IS_ERR(add_branch))
3030 + err = au_br_init(add_branch, sb, add);
3031 + if (unlikely(err)) {
3032 + au_br_do_free(add_branch);
3036 + add_bindex = add->bindex;
3038 + au_br_do_add(sb, add_branch, add_bindex);
3040 + sysaufs_brs_del(sb, add_bindex);
3041 + au_br_do_add(sb, add_branch, add_bindex);
3042 + sysaufs_brs_add(sb, add_bindex);
3045 + h_dentry = add->path.dentry;
3046 + if (!add_bindex) {
3047 + au_cpup_attr_all(root_inode, /*force*/1);
3048 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3050 + au_add_nlink(root_inode, h_dentry->d_inode);
3053 + * this test/set prevents aufs from handling unnecesary notify events
3054 + * of xino files, in case of re-adding a writable branch which was
3055 + * once detached from aufs.
3057 + if (au_xino_brid(sb) < 0
3058 + && au_br_writable(add_branch->br_perm)
3059 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3060 + && add_branch->br_xino.xi_file
3061 + && add_branch->br_xino.xi_file->f_dentry->d_parent == h_dentry)
3062 + au_xino_brid_set(sb, add_branch->br_id);
3068 +/* ---------------------------------------------------------------------- */
3070 +static unsigned long long au_farray_cb(void *a,
3071 + unsigned long long max __maybe_unused,
3074 + unsigned long long n;
3075 + struct file **p, *f;
3076 + struct au_sphlhead *files;
3077 + struct au_finfo *finfo;
3078 + struct super_block *sb = arg;
3082 + files = &au_sbi(sb)->si_files;
3083 + spin_lock(&files->spin);
3084 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3085 + f = finfo->fi_file;
3087 + && !special_file(file_inode(f)->i_mode)) {
3091 + AuDebugOn(n > max);
3094 + spin_unlock(&files->spin);
3099 +static struct file **au_farray_alloc(struct super_block *sb,
3100 + unsigned long long *max)
3102 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3103 + return au_array_alloc(max, au_farray_cb, sb);
3106 +static void au_farray_free(struct file **a, unsigned long long max)
3108 + unsigned long long ull;
3110 + for (ull = 0; ull < max; ull++)
3116 +/* ---------------------------------------------------------------------- */
3122 +/* to show the line number, do not make it inlined function */
3123 +#define AuVerbose(do_info, fmt, ...) do { \
3125 + pr_info(fmt, ##__VA_ARGS__); \
3128 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
3129 + aufs_bindex_t bend)
3131 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
3134 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
3135 + aufs_bindex_t bend)
3137 + return au_test_ibusy(dentry->d_inode, bstart, bend);
3141 + * test if the branch is deletable or not.
3143 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3144 + unsigned int sigen, const unsigned int verbose)
3146 + int err, i, j, ndentry;
3147 + aufs_bindex_t bstart, bend;
3148 + struct au_dcsub_pages dpages;
3149 + struct au_dpage *dpage;
3152 + err = au_dpages_init(&dpages, GFP_NOFS);
3153 + if (unlikely(err))
3155 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3156 + if (unlikely(err))
3159 + for (i = 0; !err && i < dpages.ndpage; i++) {
3160 + dpage = dpages.dpages + i;
3161 + ndentry = dpage->ndentry;
3162 + for (j = 0; !err && j < ndentry; j++) {
3163 + d = dpage->dentries[j];
3164 + AuDebugOn(!d_count(d));
3165 + if (!au_digen_test(d, sigen)) {
3166 + di_read_lock_child(d, AuLock_IR);
3167 + if (unlikely(au_dbrange_test(d))) {
3168 + di_read_unlock(d, AuLock_IR);
3172 + di_write_lock_child(d);
3173 + if (unlikely(au_dbrange_test(d))) {
3174 + di_write_unlock(d);
3177 + err = au_reval_dpath(d, sigen);
3179 + di_downgrade_lock(d, AuLock_IR);
3181 + di_write_unlock(d);
3186 + /* AuDbgDentry(d); */
3187 + bstart = au_dbstart(d);
3188 + bend = au_dbend(d);
3189 + if (bstart <= bindex
3191 + && au_h_dptr(d, bindex)
3192 + && au_test_dbusy(d, bstart, bend)) {
3194 + AuVerbose(verbose, "busy %pd\n", d);
3197 + di_read_unlock(d, AuLock_IR);
3202 + au_dpages_free(&dpages);
3207 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3208 + unsigned int sigen, const unsigned int verbose)
3211 + unsigned long long max, ull;
3212 + struct inode *i, **array;
3213 + aufs_bindex_t bstart, bend;
3215 + array = au_iarray_alloc(sb, &max);
3216 + err = PTR_ERR(array);
3217 + if (IS_ERR(array))
3221 + AuDbg("b%d\n", bindex);
3222 + for (ull = 0; !err && ull < max; ull++) {
3226 + if (i->i_ino == AUFS_ROOT_INO)
3229 + /* AuDbgInode(i); */
3230 + if (au_iigen(i, NULL) == sigen)
3231 + ii_read_lock_child(i);
3233 + ii_write_lock_child(i);
3234 + err = au_refresh_hinode_self(i);
3237 + ii_downgrade_lock(i);
3239 + ii_write_unlock(i);
3244 + bstart = au_ibstart(i);
3245 + bend = au_ibend(i);
3246 + if (bstart <= bindex
3248 + && au_h_iptr(i, bindex)
3249 + && au_test_ibusy(i, bstart, bend)) {
3251 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3254 + ii_read_unlock(i);
3256 + au_iarray_free(array, max);
3262 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3263 + const unsigned int verbose)
3266 + unsigned int sigen;
3268 + sigen = au_sigen(root->d_sb);
3269 + DiMustNoWaiters(root);
3270 + IiMustNoWaiters(root->d_inode);
3271 + di_write_unlock(root);
3272 + err = test_dentry_busy(root, bindex, sigen, verbose);
3274 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3275 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3280 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3281 + struct file **to_free, int *idx)
3284 + unsigned char matched, unmatched;
3285 + aufs_bindex_t bindex, bend;
3286 + struct au_fidir *fidir;
3287 + struct au_hfile *hfile;
3292 + fidir = au_fi(file)->fi_hdir;
3293 + AuDebugOn(!fidir);
3294 + bend = au_fbend_dir(file);
3295 + for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
3296 + hfile = fidir->fd_hfile + bindex;
3297 + if (!hfile->hf_file)
3300 + if (hfile->hf_br->br_id == br_id)
3304 + if (matched && unmatched)
3308 + goto out; /* success */
3312 + to_free[*idx] = file;
3321 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3322 + struct file **to_free, int opened)
3325 + unsigned long long ull, max;
3326 + aufs_bindex_t bstart;
3327 + struct file *file, **array;
3328 + struct inode *inode;
3329 + struct dentry *root;
3330 + struct au_hfile *hfile;
3332 + array = au_farray_alloc(sb, &max);
3333 + err = PTR_ERR(array);
3334 + if (IS_ERR(array))
3339 + root = sb->s_root;
3340 + di_write_unlock(root);
3341 + for (ull = 0; ull < max; ull++) {
3342 + file = array[ull];
3343 + if (unlikely(!file))
3346 + /* AuDbg("%pD\n", file); */
3347 + fi_read_lock(file);
3348 + bstart = au_fbstart(file);
3349 + inode = file_inode(file);
3350 + if (!S_ISDIR(inode->i_mode)) {
3351 + hfile = &au_fi(file)->fi_htop;
3352 + if (hfile->hf_br->br_id == br_id)
3355 + err = test_dir_busy(file, br_id, to_free, &idx);
3356 + fi_read_unlock(file);
3357 + if (unlikely(err))
3360 + di_write_lock_child(root);
3361 + au_farray_free(array, max);
3362 + AuDebugOn(idx > opened);
3368 +static void br_del_file(struct file **to_free, unsigned long long opened,
3369 + aufs_bindex_t br_id)
3371 + unsigned long long ull;
3372 + aufs_bindex_t bindex, bstart, bend, bfound;
3373 + struct file *file;
3374 + struct au_fidir *fidir;
3375 + struct au_hfile *hfile;
3377 + for (ull = 0; ull < opened; ull++) {
3378 + file = to_free[ull];
3379 + if (unlikely(!file))
3382 + /* AuDbg("%pD\n", file); */
3383 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
3385 + fidir = au_fi(file)->fi_hdir;
3386 + AuDebugOn(!fidir);
3387 + fi_write_lock(file);
3388 + bstart = au_fbstart(file);
3389 + bend = au_fbend_dir(file);
3390 + for (bindex = bstart; bindex <= bend; bindex++) {
3391 + hfile = fidir->fd_hfile + bindex;
3392 + if (!hfile->hf_file)
3395 + if (hfile->hf_br->br_id == br_id) {
3400 + AuDebugOn(bfound < 0);
3401 + au_set_h_fptr(file, bfound, NULL);
3402 + if (bfound == bstart) {
3403 + for (bstart++; bstart <= bend; bstart++)
3404 + if (au_hf_dir(file, bstart)) {
3405 + au_set_fbstart(file, bstart);
3409 + fi_write_unlock(file);
3413 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3414 + const aufs_bindex_t bindex,
3415 + const aufs_bindex_t bend)
3417 + struct au_branch **brp, **p;
3419 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3421 + brp = sbinfo->si_branch + bindex;
3422 + if (bindex < bend)
3423 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3424 + sbinfo->si_branch[0 + bend] = NULL;
3425 + sbinfo->si_bend--;
3427 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3429 + sbinfo->si_branch = p;
3430 + /* harmless error */
3433 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3434 + const aufs_bindex_t bend)
3436 + struct au_hdentry *hdp, *p;
3438 + AuRwMustWriteLock(&dinfo->di_rwsem);
3440 + hdp = dinfo->di_hdentry;
3441 + if (bindex < bend)
3442 + memmove(hdp + bindex, hdp + bindex + 1,
3443 + sizeof(*hdp) * (bend - bindex));
3444 + hdp[0 + bend].hd_dentry = NULL;
3447 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3449 + dinfo->di_hdentry = p;
3450 + /* harmless error */
3453 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3454 + const aufs_bindex_t bend)
3456 + struct au_hinode *hip, *p;
3458 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3460 + hip = iinfo->ii_hinode + bindex;
3461 + if (bindex < bend)
3462 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3463 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3464 + au_hn_init(iinfo->ii_hinode + bend);
3467 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3469 + iinfo->ii_hinode = p;
3470 + /* harmless error */
3473 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3474 + struct au_branch *br)
3476 + aufs_bindex_t bend;
3477 + struct au_sbinfo *sbinfo;
3478 + struct dentry *root, *h_root;
3479 + struct inode *inode, *h_inode;
3480 + struct au_hinode *hinode;
3482 + SiMustWriteLock(sb);
3484 + root = sb->s_root;
3485 + inode = root->d_inode;
3486 + sbinfo = au_sbi(sb);
3487 + bend = sbinfo->si_bend;
3489 + h_root = au_h_dptr(root, bindex);
3490 + hinode = au_hi(inode, bindex);
3491 + h_inode = au_igrab(hinode->hi_inode);
3494 + au_sbilist_lock();
3495 + au_br_do_del_brp(sbinfo, bindex, bend);
3496 + au_br_do_del_hdp(au_di(root), bindex, bend);
3497 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3498 + au_sbilist_unlock();
3502 + au_br_do_free(br);
3505 +static unsigned long long empty_cb(void *array, unsigned long long max,
3511 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3514 + unsigned long long opened;
3515 + unsigned int mnt_flags;
3516 + aufs_bindex_t bindex, bend, br_id;
3517 + unsigned char do_wh, verbose;
3518 + struct au_branch *br;
3519 + struct au_wbr *wbr;
3520 + struct dentry *root;
3521 + struct file **to_free;
3526 + root = sb->s_root;
3527 + bindex = au_find_dbindex(root, del->h_path.dentry);
3530 + goto out; /* success */
3532 + pr_err("%s no such branch\n", del->pathname);
3535 + AuDbg("bindex b%d\n", bindex);
3538 + mnt_flags = au_mntflags(sb);
3539 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3540 + bend = au_sbend(sb);
3541 + if (unlikely(!bend)) {
3542 + AuVerbose(verbose, "no more branches left\n");
3545 + br = au_sbr(sb, bindex);
3546 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3548 + br_id = br->br_id;
3549 + opened = atomic_read(&br->br_count);
3550 + if (unlikely(opened)) {
3551 + to_free = au_array_alloc(&opened, empty_cb, NULL);
3552 + err = PTR_ERR(to_free);
3553 + if (IS_ERR(to_free))
3556 + err = test_file_busy(sb, br_id, to_free, opened);
3557 + if (unlikely(err)) {
3558 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3564 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3566 + /* instead of WbrWhMustWriteLock(wbr) */
3567 + SiMustWriteLock(sb);
3568 + for (i = 0; i < AuBrWh_Last; i++) {
3569 + dput(wbr->wbr_wh[i]);
3570 + wbr->wbr_wh[i] = NULL;
3574 + err = test_children_busy(root, bindex, verbose);
3575 + if (unlikely(err)) {
3584 + * now we confirmed the branch is deletable.
3585 + * let's free the remaining opened dirs on the branch.
3587 + di_write_unlock(root);
3588 + br_del_file(to_free, opened, br_id);
3589 + di_write_lock_child(root);
3593 + au_br_do_del(sb, bindex, br);
3595 + sysaufs_brs_del(sb, bindex);
3596 + au_br_do_del(sb, bindex, br);
3597 + sysaufs_brs_add(sb, bindex);
3601 + au_cpup_attr_all(root->d_inode, /*force*/1);
3602 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3604 + au_sub_nlink(root->d_inode, del->h_path.dentry->d_inode);
3605 + if (au_opt_test(mnt_flags, PLINK))
3606 + au_plink_half_refresh(sb, br_id);
3608 + if (au_xino_brid(sb) == br_id)
3609 + au_xino_brid_set(sb, -1);
3610 + goto out; /* success */
3614 + rerr = au_br_init_wh(sb, br, br->br_perm);
3616 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3617 + del->pathname, rerr);
3620 + au_farray_free(to_free, opened);
3624 +/* ---------------------------------------------------------------------- */
3626 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3629 + aufs_bindex_t bstart, bend;
3630 + struct aufs_ibusy ibusy;
3631 + struct inode *inode, *h_inode;
3634 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3637 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3639 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3640 + if (unlikely(err)) {
3647 + si_read_lock(sb, AuLock_FLUSH);
3648 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3652 + ibusy.h_ino = 0; /* invalid */
3653 + inode = ilookup(sb, ibusy.ino);
3655 + || inode->i_ino == AUFS_ROOT_INO
3656 + || is_bad_inode(inode))
3659 + ii_read_lock_child(inode);
3660 + bstart = au_ibstart(inode);
3661 + bend = au_ibend(inode);
3662 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3663 + h_inode = au_h_iptr(inode, ibusy.bindex);
3664 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3665 + ibusy.h_ino = h_inode->i_ino;
3667 + ii_read_unlock(inode);
3671 + si_read_unlock(sb);
3673 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3674 + if (unlikely(err)) {
3683 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3685 + return au_ibusy(file->f_dentry->d_sb, (void __user *)arg);
3688 +#ifdef CONFIG_COMPAT
3689 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3691 + return au_ibusy(file->f_dentry->d_sb, compat_ptr(arg));
3695 +/* ---------------------------------------------------------------------- */
3698 + * change a branch permission
3701 +static void au_warn_ima(void)
3704 + /* since it doesn't support mark_files_ro() */
3705 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3709 +static int do_need_sigen_inc(int a, int b)
3711 + return au_br_whable(a) && !au_br_whable(b);
3714 +static int need_sigen_inc(int old, int new)
3716 + return do_need_sigen_inc(old, new)
3717 + || do_need_sigen_inc(new, old);
3720 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3723 + unsigned int mnt_flags;
3724 + unsigned long long ull, max;
3725 + aufs_bindex_t br_id;
3726 + unsigned char verbose, writer;
3727 + struct file *file, *hf, **array;
3728 + struct inode *inode;
3729 + struct au_hfile *hfile;
3731 + mnt_flags = au_mntflags(sb);
3732 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3734 + array = au_farray_alloc(sb, &max);
3735 + err = PTR_ERR(array);
3736 + if (IS_ERR(array))
3740 + br_id = au_sbr_id(sb, bindex);
3741 + for (ull = 0; ull < max; ull++) {
3742 + file = array[ull];
3743 + if (unlikely(!file))
3746 + /* AuDbg("%pD\n", file); */
3747 + fi_read_lock(file);
3748 + if (unlikely(au_test_mmapped(file))) {
3750 + AuVerbose(verbose, "mmapped %pD\n", file);
3752 + FiMustNoWaiters(file);
3753 + fi_read_unlock(file);
3757 + inode = file_inode(file);
3758 + hfile = &au_fi(file)->fi_htop;
3759 + hf = hfile->hf_file;
3760 + if (!S_ISREG(inode->i_mode)
3761 + || !(file->f_mode & FMODE_WRITE)
3762 + || hfile->hf_br->br_id != br_id
3763 + || !(hf->f_mode & FMODE_WRITE))
3764 + array[ull] = NULL;
3770 + FiMustNoWaiters(file);
3771 + fi_read_unlock(file);
3779 + for (ull = 0; ull < max; ull++) {
3780 + file = array[ull];
3784 + /* todo: already flushed? */
3786 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
3787 + * approach which resets f_mode and calls mnt_drop_write() and
3788 + * file_release_write() for each file, because the branch
3789 + * attribute in aufs world is totally different from the native
3792 + /* fi_read_lock(file); */
3793 + hfile = &au_fi(file)->fi_htop;
3794 + hf = hfile->hf_file;
3795 + /* fi_read_unlock(file); */
3796 + spin_lock(&hf->f_lock);
3797 + writer = !!(hf->f_mode & FMODE_WRITER);
3798 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
3799 + spin_unlock(&hf->f_lock);
3801 + put_write_access(file_inode(hf));
3802 + __mnt_drop_write(hf->f_path.mnt);
3807 + au_farray_free(array, max);
3813 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
3817 + aufs_bindex_t bindex;
3818 + struct dentry *root;
3819 + struct au_branch *br;
3820 + struct au_br_fhsm *bf;
3822 + root = sb->s_root;
3823 + bindex = au_find_dbindex(root, mod->h_root);
3826 + return 0; /* success */
3828 + pr_err("%s no such branch\n", mod->path);
3831 + AuDbg("bindex b%d\n", bindex);
3833 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
3834 + if (unlikely(err))
3837 + br = au_sbr(sb, bindex);
3838 + AuDebugOn(mod->h_root != au_br_dentry(br));
3839 + if (br->br_perm == mod->perm)
3840 + return 0; /* success */
3842 + /* pre-allocate for non-fhsm --> fhsm */
3844 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
3845 + err = au_fhsm_br_alloc(br);
3846 + if (unlikely(err))
3849 + br->br_fhsm = NULL;
3852 + if (au_br_writable(br->br_perm)) {
3853 + /* remove whiteout base */
3854 + err = au_br_init_wh(sb, br, mod->perm);
3855 + if (unlikely(err))
3858 + if (!au_br_writable(mod->perm)) {
3859 + /* rw --> ro, file might be mmapped */
3860 + DiMustNoWaiters(root);
3861 + IiMustNoWaiters(root->d_inode);
3862 + di_write_unlock(root);
3863 + err = au_br_mod_files_ro(sb, bindex);
3864 + /* aufs_write_lock() calls ..._child() */
3865 + di_write_lock_child(root);
3867 + if (unlikely(err)) {
3869 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
3872 + rerr = au_wbr_init(br, sb, br->br_perm);
3873 + if (unlikely(rerr)) {
3874 + AuIOErr("nested error %d (%d)\n",
3876 + br->br_perm = mod->perm;
3880 + } else if (au_br_writable(mod->perm)) {
3883 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
3885 + err = au_wbr_init(br, sb, mod->perm);
3886 + if (unlikely(err)) {
3887 + kfree(br->br_wbr);
3888 + br->br_wbr = NULL;
3892 + if (unlikely(err))
3895 + if (au_br_fhsm(br->br_perm)) {
3896 + if (!au_br_fhsm(mod->perm)) {
3897 + /* fhsm --> non-fhsm */
3898 + au_br_fhsm_fin(br->br_fhsm);
3899 + kfree(br->br_fhsm);
3900 + br->br_fhsm = NULL;
3902 + } else if (au_br_fhsm(mod->perm))
3903 + /* non-fhsm --> fhsm */
3906 + if ((br->br_perm & AuBrAttr_UNPIN)
3907 + && !(mod->perm & AuBrAttr_UNPIN))
3908 + au_br_dflags_force(br);
3909 + else if (!(br->br_perm & AuBrAttr_UNPIN)
3910 + && (mod->perm & AuBrAttr_UNPIN))
3911 + au_br_dflags_restore(br);
3912 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
3913 + br->br_perm = mod->perm;
3914 + goto out; /* success */
3923 +/* ---------------------------------------------------------------------- */
3925 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
3928 + struct kstatfs kstfs;
3930 + err = vfs_statfs(&br->br_path, &kstfs);
3932 + stfs->f_blocks = kstfs.f_blocks;
3933 + stfs->f_bavail = kstfs.f_bavail;
3934 + stfs->f_files = kstfs.f_files;
3935 + stfs->f_ffree = kstfs.f_ffree;
3940 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
3941 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
3942 +++ linux/fs/aufs/branch.h 2014-08-14 10:15:45.118609182 +0200
3945 + * Copyright (C) 2005-2014 Junjiro R. Okajima
3947 + * This program, aufs is free software; you can redistribute it and/or modify
3948 + * it under the terms of the GNU General Public License as published by
3949 + * the Free Software Foundation; either version 2 of the License, or
3950 + * (at your option) any later version.
3952 + * This program is distributed in the hope that it will be useful,
3953 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
3954 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3955 + * GNU General Public License for more details.
3957 + * You should have received a copy of the GNU General Public License
3958 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
3962 + * branch filesystems and xino for them
3965 +#ifndef __AUFS_BRANCH_H__
3966 +#define __AUFS_BRANCH_H__
3970 +#include <linux/mount.h>
3975 +/* ---------------------------------------------------------------------- */
3978 +struct au_xino_file {
3979 + struct file *xi_file;
3980 + struct mutex xi_nondir_mtx;
3982 + /* todo: make xino files an array to support huge inode number */
3984 +#ifdef CONFIG_DEBUG_FS
3985 + struct dentry *xi_dbgaufs;
3989 +/* File-based Hierarchical Storage Management */
3990 +struct au_br_fhsm {
3991 +#ifdef CONFIG_AUFS_FHSM
3992 + struct mutex bf_lock;
3993 + unsigned long bf_jiffy;
3994 + struct aufs_stfs bf_stfs;
3999 +/* members for writable branch only */
4000 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4002 + struct au_rwsem wbr_wh_rwsem;
4003 + struct dentry *wbr_wh[AuBrWh_Last];
4004 + atomic_t wbr_wh_running;
4005 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4006 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4007 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4010 + unsigned long long wbr_bytes;
4013 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4014 +#define AuBrDynOp (AuDyLast * 4)
4016 +#ifdef CONFIG_AUFS_HFSNOTIFY
4017 +/* support for asynchronous destruction */
4018 +struct au_br_hfsnotify {
4019 + struct fsnotify_group *hfsn_group;
4023 +/* sysfs entries */
4024 +struct au_brsysfs {
4026 + struct attribute attr;
4035 +/* protected by superblock rwsem */
4037 + struct au_xino_file br_xino;
4039 + aufs_bindex_t br_id;
4042 + unsigned int br_dflags;
4043 + struct path br_path;
4044 + spinlock_t br_dykey_lock;
4045 + struct au_dykey *br_dykey[AuBrDynOp];
4046 + atomic_t br_count;
4048 + struct au_wbr *br_wbr;
4049 + struct au_br_fhsm *br_fhsm;
4051 + /* xino truncation */
4052 + atomic_t br_xino_running;
4054 +#ifdef CONFIG_AUFS_HFSNOTIFY
4055 + struct au_br_hfsnotify *br_hfsn;
4058 +#ifdef CONFIG_SYSFS
4059 + /* entries under sysfs per mount-point */
4060 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4064 +/* ---------------------------------------------------------------------- */
4066 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4068 + return br->br_path.mnt;
4071 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4073 + return br->br_path.dentry;
4076 +static inline struct super_block *au_br_sb(struct au_branch *br)
4078 + return au_br_mnt(br)->mnt_sb;
4081 +static inline int au_br_rdonly(struct au_branch *br)
4083 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4084 + || !au_br_writable(br->br_perm))
4088 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4090 +#ifdef CONFIG_AUFS_HNOTIFY
4091 + return !(brperm & AuBrPerm_RR);
4097 +/* ---------------------------------------------------------------------- */
4101 +void au_br_free(struct au_sbinfo *sinfo);
4102 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4104 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4106 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4107 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4108 +#ifdef CONFIG_COMPAT
4109 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4112 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4115 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4118 +static const loff_t au_loff_max = LLONG_MAX;
4120 +int au_xib_trunc(struct super_block *sb);
4121 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
4123 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
4125 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4126 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4127 +ino_t au_xino_new_ino(struct super_block *sb);
4128 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4129 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4131 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4133 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4134 + struct file *base_file, int do_test);
4135 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4137 +struct au_opt_xino;
4138 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4139 +void au_xino_clr(struct super_block *sb);
4140 +struct file *au_xino_def(struct super_block *sb);
4141 +int au_xino_path(struct seq_file *seq, struct file *file);
4143 +/* ---------------------------------------------------------------------- */
4145 +/* Superblock to branch */
4147 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4149 + return au_sbr(sb, bindex)->br_id;
4153 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4155 + return au_br_mnt(au_sbr(sb, bindex));
4159 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4161 + return au_br_sb(au_sbr(sb, bindex));
4164 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4166 + atomic_dec(&au_sbr(sb, bindex)->br_count);
4169 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4171 + return au_sbr(sb, bindex)->br_perm;
4174 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4176 + return au_br_whable(au_sbr_perm(sb, bindex));
4179 +/* ---------------------------------------------------------------------- */
4182 + * wbr_wh_read_lock, wbr_wh_write_lock
4183 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4185 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4187 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4188 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4189 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4191 +/* ---------------------------------------------------------------------- */
4193 +#ifdef CONFIG_AUFS_FHSM
4194 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4196 + mutex_init(&brfhsm->bf_lock);
4197 + brfhsm->bf_jiffy = 0;
4198 + brfhsm->bf_readable = 0;
4201 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4203 + mutex_destroy(&brfhsm->bf_lock);
4206 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4207 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4210 +#endif /* __KERNEL__ */
4211 +#endif /* __AUFS_BRANCH_H__ */
4212 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4213 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4214 +++ linux/fs/aufs/conf.mk 2014-08-14 10:15:45.118609182 +0200
4217 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4221 +AuConfStr += ${1}=${${1}}
4225 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4227 + HNOTIFY HFSNOTIFY \
4237 +$(foreach i, ${AuConfAll}, \
4238 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4240 +AuConfName = ${obj}/conf.str
4241 +${AuConfName}.tmp: FORCE
4242 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4243 +${AuConfName}: ${AuConfName}.tmp
4244 + @diff -q $< $@ > /dev/null 2>&1 || { \
4245 + echo ' GEN ' $@; \
4249 +clean-files += ${AuConfName} ${AuConfName}.tmp
4250 +${obj}/sysfs.o: ${AuConfName}
4252 +-include ${srctree}/${src}/conf_priv.mk
4253 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4254 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4255 +++ linux/fs/aufs/cpup.c 2014-08-14 10:15:45.118609182 +0200
4258 + * Copyright (C) 2005-2014 Junjiro R. Okajima
4260 + * This program, aufs is free software; you can redistribute it and/or modify
4261 + * it under the terms of the GNU General Public License as published by
4262 + * the Free Software Foundation; either version 2 of the License, or
4263 + * (at your option) any later version.
4265 + * This program is distributed in the hope that it will be useful,
4266 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4267 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4268 + * GNU General Public License for more details.
4270 + * You should have received a copy of the GNU General Public License
4271 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4275 + * copy-up functions, see wbr_policy.c for copy-down
4278 +#include <linux/fs_stack.h>
4279 +#include <linux/mm.h>
4282 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4284 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4285 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4287 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4289 + dst->i_flags |= iflags & ~mask;
4290 + if (au_test_fs_notime(dst->i_sb))
4291 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4294 +void au_cpup_attr_timesizes(struct inode *inode)
4296 + struct inode *h_inode;
4298 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4299 + fsstack_copy_attr_times(inode, h_inode);
4300 + fsstack_copy_inode_size(inode, h_inode);
4303 +void au_cpup_attr_nlink(struct inode *inode, int force)
4305 + struct inode *h_inode;
4306 + struct super_block *sb;
4307 + aufs_bindex_t bindex, bend;
4310 + bindex = au_ibstart(inode);
4311 + h_inode = au_h_iptr(inode, bindex);
4313 + && !S_ISDIR(h_inode->i_mode)
4314 + && au_opt_test(au_mntflags(sb), PLINK)
4315 + && au_plink_test(inode))
4319 + * 0 can happen in revalidating.
4320 + * h_inode->i_mutex may not be held here, but it is harmless since once
4321 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4323 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4324 + * the incorrect link count.
4326 + set_nlink(inode, h_inode->i_nlink);
4329 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4330 + * it may includes whplink directory.
4332 + if (S_ISDIR(h_inode->i_mode)) {
4333 + bend = au_ibend(inode);
4334 + for (bindex++; bindex <= bend; bindex++) {
4335 + h_inode = au_h_iptr(inode, bindex);
4337 + au_add_nlink(inode, h_inode);
4342 +void au_cpup_attr_changeable(struct inode *inode)
4344 + struct inode *h_inode;
4346 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4347 + inode->i_mode = h_inode->i_mode;
4348 + inode->i_uid = h_inode->i_uid;
4349 + inode->i_gid = h_inode->i_gid;
4350 + au_cpup_attr_timesizes(inode);
4351 + au_cpup_attr_flags(inode, h_inode->i_flags);
4354 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4356 + struct au_iinfo *iinfo = au_ii(inode);
4358 + IiMustWriteLock(inode);
4360 + iinfo->ii_higen = h_inode->i_generation;
4361 + iinfo->ii_hsb1 = h_inode->i_sb;
4364 +void au_cpup_attr_all(struct inode *inode, int force)
4366 + struct inode *h_inode;
4368 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4369 + au_cpup_attr_changeable(inode);
4370 + if (inode->i_nlink > 0)
4371 + au_cpup_attr_nlink(inode, force);
4372 + inode->i_rdev = h_inode->i_rdev;
4373 + inode->i_blkbits = h_inode->i_blkbits;
4374 + au_cpup_igen(inode, h_inode);
4377 +/* ---------------------------------------------------------------------- */
4379 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4381 +/* keep the timestamps of the parent dir when cpup */
4382 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4383 + struct path *h_path)
4385 + struct inode *h_inode;
4387 + dt->dt_dentry = dentry;
4388 + dt->dt_h_path = *h_path;
4389 + h_inode = h_path->dentry->d_inode;
4390 + dt->dt_atime = h_inode->i_atime;
4391 + dt->dt_mtime = h_inode->i_mtime;
4395 +void au_dtime_revert(struct au_dtime *dt)
4397 + struct iattr attr;
4400 + attr.ia_atime = dt->dt_atime;
4401 + attr.ia_mtime = dt->dt_mtime;
4402 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4403 + | ATTR_ATIME | ATTR_ATIME_SET;
4405 + /* no delegation since this is a directory */
4406 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4407 + if (unlikely(err))
4408 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4411 +/* ---------------------------------------------------------------------- */
4413 +/* internal use only */
4414 +struct au_cpup_reg_attr {
4417 + unsigned int iflags; /* inode->i_flags */
4420 +static noinline_for_stack
4421 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4422 + struct au_cpup_reg_attr *h_src_attr)
4426 + struct path h_path;
4427 + struct inode *h_isrc, *h_idst;
4428 + struct kstat *h_st;
4430 + h_path.dentry = au_h_dptr(dst, bindex);
4431 + h_idst = h_path.dentry->d_inode;
4432 + h_path.mnt = au_sbr_mnt(dst->d_sb, bindex);
4433 + h_isrc = h_src->d_inode;
4434 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4435 + | ATTR_ATIME | ATTR_MTIME
4436 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4437 + if (h_src_attr && h_src_attr->valid) {
4438 + h_st = &h_src_attr->st;
4439 + ia.ia_uid = h_st->uid;
4440 + ia.ia_gid = h_st->gid;
4441 + ia.ia_atime = h_st->atime;
4442 + ia.ia_mtime = h_st->mtime;
4443 + if (h_idst->i_mode != h_st->mode
4444 + && !S_ISLNK(h_idst->i_mode)) {
4445 + ia.ia_valid |= ATTR_MODE;
4446 + ia.ia_mode = h_st->mode;
4448 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4449 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4451 + ia.ia_uid = h_isrc->i_uid;
4452 + ia.ia_gid = h_isrc->i_gid;
4453 + ia.ia_atime = h_isrc->i_atime;
4454 + ia.ia_mtime = h_isrc->i_mtime;
4455 + if (h_idst->i_mode != h_isrc->i_mode
4456 + && !S_ISLNK(h_idst->i_mode)) {
4457 + ia.ia_valid |= ATTR_MODE;
4458 + ia.ia_mode = h_isrc->i_mode;
4460 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4461 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4463 + /* no delegation since it is just created */
4464 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4466 + /* is this nfs only? */
4467 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4468 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4469 + ia.ia_mode = h_isrc->i_mode;
4470 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4476 +/* ---------------------------------------------------------------------- */
4478 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4479 + char *buf, unsigned long blksize)
4482 + size_t sz, rbytes, wbytes;
4483 + unsigned char all_zero;
4485 + struct mutex *h_mtx;
4486 + /* reduce stack usage */
4489 + zp = page_address(ZERO_PAGE(0));
4490 + if (unlikely(!zp))
4491 + return -ENOMEM; /* possible? */
4496 + AuDbg("len %lld\n", len);
4498 + if (len < blksize)
4502 + /* todo: signal_pending? */
4503 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4504 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4507 + if (unlikely(err < 0))
4511 + if (len >= rbytes && rbytes == blksize)
4512 + all_zero = !memcmp(buf, zp, rbytes);
4519 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4521 + /* todo: signal_pending? */
4522 + if (unlikely(err == -EAGAIN || err == -EINTR))
4524 + if (unlikely(err < 0))
4529 + if (unlikely(err < 0))
4535 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4537 + if (unlikely(res < 0))
4544 + /* the last block may be a hole */
4545 + if (!err && all_zero) {
4546 + AuLabel(last hole);
4549 + if (au_test_nfs(dst->f_dentry->d_sb)) {
4550 + /* nfs requires this step to make last hole */
4551 + /* is this only nfs? */
4553 + /* todo: signal_pending? */
4554 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4555 + } while (err == -EAGAIN || err == -EINTR);
4562 + ia->ia_size = dst->f_pos;
4563 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4564 + ia->ia_file = dst;
4565 + h_mtx = &file_inode(dst)->i_mutex;
4566 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4567 + /* no delegation since it is just created */
4568 + err = vfsub_notify_change(&dst->f_path, ia,
4569 + /*delegated*/NULL);
4570 + mutex_unlock(h_mtx);
4577 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4580 + unsigned long blksize;
4581 + unsigned char do_kfree;
4585 + blksize = dst->f_dentry->d_sb->s_blocksize;
4586 + if (!blksize || PAGE_SIZE < blksize)
4587 + blksize = PAGE_SIZE;
4588 + AuDbg("blksize %lu\n", blksize);
4589 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4591 + buf = kmalloc(blksize, GFP_NOFS);
4593 + buf = (void *)__get_free_page(GFP_NOFS);
4594 + if (unlikely(!buf))
4597 + if (len > (1 << 22))
4598 + AuDbg("copying a large file %lld\n", (long long)len);
4602 + err = au_do_copy_file(dst, src, len, buf, blksize);
4606 + free_page((unsigned long)buf);
4613 + * to support a sparse file which is opened with O_APPEND,
4614 + * we need to close the file.
4616 +static int au_cp_regular(struct au_cp_generic *cpg)
4619 + enum { SRC, DST };
4621 + aufs_bindex_t bindex;
4622 + unsigned int flags;
4623 + struct dentry *dentry;
4625 + struct file *file;
4629 + .bindex = cpg->bsrc,
4630 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4634 + .bindex = cpg->bdst,
4635 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4636 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4637 + .label = &&out_src
4640 + struct super_block *sb;
4642 + /* bsrc branch can be ro/rw. */
4643 + sb = cpg->dentry->d_sb;
4645 + for (i = 0; i < 2; i++, f++) {
4646 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4647 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4648 + /*file*/NULL, f->force_wr);
4649 + err = PTR_ERR(f->file);
4650 + if (IS_ERR(f->file))
4654 + /* try stopping to update while we copyup */
4655 + IMustLock(file[SRC].dentry->d_inode);
4656 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4658 + fput(file[DST].file);
4659 + au_sbr_put(sb, file[DST].bindex);
4662 + fput(file[SRC].file);
4663 + au_sbr_put(sb, file[SRC].bindex);
4668 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4669 + struct au_cpup_reg_attr *h_src_attr)
4673 + struct path h_path;
4674 + struct inode *h_src_inode, *h_dst_inode;
4677 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
4678 + l = i_size_read(h_src_inode);
4679 + if (cpg->len == -1 || l < cpg->len)
4682 + /* try stopping to update while we are referencing */
4683 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4684 + au_pin_hdir_unlock(cpg->pin);
4686 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4687 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4688 + h_src_attr->iflags = h_src_inode->i_flags;
4689 + err = vfs_getattr(&h_path, &h_src_attr->st);
4690 + if (unlikely(err)) {
4691 + mutex_unlock(&h_src_inode->i_mutex);
4694 + h_src_attr->valid = 1;
4695 + err = au_cp_regular(cpg);
4696 + mutex_unlock(&h_src_inode->i_mutex);
4697 + rerr = au_pin_hdir_relock(cpg->pin);
4701 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
4702 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
4703 + h_dst_inode = h_path.dentry->d_inode;
4704 + spin_lock(&h_dst_inode->i_lock);
4705 + h_dst_inode->i_state |= I_LINKABLE;
4706 + spin_unlock(&h_dst_inode->i_lock);
4713 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4714 + struct inode *h_dir)
4717 + mm_segment_t old_fs;
4724 + if (unlikely(!h_src->d_inode->i_op->readlink))
4728 + sym.k = (void *)__get_free_page(GFP_NOFS);
4729 + if (unlikely(!sym.k))
4732 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
4733 + old_fs = get_fs();
4734 + set_fs(KERNEL_DS);
4735 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
4740 + sym.k[symlen] = 0;
4741 + err = vfsub_symlink(h_dir, h_path, sym.k);
4743 + free_page((unsigned long)sym.k);
4749 +static noinline_for_stack
4750 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
4751 + struct au_cpup_reg_attr *h_src_attr)
4755 + unsigned int mnt_flags;
4756 + unsigned char isdir, isreg, force;
4757 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
4758 + struct au_dtime dt;
4759 + struct path h_path;
4760 + struct dentry *h_src, *h_dst, *h_parent;
4761 + struct inode *h_inode, *h_dir;
4762 + struct super_block *sb;
4764 + /* bsrc branch can be ro/rw. */
4765 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4766 + h_inode = h_src->d_inode;
4767 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
4769 + /* try stopping to be referenced while we are creating */
4770 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4771 + if (au_ftest_cpup(cpg->flags, RENAME))
4772 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
4773 + AUFS_WH_PFX_LEN));
4774 + h_parent = h_dst->d_parent; /* dir inode is locked */
4775 + h_dir = h_parent->d_inode;
4777 + AuDebugOn(h_parent != h_dst->d_parent);
4779 + sb = cpg->dentry->d_sb;
4780 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
4782 + h_path.dentry = h_parent;
4783 + au_dtime_store(&dt, dst_parent, &h_path);
4785 + h_path.dentry = h_dst;
4789 + mode = h_inode->i_mode;
4790 + switch (mode & S_IFMT) {
4793 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
4794 + /*want_excl*/true);
4796 + err = au_do_cpup_regular(cpg, h_src_attr);
4800 + err = vfsub_mkdir(h_dir, &h_path, mode);
4803 + * strange behaviour from the users view,
4804 + * particularry setattr case
4806 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
4807 + au_cpup_attr_nlink(dst_parent->d_inode,
4809 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
4813 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
4817 + AuDebugOn(!capable(CAP_MKNOD));
4821 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
4824 + AuIOErr("Unknown inode type 0%o\n", mode);
4828 + mnt_flags = au_mntflags(sb);
4829 + if (!au_opt_test(mnt_flags, UDBA_NONE)
4831 + && au_opt_test(mnt_flags, XINO)
4832 + && (h_inode->i_nlink == 1
4833 + || (h_inode->i_state & I_LINKABLE))
4834 + /* todo: unnecessary? */
4835 + /* && cpg->dentry->d_inode->i_nlink == 1 */
4836 + && cpg->bdst < cpg->bsrc
4837 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
4838 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
4839 + /* ignore this error */
4844 + force = !!cpg->len;
4845 + if (cpg->len == -1)
4846 + force = !!i_size_read(h_inode);
4848 + au_fhsm_wrote(sb, cpg->bdst, force);
4852 + au_dtime_revert(&dt);
4856 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
4859 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
4860 + struct inode *h_dir;
4861 + aufs_bindex_t bdst;
4863 + dentry = cpg->dentry;
4865 + h_dentry = au_h_dptr(dentry, bdst);
4866 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
4868 + au_set_h_dptr(dentry, bdst, NULL);
4869 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
4871 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
4872 + au_set_h_dptr(dentry, bdst, h_dentry);
4875 + parent = dget_parent(dentry);
4876 + h_parent = au_h_dptr(parent, bdst);
4878 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
4879 + if (IS_ERR(h_path->dentry))
4880 + err = PTR_ERR(h_path->dentry);
4882 + if (unlikely(err))
4885 + h_parent = h_dentry->d_parent; /* dir inode is locked */
4886 + h_dir = h_parent->d_inode;
4888 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
4889 + /* no delegation since it is just created */
4890 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
4891 + dput(h_path->dentry);
4898 + * copyup the @dentry from @bsrc to @bdst.
4899 + * the caller must set the both of lower dentries.
4900 + * @len is for truncating when it is -1 copyup the entire file.
4901 + * in link/rename cases, @dst_parent may be different from the real one.
4902 + * basic->bsrc can be larger than basic->bdst.
4904 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
4907 + aufs_bindex_t old_ibstart;
4908 + unsigned char isdir, plink;
4909 + struct dentry *h_src, *h_dst, *h_parent;
4910 + struct inode *dst_inode, *h_dir, *inode, *delegated;
4911 + struct super_block *sb;
4912 + struct au_branch *br;
4913 + /* to reuduce stack size */
4915 + struct au_dtime dt;
4916 + struct path h_path;
4917 + struct au_cpup_reg_attr h_src_attr;
4921 + a = kmalloc(sizeof(*a), GFP_NOFS);
4924 + a->h_src_attr.valid = 0;
4926 + sb = cpg->dentry->d_sb;
4927 + br = au_sbr(sb, cpg->bdst);
4928 + a->h_path.mnt = au_br_mnt(br);
4929 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
4930 + h_parent = h_dst->d_parent; /* dir inode is locked */
4931 + h_dir = h_parent->d_inode;
4934 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
4935 + inode = cpg->dentry->d_inode;
4938 + dst_parent = dget_parent(cpg->dentry);
4942 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
4943 + dst_inode = au_h_iptr(inode, cpg->bdst);
4945 + if (unlikely(!plink)) {
4947 + AuIOErr("hi%lu(i%lu) exists on b%d "
4948 + "but plink is disabled\n",
4949 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
4953 + if (dst_inode->i_nlink) {
4954 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
4956 + h_src = au_plink_lkup(inode, cpg->bdst);
4957 + err = PTR_ERR(h_src);
4958 + if (IS_ERR(h_src))
4960 + if (unlikely(!h_src->d_inode)) {
4962 + AuIOErr("i%lu exists on a upper branch "
4963 + "but not pseudo-linked\n",
4970 + a->h_path.dentry = h_parent;
4971 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
4974 + a->h_path.dentry = h_dst;
4976 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
4977 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
4978 + err = au_do_ren_after_cpup(cpg, &a->h_path);
4980 + au_dtime_revert(&a->dt);
4981 + if (unlikely(err == -EWOULDBLOCK)) {
4982 + pr_warn("cannot retry for NFSv4 delegation"
4983 + " for an internal link\n");
4989 + /* todo: cpup_wh_file? */
4991 + au_update_ibrange(inode, /*do_put_zero*/1);
4994 + isdir = S_ISDIR(inode->i_mode);
4995 + old_ibstart = au_ibstart(inode);
4996 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
4997 + if (unlikely(err))
4999 + dst_inode = h_dst->d_inode;
5000 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
5001 + /* todo: necessary? */
5002 + /* au_pin_hdir_unlock(cpg->pin); */
5004 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5005 + if (unlikely(err)) {
5006 + /* todo: necessary? */
5007 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5008 + mutex_unlock(&dst_inode->i_mutex);
5012 + if (cpg->bdst < old_ibstart) {
5013 + if (S_ISREG(inode->i_mode)) {
5014 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5015 + if (unlikely(err)) {
5016 + /* ignore an error */
5017 + /* au_pin_hdir_relock(cpg->pin); */
5018 + mutex_unlock(&dst_inode->i_mutex);
5022 + au_set_ibstart(inode, cpg->bdst);
5024 + au_set_ibend(inode, cpg->bdst);
5025 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5026 + au_hi_flags(inode, isdir));
5028 + /* todo: necessary? */
5029 + /* err = au_pin_hdir_relock(cpg->pin); */
5030 + mutex_unlock(&dst_inode->i_mutex);
5031 + if (unlikely(err))
5035 + && (h_src->d_inode->i_nlink > 1
5036 + || h_src->d_inode->i_state & I_LINKABLE)
5038 + au_plink_append(inode, cpg->bdst, h_dst);
5040 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5041 + a->h_path.dentry = h_dst;
5042 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5045 + goto out_parent; /* success */
5049 + a->h_path.dentry = h_parent;
5050 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5051 + a->h_path.dentry = h_dst;
5053 + if (h_dst->d_inode) {
5055 + /* no delegation since it is just created */
5056 + rerr = vfsub_unlink(h_dir, &a->h_path,
5057 + /*delegated*/NULL, /*force*/0);
5059 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5061 + au_dtime_revert(&a->dt);
5063 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5074 +struct au_cpup_single_args {
5076 + struct au_cp_generic *cpg;
5077 + struct dentry *dst_parent;
5080 +static void au_call_cpup_single(void *args)
5082 + struct au_cpup_single_args *a = args;
5084 + au_pin_hdir_acquire_nest(a->cpg->pin);
5085 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5086 + au_pin_hdir_release(a->cpg->pin);
5091 + * prevent SIGXFSZ in copy-up.
5092 + * testing CAP_MKNOD is for generic fs,
5093 + * but CAP_FSETID is for xfs only, currently.
5095 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5098 + struct super_block *sb;
5099 + struct inode *h_dir;
5102 + sb = au_pinned_parent(pin)->d_sb;
5103 + if (!au_wkq_test()
5104 + && (!au_sbi(sb)->si_plink_maint_pid
5105 + || au_plink_maint(sb, AuLock_NOPLM))) {
5106 + switch (mode & S_IFMT) {
5108 + /* no condition about RLIMIT_FSIZE and the file size */
5113 + do_sio = !capable(CAP_MKNOD);
5117 + do_sio = ((mode & (S_ISUID | S_ISGID))
5118 + && !capable(CAP_FSETID));
5119 + /* this workaround may be removed in the future */
5121 + h_dir = au_pinned_h_dir(pin);
5122 + do_sio = h_dir->i_mode & S_ISVTX;
5130 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5133 + struct dentry *h_dentry;
5135 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5136 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
5137 + err = au_cpup_single(cpg, dst_parent);
5139 + struct au_cpup_single_args args = {
5142 + .dst_parent = dst_parent
5144 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5145 + if (unlikely(wkq_err))
5154 + * copyup the @dentry from the first active lower branch to @bdst,
5155 + * using au_cpup_single().
5157 +static int au_cpup_simple(struct au_cp_generic *cpg)
5160 + unsigned int flags_orig;
5161 + struct dentry *dentry;
5163 + AuDebugOn(cpg->bsrc < 0);
5165 + dentry = cpg->dentry;
5166 + DiMustWriteLock(dentry);
5168 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5170 + flags_orig = cpg->flags;
5171 + au_fset_cpup(cpg->flags, RENAME);
5172 + err = au_cpup_single(cpg, NULL);
5173 + cpg->flags = flags_orig;
5175 + return 0; /* success */
5178 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5179 + au_set_dbstart(dentry, cpg->bsrc);
5185 +struct au_cpup_simple_args {
5187 + struct au_cp_generic *cpg;
5190 +static void au_call_cpup_simple(void *args)
5192 + struct au_cpup_simple_args *a = args;
5194 + au_pin_hdir_acquire_nest(a->cpg->pin);
5195 + *a->errp = au_cpup_simple(a->cpg);
5196 + au_pin_hdir_release(a->cpg->pin);
5199 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5202 + struct dentry *dentry, *parent;
5203 + struct file *h_file;
5204 + struct inode *h_dir;
5206 + dentry = cpg->dentry;
5208 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5209 + AuDebugOn(cpg->bsrc < 0);
5210 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5211 + err = PTR_ERR(h_file);
5212 + if (IS_ERR(h_file))
5216 + parent = dget_parent(dentry);
5217 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
5218 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5219 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5220 + err = au_cpup_simple(cpg);
5222 + struct au_cpup_simple_args args = {
5226 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5227 + if (unlikely(wkq_err))
5233 + au_h_open_post(dentry, cpg->bsrc, h_file);
5239 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5241 + aufs_bindex_t bsrc, bend;
5242 + struct dentry *dentry, *h_dentry;
5244 + if (cpg->bsrc < 0) {
5245 + dentry = cpg->dentry;
5246 + bend = au_dbend(dentry);
5247 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5248 + h_dentry = au_h_dptr(dentry, bsrc);
5250 + AuDebugOn(!h_dentry->d_inode);
5254 + AuDebugOn(bsrc > bend);
5257 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5258 + return au_do_sio_cpup_simple(cpg);
5261 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5263 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5264 + return au_do_sio_cpup_simple(cpg);
5267 +/* ---------------------------------------------------------------------- */
5270 + * copyup the deleted file for writing.
5272 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5273 + struct file *file)
5276 + unsigned int flags_orig;
5277 + aufs_bindex_t bsrc_orig;
5278 + struct dentry *h_d_dst, *h_d_start;
5279 + struct au_dinfo *dinfo;
5280 + struct au_hdentry *hdp;
5282 + dinfo = au_di(cpg->dentry);
5283 + AuRwMustWriteLock(&dinfo->di_rwsem);
5285 + bsrc_orig = cpg->bsrc;
5286 + cpg->bsrc = dinfo->di_bstart;
5287 + hdp = dinfo->di_hdentry;
5288 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5289 + dinfo->di_bstart = cpg->bdst;
5290 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5293 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5294 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_dentry;
5296 + flags_orig = cpg->flags;
5297 + cpg->flags = !AuCpup_DTIME;
5298 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5299 + cpg->flags = flags_orig;
5302 + err = au_reopen_nondir(file);
5303 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5305 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5306 + dinfo->di_bstart = cpg->bsrc;
5307 + cpg->bsrc = bsrc_orig;
5312 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5315 + aufs_bindex_t bdst;
5316 + struct au_dtime dt;
5317 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5318 + struct au_branch *br;
5319 + struct path h_path;
5321 + dentry = cpg->dentry;
5323 + br = au_sbr(dentry->d_sb, bdst);
5324 + parent = dget_parent(dentry);
5325 + h_parent = au_h_dptr(parent, bdst);
5326 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5327 + err = PTR_ERR(wh_dentry);
5328 + if (IS_ERR(wh_dentry))
5331 + h_path.dentry = h_parent;
5332 + h_path.mnt = au_br_mnt(br);
5333 + au_dtime_store(&dt, parent, &h_path);
5334 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5335 + if (unlikely(err))
5339 + h_path.dentry = wh_dentry;
5340 + if (!S_ISDIR(wh_dentry->d_inode->i_mode)) {
5341 + /* no delegation since it is just created */
5342 + err = vfsub_unlink(h_parent->d_inode, &h_path,
5343 + /*delegated*/NULL, /*force*/0);
5345 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
5346 + if (unlikely(err)) {
5347 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5351 + au_dtime_revert(&dt);
5352 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
5361 +struct au_cpup_wh_args {
5363 + struct au_cp_generic *cpg;
5364 + struct file *file;
5367 +static void au_call_cpup_wh(void *args)
5369 + struct au_cpup_wh_args *a = args;
5371 + au_pin_hdir_acquire_nest(a->cpg->pin);
5372 + *a->errp = au_cpup_wh(a->cpg, a->file);
5373 + au_pin_hdir_release(a->cpg->pin);
5376 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5379 + aufs_bindex_t bdst;
5380 + struct dentry *dentry, *parent, *h_orph, *h_parent, *h_dentry;
5381 + struct inode *dir, *h_dir, *h_tmpdir;
5382 + struct au_wbr *wbr;
5383 + struct au_pin wh_pin, *pin_orig;
5385 + dentry = cpg->dentry;
5387 + parent = dget_parent(dentry);
5388 + dir = parent->d_inode;
5391 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5394 + if (!h_dir->i_nlink) {
5395 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5396 + h_orph = wbr->wbr_orph;
5398 + h_parent = dget(au_h_dptr(parent, bdst));
5399 + au_set_h_dptr(parent, bdst, dget(h_orph));
5400 + h_tmpdir = h_orph->d_inode;
5401 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5404 + h_dentry = au_hf_top(file)->f_dentry;
5406 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
5407 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
5408 + /* todo: au_h_open_pre()? */
5410 + pin_orig = cpg->pin;
5411 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5412 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5413 + cpg->pin = &wh_pin;
5416 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5417 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5418 + err = au_cpup_wh(cpg, file);
5420 + struct au_cpup_wh_args args = {
5425 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5426 + if (unlikely(wkq_err))
5431 + mutex_unlock(&h_tmpdir->i_mutex);
5432 + /* todo: au_h_open_post()? */
5433 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5434 + au_set_h_dptr(parent, bdst, h_parent);
5435 + AuDebugOn(!pin_orig);
5436 + cpg->pin = pin_orig;
5444 +/* ---------------------------------------------------------------------- */
5447 + * generic routine for both of copy-up and copy-down.
5449 +/* cf. revalidate function in file.c */
5450 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5451 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5452 + struct au_pin *pin,
5453 + struct dentry *h_parent, void *arg),
5457 + struct au_pin pin;
5458 + struct dentry *d, *parent, *h_parent, *real_parent;
5461 + parent = dget_parent(dentry);
5462 + if (IS_ROOT(parent))
5465 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5466 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5468 + /* do not use au_dpage */
5469 + real_parent = parent;
5472 + parent = dget_parent(dentry);
5473 + h_parent = au_h_dptr(parent, bdst);
5475 + goto out; /* success */
5477 + /* find top dir which is necessary to cpup */
5481 + parent = dget_parent(d);
5482 + di_read_lock_parent3(parent, !AuLock_IR);
5483 + h_parent = au_h_dptr(parent, bdst);
5484 + di_read_unlock(parent, !AuLock_IR);
5485 + } while (!h_parent);
5487 + if (d != real_parent)
5488 + di_write_lock_child3(d);
5490 + /* somebody else might create while we were sleeping */
5491 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
5492 + if (au_h_dptr(d, bdst))
5493 + au_update_dbstart(d);
5495 + au_pin_set_dentry(&pin, d);
5496 + err = au_do_pin(&pin);
5498 + err = cp(d, bdst, &pin, h_parent, arg);
5503 + if (d != real_parent)
5504 + di_write_unlock(d);
5505 + if (unlikely(err))
5514 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5515 + struct au_pin *pin,
5516 + struct dentry *h_parent __maybe_unused ,
5517 + void *arg __maybe_unused)
5519 + struct au_cp_generic cpg = {
5525 + .flags = AuCpup_DTIME
5527 + return au_sio_cpup_simple(&cpg);
5530 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5532 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5535 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5538 + struct dentry *parent;
5539 + struct inode *dir;
5541 + parent = dget_parent(dentry);
5542 + dir = parent->d_inode;
5544 + if (au_h_iptr(dir, bdst))
5547 + di_read_unlock(parent, AuLock_IR);
5548 + di_write_lock_parent(parent);
5549 + /* someone else might change our inode while we were sleeping */
5550 + if (!au_h_iptr(dir, bdst))
5551 + err = au_cpup_dirs(dentry, bdst);
5552 + di_downgrade_lock(parent, AuLock_IR);
5558 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5559 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5560 +++ linux/fs/aufs/cpup.h 2014-01-30 21:10:02.827480967 +0100
5563 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5565 + * This program, aufs is free software; you can redistribute it and/or modify
5566 + * it under the terms of the GNU General Public License as published by
5567 + * the Free Software Foundation; either version 2 of the License, or
5568 + * (at your option) any later version.
5570 + * This program is distributed in the hope that it will be useful,
5571 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5572 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5573 + * GNU General Public License for more details.
5575 + * You should have received a copy of the GNU General Public License
5576 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5580 + * copy-up/down functions
5583 +#ifndef __AUFS_CPUP_H__
5584 +#define __AUFS_CPUP_H__
5588 +#include <linux/path.h>
5594 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5595 +void au_cpup_attr_timesizes(struct inode *inode);
5596 +void au_cpup_attr_nlink(struct inode *inode, int force);
5597 +void au_cpup_attr_changeable(struct inode *inode);
5598 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5599 +void au_cpup_attr_all(struct inode *inode, int force);
5601 +/* ---------------------------------------------------------------------- */
5603 +struct au_cp_generic {
5604 + struct dentry *dentry;
5605 + aufs_bindex_t bdst, bsrc;
5607 + struct au_pin *pin;
5608 + unsigned int flags;
5612 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5613 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5615 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5616 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5618 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5620 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5621 + the branch is marked as RO */
5623 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5624 +#define au_fset_cpup(flags, name) \
5625 + do { (flags) |= AuCpup_##name; } while (0)
5626 +#define au_fclr_cpup(flags, name) \
5627 + do { (flags) &= ~AuCpup_##name; } while (0)
5629 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5630 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5631 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5632 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5634 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5635 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5636 + struct au_pin *pin,
5637 + struct dentry *h_parent, void *arg),
5639 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5640 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5642 +/* ---------------------------------------------------------------------- */
5644 +/* keep timestamps when copyup */
5646 + struct dentry *dt_dentry;
5647 + struct path dt_h_path;
5648 + struct timespec dt_atime, dt_mtime;
5650 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5651 + struct path *h_path);
5652 +void au_dtime_revert(struct au_dtime *dt);
5654 +#endif /* __KERNEL__ */
5655 +#endif /* __AUFS_CPUP_H__ */
5656 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5657 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5658 +++ linux/fs/aufs/dbgaufs.c 2014-01-30 21:10:02.827480967 +0100
5661 + * Copyright (C) 2005-2014 Junjiro R. Okajima
5663 + * This program, aufs is free software; you can redistribute it and/or modify
5664 + * it under the terms of the GNU General Public License as published by
5665 + * the Free Software Foundation; either version 2 of the License, or
5666 + * (at your option) any later version.
5668 + * This program is distributed in the hope that it will be useful,
5669 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5670 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5671 + * GNU General Public License for more details.
5673 + * You should have received a copy of the GNU General Public License
5674 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5678 + * debugfs interface
5681 +#include <linux/debugfs.h>
5684 +#ifndef CONFIG_SYSFS
5685 +#error DEBUG_FS depends upon SYSFS
5688 +static struct dentry *dbgaufs;
5689 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5691 +/* 20 is max digits length of ulong 64 */
5692 +struct dbgaufs_arg {
5698 + * common function for all XINO files
5700 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5701 + struct file *file)
5703 + kfree(file->private_data);
5707 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5711 + struct dbgaufs_arg *p;
5714 + p = kmalloc(sizeof(*p), GFP_NOFS);
5720 + file->private_data = p;
5724 + err = vfs_getattr(&xf->f_path, &st);
5728 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
5729 + (long)file_count(xf), st.blocks, st.blksize,
5730 + (long long)st.size);
5732 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
5733 + st.blocks, st.blksize,
5734 + (long long)st.size);
5735 + AuDebugOn(p->n >= sizeof(p->a));
5737 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
5746 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
5747 + size_t count, loff_t *ppos)
5749 + struct dbgaufs_arg *p;
5751 + p = file->private_data;
5752 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5755 +/* ---------------------------------------------------------------------- */
5757 +struct dbgaufs_plink_arg {
5762 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
5763 + struct file *file)
5765 + free_page((unsigned long)file->private_data);
5769 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
5771 + int err, i, limit;
5772 + unsigned long n, sum;
5773 + struct dbgaufs_plink_arg *p;
5774 + struct au_sbinfo *sbinfo;
5775 + struct super_block *sb;
5776 + struct au_sphlhead *sphl;
5779 + p = (void *)get_zeroed_page(GFP_NOFS);
5784 + sbinfo = inode->i_private;
5785 + sb = sbinfo->si_sb;
5786 + si_noflush_read_lock(sb);
5787 + if (au_opt_test(au_mntflags(sb), PLINK)) {
5788 + limit = PAGE_SIZE - sizeof(p->n);
5790 + /* the number of buckets */
5791 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
5796 + for (i = 0, sphl = sbinfo->si_plink;
5797 + i < AuPlink_NHASH;
5799 + n = au_sphl_count(sphl);
5802 + n = snprintf(p->a + p->n, limit, "%lu ", n);
5805 + if (unlikely(limit <= 0))
5808 + p->a[p->n - 1] = '\n';
5810 + /* the sum of plinks */
5811 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
5814 + if (unlikely(limit <= 0))
5817 +#define str "1\n0\n0\n"
5818 + p->n = sizeof(str) - 1;
5819 + strcpy(p->a, str);
5822 + si_read_unlock(sb);
5825 + file->private_data = p;
5826 + goto out; /* success */
5829 + free_page((unsigned long)p);
5834 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
5835 + size_t count, loff_t *ppos)
5837 + struct dbgaufs_plink_arg *p;
5839 + p = file->private_data;
5840 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
5843 +static const struct file_operations dbgaufs_plink_fop = {
5844 + .owner = THIS_MODULE,
5845 + .open = dbgaufs_plink_open,
5846 + .release = dbgaufs_plink_release,
5847 + .read = dbgaufs_plink_read
5850 +/* ---------------------------------------------------------------------- */
5852 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
5855 + struct au_sbinfo *sbinfo;
5856 + struct super_block *sb;
5858 + sbinfo = inode->i_private;
5859 + sb = sbinfo->si_sb;
5860 + si_noflush_read_lock(sb);
5861 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
5862 + si_read_unlock(sb);
5866 +static const struct file_operations dbgaufs_xib_fop = {
5867 + .owner = THIS_MODULE,
5868 + .open = dbgaufs_xib_open,
5869 + .release = dbgaufs_xi_release,
5870 + .read = dbgaufs_xi_read
5873 +/* ---------------------------------------------------------------------- */
5875 +#define DbgaufsXi_PREFIX "xi"
5877 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
5881 + struct au_sbinfo *sbinfo;
5882 + struct super_block *sb;
5884 + struct qstr *name;
5888 + name = &file->f_dentry->d_name;
5889 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
5890 + || memcmp(name->name, DbgaufsXi_PREFIX,
5891 + sizeof(DbgaufsXi_PREFIX) - 1)))
5893 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
5894 + if (unlikely(err))
5897 + sbinfo = inode->i_private;
5898 + sb = sbinfo->si_sb;
5899 + si_noflush_read_lock(sb);
5900 + if (l <= au_sbend(sb)) {
5901 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
5902 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
5905 + si_read_unlock(sb);
5911 +static const struct file_operations dbgaufs_xino_fop = {
5912 + .owner = THIS_MODULE,
5913 + .open = dbgaufs_xino_open,
5914 + .release = dbgaufs_xi_release,
5915 + .read = dbgaufs_xi_read
5918 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
5920 + aufs_bindex_t bend;
5921 + struct au_branch *br;
5922 + struct au_xino_file *xi;
5924 + if (!au_sbi(sb)->si_dbgaufs)
5927 + bend = au_sbend(sb);
5928 + for (; bindex <= bend; bindex++) {
5929 + br = au_sbr(sb, bindex);
5930 + xi = &br->br_xino;
5931 + debugfs_remove(xi->xi_dbgaufs);
5932 + xi->xi_dbgaufs = NULL;
5936 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
5938 + struct au_sbinfo *sbinfo;
5939 + struct dentry *parent;
5940 + struct au_branch *br;
5941 + struct au_xino_file *xi;
5942 + aufs_bindex_t bend;
5943 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
5945 + sbinfo = au_sbi(sb);
5946 + parent = sbinfo->si_dbgaufs;
5950 + bend = au_sbend(sb);
5951 + for (; bindex <= bend; bindex++) {
5952 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
5953 + br = au_sbr(sb, bindex);
5954 + xi = &br->br_xino;
5955 + AuDebugOn(xi->xi_dbgaufs);
5956 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
5957 + sbinfo, &dbgaufs_xino_fop);
5958 + /* ignore an error */
5959 + if (unlikely(!xi->xi_dbgaufs))
5960 + AuWarn1("failed %s under debugfs\n", name);
5964 +/* ---------------------------------------------------------------------- */
5966 +#ifdef CONFIG_AUFS_EXPORT
5967 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
5970 + struct au_sbinfo *sbinfo;
5971 + struct super_block *sb;
5973 + sbinfo = inode->i_private;
5974 + sb = sbinfo->si_sb;
5975 + si_noflush_read_lock(sb);
5976 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
5977 + si_read_unlock(sb);
5981 +static const struct file_operations dbgaufs_xigen_fop = {
5982 + .owner = THIS_MODULE,
5983 + .open = dbgaufs_xigen_open,
5984 + .release = dbgaufs_xi_release,
5985 + .read = dbgaufs_xi_read
5988 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
5993 + * This function is a dynamic '__init' fucntion actually,
5994 + * so the tiny check for si_rwsem is unnecessary.
5996 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
5999 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6000 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6001 + &dbgaufs_xigen_fop);
6002 + if (sbinfo->si_dbgaufs_xigen)
6008 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6012 +#endif /* CONFIG_AUFS_EXPORT */
6014 +/* ---------------------------------------------------------------------- */
6016 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6019 + * This function is a dynamic '__init' fucntion actually,
6020 + * so the tiny check for si_rwsem is unnecessary.
6022 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6024 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6025 + sbinfo->si_dbgaufs = NULL;
6026 + kobject_put(&sbinfo->si_kobj);
6029 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6032 + char name[SysaufsSiNameLen];
6035 + * This function is a dynamic '__init' fucntion actually,
6036 + * so the tiny check for si_rwsem is unnecessary.
6038 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6042 + AuErr1("/debug/aufs is uninitialized\n");
6047 + sysaufs_name(sbinfo, name);
6048 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6049 + if (unlikely(!sbinfo->si_dbgaufs))
6051 + kobject_get(&sbinfo->si_kobj);
6053 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6054 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6055 + &dbgaufs_xib_fop);
6056 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6059 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6060 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6061 + &dbgaufs_plink_fop);
6062 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6065 + err = dbgaufs_xigen_init(sbinfo);
6067 + goto out; /* success */
6070 + dbgaufs_si_fin(sbinfo);
6075 +/* ---------------------------------------------------------------------- */
6077 +void dbgaufs_fin(void)
6079 + debugfs_remove(dbgaufs);
6082 +int __init dbgaufs_init(void)
6087 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6092 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6093 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6094 +++ linux/fs/aufs/dbgaufs.h 2014-01-30 21:10:02.827480967 +0100
6097 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6099 + * This program, aufs is free software; you can redistribute it and/or modify
6100 + * it under the terms of the GNU General Public License as published by
6101 + * the Free Software Foundation; either version 2 of the License, or
6102 + * (at your option) any later version.
6104 + * This program is distributed in the hope that it will be useful,
6105 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6106 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6107 + * GNU General Public License for more details.
6109 + * You should have received a copy of the GNU General Public License
6110 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6114 + * debugfs interface
6117 +#ifndef __DBGAUFS_H__
6118 +#define __DBGAUFS_H__
6122 +struct super_block;
6125 +#ifdef CONFIG_DEBUG_FS
6127 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6128 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6129 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6130 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6131 +void dbgaufs_fin(void);
6132 +int __init dbgaufs_init(void);
6134 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6135 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6136 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6137 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6138 +AuStubVoid(dbgaufs_fin, void)
6139 +AuStubInt0(__init dbgaufs_init, void)
6140 +#endif /* CONFIG_DEBUG_FS */
6142 +#endif /* __KERNEL__ */
6143 +#endif /* __DBGAUFS_H__ */
6144 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6145 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6146 +++ linux/fs/aufs/dcsub.c 2014-01-30 21:10:02.827480967 +0100
6149 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6151 + * This program, aufs is free software; you can redistribute it and/or modify
6152 + * it under the terms of the GNU General Public License as published by
6153 + * the Free Software Foundation; either version 2 of the License, or
6154 + * (at your option) any later version.
6156 + * This program is distributed in the hope that it will be useful,
6157 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6158 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6159 + * GNU General Public License for more details.
6161 + * You should have received a copy of the GNU General Public License
6162 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6166 + * sub-routines for dentry cache
6171 +static void au_dpage_free(struct au_dpage *dpage)
6174 + struct dentry **p;
6176 + p = dpage->dentries;
6177 + for (i = 0; i < dpage->ndentry; i++)
6179 + free_page((unsigned long)dpage->dentries);
6182 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6188 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6189 + if (unlikely(!dpages->dpages))
6192 + p = (void *)__get_free_page(gfp);
6196 + dpages->dpages[0].ndentry = 0;
6197 + dpages->dpages[0].dentries = p;
6198 + dpages->ndpage = 1;
6199 + return 0; /* success */
6202 + kfree(dpages->dpages);
6207 +void au_dpages_free(struct au_dcsub_pages *dpages)
6210 + struct au_dpage *p;
6212 + p = dpages->dpages;
6213 + for (i = 0; i < dpages->ndpage; i++)
6214 + au_dpage_free(p++);
6215 + kfree(dpages->dpages);
6218 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6219 + struct dentry *dentry, gfp_t gfp)
6222 + struct au_dpage *dpage;
6225 + dpage = dpages->dpages + dpages->ndpage - 1;
6226 + sz = PAGE_SIZE / sizeof(dentry);
6227 + if (unlikely(dpage->ndentry >= sz)) {
6228 + AuLabel(new dpage);
6230 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6231 + p = au_kzrealloc(dpages->dpages, sz,
6232 + sz + sizeof(*dpages->dpages), gfp);
6236 + dpages->dpages = p;
6237 + dpage = dpages->dpages + dpages->ndpage;
6238 + p = (void *)__get_free_page(gfp);
6242 + dpage->ndentry = 0;
6243 + dpage->dentries = p;
6247 + AuDebugOn(!d_count(dentry));
6248 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6249 + return 0; /* success */
6255 +/* try d_walk() in linux/fs/dcache.c */
6256 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6257 + au_dpages_test test, void *arg)
6260 + struct dentry *this_parent;
6261 + struct list_head *next;
6262 + struct super_block *sb = root->d_sb;
6265 + write_seqlock(&rename_lock);
6266 + this_parent = root;
6267 + spin_lock(&this_parent->d_lock);
6269 + next = this_parent->d_subdirs.next;
6271 + if (this_parent->d_sb == sb
6272 + && !IS_ROOT(this_parent)
6273 + && au_di(this_parent)
6274 + && d_count(this_parent)
6275 + && (!test || test(this_parent, arg))) {
6276 + err = au_dpages_append(dpages, this_parent, GFP_ATOMIC);
6277 + if (unlikely(err))
6281 + while (next != &this_parent->d_subdirs) {
6282 + struct list_head *tmp = next;
6283 + struct dentry *dentry = list_entry(tmp, struct dentry,
6287 + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED);
6288 + if (d_count(dentry)) {
6289 + if (!list_empty(&dentry->d_subdirs)) {
6290 + spin_unlock(&this_parent->d_lock);
6291 + spin_release(&dentry->d_lock.dep_map, 1,
6293 + this_parent = dentry;
6294 + spin_acquire(&this_parent->d_lock.dep_map, 0, 1,
6298 + if (dentry->d_sb == sb
6300 + && (!test || test(dentry, arg)))
6301 + err = au_dpages_append(dpages, dentry,
6304 + spin_unlock(&dentry->d_lock);
6305 + if (unlikely(err))
6309 + if (this_parent != root) {
6310 + struct dentry *tmp;
6311 + struct dentry *child;
6313 + tmp = this_parent->d_parent;
6315 + spin_unlock(&this_parent->d_lock);
6316 + child = this_parent;
6317 + this_parent = tmp;
6318 + spin_lock(&this_parent->d_lock);
6319 + rcu_read_unlock();
6320 + next = child->d_u.d_child.next;
6325 + spin_unlock(&this_parent->d_lock);
6326 + write_sequnlock(&rename_lock);
6330 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6331 + int do_include, au_dpages_test test, void *arg)
6336 + write_seqlock(&rename_lock);
6337 + spin_lock(&dentry->d_lock);
6339 + && d_count(dentry)
6340 + && (!test || test(dentry, arg)))
6341 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6342 + spin_unlock(&dentry->d_lock);
6343 + if (unlikely(err))
6347 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6350 + while (!IS_ROOT(dentry)) {
6351 + dentry = dentry->d_parent; /* rename_lock is locked */
6352 + spin_lock(&dentry->d_lock);
6353 + if (d_count(dentry)
6354 + && (!test || test(dentry, arg)))
6355 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6356 + spin_unlock(&dentry->d_lock);
6357 + if (unlikely(err))
6362 + write_sequnlock(&rename_lock);
6366 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6368 + return au_di(dentry) && dentry->d_sb == arg;
6371 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6372 + struct dentry *dentry, int do_include)
6374 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6375 + au_dcsub_dpages_aufs, dentry->d_sb);
6378 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6380 + struct path path[2] = {
6389 + return path_is_under(path + 0, path + 1);
6391 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6392 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6393 +++ linux/fs/aufs/dcsub.h 2014-08-14 10:15:45.118609182 +0200
6396 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6398 + * This program, aufs is free software; you can redistribute it and/or modify
6399 + * it under the terms of the GNU General Public License as published by
6400 + * the Free Software Foundation; either version 2 of the License, or
6401 + * (at your option) any later version.
6403 + * This program is distributed in the hope that it will be useful,
6404 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6405 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6406 + * GNU General Public License for more details.
6408 + * You should have received a copy of the GNU General Public License
6409 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6413 + * sub-routines for dentry cache
6416 +#ifndef __AUFS_DCSUB_H__
6417 +#define __AUFS_DCSUB_H__
6421 +#include <linux/dcache.h>
6422 +#include <linux/fs.h>
6428 + struct dentry **dentries;
6431 +struct au_dcsub_pages {
6433 + struct au_dpage *dpages;
6436 +/* ---------------------------------------------------------------------- */
6439 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6440 +void au_dpages_free(struct au_dcsub_pages *dpages);
6441 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6442 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6443 + au_dpages_test test, void *arg);
6444 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6445 + int do_include, au_dpages_test test, void *arg);
6446 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6447 + struct dentry *dentry, int do_include);
6448 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6450 +/* ---------------------------------------------------------------------- */
6453 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6454 + * include/linux/dcache.h. Try them (in the future).
6457 +static inline int au_d_hashed_positive(struct dentry *d)
6460 + struct inode *inode = d->d_inode;
6463 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
6468 +static inline int au_d_linkable(struct dentry *d)
6471 + struct inode *inode = d->d_inode;
6473 + err = au_d_hashed_positive(d);
6476 + && (inode->i_state & I_LINKABLE))
6481 +static inline int au_d_alive(struct dentry *d)
6484 + struct inode *inode;
6488 + err = au_d_hashed_positive(d);
6490 + inode = d->d_inode;
6491 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
6497 +static inline int au_alive_dir(struct dentry *d)
6501 + err = au_d_alive(d);
6502 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
6507 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6509 + return a->len == b->len
6510 + && !memcmp(a->name, b->name, a->len);
6513 +#endif /* __KERNEL__ */
6514 +#endif /* __AUFS_DCSUB_H__ */
6515 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6516 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6517 +++ linux/fs/aufs/debug.c 2014-08-14 10:15:45.121942630 +0200
6520 + * Copyright (C) 2005-2014 Junjiro R. Okajima
6522 + * This program, aufs is free software; you can redistribute it and/or modify
6523 + * it under the terms of the GNU General Public License as published by
6524 + * the Free Software Foundation; either version 2 of the License, or
6525 + * (at your option) any later version.
6527 + * This program is distributed in the hope that it will be useful,
6528 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6529 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6530 + * GNU General Public License for more details.
6532 + * You should have received a copy of the GNU General Public License
6533 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6537 + * debug print functions
6540 +#include <linux/vt_kern.h>
6543 +/* Returns 0, or -errno. arg is in kp->arg. */
6544 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6548 + err = kstrtoint(val, 0, &n);
6558 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6559 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6564 + return sprintf(buffer, "%d", atomic_read(a));
6567 +static struct kernel_param_ops param_ops_atomic_t = {
6568 + .set = param_atomic_t_set,
6569 + .get = param_atomic_t_get
6570 + /* void (*free)(void *arg) */
6573 +atomic_t aufs_debug = ATOMIC_INIT(0);
6574 +MODULE_PARM_DESC(debug, "debug print");
6575 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6577 +char *au_plevel = KERN_DEBUG;
6578 +#define dpri(fmt, ...) do { \
6580 + && strcmp(au_plevel, KERN_DEBUG)) \
6581 + || au_debug_test()) \
6582 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6585 +/* ---------------------------------------------------------------------- */
6587 +void au_dpri_whlist(struct au_nhash *whlist)
6589 + unsigned long ul, n;
6590 + struct hlist_head *head;
6591 + struct au_vdir_wh *pos;
6593 + n = whlist->nh_num;
6594 + head = whlist->nh_head;
6595 + for (ul = 0; ul < n; ul++) {
6596 + hlist_for_each_entry(pos, head, wh_hash)
6597 + dpri("b%d, %.*s, %d\n",
6599 + pos->wh_str.len, pos->wh_str.name,
6605 +void au_dpri_vdir(struct au_vdir *vdir)
6608 + union au_vdir_deblk_p p;
6611 + if (!vdir || IS_ERR(vdir)) {
6612 + dpri("err %ld\n", PTR_ERR(vdir));
6616 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6617 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6618 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6619 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6620 + p.deblk = vdir->vd_deblk[ul];
6622 + dpri("[%lu]: %p\n", ul, o);
6626 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6627 + struct dentry *wh)
6632 + if (!inode || IS_ERR(inode)) {
6633 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6637 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6638 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6639 + && sizeof(inode->i_blocks) != sizeof(u64));
6641 + n = (void *)wh->d_name.name;
6642 + l = wh->d_name.len;
6645 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6646 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6648 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6649 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6650 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6651 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6652 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6653 + inode->i_state, inode->i_flags, inode->i_version,
6654 + inode->i_generation,
6655 + l ? ", wh " : "", l, n);
6659 +void au_dpri_inode(struct inode *inode)
6661 + struct au_iinfo *iinfo;
6662 + aufs_bindex_t bindex;
6665 + err = do_pri_inode(-1, inode, -1, NULL);
6666 + if (err || !au_test_aufs(inode->i_sb))
6669 + iinfo = au_ii(inode);
6672 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6673 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6674 + if (iinfo->ii_bstart < 0)
6677 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6678 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6679 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6680 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6684 +void au_dpri_dalias(struct inode *inode)
6688 + spin_lock(&inode->i_lock);
6689 + hlist_for_each_entry(d, &inode->i_dentry, d_alias)
6690 + au_dpri_dentry(d);
6691 + spin_unlock(&inode->i_lock);
6694 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6696 + struct dentry *wh = NULL;
6698 + struct au_iinfo *iinfo;
6700 + if (!dentry || IS_ERR(dentry)) {
6701 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6704 + /* do not call dget_parent() here */
6705 + /* note: access d_xxx without d_lock */
6706 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6707 + bindex, dentry, dentry,
6708 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6709 + d_count(dentry), dentry->d_flags,
6710 + d_unhashed(dentry) ? "un" : "");
6712 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
6713 + iinfo = au_ii(dentry->d_inode);
6715 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6716 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
6719 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
6723 +void au_dpri_dentry(struct dentry *dentry)
6725 + struct au_dinfo *dinfo;
6726 + aufs_bindex_t bindex;
6728 + struct au_hdentry *hdp;
6730 + err = do_pri_dentry(-1, dentry);
6731 + if (err || !au_test_aufs(dentry->d_sb))
6734 + dinfo = au_di(dentry);
6737 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
6738 + dinfo->di_bstart, dinfo->di_bend,
6739 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
6740 + dinfo->di_tmpfile);
6741 + if (dinfo->di_bstart < 0)
6743 + hdp = dinfo->di_hdentry;
6744 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
6745 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
6748 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
6752 + if (!file || IS_ERR(file)) {
6753 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
6759 + && au_test_aufs(file->f_dentry->d_sb)
6761 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
6762 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
6763 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
6764 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
6765 + file->f_version, file->f_pos, a);
6766 + if (file->f_dentry)
6767 + do_pri_dentry(bindex, file->f_dentry);
6771 +void au_dpri_file(struct file *file)
6773 + struct au_finfo *finfo;
6774 + struct au_fidir *fidir;
6775 + struct au_hfile *hfile;
6776 + aufs_bindex_t bindex;
6779 + err = do_pri_file(-1, file);
6780 + if (err || !file->f_dentry || !au_test_aufs(file->f_dentry->d_sb))
6783 + finfo = au_fi(file);
6786 + if (finfo->fi_btop < 0)
6788 + fidir = finfo->fi_hdir;
6790 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
6792 + for (bindex = finfo->fi_btop;
6793 + bindex >= 0 && bindex <= fidir->fd_bbot;
6795 + hfile = fidir->fd_hfile + bindex;
6796 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
6800 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
6802 + struct vfsmount *mnt;
6803 + struct super_block *sb;
6805 + if (!br || IS_ERR(br))
6807 + mnt = au_br_mnt(br);
6808 + if (!mnt || IS_ERR(mnt))
6811 + if (!sb || IS_ERR(sb))
6814 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
6815 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
6817 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
6818 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
6819 + sb->s_flags, sb->s_count,
6820 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
6824 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
6828 +void au_dpri_sb(struct super_block *sb)
6830 + struct au_sbinfo *sbinfo;
6831 + aufs_bindex_t bindex;
6833 + /* to reuduce stack size */
6835 + struct vfsmount mnt;
6836 + struct au_branch fake;
6839 + /* this function can be called from magic sysrq */
6840 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
6841 + if (unlikely(!a)) {
6842 + dpri("no memory\n");
6846 + a->mnt.mnt_sb = sb;
6847 + a->fake.br_perm = 0;
6848 + a->fake.br_path.mnt = &a->mnt;
6849 + a->fake.br_xino.xi_file = NULL;
6850 + atomic_set(&a->fake.br_count, 0);
6851 + smp_mb(); /* atomic_set */
6852 + err = do_pri_br(-1, &a->fake);
6854 + dpri("dev 0x%x\n", sb->s_dev);
6855 + if (err || !au_test_aufs(sb))
6858 + sbinfo = au_sbi(sb);
6861 + dpri("nw %d, gen %u, kobj %d\n",
6862 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
6863 + atomic_read(&sbinfo->si_kobj.kref.refcount));
6864 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
6865 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
6868 +/* ---------------------------------------------------------------------- */
6870 +void au_dbg_sleep_jiffy(int jiffy)
6873 + jiffy = schedule_timeout_uninterruptible(jiffy);
6876 +void au_dbg_iattr(struct iattr *ia)
6878 +#define AuBit(name) \
6880 + if (ia->ia_valid & ATTR_ ## name) \
6881 + dpri(#name "\n"); \
6901 + dpri("ia_file %p\n", ia->ia_file);
6904 +/* ---------------------------------------------------------------------- */
6906 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
6908 + struct inode *h_inode, *inode = dentry->d_inode;
6909 + struct dentry *h_dentry;
6910 + aufs_bindex_t bindex, bend, bi;
6912 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
6915 + bend = au_dbend(dentry);
6916 + bi = au_ibend(inode);
6919 + bindex = au_dbstart(dentry);
6920 + bi = au_ibstart(inode);
6924 + for (; bindex <= bend; bindex++) {
6925 + h_dentry = au_h_dptr(dentry, bindex);
6928 + h_inode = au_h_iptr(inode, bindex);
6929 + if (unlikely(h_inode != h_dentry->d_inode)) {
6931 + AuDbg("b%d, %s:%d\n", bindex, func, line);
6932 + AuDbgDentry(dentry);
6933 + AuDbgInode(inode);
6940 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen)
6942 + struct dentry *parent;
6944 + parent = dget_parent(dentry);
6945 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
6946 + AuDebugOn(IS_ROOT(dentry));
6947 + AuDebugOn(au_digen_test(parent, sigen));
6951 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen)
6953 + struct dentry *parent;
6954 + struct inode *inode;
6956 + parent = dget_parent(dentry);
6957 + inode = dentry->d_inode;
6958 + AuDebugOn(inode && S_ISDIR(dentry->d_inode->i_mode));
6959 + AuDebugOn(au_digen_test(parent, sigen));
6963 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
6966 + struct au_dcsub_pages dpages;
6967 + struct au_dpage *dpage;
6968 + struct dentry **dentries;
6970 + err = au_dpages_init(&dpages, GFP_NOFS);
6972 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
6974 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
6975 + dpage = dpages.dpages + i;
6976 + dentries = dpage->dentries;
6977 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
6978 + AuDebugOn(au_digen_test(dentries[j], sigen));
6980 + au_dpages_free(&dpages);
6983 +void au_dbg_verify_kthread(void)
6985 + if (au_wkq_test()) {
6988 + * It may be recursive, but udba=notify between two aufs mounts,
6989 + * where a single ro branch is shared, is not a problem.
6995 +/* ---------------------------------------------------------------------- */
6997 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo __maybe_unused)
6999 +#ifdef AuForceNoPlink
7000 + au_opt_clr(sbinfo->si_mntflags, PLINK);
7002 +#ifdef AuForceNoXino
7003 + au_opt_clr(sbinfo->si_mntflags, XINO);
7005 +#ifdef AuForceNoRefrof
7006 + au_opt_clr(sbinfo->si_mntflags, REFROF);
7008 +#ifdef AuForceHnotify
7009 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_HNOTIFY);
7012 + sbinfo->si_rdblk = 0;
7013 + sbinfo->si_rdhash = 0;
7017 +int __init au_debug_init(void)
7019 + aufs_bindex_t bindex;
7020 + struct au_vdir_destr destr;
7023 + AuDebugOn(bindex >= 0);
7026 + AuDebugOn(destr.len < NAME_MAX);
7028 +#ifdef CONFIG_4KSTACKS
7029 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7032 +#ifdef AuForceNoBrs
7038 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7039 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7040 +++ linux/fs/aufs/debug.h 2014-01-30 21:10:02.827480967 +0100
7043 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7045 + * This program, aufs is free software; you can redistribute it and/or modify
7046 + * it under the terms of the GNU General Public License as published by
7047 + * the Free Software Foundation; either version 2 of the License, or
7048 + * (at your option) any later version.
7050 + * This program is distributed in the hope that it will be useful,
7051 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7052 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7053 + * GNU General Public License for more details.
7055 + * You should have received a copy of the GNU General Public License
7056 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7060 + * debug print functions
7063 +#ifndef __AUFS_DEBUG_H__
7064 +#define __AUFS_DEBUG_H__
7068 +#include <linux/atomic.h>
7069 +#include <linux/module.h>
7070 +#include <linux/kallsyms.h>
7071 +#include <linux/sysrq.h>
7073 +#ifdef CONFIG_AUFS_DEBUG
7074 +#define AuDebugOn(a) BUG_ON(a)
7076 +/* module parameter */
7077 +extern atomic_t aufs_debug;
7078 +static inline void au_debug_on(void)
7080 + atomic_inc(&aufs_debug);
7082 +static inline void au_debug_off(void)
7084 + atomic_dec_if_positive(&aufs_debug);
7087 +static inline int au_debug_test(void)
7089 + return atomic_read(&aufs_debug) > 0;
7092 +#define AuDebugOn(a) do {} while (0)
7093 +AuStubVoid(au_debug_on, void)
7094 +AuStubVoid(au_debug_off, void)
7095 +AuStubInt0(au_debug_test, void)
7096 +#endif /* CONFIG_AUFS_DEBUG */
7098 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7100 +/* ---------------------------------------------------------------------- */
7104 +#define AuDbg(fmt, ...) do { \
7105 + if (au_debug_test()) \
7106 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7108 +#define AuLabel(l) AuDbg(#l "\n")
7109 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7110 +#define AuWarn1(fmt, ...) do { \
7111 + static unsigned char _c; \
7113 + pr_warn(fmt, ##__VA_ARGS__); \
7116 +#define AuErr1(fmt, ...) do { \
7117 + static unsigned char _c; \
7119 + pr_err(fmt, ##__VA_ARGS__); \
7122 +#define AuIOErr1(fmt, ...) do { \
7123 + static unsigned char _c; \
7125 + AuIOErr(fmt, ##__VA_ARGS__); \
7128 +#define AuUnsupportMsg "This operation is not supported." \
7129 + " Please report this application to aufs-users ML."
7130 +#define AuUnsupport(fmt, ...) do { \
7131 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7135 +#define AuTraceErr(e) do { \
7136 + if (unlikely((e) < 0)) \
7137 + AuDbg("err %d\n", (int)(e)); \
7140 +#define AuTraceErrPtr(p) do { \
7142 + AuDbg("err %ld\n", PTR_ERR(p)); \
7145 +/* dirty macros for debug print, use with "%.*s" and caution */
7146 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7148 +/* ---------------------------------------------------------------------- */
7153 +#ifdef CONFIG_AUFS_DEBUG
7154 +extern char *au_plevel;
7156 +void au_dpri_whlist(struct au_nhash *whlist);
7158 +void au_dpri_vdir(struct au_vdir *vdir);
7160 +void au_dpri_inode(struct inode *inode);
7161 +void au_dpri_dalias(struct inode *inode);
7162 +void au_dpri_dentry(struct dentry *dentry);
7164 +void au_dpri_file(struct file *filp);
7165 +struct super_block;
7166 +void au_dpri_sb(struct super_block *sb);
7168 +void au_dbg_sleep_jiffy(int jiffy);
7170 +void au_dbg_iattr(struct iattr *ia);
7172 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7173 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7174 +void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
7175 +void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
7176 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7177 +void au_dbg_verify_kthread(void);
7179 +int __init au_debug_init(void);
7180 +void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
7181 +#define AuDbgWhlist(w) do { \
7183 + au_dpri_whlist(w); \
7186 +#define AuDbgVdir(v) do { \
7188 + au_dpri_vdir(v); \
7191 +#define AuDbgInode(i) do { \
7193 + au_dpri_inode(i); \
7196 +#define AuDbgDAlias(i) do { \
7198 + au_dpri_dalias(i); \
7201 +#define AuDbgDentry(d) do { \
7203 + au_dpri_dentry(d); \
7206 +#define AuDbgFile(f) do { \
7208 + au_dpri_file(f); \
7211 +#define AuDbgSb(sb) do { \
7212 + AuDbg(#sb "\n"); \
7216 +#define AuDbgSleep(sec) do { \
7217 + AuDbg("sleep %d sec\n", sec); \
7221 +#define AuDbgSleepJiffy(jiffy) do { \
7222 + AuDbg("sleep %d jiffies\n", jiffy); \
7223 + au_dbg_sleep_jiffy(jiffy); \
7226 +#define AuDbgIAttr(ia) do { \
7227 + AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
7228 + au_dbg_iattr(ia); \
7231 +#define AuDbgSym(addr) do { \
7232 + char sym[KSYM_SYMBOL_LEN]; \
7233 + sprint_symbol(sym, (unsigned long)addr); \
7234 + AuDbg("%s\n", sym); \
7237 +#define AuInfoSym(addr) do { \
7238 + char sym[KSYM_SYMBOL_LEN]; \
7239 + sprint_symbol(sym, (unsigned long)addr); \
7240 + AuInfo("%s\n", sym); \
7243 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7244 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
7245 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
7246 + unsigned int sigen)
7247 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7248 +AuStubVoid(au_dbg_verify_kthread, void)
7249 +AuStubInt0(__init au_debug_init, void)
7250 +AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
7252 +#define AuDbgWhlist(w) do {} while (0)
7253 +#define AuDbgVdir(v) do {} while (0)
7254 +#define AuDbgInode(i) do {} while (0)
7255 +#define AuDbgDAlias(i) do {} while (0)
7256 +#define AuDbgDentry(d) do {} while (0)
7257 +#define AuDbgFile(f) do {} while (0)
7258 +#define AuDbgSb(sb) do {} while (0)
7259 +#define AuDbgSleep(sec) do {} while (0)
7260 +#define AuDbgSleepJiffy(jiffy) do {} while (0)
7261 +#define AuDbgIAttr(ia) do {} while (0)
7262 +#define AuDbgSym(addr) do {} while (0)
7263 +#define AuInfoSym(addr) do {} while (0)
7264 +#endif /* CONFIG_AUFS_DEBUG */
7266 +/* ---------------------------------------------------------------------- */
7268 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7269 +int __init au_sysrq_init(void);
7270 +void au_sysrq_fin(void);
7272 +#ifdef CONFIG_HW_CONSOLE
7273 +#define au_dbg_blocked() do { \
7275 + handle_sysrq('w'); \
7278 +AuStubVoid(au_dbg_blocked, void)
7282 +AuStubInt0(__init au_sysrq_init, void)
7283 +AuStubVoid(au_sysrq_fin, void)
7284 +AuStubVoid(au_dbg_blocked, void)
7285 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7287 +#endif /* __KERNEL__ */
7288 +#endif /* __AUFS_DEBUG_H__ */
7289 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7290 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7291 +++ linux/fs/aufs/dentry.c 2014-08-14 10:16:04.515942371 +0200
7294 + * Copyright (C) 2005-2014 Junjiro R. Okajima
7296 + * This program, aufs is free software; you can redistribute it and/or modify
7297 + * it under the terms of the GNU General Public License as published by
7298 + * the Free Software Foundation; either version 2 of the License, or
7299 + * (at your option) any later version.
7301 + * This program is distributed in the hope that it will be useful,
7302 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7303 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7304 + * GNU General Public License for more details.
7306 + * You should have received a copy of the GNU General Public License
7307 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7311 + * lookup and dentry operations
7314 +#include <linux/namei.h>
7317 +#define AuLkup_ALLOW_NEG 1
7318 +#define AuLkup_IGNORE_PERM (1 << 1)
7319 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7320 +#define au_fset_lkup(flags, name) \
7321 + do { (flags) |= AuLkup_##name; } while (0)
7322 +#define au_fclr_lkup(flags, name) \
7323 + do { (flags) &= ~AuLkup_##name; } while (0)
7325 +struct au_do_lookup_args {
7326 + unsigned int flags;
7331 + * returns positive/negative dentry, NULL or an error.
7332 + * NULL means whiteout-ed or not-found.
7334 +static struct dentry*
7335 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7336 + aufs_bindex_t bindex, struct qstr *wh_name,
7337 + struct au_do_lookup_args *args)
7339 + struct dentry *h_dentry;
7340 + struct inode *h_inode, *inode;
7341 + struct au_branch *br;
7342 + int wh_found, opq;
7343 + unsigned char wh_able;
7344 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7345 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7349 + br = au_sbr(dentry->d_sb, bindex);
7350 + wh_able = !!au_br_whable(br->br_perm);
7352 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7353 + h_dentry = ERR_PTR(wh_found);
7356 + if (unlikely(wh_found < 0))
7359 + /* We found a whiteout */
7360 + /* au_set_dbend(dentry, bindex); */
7361 + au_set_dbwh(dentry, bindex);
7363 + return NULL; /* success */
7367 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7369 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7370 + if (IS_ERR(h_dentry))
7373 + h_inode = h_dentry->d_inode;
7377 + } else if (wh_found
7378 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7381 + if (au_dbend(dentry) <= bindex)
7382 + au_set_dbend(dentry, bindex);
7383 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7384 + au_set_dbstart(dentry, bindex);
7385 + au_set_h_dptr(dentry, bindex, h_dentry);
7387 + inode = dentry->d_inode;
7388 + if (!h_inode || !S_ISDIR(h_inode->i_mode) || !wh_able
7389 + || (inode && !S_ISDIR(inode->i_mode)))
7390 + goto out; /* success */
7392 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7393 + opq = au_diropq_test(h_dentry);
7394 + mutex_unlock(&h_inode->i_mutex);
7396 + au_set_dbdiropq(dentry, bindex);
7397 + else if (unlikely(opq < 0)) {
7398 + au_set_h_dptr(dentry, bindex, NULL);
7399 + h_dentry = ERR_PTR(opq);
7410 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7412 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7413 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7419 + * returns the number of lower positive dentries,
7420 + * otherwise an error.
7421 + * can be called at unlinking with @type is zero.
7423 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7425 + int npositive, err;
7426 + aufs_bindex_t bindex, btail, bdiropq;
7427 + unsigned char isdir, dirperm1;
7428 + struct qstr whname;
7429 + struct au_do_lookup_args args = {
7433 + const struct qstr *name = &dentry->d_name;
7434 + struct dentry *parent;
7435 + struct inode *inode;
7436 + struct super_block *sb;
7438 + sb = dentry->d_sb;
7439 + err = au_test_shwh(sb, name);
7440 + if (unlikely(err))
7443 + err = au_wh_name_alloc(&whname, name);
7444 + if (unlikely(err))
7447 + inode = dentry->d_inode;
7448 + isdir = !!(inode && S_ISDIR(inode->i_mode));
7450 + au_fset_lkup(args.flags, ALLOW_NEG);
7451 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7454 + parent = dget_parent(dentry);
7455 + btail = au_dbtaildir(parent);
7456 + for (bindex = bstart; bindex <= btail; bindex++) {
7457 + struct dentry *h_parent, *h_dentry;
7458 + struct inode *h_inode, *h_dir;
7460 + h_dentry = au_h_dptr(dentry, bindex);
7462 + if (h_dentry->d_inode)
7464 + if (type != S_IFDIR)
7468 + h_parent = au_h_dptr(parent, bindex);
7471 + h_dir = h_parent->d_inode;
7472 + if (!h_dir || !S_ISDIR(h_dir->i_mode))
7475 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7476 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7478 + mutex_unlock(&h_dir->i_mutex);
7479 + err = PTR_ERR(h_dentry);
7480 + if (IS_ERR(h_dentry))
7482 + au_fclr_lkup(args.flags, ALLOW_NEG);
7484 + au_fset_lkup(args.flags, IGNORE_PERM);
7486 + if (au_dbwh(dentry) >= 0)
7490 + h_inode = h_dentry->d_inode;
7495 + args.type = h_inode->i_mode & S_IFMT;
7496 + if (args.type != S_IFDIR)
7499 + /* the type of lower may be different */
7500 + bdiropq = au_dbdiropq(dentry);
7501 + if (bdiropq >= 0 && bdiropq <= bindex)
7507 + AuLabel(positive);
7508 + au_update_dbstart(dentry);
7511 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7512 + && au_dbstart(dentry) < 0)) {
7514 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7520 + kfree(whname.name);
7525 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7527 + struct dentry *dentry;
7530 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
7531 + dentry = vfsub_lkup_one(name, parent);
7533 + struct vfsub_lkup_one_args args = {
7539 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7540 + if (unlikely(wkq_err))
7541 + dentry = ERR_PTR(wkq_err);
7548 + * lookup @dentry on @bindex which should be negative.
7550 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7553 + struct dentry *parent, *h_parent, *h_dentry;
7554 + struct au_branch *br;
7556 + parent = dget_parent(dentry);
7557 + h_parent = au_h_dptr(parent, bindex);
7558 + br = au_sbr(dentry->d_sb, bindex);
7560 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7562 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7563 + err = PTR_ERR(h_dentry);
7564 + if (IS_ERR(h_dentry))
7566 + if (unlikely(h_dentry->d_inode)) {
7568 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7574 + if (bindex < au_dbstart(dentry))
7575 + au_set_dbstart(dentry, bindex);
7576 + if (au_dbend(dentry) < bindex)
7577 + au_set_dbend(dentry, bindex);
7578 + au_set_h_dptr(dentry, bindex, h_dentry);
7585 +/* ---------------------------------------------------------------------- */
7587 +/* subset of struct inode */
7589 + unsigned long i_ino;
7590 + /* unsigned int i_nlink; */
7596 + blkcnt_t i_blocks;
7601 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7603 + ia->i_ino = h_inode->i_ino;
7604 + /* ia->i_nlink = h_inode->i_nlink; */
7605 + ia->i_uid = h_inode->i_uid;
7606 + ia->i_gid = h_inode->i_gid;
7607 + ia->i_version = h_inode->i_version;
7609 + ia->i_size = h_inode->i_size;
7610 + ia->i_blocks = h_inode->i_blocks;
7612 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7615 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7617 + return ia->i_ino != h_inode->i_ino
7618 + /* || ia->i_nlink != h_inode->i_nlink */
7619 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7620 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7621 + || ia->i_version != h_inode->i_version
7623 + || ia->i_size != h_inode->i_size
7624 + || ia->i_blocks != h_inode->i_blocks
7626 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7629 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7630 + struct au_branch *br)
7633 + struct au_iattr ia;
7634 + struct inode *h_inode;
7635 + struct dentry *h_d;
7636 + struct super_block *h_sb;
7639 + memset(&ia, -1, sizeof(ia));
7640 + h_sb = h_dentry->d_sb;
7641 + h_inode = h_dentry->d_inode;
7643 + au_iattr_save(&ia, h_inode);
7644 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7645 + /* nfs d_revalidate may return 0 for negative dentry */
7646 + /* fuse d_revalidate always return 0 for negative dentry */
7649 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7650 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7651 + err = PTR_ERR(h_d);
7656 + if (unlikely(h_d != h_dentry
7657 + || h_d->d_inode != h_inode
7658 + || (h_inode && au_iattr_test(&ia, h_inode))))
7659 + err = au_busy_or_stale();
7667 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7668 + struct dentry *h_parent, struct au_branch *br)
7673 + if (udba == AuOpt_UDBA_REVAL
7674 + && !au_test_fs_remote(h_dentry->d_sb)) {
7676 + err = (h_dentry->d_parent->d_inode != h_dir);
7677 + } else if (udba != AuOpt_UDBA_NONE)
7678 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7683 +/* ---------------------------------------------------------------------- */
7685 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7688 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7689 + struct au_hdentry tmp, *p, *q;
7690 + struct au_dinfo *dinfo;
7691 + struct super_block *sb;
7693 + DiMustWriteLock(dentry);
7695 + sb = dentry->d_sb;
7696 + dinfo = au_di(dentry);
7697 + bend = dinfo->di_bend;
7698 + bwh = dinfo->di_bwh;
7699 + bdiropq = dinfo->di_bdiropq;
7700 + p = dinfo->di_hdentry + dinfo->di_bstart;
7701 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7702 + if (!p->hd_dentry)
7705 + new_bindex = au_br_index(sb, p->hd_id);
7706 + if (new_bindex == bindex)
7709 + if (dinfo->di_bwh == bindex)
7711 + if (dinfo->di_bdiropq == bindex)
7712 + bdiropq = new_bindex;
7713 + if (new_bindex < 0) {
7715 + p->hd_dentry = NULL;
7719 + /* swap two lower dentries, and loop again */
7720 + q = dinfo->di_hdentry + new_bindex;
7724 + if (tmp.hd_dentry) {
7730 + dinfo->di_bwh = -1;
7731 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7732 + dinfo->di_bwh = bwh;
7734 + dinfo->di_bdiropq = -1;
7736 + && bdiropq <= au_sbend(sb)
7737 + && au_sbr_whable(sb, bdiropq))
7738 + dinfo->di_bdiropq = bdiropq;
7741 + dinfo->di_bstart = -1;
7742 + dinfo->di_bend = -1;
7743 + bend = au_dbend(parent);
7744 + p = dinfo->di_hdentry;
7745 + for (bindex = 0; bindex <= bend; bindex++, p++)
7746 + if (p->hd_dentry) {
7747 + dinfo->di_bstart = bindex;
7751 + if (dinfo->di_bstart >= 0) {
7752 + p = dinfo->di_hdentry + bend;
7753 + for (bindex = bend; bindex >= 0; bindex--, p--)
7754 + if (p->hd_dentry) {
7755 + dinfo->di_bend = bindex;
7764 +static void au_do_hide(struct dentry *dentry)
7766 + struct inode *inode;
7768 + inode = dentry->d_inode;
7770 + if (!S_ISDIR(inode->i_mode)) {
7771 + if (inode->i_nlink && !d_unhashed(dentry))
7772 + drop_nlink(inode);
7774 + clear_nlink(inode);
7775 + /* stop next lookup */
7776 + inode->i_flags |= S_DEAD;
7778 + smp_mb(); /* necessary? */
7783 +static int au_hide_children(struct dentry *parent)
7785 + int err, i, j, ndentry;
7786 + struct au_dcsub_pages dpages;
7787 + struct au_dpage *dpage;
7788 + struct dentry *dentry;
7790 + err = au_dpages_init(&dpages, GFP_NOFS);
7791 + if (unlikely(err))
7793 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7794 + if (unlikely(err))
7797 + /* in reverse order */
7798 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7799 + dpage = dpages.dpages + i;
7800 + ndentry = dpage->ndentry;
7801 + for (j = ndentry - 1; j >= 0; j--) {
7802 + dentry = dpage->dentries[j];
7803 + if (dentry != parent)
7804 + au_do_hide(dentry);
7809 + au_dpages_free(&dpages);
7814 +static void au_hide(struct dentry *dentry)
7817 + struct inode *inode;
7819 + AuDbgDentry(dentry);
7820 + inode = dentry->d_inode;
7821 + if (inode && S_ISDIR(inode->i_mode)) {
7822 + /* shrink_dcache_parent(dentry); */
7823 + err = au_hide_children(dentry);
7824 + if (unlikely(err))
7825 + AuIOErr("%pd, failed hiding children, ignored %d\n",
7828 + au_do_hide(dentry);
7832 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7834 + * a dirty branch is added
7835 + * - on the top of layers
7836 + * - in the middle of layers
7837 + * - to the bottom of layers
7839 + * on the added branch there exists
7842 + * - a same named entry
7844 + * * negative --> positive
7845 + * * positive --> positive
7846 + * - type is unchanged
7847 + * - type is changed
7849 + * * negative --> negative
7850 + * * positive --> negative (rejected by au_br_del() for non-dir case)
7853 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
7854 + struct au_dinfo *tmp)
7857 + aufs_bindex_t bindex, bend;
7859 + struct dentry *dentry;
7860 + struct inode *inode;
7863 + struct au_hdentry *hd;
7864 + struct inode *inode, *h_inode;
7865 + struct dentry *h_dentry;
7868 + AuDebugOn(dinfo->di_bstart < 0);
7869 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
7870 + orig_h.inode = orig_h.dentry->d_inode;
7873 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
7874 + memset(&tmp_h, 0, sizeof(tmp_h));
7875 + if (tmp->di_bstart >= 0) {
7876 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
7877 + tmp_h.inode = tmp_h.dentry->d_inode;
7879 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
7882 + inode = dentry->d_inode;
7883 + if (!orig_h.inode) {
7884 + AuDbg("nagative originally\n");
7890 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7891 + AuDebugOn(dinfo->di_bdiropq != -1);
7893 + if (!tmp_h.inode) {
7894 + AuDbg("negative --> negative\n");
7895 + /* should have only one negative lower */
7896 + if (tmp->di_bstart >= 0
7897 + && tmp->di_bstart < dinfo->di_bstart) {
7898 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
7899 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
7900 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
7901 + au_di_cp(dinfo, tmp);
7902 + hd = tmp->di_hdentry + tmp->di_bstart;
7903 + au_set_h_dptr(dentry, tmp->di_bstart,
7904 + dget(hd->hd_dentry));
7906 + au_dbg_verify_dinode(dentry);
7908 + AuDbg("negative --> positive\n");
7910 + * similar to the behaviour of creating with bypassing
7912 + * unhash it in order to force an error in the
7913 + * succeeding create operation.
7914 + * we should not set S_DEAD here.
7917 + /* au_di_swap(tmp, dinfo); */
7918 + au_dbg_verify_dinode(dentry);
7921 + AuDbg("positive originally\n");
7922 + /* inode may be NULL */
7923 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
7924 + if (!tmp_h.inode) {
7925 + AuDbg("positive --> negative\n");
7926 + /* or bypassing aufs */
7928 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
7929 + dinfo->di_bwh = tmp->di_bwh;
7931 + err = au_refresh_hinode_self(inode);
7932 + au_dbg_verify_dinode(dentry);
7933 + } else if (orig_h.mode == tmp_h.mode) {
7934 + AuDbg("positive --> positive, same type\n");
7935 + if (!S_ISDIR(orig_h.mode)
7936 + && dinfo->di_bstart > tmp->di_bstart) {
7938 + * similar to the behaviour of removing and
7943 + err = au_refresh_hinode_self(inode);
7944 + au_dbg_verify_dinode(dentry);
7946 + /* fill empty slots */
7947 + if (dinfo->di_bstart > tmp->di_bstart)
7948 + dinfo->di_bstart = tmp->di_bstart;
7949 + if (dinfo->di_bend < tmp->di_bend)
7950 + dinfo->di_bend = tmp->di_bend;
7951 + dinfo->di_bwh = tmp->di_bwh;
7952 + dinfo->di_bdiropq = tmp->di_bdiropq;
7953 + hd = tmp->di_hdentry;
7954 + bend = dinfo->di_bend;
7955 + for (bindex = tmp->di_bstart; bindex <= bend;
7957 + if (au_h_dptr(dentry, bindex))
7959 + h_dentry = hd[bindex].hd_dentry;
7962 + h_inode = h_dentry->d_inode;
7963 + AuDebugOn(!h_inode);
7964 + AuDebugOn(orig_h.mode
7965 + != (h_inode->i_mode
7967 + au_set_h_dptr(dentry, bindex,
7970 + err = au_refresh_hinode(inode, dentry);
7971 + au_dbg_verify_dinode(dentry);
7974 + AuDbg("positive --> positive, different type\n");
7975 + /* similar to the behaviour of removing and creating */
7978 + err = au_refresh_hinode_self(inode);
7979 + au_dbg_verify_dinode(dentry);
7987 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
7990 + unsigned int sigen;
7991 + struct au_dinfo *dinfo, *tmp;
7992 + struct super_block *sb;
7993 + struct inode *inode;
7995 + DiMustWriteLock(dentry);
7996 + AuDebugOn(IS_ROOT(dentry));
7997 + AuDebugOn(!parent->d_inode);
7999 + sb = dentry->d_sb;
8000 + inode = dentry->d_inode;
8001 + sigen = au_sigen(sb);
8002 + err = au_digen_test(parent, sigen);
8003 + if (unlikely(err))
8006 + dinfo = au_di(dentry);
8007 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
8008 + if (unlikely(err))
8010 + ebrange = au_dbrange_test(dentry);
8012 + ebrange = au_do_refresh_hdentry(dentry, parent);
8014 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8015 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
8017 + err = au_refresh_hinode_self(inode);
8018 + au_dbg_verify_dinode(dentry);
8020 + goto out_dgen; /* success */
8024 + /* temporary dinfo */
8025 + AuDbgDentry(dentry);
8027 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8028 + if (unlikely(!tmp))
8030 + au_di_swap(tmp, dinfo);
8031 + /* returns the number of positive dentries */
8033 + * if current working dir is removed, it returns an error.
8034 + * but the dentry is legal.
8036 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
8037 + AuDbgDentry(dentry);
8038 + au_di_swap(tmp, dinfo);
8039 + if (err == -ENOENT)
8042 + /* compare/refresh by dinfo */
8043 + AuDbgDentry(dentry);
8044 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8045 + au_dbg_verify_dinode(dentry);
8048 + au_rw_write_unlock(&tmp->di_rwsem);
8050 + if (unlikely(err))
8054 + au_update_digen(dentry);
8056 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8057 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8058 + AuDbgDentry(dentry);
8064 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8065 + struct dentry *dentry, aufs_bindex_t bindex)
8070 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8073 + AuDbg("b%d\n", bindex);
8075 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8076 + * due to whiteout and branch permission.
8078 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8079 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8080 + /* it may return tri-state */
8081 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8083 + if (unlikely(valid < 0))
8093 +/* todo: remove this */
8094 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8095 + unsigned int flags, int do_udba)
8098 + umode_t mode, h_mode;
8099 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
8100 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8101 + struct inode *h_inode, *h_cached_inode;
8102 + struct dentry *h_dentry;
8103 + struct qstr *name, *h_name;
8110 + unhashed = !!d_unhashed(dentry);
8111 + is_root = !!IS_ROOT(dentry);
8112 + name = &dentry->d_name;
8113 + tmpfile = au_di(dentry)->di_tmpfile;
8116 + * Theoretically, REVAL test should be unnecessary in case of
8118 + * But {fs,i}notify doesn't fire some necessary events,
8119 + * IN_ATTRIB for atime/nlink/pageio
8120 + * Let's do REVAL test too.
8122 + if (do_udba && inode) {
8123 + mode = (inode->i_mode & S_IFMT);
8124 + plus = (inode->i_nlink > 0);
8125 + ibs = au_ibstart(inode);
8126 + ibe = au_ibend(inode);
8129 + bstart = au_dbstart(dentry);
8131 + if (inode && S_ISDIR(inode->i_mode))
8132 + btail = au_dbtaildir(dentry);
8133 + for (bindex = bstart; bindex <= btail; bindex++) {
8134 + h_dentry = au_h_dptr(dentry, bindex);
8138 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8139 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8140 + spin_lock(&h_dentry->d_lock);
8141 + h_name = &h_dentry->d_name;
8142 + if (unlikely(do_udba
8145 + && (unhashed != !!d_unhashed(h_dentry)
8147 + && !au_qstreq(name, h_name))
8150 + && !(flags & LOOKUP_OPEN)
8151 + && (h_dentry->d_flags
8152 + & DCACHE_NFSFS_RENAMED)))
8156 + h_unhashed = d_unhashed(h_dentry);
8157 + spin_unlock(&h_dentry->d_lock);
8158 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8159 + unhashed, h_unhashed, dentry, h_dentry);
8162 + spin_unlock(&h_dentry->d_lock);
8164 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8165 + if (unlikely(err))
8166 + /* do not goto err, to keep the errno */
8169 + /* todo: plink too? */
8174 + h_inode = h_dentry->d_inode;
8175 + if (unlikely(!!inode != !!h_inode))
8180 + h_cached_inode = h_inode;
8182 + h_mode = (h_inode->i_mode & S_IFMT);
8183 + h_plus = (h_inode->i_nlink > 0);
8185 + if (inode && ibs <= bindex && bindex <= ibe)
8186 + h_cached_inode = au_h_iptr(inode, bindex);
8189 + if (unlikely(plus != h_plus && !tmpfile))
8192 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8194 + && !IS_ROOT(h_dentry)
8195 + && unhashed != d_unhashed(h_dentry)))
8198 + if (unlikely(mode != h_mode
8199 + || h_cached_inode != h_inode))
8212 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8213 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8216 + struct dentry *parent;
8218 + if (!au_digen_test(dentry, sigen))
8221 + parent = dget_parent(dentry);
8222 + di_read_lock_parent(parent, AuLock_IR);
8223 + AuDebugOn(au_digen_test(parent, sigen));
8224 + au_dbg_verify_gen(parent, sigen);
8225 + err = au_refresh_dentry(dentry, parent);
8226 + di_read_unlock(parent, AuLock_IR);
8232 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8235 + struct dentry *d, *parent;
8236 + struct inode *inode;
8238 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8239 + return simple_reval_dpath(dentry, sigen);
8241 + /* slow loop, keep it simple and stupid */
8242 + /* cf: au_cpup_dirs() */
8245 + while (au_digen_test(dentry, sigen)) {
8249 + parent = dget_parent(d);
8250 + if (!au_digen_test(parent, sigen))
8255 + inode = d->d_inode;
8257 + di_write_lock_child2(d);
8259 + /* someone might update our dentry while we were sleeping */
8260 + if (au_digen_test(d, sigen)) {
8262 + * todo: consolidate with simple_reval_dpath(),
8263 + * do_refresh() and au_reval_for_attr().
8265 + di_read_lock_parent(parent, AuLock_IR);
8266 + err = au_refresh_dentry(d, parent);
8267 + di_read_unlock(parent, AuLock_IR);
8271 + di_write_unlock(d);
8273 + if (unlikely(err))
8281 + * if valid returns 1, otherwise 0.
8283 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8286 + unsigned int sigen;
8287 + unsigned char do_udba;
8288 + struct super_block *sb;
8289 + struct inode *inode;
8291 + /* todo: support rcu-walk? */
8292 + if (flags & LOOKUP_RCU)
8296 + if (unlikely(!au_di(dentry)))
8299 + inode = dentry->d_inode;
8300 + if (inode && is_bad_inode(inode))
8304 + sb = dentry->d_sb;
8307 + * i_mutex of parent dir may be held,
8308 + * but we should not return 'invalid' due to busy.
8310 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8311 + if (unlikely(err)) {
8316 + if (unlikely(au_dbrange_test(dentry))) {
8322 + sigen = au_sigen(sb);
8323 + if (au_digen_test(dentry, sigen)) {
8324 + AuDebugOn(IS_ROOT(dentry));
8325 + err = au_reval_dpath(dentry, sigen);
8326 + if (unlikely(err)) {
8331 + di_downgrade_lock(dentry, AuLock_IR);
8334 + if (!(flags & LOOKUP_OPEN)
8336 + && !(inode->i_state && I_LINKABLE)
8337 + && (IS_DEADDIR(inode) || !inode->i_nlink))
8340 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8341 + if (do_udba && inode) {
8342 + aufs_bindex_t bstart = au_ibstart(inode);
8343 + struct inode *h_inode;
8345 + if (bstart >= 0) {
8346 + h_inode = au_h_iptr(inode, bstart);
8347 + if (h_inode && au_test_higen(inode, h_inode))
8352 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8353 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8355 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8361 + di_downgrade_lock(dentry, AuLock_IR);
8363 + aufs_read_unlock(dentry, AuLock_IR);
8368 + AuDbg("%pd invalid, %d\n", dentry, valid);
8374 +static void aufs_d_release(struct dentry *dentry)
8376 + if (au_di(dentry)) {
8377 + au_di_fin(dentry);
8378 + au_hn_di_reinit(dentry);
8382 +const struct dentry_operations aufs_dop = {
8383 + .d_revalidate = aufs_d_revalidate,
8384 + .d_weak_revalidate = aufs_d_revalidate,
8385 + .d_release = aufs_d_release
8387 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8388 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8389 +++ linux/fs/aufs/dentry.h 2014-08-14 10:15:45.121942630 +0200
8392 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8394 + * This program, aufs is free software; you can redistribute it and/or modify
8395 + * it under the terms of the GNU General Public License as published by
8396 + * the Free Software Foundation; either version 2 of the License, or
8397 + * (at your option) any later version.
8399 + * This program is distributed in the hope that it will be useful,
8400 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8401 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8402 + * GNU General Public License for more details.
8404 + * You should have received a copy of the GNU General Public License
8405 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8409 + * lookup and dentry operations
8412 +#ifndef __AUFS_DENTRY_H__
8413 +#define __AUFS_DENTRY_H__
8417 +#include <linux/dcache.h>
8420 +struct au_hdentry {
8421 + struct dentry *hd_dentry;
8422 + aufs_bindex_t hd_id;
8426 + atomic_t di_generation;
8428 + struct au_rwsem di_rwsem;
8429 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8430 + unsigned char di_tmpfile; /* to allow the different name */
8431 + struct au_hdentry *di_hdentry;
8432 +} ____cacheline_aligned_in_smp;
8434 +/* ---------------------------------------------------------------------- */
8437 +extern const struct dentry_operations aufs_dop;
8439 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8440 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8441 + struct dentry *h_parent, struct au_branch *br);
8443 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8444 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8445 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8446 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8449 +void au_di_init_once(void *_di);
8450 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8451 +void au_di_free(struct au_dinfo *dinfo);
8452 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8453 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8454 +int au_di_init(struct dentry *dentry);
8455 +void au_di_fin(struct dentry *dentry);
8456 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8458 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8459 +void di_read_unlock(struct dentry *d, int flags);
8460 +void di_downgrade_lock(struct dentry *d, int flags);
8461 +void di_write_lock(struct dentry *d, unsigned int lsc);
8462 +void di_write_unlock(struct dentry *d);
8463 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8464 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8465 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8467 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8468 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8469 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8470 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8472 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8473 + struct dentry *h_dentry);
8474 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8475 +int au_dbrange_test(struct dentry *dentry);
8476 +void au_update_digen(struct dentry *dentry);
8477 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8478 +void au_update_dbstart(struct dentry *dentry);
8479 +void au_update_dbend(struct dentry *dentry);
8480 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8482 +/* ---------------------------------------------------------------------- */
8484 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8486 + return dentry->d_fsdata;
8489 +/* ---------------------------------------------------------------------- */
8491 +/* lock subclass for dinfo */
8493 + AuLsc_DI_CHILD, /* child first */
8494 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8495 + AuLsc_DI_CHILD3, /* copyup dirs */
8499 + AuLsc_DI_TMP /* temp for replacing dinfo */
8503 + * di_read_lock_child, di_write_lock_child,
8504 + * di_read_lock_child2, di_write_lock_child2,
8505 + * di_read_lock_child3, di_write_lock_child3,
8506 + * di_read_lock_parent, di_write_lock_parent,
8507 + * di_read_lock_parent2, di_write_lock_parent2,
8508 + * di_read_lock_parent3, di_write_lock_parent3,
8510 +#define AuReadLockFunc(name, lsc) \
8511 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8512 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8514 +#define AuWriteLockFunc(name, lsc) \
8515 +static inline void di_write_lock_##name(struct dentry *d) \
8516 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8518 +#define AuRWLockFuncs(name, lsc) \
8519 + AuReadLockFunc(name, lsc) \
8520 + AuWriteLockFunc(name, lsc)
8522 +AuRWLockFuncs(child, CHILD);
8523 +AuRWLockFuncs(child2, CHILD2);
8524 +AuRWLockFuncs(child3, CHILD3);
8525 +AuRWLockFuncs(parent, PARENT);
8526 +AuRWLockFuncs(parent2, PARENT2);
8527 +AuRWLockFuncs(parent3, PARENT3);
8529 +#undef AuReadLockFunc
8530 +#undef AuWriteLockFunc
8531 +#undef AuRWLockFuncs
8533 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8534 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8535 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8537 +/* ---------------------------------------------------------------------- */
8539 +/* todo: memory barrier? */
8540 +static inline unsigned int au_digen(struct dentry *d)
8542 + return atomic_read(&au_di(d)->di_generation);
8545 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8547 + hdentry->hd_dentry = NULL;
8550 +static inline void au_hdput(struct au_hdentry *hd)
8553 + dput(hd->hd_dentry);
8556 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8558 + DiMustAnyLock(dentry);
8559 + return au_di(dentry)->di_bstart;
8562 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8564 + DiMustAnyLock(dentry);
8565 + return au_di(dentry)->di_bend;
8568 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8570 + DiMustAnyLock(dentry);
8571 + return au_di(dentry)->di_bwh;
8574 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8576 + DiMustAnyLock(dentry);
8577 + return au_di(dentry)->di_bdiropq;
8580 +/* todo: hard/soft set? */
8581 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8583 + DiMustWriteLock(dentry);
8584 + au_di(dentry)->di_bstart = bindex;
8587 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8589 + DiMustWriteLock(dentry);
8590 + au_di(dentry)->di_bend = bindex;
8593 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8595 + DiMustWriteLock(dentry);
8596 + /* dbwh can be outside of bstart - bend range */
8597 + au_di(dentry)->di_bwh = bindex;
8600 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8602 + DiMustWriteLock(dentry);
8603 + au_di(dentry)->di_bdiropq = bindex;
8606 +/* ---------------------------------------------------------------------- */
8608 +#ifdef CONFIG_AUFS_HNOTIFY
8609 +static inline void au_digen_dec(struct dentry *d)
8611 + atomic_dec(&au_di(d)->di_generation);
8614 +static inline void au_hn_di_reinit(struct dentry *dentry)
8616 + dentry->d_fsdata = NULL;
8619 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8620 +#endif /* CONFIG_AUFS_HNOTIFY */
8622 +#endif /* __KERNEL__ */
8623 +#endif /* __AUFS_DENTRY_H__ */
8624 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8625 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8626 +++ linux/fs/aufs/dinfo.c 2014-08-14 10:15:45.121942630 +0200
8629 + * Copyright (C) 2005-2014 Junjiro R. Okajima
8631 + * This program, aufs is free software; you can redistribute it and/or modify
8632 + * it under the terms of the GNU General Public License as published by
8633 + * the Free Software Foundation; either version 2 of the License, or
8634 + * (at your option) any later version.
8636 + * This program is distributed in the hope that it will be useful,
8637 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8638 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8639 + * GNU General Public License for more details.
8641 + * You should have received a copy of the GNU General Public License
8642 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8646 + * dentry private data
8651 +void au_di_init_once(void *_dinfo)
8653 + struct au_dinfo *dinfo = _dinfo;
8654 + static struct lock_class_key aufs_di;
8656 + au_rw_init(&dinfo->di_rwsem);
8657 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8660 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8662 + struct au_dinfo *dinfo;
8665 + dinfo = au_cache_alloc_dinfo();
8666 + if (unlikely(!dinfo))
8669 + nbr = au_sbend(sb) + 1;
8672 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8673 + if (dinfo->di_hdentry) {
8674 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8675 + dinfo->di_bstart = -1;
8676 + dinfo->di_bend = -1;
8677 + dinfo->di_bwh = -1;
8678 + dinfo->di_bdiropq = -1;
8679 + dinfo->di_tmpfile = 0;
8680 + for (i = 0; i < nbr; i++)
8681 + dinfo->di_hdentry[i].hd_id = -1;
8685 + au_cache_free_dinfo(dinfo);
8692 +void au_di_free(struct au_dinfo *dinfo)
8694 + struct au_hdentry *p;
8695 + aufs_bindex_t bend, bindex;
8697 + /* dentry may not be revalidated */
8698 + bindex = dinfo->di_bstart;
8699 + if (bindex >= 0) {
8700 + bend = dinfo->di_bend;
8701 + p = dinfo->di_hdentry + bindex;
8702 + while (bindex++ <= bend)
8705 + kfree(dinfo->di_hdentry);
8706 + au_cache_free_dinfo(dinfo);
8709 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8711 + struct au_hdentry *p;
8714 + AuRwMustWriteLock(&a->di_rwsem);
8715 + AuRwMustWriteLock(&b->di_rwsem);
8717 +#define DiSwap(v, name) \
8719 + v = a->di_##name; \
8720 + a->di_##name = b->di_##name; \
8721 + b->di_##name = v; \
8724 + DiSwap(p, hdentry);
8725 + DiSwap(bi, bstart);
8728 + DiSwap(bi, bdiropq);
8734 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8736 + AuRwMustWriteLock(&dst->di_rwsem);
8737 + AuRwMustWriteLock(&src->di_rwsem);
8739 + dst->di_bstart = src->di_bstart;
8740 + dst->di_bend = src->di_bend;
8741 + dst->di_bwh = src->di_bwh;
8742 + dst->di_bdiropq = src->di_bdiropq;
8746 +int au_di_init(struct dentry *dentry)
8749 + struct super_block *sb;
8750 + struct au_dinfo *dinfo;
8753 + sb = dentry->d_sb;
8754 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8756 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8757 + /* smp_mb(); */ /* atomic_set */
8758 + dentry->d_fsdata = dinfo;
8765 +void au_di_fin(struct dentry *dentry)
8767 + struct au_dinfo *dinfo;
8769 + dinfo = au_di(dentry);
8770 + AuRwDestroy(&dinfo->di_rwsem);
8771 + au_di_free(dinfo);
8774 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8777 + struct au_hdentry *hdp;
8779 + AuRwMustWriteLock(&dinfo->di_rwsem);
8782 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8784 + sz = sizeof(*hdp);
8785 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8787 + dinfo->di_hdentry = hdp;
8794 +/* ---------------------------------------------------------------------- */
8796 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8799 + case AuLsc_DI_CHILD:
8800 + ii_write_lock_child(inode);
8802 + case AuLsc_DI_CHILD2:
8803 + ii_write_lock_child2(inode);
8805 + case AuLsc_DI_CHILD3:
8806 + ii_write_lock_child3(inode);
8808 + case AuLsc_DI_PARENT:
8809 + ii_write_lock_parent(inode);
8811 + case AuLsc_DI_PARENT2:
8812 + ii_write_lock_parent2(inode);
8814 + case AuLsc_DI_PARENT3:
8815 + ii_write_lock_parent3(inode);
8822 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
8825 + case AuLsc_DI_CHILD:
8826 + ii_read_lock_child(inode);
8828 + case AuLsc_DI_CHILD2:
8829 + ii_read_lock_child2(inode);
8831 + case AuLsc_DI_CHILD3:
8832 + ii_read_lock_child3(inode);
8834 + case AuLsc_DI_PARENT:
8835 + ii_read_lock_parent(inode);
8837 + case AuLsc_DI_PARENT2:
8838 + ii_read_lock_parent2(inode);
8840 + case AuLsc_DI_PARENT3:
8841 + ii_read_lock_parent3(inode);
8848 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
8850 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
8852 + if (au_ftest_lock(flags, IW))
8853 + do_ii_write_lock(d->d_inode, lsc);
8854 + else if (au_ftest_lock(flags, IR))
8855 + do_ii_read_lock(d->d_inode, lsc);
8859 +void di_read_unlock(struct dentry *d, int flags)
8862 + if (au_ftest_lock(flags, IW)) {
8863 + au_dbg_verify_dinode(d);
8864 + ii_write_unlock(d->d_inode);
8865 + } else if (au_ftest_lock(flags, IR)) {
8866 + au_dbg_verify_dinode(d);
8867 + ii_read_unlock(d->d_inode);
8870 + au_rw_read_unlock(&au_di(d)->di_rwsem);
8873 +void di_downgrade_lock(struct dentry *d, int flags)
8875 + if (d->d_inode && au_ftest_lock(flags, IR))
8876 + ii_downgrade_lock(d->d_inode);
8877 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
8880 +void di_write_lock(struct dentry *d, unsigned int lsc)
8882 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
8884 + do_ii_write_lock(d->d_inode, lsc);
8887 +void di_write_unlock(struct dentry *d)
8889 + au_dbg_verify_dinode(d);
8891 + ii_write_unlock(d->d_inode);
8892 + au_rw_write_unlock(&au_di(d)->di_rwsem);
8895 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
8897 + AuDebugOn(d1 == d2
8898 + || d1->d_inode == d2->d_inode
8899 + || d1->d_sb != d2->d_sb);
8901 + if (isdir && au_test_subdir(d1, d2)) {
8902 + di_write_lock_child(d1);
8903 + di_write_lock_child2(d2);
8905 + /* there should be no races */
8906 + di_write_lock_child(d2);
8907 + di_write_lock_child2(d1);
8911 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
8913 + AuDebugOn(d1 == d2
8914 + || d1->d_inode == d2->d_inode
8915 + || d1->d_sb != d2->d_sb);
8917 + if (isdir && au_test_subdir(d1, d2)) {
8918 + di_write_lock_parent(d1);
8919 + di_write_lock_parent2(d2);
8921 + /* there should be no races */
8922 + di_write_lock_parent(d2);
8923 + di_write_lock_parent2(d1);
8927 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
8929 + di_write_unlock(d1);
8930 + if (d1->d_inode == d2->d_inode)
8931 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
8933 + di_write_unlock(d2);
8936 +/* ---------------------------------------------------------------------- */
8938 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
8942 + DiMustAnyLock(dentry);
8944 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
8946 + AuDebugOn(bindex < 0);
8947 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
8948 + AuDebugOn(d && d_count(d) <= 0);
8953 + * extended version of au_h_dptr().
8954 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
8957 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
8959 + struct dentry *h_dentry;
8960 + struct inode *inode, *h_inode;
8962 + inode = dentry->d_inode;
8963 + AuDebugOn(!inode);
8966 + if (au_dbstart(dentry) <= bindex
8967 + && bindex <= au_dbend(dentry))
8968 + h_dentry = au_h_dptr(dentry, bindex);
8969 + if (h_dentry && !au_d_linkable(h_dentry)) {
8971 + goto out; /* success */
8974 + AuDebugOn(bindex < au_ibstart(inode));
8975 + AuDebugOn(au_ibend(inode) < bindex);
8976 + h_inode = au_h_iptr(inode, bindex);
8977 + h_dentry = d_find_alias(h_inode);
8979 + if (!IS_ERR(h_dentry)) {
8980 + if (!au_d_linkable(h_dentry))
8981 + goto out; /* success */
8987 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
8988 + h_dentry = au_plink_lkup(inode, bindex);
8989 + AuDebugOn(!h_dentry);
8990 + if (!IS_ERR(h_dentry)) {
8991 + if (!au_d_hashed_positive(h_dentry))
8992 + goto out; /* success */
8999 + AuDbgDentry(h_dentry);
9003 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9005 + aufs_bindex_t bend, bwh;
9007 + bend = au_dbend(dentry);
9009 + bwh = au_dbwh(dentry);
9012 + if (0 < bwh && bwh < bend)
9018 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9020 + aufs_bindex_t bend, bopq;
9022 + bend = au_dbtail(dentry);
9024 + bopq = au_dbdiropq(dentry);
9025 + if (0 <= bopq && bopq < bend)
9031 +/* ---------------------------------------------------------------------- */
9033 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9034 + struct dentry *h_dentry)
9036 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
9037 + struct au_branch *br;
9039 + DiMustWriteLock(dentry);
9042 + hd->hd_dentry = h_dentry;
9044 + br = au_sbr(dentry->d_sb, bindex);
9045 + hd->hd_id = br->br_id;
9049 +int au_dbrange_test(struct dentry *dentry)
9052 + aufs_bindex_t bstart, bend;
9055 + bstart = au_dbstart(dentry);
9056 + bend = au_dbend(dentry);
9058 + AuDebugOn(bend < 0 && bstart > bend);
9061 + AuDebugOn(bend >= 0);
9067 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9072 + if (unlikely(au_digen(dentry) != sigen
9073 + || au_iigen_test(dentry->d_inode, sigen)))
9079 +void au_update_digen(struct dentry *dentry)
9081 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9082 + /* smp_mb(); */ /* atomic_set */
9085 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9087 + struct au_dinfo *dinfo;
9088 + struct dentry *h_d;
9089 + struct au_hdentry *hdp;
9091 + DiMustWriteLock(dentry);
9093 + dinfo = au_di(dentry);
9094 + if (!dinfo || dinfo->di_bstart < 0)
9097 + hdp = dinfo->di_hdentry;
9098 + if (do_put_zero) {
9099 + aufs_bindex_t bindex, bend;
9101 + bend = dinfo->di_bend;
9102 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
9103 + h_d = hdp[0 + bindex].hd_dentry;
9104 + if (h_d && !h_d->d_inode)
9105 + au_set_h_dptr(dentry, bindex, NULL);
9109 + dinfo->di_bstart = -1;
9110 + while (++dinfo->di_bstart <= dinfo->di_bend)
9111 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
9113 + if (dinfo->di_bstart > dinfo->di_bend) {
9114 + dinfo->di_bstart = -1;
9115 + dinfo->di_bend = -1;
9120 + while (0 <= --dinfo->di_bend)
9121 + if (hdp[0 + dinfo->di_bend].hd_dentry)
9123 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
9126 +void au_update_dbstart(struct dentry *dentry)
9128 + aufs_bindex_t bindex, bend;
9129 + struct dentry *h_dentry;
9131 + bend = au_dbend(dentry);
9132 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
9133 + h_dentry = au_h_dptr(dentry, bindex);
9136 + if (h_dentry->d_inode) {
9137 + au_set_dbstart(dentry, bindex);
9140 + au_set_h_dptr(dentry, bindex, NULL);
9144 +void au_update_dbend(struct dentry *dentry)
9146 + aufs_bindex_t bindex, bstart;
9147 + struct dentry *h_dentry;
9149 + bstart = au_dbstart(dentry);
9150 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
9151 + h_dentry = au_h_dptr(dentry, bindex);
9154 + if (h_dentry->d_inode) {
9155 + au_set_dbend(dentry, bindex);
9158 + au_set_h_dptr(dentry, bindex, NULL);
9162 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9164 + aufs_bindex_t bindex, bend;
9166 + bend = au_dbend(dentry);
9167 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
9168 + if (au_h_dptr(dentry, bindex) == h_dentry)
9172 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9173 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9174 +++ linux/fs/aufs/dir.c 2014-08-14 10:15:45.121942630 +0200
9177 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9179 + * This program, aufs is free software; you can redistribute it and/or modify
9180 + * it under the terms of the GNU General Public License as published by
9181 + * the Free Software Foundation; either version 2 of the License, or
9182 + * (at your option) any later version.
9184 + * This program is distributed in the hope that it will be useful,
9185 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9186 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9187 + * GNU General Public License for more details.
9189 + * You should have received a copy of the GNU General Public License
9190 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9194 + * directory operations
9197 +#include <linux/fs_stack.h>
9200 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9202 + unsigned int nlink;
9204 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9206 + nlink = dir->i_nlink;
9207 + nlink += h_dir->i_nlink - 2;
9208 + if (h_dir->i_nlink < 2)
9210 + smp_mb(); /* for i_nlink */
9211 + /* 0 can happen in revaliding */
9212 + set_nlink(dir, nlink);
9215 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9217 + unsigned int nlink;
9219 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9221 + nlink = dir->i_nlink;
9222 + nlink -= h_dir->i_nlink - 2;
9223 + if (h_dir->i_nlink < 2)
9225 + smp_mb(); /* for i_nlink */
9226 + /* nlink == 0 means the branch-fs is broken */
9227 + set_nlink(dir, nlink);
9230 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9233 + aufs_bindex_t bindex, bend;
9234 + struct file *h_file;
9235 + struct dentry *h_dentry;
9239 + AuDebugOn(!file_inode(file));
9240 + AuDebugOn(!S_ISDIR(file_inode(file)->i_mode));
9242 + bend = au_fbend_dir(file);
9243 + for (bindex = au_fbstart(file);
9244 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9246 + h_file = au_hf_dir(file, bindex);
9247 + if (h_file && file_inode(h_file))
9248 + sz += vfsub_f_size_read(h_file);
9251 + AuDebugOn(!dentry);
9252 + AuDebugOn(!dentry->d_inode);
9253 + AuDebugOn(!S_ISDIR(dentry->d_inode->i_mode));
9255 + bend = au_dbtaildir(dentry);
9256 + for (bindex = au_dbstart(dentry);
9257 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9259 + h_dentry = au_h_dptr(dentry, bindex);
9260 + if (h_dentry && h_dentry->d_inode)
9261 + sz += i_size_read(h_dentry->d_inode);
9264 + if (sz < KMALLOC_MAX_SIZE)
9265 + sz = roundup_pow_of_two(sz);
9266 + if (sz > KMALLOC_MAX_SIZE)
9267 + sz = KMALLOC_MAX_SIZE;
9268 + else if (sz < NAME_MAX) {
9269 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9270 + sz = AUFS_RDBLK_DEF;
9275 +/* ---------------------------------------------------------------------- */
9277 +static int reopen_dir(struct file *file)
9280 + unsigned int flags;
9281 + aufs_bindex_t bindex, btail, bstart;
9282 + struct dentry *dentry, *h_dentry;
9283 + struct file *h_file;
9285 + /* open all lower dirs */
9286 + dentry = file->f_dentry;
9287 + bstart = au_dbstart(dentry);
9288 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9289 + au_set_h_fptr(file, bindex, NULL);
9290 + au_set_fbstart(file, bstart);
9292 + btail = au_dbtaildir(dentry);
9293 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9294 + au_set_h_fptr(file, bindex, NULL);
9295 + au_set_fbend_dir(file, btail);
9297 + flags = vfsub_file_flags(file);
9298 + for (bindex = bstart; bindex <= btail; bindex++) {
9299 + h_dentry = au_h_dptr(dentry, bindex);
9302 + h_file = au_hf_dir(file, bindex);
9306 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9307 + err = PTR_ERR(h_file);
9308 + if (IS_ERR(h_file))
9309 + goto out; /* close all? */
9310 + au_set_h_fptr(file, bindex, h_file);
9312 + au_update_figen(file);
9313 + /* todo: necessary? */
9314 + /* file->f_ra = h_file->f_ra; */
9321 +static int do_open_dir(struct file *file, int flags)
9324 + aufs_bindex_t bindex, btail;
9325 + struct dentry *dentry, *h_dentry;
9326 + struct file *h_file;
9328 + FiMustWriteLock(file);
9331 + dentry = file->f_dentry;
9332 + file->f_version = dentry->d_inode->i_version;
9333 + bindex = au_dbstart(dentry);
9334 + au_set_fbstart(file, bindex);
9335 + btail = au_dbtaildir(dentry);
9336 + au_set_fbend_dir(file, btail);
9337 + for (; !err && bindex <= btail; bindex++) {
9338 + h_dentry = au_h_dptr(dentry, bindex);
9342 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9343 + if (IS_ERR(h_file)) {
9344 + err = PTR_ERR(h_file);
9347 + au_set_h_fptr(file, bindex, h_file);
9349 + au_update_figen(file);
9350 + /* todo: necessary? */
9351 + /* file->f_ra = h_file->f_ra; */
9353 + return 0; /* success */
9356 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9357 + au_set_h_fptr(file, bindex, NULL);
9358 + au_set_fbstart(file, -1);
9359 + au_set_fbend_dir(file, -1);
9364 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9365 + struct file *file)
9368 + struct super_block *sb;
9369 + struct au_fidir *fidir;
9372 + sb = file->f_dentry->d_sb;
9373 + si_read_lock(sb, AuLock_FLUSH);
9374 + fidir = au_fidir_alloc(sb);
9376 + err = au_do_open(file, do_open_dir, fidir);
9377 + if (unlikely(err))
9380 + si_read_unlock(sb);
9384 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9385 + struct file *file)
9387 + struct au_vdir *vdir_cache;
9388 + struct au_finfo *finfo;
9389 + struct au_fidir *fidir;
9390 + aufs_bindex_t bindex, bend;
9392 + finfo = au_fi(file);
9393 + fidir = finfo->fi_hdir;
9395 + au_sphl_del(&finfo->fi_hlist,
9396 + &au_sbi(file->f_dentry->d_sb)->si_files);
9397 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9399 + au_vdir_free(vdir_cache);
9401 + bindex = finfo->fi_btop;
9402 + if (bindex >= 0) {
9404 + * calls fput() instead of filp_close(),
9405 + * since no dnotify or lock for the lower file.
9407 + bend = fidir->fd_bbot;
9408 + for (; bindex <= bend; bindex++)
9409 + au_set_h_fptr(file, bindex, NULL);
9412 + finfo->fi_hdir = NULL;
9414 + au_finfo_fin(file);
9418 +/* ---------------------------------------------------------------------- */
9420 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9423 + aufs_bindex_t bindex, bend;
9424 + struct file *h_file;
9427 + bend = au_fbend_dir(file);
9428 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9429 + h_file = au_hf_dir(file, bindex);
9431 + err = vfsub_flush(h_file, id);
9436 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9438 + return au_do_flush(file, id, au_do_flush_dir);
9441 +/* ---------------------------------------------------------------------- */
9443 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9446 + aufs_bindex_t bend, bindex;
9447 + struct inode *inode;
9448 + struct super_block *sb;
9451 + sb = dentry->d_sb;
9452 + inode = dentry->d_inode;
9454 + bend = au_dbend(dentry);
9455 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9456 + struct path h_path;
9458 + if (au_test_ro(sb, bindex, inode))
9460 + h_path.dentry = au_h_dptr(dentry, bindex);
9461 + if (!h_path.dentry)
9464 + h_path.mnt = au_sbr_mnt(sb, bindex);
9465 + err = vfsub_fsync(NULL, &h_path, datasync);
9471 +static int au_do_fsync_dir(struct file *file, int datasync)
9474 + aufs_bindex_t bend, bindex;
9475 + struct file *h_file;
9476 + struct super_block *sb;
9477 + struct inode *inode;
9479 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9480 + if (unlikely(err))
9483 + sb = file->f_dentry->d_sb;
9484 + inode = file_inode(file);
9485 + bend = au_fbend_dir(file);
9486 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9487 + h_file = au_hf_dir(file, bindex);
9488 + if (!h_file || au_test_ro(sb, bindex, inode))
9491 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9499 + * @file may be NULL
9501 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9505 + struct dentry *dentry;
9506 + struct super_block *sb;
9507 + struct mutex *mtx;
9510 + dentry = file->f_dentry;
9511 + mtx = &dentry->d_inode->i_mutex;
9513 + sb = dentry->d_sb;
9514 + si_noflush_read_lock(sb);
9516 + err = au_do_fsync_dir(file, datasync);
9518 + di_write_lock_child(dentry);
9519 + err = au_do_fsync_dir_no_file(dentry, datasync);
9521 + au_cpup_attr_timesizes(dentry->d_inode);
9522 + di_write_unlock(dentry);
9524 + fi_write_unlock(file);
9526 + si_read_unlock(sb);
9527 + mutex_unlock(mtx);
9531 +/* ---------------------------------------------------------------------- */
9533 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9536 + struct dentry *dentry;
9537 + struct inode *inode, *h_inode;
9538 + struct super_block *sb;
9540 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9542 + dentry = file->f_dentry;
9543 + inode = dentry->d_inode;
9546 + sb = dentry->d_sb;
9547 + si_read_lock(sb, AuLock_FLUSH);
9548 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9549 + if (unlikely(err))
9551 + err = au_alive_dir(dentry);
9553 + err = au_vdir_init(file);
9554 + di_downgrade_lock(dentry, AuLock_IR);
9555 + if (unlikely(err))
9558 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9559 + if (!au_test_nfsd()) {
9560 + err = au_vdir_fill_de(file, ctx);
9561 + fsstack_copy_attr_atime(inode, h_inode);
9564 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9565 + * encode_fh() and others.
9567 + atomic_inc(&h_inode->i_count);
9568 + di_read_unlock(dentry, AuLock_IR);
9569 + si_read_unlock(sb);
9570 + err = au_vdir_fill_de(file, ctx);
9571 + fsstack_copy_attr_atime(inode, h_inode);
9572 + fi_write_unlock(file);
9580 + di_read_unlock(dentry, AuLock_IR);
9581 + fi_write_unlock(file);
9583 + si_read_unlock(sb);
9587 +/* ---------------------------------------------------------------------- */
9589 +#define AuTestEmpty_WHONLY 1
9590 +#define AuTestEmpty_CALLED (1 << 1)
9591 +#define AuTestEmpty_SHWH (1 << 2)
9592 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9593 +#define au_fset_testempty(flags, name) \
9594 + do { (flags) |= AuTestEmpty_##name; } while (0)
9595 +#define au_fclr_testempty(flags, name) \
9596 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9598 +#ifndef CONFIG_AUFS_SHWH
9599 +#undef AuTestEmpty_SHWH
9600 +#define AuTestEmpty_SHWH 0
9603 +struct test_empty_arg {
9604 + struct dir_context ctx;
9605 + struct au_nhash *whlist;
9606 + unsigned int flags;
9608 + aufs_bindex_t bindex;
9611 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9612 + int namelen, loff_t offset __maybe_unused, u64 ino,
9613 + unsigned int d_type)
9615 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9617 + char *name = (void *)__name;
9620 + au_fset_testempty(arg->flags, CALLED);
9622 + if (name[0] == '.'
9623 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9624 + goto out; /* success */
9626 + if (namelen <= AUFS_WH_PFX_LEN
9627 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9628 + if (au_ftest_testempty(arg->flags, WHONLY)
9629 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9630 + arg->err = -ENOTEMPTY;
9634 + name += AUFS_WH_PFX_LEN;
9635 + namelen -= AUFS_WH_PFX_LEN;
9636 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9637 + arg->err = au_nhash_append_wh
9638 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9639 + au_ftest_testempty(arg->flags, SHWH));
9643 + AuTraceErr(arg->err);
9647 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9650 + struct file *h_file;
9652 + h_file = au_h_open(dentry, arg->bindex,
9653 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9654 + /*file*/NULL, /*force_wr*/0);
9655 + err = PTR_ERR(h_file);
9656 + if (IS_ERR(h_file))
9660 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9661 + && !file_inode(h_file)->i_nlink)
9666 + au_fclr_testempty(arg->flags, CALLED);
9668 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9671 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9675 + au_sbr_put(dentry->d_sb, arg->bindex);
9680 +struct do_test_empty_args {
9682 + struct dentry *dentry;
9683 + struct test_empty_arg *arg;
9686 +static void call_do_test_empty(void *args)
9688 + struct do_test_empty_args *a = args;
9689 + *a->errp = do_test_empty(a->dentry, a->arg);
9692 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9695 + struct dentry *h_dentry;
9696 + struct inode *h_inode;
9698 + h_dentry = au_h_dptr(dentry, arg->bindex);
9699 + h_inode = h_dentry->d_inode;
9700 + /* todo: i_mode changes anytime? */
9701 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
9702 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
9703 + mutex_unlock(&h_inode->i_mutex);
9705 + err = do_test_empty(dentry, arg);
9707 + struct do_test_empty_args args = {
9712 + unsigned int flags = arg->flags;
9714 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
9715 + if (unlikely(wkq_err))
9717 + arg->flags = flags;
9723 +int au_test_empty_lower(struct dentry *dentry)
9726 + unsigned int rdhash;
9727 + aufs_bindex_t bindex, bstart, btail;
9728 + struct au_nhash whlist;
9729 + struct test_empty_arg arg = {
9731 + .actor = au_diractor(test_empty_cb)
9734 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
9736 + SiMustAnyLock(dentry->d_sb);
9738 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
9740 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
9741 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
9742 + if (unlikely(err))
9746 + arg.whlist = &whlist;
9747 + bstart = au_dbstart(dentry);
9748 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9749 + au_fset_testempty(arg.flags, SHWH);
9750 + test_empty = do_test_empty;
9751 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
9752 + test_empty = sio_test_empty;
9753 + arg.bindex = bstart;
9754 + err = test_empty(dentry, &arg);
9755 + if (unlikely(err))
9758 + au_fset_testempty(arg.flags, WHONLY);
9759 + btail = au_dbtaildir(dentry);
9760 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
9761 + struct dentry *h_dentry;
9763 + h_dentry = au_h_dptr(dentry, bindex);
9764 + if (h_dentry && h_dentry->d_inode) {
9765 + arg.bindex = bindex;
9766 + err = test_empty(dentry, &arg);
9771 + au_nhash_wh_free(&whlist);
9776 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
9779 + struct test_empty_arg arg = {
9781 + .actor = au_diractor(test_empty_cb)
9784 + aufs_bindex_t bindex, btail;
9787 + arg.whlist = whlist;
9788 + arg.flags = AuTestEmpty_WHONLY;
9789 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
9790 + au_fset_testempty(arg.flags, SHWH);
9791 + btail = au_dbtaildir(dentry);
9792 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
9793 + struct dentry *h_dentry;
9795 + h_dentry = au_h_dptr(dentry, bindex);
9796 + if (h_dentry && h_dentry->d_inode) {
9797 + arg.bindex = bindex;
9798 + err = sio_test_empty(dentry, &arg);
9805 +/* ---------------------------------------------------------------------- */
9807 +const struct file_operations aufs_dir_fop = {
9808 + .owner = THIS_MODULE,
9809 + .llseek = default_llseek,
9810 + .read = generic_read_dir,
9811 + .iterate = aufs_iterate,
9812 + .unlocked_ioctl = aufs_ioctl_dir,
9813 +#ifdef CONFIG_COMPAT
9814 + .compat_ioctl = aufs_compat_ioctl_dir,
9816 + .open = aufs_open_dir,
9817 + .release = aufs_release_dir,
9818 + .flush = aufs_flush_dir,
9819 + .fsync = aufs_fsync_dir
9821 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
9822 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
9823 +++ linux/fs/aufs/dir.h 2014-01-30 21:10:02.830814411 +0100
9826 + * Copyright (C) 2005-2014 Junjiro R. Okajima
9828 + * This program, aufs is free software; you can redistribute it and/or modify
9829 + * it under the terms of the GNU General Public License as published by
9830 + * the Free Software Foundation; either version 2 of the License, or
9831 + * (at your option) any later version.
9833 + * This program is distributed in the hope that it will be useful,
9834 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9835 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9836 + * GNU General Public License for more details.
9838 + * You should have received a copy of the GNU General Public License
9839 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9843 + * directory operations
9846 +#ifndef __AUFS_DIR_H__
9847 +#define __AUFS_DIR_H__
9851 +#include <linux/fs.h>
9853 +/* ---------------------------------------------------------------------- */
9855 +/* need to be faster and smaller */
9858 + unsigned int nh_num;
9859 + struct hlist_head *nh_head;
9862 +struct au_vdir_destr {
9863 + unsigned char len;
9864 + unsigned char name[0];
9867 +struct au_vdir_dehstr {
9868 + struct hlist_node hash;
9869 + struct au_vdir_destr *str;
9870 +} ____cacheline_aligned_in_smp;
9872 +struct au_vdir_de {
9874 + unsigned char de_type;
9875 + /* caution: packed */
9876 + struct au_vdir_destr de_str;
9879 +struct au_vdir_wh {
9880 + struct hlist_node wh_hash;
9881 +#ifdef CONFIG_AUFS_SHWH
9883 + aufs_bindex_t wh_bindex;
9884 + unsigned char wh_type;
9886 + aufs_bindex_t wh_bindex;
9888 + /* caution: packed */
9889 + struct au_vdir_destr wh_str;
9892 +union au_vdir_deblk_p {
9893 + unsigned char *deblk;
9894 + struct au_vdir_de *de;
9898 + unsigned char **vd_deblk;
9899 + unsigned long vd_nblk;
9902 + union au_vdir_deblk_p p;
9905 + unsigned long vd_version;
9906 + unsigned int vd_deblk_sz;
9907 + unsigned long vd_jiffy;
9908 +} ____cacheline_aligned_in_smp;
9910 +/* ---------------------------------------------------------------------- */
9913 +extern const struct file_operations aufs_dir_fop;
9914 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
9915 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
9916 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
9917 +int au_test_empty_lower(struct dentry *dentry);
9918 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
9921 +unsigned int au_rdhash_est(loff_t sz);
9922 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
9923 +void au_nhash_wh_free(struct au_nhash *whlist);
9924 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
9926 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
9927 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
9928 + unsigned int d_type, aufs_bindex_t bindex,
9929 + unsigned char shwh);
9930 +void au_vdir_free(struct au_vdir *vdir);
9931 +int au_vdir_init(struct file *file);
9932 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
9935 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
9937 +#ifdef CONFIG_AUFS_RDU
9939 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
9940 +#ifdef CONFIG_COMPAT
9941 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9942 + unsigned long arg);
9945 +static inline long au_rdu_ioctl(struct file *file, unsigned int cmd,
9946 + unsigned long arg)
9950 +#ifdef CONFIG_COMPAT
9951 +static inline long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
9952 + unsigned long arg)
9959 +#endif /* __KERNEL__ */
9960 +#endif /* __AUFS_DIR_H__ */
9961 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
9962 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
9963 +++ linux/fs/aufs/dynop.c 2014-01-30 21:10:02.830814411 +0100
9966 + * Copyright (C) 2010-2014 Junjiro R. Okajima
9968 + * This program, aufs is free software; you can redistribute it and/or modify
9969 + * it under the terms of the GNU General Public License as published by
9970 + * the Free Software Foundation; either version 2 of the License, or
9971 + * (at your option) any later version.
9973 + * This program is distributed in the hope that it will be useful,
9974 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9975 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9976 + * GNU General Public License for more details.
9978 + * You should have received a copy of the GNU General Public License
9979 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9983 + * dynamically customizable operations for regular files
9988 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
9991 + * How large will these lists be?
9992 + * Usually just a few elements, 20-30 at most for each, I guess.
9994 +static struct au_splhead dynop[AuDyLast];
9996 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
9998 + struct au_dykey *key, *tmp;
9999 + struct list_head *head;
10002 + head = &spl->head;
10004 + list_for_each_entry_rcu(tmp, head, dk_list)
10005 + if (tmp->dk_op.dy_hop == h_op) {
10007 + kref_get(&key->dk_kref);
10010 + rcu_read_unlock();
10015 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10017 + struct au_dykey **k, *found;
10018 + const void *h_op = key->dk_op.dy_hop;
10022 + k = br->br_dykey;
10023 + for (i = 0; i < AuBrDynOp; i++)
10025 + if (k[i]->dk_op.dy_hop == h_op) {
10032 + spin_lock(&br->br_dykey_lock);
10033 + for (; i < AuBrDynOp; i++)
10035 + if (k[i]->dk_op.dy_hop == h_op) {
10043 + spin_unlock(&br->br_dykey_lock);
10044 + BUG_ON(i == AuBrDynOp); /* expand the array */
10050 +/* kref_get() if @key is already added */
10051 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
10053 + struct au_dykey *tmp, *found;
10054 + struct list_head *head;
10055 + const void *h_op = key->dk_op.dy_hop;
10058 + head = &spl->head;
10059 + spin_lock(&spl->spin);
10060 + list_for_each_entry(tmp, head, dk_list)
10061 + if (tmp->dk_op.dy_hop == h_op) {
10062 + kref_get(&tmp->dk_kref);
10067 + list_add_rcu(&key->dk_list, head);
10068 + spin_unlock(&spl->spin);
10075 +static void dy_free_rcu(struct rcu_head *rcu)
10077 + struct au_dykey *key;
10079 + key = container_of(rcu, struct au_dykey, dk_rcu);
10084 +static void dy_free(struct kref *kref)
10086 + struct au_dykey *key;
10087 + struct au_splhead *spl;
10089 + key = container_of(kref, struct au_dykey, dk_kref);
10090 + spl = dynop + key->dk_op.dy_type;
10091 + au_spl_del_rcu(&key->dk_list, spl);
10092 + call_rcu(&key->dk_rcu, dy_free_rcu);
10095 +void au_dy_put(struct au_dykey *key)
10097 + kref_put(&key->dk_kref, dy_free);
10100 +/* ---------------------------------------------------------------------- */
10102 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10104 +#ifdef CONFIG_AUFS_DEBUG
10105 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10106 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10108 +#define DyDbgDeclare(cnt) do {} while (0)
10109 +#define DyDbgInc(cnt) do {} while (0)
10112 +#define DySet(func, dst, src, h_op, h_sb) do { \
10114 + if (h_op->func) { \
10116 + dst.func = src.func; \
10118 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10122 +#define DySetForce(func, dst, src) do { \
10123 + AuDebugOn(!src.func); \
10125 + dst.func = src.func; \
10128 +#define DySetAop(func) \
10129 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10130 +#define DySetAopForce(func) \
10131 + DySetForce(func, dyaop->da_op, aufs_aop)
10133 +static void dy_aop(struct au_dykey *key, const void *h_op,
10134 + struct super_block *h_sb __maybe_unused)
10136 + struct au_dyaop *dyaop = (void *)key;
10137 + const struct address_space_operations *h_aop = h_op;
10138 + DyDbgDeclare(cnt);
10140 + AuDbg("%s\n", au_sbtype(h_sb));
10142 + DySetAop(writepage);
10143 + DySetAopForce(readpage); /* force */
10144 + DySetAop(writepages);
10145 + DySetAop(set_page_dirty);
10146 + DySetAop(readpages);
10147 + DySetAop(write_begin);
10148 + DySetAop(write_end);
10150 + DySetAop(invalidatepage);
10151 + DySetAop(releasepage);
10152 + DySetAop(freepage);
10153 + /* these two will be changed according to an aufs mount option */
10154 + DySetAop(direct_IO);
10155 + DySetAop(get_xip_mem);
10156 + DySetAop(migratepage);
10157 + DySetAop(launder_page);
10158 + DySetAop(is_partially_uptodate);
10159 + DySetAop(is_dirty_writeback);
10160 + DySetAop(error_remove_page);
10161 + DySetAop(swap_activate);
10162 + DySetAop(swap_deactivate);
10164 + DyDbgSize(cnt, *h_aop);
10165 + dyaop->da_get_xip_mem = h_aop->get_xip_mem;
10168 +/* ---------------------------------------------------------------------- */
10170 +static void dy_bug(struct kref *kref)
10175 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10177 + struct au_dykey *key, *old;
10178 + struct au_splhead *spl;
10181 + void (*set)(struct au_dykey *key, const void *h_op,
10182 + struct super_block *h_sb __maybe_unused);
10184 + static const struct op a[] = {
10186 + .sz = sizeof(struct au_dyaop),
10190 + const struct op *p;
10192 + spl = dynop + op->dy_type;
10193 + key = dy_gfind_get(spl, op->dy_hop);
10195 + goto out_add; /* success */
10197 + p = a + op->dy_type;
10198 + key = kzalloc(p->sz, GFP_NOFS);
10199 + if (unlikely(!key)) {
10200 + key = ERR_PTR(-ENOMEM);
10204 + key->dk_op.dy_hop = op->dy_hop;
10205 + kref_init(&key->dk_kref);
10206 + p->set(key, op->dy_hop, au_br_sb(br));
10207 + old = dy_gadd(spl, key);
10214 + old = dy_bradd(br, key);
10216 + /* its ref-count should never be zero here */
10217 + kref_put(&key->dk_kref, dy_bug);
10222 +/* ---------------------------------------------------------------------- */
10224 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10225 + * This behaviour is neccessary to return an error from open(O_DIRECT) instead
10226 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10227 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10228 + * See the aufs manual in detail.
10230 + * To keep this behaviour, aufs has to set NULL to ->get_xip_mem too, and the
10231 + * performance of fadvise() and madvise() may be affected.
10233 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10236 + dyaop->da_op.direct_IO = NULL;
10237 + dyaop->da_op.get_xip_mem = NULL;
10239 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10240 + dyaop->da_op.get_xip_mem = aufs_aop.get_xip_mem;
10241 + if (!dyaop->da_get_xip_mem)
10242 + dyaop->da_op.get_xip_mem = NULL;
10246 +static struct au_dyaop *dy_aget(struct au_branch *br,
10247 + const struct address_space_operations *h_aop,
10250 + struct au_dyaop *dyaop;
10251 + struct au_dynop op;
10253 + op.dy_type = AuDy_AOP;
10254 + op.dy_haop = h_aop;
10255 + dyaop = (void *)dy_get(&op, br);
10256 + if (IS_ERR(dyaop))
10258 + dy_adx(dyaop, do_dx);
10264 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10265 + struct inode *h_inode)
10268 + struct super_block *sb;
10269 + struct au_branch *br;
10270 + struct au_dyaop *dyaop;
10272 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10273 + IiMustWriteLock(inode);
10275 + sb = inode->i_sb;
10276 + br = au_sbr(sb, bindex);
10277 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10278 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10279 + err = PTR_ERR(dyaop);
10280 + if (IS_ERR(dyaop))
10281 + /* unnecessary to call dy_fput() */
10285 + inode->i_mapping->a_ops = &dyaop->da_op;
10292 + * Is it safe to replace a_ops during the inode/file is in operation?
10293 + * Yes, I hope so.
10295 +int au_dy_irefresh(struct inode *inode)
10298 + aufs_bindex_t bstart;
10299 + struct inode *h_inode;
10302 + if (S_ISREG(inode->i_mode)) {
10303 + bstart = au_ibstart(inode);
10304 + h_inode = au_h_iptr(inode, bstart);
10305 + err = au_dy_iaop(inode, bstart, h_inode);
10310 +void au_dy_arefresh(int do_dx)
10312 + struct au_splhead *spl;
10313 + struct list_head *head;
10314 + struct au_dykey *key;
10316 + spl = dynop + AuDy_AOP;
10317 + head = &spl->head;
10318 + spin_lock(&spl->spin);
10319 + list_for_each_entry(key, head, dk_list)
10320 + dy_adx((void *)key, do_dx);
10321 + spin_unlock(&spl->spin);
10324 +/* ---------------------------------------------------------------------- */
10326 +void __init au_dy_init(void)
10330 + /* make sure that 'struct au_dykey *' can be any type */
10331 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10333 + for (i = 0; i < AuDyLast; i++)
10334 + au_spl_init(dynop + i);
10337 +void au_dy_fin(void)
10341 + for (i = 0; i < AuDyLast; i++)
10342 + WARN_ON(!list_empty(&dynop[i].head));
10344 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10345 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10346 +++ linux/fs/aufs/dynop.h 2014-01-30 21:10:02.830814411 +0100
10349 + * Copyright (C) 2010-2014 Junjiro R. Okajima
10351 + * This program, aufs is free software; you can redistribute it and/or modify
10352 + * it under the terms of the GNU General Public License as published by
10353 + * the Free Software Foundation; either version 2 of the License, or
10354 + * (at your option) any later version.
10356 + * This program is distributed in the hope that it will be useful,
10357 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10358 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10359 + * GNU General Public License for more details.
10361 + * You should have received a copy of the GNU General Public License
10362 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10366 + * dynamically customizable operations (for regular files only)
10369 +#ifndef __AUFS_DYNOP_H__
10370 +#define __AUFS_DYNOP_H__
10374 +#include "inode.h"
10376 +enum {AuDy_AOP, AuDyLast};
10381 + const void *dy_hop;
10382 + const struct address_space_operations *dy_haop;
10388 + struct list_head dk_list;
10389 + struct rcu_head dk_rcu;
10391 + struct au_dynop dk_op;
10394 + * during I am in the branch local array, kref is gotten. when the
10395 + * branch is removed, kref is put.
10397 + struct kref dk_kref;
10400 +/* stop unioning since their sizes are very different from each other */
10402 + struct au_dykey da_key;
10403 + struct address_space_operations da_op; /* not const */
10404 + int (*da_get_xip_mem)(struct address_space *, pgoff_t, int,
10405 + void **, unsigned long *);
10408 +/* ---------------------------------------------------------------------- */
10412 +void au_dy_put(struct au_dykey *key);
10413 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10414 + struct inode *h_inode);
10415 +int au_dy_irefresh(struct inode *inode);
10416 +void au_dy_arefresh(int do_dio);
10418 +void __init au_dy_init(void);
10419 +void au_dy_fin(void);
10421 +#endif /* __KERNEL__ */
10422 +#endif /* __AUFS_DYNOP_H__ */
10423 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10424 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10425 +++ linux/fs/aufs/export.c 2014-01-30 21:10:02.830814411 +0100
10428 + * Copyright (C) 2005-2014 Junjiro R. Okajima
10430 + * This program, aufs is free software; you can redistribute it and/or modify
10431 + * it under the terms of the GNU General Public License as published by
10432 + * the Free Software Foundation; either version 2 of the License, or
10433 + * (at your option) any later version.
10435 + * This program is distributed in the hope that it will be useful,
10436 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10437 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10438 + * GNU General Public License for more details.
10440 + * You should have received a copy of the GNU General Public License
10441 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10448 +#include <linux/exportfs.h>
10449 +#include <linux/fs_struct.h>
10450 +#include <linux/namei.h>
10451 +#include <linux/nsproxy.h>
10452 +#include <linux/random.h>
10453 +#include <linux/writeback.h>
10454 +#include "../fs/mount.h"
10458 +#ifdef CONFIG_AUFS_INO_T_64
10466 +static ino_t decode_ino(__u32 *a)
10470 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10472 +#ifdef CONFIG_AUFS_INO_T_64
10478 +static void encode_ino(__u32 *a, ino_t ino)
10484 +#ifdef CONFIG_AUFS_INO_T_64
10489 +/* NFS file handle */
10493 +#ifdef CONFIG_AUFS_INO_T_64
10494 + /* support 64bit inode number */
10507 + Fh_ino = Fh_ino1,
10508 + Fh_dir_ino = Fh_dir_ino1
10511 +static int au_test_anon(struct dentry *dentry)
10513 + /* note: read d_flags without d_lock */
10514 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10517 +int au_test_nfsd(void)
10520 + struct task_struct *tsk = current;
10521 + char comm[sizeof(tsk->comm)];
10524 + if (tsk->flags & PF_KTHREAD) {
10525 + get_task_comm(comm, tsk);
10526 + ret = !strcmp(comm, "nfsd");
10532 +/* ---------------------------------------------------------------------- */
10533 +/* inode generation external table */
10535 +void au_xigen_inc(struct inode *inode)
10540 + struct super_block *sb;
10541 + struct au_sbinfo *sbinfo;
10543 + sb = inode->i_sb;
10544 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10546 + sbinfo = au_sbi(sb);
10547 + pos = inode->i_ino;
10548 + pos *= sizeof(igen);
10549 + igen = inode->i_generation + 1;
10550 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10551 + sizeof(igen), &pos);
10552 + if (sz == sizeof(igen))
10553 + return; /* success */
10555 + if (unlikely(sz >= 0))
10556 + AuIOErr("xigen error (%zd)\n", sz);
10559 +int au_xigen_new(struct inode *inode)
10564 + struct super_block *sb;
10565 + struct au_sbinfo *sbinfo;
10566 + struct file *file;
10569 + /* todo: dirty, at mount time */
10570 + if (inode->i_ino == AUFS_ROOT_INO)
10572 + sb = inode->i_sb;
10573 + SiMustAnyLock(sb);
10574 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10578 + pos = inode->i_ino;
10579 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10580 + AuIOErr1("too large i%lld\n", pos);
10583 + pos *= sizeof(inode->i_generation);
10586 + sbinfo = au_sbi(sb);
10587 + file = sbinfo->si_xigen;
10590 + if (vfsub_f_size_read(file)
10591 + < pos + sizeof(inode->i_generation)) {
10592 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10593 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10594 + sizeof(inode->i_generation), &pos);
10596 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10597 + sizeof(inode->i_generation), &pos);
10598 + if (sz == sizeof(inode->i_generation))
10599 + goto out; /* success */
10602 + if (unlikely(sz >= 0)) {
10604 + AuIOErr("xigen error (%zd)\n", sz);
10611 +int au_xigen_set(struct super_block *sb, struct file *base)
10614 + struct au_sbinfo *sbinfo;
10615 + struct file *file;
10617 + SiMustWriteLock(sb);
10619 + sbinfo = au_sbi(sb);
10620 + file = au_xino_create2(base, sbinfo->si_xigen);
10621 + err = PTR_ERR(file);
10622 + if (IS_ERR(file))
10625 + if (sbinfo->si_xigen)
10626 + fput(sbinfo->si_xigen);
10627 + sbinfo->si_xigen = file;
10633 +void au_xigen_clr(struct super_block *sb)
10635 + struct au_sbinfo *sbinfo;
10637 + SiMustWriteLock(sb);
10639 + sbinfo = au_sbi(sb);
10640 + if (sbinfo->si_xigen) {
10641 + fput(sbinfo->si_xigen);
10642 + sbinfo->si_xigen = NULL;
10646 +/* ---------------------------------------------------------------------- */
10648 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10651 + struct dentry *dentry, *d;
10652 + struct inode *inode;
10653 + unsigned int sigen;
10656 + inode = ilookup(sb, ino);
10660 + dentry = ERR_PTR(-ESTALE);
10661 + sigen = au_sigen(sb);
10662 + if (unlikely(is_bad_inode(inode)
10663 + || IS_DEADDIR(inode)
10664 + || sigen != au_iigen(inode, NULL)))
10668 + if (!dir_ino || S_ISDIR(inode->i_mode))
10669 + dentry = d_find_alias(inode);
10671 + spin_lock(&inode->i_lock);
10672 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
10673 + spin_lock(&d->d_lock);
10674 + if (!au_test_anon(d)
10675 + && d->d_parent->d_inode->i_ino == dir_ino) {
10676 + dentry = dget_dlock(d);
10677 + spin_unlock(&d->d_lock);
10680 + spin_unlock(&d->d_lock);
10682 + spin_unlock(&inode->i_lock);
10684 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10685 + /* need to refresh */
10693 + AuTraceErrPtr(dentry);
10697 +/* ---------------------------------------------------------------------- */
10699 +/* todo: dirty? */
10700 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10702 +struct au_compare_mnt_args {
10704 + struct super_block *sb;
10707 + struct vfsmount *mnt;
10710 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
10712 + struct au_compare_mnt_args *a = arg;
10714 + if (mnt->mnt_sb != a->sb)
10716 + a->mnt = mntget(mnt);
10720 +static struct vfsmount *au_mnt_get(struct super_block *sb)
10723 + struct path root;
10724 + struct au_compare_mnt_args args = {
10728 + get_fs_root(current->fs, &root);
10730 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
10731 + rcu_read_unlock();
10734 + AuDebugOn(!args.mnt);
10738 +struct au_nfsd_si_lock {
10739 + unsigned int sigen;
10740 + aufs_bindex_t bindex, br_id;
10741 + unsigned char force_lock;
10744 +static int si_nfsd_read_lock(struct super_block *sb,
10745 + struct au_nfsd_si_lock *nsi_lock)
10748 + aufs_bindex_t bindex;
10750 + si_read_lock(sb, AuLock_FLUSH);
10752 + /* branch id may be wrapped around */
10754 + bindex = au_br_index(sb, nsi_lock->br_id);
10755 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
10756 + goto out; /* success */
10760 + if (!nsi_lock->force_lock)
10761 + si_read_unlock(sb);
10764 + nsi_lock->bindex = bindex;
10768 +struct find_name_by_ino {
10769 + struct dir_context ctx;
10770 + int called, found;
10777 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
10778 + loff_t offset, u64 ino, unsigned int d_type)
10780 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
10784 + if (a->ino != ino)
10787 + memcpy(a->name, name, namelen);
10788 + a->namelen = namelen;
10793 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
10794 + struct au_nfsd_si_lock *nsi_lock)
10796 + struct dentry *dentry, *parent;
10797 + struct file *file;
10798 + struct inode *dir;
10799 + struct find_name_by_ino arg = {
10801 + .actor = au_diractor(find_name_by_ino)
10806 + parent = path->dentry;
10808 + si_read_unlock(parent->d_sb);
10809 + file = vfsub_dentry_open(path, au_dir_roflags);
10810 + dentry = (void *)file;
10811 + if (IS_ERR(file))
10814 + dentry = ERR_PTR(-ENOMEM);
10815 + arg.name = (void *)__get_free_page(GFP_NOFS);
10816 + if (unlikely(!arg.name))
10823 + err = vfsub_iterate_dir(file, &arg.ctx);
10824 + } while (!err && !arg.found && arg.called);
10825 + dentry = ERR_PTR(err);
10826 + if (unlikely(err))
10828 + /* instead of ENOENT */
10829 + dentry = ERR_PTR(-ESTALE);
10833 + /* do not call vfsub_lkup_one() */
10834 + dir = parent->d_inode;
10835 + mutex_lock(&dir->i_mutex);
10836 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
10837 + mutex_unlock(&dir->i_mutex);
10838 + AuTraceErrPtr(dentry);
10839 + if (IS_ERR(dentry))
10841 + AuDebugOn(au_test_anon(dentry));
10842 + if (unlikely(!dentry->d_inode)) {
10844 + dentry = ERR_PTR(-ENOENT);
10848 + free_page((unsigned long)arg.name);
10852 + if (unlikely(nsi_lock
10853 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
10854 + if (!IS_ERR(dentry)) {
10856 + dentry = ERR_PTR(-ESTALE);
10858 + AuTraceErrPtr(dentry);
10862 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
10864 + struct au_nfsd_si_lock *nsi_lock)
10866 + struct dentry *dentry;
10867 + struct path path;
10869 + if (dir_ino != AUFS_ROOT_INO) {
10870 + path.dentry = decode_by_ino(sb, dir_ino, 0);
10871 + dentry = path.dentry;
10872 + if (!path.dentry || IS_ERR(path.dentry))
10874 + AuDebugOn(au_test_anon(path.dentry));
10876 + path.dentry = dget(sb->s_root);
10878 + path.mnt = au_mnt_get(sb);
10879 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
10883 + AuTraceErrPtr(dentry);
10887 +/* ---------------------------------------------------------------------- */
10889 +static int h_acceptable(void *expv, struct dentry *dentry)
10894 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
10895 + char *buf, int len, struct super_block *sb)
10899 + struct path path;
10901 + p = d_path(h_rootpath, buf, len);
10906 + path.mnt = h_rootpath->mnt;
10907 + path.dentry = h_parent;
10908 + p = d_path(&path, buf, len);
10914 + path.mnt = au_mnt_get(sb);
10915 + path.dentry = sb->s_root;
10916 + p = d_path(&path, buf, len - strlen(p));
10917 + mntput(path.mnt);
10921 + p[strlen(p)] = '/';
10924 + AuTraceErrPtr(p);
10929 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
10930 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
10932 + struct dentry *dentry, *h_parent, *root;
10933 + struct super_block *h_sb;
10934 + char *pathname, *p;
10935 + struct vfsmount *h_mnt;
10936 + struct au_branch *br;
10938 + struct path path;
10940 + br = au_sbr(sb, nsi_lock->bindex);
10941 + h_mnt = au_br_mnt(br);
10942 + h_sb = h_mnt->mnt_sb;
10943 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
10944 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
10945 + fh_len - Fh_tail, fh[Fh_h_type],
10946 + h_acceptable, /*context*/NULL);
10947 + dentry = h_parent;
10948 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
10949 + AuWarn1("%s decode_fh failed, %ld\n",
10950 + au_sbtype(h_sb), PTR_ERR(h_parent));
10954 + if (unlikely(au_test_anon(h_parent))) {
10955 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
10956 + au_sbtype(h_sb));
10957 + goto out_h_parent;
10960 + dentry = ERR_PTR(-ENOMEM);
10961 + pathname = (void *)__get_free_page(GFP_NOFS);
10962 + if (unlikely(!pathname))
10963 + goto out_h_parent;
10965 + root = sb->s_root;
10966 + path.mnt = h_mnt;
10967 + di_read_lock_parent(root, !AuLock_IR);
10968 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
10969 + di_read_unlock(root, !AuLock_IR);
10970 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
10971 + dentry = (void *)p;
10973 + goto out_pathname;
10975 + si_read_unlock(sb);
10976 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
10977 + dentry = ERR_PTR(err);
10978 + if (unlikely(err))
10981 + dentry = ERR_PTR(-ENOENT);
10982 + AuDebugOn(au_test_anon(path.dentry));
10983 + if (unlikely(!path.dentry->d_inode))
10986 + if (ino != path.dentry->d_inode->i_ino)
10987 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
10989 + dentry = dget(path.dentry);
10994 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
10995 + if (!IS_ERR(dentry)) {
10997 + dentry = ERR_PTR(-ESTALE);
11000 + free_page((unsigned long)pathname);
11004 + AuTraceErrPtr(dentry);
11008 +/* ---------------------------------------------------------------------- */
11010 +static struct dentry *
11011 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11014 + struct dentry *dentry;
11015 + __u32 *fh = fid->raw;
11016 + struct au_branch *br;
11017 + ino_t ino, dir_ino;
11018 + struct au_nfsd_si_lock nsi_lock = {
11022 + dentry = ERR_PTR(-ESTALE);
11023 + /* it should never happen, but the file handle is unreliable */
11024 + if (unlikely(fh_len < Fh_tail))
11026 + nsi_lock.sigen = fh[Fh_sigen];
11027 + nsi_lock.br_id = fh[Fh_br_id];
11029 + /* branch id may be wrapped around */
11031 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11033 + nsi_lock.force_lock = 1;
11035 + /* is this inode still cached? */
11036 + ino = decode_ino(fh + Fh_ino);
11037 + /* it should never happen */
11038 + if (unlikely(ino == AUFS_ROOT_INO))
11041 + dir_ino = decode_ino(fh + Fh_dir_ino);
11042 + dentry = decode_by_ino(sb, ino, dir_ino);
11043 + if (IS_ERR(dentry))
11048 + /* is the parent dir cached? */
11049 + br = au_sbr(sb, nsi_lock.bindex);
11050 + atomic_inc(&br->br_count);
11051 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11052 + if (IS_ERR(dentry))
11057 + /* lookup path */
11058 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11059 + if (IS_ERR(dentry))
11061 + if (unlikely(!dentry))
11062 + /* todo?: make it ESTALE */
11066 + if (!au_digen_test(dentry, au_sigen(sb))
11067 + && dentry->d_inode->i_generation == fh[Fh_igen])
11068 + goto out_unlock; /* success */
11071 + dentry = ERR_PTR(-ESTALE);
11074 + atomic_dec(&br->br_count);
11075 + si_read_unlock(sb);
11077 + AuTraceErrPtr(dentry);
11081 +#if 0 /* reserved for future use */
11082 +/* support subtreecheck option */
11083 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11084 + int fh_len, int fh_type)
11086 + struct dentry *parent;
11087 + __u32 *fh = fid->raw;
11090 + dir_ino = decode_ino(fh + Fh_dir_ino);
11091 + parent = decode_by_ino(sb, dir_ino, 0);
11092 + if (IS_ERR(parent))
11095 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11096 + dir_ino, fh, fh_len);
11099 + AuTraceErrPtr(parent);
11104 +/* ---------------------------------------------------------------------- */
11106 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11107 + struct inode *dir)
11110 + aufs_bindex_t bindex;
11111 + struct super_block *sb, *h_sb;
11112 + struct dentry *dentry, *parent, *h_parent;
11113 + struct inode *h_dir;
11114 + struct au_branch *br;
11117 + if (unlikely(*max_len <= Fh_tail)) {
11118 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11122 + err = FILEID_ROOT;
11123 + if (inode->i_ino == AUFS_ROOT_INO) {
11124 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11129 + sb = inode->i_sb;
11130 + err = si_read_lock(sb, AuLock_FLUSH);
11131 + if (unlikely(err))
11134 +#ifdef CONFIG_AUFS_DEBUG
11135 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11136 + AuWarn1("NFS-exporting requires xino\n");
11140 + ii_read_lock_child(inode);
11141 + bindex = au_ibstart(inode);
11143 + dentry = d_find_alias(inode);
11144 + if (unlikely(!dentry))
11146 + AuDebugOn(au_test_anon(dentry));
11147 + parent = dget_parent(dentry);
11149 + if (unlikely(!parent))
11151 + dir = parent->d_inode;
11154 + ii_read_lock_parent(dir);
11155 + h_dir = au_h_iptr(dir, bindex);
11156 + ii_read_unlock(dir);
11157 + if (unlikely(!h_dir))
11159 + h_parent = d_find_alias(h_dir);
11160 + if (unlikely(!h_parent))
11161 + goto out_hparent;
11164 + br = au_sbr(sb, bindex);
11165 + h_sb = au_br_sb(br);
11166 + if (unlikely(!h_sb->s_export_op)) {
11167 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11168 + goto out_hparent;
11171 + fh[Fh_br_id] = br->br_id;
11172 + fh[Fh_sigen] = au_sigen(sb);
11173 + encode_ino(fh + Fh_ino, inode->i_ino);
11174 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11175 + fh[Fh_igen] = inode->i_generation;
11177 + *max_len -= Fh_tail;
11178 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11180 + /*connectable or subtreecheck*/0);
11181 + err = fh[Fh_h_type];
11182 + *max_len += Fh_tail;
11183 + /* todo: macros? */
11184 + if (err != FILEID_INVALID)
11187 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11194 + ii_read_unlock(inode);
11195 + si_read_unlock(sb);
11197 + if (unlikely(err < 0))
11198 + err = FILEID_INVALID;
11202 +/* ---------------------------------------------------------------------- */
11204 +static int aufs_commit_metadata(struct inode *inode)
11207 + aufs_bindex_t bindex;
11208 + struct super_block *sb;
11209 + struct inode *h_inode;
11210 + int (*f)(struct inode *inode);
11212 + sb = inode->i_sb;
11213 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11214 + ii_write_lock_child(inode);
11215 + bindex = au_ibstart(inode);
11216 + AuDebugOn(bindex < 0);
11217 + h_inode = au_h_iptr(inode, bindex);
11219 + f = h_inode->i_sb->s_export_op->commit_metadata;
11221 + err = f(h_inode);
11223 + struct writeback_control wbc = {
11224 + .sync_mode = WB_SYNC_ALL,
11225 + .nr_to_write = 0 /* metadata only */
11228 + err = sync_inode(h_inode, &wbc);
11231 + au_cpup_attr_timesizes(inode);
11232 + ii_write_unlock(inode);
11233 + si_read_unlock(sb);
11237 +/* ---------------------------------------------------------------------- */
11239 +static struct export_operations aufs_export_op = {
11240 + .fh_to_dentry = aufs_fh_to_dentry,
11241 + /* .fh_to_parent = aufs_fh_to_parent, */
11242 + .encode_fh = aufs_encode_fh,
11243 + .commit_metadata = aufs_commit_metadata
11246 +void au_export_init(struct super_block *sb)
11248 + struct au_sbinfo *sbinfo;
11251 + sb->s_export_op = &aufs_export_op;
11252 + sbinfo = au_sbi(sb);
11253 + sbinfo->si_xigen = NULL;
11254 + get_random_bytes(&u, sizeof(u));
11255 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11256 + atomic_set(&sbinfo->si_xigen_next, u);
11258 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11259 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11260 +++ linux/fs/aufs/fhsm.c 2014-08-14 10:15:45.121942630 +0200
11263 + * Copyright (C) 2011-2014 Junjiro R. Okajima
11265 + * This program, aufs is free software; you can redistribute it and/or modify
11266 + * it under the terms of the GNU General Public License as published by
11267 + * the Free Software Foundation; either version 2 of the License, or
11268 + * (at your option) any later version.
11270 + * This program is distributed in the hope that it will be useful,
11271 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11272 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11273 + * GNU General Public License for more details.
11275 + * You should have received a copy of the GNU General Public License
11276 + * along with this program; if not, write to the Free Software
11277 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11281 + * File-based Hierarchy Storage Management
11284 +#include <linux/anon_inodes.h>
11285 +#include <linux/poll.h>
11286 +#include <linux/seq_file.h>
11287 +#include <linux/statfs.h>
11290 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11292 + struct au_br_fhsm *bf;
11294 + bf = br->br_fhsm;
11295 + MtxMustLock(&bf->bf_lock);
11297 + return !bf->bf_readable
11298 + || time_after(jiffies,
11299 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11302 +/* ---------------------------------------------------------------------- */
11304 +static void au_fhsm_notify(struct super_block *sb, int val)
11306 + struct au_sbinfo *sbinfo;
11307 + struct au_fhsm *fhsm;
11309 + SiMustAnyLock(sb);
11311 + sbinfo = au_sbi(sb);
11312 + fhsm = &sbinfo->si_fhsm;
11313 + if (au_fhsm_pid(fhsm)
11314 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11315 + atomic_set(&fhsm->fhsm_readable, val);
11317 + wake_up(&fhsm->fhsm_wqh);
11321 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11322 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11325 + struct au_branch *br;
11326 + struct au_br_fhsm *bf;
11328 + br = au_sbr(sb, bindex);
11329 + AuDebugOn(au_br_rdonly(br));
11330 + bf = br->br_fhsm;
11334 + mutex_lock(&bf->bf_lock);
11336 + MtxMustLock(&bf->bf_lock);
11338 + /* sb->s_root for NFS is unreliable */
11339 + err = au_br_stfs(br, &bf->bf_stfs);
11340 + if (unlikely(err)) {
11341 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11345 + bf->bf_jiffy = jiffies;
11346 + bf->bf_readable = 1;
11348 + au_fhsm_notify(sb, /*val*/1);
11350 + *rstfs = bf->bf_stfs;
11354 + mutex_unlock(&bf->bf_lock);
11355 + au_fhsm_notify(sb, /*val*/1);
11360 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11363 + unsigned char do_notify;
11364 + aufs_bindex_t bend, blower;
11365 + struct au_sbinfo *sbinfo;
11366 + struct au_fhsm *fhsm;
11367 + struct au_branch *br;
11368 + struct au_br_fhsm *bf;
11370 + AuDbg("b%d, force %d\n", bindex, force);
11371 + SiMustAnyLock(sb);
11373 + sbinfo = au_sbi(sb);
11374 + fhsm = &sbinfo->si_fhsm;
11375 + if (!au_ftest_si(sbinfo, FHSM))
11379 + bend = au_sbend(sb);
11380 + for (blower = bindex + 1; blower <= bend; blower++) {
11381 + br = au_sbr(sb, blower);
11382 + if (au_br_fhsm(br->br_perm)) {
11390 + br = au_sbr(sb, bindex);
11391 + bf = br->br_fhsm;
11393 + mutex_lock(&bf->bf_lock);
11395 + || au_fhsm_pid(fhsm)
11396 + || au_fhsm_test_jiffy(sbinfo, br))
11397 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11399 + mutex_unlock(&bf->bf_lock);
11402 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11404 + aufs_bindex_t bindex, bend;
11405 + struct au_branch *br;
11407 + /* exclude the bottom */
11408 + bend = au_sbend(sb);
11409 + for (bindex = 0; bindex < bend; bindex++) {
11410 + br = au_sbr(sb, bindex);
11411 + if (au_br_fhsm(br->br_perm))
11412 + au_fhsm_wrote(sb, bindex, force);
11416 +/* ---------------------------------------------------------------------- */
11418 +static unsigned int au_fhsm_poll(struct file *file,
11419 + struct poll_table_struct *wait)
11421 + unsigned int mask;
11422 + struct au_sbinfo *sbinfo;
11423 + struct au_fhsm *fhsm;
11426 + sbinfo = file->private_data;
11427 + fhsm = &sbinfo->si_fhsm;
11428 + poll_wait(file, &fhsm->fhsm_wqh, wait);
11429 + if (atomic_read(&fhsm->fhsm_readable))
11430 + mask = POLLIN /* | POLLRDNORM */;
11432 + AuTraceErr((int)mask);
11436 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
11437 + struct aufs_stfs *stfs, __s16 brid)
11441 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
11443 + err = __put_user(brid, &stbr->brid);
11444 + if (unlikely(err))
11450 +static ssize_t au_fhsm_do_read(struct super_block *sb,
11451 + struct aufs_stbr __user *stbr, size_t count)
11455 + aufs_bindex_t bindex, bend;
11456 + struct au_branch *br;
11457 + struct au_br_fhsm *bf;
11459 + /* except the bottom branch */
11462 + bend = au_sbend(sb);
11463 + for (bindex = 0; !err && bindex < bend; bindex++) {
11464 + br = au_sbr(sb, bindex);
11465 + if (!au_br_fhsm(br->br_perm))
11468 + bf = br->br_fhsm;
11469 + mutex_lock(&bf->bf_lock);
11470 + if (bf->bf_readable) {
11472 + if (count >= sizeof(*stbr))
11473 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
11476 + bf->bf_readable = 0;
11477 + count -= sizeof(*stbr);
11481 + mutex_unlock(&bf->bf_lock);
11484 + err = sizeof(*stbr) * nstbr;
11489 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
11494 + aufs_bindex_t nfhsm, bindex, bend;
11495 + struct au_sbinfo *sbinfo;
11496 + struct au_fhsm *fhsm;
11497 + struct au_branch *br;
11498 + struct super_block *sb;
11501 + sbinfo = file->private_data;
11502 + fhsm = &sbinfo->si_fhsm;
11504 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
11505 + if (!atomic_read(&fhsm->fhsm_readable)) {
11506 + if (vfsub_file_flags(file) & O_NONBLOCK)
11509 + err = wait_event_interruptible_locked_irq
11511 + atomic_read(&fhsm->fhsm_readable));
11513 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
11514 + if (unlikely(err))
11517 + /* sb may already be dead */
11518 + au_rw_read_lock(&sbinfo->si_rwsem);
11519 + readable = atomic_read(&fhsm->fhsm_readable);
11520 + if (readable > 0) {
11521 + sb = sbinfo->si_sb;
11523 + /* exclude the bottom branch */
11525 + bend = au_sbend(sb);
11526 + for (bindex = 0; bindex < bend; bindex++) {
11527 + br = au_sbr(sb, bindex);
11528 + if (au_br_fhsm(br->br_perm))
11532 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
11533 + atomic_set(&fhsm->fhsm_readable, 0);
11534 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
11538 + au_rw_read_unlock(&sbinfo->si_rwsem);
11546 +static int au_fhsm_release(struct inode *inode, struct file *file)
11548 + struct au_sbinfo *sbinfo;
11549 + struct au_fhsm *fhsm;
11551 + /* sb may already be dead */
11552 + sbinfo = file->private_data;
11553 + fhsm = &sbinfo->si_fhsm;
11554 + spin_lock(&fhsm->fhsm_spin);
11555 + fhsm->fhsm_pid = 0;
11556 + spin_unlock(&fhsm->fhsm_spin);
11557 + kobject_put(&sbinfo->si_kobj);
11562 +static const struct file_operations au_fhsm_fops = {
11563 + .owner = THIS_MODULE,
11564 + .llseek = noop_llseek,
11565 + .read = au_fhsm_read,
11566 + .poll = au_fhsm_poll,
11567 + .release = au_fhsm_release
11570 +int au_fhsm_fd(struct super_block *sb, int oflags)
11573 + struct au_sbinfo *sbinfo;
11574 + struct au_fhsm *fhsm;
11577 + if (unlikely(!capable(CAP_SYS_ADMIN)))
11581 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
11585 + sbinfo = au_sbi(sb);
11586 + fhsm = &sbinfo->si_fhsm;
11587 + spin_lock(&fhsm->fhsm_spin);
11588 + if (!fhsm->fhsm_pid)
11589 + fhsm->fhsm_pid = current->pid;
11592 + spin_unlock(&fhsm->fhsm_spin);
11593 + if (unlikely(err))
11596 + oflags |= O_RDONLY;
11597 + /* oflags |= FMODE_NONOTIFY; */
11598 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
11600 + if (unlikely(fd < 0))
11603 + /* succeed reglardless 'fhsm' status */
11604 + kobject_get(&sbinfo->si_kobj);
11605 + si_noflush_read_lock(sb);
11606 + if (au_ftest_si(sbinfo, FHSM))
11607 + au_fhsm_wrote_all(sb, /*force*/0);
11608 + si_read_unlock(sb);
11609 + goto out; /* success */
11612 + spin_lock(&fhsm->fhsm_spin);
11613 + fhsm->fhsm_pid = 0;
11614 + spin_unlock(&fhsm->fhsm_spin);
11620 +/* ---------------------------------------------------------------------- */
11622 +int au_fhsm_br_alloc(struct au_branch *br)
11627 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
11629 + au_br_fhsm_init(br->br_fhsm);
11636 +/* ---------------------------------------------------------------------- */
11638 +void au_fhsm_fin(struct super_block *sb)
11640 + au_fhsm_notify(sb, /*val*/-1);
11643 +void au_fhsm_init(struct au_sbinfo *sbinfo)
11645 + struct au_fhsm *fhsm;
11647 + fhsm = &sbinfo->si_fhsm;
11648 + spin_lock_init(&fhsm->fhsm_spin);
11649 + init_waitqueue_head(&fhsm->fhsm_wqh);
11650 + atomic_set(&fhsm->fhsm_readable, 0);
11651 + fhsm->fhsm_expire
11652 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
11655 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
11657 + sbinfo->si_fhsm.fhsm_expire
11658 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
11661 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
11665 + if (!au_ftest_si(sbinfo, FHSM))
11668 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
11669 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
11670 + seq_printf(seq, ",fhsm_sec=%u", u);
11672 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
11673 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
11674 +++ linux/fs/aufs/file.c 2014-08-14 10:16:04.515942371 +0200
11677 + * Copyright (C) 2005-2014 Junjiro R. Okajima
11679 + * This program, aufs is free software; you can redistribute it and/or modify
11680 + * it under the terms of the GNU General Public License as published by
11681 + * the Free Software Foundation; either version 2 of the License, or
11682 + * (at your option) any later version.
11684 + * This program is distributed in the hope that it will be useful,
11685 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11686 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11687 + * GNU General Public License for more details.
11689 + * You should have received a copy of the GNU General Public License
11690 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11694 + * handling file/dir, and address_space operation
11697 +#ifdef CONFIG_AUFS_DEBUG
11698 +#include <linux/migrate.h>
11700 +#include <linux/pagemap.h>
11703 +/* drop flags for writing */
11704 +unsigned int au_file_roflags(unsigned int flags)
11706 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
11707 + flags |= O_RDONLY | O_NOATIME;
11711 +/* common functions to regular file and dir */
11712 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11713 + struct file *file, int force_wr)
11715 + struct file *h_file;
11716 + struct dentry *h_dentry;
11717 + struct inode *h_inode;
11718 + struct super_block *sb;
11719 + struct au_branch *br;
11720 + struct path h_path;
11721 + int err, exec_flag;
11723 + /* a race condition can happen between open and unlink/rmdir */
11724 + h_file = ERR_PTR(-ENOENT);
11725 + h_dentry = au_h_dptr(dentry, bindex);
11726 + if (au_test_nfsd() && !h_dentry)
11728 + h_inode = h_dentry->d_inode;
11729 + if (au_test_nfsd() && !h_inode)
11731 + spin_lock(&h_dentry->d_lock);
11732 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
11734 + /* || !dentry->d_inode->i_nlink */
11736 + spin_unlock(&h_dentry->d_lock);
11737 + if (unlikely(err))
11740 + sb = dentry->d_sb;
11741 + br = au_sbr(sb, bindex);
11742 + h_file = ERR_PTR(-EACCES);
11743 + exec_flag = flags & __FMODE_EXEC;
11744 + if (exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC))
11747 + /* drop flags for writing */
11748 + if (au_test_ro(sb, bindex, dentry->d_inode)) {
11749 + if (force_wr && !(flags & O_WRONLY))
11751 + flags = au_file_roflags(flags);
11753 + h_file = ERR_PTR(-EROFS);
11754 + flags = au_file_roflags(flags);
11755 + if (unlikely(vfsub_native_ro(h_inode)
11756 + || IS_APPEND(h_inode)))
11758 + flags &= ~O_ACCMODE;
11759 + flags |= O_WRONLY;
11762 + flags &= ~O_CREAT;
11763 + atomic_inc(&br->br_count);
11764 + h_path.dentry = h_dentry;
11765 + h_path.mnt = au_br_mnt(br);
11766 + h_file = vfsub_dentry_open(&h_path, flags);
11767 + if (IS_ERR(h_file))
11771 + err = deny_write_access(h_file);
11772 + if (unlikely(err)) {
11774 + h_file = ERR_PTR(err);
11778 + fsnotify_open(h_file);
11779 + goto out; /* success */
11782 + atomic_dec(&br->br_count);
11787 +static int au_cmoo(struct dentry *dentry)
11790 + unsigned int udba;
11791 + struct path h_path;
11792 + struct au_pin pin;
11793 + struct au_cp_generic cpg = {
11794 + .dentry = dentry,
11799 + .flags = AuCpup_DTIME | AuCpup_HOPEN
11801 + struct inode *inode, *delegated;
11802 + struct super_block *sb;
11803 + struct au_sbinfo *sbinfo;
11804 + struct au_fhsm *fhsm;
11806 + struct au_branch *br;
11807 + struct dentry *parent;
11808 + struct au_hinode *hdir;
11810 + DiMustWriteLock(dentry);
11811 + inode = dentry->d_inode;
11812 + IiMustWriteLock(inode);
11815 + if (IS_ROOT(dentry))
11817 + cpg.bsrc = au_dbstart(dentry);
11821 + sb = dentry->d_sb;
11822 + sbinfo = au_sbi(sb);
11823 + fhsm = &sbinfo->si_fhsm;
11824 + pid = au_fhsm_pid(fhsm);
11826 + && (current->pid == pid
11827 + || current->real_parent->pid == pid))
11830 + br = au_sbr(sb, cpg.bsrc);
11831 + cmoo = au_br_cmoo(br->br_perm);
11834 + if (!S_ISREG(inode->i_mode))
11835 + cmoo &= AuBrAttr_COO_ALL;
11839 + parent = dget_parent(dentry);
11840 + di_write_lock_parent(parent);
11841 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
11843 + if (unlikely(err < 0)) {
11844 + err = 0; /* there is no upper writable branch */
11847 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
11849 + /* do not respect the coo attrib for the target branch */
11850 + err = au_cpup_dirs(dentry, cpg.bdst);
11851 + if (unlikely(err))
11854 + di_downgrade_lock(parent, AuLock_IR);
11855 + udba = au_opt_udba(sb);
11856 + err = au_pin(&pin, dentry, cpg.bdst, udba,
11857 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11858 + if (unlikely(err))
11861 + err = au_sio_cpup_simple(&cpg);
11863 + if (unlikely(err))
11865 + if (!(cmoo & AuBrWAttr_MOO))
11866 + goto out_parent; /* success */
11868 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
11869 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
11870 + if (unlikely(err))
11873 + h_path.mnt = au_br_mnt(br);
11874 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
11875 + hdir = au_hi(parent->d_inode, cpg.bsrc);
11876 + delegated = NULL;
11877 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
11879 + /* todo: keep h_dentry or not? */
11880 + if (unlikely(err == -EWOULDBLOCK)) {
11881 + pr_warn("cannot retry for NFSv4 delegation"
11882 + " for an internal unlink\n");
11885 + if (unlikely(err)) {
11886 + pr_err("unlink %pd after coo failed (%d), ignored\n",
11890 + goto out_parent; /* success */
11893 + di_downgrade_lock(parent, AuLock_IR);
11895 + di_read_unlock(parent, AuLock_IR);
11902 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
11903 + struct au_fidir *fidir)
11906 + struct dentry *dentry;
11907 + struct au_finfo *finfo;
11909 + err = au_finfo_init(file, fidir);
11910 + if (unlikely(err))
11913 + dentry = file->f_dentry;
11914 + di_write_lock_child(dentry);
11915 + err = au_cmoo(dentry);
11916 + di_downgrade_lock(dentry, AuLock_IR);
11918 + err = open(file, vfsub_file_flags(file));
11919 + di_read_unlock(dentry, AuLock_IR);
11921 + finfo = au_fi(file);
11923 + finfo->fi_file = file;
11924 + au_sphl_add(&finfo->fi_hlist,
11925 + &au_sbi(file->f_dentry->d_sb)->si_files);
11927 + fi_write_unlock(file);
11928 + if (unlikely(err)) {
11929 + finfo->fi_hdir = NULL;
11930 + au_finfo_fin(file);
11937 +int au_reopen_nondir(struct file *file)
11940 + aufs_bindex_t bstart;
11941 + struct dentry *dentry;
11942 + struct file *h_file, *h_file_tmp;
11944 + dentry = file->f_dentry;
11945 + bstart = au_dbstart(dentry);
11946 + h_file_tmp = NULL;
11947 + if (au_fbstart(file) == bstart) {
11948 + h_file = au_hf_top(file);
11949 + if (file->f_mode == h_file->f_mode)
11950 + return 0; /* success */
11951 + h_file_tmp = h_file;
11952 + get_file(h_file_tmp);
11953 + au_set_h_fptr(file, bstart, NULL);
11955 + AuDebugOn(au_fi(file)->fi_hdir);
11958 + * file exists on both of rw and ro
11959 + * open --> dbstart and fbstart are both 0
11960 + * prepend a branch as rw, "rw" become ro
11962 + * delete the top branch, "rw" becomes rw again
11963 + * --> dbstart is 1, fbstart is still 0
11964 + * write --> fbstart is 0 but dbstart is 1
11966 + /* AuDebugOn(au_fbstart(file) < bstart); */
11968 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
11969 + file, /*force_wr*/0);
11970 + err = PTR_ERR(h_file);
11971 + if (IS_ERR(h_file)) {
11972 + if (h_file_tmp) {
11973 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
11974 + au_set_h_fptr(file, bstart, h_file_tmp);
11975 + h_file_tmp = NULL;
11977 + goto out; /* todo: close all? */
11981 + au_set_fbstart(file, bstart);
11982 + au_set_h_fptr(file, bstart, h_file);
11983 + au_update_figen(file);
11984 + /* todo: necessary? */
11985 + /* file->f_ra = h_file->f_ra; */
11989 + fput(h_file_tmp);
11993 +/* ---------------------------------------------------------------------- */
11995 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
11996 + struct dentry *hi_wh)
11999 + aufs_bindex_t bstart;
12000 + struct au_dinfo *dinfo;
12001 + struct dentry *h_dentry;
12002 + struct au_hdentry *hdp;
12004 + dinfo = au_di(file->f_dentry);
12005 + AuRwMustWriteLock(&dinfo->di_rwsem);
12007 + bstart = dinfo->di_bstart;
12008 + dinfo->di_bstart = btgt;
12009 + hdp = dinfo->di_hdentry;
12010 + h_dentry = hdp[0 + btgt].hd_dentry;
12011 + hdp[0 + btgt].hd_dentry = hi_wh;
12012 + err = au_reopen_nondir(file);
12013 + hdp[0 + btgt].hd_dentry = h_dentry;
12014 + dinfo->di_bstart = bstart;
12019 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12020 + aufs_bindex_t bcpup, struct au_pin *pin)
12023 + struct inode *inode, *h_inode;
12024 + struct dentry *h_dentry, *hi_wh;
12025 + struct au_cp_generic cpg = {
12026 + .dentry = file->f_dentry,
12033 + au_update_dbstart(cpg.dentry);
12034 + inode = cpg.dentry->d_inode;
12036 + if (au_dbstart(cpg.dentry) <= bcpup
12037 + && au_dbend(cpg.dentry) >= bcpup) {
12038 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12040 + h_inode = h_dentry->d_inode;
12042 + hi_wh = au_hi_wh(inode, bcpup);
12043 + if (!hi_wh && !h_inode)
12044 + err = au_sio_cpup_wh(&cpg, file);
12046 + /* already copied-up after unlink */
12047 + err = au_reopen_wh(file, bcpup, hi_wh);
12050 + && (inode->i_nlink > 1
12051 + || (inode->i_state & I_LINKABLE))
12052 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12053 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12059 + * prepare the @file for writing.
12061 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12064 + aufs_bindex_t dbstart;
12065 + struct dentry *parent, *h_dentry;
12066 + struct inode *inode;
12067 + struct super_block *sb;
12068 + struct file *h_file;
12069 + struct au_cp_generic cpg = {
12070 + .dentry = file->f_dentry,
12075 + .flags = AuCpup_DTIME
12078 + sb = cpg.dentry->d_sb;
12079 + inode = cpg.dentry->d_inode;
12080 + cpg.bsrc = au_fbstart(file);
12081 + err = au_test_ro(sb, cpg.bsrc, inode);
12082 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12083 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12088 + /* need to cpup or reopen */
12089 + parent = dget_parent(cpg.dentry);
12090 + di_write_lock_parent(parent);
12091 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12093 + if (unlikely(err < 0))
12097 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12098 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12099 + if (unlikely(err))
12103 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12104 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12105 + if (unlikely(err))
12108 + h_dentry = au_hf_top(file)->f_dentry;
12109 + dbstart = au_dbstart(cpg.dentry);
12110 + if (dbstart <= cpg.bdst) {
12111 + h_dentry = au_h_dptr(cpg.dentry, cpg.bdst);
12112 + AuDebugOn(!h_dentry);
12113 + cpg.bsrc = cpg.bdst;
12116 + if (dbstart <= cpg.bdst /* just reopen */
12117 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12119 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12120 + if (IS_ERR(h_file))
12121 + err = PTR_ERR(h_file);
12123 + di_downgrade_lock(parent, AuLock_IR);
12124 + if (dbstart > cpg.bdst)
12125 + err = au_sio_cpup_simple(&cpg);
12127 + err = au_reopen_nondir(file);
12128 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12130 + } else { /* copyup as wh and reopen */
12132 + * since writable hfsplus branch is not supported,
12133 + * h_open_pre/post() are unnecessary.
12135 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12136 + di_downgrade_lock(parent, AuLock_IR);
12140 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12141 + goto out_dput; /* success */
12147 + di_downgrade_lock(parent, AuLock_IR);
12149 + di_read_unlock(parent, AuLock_IR);
12156 +/* ---------------------------------------------------------------------- */
12158 +int au_do_flush(struct file *file, fl_owner_t id,
12159 + int (*flush)(struct file *file, fl_owner_t id))
12162 + struct super_block *sb;
12163 + struct inode *inode;
12165 + inode = file_inode(file);
12166 + sb = inode->i_sb;
12167 + si_noflush_read_lock(sb);
12168 + fi_read_lock(file);
12169 + ii_read_lock_child(inode);
12171 + err = flush(file, id);
12172 + au_cpup_attr_timesizes(inode);
12174 + ii_read_unlock(inode);
12175 + fi_read_unlock(file);
12176 + si_read_unlock(sb);
12180 +/* ---------------------------------------------------------------------- */
12182 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12185 + struct au_pin pin;
12186 + struct au_finfo *finfo;
12187 + struct dentry *parent, *hi_wh;
12188 + struct inode *inode;
12189 + struct super_block *sb;
12190 + struct au_cp_generic cpg = {
12191 + .dentry = file->f_dentry,
12196 + .flags = AuCpup_DTIME
12199 + FiMustWriteLock(file);
12202 + finfo = au_fi(file);
12203 + sb = cpg.dentry->d_sb;
12204 + inode = cpg.dentry->d_inode;
12205 + cpg.bdst = au_ibstart(inode);
12206 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12209 + parent = dget_parent(cpg.dentry);
12210 + if (au_test_ro(sb, cpg.bdst, inode)) {
12211 + di_read_lock_parent(parent, !AuLock_IR);
12212 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12214 + di_read_unlock(parent, !AuLock_IR);
12215 + if (unlikely(err < 0))
12220 + di_read_lock_parent(parent, AuLock_IR);
12221 + hi_wh = au_hi_wh(inode, cpg.bdst);
12222 + if (!S_ISDIR(inode->i_mode)
12223 + && au_opt_test(au_mntflags(sb), PLINK)
12224 + && au_plink_test(inode)
12225 + && !d_unhashed(cpg.dentry)
12226 + && cpg.bdst < au_dbstart(cpg.dentry)) {
12227 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12228 + if (unlikely(err))
12231 + /* always superio. */
12232 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12233 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12235 + err = au_sio_cpup_simple(&cpg);
12238 + } else if (hi_wh) {
12239 + /* already copied-up after unlink */
12240 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12241 + *need_reopen = 0;
12245 + di_read_unlock(parent, AuLock_IR);
12252 +static void au_do_refresh_dir(struct file *file)
12254 + aufs_bindex_t bindex, bend, new_bindex, brid;
12255 + struct au_hfile *p, tmp, *q;
12256 + struct au_finfo *finfo;
12257 + struct super_block *sb;
12258 + struct au_fidir *fidir;
12260 + FiMustWriteLock(file);
12262 + sb = file->f_dentry->d_sb;
12263 + finfo = au_fi(file);
12264 + fidir = finfo->fi_hdir;
12265 + AuDebugOn(!fidir);
12266 + p = fidir->fd_hfile + finfo->fi_btop;
12267 + brid = p->hf_br->br_id;
12268 + bend = fidir->fd_bbot;
12269 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
12273 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12274 + if (new_bindex == bindex)
12276 + if (new_bindex < 0) {
12277 + au_set_h_fptr(file, bindex, NULL);
12281 + /* swap two lower inode, and loop again */
12282 + q = fidir->fd_hfile + new_bindex;
12286 + if (tmp.hf_file) {
12292 + p = fidir->fd_hfile;
12293 + if (!au_test_mmapped(file) && !d_unlinked(file->f_dentry)) {
12294 + bend = au_sbend(sb);
12295 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
12296 + finfo->fi_btop++, p++)
12297 + if (p->hf_file) {
12298 + if (file_inode(p->hf_file))
12301 + au_hfput(p, file);
12304 + bend = au_br_index(sb, brid);
12305 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
12306 + finfo->fi_btop++, p++)
12308 + au_hfput(p, file);
12309 + bend = au_sbend(sb);
12312 + p = fidir->fd_hfile + bend;
12313 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
12314 + fidir->fd_bbot--, p--)
12315 + if (p->hf_file) {
12316 + if (file_inode(p->hf_file))
12319 + au_hfput(p, file);
12321 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12325 + * after branch manipulating, refresh the file.
12327 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12329 + int err, need_reopen;
12330 + aufs_bindex_t bend, bindex;
12331 + struct dentry *dentry;
12332 + struct au_finfo *finfo;
12333 + struct au_hfile *hfile;
12335 + dentry = file->f_dentry;
12336 + finfo = au_fi(file);
12337 + if (!finfo->fi_hdir) {
12338 + hfile = &finfo->fi_htop;
12339 + AuDebugOn(!hfile->hf_file);
12340 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
12341 + AuDebugOn(bindex < 0);
12342 + if (bindex != finfo->fi_btop)
12343 + au_set_fbstart(file, bindex);
12345 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
12346 + if (unlikely(err))
12348 + au_do_refresh_dir(file);
12353 + if (!au_test_mmapped(file))
12354 + err = au_file_refresh_by_inode(file, &need_reopen);
12355 + if (!err && need_reopen && !d_unlinked(dentry))
12356 + err = reopen(file);
12358 + au_update_figen(file);
12359 + goto out; /* success */
12362 + /* error, close all lower files */
12363 + if (finfo->fi_hdir) {
12364 + bend = au_fbend_dir(file);
12365 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
12366 + au_set_h_fptr(file, bindex, NULL);
12373 +/* common function to regular file and dir */
12374 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12378 + unsigned int sigen, figen;
12379 + aufs_bindex_t bstart;
12380 + unsigned char pseudo_link;
12381 + struct dentry *dentry;
12382 + struct inode *inode;
12385 + dentry = file->f_dentry;
12386 + inode = dentry->d_inode;
12387 + sigen = au_sigen(dentry->d_sb);
12388 + fi_write_lock(file);
12389 + figen = au_figen(file);
12390 + di_write_lock_child(dentry);
12391 + bstart = au_dbstart(dentry);
12392 + pseudo_link = (bstart != au_ibstart(inode));
12393 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
12395 + di_downgrade_lock(dentry, AuLock_IR);
12396 + fi_downgrade_lock(file);
12398 + goto out; /* success */
12401 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12402 + if (au_digen_test(dentry, sigen)) {
12403 + err = au_reval_dpath(dentry, sigen);
12404 + AuDebugOn(!err && au_digen_test(dentry, sigen));
12408 + err = refresh_file(file, reopen);
12411 + di_downgrade_lock(dentry, AuLock_IR);
12412 + fi_downgrade_lock(file);
12415 + di_write_unlock(dentry);
12416 + fi_write_unlock(file);
12423 +/* ---------------------------------------------------------------------- */
12425 +/* cf. aufs_nopage() */
12426 +/* for madvise(2) */
12427 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
12429 + unlock_page(page);
12433 +/* it will never be called, but necessary to support O_DIRECT */
12434 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
12435 + struct iov_iter *iter, loff_t offset)
12436 +{ BUG(); return 0; }
12439 + * it will never be called, but madvise and fadvise behaves differently
12440 + * when get_xip_mem is defined
12442 +static int aufs_get_xip_mem(struct address_space *mapping, pgoff_t pgoff,
12443 + int create, void **kmem, unsigned long *pfn)
12444 +{ BUG(); return 0; }
12446 +/* they will never be called. */
12447 +#ifdef CONFIG_AUFS_DEBUG
12448 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
12449 + loff_t pos, unsigned len, unsigned flags,
12450 + struct page **pagep, void **fsdata)
12451 +{ AuUnsupport(); return 0; }
12452 +static int aufs_write_end(struct file *file, struct address_space *mapping,
12453 + loff_t pos, unsigned len, unsigned copied,
12454 + struct page *page, void *fsdata)
12455 +{ AuUnsupport(); return 0; }
12456 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
12457 +{ AuUnsupport(); return 0; }
12459 +static int aufs_set_page_dirty(struct page *page)
12460 +{ AuUnsupport(); return 0; }
12461 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
12462 + unsigned int length)
12463 +{ AuUnsupport(); }
12464 +static int aufs_releasepage(struct page *page, gfp_t gfp)
12465 +{ AuUnsupport(); return 0; }
12466 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
12467 + struct page *page, enum migrate_mode mode)
12468 +{ AuUnsupport(); return 0; }
12469 +static int aufs_launder_page(struct page *page)
12470 +{ AuUnsupport(); return 0; }
12471 +static int aufs_is_partially_uptodate(struct page *page,
12472 + unsigned long from,
12473 + unsigned long count)
12474 +{ AuUnsupport(); return 0; }
12475 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
12477 +{ AuUnsupport(); }
12478 +static int aufs_error_remove_page(struct address_space *mapping,
12479 + struct page *page)
12480 +{ AuUnsupport(); return 0; }
12481 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
12483 +{ AuUnsupport(); return 0; }
12484 +static void aufs_swap_deactivate(struct file *file)
12485 +{ AuUnsupport(); }
12486 +#endif /* CONFIG_AUFS_DEBUG */
12488 +const struct address_space_operations aufs_aop = {
12489 + .readpage = aufs_readpage,
12490 + .direct_IO = aufs_direct_IO,
12491 + .get_xip_mem = aufs_get_xip_mem,
12492 +#ifdef CONFIG_AUFS_DEBUG
12493 + .writepage = aufs_writepage,
12494 + /* no writepages, because of writepage */
12495 + .set_page_dirty = aufs_set_page_dirty,
12496 + /* no readpages, because of readpage */
12497 + .write_begin = aufs_write_begin,
12498 + .write_end = aufs_write_end,
12499 + /* no bmap, no block device */
12500 + .invalidatepage = aufs_invalidatepage,
12501 + .releasepage = aufs_releasepage,
12502 + .migratepage = aufs_migratepage,
12503 + .launder_page = aufs_launder_page,
12504 + .is_partially_uptodate = aufs_is_partially_uptodate,
12505 + .is_dirty_writeback = aufs_is_dirty_writeback,
12506 + .error_remove_page = aufs_error_remove_page,
12507 + .swap_activate = aufs_swap_activate,
12508 + .swap_deactivate = aufs_swap_deactivate
12509 +#endif /* CONFIG_AUFS_DEBUG */
12511 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
12512 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
12513 +++ linux/fs/aufs/file.h 2014-08-14 10:15:45.121942630 +0200
12516 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12518 + * This program, aufs is free software; you can redistribute it and/or modify
12519 + * it under the terms of the GNU General Public License as published by
12520 + * the Free Software Foundation; either version 2 of the License, or
12521 + * (at your option) any later version.
12523 + * This program is distributed in the hope that it will be useful,
12524 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12525 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12526 + * GNU General Public License for more details.
12528 + * You should have received a copy of the GNU General Public License
12529 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12533 + * file operations
12536 +#ifndef __AUFS_FILE_H__
12537 +#define __AUFS_FILE_H__
12541 +#include <linux/file.h>
12542 +#include <linux/fs.h>
12543 +#include <linux/poll.h>
12544 +#include "rwsem.h"
12548 + struct file *hf_file;
12549 + struct au_branch *hf_br;
12554 + aufs_bindex_t fd_bbot;
12555 + aufs_bindex_t fd_nent;
12556 + struct au_vdir *fd_vdir_cache;
12557 + struct au_hfile fd_hfile[];
12560 +static inline int au_fidir_sz(int nent)
12562 + AuDebugOn(nent < 0);
12563 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
12567 + atomic_t fi_generation;
12569 + struct au_rwsem fi_rwsem;
12570 + aufs_bindex_t fi_btop;
12572 + /* do not union them */
12573 + struct { /* for non-dir */
12574 + struct au_hfile fi_htop;
12575 + atomic_t fi_mmapped;
12577 + struct au_fidir *fi_hdir; /* for dir only */
12579 + struct hlist_node fi_hlist;
12580 + struct file *fi_file; /* very ugly */
12581 +} ____cacheline_aligned_in_smp;
12583 +/* ---------------------------------------------------------------------- */
12586 +extern const struct address_space_operations aufs_aop;
12587 +unsigned int au_file_roflags(unsigned int flags);
12588 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12589 + struct file *file, int force_wr);
12590 +int au_do_open(struct file *file, int (*open)(struct file *file, int flags),
12591 + struct au_fidir *fidir);
12592 +int au_reopen_nondir(struct file *file);
12594 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
12595 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12597 +int au_do_flush(struct file *file, fl_owner_t id,
12598 + int (*flush)(struct file *file, fl_owner_t id));
12601 +#ifdef CONFIG_AUFS_POLL
12602 +unsigned int aufs_poll(struct file *file, poll_table *wait);
12605 +#ifdef CONFIG_AUFS_BR_HFSPLUS
12607 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
12609 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
12610 + struct file *h_file);
12613 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
12619 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
12620 + struct file *h_file);
12624 +extern const struct file_operations aufs_file_fop;
12625 +int au_do_open_nondir(struct file *file, int flags);
12626 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
12629 +void au_hfput(struct au_hfile *hf, struct file *file);
12630 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
12631 + struct file *h_file);
12633 +void au_update_figen(struct file *file);
12634 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
12635 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
12637 +void au_fi_init_once(void *_fi);
12638 +void au_finfo_fin(struct file *file);
12639 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
12642 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
12643 +#ifdef CONFIG_COMPAT
12644 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
12645 + unsigned long arg);
12646 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
12647 + unsigned long arg);
12650 +/* ---------------------------------------------------------------------- */
12652 +static inline struct au_finfo *au_fi(struct file *file)
12654 + return file->private_data;
12657 +/* ---------------------------------------------------------------------- */
12660 + * fi_read_lock, fi_write_lock,
12661 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
12663 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
12665 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
12666 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
12667 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
12669 +/* ---------------------------------------------------------------------- */
12671 +/* todo: hard/soft set? */
12672 +static inline aufs_bindex_t au_fbstart(struct file *file)
12674 + FiMustAnyLock(file);
12675 + return au_fi(file)->fi_btop;
12678 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
12680 + FiMustAnyLock(file);
12681 + AuDebugOn(!au_fi(file)->fi_hdir);
12682 + return au_fi(file)->fi_hdir->fd_bbot;
12685 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
12687 + FiMustAnyLock(file);
12688 + AuDebugOn(!au_fi(file)->fi_hdir);
12689 + return au_fi(file)->fi_hdir->fd_vdir_cache;
12692 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
12694 + FiMustWriteLock(file);
12695 + au_fi(file)->fi_btop = bindex;
12698 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
12700 + FiMustWriteLock(file);
12701 + AuDebugOn(!au_fi(file)->fi_hdir);
12702 + au_fi(file)->fi_hdir->fd_bbot = bindex;
12705 +static inline void au_set_fvdir_cache(struct file *file,
12706 + struct au_vdir *vdir_cache)
12708 + FiMustWriteLock(file);
12709 + AuDebugOn(!au_fi(file)->fi_hdir);
12710 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
12713 +static inline struct file *au_hf_top(struct file *file)
12715 + FiMustAnyLock(file);
12716 + AuDebugOn(au_fi(file)->fi_hdir);
12717 + return au_fi(file)->fi_htop.hf_file;
12720 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
12722 + FiMustAnyLock(file);
12723 + AuDebugOn(!au_fi(file)->fi_hdir);
12724 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
12727 +/* todo: memory barrier? */
12728 +static inline unsigned int au_figen(struct file *f)
12730 + return atomic_read(&au_fi(f)->fi_generation);
12733 +static inline void au_set_mmapped(struct file *f)
12735 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
12737 + pr_warn("fi_mmapped wrapped around\n");
12738 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
12742 +static inline void au_unset_mmapped(struct file *f)
12744 + atomic_dec(&au_fi(f)->fi_mmapped);
12747 +static inline int au_test_mmapped(struct file *f)
12749 + return atomic_read(&au_fi(f)->fi_mmapped);
12752 +/* customize vma->vm_file */
12754 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
12755 + struct file *file)
12759 + f = vma->vm_file;
12761 + vma->vm_file = file;
12766 +#define AuDbgVmRegion(file, vma) do {} while (0)
12768 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
12769 + struct file *file)
12771 + au_do_vm_file_reset(vma, file);
12774 +#define AuDbgVmRegion(file, vma) \
12775 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
12777 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
12778 + struct file *file)
12782 + au_do_vm_file_reset(vma, file);
12783 + f = vma->vm_region->vm_file;
12785 + vma->vm_region->vm_file = file;
12788 +#endif /* CONFIG_MMU */
12790 +/* handle vma->vm_prfile */
12791 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
12792 + struct file *file)
12795 + vma->vm_prfile = file;
12796 +#ifndef CONFIG_MMU
12798 + vma->vm_region->vm_prfile = file;
12802 +#endif /* __KERNEL__ */
12803 +#endif /* __AUFS_FILE_H__ */
12804 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
12805 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
12806 +++ linux/fs/aufs/finfo.c 2014-01-30 21:10:02.850815069 +0100
12809 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12811 + * This program, aufs is free software; you can redistribute it and/or modify
12812 + * it under the terms of the GNU General Public License as published by
12813 + * the Free Software Foundation; either version 2 of the License, or
12814 + * (at your option) any later version.
12816 + * This program is distributed in the hope that it will be useful,
12817 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12818 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12819 + * GNU General Public License for more details.
12821 + * You should have received a copy of the GNU General Public License
12822 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12826 + * file private data
12831 +void au_hfput(struct au_hfile *hf, struct file *file)
12833 + /* todo: direct access f_flags */
12834 + if (vfsub_file_flags(file) & __FMODE_EXEC)
12835 + allow_write_access(hf->hf_file);
12836 + fput(hf->hf_file);
12837 + hf->hf_file = NULL;
12838 + atomic_dec(&hf->hf_br->br_count);
12839 + hf->hf_br = NULL;
12842 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
12844 + struct au_finfo *finfo = au_fi(file);
12845 + struct au_hfile *hf;
12846 + struct au_fidir *fidir;
12848 + fidir = finfo->fi_hdir;
12850 + AuDebugOn(finfo->fi_btop != bindex);
12851 + hf = &finfo->fi_htop;
12853 + hf = fidir->fd_hfile + bindex;
12855 + if (hf && hf->hf_file)
12856 + au_hfput(hf, file);
12858 + FiMustWriteLock(file);
12859 + hf->hf_file = val;
12860 + hf->hf_br = au_sbr(file->f_dentry->d_sb, bindex);
12864 +void au_update_figen(struct file *file)
12866 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_dentry));
12867 + /* smp_mb(); */ /* atomic_set */
12870 +/* ---------------------------------------------------------------------- */
12872 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
12874 + struct au_fidir *fidir;
12877 + nbr = au_sbend(sb) + 1;
12879 + nbr = 2; /* initial allocate for 2 branches */
12880 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
12882 + fidir->fd_bbot = -1;
12883 + fidir->fd_nent = nbr;
12884 + fidir->fd_vdir_cache = NULL;
12890 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
12893 + struct au_fidir *fidir, *p;
12895 + AuRwMustWriteLock(&finfo->fi_rwsem);
12896 + fidir = finfo->fi_hdir;
12897 + AuDebugOn(!fidir);
12900 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
12903 + p->fd_nent = nbr;
12904 + finfo->fi_hdir = p;
12911 +/* ---------------------------------------------------------------------- */
12913 +void au_finfo_fin(struct file *file)
12915 + struct au_finfo *finfo;
12917 + au_nfiles_dec(file->f_dentry->d_sb);
12919 + finfo = au_fi(file);
12920 + AuDebugOn(finfo->fi_hdir);
12921 + AuRwDestroy(&finfo->fi_rwsem);
12922 + au_cache_free_finfo(finfo);
12925 +void au_fi_init_once(void *_finfo)
12927 + struct au_finfo *finfo = _finfo;
12928 + static struct lock_class_key aufs_fi;
12930 + au_rw_init(&finfo->fi_rwsem);
12931 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
12934 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
12937 + struct au_finfo *finfo;
12938 + struct dentry *dentry;
12941 + dentry = file->f_dentry;
12942 + finfo = au_cache_alloc_finfo();
12943 + if (unlikely(!finfo))
12947 + au_nfiles_inc(dentry->d_sb);
12948 + /* verbose coding for lock class name */
12950 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
12952 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
12953 + au_rw_write_lock(&finfo->fi_rwsem);
12954 + finfo->fi_btop = -1;
12955 + finfo->fi_hdir = fidir;
12956 + atomic_set(&finfo->fi_generation, au_digen(dentry));
12957 + /* smp_mb(); */ /* atomic_set */
12959 + file->private_data = finfo;
12964 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
12965 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
12966 +++ linux/fs/aufs/f_op.c 2014-08-14 10:16:04.515942371 +0200
12969 + * Copyright (C) 2005-2014 Junjiro R. Okajima
12971 + * This program, aufs is free software; you can redistribute it and/or modify
12972 + * it under the terms of the GNU General Public License as published by
12973 + * the Free Software Foundation; either version 2 of the License, or
12974 + * (at your option) any later version.
12976 + * This program is distributed in the hope that it will be useful,
12977 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12978 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12979 + * GNU General Public License for more details.
12981 + * You should have received a copy of the GNU General Public License
12982 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12986 + * file and vm operations
12989 +#include <linux/aio.h>
12990 +#include <linux/fs_stack.h>
12991 +#include <linux/mman.h>
12992 +#include <linux/security.h>
12995 +int au_do_open_nondir(struct file *file, int flags)
12998 + aufs_bindex_t bindex;
12999 + struct file *h_file;
13000 + struct dentry *dentry;
13001 + struct au_finfo *finfo;
13002 + struct inode *h_inode;
13004 + FiMustWriteLock(file);
13007 + dentry = file->f_dentry;
13008 + finfo = au_fi(file);
13009 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13010 + atomic_set(&finfo->fi_mmapped, 0);
13011 + bindex = au_dbstart(dentry);
13012 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13013 + if (IS_ERR(h_file))
13014 + err = PTR_ERR(h_file);
13016 + if ((flags & __O_TMPFILE)
13017 + && !(flags & O_EXCL)) {
13018 + h_inode = file_inode(h_file);
13019 + spin_lock(&h_inode->i_lock);
13020 + h_inode->i_state |= I_LINKABLE;
13021 + spin_unlock(&h_inode->i_lock);
13023 + au_set_fbstart(file, bindex);
13024 + au_set_h_fptr(file, bindex, h_file);
13025 + au_update_figen(file);
13026 + /* todo: necessary? */
13027 + /* file->f_ra = h_file->f_ra; */
13033 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13034 + struct file *file)
13037 + struct super_block *sb;
13039 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13040 + file, vfsub_file_flags(file), file->f_mode);
13042 + sb = file->f_dentry->d_sb;
13043 + si_read_lock(sb, AuLock_FLUSH);
13044 + err = au_do_open(file, au_do_open_nondir, /*fidir*/NULL);
13045 + si_read_unlock(sb);
13049 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13051 + struct au_finfo *finfo;
13052 + aufs_bindex_t bindex;
13054 + finfo = au_fi(file);
13055 + au_sphl_del(&finfo->fi_hlist, &au_sbi(file->f_dentry->d_sb)->si_files);
13056 + bindex = finfo->fi_btop;
13058 + au_set_h_fptr(file, bindex, NULL);
13060 + au_finfo_fin(file);
13064 +/* ---------------------------------------------------------------------- */
13066 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13069 + struct file *h_file;
13072 + h_file = au_hf_top(file);
13074 + err = vfsub_flush(h_file, id);
13078 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13080 + return au_do_flush(file, id, au_do_flush_nondir);
13083 +/* ---------------------------------------------------------------------- */
13085 + * read and write functions acquire [fdi]_rwsem once, but release before
13086 + * mmap_sem. This is because to stop a race condition between mmap(2).
13087 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13088 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13089 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13092 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13096 + struct dentry *dentry;
13097 + struct file *h_file;
13098 + struct super_block *sb;
13100 + dentry = file->f_dentry;
13101 + sb = dentry->d_sb;
13102 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13103 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13104 + if (unlikely(err))
13107 + h_file = au_hf_top(file);
13108 + get_file(h_file);
13109 + di_read_unlock(dentry, AuLock_IR);
13110 + fi_read_unlock(file);
13112 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13113 + err = vfsub_read_u(h_file, buf, count, ppos);
13114 + /* todo: necessary? */
13115 + /* file->f_ra = h_file->f_ra; */
13116 + /* update without lock, I don't think it a problem */
13117 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13121 + si_read_unlock(sb);
13126 + * todo: very ugly
13127 + * it locks both of i_mutex and si_rwsem for read in safe.
13128 + * if the plink maintenance mode continues forever (that is the problem),
13129 + * may loop forever.
13131 +static void au_mtx_and_read_lock(struct inode *inode)
13134 + struct super_block *sb = inode->i_sb;
13137 + mutex_lock(&inode->i_mutex);
13138 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13141 + mutex_unlock(&inode->i_mutex);
13142 + si_read_lock(sb, AuLock_NOPLMW);
13143 + si_read_unlock(sb);
13147 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13148 + size_t count, loff_t *ppos)
13152 + aufs_bindex_t bstart;
13153 + struct au_pin pin;
13154 + struct dentry *dentry;
13155 + struct inode *inode, *h_inode;
13156 + struct super_block *sb;
13157 + struct file *h_file;
13158 + char __user *buf = (char __user *)ubuf;
13160 + dentry = file->f_dentry;
13161 + sb = dentry->d_sb;
13162 + inode = dentry->d_inode;
13163 + au_mtx_and_read_lock(inode);
13165 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13166 + if (unlikely(err))
13169 + err = au_ready_to_write(file, -1, &pin);
13170 + di_downgrade_lock(dentry, AuLock_IR);
13171 + if (unlikely(err)) {
13172 + di_read_unlock(dentry, AuLock_IR);
13173 + fi_write_unlock(file);
13177 + bstart = au_fbstart(file);
13178 + h_file = au_hf_top(file);
13179 + get_file(h_file);
13180 + h_inode = h_file->f_dentry->d_inode;
13181 + blks = h_inode->i_blocks;
13183 + di_read_unlock(dentry, AuLock_IR);
13184 + fi_write_unlock(file);
13186 + err = vfsub_write_u(h_file, buf, count, ppos);
13187 + ii_write_lock_child(inode);
13188 + au_cpup_attr_timesizes(inode);
13189 + inode->i_mode = file_inode(h_file)->i_mode;
13190 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13192 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13193 + ii_write_unlock(inode);
13197 + si_read_unlock(sb);
13198 + mutex_unlock(&inode->i_mutex);
13202 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13203 + struct iov_iter *iov_iter)
13206 + struct file *file;
13207 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13208 + ssize_t (*aio)(struct kiocb *, const struct iovec *, unsigned long,
13211 + err = security_file_permission(h_file, rw);
13212 + if (unlikely(err))
13218 + if (rw == MAY_READ) {
13219 + iter = h_file->f_op->read_iter;
13220 + aio = h_file->f_op->aio_read;
13221 + } else if (rw == MAY_WRITE) {
13222 + iter = h_file->f_op->write_iter;
13223 + aio = h_file->f_op->aio_write;
13226 + file = kio->ki_filp;
13227 + kio->ki_filp = h_file;
13230 + err = iter(kio, iov_iter);
13232 + } else if (aio) {
13234 + err = aio(kio, iov_iter->iov, iov_iter->nr_segs, kio->ki_pos);
13237 + /* currently there is no such fs */
13239 + kio->ki_filp = file;
13245 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13248 + struct file *file, *h_file;
13249 + struct dentry *dentry;
13250 + struct super_block *sb;
13252 + file = kio->ki_filp;
13253 + dentry = file->f_dentry;
13254 + sb = dentry->d_sb;
13255 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13256 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13257 + if (unlikely(err))
13260 + h_file = au_hf_top(file);
13261 + get_file(h_file);
13262 + di_read_unlock(dentry, AuLock_IR);
13263 + fi_read_unlock(file);
13265 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13266 + /* todo: necessary? */
13267 + /* file->f_ra = h_file->f_ra; */
13268 + /* update without lock, I don't think it a problem */
13269 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13273 + si_read_unlock(sb);
13277 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13281 + aufs_bindex_t bstart;
13282 + struct au_pin pin;
13283 + struct dentry *dentry;
13284 + struct inode *inode, *h_inode;
13285 + struct file *file, *h_file;
13286 + struct super_block *sb;
13288 + file = kio->ki_filp;
13289 + dentry = file->f_dentry;
13290 + sb = dentry->d_sb;
13291 + inode = dentry->d_inode;
13292 + au_mtx_and_read_lock(inode);
13294 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13295 + if (unlikely(err))
13298 + err = au_ready_to_write(file, -1, &pin);
13299 + di_downgrade_lock(dentry, AuLock_IR);
13300 + if (unlikely(err)) {
13301 + di_read_unlock(dentry, AuLock_IR);
13302 + fi_write_unlock(file);
13306 + bstart = au_fbstart(file);
13307 + h_file = au_hf_top(file);
13308 + get_file(h_file);
13309 + h_inode = h_file->f_dentry->d_inode;
13310 + blks = h_inode->i_blocks;
13312 + di_read_unlock(dentry, AuLock_IR);
13313 + fi_write_unlock(file);
13315 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13316 + ii_write_lock_child(inode);
13317 + au_cpup_attr_timesizes(inode);
13318 + inode->i_mode = file_inode(h_file)->i_mode;
13319 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13321 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13322 + ii_write_unlock(inode);
13326 + si_read_unlock(sb);
13327 + mutex_unlock(&inode->i_mutex);
13331 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13332 + struct pipe_inode_info *pipe, size_t len,
13333 + unsigned int flags)
13336 + struct file *h_file;
13337 + struct dentry *dentry;
13338 + struct super_block *sb;
13340 + dentry = file->f_dentry;
13341 + sb = dentry->d_sb;
13342 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13343 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13344 + if (unlikely(err))
13348 + h_file = au_hf_top(file);
13349 + get_file(h_file);
13350 + if (au_test_loopback_kthread()) {
13351 + au_warn_loopback(h_file->f_dentry->d_sb);
13352 + if (file->f_mapping != h_file->f_mapping) {
13353 + file->f_mapping = h_file->f_mapping;
13354 + smp_mb(); /* unnecessary? */
13357 + di_read_unlock(dentry, AuLock_IR);
13358 + fi_read_unlock(file);
13360 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13361 + /* todo: necessasry? */
13362 + /* file->f_ra = h_file->f_ra; */
13363 + /* update without lock, I don't think it a problem */
13364 + fsstack_copy_attr_atime(dentry->d_inode, file_inode(h_file));
13368 + si_read_unlock(sb);
13373 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
13374 + size_t len, unsigned int flags)
13378 + aufs_bindex_t bstart;
13379 + struct au_pin pin;
13380 + struct dentry *dentry;
13381 + struct inode *inode, *h_inode;
13382 + struct super_block *sb;
13383 + struct file *h_file;
13385 + dentry = file->f_dentry;
13386 + sb = dentry->d_sb;
13387 + inode = dentry->d_inode;
13388 + au_mtx_and_read_lock(inode);
13390 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13391 + if (unlikely(err))
13394 + err = au_ready_to_write(file, -1, &pin);
13395 + di_downgrade_lock(dentry, AuLock_IR);
13396 + if (unlikely(err)) {
13397 + di_read_unlock(dentry, AuLock_IR);
13398 + fi_write_unlock(file);
13402 + bstart = au_fbstart(file);
13403 + h_file = au_hf_top(file);
13404 + get_file(h_file);
13405 + h_inode = h_file->f_dentry->d_inode;
13406 + blks = h_inode->i_blocks;
13408 + di_read_unlock(dentry, AuLock_IR);
13409 + fi_write_unlock(file);
13411 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
13412 + ii_write_lock_child(inode);
13413 + au_cpup_attr_timesizes(inode);
13414 + inode->i_mode = file_inode(h_file)->i_mode;
13415 + AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks);
13417 + au_fhsm_wrote(sb, bstart, /*force*/h_inode->i_blocks > blks);
13418 + ii_write_unlock(inode);
13422 + si_read_unlock(sb);
13423 + mutex_unlock(&inode->i_mutex);
13427 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
13431 + struct au_pin pin;
13432 + struct dentry *dentry;
13433 + struct super_block *sb;
13434 + struct inode *inode;
13435 + struct file *h_file;
13437 + dentry = file->f_dentry;
13438 + sb = dentry->d_sb;
13439 + inode = dentry->d_inode;
13440 + au_mtx_and_read_lock(inode);
13442 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13443 + if (unlikely(err))
13446 + err = au_ready_to_write(file, -1, &pin);
13447 + di_downgrade_lock(dentry, AuLock_IR);
13448 + if (unlikely(err)) {
13449 + di_read_unlock(dentry, AuLock_IR);
13450 + fi_write_unlock(file);
13454 + h_file = au_hf_top(file);
13455 + get_file(h_file);
13457 + di_read_unlock(dentry, AuLock_IR);
13458 + fi_write_unlock(file);
13461 + err = do_fallocate(h_file, mode, offset, len);
13463 + ii_write_lock_child(inode);
13464 + au_cpup_attr_timesizes(inode);
13465 + inode->i_mode = file_inode(h_file)->i_mode;
13466 + ii_write_unlock(inode);
13470 + si_read_unlock(sb);
13471 + mutex_unlock(&inode->i_mutex);
13475 +/* ---------------------------------------------------------------------- */
13478 + * The locking order around current->mmap_sem.
13479 + * - in most and regular cases
13480 + * file I/O syscall -- aufs_read() or something
13481 + * -- si_rwsem for read -- mmap_sem
13482 + * (Note that [fdi]i_rwsem are released before mmap_sem).
13484 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
13485 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
13486 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
13487 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
13488 + * It means that when aufs acquires si_rwsem for write, the process should never
13489 + * acquire mmap_sem.
13491 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
13492 + * problem either since any directory is not able to be mmap-ed.
13493 + * The similar scenario is applied to aufs_readlink() too.
13496 +#if 0 /* stop calling security_file_mmap() */
13497 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
13498 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
13500 +static unsigned long au_arch_prot_conv(unsigned long flags)
13502 + /* currently ppc64 only */
13503 +#ifdef CONFIG_PPC64
13504 + /* cf. linux/arch/powerpc/include/asm/mman.h */
13505 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
13506 + return AuConv_VM_PROT(flags, SAO);
13508 + AuDebugOn(arch_calc_vm_prot_bits(-1));
13513 +static unsigned long au_prot_conv(unsigned long flags)
13515 + return AuConv_VM_PROT(flags, READ)
13516 + | AuConv_VM_PROT(flags, WRITE)
13517 + | AuConv_VM_PROT(flags, EXEC)
13518 + | au_arch_prot_conv(flags);
13521 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
13522 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
13524 +static unsigned long au_flag_conv(unsigned long flags)
13526 + return AuConv_VM_MAP(flags, GROWSDOWN)
13527 + | AuConv_VM_MAP(flags, DENYWRITE)
13528 + | AuConv_VM_MAP(flags, LOCKED);
13532 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
13535 + aufs_bindex_t bstart;
13536 + const unsigned char wlock
13537 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
13538 + struct dentry *dentry;
13539 + struct super_block *sb;
13540 + struct file *h_file;
13541 + struct au_branch *br;
13542 + struct au_pin pin;
13544 + AuDbgVmRegion(file, vma);
13546 + dentry = file->f_dentry;
13547 + sb = dentry->d_sb;
13549 + si_read_lock(sb, AuLock_NOPLMW);
13550 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13551 + if (unlikely(err))
13555 + err = au_ready_to_write(file, -1, &pin);
13556 + di_write_unlock(dentry);
13557 + if (unlikely(err)) {
13558 + fi_write_unlock(file);
13563 + di_write_unlock(dentry);
13565 + bstart = au_fbstart(file);
13566 + br = au_sbr(sb, bstart);
13567 + h_file = au_hf_top(file);
13568 + get_file(h_file);
13569 + au_set_mmapped(file);
13570 + fi_write_unlock(file);
13573 + au_vm_file_reset(vma, h_file);
13575 + * we cannot call security_mmap_file() here since it may acquire
13576 + * mmap_sem or i_mutex.
13578 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
13579 + * au_flag_conv(vma->vm_flags));
13582 + err = h_file->f_op->mmap(h_file, vma);
13583 + if (unlikely(err))
13586 + au_vm_prfile_set(vma, file);
13587 + /* update without lock, I don't think it a problem */
13588 + fsstack_copy_attr_atime(file_inode(file), file_inode(h_file));
13589 + goto out_fput; /* success */
13592 + au_unset_mmapped(file);
13593 + au_vm_file_reset(vma, file);
13598 + si_read_unlock(sb);
13604 +/* ---------------------------------------------------------------------- */
13606 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
13610 + struct au_pin pin;
13611 + struct dentry *dentry;
13612 + struct inode *inode;
13613 + struct file *h_file;
13614 + struct super_block *sb;
13616 + dentry = file->f_dentry;
13617 + inode = dentry->d_inode;
13618 + sb = dentry->d_sb;
13619 + mutex_lock(&inode->i_mutex);
13620 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13621 + if (unlikely(err))
13624 + err = 0; /* -EBADF; */ /* posix? */
13625 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13627 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13628 + if (unlikely(err))
13631 + err = au_ready_to_write(file, -1, &pin);
13632 + di_downgrade_lock(dentry, AuLock_IR);
13633 + if (unlikely(err))
13638 + h_file = au_hf_top(file);
13639 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
13640 + au_cpup_attr_timesizes(inode);
13643 + di_read_unlock(dentry, AuLock_IR);
13644 + fi_write_unlock(file);
13646 + si_read_unlock(sb);
13648 + mutex_unlock(&inode->i_mutex);
13652 +/* no one supports this operation, currently */
13654 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
13657 + struct au_pin pin;
13658 + struct dentry *dentry;
13659 + struct inode *inode;
13660 + struct file *file, *h_file;
13662 + file = kio->ki_filp;
13663 + dentry = file->f_dentry;
13664 + inode = dentry->d_inode;
13665 + au_mtx_and_read_lock(inode);
13667 + err = 0; /* -EBADF; */ /* posix? */
13668 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13670 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13671 + if (unlikely(err))
13674 + err = au_ready_to_write(file, -1, &pin);
13675 + di_downgrade_lock(dentry, AuLock_IR);
13676 + if (unlikely(err))
13681 + h_file = au_hf_top(file);
13682 + if (h_file->f_op->aio_fsync) {
13683 + struct mutex *h_mtx;
13685 + h_mtx = &file_inode(h_file)->i_mutex;
13686 + if (!is_sync_kiocb(kio)) {
13687 + get_file(h_file);
13690 + kio->ki_filp = h_file;
13691 + err = h_file->f_op->aio_fsync(kio, datasync);
13692 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13694 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
13696 + au_cpup_attr_timesizes(inode);
13697 + mutex_unlock(h_mtx);
13701 + di_read_unlock(dentry, AuLock_IR);
13702 + fi_write_unlock(file);
13704 + si_read_unlock(inode->sb);
13705 + mutex_unlock(&inode->i_mutex);
13710 +static int aufs_fasync(int fd, struct file *file, int flag)
13713 + struct file *h_file;
13714 + struct dentry *dentry;
13715 + struct super_block *sb;
13717 + dentry = file->f_dentry;
13718 + sb = dentry->d_sb;
13719 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13720 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13721 + if (unlikely(err))
13724 + h_file = au_hf_top(file);
13725 + if (h_file->f_op->fasync)
13726 + err = h_file->f_op->fasync(fd, h_file, flag);
13728 + di_read_unlock(dentry, AuLock_IR);
13729 + fi_read_unlock(file);
13732 + si_read_unlock(sb);
13736 +/* ---------------------------------------------------------------------- */
13738 +/* no one supports this operation, currently */
13740 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
13741 + size_t len, loff_t *pos , int more)
13746 +/* ---------------------------------------------------------------------- */
13748 +const struct file_operations aufs_file_fop = {
13749 + .owner = THIS_MODULE,
13751 + .llseek = default_llseek,
13753 + .read = aufs_read,
13754 + .write = aufs_write,
13755 + .read_iter = aufs_read_iter,
13756 + .write_iter = aufs_write_iter,
13758 +#ifdef CONFIG_AUFS_POLL
13759 + .poll = aufs_poll,
13761 + .unlocked_ioctl = aufs_ioctl_nondir,
13762 +#ifdef CONFIG_COMPAT
13763 + .compat_ioctl = aufs_compat_ioctl_nondir,
13765 + .mmap = aufs_mmap,
13766 + .open = aufs_open_nondir,
13767 + .flush = aufs_flush_nondir,
13768 + .release = aufs_release_nondir,
13769 + .fsync = aufs_fsync_nondir,
13770 + /* .aio_fsync = aufs_aio_fsync_nondir, */
13771 + .fasync = aufs_fasync,
13772 + /* .sendpage = aufs_sendpage, */
13773 + .splice_write = aufs_splice_write,
13774 + .splice_read = aufs_splice_read,
13776 + .aio_splice_write = aufs_aio_splice_write,
13777 + .aio_splice_read = aufs_aio_splice_read,
13779 + .fallocate = aufs_fallocate
13781 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
13782 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
13783 +++ linux/fs/aufs/fstype.h 2014-01-30 21:10:02.850815069 +0100
13786 + * Copyright (C) 2005-2014 Junjiro R. Okajima
13788 + * This program, aufs is free software; you can redistribute it and/or modify
13789 + * it under the terms of the GNU General Public License as published by
13790 + * the Free Software Foundation; either version 2 of the License, or
13791 + * (at your option) any later version.
13793 + * This program is distributed in the hope that it will be useful,
13794 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13795 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13796 + * GNU General Public License for more details.
13798 + * You should have received a copy of the GNU General Public License
13799 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13803 + * judging filesystem type
13806 +#ifndef __AUFS_FSTYPE_H__
13807 +#define __AUFS_FSTYPE_H__
13811 +#include <linux/fs.h>
13812 +#include <linux/magic.h>
13813 +#include <linux/romfs_fs.h>
13815 +static inline int au_test_aufs(struct super_block *sb)
13817 + return sb->s_magic == AUFS_SUPER_MAGIC;
13820 +static inline const char *au_sbtype(struct super_block *sb)
13822 + return sb->s_type->name;
13825 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
13827 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
13828 + return sb->s_magic == ROMFS_MAGIC;
13834 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
13836 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
13837 + return sb->s_magic == ISOFS_SUPER_MAGIC;
13843 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
13845 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
13846 + return sb->s_magic == CRAMFS_MAGIC;
13851 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
13853 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
13854 + return sb->s_magic == NFS_SUPER_MAGIC;
13860 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
13862 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
13863 + return sb->s_magic == FUSE_SUPER_MAGIC;
13869 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
13871 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
13872 + return sb->s_magic == XFS_SB_MAGIC;
13878 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
13880 +#ifdef CONFIG_TMPFS
13881 + return sb->s_magic == TMPFS_MAGIC;
13887 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
13889 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
13890 + return !strcmp(au_sbtype(sb), "ecryptfs");
13896 +static inline int au_test_ocfs2(struct super_block *sb __maybe_unused)
13898 +#if defined(CONFIG_OCFS2_FS) || defined(CONFIG_OCFS2_FS_MODULE)
13899 + return sb->s_magic == OCFS2_SUPER_MAGIC;
13905 +static inline int au_test_ocfs2_dlmfs(struct super_block *sb __maybe_unused)
13907 +#if defined(CONFIG_OCFS2_FS_O2CB) || defined(CONFIG_OCFS2_FS_O2CB_MODULE)
13908 + return sb->s_magic == DLMFS_MAGIC;
13914 +static inline int au_test_coda(struct super_block *sb __maybe_unused)
13916 +#if defined(CONFIG_CODA_FS) || defined(CONFIG_CODA_FS_MODULE)
13917 + return sb->s_magic == CODA_SUPER_MAGIC;
13923 +static inline int au_test_v9fs(struct super_block *sb __maybe_unused)
13925 +#if defined(CONFIG_9P_FS) || defined(CONFIG_9P_FS_MODULE)
13926 + return sb->s_magic == V9FS_MAGIC;
13932 +static inline int au_test_ext4(struct super_block *sb __maybe_unused)
13934 +#if defined(CONFIG_EXT4_FS) || defined(CONFIG_EXT4_FS_MODULE)
13935 + return sb->s_magic == EXT4_SUPER_MAGIC;
13941 +static inline int au_test_sysv(struct super_block *sb __maybe_unused)
13943 +#if defined(CONFIG_SYSV_FS) || defined(CONFIG_SYSV_FS_MODULE)
13944 + return !strcmp(au_sbtype(sb), "sysv");
13950 +static inline int au_test_ramfs(struct super_block *sb)
13952 + return sb->s_magic == RAMFS_MAGIC;
13955 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
13957 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
13958 + return sb->s_magic == UBIFS_SUPER_MAGIC;
13964 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
13966 +#ifdef CONFIG_PROC_FS
13967 + return sb->s_magic == PROC_SUPER_MAGIC;
13973 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
13975 +#ifdef CONFIG_SYSFS
13976 + return sb->s_magic == SYSFS_MAGIC;
13982 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
13984 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
13985 + return sb->s_magic == CONFIGFS_MAGIC;
13991 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
13993 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
13994 + return sb->s_magic == MINIX3_SUPER_MAGIC
13995 + || sb->s_magic == MINIX2_SUPER_MAGIC
13996 + || sb->s_magic == MINIX2_SUPER_MAGIC2
13997 + || sb->s_magic == MINIX_SUPER_MAGIC
13998 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14004 +static inline int au_test_cifs(struct super_block *sb __maybe_unused)
14006 +#if defined(CONFIG_CIFS_FS) || defined(CONFIGCIFS_FS_MODULE)
14007 + return sb->s_magic == CIFS_MAGIC_NUMBER;
14013 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14015 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
14016 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14022 +static inline int au_test_msdos(struct super_block *sb)
14024 + return au_test_fat(sb);
14027 +static inline int au_test_vfat(struct super_block *sb)
14029 + return au_test_fat(sb);
14032 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14034 +#ifdef CONFIG_SECURITYFS
14035 + return sb->s_magic == SECURITYFS_MAGIC;
14041 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14043 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
14044 + return sb->s_magic == SQUASHFS_MAGIC;
14050 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14052 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
14053 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14059 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14061 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
14062 + return sb->s_magic == XENFS_SUPER_MAGIC;
14068 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14070 +#ifdef CONFIG_DEBUG_FS
14071 + return sb->s_magic == DEBUGFS_MAGIC;
14077 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14079 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
14080 + return sb->s_magic == NILFS_SUPER_MAGIC;
14086 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14088 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
14089 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14095 +/* ---------------------------------------------------------------------- */
14097 + * they can't be an aufs branch.
14099 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14102 +#ifndef CONFIG_AUFS_BR_RAMFS
14103 + au_test_ramfs(sb) ||
14105 + au_test_procfs(sb)
14106 + || au_test_sysfs(sb)
14107 + || au_test_configfs(sb)
14108 + || au_test_debugfs(sb)
14109 + || au_test_securityfs(sb)
14110 + || au_test_xenfs(sb)
14111 + || au_test_ecryptfs(sb)
14112 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14113 + || au_test_aufs(sb); /* will be supported in next version */
14116 +static inline int au_test_fs_remote(struct super_block *sb)
14118 + return !au_test_tmpfs(sb)
14119 +#ifdef CONFIG_AUFS_BR_RAMFS
14120 + && !au_test_ramfs(sb)
14122 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14125 +/* ---------------------------------------------------------------------- */
14128 + * Note: these functions (below) are created after reading ->getattr() in all
14129 + * filesystems under linux/fs. it means we have to do so in every update...
14133 + * some filesystems require getattr to refresh the inode attributes before
14135 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14136 + * and leave the work for d_revalidate()
14138 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14140 + return au_test_nfs(sb)
14141 + || au_test_fuse(sb)
14142 + /* || au_test_ocfs2(sb) */ /* untested */
14143 + /* || au_test_btrfs(sb) */ /* untested */
14144 + /* || au_test_coda(sb) */ /* untested */
14145 + /* || au_test_v9fs(sb) */ /* untested */
14150 + * filesystems which don't maintain i_size or i_blocks.
14152 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14154 + return au_test_xfs(sb)
14155 + || au_test_btrfs(sb)
14156 + || au_test_ubifs(sb)
14157 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14158 + /* || au_test_ext4(sb) */ /* untested */
14159 + /* || au_test_ocfs2(sb) */ /* untested */
14160 + /* || au_test_ocfs2_dlmfs(sb) */ /* untested */
14161 + /* || au_test_sysv(sb) */ /* untested */
14162 + /* || au_test_minix(sb) */ /* untested */
14167 + * filesystems which don't store the correct value in some of their inode
14170 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14172 + return au_test_fs_bad_iattr_size(sb)
14173 + /* || au_test_cifs(sb) */ /* untested */
14174 + || au_test_fat(sb)
14175 + || au_test_msdos(sb)
14176 + || au_test_vfat(sb);
14179 +/* they don't check i_nlink in link(2) */
14180 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14182 + return au_test_tmpfs(sb)
14183 +#ifdef CONFIG_AUFS_BR_RAMFS
14184 + || au_test_ramfs(sb)
14186 + || au_test_ubifs(sb)
14187 + || au_test_hfsplus(sb);
14191 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14193 +static inline int au_test_fs_notime(struct super_block *sb)
14195 + return au_test_nfs(sb)
14196 + || au_test_fuse(sb)
14197 + || au_test_ubifs(sb)
14198 + /* || au_test_cifs(sb) */ /* untested */
14203 + * filesystems which requires replacing i_mapping.
14205 +static inline int au_test_fs_bad_mapping(struct super_block *sb)
14207 + return au_test_fuse(sb)
14208 + || au_test_ubifs(sb);
14211 +/* temporary support for i#1 in cramfs */
14212 +static inline int au_test_fs_unique_ino(struct inode *inode)
14214 + if (au_test_cramfs(inode->i_sb))
14215 + return inode->i_ino != 1;
14219 +/* ---------------------------------------------------------------------- */
14222 + * the filesystem where the xino files placed must support i/o after unlink and
14223 + * maintain i_size and i_blocks.
14225 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14227 + return au_test_fs_remote(sb)
14228 + || au_test_fs_bad_iattr_size(sb)
14229 + /* don't want unnecessary work for xino */
14230 + || au_test_aufs(sb)
14231 + || au_test_ecryptfs(sb)
14232 + || au_test_nilfs(sb);
14235 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14237 + return au_test_tmpfs(sb)
14238 + || au_test_ramfs(sb);
14242 + * test if the @sb is real-readonly.
14244 +static inline int au_test_fs_rr(struct super_block *sb)
14246 + return au_test_squashfs(sb)
14247 + || au_test_iso9660(sb)
14248 + || au_test_cramfs(sb)
14249 + || au_test_romfs(sb);
14252 +#endif /* __KERNEL__ */
14253 +#endif /* __AUFS_FSTYPE_H__ */
14254 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14255 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14256 +++ linux/fs/aufs/hfsnotify.c 2014-08-14 10:16:04.515942371 +0200
14259 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14261 + * This program, aufs is free software; you can redistribute it and/or modify
14262 + * it under the terms of the GNU General Public License as published by
14263 + * the Free Software Foundation; either version 2 of the License, or
14264 + * (at your option) any later version.
14266 + * This program is distributed in the hope that it will be useful,
14267 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14268 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14269 + * GNU General Public License for more details.
14271 + * You should have received a copy of the GNU General Public License
14272 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14276 + * fsnotify for the lower directories
14281 +/* FS_IN_IGNORED is unnecessary */
14282 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14283 + | FS_CREATE | FS_EVENT_ON_CHILD);
14284 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14285 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14287 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14289 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14292 + au_cache_free_hnotify(hn);
14293 + smp_mb__before_atomic();
14294 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14295 + wake_up(&au_hfsn_wq);
14298 +static int au_hfsn_alloc(struct au_hinode *hinode)
14301 + struct au_hnotify *hn;
14302 + struct super_block *sb;
14303 + struct au_branch *br;
14304 + struct fsnotify_mark *mark;
14305 + aufs_bindex_t bindex;
14307 + hn = hinode->hi_notify;
14308 + sb = hn->hn_aufs_inode->i_sb;
14309 + bindex = au_br_index(sb, hinode->hi_id);
14310 + br = au_sbr(sb, bindex);
14311 + AuDebugOn(!br->br_hfsn);
14313 + mark = &hn->hn_mark;
14314 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14315 + mark->mask = AuHfsnMask;
14317 + * by udba rename or rmdir, aufs assign a new inode to the known
14318 + * h_inode, so specify 1 to allow dups.
14320 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14321 + /*mnt*/NULL, /*allow_dups*/1);
14322 + /* even if err */
14323 + fsnotify_put_mark(mark);
14328 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14330 + struct fsnotify_mark *mark;
14331 + unsigned long long ull;
14332 + struct fsnotify_group *group;
14334 + ull = atomic64_inc_return(&au_hfsn_ifree);
14337 + mark = &hn->hn_mark;
14338 + spin_lock(&mark->lock);
14339 + group = mark->group;
14340 + fsnotify_get_group(group);
14341 + spin_unlock(&mark->lock);
14342 + fsnotify_destroy_mark(mark, group);
14343 + fsnotify_put_group(group);
14345 + /* free hn by myself */
14349 +/* ---------------------------------------------------------------------- */
14351 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14353 + struct fsnotify_mark *mark;
14355 + mark = &hinode->hi_notify->hn_mark;
14356 + spin_lock(&mark->lock);
14358 + AuDebugOn(mark->mask & AuHfsnMask);
14359 + mark->mask |= AuHfsnMask;
14361 + AuDebugOn(!(mark->mask & AuHfsnMask));
14362 + mark->mask &= ~AuHfsnMask;
14364 + spin_unlock(&mark->lock);
14365 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14368 +/* ---------------------------------------------------------------------- */
14370 +/* #define AuDbgHnotify */
14371 +#ifdef AuDbgHnotify
14372 +static char *au_hfsn_name(u32 mask)
14374 +#ifdef CONFIG_AUFS_DEBUG
14375 +#define test_ret(flag) \
14377 + if (mask & flag) \
14380 + test_ret(FS_ACCESS);
14381 + test_ret(FS_MODIFY);
14382 + test_ret(FS_ATTRIB);
14383 + test_ret(FS_CLOSE_WRITE);
14384 + test_ret(FS_CLOSE_NOWRITE);
14385 + test_ret(FS_OPEN);
14386 + test_ret(FS_MOVED_FROM);
14387 + test_ret(FS_MOVED_TO);
14388 + test_ret(FS_CREATE);
14389 + test_ret(FS_DELETE);
14390 + test_ret(FS_DELETE_SELF);
14391 + test_ret(FS_MOVE_SELF);
14392 + test_ret(FS_UNMOUNT);
14393 + test_ret(FS_Q_OVERFLOW);
14394 + test_ret(FS_IN_IGNORED);
14395 + test_ret(FS_IN_ISDIR);
14396 + test_ret(FS_IN_ONESHOT);
14397 + test_ret(FS_EVENT_ON_CHILD);
14406 +/* ---------------------------------------------------------------------- */
14408 +static void au_hfsn_free_group(struct fsnotify_group *group)
14410 + struct au_br_hfsnotify *hfsn = group->private;
14416 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14417 + struct inode *inode,
14418 + struct fsnotify_mark *inode_mark,
14419 + struct fsnotify_mark *vfsmount_mark,
14420 + u32 mask, void *data, int data_type,
14421 + const unsigned char *file_name, u32 cookie)
14424 + struct au_hnotify *hnotify;
14425 + struct inode *h_dir, *h_inode;
14426 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14428 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14431 + /* if FS_UNMOUNT happens, there must be another bug */
14432 + AuDebugOn(mask & FS_UNMOUNT);
14433 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14438 +#ifdef AuDbgHnotify
14440 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14441 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14442 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14443 + h_dir->i_ino, mask, au_hfsn_name(mask),
14444 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14445 + /* WARN_ON(1); */
14450 + AuDebugOn(!inode_mark);
14451 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14452 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14458 +static struct fsnotify_ops au_hfsn_ops = {
14459 + .handle_event = au_hfsn_handle_event,
14460 + .free_group_priv = au_hfsn_free_group
14463 +/* ---------------------------------------------------------------------- */
14465 +static void au_hfsn_fin_br(struct au_branch *br)
14467 + struct au_br_hfsnotify *hfsn;
14469 + hfsn = br->br_hfsn;
14471 + fsnotify_put_group(hfsn->hfsn_group);
14474 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14477 + struct fsnotify_group *group;
14478 + struct au_br_hfsnotify *hfsn;
14481 + br->br_hfsn = NULL;
14482 + if (!au_br_hnotifyable(perm))
14486 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14487 + if (unlikely(!hfsn))
14491 + group = fsnotify_alloc_group(&au_hfsn_ops);
14492 + if (IS_ERR(group)) {
14493 + err = PTR_ERR(group);
14494 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14498 + group->private = hfsn;
14499 + hfsn->hfsn_group = group;
14500 + br->br_hfsn = hfsn;
14501 + goto out; /* success */
14509 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14514 + if (!br->br_hfsn)
14515 + err = au_hfsn_init_br(br, perm);
14520 +/* ---------------------------------------------------------------------- */
14522 +static void au_hfsn_fin(void)
14524 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14525 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14528 +const struct au_hnotify_op au_hnotify_op = {
14529 + .ctl = au_hfsn_ctl,
14530 + .alloc = au_hfsn_alloc,
14531 + .free = au_hfsn_free,
14533 + .fin = au_hfsn_fin,
14535 + .reset_br = au_hfsn_reset_br,
14536 + .fin_br = au_hfsn_fin_br,
14537 + .init_br = au_hfsn_init_br
14539 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14540 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14541 +++ linux/fs/aufs/hfsplus.c 2014-01-30 21:10:02.850815069 +0100
14544 + * Copyright (C) 2010-2014 Junjiro R. Okajima
14546 + * This program, aufs is free software; you can redistribute it and/or modify
14547 + * it under the terms of the GNU General Public License as published by
14548 + * the Free Software Foundation; either version 2 of the License, or
14549 + * (at your option) any later version.
14551 + * This program is distributed in the hope that it will be useful,
14552 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14553 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14554 + * GNU General Public License for more details.
14556 + * You should have received a copy of the GNU General Public License
14557 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14561 + * special support for filesystems which aqucires an inode mutex
14562 + * at final closing a file, eg, hfsplus.
14564 + * This trick is very simple and stupid, just to open the file before really
14565 + * neceeary open to tell hfsplus that this is not the final closing.
14566 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14567 + * and au_h_open_post() after releasing it.
14572 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14575 + struct file *h_file;
14576 + struct dentry *h_dentry;
14578 + h_dentry = au_h_dptr(dentry, bindex);
14579 + AuDebugOn(!h_dentry);
14580 + AuDebugOn(!h_dentry->d_inode);
14583 + if (au_test_hfsplus(h_dentry->d_sb)
14584 + && S_ISREG(h_dentry->d_inode->i_mode))
14585 + h_file = au_h_open(dentry, bindex,
14586 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14587 + /*file*/NULL, force_wr);
14591 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14592 + struct file *h_file)
14596 + au_sbr_put(dentry->d_sb, bindex);
14599 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
14600 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14601 +++ linux/fs/aufs/hnotify.c 2014-08-14 10:16:04.515942371 +0200
14604 + * Copyright (C) 2005-2014 Junjiro R. Okajima
14606 + * This program, aufs is free software; you can redistribute it and/or modify
14607 + * it under the terms of the GNU General Public License as published by
14608 + * the Free Software Foundation; either version 2 of the License, or
14609 + * (at your option) any later version.
14611 + * This program is distributed in the hope that it will be useful,
14612 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14613 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14614 + * GNU General Public License for more details.
14616 + * You should have received a copy of the GNU General Public License
14617 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14621 + * abstraction to notify the direct changes on lower directories
14626 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14629 + struct au_hnotify *hn;
14632 + hn = au_cache_alloc_hnotify();
14634 + hn->hn_aufs_inode = inode;
14635 + hinode->hi_notify = hn;
14636 + err = au_hnotify_op.alloc(hinode);
14638 + if (unlikely(err)) {
14639 + hinode->hi_notify = NULL;
14640 + au_cache_free_hnotify(hn);
14642 + * The upper dir was removed by udba, but the same named
14643 + * dir left. In this case, aufs assignes a new inode
14644 + * number and set the monitor again.
14645 + * For the lower dir, the old monitnor is still left.
14647 + if (err == -EEXIST)
14656 +void au_hn_free(struct au_hinode *hinode)
14658 + struct au_hnotify *hn;
14660 + hn = hinode->hi_notify;
14662 + hinode->hi_notify = NULL;
14663 + if (au_hnotify_op.free(hinode, hn))
14664 + au_cache_free_hnotify(hn);
14668 +/* ---------------------------------------------------------------------- */
14670 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
14672 + if (hinode->hi_notify)
14673 + au_hnotify_op.ctl(hinode, do_set);
14676 +void au_hn_reset(struct inode *inode, unsigned int flags)
14678 + aufs_bindex_t bindex, bend;
14679 + struct inode *hi;
14680 + struct dentry *iwhdentry;
14682 + bend = au_ibend(inode);
14683 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14684 + hi = au_h_iptr(inode, bindex);
14688 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
14689 + iwhdentry = au_hi_wh(inode, bindex);
14693 + au_set_h_iptr(inode, bindex, NULL, 0);
14694 + au_set_h_iptr(inode, bindex, au_igrab(hi),
14695 + flags & ~AuHi_XINO);
14698 + /* mutex_unlock(&hi->i_mutex); */
14702 +/* ---------------------------------------------------------------------- */
14704 +static int hn_xino(struct inode *inode, struct inode *h_inode)
14707 + aufs_bindex_t bindex, bend, bfound, bstart;
14708 + struct inode *h_i;
14711 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14712 + pr_warn("branch root dir was changed\n");
14717 + bend = au_ibend(inode);
14718 + bstart = au_ibstart(inode);
14719 +#if 0 /* reserved for future use */
14720 + if (bindex == bend) {
14721 + /* keep this ino in rename case */
14725 + for (bindex = bstart; bindex <= bend; bindex++)
14726 + if (au_h_iptr(inode, bindex) == h_inode) {
14733 + for (bindex = bstart; bindex <= bend; bindex++) {
14734 + h_i = au_h_iptr(inode, bindex);
14738 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
14739 + /* ignore this error */
14740 + /* bad action? */
14743 + /* children inode number will be broken */
14750 +static int hn_gen_tree(struct dentry *dentry)
14752 + int err, i, j, ndentry;
14753 + struct au_dcsub_pages dpages;
14754 + struct au_dpage *dpage;
14755 + struct dentry **dentries;
14757 + err = au_dpages_init(&dpages, GFP_NOFS);
14758 + if (unlikely(err))
14760 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
14761 + if (unlikely(err))
14764 + for (i = 0; i < dpages.ndpage; i++) {
14765 + dpage = dpages.dpages + i;
14766 + dentries = dpage->dentries;
14767 + ndentry = dpage->ndentry;
14768 + for (j = 0; j < ndentry; j++) {
14769 + struct dentry *d;
14777 + /* todo: reset children xino?
14778 + cached children only? */
14779 + au_iigen_dec(d->d_inode);
14784 + au_dpages_free(&dpages);
14787 + /* discard children */
14788 + dentry_unhash(dentry);
14796 + * return 0 if processed.
14798 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
14799 + const unsigned int isdir)
14802 + struct dentry *d;
14803 + struct qstr *dname;
14806 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14807 + pr_warn("branch root dir was changed\n");
14813 + AuDebugOn(!name);
14814 + au_iigen_dec(inode);
14815 + spin_lock(&inode->i_lock);
14816 + hlist_for_each_entry(d, &inode->i_dentry, d_alias) {
14817 + spin_lock(&d->d_lock);
14818 + dname = &d->d_name;
14819 + if (dname->len != nlen
14820 + && memcmp(dname->name, name, nlen)) {
14821 + spin_unlock(&d->d_lock);
14826 + spin_unlock(&d->d_lock);
14829 + spin_unlock(&inode->i_lock);
14831 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
14832 + d = d_find_alias(inode);
14834 + au_iigen_dec(inode);
14838 + spin_lock(&d->d_lock);
14839 + dname = &d->d_name;
14840 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
14841 + spin_unlock(&d->d_lock);
14842 + err = hn_gen_tree(d);
14843 + spin_lock(&d->d_lock);
14845 + spin_unlock(&d->d_lock);
14854 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
14857 + struct inode *inode;
14859 + inode = dentry->d_inode;
14860 + if (IS_ROOT(dentry)
14861 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
14863 + pr_warn("branch root dir was changed\n");
14869 + au_digen_dec(dentry);
14871 + au_iigen_dec(inode);
14873 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
14875 + err = hn_gen_tree(dentry);
14882 +/* ---------------------------------------------------------------------- */
14884 +/* hnotify job flags */
14885 +#define AuHnJob_XINO0 1
14886 +#define AuHnJob_GEN (1 << 1)
14887 +#define AuHnJob_DIRENT (1 << 2)
14888 +#define AuHnJob_ISDIR (1 << 3)
14889 +#define AuHnJob_TRYXINO0 (1 << 4)
14890 +#define AuHnJob_MNTPNT (1 << 5)
14891 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
14892 +#define au_fset_hnjob(flags, name) \
14893 + do { (flags) |= AuHnJob_##name; } while (0)
14894 +#define au_fclr_hnjob(flags, name) \
14895 + do { (flags) &= ~AuHnJob_##name; } while (0)
14903 +struct au_hnotify_args {
14904 + struct inode *h_dir, *dir, *h_child_inode;
14906 + unsigned int flags[AuHnLast];
14907 + unsigned int h_child_nlen;
14908 + char h_child_name[];
14911 +struct hn_job_args {
14912 + unsigned int flags;
14913 + struct inode *inode, *h_inode, *dir, *h_dir;
14914 + struct dentry *dentry;
14919 +static int hn_job(struct hn_job_args *a)
14921 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
14925 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
14926 + hn_xino(a->inode, a->h_inode); /* ignore this error */
14928 + if (au_ftest_hnjob(a->flags, TRYXINO0)
14931 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
14932 + if (!a->h_inode->i_nlink
14933 + && !(a->h_inode->i_state & I_LINKABLE))
14934 + hn_xino(a->inode, a->h_inode); /* ignore this error */
14935 + mutex_unlock(&a->h_inode->i_mutex);
14938 + /* make the generation obsolete */
14939 + if (au_ftest_hnjob(a->flags, GEN)) {
14942 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
14944 + if (e && a->dentry)
14945 + hn_gen_by_name(a->dentry, isdir);
14946 + /* ignore this error */
14949 + /* make dir entries obsolete */
14950 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
14951 + struct au_vdir *vdir;
14953 + vdir = au_ivdir(a->inode);
14955 + vdir->vd_jiffy = 0;
14956 + /* IMustLock(a->inode); */
14957 + /* a->inode->i_version++; */
14960 + /* can do nothing but warn */
14961 + if (au_ftest_hnjob(a->flags, MNTPNT)
14963 + && d_mountpoint(a->dentry))
14964 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
14969 +/* ---------------------------------------------------------------------- */
14971 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
14972 + struct inode *dir)
14974 + struct dentry *dentry, *d, *parent;
14975 + struct qstr *dname;
14977 + parent = d_find_alias(dir);
14982 + spin_lock(&parent->d_lock);
14983 + list_for_each_entry(d, &parent->d_subdirs, d_u.d_child) {
14984 + /* AuDbg("%pd\n", d); */
14985 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
14986 + dname = &d->d_name;
14987 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
14988 + goto cont_unlock;
14992 + goto cont_unlock;
14993 + if (d_count(d)) {
14994 + dentry = dget_dlock(d);
14995 + spin_unlock(&d->d_lock);
15000 + spin_unlock(&d->d_lock);
15002 + spin_unlock(&parent->d_lock);
15006 + di_write_lock_child(dentry);
15011 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15012 + aufs_bindex_t bindex, ino_t h_ino)
15014 + struct inode *inode;
15019 + err = au_xino_read(sb, bindex, h_ino, &ino);
15021 + inode = ilookup(sb, ino);
15025 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15026 + pr_warn("wrong root branch\n");
15032 + ii_write_lock_child(inode);
15038 +static void au_hn_bh(void *_args)
15040 + struct au_hnotify_args *a = _args;
15041 + struct super_block *sb;
15042 + aufs_bindex_t bindex, bend, bfound;
15043 + unsigned char xino, try_iput;
15045 + struct inode *inode;
15047 + struct hn_job_args args;
15048 + struct dentry *dentry;
15049 + struct au_sbinfo *sbinfo;
15051 + AuDebugOn(!_args);
15052 + AuDebugOn(!a->h_dir);
15053 + AuDebugOn(!a->dir);
15054 + AuDebugOn(!a->mask);
15055 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15056 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15057 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15062 + * do not lock a->dir->i_mutex here
15063 + * because of d_revalidate() may cause a deadlock.
15065 + sb = a->dir->i_sb;
15067 + sbinfo = au_sbi(sb);
15068 + AuDebugOn(!sbinfo);
15069 + si_write_lock(sb, AuLock_NOPLMW);
15071 + ii_read_lock_parent(a->dir);
15073 + bend = au_ibend(a->dir);
15074 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
15075 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15079 + ii_read_unlock(a->dir);
15080 + if (unlikely(bfound < 0))
15083 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15085 + if (a->h_child_inode)
15086 + h_ino = a->h_child_inode->i_ino;
15088 + if (a->h_child_nlen
15089 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15090 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15091 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15095 + inode = dentry->d_inode;
15096 + if (xino && !inode && h_ino
15097 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15098 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15099 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15100 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15104 + args.flags = a->flags[AuHn_CHILD];
15105 + args.dentry = dentry;
15106 + args.inode = inode;
15107 + args.h_inode = a->h_child_inode;
15108 + args.dir = a->dir;
15109 + args.h_dir = a->h_dir;
15110 + args.h_name = a->h_child_name;
15111 + args.h_nlen = a->h_child_nlen;
15112 + err = hn_job(&args);
15114 + if (au_di(dentry))
15115 + di_write_unlock(dentry);
15118 + if (inode && try_iput) {
15119 + ii_write_unlock(inode);
15123 + ii_write_lock_parent(a->dir);
15124 + args.flags = a->flags[AuHn_PARENT];
15125 + args.dentry = NULL;
15126 + args.inode = a->dir;
15127 + args.h_inode = a->h_dir;
15129 + args.h_dir = NULL;
15130 + args.h_name = NULL;
15132 + err = hn_job(&args);
15133 + ii_write_unlock(a->dir);
15136 + iput(a->h_child_inode);
15139 + si_write_unlock(sb);
15140 + au_nwt_done(&sbinfo->si_nowait);
15144 +/* ---------------------------------------------------------------------- */
15146 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15147 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15150 + unsigned int flags[AuHnLast], f;
15151 + unsigned char isdir, isroot, wh;
15152 + struct inode *dir;
15153 + struct au_hnotify_args *args;
15154 + char *p, *h_child_name;
15157 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15158 + dir = igrab(hnotify->hn_aufs_inode);
15162 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15164 + h_child_name = (void *)h_child_qstr->name;
15165 + len = h_child_qstr->len;
15166 + if (h_child_name) {
15167 + if (len > AUFS_WH_PFX_LEN
15168 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15169 + h_child_name += AUFS_WH_PFX_LEN;
15170 + len -= AUFS_WH_PFX_LEN;
15176 + if (h_child_inode)
15177 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15178 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15179 + flags[AuHn_CHILD] = 0;
15181 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15182 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15183 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15184 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15185 + case FS_MOVED_FROM:
15186 + case FS_MOVED_TO:
15187 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15188 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15191 + AuDebugOn(!h_child_name);
15196 + * aufs never be able to get this child inode.
15197 + * revalidation should be in d_revalidate()
15198 + * by checking i_nlink, i_generation or d_unhashed().
15200 + AuDebugOn(!h_child_name);
15201 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15202 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15210 + h_child_inode = NULL;
15213 + /* iput() and kfree() will be called in au_hnotify() */
15214 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15215 + if (unlikely(!args)) {
15216 + AuErr1("no memory\n");
15220 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15221 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15222 + args->mask = mask;
15224 + args->h_dir = igrab(h_dir);
15225 + if (h_child_inode)
15226 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15227 + args->h_child_inode = h_child_inode;
15228 + args->h_child_nlen = len;
15230 + p = (void *)args;
15231 + p += sizeof(*args);
15232 + memcpy(p, h_child_name, len);
15236 + /* NFS fires the event for silly-renamed one from kworker */
15238 + if (!dir->i_nlink
15239 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15241 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15242 + if (unlikely(err)) {
15243 + pr_err("wkq %d\n", err);
15244 + iput(args->h_child_inode);
15245 + iput(args->h_dir);
15254 +/* ---------------------------------------------------------------------- */
15256 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15260 + AuDebugOn(!(udba & AuOptMask_UDBA));
15263 + if (au_hnotify_op.reset_br)
15264 + err = au_hnotify_op.reset_br(udba, br, perm);
15269 +int au_hnotify_init_br(struct au_branch *br, int perm)
15274 + if (au_hnotify_op.init_br)
15275 + err = au_hnotify_op.init_br(br, perm);
15280 +void au_hnotify_fin_br(struct au_branch *br)
15282 + if (au_hnotify_op.fin_br)
15283 + au_hnotify_op.fin_br(br);
15286 +static void au_hn_destroy_cache(void)
15288 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15289 + au_cachep[AuCache_HNOTIFY] = NULL;
15292 +int __init au_hnotify_init(void)
15297 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15298 + if (au_cachep[AuCache_HNOTIFY]) {
15300 + if (au_hnotify_op.init)
15301 + err = au_hnotify_op.init();
15302 + if (unlikely(err))
15303 + au_hn_destroy_cache();
15309 +void au_hnotify_fin(void)
15311 + if (au_hnotify_op.fin)
15312 + au_hnotify_op.fin();
15313 + /* cf. au_cache_fin() */
15314 + if (au_cachep[AuCache_HNOTIFY])
15315 + au_hn_destroy_cache();
15317 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15318 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15319 +++ linux/fs/aufs/iinfo.c 2014-08-14 10:15:45.128609525 +0200
15322 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15324 + * This program, aufs is free software; you can redistribute it and/or modify
15325 + * it under the terms of the GNU General Public License as published by
15326 + * the Free Software Foundation; either version 2 of the License, or
15327 + * (at your option) any later version.
15329 + * This program is distributed in the hope that it will be useful,
15330 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15331 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15332 + * GNU General Public License for more details.
15334 + * You should have received a copy of the GNU General Public License
15335 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15339 + * inode private data
15344 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15346 + struct inode *h_inode;
15348 + IiMustAnyLock(inode);
15350 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
15351 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15355 +/* todo: hard/soft set? */
15356 +void au_hiput(struct au_hinode *hinode)
15358 + au_hn_free(hinode);
15359 + dput(hinode->hi_whdentry);
15360 + iput(hinode->hi_inode);
15363 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15365 + unsigned int flags;
15366 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15369 + if (au_opt_test(mnt_flags, XINO))
15370 + au_fset_hi(flags, XINO);
15371 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15372 + au_fset_hi(flags, HNOTIFY);
15376 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15377 + struct inode *h_inode, unsigned int flags)
15379 + struct au_hinode *hinode;
15380 + struct inode *hi;
15381 + struct au_iinfo *iinfo = au_ii(inode);
15383 + IiMustWriteLock(inode);
15385 + hinode = iinfo->ii_hinode + bindex;
15386 + hi = hinode->hi_inode;
15387 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15390 + au_hiput(hinode);
15391 + hinode->hi_inode = h_inode;
15394 + struct super_block *sb = inode->i_sb;
15395 + struct au_branch *br;
15397 + AuDebugOn(inode->i_mode
15398 + && (h_inode->i_mode & S_IFMT)
15399 + != (inode->i_mode & S_IFMT));
15400 + if (bindex == iinfo->ii_bstart)
15401 + au_cpup_igen(inode, h_inode);
15402 + br = au_sbr(sb, bindex);
15403 + hinode->hi_id = br->br_id;
15404 + if (au_ftest_hi(flags, XINO)) {
15405 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15407 + if (unlikely(err))
15408 + AuIOErr1("failed au_xino_write() %d\n", err);
15411 + if (au_ftest_hi(flags, HNOTIFY)
15412 + && au_br_hnotifyable(br->br_perm)) {
15413 + err = au_hn_alloc(hinode, inode);
15414 + if (unlikely(err))
15415 + AuIOErr1("au_hn_alloc() %d\n", err);
15420 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15421 + struct dentry *h_wh)
15423 + struct au_hinode *hinode;
15425 + IiMustWriteLock(inode);
15427 + hinode = au_ii(inode)->ii_hinode + bindex;
15428 + AuDebugOn(hinode->hi_whdentry);
15429 + hinode->hi_whdentry = h_wh;
15432 +void au_update_iigen(struct inode *inode, int half)
15434 + struct au_iinfo *iinfo;
15435 + struct au_iigen *iigen;
15436 + unsigned int sigen;
15438 + sigen = au_sigen(inode->i_sb);
15439 + iinfo = au_ii(inode);
15440 + iigen = &iinfo->ii_generation;
15441 + spin_lock(&iinfo->ii_genspin);
15442 + iigen->ig_generation = sigen;
15444 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15446 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15447 + spin_unlock(&iinfo->ii_genspin);
15450 +/* it may be called at remount time, too */
15451 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15453 + struct au_iinfo *iinfo;
15454 + aufs_bindex_t bindex, bend;
15456 + iinfo = au_ii(inode);
15460 + IiMustWriteLock(inode);
15462 + if (do_put_zero && iinfo->ii_bstart >= 0) {
15463 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15465 + struct inode *h_i;
15467 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
15470 + && !(h_i->i_state & I_LINKABLE))
15471 + au_set_h_iptr(inode, bindex, NULL, 0);
15475 + iinfo->ii_bstart = -1;
15476 + iinfo->ii_bend = -1;
15477 + bend = au_sbend(inode->i_sb);
15478 + for (bindex = 0; bindex <= bend; bindex++)
15479 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15480 + iinfo->ii_bstart = bindex;
15483 + if (iinfo->ii_bstart >= 0)
15484 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
15485 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15486 + iinfo->ii_bend = bindex;
15489 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
15492 +/* ---------------------------------------------------------------------- */
15494 +void au_icntnr_init_once(void *_c)
15496 + struct au_icntnr *c = _c;
15497 + struct au_iinfo *iinfo = &c->iinfo;
15498 + static struct lock_class_key aufs_ii;
15500 + spin_lock_init(&iinfo->ii_genspin);
15501 + au_rw_init(&iinfo->ii_rwsem);
15502 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
15503 + inode_init_once(&c->vfs_inode);
15506 +int au_iinfo_init(struct inode *inode)
15508 + struct au_iinfo *iinfo;
15509 + struct super_block *sb;
15512 + sb = inode->i_sb;
15513 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15514 + nbr = au_sbend(sb) + 1;
15515 + if (unlikely(nbr <= 0))
15517 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15518 + if (iinfo->ii_hinode) {
15519 + au_ninodes_inc(sb);
15520 + for (i = 0; i < nbr; i++)
15521 + iinfo->ii_hinode[i].hi_id = -1;
15523 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15524 + iinfo->ii_bstart = -1;
15525 + iinfo->ii_bend = -1;
15526 + iinfo->ii_vdir = NULL;
15532 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
15535 + struct au_hinode *hip;
15537 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15540 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
15542 + sz = sizeof(*hip);
15543 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
15545 + iinfo->ii_hinode = hip;
15552 +void au_iinfo_fin(struct inode *inode)
15554 + struct au_iinfo *iinfo;
15555 + struct au_hinode *hi;
15556 + struct super_block *sb;
15557 + aufs_bindex_t bindex, bend;
15558 + const unsigned char unlinked = !inode->i_nlink;
15560 + iinfo = au_ii(inode);
15561 + /* bad_inode case */
15565 + sb = inode->i_sb;
15566 + au_ninodes_dec(sb);
15567 + if (si_pid_test(sb))
15568 + au_xino_delete_inode(inode, unlinked);
15571 + * it is safe to hide the dependency between sbinfo and
15575 + si_noflush_read_lock(sb);
15576 + au_xino_delete_inode(inode, unlinked);
15577 + si_read_unlock(sb);
15581 + if (iinfo->ii_vdir)
15582 + au_vdir_free(iinfo->ii_vdir);
15584 + bindex = iinfo->ii_bstart;
15585 + if (bindex >= 0) {
15586 + hi = iinfo->ii_hinode + bindex;
15587 + bend = iinfo->ii_bend;
15588 + while (bindex++ <= bend) {
15589 + if (hi->hi_inode)
15594 + kfree(iinfo->ii_hinode);
15595 + iinfo->ii_hinode = NULL;
15596 + AuRwDestroy(&iinfo->ii_rwsem);
15598 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
15599 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
15600 +++ linux/fs/aufs/inode.c 2014-08-14 10:15:45.128609525 +0200
15603 + * Copyright (C) 2005-2014 Junjiro R. Okajima
15605 + * This program, aufs is free software; you can redistribute it and/or modify
15606 + * it under the terms of the GNU General Public License as published by
15607 + * the Free Software Foundation; either version 2 of the License, or
15608 + * (at your option) any later version.
15610 + * This program is distributed in the hope that it will be useful,
15611 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15612 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15613 + * GNU General Public License for more details.
15615 + * You should have received a copy of the GNU General Public License
15616 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15620 + * inode functions
15625 +struct inode *au_igrab(struct inode *inode)
15628 + AuDebugOn(!atomic_read(&inode->i_count));
15634 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
15636 + au_cpup_attr_all(inode, /*force*/0);
15637 + au_update_iigen(inode, /*half*/1);
15639 + inode->i_version++;
15642 +static int au_ii_refresh(struct inode *inode, int *update)
15646 + aufs_bindex_t bindex, new_bindex;
15647 + struct super_block *sb;
15648 + struct au_iinfo *iinfo;
15649 + struct au_hinode *p, *q, tmp;
15651 + IiMustWriteLock(inode);
15654 + sb = inode->i_sb;
15655 + type = inode->i_mode & S_IFMT;
15656 + iinfo = au_ii(inode);
15657 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
15658 + if (unlikely(err))
15661 + AuDebugOn(iinfo->ii_bstart < 0);
15662 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15663 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15665 + if (!p->hi_inode)
15668 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
15669 + new_bindex = au_br_index(sb, p->hi_id);
15670 + if (new_bindex == bindex)
15673 + if (new_bindex < 0) {
15676 + p->hi_inode = NULL;
15680 + if (new_bindex < iinfo->ii_bstart)
15681 + iinfo->ii_bstart = new_bindex;
15682 + if (iinfo->ii_bend < new_bindex)
15683 + iinfo->ii_bend = new_bindex;
15684 + /* swap two lower inode, and loop again */
15685 + q = iinfo->ii_hinode + new_bindex;
15689 + if (tmp.hi_inode) {
15694 + au_update_ibrange(inode, /*do_put_zero*/0);
15695 + e = au_dy_irefresh(inode);
15696 + if (unlikely(e && !err))
15704 +int au_refresh_hinode_self(struct inode *inode)
15708 + err = au_ii_refresh(inode, &update);
15710 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
15716 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
15718 + int err, e, update;
15719 + unsigned int flags;
15721 + aufs_bindex_t bindex, bend;
15722 + unsigned char isdir;
15723 + struct au_hinode *p;
15724 + struct au_iinfo *iinfo;
15726 + err = au_ii_refresh(inode, &update);
15727 + if (unlikely(err))
15731 + iinfo = au_ii(inode);
15732 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15733 + mode = (inode->i_mode & S_IFMT);
15734 + isdir = S_ISDIR(mode);
15735 + flags = au_hi_flags(inode, isdir);
15736 + bend = au_dbend(dentry);
15737 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
15738 + struct inode *h_i;
15739 + struct dentry *h_d;
15741 + h_d = au_h_dptr(dentry, bindex);
15742 + if (!h_d || !h_d->d_inode)
15745 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
15746 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
15747 + h_i = au_h_iptr(inode, bindex);
15749 + if (h_i == h_d->d_inode)
15755 + if (bindex < iinfo->ii_bstart)
15756 + iinfo->ii_bstart = bindex;
15757 + if (iinfo->ii_bend < bindex)
15758 + iinfo->ii_bend = bindex;
15759 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
15762 + au_update_ibrange(inode, /*do_put_zero*/0);
15763 + e = au_dy_irefresh(inode);
15764 + if (unlikely(e && !err))
15767 + au_refresh_hinode_attr(inode, update && isdir);
15774 +static int set_inode(struct inode *inode, struct dentry *dentry)
15777 + unsigned int flags;
15779 + aufs_bindex_t bindex, bstart, btail;
15780 + unsigned char isdir;
15781 + struct dentry *h_dentry;
15782 + struct inode *h_inode;
15783 + struct au_iinfo *iinfo;
15785 + IiMustWriteLock(inode);
15789 + bstart = au_dbstart(dentry);
15790 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
15791 + mode = h_inode->i_mode;
15792 + switch (mode & S_IFMT) {
15794 + btail = au_dbtail(dentry);
15795 + inode->i_op = &aufs_iop;
15796 + inode->i_fop = &aufs_file_fop;
15797 + err = au_dy_iaop(inode, bstart, h_inode);
15798 + if (unlikely(err))
15803 + btail = au_dbtaildir(dentry);
15804 + inode->i_op = &aufs_dir_iop;
15805 + inode->i_fop = &aufs_dir_fop;
15808 + btail = au_dbtail(dentry);
15809 + inode->i_op = &aufs_symlink_iop;
15815 + btail = au_dbtail(dentry);
15816 + inode->i_op = &aufs_iop;
15817 + init_special_inode(inode, mode, h_inode->i_rdev);
15820 + AuIOErr("Unknown file type 0%o\n", mode);
15825 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
15826 + flags = au_hi_flags(inode, isdir);
15827 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
15828 + && au_ftest_hi(flags, HNOTIFY)
15829 + && dentry->d_name.len > AUFS_WH_PFX_LEN
15830 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
15831 + au_fclr_hi(flags, HNOTIFY);
15832 + iinfo = au_ii(inode);
15833 + iinfo->ii_bstart = bstart;
15834 + iinfo->ii_bend = btail;
15835 + for (bindex = bstart; bindex <= btail; bindex++) {
15836 + h_dentry = au_h_dptr(dentry, bindex);
15838 + au_set_h_iptr(inode, bindex,
15839 + au_igrab(h_dentry->d_inode), flags);
15841 + au_cpup_attr_all(inode, /*force*/1);
15848 + * successful returns with iinfo write_locked
15850 + * zero: success, matched
15851 + * plus: no error, but unmatched
15853 +static int reval_inode(struct inode *inode, struct dentry *dentry)
15856 + unsigned int gen;
15857 + struct au_iigen iigen;
15858 + aufs_bindex_t bindex, bend;
15859 + struct inode *h_inode, *h_dinode;
15862 + * before this function, if aufs got any iinfo lock, it must be only
15863 + * one, the parent dir.
15864 + * it can happen by UDBA and the obsoleted inode number.
15867 + if (unlikely(inode->i_ino == parent_ino(dentry)))
15871 + ii_write_lock_new_child(inode);
15872 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
15873 + bend = au_ibend(inode);
15874 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
15875 + h_inode = au_h_iptr(inode, bindex);
15876 + if (!h_inode || h_inode != h_dinode)
15880 + gen = au_iigen(inode, &iigen);
15881 + if (gen == au_digen(dentry)
15882 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
15885 + /* fully refresh inode using dentry */
15886 + err = au_refresh_hinode(inode, dentry);
15888 + au_update_iigen(inode, /*half*/0);
15892 + if (unlikely(err))
15893 + ii_write_unlock(inode);
15898 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
15899 + unsigned int d_type, ino_t *ino)
15902 + struct mutex *mtx;
15904 + /* prevent hardlinked inode number from race condition */
15906 + if (d_type != DT_DIR) {
15907 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
15910 + err = au_xino_read(sb, bindex, h_ino, ino);
15911 + if (unlikely(err))
15916 + *ino = au_xino_new_ino(sb);
15917 + if (unlikely(!*ino))
15919 + err = au_xino_write(sb, bindex, h_ino, *ino);
15920 + if (unlikely(err))
15926 + mutex_unlock(mtx);
15930 +/* successful returns with iinfo write_locked */
15931 +/* todo: return with unlocked? */
15932 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
15934 + struct inode *inode, *h_inode;
15935 + struct dentry *h_dentry;
15936 + struct super_block *sb;
15937 + struct mutex *mtx;
15938 + ino_t h_ino, ino;
15940 + aufs_bindex_t bstart;
15942 + sb = dentry->d_sb;
15943 + bstart = au_dbstart(dentry);
15944 + h_dentry = au_h_dptr(dentry, bstart);
15945 + h_inode = h_dentry->d_inode;
15946 + h_ino = h_inode->i_ino;
15949 + * stop 'race'-ing between hardlinks under different
15953 + if (!S_ISDIR(h_inode->i_mode))
15954 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
15959 + err = au_xino_read(sb, bstart, h_ino, &ino);
15960 + inode = ERR_PTR(err);
15961 + if (unlikely(err))
15965 + ino = au_xino_new_ino(sb);
15966 + if (unlikely(!ino)) {
15967 + inode = ERR_PTR(-EIO);
15972 + AuDbg("i%lu\n", (unsigned long)ino);
15973 + inode = au_iget_locked(sb, ino);
15974 + err = PTR_ERR(inode);
15975 + if (IS_ERR(inode))
15978 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
15979 + if (inode->i_state & I_NEW) {
15980 + /* verbose coding for lock class name */
15981 + if (unlikely(S_ISLNK(h_inode->i_mode)))
15982 + au_rw_class(&au_ii(inode)->ii_rwsem,
15983 + au_lc_key + AuLcSymlink_IIINFO);
15984 + else if (unlikely(S_ISDIR(h_inode->i_mode)))
15985 + au_rw_class(&au_ii(inode)->ii_rwsem,
15986 + au_lc_key + AuLcDir_IIINFO);
15987 + else /* likely */
15988 + au_rw_class(&au_ii(inode)->ii_rwsem,
15989 + au_lc_key + AuLcNonDir_IIINFO);
15991 + ii_write_lock_new_child(inode);
15992 + err = set_inode(inode, dentry);
15994 + unlock_new_inode(inode);
15995 + goto out; /* success */
15999 + * iget_failed() calls iput(), but we need to call
16000 + * ii_write_unlock() after iget_failed(). so dirty hack for
16003 + atomic_inc(&inode->i_count);
16004 + iget_failed(inode);
16005 + ii_write_unlock(inode);
16006 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
16007 + /* ignore this error */
16009 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16011 + * horrible race condition between lookup, readdir and copyup
16012 + * (or something).
16015 + mutex_unlock(mtx);
16016 + err = reval_inode(inode, dentry);
16017 + if (unlikely(err < 0)) {
16024 + goto out; /* success */
16029 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
16030 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16031 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16032 + bstart, au_sbtype(h_dentry->d_sb), dentry,
16033 + (unsigned long)h_ino, (unsigned long)ino);
16035 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
16039 + mutex_unlock(mtx);
16045 + inode = ERR_PTR(err);
16048 + mutex_unlock(mtx);
16052 +/* ---------------------------------------------------------------------- */
16054 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16055 + struct inode *inode)
16058 + struct inode *hi;
16060 + err = au_br_rdonly(au_sbr(sb, bindex));
16062 + /* pseudo-link after flushed may happen out of bounds */
16065 + && au_ibstart(inode) <= bindex
16066 + && bindex <= au_ibend(inode)) {
16068 + * permission check is unnecessary since vfsub routine
16069 + * will be called later
16071 + hi = au_h_iptr(inode, bindex);
16073 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16079 +int au_test_h_perm(struct inode *h_inode, int mask)
16081 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16083 + return inode_permission(h_inode, mask);
16086 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16088 + if (au_test_nfs(h_inode->i_sb)
16089 + && (mask & MAY_WRITE)
16090 + && S_ISDIR(h_inode->i_mode))
16091 + mask |= MAY_READ; /* force permission check */
16092 + return au_test_h_perm(h_inode, mask);
16094 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16095 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16096 +++ linux/fs/aufs/inode.h 2014-08-14 10:15:45.128609525 +0200
16099 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16101 + * This program, aufs is free software; you can redistribute it and/or modify
16102 + * it under the terms of the GNU General Public License as published by
16103 + * the Free Software Foundation; either version 2 of the License, or
16104 + * (at your option) any later version.
16106 + * This program is distributed in the hope that it will be useful,
16107 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16108 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16109 + * GNU General Public License for more details.
16111 + * You should have received a copy of the GNU General Public License
16112 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16116 + * inode operations
16119 +#ifndef __AUFS_INODE_H__
16120 +#define __AUFS_INODE_H__
16124 +#include <linux/fsnotify.h>
16125 +#include "rwsem.h"
16129 +struct au_hnotify {
16130 +#ifdef CONFIG_AUFS_HNOTIFY
16131 +#ifdef CONFIG_AUFS_HFSNOTIFY
16132 + /* never use fsnotify_add_vfsmount_mark() */
16133 + struct fsnotify_mark hn_mark;
16135 + struct inode *hn_aufs_inode; /* no get/put */
16137 +} ____cacheline_aligned_in_smp;
16139 +struct au_hinode {
16140 + struct inode *hi_inode;
16141 + aufs_bindex_t hi_id;
16142 +#ifdef CONFIG_AUFS_HNOTIFY
16143 + struct au_hnotify *hi_notify;
16146 + /* reference to the copied-up whiteout with get/put */
16147 + struct dentry *hi_whdentry;
16151 +#define AuIG_HALF_REFRESHED 1
16152 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16153 +#define au_ig_fset(flags, name) \
16154 + do { (flags) |= AuIG_##name; } while (0)
16155 +#define au_ig_fclr(flags, name) \
16156 + do { (flags) &= ~AuIG_##name; } while (0)
16159 + __u32 ig_generation, ig_flags;
16164 + spinlock_t ii_genspin;
16165 + struct au_iigen ii_generation;
16166 + struct super_block *ii_hsb1; /* no get/put */
16168 + struct au_rwsem ii_rwsem;
16169 + aufs_bindex_t ii_bstart, ii_bend;
16171 + struct au_hinode *ii_hinode;
16172 + struct au_vdir *ii_vdir;
16175 +struct au_icntnr {
16176 + struct au_iinfo iinfo;
16177 + struct inode vfs_inode;
16178 +} ____cacheline_aligned_in_smp;
16180 +/* au_pin flags */
16181 +#define AuPin_DI_LOCKED 1
16182 +#define AuPin_MNT_WRITE (1 << 1)
16183 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16184 +#define au_fset_pin(flags, name) \
16185 + do { (flags) |= AuPin_##name; } while (0)
16186 +#define au_fclr_pin(flags, name) \
16187 + do { (flags) &= ~AuPin_##name; } while (0)
16191 + struct dentry *dentry;
16192 + unsigned int udba;
16193 + unsigned char lsc_di, lsc_hi, flags;
16194 + aufs_bindex_t bindex;
16197 + struct dentry *parent;
16198 + struct au_hinode *hdir;
16199 + struct vfsmount *h_mnt;
16201 + /* temporary unlock/relock for copyup */
16202 + struct dentry *h_dentry, *h_parent;
16203 + struct au_branch *br;
16204 + struct task_struct *task;
16207 +void au_pin_hdir_unlock(struct au_pin *p);
16208 +int au_pin_hdir_relock(struct au_pin *p);
16209 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
16210 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16211 +void au_pin_hdir_release(struct au_pin *p);
16213 +/* ---------------------------------------------------------------------- */
16215 +static inline struct au_iinfo *au_ii(struct inode *inode)
16217 + struct au_iinfo *iinfo;
16219 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16220 + if (iinfo->ii_hinode)
16222 + return NULL; /* debugging bad_inode case */
16225 +/* ---------------------------------------------------------------------- */
16228 +struct inode *au_igrab(struct inode *inode);
16229 +int au_refresh_hinode_self(struct inode *inode);
16230 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16231 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16232 + unsigned int d_type, ino_t *ino);
16233 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16234 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16235 + struct inode *inode);
16236 +int au_test_h_perm(struct inode *h_inode, int mask);
16237 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16239 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16240 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16242 +#ifdef CONFIG_AUFS_SHWH
16243 + return au_ino(sb, bindex, h_ino, d_type, ino);
16250 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
16252 +/* au_wr_dir flags */
16253 +#define AuWrDir_ADD_ENTRY 1
16254 +#define AuWrDir_TMP_WHENTRY (1 << 1)
16255 +#define AuWrDir_ISDIR (1 << 2)
16256 +#define AuWrDir_TMPFILE (1 << 3)
16257 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16258 +#define au_fset_wrdir(flags, name) \
16259 + do { (flags) |= AuWrDir_##name; } while (0)
16260 +#define au_fclr_wrdir(flags, name) \
16261 + do { (flags) &= ~AuWrDir_##name; } while (0)
16263 +struct au_wr_dir_args {
16264 + aufs_bindex_t force_btgt;
16265 + unsigned char flags;
16267 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16268 + struct au_wr_dir_args *args);
16270 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16271 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16272 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16273 + unsigned int udba, unsigned char flags);
16274 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16275 + unsigned int udba, unsigned char flags) __must_check;
16276 +int au_do_pin(struct au_pin *pin) __must_check;
16277 +void au_unpin(struct au_pin *pin);
16280 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16281 + struct dentry *h_parent, int isdir);
16282 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16284 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16285 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16287 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16288 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16289 + struct dentry *dentry);
16290 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16293 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16294 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16295 + struct dentry *h_parent, int isdir);
16296 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16297 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16300 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16301 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16302 + struct inode *dir, struct dentry *dentry);
16305 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16306 +void au_hiput(struct au_hinode *hinode);
16307 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16308 + struct dentry *h_wh);
16309 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16311 +/* hinode flags */
16312 +#define AuHi_XINO 1
16313 +#define AuHi_HNOTIFY (1 << 1)
16314 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16315 +#define au_fset_hi(flags, name) \
16316 + do { (flags) |= AuHi_##name; } while (0)
16317 +#define au_fclr_hi(flags, name) \
16318 + do { (flags) &= ~AuHi_##name; } while (0)
16320 +#ifndef CONFIG_AUFS_HNOTIFY
16321 +#undef AuHi_HNOTIFY
16322 +#define AuHi_HNOTIFY 0
16325 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16326 + struct inode *h_inode, unsigned int flags);
16328 +void au_update_iigen(struct inode *inode, int half);
16329 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16331 +void au_icntnr_init_once(void *_c);
16332 +int au_iinfo_init(struct inode *inode);
16333 +void au_iinfo_fin(struct inode *inode);
16334 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
16336 +#ifdef CONFIG_PROC_FS
16338 +int au_plink_maint(struct super_block *sb, int flags);
16339 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16340 +int au_plink_maint_enter(struct super_block *sb);
16341 +#ifdef CONFIG_AUFS_DEBUG
16342 +void au_plink_list(struct super_block *sb);
16344 +AuStubVoid(au_plink_list, struct super_block *sb)
16346 +int au_plink_test(struct inode *inode);
16347 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16348 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16349 + struct dentry *h_dentry);
16350 +void au_plink_put(struct super_block *sb, int verbose);
16351 +void au_plink_clean(struct super_block *sb, int verbose);
16352 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16354 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16355 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16356 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16357 +AuStubVoid(au_plink_list, struct super_block *sb);
16358 +AuStubInt0(au_plink_test, struct inode *inode);
16359 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16360 + struct inode *inode, aufs_bindex_t bindex);
16361 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16362 + struct dentry *h_dentry);
16363 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16364 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16365 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16366 +#endif /* CONFIG_PROC_FS */
16368 +/* ---------------------------------------------------------------------- */
16370 +/* lock subclass for iinfo */
16372 + AuLsc_II_CHILD, /* child first */
16373 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16374 + AuLsc_II_CHILD3, /* copyup dirs */
16375 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16376 + AuLsc_II_PARENT2,
16377 + AuLsc_II_PARENT3, /* copyup dirs */
16378 + AuLsc_II_NEW_CHILD
16382 + * ii_read_lock_child, ii_write_lock_child,
16383 + * ii_read_lock_child2, ii_write_lock_child2,
16384 + * ii_read_lock_child3, ii_write_lock_child3,
16385 + * ii_read_lock_parent, ii_write_lock_parent,
16386 + * ii_read_lock_parent2, ii_write_lock_parent2,
16387 + * ii_read_lock_parent3, ii_write_lock_parent3,
16388 + * ii_read_lock_new_child, ii_write_lock_new_child,
16390 +#define AuReadLockFunc(name, lsc) \
16391 +static inline void ii_read_lock_##name(struct inode *i) \
16393 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16396 +#define AuWriteLockFunc(name, lsc) \
16397 +static inline void ii_write_lock_##name(struct inode *i) \
16399 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16402 +#define AuRWLockFuncs(name, lsc) \
16403 + AuReadLockFunc(name, lsc) \
16404 + AuWriteLockFunc(name, lsc)
16406 +AuRWLockFuncs(child, CHILD);
16407 +AuRWLockFuncs(child2, CHILD2);
16408 +AuRWLockFuncs(child3, CHILD3);
16409 +AuRWLockFuncs(parent, PARENT);
16410 +AuRWLockFuncs(parent2, PARENT2);
16411 +AuRWLockFuncs(parent3, PARENT3);
16412 +AuRWLockFuncs(new_child, NEW_CHILD);
16414 +#undef AuReadLockFunc
16415 +#undef AuWriteLockFunc
16416 +#undef AuRWLockFuncs
16419 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
16421 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
16423 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
16424 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
16425 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
16427 +/* ---------------------------------------------------------------------- */
16429 +static inline void au_icntnr_init(struct au_icntnr *c)
16431 +#ifdef CONFIG_AUFS_DEBUG
16432 + c->vfs_inode.i_mode = 0;
16436 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
16438 + unsigned int gen;
16439 + struct au_iinfo *iinfo;
16441 + iinfo = au_ii(inode);
16442 + spin_lock(&iinfo->ii_genspin);
16444 + *iigen = iinfo->ii_generation;
16445 + gen = iinfo->ii_generation.ig_generation;
16446 + spin_unlock(&iinfo->ii_genspin);
16451 +/* tiny test for inode number */
16452 +/* tmpfs generation is too rough */
16453 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
16455 + struct au_iinfo *iinfo;
16457 + iinfo = au_ii(inode);
16458 + AuRwMustAnyLock(&iinfo->ii_rwsem);
16459 + return !(iinfo->ii_hsb1 == h_inode->i_sb
16460 + && iinfo->ii_higen == h_inode->i_generation);
16463 +static inline void au_iigen_dec(struct inode *inode)
16465 + struct au_iinfo *iinfo;
16467 + iinfo = au_ii(inode);
16468 + spin_lock(&iinfo->ii_genspin);
16469 + iinfo->ii_generation.ig_generation--;
16470 + spin_unlock(&iinfo->ii_genspin);
16473 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
16478 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
16484 +/* ---------------------------------------------------------------------- */
16486 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
16487 + aufs_bindex_t bindex)
16489 + IiMustAnyLock(inode);
16490 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
16493 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
16495 + IiMustAnyLock(inode);
16496 + return au_ii(inode)->ii_bstart;
16499 +static inline aufs_bindex_t au_ibend(struct inode *inode)
16501 + IiMustAnyLock(inode);
16502 + return au_ii(inode)->ii_bend;
16505 +static inline struct au_vdir *au_ivdir(struct inode *inode)
16507 + IiMustAnyLock(inode);
16508 + return au_ii(inode)->ii_vdir;
16511 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
16513 + IiMustAnyLock(inode);
16514 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
16517 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
16519 + IiMustWriteLock(inode);
16520 + au_ii(inode)->ii_bstart = bindex;
16523 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
16525 + IiMustWriteLock(inode);
16526 + au_ii(inode)->ii_bend = bindex;
16529 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
16531 + IiMustWriteLock(inode);
16532 + au_ii(inode)->ii_vdir = vdir;
16535 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
16537 + IiMustAnyLock(inode);
16538 + return au_ii(inode)->ii_hinode + bindex;
16541 +/* ---------------------------------------------------------------------- */
16543 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
16546 + return pin->parent;
16550 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
16552 + if (pin && pin->hdir)
16553 + return pin->hdir->hi_inode;
16557 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
16560 + return pin->hdir;
16564 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
16567 + pin->dentry = dentry;
16570 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
16571 + unsigned char lflag)
16575 + au_fset_pin(pin->flags, DI_LOCKED);
16577 + au_fclr_pin(pin->flags, DI_LOCKED);
16581 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
16584 + dput(pin->parent);
16585 + pin->parent = dget(parent);
16589 +/* ---------------------------------------------------------------------- */
16592 +#ifdef CONFIG_AUFS_HNOTIFY
16593 +struct au_hnotify_op {
16594 + void (*ctl)(struct au_hinode *hinode, int do_set);
16595 + int (*alloc)(struct au_hinode *hinode);
16598 + * if it returns true, the the caller should free hinode->hi_notify,
16599 + * otherwise ->free() frees it.
16601 + int (*free)(struct au_hinode *hinode,
16602 + struct au_hnotify *hn) __must_check;
16604 + void (*fin)(void);
16605 + int (*init)(void);
16607 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
16608 + void (*fin_br)(struct au_branch *br);
16609 + int (*init_br)(struct au_branch *br, int perm);
16613 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
16614 +void au_hn_free(struct au_hinode *hinode);
16615 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
16616 +void au_hn_reset(struct inode *inode, unsigned int flags);
16617 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
16618 + struct qstr *h_child_qstr, struct inode *h_child_inode);
16619 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
16620 +int au_hnotify_init_br(struct au_branch *br, int perm);
16621 +void au_hnotify_fin_br(struct au_branch *br);
16622 +int __init au_hnotify_init(void);
16623 +void au_hnotify_fin(void);
16626 +extern const struct au_hnotify_op au_hnotify_op;
16629 +void au_hn_init(struct au_hinode *hinode)
16631 + hinode->hi_notify = NULL;
16634 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
16636 + return hinode->hi_notify;
16641 +int au_hn_alloc(struct au_hinode *hinode __maybe_unused,
16642 + struct inode *inode __maybe_unused)
16644 + return -EOPNOTSUPP;
16647 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
16652 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
16653 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
16654 + int do_set __maybe_unused)
16655 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
16656 + unsigned int flags __maybe_unused)
16657 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
16658 + struct au_branch *br __maybe_unused,
16659 + int perm __maybe_unused)
16660 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
16661 + int perm __maybe_unused)
16662 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
16663 +AuStubInt0(__init au_hnotify_init, void)
16664 +AuStubVoid(au_hnotify_fin, void)
16665 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
16666 +#endif /* CONFIG_AUFS_HNOTIFY */
16668 +static inline void au_hn_suspend(struct au_hinode *hdir)
16670 + au_hn_ctl(hdir, /*do_set*/0);
16673 +static inline void au_hn_resume(struct au_hinode *hdir)
16675 + au_hn_ctl(hdir, /*do_set*/1);
16678 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
16680 + mutex_lock(&hdir->hi_inode->i_mutex);
16681 + au_hn_suspend(hdir);
16684 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
16685 + unsigned int sc __maybe_unused)
16687 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
16688 + au_hn_suspend(hdir);
16691 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
16693 + au_hn_resume(hdir);
16694 + mutex_unlock(&hdir->hi_inode->i_mutex);
16697 +#endif /* __KERNEL__ */
16698 +#endif /* __AUFS_INODE_H__ */
16699 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
16700 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
16701 +++ linux/fs/aufs/ioctl.c 2014-08-14 10:15:45.128609525 +0200
16704 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16706 + * This program, aufs is free software; you can redistribute it and/or modify
16707 + * it under the terms of the GNU General Public License as published by
16708 + * the Free Software Foundation; either version 2 of the License, or
16709 + * (at your option) any later version.
16711 + * This program is distributed in the hope that it will be useful,
16712 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16713 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16714 + * GNU General Public License for more details.
16716 + * You should have received a copy of the GNU General Public License
16717 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16722 + * plink-management and readdir in userspace.
16723 + * assist the pathconf(3) wrapper library.
16725 + * File-based Hierarchical Storage Management.
16728 +#include <linux/compat.h>
16729 +#include <linux/file.h>
16732 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
16735 + aufs_bindex_t wbi, bindex, bend;
16736 + struct file *h_file;
16737 + struct super_block *sb;
16738 + struct dentry *root;
16739 + struct au_branch *br;
16740 + struct aufs_wbr_fd wbrfd = {
16741 + .oflags = au_dir_roflags,
16744 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
16745 + | O_NOATIME | O_CLOEXEC;
16747 + AuDebugOn(wbrfd.oflags & ~valid);
16750 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
16751 + if (unlikely(err)) {
16757 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
16758 + wbrfd.oflags |= au_dir_roflags;
16759 + AuDbg("0%o\n", wbrfd.oflags);
16760 + if (unlikely(wbrfd.oflags & ~valid))
16764 + fd = get_unused_fd();
16766 + if (unlikely(fd < 0))
16769 + h_file = ERR_PTR(-EINVAL);
16772 + sb = path->dentry->d_sb;
16773 + root = sb->s_root;
16774 + aufs_read_lock(root, AuLock_IR);
16775 + bend = au_sbend(sb);
16776 + if (wbrfd.brid >= 0) {
16777 + wbi = au_br_index(sb, wbrfd.brid);
16778 + if (unlikely(wbi < 0 || wbi > bend))
16782 + h_file = ERR_PTR(-ENOENT);
16783 + br = au_sbr(sb, wbi);
16784 + if (!au_br_writable(br->br_perm)) {
16788 + bindex = wbi + 1;
16790 + for (; bindex <= bend; bindex++) {
16791 + br = au_sbr(sb, bindex);
16792 + if (au_br_writable(br->br_perm)) {
16794 + br = au_sbr(sb, wbi);
16799 + AuDbg("wbi %d\n", wbi);
16801 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
16805 + aufs_read_unlock(root, AuLock_IR);
16806 + err = PTR_ERR(h_file);
16807 + if (IS_ERR(h_file))
16810 + atomic_dec(&br->br_count); /* cf. au_h_open() */
16811 + fd_install(fd, h_file);
16813 + goto out; /* success */
16816 + put_unused_fd(fd);
16822 +/* ---------------------------------------------------------------------- */
16824 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
16829 + case AUFS_CTL_RDU:
16830 + case AUFS_CTL_RDU_INO:
16831 + err = au_rdu_ioctl(file, cmd, arg);
16834 + case AUFS_CTL_WBR_FD:
16835 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
16838 + case AUFS_CTL_IBUSY:
16839 + err = au_ibusy_ioctl(file, arg);
16842 + case AUFS_CTL_BRINFO:
16843 + err = au_brinfo_ioctl(file, arg);
16846 + case AUFS_CTL_FHSM_FD:
16847 + err = au_fhsm_fd(file->f_dentry->d_sb, arg);
16851 + /* do not call the lower */
16852 + AuDbg("0x%x\n", cmd);
16860 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
16865 + case AUFS_CTL_MVDOWN:
16866 + err = au_mvdown(file->f_dentry, (void __user *)arg);
16869 + case AUFS_CTL_WBR_FD:
16870 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
16874 + /* do not call the lower */
16875 + AuDbg("0x%x\n", cmd);
16883 +#ifdef CONFIG_COMPAT
16884 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
16885 + unsigned long arg)
16890 + case AUFS_CTL_RDU:
16891 + case AUFS_CTL_RDU_INO:
16892 + err = au_rdu_compat_ioctl(file, cmd, arg);
16895 + case AUFS_CTL_IBUSY:
16896 + err = au_ibusy_compat_ioctl(file, arg);
16899 + case AUFS_CTL_BRINFO:
16900 + err = au_brinfo_compat_ioctl(file, arg);
16904 + err = aufs_ioctl_dir(file, cmd, arg);
16911 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
16912 + unsigned long arg)
16914 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
16917 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
16918 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
16919 +++ linux/fs/aufs/i_op_add.c 2014-08-14 10:15:45.121942630 +0200
16922 + * Copyright (C) 2005-2014 Junjiro R. Okajima
16924 + * This program, aufs is free software; you can redistribute it and/or modify
16925 + * it under the terms of the GNU General Public License as published by
16926 + * the Free Software Foundation; either version 2 of the License, or
16927 + * (at your option) any later version.
16929 + * This program is distributed in the hope that it will be useful,
16930 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16931 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16932 + * GNU General Public License for more details.
16934 + * You should have received a copy of the GNU General Public License
16935 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16939 + * inode operations (add entry)
16945 + * final procedure of adding a new entry, except link(2).
16946 + * remove whiteout, instantiate, copyup the parent dir's times and size
16947 + * and update version.
16948 + * if it failed, re-create the removed whiteout.
16950 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
16951 + struct dentry *wh_dentry, struct dentry *dentry)
16954 + aufs_bindex_t bwh;
16955 + struct path h_path;
16956 + struct super_block *sb;
16957 + struct inode *inode, *h_dir;
16958 + struct dentry *wh;
16963 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
16964 + IMustLock(h_dir);
16965 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
16966 + bwh = au_dbwh(dentry);
16967 + h_path.dentry = wh_dentry;
16968 + h_path.mnt = au_sbr_mnt(sb, bindex);
16969 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
16971 + if (unlikely(err))
16975 + inode = au_new_inode(dentry, /*must_new*/1);
16976 + if (!IS_ERR(inode)) {
16977 + d_instantiate(dentry, inode);
16978 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
16980 + if (au_ibstart(dir) == au_dbstart(dentry))
16981 + au_cpup_attr_timesizes(dir);
16982 + dir->i_version++;
16983 + au_fhsm_wrote(sb, bindex, /*force*/0);
16984 + return 0; /* success */
16987 + err = PTR_ERR(inode);
16992 + /* dir inode is locked */
16993 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
16994 + rerr = PTR_ERR(wh);
16995 + if (IS_ERR(wh)) {
16996 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
16997 + dentry, err, rerr);
17006 +static int au_d_may_add(struct dentry *dentry)
17011 + if (unlikely(d_unhashed(dentry)))
17013 + if (unlikely(dentry->d_inode))
17019 + * simple tests for the adding inode operations.
17020 + * following the checks in vfs, plus the parent-child relationship.
17022 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17023 + struct dentry *h_parent, int isdir)
17027 + struct dentry *h_dentry;
17028 + struct inode *h_inode;
17030 + err = -ENAMETOOLONG;
17031 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17034 + h_dentry = au_h_dptr(dentry, bindex);
17035 + h_inode = h_dentry->d_inode;
17036 + if (!dentry->d_inode) {
17038 + if (unlikely(h_inode))
17041 + /* rename(2) case */
17043 + if (unlikely(!h_inode || !h_inode->i_nlink))
17046 + h_mode = h_inode->i_mode;
17049 + if (unlikely(S_ISDIR(h_mode)))
17051 + } else if (unlikely(!S_ISDIR(h_mode))) {
17058 + /* expected parent dir is locked */
17059 + if (unlikely(h_parent != h_dentry->d_parent))
17068 + * initial procedure of adding a new entry.
17069 + * prepare writable branch and the parent dir, lock it,
17070 + * and lookup whiteout for the new entry.
17072 +static struct dentry*
17073 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17074 + struct dentry *src_dentry, struct au_pin *pin,
17075 + struct au_wr_dir_args *wr_dir_args)
17077 + struct dentry *wh_dentry, *h_parent;
17078 + struct super_block *sb;
17079 + struct au_branch *br;
17081 + unsigned int udba;
17082 + aufs_bindex_t bcpup;
17084 + AuDbg("%pd\n", dentry);
17086 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17088 + wh_dentry = ERR_PTR(err);
17089 + if (unlikely(err < 0))
17092 + sb = dentry->d_sb;
17093 + udba = au_opt_udba(sb);
17094 + err = au_pin(pin, dentry, bcpup, udba,
17095 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17096 + wh_dentry = ERR_PTR(err);
17097 + if (unlikely(err))
17100 + h_parent = au_pinned_h_parent(pin);
17101 + if (udba != AuOpt_UDBA_NONE
17102 + && au_dbstart(dentry) == bcpup)
17103 + err = au_may_add(dentry, bcpup, h_parent,
17104 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17105 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17106 + err = -ENAMETOOLONG;
17107 + wh_dentry = ERR_PTR(err);
17108 + if (unlikely(err))
17111 + br = au_sbr(sb, bcpup);
17113 + struct path tmp = {
17114 + .dentry = h_parent,
17115 + .mnt = au_br_mnt(br)
17117 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17120 + wh_dentry = NULL;
17121 + if (bcpup != au_dbwh(dentry))
17122 + goto out; /* success */
17124 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17127 + if (IS_ERR(wh_dentry))
17130 + return wh_dentry;
17133 +/* ---------------------------------------------------------------------- */
17135 +enum { Mknod, Symlink, Creat };
17136 +struct simple_arg {
17144 + const char *symname;
17153 +static int add_simple(struct inode *dir, struct dentry *dentry,
17154 + struct simple_arg *arg)
17157 + aufs_bindex_t bstart;
17158 + unsigned char created;
17159 + struct dentry *wh_dentry, *parent;
17160 + struct inode *h_dir;
17161 + /* to reuduce stack size */
17163 + struct au_dtime dt;
17164 + struct au_pin pin;
17165 + struct path h_path;
17166 + struct au_wr_dir_args wr_dir_args;
17169 + AuDbg("%pd\n", dentry);
17173 + a = kmalloc(sizeof(*a), GFP_NOFS);
17174 + if (unlikely(!a))
17176 + a->wr_dir_args.force_btgt = -1;
17177 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17179 + parent = dentry->d_parent; /* dir inode is locked */
17180 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17181 + if (unlikely(err))
17183 + err = au_d_may_add(dentry);
17184 + if (unlikely(err))
17186 + di_write_lock_parent(parent);
17187 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17188 + &a->pin, &a->wr_dir_args);
17189 + err = PTR_ERR(wh_dentry);
17190 + if (IS_ERR(wh_dentry))
17193 + bstart = au_dbstart(dentry);
17194 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17195 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
17196 + h_dir = au_pinned_h_dir(&a->pin);
17197 + switch (arg->type) {
17199 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17200 + arg->u.c.want_excl);
17203 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17206 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17214 + err = epilog(dir, bstart, wh_dentry, dentry);
17217 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
17218 + /* no delegation since it is just created */
17219 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17222 + AuIOErr("%pd revert failure(%d, %d)\n",
17223 + dentry, err, rerr);
17226 + au_dtime_revert(&a->dt);
17229 + au_unpin(&a->pin);
17233 + di_write_unlock(parent);
17235 + if (unlikely(err)) {
17236 + au_update_dbstart(dentry);
17239 + aufs_read_unlock(dentry, AuLock_DW);
17246 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17249 + struct simple_arg arg = {
17256 + return add_simple(dir, dentry, &arg);
17259 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17261 + struct simple_arg arg = {
17263 + .u.s.symname = symname
17265 + return add_simple(dir, dentry, &arg);
17268 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17271 + struct simple_arg arg = {
17275 + .want_excl = want_excl
17278 + return add_simple(dir, dentry, &arg);
17281 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17284 + aufs_bindex_t bindex;
17285 + struct super_block *sb;
17286 + struct dentry *parent, *h_parent, *h_dentry;
17287 + struct inode *h_dir, *inode;
17288 + struct vfsmount *h_mnt;
17289 + struct au_wr_dir_args wr_dir_args = {
17290 + .force_btgt = -1,
17291 + .flags = AuWrDir_TMPFILE
17294 + /* copy-up may happen */
17295 + mutex_lock(&dir->i_mutex);
17298 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17299 + if (unlikely(err))
17302 + err = au_di_init(dentry);
17303 + if (unlikely(err))
17307 + parent = d_find_any_alias(dir);
17308 + AuDebugOn(!parent);
17309 + di_write_lock_parent(parent);
17310 + if (unlikely(parent->d_inode != dir))
17313 + err = au_digen_test(parent, au_sigen(sb));
17314 + if (unlikely(err))
17317 + bindex = au_dbstart(parent);
17318 + au_set_dbstart(dentry, bindex);
17319 + au_set_dbend(dentry, bindex);
17320 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17322 + if (unlikely(err < 0))
17325 + err = -EOPNOTSUPP;
17326 + h_dir = au_h_iptr(dir, bindex);
17327 + if (unlikely(!h_dir->i_op->tmpfile))
17330 + h_mnt = au_sbr_mnt(sb, bindex);
17331 + err = vfsub_mnt_want_write(h_mnt);
17332 + if (unlikely(err))
17335 + h_parent = au_h_dptr(parent, bindex);
17336 + err = inode_permission(h_parent->d_inode, MAY_WRITE | MAY_EXEC);
17337 + if (unlikely(err))
17341 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17342 + if (unlikely(!h_dentry))
17345 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17346 + if (unlikely(err))
17349 + au_set_dbstart(dentry, bindex);
17350 + au_set_dbend(dentry, bindex);
17351 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17352 + inode = au_new_inode(dentry, /*must_new*/1);
17353 + if (IS_ERR(inode)) {
17354 + err = PTR_ERR(inode);
17355 + au_set_h_dptr(dentry, bindex, NULL);
17356 + au_set_dbstart(dentry, -1);
17357 + au_set_dbend(dentry, -1);
17359 + if (!inode->i_nlink)
17360 + set_nlink(inode, 1);
17361 + d_tmpfile(dentry, inode);
17362 + au_di(dentry)->di_tmpfile = 1;
17364 + /* update without i_mutex */
17365 + if (au_ibstart(dir) == au_dbstart(dentry))
17366 + au_cpup_attr_timesizes(dir);
17372 + vfsub_mnt_drop_write(h_mnt);
17374 + di_write_unlock(parent);
17376 + di_write_unlock(dentry);
17379 + /* verbose coding for lock class name */
17380 + au_rw_class(&au_di(dentry)->di_rwsem,
17381 + au_lc_key + AuLcNonDir_DIINFO);
17386 + au_di_fin(dentry);
17387 + dentry->d_fsdata = NULL;
17390 + si_read_unlock(sb);
17392 + mutex_unlock(&dir->i_mutex);
17396 +/* ---------------------------------------------------------------------- */
17398 +struct au_link_args {
17399 + aufs_bindex_t bdst, bsrc;
17400 + struct au_pin pin;
17401 + struct path h_path;
17402 + struct dentry *src_parent, *parent;
17405 +static int au_cpup_before_link(struct dentry *src_dentry,
17406 + struct au_link_args *a)
17409 + struct dentry *h_src_dentry;
17410 + struct au_cp_generic cpg = {
17411 + .dentry = src_dentry,
17416 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
17419 + di_read_lock_parent(a->src_parent, AuLock_IR);
17420 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
17421 + if (unlikely(err))
17424 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
17425 + err = au_pin(&a->pin, src_dentry, a->bdst,
17426 + au_opt_udba(src_dentry->d_sb),
17427 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17428 + if (unlikely(err))
17431 + err = au_sio_cpup_simple(&cpg);
17432 + au_unpin(&a->pin);
17435 + di_read_unlock(a->src_parent, AuLock_IR);
17439 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
17440 + struct au_link_args *a)
17443 + unsigned char plink;
17444 + aufs_bindex_t bend;
17445 + struct dentry *h_src_dentry;
17446 + struct inode *h_inode, *inode, *delegated;
17447 + struct super_block *sb;
17448 + struct file *h_file;
17452 + sb = src_dentry->d_sb;
17453 + inode = src_dentry->d_inode;
17454 + if (au_ibstart(inode) <= a->bdst)
17455 + h_inode = au_h_iptr(inode, a->bdst);
17456 + if (!h_inode || !h_inode->i_nlink) {
17457 + /* copyup src_dentry as the name of dentry. */
17458 + bend = au_dbend(dentry);
17459 + if (bend < a->bsrc)
17460 + au_set_dbend(dentry, a->bsrc);
17461 + au_set_h_dptr(dentry, a->bsrc,
17462 + dget(au_h_dptr(src_dentry, a->bsrc)));
17463 + dget(a->h_path.dentry);
17464 + au_set_h_dptr(dentry, a->bdst, NULL);
17465 + dentry->d_inode = src_dentry->d_inode; /* tmp */
17466 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
17467 + if (IS_ERR(h_file))
17468 + err = PTR_ERR(h_file);
17470 + struct au_cp_generic cpg = {
17471 + .dentry = dentry,
17476 + .flags = AuCpup_KEEPLINO
17478 + err = au_sio_cpup_simple(&cpg);
17479 + au_h_open_post(dentry, a->bsrc, h_file);
17481 + dput(a->h_path.dentry);
17482 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17484 + au_set_h_dptr(dentry, a->bdst,
17485 + a->h_path.dentry);
17487 + dentry->d_inode = NULL; /* restore */
17488 + au_set_h_dptr(dentry, a->bsrc, NULL);
17489 + au_set_dbend(dentry, bend);
17491 + /* the inode of src_dentry already exists on a.bdst branch */
17492 + h_src_dentry = d_find_alias(h_inode);
17493 + if (!h_src_dentry && au_plink_test(inode)) {
17495 + h_src_dentry = au_plink_lkup(inode, a->bdst);
17496 + err = PTR_ERR(h_src_dentry);
17497 + if (IS_ERR(h_src_dentry))
17500 + if (unlikely(!h_src_dentry->d_inode)) {
17501 + dput(h_src_dentry);
17502 + h_src_dentry = NULL;
17506 + if (h_src_dentry) {
17507 + delegated = NULL;
17508 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17509 + &a->h_path, &delegated);
17510 + if (unlikely(err == -EWOULDBLOCK)) {
17511 + pr_warn("cannot retry for NFSv4 delegation"
17512 + " for an internal link\n");
17515 + dput(h_src_dentry);
17517 + AuIOErr("no dentry found for hi%lu on b%d\n",
17518 + h_inode->i_ino, a->bdst);
17523 + if (!err && !plink)
17524 + au_plink_append(inode, a->bdst, a->h_path.dentry);
17531 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17532 + struct dentry *dentry)
17535 + struct au_dtime dt;
17536 + struct au_link_args *a;
17537 + struct dentry *wh_dentry, *h_src_dentry;
17538 + struct inode *inode, *delegated;
17539 + struct super_block *sb;
17540 + struct au_wr_dir_args wr_dir_args = {
17541 + /* .force_btgt = -1, */
17542 + .flags = AuWrDir_ADD_ENTRY
17546 + inode = src_dentry->d_inode;
17547 + IMustLock(inode);
17550 + a = kzalloc(sizeof(*a), GFP_NOFS);
17551 + if (unlikely(!a))
17554 + a->parent = dentry->d_parent; /* dir inode is locked */
17555 + err = aufs_read_and_write_lock2(dentry, src_dentry,
17556 + AuLock_NOPLM | AuLock_GEN);
17557 + if (unlikely(err))
17559 + err = au_d_linkable(src_dentry);
17560 + if (unlikely(err))
17562 + err = au_d_may_add(dentry);
17563 + if (unlikely(err))
17566 + a->src_parent = dget_parent(src_dentry);
17567 + wr_dir_args.force_btgt = au_ibstart(inode);
17569 + di_write_lock_parent(a->parent);
17570 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
17571 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
17573 + err = PTR_ERR(wh_dentry);
17574 + if (IS_ERR(wh_dentry))
17578 + sb = dentry->d_sb;
17579 + a->bdst = au_dbstart(dentry);
17580 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17581 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
17582 + a->bsrc = au_ibstart(inode);
17583 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17584 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
17585 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
17586 + if (!h_src_dentry) {
17587 + a->bsrc = au_dbstart(src_dentry);
17588 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17589 + AuDebugOn(!h_src_dentry);
17590 + } else if (IS_ERR(h_src_dentry)) {
17591 + err = PTR_ERR(h_src_dentry);
17595 + if (au_opt_test(au_mntflags(sb), PLINK)) {
17596 + if (a->bdst < a->bsrc
17597 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
17598 + err = au_cpup_or_link(src_dentry, dentry, a);
17600 + delegated = NULL;
17601 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17602 + &a->h_path, &delegated);
17603 + if (unlikely(err == -EWOULDBLOCK)) {
17604 + pr_warn("cannot retry for NFSv4 delegation"
17605 + " for an internal link\n");
17609 + dput(h_src_dentry);
17612 + * copyup src_dentry to the branch we process,
17613 + * and then link(2) to it.
17615 + dput(h_src_dentry);
17616 + if (a->bdst < a->bsrc
17617 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
17618 + au_unpin(&a->pin);
17619 + di_write_unlock(a->parent);
17620 + err = au_cpup_before_link(src_dentry, a);
17621 + di_write_lock_parent(a->parent);
17623 + err = au_pin(&a->pin, dentry, a->bdst,
17625 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17626 + if (unlikely(err))
17630 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
17632 + if (h_src_dentry && h_src_dentry->d_inode) {
17633 + delegated = NULL;
17634 + err = vfsub_link(h_src_dentry,
17635 + au_pinned_h_dir(&a->pin),
17636 + &a->h_path, &delegated);
17637 + if (unlikely(err == -EWOULDBLOCK)) {
17638 + pr_warn("cannot retry"
17639 + " for NFSv4 delegation"
17640 + " for an internal link\n");
17646 + if (unlikely(err))
17650 + a->h_path.dentry = wh_dentry;
17651 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
17653 + if (unlikely(err))
17657 + dir->i_version++;
17658 + if (au_ibstart(dir) == au_dbstart(dentry))
17659 + au_cpup_attr_timesizes(dir);
17660 + inc_nlink(inode);
17661 + inode->i_ctime = dir->i_ctime;
17662 + d_instantiate(dentry, au_igrab(inode));
17663 + if (d_unhashed(a->h_path.dentry))
17664 + /* some filesystem calls d_drop() */
17666 + /* some filesystems consume an inode even hardlink */
17667 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
17668 + goto out_unpin; /* success */
17671 + /* no delegation since it is just created */
17672 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
17673 + /*delegated*/NULL, /*force*/0);
17674 + if (unlikely(rerr)) {
17675 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
17678 + au_dtime_revert(&dt);
17680 + au_unpin(&a->pin);
17684 + di_write_unlock(a->parent);
17685 + dput(a->src_parent);
17687 + if (unlikely(err)) {
17688 + au_update_dbstart(dentry);
17691 + aufs_read_and_write_unlock2(dentry, src_dentry);
17699 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
17702 + aufs_bindex_t bindex;
17703 + unsigned char diropq;
17704 + struct path h_path;
17705 + struct dentry *wh_dentry, *parent, *opq_dentry;
17706 + struct mutex *h_mtx;
17707 + struct super_block *sb;
17709 + struct au_pin pin;
17710 + struct au_dtime dt;
17711 + } *a; /* reduce the stack usage */
17712 + struct au_wr_dir_args wr_dir_args = {
17713 + .force_btgt = -1,
17714 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
17720 + a = kmalloc(sizeof(*a), GFP_NOFS);
17721 + if (unlikely(!a))
17724 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17725 + if (unlikely(err))
17727 + err = au_d_may_add(dentry);
17728 + if (unlikely(err))
17731 + parent = dentry->d_parent; /* dir inode is locked */
17732 + di_write_lock_parent(parent);
17733 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17734 + &a->pin, &wr_dir_args);
17735 + err = PTR_ERR(wh_dentry);
17736 + if (IS_ERR(wh_dentry))
17739 + sb = dentry->d_sb;
17740 + bindex = au_dbstart(dentry);
17741 + h_path.dentry = au_h_dptr(dentry, bindex);
17742 + h_path.mnt = au_sbr_mnt(sb, bindex);
17743 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
17744 + if (unlikely(err))
17747 + /* make the dir opaque */
17749 + h_mtx = &h_path.dentry->d_inode->i_mutex;
17751 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
17752 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17753 + opq_dentry = au_diropq_create(dentry, bindex);
17754 + mutex_unlock(h_mtx);
17755 + err = PTR_ERR(opq_dentry);
17756 + if (IS_ERR(opq_dentry))
17758 + dput(opq_dentry);
17762 + err = epilog(dir, bindex, wh_dentry, dentry);
17765 + goto out_unpin; /* success */
17770 + AuLabel(revert opq);
17771 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
17772 + rerr = au_diropq_remove(dentry, bindex);
17773 + mutex_unlock(h_mtx);
17775 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
17776 + dentry, err, rerr);
17782 + AuLabel(revert dir);
17783 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
17785 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
17786 + dentry, err, rerr);
17789 + au_dtime_revert(&a->dt);
17791 + au_unpin(&a->pin);
17794 + di_write_unlock(parent);
17796 + if (unlikely(err)) {
17797 + au_update_dbstart(dentry);
17800 + aufs_read_unlock(dentry, AuLock_DW);
17806 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
17807 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
17808 +++ linux/fs/aufs/i_op.c 2014-08-14 10:15:45.121942630 +0200
17811 + * Copyright (C) 2005-2014 Junjiro R. Okajima
17813 + * This program, aufs is free software; you can redistribute it and/or modify
17814 + * it under the terms of the GNU General Public License as published by
17815 + * the Free Software Foundation; either version 2 of the License, or
17816 + * (at your option) any later version.
17818 + * This program is distributed in the hope that it will be useful,
17819 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17820 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17821 + * GNU General Public License for more details.
17823 + * You should have received a copy of the GNU General Public License
17824 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17828 + * inode operations (except add/del/rename)
17831 +#include <linux/device_cgroup.h>
17832 +#include <linux/fs_stack.h>
17833 +#include <linux/mm.h>
17834 +#include <linux/namei.h>
17835 +#include <linux/security.h>
17838 +static int h_permission(struct inode *h_inode, int mask,
17839 + struct vfsmount *h_mnt, int brperm)
17842 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
17845 + if ((write_mask && IS_IMMUTABLE(h_inode))
17846 + || ((mask & MAY_EXEC)
17847 + && S_ISREG(h_inode->i_mode)
17848 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
17849 + || !(h_inode->i_mode & S_IXUGO))))
17853 + * - skip the lower fs test in the case of write to ro branch.
17854 + * - nfs dir permission write check is optimized, but a policy for
17855 + * link/rename requires a real check.
17857 + if ((write_mask && !au_br_writable(brperm))
17858 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
17859 + && write_mask && !(mask & MAY_READ))
17860 + || !h_inode->i_op->permission) {
17861 + /* AuLabel(generic_permission); */
17862 + err = generic_permission(h_inode, mask);
17864 + /* AuLabel(h_inode->permission); */
17865 + err = h_inode->i_op->permission(h_inode, mask);
17870 + err = devcgroup_inode_permission(h_inode, mask);
17872 + err = security_inode_permission(h_inode, mask);
17876 + /* todo: do we need to call ima_path_check()? */
17877 + struct path h_path = {
17881 + err = ima_path_check(&h_path,
17882 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
17883 + IMA_COUNT_LEAVE);
17891 +static int aufs_permission(struct inode *inode, int mask)
17894 + aufs_bindex_t bindex, bend;
17895 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
17896 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
17897 + struct inode *h_inode;
17898 + struct super_block *sb;
17899 + struct au_branch *br;
17901 + /* todo: support rcu-walk? */
17902 + if (mask & MAY_NOT_BLOCK)
17905 + sb = inode->i_sb;
17906 + si_read_lock(sb, AuLock_FLUSH);
17907 + ii_read_lock_child(inode);
17909 + err = au_iigen_test(inode, au_sigen(sb));
17910 + if (unlikely(err))
17916 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
17917 + err = au_busy_or_stale();
17918 + h_inode = au_h_iptr(inode, au_ibstart(inode));
17919 + if (unlikely(!h_inode
17920 + || (h_inode->i_mode & S_IFMT)
17921 + != (inode->i_mode & S_IFMT)))
17925 + bindex = au_ibstart(inode);
17926 + br = au_sbr(sb, bindex);
17927 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
17930 + && !special_file(h_inode->i_mode)) {
17931 + /* test whether the upper writable branch exists */
17933 + for (; bindex >= 0; bindex--)
17934 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
17942 + /* non-write to dir */
17944 + bend = au_ibend(inode);
17945 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
17946 + h_inode = au_h_iptr(inode, bindex);
17948 + err = au_busy_or_stale();
17949 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
17952 + br = au_sbr(sb, bindex);
17953 + err = h_permission(h_inode, mask, au_br_mnt(br),
17959 + ii_read_unlock(inode);
17960 + si_read_unlock(sb);
17964 +/* ---------------------------------------------------------------------- */
17966 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
17967 + unsigned int flags)
17969 + struct dentry *ret, *parent;
17970 + struct inode *inode;
17971 + struct super_block *sb;
17972 + int err, npositive;
17976 + /* todo: support rcu-walk? */
17977 + ret = ERR_PTR(-ECHILD);
17978 + if (flags & LOOKUP_RCU)
17981 + ret = ERR_PTR(-ENAMETOOLONG);
17982 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17986 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17987 + ret = ERR_PTR(err);
17988 + if (unlikely(err))
17991 + err = au_di_init(dentry);
17992 + ret = ERR_PTR(err);
17993 + if (unlikely(err))
17997 + npositive = 0; /* suppress a warning */
17998 + parent = dentry->d_parent; /* dir inode is locked */
17999 + di_read_lock_parent(parent, AuLock_IR);
18000 + err = au_alive_dir(parent);
18002 + err = au_digen_test(parent, au_sigen(sb));
18004 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
18008 + di_read_unlock(parent, AuLock_IR);
18009 + ret = ERR_PTR(err);
18010 + if (unlikely(err < 0))
18014 + inode = au_new_inode(dentry, /*must_new*/0);
18015 + ret = (void *)inode;
18017 + if (IS_ERR(inode)) {
18022 + ret = d_splice_alias(inode, dentry);
18024 + if (unlikely(d_need_lookup(dentry))) {
18025 + spin_lock(&dentry->d_lock);
18026 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18027 + spin_unlock(&dentry->d_lock);
18030 + if (unlikely(IS_ERR(ret) && inode)) {
18031 + ii_write_unlock(inode);
18037 + di_write_unlock(dentry);
18039 + /* verbose coding for lock class name */
18040 + if (unlikely(S_ISLNK(inode->i_mode)))
18041 + au_rw_class(&au_di(dentry)->di_rwsem,
18042 + au_lc_key + AuLcSymlink_DIINFO);
18043 + else if (unlikely(S_ISDIR(inode->i_mode)))
18044 + au_rw_class(&au_di(dentry)->di_rwsem,
18045 + au_lc_key + AuLcDir_DIINFO);
18046 + else /* likely */
18047 + au_rw_class(&au_di(dentry)->di_rwsem,
18048 + au_lc_key + AuLcNonDir_DIINFO);
18051 + si_read_unlock(sb);
18056 +/* ---------------------------------------------------------------------- */
18058 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18059 + const unsigned char add_entry, aufs_bindex_t bcpup,
18060 + aufs_bindex_t bstart)
18063 + struct dentry *h_parent;
18064 + struct inode *h_dir;
18067 + IMustLock(parent->d_inode);
18069 + di_write_lock_parent(parent);
18072 + if (!au_h_dptr(parent, bcpup)) {
18073 + if (bstart > bcpup)
18074 + err = au_cpup_dirs(dentry, bcpup);
18075 + else if (bstart < bcpup)
18076 + err = au_cpdown_dirs(dentry, bcpup);
18080 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18081 + h_parent = au_h_dptr(parent, bcpup);
18082 + h_dir = h_parent->d_inode;
18083 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
18084 + err = au_lkup_neg(dentry, bcpup,
18085 + au_ftest_wrdir(add_entry, TMP_WHENTRY));
18086 + /* todo: no unlock here */
18087 + mutex_unlock(&h_dir->i_mutex);
18089 + AuDbg("bcpup %d\n", bcpup);
18091 + if (!dentry->d_inode)
18092 + au_set_h_dptr(dentry, bstart, NULL);
18093 + au_update_dbrange(dentry, /*do_put_zero*/0);
18098 + di_write_unlock(parent);
18100 + err = bcpup; /* success */
18107 + * decide the branch and the parent dir where we will create a new entry.
18108 + * returns new bindex or an error.
18109 + * copyup the parent dir if needed.
18111 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18112 + struct au_wr_dir_args *args)
18115 + unsigned int flags;
18116 + aufs_bindex_t bcpup, bstart, src_bstart;
18117 + const unsigned char add_entry
18118 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18119 + | au_ftest_wrdir(args->flags, TMP_WHENTRY)
18120 + | au_ftest_wrdir(args->flags, TMPFILE);
18121 + struct super_block *sb;
18122 + struct dentry *parent;
18123 + struct au_sbinfo *sbinfo;
18125 + sb = dentry->d_sb;
18126 + sbinfo = au_sbi(sb);
18127 + parent = dget_parent(dentry);
18128 + bstart = au_dbstart(dentry);
18130 + if (args->force_btgt < 0) {
18131 + if (src_dentry) {
18132 + src_bstart = au_dbstart(src_dentry);
18133 + if (src_bstart < bstart)
18134 + bcpup = src_bstart;
18135 + } else if (add_entry) {
18137 + if (au_ftest_wrdir(args->flags, ISDIR))
18138 + au_fset_wbr(flags, DIR);
18139 + err = AuWbrCreate(sbinfo, dentry, flags);
18143 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
18145 + err = AuWbrCopyup(sbinfo, dentry);
18147 + if (!IS_ROOT(dentry)) {
18148 + di_read_lock_parent(parent, !AuLock_IR);
18149 + err = AuWbrCopyup(sbinfo, dentry);
18150 + di_read_unlock(parent, !AuLock_IR);
18152 + err = AuWbrCopyup(sbinfo, dentry);
18155 + if (unlikely(err < 0))
18159 + bcpup = args->force_btgt;
18160 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
18163 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
18165 + if (bcpup == bstart)
18166 + goto out; /* success */
18168 + /* copyup the new parent into the branch we process */
18169 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
18171 + if (!dentry->d_inode) {
18172 + au_set_h_dptr(dentry, bstart, NULL);
18173 + au_set_dbstart(dentry, bcpup);
18174 + au_set_dbend(dentry, bcpup);
18176 + AuDebugOn(add_entry
18177 + && !au_ftest_wrdir(args->flags, TMPFILE)
18178 + && !au_h_dptr(dentry, bcpup));
18186 +/* ---------------------------------------------------------------------- */
18188 +void au_pin_hdir_unlock(struct au_pin *p)
18191 + au_hn_imtx_unlock(p->hdir);
18194 +static int au_pin_hdir_lock(struct au_pin *p)
18202 + /* even if an error happens later, keep this lock */
18203 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
18206 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
18211 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18212 + p->h_parent, p->br);
18218 +int au_pin_hdir_relock(struct au_pin *p)
18221 + struct inode *h_i;
18222 + struct dentry *h_d[] = {
18227 + err = au_pin_hdir_lock(p);
18228 + if (unlikely(err))
18231 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
18234 + h_i = h_d[i]->d_inode;
18236 + err = !h_i->i_nlink;
18243 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
18245 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
18246 + p->hdir->hi_inode->i_mutex.owner = task;
18250 +void au_pin_hdir_acquire_nest(struct au_pin *p)
18253 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
18254 + p->lsc_hi, 0, NULL, _RET_IP_);
18255 + au_pin_hdir_set_owner(p, current);
18259 +void au_pin_hdir_release(struct au_pin *p)
18262 + au_pin_hdir_set_owner(p, p->task);
18263 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
18267 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
18269 + if (pin && pin->parent)
18270 + return au_h_dptr(pin->parent, pin->bindex);
18274 +void au_unpin(struct au_pin *p)
18277 + au_pin_hdir_unlock(p);
18278 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
18279 + vfsub_mnt_drop_write(p->h_mnt);
18283 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18284 + di_read_unlock(p->parent, AuLock_IR);
18285 + iput(p->hdir->hi_inode);
18287 + p->parent = NULL;
18290 + /* do not clear p->task */
18293 +int au_do_pin(struct au_pin *p)
18296 + struct super_block *sb;
18297 + struct inode *h_dir;
18300 + sb = p->dentry->d_sb;
18301 + p->br = au_sbr(sb, p->bindex);
18302 + if (IS_ROOT(p->dentry)) {
18303 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18304 + p->h_mnt = au_br_mnt(p->br);
18305 + err = vfsub_mnt_want_write(p->h_mnt);
18306 + if (unlikely(err)) {
18307 + au_fclr_pin(p->flags, MNT_WRITE);
18314 + p->h_dentry = NULL;
18315 + if (p->bindex <= au_dbend(p->dentry))
18316 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
18318 + p->parent = dget_parent(p->dentry);
18319 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18320 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
18323 + p->h_parent = au_h_dptr(p->parent, p->bindex);
18324 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
18326 + h_dir = p->hdir->hi_inode;
18330 + * if DI_LOCKED is not set, then p->parent may be different
18331 + * and h_parent can be NULL.
18333 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
18335 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18336 + di_read_unlock(p->parent, AuLock_IR);
18338 + p->parent = NULL;
18342 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18343 + p->h_mnt = au_br_mnt(p->br);
18344 + err = vfsub_mnt_want_write(p->h_mnt);
18345 + if (unlikely(err)) {
18346 + au_fclr_pin(p->flags, MNT_WRITE);
18347 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18348 + di_read_unlock(p->parent, AuLock_IR);
18350 + p->parent = NULL;
18356 + err = au_pin_hdir_lock(p);
18358 + goto out; /* success */
18363 + pr_err("err %d\n", err);
18364 + err = au_busy_or_stale();
18369 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
18370 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18371 + unsigned int udba, unsigned char flags)
18373 + p->dentry = dentry;
18375 + p->lsc_di = lsc_di;
18376 + p->lsc_hi = lsc_hi;
18377 + p->flags = flags;
18378 + p->bindex = bindex;
18380 + p->parent = NULL;
18384 + p->h_dentry = NULL;
18385 + p->h_parent = NULL;
18387 + p->task = current;
18390 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18391 + unsigned int udba, unsigned char flags)
18393 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
18395 + return au_do_pin(pin);
18398 +/* ---------------------------------------------------------------------- */
18401 + * ->setattr() and ->getattr() are called in various cases.
18402 + * chmod, stat: dentry is revalidated.
18403 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
18405 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
18407 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
18408 +static int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
18411 + struct inode *inode;
18412 + struct dentry *parent;
18415 + inode = dentry->d_inode;
18416 + if (au_digen_test(dentry, sigen)) {
18417 + parent = dget_parent(dentry);
18418 + di_read_lock_parent(parent, AuLock_IR);
18419 + err = au_refresh_dentry(dentry, parent);
18420 + di_read_unlock(parent, AuLock_IR);
18428 +#define AuIcpup_DID_CPUP 1
18429 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
18430 +#define au_fset_icpup(flags, name) \
18431 + do { (flags) |= AuIcpup_##name; } while (0)
18432 +#define au_fclr_icpup(flags, name) \
18433 + do { (flags) &= ~AuIcpup_##name; } while (0)
18435 +struct au_icpup_args {
18436 + unsigned char flags;
18437 + unsigned char pin_flags;
18438 + aufs_bindex_t btgt;
18439 + unsigned int udba;
18440 + struct au_pin pin;
18441 + struct path h_path;
18442 + struct inode *h_inode;
18445 +static int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18446 + struct au_icpup_args *a)
18450 + aufs_bindex_t bstart, ibstart;
18451 + struct dentry *hi_wh, *parent;
18452 + struct inode *inode;
18453 + struct au_wr_dir_args wr_dir_args = {
18454 + .force_btgt = -1,
18458 + bstart = au_dbstart(dentry);
18459 + inode = dentry->d_inode;
18460 + if (S_ISDIR(inode->i_mode))
18461 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18462 + /* plink or hi_wh() case */
18463 + ibstart = au_ibstart(inode);
18464 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
18465 + wr_dir_args.force_btgt = ibstart;
18466 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18467 + if (unlikely(err < 0))
18470 + if (err != bstart)
18471 + au_fset_icpup(a->flags, DID_CPUP);
18474 + a->pin_flags = AuPin_MNT_WRITE;
18476 + if (!IS_ROOT(dentry)) {
18477 + au_fset_pin(a->pin_flags, DI_LOCKED);
18478 + parent = dget_parent(dentry);
18479 + di_write_lock_parent(parent);
18482 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
18483 + if (unlikely(err))
18486 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18487 + a->h_inode = a->h_path.dentry->d_inode;
18488 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18490 + if ((ia->ia_valid & ATTR_SIZE) && ia->ia_size < i_size_read(a->h_inode))
18491 + sz = ia->ia_size;
18492 + mutex_unlock(&a->h_inode->i_mutex);
18495 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
18496 + hi_wh = au_hi_wh(inode, a->btgt);
18498 + struct au_cp_generic cpg = {
18499 + .dentry = dentry,
18505 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
18506 + if (unlikely(err))
18508 + hi_wh = au_hi_wh(inode, a->btgt);
18509 + /* todo: revalidate hi_wh? */
18514 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
18515 + di_downgrade_lock(parent, AuLock_IR);
18519 + if (!au_ftest_icpup(a->flags, DID_CPUP))
18520 + goto out; /* success */
18522 + if (!d_unhashed(dentry)) {
18523 + struct au_cp_generic cpg = {
18524 + .dentry = dentry,
18529 + .flags = AuCpup_DTIME | AuCpup_HOPEN
18531 + err = au_sio_cpup_simple(&cpg);
18533 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18534 + } else if (!hi_wh)
18535 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18537 + a->h_path.dentry = hi_wh; /* do not dget here */
18540 + a->h_inode = a->h_path.dentry->d_inode;
18542 + goto out; /* success */
18543 + au_unpin(&a->pin);
18546 + di_write_unlock(parent);
18551 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18555 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
18558 + struct inode *inode, *delegated;
18559 + struct super_block *sb;
18560 + struct file *file;
18561 + struct au_icpup_args *a;
18563 + inode = dentry->d_inode;
18564 + IMustLock(inode);
18567 + a = kzalloc(sizeof(*a), GFP_NOFS);
18568 + if (unlikely(!a))
18571 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
18572 + ia->ia_valid &= ~ATTR_MODE;
18575 + sb = dentry->d_sb;
18576 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18577 + if (unlikely(err))
18580 + if (ia->ia_valid & ATTR_FILE) {
18581 + /* currently ftruncate(2) only */
18582 + AuDebugOn(!S_ISREG(inode->i_mode));
18583 + file = ia->ia_file;
18584 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
18585 + if (unlikely(err))
18587 + ia->ia_file = au_hf_top(file);
18588 + a->udba = AuOpt_UDBA_NONE;
18590 + /* fchmod() doesn't pass ia_file */
18591 + a->udba = au_opt_udba(sb);
18592 + di_write_lock_child(dentry);
18593 + /* no d_unlinked(), to set UDBA_NONE for root */
18594 + if (d_unhashed(dentry))
18595 + a->udba = AuOpt_UDBA_NONE;
18596 + if (a->udba != AuOpt_UDBA_NONE) {
18597 + AuDebugOn(IS_ROOT(dentry));
18598 + err = au_reval_for_attr(dentry, au_sigen(sb));
18599 + if (unlikely(err))
18604 + err = au_pin_and_icpup(dentry, ia, a);
18605 + if (unlikely(err < 0))
18607 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
18608 + ia->ia_file = NULL;
18609 + ia->ia_valid &= ~ATTR_FILE;
18612 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
18613 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
18614 + == (ATTR_MODE | ATTR_CTIME)) {
18615 + err = security_path_chmod(&a->h_path, ia->ia_mode);
18616 + if (unlikely(err))
18618 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
18619 + && (ia->ia_valid & ATTR_CTIME)) {
18620 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
18621 + if (unlikely(err))
18625 + if (ia->ia_valid & ATTR_SIZE) {
18628 + if (ia->ia_size < i_size_read(inode))
18630 + truncate_setsize(inode, ia->ia_size);
18633 + if (ia->ia_valid & ATTR_FILE)
18635 + mutex_unlock(&a->h_inode->i_mutex);
18636 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
18637 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18639 + delegated = NULL;
18641 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
18643 + err = break_deleg_wait(&delegated);
18651 + au_cpup_attr_changeable(inode);
18654 + mutex_unlock(&a->h_inode->i_mutex);
18655 + au_unpin(&a->pin);
18656 + if (unlikely(err))
18657 + au_update_dbstart(dentry);
18659 + di_write_unlock(dentry);
18661 + fi_write_unlock(file);
18662 + ia->ia_file = file;
18663 + ia->ia_valid |= ATTR_FILE;
18666 + si_read_unlock(sb);
18674 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
18675 + unsigned int nlink)
18679 + inode->i_mode = st->mode;
18680 + /* don't i_[ug]id_write() here */
18681 + inode->i_uid = st->uid;
18682 + inode->i_gid = st->gid;
18683 + inode->i_atime = st->atime;
18684 + inode->i_mtime = st->mtime;
18685 + inode->i_ctime = st->ctime;
18687 + au_cpup_attr_nlink(inode, /*force*/0);
18688 + if (S_ISDIR(inode->i_mode)) {
18689 + n = inode->i_nlink;
18692 + smp_mb(); /* for i_nlink */
18693 + /* 0 can happen */
18694 + set_nlink(inode, n);
18697 + spin_lock(&inode->i_lock);
18698 + inode->i_blocks = st->blocks;
18699 + i_size_write(inode, st->size);
18700 + spin_unlock(&inode->i_lock);
18703 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
18704 + struct dentry *dentry, struct kstat *st)
18707 + unsigned int mnt_flags, sigen;
18708 + aufs_bindex_t bindex;
18709 + unsigned char udba_none, positive;
18710 + struct super_block *sb, *h_sb;
18711 + struct inode *inode;
18712 + struct path h_path;
18714 + sb = dentry->d_sb;
18715 + inode = dentry->d_inode;
18716 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18717 + if (unlikely(err))
18719 + mnt_flags = au_mntflags(sb);
18720 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
18722 + /* support fstat(2) */
18723 + if (!d_unlinked(dentry) && !udba_none) {
18724 + sigen = au_sigen(sb);
18725 + err = au_digen_test(dentry, sigen);
18727 + di_read_lock_child(dentry, AuLock_IR);
18728 + err = au_dbrange_test(dentry);
18729 + if (unlikely(err))
18732 + AuDebugOn(IS_ROOT(dentry));
18733 + di_write_lock_child(dentry);
18734 + err = au_dbrange_test(dentry);
18736 + err = au_reval_for_attr(dentry, sigen);
18737 + di_downgrade_lock(dentry, AuLock_IR);
18738 + if (unlikely(err))
18742 + di_read_lock_child(dentry, AuLock_IR);
18744 + bindex = au_ibstart(inode);
18745 + h_path.mnt = au_sbr_mnt(sb, bindex);
18746 + h_sb = h_path.mnt->mnt_sb;
18747 + if (!au_test_fs_bad_iattr(h_sb) && udba_none)
18748 + goto out_fill; /* success */
18750 + h_path.dentry = NULL;
18751 + if (au_dbstart(dentry) == bindex)
18752 + h_path.dentry = dget(au_h_dptr(dentry, bindex));
18753 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
18754 + h_path.dentry = au_plink_lkup(inode, bindex);
18755 + if (IS_ERR(h_path.dentry))
18756 + goto out_fill; /* pretending success */
18758 + /* illegally overlapped or something */
18759 + if (unlikely(!h_path.dentry))
18760 + goto out_fill; /* pretending success */
18762 + positive = !!h_path.dentry->d_inode;
18764 + err = vfs_getattr(&h_path, st);
18765 + dput(h_path.dentry);
18768 + au_refresh_iattr(inode, st,
18769 + h_path.dentry->d_inode->i_nlink);
18770 + goto out_fill; /* success */
18776 + generic_fillattr(inode, st);
18778 + di_read_unlock(dentry, AuLock_IR);
18779 + si_read_unlock(sb);
18785 +/* ---------------------------------------------------------------------- */
18787 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
18791 + struct super_block *sb;
18792 + struct dentry *h_dentry;
18795 + h_dentry = au_h_dptr(dentry, bindex);
18796 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
18799 + err = security_inode_readlink(h_dentry);
18800 + if (unlikely(err))
18803 + sb = dentry->d_sb;
18804 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
18805 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
18806 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
18808 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
18814 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
18818 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
18819 + if (unlikely(err))
18821 + err = au_d_hashed_positive(dentry);
18823 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
18824 + aufs_read_unlock(dentry, AuLock_IR);
18830 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
18833 + mm_segment_t old_fs;
18840 + buf.k = (void *)__get_free_page(GFP_NOFS);
18841 + if (unlikely(!buf.k))
18844 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
18845 + if (unlikely(err))
18848 + err = au_d_hashed_positive(dentry);
18850 + old_fs = get_fs();
18851 + set_fs(KERNEL_DS);
18852 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
18855 + aufs_read_unlock(dentry, AuLock_IR);
18859 + /* will be freed by put_link */
18860 + nd_set_link(nd, buf.k);
18861 + return NULL; /* success */
18865 + free_page((unsigned long)buf.k);
18868 + return ERR_PTR(err);
18871 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
18872 + struct nameidata *nd, void *cookie __maybe_unused)
18876 + p = nd_get_link(nd);
18877 + if (!IS_ERR_OR_NULL(p))
18878 + free_page((unsigned long)p);
18881 +/* ---------------------------------------------------------------------- */
18883 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
18886 + struct super_block *sb;
18887 + struct inode *h_inode;
18889 + sb = inode->i_sb;
18890 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
18892 + si_read_lock(sb, AuLock_FLUSH);
18893 + ii_write_lock_child(inode);
18895 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18896 + err = vfsub_update_time(h_inode, ts, flags);
18899 + au_cpup_attr_timesizes(inode);
18900 + ii_write_unlock(inode);
18901 + si_read_unlock(sb);
18904 + if (!err && (flags & S_VERSION))
18905 + inode_inc_iversion(inode);
18910 +/* ---------------------------------------------------------------------- */
18912 +struct inode_operations aufs_symlink_iop = {
18913 + .permission = aufs_permission,
18914 + .setattr = aufs_setattr,
18915 + .getattr = aufs_getattr,
18917 + .readlink = aufs_readlink,
18918 + .follow_link = aufs_follow_link,
18919 + .put_link = aufs_put_link,
18921 + /* .update_time = aufs_update_time */
18924 +struct inode_operations aufs_dir_iop = {
18925 + .create = aufs_create,
18926 + .lookup = aufs_lookup,
18927 + .link = aufs_link,
18928 + .unlink = aufs_unlink,
18929 + .symlink = aufs_symlink,
18930 + .mkdir = aufs_mkdir,
18931 + .rmdir = aufs_rmdir,
18932 + .mknod = aufs_mknod,
18933 + .rename = aufs_rename,
18935 + .permission = aufs_permission,
18936 + .setattr = aufs_setattr,
18937 + .getattr = aufs_getattr,
18939 + .update_time = aufs_update_time,
18940 + /* no support for atomic_open() */
18942 + .tmpfile = aufs_tmpfile
18945 +struct inode_operations aufs_iop = {
18946 + .permission = aufs_permission,
18947 + .setattr = aufs_setattr,
18948 + .getattr = aufs_getattr,
18950 + .update_time = aufs_update_time
18952 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
18953 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
18954 +++ linux/fs/aufs/i_op_del.c 2014-08-14 10:15:45.121942630 +0200
18957 + * Copyright (C) 2005-2014 Junjiro R. Okajima
18959 + * This program, aufs is free software; you can redistribute it and/or modify
18960 + * it under the terms of the GNU General Public License as published by
18961 + * the Free Software Foundation; either version 2 of the License, or
18962 + * (at your option) any later version.
18964 + * This program is distributed in the hope that it will be useful,
18965 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18966 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18967 + * GNU General Public License for more details.
18969 + * You should have received a copy of the GNU General Public License
18970 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18974 + * inode operations (del entry)
18980 + * decide if a new whiteout for @dentry is necessary or not.
18981 + * when it is necessary, prepare the parent dir for the upper branch whose
18982 + * branch index is @bcpup for creation. the actual creation of the whiteout will
18983 + * be done by caller.
18985 + * 0: wh is unnecessary
18986 + * plus: wh is necessary
18989 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
18991 + int need_wh, err;
18992 + aufs_bindex_t bstart;
18993 + struct super_block *sb;
18995 + sb = dentry->d_sb;
18996 + bstart = au_dbstart(dentry);
18997 + if (*bcpup < 0) {
18999 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
19000 + err = AuWbrCopyup(au_sbi(sb), dentry);
19002 + if (unlikely(err < 0))
19006 + AuDebugOn(bstart < *bcpup
19007 + || au_test_ro(sb, *bcpup, dentry->d_inode));
19008 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
19010 + if (*bcpup != bstart) {
19011 + err = au_cpup_dirs(dentry, *bcpup);
19012 + if (unlikely(err))
19016 + struct au_dinfo *dinfo, *tmp;
19018 + need_wh = -ENOMEM;
19019 + dinfo = au_di(dentry);
19020 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19022 + au_di_cp(tmp, dinfo);
19023 + au_di_swap(tmp, dinfo);
19024 + /* returns the number of positive dentries */
19025 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
19026 + au_di_swap(tmp, dinfo);
19027 + au_rw_write_unlock(&tmp->di_rwsem);
19031 + AuDbg("need_wh %d\n", need_wh);
19039 + * simple tests for the del-entry operations.
19040 + * following the checks in vfs, plus the parent-child relationship.
19042 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19043 + struct dentry *h_parent, int isdir)
19047 + struct dentry *h_dentry, *h_latest;
19048 + struct inode *h_inode;
19050 + h_dentry = au_h_dptr(dentry, bindex);
19051 + h_inode = h_dentry->d_inode;
19052 + if (dentry->d_inode) {
19054 + if (unlikely(!h_inode || !h_inode->i_nlink))
19057 + h_mode = h_inode->i_mode;
19060 + if (unlikely(S_ISDIR(h_mode)))
19062 + } else if (unlikely(!S_ISDIR(h_mode))) {
19067 + /* rename(2) case */
19069 + if (unlikely(h_inode))
19074 + /* expected parent dir is locked */
19075 + if (unlikely(h_parent != h_dentry->d_parent))
19080 + * rmdir a dir may break the consistency on some filesystem.
19081 + * let's try heavy test.
19084 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
19085 + && au_test_h_perm(h_parent->d_inode,
19086 + MAY_EXEC | MAY_WRITE)))
19089 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
19091 + if (IS_ERR(h_latest))
19093 + if (h_latest == h_dentry)
19102 + * decide the branch where we operate for @dentry. the branch index will be set
19103 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
19104 + * dir for reverting.
19105 + * when a new whiteout is necessary, create it.
19107 +static struct dentry*
19108 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
19109 + struct au_dtime *dt, struct au_pin *pin)
19111 + struct dentry *wh_dentry;
19112 + struct super_block *sb;
19113 + struct path h_path;
19114 + int err, need_wh;
19115 + unsigned int udba;
19116 + aufs_bindex_t bcpup;
19118 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
19119 + wh_dentry = ERR_PTR(need_wh);
19120 + if (unlikely(need_wh < 0))
19123 + sb = dentry->d_sb;
19124 + udba = au_opt_udba(sb);
19126 + err = au_pin(pin, dentry, bcpup, udba,
19127 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19128 + wh_dentry = ERR_PTR(err);
19129 + if (unlikely(err))
19132 + h_path.dentry = au_pinned_h_parent(pin);
19133 + if (udba != AuOpt_UDBA_NONE
19134 + && au_dbstart(dentry) == bcpup) {
19135 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
19136 + wh_dentry = ERR_PTR(err);
19137 + if (unlikely(err))
19141 + h_path.mnt = au_sbr_mnt(sb, bcpup);
19142 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
19143 + wh_dentry = NULL;
19145 + goto out; /* success, no need to create whiteout */
19147 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
19148 + if (IS_ERR(wh_dentry))
19151 + /* returns with the parent is locked and wh_dentry is dget-ed */
19152 + goto out; /* success */
19157 + return wh_dentry;
19161 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
19162 + * in order to be revertible and save time for removing many child whiteouts
19164 + * returns 1 when there are too many child whiteout and caller should remove
19165 + * them asynchronously. returns 0 when the number of children is enough small to
19166 + * remove now or the branch fs is a remote fs.
19167 + * otherwise return an error.
19169 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
19170 + struct au_nhash *whlist, struct inode *dir)
19172 + int rmdir_later, err, dirwh;
19173 + struct dentry *h_dentry;
19174 + struct super_block *sb;
19176 + sb = dentry->d_sb;
19177 + SiMustAnyLock(sb);
19178 + h_dentry = au_h_dptr(dentry, bindex);
19179 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
19180 + if (unlikely(err))
19183 + /* stop monitoring */
19184 + au_hn_free(au_hi(dentry->d_inode, bindex));
19186 + if (!au_test_fs_remote(h_dentry->d_sb)) {
19187 + dirwh = au_sbi(sb)->si_dirwh;
19188 + rmdir_later = (dirwh <= 1);
19189 + if (!rmdir_later)
19190 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
19193 + return rmdir_later;
19196 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
19197 + if (unlikely(err)) {
19198 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
19199 + h_dentry, bindex, err);
19209 + * final procedure for deleting a entry.
19210 + * maintain dentry and iattr.
19212 +static void epilog(struct inode *dir, struct dentry *dentry,
19213 + aufs_bindex_t bindex)
19215 + struct inode *inode;
19217 + inode = dentry->d_inode;
19219 + inode->i_ctime = dir->i_ctime;
19221 + if (au_ibstart(dir) == bindex)
19222 + au_cpup_attr_timesizes(dir);
19223 + dir->i_version++;
19227 + * when an error happened, remove the created whiteout and revert everything.
19229 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
19230 + aufs_bindex_t bwh, struct dentry *wh_dentry,
19231 + struct dentry *dentry, struct au_dtime *dt)
19234 + struct path h_path = {
19235 + .dentry = wh_dentry,
19236 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
19239 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
19241 + au_set_dbwh(dentry, bwh);
19242 + au_dtime_revert(dt);
19246 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
19250 +/* ---------------------------------------------------------------------- */
19252 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
19255 + aufs_bindex_t bwh, bindex, bstart;
19256 + struct inode *inode, *h_dir, *delegated;
19257 + struct dentry *parent, *wh_dentry;
19258 + /* to reuduce stack size */
19260 + struct au_dtime dt;
19261 + struct au_pin pin;
19262 + struct path h_path;
19268 + a = kmalloc(sizeof(*a), GFP_NOFS);
19269 + if (unlikely(!a))
19272 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19273 + if (unlikely(err))
19275 + err = au_d_hashed_positive(dentry);
19276 + if (unlikely(err))
19278 + inode = dentry->d_inode;
19279 + IMustLock(inode);
19281 + if (unlikely(S_ISDIR(inode->i_mode)))
19282 + goto out_unlock; /* possible? */
19284 + bstart = au_dbstart(dentry);
19285 + bwh = au_dbwh(dentry);
19287 + parent = dentry->d_parent; /* dir inode is locked */
19288 + di_write_lock_parent(parent);
19289 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
19291 + err = PTR_ERR(wh_dentry);
19292 + if (IS_ERR(wh_dentry))
19295 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
19296 + a->h_path.dentry = au_h_dptr(dentry, bstart);
19297 + dget(a->h_path.dentry);
19298 + if (bindex == bstart) {
19299 + h_dir = au_pinned_h_dir(&a->pin);
19300 + delegated = NULL;
19301 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
19302 + if (unlikely(err == -EWOULDBLOCK)) {
19303 + pr_warn("cannot retry for NFSv4 delegation"
19304 + " for an internal unlink\n");
19308 + /* dir inode is locked */
19309 + h_dir = wh_dentry->d_parent->d_inode;
19310 + IMustLock(h_dir);
19315 + vfsub_drop_nlink(inode);
19316 + epilog(dir, dentry, bindex);
19318 + /* update target timestamps */
19319 + if (bindex == bstart) {
19320 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
19322 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
19324 + /* todo: this timestamp may be reverted later */
19325 + inode->i_ctime = h_dir->i_ctime;
19326 + goto out_unpin; /* success */
19333 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19340 + au_unpin(&a->pin);
19342 + dput(a->h_path.dentry);
19344 + di_write_unlock(parent);
19346 + aufs_read_unlock(dentry, AuLock_DW);
19353 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
19355 + int err, rmdir_later;
19356 + aufs_bindex_t bwh, bindex, bstart;
19357 + struct inode *inode;
19358 + struct dentry *parent, *wh_dentry, *h_dentry;
19359 + struct au_whtmp_rmdir *args;
19360 + /* to reuduce stack size */
19362 + struct au_dtime dt;
19363 + struct au_pin pin;
19369 + a = kmalloc(sizeof(*a), GFP_NOFS);
19370 + if (unlikely(!a))
19373 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
19374 + if (unlikely(err))
19376 + err = au_alive_dir(dentry);
19377 + if (unlikely(err))
19379 + inode = dentry->d_inode;
19380 + IMustLock(inode);
19382 + if (unlikely(!S_ISDIR(inode->i_mode)))
19383 + goto out_unlock; /* possible? */
19386 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
19387 + if (unlikely(!args))
19390 + parent = dentry->d_parent; /* dir inode is locked */
19391 + di_write_lock_parent(parent);
19392 + err = au_test_empty(dentry, &args->whlist);
19393 + if (unlikely(err))
19396 + bstart = au_dbstart(dentry);
19397 + bwh = au_dbwh(dentry);
19399 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
19401 + err = PTR_ERR(wh_dentry);
19402 + if (IS_ERR(wh_dentry))
19405 + h_dentry = au_h_dptr(dentry, bstart);
19408 + if (bindex == bstart) {
19409 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
19411 + rmdir_later = err;
19415 + /* stop monitoring */
19416 + au_hn_free(au_hi(inode, bstart));
19418 + /* dir inode is locked */
19419 + IMustLock(wh_dentry->d_parent->d_inode);
19424 + vfsub_dead_dir(inode);
19425 + au_set_dbdiropq(dentry, -1);
19426 + epilog(dir, dentry, bindex);
19428 + if (rmdir_later) {
19429 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
19433 + goto out_unpin; /* success */
19441 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19448 + au_unpin(&a->pin);
19452 + di_write_unlock(parent);
19454 + au_whtmp_rmdir_free(args);
19456 + aufs_read_unlock(dentry, AuLock_DW);
19463 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
19464 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
19465 +++ linux/fs/aufs/i_op_ren.c 2014-08-14 10:15:45.128609525 +0200
19468 + * Copyright (C) 2005-2014 Junjiro R. Okajima
19470 + * This program, aufs is free software; you can redistribute it and/or modify
19471 + * it under the terms of the GNU General Public License as published by
19472 + * the Free Software Foundation; either version 2 of the License, or
19473 + * (at your option) any later version.
19475 + * This program is distributed in the hope that it will be useful,
19476 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19477 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19478 + * GNU General Public License for more details.
19480 + * You should have received a copy of the GNU General Public License
19481 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19485 + * inode operation (rename entry)
19486 + * todo: this is crazy monster
19491 +enum { AuSRC, AuDST, AuSrcDst };
19492 +enum { AuPARENT, AuCHILD, AuParentChild };
19494 +#define AuRen_ISDIR 1
19495 +#define AuRen_ISSAMEDIR (1 << 1)
19496 +#define AuRen_WHSRC (1 << 2)
19497 +#define AuRen_WHDST (1 << 3)
19498 +#define AuRen_MNT_WRITE (1 << 4)
19499 +#define AuRen_DT_DSTDIR (1 << 5)
19500 +#define AuRen_DIROPQ (1 << 6)
19501 +#define AuRen_CPUP (1 << 7)
19502 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
19503 +#define au_fset_ren(flags, name) \
19504 + do { (flags) |= AuRen_##name; } while (0)
19505 +#define au_fclr_ren(flags, name) \
19506 + do { (flags) &= ~AuRen_##name; } while (0)
19508 +struct au_ren_args {
19510 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
19512 + struct inode *dir, *inode;
19513 + struct au_hinode *hdir;
19514 + struct au_dtime dt[AuParentChild];
19515 + aufs_bindex_t bstart;
19518 +#define src_dentry sd[AuSRC].dentry
19519 +#define src_dir sd[AuSRC].dir
19520 +#define src_inode sd[AuSRC].inode
19521 +#define src_h_dentry sd[AuSRC].h_dentry
19522 +#define src_parent sd[AuSRC].parent
19523 +#define src_h_parent sd[AuSRC].h_parent
19524 +#define src_wh_dentry sd[AuSRC].wh_dentry
19525 +#define src_hdir sd[AuSRC].hdir
19526 +#define src_h_dir sd[AuSRC].hdir->hi_inode
19527 +#define src_dt sd[AuSRC].dt
19528 +#define src_bstart sd[AuSRC].bstart
19530 +#define dst_dentry sd[AuDST].dentry
19531 +#define dst_dir sd[AuDST].dir
19532 +#define dst_inode sd[AuDST].inode
19533 +#define dst_h_dentry sd[AuDST].h_dentry
19534 +#define dst_parent sd[AuDST].parent
19535 +#define dst_h_parent sd[AuDST].h_parent
19536 +#define dst_wh_dentry sd[AuDST].wh_dentry
19537 +#define dst_hdir sd[AuDST].hdir
19538 +#define dst_h_dir sd[AuDST].hdir->hi_inode
19539 +#define dst_dt sd[AuDST].dt
19540 +#define dst_bstart sd[AuDST].bstart
19542 + struct dentry *h_trap;
19543 + struct au_branch *br;
19544 + struct au_hinode *src_hinode;
19545 + struct path h_path;
19546 + struct au_nhash whlist;
19547 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
19549 + unsigned int flags;
19551 + struct au_whtmp_rmdir *thargs;
19552 + struct dentry *h_dst;
19555 +/* ---------------------------------------------------------------------- */
19558 + * functions for reverting.
19559 + * when an error happened in a single rename systemcall, we should revert
19560 + * everything as if nothing happend.
19561 + * we don't need to revert the copied-up/down the parent dir since they are
19565 +#define RevertFailure(fmt, ...) do { \
19566 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
19567 + ##__VA_ARGS__, err, rerr); \
19571 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
19575 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
19576 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
19577 + au_hn_imtx_unlock(a->src_hinode);
19578 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
19580 + RevertFailure("remove diropq %pd", a->src_dentry);
19583 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
19586 + struct inode *delegated;
19588 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
19589 + a->src_h_parent);
19590 + rerr = PTR_ERR(a->h_path.dentry);
19591 + if (IS_ERR(a->h_path.dentry)) {
19592 + RevertFailure("lkup one %pd", a->src_dentry);
19596 + delegated = NULL;
19597 + rerr = vfsub_rename(a->dst_h_dir,
19598 + au_h_dptr(a->src_dentry, a->btgt),
19599 + a->src_h_dir, &a->h_path, &delegated);
19600 + if (unlikely(rerr == -EWOULDBLOCK)) {
19601 + pr_warn("cannot retry for NFSv4 delegation"
19602 + " for an internal rename\n");
19605 + d_drop(a->h_path.dentry);
19606 + dput(a->h_path.dentry);
19607 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
19609 + RevertFailure("rename %pd", a->src_dentry);
19612 +static void au_ren_rev_cpup(int err, struct au_ren_args *a)
19616 + a->h_path.dentry = a->dst_h_dentry;
19617 + /* no delegation since it is just created */
19618 + rerr = vfsub_unlink(a->dst_h_dir, &a->h_path, /*delegated*/NULL,
19620 + au_set_h_dptr(a->src_dentry, a->btgt, NULL);
19621 + au_set_dbstart(a->src_dentry, a->src_bstart);
19623 + RevertFailure("unlink %pd", a->dst_h_dentry);
19626 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
19629 + struct inode *delegated;
19631 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
19632 + a->dst_h_parent);
19633 + rerr = PTR_ERR(a->h_path.dentry);
19634 + if (IS_ERR(a->h_path.dentry)) {
19635 + RevertFailure("lkup one %pd", a->dst_dentry);
19638 + if (a->h_path.dentry->d_inode) {
19639 + d_drop(a->h_path.dentry);
19640 + dput(a->h_path.dentry);
19644 + delegated = NULL;
19645 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
19647 + if (unlikely(rerr == -EWOULDBLOCK)) {
19648 + pr_warn("cannot retry for NFSv4 delegation"
19649 + " for an internal rename\n");
19652 + d_drop(a->h_path.dentry);
19653 + dput(a->h_path.dentry);
19655 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
19657 + RevertFailure("rename %pd", a->h_dst);
19660 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
19664 + a->h_path.dentry = a->src_wh_dentry;
19665 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
19666 + au_set_dbwh(a->src_dentry, a->src_bwh);
19668 + RevertFailure("unlink %pd", a->src_wh_dentry);
19670 +#undef RevertFailure
19672 +/* ---------------------------------------------------------------------- */
19675 + * when we have to copyup the renaming entry, do it with the rename-target name
19676 + * in order to minimize the cost (the later actual rename is unnecessary).
19677 + * otherwise rename it on the target branch.
19679 +static int au_ren_or_cpup(struct au_ren_args *a)
19682 + struct dentry *d;
19683 + struct inode *delegated;
19685 + d = a->src_dentry;
19686 + if (au_dbstart(d) == a->btgt) {
19687 + a->h_path.dentry = a->dst_h_dentry;
19688 + if (au_ftest_ren(a->flags, DIROPQ)
19689 + && au_dbdiropq(d) == a->btgt)
19690 + au_fclr_ren(a->flags, DIROPQ);
19691 + AuDebugOn(au_dbstart(d) != a->btgt);
19692 + delegated = NULL;
19693 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
19694 + a->dst_h_dir, &a->h_path, &delegated);
19695 + if (unlikely(err == -EWOULDBLOCK)) {
19696 + pr_warn("cannot retry for NFSv4 delegation"
19697 + " for an internal rename\n");
19703 + if (!err && a->h_dst)
19704 + /* it will be set to dinfo later */
19710 +/* cf. aufs_rmdir() */
19711 +static int au_ren_del_whtmp(struct au_ren_args *a)
19714 + struct inode *dir;
19716 + dir = a->dst_dir;
19717 + SiMustAnyLock(dir->i_sb);
19718 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
19719 + au_sbi(dir->i_sb)->si_dirwh)
19720 + || au_test_fs_remote(a->h_dst->d_sb)) {
19721 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
19722 + if (unlikely(err))
19723 + pr_warn("failed removing whtmp dir %pd (%d), "
19724 + "ignored.\n", a->h_dst, err);
19726 + au_nhash_wh_free(&a->thargs->whlist);
19727 + a->thargs->whlist = a->whlist;
19728 + a->whlist.nh_num = 0;
19729 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
19731 + a->thargs = NULL;
19737 +/* make it 'opaque' dir. */
19738 +static int au_ren_diropq(struct au_ren_args *a)
19741 + struct dentry *diropq;
19744 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
19745 + a->src_hinode = au_hi(a->src_inode, a->btgt);
19746 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
19747 + diropq = au_diropq_create(a->src_dentry, a->btgt);
19748 + au_hn_imtx_unlock(a->src_hinode);
19749 + if (IS_ERR(diropq))
19750 + err = PTR_ERR(diropq);
19757 +static int do_rename(struct au_ren_args *a)
19760 + struct dentry *d, *h_d;
19762 + /* prepare workqueue args for asynchronous rmdir */
19763 + h_d = a->dst_h_dentry;
19764 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
19766 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
19767 + if (unlikely(!a->thargs))
19769 + a->h_dst = dget(h_d);
19772 + /* create whiteout for src_dentry */
19773 + if (au_ftest_ren(a->flags, WHSRC)) {
19774 + a->src_bwh = au_dbwh(a->src_dentry);
19775 + AuDebugOn(a->src_bwh >= 0);
19777 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
19778 + err = PTR_ERR(a->src_wh_dentry);
19779 + if (IS_ERR(a->src_wh_dentry))
19783 + /* lookup whiteout for dentry */
19784 + if (au_ftest_ren(a->flags, WHDST)) {
19785 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
19787 + err = PTR_ERR(h_d);
19790 + if (!h_d->d_inode)
19793 + a->dst_wh_dentry = h_d;
19796 + /* rename dentry to tmpwh */
19798 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
19799 + if (unlikely(err))
19802 + d = a->dst_dentry;
19803 + au_set_h_dptr(d, a->btgt, NULL);
19804 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
19805 + if (unlikely(err))
19807 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
19810 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
19812 + /* rename by vfs_rename or cpup */
19813 + d = a->dst_dentry;
19814 + if (au_ftest_ren(a->flags, ISDIR)
19815 + && (a->dst_wh_dentry
19816 + || au_dbdiropq(d) == a->btgt
19817 + /* hide the lower to keep xino */
19818 + || a->btgt < au_dbend(d)
19819 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
19820 + au_fset_ren(a->flags, DIROPQ);
19821 + err = au_ren_or_cpup(a);
19822 + if (unlikely(err))
19823 + /* leave the copied-up one */
19826 + /* make dir opaque */
19827 + if (au_ftest_ren(a->flags, DIROPQ)) {
19828 + err = au_ren_diropq(a);
19829 + if (unlikely(err))
19833 + /* update target timestamps */
19834 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
19835 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
19836 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
19837 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
19839 + /* remove whiteout for dentry */
19840 + if (a->dst_wh_dentry) {
19841 + a->h_path.dentry = a->dst_wh_dentry;
19842 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
19844 + if (unlikely(err))
19848 + /* remove whtmp */
19850 + au_ren_del_whtmp(a); /* ignore this error */
19852 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
19854 + goto out_success;
19857 + if (au_ftest_ren(a->flags, DIROPQ))
19858 + au_ren_rev_diropq(err, a);
19860 + if (!au_ftest_ren(a->flags, CPUP))
19861 + au_ren_rev_rename(err, a);
19863 + au_ren_rev_cpup(err, a);
19867 + au_ren_rev_whtmp(err, a);
19869 + dput(a->dst_wh_dentry);
19870 + a->dst_wh_dentry = NULL;
19872 + if (a->src_wh_dentry)
19873 + au_ren_rev_whsrc(err, a);
19875 + dput(a->src_wh_dentry);
19876 + dput(a->dst_wh_dentry);
19880 + au_whtmp_rmdir_free(a->thargs);
19881 + a->thargs = NULL;
19887 +/* ---------------------------------------------------------------------- */
19890 + * test if @dentry dir can be rename destination or not.
19891 + * success means, it is a logically empty dir.
19893 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
19895 + return au_test_empty(dentry, whlist);
19899 + * test if @dentry dir can be rename source or not.
19900 + * if it can, return 0 and @children is filled.
19902 + * - it is a logically empty dir.
19903 + * - or, it exists on writable branch and has no children including whiteouts
19904 + * on the lower branch.
19906 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
19909 + unsigned int rdhash;
19910 + aufs_bindex_t bstart;
19912 + bstart = au_dbstart(dentry);
19913 + if (bstart != btgt) {
19914 + struct au_nhash whlist;
19916 + SiMustAnyLock(dentry->d_sb);
19917 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
19919 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
19921 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
19922 + if (unlikely(err))
19924 + err = au_test_empty(dentry, &whlist);
19925 + au_nhash_wh_free(&whlist);
19929 + if (bstart == au_dbtaildir(dentry))
19930 + return 0; /* success */
19932 + err = au_test_empty_lower(dentry);
19935 + if (err == -ENOTEMPTY) {
19936 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
19937 + " is not supported\n");
19943 +/* side effect: sets whlist and h_dentry */
19944 +static int au_ren_may_dir(struct au_ren_args *a)
19947 + unsigned int rdhash;
19948 + struct dentry *d;
19950 + d = a->dst_dentry;
19951 + SiMustAnyLock(d->d_sb);
19954 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
19955 + rdhash = au_sbi(d->d_sb)->si_rdhash;
19957 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
19958 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
19959 + if (unlikely(err))
19962 + au_set_dbstart(d, a->dst_bstart);
19963 + err = may_rename_dstdir(d, &a->whlist);
19964 + au_set_dbstart(d, a->btgt);
19966 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
19967 + if (unlikely(err))
19970 + d = a->src_dentry;
19971 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
19972 + if (au_ftest_ren(a->flags, ISDIR)) {
19973 + err = may_rename_srcdir(d, a->btgt);
19974 + if (unlikely(err)) {
19975 + au_nhash_wh_free(&a->whlist);
19976 + a->whlist.nh_num = 0;
19983 +/* ---------------------------------------------------------------------- */
19986 + * simple tests for rename.
19987 + * following the checks in vfs, plus the parent-child relationship.
19989 +static int au_may_ren(struct au_ren_args *a)
19992 + struct inode *h_inode;
19994 + if (a->src_bstart == a->btgt) {
19995 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
19996 + au_ftest_ren(a->flags, ISDIR));
19997 + if (unlikely(err))
20000 + if (unlikely(a->src_h_dentry == a->h_trap))
20005 + if (a->dst_bstart != a->btgt)
20008 + err = -ENOTEMPTY;
20009 + if (unlikely(a->dst_h_dentry == a->h_trap))
20013 + h_inode = a->dst_h_dentry->d_inode;
20014 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20015 + if (!a->dst_dentry->d_inode) {
20016 + if (unlikely(h_inode))
20018 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
20021 + if (unlikely(!h_inode || !h_inode->i_nlink))
20023 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
20025 + if (unlikely(err))
20030 + if (unlikely(err == -ENOENT || err == -EEXIST))
20036 +/* ---------------------------------------------------------------------- */
20041 + * - src_dir and dir by lock_rename()
20042 + * - inode if exitsts
20045 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
20047 + * + di_write_lock2_child()
20048 + * + di_write_lock_child()
20049 + * + ii_write_lock_child()
20050 + * + di_write_lock_child2()
20051 + * + ii_write_lock_child2()
20052 + * + src_parent and parent
20053 + * + di_write_lock_parent()
20054 + * + ii_write_lock_parent()
20055 + * + di_write_lock_parent2()
20056 + * + ii_write_lock_parent2()
20057 + * + lower src_dir and dir by vfsub_lock_rename()
20058 + * + verify the every relationships between child and parent. if any
20059 + * of them failed, unlock all and return -EBUSY.
20061 +static void au_ren_unlock(struct au_ren_args *a)
20063 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
20064 + a->dst_h_parent, a->dst_hdir);
20065 + if (au_ftest_ren(a->flags, MNT_WRITE))
20066 + vfsub_mnt_drop_write(au_br_mnt(a->br));
20069 +static int au_ren_lock(struct au_ren_args *a)
20072 + unsigned int udba;
20075 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
20076 + a->src_hdir = au_hi(a->src_dir, a->btgt);
20077 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
20078 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
20080 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
20081 + if (unlikely(err))
20083 + au_fset_ren(a->flags, MNT_WRITE);
20084 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
20085 + a->dst_h_parent, a->dst_hdir);
20086 + udba = au_opt_udba(a->src_dentry->d_sb);
20087 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
20088 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
20089 + err = au_busy_or_stale();
20090 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
20091 + err = au_h_verify(a->src_h_dentry, udba,
20092 + a->src_h_parent->d_inode, a->src_h_parent,
20094 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
20095 + err = au_h_verify(a->dst_h_dentry, udba,
20096 + a->dst_h_parent->d_inode, a->dst_h_parent,
20099 + goto out; /* success */
20101 + err = au_busy_or_stale();
20102 + au_ren_unlock(a);
20108 +/* ---------------------------------------------------------------------- */
20110 +static void au_ren_refresh_dir(struct au_ren_args *a)
20112 + struct inode *dir;
20114 + dir = a->dst_dir;
20115 + dir->i_version++;
20116 + if (au_ftest_ren(a->flags, ISDIR)) {
20117 + /* is this updating defined in POSIX? */
20118 + au_cpup_attr_timesizes(a->src_inode);
20119 + au_cpup_attr_nlink(dir, /*force*/1);
20122 + if (au_ibstart(dir) == a->btgt)
20123 + au_cpup_attr_timesizes(dir);
20125 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20128 + dir = a->src_dir;
20129 + dir->i_version++;
20130 + if (au_ftest_ren(a->flags, ISDIR))
20131 + au_cpup_attr_nlink(dir, /*force*/1);
20132 + if (au_ibstart(dir) == a->btgt)
20133 + au_cpup_attr_timesizes(dir);
20136 +static void au_ren_refresh(struct au_ren_args *a)
20138 + aufs_bindex_t bend, bindex;
20139 + struct dentry *d, *h_d;
20140 + struct inode *i, *h_i;
20141 + struct super_block *sb;
20143 + d = a->dst_dentry;
20146 + /* already dget-ed by au_ren_or_cpup() */
20147 + au_set_h_dptr(d, a->btgt, a->h_dst);
20149 + i = a->dst_inode;
20151 + if (!au_ftest_ren(a->flags, ISDIR))
20152 + vfsub_drop_nlink(i);
20154 + vfsub_dead_dir(i);
20155 + au_cpup_attr_timesizes(i);
20157 + au_update_dbrange(d, /*do_put_zero*/1);
20160 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
20161 + au_set_h_dptr(d, bindex, NULL);
20162 + bend = au_dbend(d);
20163 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
20164 + au_set_h_dptr(d, bindex, NULL);
20165 + au_update_dbrange(d, /*do_put_zero*/0);
20168 + d = a->src_dentry;
20169 + au_set_dbwh(d, -1);
20170 + bend = au_dbend(d);
20171 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20172 + h_d = au_h_dptr(d, bindex);
20174 + au_set_h_dptr(d, bindex, NULL);
20176 + au_set_dbend(d, a->btgt);
20179 + i = a->src_inode;
20180 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
20181 + return; /* success */
20183 + bend = au_ibend(i);
20184 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20185 + h_i = au_h_iptr(i, bindex);
20187 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
20188 + /* ignore this error */
20189 + au_set_h_iptr(i, bindex, NULL, 0);
20192 + au_set_ibend(i, a->btgt);
20195 +/* ---------------------------------------------------------------------- */
20197 +/* mainly for link(2) and rename(2) */
20198 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
20200 + aufs_bindex_t bdiropq, bwh;
20201 + struct dentry *parent;
20202 + struct au_branch *br;
20204 + parent = dentry->d_parent;
20205 + IMustLock(parent->d_inode); /* dir is locked */
20207 + bdiropq = au_dbdiropq(parent);
20208 + bwh = au_dbwh(dentry);
20209 + br = au_sbr(dentry->d_sb, btgt);
20210 + if (au_br_rdonly(br)
20211 + || (0 <= bdiropq && bdiropq < btgt)
20212 + || (0 <= bwh && bwh < btgt))
20215 + AuDbg("btgt %d\n", btgt);
20219 +/* sets src_bstart, dst_bstart and btgt */
20220 +static int au_ren_wbr(struct au_ren_args *a)
20223 + struct au_wr_dir_args wr_dir_args = {
20224 + /* .force_btgt = -1, */
20225 + .flags = AuWrDir_ADD_ENTRY
20228 + a->src_bstart = au_dbstart(a->src_dentry);
20229 + a->dst_bstart = au_dbstart(a->dst_dentry);
20230 + if (au_ftest_ren(a->flags, ISDIR))
20231 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
20232 + wr_dir_args.force_btgt = a->src_bstart;
20233 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
20234 + wr_dir_args.force_btgt = a->dst_bstart;
20235 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
20236 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
20242 +static void au_ren_dt(struct au_ren_args *a)
20244 + a->h_path.dentry = a->src_h_parent;
20245 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
20246 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
20247 + a->h_path.dentry = a->dst_h_parent;
20248 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
20251 + au_fclr_ren(a->flags, DT_DSTDIR);
20252 + if (!au_ftest_ren(a->flags, ISDIR))
20255 + a->h_path.dentry = a->src_h_dentry;
20256 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
20257 + if (a->dst_h_dentry->d_inode) {
20258 + au_fset_ren(a->flags, DT_DSTDIR);
20259 + a->h_path.dentry = a->dst_h_dentry;
20260 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
20264 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
20266 + struct dentry *h_d;
20267 + struct mutex *h_mtx;
20269 + au_dtime_revert(a->src_dt + AuPARENT);
20270 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
20271 + au_dtime_revert(a->dst_dt + AuPARENT);
20273 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
20274 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
20275 + h_mtx = &h_d->d_inode->i_mutex;
20276 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20277 + au_dtime_revert(a->src_dt + AuCHILD);
20278 + mutex_unlock(h_mtx);
20280 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
20281 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
20282 + h_mtx = &h_d->d_inode->i_mutex;
20283 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20284 + au_dtime_revert(a->dst_dt + AuCHILD);
20285 + mutex_unlock(h_mtx);
20290 +/* ---------------------------------------------------------------------- */
20292 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
20293 + struct inode *_dst_dir, struct dentry *_dst_dentry)
20296 + /* reduce stack space */
20297 + struct au_ren_args *a;
20299 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
20300 + IMustLock(_src_dir);
20301 + IMustLock(_dst_dir);
20304 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
20305 + a = kzalloc(sizeof(*a), GFP_NOFS);
20306 + if (unlikely(!a))
20309 + a->src_dir = _src_dir;
20310 + a->src_dentry = _src_dentry;
20311 + a->src_inode = a->src_dentry->d_inode;
20312 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
20313 + a->dst_dir = _dst_dir;
20314 + a->dst_dentry = _dst_dentry;
20315 + a->dst_inode = a->dst_dentry->d_inode;
20316 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
20317 + if (a->dst_inode) {
20318 + IMustLock(a->dst_inode);
20319 + au_igrab(a->dst_inode);
20323 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
20324 + if (S_ISDIR(a->src_inode->i_mode)) {
20325 + au_fset_ren(a->flags, ISDIR);
20326 + if (unlikely(a->dst_inode && !S_ISDIR(a->dst_inode->i_mode)))
20328 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20329 + AuLock_DIR | flags);
20331 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20333 + if (unlikely(err))
20336 + err = au_d_hashed_positive(a->src_dentry);
20337 + if (unlikely(err))
20340 + if (a->dst_inode) {
20342 + * If it is a dir, VFS unhash dst_dentry before this
20343 + * function. It means we cannot rely upon d_unhashed().
20345 + if (unlikely(!a->dst_inode->i_nlink))
20347 + if (!S_ISDIR(a->dst_inode->i_mode)) {
20348 + err = au_d_hashed_positive(a->dst_dentry);
20349 + if (unlikely(err))
20351 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
20353 + } else if (unlikely(d_unhashed(a->dst_dentry)))
20357 + * is it possible?
20358 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
20359 + * there may exist a problem somewhere else.
20362 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
20365 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
20366 + di_write_lock_parent(a->dst_parent);
20368 + /* which branch we process */
20369 + err = au_ren_wbr(a);
20370 + if (unlikely(err < 0))
20372 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
20373 + a->h_path.mnt = au_br_mnt(a->br);
20375 + /* are they available to be renamed */
20376 + err = au_ren_may_dir(a);
20377 + if (unlikely(err))
20378 + goto out_children;
20380 + /* prepare the writable parent dir on the same branch */
20381 + if (a->dst_bstart == a->btgt) {
20382 + au_fset_ren(a->flags, WHDST);
20384 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
20385 + if (unlikely(err))
20386 + goto out_children;
20389 + if (a->src_dir != a->dst_dir) {
20391 + * this temporary unlock is safe,
20392 + * because both dir->i_mutex are locked.
20394 + di_write_unlock(a->dst_parent);
20395 + di_write_lock_parent(a->src_parent);
20396 + err = au_wr_dir_need_wh(a->src_dentry,
20397 + au_ftest_ren(a->flags, ISDIR),
20399 + di_write_unlock(a->src_parent);
20400 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
20401 + au_fclr_ren(a->flags, ISSAMEDIR);
20403 + err = au_wr_dir_need_wh(a->src_dentry,
20404 + au_ftest_ren(a->flags, ISDIR),
20406 + if (unlikely(err < 0))
20407 + goto out_children;
20409 + au_fset_ren(a->flags, WHSRC);
20412 + if (a->src_bstart != a->btgt) {
20413 + struct au_pin pin;
20415 + err = au_pin(&pin, a->src_dentry, a->btgt,
20416 + au_opt_udba(a->src_dentry->d_sb),
20417 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20419 + struct au_cp_generic cpg = {
20420 + .dentry = a->src_dentry,
20422 + .bsrc = a->src_bstart,
20425 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20427 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
20428 + err = au_sio_cpup_simple(&cpg);
20431 + if (unlikely(err))
20432 + goto out_children;
20433 + a->src_bstart = a->btgt;
20434 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
20435 + au_fset_ren(a->flags, WHSRC);
20438 + /* lock them all */
20439 + err = au_ren_lock(a);
20440 + if (unlikely(err))
20441 + /* leave the copied-up one */
20442 + goto out_children;
20444 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
20445 + err = au_may_ren(a);
20446 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
20447 + err = -ENAMETOOLONG;
20448 + if (unlikely(err))
20451 + /* store timestamps to be revertible */
20455 + err = do_rename(a);
20456 + if (unlikely(err))
20459 + /* update dir attributes */
20460 + au_ren_refresh_dir(a);
20462 + /* dput/iput all lower dentries */
20463 + au_ren_refresh(a);
20465 + goto out_hdir; /* success */
20468 + au_ren_rev_dt(err, a);
20470 + au_ren_unlock(a);
20472 + au_nhash_wh_free(&a->whlist);
20473 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
20474 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
20475 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
20476 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
20480 + d_move(a->src_dentry, a->dst_dentry);
20482 + au_update_dbstart(a->dst_dentry);
20483 + if (!a->dst_inode)
20484 + d_drop(a->dst_dentry);
20486 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20487 + di_write_unlock(a->dst_parent);
20489 + di_write_unlock2(a->src_parent, a->dst_parent);
20491 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
20493 + iput(a->dst_inode);
20495 + au_whtmp_rmdir_free(a->thargs);
20501 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
20502 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
20503 +++ linux/fs/aufs/Kconfig 2014-08-14 10:15:45.118609182 +0200
20506 + tristate "Aufs (Advanced multi layered unification filesystem) support"
20508 + Aufs is a stackable unification filesystem such as Unionfs,
20509 + which unifies several directories and provides a merged single
20511 + In the early days, aufs was entirely re-designed and
20512 + re-implemented Unionfs Version 1.x series. Introducing many
20513 + original ideas, approaches and improvements, it becomes totally
20514 + different from Unionfs while keeping the basic features.
20518 + prompt "Maximum number of branches"
20519 + default AUFS_BRANCH_MAX_127
20521 + Specifies the maximum number of branches (or member directories)
20522 + in a single aufs. The larger value consumes more system
20523 + resources and has a minor impact to performance.
20524 +config AUFS_BRANCH_MAX_127
20527 + Specifies the maximum number of branches (or member directories)
20528 + in a single aufs. The larger value consumes more system
20529 + resources and has a minor impact to performance.
20530 +config AUFS_BRANCH_MAX_511
20533 + Specifies the maximum number of branches (or member directories)
20534 + in a single aufs. The larger value consumes more system
20535 + resources and has a minor impact to performance.
20536 +config AUFS_BRANCH_MAX_1023
20539 + Specifies the maximum number of branches (or member directories)
20540 + in a single aufs. The larger value consumes more system
20541 + resources and has a minor impact to performance.
20542 +config AUFS_BRANCH_MAX_32767
20545 + Specifies the maximum number of branches (or member directories)
20546 + in a single aufs. The larger value consumes more system
20547 + resources and has a minor impact to performance.
20550 +config AUFS_SBILIST
20552 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
20555 + Automatic configuration for internal use.
20556 + When aufs supports Magic SysRq or /proc, enabled automatically.
20558 +config AUFS_HNOTIFY
20559 + bool "Detect direct branch access (bypassing aufs)"
20561 + If you want to modify files on branches directly, eg. bypassing aufs,
20562 + and want aufs to detect the changes of them fully, then enable this
20563 + option and use 'udba=notify' mount option.
20564 + Currently there is only one available configuration, "fsnotify".
20565 + It will have a negative impact to the performance.
20566 + See detail in aufs.5.
20569 + prompt "method" if AUFS_HNOTIFY
20570 + default AUFS_HFSNOTIFY
20571 +config AUFS_HFSNOTIFY
20576 +config AUFS_EXPORT
20577 + bool "NFS-exportable aufs"
20578 + depends on EXPORTFS
20580 + If you want to export your mounted aufs via NFS, then enable this
20581 + option. There are several requirements for this configuration.
20582 + See detail in aufs.5.
20584 +config AUFS_INO_T_64
20586 + depends on AUFS_EXPORT
20587 + depends on 64BIT && !(ALPHA || S390)
20590 + Automatic configuration for internal use.
20591 + /* typedef unsigned long/int __kernel_ino_t */
20592 + /* alpha and s390x are int */
20595 + bool "File-based Hierarchical Storage Management"
20597 + Hierarchical Storage Management (or HSM) is a well-known feature
20598 + in the storage world. Aufs provides this feature as file-based.
20599 + with multiple branches.
20600 + These multiple branches are prioritized, ie. the topmost one
20601 + should be the fastest drive and be used heavily.
20604 + bool "Readdir in userspace"
20606 + Aufs has two methods to provide a merged view for a directory,
20607 + by a user-space library and by kernel-space natively. The latter
20608 + is always enabled but sometimes large and slow.
20609 + If you enable this option, install the library in aufs2-util
20610 + package, and set some environment variables for your readdir(3),
20611 + then the work will be handled in user-space which generally
20612 + shows better performance in most cases.
20613 + See detail in aufs.5.
20616 + bool "Show whiteouts"
20618 + If you want to make the whiteouts in aufs visible, then enable
20619 + this option and specify 'shwh' mount option. Although it may
20620 + sounds like philosophy or something, but in technically it
20621 + simply shows the name of whiteout with keeping its behaviour.
20623 +config AUFS_BR_RAMFS
20624 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
20626 + If you want to use ramfs as an aufs branch fs, then enable this
20627 + option. Generally tmpfs is recommended.
20628 + Aufs prohibited them to be a branch fs by default, because
20629 + initramfs becomes unusable after switch_root or something
20630 + generally. If you sets initramfs as an aufs branch and boot your
20631 + system by switch_root, you will meet a problem easily since the
20632 + files in initramfs may be inaccessible.
20633 + Unless you are going to use ramfs as an aufs branch fs without
20634 + switch_root or something, leave it N.
20636 +config AUFS_BR_FUSE
20637 + bool "Fuse fs as an aufs branch"
20638 + depends on FUSE_FS
20641 + If you want to use fuse-based userspace filesystem as an aufs
20642 + branch fs, then enable this option.
20643 + It implements the internal poll(2) operation which is
20644 + implemented by fuse only (curretnly).
20649 + Automatic configuration for internal use.
20651 +config AUFS_BR_HFSPLUS
20652 + bool "Hfsplus as an aufs branch"
20653 + depends on HFSPLUS_FS
20656 + If you want to use hfsplus fs as an aufs branch fs, then enable
20657 + this option. This option introduces a small overhead at
20658 + copying-up a file on hfsplus.
20660 +config AUFS_BDEV_LOOP
20662 + depends on BLK_DEV_LOOP
20665 + Automatic configuration for internal use.
20666 + Convert =[ym] into =y.
20669 + bool "Debug aufs"
20671 + Enable this to compile aufs internal debug code.
20672 + It will have a negative impact to the performance.
20674 +config AUFS_MAGIC_SYSRQ
20676 + depends on AUFS_DEBUG && MAGIC_SYSRQ
20679 + Automatic configuration for internal use.
20680 + When aufs supports Magic SysRq, enabled automatically.
20682 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
20683 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
20684 +++ linux/fs/aufs/loop.c 2014-01-30 21:10:02.850815069 +0100
20687 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20689 + * This program, aufs is free software; you can redistribute it and/or modify
20690 + * it under the terms of the GNU General Public License as published by
20691 + * the Free Software Foundation; either version 2 of the License, or
20692 + * (at your option) any later version.
20694 + * This program is distributed in the hope that it will be useful,
20695 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20696 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20697 + * GNU General Public License for more details.
20699 + * You should have received a copy of the GNU General Public License
20700 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20704 + * support for loopback block device as a branch
20709 +/* added into drivers/block/loop.c */
20710 +static struct file *(*backing_file_func)(struct super_block *sb);
20713 + * test if two lower dentries have overlapping branches.
20715 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
20717 + struct super_block *h_sb;
20718 + struct file *backing_file;
20720 + if (unlikely(!backing_file_func)) {
20721 + /* don't load "loop" module here */
20722 + backing_file_func = symbol_get(loop_backing_file);
20723 + if (unlikely(!backing_file_func))
20724 + /* "loop" module is not loaded */
20728 + h_sb = h_adding->d_sb;
20729 + backing_file = backing_file_func(h_sb);
20730 + if (!backing_file)
20733 + h_adding = backing_file->f_dentry;
20735 + * h_adding can be local NFS.
20736 + * in this case aufs cannot detect the loop.
20738 + if (unlikely(h_adding->d_sb == sb))
20740 + return !!au_test_subdir(h_adding, sb->s_root);
20743 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
20744 +int au_test_loopback_kthread(void)
20747 + struct task_struct *tsk = current;
20748 + char c, comm[sizeof(tsk->comm)];
20751 + if (tsk->flags & PF_KTHREAD) {
20752 + get_task_comm(comm, tsk);
20754 + ret = ('0' <= c && c <= '9'
20755 + && !strncmp(comm, "loop", 4));
20761 +/* ---------------------------------------------------------------------- */
20763 +#define au_warn_loopback_step 16
20764 +static int au_warn_loopback_nelem = au_warn_loopback_step;
20765 +static unsigned long *au_warn_loopback_array;
20767 +void au_warn_loopback(struct super_block *h_sb)
20769 + int i, new_nelem;
20770 + unsigned long *a, magic;
20771 + static DEFINE_SPINLOCK(spin);
20773 + magic = h_sb->s_magic;
20774 + spin_lock(&spin);
20775 + a = au_warn_loopback_array;
20776 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
20777 + if (a[i] == magic) {
20778 + spin_unlock(&spin);
20782 + /* h_sb is new to us, print it */
20783 + if (i < au_warn_loopback_nelem) {
20788 + /* expand the array */
20789 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
20790 + a = au_kzrealloc(au_warn_loopback_array,
20791 + au_warn_loopback_nelem * sizeof(unsigned long),
20792 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
20794 + au_warn_loopback_nelem = new_nelem;
20795 + au_warn_loopback_array = a;
20800 + spin_unlock(&spin);
20801 + AuWarn1("realloc failed, ignored\n");
20805 + spin_unlock(&spin);
20806 + pr_warn("you may want to try another patch for loopback file "
20807 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
20810 +int au_loopback_init(void)
20813 + struct super_block *sb __maybe_unused;
20815 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
20818 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
20819 + sizeof(unsigned long), GFP_NOFS);
20820 + if (unlikely(!au_warn_loopback_array))
20826 +void au_loopback_fin(void)
20828 + symbol_put(loop_backing_file);
20829 + kfree(au_warn_loopback_array);
20831 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
20832 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
20833 +++ linux/fs/aufs/loop.h 2014-01-30 21:10:02.850815069 +0100
20836 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20838 + * This program, aufs is free software; you can redistribute it and/or modify
20839 + * it under the terms of the GNU General Public License as published by
20840 + * the Free Software Foundation; either version 2 of the License, or
20841 + * (at your option) any later version.
20843 + * This program is distributed in the hope that it will be useful,
20844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20846 + * GNU General Public License for more details.
20848 + * You should have received a copy of the GNU General Public License
20849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20853 + * support for loopback mount as a branch
20856 +#ifndef __AUFS_LOOP_H__
20857 +#define __AUFS_LOOP_H__
20862 +struct super_block;
20864 +#ifdef CONFIG_AUFS_BDEV_LOOP
20865 +/* drivers/block/loop.c */
20866 +struct file *loop_backing_file(struct super_block *sb);
20869 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
20870 +int au_test_loopback_kthread(void);
20871 +void au_warn_loopback(struct super_block *h_sb);
20873 +int au_loopback_init(void);
20874 +void au_loopback_fin(void);
20876 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
20877 + struct dentry *h_adding)
20878 +AuStubInt0(au_test_loopback_kthread, void)
20879 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
20881 +AuStubInt0(au_loopback_init, void)
20882 +AuStubVoid(au_loopback_fin, void)
20883 +#endif /* BLK_DEV_LOOP */
20885 +#endif /* __KERNEL__ */
20886 +#endif /* __AUFS_LOOP_H__ */
20887 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
20888 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
20889 +++ linux/fs/aufs/magic.mk 2014-01-30 21:10:02.850815069 +0100
20892 +# defined in ${srctree}/fs/fuse/inode.c
20894 +ifdef CONFIG_FUSE_FS
20895 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
20898 +# defined in ${srctree}/fs/ocfs2/ocfs2_fs.h
20900 +ifdef CONFIG_OCFS2_FS
20901 +ccflags-y += -DOCFS2_SUPER_MAGIC=0x7461636f
20904 +# defined in ${srctree}/fs/ocfs2/dlm/userdlm.h
20906 +ifdef CONFIG_OCFS2_FS_O2CB
20907 +ccflags-y += -DDLMFS_MAGIC=0x76a9f425
20910 +# defined in ${srctree}/fs/cifs/cifsfs.c
20912 +ifdef CONFIG_CIFS_FS
20913 +ccflags-y += -DCIFS_MAGIC_NUMBER=0xFF534D42
20916 +# defined in ${srctree}/fs/xfs/xfs_sb.h
20918 +ifdef CONFIG_XFS_FS
20919 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
20922 +# defined in ${srctree}/fs/configfs/mount.c
20924 +ifdef CONFIG_CONFIGFS_FS
20925 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
20928 +# defined in ${srctree}/fs/9p/v9fs.h
20930 +ifdef CONFIG_9P_FS
20931 +ccflags-y += -DV9FS_MAGIC=0x01021997
20934 +# defined in ${srctree}/fs/ubifs/ubifs.h
20936 +ifdef CONFIG_UBIFS_FS
20937 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
20940 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
20942 +ifdef CONFIG_HFSPLUS_FS
20943 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
20945 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
20946 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
20947 +++ linux/fs/aufs/Makefile 2014-08-14 10:15:45.118609182 +0200
20950 +include ${src}/magic.mk
20951 +ifeq (${CONFIG_AUFS_FS},m)
20952 +include ${src}/conf.mk
20954 +-include ${src}/priv_def.mk
20956 +# cf. include/linux/kernel.h
20958 +ccflags-y += -DDEBUG
20959 +# sparse requires the full pathname
20961 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
20963 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
20966 +obj-$(CONFIG_AUFS_FS) += aufs.o
20967 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
20968 + wkq.o vfsub.o dcsub.o \
20969 + cpup.o whout.o wbr_policy.o \
20970 + dinfo.o dentry.o \
20972 + finfo.o file.o f_op.o \
20974 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
20978 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
20979 +aufs-$(CONFIG_SYSFS) += sysfs.o
20980 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
20981 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
20982 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
20983 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
20984 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
20985 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
20986 +aufs-$(CONFIG_AUFS_POLL) += poll.o
20987 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
20988 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
20989 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
20990 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
20991 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
20992 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
20993 +++ linux/fs/aufs/module.c 2014-08-14 10:15:45.128609525 +0200
20996 + * Copyright (C) 2005-2014 Junjiro R. Okajima
20998 + * This program, aufs is free software; you can redistribute it and/or modify
20999 + * it under the terms of the GNU General Public License as published by
21000 + * the Free Software Foundation; either version 2 of the License, or
21001 + * (at your option) any later version.
21003 + * This program is distributed in the hope that it will be useful,
21004 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21005 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21006 + * GNU General Public License for more details.
21008 + * You should have received a copy of the GNU General Public License
21009 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21013 + * module global variables and operations
21016 +#include <linux/module.h>
21017 +#include <linux/seq_file.h>
21020 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21022 + if (new_sz <= nused)
21025 + p = krealloc(p, new_sz, gfp);
21027 + memset(p + nused, 0, new_sz - nused);
21031 +/* ---------------------------------------------------------------------- */
21036 +struct kmem_cache *au_cachep[AuCache_Last];
21037 +static int __init au_cache_init(void)
21039 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21040 + if (au_cachep[AuCache_DINFO])
21041 + /* SLAB_DESTROY_BY_RCU */
21042 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21043 + au_icntnr_init_once);
21044 + if (au_cachep[AuCache_ICNTNR])
21045 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21046 + au_fi_init_once);
21047 + if (au_cachep[AuCache_FINFO])
21048 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21049 + if (au_cachep[AuCache_VDIR])
21050 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21051 + if (au_cachep[AuCache_DEHSTR])
21057 +static void au_cache_fin(void)
21062 + * Make sure all delayed rcu free inodes are flushed before we
21067 + /* excluding AuCache_HNOTIFY */
21068 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21069 + for (i = 0; i < AuCache_HNOTIFY; i++)
21070 + if (au_cachep[i]) {
21071 + kmem_cache_destroy(au_cachep[i]);
21072 + au_cachep[i] = NULL;
21076 +/* ---------------------------------------------------------------------- */
21078 +int au_dir_roflags;
21080 +#ifdef CONFIG_AUFS_SBILIST
21082 + * iterate_supers_type() doesn't protect us from
21083 + * remounting (branch management)
21085 +struct au_splhead au_sbilist;
21088 +struct lock_class_key au_lc_key[AuLcKey_Last];
21091 + * functions for module interface.
21093 +MODULE_LICENSE("GPL");
21094 +/* MODULE_LICENSE("GPL v2"); */
21095 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21096 +MODULE_DESCRIPTION(AUFS_NAME
21097 + " -- Advanced multi layered unification filesystem");
21098 +MODULE_VERSION(AUFS_VERSION);
21099 +MODULE_ALIAS_FS(AUFS_NAME);
21101 +/* this module parameter has no meaning when SYSFS is disabled */
21102 +int sysaufs_brs = 1;
21103 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21104 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21106 +/* this module parameter has no meaning when USER_NS is disabled */
21107 +static bool au_userns;
21108 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21109 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21111 +/* ---------------------------------------------------------------------- */
21113 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21115 +int au_seq_path(struct seq_file *seq, struct path *path)
21117 + return seq_path(seq, path, au_esc_chars);
21120 +/* ---------------------------------------------------------------------- */
21122 +static int __init aufs_init(void)
21127 + p = au_esc_chars;
21128 + for (i = 1; i <= ' '; i++)
21134 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21136 + au_sbilist_init();
21137 + sysaufs_brs_init();
21140 + err = sysaufs_init();
21141 + if (unlikely(err))
21143 + err = au_procfs_init();
21144 + if (unlikely(err))
21145 + goto out_sysaufs;
21146 + err = au_wkq_init();
21147 + if (unlikely(err))
21149 + err = au_loopback_init();
21150 + if (unlikely(err))
21152 + err = au_hnotify_init();
21153 + if (unlikely(err))
21154 + goto out_loopback;
21155 + err = au_sysrq_init();
21156 + if (unlikely(err))
21158 + err = au_cache_init();
21159 + if (unlikely(err))
21162 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
21163 + err = register_filesystem(&aufs_fs_type);
21164 + if (unlikely(err))
21167 + /* since we define pr_fmt, call printk directly */
21168 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
21169 + goto out; /* success */
21176 + au_hnotify_fin();
21178 + au_loopback_fin();
21190 +static void __exit aufs_exit(void)
21192 + unregister_filesystem(&aufs_fs_type);
21195 + au_hnotify_fin();
21196 + au_loopback_fin();
21203 +module_init(aufs_init);
21204 +module_exit(aufs_exit);
21205 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
21206 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
21207 +++ linux/fs/aufs/module.h 2014-01-30 21:10:02.850815069 +0100
21210 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21212 + * This program, aufs is free software; you can redistribute it and/or modify
21213 + * it under the terms of the GNU General Public License as published by
21214 + * the Free Software Foundation; either version 2 of the License, or
21215 + * (at your option) any later version.
21217 + * This program is distributed in the hope that it will be useful,
21218 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21219 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21220 + * GNU General Public License for more details.
21222 + * You should have received a copy of the GNU General Public License
21223 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21227 + * module initialization and module-global
21230 +#ifndef __AUFS_MODULE_H__
21231 +#define __AUFS_MODULE_H__
21235 +#include <linux/slab.h>
21240 +/* module parameters */
21241 +extern int sysaufs_brs;
21243 +/* ---------------------------------------------------------------------- */
21245 +extern int au_dir_roflags;
21248 + AuLcNonDir_FIINFO,
21249 + AuLcNonDir_DIINFO,
21250 + AuLcNonDir_IIINFO,
21256 + AuLcSymlink_DIINFO,
21257 + AuLcSymlink_IIINFO,
21261 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
21263 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
21264 +int au_seq_path(struct seq_file *seq, struct path *path);
21266 +#ifdef CONFIG_PROC_FS
21268 +int __init au_procfs_init(void);
21269 +void au_procfs_fin(void);
21271 +AuStubInt0(au_procfs_init, void);
21272 +AuStubVoid(au_procfs_fin, void);
21275 +/* ---------------------------------------------------------------------- */
21284 + AuCache_HNOTIFY, /* must be last */
21288 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
21289 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
21290 +#define AuCacheCtor(type, ctor) \
21291 + kmem_cache_create(#type, sizeof(struct type), \
21292 + __alignof__(struct type), AuCacheFlags, ctor)
21294 +extern struct kmem_cache *au_cachep[];
21296 +#define AuCacheFuncs(name, index) \
21297 +static inline struct au_##name *au_cache_alloc_##name(void) \
21298 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
21299 +static inline void au_cache_free_##name(struct au_##name *p) \
21300 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
21302 +AuCacheFuncs(dinfo, DINFO);
21303 +AuCacheFuncs(icntnr, ICNTNR);
21304 +AuCacheFuncs(finfo, FINFO);
21305 +AuCacheFuncs(vdir, VDIR);
21306 +AuCacheFuncs(vdir_dehstr, DEHSTR);
21307 +#ifdef CONFIG_AUFS_HNOTIFY
21308 +AuCacheFuncs(hnotify, HNOTIFY);
21311 +#endif /* __KERNEL__ */
21312 +#endif /* __AUFS_MODULE_H__ */
21313 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
21314 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
21315 +++ linux/fs/aufs/mvdown.c 2014-08-14 10:15:45.128609525 +0200
21318 + * Copyright (C) 2011-2014 Junjiro R. Okajima
21320 + * This program, aufs is free software; you can redistribute it and/or modify
21321 + * it under the terms of the GNU General Public License as published by
21322 + * the Free Software Foundation; either version 2 of the License, or
21323 + * (at your option) any later version.
21325 + * This program is distributed in the hope that it will be useful,
21326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21328 + * GNU General Public License for more details.
21330 + * You should have received a copy of the GNU General Public License
21331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21335 + * move-down, opposite of copy-up
21340 +struct au_mvd_args {
21342 + struct super_block *h_sb;
21343 + struct dentry *h_parent;
21344 + struct au_hinode *hdir;
21345 + struct inode *h_dir, *h_inode;
21346 + } info[AUFS_MVDOWN_NARRAY];
21348 + struct aufs_mvdown mvdown;
21349 + struct dentry *dentry, *parent;
21350 + struct inode *inode, *dir;
21351 + struct super_block *sb;
21352 + aufs_bindex_t bopq, bwh, bfound;
21353 + unsigned char rename_lock;
21354 + struct au_pin pin;
21357 +#define mvd_errno mvdown.au_errno
21358 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
21359 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
21360 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
21361 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
21363 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
21364 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
21365 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
21366 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
21367 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
21369 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
21370 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
21371 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
21372 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
21373 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
21375 +#define AU_MVD_PR(flag, ...) do { \
21377 + pr_err(__VA_ARGS__); \
21380 +static int find_lower_writable(struct au_mvd_args *a)
21382 + struct super_block *sb;
21383 + aufs_bindex_t bindex, bend;
21384 + struct au_branch *br;
21387 + bindex = a->mvd_bsrc;
21388 + bend = au_sbend(sb);
21389 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
21390 + for (bindex++; bindex <= bend; bindex++) {
21391 + br = au_sbr(sb, bindex);
21392 + if (au_br_fhsm(br->br_perm)
21393 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
21396 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
21397 + for (bindex++; bindex <= bend; bindex++) {
21398 + br = au_sbr(sb, bindex);
21399 + if (!au_br_rdonly(br))
21403 + for (bindex++; bindex <= bend; bindex++) {
21404 + br = au_sbr(sb, bindex);
21405 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
21406 + if (au_br_rdonly(br))
21408 + |= AUFS_MVDOWN_ROLOWER_R;
21416 +/* make the parent dir on bdst */
21417 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
21422 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
21423 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
21424 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
21425 + a->mvd_h_dst_parent = NULL;
21426 + if (au_dbend(a->parent) >= a->mvd_bdst)
21427 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21428 + if (!a->mvd_h_dst_parent) {
21429 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
21430 + if (unlikely(err)) {
21431 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
21434 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21442 +/* lock them all */
21443 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
21446 + struct dentry *h_trap;
21448 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
21449 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
21450 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
21451 + a->rename_lock = 0;
21452 + err = au_pin(&a->pin, a->dentry, a->mvd_bdst,
21453 + au_opt_udba(a->sb),
21454 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21456 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
21457 + mutex_lock_nested(&a->mvd_h_src_dir->i_mutex,
21458 + AuLsc_I_PARENT3);
21460 + AU_MVD_PR(dmsg, "pin failed\n");
21465 + a->rename_lock = 1;
21466 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21467 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21469 + err = (h_trap != a->mvd_h_src_parent);
21471 + err = (h_trap != a->mvd_h_dst_parent);
21473 + BUG_ON(err); /* it should never happen */
21480 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
21482 + if (!a->rename_lock) {
21483 + mutex_unlock(&a->mvd_h_src_dir->i_mutex);
21484 + au_unpin(&a->pin);
21486 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
21487 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
21490 +/* copy-down the file */
21491 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
21494 + struct au_cp_generic cpg = {
21495 + .dentry = a->dentry,
21496 + .bdst = a->mvd_bdst,
21497 + .bsrc = a->mvd_bsrc,
21500 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21503 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
21504 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
21505 + au_fset_cpup(cpg.flags, OVERWRITE);
21506 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
21507 + au_fset_cpup(cpg.flags, RWDST);
21508 + err = au_sio_cpdown_simple(&cpg);
21509 + if (unlikely(err))
21510 + AU_MVD_PR(dmsg, "cpdown failed\n");
21517 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
21520 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
21523 + struct path h_path;
21524 + struct au_branch *br;
21525 + struct inode *delegated;
21527 + br = au_sbr(a->sb, a->mvd_bdst);
21528 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
21529 + err = PTR_ERR(h_path.dentry);
21530 + if (IS_ERR(h_path.dentry)) {
21531 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
21536 + if (h_path.dentry->d_inode) {
21537 + h_path.mnt = au_br_mnt(br);
21538 + delegated = NULL;
21539 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
21540 + &delegated, /*force*/0);
21541 + if (unlikely(err == -EWOULDBLOCK)) {
21542 + pr_warn("cannot retry for NFSv4 delegation"
21543 + " for an internal unlink\n");
21546 + if (unlikely(err))
21547 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
21549 + dput(h_path.dentry);
21557 + * unlink the topmost h_dentry
21558 + * Note: the target file MAY be modified by UDBA between this mutex_unlock() and
21559 + * mutex_lock() in vfs_unlink(). in this case, such changes may be lost.
21561 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
21564 + struct path h_path;
21565 + struct inode *delegated;
21567 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
21568 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
21569 + delegated = NULL;
21570 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
21571 + if (unlikely(err == -EWOULDBLOCK)) {
21572 + pr_warn("cannot retry for NFSv4 delegation"
21573 + " for an internal unlink\n");
21576 + if (unlikely(err))
21577 + AU_MVD_PR(dmsg, "unlink failed\n");
21583 +/* Since mvdown succeeded, we ignore an error of this function */
21584 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
21587 + struct au_branch *br;
21589 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
21590 + br = au_sbr(a->sb, a->mvd_bsrc);
21591 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
21593 + br = au_sbr(a->sb, a->mvd_bdst);
21594 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
21595 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
21598 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
21600 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
21604 + * copy-down the file and unlink the bsrc file.
21605 + * - unlink the bdst whout if exist
21606 + * - copy-down the file (with whtmp name and rename)
21607 + * - unlink the bsrc file
21609 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
21613 + err = au_do_mkdir(dmsg, a);
21615 + err = au_do_lock(dmsg, a);
21616 + if (unlikely(err))
21620 + * do not revert the activities we made on bdst since they should be
21621 + * harmless in aufs.
21624 + err = au_do_cpdown(dmsg, a);
21626 + err = au_do_unlink_wh(dmsg, a);
21627 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
21628 + err = au_do_unlink(dmsg, a);
21629 + if (unlikely(err))
21632 + if (find_lower_writable(a) < 0)
21633 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
21635 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
21636 + au_do_stfs(dmsg, a);
21638 + /* maintain internal array */
21639 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
21640 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
21641 + au_set_dbstart(a->dentry, a->mvd_bdst);
21642 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
21643 + au_set_ibstart(a->inode, a->mvd_bdst);
21645 + if (au_dbend(a->dentry) < a->mvd_bdst)
21646 + au_set_dbend(a->dentry, a->mvd_bdst);
21647 + if (au_ibend(a->inode) < a->mvd_bdst)
21648 + au_set_ibend(a->inode, a->mvd_bdst);
21651 + au_do_unlock(dmsg, a);
21657 +/* ---------------------------------------------------------------------- */
21659 +/* make sure the file is idle */
21660 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
21662 + int err, plinked;
21665 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
21666 + if (au_dbstart(a->dentry) == a->mvd_bsrc
21667 + && d_count(a->dentry) == 1
21668 + && atomic_read(&a->inode->i_count) == 1
21669 + /* && a->mvd_h_src_inode->i_nlink == 1 */
21670 + && (!plinked || !au_plink_test(a->inode))
21671 + && a->inode->i_nlink == 1)
21676 + "b%d, d{b%d, c%u?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
21677 + a->mvd_bsrc, au_dbstart(a->dentry), d_count(a->dentry),
21678 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
21679 + a->mvd_h_src_inode->i_nlink,
21680 + plinked, plinked ? au_plink_test(a->inode) : 0);
21687 +/* make sure the parent dir is fine */
21688 +static int au_mvd_args_parent(const unsigned char dmsg,
21689 + struct au_mvd_args *a)
21692 + aufs_bindex_t bindex;
21695 + if (unlikely(au_alive_dir(a->parent))) {
21697 + AU_MVD_PR(dmsg, "parent dir is dead\n");
21701 + a->bopq = au_dbdiropq(a->parent);
21702 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
21703 + AuDbg("b%d\n", bindex);
21704 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
21705 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
21707 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
21708 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
21709 + a->bopq, a->mvd_bdst);
21717 +static int au_mvd_args_intermediate(const unsigned char dmsg,
21718 + struct au_mvd_args *a)
21721 + struct au_dinfo *dinfo, *tmp;
21723 + /* lookup the next lower positive entry */
21725 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
21726 + if (unlikely(!tmp))
21731 + dinfo = au_di(a->dentry);
21732 + au_di_cp(tmp, dinfo);
21733 + au_di_swap(tmp, dinfo);
21735 + /* returns the number of positive dentries */
21736 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
21738 + a->bwh = au_dbwh(a->dentry);
21739 + else if (err > 0)
21740 + a->bfound = au_dbstart(a->dentry);
21742 + au_di_swap(tmp, dinfo);
21743 + au_rw_write_unlock(&tmp->di_rwsem);
21745 + if (unlikely(err < 0))
21746 + AU_MVD_PR(dmsg, "failed look-up lower\n");
21749 + * here, we have these cases.
21751 + * no positive dentry under bsrc. there are more sub-cases.
21753 + * there no whiteout, we can safely move-down.
21756 + * bsrc < bwh && bwh < bdst
21757 + * there is a whiteout on RO branch. cannot proceed.
21759 + * there is a whiteout on the RW target branch. it should
21762 + * there is a whiteout somewhere unrelated branch.
21763 + * -1 < bfound && bfound <= bsrc
21766 + * found, but it is on RO branch between bsrc and bdst. cannot
21769 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
21772 + * found, after we create the file on bdst, it will be hidden.
21775 + AuDebugOn(a->bfound == -1
21777 + && a->bwh <= a->mvd_bsrc);
21778 + AuDebugOn(-1 < a->bfound
21779 + && a->bfound <= a->mvd_bsrc);
21782 + if (a->bfound == -1
21783 + && a->mvd_bsrc < a->bwh
21785 + && a->bwh < a->mvd_bdst) {
21786 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
21787 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
21788 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
21790 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
21791 + a->mvd_errno = EAU_MVDOWN_UPPER;
21792 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
21793 + a->mvd_bdst, a->bfound);
21797 + err = 0; /* success */
21804 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
21809 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
21810 + && a->bfound == a->mvd_bdst)
21816 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
21819 + struct au_branch *br;
21822 + if (unlikely(S_ISDIR(a->inode->i_mode)))
21826 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
21827 + a->mvd_bsrc = au_ibstart(a->inode);
21829 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
21830 + if (unlikely(a->mvd_bsrc < 0
21831 + || (a->mvd_bsrc < au_dbstart(a->dentry)
21832 + || au_dbend(a->dentry) < a->mvd_bsrc
21833 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
21834 + || (a->mvd_bsrc < au_ibstart(a->inode)
21835 + || au_ibend(a->inode) < a->mvd_bsrc
21836 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
21837 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
21838 + AU_MVD_PR(dmsg, "no upper\n");
21842 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
21843 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
21844 + AU_MVD_PR(dmsg, "on the bottom\n");
21847 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
21848 + br = au_sbr(a->sb, a->mvd_bsrc);
21849 + err = au_br_rdonly(br);
21850 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
21851 + if (unlikely(err))
21853 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
21854 + || IS_APPEND(a->mvd_h_src_inode))) {
21856 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
21862 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
21863 + a->mvd_bdst = find_lower_writable(a);
21864 + if (unlikely(a->mvd_bdst < 0)) {
21865 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
21866 + AU_MVD_PR(dmsg, "no writable lower branch\n");
21870 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
21871 + if (unlikely(a->mvd_bdst < 0
21872 + || au_sbend(a->sb) < a->mvd_bdst)) {
21873 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
21874 + AU_MVD_PR(dmsg, "no lower brid\n");
21879 + err = au_mvd_args_busy(dmsg, a);
21881 + err = au_mvd_args_parent(dmsg, a);
21883 + err = au_mvd_args_intermediate(dmsg, a);
21885 + err = au_mvd_args_exist(dmsg, a);
21887 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
21894 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
21897 + unsigned char dmsg;
21898 + struct au_mvd_args *args;
21901 + if (unlikely(!capable(CAP_SYS_ADMIN)))
21905 + args = kmalloc(sizeof(*args), GFP_NOFS);
21906 + if (unlikely(!args))
21909 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
21911 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
21912 + if (unlikely(err)) {
21917 + AuDbg("flags 0x%x\n", args->mvdown.flags);
21918 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
21919 + args->mvdown.au_errno = 0;
21920 + args->dentry = dentry;
21921 + args->inode = dentry->d_inode;
21922 + args->sb = dentry->d_sb;
21925 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
21926 + args->parent = dget_parent(dentry);
21927 + args->dir = args->parent->d_inode;
21928 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
21929 + dput(args->parent);
21930 + if (unlikely(args->parent != dentry->d_parent)) {
21931 + AU_MVD_PR(dmsg, "parent dir is moved\n");
21935 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
21936 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
21937 + if (unlikely(err))
21940 + di_write_lock_parent(args->parent);
21941 + err = au_mvd_args(dmsg, args);
21942 + if (unlikely(err))
21945 + AuDbgDentry(dentry);
21946 + AuDbgInode(args->inode);
21947 + err = au_do_mvdown(dmsg, args);
21948 + if (unlikely(err))
21950 + AuDbgDentry(dentry);
21951 + AuDbgInode(args->inode);
21953 + au_cpup_attr_timesizes(args->dir);
21954 + au_cpup_attr_timesizes(args->inode);
21955 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
21956 + /* au_digen_dec(dentry); */
21959 + di_write_unlock(args->parent);
21960 + aufs_read_unlock(dentry, AuLock_DW);
21962 + mutex_unlock(&args->inode->i_mutex);
21964 + mutex_unlock(&args->dir->i_mutex);
21966 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
21974 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
21975 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
21976 +++ linux/fs/aufs/opts.c 2014-08-14 10:15:45.128609525 +0200
21979 + * Copyright (C) 2005-2014 Junjiro R. Okajima
21981 + * This program, aufs is free software; you can redistribute it and/or modify
21982 + * it under the terms of the GNU General Public License as published by
21983 + * the Free Software Foundation; either version 2 of the License, or
21984 + * (at your option) any later version.
21986 + * This program is distributed in the hope that it will be useful,
21987 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21988 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21989 + * GNU General Public License for more details.
21991 + * You should have received a copy of the GNU General Public License
21992 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21996 + * mount options/flags
21999 +#include <linux/namei.h>
22000 +#include <linux/types.h> /* a distribution requires */
22001 +#include <linux/parser.h>
22004 +/* ---------------------------------------------------------------------- */
22008 + Opt_add, Opt_del, Opt_mod, Opt_reorder, Opt_append, Opt_prepend,
22009 + Opt_idel, Opt_imod, Opt_ireorder,
22010 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, Opt_rendir,
22011 + Opt_rdblk_def, Opt_rdhash_def,
22012 + Opt_xino, Opt_zxino, Opt_noxino,
22013 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22014 + Opt_trunc_xino_path, Opt_itrunc_xino,
22015 + Opt_trunc_xib, Opt_notrunc_xib,
22016 + Opt_shwh, Opt_noshwh,
22017 + Opt_plink, Opt_noplink, Opt_list_plink,
22019 + Opt_dio, Opt_nodio,
22020 + /* Opt_lock, Opt_unlock, */
22021 + Opt_cmd, Opt_cmd_args,
22022 + Opt_diropq_a, Opt_diropq_w,
22023 + Opt_warn_perm, Opt_nowarn_perm,
22024 + Opt_wbr_copyup, Opt_wbr_create,
22026 + Opt_refrof, Opt_norefrof,
22027 + Opt_verbose, Opt_noverbose,
22028 + Opt_sum, Opt_nosum, Opt_wsum,
22029 + Opt_dirperm1, Opt_nodirperm1,
22030 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22033 +static match_table_t options = {
22034 + {Opt_br, "br=%s"},
22035 + {Opt_br, "br:%s"},
22037 + {Opt_add, "add=%d:%s"},
22038 + {Opt_add, "add:%d:%s"},
22039 + {Opt_add, "ins=%d:%s"},
22040 + {Opt_add, "ins:%d:%s"},
22041 + {Opt_append, "append=%s"},
22042 + {Opt_append, "append:%s"},
22043 + {Opt_prepend, "prepend=%s"},
22044 + {Opt_prepend, "prepend:%s"},
22046 + {Opt_del, "del=%s"},
22047 + {Opt_del, "del:%s"},
22048 + /* {Opt_idel, "idel:%d"}, */
22049 + {Opt_mod, "mod=%s"},
22050 + {Opt_mod, "mod:%s"},
22051 + /* {Opt_imod, "imod:%d:%s"}, */
22053 + {Opt_dirwh, "dirwh=%d"},
22055 + {Opt_xino, "xino=%s"},
22056 + {Opt_noxino, "noxino"},
22057 + {Opt_trunc_xino, "trunc_xino"},
22058 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22059 + {Opt_notrunc_xino, "notrunc_xino"},
22060 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22061 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22062 + /* {Opt_zxino, "zxino=%s"}, */
22063 + {Opt_trunc_xib, "trunc_xib"},
22064 + {Opt_notrunc_xib, "notrunc_xib"},
22066 +#ifdef CONFIG_PROC_FS
22067 + {Opt_plink, "plink"},
22069 + {Opt_ignore_silent, "plink"},
22072 + {Opt_noplink, "noplink"},
22074 +#ifdef CONFIG_AUFS_DEBUG
22075 + {Opt_list_plink, "list_plink"},
22078 + {Opt_udba, "udba=%s"},
22080 + {Opt_dio, "dio"},
22081 + {Opt_nodio, "nodio"},
22083 +#ifdef CONFIG_AUFS_FHSM
22084 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22086 + {Opt_ignore_silent, "fhsm_sec=%d"},
22089 + {Opt_diropq_a, "diropq=always"},
22090 + {Opt_diropq_a, "diropq=a"},
22091 + {Opt_diropq_w, "diropq=whiteouted"},
22092 + {Opt_diropq_w, "diropq=w"},
22094 + {Opt_warn_perm, "warn_perm"},
22095 + {Opt_nowarn_perm, "nowarn_perm"},
22097 + /* keep them temporary */
22098 + {Opt_ignore_silent, "nodlgt"},
22099 + {Opt_ignore_silent, "clean_plink"},
22101 +#ifdef CONFIG_AUFS_SHWH
22102 + {Opt_shwh, "shwh"},
22104 + {Opt_noshwh, "noshwh"},
22106 + {Opt_dirperm1, "dirperm1"},
22107 + {Opt_nodirperm1, "nodirperm1"},
22109 + {Opt_rendir, "rendir=%d"},
22111 + {Opt_refrof, "refrof"},
22112 + {Opt_norefrof, "norefrof"},
22114 + {Opt_verbose, "verbose"},
22115 + {Opt_verbose, "v"},
22116 + {Opt_noverbose, "noverbose"},
22117 + {Opt_noverbose, "quiet"},
22118 + {Opt_noverbose, "q"},
22119 + {Opt_noverbose, "silent"},
22121 + {Opt_sum, "sum"},
22122 + {Opt_nosum, "nosum"},
22123 + {Opt_wsum, "wsum"},
22125 + {Opt_rdcache, "rdcache=%d"},
22126 + {Opt_rdblk, "rdblk=%d"},
22127 + {Opt_rdblk_def, "rdblk=def"},
22128 + {Opt_rdhash, "rdhash=%d"},
22129 + {Opt_rdhash_def, "rdhash=def"},
22131 + {Opt_wbr_create, "create=%s"},
22132 + {Opt_wbr_create, "create_policy=%s"},
22133 + {Opt_wbr_copyup, "cpup=%s"},
22134 + {Opt_wbr_copyup, "copyup=%s"},
22135 + {Opt_wbr_copyup, "copyup_policy=%s"},
22137 + /* internal use for the scripts */
22138 + {Opt_ignore_silent, "si=%s"},
22140 + {Opt_br, "dirs=%s"},
22141 + {Opt_ignore, "debug=%d"},
22142 + {Opt_ignore, "delete=whiteout"},
22143 + {Opt_ignore, "delete=all"},
22144 + {Opt_ignore, "imap=%s"},
22146 + /* temporary workaround, due to old mount(8)? */
22147 + {Opt_ignore_silent, "relatime"},
22152 +/* ---------------------------------------------------------------------- */
22154 +static const char *au_parser_pattern(int val, match_table_t tbl)
22156 + struct match_token *p;
22159 + while (p->pattern) {
22160 + if (p->token == val)
22161 + return p->pattern;
22168 +static const char *au_optstr(int *val, match_table_t tbl)
22170 + struct match_token *p;
22175 + while (p->token) {
22176 + if ((v & p->token) == p->token) {
22177 + *val &= ~p->token;
22178 + return p->pattern;
22185 +/* ---------------------------------------------------------------------- */
22187 +static match_table_t brperm = {
22188 + {AuBrPerm_RO, AUFS_BRPERM_RO},
22189 + {AuBrPerm_RR, AUFS_BRPERM_RR},
22190 + {AuBrPerm_RW, AUFS_BRPERM_RW},
22194 +static match_table_t brattr = {
22196 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
22197 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
22198 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
22199 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
22201 + /* ro/rr branch */
22202 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
22205 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
22206 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
22211 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
22218 + p = strchr(str, '+');
22221 + v = match_token(str, table, args);
22223 + if (v & AuBrAttr_CMOO_Mask)
22224 + attr &= ~AuBrAttr_CMOO_Mask;
22229 + pr_warn("ignored branch attribute %s\n", str);
22239 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
22248 + p = au_optstr(&perm, brattr);
22251 + memcpy(q, p, sz + 1);
22257 + p = au_optstr(&perm, brattr);
22261 + memcpy(q, p, sz + 1);
22270 +static int noinline_for_stack br_perm_val(char *perm)
22272 + int val, bad, sz;
22274 + substring_t args[MAX_OPT_ARGS];
22275 + au_br_perm_str_t attr;
22277 + p = strchr(perm, '+');
22280 + val = match_token(perm, brperm, args);
22284 + pr_warn("ignored branch permission %s\n", perm);
22285 + val = AuBrPerm_RO;
22291 + val |= br_attr_val(p + 1, brattr, args);
22294 + switch (val & AuBrPerm_Mask) {
22295 + case AuBrPerm_RO:
22296 + case AuBrPerm_RR:
22297 + bad = val & AuBrWAttr_Mask;
22298 + val &= ~AuBrWAttr_Mask;
22300 + case AuBrPerm_RW:
22301 + bad = val & AuBrRAttr_Mask;
22302 + val &= ~AuBrRAttr_Mask;
22305 + if (unlikely(bad)) {
22306 + sz = au_do_optstr_br_attr(&attr, bad);
22308 + pr_warn("ignored branch attribute %s\n", attr.a);
22315 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
22317 + au_br_perm_str_t attr;
22323 + p = au_optstr(&perm, brperm);
22324 + AuDebugOn(!p || !*p);
22326 + memcpy(q, p, sz + 1);
22329 + sz = au_do_optstr_br_attr(&attr, perm);
22332 + memcpy(q, attr.a, sz + 1);
22335 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
22338 +/* ---------------------------------------------------------------------- */
22340 +static match_table_t udbalevel = {
22341 + {AuOpt_UDBA_REVAL, "reval"},
22342 + {AuOpt_UDBA_NONE, "none"},
22343 +#ifdef CONFIG_AUFS_HNOTIFY
22344 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
22345 +#ifdef CONFIG_AUFS_HFSNOTIFY
22346 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
22352 +static int noinline_for_stack udba_val(char *str)
22354 + substring_t args[MAX_OPT_ARGS];
22356 + return match_token(str, udbalevel, args);
22359 +const char *au_optstr_udba(int udba)
22361 + return au_parser_pattern(udba, udbalevel);
22364 +/* ---------------------------------------------------------------------- */
22366 +static match_table_t au_wbr_create_policy = {
22367 + {AuWbrCreate_TDP, "tdp"},
22368 + {AuWbrCreate_TDP, "top-down-parent"},
22369 + {AuWbrCreate_RR, "rr"},
22370 + {AuWbrCreate_RR, "round-robin"},
22371 + {AuWbrCreate_MFS, "mfs"},
22372 + {AuWbrCreate_MFS, "most-free-space"},
22373 + {AuWbrCreate_MFSV, "mfs:%d"},
22374 + {AuWbrCreate_MFSV, "most-free-space:%d"},
22376 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
22377 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
22378 + {AuWbrCreate_PMFS, "pmfs"},
22379 + {AuWbrCreate_PMFSV, "pmfs:%d"},
22380 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
22381 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
22387 + * cf. linux/lib/parser.c and cmdline.c
22388 + * gave up calling memparse() since it uses simple_strtoull() instead of
22391 +static int noinline_for_stack
22392 +au_match_ull(substring_t *s, unsigned long long *result)
22395 + unsigned int len;
22399 + len = s->to - s->from;
22400 + if (len + 1 <= sizeof(a)) {
22401 + memcpy(a, s->from, len);
22403 + err = kstrtoull(a, 0, result);
22408 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
22409 + struct au_opt_wbr_create *create)
22412 + unsigned long long ull;
22415 + if (!au_match_ull(arg, &ull))
22416 + create->mfsrr_watermark = ull;
22418 + pr_err("bad integer in %s\n", str);
22425 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
22426 + struct au_opt_wbr_create *create)
22431 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
22432 + create->mfs_second = n;
22434 + pr_err("bad integer in %s\n", str);
22441 +static int noinline_for_stack
22442 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
22445 + substring_t args[MAX_OPT_ARGS];
22447 + err = match_token(str, au_wbr_create_policy, args);
22448 + create->wbr_create = err;
22450 + case AuWbrCreate_MFSRRV:
22451 + case AuWbrCreate_PMFSRRV:
22452 + e = au_wbr_mfs_wmark(&args[0], str, create);
22454 + e = au_wbr_mfs_sec(&args[1], str, create);
22458 + case AuWbrCreate_MFSRR:
22459 + case AuWbrCreate_PMFSRR:
22460 + e = au_wbr_mfs_wmark(&args[0], str, create);
22461 + if (unlikely(e)) {
22466 + case AuWbrCreate_MFS:
22467 + case AuWbrCreate_PMFS:
22468 + create->mfs_second = AUFS_MFS_DEF_SEC;
22470 + case AuWbrCreate_MFSV:
22471 + case AuWbrCreate_PMFSV:
22472 + e = au_wbr_mfs_sec(&args[0], str, create);
22481 +const char *au_optstr_wbr_create(int wbr_create)
22483 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
22486 +static match_table_t au_wbr_copyup_policy = {
22487 + {AuWbrCopyup_TDP, "tdp"},
22488 + {AuWbrCopyup_TDP, "top-down-parent"},
22489 + {AuWbrCopyup_BUP, "bup"},
22490 + {AuWbrCopyup_BUP, "bottom-up-parent"},
22491 + {AuWbrCopyup_BU, "bu"},
22492 + {AuWbrCopyup_BU, "bottom-up"},
22496 +static int noinline_for_stack au_wbr_copyup_val(char *str)
22498 + substring_t args[MAX_OPT_ARGS];
22500 + return match_token(str, au_wbr_copyup_policy, args);
22503 +const char *au_optstr_wbr_copyup(int wbr_copyup)
22505 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
22508 +/* ---------------------------------------------------------------------- */
22510 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
22512 +static void dump_opts(struct au_opts *opts)
22514 +#ifdef CONFIG_AUFS_DEBUG
22515 + /* reduce stack space */
22517 + struct au_opt_add *add;
22518 + struct au_opt_del *del;
22519 + struct au_opt_mod *mod;
22520 + struct au_opt_xino *xino;
22521 + struct au_opt_xino_itrunc *xino_itrunc;
22522 + struct au_opt_wbr_create *create;
22524 + struct au_opt *opt;
22527 + while (opt->type != Opt_tail) {
22528 + switch (opt->type) {
22530 + u.add = &opt->add;
22531 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
22532 + u.add->bindex, u.add->pathname, u.add->perm,
22533 + u.add->path.dentry);
22537 + u.del = &opt->del;
22538 + AuDbg("del {%s, %p}\n",
22539 + u.del->pathname, u.del->h_path.dentry);
22543 + u.mod = &opt->mod;
22544 + AuDbg("mod {%s, 0x%x, %p}\n",
22545 + u.mod->path, u.mod->perm, u.mod->h_root);
22548 + u.add = &opt->add;
22549 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
22550 + u.add->bindex, u.add->pathname, u.add->perm,
22551 + u.add->path.dentry);
22553 + case Opt_prepend:
22554 + u.add = &opt->add;
22555 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
22556 + u.add->bindex, u.add->pathname, u.add->perm,
22557 + u.add->path.dentry);
22560 + AuDbg("dirwh %d\n", opt->dirwh);
22562 + case Opt_rdcache:
22563 + AuDbg("rdcache %d\n", opt->rdcache);
22566 + AuDbg("rdblk %u\n", opt->rdblk);
22568 + case Opt_rdblk_def:
22569 + AuDbg("rdblk_def\n");
22572 + AuDbg("rdhash %u\n", opt->rdhash);
22574 + case Opt_rdhash_def:
22575 + AuDbg("rdhash_def\n");
22578 + u.xino = &opt->xino;
22579 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
22581 + case Opt_trunc_xino:
22582 + AuLabel(trunc_xino);
22584 + case Opt_notrunc_xino:
22585 + AuLabel(notrunc_xino);
22587 + case Opt_trunc_xino_path:
22588 + case Opt_itrunc_xino:
22589 + u.xino_itrunc = &opt->xino_itrunc;
22590 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
22596 + case Opt_trunc_xib:
22597 + AuLabel(trunc_xib);
22599 + case Opt_notrunc_xib:
22600 + AuLabel(notrunc_xib);
22608 + case Opt_dirperm1:
22609 + AuLabel(dirperm1);
22611 + case Opt_nodirperm1:
22612 + AuLabel(nodirperm1);
22617 + case Opt_noplink:
22618 + AuLabel(noplink);
22620 + case Opt_list_plink:
22621 + AuLabel(list_plink);
22624 + AuDbg("udba %d, %s\n",
22625 + opt->udba, au_optstr_udba(opt->udba));
22633 + case Opt_diropq_a:
22634 + AuLabel(diropq_a);
22636 + case Opt_diropq_w:
22637 + AuLabel(diropq_w);
22639 + case Opt_warn_perm:
22640 + AuLabel(warn_perm);
22642 + case Opt_nowarn_perm:
22643 + AuLabel(nowarn_perm);
22648 + case Opt_norefrof:
22649 + AuLabel(norefrof);
22651 + case Opt_verbose:
22652 + AuLabel(verbose);
22654 + case Opt_noverbose:
22655 + AuLabel(noverbose);
22666 + case Opt_wbr_create:
22667 + u.create = &opt->wbr_create;
22668 + AuDbg("create %d, %s\n", u.create->wbr_create,
22669 + au_optstr_wbr_create(u.create->wbr_create));
22670 + switch (u.create->wbr_create) {
22671 + case AuWbrCreate_MFSV:
22672 + case AuWbrCreate_PMFSV:
22673 + AuDbg("%d sec\n", u.create->mfs_second);
22675 + case AuWbrCreate_MFSRR:
22676 + AuDbg("%llu watermark\n",
22677 + u.create->mfsrr_watermark);
22679 + case AuWbrCreate_MFSRRV:
22680 + case AuWbrCreate_PMFSRRV:
22681 + AuDbg("%llu watermark, %d sec\n",
22682 + u.create->mfsrr_watermark,
22683 + u.create->mfs_second);
22687 + case Opt_wbr_copyup:
22688 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
22689 + au_optstr_wbr_copyup(opt->wbr_copyup));
22691 + case Opt_fhsm_sec:
22692 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
22702 +void au_opts_free(struct au_opts *opts)
22704 + struct au_opt *opt;
22707 + while (opt->type != Opt_tail) {
22708 + switch (opt->type) {
22711 + case Opt_prepend:
22712 + path_put(&opt->add.path);
22716 + path_put(&opt->del.h_path);
22720 + dput(opt->mod.h_root);
22723 + fput(opt->xino.file);
22730 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
22731 + aufs_bindex_t bindex)
22734 + struct au_opt_add *add = &opt->add;
22737 + add->bindex = bindex;
22738 + add->perm = AuBrPerm_RO;
22739 + add->pathname = opt_str;
22740 + p = strchr(opt_str, '=');
22744 + add->perm = br_perm_val(p);
22747 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
22750 + add->perm = AuBrPerm_RO;
22751 + if (au_test_fs_rr(add->path.dentry->d_sb))
22752 + add->perm = AuBrPerm_RR;
22753 + else if (!bindex && !(sb_flags & MS_RDONLY))
22754 + add->perm = AuBrPerm_RW;
22756 + opt->type = Opt_add;
22759 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
22766 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
22770 + del->pathname = args[0].from;
22771 + AuDbg("del path %s\n", del->pathname);
22773 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
22774 + if (unlikely(err))
22775 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
22780 +#if 0 /* reserved for future use */
22781 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
22782 + struct au_opt_del *del, substring_t args[])
22785 + struct dentry *root;
22788 + root = sb->s_root;
22789 + aufs_read_lock(root, AuLock_FLUSH);
22790 + if (bindex < 0 || au_sbend(sb) < bindex) {
22791 + pr_err("out of bounds, %d\n", bindex);
22796 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
22797 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
22800 + aufs_read_unlock(root, !AuLock_IR);
22805 +static int noinline_for_stack
22806 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
22809 + struct path path;
22813 + mod->path = args[0].from;
22814 + p = strchr(mod->path, '=');
22815 + if (unlikely(!p)) {
22816 + pr_err("no permssion %s\n", args[0].from);
22821 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
22822 + if (unlikely(err)) {
22823 + pr_err("lookup failed %s (%d)\n", mod->path, err);
22827 + mod->perm = br_perm_val(p);
22828 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
22829 + mod->h_root = dget(path.dentry);
22836 +#if 0 /* reserved for future use */
22837 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
22838 + struct au_opt_mod *mod, substring_t args[])
22841 + struct dentry *root;
22844 + root = sb->s_root;
22845 + aufs_read_lock(root, AuLock_FLUSH);
22846 + if (bindex < 0 || au_sbend(sb) < bindex) {
22847 + pr_err("out of bounds, %d\n", bindex);
22852 + mod->perm = br_perm_val(args[1].from);
22853 + AuDbg("mod path %s, perm 0x%x, %s\n",
22854 + mod->path, mod->perm, args[1].from);
22855 + mod->h_root = dget(au_h_dptr(root, bindex));
22858 + aufs_read_unlock(root, !AuLock_IR);
22863 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
22864 + substring_t args[])
22867 + struct file *file;
22869 + file = au_xino_create(sb, args[0].from, /*silent*/0);
22870 + err = PTR_ERR(file);
22871 + if (IS_ERR(file))
22875 + if (unlikely(file->f_dentry->d_sb == sb)) {
22877 + pr_err("%s must be outside\n", args[0].from);
22882 + xino->file = file;
22883 + xino->path = args[0].from;
22889 +static int noinline_for_stack
22890 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
22891 + struct au_opt_xino_itrunc *xino_itrunc,
22892 + substring_t args[])
22895 + aufs_bindex_t bend, bindex;
22896 + struct path path;
22897 + struct dentry *root;
22899 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
22900 + if (unlikely(err)) {
22901 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
22905 + xino_itrunc->bindex = -1;
22906 + root = sb->s_root;
22907 + aufs_read_lock(root, AuLock_FLUSH);
22908 + bend = au_sbend(sb);
22909 + for (bindex = 0; bindex <= bend; bindex++) {
22910 + if (au_h_dptr(root, bindex) == path.dentry) {
22911 + xino_itrunc->bindex = bindex;
22915 + aufs_read_unlock(root, !AuLock_IR);
22918 + if (unlikely(xino_itrunc->bindex < 0)) {
22919 + pr_err("no such branch %s\n", args[0].from);
22927 +/* called without aufs lock */
22928 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
22930 + int err, n, token;
22931 + aufs_bindex_t bindex;
22932 + unsigned char skipped;
22933 + struct dentry *root;
22934 + struct au_opt *opt, *opt_tail;
22936 + /* reduce the stack space */
22938 + struct au_opt_xino_itrunc *xino_itrunc;
22939 + struct au_opt_wbr_create *create;
22942 + substring_t args[MAX_OPT_ARGS];
22946 + a = kmalloc(sizeof(*a), GFP_NOFS);
22947 + if (unlikely(!a))
22950 + root = sb->s_root;
22954 + opt_tail = opt + opts->max_opt - 1;
22955 + opt->type = Opt_tail;
22956 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
22959 + token = match_token(opt_str, options, a->args);
22963 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
22965 + err = opt_add(opt, opt_str, opts->sb_flags,
22967 + if (unlikely(!err && ++opt > opt_tail)) {
22971 + opt->type = Opt_tail;
22976 + if (unlikely(match_int(&a->args[0], &n))) {
22977 + pr_err("bad integer in %s\n", opt_str);
22981 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
22984 + opt->type = token;
22987 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
22988 + /*dummy bindex*/1);
22990 + opt->type = token;
22992 + case Opt_prepend:
22993 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
22996 + opt->type = token;
22999 + err = au_opts_parse_del(&opt->del, a->args);
23001 + opt->type = token;
23003 +#if 0 /* reserved for future use */
23005 + del->pathname = "(indexed)";
23006 + if (unlikely(match_int(&args[0], &n))) {
23007 + pr_err("bad integer in %s\n", opt_str);
23010 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23012 + opt->type = token;
23016 + err = au_opts_parse_mod(&opt->mod, a->args);
23018 + opt->type = token;
23020 +#ifdef IMOD /* reserved for future use */
23022 + u.mod->path = "(indexed)";
23023 + if (unlikely(match_int(&a->args[0], &n))) {
23024 + pr_err("bad integer in %s\n", opt_str);
23027 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23029 + opt->type = token;
23033 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23035 + opt->type = token;
23038 + case Opt_trunc_xino_path:
23039 + err = au_opts_parse_xino_itrunc_path
23040 + (sb, &opt->xino_itrunc, a->args);
23042 + opt->type = token;
23045 + case Opt_itrunc_xino:
23046 + u.xino_itrunc = &opt->xino_itrunc;
23047 + if (unlikely(match_int(&a->args[0], &n))) {
23048 + pr_err("bad integer in %s\n", opt_str);
23051 + u.xino_itrunc->bindex = n;
23052 + aufs_read_lock(root, AuLock_FLUSH);
23053 + if (n < 0 || au_sbend(sb) < n) {
23054 + pr_err("out of bounds, %d\n", n);
23055 + aufs_read_unlock(root, !AuLock_IR);
23058 + aufs_read_unlock(root, !AuLock_IR);
23060 + opt->type = token;
23064 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23067 + opt->type = token;
23070 + case Opt_rdcache:
23071 + if (unlikely(match_int(&a->args[0], &n))) {
23072 + pr_err("bad integer in %s\n", opt_str);
23075 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23076 + pr_err("rdcache must be smaller than %d\n",
23077 + AUFS_RDCACHE_MAX);
23080 + opt->rdcache = n;
23082 + opt->type = token;
23085 + if (unlikely(match_int(&a->args[0], &n)
23087 + || n > KMALLOC_MAX_SIZE)) {
23088 + pr_err("bad integer in %s\n", opt_str);
23091 + if (unlikely(n && n < NAME_MAX)) {
23092 + pr_err("rdblk must be larger than %d\n",
23098 + opt->type = token;
23101 + if (unlikely(match_int(&a->args[0], &n)
23103 + || n * sizeof(struct hlist_head)
23104 + > KMALLOC_MAX_SIZE)) {
23105 + pr_err("bad integer in %s\n", opt_str);
23110 + opt->type = token;
23113 + case Opt_trunc_xino:
23114 + case Opt_notrunc_xino:
23116 + case Opt_trunc_xib:
23117 + case Opt_notrunc_xib:
23120 + case Opt_dirperm1:
23121 + case Opt_nodirperm1:
23123 + case Opt_noplink:
23124 + case Opt_list_plink:
23127 + case Opt_diropq_a:
23128 + case Opt_diropq_w:
23129 + case Opt_warn_perm:
23130 + case Opt_nowarn_perm:
23132 + case Opt_norefrof:
23133 + case Opt_verbose:
23134 + case Opt_noverbose:
23138 + case Opt_rdblk_def:
23139 + case Opt_rdhash_def:
23141 + opt->type = token;
23145 + opt->udba = udba_val(a->args[0].from);
23146 + if (opt->udba >= 0) {
23148 + opt->type = token;
23150 + pr_err("wrong value, %s\n", opt_str);
23153 + case Opt_wbr_create:
23154 + u.create = &opt->wbr_create;
23155 + u.create->wbr_create
23156 + = au_wbr_create_val(a->args[0].from, u.create);
23157 + if (u.create->wbr_create >= 0) {
23159 + opt->type = token;
23161 + pr_err("wrong value, %s\n", opt_str);
23163 + case Opt_wbr_copyup:
23164 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
23165 + if (opt->wbr_copyup >= 0) {
23167 + opt->type = token;
23169 + pr_err("wrong value, %s\n", opt_str);
23172 + case Opt_fhsm_sec:
23173 + if (unlikely(match_int(&a->args[0], &n)
23175 + pr_err("bad integer in %s\n", opt_str);
23178 + if (sysaufs_brs) {
23179 + opt->fhsm_second = n;
23180 + opt->type = token;
23182 + pr_warn("ignored %s\n", opt_str);
23187 + pr_warn("ignored %s\n", opt_str);
23189 + case Opt_ignore_silent:
23194 + pr_err("unknown option %s\n", opt_str);
23198 + if (!err && !skipped) {
23199 + if (unlikely(++opt > opt_tail)) {
23202 + opt->type = Opt_tail;
23205 + opt->type = Opt_tail;
23211 + if (unlikely(err))
23212 + au_opts_free(opts);
23218 +static int au_opt_wbr_create(struct super_block *sb,
23219 + struct au_opt_wbr_create *create)
23222 + struct au_sbinfo *sbinfo;
23224 + SiMustWriteLock(sb);
23226 + err = 1; /* handled */
23227 + sbinfo = au_sbi(sb);
23228 + if (sbinfo->si_wbr_create_ops->fin) {
23229 + err = sbinfo->si_wbr_create_ops->fin(sb);
23234 + sbinfo->si_wbr_create = create->wbr_create;
23235 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
23236 + switch (create->wbr_create) {
23237 + case AuWbrCreate_MFSRRV:
23238 + case AuWbrCreate_MFSRR:
23239 + case AuWbrCreate_PMFSRR:
23240 + case AuWbrCreate_PMFSRRV:
23241 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
23243 + case AuWbrCreate_MFS:
23244 + case AuWbrCreate_MFSV:
23245 + case AuWbrCreate_PMFS:
23246 + case AuWbrCreate_PMFSV:
23247 + sbinfo->si_wbr_mfs.mfs_expire
23248 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
23252 + if (sbinfo->si_wbr_create_ops->init)
23253 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
23260 + * plus: processed without an error
23261 + * zero: unprocessed
23263 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
23264 + struct au_opts *opts)
23267 + struct au_sbinfo *sbinfo;
23269 + SiMustWriteLock(sb);
23271 + err = 1; /* handled */
23272 + sbinfo = au_sbi(sb);
23273 + switch (opt->type) {
23275 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23276 + sbinfo->si_mntflags |= opt->udba;
23277 + opts->given_udba |= opt->udba;
23281 + au_opt_set(sbinfo->si_mntflags, PLINK);
23283 + case Opt_noplink:
23284 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23285 + au_plink_put(sb, /*verbose*/1);
23286 + au_opt_clr(sbinfo->si_mntflags, PLINK);
23288 + case Opt_list_plink:
23289 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23290 + au_plink_list(sb);
23294 + au_opt_set(sbinfo->si_mntflags, DIO);
23295 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23298 + au_opt_clr(sbinfo->si_mntflags, DIO);
23299 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23302 + case Opt_fhsm_sec:
23303 + au_fhsm_set(sbinfo, opt->fhsm_second);
23306 + case Opt_diropq_a:
23307 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23309 + case Opt_diropq_w:
23310 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23313 + case Opt_warn_perm:
23314 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
23316 + case Opt_nowarn_perm:
23317 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
23321 + au_opt_set(sbinfo->si_mntflags, REFROF);
23323 + case Opt_norefrof:
23324 + au_opt_clr(sbinfo->si_mntflags, REFROF);
23327 + case Opt_verbose:
23328 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
23330 + case Opt_noverbose:
23331 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
23335 + au_opt_set(sbinfo->si_mntflags, SUM);
23338 + au_opt_clr(sbinfo->si_mntflags, SUM);
23339 + au_opt_set(sbinfo->si_mntflags, SUM_W);
23341 + au_opt_clr(sbinfo->si_mntflags, SUM);
23342 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
23345 + case Opt_wbr_create:
23346 + err = au_opt_wbr_create(sb, &opt->wbr_create);
23348 + case Opt_wbr_copyup:
23349 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
23350 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
23354 + sbinfo->si_dirwh = opt->dirwh;
23357 + case Opt_rdcache:
23358 + sbinfo->si_rdcache
23359 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
23362 + sbinfo->si_rdblk = opt->rdblk;
23364 + case Opt_rdblk_def:
23365 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
23368 + sbinfo->si_rdhash = opt->rdhash;
23370 + case Opt_rdhash_def:
23371 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
23375 + au_opt_set(sbinfo->si_mntflags, SHWH);
23378 + au_opt_clr(sbinfo->si_mntflags, SHWH);
23381 + case Opt_dirperm1:
23382 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
23384 + case Opt_nodirperm1:
23385 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
23388 + case Opt_trunc_xino:
23389 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
23391 + case Opt_notrunc_xino:
23392 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
23395 + case Opt_trunc_xino_path:
23396 + case Opt_itrunc_xino:
23397 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
23402 + case Opt_trunc_xib:
23403 + au_fset_opts(opts->flags, TRUNC_XIB);
23405 + case Opt_notrunc_xib:
23406 + au_fclr_opts(opts->flags, TRUNC_XIB);
23418 + * returns tri-state.
23419 + * plus: processed without an error
23420 + * zero: unprocessed
23423 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
23424 + struct au_opts *opts)
23426 + int err, do_refresh;
23429 + switch (opt->type) {
23431 + opt->add.bindex = au_sbend(sb) + 1;
23432 + if (opt->add.bindex < 0)
23433 + opt->add.bindex = 0;
23435 + case Opt_prepend:
23436 + opt->add.bindex = 0;
23437 + add: /* indented label */
23439 + err = au_br_add(sb, &opt->add,
23440 + au_ftest_opts(opts->flags, REMOUNT));
23443 + au_fset_opts(opts->flags, REFRESH);
23449 + err = au_br_del(sb, &opt->del,
23450 + au_ftest_opts(opts->flags, REMOUNT));
23453 + au_fset_opts(opts->flags, TRUNC_XIB);
23454 + au_fset_opts(opts->flags, REFRESH);
23460 + err = au_br_mod(sb, &opt->mod,
23461 + au_ftest_opts(opts->flags, REMOUNT),
23466 + au_fset_opts(opts->flags, REFRESH);
23474 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
23475 + struct au_opt_xino **opt_xino,
23476 + struct au_opts *opts)
23479 + aufs_bindex_t bend, bindex;
23480 + struct dentry *root, *parent, *h_root;
23483 + switch (opt->type) {
23485 + err = au_xino_set(sb, &opt->xino,
23486 + !!au_ftest_opts(opts->flags, REMOUNT));
23487 + if (unlikely(err))
23490 + *opt_xino = &opt->xino;
23491 + au_xino_brid_set(sb, -1);
23493 + /* safe d_parent access */
23494 + parent = opt->xino.file->f_dentry->d_parent;
23495 + root = sb->s_root;
23496 + bend = au_sbend(sb);
23497 + for (bindex = 0; bindex <= bend; bindex++) {
23498 + h_root = au_h_dptr(root, bindex);
23499 + if (h_root == parent) {
23500 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
23508 + au_xino_brid_set(sb, -1);
23509 + *opt_xino = (void *)-1;
23516 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
23517 + unsigned int pending)
23520 + aufs_bindex_t bindex, bend;
23521 + unsigned char do_plink, skip, do_free;
23522 + struct au_branch *br;
23523 + struct au_wbr *wbr;
23524 + struct dentry *root;
23525 + struct inode *dir, *h_dir;
23526 + struct au_sbinfo *sbinfo;
23527 + struct au_hinode *hdir;
23529 + SiMustAnyLock(sb);
23531 + sbinfo = au_sbi(sb);
23532 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
23534 + if (!(sb_flags & MS_RDONLY)) {
23535 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
23536 + pr_warn("first branch should be rw\n");
23537 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
23538 + pr_warn("shwh should be used with ro\n");
23541 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
23542 + && !au_opt_test(sbinfo->si_mntflags, XINO))
23543 + pr_warn("udba=*notify requires xino\n");
23545 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
23546 + pr_warn("dirperm1 breaks the protection"
23547 + " by the permission bits on the lower branch\n");
23551 + root = sb->s_root;
23552 + dir = root->d_inode;
23553 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
23554 + bend = au_sbend(sb);
23555 + for (bindex = 0; !err && bindex <= bend; bindex++) {
23557 + h_dir = au_h_iptr(dir, bindex);
23558 + br = au_sbr(sb, bindex);
23561 + wbr = br->br_wbr;
23563 + wbr_wh_read_lock(wbr);
23565 + if (!au_br_writable(br->br_perm)) {
23568 + || (!wbr->wbr_whbase
23569 + && !wbr->wbr_plink
23570 + && !wbr->wbr_orph));
23571 + } else if (!au_br_wh_linkable(br->br_perm)) {
23572 + /* skip = (!br->br_whbase && !br->br_orph); */
23573 + skip = (!wbr || !wbr->wbr_whbase);
23574 + if (skip && wbr) {
23576 + skip = !!wbr->wbr_plink;
23578 + skip = !wbr->wbr_plink;
23581 + /* skip = (br->br_whbase && br->br_ohph); */
23582 + skip = (wbr && wbr->wbr_whbase);
23585 + skip = !!wbr->wbr_plink;
23587 + skip = !wbr->wbr_plink;
23591 + wbr_wh_read_unlock(wbr);
23593 + if (au_br_fhsm(br->br_perm)) {
23595 + AuDebugOn(!br->br_fhsm);
23601 + hdir = au_hi(dir, bindex);
23602 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
23604 + wbr_wh_write_lock(wbr);
23605 + err = au_wh_init(br, sb);
23607 + wbr_wh_write_unlock(wbr);
23608 + au_hn_imtx_unlock(hdir);
23610 + if (!err && do_free) {
23612 + br->br_wbr = NULL;
23617 + au_fset_si(sbinfo, FHSM);
23619 + au_fclr_si(sbinfo, FHSM);
23624 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
23627 + unsigned int tmp;
23628 + aufs_bindex_t bindex, bend;
23629 + struct au_opt *opt;
23630 + struct au_opt_xino *opt_xino, xino;
23631 + struct au_sbinfo *sbinfo;
23632 + struct au_branch *br;
23633 + struct inode *dir;
23635 + SiMustWriteLock(sb);
23640 + while (err >= 0 && opt->type != Opt_tail)
23641 + err = au_opt_simple(sb, opt++, opts);
23644 + else if (unlikely(err < 0))
23647 + /* disable xino and udba temporary */
23648 + sbinfo = au_sbi(sb);
23649 + tmp = sbinfo->si_mntflags;
23650 + au_opt_clr(sbinfo->si_mntflags, XINO);
23651 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
23654 + while (err >= 0 && opt->type != Opt_tail)
23655 + err = au_opt_br(sb, opt++, opts);
23658 + else if (unlikely(err < 0))
23661 + bend = au_sbend(sb);
23662 + if (unlikely(bend < 0)) {
23664 + pr_err("no branches\n");
23668 + if (au_opt_test(tmp, XINO))
23669 + au_opt_set(sbinfo->si_mntflags, XINO);
23671 + while (!err && opt->type != Opt_tail)
23672 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
23673 + if (unlikely(err))
23676 + err = au_opts_verify(sb, sb->s_flags, tmp);
23677 + if (unlikely(err))
23680 + /* restore xino */
23681 + if (au_opt_test(tmp, XINO) && !opt_xino) {
23682 + xino.file = au_xino_def(sb);
23683 + err = PTR_ERR(xino.file);
23684 + if (IS_ERR(xino.file))
23687 + err = au_xino_set(sb, &xino, /*remount*/0);
23689 + if (unlikely(err))
23693 + /* restore udba */
23694 + tmp &= AuOptMask_UDBA;
23695 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23696 + sbinfo->si_mntflags |= tmp;
23697 + bend = au_sbend(sb);
23698 + for (bindex = 0; bindex <= bend; bindex++) {
23699 + br = au_sbr(sb, bindex);
23700 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
23701 + if (unlikely(err))
23702 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
23704 + /* go on even if err */
23706 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
23707 + dir = sb->s_root->d_inode;
23708 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
23715 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
23718 + struct inode *dir;
23719 + struct au_opt_xino *opt_xino;
23720 + struct au_opt *opt;
23721 + struct au_sbinfo *sbinfo;
23723 + SiMustWriteLock(sb);
23725 + dir = sb->s_root->d_inode;
23726 + sbinfo = au_sbi(sb);
23730 + while (err >= 0 && opt->type != Opt_tail) {
23731 + err = au_opt_simple(sb, opt, opts);
23733 + err = au_opt_br(sb, opt, opts);
23735 + err = au_opt_xino(sb, opt, &opt_xino, opts);
23741 + /* go on even err */
23743 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
23744 + if (unlikely(rerr && !err))
23747 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
23748 + rerr = au_xib_trunc(sb);
23749 + if (unlikely(rerr && !err))
23753 + /* will be handled by the caller */
23754 + if (!au_ftest_opts(opts->flags, REFRESH)
23755 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
23756 + au_fset_opts(opts->flags, REFRESH);
23758 + AuDbg("status 0x%x\n", opts->flags);
23762 +/* ---------------------------------------------------------------------- */
23764 +unsigned int au_opt_udba(struct super_block *sb)
23766 + return au_mntflags(sb) & AuOptMask_UDBA;
23768 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
23769 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
23770 +++ linux/fs/aufs/opts.h 2014-08-14 10:15:45.128609525 +0200
23773 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23775 + * This program, aufs is free software; you can redistribute it and/or modify
23776 + * it under the terms of the GNU General Public License as published by
23777 + * the Free Software Foundation; either version 2 of the License, or
23778 + * (at your option) any later version.
23780 + * This program is distributed in the hope that it will be useful,
23781 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23782 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23783 + * GNU General Public License for more details.
23785 + * You should have received a copy of the GNU General Public License
23786 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23790 + * mount options/flags
23793 +#ifndef __AUFS_OPTS_H__
23794 +#define __AUFS_OPTS_H__
23798 +#include <linux/path.h>
23799 +#include "branch.h"
23802 +struct super_block;
23804 +/* ---------------------------------------------------------------------- */
23807 +#define AuOpt_XINO 1 /* external inode number bitmap
23808 + and translation table */
23809 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
23810 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
23811 +#define AuOpt_UDBA_REVAL (1 << 3)
23812 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
23813 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
23814 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
23815 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
23817 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
23818 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
23819 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
23820 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
23821 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
23822 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
23823 +#define AuOpt_DIO (1 << 14) /* direct io */
23825 +#ifndef CONFIG_AUFS_HNOTIFY
23826 +#undef AuOpt_UDBA_HNOTIFY
23827 +#define AuOpt_UDBA_HNOTIFY 0
23829 +#ifndef CONFIG_AUFS_SHWH
23831 +#define AuOpt_SHWH 0
23834 +#define AuOpt_Def (AuOpt_XINO \
23835 + | AuOpt_UDBA_REVAL \
23837 + /* | AuOpt_DIRPERM1 */ \
23838 + | AuOpt_WARN_PERM)
23839 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
23840 + | AuOpt_UDBA_REVAL \
23841 + | AuOpt_UDBA_HNOTIFY)
23843 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
23844 +#define au_opt_set(flags, name) do { \
23845 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
23846 + ((flags) |= AuOpt_##name); \
23848 +#define au_opt_set_udba(flags, name) do { \
23849 + (flags) &= ~AuOptMask_UDBA; \
23850 + ((flags) |= AuOpt_##name); \
23852 +#define au_opt_clr(flags, name) do { \
23853 + ((flags) &= ~AuOpt_##name); \
23856 +static inline unsigned int au_opts_plink(unsigned int mntflags)
23858 +#ifdef CONFIG_PROC_FS
23861 + return mntflags & ~AuOpt_PLINK;
23865 +/* ---------------------------------------------------------------------- */
23867 +/* policies to select one among multiple writable branches */
23869 + AuWbrCreate_TDP, /* top down parent */
23870 + AuWbrCreate_RR, /* round robin */
23871 + AuWbrCreate_MFS, /* most free space */
23872 + AuWbrCreate_MFSV, /* mfs with seconds */
23873 + AuWbrCreate_MFSRR, /* mfs then rr */
23874 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
23875 + AuWbrCreate_PMFS, /* parent and mfs */
23876 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
23877 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
23878 + AuWbrCreate_PMFSRRV, /* plus seconds */
23880 + AuWbrCreate_Def = AuWbrCreate_TDP
23884 + AuWbrCopyup_TDP, /* top down parent */
23885 + AuWbrCopyup_BUP, /* bottom up parent */
23886 + AuWbrCopyup_BU, /* bottom up */
23888 + AuWbrCopyup_Def = AuWbrCopyup_TDP
23891 +/* ---------------------------------------------------------------------- */
23893 +struct au_opt_add {
23894 + aufs_bindex_t bindex;
23897 + struct path path;
23900 +struct au_opt_del {
23902 + struct path h_path;
23905 +struct au_opt_mod {
23908 + struct dentry *h_root;
23911 +struct au_opt_xino {
23913 + struct file *file;
23916 +struct au_opt_xino_itrunc {
23917 + aufs_bindex_t bindex;
23920 +struct au_opt_wbr_create {
23923 + unsigned long long mfsrr_watermark;
23929 + struct au_opt_xino xino;
23930 + struct au_opt_xino_itrunc xino_itrunc;
23931 + struct au_opt_add add;
23932 + struct au_opt_del del;
23933 + struct au_opt_mod mod;
23936 + unsigned int rdblk;
23937 + unsigned int rdhash;
23939 + struct au_opt_wbr_create wbr_create;
23941 + unsigned int fhsm_second;
23946 +#define AuOpts_REMOUNT 1
23947 +#define AuOpts_REFRESH (1 << 1)
23948 +#define AuOpts_TRUNC_XIB (1 << 2)
23949 +#define AuOpts_REFRESH_DYAOP (1 << 3)
23950 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
23951 +#define au_fset_opts(flags, name) \
23952 + do { (flags) |= AuOpts_##name; } while (0)
23953 +#define au_fclr_opts(flags, name) \
23954 + do { (flags) &= ~AuOpts_##name; } while (0)
23957 + struct au_opt *opt;
23960 + unsigned int given_udba;
23961 + unsigned int flags;
23962 + unsigned long sb_flags;
23965 +/* ---------------------------------------------------------------------- */
23967 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
23968 +const char *au_optstr_udba(int udba);
23969 +const char *au_optstr_wbr_copyup(int wbr_copyup);
23970 +const char *au_optstr_wbr_create(int wbr_create);
23972 +void au_opts_free(struct au_opts *opts);
23973 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
23974 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
23975 + unsigned int pending);
23976 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
23977 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
23979 +unsigned int au_opt_udba(struct super_block *sb);
23981 +/* ---------------------------------------------------------------------- */
23983 +#endif /* __KERNEL__ */
23984 +#endif /* __AUFS_OPTS_H__ */
23985 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
23986 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
23987 +++ linux/fs/aufs/plink.c 2014-01-30 21:10:02.857481956 +0100
23990 + * Copyright (C) 2005-2014 Junjiro R. Okajima
23992 + * This program, aufs is free software; you can redistribute it and/or modify
23993 + * it under the terms of the GNU General Public License as published by
23994 + * the Free Software Foundation; either version 2 of the License, or
23995 + * (at your option) any later version.
23997 + * This program is distributed in the hope that it will be useful,
23998 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23999 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24000 + * GNU General Public License for more details.
24002 + * You should have received a copy of the GNU General Public License
24003 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24013 + * the pseudo-link maintenance mode.
24014 + * during a user process maintains the pseudo-links,
24015 + * prohibit adding a new plink and branch manipulation.
24019 + * For entry functions which will handle plink, and i_mutex is already held
24021 + * They cannot wait and should return an error at once.
24022 + * Callers has to check the error.
24024 + * For entry functions which will handle plink, but i_mutex is not held
24026 + * They can wait the plink maintenance mode to finish.
24028 + * They behave like F_SETLK and F_SETLKW.
24029 + * If the caller never handle plink, then both flags are unnecessary.
24032 +int au_plink_maint(struct super_block *sb, int flags)
24036 + struct au_sbinfo *sbi;
24038 + SiMustAnyLock(sb);
24041 + if (!au_opt_test(au_mntflags(sb), PLINK))
24044 + sbi = au_sbi(sb);
24045 + pid = sbi->si_plink_maint_pid;
24046 + if (!pid || pid == current->pid)
24049 + /* todo: it highly depends upon /sbin/mount.aufs */
24051 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
24052 + rcu_read_unlock();
24056 + if (au_ftest_lock(flags, NOPLMW)) {
24057 + /* if there is no i_mutex lock in VFS, we don't need to wait */
24058 + /* AuDebugOn(!lockdep_depth(current)); */
24059 + while (sbi->si_plink_maint_pid) {
24060 + si_read_unlock(sb);
24061 + /* gave up wake_up_bit() */
24062 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
24064 + if (au_ftest_lock(flags, FLUSH))
24065 + au_nwt_flush(&sbi->si_nowait);
24066 + si_noflush_read_lock(sb);
24068 + } else if (au_ftest_lock(flags, NOPLM)) {
24069 + AuDbg("ppid %d, pid %d\n", ppid, pid);
24077 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
24079 + spin_lock(&sbinfo->si_plink_maint_lock);
24080 + sbinfo->si_plink_maint_pid = 0;
24081 + spin_unlock(&sbinfo->si_plink_maint_lock);
24082 + wake_up_all(&sbinfo->si_plink_wq);
24085 +int au_plink_maint_enter(struct super_block *sb)
24088 + struct au_sbinfo *sbinfo;
24091 + sbinfo = au_sbi(sb);
24092 + /* make sure i am the only one in this fs */
24093 + si_write_lock(sb, AuLock_FLUSH);
24094 + if (au_opt_test(au_mntflags(sb), PLINK)) {
24095 + spin_lock(&sbinfo->si_plink_maint_lock);
24096 + if (!sbinfo->si_plink_maint_pid)
24097 + sbinfo->si_plink_maint_pid = current->pid;
24100 + spin_unlock(&sbinfo->si_plink_maint_lock);
24102 + si_write_unlock(sb);
24107 +/* ---------------------------------------------------------------------- */
24109 +#ifdef CONFIG_AUFS_DEBUG
24110 +void au_plink_list(struct super_block *sb)
24113 + struct au_sbinfo *sbinfo;
24114 + struct hlist_head *plink_hlist;
24115 + struct pseudo_link *plink;
24117 + SiMustAnyLock(sb);
24119 + sbinfo = au_sbi(sb);
24120 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24121 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24123 + for (i = 0; i < AuPlink_NHASH; i++) {
24124 + plink_hlist = &sbinfo->si_plink[i].head;
24126 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24127 + AuDbg("%lu\n", plink->inode->i_ino);
24128 + rcu_read_unlock();
24133 +/* is the inode pseudo-linked? */
24134 +int au_plink_test(struct inode *inode)
24137 + struct au_sbinfo *sbinfo;
24138 + struct hlist_head *plink_hlist;
24139 + struct pseudo_link *plink;
24141 + sbinfo = au_sbi(inode->i_sb);
24142 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24143 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
24144 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24147 + i = au_plink_hash(inode->i_ino);
24148 + plink_hlist = &sbinfo->si_plink[i].head;
24150 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24151 + if (plink->inode == inode) {
24155 + rcu_read_unlock();
24159 +/* ---------------------------------------------------------------------- */
24162 + * generate a name for plink.
24163 + * the file will be stored under AUFS_WH_PLINKDIR.
24165 +/* 20 is max digits length of ulong 64 */
24166 +#define PLINK_NAME_LEN ((20 + 1) * 2)
24168 +static int plink_name(char *name, int len, struct inode *inode,
24169 + aufs_bindex_t bindex)
24172 + struct inode *h_inode;
24174 + h_inode = au_h_iptr(inode, bindex);
24175 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
24179 +struct au_do_plink_lkup_args {
24180 + struct dentry **errp;
24181 + struct qstr *tgtname;
24182 + struct dentry *h_parent;
24183 + struct au_branch *br;
24186 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
24187 + struct dentry *h_parent,
24188 + struct au_branch *br)
24190 + struct dentry *h_dentry;
24191 + struct mutex *h_mtx;
24193 + h_mtx = &h_parent->d_inode->i_mutex;
24194 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
24195 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
24196 + mutex_unlock(h_mtx);
24200 +static void au_call_do_plink_lkup(void *args)
24202 + struct au_do_plink_lkup_args *a = args;
24203 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
24206 +/* lookup the plink-ed @inode under the branch at @bindex */
24207 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
24209 + struct dentry *h_dentry, *h_parent;
24210 + struct au_branch *br;
24211 + struct inode *h_dir;
24213 + char a[PLINK_NAME_LEN];
24214 + struct qstr tgtname = QSTR_INIT(a, 0);
24216 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24218 + br = au_sbr(inode->i_sb, bindex);
24219 + h_parent = br->br_wbr->wbr_plink;
24220 + h_dir = h_parent->d_inode;
24221 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24223 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24224 + struct au_do_plink_lkup_args args = {
24225 + .errp = &h_dentry,
24226 + .tgtname = &tgtname,
24227 + .h_parent = h_parent,
24231 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
24232 + if (unlikely(wkq_err))
24233 + h_dentry = ERR_PTR(wkq_err);
24235 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
24240 +/* create a pseudo-link */
24241 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
24242 + struct dentry *h_dentry, struct au_branch *br)
24245 + struct path h_path = {
24246 + .mnt = au_br_mnt(br)
24248 + struct inode *h_dir, *delegated;
24250 + h_dir = h_parent->d_inode;
24251 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
24253 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
24254 + err = PTR_ERR(h_path.dentry);
24255 + if (IS_ERR(h_path.dentry))
24259 + /* wh.plink dir is not monitored */
24260 + /* todo: is it really safe? */
24261 + if (h_path.dentry->d_inode
24262 + && h_path.dentry->d_inode != h_dentry->d_inode) {
24263 + delegated = NULL;
24264 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
24265 + if (unlikely(err == -EWOULDBLOCK)) {
24266 + pr_warn("cannot retry for NFSv4 delegation"
24267 + " for an internal unlink\n");
24270 + dput(h_path.dentry);
24271 + h_path.dentry = NULL;
24275 + if (!err && !h_path.dentry->d_inode) {
24276 + delegated = NULL;
24277 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
24278 + if (unlikely(err == -EWOULDBLOCK)) {
24279 + pr_warn("cannot retry for NFSv4 delegation"
24280 + " for an internal link\n");
24284 + dput(h_path.dentry);
24287 + mutex_unlock(&h_dir->i_mutex);
24291 +struct do_whplink_args {
24293 + struct qstr *tgt;
24294 + struct dentry *h_parent;
24295 + struct dentry *h_dentry;
24296 + struct au_branch *br;
24299 +static void call_do_whplink(void *args)
24301 + struct do_whplink_args *a = args;
24302 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
24305 +static int whplink(struct dentry *h_dentry, struct inode *inode,
24306 + aufs_bindex_t bindex, struct au_branch *br)
24308 + int err, wkq_err;
24309 + struct au_wbr *wbr;
24310 + struct dentry *h_parent;
24311 + struct inode *h_dir;
24312 + char a[PLINK_NAME_LEN];
24313 + struct qstr tgtname = QSTR_INIT(a, 0);
24315 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
24316 + h_parent = wbr->wbr_plink;
24317 + h_dir = h_parent->d_inode;
24318 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24320 + /* always superio. */
24321 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24322 + struct do_whplink_args args = {
24325 + .h_parent = h_parent,
24326 + .h_dentry = h_dentry,
24329 + wkq_err = au_wkq_wait(call_do_whplink, &args);
24330 + if (unlikely(wkq_err))
24333 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
24338 +/* free a single plink */
24339 +static void do_put_plink(struct pseudo_link *plink, int do_del)
24342 + hlist_del(&plink->hlist);
24343 + iput(plink->inode);
24347 +static void do_put_plink_rcu(struct rcu_head *rcu)
24349 + struct pseudo_link *plink;
24351 + plink = container_of(rcu, struct pseudo_link, rcu);
24352 + iput(plink->inode);
24357 + * create a new pseudo-link for @h_dentry on @bindex.
24358 + * the linked inode is held in aufs @inode.
24360 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
24361 + struct dentry *h_dentry)
24363 + struct super_block *sb;
24364 + struct au_sbinfo *sbinfo;
24365 + struct hlist_head *plink_hlist;
24366 + struct pseudo_link *plink, *tmp;
24367 + struct au_sphlhead *sphl;
24368 + int found, err, cnt, i;
24370 + sb = inode->i_sb;
24371 + sbinfo = au_sbi(sb);
24372 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24373 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24375 + found = au_plink_test(inode);
24379 + i = au_plink_hash(inode->i_ino);
24380 + sphl = sbinfo->si_plink + i;
24381 + plink_hlist = &sphl->head;
24382 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
24384 + tmp->inode = au_igrab(inode);
24390 + spin_lock(&sphl->spin);
24391 + hlist_for_each_entry(plink, plink_hlist, hlist) {
24392 + if (plink->inode == inode) {
24398 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
24399 + spin_unlock(&sphl->spin);
24401 + cnt = au_sphl_count(sphl);
24402 +#define msg "unexpectedly unblanced or too many pseudo-links"
24403 + if (cnt > AUFS_PLINK_WARN)
24404 + AuWarn1(msg ", %d\n", cnt);
24406 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
24408 + do_put_plink(tmp, 0);
24413 + if (unlikely(err)) {
24414 + pr_warn("err %d, damaged pseudo link.\n", err);
24416 + au_sphl_del_rcu(&tmp->hlist, sphl);
24417 + call_rcu(&tmp->rcu, do_put_plink_rcu);
24422 +/* free all plinks */
24423 +void au_plink_put(struct super_block *sb, int verbose)
24426 + struct au_sbinfo *sbinfo;
24427 + struct hlist_head *plink_hlist;
24428 + struct hlist_node *tmp;
24429 + struct pseudo_link *plink;
24431 + SiMustWriteLock(sb);
24433 + sbinfo = au_sbi(sb);
24434 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24435 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24437 + /* no spin_lock since sbinfo is write-locked */
24439 + for (i = 0; i < AuPlink_NHASH; i++) {
24440 + plink_hlist = &sbinfo->si_plink[i].head;
24441 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
24442 + pr_warn("pseudo-link is not flushed");
24445 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
24446 + do_put_plink(plink, 0);
24447 + INIT_HLIST_HEAD(plink_hlist);
24451 +void au_plink_clean(struct super_block *sb, int verbose)
24453 + struct dentry *root;
24455 + root = sb->s_root;
24456 + aufs_write_lock(root);
24457 + if (au_opt_test(au_mntflags(sb), PLINK))
24458 + au_plink_put(sb, verbose);
24459 + aufs_write_unlock(root);
24462 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
24465 + aufs_bindex_t bstart, bend, bindex;
24468 + bstart = au_ibstart(inode);
24469 + bend = au_ibend(inode);
24470 + if (bstart >= 0) {
24471 + for (bindex = bstart; bindex <= bend; bindex++) {
24472 + if (!au_h_iptr(inode, bindex)
24473 + || au_ii_br_id(inode, bindex) != br_id)
24475 + au_set_h_iptr(inode, bindex, NULL, 0);
24480 + for (bindex = bstart; bindex <= bend; bindex++)
24481 + if (au_h_iptr(inode, bindex)) {
24491 +/* free the plinks on a branch specified by @br_id */
24492 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
24494 + struct au_sbinfo *sbinfo;
24495 + struct hlist_head *plink_hlist;
24496 + struct hlist_node *tmp;
24497 + struct pseudo_link *plink;
24498 + struct inode *inode;
24501 + SiMustWriteLock(sb);
24503 + sbinfo = au_sbi(sb);
24504 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24505 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24507 + /* no spin_lock since sbinfo is write-locked */
24508 + for (i = 0; i < AuPlink_NHASH; i++) {
24509 + plink_hlist = &sbinfo->si_plink[i].head;
24510 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
24511 + inode = au_igrab(plink->inode);
24512 + ii_write_lock_child(inode);
24513 + do_put = au_plink_do_half_refresh(inode, br_id);
24515 + do_put_plink(plink, 1);
24516 + ii_write_unlock(inode);
24521 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
24522 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
24523 +++ linux/fs/aufs/poll.c 2014-01-30 21:10:02.857481956 +0100
24526 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24528 + * This program, aufs is free software; you can redistribute it and/or modify
24529 + * it under the terms of the GNU General Public License as published by
24530 + * the Free Software Foundation; either version 2 of the License, or
24531 + * (at your option) any later version.
24533 + * This program is distributed in the hope that it will be useful,
24534 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24535 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24536 + * GNU General Public License for more details.
24538 + * You should have received a copy of the GNU General Public License
24539 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24544 + * There is only one filesystem which implements ->poll operation, currently.
24549 +unsigned int aufs_poll(struct file *file, poll_table *wait)
24551 + unsigned int mask;
24553 + struct file *h_file;
24554 + struct dentry *dentry;
24555 + struct super_block *sb;
24557 + /* We should pretend an error happened. */
24558 + mask = POLLERR /* | POLLIN | POLLOUT */;
24559 + dentry = file->f_dentry;
24560 + sb = dentry->d_sb;
24561 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
24562 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
24563 + if (unlikely(err))
24566 + /* it is not an error if h_file has no operation */
24567 + mask = DEFAULT_POLLMASK;
24568 + h_file = au_hf_top(file);
24569 + if (h_file->f_op->poll)
24570 + mask = h_file->f_op->poll(h_file, wait);
24572 + di_read_unlock(dentry, AuLock_IR);
24573 + fi_read_unlock(file);
24576 + si_read_unlock(sb);
24577 + AuTraceErr((int)mask);
24580 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
24581 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
24582 +++ linux/fs/aufs/procfs.c 2014-01-30 21:10:02.857481956 +0100
24585 + * Copyright (C) 2010-2014 Junjiro R. Okajima
24587 + * This program, aufs is free software; you can redistribute it and/or modify
24588 + * it under the terms of the GNU General Public License as published by
24589 + * the Free Software Foundation; either version 2 of the License, or
24590 + * (at your option) any later version.
24592 + * This program is distributed in the hope that it will be useful,
24593 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24594 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24595 + * GNU General Public License for more details.
24597 + * You should have received a copy of the GNU General Public License
24598 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24602 + * procfs interfaces
24605 +#include <linux/proc_fs.h>
24608 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
24610 + struct au_sbinfo *sbinfo;
24612 + sbinfo = file->private_data;
24614 + au_plink_maint_leave(sbinfo);
24615 + kobject_put(&sbinfo->si_kobj);
24621 +static void au_procfs_plm_write_clean(struct file *file)
24623 + struct au_sbinfo *sbinfo;
24625 + sbinfo = file->private_data;
24627 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
24630 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
24633 + struct super_block *sb;
24634 + struct au_sbinfo *sbinfo;
24637 + if (unlikely(file->private_data))
24641 + /* don't use au_sbilist_lock() here */
24642 + spin_lock(&au_sbilist.spin);
24643 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
24644 + if (id == sysaufs_si_id(sbinfo)) {
24645 + kobject_get(&sbinfo->si_kobj);
24646 + sb = sbinfo->si_sb;
24649 + spin_unlock(&au_sbilist.spin);
24652 + if (unlikely(!sb))
24655 + err = au_plink_maint_enter(sb);
24657 + /* keep kobject_get() */
24658 + file->private_data = sbinfo;
24660 + kobject_put(&sbinfo->si_kobj);
24666 + * Accept a valid "si=xxxx" only.
24667 + * Once it is accepted successfully, accept "clean" too.
24669 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
24670 + size_t count, loff_t *ppos)
24673 + unsigned long id;
24674 + /* last newline is allowed */
24675 + char buf[3 + sizeof(unsigned long) * 2 + 1];
24678 + if (unlikely(!capable(CAP_SYS_ADMIN)))
24682 + if (unlikely(count > sizeof(buf)))
24685 + err = copy_from_user(buf, ubuf, count);
24686 + if (unlikely(err)) {
24693 + if (!strcmp("clean", buf)) {
24694 + au_procfs_plm_write_clean(file);
24695 + goto out_success;
24696 + } else if (unlikely(strncmp("si=", buf, 3)))
24699 + err = kstrtoul(buf + 3, 16, &id);
24700 + if (unlikely(err))
24703 + err = au_procfs_plm_write_si(file, id);
24704 + if (unlikely(err))
24708 + err = count; /* success */
24713 +static const struct file_operations au_procfs_plm_fop = {
24714 + .write = au_procfs_plm_write,
24715 + .release = au_procfs_plm_release,
24716 + .owner = THIS_MODULE
24719 +/* ---------------------------------------------------------------------- */
24721 +static struct proc_dir_entry *au_procfs_dir;
24723 +void au_procfs_fin(void)
24725 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
24726 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
24729 +int __init au_procfs_init(void)
24732 + struct proc_dir_entry *entry;
24735 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
24736 + if (unlikely(!au_procfs_dir))
24739 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
24740 + au_procfs_dir, &au_procfs_plm_fop);
24741 + if (unlikely(!entry))
24745 + goto out; /* success */
24749 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
24753 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
24754 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
24755 +++ linux/fs/aufs/rdu.c 2014-01-30 21:10:02.857481956 +0100
24758 + * Copyright (C) 2005-2014 Junjiro R. Okajima
24760 + * This program, aufs is free software; you can redistribute it and/or modify
24761 + * it under the terms of the GNU General Public License as published by
24762 + * the Free Software Foundation; either version 2 of the License, or
24763 + * (at your option) any later version.
24765 + * This program is distributed in the hope that it will be useful,
24766 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24767 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24768 + * GNU General Public License for more details.
24770 + * You should have received a copy of the GNU General Public License
24771 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24775 + * readdir in userspace.
24778 +#include <linux/compat.h>
24779 +#include <linux/fs_stack.h>
24780 +#include <linux/security.h>
24783 +/* bits for struct aufs_rdu.flags */
24784 +#define AuRdu_CALLED 1
24785 +#define AuRdu_CONT (1 << 1)
24786 +#define AuRdu_FULL (1 << 2)
24787 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
24788 +#define au_fset_rdu(flags, name) \
24789 + do { (flags) |= AuRdu_##name; } while (0)
24790 +#define au_fclr_rdu(flags, name) \
24791 + do { (flags) &= ~AuRdu_##name; } while (0)
24793 +struct au_rdu_arg {
24794 + struct dir_context ctx;
24795 + struct aufs_rdu *rdu;
24796 + union au_rdu_ent_ul ent;
24797 + unsigned long end;
24799 + struct super_block *sb;
24803 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
24804 + loff_t offset, u64 h_ino, unsigned int d_type)
24807 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
24808 + struct aufs_rdu *rdu = arg->rdu;
24809 + struct au_rdu_ent ent;
24813 + au_fset_rdu(rdu->cookie.flags, CALLED);
24814 + len = au_rdu_len(nlen);
24815 + if (arg->ent.ul + len < arg->end) {
24817 + ent.bindex = rdu->cookie.bindex;
24818 + ent.type = d_type;
24820 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
24821 + ent.type = DT_UNKNOWN;
24823 + /* unnecessary to support mmap_sem since this is a dir */
24825 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
24827 + if (copy_to_user(arg->ent.e->name, name, nlen))
24829 + /* the terminating NULL */
24830 + if (__put_user(0, arg->ent.e->name + nlen))
24833 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
24834 + arg->ent.ul += len;
24838 + au_fset_rdu(rdu->cookie.flags, FULL);
24840 + rdu->tail = arg->ent;
24844 + /* AuTraceErr(err); */
24848 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
24852 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
24854 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
24855 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
24857 + if (unlikely(offset != cookie->h_pos))
24863 + au_fclr_rdu(cookie->flags, CALLED);
24865 + err = vfsub_iterate_dir(h_file, &arg->ctx);
24869 + && au_ftest_rdu(cookie->flags, CALLED)
24870 + && !au_ftest_rdu(cookie->flags, FULL));
24871 + cookie->h_pos = h_file->f_pos;
24878 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
24881 + aufs_bindex_t bend;
24882 + struct au_rdu_arg arg = {
24884 + .actor = au_diractor(au_rdu_fill)
24887 + struct dentry *dentry;
24888 + struct inode *inode;
24889 + struct file *h_file;
24890 + struct au_rdu_cookie *cookie = &rdu->cookie;
24892 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
24893 + if (unlikely(err)) {
24899 + rdu->tail = rdu->ent;
24902 + arg.ent = rdu->ent;
24903 + arg.end = arg.ent.ul;
24904 + arg.end += rdu->sz;
24907 + if (unlikely(!file->f_op->iterate))
24910 + err = security_file_permission(file, MAY_READ);
24912 + if (unlikely(err))
24915 + dentry = file->f_dentry;
24916 + inode = dentry->d_inode;
24918 + mutex_lock(&inode->i_mutex);
24920 + err = mutex_lock_killable(&inode->i_mutex);
24922 + if (unlikely(err))
24926 + arg.sb = inode->i_sb;
24927 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
24928 + if (unlikely(err))
24930 + err = au_alive_dir(dentry);
24931 + if (unlikely(err))
24933 + /* todo: reval? */
24934 + fi_read_lock(file);
24937 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
24938 + && cookie->generation != au_figen(file)))
24943 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
24945 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
24947 + bend = au_fbstart(file);
24948 + if (cookie->bindex < bend)
24949 + cookie->bindex = bend;
24950 + bend = au_fbend_dir(file);
24951 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
24952 + for (; !err && cookie->bindex <= bend;
24953 + cookie->bindex++, cookie->h_pos = 0) {
24954 + h_file = au_hf_dir(file, cookie->bindex);
24958 + au_fclr_rdu(cookie->flags, FULL);
24959 + err = au_rdu_do(h_file, &arg);
24961 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
24964 + AuDbg("rent %llu\n", rdu->rent);
24966 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
24967 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
24968 + au_fset_rdu(cookie->flags, CONT);
24969 + cookie->generation = au_figen(file);
24972 + ii_read_lock_child(inode);
24973 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
24974 + ii_read_unlock(inode);
24977 + fi_read_unlock(file);
24979 + si_read_unlock(arg.sb);
24981 + mutex_unlock(&inode->i_mutex);
24987 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
24991 + unsigned long long nent;
24992 + union au_rdu_ent_ul *u;
24993 + struct au_rdu_ent ent;
24994 + struct super_block *sb;
24997 + nent = rdu->nent;
24999 + sb = file->f_dentry->d_sb;
25000 + si_read_lock(sb, AuLock_FLUSH);
25001 + while (nent-- > 0) {
25002 + /* unnecessary to support mmap_sem since this is a dir */
25003 + err = copy_from_user(&ent, u->e, sizeof(ent));
25005 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
25006 + if (unlikely(err)) {
25012 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
25014 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
25016 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
25018 + if (unlikely(err)) {
25023 + err = __put_user(ino, &u->e->ino);
25024 + if (unlikely(err)) {
25029 + u->ul += au_rdu_len(ent.nlen);
25031 + si_read_unlock(sb);
25036 +/* ---------------------------------------------------------------------- */
25038 +static int au_rdu_verify(struct aufs_rdu *rdu)
25040 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
25041 + "%llu, b%d, 0x%x, g%u}\n",
25042 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
25044 + rdu->rent, rdu->shwh, rdu->full,
25045 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
25046 + rdu->cookie.generation);
25048 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
25052 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
25056 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25059 + struct aufs_rdu rdu;
25060 + void __user *p = (void __user *)arg;
25062 + err = copy_from_user(&rdu, p, sizeof(rdu));
25063 + if (unlikely(err)) {
25068 + err = au_rdu_verify(&rdu);
25069 + if (unlikely(err))
25073 + case AUFS_CTL_RDU:
25074 + err = au_rdu(file, &rdu);
25075 + if (unlikely(err))
25078 + e = copy_to_user(p, &rdu, sizeof(rdu));
25079 + if (unlikely(e)) {
25084 + case AUFS_CTL_RDU_INO:
25085 + err = au_rdu_ino(file, &rdu);
25089 + /* err = -ENOTTY; */
25098 +#ifdef CONFIG_COMPAT
25099 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25102 + struct aufs_rdu rdu;
25103 + void __user *p = compat_ptr(arg);
25105 + /* todo: get_user()? */
25106 + err = copy_from_user(&rdu, p, sizeof(rdu));
25107 + if (unlikely(err)) {
25112 + rdu.ent.e = compat_ptr(rdu.ent.ul);
25113 + err = au_rdu_verify(&rdu);
25114 + if (unlikely(err))
25118 + case AUFS_CTL_RDU:
25119 + err = au_rdu(file, &rdu);
25120 + if (unlikely(err))
25123 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
25124 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
25125 + e = copy_to_user(p, &rdu, sizeof(rdu));
25126 + if (unlikely(e)) {
25131 + case AUFS_CTL_RDU_INO:
25132 + err = au_rdu_ino(file, &rdu);
25136 + /* err = -ENOTTY; */
25145 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
25146 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
25147 +++ linux/fs/aufs/rwsem.h 2014-08-14 10:15:45.128609525 +0200
25150 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25152 + * This program, aufs is free software; you can redistribute it and/or modify
25153 + * it under the terms of the GNU General Public License as published by
25154 + * the Free Software Foundation; either version 2 of the License, or
25155 + * (at your option) any later version.
25157 + * This program is distributed in the hope that it will be useful,
25158 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25159 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25160 + * GNU General Public License for more details.
25162 + * You should have received a copy of the GNU General Public License
25163 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25167 + * simple read-write semaphore wrappers
25170 +#ifndef __AUFS_RWSEM_H__
25171 +#define __AUFS_RWSEM_H__
25175 +#include "debug.h"
25178 + struct rw_semaphore rwsem;
25179 +#ifdef CONFIG_AUFS_DEBUG
25180 + /* just for debugging, not almighty counter */
25181 + atomic_t rcnt, wcnt;
25185 +#ifdef CONFIG_AUFS_DEBUG
25186 +#define AuDbgCntInit(rw) do { \
25187 + atomic_set(&(rw)->rcnt, 0); \
25188 + atomic_set(&(rw)->wcnt, 0); \
25189 + smp_mb(); /* atomic set */ \
25192 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
25193 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
25194 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
25195 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
25197 +#define AuDbgCntInit(rw) do {} while (0)
25198 +#define AuDbgRcntInc(rw) do {} while (0)
25199 +#define AuDbgRcntDec(rw) do {} while (0)
25200 +#define AuDbgWcntInc(rw) do {} while (0)
25201 +#define AuDbgWcntDec(rw) do {} while (0)
25202 +#endif /* CONFIG_AUFS_DEBUG */
25204 +/* to debug easier, do not make them inlined functions */
25205 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
25206 +/* rwsem_is_locked() is unusable */
25207 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
25208 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
25209 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
25210 + && atomic_read(&(rw)->wcnt) <= 0)
25211 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
25212 + || atomic_read(&(rw)->wcnt))
25214 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
25216 +static inline void au_rw_init(struct au_rwsem *rw)
25218 + AuDbgCntInit(rw);
25219 + init_rwsem(&rw->rwsem);
25222 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
25225 + down_write(&rw->rwsem);
25226 + AuDbgWcntInc(rw);
25229 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
25230 + unsigned int lsc)
25233 + down_write_nested(&rw->rwsem, lsc);
25234 + AuDbgWcntInc(rw);
25237 +static inline void au_rw_read_lock(struct au_rwsem *rw)
25239 + down_read(&rw->rwsem);
25240 + AuDbgRcntInc(rw);
25243 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
25245 + down_read_nested(&rw->rwsem, lsc);
25246 + AuDbgRcntInc(rw);
25249 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
25251 + AuRwMustReadLock(rw);
25252 + AuDbgRcntDec(rw);
25253 + up_read(&rw->rwsem);
25256 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
25258 + AuRwMustWriteLock(rw);
25259 + AuDbgRcntInc(rw);
25260 + AuDbgWcntDec(rw);
25261 + downgrade_write(&rw->rwsem);
25264 +static inline void au_rw_write_lock(struct au_rwsem *rw)
25266 + down_write(&rw->rwsem);
25267 + AuDbgWcntInc(rw);
25270 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
25271 + unsigned int lsc)
25273 + down_write_nested(&rw->rwsem, lsc);
25274 + AuDbgWcntInc(rw);
25277 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
25279 + AuRwMustWriteLock(rw);
25280 + AuDbgWcntDec(rw);
25281 + up_write(&rw->rwsem);
25284 +/* why is not _nested version defined */
25285 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
25289 + ret = down_read_trylock(&rw->rwsem);
25291 + AuDbgRcntInc(rw);
25295 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
25299 + ret = down_write_trylock(&rw->rwsem);
25301 + AuDbgWcntInc(rw);
25305 +#undef AuDbgCntInit
25306 +#undef AuDbgRcntInc
25307 +#undef AuDbgRcntDec
25308 +#undef AuDbgWcntInc
25309 +#undef AuDbgWcntDec
25311 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
25312 +static inline void prefix##_read_lock(param) \
25313 +{ au_rw_read_lock(rwsem); } \
25314 +static inline void prefix##_write_lock(param) \
25315 +{ au_rw_write_lock(rwsem); } \
25316 +static inline int prefix##_read_trylock(param) \
25317 +{ return au_rw_read_trylock(rwsem); } \
25318 +static inline int prefix##_write_trylock(param) \
25319 +{ return au_rw_write_trylock(rwsem); }
25320 +/* why is not _nested version defined */
25321 +/* static inline void prefix##_read_trylock_nested(param, lsc)
25322 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
25323 +static inline void prefix##_write_trylock_nestd(param, lsc)
25324 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
25326 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
25327 +static inline void prefix##_read_unlock(param) \
25328 +{ au_rw_read_unlock(rwsem); } \
25329 +static inline void prefix##_write_unlock(param) \
25330 +{ au_rw_write_unlock(rwsem); } \
25331 +static inline void prefix##_downgrade_lock(param) \
25332 +{ au_rw_dgrade_lock(rwsem); }
25334 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
25335 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
25336 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
25338 +#endif /* __KERNEL__ */
25339 +#endif /* __AUFS_RWSEM_H__ */
25340 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
25341 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
25342 +++ linux/fs/aufs/sbinfo.c 2014-08-14 10:15:45.128609525 +0200
25345 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25347 + * This program, aufs is free software; you can redistribute it and/or modify
25348 + * it under the terms of the GNU General Public License as published by
25349 + * the Free Software Foundation; either version 2 of the License, or
25350 + * (at your option) any later version.
25352 + * This program is distributed in the hope that it will be useful,
25353 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25354 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25355 + * GNU General Public License for more details.
25357 + * You should have received a copy of the GNU General Public License
25358 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25362 + * superblock private data
25368 + * they are necessary regardless sysfs is disabled.
25370 +void au_si_free(struct kobject *kobj)
25373 + struct au_sbinfo *sbinfo;
25374 + char *locked __maybe_unused; /* debug only */
25376 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
25377 + for (i = 0; i < AuPlink_NHASH; i++)
25378 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
25379 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
25381 + au_rw_write_lock(&sbinfo->si_rwsem);
25382 + au_br_free(sbinfo);
25383 + au_rw_write_unlock(&sbinfo->si_rwsem);
25385 + AuDebugOn(radix_tree_gang_lookup
25386 + (&sbinfo->au_si_pid.tree, (void **)&locked,
25387 + /*first_index*/PID_MAX_DEFAULT - 1,
25388 + /*max_items*/sizeof(locked)/sizeof(*locked)));
25390 + kfree(sbinfo->si_branch);
25391 + kfree(sbinfo->au_si_pid.bitmap);
25392 + mutex_destroy(&sbinfo->si_xib_mtx);
25393 + AuRwDestroy(&sbinfo->si_rwsem);
25398 +int au_si_alloc(struct super_block *sb)
25401 + struct au_sbinfo *sbinfo;
25402 + static struct lock_class_key aufs_si;
25405 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
25406 + if (unlikely(!sbinfo))
25409 + BUILD_BUG_ON(sizeof(unsigned long) !=
25410 + sizeof(*sbinfo->au_si_pid.bitmap));
25411 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
25412 + sizeof(*sbinfo->au_si_pid.bitmap),
25414 + if (unlikely(!sbinfo->au_si_pid.bitmap))
25417 + /* will be reallocated separately */
25418 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
25419 + if (unlikely(!sbinfo->si_branch))
25422 + err = sysaufs_si_init(sbinfo);
25423 + if (unlikely(err))
25426 + au_nwt_init(&sbinfo->si_nowait);
25427 + au_rw_init_wlock(&sbinfo->si_rwsem);
25428 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
25429 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
25430 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
25432 + atomic_long_set(&sbinfo->si_ninodes, 0);
25433 + atomic_long_set(&sbinfo->si_nfiles, 0);
25435 + sbinfo->si_bend = -1;
25436 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
25438 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
25439 + sbinfo->si_wbr_create = AuWbrCreate_Def;
25440 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
25441 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
25443 + au_fhsm_init(sbinfo);
25445 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
25447 + sbinfo->si_xino_jiffy = jiffies;
25448 + sbinfo->si_xino_expire
25449 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
25450 + mutex_init(&sbinfo->si_xib_mtx);
25451 + sbinfo->si_xino_brid = -1;
25452 + /* leave si_xib_last_pindex and si_xib_next_bit */
25454 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
25455 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
25456 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
25457 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
25459 + for (i = 0; i < AuPlink_NHASH; i++)
25460 + au_sphl_init(sbinfo->si_plink + i);
25461 + init_waitqueue_head(&sbinfo->si_plink_wq);
25462 + spin_lock_init(&sbinfo->si_plink_maint_lock);
25464 + au_sphl_init(&sbinfo->si_files);
25466 + /* leave other members for sysaufs and si_mnt. */
25467 + sbinfo->si_sb = sb;
25468 + sb->s_fs_info = sbinfo;
25470 + au_debug_sbinfo_init(sbinfo);
25471 + return 0; /* success */
25474 + kfree(sbinfo->si_branch);
25476 + kfree(sbinfo->au_si_pid.bitmap);
25483 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
25486 + struct au_branch **brp;
25488 + AuRwMustWriteLock(&sbinfo->si_rwsem);
25491 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
25492 + if (unlikely(!sz))
25493 + sz = sizeof(*brp);
25494 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
25496 + sbinfo->si_branch = brp;
25503 +/* ---------------------------------------------------------------------- */
25505 +unsigned int au_sigen_inc(struct super_block *sb)
25507 + unsigned int gen;
25509 + SiMustWriteLock(sb);
25511 + gen = ++au_sbi(sb)->si_generation;
25512 + au_update_digen(sb->s_root);
25513 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
25514 + sb->s_root->d_inode->i_version++;
25518 +aufs_bindex_t au_new_br_id(struct super_block *sb)
25520 + aufs_bindex_t br_id;
25522 + struct au_sbinfo *sbinfo;
25524 + SiMustWriteLock(sb);
25526 + sbinfo = au_sbi(sb);
25527 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
25528 + br_id = ++sbinfo->si_last_br_id;
25529 + AuDebugOn(br_id < 0);
25530 + if (br_id && au_br_index(sb, br_id) < 0)
25537 +/* ---------------------------------------------------------------------- */
25539 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
25540 +int si_read_lock(struct super_block *sb, int flags)
25545 + if (au_ftest_lock(flags, FLUSH))
25546 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25548 + si_noflush_read_lock(sb);
25549 + err = au_plink_maint(sb, flags);
25550 + if (unlikely(err))
25551 + si_read_unlock(sb);
25556 +int si_write_lock(struct super_block *sb, int flags)
25560 + if (au_ftest_lock(flags, FLUSH))
25561 + au_nwt_flush(&au_sbi(sb)->si_nowait);
25563 + si_noflush_write_lock(sb);
25564 + err = au_plink_maint(sb, flags);
25565 + if (unlikely(err))
25566 + si_write_unlock(sb);
25571 +/* dentry and super_block lock. call at entry point */
25572 +int aufs_read_lock(struct dentry *dentry, int flags)
25575 + struct super_block *sb;
25577 + sb = dentry->d_sb;
25578 + err = si_read_lock(sb, flags);
25579 + if (unlikely(err))
25582 + if (au_ftest_lock(flags, DW))
25583 + di_write_lock_child(dentry);
25585 + di_read_lock_child(dentry, flags);
25587 + if (au_ftest_lock(flags, GEN)) {
25588 + err = au_digen_test(dentry, au_sigen(sb));
25589 + AuDebugOn(!err && au_dbrange_test(dentry));
25590 + if (unlikely(err))
25591 + aufs_read_unlock(dentry, flags);
25598 +void aufs_read_unlock(struct dentry *dentry, int flags)
25600 + if (au_ftest_lock(flags, DW))
25601 + di_write_unlock(dentry);
25603 + di_read_unlock(dentry, flags);
25604 + si_read_unlock(dentry->d_sb);
25607 +void aufs_write_lock(struct dentry *dentry)
25609 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
25610 + di_write_lock_child(dentry);
25613 +void aufs_write_unlock(struct dentry *dentry)
25615 + di_write_unlock(dentry);
25616 + si_write_unlock(dentry->d_sb);
25619 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
25622 + unsigned int sigen;
25623 + struct super_block *sb;
25626 + err = si_read_lock(sb, flags);
25627 + if (unlikely(err))
25630 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
25632 + if (au_ftest_lock(flags, GEN)) {
25633 + sigen = au_sigen(sb);
25634 + err = au_digen_test(d1, sigen);
25635 + AuDebugOn(!err && au_dbrange_test(d1));
25637 + err = au_digen_test(d2, sigen);
25638 + AuDebugOn(!err && au_dbrange_test(d2));
25640 + if (unlikely(err))
25641 + aufs_read_and_write_unlock2(d1, d2);
25648 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
25650 + di_write_unlock2(d1, d2);
25651 + si_read_unlock(d1->d_sb);
25654 +/* ---------------------------------------------------------------------- */
25656 +int si_pid_test_slow(struct super_block *sb)
25661 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
25662 + rcu_read_unlock();
25664 + return (long)!!p;
25667 +void si_pid_set_slow(struct super_block *sb)
25670 + struct au_sbinfo *sbinfo;
25672 + AuDebugOn(si_pid_test_slow(sb));
25674 + sbinfo = au_sbi(sb);
25675 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
25677 + spin_lock(&sbinfo->au_si_pid.tree_lock);
25678 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
25679 + /*any valid ptr*/sb);
25680 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
25682 + radix_tree_preload_end();
25685 +void si_pid_clr_slow(struct super_block *sb)
25688 + struct au_sbinfo *sbinfo;
25690 + AuDebugOn(!si_pid_test_slow(sb));
25692 + sbinfo = au_sbi(sb);
25693 + spin_lock(&sbinfo->au_si_pid.tree_lock);
25694 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
25695 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
25697 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
25698 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
25699 +++ linux/fs/aufs/spl.h 2014-01-30 21:10:02.857481956 +0100
25702 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25704 + * This program, aufs is free software; you can redistribute it and/or modify
25705 + * it under the terms of the GNU General Public License as published by
25706 + * the Free Software Foundation; either version 2 of the License, or
25707 + * (at your option) any later version.
25709 + * This program is distributed in the hope that it will be useful,
25710 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25711 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25712 + * GNU General Public License for more details.
25714 + * You should have received a copy of the GNU General Public License
25715 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25719 + * simple list protected by a spinlock
25722 +#ifndef __AUFS_SPL_H__
25723 +#define __AUFS_SPL_H__
25727 +struct au_splhead {
25729 + struct list_head head;
25732 +static inline void au_spl_init(struct au_splhead *spl)
25734 + spin_lock_init(&spl->spin);
25735 + INIT_LIST_HEAD(&spl->head);
25738 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
25740 + spin_lock(&spl->spin);
25741 + list_add(list, &spl->head);
25742 + spin_unlock(&spl->spin);
25745 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
25747 + spin_lock(&spl->spin);
25749 + spin_unlock(&spl->spin);
25752 +static inline void au_spl_del_rcu(struct list_head *list,
25753 + struct au_splhead *spl)
25755 + spin_lock(&spl->spin);
25756 + list_del_rcu(list);
25757 + spin_unlock(&spl->spin);
25760 +/* ---------------------------------------------------------------------- */
25762 +struct au_sphlhead {
25764 + struct hlist_head head;
25767 +static inline void au_sphl_init(struct au_sphlhead *sphl)
25769 + spin_lock_init(&sphl->spin);
25770 + INIT_HLIST_HEAD(&sphl->head);
25773 +static inline void au_sphl_add(struct hlist_node *hlist,
25774 + struct au_sphlhead *sphl)
25776 + spin_lock(&sphl->spin);
25777 + hlist_add_head(hlist, &sphl->head);
25778 + spin_unlock(&sphl->spin);
25781 +static inline void au_sphl_del(struct hlist_node *hlist,
25782 + struct au_sphlhead *sphl)
25784 + spin_lock(&sphl->spin);
25785 + hlist_del(hlist);
25786 + spin_unlock(&sphl->spin);
25789 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
25790 + struct au_sphlhead *sphl)
25792 + spin_lock(&sphl->spin);
25793 + hlist_del_rcu(hlist);
25794 + spin_unlock(&sphl->spin);
25797 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
25799 + unsigned long cnt;
25800 + struct hlist_node *pos;
25803 + spin_lock(&sphl->spin);
25804 + hlist_for_each(pos, &sphl->head)
25806 + spin_unlock(&sphl->spin);
25810 +#endif /* __KERNEL__ */
25811 +#endif /* __AUFS_SPL_H__ */
25812 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
25813 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
25814 +++ linux/fs/aufs/super.c 2014-08-14 10:15:45.131942973 +0200
25817 + * Copyright (C) 2005-2014 Junjiro R. Okajima
25819 + * This program, aufs is free software; you can redistribute it and/or modify
25820 + * it under the terms of the GNU General Public License as published by
25821 + * the Free Software Foundation; either version 2 of the License, or
25822 + * (at your option) any later version.
25824 + * This program is distributed in the hope that it will be useful,
25825 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25826 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25827 + * GNU General Public License for more details.
25829 + * You should have received a copy of the GNU General Public License
25830 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25834 + * mount and super_block operations
25837 +#include <linux/mm.h>
25838 +#include <linux/module.h>
25839 +#include <linux/seq_file.h>
25840 +#include <linux/statfs.h>
25841 +#include <linux/vmalloc.h>
25842 +#include <linux/writeback.h>
25846 + * super_operations
25848 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
25850 + struct au_icntnr *c;
25852 + c = au_cache_alloc_icntnr();
25854 + au_icntnr_init(c);
25855 + c->vfs_inode.i_version = 1; /* sigen(sb); */
25856 + c->iinfo.ii_hinode = NULL;
25857 + return &c->vfs_inode;
25862 +static void aufs_destroy_inode_cb(struct rcu_head *head)
25864 + struct inode *inode = container_of(head, struct inode, i_rcu);
25866 + INIT_HLIST_HEAD(&inode->i_dentry);
25867 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
25870 +static void aufs_destroy_inode(struct inode *inode)
25872 + au_iinfo_fin(inode);
25873 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
25876 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
25878 + struct inode *inode;
25881 + inode = iget_locked(sb, ino);
25882 + if (unlikely(!inode)) {
25883 + inode = ERR_PTR(-ENOMEM);
25886 + if (!(inode->i_state & I_NEW))
25889 + err = au_xigen_new(inode);
25891 + err = au_iinfo_init(inode);
25893 + inode->i_version++;
25895 + iget_failed(inode);
25896 + inode = ERR_PTR(err);
25900 + /* never return NULL */
25901 + AuDebugOn(!inode);
25902 + AuTraceErrPtr(inode);
25906 +/* lock free root dinfo */
25907 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
25910 + aufs_bindex_t bindex, bend;
25911 + struct path path;
25912 + struct au_hdentry *hdp;
25913 + struct au_branch *br;
25914 + au_br_perm_str_t perm;
25917 + bend = au_sbend(sb);
25918 + hdp = au_di(sb->s_root)->di_hdentry;
25919 + for (bindex = 0; !err && bindex <= bend; bindex++) {
25920 + br = au_sbr(sb, bindex);
25921 + path.mnt = au_br_mnt(br);
25922 + path.dentry = hdp[bindex].hd_dentry;
25923 + err = au_seq_path(seq, &path);
25925 + au_optstr_br_perm(&perm, br->br_perm);
25926 + err = seq_printf(seq, "=%s", perm.a);
25930 + if (!err && bindex != bend)
25931 + err = seq_putc(seq, ':');
25937 +static void au_show_wbr_create(struct seq_file *m, int v,
25938 + struct au_sbinfo *sbinfo)
25942 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25944 + seq_puts(m, ",create=");
25945 + pat = au_optstr_wbr_create(v);
25947 + case AuWbrCreate_TDP:
25948 + case AuWbrCreate_RR:
25949 + case AuWbrCreate_MFS:
25950 + case AuWbrCreate_PMFS:
25951 + seq_puts(m, pat);
25953 + case AuWbrCreate_MFSV:
25954 + seq_printf(m, /*pat*/"mfs:%lu",
25955 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
25958 + case AuWbrCreate_PMFSV:
25959 + seq_printf(m, /*pat*/"pmfs:%lu",
25960 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
25963 + case AuWbrCreate_MFSRR:
25964 + seq_printf(m, /*pat*/"mfsrr:%llu",
25965 + sbinfo->si_wbr_mfs.mfsrr_watermark);
25967 + case AuWbrCreate_MFSRRV:
25968 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
25969 + sbinfo->si_wbr_mfs.mfsrr_watermark,
25970 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
25973 + case AuWbrCreate_PMFSRR:
25974 + seq_printf(m, /*pat*/"pmfsrr:%llu",
25975 + sbinfo->si_wbr_mfs.mfsrr_watermark);
25977 + case AuWbrCreate_PMFSRRV:
25978 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
25979 + sbinfo->si_wbr_mfs.mfsrr_watermark,
25980 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
25986 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
25988 +#ifdef CONFIG_SYSFS
25992 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
25993 + aufs_bindex_t bindex, brid;
25994 + struct qstr *name;
25996 + struct dentry *d, *h_root;
25997 + struct au_hdentry *hdp;
25999 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26002 + f = au_sbi(sb)->si_xib;
26006 + /* stop printing the default xino path on the first writable branch */
26008 + brid = au_xino_brid(sb);
26010 + bindex = au_br_index(sb, brid);
26011 + hdp = au_di(sb->s_root)->di_hdentry;
26012 + h_root = hdp[0 + bindex].hd_dentry;
26015 + name = &d->d_name;
26016 + /* safe ->d_parent because the file is unlinked */
26017 + if (d->d_parent == h_root
26018 + && name->len == len
26019 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
26022 + seq_puts(seq, ",xino=");
26023 + err = au_xino_path(seq, f);
26030 +/* seq_file will re-call me in case of too long string */
26031 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
26034 + unsigned int mnt_flags, v;
26035 + struct super_block *sb;
26036 + struct au_sbinfo *sbinfo;
26038 +#define AuBool(name, str) do { \
26039 + v = au_opt_test(mnt_flags, name); \
26040 + if (v != au_opt_test(AuOpt_Def, name)) \
26041 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
26044 +#define AuStr(name, str) do { \
26045 + v = mnt_flags & AuOptMask_##name; \
26046 + if (v != (AuOpt_Def & AuOptMask_##name)) \
26047 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
26050 +#define AuUInt(name, str, val) do { \
26051 + if (val != AUFS_##name##_DEF) \
26052 + seq_printf(m, "," #str "=%u", val); \
26055 + /* lock free root dinfo */
26056 + sb = dentry->d_sb;
26057 + si_noflush_read_lock(sb);
26058 + sbinfo = au_sbi(sb);
26059 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
26061 + mnt_flags = au_mntflags(sb);
26062 + if (au_opt_test(mnt_flags, XINO)) {
26063 + err = au_show_xino(m, sb);
26064 + if (unlikely(err))
26067 + seq_puts(m, ",noxino");
26069 + AuBool(TRUNC_XINO, trunc_xino);
26070 + AuStr(UDBA, udba);
26071 + AuBool(SHWH, shwh);
26072 + AuBool(PLINK, plink);
26073 + AuBool(DIO, dio);
26074 + AuBool(DIRPERM1, dirperm1);
26075 + /* AuBool(REFROF, refrof); */
26077 + v = sbinfo->si_wbr_create;
26078 + if (v != AuWbrCreate_Def)
26079 + au_show_wbr_create(m, v, sbinfo);
26081 + v = sbinfo->si_wbr_copyup;
26082 + if (v != AuWbrCopyup_Def)
26083 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
26085 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
26086 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
26087 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
26089 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
26091 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
26092 + AuUInt(RDCACHE, rdcache, v);
26094 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
26095 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
26097 + au_fhsm_show(m, sbinfo);
26099 + AuBool(SUM, sum);
26100 + /* AuBool(SUM_W, wsum); */
26101 + AuBool(WARN_PERM, warn_perm);
26102 + AuBool(VERBOSE, verbose);
26105 + /* be sure to print "br:" last */
26106 + if (!sysaufs_brs) {
26107 + seq_puts(m, ",br:");
26108 + au_show_brs(m, sb);
26110 + si_read_unlock(sb);
26118 +/* ---------------------------------------------------------------------- */
26120 +/* sum mode which returns the summation for statfs(2) */
26122 +static u64 au_add_till_max(u64 a, u64 b)
26130 + return ULLONG_MAX;
26133 +static u64 au_mul_till_max(u64 a, long mul)
26141 + return ULLONG_MAX;
26144 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
26147 + long bsize, factor;
26148 + u64 blocks, bfree, bavail, files, ffree;
26149 + aufs_bindex_t bend, bindex, i;
26150 + unsigned char shared;
26151 + struct path h_path;
26152 + struct super_block *h_sb;
26155 + bsize = LONG_MAX;
26161 + bend = au_sbend(sb);
26162 + for (bindex = 0; bindex <= bend; bindex++) {
26163 + h_path.mnt = au_sbr_mnt(sb, bindex);
26164 + h_sb = h_path.mnt->mnt_sb;
26166 + for (i = 0; !shared && i < bindex; i++)
26167 + shared = (au_sbr_sb(sb, i) == h_sb);
26171 + /* sb->s_root for NFS is unreliable */
26172 + h_path.dentry = h_path.mnt->mnt_root;
26173 + err = vfs_statfs(&h_path, buf);
26174 + if (unlikely(err))
26177 + if (bsize > buf->f_bsize) {
26179 + * we will reduce bsize, so we have to expand blocks
26180 + * etc. to match them again
26182 + factor = (bsize / buf->f_bsize);
26183 + blocks = au_mul_till_max(blocks, factor);
26184 + bfree = au_mul_till_max(bfree, factor);
26185 + bavail = au_mul_till_max(bavail, factor);
26186 + bsize = buf->f_bsize;
26189 + factor = (buf->f_bsize / bsize);
26190 + blocks = au_add_till_max(blocks,
26191 + au_mul_till_max(buf->f_blocks, factor));
26192 + bfree = au_add_till_max(bfree,
26193 + au_mul_till_max(buf->f_bfree, factor));
26194 + bavail = au_add_till_max(bavail,
26195 + au_mul_till_max(buf->f_bavail, factor));
26196 + files = au_add_till_max(files, buf->f_files);
26197 + ffree = au_add_till_max(ffree, buf->f_ffree);
26200 + buf->f_bsize = bsize;
26201 + buf->f_blocks = blocks;
26202 + buf->f_bfree = bfree;
26203 + buf->f_bavail = bavail;
26204 + buf->f_files = files;
26205 + buf->f_ffree = ffree;
26206 + buf->f_frsize = 0;
26212 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
26215 + struct path h_path;
26216 + struct super_block *sb;
26218 + /* lock free root dinfo */
26219 + sb = dentry->d_sb;
26220 + si_noflush_read_lock(sb);
26221 + if (!au_opt_test(au_mntflags(sb), SUM)) {
26222 + /* sb->s_root for NFS is unreliable */
26223 + h_path.mnt = au_sbr_mnt(sb, 0);
26224 + h_path.dentry = h_path.mnt->mnt_root;
26225 + err = vfs_statfs(&h_path, buf);
26227 + err = au_statfs_sum(sb, buf);
26228 + si_read_unlock(sb);
26231 + buf->f_type = AUFS_SUPER_MAGIC;
26232 + buf->f_namelen = AUFS_MAX_NAMELEN;
26233 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
26235 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
26240 +/* ---------------------------------------------------------------------- */
26242 +static int aufs_sync_fs(struct super_block *sb, int wait)
26245 + aufs_bindex_t bend, bindex;
26246 + struct au_branch *br;
26247 + struct super_block *h_sb;
26250 + si_noflush_read_lock(sb);
26251 + bend = au_sbend(sb);
26252 + for (bindex = 0; bindex <= bend; bindex++) {
26253 + br = au_sbr(sb, bindex);
26254 + if (!au_br_writable(br->br_perm))
26257 + h_sb = au_sbr_sb(sb, bindex);
26258 + if (h_sb->s_op->sync_fs) {
26259 + e = h_sb->s_op->sync_fs(h_sb, wait);
26260 + if (unlikely(e && !err))
26262 + /* go on even if an error happens */
26265 + si_read_unlock(sb);
26270 +/* ---------------------------------------------------------------------- */
26272 +/* final actions when unmounting a file system */
26273 +static void aufs_put_super(struct super_block *sb)
26275 + struct au_sbinfo *sbinfo;
26277 + sbinfo = au_sbi(sb);
26281 + dbgaufs_si_fin(sbinfo);
26282 + kobject_put(&sbinfo->si_kobj);
26285 +/* ---------------------------------------------------------------------- */
26287 +void au_array_free(void *array)
26290 + if (!is_vmalloc_addr(array))
26297 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
26300 + unsigned long long n, sz;
26307 + if (*hint > ULLONG_MAX / sizeof(array)) {
26308 + array = ERR_PTR(-EMFILE);
26309 + pr_err("hint %llu\n", *hint);
26313 + sz = sizeof(array) * *hint;
26314 + array = kzalloc(sz, GFP_NOFS);
26315 + if (unlikely(!array))
26316 + array = vzalloc(sz);
26317 + if (unlikely(!array)) {
26318 + array = ERR_PTR(-ENOMEM);
26322 + n = cb(array, *hint, arg);
26323 + AuDebugOn(n > *hint);
26330 +static unsigned long long au_iarray_cb(void *a,
26331 + unsigned long long max __maybe_unused,
26334 + unsigned long long n;
26335 + struct inode **p, *inode;
26336 + struct list_head *head;
26341 + spin_lock(&inode_sb_list_lock);
26342 + list_for_each_entry(inode, head, i_sb_list) {
26343 + if (!is_bad_inode(inode)
26344 + && au_ii(inode)->ii_bstart >= 0) {
26345 + spin_lock(&inode->i_lock);
26346 + if (atomic_read(&inode->i_count)) {
26350 + AuDebugOn(n > max);
26352 + spin_unlock(&inode->i_lock);
26355 + spin_unlock(&inode_sb_list_lock);
26360 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
26362 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
26363 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
26366 +void au_iarray_free(struct inode **a, unsigned long long max)
26368 + unsigned long long ull;
26370 + for (ull = 0; ull < max; ull++)
26372 + au_array_free(a);
26375 +/* ---------------------------------------------------------------------- */
26378 + * refresh dentry and inode at remount time.
26380 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
26381 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
26382 + struct dentry *parent)
26386 + di_write_lock_child(dentry);
26387 + di_read_lock_parent(parent, AuLock_IR);
26388 + err = au_refresh_dentry(dentry, parent);
26389 + if (!err && dir_flags)
26390 + au_hn_reset(dentry->d_inode, dir_flags);
26391 + di_read_unlock(parent, AuLock_IR);
26392 + di_write_unlock(dentry);
26397 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
26398 + struct au_sbinfo *sbinfo,
26399 + const unsigned int dir_flags)
26402 + struct dentry *parent;
26403 + struct inode *inode;
26406 + parent = dget_parent(dentry);
26407 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
26408 + inode = dentry->d_inode;
26410 + if (!S_ISDIR(inode->i_mode))
26411 + err = au_do_refresh(dentry, /*dir_flags*/0,
26414 + err = au_do_refresh(dentry, dir_flags, parent);
26415 + if (unlikely(err))
26416 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
26419 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
26420 + AuDbgDentry(dentry);
26428 +static int au_refresh_d(struct super_block *sb)
26430 + int err, i, j, ndentry, e;
26431 + unsigned int sigen;
26432 + struct au_dcsub_pages dpages;
26433 + struct au_dpage *dpage;
26434 + struct dentry **dentries, *d;
26435 + struct au_sbinfo *sbinfo;
26436 + struct dentry *root = sb->s_root;
26437 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
26439 + err = au_dpages_init(&dpages, GFP_NOFS);
26440 + if (unlikely(err))
26442 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
26443 + if (unlikely(err))
26446 + sigen = au_sigen(sb);
26447 + sbinfo = au_sbi(sb);
26448 + for (i = 0; i < dpages.ndpage; i++) {
26449 + dpage = dpages.dpages + i;
26450 + dentries = dpage->dentries;
26451 + ndentry = dpage->ndentry;
26452 + for (j = 0; j < ndentry; j++) {
26454 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
26455 + if (unlikely(e && !err))
26457 + /* go on even err */
26462 + au_dpages_free(&dpages);
26467 +static int au_refresh_i(struct super_block *sb)
26470 + unsigned int sigen;
26471 + unsigned long long max, ull;
26472 + struct inode *inode, **array;
26474 + array = au_iarray_alloc(sb, &max);
26475 + err = PTR_ERR(array);
26476 + if (IS_ERR(array))
26480 + sigen = au_sigen(sb);
26481 + for (ull = 0; ull < max; ull++) {
26482 + inode = array[ull];
26483 + if (unlikely(!inode))
26485 + if (au_iigen(inode, NULL) != sigen) {
26486 + ii_write_lock_child(inode);
26487 + e = au_refresh_hinode_self(inode);
26488 + ii_write_unlock(inode);
26489 + if (unlikely(e)) {
26490 + pr_err("error %d, i%lu\n", e, inode->i_ino);
26493 + /* go on even if err */
26498 + au_iarray_free(array, max);
26504 +static void au_remount_refresh(struct super_block *sb)
26507 + unsigned int udba;
26508 + aufs_bindex_t bindex, bend;
26509 + struct dentry *root;
26510 + struct inode *inode;
26511 + struct au_branch *br;
26513 + au_sigen_inc(sb);
26514 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
26516 + root = sb->s_root;
26517 + DiMustNoWaiters(root);
26518 + inode = root->d_inode;
26519 + IiMustNoWaiters(inode);
26521 + udba = au_opt_udba(sb);
26522 + bend = au_sbend(sb);
26523 + for (bindex = 0; bindex <= bend; bindex++) {
26524 + br = au_sbr(sb, bindex);
26525 + err = au_hnotify_reset_br(udba, br, br->br_perm);
26526 + if (unlikely(err))
26527 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
26529 + /* go on even if err */
26531 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
26533 + di_write_unlock(root);
26534 + err = au_refresh_d(sb);
26535 + e = au_refresh_i(sb);
26536 + if (unlikely(e && !err))
26538 + /* aufs_write_lock() calls ..._child() */
26539 + di_write_lock_child(root);
26541 + au_cpup_attr_all(inode, /*force*/1);
26543 + if (unlikely(err))
26544 + AuIOErr("refresh failed, ignored, %d\n", err);
26547 +/* stop extra interpretation of errno in mount(8), and strange error messages */
26548 +static int cvt_err(int err)
26562 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
26565 + unsigned int mntflags;
26566 + struct au_opts opts;
26567 + struct dentry *root;
26568 + struct inode *inode;
26569 + struct au_sbinfo *sbinfo;
26572 + root = sb->s_root;
26573 + if (!data || !*data) {
26574 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
26576 + di_write_lock_child(root);
26577 + err = au_opts_verify(sb, *flags, /*pending*/0);
26578 + aufs_write_unlock(root);
26584 + memset(&opts, 0, sizeof(opts));
26585 + opts.opt = (void *)__get_free_page(GFP_NOFS);
26586 + if (unlikely(!opts.opt))
26588 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
26589 + opts.flags = AuOpts_REMOUNT;
26590 + opts.sb_flags = *flags;
26592 + /* parse it before aufs lock */
26593 + err = au_opts_parse(sb, data, &opts);
26594 + if (unlikely(err))
26597 + sbinfo = au_sbi(sb);
26598 + inode = root->d_inode;
26599 + mutex_lock(&inode->i_mutex);
26600 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
26601 + if (unlikely(err))
26603 + di_write_lock_child(root);
26605 + /* au_opts_remount() may return an error */
26606 + err = au_opts_remount(sb, &opts);
26607 + au_opts_free(&opts);
26609 + if (au_ftest_opts(opts.flags, REFRESH))
26610 + au_remount_refresh(sb);
26612 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
26613 + mntflags = au_mntflags(sb);
26614 + do_dx = !!au_opt_test(mntflags, DIO);
26615 + au_dy_arefresh(do_dx);
26618 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
26619 + aufs_write_unlock(root);
26622 + mutex_unlock(&inode->i_mutex);
26624 + free_page((unsigned long)opts.opt);
26626 + err = cvt_err(err);
26631 +static const struct super_operations aufs_sop = {
26632 + .alloc_inode = aufs_alloc_inode,
26633 + .destroy_inode = aufs_destroy_inode,
26634 + /* always deleting, no clearing */
26635 + .drop_inode = generic_delete_inode,
26636 + .show_options = aufs_show_options,
26637 + .statfs = aufs_statfs,
26638 + .put_super = aufs_put_super,
26639 + .sync_fs = aufs_sync_fs,
26640 + .remount_fs = aufs_remount_fs
26643 +/* ---------------------------------------------------------------------- */
26645 +static int alloc_root(struct super_block *sb)
26648 + struct inode *inode;
26649 + struct dentry *root;
26652 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
26653 + err = PTR_ERR(inode);
26654 + if (IS_ERR(inode))
26657 + inode->i_op = &aufs_dir_iop;
26658 + inode->i_fop = &aufs_dir_fop;
26659 + inode->i_mode = S_IFDIR;
26660 + set_nlink(inode, 2);
26661 + unlock_new_inode(inode);
26663 + root = d_make_root(inode);
26664 + if (unlikely(!root))
26666 + err = PTR_ERR(root);
26667 + if (IS_ERR(root))
26670 + err = au_di_init(root);
26672 + sb->s_root = root;
26673 + return 0; /* success */
26681 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
26682 + int silent __maybe_unused)
26685 + struct au_opts opts;
26686 + struct dentry *root;
26687 + struct inode *inode;
26688 + char *arg = raw_data;
26690 + if (unlikely(!arg || !*arg)) {
26692 + pr_err("no arg\n");
26697 + memset(&opts, 0, sizeof(opts));
26698 + opts.opt = (void *)__get_free_page(GFP_NOFS);
26699 + if (unlikely(!opts.opt))
26701 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
26702 + opts.sb_flags = sb->s_flags;
26704 + err = au_si_alloc(sb);
26705 + if (unlikely(err))
26708 + /* all timestamps always follow the ones on the branch */
26709 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
26710 + sb->s_op = &aufs_sop;
26711 + sb->s_d_op = &aufs_dop;
26712 + sb->s_magic = AUFS_SUPER_MAGIC;
26713 + sb->s_maxbytes = 0;
26714 + au_export_init(sb);
26716 + err = alloc_root(sb);
26717 + if (unlikely(err)) {
26718 + si_write_unlock(sb);
26721 + root = sb->s_root;
26722 + inode = root->d_inode;
26725 + * actually we can parse options regardless aufs lock here.
26726 + * but at remount time, parsing must be done before aufs lock.
26727 + * so we follow the same rule.
26729 + ii_write_lock_parent(inode);
26730 + aufs_write_unlock(root);
26731 + err = au_opts_parse(sb, arg, &opts);
26732 + if (unlikely(err))
26735 + /* lock vfs_inode first, then aufs. */
26736 + mutex_lock(&inode->i_mutex);
26737 + aufs_write_lock(root);
26738 + err = au_opts_mount(sb, &opts);
26739 + au_opts_free(&opts);
26740 + aufs_write_unlock(root);
26741 + mutex_unlock(&inode->i_mutex);
26743 + goto out_opts; /* success */
26747 + sb->s_root = NULL;
26749 + dbgaufs_si_fin(au_sbi(sb));
26750 + kobject_put(&au_sbi(sb)->si_kobj);
26751 + sb->s_fs_info = NULL;
26753 + free_page((unsigned long)opts.opt);
26756 + err = cvt_err(err);
26761 +/* ---------------------------------------------------------------------- */
26763 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
26764 + const char *dev_name __maybe_unused,
26767 + struct dentry *root;
26768 + struct super_block *sb;
26770 + /* all timestamps always follow the ones on the branch */
26771 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
26772 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
26773 + if (IS_ERR(root))
26777 + si_write_lock(sb, !AuLock_FLUSH);
26778 + sysaufs_brs_add(sb, 0);
26779 + si_write_unlock(sb);
26780 + au_sbilist_add(sb);
26786 +static void aufs_kill_sb(struct super_block *sb)
26788 + struct au_sbinfo *sbinfo;
26790 + sbinfo = au_sbi(sb);
26792 + au_sbilist_del(sb);
26793 + aufs_write_lock(sb->s_root);
26795 + if (sbinfo->si_wbr_create_ops->fin)
26796 + sbinfo->si_wbr_create_ops->fin(sb);
26797 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
26798 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
26799 + au_remount_refresh(sb);
26801 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
26802 + au_plink_put(sb, /*verbose*/1);
26804 + sbinfo->si_sb = NULL;
26805 + aufs_write_unlock(sb->s_root);
26806 + au_nwt_flush(&sbinfo->si_nowait);
26808 + kill_anon_super(sb);
26811 +struct file_system_type aufs_fs_type = {
26812 + .name = AUFS_FSTYPE,
26813 + /* a race between rename and others */
26814 + .fs_flags = FS_RENAME_DOES_D_MOVE,
26815 + .mount = aufs_mount,
26816 + .kill_sb = aufs_kill_sb,
26817 + /* no need to __module_get() and module_put(). */
26818 + .owner = THIS_MODULE,
26820 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
26821 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
26822 +++ linux/fs/aufs/super.h 2014-08-14 10:15:45.131942973 +0200
26825 + * Copyright (C) 2005-2014 Junjiro R. Okajima
26827 + * This program, aufs is free software; you can redistribute it and/or modify
26828 + * it under the terms of the GNU General Public License as published by
26829 + * the Free Software Foundation; either version 2 of the License, or
26830 + * (at your option) any later version.
26832 + * This program is distributed in the hope that it will be useful,
26833 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26834 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26835 + * GNU General Public License for more details.
26837 + * You should have received a copy of the GNU General Public License
26838 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26842 + * super_block operations
26845 +#ifndef __AUFS_SUPER_H__
26846 +#define __AUFS_SUPER_H__
26850 +#include <linux/fs.h>
26851 +#include "rwsem.h"
26855 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
26856 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
26859 +/* policies to select one among multiple writable branches */
26860 +struct au_wbr_copyup_operations {
26861 + int (*copyup)(struct dentry *dentry);
26864 +#define AuWbr_DIR 1 /* target is a dir */
26865 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
26867 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
26868 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
26869 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
26871 +struct au_wbr_create_operations {
26872 + int (*create)(struct dentry *dentry, unsigned int flags);
26873 + int (*init)(struct super_block *sb);
26874 + int (*fin)(struct super_block *sb);
26877 +struct au_wbr_mfs {
26878 + struct mutex mfs_lock; /* protect this structure */
26879 + unsigned long mfs_jiffy;
26880 + unsigned long mfs_expire;
26881 + aufs_bindex_t mfs_bindex;
26883 + unsigned long long mfsrr_bytes;
26884 + unsigned long long mfsrr_watermark;
26887 +struct pseudo_link {
26889 + struct hlist_node hlist;
26890 + struct rcu_head rcu;
26892 + struct inode *inode;
26895 +#define AuPlink_NHASH 100
26896 +static inline int au_plink_hash(ino_t ino)
26898 + return ino % AuPlink_NHASH;
26901 +/* File-based Hierarchical Storage Management */
26903 +#ifdef CONFIG_AUFS_FHSM
26904 + /* allow only one process who can receive the notification */
26905 + spinlock_t fhsm_spin;
26907 + wait_queue_head_t fhsm_wqh;
26908 + atomic_t fhsm_readable;
26910 + /* only this is protected by si_rwsem */
26911 + unsigned long fhsm_expire;
26916 +struct au_sbinfo {
26917 + /* nowait tasks in the system-wide workqueue */
26918 + struct au_nowait_tasks si_nowait;
26921 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
26922 + * rwsem for au_sbinfo is necessary.
26924 + struct au_rwsem si_rwsem;
26926 + /* prevent recursive locking in deleting inode */
26928 + unsigned long *bitmap;
26929 + spinlock_t tree_lock;
26930 + struct radix_tree_root tree;
26934 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
26937 + atomic_long_t si_ninodes, si_nfiles;
26939 + /* branch management */
26940 + unsigned int si_generation;
26942 + /* see above flags */
26943 + unsigned char au_si_status;
26945 + aufs_bindex_t si_bend;
26947 + /* dirty trick to keep br_id plus */
26948 + unsigned int si_last_br_id :
26949 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
26950 + struct au_branch **si_branch;
26952 + /* policy to select a writable branch */
26953 + unsigned char si_wbr_copyup;
26954 + unsigned char si_wbr_create;
26955 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
26956 + struct au_wbr_create_operations *si_wbr_create_ops;
26958 + /* round robin */
26959 + atomic_t si_wbr_rr_next;
26961 + /* most free space */
26962 + struct au_wbr_mfs si_wbr_mfs;
26964 + /* File-based Hierarchical Storage Management */
26965 + struct au_fhsm si_fhsm;
26967 + /* mount flags */
26968 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
26969 + unsigned int si_mntflags;
26971 + /* external inode number (bitmap and translation table) */
26972 + au_readf_t si_xread;
26973 + au_writef_t si_xwrite;
26974 + struct file *si_xib;
26975 + struct mutex si_xib_mtx; /* protect xib members */
26976 + unsigned long *si_xib_buf;
26977 + unsigned long si_xib_last_pindex;
26978 + int si_xib_next_bit;
26979 + aufs_bindex_t si_xino_brid;
26980 + unsigned long si_xino_jiffy;
26981 + unsigned long si_xino_expire;
26982 + /* reserved for future use */
26983 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
26985 +#ifdef CONFIG_AUFS_EXPORT
26986 + /* i_generation */
26987 + struct file *si_xigen;
26988 + atomic_t si_xigen_next;
26991 + /* vdir parameters */
26992 + unsigned long si_rdcache; /* max cache time in jiffies */
26993 + unsigned int si_rdblk; /* deblk size */
26994 + unsigned int si_rdhash; /* hash size */
26997 + * If the number of whiteouts are larger than si_dirwh, leave all of
26998 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
26999 + * future fsck.aufs or kernel thread will remove them later.
27000 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
27002 + unsigned int si_dirwh;
27005 + * rename(2) a directory with all children.
27007 + /* reserved for future use */
27008 + /* int si_rendir; */
27010 + /* pseudo_link list */
27011 + struct au_sphlhead si_plink[AuPlink_NHASH];
27012 + wait_queue_head_t si_plink_wq;
27013 + spinlock_t si_plink_maint_lock;
27014 + pid_t si_plink_maint_pid;
27017 + struct au_sphlhead si_files;
27020 + * sysfs and lifetime management.
27021 + * this is not a small structure and it may be a waste of memory in case
27022 + * of sysfs is disabled, particulary when many aufs-es are mounted.
27023 + * but using sysfs is majority.
27025 + struct kobject si_kobj;
27026 +#ifdef CONFIG_DEBUG_FS
27027 + struct dentry *si_dbgaufs;
27028 + struct dentry *si_dbgaufs_plink;
27029 + struct dentry *si_dbgaufs_xib;
27030 +#ifdef CONFIG_AUFS_EXPORT
27031 + struct dentry *si_dbgaufs_xigen;
27035 +#ifdef CONFIG_AUFS_SBILIST
27036 + struct list_head si_list;
27039 + /* dirty, necessary for unmounting, sysfs and sysrq */
27040 + struct super_block *si_sb;
27043 +/* sbinfo status flags */
27045 + * set true when refresh_dirs() failed at remount time.
27046 + * then try refreshing dirs at access time again.
27047 + * if it is false, refreshing dirs at access time is unnecesary
27049 +#define AuSi_FAILED_REFRESH_DIR 1
27051 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
27053 +#ifndef CONFIG_AUFS_FHSM
27055 +#define AuSi_FHSM 0
27058 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
27059 + unsigned int flag)
27061 + AuRwMustAnyLock(&sbi->si_rwsem);
27062 + return sbi->au_si_status & flag;
27064 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
27065 +#define au_fset_si(sbinfo, name) do { \
27066 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27067 + (sbinfo)->au_si_status |= AuSi_##name; \
27069 +#define au_fclr_si(sbinfo, name) do { \
27070 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27071 + (sbinfo)->au_si_status &= ~AuSi_##name; \
27074 +/* ---------------------------------------------------------------------- */
27076 +/* policy to select one among writable branches */
27077 +#define AuWbrCopyup(sbinfo, ...) \
27078 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
27079 +#define AuWbrCreate(sbinfo, ...) \
27080 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
27082 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
27083 +#define AuLock_DW 1 /* write-lock dentry */
27084 +#define AuLock_IR (1 << 1) /* read-lock inode */
27085 +#define AuLock_IW (1 << 2) /* write-lock inode */
27086 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
27087 +#define AuLock_DIR (1 << 4) /* target is a dir */
27088 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
27089 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
27090 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
27091 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
27092 +#define au_fset_lock(flags, name) \
27093 + do { (flags) |= AuLock_##name; } while (0)
27094 +#define au_fclr_lock(flags, name) \
27095 + do { (flags) &= ~AuLock_##name; } while (0)
27097 +/* ---------------------------------------------------------------------- */
27100 +extern struct file_system_type aufs_fs_type;
27101 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
27102 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
27104 +void au_array_free(void *array);
27105 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
27106 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
27107 +void au_iarray_free(struct inode **a, unsigned long long max);
27110 +void au_si_free(struct kobject *kobj);
27111 +int au_si_alloc(struct super_block *sb);
27112 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
27114 +unsigned int au_sigen_inc(struct super_block *sb);
27115 +aufs_bindex_t au_new_br_id(struct super_block *sb);
27117 +int si_read_lock(struct super_block *sb, int flags);
27118 +int si_write_lock(struct super_block *sb, int flags);
27119 +int aufs_read_lock(struct dentry *dentry, int flags);
27120 +void aufs_read_unlock(struct dentry *dentry, int flags);
27121 +void aufs_write_lock(struct dentry *dentry);
27122 +void aufs_write_unlock(struct dentry *dentry);
27123 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
27124 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
27126 +int si_pid_test_slow(struct super_block *sb);
27127 +void si_pid_set_slow(struct super_block *sb);
27128 +void si_pid_clr_slow(struct super_block *sb);
27130 +/* wbr_policy.c */
27131 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
27132 +extern struct au_wbr_create_operations au_wbr_create_ops[];
27133 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
27134 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
27135 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
27138 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
27140 +#ifdef CONFIG_AUFS_FHSM
27143 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
27147 + spin_lock(&fhsm->fhsm_spin);
27148 + pid = fhsm->fhsm_pid;
27149 + spin_unlock(&fhsm->fhsm_spin);
27154 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
27155 +void au_fhsm_wrote_all(struct super_block *sb, int force);
27156 +int au_fhsm_fd(struct super_block *sb, int oflags);
27157 +int au_fhsm_br_alloc(struct au_branch *br);
27158 +void au_fhsm_fin(struct super_block *sb);
27159 +void au_fhsm_init(struct au_sbinfo *sbinfo);
27160 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
27161 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
27163 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
27165 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
27166 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
27167 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm);
27168 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br);
27169 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
27170 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
27171 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
27172 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
27175 +/* ---------------------------------------------------------------------- */
27177 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
27179 + return sb->s_fs_info;
27182 +/* ---------------------------------------------------------------------- */
27184 +#ifdef CONFIG_AUFS_EXPORT
27185 +int au_test_nfsd(void);
27186 +void au_export_init(struct super_block *sb);
27187 +void au_xigen_inc(struct inode *inode);
27188 +int au_xigen_new(struct inode *inode);
27189 +int au_xigen_set(struct super_block *sb, struct file *base);
27190 +void au_xigen_clr(struct super_block *sb);
27192 +static inline int au_busy_or_stale(void)
27194 + if (!au_test_nfsd())
27199 +AuStubInt0(au_test_nfsd, void)
27200 +AuStubVoid(au_export_init, struct super_block *sb)
27201 +AuStubVoid(au_xigen_inc, struct inode *inode)
27202 +AuStubInt0(au_xigen_new, struct inode *inode)
27203 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
27204 +AuStubVoid(au_xigen_clr, struct super_block *sb)
27205 +static inline int au_busy_or_stale(void)
27209 +#endif /* CONFIG_AUFS_EXPORT */
27211 +/* ---------------------------------------------------------------------- */
27213 +#ifdef CONFIG_AUFS_SBILIST
27215 +extern struct au_splhead au_sbilist;
27217 +static inline void au_sbilist_init(void)
27219 + au_spl_init(&au_sbilist);
27222 +static inline void au_sbilist_add(struct super_block *sb)
27224 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
27227 +static inline void au_sbilist_del(struct super_block *sb)
27229 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
27232 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
27233 +static inline void au_sbilist_lock(void)
27235 + spin_lock(&au_sbilist.spin);
27238 +static inline void au_sbilist_unlock(void)
27240 + spin_unlock(&au_sbilist.spin);
27242 +#define AuGFP_SBILIST GFP_ATOMIC
27244 +AuStubVoid(au_sbilist_lock, void)
27245 +AuStubVoid(au_sbilist_unlock, void)
27246 +#define AuGFP_SBILIST GFP_NOFS
27247 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
27249 +AuStubVoid(au_sbilist_init, void)
27250 +AuStubVoid(au_sbilist_add, struct super_block*)
27251 +AuStubVoid(au_sbilist_del, struct super_block*)
27252 +AuStubVoid(au_sbilist_lock, void)
27253 +AuStubVoid(au_sbilist_unlock, void)
27254 +#define AuGFP_SBILIST GFP_NOFS
27257 +/* ---------------------------------------------------------------------- */
27259 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
27262 + * This function is a dynamic '__init' fucntion actually,
27263 + * so the tiny check for si_rwsem is unnecessary.
27265 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
27266 +#ifdef CONFIG_DEBUG_FS
27267 + sbinfo->si_dbgaufs = NULL;
27268 + sbinfo->si_dbgaufs_plink = NULL;
27269 + sbinfo->si_dbgaufs_xib = NULL;
27270 +#ifdef CONFIG_AUFS_EXPORT
27271 + sbinfo->si_dbgaufs_xigen = NULL;
27276 +/* ---------------------------------------------------------------------- */
27278 +static inline pid_t si_pid_bit(void)
27280 + /* the origin of pid is 1, but the bitmap's is 0 */
27281 + return current->pid - 1;
27284 +static inline int si_pid_test(struct super_block *sb)
27288 + bit = si_pid_bit();
27289 + if (bit < PID_MAX_DEFAULT)
27290 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27292 + return si_pid_test_slow(sb);
27295 +static inline void si_pid_set(struct super_block *sb)
27299 + bit = si_pid_bit();
27300 + if (bit < PID_MAX_DEFAULT) {
27301 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
27302 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27305 + si_pid_set_slow(sb);
27308 +static inline void si_pid_clr(struct super_block *sb)
27312 + bit = si_pid_bit();
27313 + if (bit < PID_MAX_DEFAULT) {
27314 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
27315 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
27318 + si_pid_clr_slow(sb);
27321 +/* ---------------------------------------------------------------------- */
27323 +/* lock superblock. mainly for entry point functions */
27325 + * __si_read_lock, __si_write_lock,
27326 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
27328 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
27330 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
27331 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
27332 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
27334 +static inline void si_noflush_read_lock(struct super_block *sb)
27336 + __si_read_lock(sb);
27340 +static inline int si_noflush_read_trylock(struct super_block *sb)
27344 + locked = __si_read_trylock(sb);
27350 +static inline void si_noflush_write_lock(struct super_block *sb)
27352 + __si_write_lock(sb);
27356 +static inline int si_noflush_write_trylock(struct super_block *sb)
27360 + locked = __si_write_trylock(sb);
27366 +#if 0 /* unused */
27367 +static inline int si_read_trylock(struct super_block *sb, int flags)
27369 + if (au_ftest_lock(flags, FLUSH))
27370 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27371 + return si_noflush_read_trylock(sb);
27375 +static inline void si_read_unlock(struct super_block *sb)
27378 + __si_read_unlock(sb);
27381 +#if 0 /* unused */
27382 +static inline int si_write_trylock(struct super_block *sb, int flags)
27384 + if (au_ftest_lock(flags, FLUSH))
27385 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27386 + return si_noflush_write_trylock(sb);
27390 +static inline void si_write_unlock(struct super_block *sb)
27393 + __si_write_unlock(sb);
27396 +#if 0 /* unused */
27397 +static inline void si_downgrade_lock(struct super_block *sb)
27399 + __si_downgrade_lock(sb);
27403 +/* ---------------------------------------------------------------------- */
27405 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
27407 + SiMustAnyLock(sb);
27408 + return au_sbi(sb)->si_bend;
27411 +static inline unsigned int au_mntflags(struct super_block *sb)
27413 + SiMustAnyLock(sb);
27414 + return au_sbi(sb)->si_mntflags;
27417 +static inline unsigned int au_sigen(struct super_block *sb)
27419 + SiMustAnyLock(sb);
27420 + return au_sbi(sb)->si_generation;
27423 +static inline void au_ninodes_inc(struct super_block *sb)
27425 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
27428 +static inline void au_ninodes_dec(struct super_block *sb)
27430 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
27431 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
27434 +static inline void au_nfiles_inc(struct super_block *sb)
27436 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
27439 +static inline void au_nfiles_dec(struct super_block *sb)
27441 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
27442 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
27445 +static inline struct au_branch *au_sbr(struct super_block *sb,
27446 + aufs_bindex_t bindex)
27448 + SiMustAnyLock(sb);
27449 + return au_sbi(sb)->si_branch[0 + bindex];
27452 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
27454 + SiMustWriteLock(sb);
27455 + au_sbi(sb)->si_xino_brid = brid;
27458 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
27460 + SiMustAnyLock(sb);
27461 + return au_sbi(sb)->si_xino_brid;
27464 +#endif /* __KERNEL__ */
27465 +#endif /* __AUFS_SUPER_H__ */
27466 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
27467 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
27468 +++ linux/fs/aufs/sysaufs.c 2014-01-30 21:10:02.857481956 +0100
27471 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27473 + * This program, aufs is free software; you can redistribute it and/or modify
27474 + * it under the terms of the GNU General Public License as published by
27475 + * the Free Software Foundation; either version 2 of the License, or
27476 + * (at your option) any later version.
27478 + * This program is distributed in the hope that it will be useful,
27479 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27480 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27481 + * GNU General Public License for more details.
27483 + * You should have received a copy of the GNU General Public License
27484 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27488 + * sysfs interface and lifetime management
27489 + * they are necessary regardless sysfs is disabled.
27492 +#include <linux/random.h>
27495 +unsigned long sysaufs_si_mask;
27496 +struct kset *sysaufs_kset;
27498 +#define AuSiAttr(_name) { \
27499 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
27500 + .show = sysaufs_si_##_name, \
27503 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
27504 +struct attribute *sysaufs_si_attrs[] = {
27505 + &sysaufs_si_attr_xi_path.attr,
27509 +static const struct sysfs_ops au_sbi_ops = {
27510 + .show = sysaufs_si_show
27513 +static struct kobj_type au_sbi_ktype = {
27514 + .release = au_si_free,
27515 + .sysfs_ops = &au_sbi_ops,
27516 + .default_attrs = sysaufs_si_attrs
27519 +/* ---------------------------------------------------------------------- */
27521 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
27525 + sbinfo->si_kobj.kset = sysaufs_kset;
27526 + /* cf. sysaufs_name() */
27527 + err = kobject_init_and_add
27528 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
27529 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
27531 + dbgaufs_si_null(sbinfo);
27533 + err = dbgaufs_si_init(sbinfo);
27534 + if (unlikely(err))
27535 + kobject_put(&sbinfo->si_kobj);
27540 +void sysaufs_fin(void)
27543 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
27544 + kset_unregister(sysaufs_kset);
27547 +int __init sysaufs_init(void)
27552 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
27553 + } while (!sysaufs_si_mask);
27556 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
27557 + if (unlikely(!sysaufs_kset))
27559 + err = PTR_ERR(sysaufs_kset);
27560 + if (IS_ERR(sysaufs_kset))
27562 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
27563 + if (unlikely(err)) {
27564 + kset_unregister(sysaufs_kset);
27568 + err = dbgaufs_init();
27569 + if (unlikely(err))
27574 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
27575 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
27576 +++ linux/fs/aufs/sysaufs.h 2014-08-14 10:15:45.131942973 +0200
27579 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27581 + * This program, aufs is free software; you can redistribute it and/or modify
27582 + * it under the terms of the GNU General Public License as published by
27583 + * the Free Software Foundation; either version 2 of the License, or
27584 + * (at your option) any later version.
27586 + * This program is distributed in the hope that it will be useful,
27587 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27588 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27589 + * GNU General Public License for more details.
27591 + * You should have received a copy of the GNU General Public License
27592 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27596 + * sysfs interface and mount lifetime management
27599 +#ifndef __SYSAUFS_H__
27600 +#define __SYSAUFS_H__
27604 +#include <linux/sysfs.h>
27605 +#include "module.h"
27607 +struct super_block;
27610 +struct sysaufs_si_attr {
27611 + struct attribute attr;
27612 + int (*show)(struct seq_file *seq, struct super_block *sb);
27615 +/* ---------------------------------------------------------------------- */
27618 +extern unsigned long sysaufs_si_mask;
27619 +extern struct kset *sysaufs_kset;
27620 +extern struct attribute *sysaufs_si_attrs[];
27621 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
27622 +int __init sysaufs_init(void);
27623 +void sysaufs_fin(void);
27625 +/* ---------------------------------------------------------------------- */
27627 +/* some people doesn't like to show a pointer in kernel */
27628 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
27630 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
27633 +#define SysaufsSiNamePrefix "si_"
27634 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
27635 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
27637 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
27638 + sysaufs_si_id(sbinfo));
27642 +#ifdef CONFIG_SYSFS
27644 +extern struct attribute_group *sysaufs_attr_group;
27646 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
27647 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
27649 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
27650 +#ifdef CONFIG_COMPAT
27651 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
27654 +void sysaufs_br_init(struct au_branch *br);
27655 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
27656 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
27658 +#define sysaufs_brs_init() do {} while (0)
27661 +#define sysaufs_attr_group NULL
27663 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
27666 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
27672 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
27673 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
27674 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
27676 +static inline void sysaufs_brs_init(void)
27681 +#endif /* CONFIG_SYSFS */
27683 +#endif /* __KERNEL__ */
27684 +#endif /* __SYSAUFS_H__ */
27685 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
27686 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
27687 +++ linux/fs/aufs/sysfs.c 2014-08-14 10:15:45.131942973 +0200
27690 + * Copyright (C) 2005-2014 Junjiro R. Okajima
27692 + * This program, aufs is free software; you can redistribute it and/or modify
27693 + * it under the terms of the GNU General Public License as published by
27694 + * the Free Software Foundation; either version 2 of the License, or
27695 + * (at your option) any later version.
27697 + * This program is distributed in the hope that it will be useful,
27698 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27699 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27700 + * GNU General Public License for more details.
27702 + * You should have received a copy of the GNU General Public License
27703 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27707 + * sysfs interface
27710 +#include <linux/compat.h>
27711 +#include <linux/seq_file.h>
27714 +#ifdef CONFIG_AUFS_FS_MODULE
27715 +/* this entry violates the "one line per file" policy of sysfs */
27716 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
27720 + static char *conf =
27721 +/* this file is generated at compiling */
27722 +#include "conf.str"
27725 + err = snprintf(buf, PAGE_SIZE, conf);
27726 + if (unlikely(err >= PAGE_SIZE))
27731 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
27734 +static struct attribute *au_attr[] = {
27735 +#ifdef CONFIG_AUFS_FS_MODULE
27736 + &au_config_attr.attr,
27738 + NULL, /* need to NULL terminate the list of attributes */
27741 +static struct attribute_group sysaufs_attr_group_body = {
27745 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
27747 +/* ---------------------------------------------------------------------- */
27749 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
27753 + SiMustAnyLock(sb);
27756 + if (au_opt_test(au_mntflags(sb), XINO)) {
27757 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
27758 + seq_putc(seq, '\n');
27764 + * the lifetime of branch is independent from the entry under sysfs.
27765 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
27768 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
27769 + aufs_bindex_t bindex, int idx)
27772 + struct path path;
27773 + struct dentry *root;
27774 + struct au_branch *br;
27775 + au_br_perm_str_t perm;
27777 + AuDbg("b%d\n", bindex);
27780 + root = sb->s_root;
27781 + di_read_lock_parent(root, !AuLock_IR);
27782 + br = au_sbr(sb, bindex);
27785 + case AuBrSysfs_BR:
27786 + path.mnt = au_br_mnt(br);
27787 + path.dentry = au_h_dptr(root, bindex);
27788 + au_seq_path(seq, &path);
27789 + au_optstr_br_perm(&perm, br->br_perm);
27790 + err = seq_printf(seq, "=%s\n", perm.a);
27792 + case AuBrSysfs_BRID:
27793 + err = seq_printf(seq, "%d\n", br->br_id);
27796 + di_read_unlock(root, !AuLock_IR);
27803 +/* ---------------------------------------------------------------------- */
27805 +static struct seq_file *au_seq(char *p, ssize_t len)
27807 + struct seq_file *seq;
27809 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
27811 + /* mutex_init(&seq.lock); */
27814 + return seq; /* success */
27817 + seq = ERR_PTR(-ENOMEM);
27821 +#define SysaufsBr_PREFIX "br"
27822 +#define SysaufsBrid_PREFIX "brid"
27824 +/* todo: file size may exceed PAGE_SIZE */
27825 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
27831 + aufs_bindex_t bend;
27832 + struct au_sbinfo *sbinfo;
27833 + struct super_block *sb;
27834 + struct seq_file *seq;
27836 + struct attribute **cattr;
27838 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
27839 + sb = sbinfo->si_sb;
27842 + * prevent a race condition between sysfs and aufs.
27843 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
27844 + * prohibits maintaining the sysfs entries.
27845 + * hew we acquire read lock after sysfs_get_active_two().
27846 + * on the other hand, the remount process may maintain the sysfs/aufs
27847 + * entries after acquiring write lock.
27848 + * it can cause a deadlock.
27849 + * simply we gave up processing read here.
27852 + if (unlikely(!si_noflush_read_trylock(sb)))
27855 + seq = au_seq(buf, PAGE_SIZE);
27856 + err = PTR_ERR(seq);
27860 + name = (void *)attr->name;
27861 + cattr = sysaufs_si_attrs;
27863 + if (!strcmp(name, (*cattr)->name)) {
27864 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
27871 + if (!strncmp(name, SysaufsBrid_PREFIX,
27872 + sizeof(SysaufsBrid_PREFIX) - 1)) {
27873 + idx = AuBrSysfs_BRID;
27874 + name += sizeof(SysaufsBrid_PREFIX) - 1;
27875 + } else if (!strncmp(name, SysaufsBr_PREFIX,
27876 + sizeof(SysaufsBr_PREFIX) - 1)) {
27877 + idx = AuBrSysfs_BR;
27878 + name += sizeof(SysaufsBr_PREFIX) - 1;
27882 + err = kstrtol(name, 10, &l);
27884 + bend = au_sbend(sb);
27886 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
27893 + err = seq->count;
27894 + /* sysfs limit */
27895 + if (unlikely(err == PAGE_SIZE))
27900 + si_read_unlock(sb);
27905 +/* ---------------------------------------------------------------------- */
27907 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
27911 + aufs_bindex_t bindex, bend;
27914 + struct seq_file *seq;
27915 + struct au_branch *br;
27917 + si_read_lock(sb, AuLock_FLUSH);
27918 + bend = au_sbend(sb);
27924 + buf = (void *)__get_free_page(GFP_NOFS);
27925 + if (unlikely(!buf))
27928 + seq = au_seq(buf, PAGE_SIZE);
27929 + err = PTR_ERR(seq);
27933 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
27934 + for (bindex = 0; bindex <= bend; bindex++, arg++) {
27935 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
27936 + if (unlikely(err))
27939 + br = au_sbr(sb, bindex);
27940 + brid = br->br_id;
27941 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
27942 + err = __put_user(brid, &arg->id);
27943 + if (unlikely(err))
27946 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
27947 + err = __put_user(br->br_perm, &arg->perm);
27948 + if (unlikely(err))
27951 + au_seq_path(seq, &br->br_path);
27952 + err = seq_putc(seq, '\0');
27953 + if (!err && seq->count <= sz) {
27954 + err = copy_to_user(arg->path, seq->buf, seq->count);
27956 + if (unlikely(err))
27963 + if (unlikely(err))
27969 + free_page((unsigned long)buf);
27971 + si_read_unlock(sb);
27975 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
27977 + return au_brinfo(file->f_dentry->d_sb, (void __user *)arg);
27980 +#ifdef CONFIG_COMPAT
27981 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
27983 + return au_brinfo(file->f_dentry->d_sb, compat_ptr(arg));
27987 +/* ---------------------------------------------------------------------- */
27989 +void sysaufs_br_init(struct au_branch *br)
27992 + struct au_brsysfs *br_sysfs;
27993 + struct attribute *attr;
27995 + br_sysfs = br->br_sysfs;
27996 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
27997 + attr = &br_sysfs->attr;
27998 + sysfs_attr_init(attr);
27999 + attr->name = br_sysfs->name;
28000 + attr->mode = S_IRUGO;
28005 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
28007 + struct au_branch *br;
28008 + struct kobject *kobj;
28009 + struct au_brsysfs *br_sysfs;
28011 + aufs_bindex_t bend;
28013 + dbgaufs_brs_del(sb, bindex);
28015 + if (!sysaufs_brs)
28018 + kobj = &au_sbi(sb)->si_kobj;
28019 + bend = au_sbend(sb);
28020 + for (; bindex <= bend; bindex++) {
28021 + br = au_sbr(sb, bindex);
28022 + br_sysfs = br->br_sysfs;
28023 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28024 + sysfs_remove_file(kobj, &br_sysfs->attr);
28030 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
28033 + aufs_bindex_t bend;
28034 + struct kobject *kobj;
28035 + struct au_branch *br;
28036 + struct au_brsysfs *br_sysfs;
28038 + dbgaufs_brs_add(sb, bindex);
28040 + if (!sysaufs_brs)
28043 + kobj = &au_sbi(sb)->si_kobj;
28044 + bend = au_sbend(sb);
28045 + for (; bindex <= bend; bindex++) {
28046 + br = au_sbr(sb, bindex);
28047 + br_sysfs = br->br_sysfs;
28048 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
28049 + SysaufsBr_PREFIX "%d", bindex);
28050 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
28051 + SysaufsBrid_PREFIX "%d", bindex);
28052 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28053 + err = sysfs_create_file(kobj, &br_sysfs->attr);
28054 + if (unlikely(err))
28055 + pr_warn("failed %s under sysfs(%d)\n",
28056 + br_sysfs->name, err);
28061 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
28062 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
28063 +++ linux/fs/aufs/sysrq.c 2014-08-14 10:15:45.131942973 +0200
28066 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28068 + * This program, aufs is free software; you can redistribute it and/or modify
28069 + * it under the terms of the GNU General Public License as published by
28070 + * the Free Software Foundation; either version 2 of the License, or
28071 + * (at your option) any later version.
28073 + * This program is distributed in the hope that it will be useful,
28074 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28075 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28076 + * GNU General Public License for more details.
28078 + * You should have received a copy of the GNU General Public License
28079 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28083 + * magic sysrq hanlder
28086 +/* #include <linux/sysrq.h> */
28087 +#include <linux/writeback.h>
28090 +/* ---------------------------------------------------------------------- */
28092 +static void sysrq_sb(struct super_block *sb)
28095 + struct au_sbinfo *sbinfo;
28096 + struct file *file;
28097 + struct au_sphlhead *files;
28098 + struct au_finfo *finfo;
28100 + plevel = au_plevel;
28101 + au_plevel = KERN_WARNING;
28103 + /* since we define pr_fmt, call printk directly */
28104 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
28106 + sbinfo = au_sbi(sb);
28107 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
28108 + pr("superblock\n");
28112 + pr("root dentry\n");
28113 + au_dpri_dentry(sb->s_root);
28114 + pr("root inode\n");
28115 + au_dpri_inode(sb->s_root->d_inode);
28120 + int err, i, j, ndentry;
28121 + struct au_dcsub_pages dpages;
28122 + struct au_dpage *dpage;
28124 + err = au_dpages_init(&dpages, GFP_ATOMIC);
28125 + if (unlikely(err))
28127 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
28129 + for (i = 0; i < dpages.ndpage; i++) {
28130 + dpage = dpages.dpages + i;
28131 + ndentry = dpage->ndentry;
28132 + for (j = 0; j < ndentry; j++)
28133 + au_dpri_dentry(dpage->dentries[j]);
28135 + au_dpages_free(&dpages);
28143 + pr("isolated inode\n");
28144 + spin_lock(&inode_sb_list_lock);
28145 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
28146 + spin_lock(&i->i_lock);
28147 + if (1 || hlist_empty(&i->i_dentry))
28148 + au_dpri_inode(i);
28149 + spin_unlock(&i->i_lock);
28151 + spin_unlock(&inode_sb_list_lock);
28155 + files = &au_sbi(sb)->si_files;
28156 + spin_lock(&files->spin);
28157 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
28160 + file = finfo->fi_file;
28161 + mode = file_inode(file)->i_mode;
28162 + if (!special_file(mode))
28163 + au_dpri_file(file);
28165 + spin_unlock(&files->spin);
28169 + au_plevel = plevel;
28172 +/* ---------------------------------------------------------------------- */
28174 +/* module parameter */
28175 +static char *aufs_sysrq_key = "a";
28176 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
28177 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
28179 +static void au_sysrq(int key __maybe_unused)
28181 + struct au_sbinfo *sbinfo;
28184 + au_sbilist_lock();
28185 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
28186 + sysrq_sb(sbinfo->si_sb);
28187 + au_sbilist_unlock();
28191 +static struct sysrq_key_op au_sysrq_op = {
28192 + .handler = au_sysrq,
28193 + .help_msg = "Aufs",
28194 + .action_msg = "Aufs",
28195 + .enable_mask = SYSRQ_ENABLE_DUMP
28198 +/* ---------------------------------------------------------------------- */
28200 +int __init au_sysrq_init(void)
28206 + key = *aufs_sysrq_key;
28207 + if ('a' <= key && key <= 'z')
28208 + err = register_sysrq_key(key, &au_sysrq_op);
28209 + if (unlikely(err))
28210 + pr_err("err %d, sysrq=%c\n", err, key);
28214 +void au_sysrq_fin(void)
28218 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
28219 + if (unlikely(err))
28220 + pr_err("err %d (ignored)\n", err);
28222 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
28223 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
28224 +++ linux/fs/aufs/vdir.c 2014-08-14 10:15:45.131942973 +0200
28227 + * Copyright (C) 2005-2014 Junjiro R. Okajima
28229 + * This program, aufs is free software; you can redistribute it and/or modify
28230 + * it under the terms of the GNU General Public License as published by
28231 + * the Free Software Foundation; either version 2 of the License, or
28232 + * (at your option) any later version.
28234 + * This program is distributed in the hope that it will be useful,
28235 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28236 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28237 + * GNU General Public License for more details.
28239 + * You should have received a copy of the GNU General Public License
28240 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28244 + * virtual or vertical directory
28249 +static unsigned int calc_size(int nlen)
28251 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
28254 +static int set_deblk_end(union au_vdir_deblk_p *p,
28255 + union au_vdir_deblk_p *deblk_end)
28257 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
28258 + p->de->de_str.len = 0;
28262 + return -1; /* error */
28265 +/* returns true or false */
28266 +static int is_deblk_end(union au_vdir_deblk_p *p,
28267 + union au_vdir_deblk_p *deblk_end)
28269 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
28270 + return !p->de->de_str.len;
28274 +static unsigned char *last_deblk(struct au_vdir *vdir)
28276 + return vdir->vd_deblk[vdir->vd_nblk - 1];
28279 +/* ---------------------------------------------------------------------- */
28281 +/* estimate the apropriate size for name hash table */
28282 +unsigned int au_rdhash_est(loff_t sz)
28290 + if (sz < AUFS_RDHASH_DEF)
28291 + n = AUFS_RDHASH_DEF;
28292 + /* pr_info("n %u\n", n); */
28297 + * the allocated memory has to be freed by
28298 + * au_nhash_wh_free() or au_nhash_de_free().
28300 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
28302 + struct hlist_head *head;
28306 + sz = sizeof(*nhash->nh_head) * num_hash;
28307 + head = kmalloc(sz, gfp);
28309 + nhash->nh_num = num_hash;
28310 + nhash->nh_head = head;
28311 + for (u = 0; u < num_hash; u++)
28312 + INIT_HLIST_HEAD(head++);
28313 + return 0; /* success */
28319 +static void nhash_count(struct hlist_head *head)
28323 + struct hlist_node *pos;
28326 + hlist_for_each(pos, head)
28328 + pr_info("%lu\n", n);
28332 +static void au_nhash_wh_do_free(struct hlist_head *head)
28334 + struct au_vdir_wh *pos;
28335 + struct hlist_node *node;
28337 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
28341 +static void au_nhash_de_do_free(struct hlist_head *head)
28343 + struct au_vdir_dehstr *pos;
28344 + struct hlist_node *node;
28346 + hlist_for_each_entry_safe(pos, node, head, hash)
28347 + au_cache_free_vdir_dehstr(pos);
28350 +static void au_nhash_do_free(struct au_nhash *nhash,
28351 + void (*free)(struct hlist_head *head))
28354 + struct hlist_head *head;
28356 + n = nhash->nh_num;
28360 + head = nhash->nh_head;
28361 + while (n-- > 0) {
28362 + nhash_count(head);
28365 + kfree(nhash->nh_head);
28368 +void au_nhash_wh_free(struct au_nhash *whlist)
28370 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
28373 +static void au_nhash_de_free(struct au_nhash *delist)
28375 + au_nhash_do_free(delist, au_nhash_de_do_free);
28378 +/* ---------------------------------------------------------------------- */
28380 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
28384 + unsigned int u, n;
28385 + struct hlist_head *head;
28386 + struct au_vdir_wh *pos;
28389 + n = whlist->nh_num;
28390 + head = whlist->nh_head;
28391 + for (u = 0; u < n; u++, head++)
28392 + hlist_for_each_entry(pos, head, wh_hash)
28393 + if (pos->wh_bindex == btgt && ++num > limit)
28398 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
28399 + unsigned char *name,
28400 + unsigned int len)
28403 + /* const unsigned int magic_bit = 12; */
28405 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
28410 + /* v = hash_long(v, magic_bit); */
28411 + v %= nhash->nh_num;
28412 + return nhash->nh_head + v;
28415 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
28418 + return str->len == nlen && !memcmp(str->name, name, nlen);
28421 +/* returns found or not */
28422 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
28424 + struct hlist_head *head;
28425 + struct au_vdir_wh *pos;
28426 + struct au_vdir_destr *str;
28428 + head = au_name_hash(whlist, name, nlen);
28429 + hlist_for_each_entry(pos, head, wh_hash) {
28430 + str = &pos->wh_str;
28431 + AuDbg("%.*s\n", str->len, str->name);
28432 + if (au_nhash_test_name(str, name, nlen))
28438 +/* returns found(true) or not */
28439 +static int test_known(struct au_nhash *delist, char *name, int nlen)
28441 + struct hlist_head *head;
28442 + struct au_vdir_dehstr *pos;
28443 + struct au_vdir_destr *str;
28445 + head = au_name_hash(delist, name, nlen);
28446 + hlist_for_each_entry(pos, head, hash) {
28448 + AuDbg("%.*s\n", str->len, str->name);
28449 + if (au_nhash_test_name(str, name, nlen))
28455 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
28456 + unsigned char d_type)
28458 +#ifdef CONFIG_AUFS_SHWH
28459 + wh->wh_ino = ino;
28460 + wh->wh_type = d_type;
28464 +/* ---------------------------------------------------------------------- */
28466 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
28467 + unsigned int d_type, aufs_bindex_t bindex,
28468 + unsigned char shwh)
28471 + struct au_vdir_destr *str;
28472 + struct au_vdir_wh *wh;
28474 + AuDbg("%.*s\n", nlen, name);
28475 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
28478 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
28479 + if (unlikely(!wh))
28483 + wh->wh_bindex = bindex;
28485 + au_shwh_init_wh(wh, ino, d_type);
28486 + str = &wh->wh_str;
28488 + memcpy(str->name, name, nlen);
28489 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
28496 +static int append_deblk(struct au_vdir *vdir)
28499 + unsigned long ul;
28500 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
28501 + union au_vdir_deblk_p p, deblk_end;
28502 + unsigned char **o;
28505 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
28507 + if (unlikely(!o))
28510 + vdir->vd_deblk = o;
28511 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
28513 + ul = vdir->vd_nblk++;
28514 + vdir->vd_deblk[ul] = p.deblk;
28515 + vdir->vd_last.ul = ul;
28516 + vdir->vd_last.p.deblk = p.deblk;
28517 + deblk_end.deblk = p.deblk + deblk_sz;
28518 + err = set_deblk_end(&p, &deblk_end);
28525 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
28526 + unsigned int d_type, struct au_nhash *delist)
28530 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
28531 + union au_vdir_deblk_p p, *room, deblk_end;
28532 + struct au_vdir_dehstr *dehstr;
28534 + p.deblk = last_deblk(vdir);
28535 + deblk_end.deblk = p.deblk + deblk_sz;
28536 + room = &vdir->vd_last.p;
28537 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
28538 + || !is_deblk_end(room, &deblk_end));
28540 + sz = calc_size(nlen);
28541 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
28542 + err = append_deblk(vdir);
28543 + if (unlikely(err))
28546 + p.deblk = last_deblk(vdir);
28547 + deblk_end.deblk = p.deblk + deblk_sz;
28549 + AuDebugOn(room->deblk != p.deblk);
28553 + dehstr = au_cache_alloc_vdir_dehstr();
28554 + if (unlikely(!dehstr))
28557 + dehstr->str = &room->de->de_str;
28558 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
28559 + room->de->de_ino = ino;
28560 + room->de->de_type = d_type;
28561 + room->de->de_str.len = nlen;
28562 + memcpy(room->de->de_str.name, name, nlen);
28565 + room->deblk += sz;
28566 + if (unlikely(set_deblk_end(room, &deblk_end)))
28567 + err = append_deblk(vdir);
28574 +/* ---------------------------------------------------------------------- */
28576 +void au_vdir_free(struct au_vdir *vdir)
28578 + unsigned char **deblk;
28580 + deblk = vdir->vd_deblk;
28581 + while (vdir->vd_nblk--)
28583 + kfree(vdir->vd_deblk);
28584 + au_cache_free_vdir(vdir);
28587 +static struct au_vdir *alloc_vdir(struct file *file)
28589 + struct au_vdir *vdir;
28590 + struct super_block *sb;
28593 + sb = file->f_dentry->d_sb;
28594 + SiMustAnyLock(sb);
28597 + vdir = au_cache_alloc_vdir();
28598 + if (unlikely(!vdir))
28601 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
28602 + if (unlikely(!vdir->vd_deblk))
28605 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
28606 + if (!vdir->vd_deblk_sz) {
28607 + /* estimate the apropriate size for deblk */
28608 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
28609 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
28611 + vdir->vd_nblk = 0;
28612 + vdir->vd_version = 0;
28613 + vdir->vd_jiffy = 0;
28614 + err = append_deblk(vdir);
28616 + return vdir; /* success */
28618 + kfree(vdir->vd_deblk);
28621 + au_cache_free_vdir(vdir);
28623 + vdir = ERR_PTR(err);
28627 +static int reinit_vdir(struct au_vdir *vdir)
28630 + union au_vdir_deblk_p p, deblk_end;
28632 + while (vdir->vd_nblk > 1) {
28633 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
28634 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
28637 + p.deblk = vdir->vd_deblk[0];
28638 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
28639 + err = set_deblk_end(&p, &deblk_end);
28640 + /* keep vd_dblk_sz */
28641 + vdir->vd_last.ul = 0;
28642 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
28643 + vdir->vd_version = 0;
28644 + vdir->vd_jiffy = 0;
28649 +/* ---------------------------------------------------------------------- */
28651 +#define AuFillVdir_CALLED 1
28652 +#define AuFillVdir_WHABLE (1 << 1)
28653 +#define AuFillVdir_SHWH (1 << 2)
28654 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
28655 +#define au_fset_fillvdir(flags, name) \
28656 + do { (flags) |= AuFillVdir_##name; } while (0)
28657 +#define au_fclr_fillvdir(flags, name) \
28658 + do { (flags) &= ~AuFillVdir_##name; } while (0)
28660 +#ifndef CONFIG_AUFS_SHWH
28661 +#undef AuFillVdir_SHWH
28662 +#define AuFillVdir_SHWH 0
28665 +struct fillvdir_arg {
28666 + struct dir_context ctx;
28667 + struct file *file;
28668 + struct au_vdir *vdir;
28669 + struct au_nhash delist;
28670 + struct au_nhash whlist;
28671 + aufs_bindex_t bindex;
28672 + unsigned int flags;
28676 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
28677 + loff_t offset __maybe_unused, u64 h_ino,
28678 + unsigned int d_type)
28680 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
28681 + char *name = (void *)__name;
28682 + struct super_block *sb;
28684 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
28687 + sb = arg->file->f_dentry->d_sb;
28688 + au_fset_fillvdir(arg->flags, CALLED);
28690 + if (nlen <= AUFS_WH_PFX_LEN
28691 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
28692 + if (test_known(&arg->delist, name, nlen)
28693 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
28694 + goto out; /* already exists or whiteouted */
28696 + sb = arg->file->f_dentry->d_sb;
28697 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
28699 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
28700 + d_type = DT_UNKNOWN;
28701 + arg->err = append_de(arg->vdir, name, nlen, ino,
28702 + d_type, &arg->delist);
28704 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
28705 + name += AUFS_WH_PFX_LEN;
28706 + nlen -= AUFS_WH_PFX_LEN;
28707 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
28708 + goto out; /* already whiteouted */
28711 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
28714 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
28715 + d_type = DT_UNKNOWN;
28716 + arg->err = au_nhash_append_wh
28717 + (&arg->whlist, name, nlen, ino, d_type,
28718 + arg->bindex, shwh);
28724 + arg->vdir->vd_jiffy = jiffies;
28726 + AuTraceErr(arg->err);
28730 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
28731 + struct au_nhash *whlist, struct au_nhash *delist)
28733 +#ifdef CONFIG_AUFS_SHWH
28735 + unsigned int nh, u;
28736 + struct hlist_head *head;
28737 + struct au_vdir_wh *pos;
28738 + struct hlist_node *n;
28740 + struct au_vdir_destr *destr;
28742 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
28745 + o = p = (void *)__get_free_page(GFP_NOFS);
28746 + if (unlikely(!p))
28750 + nh = whlist->nh_num;
28751 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
28752 + p += AUFS_WH_PFX_LEN;
28753 + for (u = 0; u < nh; u++) {
28754 + head = whlist->nh_head + u;
28755 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
28756 + destr = &pos->wh_str;
28757 + memcpy(p, destr->name, destr->len);
28758 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
28759 + pos->wh_ino, pos->wh_type, delist);
28760 + if (unlikely(err))
28765 + free_page((unsigned long)o);
28775 +static int au_do_read_vdir(struct fillvdir_arg *arg)
28778 + unsigned int rdhash;
28780 + aufs_bindex_t bend, bindex, bstart;
28781 + unsigned char shwh;
28782 + struct file *hf, *file;
28783 + struct super_block *sb;
28785 + file = arg->file;
28786 + sb = file->f_dentry->d_sb;
28787 + SiMustAnyLock(sb);
28789 + rdhash = au_sbi(sb)->si_rdhash;
28791 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
28792 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
28793 + if (unlikely(err))
28795 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
28796 + if (unlikely(err))
28802 + if (au_opt_test(au_mntflags(sb), SHWH)) {
28804 + au_fset_fillvdir(arg->flags, SHWH);
28806 + bstart = au_fbstart(file);
28807 + bend = au_fbend_dir(file);
28808 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
28809 + hf = au_hf_dir(file, bindex);
28813 + offset = vfsub_llseek(hf, 0, SEEK_SET);
28815 + if (unlikely(offset))
28818 + arg->bindex = bindex;
28819 + au_fclr_fillvdir(arg->flags, WHABLE);
28821 + || (bindex != bend
28822 + && au_br_whable(au_sbr_perm(sb, bindex))))
28823 + au_fset_fillvdir(arg->flags, WHABLE);
28826 + au_fclr_fillvdir(arg->flags, CALLED);
28828 + err = vfsub_iterate_dir(hf, &arg->ctx);
28831 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
28834 + * dir_relax() may be good for concurrency, but aufs should not
28835 + * use it since it will cause a lockdep problem.
28839 + if (!err && shwh)
28840 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
28842 + au_nhash_wh_free(&arg->whlist);
28845 + au_nhash_de_free(&arg->delist);
28850 +static int read_vdir(struct file *file, int may_read)
28853 + unsigned long expire;
28854 + unsigned char do_read;
28855 + struct fillvdir_arg arg = {
28857 + .actor = au_diractor(fillvdir)
28860 + struct inode *inode;
28861 + struct au_vdir *vdir, *allocated;
28864 + inode = file_inode(file);
28865 + IMustLock(inode);
28866 + SiMustAnyLock(inode->i_sb);
28868 + allocated = NULL;
28870 + expire = au_sbi(inode->i_sb)->si_rdcache;
28871 + vdir = au_ivdir(inode);
28874 + vdir = alloc_vdir(file);
28875 + err = PTR_ERR(vdir);
28876 + if (IS_ERR(vdir))
28879 + allocated = vdir;
28880 + } else if (may_read
28881 + && (inode->i_version != vdir->vd_version
28882 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
28884 + err = reinit_vdir(vdir);
28885 + if (unlikely(err))
28890 + return 0; /* success */
28894 + err = au_do_read_vdir(&arg);
28896 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
28897 + vdir->vd_version = inode->i_version;
28898 + vdir->vd_last.ul = 0;
28899 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
28901 + au_set_ivdir(inode, allocated);
28902 + } else if (allocated)
28903 + au_vdir_free(allocated);
28909 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
28912 + unsigned long ul, n;
28913 + const unsigned int deblk_sz = src->vd_deblk_sz;
28915 + AuDebugOn(tgt->vd_nblk != 1);
28918 + if (tgt->vd_nblk < src->vd_nblk) {
28919 + unsigned char **p;
28921 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
28923 + if (unlikely(!p))
28925 + tgt->vd_deblk = p;
28928 + if (tgt->vd_deblk_sz != deblk_sz) {
28929 + unsigned char *p;
28931 + tgt->vd_deblk_sz = deblk_sz;
28932 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
28933 + if (unlikely(!p))
28935 + tgt->vd_deblk[0] = p;
28937 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
28938 + tgt->vd_version = src->vd_version;
28939 + tgt->vd_jiffy = src->vd_jiffy;
28941 + n = src->vd_nblk;
28942 + for (ul = 1; ul < n; ul++) {
28943 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
28945 + if (unlikely(!tgt->vd_deblk[ul]))
28949 + tgt->vd_nblk = n;
28950 + tgt->vd_last.ul = tgt->vd_last.ul;
28951 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
28952 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
28953 + - src->vd_deblk[src->vd_last.ul];
28955 + return 0; /* success */
28958 + rerr = reinit_vdir(tgt);
28963 +int au_vdir_init(struct file *file)
28966 + struct inode *inode;
28967 + struct au_vdir *vdir_cache, *allocated;
28969 + /* test file->f_pos here instead of ctx->pos */
28970 + err = read_vdir(file, !file->f_pos);
28971 + if (unlikely(err))
28974 + allocated = NULL;
28975 + vdir_cache = au_fvdir_cache(file);
28976 + if (!vdir_cache) {
28977 + vdir_cache = alloc_vdir(file);
28978 + err = PTR_ERR(vdir_cache);
28979 + if (IS_ERR(vdir_cache))
28981 + allocated = vdir_cache;
28982 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
28983 + /* test file->f_pos here instead of ctx->pos */
28984 + err = reinit_vdir(vdir_cache);
28985 + if (unlikely(err))
28988 + return 0; /* success */
28990 + inode = file_inode(file);
28991 + err = copy_vdir(vdir_cache, au_ivdir(inode));
28993 + file->f_version = inode->i_version;
28995 + au_set_fvdir_cache(file, allocated);
28996 + } else if (allocated)
28997 + au_vdir_free(allocated);
29003 +static loff_t calc_offset(struct au_vdir *vdir)
29006 + union au_vdir_deblk_p p;
29008 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
29009 + offset = vdir->vd_last.p.deblk - p.deblk;
29010 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
29014 +/* returns true or false */
29015 +static int seek_vdir(struct file *file, struct dir_context *ctx)
29018 + unsigned int deblk_sz;
29019 + unsigned long ul, n;
29021 + union au_vdir_deblk_p p, deblk_end;
29022 + struct au_vdir *vdir_cache;
29025 + vdir_cache = au_fvdir_cache(file);
29026 + offset = calc_offset(vdir_cache);
29027 + AuDbg("offset %lld\n", offset);
29028 + if (ctx->pos == offset)
29031 + vdir_cache->vd_last.ul = 0;
29032 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
29037 + deblk_sz = vdir_cache->vd_deblk_sz;
29038 + ul = div64_u64(ctx->pos, deblk_sz);
29039 + AuDbg("ul %lu\n", ul);
29040 + if (ul >= vdir_cache->vd_nblk)
29043 + n = vdir_cache->vd_nblk;
29044 + for (; ul < n; ul++) {
29045 + p.deblk = vdir_cache->vd_deblk[ul];
29046 + deblk_end.deblk = p.deblk + deblk_sz;
29048 + offset *= deblk_sz;
29049 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
29052 + l = calc_size(p.de->de_str.len);
29056 + if (!is_deblk_end(&p, &deblk_end)) {
29058 + vdir_cache->vd_last.ul = ul;
29059 + vdir_cache->vd_last.p = p;
29066 + AuTraceErr(!valid);
29070 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
29072 + unsigned int l, deblk_sz;
29073 + union au_vdir_deblk_p deblk_end;
29074 + struct au_vdir *vdir_cache;
29075 + struct au_vdir_de *de;
29077 + vdir_cache = au_fvdir_cache(file);
29078 + if (!seek_vdir(file, ctx))
29081 + deblk_sz = vdir_cache->vd_deblk_sz;
29083 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29084 + deblk_end.deblk += deblk_sz;
29085 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
29086 + de = vdir_cache->vd_last.p.de;
29087 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
29088 + de->de_str.len, de->de_str.name, ctx->pos,
29089 + (unsigned long)de->de_ino, de->de_type);
29090 + if (unlikely(!dir_emit(ctx, de->de_str.name,
29091 + de->de_str.len, de->de_ino,
29093 + /* todo: ignore the error caused by udba? */
29094 + /* return err; */
29098 + l = calc_size(de->de_str.len);
29099 + vdir_cache->vd_last.p.deblk += l;
29102 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
29103 + vdir_cache->vd_last.ul++;
29104 + vdir_cache->vd_last.p.deblk
29105 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29106 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
29115 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
29116 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
29117 +++ linux/fs/aufs/vfsub.c 2014-08-14 10:16:04.515942371 +0200
29120 + * Copyright (C) 2005-2014 Junjiro R. Okajima
29122 + * This program, aufs is free software; you can redistribute it and/or modify
29123 + * it under the terms of the GNU General Public License as published by
29124 + * the Free Software Foundation; either version 2 of the License, or
29125 + * (at your option) any later version.
29127 + * This program is distributed in the hope that it will be useful,
29128 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29129 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29130 + * GNU General Public License for more details.
29132 + * You should have received a copy of the GNU General Public License
29133 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29137 + * sub-routines for VFS
29140 +#include <linux/ima.h>
29141 +#include <linux/namei.h>
29142 +#include <linux/security.h>
29143 +#include <linux/splice.h>
29146 +int vfsub_update_h_iattr(struct path *h_path, int *did)
29150 + struct super_block *h_sb;
29152 + /* for remote fs, leave work for its getattr or d_revalidate */
29153 + /* for bad i_attr fs, handle them in aufs_getattr() */
29154 + /* still some fs may acquire i_mutex. we need to skip them */
29158 + h_sb = h_path->dentry->d_sb;
29159 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
29161 + err = vfs_getattr(h_path, &st);
29166 +/* ---------------------------------------------------------------------- */
29168 +struct file *vfsub_dentry_open(struct path *path, int flags)
29170 + struct file *file;
29172 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
29174 + if (!IS_ERR_OR_NULL(file)
29175 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
29176 + i_readcount_inc(path->dentry->d_inode);
29181 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
29183 + struct file *file;
29186 + file = filp_open(path,
29187 + oflags /* | __FMODE_NONOTIFY */,
29190 + if (IS_ERR(file))
29192 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29198 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
29202 + err = kern_path(name, flags, path);
29203 + if (!err && path->dentry->d_inode)
29204 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
29208 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
29211 + struct path path = {
29215 + /* VFS checks it too, but by WARN_ON_ONCE() */
29216 + IMustLock(parent->d_inode);
29218 + path.dentry = lookup_one_len(name, parent, len);
29219 + if (IS_ERR(path.dentry))
29221 + if (path.dentry->d_inode)
29222 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
29225 + AuTraceErrPtr(path.dentry);
29226 + return path.dentry;
29229 +void vfsub_call_lkup_one(void *args)
29231 + struct vfsub_lkup_one_args *a = args;
29232 + *a->errp = vfsub_lkup_one(a->name, a->parent);
29235 +/* ---------------------------------------------------------------------- */
29237 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
29238 + struct dentry *d2, struct au_hinode *hdir2)
29240 + struct dentry *d;
29243 + d = lock_rename(d1, d2);
29245 + au_hn_suspend(hdir1);
29246 + if (hdir1 != hdir2)
29247 + au_hn_suspend(hdir2);
29252 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
29253 + struct dentry *d2, struct au_hinode *hdir2)
29255 + au_hn_resume(hdir1);
29256 + if (hdir1 != hdir2)
29257 + au_hn_resume(hdir2);
29259 + unlock_rename(d1, d2);
29263 +/* ---------------------------------------------------------------------- */
29265 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
29268 + struct dentry *d;
29272 + d = path->dentry;
29273 + path->dentry = d->d_parent;
29274 + err = security_path_mknod(path, d, mode, 0);
29275 + path->dentry = d;
29276 + if (unlikely(err))
29279 + err = vfs_create(dir, path->dentry, mode, want_excl);
29281 + struct path tmp = *path;
29284 + vfsub_update_h_iattr(&tmp, &did);
29286 + tmp.dentry = path->dentry->d_parent;
29287 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29296 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
29299 + struct dentry *d;
29303 + d = path->dentry;
29304 + path->dentry = d->d_parent;
29305 + err = security_path_symlink(path, d, symname);
29306 + path->dentry = d;
29307 + if (unlikely(err))
29310 + err = vfs_symlink(dir, path->dentry, symname);
29312 + struct path tmp = *path;
29315 + vfsub_update_h_iattr(&tmp, &did);
29317 + tmp.dentry = path->dentry->d_parent;
29318 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29327 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
29330 + struct dentry *d;
29334 + d = path->dentry;
29335 + path->dentry = d->d_parent;
29336 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
29337 + path->dentry = d;
29338 + if (unlikely(err))
29341 + err = vfs_mknod(dir, path->dentry, mode, dev);
29343 + struct path tmp = *path;
29346 + vfsub_update_h_iattr(&tmp, &did);
29348 + tmp.dentry = path->dentry->d_parent;
29349 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29358 +static int au_test_nlink(struct inode *inode)
29360 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
29362 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
29363 + || inode->i_nlink < link_max)
29368 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
29369 + struct inode **delegated_inode)
29372 + struct dentry *d;
29376 + err = au_test_nlink(src_dentry->d_inode);
29377 + if (unlikely(err))
29380 + /* we don't call may_linkat() */
29381 + d = path->dentry;
29382 + path->dentry = d->d_parent;
29383 + err = security_path_link(src_dentry, path, d);
29384 + path->dentry = d;
29385 + if (unlikely(err))
29389 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
29392 + struct path tmp = *path;
29395 + /* fuse has different memory inode for the same inumber */
29396 + vfsub_update_h_iattr(&tmp, &did);
29398 + tmp.dentry = path->dentry->d_parent;
29399 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29400 + tmp.dentry = src_dentry;
29401 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29410 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
29411 + struct inode *dir, struct path *path,
29412 + struct inode **delegated_inode)
29415 + struct path tmp = {
29418 + struct dentry *d;
29421 + IMustLock(src_dir);
29423 + d = path->dentry;
29424 + path->dentry = d->d_parent;
29425 + tmp.dentry = src_dentry->d_parent;
29426 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
29427 + path->dentry = d;
29428 + if (unlikely(err))
29432 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
29433 + delegated_inode, /*flags*/0);
29438 + tmp.dentry = d->d_parent;
29439 + vfsub_update_h_iattr(&tmp, &did);
29441 + tmp.dentry = src_dentry;
29442 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29443 + tmp.dentry = src_dentry->d_parent;
29444 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29453 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
29456 + struct dentry *d;
29460 + d = path->dentry;
29461 + path->dentry = d->d_parent;
29462 + err = security_path_mkdir(path, d, mode);
29463 + path->dentry = d;
29464 + if (unlikely(err))
29467 + err = vfs_mkdir(dir, path->dentry, mode);
29469 + struct path tmp = *path;
29472 + vfsub_update_h_iattr(&tmp, &did);
29474 + tmp.dentry = path->dentry->d_parent;
29475 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
29484 +int vfsub_rmdir(struct inode *dir, struct path *path)
29487 + struct dentry *d;
29491 + d = path->dentry;
29492 + path->dentry = d->d_parent;
29493 + err = security_path_rmdir(path, d);
29494 + path->dentry = d;
29495 + if (unlikely(err))
29499 + err = vfs_rmdir(dir, path->dentry);
29502 + struct path tmp = {
29503 + .dentry = path->dentry->d_parent,
29507 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
29514 +/* ---------------------------------------------------------------------- */
29516 +/* todo: support mmap_sem? */
29517 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
29523 + err = vfs_read(file, ubuf, count, ppos);
29526 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29530 +/* todo: kernel_read()? */
29531 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
29535 + mm_segment_t oldfs;
29542 + oldfs = get_fs();
29543 + set_fs(KERNEL_DS);
29544 + err = vfsub_read_u(file, buf.u, count, ppos);
29549 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
29555 + err = vfs_write(file, ubuf, count, ppos);
29558 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29562 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
29565 + mm_segment_t oldfs;
29568 + const char __user *u;
29572 + oldfs = get_fs();
29573 + set_fs(KERNEL_DS);
29574 + err = vfsub_write_u(file, buf.u, count, ppos);
29579 +int vfsub_flush(struct file *file, fl_owner_t id)
29584 + if (file->f_op->flush) {
29585 + if (!au_test_nfs(file->f_dentry->d_sb))
29586 + err = file->f_op->flush(file, id);
29589 + err = file->f_op->flush(file, id);
29593 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
29599 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
29603 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
29606 + err = iterate_dir(file, ctx);
29609 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29613 +long vfsub_splice_to(struct file *in, loff_t *ppos,
29614 + struct pipe_inode_info *pipe, size_t len,
29615 + unsigned int flags)
29620 + err = do_splice_to(in, ppos, pipe, len, flags);
29622 + file_accessed(in);
29624 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
29628 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
29629 + loff_t *ppos, size_t len, unsigned int flags)
29634 + err = do_splice_from(pipe, out, ppos, len, flags);
29637 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
29641 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
29645 + /* file can be NULL */
29647 + err = vfs_fsync(file, datasync);
29651 + AuDebugOn(!file);
29652 + path = &file->f_path;
29654 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
29659 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
29660 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
29661 + struct file *h_file)
29664 + struct inode *h_inode;
29665 + struct super_block *h_sb;
29668 + err = vfsub_truncate(h_path, length);
29672 + h_inode = h_path->dentry->d_inode;
29673 + h_sb = h_inode->i_sb;
29675 + sb_start_write(h_sb);
29677 + err = locks_verify_truncate(h_inode, h_file, length);
29679 + err = security_path_truncate(h_path);
29682 + err = do_truncate(h_path->dentry, length, attr, h_file);
29686 + sb_end_write(h_sb);
29693 +/* ---------------------------------------------------------------------- */
29695 +struct au_vfsub_mkdir_args {
29697 + struct inode *dir;
29698 + struct path *path;
29702 +static void au_call_vfsub_mkdir(void *args)
29704 + struct au_vfsub_mkdir_args *a = args;
29705 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
29708 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
29710 + int err, do_sio, wkq_err;
29712 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
29714 + err = vfsub_mkdir(dir, path, mode);
29716 + struct au_vfsub_mkdir_args args = {
29722 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
29723 + if (unlikely(wkq_err))
29730 +struct au_vfsub_rmdir_args {
29732 + struct inode *dir;
29733 + struct path *path;
29736 +static void au_call_vfsub_rmdir(void *args)
29738 + struct au_vfsub_rmdir_args *a = args;
29739 + *a->errp = vfsub_rmdir(a->dir, a->path);
29742 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
29744 + int err, do_sio, wkq_err;
29746 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
29748 + err = vfsub_rmdir(dir, path);
29750 + struct au_vfsub_rmdir_args args = {
29755 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
29756 + if (unlikely(wkq_err))
29763 +/* ---------------------------------------------------------------------- */
29765 +struct notify_change_args {
29767 + struct path *path;
29768 + struct iattr *ia;
29769 + struct inode **delegated_inode;
29772 +static void call_notify_change(void *args)
29774 + struct notify_change_args *a = args;
29775 + struct inode *h_inode;
29777 + h_inode = a->path->dentry->d_inode;
29778 + IMustLock(h_inode);
29780 + *a->errp = -EPERM;
29781 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
29782 + *a->errp = notify_change(a->path->dentry, a->ia,
29783 + a->delegated_inode);
29785 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
29787 + AuTraceErr(*a->errp);
29790 +int vfsub_notify_change(struct path *path, struct iattr *ia,
29791 + struct inode **delegated_inode)
29794 + struct notify_change_args args = {
29798 + .delegated_inode = delegated_inode
29801 + call_notify_change(&args);
29806 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
29807 + struct inode **delegated_inode)
29809 + int err, wkq_err;
29810 + struct notify_change_args args = {
29814 + .delegated_inode = delegated_inode
29817 + wkq_err = au_wkq_wait(call_notify_change, &args);
29818 + if (unlikely(wkq_err))
29824 +/* ---------------------------------------------------------------------- */
29826 +struct unlink_args {
29828 + struct inode *dir;
29829 + struct path *path;
29830 + struct inode **delegated_inode;
29833 +static void call_unlink(void *args)
29835 + struct unlink_args *a = args;
29836 + struct dentry *d = a->path->dentry;
29837 + struct inode *h_inode;
29838 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
29839 + && d_count(d) == 1);
29841 + IMustLock(a->dir);
29843 + a->path->dentry = d->d_parent;
29844 + *a->errp = security_path_unlink(a->path, d);
29845 + a->path->dentry = d;
29846 + if (unlikely(*a->errp))
29849 + if (!stop_sillyrename)
29851 + h_inode = d->d_inode;
29856 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
29859 + struct path tmp = {
29860 + .dentry = d->d_parent,
29861 + .mnt = a->path->mnt
29863 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
29866 + if (!stop_sillyrename)
29871 + AuTraceErr(*a->errp);
29875 + * @dir: must be locked.
29876 + * @dentry: target dentry.
29878 +int vfsub_unlink(struct inode *dir, struct path *path,
29879 + struct inode **delegated_inode, int force)
29882 + struct unlink_args args = {
29886 + .delegated_inode = delegated_inode
29890 + call_unlink(&args);
29894 + wkq_err = au_wkq_wait(call_unlink, &args);
29895 + if (unlikely(wkq_err))
29901 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
29902 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
29903 +++ linux/fs/aufs/vfsub.h 2014-08-14 10:15:45.131942973 +0200
29906 + * Copyright (C) 2005-2014 Junjiro R. Okajima
29908 + * This program, aufs is free software; you can redistribute it and/or modify
29909 + * it under the terms of the GNU General Public License as published by
29910 + * the Free Software Foundation; either version 2 of the License, or
29911 + * (at your option) any later version.
29913 + * This program is distributed in the hope that it will be useful,
29914 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29915 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29916 + * GNU General Public License for more details.
29918 + * You should have received a copy of the GNU General Public License
29919 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29923 + * sub-routines for VFS
29926 +#ifndef __AUFS_VFSUB_H__
29927 +#define __AUFS_VFSUB_H__
29931 +#include <linux/fs.h>
29932 +#include <linux/lglock.h>
29933 +#include <linux/mount.h>
29934 +#include "debug.h"
29936 +/* copied from linux/fs/internal.h */
29937 +/* todo: BAD approach!! */
29938 +extern void __mnt_drop_write(struct vfsmount *);
29939 +extern spinlock_t inode_sb_list_lock;
29941 +/* ---------------------------------------------------------------------- */
29943 +/* lock subclass for lower inode */
29944 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
29945 +/* reduce? gave up. */
29947 + AuLsc_I_Begin = I_MUTEX_NONDIR2, /* 4 */
29948 + AuLsc_I_PARENT, /* lower inode, parent first */
29949 + AuLsc_I_PARENT2, /* copyup dirs */
29950 + AuLsc_I_PARENT3, /* copyup wh */
29956 +/* to debug easier, do not make them inlined functions */
29957 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
29958 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
29960 +/* ---------------------------------------------------------------------- */
29962 +static inline void vfsub_drop_nlink(struct inode *inode)
29964 + AuDebugOn(!inode->i_nlink);
29965 + drop_nlink(inode);
29968 +static inline void vfsub_dead_dir(struct inode *inode)
29970 + AuDebugOn(!S_ISDIR(inode->i_mode));
29971 + inode->i_flags |= S_DEAD;
29972 + clear_nlink(inode);
29975 +static inline int vfsub_native_ro(struct inode *inode)
29977 + return (inode->i_sb->s_flags & MS_RDONLY)
29978 + || IS_RDONLY(inode)
29979 + /* || IS_APPEND(inode) */
29980 + || IS_IMMUTABLE(inode);
29983 +/* ---------------------------------------------------------------------- */
29985 +int vfsub_update_h_iattr(struct path *h_path, int *did);
29986 +struct file *vfsub_dentry_open(struct path *path, int flags);
29987 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
29988 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
29990 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
29993 +struct vfsub_lkup_one_args {
29994 + struct dentry **errp;
29995 + struct qstr *name;
29996 + struct dentry *parent;
29999 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
30000 + struct dentry *parent)
30002 + return vfsub_lookup_one_len(name->name, parent, name->len);
30005 +void vfsub_call_lkup_one(void *args);
30007 +/* ---------------------------------------------------------------------- */
30009 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
30014 + err = mnt_want_write(mnt);
30019 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
30022 + mnt_drop_write(mnt);
30026 +static inline void vfsub_mnt_drop_write_file(struct file *file)
30029 + mnt_drop_write_file(file);
30033 +/* ---------------------------------------------------------------------- */
30036 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30037 + struct dentry *d2, struct au_hinode *hdir2);
30038 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30039 + struct dentry *d2, struct au_hinode *hdir2);
30041 +int vfsub_create(struct inode *dir, struct path *path, int mode,
30043 +int vfsub_symlink(struct inode *dir, struct path *path,
30044 + const char *symname);
30045 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
30046 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
30047 + struct path *path, struct inode **delegated_inode);
30048 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
30049 + struct inode *hdir, struct path *path,
30050 + struct inode **delegated_inode);
30051 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
30052 +int vfsub_rmdir(struct inode *dir, struct path *path);
30054 +/* ---------------------------------------------------------------------- */
30056 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30058 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30060 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30062 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
30064 +int vfsub_flush(struct file *file, fl_owner_t id);
30065 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
30067 +/* just for type-check */
30068 +static inline filldir_t au_diractor(int (*func)(struct dir_context *,
30069 + const char *, int, loff_t, u64,
30072 + return (filldir_t)func;
30076 +static inline loff_t vfsub_f_size_read(struct file *file)
30078 + return i_size_read(file_inode(file));
30081 +static inline unsigned int vfsub_file_flags(struct file *file)
30083 + unsigned int flags;
30085 + spin_lock(&file->f_lock);
30086 + flags = file->f_flags;
30087 + spin_unlock(&file->f_lock);
30092 +static inline void vfsub_file_accessed(struct file *h_file)
30094 + file_accessed(h_file);
30095 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
30098 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
30099 + struct dentry *h_dentry)
30101 + struct path h_path = {
30102 + .dentry = h_dentry,
30105 + touch_atime(&h_path);
30106 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
30109 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
30112 + return update_time(h_inode, ts, flags);
30113 + /* no vfsub_update_h_iattr() since we don't have struct path */
30116 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30117 + struct pipe_inode_info *pipe, size_t len,
30118 + unsigned int flags);
30119 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30120 + loff_t *ppos, size_t len, unsigned int flags);
30122 +static inline long vfsub_truncate(struct path *path, loff_t length)
30127 + err = vfs_truncate(path, length);
30132 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30133 + struct file *h_file);
30134 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
30136 +/* ---------------------------------------------------------------------- */
30138 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
30143 + err = vfs_llseek(file, offset, origin);
30148 +/* ---------------------------------------------------------------------- */
30150 +/* dirty workaround for strict type of fmode_t */
30156 +static inline unsigned int vfsub_fmode_to_uint(fmode_t fm)
30158 + union vfsub_fmu u = {
30162 + BUILD_BUG_ON(sizeof(u.fm) != sizeof(u.ui));
30167 +static inline fmode_t vfsub_uint_to_fmode(unsigned int ui)
30169 + union vfsub_fmu u = {
30176 +/* ---------------------------------------------------------------------- */
30178 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
30179 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
30180 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30181 + struct inode **delegated_inode);
30182 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30183 + struct inode **delegated_inode);
30184 +int vfsub_unlink(struct inode *dir, struct path *path,
30185 + struct inode **delegated_inode, int force);
30187 +#endif /* __KERNEL__ */
30188 +#endif /* __AUFS_VFSUB_H__ */
30189 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
30190 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
30191 +++ linux/fs/aufs/wbr_policy.c 2014-08-14 10:15:45.131942973 +0200
30194 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30196 + * This program, aufs is free software; you can redistribute it and/or modify
30197 + * it under the terms of the GNU General Public License as published by
30198 + * the Free Software Foundation; either version 2 of the License, or
30199 + * (at your option) any later version.
30201 + * This program is distributed in the hope that it will be useful,
30202 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30203 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30204 + * GNU General Public License for more details.
30206 + * You should have received a copy of the GNU General Public License
30207 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30211 + * policies for selecting one among multiple writable branches
30214 +#include <linux/statfs.h>
30217 +/* subset of cpup_attr() */
30218 +static noinline_for_stack
30219 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
30223 + struct inode *h_isrc;
30225 + h_isrc = h_src->d_inode;
30226 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
30227 + ia.ia_mode = h_isrc->i_mode;
30228 + ia.ia_uid = h_isrc->i_uid;
30229 + ia.ia_gid = h_isrc->i_gid;
30230 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
30231 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
30232 + /* no delegation since it is just created */
30233 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
30235 + /* is this nfs only? */
30236 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
30237 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
30238 + ia.ia_mode = h_isrc->i_mode;
30239 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
30245 +#define AuCpdown_PARENT_OPQ 1
30246 +#define AuCpdown_WHED (1 << 1)
30247 +#define AuCpdown_MADE_DIR (1 << 2)
30248 +#define AuCpdown_DIROPQ (1 << 3)
30249 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
30250 +#define au_fset_cpdown(flags, name) \
30251 + do { (flags) |= AuCpdown_##name; } while (0)
30252 +#define au_fclr_cpdown(flags, name) \
30253 + do { (flags) &= ~AuCpdown_##name; } while (0)
30255 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
30256 + unsigned int *flags)
30259 + struct dentry *opq_dentry;
30261 + opq_dentry = au_diropq_create(dentry, bdst);
30262 + err = PTR_ERR(opq_dentry);
30263 + if (IS_ERR(opq_dentry))
30265 + dput(opq_dentry);
30266 + au_fset_cpdown(*flags, DIROPQ);
30272 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
30273 + struct inode *dir, aufs_bindex_t bdst)
30276 + struct path h_path;
30277 + struct au_branch *br;
30279 + br = au_sbr(dentry->d_sb, bdst);
30280 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
30281 + err = PTR_ERR(h_path.dentry);
30282 + if (IS_ERR(h_path.dentry))
30286 + if (h_path.dentry->d_inode) {
30287 + h_path.mnt = au_br_mnt(br);
30288 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
30291 + dput(h_path.dentry);
30297 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
30298 + struct au_pin *pin,
30299 + struct dentry *h_parent, void *arg)
30302 + aufs_bindex_t bopq, bstart;
30303 + struct path h_path;
30304 + struct dentry *parent;
30305 + struct inode *h_dir, *h_inode, *inode, *dir;
30306 + unsigned int *flags = arg;
30308 + bstart = au_dbstart(dentry);
30309 + /* dentry is di-locked */
30310 + parent = dget_parent(dentry);
30311 + dir = parent->d_inode;
30312 + h_dir = h_parent->d_inode;
30313 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
30314 + IMustLock(h_dir);
30316 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
30317 + if (unlikely(err < 0))
30319 + h_path.dentry = au_h_dptr(dentry, bdst);
30320 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
30321 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
30322 + S_IRWXU | S_IRUGO | S_IXUGO);
30323 + if (unlikely(err))
30325 + au_fset_cpdown(*flags, MADE_DIR);
30327 + bopq = au_dbdiropq(dentry);
30328 + au_fclr_cpdown(*flags, WHED);
30329 + au_fclr_cpdown(*flags, DIROPQ);
30330 + if (au_dbwh(dentry) == bdst)
30331 + au_fset_cpdown(*flags, WHED);
30332 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
30333 + au_fset_cpdown(*flags, PARENT_OPQ);
30334 + h_inode = h_path.dentry->d_inode;
30335 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
30336 + if (au_ftest_cpdown(*flags, WHED)) {
30337 + err = au_cpdown_dir_opq(dentry, bdst, flags);
30338 + if (unlikely(err)) {
30339 + mutex_unlock(&h_inode->i_mutex);
30344 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
30345 + mutex_unlock(&h_inode->i_mutex);
30346 + if (unlikely(err))
30349 + if (au_ftest_cpdown(*flags, WHED)) {
30350 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
30351 + if (unlikely(err))
30355 + inode = dentry->d_inode;
30356 + if (au_ibend(inode) < bdst)
30357 + au_set_ibend(inode, bdst);
30358 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
30359 + au_hi_flags(inode, /*isdir*/1));
30360 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
30361 + goto out; /* success */
30365 + if (au_ftest_cpdown(*flags, DIROPQ)) {
30366 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
30367 + rerr = au_diropq_remove(dentry, bdst);
30368 + mutex_unlock(&h_inode->i_mutex);
30369 + if (unlikely(rerr)) {
30370 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
30371 + dentry, bdst, rerr);
30377 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
30378 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
30379 + if (unlikely(rerr)) {
30380 + AuIOErr("failed removing %pd b%d (%d)\n",
30381 + dentry, bdst, rerr);
30386 + au_set_h_dptr(dentry, bdst, NULL);
30387 + if (au_dbend(dentry) == bdst)
30388 + au_update_dbend(dentry);
30394 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
30397 + unsigned int flags;
30400 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
30405 +/* ---------------------------------------------------------------------- */
30407 +/* policies for create */
30409 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
30411 + int err, i, j, ndentry;
30412 + aufs_bindex_t bopq;
30413 + struct au_dcsub_pages dpages;
30414 + struct au_dpage *dpage;
30415 + struct dentry **dentries, *parent, *d;
30417 + err = au_dpages_init(&dpages, GFP_NOFS);
30418 + if (unlikely(err))
30420 + parent = dget_parent(dentry);
30421 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
30422 + if (unlikely(err))
30426 + for (i = 0; i < dpages.ndpage; i++) {
30427 + dpage = dpages.dpages + i;
30428 + dentries = dpage->dentries;
30429 + ndentry = dpage->ndentry;
30430 + for (j = 0; j < ndentry; j++) {
30432 + di_read_lock_parent2(d, !AuLock_IR);
30433 + bopq = au_dbdiropq(d);
30434 + di_read_unlock(d, !AuLock_IR);
30435 + if (bopq >= 0 && bopq < err)
30442 + au_dpages_free(&dpages);
30447 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
30449 + for (; bindex >= 0; bindex--)
30450 + if (!au_br_rdonly(au_sbr(sb, bindex)))
30455 +/* top down parent */
30456 +static int au_wbr_create_tdp(struct dentry *dentry,
30457 + unsigned int flags __maybe_unused)
30460 + aufs_bindex_t bstart, bindex;
30461 + struct super_block *sb;
30462 + struct dentry *parent, *h_parent;
30464 + sb = dentry->d_sb;
30465 + bstart = au_dbstart(dentry);
30467 + if (!au_br_rdonly(au_sbr(sb, bstart)))
30471 + parent = dget_parent(dentry);
30472 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
30473 + h_parent = au_h_dptr(parent, bindex);
30474 + if (!h_parent || !h_parent->d_inode)
30477 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
30484 + /* bottom up here */
30485 + if (unlikely(err < 0)) {
30486 + err = au_wbr_bu(sb, bstart - 1);
30488 + err = au_wbr_nonopq(dentry, err);
30492 + AuDbg("b%d\n", err);
30496 +/* ---------------------------------------------------------------------- */
30498 +/* an exception for the policy other than tdp */
30499 +static int au_wbr_create_exp(struct dentry *dentry)
30502 + aufs_bindex_t bwh, bdiropq;
30503 + struct dentry *parent;
30506 + bwh = au_dbwh(dentry);
30507 + parent = dget_parent(dentry);
30508 + bdiropq = au_dbdiropq(parent);
30510 + if (bdiropq >= 0)
30511 + err = min(bdiropq, bwh);
30514 + AuDbg("%d\n", err);
30515 + } else if (bdiropq >= 0) {
30517 + AuDbg("%d\n", err);
30522 + err = au_wbr_nonopq(dentry, err);
30524 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
30527 + AuDbg("%d\n", err);
30531 +/* ---------------------------------------------------------------------- */
30534 +static int au_wbr_create_init_rr(struct super_block *sb)
30538 + err = au_wbr_bu(sb, au_sbend(sb));
30539 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
30542 + AuDbg("b%d\n", err);
30546 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
30550 + aufs_bindex_t bindex, bend;
30551 + struct super_block *sb;
30554 + err = au_wbr_create_exp(dentry);
30558 + sb = dentry->d_sb;
30559 + next = &au_sbi(sb)->si_wbr_rr_next;
30560 + bend = au_sbend(sb);
30562 + for (bindex = 0; bindex <= bend; bindex++) {
30563 + if (!au_ftest_wbr(flags, DIR)) {
30564 + err = atomic_dec_return(next) + 1;
30565 + /* modulo for 0 is meaningless */
30566 + if (unlikely(!err))
30567 + err = atomic_dec_return(next) + 1;
30569 + err = atomic_read(next);
30570 + AuDbg("%d\n", err);
30573 + AuDbg("%d\n", err);
30574 + if (!au_br_rdonly(au_sbr(sb, err)))
30580 + err = au_wbr_nonopq(dentry, err);
30583 + AuDbg("%d\n", err);
30587 +/* ---------------------------------------------------------------------- */
30589 +/* most free space */
30590 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
30592 + struct super_block *sb;
30593 + struct au_branch *br;
30594 + struct au_wbr_mfs *mfs;
30595 + struct dentry *h_parent;
30596 + aufs_bindex_t bindex, bend;
30598 + unsigned long long b, bavail;
30599 + struct path h_path;
30600 + /* reduce the stack usage */
30601 + struct kstatfs *st;
30603 + st = kmalloc(sizeof(*st), GFP_NOFS);
30604 + if (unlikely(!st)) {
30605 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
30610 + sb = dentry->d_sb;
30611 + mfs = &au_sbi(sb)->si_wbr_mfs;
30612 + MtxMustLock(&mfs->mfs_lock);
30613 + mfs->mfs_bindex = -EROFS;
30614 + mfs->mfsrr_bytes = 0;
30617 + bend = au_sbend(sb);
30619 + bindex = au_dbstart(parent);
30620 + bend = au_dbtaildir(parent);
30623 + for (; bindex <= bend; bindex++) {
30625 + h_parent = au_h_dptr(parent, bindex);
30626 + if (!h_parent || !h_parent->d_inode)
30629 + br = au_sbr(sb, bindex);
30630 + if (au_br_rdonly(br))
30633 + /* sb->s_root for NFS is unreliable */
30634 + h_path.mnt = au_br_mnt(br);
30635 + h_path.dentry = h_path.mnt->mnt_root;
30636 + err = vfs_statfs(&h_path, st);
30637 + if (unlikely(err)) {
30638 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
30642 + /* when the available size is equal, select the lower one */
30643 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
30644 + || sizeof(b) < sizeof(st->f_bsize));
30645 + b = st->f_bavail * st->f_bsize;
30646 + br->br_wbr->wbr_bytes = b;
30647 + if (b >= bavail) {
30649 + mfs->mfs_bindex = bindex;
30650 + mfs->mfs_jiffy = jiffies;
30654 + mfs->mfsrr_bytes = bavail;
30655 + AuDbg("b%d\n", mfs->mfs_bindex);
30659 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
30662 + struct dentry *parent;
30663 + struct super_block *sb;
30664 + struct au_wbr_mfs *mfs;
30666 + err = au_wbr_create_exp(dentry);
30670 + sb = dentry->d_sb;
30672 + if (au_ftest_wbr(flags, PARENT))
30673 + parent = dget_parent(dentry);
30674 + mfs = &au_sbi(sb)->si_wbr_mfs;
30675 + mutex_lock(&mfs->mfs_lock);
30676 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
30677 + || mfs->mfs_bindex < 0
30678 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
30679 + au_mfs(dentry, parent);
30680 + mutex_unlock(&mfs->mfs_lock);
30681 + err = mfs->mfs_bindex;
30685 + err = au_wbr_nonopq(dentry, err);
30688 + AuDbg("b%d\n", err);
30692 +static int au_wbr_create_init_mfs(struct super_block *sb)
30694 + struct au_wbr_mfs *mfs;
30696 + mfs = &au_sbi(sb)->si_wbr_mfs;
30697 + mutex_init(&mfs->mfs_lock);
30698 + mfs->mfs_jiffy = 0;
30699 + mfs->mfs_bindex = -EROFS;
30704 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
30706 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
30710 +/* ---------------------------------------------------------------------- */
30712 +/* most free space and then round robin */
30713 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
30716 + struct au_wbr_mfs *mfs;
30718 + err = au_wbr_create_mfs(dentry, flags);
30720 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
30721 + mutex_lock(&mfs->mfs_lock);
30722 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
30723 + err = au_wbr_create_rr(dentry, flags);
30724 + mutex_unlock(&mfs->mfs_lock);
30727 + AuDbg("b%d\n", err);
30731 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
30735 + au_wbr_create_init_mfs(sb); /* ignore */
30736 + err = au_wbr_create_init_rr(sb);
30741 +/* ---------------------------------------------------------------------- */
30743 +/* top down parent and most free space */
30744 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
30747 + unsigned long long b;
30748 + aufs_bindex_t bindex, bstart, bend;
30749 + struct super_block *sb;
30750 + struct dentry *parent, *h_parent;
30751 + struct au_branch *br;
30753 + err = au_wbr_create_tdp(dentry, flags);
30754 + if (unlikely(err < 0))
30756 + parent = dget_parent(dentry);
30757 + bstart = au_dbstart(parent);
30758 + bend = au_dbtaildir(parent);
30759 + if (bstart == bend)
30760 + goto out_parent; /* success */
30762 + e2 = au_wbr_create_mfs(dentry, flags);
30764 + goto out_parent; /* success */
30766 + /* when the available size is equal, select upper one */
30767 + sb = dentry->d_sb;
30768 + br = au_sbr(sb, err);
30769 + b = br->br_wbr->wbr_bytes;
30770 + AuDbg("b%d, %llu\n", err, b);
30772 + for (bindex = bstart; bindex <= bend; bindex++) {
30773 + h_parent = au_h_dptr(parent, bindex);
30774 + if (!h_parent || !h_parent->d_inode)
30777 + br = au_sbr(sb, bindex);
30778 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
30779 + b = br->br_wbr->wbr_bytes;
30781 + AuDbg("b%d, %llu\n", err, b);
30786 + err = au_wbr_nonopq(dentry, err);
30791 + AuDbg("b%d\n", err);
30795 +/* ---------------------------------------------------------------------- */
30798 + * - top down parent
30799 + * - most free space with parent
30800 + * - most free space round-robin regardless parent
30802 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
30805 + unsigned long long watermark;
30806 + struct super_block *sb;
30807 + struct au_branch *br;
30808 + struct au_wbr_mfs *mfs;
30810 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
30811 + if (unlikely(err < 0))
30814 + sb = dentry->d_sb;
30815 + br = au_sbr(sb, err);
30816 + mfs = &au_sbi(sb)->si_wbr_mfs;
30817 + mutex_lock(&mfs->mfs_lock);
30818 + watermark = mfs->mfsrr_watermark;
30819 + mutex_unlock(&mfs->mfs_lock);
30820 + if (br->br_wbr->wbr_bytes < watermark)
30821 + /* regardless the parent dir */
30822 + err = au_wbr_create_mfsrr(dentry, flags);
30825 + AuDbg("b%d\n", err);
30829 +/* ---------------------------------------------------------------------- */
30831 +/* policies for copyup */
30833 +/* top down parent */
30834 +static int au_wbr_copyup_tdp(struct dentry *dentry)
30836 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
30839 +/* bottom up parent */
30840 +static int au_wbr_copyup_bup(struct dentry *dentry)
30843 + aufs_bindex_t bindex, bstart;
30844 + struct dentry *parent, *h_parent;
30845 + struct super_block *sb;
30848 + sb = dentry->d_sb;
30849 + parent = dget_parent(dentry);
30850 + bstart = au_dbstart(parent);
30851 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
30852 + h_parent = au_h_dptr(parent, bindex);
30853 + if (!h_parent || !h_parent->d_inode)
30856 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
30863 + /* bottom up here */
30864 + if (unlikely(err < 0))
30865 + err = au_wbr_bu(sb, bstart - 1);
30867 + AuDbg("b%d\n", err);
30872 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
30876 + err = au_wbr_bu(dentry->d_sb, bstart);
30877 + AuDbg("b%d\n", err);
30878 + if (err > bstart)
30879 + err = au_wbr_nonopq(dentry, err);
30881 + AuDbg("b%d\n", err);
30885 +static int au_wbr_copyup_bu(struct dentry *dentry)
30888 + aufs_bindex_t bstart;
30890 + bstart = au_dbstart(dentry);
30891 + err = au_wbr_do_copyup_bu(dentry, bstart);
30895 +/* ---------------------------------------------------------------------- */
30897 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
30898 + [AuWbrCopyup_TDP] = {
30899 + .copyup = au_wbr_copyup_tdp
30901 + [AuWbrCopyup_BUP] = {
30902 + .copyup = au_wbr_copyup_bup
30904 + [AuWbrCopyup_BU] = {
30905 + .copyup = au_wbr_copyup_bu
30909 +struct au_wbr_create_operations au_wbr_create_ops[] = {
30910 + [AuWbrCreate_TDP] = {
30911 + .create = au_wbr_create_tdp
30913 + [AuWbrCreate_RR] = {
30914 + .create = au_wbr_create_rr,
30915 + .init = au_wbr_create_init_rr
30917 + [AuWbrCreate_MFS] = {
30918 + .create = au_wbr_create_mfs,
30919 + .init = au_wbr_create_init_mfs,
30920 + .fin = au_wbr_create_fin_mfs
30922 + [AuWbrCreate_MFSV] = {
30923 + .create = au_wbr_create_mfs,
30924 + .init = au_wbr_create_init_mfs,
30925 + .fin = au_wbr_create_fin_mfs
30927 + [AuWbrCreate_MFSRR] = {
30928 + .create = au_wbr_create_mfsrr,
30929 + .init = au_wbr_create_init_mfsrr,
30930 + .fin = au_wbr_create_fin_mfs
30932 + [AuWbrCreate_MFSRRV] = {
30933 + .create = au_wbr_create_mfsrr,
30934 + .init = au_wbr_create_init_mfsrr,
30935 + .fin = au_wbr_create_fin_mfs
30937 + [AuWbrCreate_PMFS] = {
30938 + .create = au_wbr_create_pmfs,
30939 + .init = au_wbr_create_init_mfs,
30940 + .fin = au_wbr_create_fin_mfs
30942 + [AuWbrCreate_PMFSV] = {
30943 + .create = au_wbr_create_pmfs,
30944 + .init = au_wbr_create_init_mfs,
30945 + .fin = au_wbr_create_fin_mfs
30947 + [AuWbrCreate_PMFSRR] = {
30948 + .create = au_wbr_create_pmfsrr,
30949 + .init = au_wbr_create_init_mfsrr,
30950 + .fin = au_wbr_create_fin_mfs
30952 + [AuWbrCreate_PMFSRRV] = {
30953 + .create = au_wbr_create_pmfsrr,
30954 + .init = au_wbr_create_init_mfsrr,
30955 + .fin = au_wbr_create_fin_mfs
30958 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
30959 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
30960 +++ linux/fs/aufs/whout.c 2014-08-14 10:15:45.131942973 +0200
30963 + * Copyright (C) 2005-2014 Junjiro R. Okajima
30965 + * This program, aufs is free software; you can redistribute it and/or modify
30966 + * it under the terms of the GNU General Public License as published by
30967 + * the Free Software Foundation; either version 2 of the License, or
30968 + * (at your option) any later version.
30970 + * This program is distributed in the hope that it will be useful,
30971 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30972 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30973 + * GNU General Public License for more details.
30975 + * You should have received a copy of the GNU General Public License
30976 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30980 + * whiteout for logical deletion and opaque directory
30985 +#define WH_MASK S_IRUGO
30988 + * If a directory contains this file, then it is opaque. We start with the
30989 + * .wh. flag so that it is blocked by lookup.
30991 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
30992 + sizeof(AUFS_WH_DIROPQ) - 1);
30995 + * generate whiteout name, which is NOT terminated by NULL.
30996 + * @name: original d_name.name
30997 + * @len: original d_name.len
30998 + * @wh: whiteout qstr
30999 + * returns zero when succeeds, otherwise error.
31000 + * succeeded value as wh->name should be freed by kfree().
31002 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
31006 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
31007 + return -ENAMETOOLONG;
31009 + wh->len = name->len + AUFS_WH_PFX_LEN;
31010 + p = kmalloc(wh->len, GFP_NOFS);
31013 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
31014 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
31021 +/* ---------------------------------------------------------------------- */
31024 + * test if the @wh_name exists under @h_parent.
31025 + * @try_sio specifies the necessary of super-io.
31027 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
31030 + struct dentry *wh_dentry;
31033 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
31035 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
31036 + err = PTR_ERR(wh_dentry);
31037 + if (IS_ERR(wh_dentry))
31041 + if (!wh_dentry->d_inode)
31042 + goto out_wh; /* success */
31045 + if (S_ISREG(wh_dentry->d_inode->i_mode))
31046 + goto out_wh; /* success */
31049 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
31050 + wh_dentry, wh_dentry->d_inode->i_mode);
31059 + * test if the @h_dentry sets opaque or not.
31061 +int au_diropq_test(struct dentry *h_dentry)
31064 + struct inode *h_dir;
31066 + h_dir = h_dentry->d_inode;
31067 + err = au_wh_test(h_dentry, &diropq_name,
31068 + au_test_h_perm_sio(h_dir, MAY_EXEC));
31073 + * returns a negative dentry whose name is unique and temporary.
31075 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
31076 + struct qstr *prefix)
31078 + struct dentry *dentry;
31080 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
31082 + /* strict atomic_t is unnecessary here */
31083 + static unsigned short cnt;
31086 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
31089 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
31090 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
31091 + dentry = ERR_PTR(-ENAMETOOLONG);
31092 + if (unlikely(qs.len > NAME_MAX))
31094 + dentry = ERR_PTR(-ENOMEM);
31095 + name = kmalloc(qs.len + 1, GFP_NOFS);
31096 + if (unlikely(!name))
31100 + /* doubly whiteout-ed */
31101 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
31102 + p = name + AUFS_WH_PFX_LEN * 2;
31103 + memcpy(p, prefix->name, prefix->len);
31104 + p += prefix->len;
31106 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
31109 + for (i = 0; i < 3; i++) {
31110 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
31111 + dentry = au_sio_lkup_one(&qs, h_parent);
31112 + if (IS_ERR(dentry) || !dentry->d_inode)
31116 + /* pr_warn("could not get random name\n"); */
31117 + dentry = ERR_PTR(-EEXIST);
31118 + AuDbg("%.*s\n", AuLNPair(&qs));
31122 + if (name != defname)
31125 + AuTraceErrPtr(dentry);
31130 + * rename the @h_dentry on @br to the whiteouted temporary name.
31132 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
31135 + struct path h_path = {
31136 + .mnt = au_br_mnt(br)
31138 + struct inode *h_dir, *delegated;
31139 + struct dentry *h_parent;
31141 + h_parent = h_dentry->d_parent; /* dir inode is locked */
31142 + h_dir = h_parent->d_inode;
31143 + IMustLock(h_dir);
31145 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
31146 + err = PTR_ERR(h_path.dentry);
31147 + if (IS_ERR(h_path.dentry))
31150 + /* under the same dir, no need to lock_rename() */
31151 + delegated = NULL;
31152 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
31154 + if (unlikely(err == -EWOULDBLOCK)) {
31155 + pr_warn("cannot retry for NFSv4 delegation"
31156 + " for an internal rename\n");
31159 + dput(h_path.dentry);
31166 +/* ---------------------------------------------------------------------- */
31168 + * functions for removing a whiteout
31171 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
31174 + struct inode *delegated;
31177 + * forces superio when the dir has a sticky bit.
31178 + * this may be a violation of unix fs semantics.
31180 + force = (h_dir->i_mode & S_ISVTX)
31181 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
31182 + delegated = NULL;
31183 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
31184 + if (unlikely(err == -EWOULDBLOCK)) {
31185 + pr_warn("cannot retry for NFSv4 delegation"
31186 + " for an internal unlink\n");
31192 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
31193 + struct dentry *dentry)
31197 + err = do_unlink_wh(h_dir, h_path);
31198 + if (!err && dentry)
31199 + au_set_dbwh(dentry, -1);
31204 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
31205 + struct au_branch *br)
31208 + struct path h_path = {
31209 + .mnt = au_br_mnt(br)
31213 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
31214 + if (IS_ERR(h_path.dentry))
31215 + err = PTR_ERR(h_path.dentry);
31217 + if (h_path.dentry->d_inode
31218 + && S_ISREG(h_path.dentry->d_inode->i_mode))
31219 + err = do_unlink_wh(h_parent->d_inode, &h_path);
31220 + dput(h_path.dentry);
31226 +/* ---------------------------------------------------------------------- */
31228 + * initialize/clean whiteout for a branch
31231 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
31235 + struct inode *delegated;
31237 + if (!whpath->dentry->d_inode)
31241 + err = vfsub_rmdir(h_dir, whpath);
31243 + delegated = NULL;
31244 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
31245 + if (unlikely(err == -EWOULDBLOCK)) {
31246 + pr_warn("cannot retry for NFSv4 delegation"
31247 + " for an internal unlink\n");
31251 + if (unlikely(err))
31252 + pr_warn("failed removing %pd (%d), ignored.\n",
31253 + whpath->dentry, err);
31256 +static int test_linkable(struct dentry *h_root)
31258 + struct inode *h_dir = h_root->d_inode;
31260 + if (h_dir->i_op->link)
31263 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
31264 + h_root, au_sbtype(h_root->d_sb));
31268 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
31269 +static int au_whdir(struct inode *h_dir, struct path *path)
31274 + if (!path->dentry->d_inode) {
31275 + int mode = S_IRWXU;
31277 + if (au_test_nfs(path->dentry->d_sb))
31279 + err = vfsub_mkdir(h_dir, path, mode);
31280 + } else if (S_ISDIR(path->dentry->d_inode->i_mode))
31283 + pr_err("unknown %pd exists\n", path->dentry);
31288 +struct au_wh_base {
31289 + const struct qstr *name;
31290 + struct dentry *dentry;
31293 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
31294 + struct path *h_path)
31296 + h_path->dentry = base[AuBrWh_BASE].dentry;
31297 + au_wh_clean(h_dir, h_path, /*isdir*/0);
31298 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31299 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31300 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31301 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31305 + * returns tri-state,
31306 + * minus: error, caller should print the mesage
31308 + * plus: error, caller should NOT print the mesage
31310 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
31311 + int do_plink, struct au_wh_base base[],
31312 + struct path *h_path)
31315 + struct inode *h_dir;
31317 + h_dir = h_root->d_inode;
31318 + h_path->dentry = base[AuBrWh_BASE].dentry;
31319 + au_wh_clean(h_dir, h_path, /*isdir*/0);
31320 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31322 + err = test_linkable(h_root);
31323 + if (unlikely(err)) {
31328 + err = au_whdir(h_dir, h_path);
31329 + if (unlikely(err))
31331 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
31333 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31334 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31335 + err = au_whdir(h_dir, h_path);
31336 + if (unlikely(err))
31338 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
31345 + * for the moment, aufs supports the branch filesystem which does not support
31346 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
31347 + * copyup failed. finally, such filesystem will not be used as the writable
31350 + * returns tri-state, see above.
31352 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
31353 + int do_plink, struct au_wh_base base[],
31354 + struct path *h_path)
31357 + struct inode *h_dir;
31359 + WbrWhMustWriteLock(wbr);
31361 + err = test_linkable(h_root);
31362 + if (unlikely(err)) {
31368 + * todo: should this create be done in /sbin/mount.aufs helper?
31371 + h_dir = h_root->d_inode;
31372 + if (!base[AuBrWh_BASE].dentry->d_inode) {
31373 + h_path->dentry = base[AuBrWh_BASE].dentry;
31374 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
31375 + } else if (S_ISREG(base[AuBrWh_BASE].dentry->d_inode->i_mode))
31378 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
31379 + if (unlikely(err))
31382 + h_path->dentry = base[AuBrWh_PLINK].dentry;
31384 + err = au_whdir(h_dir, h_path);
31385 + if (unlikely(err))
31387 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
31389 + au_wh_clean(h_dir, h_path, /*isdir*/1);
31390 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
31392 + h_path->dentry = base[AuBrWh_ORPH].dentry;
31393 + err = au_whdir(h_dir, h_path);
31394 + if (unlikely(err))
31396 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
31403 + * initialize the whiteout base file/dir for @br.
31405 +int au_wh_init(struct au_branch *br, struct super_block *sb)
31408 + const unsigned char do_plink
31409 + = !!au_opt_test(au_mntflags(sb), PLINK);
31410 + struct inode *h_dir;
31411 + struct path path = br->br_path;
31412 + struct dentry *h_root = path.dentry;
31413 + struct au_wbr *wbr = br->br_wbr;
31414 + static const struct qstr base_name[] = {
31415 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
31416 + sizeof(AUFS_BASE_NAME) - 1),
31417 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
31418 + sizeof(AUFS_PLINKDIR_NAME) - 1),
31419 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
31420 + sizeof(AUFS_ORPHDIR_NAME) - 1)
31422 + struct au_wh_base base[] = {
31423 + [AuBrWh_BASE] = {
31424 + .name = base_name + AuBrWh_BASE,
31427 + [AuBrWh_PLINK] = {
31428 + .name = base_name + AuBrWh_PLINK,
31431 + [AuBrWh_ORPH] = {
31432 + .name = base_name + AuBrWh_ORPH,
31438 + WbrWhMustWriteLock(wbr);
31440 + for (i = 0; i < AuBrWh_Last; i++) {
31441 + /* doubly whiteouted */
31442 + struct dentry *d;
31444 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
31445 + err = PTR_ERR(d);
31449 + base[i].dentry = d;
31451 + && wbr->wbr_wh[i]
31452 + && wbr->wbr_wh[i] != base[i].dentry);
31456 + for (i = 0; i < AuBrWh_Last; i++) {
31457 + dput(wbr->wbr_wh[i]);
31458 + wbr->wbr_wh[i] = NULL;
31462 + if (!au_br_writable(br->br_perm)) {
31463 + h_dir = h_root->d_inode;
31464 + au_wh_init_ro(h_dir, base, &path);
31465 + } else if (!au_br_wh_linkable(br->br_perm)) {
31466 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
31472 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
31478 + goto out; /* success */
31481 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
31482 + err, h_root, au_sbtype(h_root->d_sb));
31484 + for (i = 0; i < AuBrWh_Last; i++)
31485 + dput(base[i].dentry);
31489 +/* ---------------------------------------------------------------------- */
31491 + * whiteouts are all hard-linked usually.
31492 + * when its link count reaches a ceiling, we create a new whiteout base
31493 + * asynchronously.
31496 +struct reinit_br_wh {
31497 + struct super_block *sb;
31498 + struct au_branch *br;
31501 +static void reinit_br_wh(void *arg)
31504 + aufs_bindex_t bindex;
31505 + struct path h_path;
31506 + struct reinit_br_wh *a = arg;
31507 + struct au_wbr *wbr;
31508 + struct inode *dir, *delegated;
31509 + struct dentry *h_root;
31510 + struct au_hinode *hdir;
31513 + wbr = a->br->br_wbr;
31514 + /* big aufs lock */
31515 + si_noflush_write_lock(a->sb);
31516 + if (!au_br_writable(a->br->br_perm))
31518 + bindex = au_br_index(a->sb, a->br->br_id);
31519 + if (unlikely(bindex < 0))
31522 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
31523 + dir = a->sb->s_root->d_inode;
31524 + hdir = au_hi(dir, bindex);
31525 + h_root = au_h_dptr(a->sb->s_root, bindex);
31526 + AuDebugOn(h_root != au_br_dentry(a->br));
31528 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
31529 + wbr_wh_write_lock(wbr);
31530 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
31533 + h_path.dentry = wbr->wbr_whbase;
31534 + h_path.mnt = au_br_mnt(a->br);
31535 + delegated = NULL;
31536 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
31538 + if (unlikely(err == -EWOULDBLOCK)) {
31539 + pr_warn("cannot retry for NFSv4 delegation"
31540 + " for an internal unlink\n");
31544 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
31547 + dput(wbr->wbr_whbase);
31548 + wbr->wbr_whbase = NULL;
31550 + err = au_wh_init(a->br, a->sb);
31551 + wbr_wh_write_unlock(wbr);
31552 + au_hn_imtx_unlock(hdir);
31553 + di_read_unlock(a->sb->s_root, AuLock_IR);
31555 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
31559 + atomic_dec(&wbr->wbr_wh_running);
31560 + atomic_dec(&a->br->br_count);
31561 + si_write_unlock(a->sb);
31562 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
31564 + if (unlikely(err))
31565 + AuIOErr("err %d\n", err);
31568 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
31570 + int do_dec, wkq_err;
31571 + struct reinit_br_wh *arg;
31574 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
31577 + /* ignore ENOMEM */
31578 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
31581 + * dec(wh_running), kfree(arg) and dec(br_count)
31582 + * in reinit function
31586 + atomic_inc(&br->br_count);
31587 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
31588 + if (unlikely(wkq_err)) {
31589 + atomic_dec(&br->br_wbr->wbr_wh_running);
31590 + atomic_dec(&br->br_count);
31598 + atomic_dec(&br->br_wbr->wbr_wh_running);
31601 +/* ---------------------------------------------------------------------- */
31604 + * create the whiteout @wh.
31606 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
31607 + struct dentry *wh)
31610 + struct path h_path = {
31613 + struct au_branch *br;
31614 + struct au_wbr *wbr;
31615 + struct dentry *h_parent;
31616 + struct inode *h_dir, *delegated;
31618 + h_parent = wh->d_parent; /* dir inode is locked */
31619 + h_dir = h_parent->d_inode;
31620 + IMustLock(h_dir);
31622 + br = au_sbr(sb, bindex);
31623 + h_path.mnt = au_br_mnt(br);
31624 + wbr = br->br_wbr;
31625 + wbr_wh_read_lock(wbr);
31626 + if (wbr->wbr_whbase) {
31627 + delegated = NULL;
31628 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
31629 + if (unlikely(err == -EWOULDBLOCK)) {
31630 + pr_warn("cannot retry for NFSv4 delegation"
31631 + " for an internal link\n");
31634 + if (!err || err != -EMLINK)
31637 + /* link count full. re-initialize br_whbase. */
31638 + kick_reinit_br_wh(sb, br);
31641 + /* return this error in this context */
31642 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
31644 + au_fhsm_wrote(sb, bindex, /*force*/0);
31647 + wbr_wh_read_unlock(wbr);
31651 +/* ---------------------------------------------------------------------- */
31654 + * create or remove the diropq.
31656 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
31657 + unsigned int flags)
31659 + struct dentry *opq_dentry, *h_dentry;
31660 + struct super_block *sb;
31661 + struct au_branch *br;
31664 + sb = dentry->d_sb;
31665 + br = au_sbr(sb, bindex);
31666 + h_dentry = au_h_dptr(dentry, bindex);
31667 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
31668 + if (IS_ERR(opq_dentry))
31671 + if (au_ftest_diropq(flags, CREATE)) {
31672 + err = link_or_create_wh(sb, bindex, opq_dentry);
31674 + au_set_dbdiropq(dentry, bindex);
31675 + goto out; /* success */
31678 + struct path tmp = {
31679 + .dentry = opq_dentry,
31680 + .mnt = au_br_mnt(br)
31682 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
31684 + au_set_dbdiropq(dentry, -1);
31686 + dput(opq_dentry);
31687 + opq_dentry = ERR_PTR(err);
31690 + return opq_dentry;
31693 +struct do_diropq_args {
31694 + struct dentry **errp;
31695 + struct dentry *dentry;
31696 + aufs_bindex_t bindex;
31697 + unsigned int flags;
31700 +static void call_do_diropq(void *args)
31702 + struct do_diropq_args *a = args;
31703 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
31706 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
31707 + unsigned int flags)
31709 + struct dentry *diropq, *h_dentry;
31711 + h_dentry = au_h_dptr(dentry, bindex);
31712 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
31713 + diropq = do_diropq(dentry, bindex, flags);
31716 + struct do_diropq_args args = {
31718 + .dentry = dentry,
31719 + .bindex = bindex,
31723 + wkq_err = au_wkq_wait(call_do_diropq, &args);
31724 + if (unlikely(wkq_err))
31725 + diropq = ERR_PTR(wkq_err);
31731 +/* ---------------------------------------------------------------------- */
31734 + * lookup whiteout dentry.
31735 + * @h_parent: lower parent dentry which must exist and be locked
31736 + * @base_name: name of dentry which will be whiteouted
31737 + * returns dentry for whiteout.
31739 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
31740 + struct au_branch *br)
31743 + struct qstr wh_name;
31744 + struct dentry *wh_dentry;
31746 + err = au_wh_name_alloc(&wh_name, base_name);
31747 + wh_dentry = ERR_PTR(err);
31749 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
31750 + kfree(wh_name.name);
31752 + return wh_dentry;
31756 + * link/create a whiteout for @dentry on @bindex.
31758 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
31759 + struct dentry *h_parent)
31761 + struct dentry *wh_dentry;
31762 + struct super_block *sb;
31765 + sb = dentry->d_sb;
31766 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
31767 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
31768 + err = link_or_create_wh(sb, bindex, wh_dentry);
31770 + au_set_dbwh(dentry, bindex);
31771 + au_fhsm_wrote(sb, bindex, /*force*/0);
31774 + wh_dentry = ERR_PTR(err);
31778 + return wh_dentry;
31781 +/* ---------------------------------------------------------------------- */
31783 +/* Delete all whiteouts in this directory on branch bindex. */
31784 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
31785 + aufs_bindex_t bindex, struct au_branch *br)
31788 + unsigned long ul, n;
31789 + struct qstr wh_name;
31791 + struct hlist_head *head;
31792 + struct au_vdir_wh *pos;
31793 + struct au_vdir_destr *str;
31796 + p = (void *)__get_free_page(GFP_NOFS);
31797 + wh_name.name = p;
31798 + if (unlikely(!wh_name.name))
31802 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
31803 + p += AUFS_WH_PFX_LEN;
31804 + n = whlist->nh_num;
31805 + head = whlist->nh_head;
31806 + for (ul = 0; !err && ul < n; ul++, head++) {
31807 + hlist_for_each_entry(pos, head, wh_hash) {
31808 + if (pos->wh_bindex != bindex)
31811 + str = &pos->wh_str;
31812 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
31813 + memcpy(p, str->name, str->len);
31814 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
31815 + err = unlink_wh_name(h_dentry, &wh_name, br);
31820 + AuIOErr("whiteout name too long %.*s\n",
31821 + str->len, str->name);
31826 + free_page((unsigned long)wh_name.name);
31832 +struct del_wh_children_args {
31834 + struct dentry *h_dentry;
31835 + struct au_nhash *whlist;
31836 + aufs_bindex_t bindex;
31837 + struct au_branch *br;
31840 +static void call_del_wh_children(void *args)
31842 + struct del_wh_children_args *a = args;
31843 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
31846 +/* ---------------------------------------------------------------------- */
31848 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
31850 + struct au_whtmp_rmdir *whtmp;
31852 + unsigned int rdhash;
31854 + SiMustAnyLock(sb);
31856 + whtmp = kmalloc(sizeof(*whtmp), gfp);
31857 + if (unlikely(!whtmp)) {
31858 + whtmp = ERR_PTR(-ENOMEM);
31862 + whtmp->dir = NULL;
31863 + whtmp->br = NULL;
31864 + whtmp->wh_dentry = NULL;
31865 + /* no estimation for dir size */
31866 + rdhash = au_sbi(sb)->si_rdhash;
31868 + rdhash = AUFS_RDHASH_DEF;
31869 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
31870 + if (unlikely(err)) {
31872 + whtmp = ERR_PTR(err);
31879 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
31882 + atomic_dec(&whtmp->br->br_count);
31883 + dput(whtmp->wh_dentry);
31884 + iput(whtmp->dir);
31885 + au_nhash_wh_free(&whtmp->whlist);
31890 + * rmdir the whiteouted temporary named dir @h_dentry.
31891 + * @whlist: whiteouted children.
31893 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
31894 + struct dentry *wh_dentry, struct au_nhash *whlist)
31897 + struct path h_tmp;
31898 + struct inode *wh_inode, *h_dir;
31899 + struct au_branch *br;
31901 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
31902 + IMustLock(h_dir);
31904 + br = au_sbr(dir->i_sb, bindex);
31905 + wh_inode = wh_dentry->d_inode;
31906 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
31909 + * someone else might change some whiteouts while we were sleeping.
31910 + * it means this whlist may have an obsoleted entry.
31912 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
31913 + err = del_wh_children(wh_dentry, whlist, bindex, br);
31916 + struct del_wh_children_args args = {
31918 + .h_dentry = wh_dentry,
31919 + .whlist = whlist,
31920 + .bindex = bindex,
31924 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
31925 + if (unlikely(wkq_err))
31928 + mutex_unlock(&wh_inode->i_mutex);
31931 + h_tmp.dentry = wh_dentry;
31932 + h_tmp.mnt = au_br_mnt(br);
31933 + err = vfsub_rmdir(h_dir, &h_tmp);
31937 + if (au_ibstart(dir) == bindex) {
31938 + /* todo: dir->i_mutex is necessary */
31939 + au_cpup_attr_timesizes(dir);
31940 + vfsub_drop_nlink(dir);
31942 + return 0; /* success */
31945 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
31949 +static void call_rmdir_whtmp(void *args)
31952 + aufs_bindex_t bindex;
31953 + struct au_whtmp_rmdir *a = args;
31954 + struct super_block *sb;
31955 + struct dentry *h_parent;
31956 + struct inode *h_dir;
31957 + struct au_hinode *hdir;
31959 + /* rmdir by nfsd may cause deadlock with this i_mutex */
31960 + /* mutex_lock(&a->dir->i_mutex); */
31962 + sb = a->dir->i_sb;
31963 + si_read_lock(sb, !AuLock_FLUSH);
31964 + if (!au_br_writable(a->br->br_perm))
31966 + bindex = au_br_index(sb, a->br->br_id);
31967 + if (unlikely(bindex < 0))
31971 + ii_write_lock_parent(a->dir);
31972 + h_parent = dget_parent(a->wh_dentry);
31973 + h_dir = h_parent->d_inode;
31974 + hdir = au_hi(a->dir, bindex);
31975 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
31976 + if (unlikely(err))
31978 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
31979 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
31982 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
31983 + au_hn_imtx_unlock(hdir);
31984 + vfsub_mnt_drop_write(au_br_mnt(a->br));
31988 + ii_write_unlock(a->dir);
31990 + /* mutex_unlock(&a->dir->i_mutex); */
31991 + au_whtmp_rmdir_free(a);
31992 + si_read_unlock(sb);
31993 + au_nwt_done(&au_sbi(sb)->si_nowait);
31994 + if (unlikely(err))
31995 + AuIOErr("err %d\n", err);
31998 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
31999 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
32002 + struct super_block *sb;
32006 + /* all post-process will be done in do_rmdir_whtmp(). */
32008 + args->dir = au_igrab(dir);
32009 + args->br = au_sbr(sb, bindex);
32010 + atomic_inc(&args->br->br_count);
32011 + args->wh_dentry = dget(wh_dentry);
32012 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
32013 + if (unlikely(wkq_err)) {
32014 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
32015 + au_whtmp_rmdir_free(args);
32018 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
32019 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
32020 +++ linux/fs/aufs/whout.h 2014-08-14 10:15:45.131942973 +0200
32023 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32025 + * This program, aufs is free software; you can redistribute it and/or modify
32026 + * it under the terms of the GNU General Public License as published by
32027 + * the Free Software Foundation; either version 2 of the License, or
32028 + * (at your option) any later version.
32030 + * This program is distributed in the hope that it will be useful,
32031 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32032 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32033 + * GNU General Public License for more details.
32035 + * You should have received a copy of the GNU General Public License
32036 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32040 + * whiteout for logical deletion and opaque directory
32043 +#ifndef __AUFS_WHOUT_H__
32044 +#define __AUFS_WHOUT_H__
32051 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
32053 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
32054 +int au_diropq_test(struct dentry *h_dentry);
32055 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32056 + struct qstr *prefix);
32057 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
32058 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32059 + struct dentry *dentry);
32060 +int au_wh_init(struct au_branch *br, struct super_block *sb);
32062 +/* diropq flags */
32063 +#define AuDiropq_CREATE 1
32064 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
32065 +#define au_fset_diropq(flags, name) \
32066 + do { (flags) |= AuDiropq_##name; } while (0)
32067 +#define au_fclr_diropq(flags, name) \
32068 + do { (flags) &= ~AuDiropq_##name; } while (0)
32070 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32071 + unsigned int flags);
32072 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32073 + struct au_branch *br);
32074 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32075 + struct dentry *h_parent);
32077 +/* real rmdir for the whiteout-ed dir */
32078 +struct au_whtmp_rmdir {
32079 + struct inode *dir;
32080 + struct au_branch *br;
32081 + struct dentry *wh_dentry;
32082 + struct au_nhash whlist;
32085 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
32086 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
32087 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32088 + struct dentry *wh_dentry, struct au_nhash *whlist);
32089 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32090 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
32092 +/* ---------------------------------------------------------------------- */
32094 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
32095 + aufs_bindex_t bindex)
32097 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
32100 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
32102 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
32105 +#endif /* __KERNEL__ */
32106 +#endif /* __AUFS_WHOUT_H__ */
32107 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
32108 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
32109 +++ linux/fs/aufs/wkq.c 2014-08-14 10:16:04.515942371 +0200
32112 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32114 + * This program, aufs is free software; you can redistribute it and/or modify
32115 + * it under the terms of the GNU General Public License as published by
32116 + * the Free Software Foundation; either version 2 of the License, or
32117 + * (at your option) any later version.
32119 + * This program is distributed in the hope that it will be useful,
32120 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32121 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32122 + * GNU General Public License for more details.
32124 + * You should have received a copy of the GNU General Public License
32125 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32129 + * workqueue for asynchronous/super-io operations
32130 + * todo: try new dredential scheme
32133 +#include <linux/module.h>
32136 +/* internal workqueue named AUFS_WKQ_NAME */
32138 +static struct workqueue_struct *au_wkq;
32140 +struct au_wkinfo {
32141 + struct work_struct wk;
32142 + struct kobject *kobj;
32144 + unsigned int flags; /* see wkq.h */
32146 + au_wkq_func_t func;
32149 + struct completion *comp;
32152 +/* ---------------------------------------------------------------------- */
32154 +static void wkq_func(struct work_struct *wk)
32156 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
32158 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
32159 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
32161 + wkinfo->func(wkinfo->args);
32162 + if (au_ftest_wkq(wkinfo->flags, WAIT))
32163 + complete(wkinfo->comp);
32165 + kobject_put(wkinfo->kobj);
32166 + module_put(THIS_MODULE); /* todo: ?? */
32172 + * Since struct completion is large, try allocating it dynamically.
32174 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
32175 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
32177 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32179 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
32181 + init_completion(*comp);
32182 + wkinfo->comp = *comp;
32188 +static void au_wkq_comp_free(struct completion *comp)
32196 +#define AuWkqCompDeclare(name) \
32197 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
32198 + struct completion *comp = &_ ## name
32200 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32202 + wkinfo->comp = *comp;
32206 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
32210 +#endif /* 4KSTACKS */
32212 +static void au_wkq_run(struct au_wkinfo *wkinfo)
32214 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
32215 + if (au_wkq_test()) {
32216 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
32217 + " due to a dead dir by UDBA?\n");
32218 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
32221 + au_dbg_verify_kthread();
32223 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
32224 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
32225 + queue_work(au_wkq, &wkinfo->wk);
32227 + INIT_WORK(&wkinfo->wk, wkq_func);
32228 + schedule_work(&wkinfo->wk);
32233 + * Be careful. It is easy to make deadlock happen.
32234 + * processA: lock, wkq and wait
32235 + * processB: wkq and wait, lock in wkq
32238 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
32241 + AuWkqCompDeclare(comp);
32242 + struct au_wkinfo wkinfo = {
32248 + err = au_wkq_comp_alloc(&wkinfo, &comp);
32250 + au_wkq_run(&wkinfo);
32251 + /* no timeout, no interrupt */
32252 + wait_for_completion(wkinfo.comp);
32253 + au_wkq_comp_free(comp);
32254 + destroy_work_on_stack(&wkinfo.wk);
32262 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
32263 + * problem in a concurrent umounting.
32265 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
32266 + unsigned int flags)
32269 + struct au_wkinfo *wkinfo;
32271 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
32274 + * wkq_func() must free this wkinfo.
32275 + * it highly depends upon the implementation of workqueue.
32278 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
32280 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
32281 + wkinfo->flags = flags & ~AuWkq_WAIT;
32282 + wkinfo->func = func;
32283 + wkinfo->args = args;
32284 + wkinfo->comp = NULL;
32285 + kobject_get(wkinfo->kobj);
32286 + __module_get(THIS_MODULE); /* todo: ?? */
32288 + au_wkq_run(wkinfo);
32291 + au_nwt_done(&au_sbi(sb)->si_nowait);
32297 +/* ---------------------------------------------------------------------- */
32299 +void au_nwt_init(struct au_nowait_tasks *nwt)
32301 + atomic_set(&nwt->nw_len, 0);
32302 + /* smp_mb(); */ /* atomic_set */
32303 + init_waitqueue_head(&nwt->nw_wq);
32306 +void au_wkq_fin(void)
32308 + destroy_workqueue(au_wkq);
32311 +int __init au_wkq_init(void)
32316 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
32317 + if (IS_ERR(au_wkq))
32318 + err = PTR_ERR(au_wkq);
32319 + else if (!au_wkq)
32324 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
32325 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
32326 +++ linux/fs/aufs/wkq.h 2014-01-30 21:10:02.860815399 +0100
32329 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32331 + * This program, aufs is free software; you can redistribute it and/or modify
32332 + * it under the terms of the GNU General Public License as published by
32333 + * the Free Software Foundation; either version 2 of the License, or
32334 + * (at your option) any later version.
32336 + * This program is distributed in the hope that it will be useful,
32337 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32338 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32339 + * GNU General Public License for more details.
32341 + * You should have received a copy of the GNU General Public License
32342 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32346 + * workqueue for asynchronous/super-io operations
32347 + * todo: try new credentials management scheme
32350 +#ifndef __AUFS_WKQ_H__
32351 +#define __AUFS_WKQ_H__
32355 +struct super_block;
32357 +/* ---------------------------------------------------------------------- */
32360 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
32362 +struct au_nowait_tasks {
32364 + wait_queue_head_t nw_wq;
32367 +/* ---------------------------------------------------------------------- */
32369 +typedef void (*au_wkq_func_t)(void *args);
32372 +#define AuWkq_WAIT 1
32373 +#define AuWkq_NEST (1 << 1)
32374 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
32375 +#define au_fset_wkq(flags, name) \
32376 + do { (flags) |= AuWkq_##name; } while (0)
32377 +#define au_fclr_wkq(flags, name) \
32378 + do { (flags) &= ~AuWkq_##name; } while (0)
32380 +#ifndef CONFIG_AUFS_HNOTIFY
32382 +#define AuWkq_NEST 0
32386 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
32387 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
32388 + unsigned int flags);
32389 +void au_nwt_init(struct au_nowait_tasks *nwt);
32390 +int __init au_wkq_init(void);
32391 +void au_wkq_fin(void);
32393 +/* ---------------------------------------------------------------------- */
32395 +static inline int au_wkq_test(void)
32397 + return current->flags & PF_WQ_WORKER;
32400 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
32402 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
32405 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
32407 + if (atomic_dec_and_test(&nwt->nw_len))
32408 + wake_up_all(&nwt->nw_wq);
32411 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
32413 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
32417 +#endif /* __KERNEL__ */
32418 +#endif /* __AUFS_WKQ_H__ */
32419 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
32420 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
32421 +++ linux/fs/aufs/xino.c 2014-08-14 10:16:04.515942371 +0200
32424 + * Copyright (C) 2005-2014 Junjiro R. Okajima
32426 + * This program, aufs is free software; you can redistribute it and/or modify
32427 + * it under the terms of the GNU General Public License as published by
32428 + * the Free Software Foundation; either version 2 of the License, or
32429 + * (at your option) any later version.
32431 + * This program is distributed in the hope that it will be useful,
32432 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32433 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32434 + * GNU General Public License for more details.
32436 + * You should have received a copy of the GNU General Public License
32437 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32441 + * external inode number translation table and bitmap
32444 +#include <linux/seq_file.h>
32445 +#include <linux/statfs.h>
32448 +/* todo: unnecessary to support mmap_sem since kernel-space? */
32449 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
32453 + mm_segment_t oldfs;
32460 + oldfs = get_fs();
32461 + set_fs(KERNEL_DS);
32463 + /* todo: signal_pending? */
32464 + err = func(file, buf.u, size, pos);
32465 + } while (err == -EAGAIN || err == -EINTR);
32468 +#if 0 /* reserved for future use */
32470 + fsnotify_access(file->f_dentry);
32476 +/* ---------------------------------------------------------------------- */
32478 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
32479 + size_t size, loff_t *pos)
32482 + mm_segment_t oldfs;
32485 + const char __user *u;
32489 + oldfs = get_fs();
32490 + set_fs(KERNEL_DS);
32492 + /* todo: signal_pending? */
32493 + err = func(file, buf.u, size, pos);
32494 + } while (err == -EAGAIN || err == -EINTR);
32497 +#if 0 /* reserved for future use */
32499 + fsnotify_modify(file->f_dentry);
32505 +struct do_xino_fwrite_args {
32507 + au_writef_t func;
32508 + struct file *file;
32514 +static void call_do_xino_fwrite(void *args)
32516 + struct do_xino_fwrite_args *a = args;
32517 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
32520 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
32525 + /* todo: signal block and no wkq? */
32526 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
32528 + err = do_xino_fwrite(func, file, buf, size, pos);
32532 + * it breaks RLIMIT_FSIZE and normal user's limit,
32533 + * users should care about quota and real 'filesystem full.'
32536 + struct do_xino_fwrite_args args = {
32545 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
32546 + if (unlikely(wkq_err))
32553 +/* ---------------------------------------------------------------------- */
32556 + * create a new xinofile at the same place/path as @base_file.
32558 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
32560 + struct file *file;
32561 + struct dentry *base, *parent;
32562 + struct inode *dir, *delegated;
32563 + struct qstr *name;
32564 + struct path path;
32567 + base = base_file->f_dentry;
32568 + parent = base->d_parent; /* dir inode is locked */
32569 + dir = parent->d_inode;
32572 + file = ERR_PTR(-EINVAL);
32573 + name = &base->d_name;
32574 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
32575 + if (IS_ERR(path.dentry)) {
32576 + file = (void *)path.dentry;
32577 + pr_err("%pd lookup err %ld\n",
32578 + base, PTR_ERR(path.dentry));
32582 + /* no need to mnt_want_write() since we call dentry_open() later */
32583 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
32584 + if (unlikely(err)) {
32585 + file = ERR_PTR(err);
32586 + pr_err("%pd create err %d\n", base, err);
32590 + path.mnt = base_file->f_path.mnt;
32591 + file = vfsub_dentry_open(&path,
32592 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
32593 + /* | __FMODE_NONOTIFY */);
32594 + if (IS_ERR(file)) {
32595 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
32599 + delegated = NULL;
32600 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
32601 + if (unlikely(err == -EWOULDBLOCK)) {
32602 + pr_warn("cannot retry for NFSv4 delegation"
32603 + " for an internal unlink\n");
32606 + if (unlikely(err)) {
32607 + pr_err("%pd unlink err %d\n", base, err);
32612 + /* no one can touch copy_src xino */
32613 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
32614 + if (unlikely(err)) {
32615 + pr_err("%pd copy err %d\n", base, err);
32619 + goto out_dput; /* success */
32623 + file = ERR_PTR(err);
32625 + dput(path.dentry);
32630 +struct au_xino_lock_dir {
32631 + struct au_hinode *hdir;
32632 + struct dentry *parent;
32633 + struct mutex *mtx;
32636 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
32637 + struct au_xino_lock_dir *ldir)
32639 + aufs_bindex_t brid, bindex;
32641 + ldir->hdir = NULL;
32643 + brid = au_xino_brid(sb);
32645 + bindex = au_br_index(sb, brid);
32646 + if (bindex >= 0) {
32647 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
32648 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
32650 + ldir->parent = dget_parent(xino->f_dentry);
32651 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
32652 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
32656 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
32659 + au_hn_imtx_unlock(ldir->hdir);
32661 + mutex_unlock(ldir->mtx);
32662 + dput(ldir->parent);
32666 +/* ---------------------------------------------------------------------- */
32668 +/* trucate xino files asynchronously */
32670 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
32673 + unsigned long jiffy;
32675 + aufs_bindex_t bi, bend;
32676 + struct kstatfs *st;
32677 + struct au_branch *br;
32678 + struct file *new_xino, *file;
32679 + struct super_block *h_sb;
32680 + struct au_xino_lock_dir ldir;
32683 + st = kzalloc(sizeof(*st), GFP_NOFS);
32684 + if (unlikely(!st))
32688 + bend = au_sbend(sb);
32689 + if (unlikely(bindex < 0 || bend < bindex))
32691 + br = au_sbr(sb, bindex);
32692 + file = br->br_xino.xi_file;
32696 + err = vfs_statfs(&file->f_path, st);
32697 + if (unlikely(err))
32698 + AuErr1("statfs err %d, ignored\n", err);
32700 + blocks = file_inode(file)->i_blocks;
32701 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
32702 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
32704 + au_xino_lock_dir(sb, file, &ldir);
32705 + /* mnt_want_write() is unnecessary here */
32706 + new_xino = au_xino_create2(file, file);
32707 + au_xino_unlock_dir(&ldir);
32708 + err = PTR_ERR(new_xino);
32709 + if (IS_ERR(new_xino)) {
32710 + pr_err("err %d, ignored\n", err);
32715 + br->br_xino.xi_file = new_xino;
32717 + h_sb = au_br_sb(br);
32718 + for (bi = 0; bi <= bend; bi++) {
32719 + if (unlikely(bi == bindex))
32721 + br = au_sbr(sb, bi);
32722 + if (au_br_sb(br) != h_sb)
32725 + fput(br->br_xino.xi_file);
32726 + br->br_xino.xi_file = new_xino;
32727 + get_file(new_xino);
32730 + err = vfs_statfs(&new_xino->f_path, st);
32732 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
32733 + bindex, (u64)file_inode(new_xino)->i_blocks,
32734 + st->f_bfree, st->f_blocks);
32735 + if (file_inode(new_xino)->i_blocks < blocks)
32736 + au_sbi(sb)->si_xino_jiffy = jiffy;
32738 + AuErr1("statfs err %d, ignored\n", err);
32746 +struct xino_do_trunc_args {
32747 + struct super_block *sb;
32748 + struct au_branch *br;
32751 +static void xino_do_trunc(void *_args)
32753 + struct xino_do_trunc_args *args = _args;
32754 + struct super_block *sb;
32755 + struct au_branch *br;
32756 + struct inode *dir;
32758 + aufs_bindex_t bindex;
32762 + dir = sb->s_root->d_inode;
32765 + si_noflush_write_lock(sb);
32766 + ii_read_lock_parent(dir);
32767 + bindex = au_br_index(sb, br->br_id);
32768 + err = au_xino_trunc(sb, bindex);
32769 + ii_read_unlock(dir);
32770 + if (unlikely(err))
32771 + pr_warn("err b%d, (%d)\n", bindex, err);
32772 + atomic_dec(&br->br_xino_running);
32773 + atomic_dec(&br->br_count);
32774 + si_write_unlock(sb);
32775 + au_nwt_done(&au_sbi(sb)->si_nowait);
32779 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
32782 + struct kstatfs st;
32783 + struct au_sbinfo *sbinfo;
32785 + /* todo: si_xino_expire and the ratio should be customizable */
32786 + sbinfo = au_sbi(sb);
32787 + if (time_before(jiffies,
32788 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
32791 + /* truncation border */
32792 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
32793 + if (unlikely(err)) {
32794 + AuErr1("statfs err %d, ignored\n", err);
32797 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
32803 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
32805 + struct xino_do_trunc_args *args;
32808 + if (!xino_trunc_test(sb, br))
32811 + if (atomic_inc_return(&br->br_xino_running) > 1)
32814 + /* lock and kfree() will be called in trunc_xino() */
32815 + args = kmalloc(sizeof(*args), GFP_NOFS);
32816 + if (unlikely(!args)) {
32817 + AuErr1("no memory\n");
32821 + atomic_inc(&br->br_count);
32824 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
32826 + return; /* success */
32828 + pr_err("wkq %d\n", wkq_err);
32829 + atomic_dec(&br->br_count);
32834 + atomic_dec(&br->br_xino_running);
32837 +/* ---------------------------------------------------------------------- */
32839 +static int au_xino_do_write(au_writef_t write, struct file *file,
32840 + ino_t h_ino, ino_t ino)
32846 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
32847 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
32850 + pos *= sizeof(ino);
32851 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
32852 + if (sz == sizeof(ino))
32853 + return 0; /* success */
32855 + AuIOErr("write failed (%zd)\n", sz);
32860 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
32861 + * at the position of @h_ino.
32862 + * even if @ino is zero, it is written to the xinofile and means no entry.
32863 + * if the size of the xino file on a specific filesystem exceeds the watermark,
32864 + * try truncating it.
32866 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
32870 + unsigned int mnt_flags;
32871 + struct au_branch *br;
32873 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
32874 + || ((loff_t)-1) > 0);
32875 + SiMustAnyLock(sb);
32877 + mnt_flags = au_mntflags(sb);
32878 + if (!au_opt_test(mnt_flags, XINO))
32881 + br = au_sbr(sb, bindex);
32882 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
32885 + if (au_opt_test(mnt_flags, TRUNC_XINO)
32886 + && au_test_fs_trunc_xino(au_br_sb(br)))
32887 + xino_try_trunc(sb, br);
32888 + return 0; /* success */
32891 + AuIOErr("write failed (%d)\n", err);
32895 +/* ---------------------------------------------------------------------- */
32897 +/* aufs inode number bitmap */
32899 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
32900 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
32904 + AuDebugOn(bit < 0 || page_bits <= bit);
32905 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
32909 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
32911 + AuDebugOn(ino < AUFS_FIRST_INO);
32912 + ino -= AUFS_FIRST_INO;
32913 + *pindex = ino / page_bits;
32914 + *bit = ino % page_bits;
32917 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
32922 + struct au_sbinfo *sbinfo;
32923 + struct file *xib;
32924 + unsigned long *p;
32926 + sbinfo = au_sbi(sb);
32927 + MtxMustLock(&sbinfo->si_xib_mtx);
32928 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
32929 + || !au_opt_test(sbinfo->si_mntflags, XINO));
32931 + if (pindex == sbinfo->si_xib_last_pindex)
32934 + xib = sbinfo->si_xib;
32935 + p = sbinfo->si_xib_buf;
32936 + pos = sbinfo->si_xib_last_pindex;
32937 + pos *= PAGE_SIZE;
32938 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
32939 + if (unlikely(sz != PAGE_SIZE))
32943 + pos *= PAGE_SIZE;
32944 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
32945 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
32947 + memset(p, 0, PAGE_SIZE);
32948 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
32950 + if (sz == PAGE_SIZE) {
32951 + sbinfo->si_xib_last_pindex = pindex;
32952 + return 0; /* success */
32956 + AuIOErr1("write failed (%zd)\n", sz);
32963 +/* ---------------------------------------------------------------------- */
32965 +static void au_xib_clear_bit(struct inode *inode)
32968 + unsigned long pindex;
32969 + struct super_block *sb;
32970 + struct au_sbinfo *sbinfo;
32972 + AuDebugOn(inode->i_nlink);
32974 + sb = inode->i_sb;
32975 + xib_calc_bit(inode->i_ino, &pindex, &bit);
32976 + AuDebugOn(page_bits <= bit);
32977 + sbinfo = au_sbi(sb);
32978 + mutex_lock(&sbinfo->si_xib_mtx);
32979 + err = xib_pindex(sb, pindex);
32981 + clear_bit(bit, sbinfo->si_xib_buf);
32982 + sbinfo->si_xib_next_bit = bit;
32984 + mutex_unlock(&sbinfo->si_xib_mtx);
32987 +/* for s_op->delete_inode() */
32988 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
32991 + unsigned int mnt_flags;
32992 + aufs_bindex_t bindex, bend, bi;
32993 + unsigned char try_trunc;
32994 + struct au_iinfo *iinfo;
32995 + struct super_block *sb;
32996 + struct au_hinode *hi;
32997 + struct inode *h_inode;
32998 + struct au_branch *br;
32999 + au_writef_t xwrite;
33001 + sb = inode->i_sb;
33002 + mnt_flags = au_mntflags(sb);
33003 + if (!au_opt_test(mnt_flags, XINO)
33004 + || inode->i_ino == AUFS_ROOT_INO)
33008 + au_xigen_inc(inode);
33009 + au_xib_clear_bit(inode);
33012 + iinfo = au_ii(inode);
33016 + bindex = iinfo->ii_bstart;
33020 + xwrite = au_sbi(sb)->si_xwrite;
33021 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
33022 + hi = iinfo->ii_hinode + bindex;
33023 + bend = iinfo->ii_bend;
33024 + for (; bindex <= bend; bindex++, hi++) {
33025 + h_inode = hi->hi_inode;
33027 + || (!unlinked && h_inode->i_nlink))
33030 + /* inode may not be revalidated */
33031 + bi = au_br_index(sb, hi->hi_id);
33035 + br = au_sbr(sb, bi);
33036 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
33037 + h_inode->i_ino, /*ino*/0);
33038 + if (!err && try_trunc
33039 + && au_test_fs_trunc_xino(au_br_sb(br)))
33040 + xino_try_trunc(sb, br);
33044 +/* get an unused inode number from bitmap */
33045 +ino_t au_xino_new_ino(struct super_block *sb)
33048 + unsigned long *p, pindex, ul, pend;
33049 + struct au_sbinfo *sbinfo;
33050 + struct file *file;
33051 + int free_bit, err;
33053 + if (!au_opt_test(au_mntflags(sb), XINO))
33054 + return iunique(sb, AUFS_FIRST_INO);
33056 + sbinfo = au_sbi(sb);
33057 + mutex_lock(&sbinfo->si_xib_mtx);
33058 + p = sbinfo->si_xib_buf;
33059 + free_bit = sbinfo->si_xib_next_bit;
33060 + if (free_bit < page_bits && !test_bit(free_bit, p))
33061 + goto out; /* success */
33062 + free_bit = find_first_zero_bit(p, page_bits);
33063 + if (free_bit < page_bits)
33064 + goto out; /* success */
33066 + pindex = sbinfo->si_xib_last_pindex;
33067 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
33068 + err = xib_pindex(sb, ul);
33069 + if (unlikely(err))
33071 + free_bit = find_first_zero_bit(p, page_bits);
33072 + if (free_bit < page_bits)
33073 + goto out; /* success */
33076 + file = sbinfo->si_xib;
33077 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
33078 + for (ul = pindex + 1; ul <= pend; ul++) {
33079 + err = xib_pindex(sb, ul);
33080 + if (unlikely(err))
33082 + free_bit = find_first_zero_bit(p, page_bits);
33083 + if (free_bit < page_bits)
33084 + goto out; /* success */
33089 + set_bit(free_bit, p);
33090 + sbinfo->si_xib_next_bit = free_bit + 1;
33091 + pindex = sbinfo->si_xib_last_pindex;
33092 + mutex_unlock(&sbinfo->si_xib_mtx);
33093 + ino = xib_calc_ino(pindex, free_bit);
33094 + AuDbg("i%lu\n", (unsigned long)ino);
33097 + mutex_unlock(&sbinfo->si_xib_mtx);
33103 + * read @ino from xinofile for the specified branch{@sb, @bindex}
33104 + * at the position of @h_ino.
33105 + * if @ino does not exist and @do_new is true, get new one.
33107 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
33113 + struct file *file;
33114 + struct au_sbinfo *sbinfo;
33117 + if (!au_opt_test(au_mntflags(sb), XINO))
33118 + return 0; /* no xino */
33121 + sbinfo = au_sbi(sb);
33123 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
33124 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
33127 + pos *= sizeof(*ino);
33129 + file = au_sbr(sb, bindex)->br_xino.xi_file;
33130 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
33131 + return 0; /* no ino */
33133 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
33134 + if (sz == sizeof(*ino))
33135 + return 0; /* success */
33138 + if (unlikely(sz >= 0)) {
33140 + AuIOErr("xino read error (%zd)\n", sz);
33146 +/* ---------------------------------------------------------------------- */
33148 +/* create and set a new xino file */
33150 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
33152 + struct file *file;
33153 + struct dentry *h_parent, *d;
33154 + struct inode *h_dir;
33158 + * at mount-time, and the xino file is the default path,
33159 + * hnotify is disabled so we have no notify events to ignore.
33160 + * when a user specified the xino, we cannot get au_hdir to be ignored.
33162 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
33163 + /* | __FMODE_NONOTIFY */,
33164 + S_IRUGO | S_IWUGO);
33165 + if (IS_ERR(file)) {
33167 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
33171 + /* keep file count */
33172 + h_parent = dget_parent(file->f_dentry);
33173 + h_dir = h_parent->d_inode;
33174 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
33175 + /* mnt_want_write() is unnecessary here */
33176 + /* no delegation since it is just created */
33177 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, /*force*/0);
33178 + mutex_unlock(&h_dir->i_mutex);
33180 + if (unlikely(err)) {
33182 + pr_err("unlink %s(%d)\n", fname, err);
33187 + d = file->f_dentry;
33188 + if (unlikely(sb == d->d_sb)) {
33190 + pr_err("%s must be outside\n", fname);
33193 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
33195 + pr_err("xino doesn't support %s(%s)\n",
33196 + fname, au_sbtype(d->d_sb));
33199 + return file; /* success */
33203 + file = ERR_PTR(err);
33208 + * find another branch who is on the same filesystem of the specified
33209 + * branch{@btgt}. search until @bend.
33211 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
33212 + aufs_bindex_t bend)
33214 + aufs_bindex_t bindex;
33215 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
33217 + for (bindex = 0; bindex < btgt; bindex++)
33218 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
33220 + for (bindex++; bindex <= bend; bindex++)
33221 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
33226 +/* ---------------------------------------------------------------------- */
33229 + * initialize the xinofile for the specified branch @br
33230 + * at the place/path where @base_file indicates.
33231 + * test whether another branch is on the same filesystem or not,
33232 + * if @do_test is true.
33234 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
33235 + struct file *base_file, int do_test)
33239 + aufs_bindex_t bend, bindex;
33240 + struct au_branch *shared_br, *b;
33241 + struct file *file;
33242 + struct super_block *tgt_sb;
33244 + shared_br = NULL;
33245 + bend = au_sbend(sb);
33247 + tgt_sb = au_br_sb(br);
33248 + for (bindex = 0; bindex <= bend; bindex++) {
33249 + b = au_sbr(sb, bindex);
33250 + if (tgt_sb == au_br_sb(b)) {
33257 + if (!shared_br || !shared_br->br_xino.xi_file) {
33258 + struct au_xino_lock_dir ldir;
33260 + au_xino_lock_dir(sb, base_file, &ldir);
33261 + /* mnt_want_write() is unnecessary here */
33262 + file = au_xino_create2(base_file, NULL);
33263 + au_xino_unlock_dir(&ldir);
33264 + err = PTR_ERR(file);
33265 + if (IS_ERR(file))
33267 + br->br_xino.xi_file = file;
33269 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
33270 + get_file(br->br_xino.xi_file);
33273 + ino = AUFS_ROOT_INO;
33274 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
33276 + if (unlikely(err)) {
33277 + fput(br->br_xino.xi_file);
33278 + br->br_xino.xi_file = NULL;
33285 +/* ---------------------------------------------------------------------- */
33287 +/* trucate a xino bitmap file */
33290 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
33294 + unsigned long pindex;
33295 + loff_t pos, pend;
33296 + struct au_sbinfo *sbinfo;
33299 + unsigned long *p;
33302 + sbinfo = au_sbi(sb);
33303 + MtxMustLock(&sbinfo->si_xib_mtx);
33304 + p = sbinfo->si_xib_buf;
33305 + func = sbinfo->si_xread;
33306 + pend = vfsub_f_size_read(file);
33308 + while (pos < pend) {
33309 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
33311 + if (unlikely(sz <= 0))
33315 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
33316 + if (unlikely(*ino < AUFS_FIRST_INO))
33319 + xib_calc_bit(*ino, &pindex, &bit);
33320 + AuDebugOn(page_bits <= bit);
33321 + err = xib_pindex(sb, pindex);
33333 +static int xib_restore(struct super_block *sb)
33336 + aufs_bindex_t bindex, bend;
33340 + page = (void *)__get_free_page(GFP_NOFS);
33341 + if (unlikely(!page))
33345 + bend = au_sbend(sb);
33346 + for (bindex = 0; !err && bindex <= bend; bindex++)
33347 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
33348 + err = do_xib_restore
33349 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
33351 + AuDbg("b%d\n", bindex);
33352 + free_page((unsigned long)page);
33358 +int au_xib_trunc(struct super_block *sb)
33363 + struct au_xino_lock_dir ldir;
33364 + struct au_sbinfo *sbinfo;
33365 + unsigned long *p;
33366 + struct file *file;
33368 + SiMustWriteLock(sb);
33371 + sbinfo = au_sbi(sb);
33372 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
33375 + file = sbinfo->si_xib;
33376 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
33379 + au_xino_lock_dir(sb, file, &ldir);
33380 + /* mnt_want_write() is unnecessary here */
33381 + file = au_xino_create2(sbinfo->si_xib, NULL);
33382 + au_xino_unlock_dir(&ldir);
33383 + err = PTR_ERR(file);
33384 + if (IS_ERR(file))
33386 + fput(sbinfo->si_xib);
33387 + sbinfo->si_xib = file;
33389 + p = sbinfo->si_xib_buf;
33390 + memset(p, 0, PAGE_SIZE);
33392 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
33393 + if (unlikely(sz != PAGE_SIZE)) {
33395 + AuIOErr("err %d\n", err);
33401 + mutex_lock(&sbinfo->si_xib_mtx);
33402 + /* mnt_want_write() is unnecessary here */
33403 + err = xib_restore(sb);
33404 + mutex_unlock(&sbinfo->si_xib_mtx);
33410 +/* ---------------------------------------------------------------------- */
33413 + * xino mount option handlers
33415 +static au_readf_t find_readf(struct file *h_file)
33417 + const struct file_operations *fop = h_file->f_op;
33420 + return fop->read;
33421 + if (fop->aio_read)
33422 + return do_sync_read;
33423 + if (fop->read_iter)
33424 + return new_sync_read;
33425 + return ERR_PTR(-ENOSYS);
33428 +static au_writef_t find_writef(struct file *h_file)
33430 + const struct file_operations *fop = h_file->f_op;
33433 + return fop->write;
33434 + if (fop->aio_write)
33435 + return do_sync_write;
33436 + if (fop->write_iter)
33437 + return new_sync_write;
33438 + return ERR_PTR(-ENOSYS);
33442 +static void xino_clear_xib(struct super_block *sb)
33444 + struct au_sbinfo *sbinfo;
33446 + SiMustWriteLock(sb);
33448 + sbinfo = au_sbi(sb);
33449 + sbinfo->si_xread = NULL;
33450 + sbinfo->si_xwrite = NULL;
33451 + if (sbinfo->si_xib)
33452 + fput(sbinfo->si_xib);
33453 + sbinfo->si_xib = NULL;
33454 + free_page((unsigned long)sbinfo->si_xib_buf);
33455 + sbinfo->si_xib_buf = NULL;
33458 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
33462 + struct au_sbinfo *sbinfo;
33463 + struct file *file;
33465 + SiMustWriteLock(sb);
33467 + sbinfo = au_sbi(sb);
33468 + file = au_xino_create2(base, sbinfo->si_xib);
33469 + err = PTR_ERR(file);
33470 + if (IS_ERR(file))
33472 + if (sbinfo->si_xib)
33473 + fput(sbinfo->si_xib);
33474 + sbinfo->si_xib = file;
33475 + sbinfo->si_xread = find_readf(file);
33476 + sbinfo->si_xwrite = find_writef(file);
33479 + if (!sbinfo->si_xib_buf)
33480 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
33481 + if (unlikely(!sbinfo->si_xib_buf))
33484 + sbinfo->si_xib_last_pindex = 0;
33485 + sbinfo->si_xib_next_bit = 0;
33486 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
33488 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
33489 + PAGE_SIZE, &pos);
33490 + if (unlikely(err != PAGE_SIZE))
33494 + goto out; /* success */
33497 + free_page((unsigned long)sbinfo->si_xib_buf);
33498 + sbinfo->si_xib_buf = NULL;
33502 + fput(sbinfo->si_xib);
33503 + sbinfo->si_xib = NULL;
33504 + sbinfo->si_xread = NULL;
33505 + sbinfo->si_xwrite = NULL;
33510 +/* xino for each branch */
33511 +static void xino_clear_br(struct super_block *sb)
33513 + aufs_bindex_t bindex, bend;
33514 + struct au_branch *br;
33516 + bend = au_sbend(sb);
33517 + for (bindex = 0; bindex <= bend; bindex++) {
33518 + br = au_sbr(sb, bindex);
33519 + if (!br || !br->br_xino.xi_file)
33522 + fput(br->br_xino.xi_file);
33523 + br->br_xino.xi_file = NULL;
33527 +static int au_xino_set_br(struct super_block *sb, struct file *base)
33531 + aufs_bindex_t bindex, bend, bshared;
33533 + struct file *old, *new;
33535 + struct au_branch *br;
33536 + struct inode *inode;
33537 + au_writef_t writef;
33539 + SiMustWriteLock(sb);
33542 + bend = au_sbend(sb);
33543 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
33544 + if (unlikely(!fpair))
33547 + inode = sb->s_root->d_inode;
33548 + ino = AUFS_ROOT_INO;
33549 + writef = au_sbi(sb)->si_xwrite;
33550 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
33551 + br = au_sbr(sb, bindex);
33552 + bshared = is_sb_shared(sb, bindex, bindex - 1);
33553 + if (bshared >= 0) {
33554 + /* shared xino */
33555 + *p = fpair[bshared];
33556 + get_file(p->new);
33561 + p->old = br->br_xino.xi_file;
33562 + p->new = au_xino_create2(base, br->br_xino.xi_file);
33563 + err = PTR_ERR(p->new);
33564 + if (IS_ERR(p->new)) {
33570 + err = au_xino_do_write(writef, p->new,
33571 + au_h_iptr(inode, bindex)->i_ino, ino);
33572 + if (unlikely(err))
33576 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
33577 + br = au_sbr(sb, bindex);
33578 + if (br->br_xino.xi_file)
33579 + fput(br->br_xino.xi_file);
33580 + get_file(p->new);
33581 + br->br_xino.xi_file = p->new;
33585 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
33595 +void au_xino_clr(struct super_block *sb)
33597 + struct au_sbinfo *sbinfo;
33599 + au_xigen_clr(sb);
33600 + xino_clear_xib(sb);
33601 + xino_clear_br(sb);
33602 + sbinfo = au_sbi(sb);
33603 + /* lvalue, do not call au_mntflags() */
33604 + au_opt_clr(sbinfo->si_mntflags, XINO);
33607 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
33610 + struct dentry *parent, *cur_parent;
33611 + struct qstr *dname, *cur_name;
33612 + struct file *cur_xino;
33613 + struct inode *dir;
33614 + struct au_sbinfo *sbinfo;
33616 + SiMustWriteLock(sb);
33619 + sbinfo = au_sbi(sb);
33620 + parent = dget_parent(xino->file->f_dentry);
33623 + dname = &xino->file->f_dentry->d_name;
33624 + cur_xino = sbinfo->si_xib;
33626 + cur_parent = dget_parent(cur_xino->f_dentry);
33627 + cur_name = &cur_xino->f_dentry->d_name;
33628 + skip = (cur_parent == parent
33629 + && au_qstreq(dname, cur_name));
33630 + dput(cur_parent);
33636 + au_opt_set(sbinfo->si_mntflags, XINO);
33637 + dir = parent->d_inode;
33638 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
33639 + /* mnt_want_write() is unnecessary here */
33640 + err = au_xino_set_xib(sb, xino->file);
33642 + err = au_xigen_set(sb, xino->file);
33644 + err = au_xino_set_br(sb, xino->file);
33645 + mutex_unlock(&dir->i_mutex);
33647 + goto out; /* success */
33650 + AuIOErr("failed creating xino(%d).\n", err);
33657 +/* ---------------------------------------------------------------------- */
33660 + * create a xinofile at the default place/path.
33662 +struct file *au_xino_def(struct super_block *sb)
33664 + struct file *file;
33666 + struct au_branch *br;
33667 + struct super_block *h_sb;
33668 + struct path path;
33669 + aufs_bindex_t bend, bindex, bwr;
33672 + bend = au_sbend(sb);
33674 + for (bindex = 0; bindex <= bend; bindex++) {
33675 + br = au_sbr(sb, bindex);
33676 + if (au_br_writable(br->br_perm)
33677 + && !au_test_fs_bad_xino(au_br_sb(br))) {
33684 + file = ERR_PTR(-ENOMEM);
33685 + page = (void *)__get_free_page(GFP_NOFS);
33686 + if (unlikely(!page))
33688 + path.mnt = au_br_mnt(br);
33689 + path.dentry = au_h_dptr(sb->s_root, bwr);
33690 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
33691 + file = (void *)p;
33692 + if (!IS_ERR(p)) {
33693 + strcat(p, "/" AUFS_XINO_FNAME);
33694 + AuDbg("%s\n", p);
33695 + file = au_xino_create(sb, p, /*silent*/0);
33696 + if (!IS_ERR(file))
33697 + au_xino_brid_set(sb, br->br_id);
33699 + free_page((unsigned long)page);
33701 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
33702 + if (IS_ERR(file))
33704 + h_sb = file->f_dentry->d_sb;
33705 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
33706 + pr_err("xino doesn't support %s(%s)\n",
33707 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
33709 + file = ERR_PTR(-EINVAL);
33711 + if (!IS_ERR(file))
33712 + au_xino_brid_set(sb, -1);
33719 +/* ---------------------------------------------------------------------- */
33721 +int au_xino_path(struct seq_file *seq, struct file *file)
33725 + err = au_seq_path(seq, &file->f_path);
33726 + if (unlikely(err < 0))
33730 +#define Deleted "\\040(deleted)"
33731 + seq->count -= sizeof(Deleted) - 1;
33732 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
33733 + sizeof(Deleted) - 1));
33739 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
33740 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
33741 +++ linux/include/uapi/linux/aufs_type.h 2014-08-14 10:16:04.522609267 +0200
33744 + * Copyright (C) 2005-2014 Junjiro R. Okajima
33746 + * This program, aufs is free software; you can redistribute it and/or modify
33747 + * it under the terms of the GNU General Public License as published by
33748 + * the Free Software Foundation; either version 2 of the License, or
33749 + * (at your option) any later version.
33751 + * This program is distributed in the hope that it will be useful,
33752 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33753 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33754 + * GNU General Public License for more details.
33756 + * You should have received a copy of the GNU General Public License
33757 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33760 +#ifndef __AUFS_TYPE_H__
33761 +#define __AUFS_TYPE_H__
33763 +#define AUFS_NAME "aufs"
33767 + * define it before including all other headers.
33768 + * sched.h may use pr_* macros before defining "current", so define the
33769 + * no-current version first, and re-define later.
33771 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
33772 +#include <linux/sched.h>
33774 +#define pr_fmt(fmt) \
33775 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
33776 + (int)sizeof(current->comm), current->comm, current->pid
33778 +#include <stdint.h>
33779 +#include <sys/types.h>
33780 +#endif /* __KERNEL__ */
33782 +#include <linux/limits.h>
33784 +#define AUFS_VERSION "3.16-20140811"
33786 +/* todo? move this to linux-2.6.19/include/magic.h */
33787 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
33789 +/* ---------------------------------------------------------------------- */
33791 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
33792 +typedef int8_t aufs_bindex_t;
33793 +#define AUFS_BRANCH_MAX 127
33795 +typedef int16_t aufs_bindex_t;
33796 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
33797 +#define AUFS_BRANCH_MAX 511
33798 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
33799 +#define AUFS_BRANCH_MAX 1023
33800 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
33801 +#define AUFS_BRANCH_MAX 32767
33806 +#ifndef AUFS_BRANCH_MAX
33807 +#error unknown CONFIG_AUFS_BRANCH_MAX value
33809 +#endif /* __KERNEL__ */
33811 +/* ---------------------------------------------------------------------- */
33813 +#define AUFS_FSTYPE AUFS_NAME
33815 +#define AUFS_ROOT_INO 2
33816 +#define AUFS_FIRST_INO 11
33818 +#define AUFS_WH_PFX ".wh."
33819 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
33820 +#define AUFS_WH_TMP_LEN 4
33821 +/* a limit for rmdir/rename a dir and copyup */
33822 +#define AUFS_MAX_NAMELEN (NAME_MAX \
33823 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
33825 + - AUFS_WH_TMP_LEN) /* hex */
33826 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
33827 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
33828 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
33829 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
33830 +#define AUFS_DIRWH_DEF 3
33831 +#define AUFS_RDCACHE_DEF 10 /* seconds */
33832 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
33833 +#define AUFS_RDBLK_DEF 512 /* bytes */
33834 +#define AUFS_RDHASH_DEF 32
33835 +#define AUFS_WKQ_NAME AUFS_NAME "d"
33836 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
33837 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
33838 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
33839 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
33841 +/* pseudo-link maintenace under /proc */
33842 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
33843 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
33844 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
33846 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
33847 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
33849 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
33850 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
33851 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
33853 +/* doubly whiteouted */
33854 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
33855 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
33856 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
33858 +/* branch permissions and attributes */
33859 +#define AUFS_BRPERM_RW "rw"
33860 +#define AUFS_BRPERM_RO "ro"
33861 +#define AUFS_BRPERM_RR "rr"
33862 +#define AUFS_BRATTR_COO_REG "coo_reg"
33863 +#define AUFS_BRATTR_COO_ALL "coo_all"
33864 +#define AUFS_BRATTR_FHSM "fhsm"
33865 +#define AUFS_BRATTR_UNPIN "unpin"
33866 +#define AUFS_BRRATTR_WH "wh"
33867 +#define AUFS_BRWATTR_NLWH "nolwh"
33868 +#define AUFS_BRWATTR_MOO "moo"
33870 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
33871 +#define AuBrPerm_RO (1 << 1) /* readonly */
33872 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
33873 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
33875 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
33876 +#define AuBrAttr_COO_ALL (1 << 4)
33877 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
33879 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
33880 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
33883 +#define AuBrRAttr_WH (1 << 7) /* whiteout-able */
33884 +#define AuBrRAttr_Mask AuBrRAttr_WH
33886 +#define AuBrWAttr_NoLinkWH (1 << 8) /* un-hardlinkable whiteouts */
33887 +#define AuBrWAttr_MOO (1 << 9) /* move-up on open */
33888 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
33890 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
33893 +#ifndef CONFIG_AUFS_FHSM
33894 +#undef AuBrAttr_FHSM
33895 +#define AuBrAttr_FHSM 0
33899 +/* the longest combination */
33900 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
33901 + "+" AUFS_BRATTR_COO_REG \
33902 + "+" AUFS_BRATTR_FHSM \
33903 + "+" AUFS_BRATTR_UNPIN \
33904 + "+" AUFS_BRWATTR_NLWH)
33907 + char a[AuBrPermStrSz];
33908 +} au_br_perm_str_t;
33910 +static inline int au_br_writable(int brperm)
33912 + return brperm & AuBrPerm_RW;
33915 +static inline int au_br_whable(int brperm)
33917 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
33920 +static inline int au_br_wh_linkable(int brperm)
33922 + return !(brperm & AuBrWAttr_NoLinkWH);
33925 +static inline int au_br_cmoo(int brperm)
33927 + return brperm & AuBrAttr_CMOO_Mask;
33930 +static inline int au_br_fhsm(int brperm)
33932 + return brperm & AuBrAttr_FHSM;
33935 +/* ---------------------------------------------------------------------- */
33939 + /* readdir in userspace */
33943 + AuCtl_WBR_FD, /* pathconf wrapper */
33944 + AuCtl_IBUSY, /* busy inode */
33945 + AuCtl_MVDOWN, /* move-down */
33946 + AuCtl_BR, /* info about branches */
33947 + AuCtl_FHSM_FD /* connection for fhsm */
33950 +/* borrowed from linux/include/linux/kernel.h */
33952 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
33953 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
33956 +/* borrowed from linux/include/linux/compiler-gcc3.h */
33958 +#define __aligned(x) __attribute__((aligned(x)))
33963 +#define __packed __attribute__((packed))
33967 +struct au_rdu_cookie {
33972 + uint32_t generation;
33975 +struct au_rdu_ent {
33984 +static inline int au_rdu_len(int nlen)
33986 + /* include the terminating NULL */
33987 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
33988 + sizeof(uint64_t));
33991 +union au_rdu_ent_ul {
33992 + struct au_rdu_ent __user *e;
34004 + uint64_t sz; /* AuCtl_RDU */
34005 + uint64_t nent; /* AuCtl_RDU_INO */
34007 + union au_rdu_ent_ul ent;
34008 + uint16_t verify[AufsCtlRduV_End];
34010 + /* input/output */
34014 + union au_rdu_ent_ul tail;
34015 + /* number of entries which were added in a single call */
34020 + struct au_rdu_cookie cookie;
34023 +/* ---------------------------------------------------------------------- */
34025 +struct aufs_wbr_fd {
34030 +/* ---------------------------------------------------------------------- */
34032 +struct aufs_ibusy {
34033 + uint64_t ino, h_ino;
34037 +/* ---------------------------------------------------------------------- */
34039 +/* error code for move-down */
34040 +/* the actual message strings are implemented in aufs-util.git */
34042 + EAU_MVDOWN_OPAQUE = 1,
34043 + EAU_MVDOWN_WHITEOUT,
34044 + EAU_MVDOWN_UPPER,
34045 + EAU_MVDOWN_BOTTOM,
34046 + EAU_MVDOWN_NOUPPER,
34047 + EAU_MVDOWN_NOLOWERBR,
34051 +/* flags for move-down */
34052 +#define AUFS_MVDOWN_DMSG 1
34053 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
34054 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
34055 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
34056 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
34057 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
34058 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
34059 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
34060 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
34061 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
34062 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
34063 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
34064 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
34066 +/* index for move-down */
34068 + AUFS_MVDOWN_UPPER,
34069 + AUFS_MVDOWN_LOWER,
34070 + AUFS_MVDOWN_NARRAY
34074 + * additional info of move-down
34075 + * number of free blocks and inodes.
34076 + * subset of struct kstatfs, but smaller and always 64bit.
34078 +struct aufs_stfs {
34079 + uint64_t f_blocks;
34080 + uint64_t f_bavail;
34081 + uint64_t f_files;
34082 + uint64_t f_ffree;
34085 +struct aufs_stbr {
34086 + int16_t brid; /* optional input */
34087 + int16_t bindex; /* output */
34088 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
34091 +struct aufs_mvdown {
34092 + uint32_t flags; /* input/output */
34093 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
34094 + int8_t au_errno; /* output */
34097 +/* ---------------------------------------------------------------------- */
34099 +union aufs_brinfo {
34100 + /* PATH_MAX may differ between kernel-space and user-space */
34101 + char _spacer[4096];
34109 +/* ---------------------------------------------------------------------- */
34111 +#define AuCtlType 'A'
34112 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
34113 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
34114 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
34115 + struct aufs_wbr_fd)
34116 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
34117 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
34118 + struct aufs_mvdown)
34119 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
34120 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
34122 +#endif /* __AUFS_TYPE_H__ */
34123 aufs3.16 loopback patch
34125 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
34126 index 30efd68..77b31b4 100644
34127 --- a/drivers/block/loop.c
34128 +++ b/drivers/block/loop.c
34129 @@ -514,7 +514,7 @@ out:
34132 struct switch_request {
34133 - struct file *file;
34134 + struct file *file, *virt_file;
34135 struct completion wait;
34138 @@ -576,7 +576,8 @@ static int loop_thread(void *data)
34139 * First it needs to flush existing IO, it does this by sending a magic
34140 * BIO down the pipe. The completion of this BIO does the actual switch.
34142 -static int loop_switch(struct loop_device *lo, struct file *file)
34143 +static int loop_switch(struct loop_device *lo, struct file *file,
34144 + struct file *virt_file)
34146 struct switch_request w;
34147 struct bio *bio = bio_alloc(GFP_KERNEL, 0);
34148 @@ -584,6 +585,7 @@ static int loop_switch(struct loop_device *lo, struct file *file)
34150 init_completion(&w.wait);
34152 + w.virt_file = virt_file;
34153 bio->bi_private = &w;
34154 bio->bi_bdev = NULL;
34155 loop_make_request(lo->lo_queue, bio);
34156 @@ -600,7 +602,7 @@ static int loop_flush(struct loop_device *lo)
34157 if (!lo->lo_thread)
34160 - return loop_switch(lo, NULL);
34161 + return loop_switch(lo, NULL, NULL);
34165 @@ -619,6 +621,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
34166 mapping = file->f_mapping;
34167 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
34168 lo->lo_backing_file = file;
34169 + lo->lo_backing_virt_file = p->virt_file;
34170 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
34171 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
34172 lo->old_gfp_mask = mapping_gfp_mask(mapping);
34173 @@ -627,6 +630,13 @@ out:
34174 complete(&p->wait);
34177 +static struct file *loop_real_file(struct file *file)
34179 + struct file *f = NULL;
34180 + if (file->f_dentry->d_sb->s_op->real_loop)
34181 + f = file->f_dentry->d_sb->s_op->real_loop(file);
34186 * loop_change_fd switched the backing store of a loopback device to
34187 @@ -640,6 +650,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
34190 struct file *file, *old_file;
34191 + struct file *f, *virt_file = NULL, *old_virt_file;
34192 struct inode *inode;
34195 @@ -656,9 +667,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
34199 + f = loop_real_file(file);
34201 + virt_file = file;
34206 inode = file->f_mapping->host;
34207 old_file = lo->lo_backing_file;
34208 + old_virt_file = lo->lo_backing_virt_file;
34212 @@ -670,17 +688,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
34215 /* and ... switch */
34216 - error = loop_switch(lo, file);
34217 + error = loop_switch(lo, file, virt_file);
34222 + if (old_virt_file)
34223 + fput(old_virt_file);
34224 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
34225 ioctl_by_bdev(bdev, BLKRRPART, 0);
34235 @@ -841,7 +863,7 @@ static void loop_config_discard(struct loop_device *lo)
34236 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
34237 struct block_device *bdev, unsigned int arg)
34239 - struct file *file, *f;
34240 + struct file *file, *f, *virt_file = NULL;
34241 struct inode *inode;
34242 struct address_space *mapping;
34243 unsigned lo_blocksize;
34244 @@ -856,6 +878,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
34248 + f = loop_real_file(file);
34250 + virt_file = file;
34256 if (lo->lo_state != Lo_unbound)
34257 @@ -904,6 +932,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
34258 lo->lo_device = bdev;
34259 lo->lo_flags = lo_flags;
34260 lo->lo_backing_file = file;
34261 + lo->lo_backing_virt_file = virt_file;
34262 lo->transfer = transfer_none;
34264 lo->lo_sizelimit = 0;
34265 @@ -948,6 +977,7 @@ out_clr:
34266 lo->lo_thread = NULL;
34267 lo->lo_device = NULL;
34268 lo->lo_backing_file = NULL;
34269 + lo->lo_backing_virt_file = NULL;
34271 set_capacity(lo->lo_disk, 0);
34272 invalidate_bdev(bdev);
34273 @@ -957,6 +987,8 @@ out_clr:
34274 lo->lo_state = Lo_unbound;
34280 /* This is safe: open() is still holding a reference. */
34281 module_put(THIS_MODULE);
34282 @@ -1003,6 +1035,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
34283 static int loop_clr_fd(struct loop_device *lo)
34285 struct file *filp = lo->lo_backing_file;
34286 + struct file *virt_filp = lo->lo_backing_virt_file;
34287 gfp_t gfp = lo->old_gfp_mask;
34288 struct block_device *bdev = lo->lo_device;
34290 @@ -1036,6 +1069,7 @@ static int loop_clr_fd(struct loop_device *lo)
34292 spin_lock_irq(&lo->lo_lock);
34293 lo->lo_backing_file = NULL;
34294 + lo->lo_backing_virt_file = NULL;
34295 spin_unlock_irq(&lo->lo_lock);
34297 loop_release_xfer(lo);
34298 @@ -1078,6 +1112,8 @@ static int loop_clr_fd(struct loop_device *lo)
34299 * bd_mutex which is usually taken before lo_ctl_mutex.
34307 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
34308 index 90df5d6..cb91822 100644
34309 --- a/drivers/block/loop.h
34310 +++ b/drivers/block/loop.h
34311 @@ -44,7 +44,7 @@ struct loop_device {
34312 int (*ioctl)(struct loop_device *, int cmd,
34313 unsigned long arg);
34315 - struct file * lo_backing_file;
34316 + struct file * lo_backing_file, *lo_backing_virt_file;
34317 struct block_device *lo_device;
34318 unsigned lo_blocksize;
34320 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
34321 index 24ced51..69fa5cc 100644
34322 --- a/fs/aufs/f_op.c
34323 +++ b/fs/aufs/f_op.c
34324 @@ -367,7 +367,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
34326 h_file = au_hf_top(file);
34328 - if (au_test_loopback_kthread()) {
34329 + if (0 && au_test_loopback_kthread()) {
34330 au_warn_loopback(h_file->f_dentry->d_sb);
34331 if (file->f_mapping != h_file->f_mapping) {
34332 file->f_mapping = h_file->f_mapping;
34333 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
34334 index 3b03b52..4ab749d 100644
34335 --- a/fs/aufs/loop.c
34336 +++ b/fs/aufs/loop.c
34337 @@ -130,3 +130,19 @@ void au_loopback_fin(void)
34338 symbol_put(loop_backing_file);
34339 kfree(au_warn_loopback_array);
34342 +/* ---------------------------------------------------------------------- */
34344 +/* support the loopback block device insude aufs */
34346 +struct file *aufs_real_loop(struct file *file)
34350 + BUG_ON(!au_test_aufs(file->f_dentry->d_sb));
34351 + fi_read_lock(file);
34352 + f = au_hf_top(file);
34353 + fi_read_unlock(file);
34357 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
34358 index da8b756..28cb7ea 100644
34359 --- a/fs/aufs/loop.h
34360 +++ b/fs/aufs/loop.h
34361 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
34363 int au_loopback_init(void);
34364 void au_loopback_fin(void);
34366 +struct file *aufs_real_loop(struct file *file);
34368 +AuStub(struct file *, loop_backing_file, return NULL)
34370 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
34371 struct dentry *h_adding)
34372 AuStubInt0(au_test_loopback_kthread, void)
34373 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
34375 AuStubInt0(au_loopback_init, void)
34376 AuStubVoid(au_loopback_fin, void)
34378 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
34379 #endif /* BLK_DEV_LOOP */
34381 #endif /* __KERNEL__ */
34382 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
34383 index 45146eb..fccd7d6 100644
34384 --- a/fs/aufs/super.c
34385 +++ b/fs/aufs/super.c
34386 @@ -809,7 +809,10 @@ static const struct super_operations aufs_sop = {
34387 .statfs = aufs_statfs,
34388 .put_super = aufs_put_super,
34389 .sync_fs = aufs_sync_fs,
34390 - .remount_fs = aufs_remount_fs
34391 + .remount_fs = aufs_remount_fs,
34392 +#ifdef CONFIG_AUFS_BDEV_LOOP
34393 + .real_loop = aufs_real_loop
34397 /* ---------------------------------------------------------------------- */
34398 diff --git a/include/linux/fs.h b/include/linux/fs.h
34399 index 2f32b35..f94f0e6 100644
34400 --- a/include/linux/fs.h
34401 +++ b/include/linux/fs.h
34402 @@ -1561,6 +1561,10 @@ struct super_operations {
34403 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
34404 long (*nr_cached_objects)(struct super_block *, int);
34405 long (*free_cached_objects)(struct super_block *, long, int);
34406 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
34408 + struct file *(*real_loop)(struct file *);