1 aufs3.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index ec35851..a059d62 100644
7 @@ -218,6 +218,7 @@ source "fs/sysv/Kconfig"
8 source "fs/ufs/Kconfig"
9 source "fs/exofs/Kconfig"
10 source "fs/f2fs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index a88ac48..162500e 100644
19 @@ -126,3 +126,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
25 index 68ceb97..0352fa4 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -58,6 +58,7 @@ header-y += atmsvc.h
30 header-y += atm_zatm.h
32 +header-y += aufs_type.h
33 header-y += auto_fs4.h
36 aufs3.x-rcN base patch
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index efbcb50..30a1654 100644
42 @@ -1864,6 +1864,20 @@ F: include/linux/audit.h
43 F: include/uapi/linux/audit.h
46 +AUFS (advanced multi layered unification filesystem) FILESYSTEM
47 +M: "J. R. Okajima" <hooanon05g@gmail.com>
48 +L: linux-unionfs@vger.kernel.org
49 +L: aufs-users@lists.sourceforge.net (members only)
50 +W: http://aufs.sourceforge.net
51 +T: git://git.code.sf.net/p/aufs/aufs3-linux
52 +T: git://github.com/sfjro/aufs3-linux.git
54 +F: Documentation/filesystems/aufs/
55 +F: Documentation/ABI/testing/debugfs-aufs
56 +F: Documentation/ABI/testing/sysfs-aufs
58 +F: include/uapi/linux/aufs_type.h
60 AUXILIARY DISPLAY DRIVERS
61 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
62 W: http://miguelojeda.es/auxdisplay.htm
63 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
64 index d1f168b..a0da519 100644
65 --- a/drivers/block/loop.c
66 +++ b/drivers/block/loop.c
67 @@ -592,6 +592,24 @@ static inline int is_loop_device(struct file *file)
68 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
73 + * no get/put for file.
75 +struct file *loop_backing_file(struct super_block *sb)
78 + struct loop_device *l;
81 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
82 + l = sb->s_bdev->bd_disk->private_data;
83 + ret = l->lo_backing_file;
87 +EXPORT_SYMBOL(loop_backing_file);
89 /* loop sysfs attributes */
91 static ssize_t loop_attr_show(struct device *dev, char *page,
92 diff --git a/fs/dcache.c b/fs/dcache.c
93 index c71e373..b93a9f2 100644
96 @@ -1130,7 +1130,7 @@ enum d_walk_ret {
98 * The @enter() and @finish() callbacks are called with d_lock held.
100 -static void d_walk(struct dentry *parent, void *data,
101 +void d_walk(struct dentry *parent, void *data,
102 enum d_walk_ret (*enter)(void *, struct dentry *),
103 void (*finish)(void *))
105 diff --git a/fs/splice.c b/fs/splice.c
106 index 7968da9..beb9993 100644
109 @@ -1099,8 +1099,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
111 * Attempt to initiate a splice from pipe to file.
113 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
114 - loff_t *ppos, size_t len, unsigned int flags)
115 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
116 + loff_t *ppos, size_t len, unsigned int flags)
118 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
119 loff_t *, size_t, unsigned int);
120 @@ -1116,9 +1116,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
122 * Attempt to initiate a splice from a file to a pipe.
124 -static long do_splice_to(struct file *in, loff_t *ppos,
125 - struct pipe_inode_info *pipe, size_t len,
126 - unsigned int flags)
127 +long do_splice_to(struct file *in, loff_t *ppos,
128 + struct pipe_inode_info *pipe, size_t len,
129 + unsigned int flags)
131 ssize_t (*splice_read)(struct file *, loff_t *,
132 struct pipe_inode_info *, size_t, unsigned int);
133 diff --git a/include/linux/file.h b/include/linux/file.h
134 index f87d308..9a290b3 100644
135 --- a/include/linux/file.h
136 +++ b/include/linux/file.h
137 @@ -19,6 +19,7 @@ struct dentry;
139 extern struct file *alloc_file(struct path *, fmode_t mode,
140 const struct file_operations *fop);
141 +extern struct file *get_empty_filp(void);
143 static inline void fput_light(struct file *file, int fput_needed)
145 diff --git a/include/linux/splice.h b/include/linux/splice.h
146 index da2751d..2e0fca6 100644
147 --- a/include/linux/splice.h
148 +++ b/include/linux/splice.h
149 @@ -83,4 +83,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
150 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
152 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
154 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
155 + loff_t *ppos, size_t len, unsigned int flags);
156 +extern long do_splice_to(struct file *in, loff_t *ppos,
157 + struct pipe_inode_info *pipe, size_t len,
158 + unsigned int flags);
160 aufs3.x-rcN mmap patch
162 diff --git a/fs/buffer.c b/fs/buffer.c
163 index 20805db..363569f 100644
166 @@ -2450,7 +2450,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
167 * Update file times before taking page lock. We may end up failing the
168 * fault so this update may be superfluous but who really cares...
170 - file_update_time(vma->vm_file);
171 + vma_file_update_time(vma);
173 ret = __block_page_mkwrite(vma, vmf, get_block);
174 sb_end_pagefault(sb);
175 diff --git a/fs/proc/base.c b/fs/proc/base.c
176 index 3f3d7ae..426bcc7 100644
179 @@ -1735,7 +1735,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
180 down_read(&mm->mmap_sem);
181 vma = find_exact_vma(mm, vm_start, vm_end);
182 if (vma && vma->vm_file) {
183 - *path = vma->vm_file->f_path;
184 + *path = vma_pr_or_file(vma)->f_path;
188 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
189 index d4a3574..1397181 100644
190 --- a/fs/proc/nommu.c
191 +++ b/fs/proc/nommu.c
192 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
193 file = region->vm_file;
196 - struct inode *inode = file_inode(region->vm_file);
197 + struct inode *inode;
199 + file = vmr_pr_or_file(region);
200 + inode = file_inode(file);
201 dev = inode->i_sb->s_dev;
204 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
205 index 6dee68d..9afa35d 100644
206 --- a/fs/proc/task_mmu.c
207 +++ b/fs/proc/task_mmu.c
208 @@ -279,7 +279,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
209 const char *name = NULL;
212 - struct inode *inode = file_inode(vma->vm_file);
213 + struct inode *inode;
215 + file = vma_pr_or_file(vma);
216 + inode = file_inode(file);
217 dev = inode->i_sb->s_dev;
219 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
220 @@ -1479,7 +1482,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
221 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
222 struct vm_area_struct *vma = v;
223 struct numa_maps *md = &numa_priv->md;
224 - struct file *file = vma->vm_file;
225 + struct file *file = vma_pr_or_file(vma);
226 struct mm_struct *mm = vma->vm_mm;
227 struct mm_walk walk = {
228 .hugetlb_entry = gather_hugetlb_stats,
229 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
230 index 599ec2e..1740207 100644
231 --- a/fs/proc/task_nommu.c
232 +++ b/fs/proc/task_nommu.c
233 @@ -160,7 +160,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
237 - struct inode *inode = file_inode(vma->vm_file);
238 + struct inode *inode;
240 + file = vma_pr_or_file(vma);
241 + inode = file_inode(file);
242 dev = inode->i_sb->s_dev;
244 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
245 diff --git a/include/linux/mm.h b/include/linux/mm.h
246 index 47a9392..c8f8b46 100644
247 --- a/include/linux/mm.h
248 +++ b/include/linux/mm.h
249 @@ -1254,6 +1254,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
253 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
254 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
256 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
257 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
259 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
261 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
263 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
264 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
267 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
268 +extern void vmr_do_fput(struct vm_region *, const char[], int);
270 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
272 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
273 +#endif /* !CONFIG_MMU */
275 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
276 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
277 void *buf, int len, int write);
278 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
279 index 199a03a..ed38ea3 100644
280 --- a/include/linux/mm_types.h
281 +++ b/include/linux/mm_types.h
282 @@ -241,6 +241,7 @@ struct vm_region {
283 unsigned long vm_top; /* region allocated to here */
284 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
285 struct file *vm_file; /* the backing file or NULL */
286 + struct file *vm_prfile; /* the virtual backing file or NULL */
288 int vm_usage; /* region usage count (access under nommu_region_sem) */
289 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
290 @@ -305,6 +306,7 @@ struct vm_area_struct {
291 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
292 units, *not* PAGE_CACHE_SIZE */
293 struct file * vm_file; /* File we map to (can be NULL). */
294 + struct file *vm_prfile; /* shadow of vm_file */
295 void * vm_private_data; /* was vm_pte (shared mem) */
298 diff --git a/kernel/fork.c b/kernel/fork.c
299 index cf65139..f28a048 100644
302 @@ -430,7 +430,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
303 struct inode *inode = file_inode(file);
304 struct address_space *mapping = file->f_mapping;
308 if (tmp->vm_flags & VM_DENYWRITE)
309 atomic_dec(&inode->i_writecount);
310 i_mmap_lock_write(mapping);
311 diff --git a/mm/Makefile b/mm/Makefile
312 index 15dbe99..88e25b5 100644
315 @@ -21,7 +21,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
316 mm_init.o mmu_context.o percpu.o slab_common.o \
317 compaction.o vmacache.o \
318 interval_tree.o list_lru.o workingset.o \
320 + prfile.o debug.o $(mmu-y)
324 diff --git a/mm/filemap.c b/mm/filemap.c
325 index ad72420..8885258 100644
328 @@ -2064,7 +2064,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
329 int ret = VM_FAULT_LOCKED;
331 sb_start_pagefault(inode->i_sb);
332 - file_update_time(vma->vm_file);
333 + vma_file_update_time(vma);
335 if (page->mapping != inode->i_mapping) {
337 diff --git a/mm/madvise.c b/mm/madvise.c
338 index d551475..1ebf71b 100644
341 @@ -320,12 +320,12 @@ static long madvise_remove(struct vm_area_struct *vma,
342 * vma's reference to the file) can go away as soon as we drop
347 up_read(¤t->mm->mmap_sem);
348 error = vfs_fallocate(f,
349 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
350 offset, end - start);
353 down_read(¤t->mm->mmap_sem);
356 diff --git a/mm/memory.c b/mm/memory.c
357 index 97839f5..5e5d491 100644
360 @@ -2034,7 +2034,7 @@ static inline int wp_page_reuse(struct m
364 - file_update_time(vma->vm_file);
365 + vma_file_update_time(vma);
368 return VM_FAULT_WRITE;
369 diff --git a/mm/mmap.c b/mm/mmap.c
370 index 9ec50a3..4a6a641 100644
373 @@ -274,7 +274,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
374 if (vma->vm_ops && vma->vm_ops->close)
375 vma->vm_ops->close(vma);
377 - fput(vma->vm_file);
379 mpol_put(vma_policy(vma));
380 kmem_cache_free(vm_area_cachep, vma);
382 @@ -886,7 +886,7 @@ again: remove_next = 1 + (end > next->vm_end);
385 uprobe_munmap(next, next->vm_start, next->vm_end);
390 anon_vma_merge(vma, next);
391 @@ -1671,8 +1671,8 @@ out:
399 /* Undo any partial mapping done by a device driver. */
400 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
401 @@ -2473,7 +2473,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
405 - get_file(new->vm_file);
408 if (new->vm_ops && new->vm_ops->open)
409 new->vm_ops->open(new);
410 @@ -2492,7 +2492,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
411 if (new->vm_ops && new->vm_ops->close)
412 new->vm_ops->close(new);
414 - fput(new->vm_file);
416 unlink_anon_vmas(new);
418 mpol_put(vma_policy(new));
419 @@ -2635,7 +2635,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
420 struct vm_area_struct *vma;
421 unsigned long populate = 0;
422 unsigned long ret = -EINVAL;
425 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
426 "See Documentation/vm/remap_file_pages.txt.\n",
427 @@ -2679,10 +2678,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
428 munlock_vma_pages_range(vma, start, start + size);
431 - file = get_file(vma->vm_file);
433 ret = do_mmap_pgoff(vma->vm_file, start, size,
434 prot, flags, pgoff, &populate);
438 up_write(&mm->mmap_sem);
440 @@ -2950,7 +2949,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
441 if (anon_vma_clone(new_vma, vma))
442 goto out_free_mempol;
443 if (new_vma->vm_file)
444 - get_file(new_vma->vm_file);
445 + vma_get_file(new_vma);
446 if (new_vma->vm_ops && new_vma->vm_ops->open)
447 new_vma->vm_ops->open(new_vma);
448 vma_link(mm, new_vma, prev, rb_link, rb_parent);
449 diff --git a/mm/msync.c b/mm/msync.c
450 index bb04d53..5c24c54 100644
453 @@ -84,10 +84,10 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
455 if ((flags & MS_SYNC) && file &&
456 (vma->vm_flags & VM_SHARED)) {
459 up_read(&mm->mmap_sem);
460 error = vfs_fsync_range(file, fstart, fend, 1);
463 if (error || start >= end)
465 down_read(&mm->mmap_sem);
466 diff --git a/mm/nommu.c b/mm/nommu.c
467 index 3fba2dc..870ce96 100644
470 @@ -693,7 +693,7 @@ static void __put_nommu_region(struct vm_region *region)
471 up_write(&nommu_region_sem);
474 - fput(region->vm_file);
477 /* IO memory and memory shared directly out of the pagecache
478 * from ramfs/tmpfs mustn't be released here */
479 @@ -858,7 +858,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
480 if (vma->vm_ops && vma->vm_ops->close)
481 vma->vm_ops->close(vma);
483 - fput(vma->vm_file);
485 put_nommu_region(vma->vm_region);
486 kmem_cache_free(vm_area_cachep, vma);
488 @@ -1398,7 +1398,7 @@ unsigned long do_mmap_pgoff(struct file *file,
489 goto error_just_free;
492 - fput(region->vm_file);
494 kmem_cache_free(vm_region_jar, region);
497 @@ -1474,10 +1474,10 @@ error_just_free:
498 up_write(&nommu_region_sem);
501 - fput(region->vm_file);
503 kmem_cache_free(vm_region_jar, region);
505 - fput(vma->vm_file);
507 kmem_cache_free(vm_area_cachep, vma);
508 kleave(" = %d", ret);
510 diff --git a/mm/prfile.c b/mm/prfile.c
512 index 0000000..6aa5ab5
517 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
518 + * in /proc/PID/maps.
519 + * Call these functions via macros defined in linux/mm.h.
521 + * See Documentation/filesystems/aufs/design/06mmap.txt
523 + * Copyright (c) 2014 Junjro R. Okajima
524 + * Copyright (c) 2014 Ian Campbell
527 +#include <linux/mm.h>
528 +#include <linux/file.h>
529 +#include <linux/fs.h>
531 +/* #define PRFILE_TRACE */
532 +static inline void prfile_trace(struct file *f, struct file *pr,
533 + const char func[], int line, const char func2[])
537 + pr_info("%s:%d: %s, %p\n", func, line, func2,
538 + f ? (char *)f->f_path.dentry->d_name.name : "(null)");
542 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
545 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
547 + prfile_trace(f, pr, func, line, __func__);
548 + file_update_time(f);
550 + file_update_time(pr);
553 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
556 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
558 + prfile_trace(f, pr, func, line, __func__);
559 + return (f && pr) ? pr : f;
562 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
564 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
566 + prfile_trace(f, pr, func, line, __func__);
572 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
574 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
576 + prfile_trace(f, pr, func, line, __func__);
583 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
586 + struct file *f = region->vm_file, *pr = region->vm_prfile;
588 + prfile_trace(f, pr, func, line, __func__);
589 + return (f && pr) ? pr : f;
592 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
594 + struct file *f = region->vm_file, *pr = region->vm_prfile;
596 + prfile_trace(f, pr, func, line, __func__);
601 +#endif /* !CONFIG_MMU */
602 aufs3.x-rcN standalone patch
604 diff --git a/fs/dcache.c b/fs/dcache.c
605 index b93a9f2..5a010ee 100644
608 @@ -1235,6 +1235,7 @@ rename_retry:
612 +EXPORT_SYMBOL(d_walk);
615 * Search for at least 1 mount point in the dentry's subdirs.
616 diff --git a/fs/file_table.c b/fs/file_table.c
617 index 3f85411..00e9dcf 100644
618 --- a/fs/file_table.c
619 +++ b/fs/file_table.c
620 @@ -147,6 +147,7 @@ over:
622 return ERR_PTR(-ENFILE);
624 +EXPORT_SYMBOL(get_empty_filp);
627 * alloc_file - allocate and initialize a 'struct file'
628 @@ -308,6 +309,7 @@ void put_filp(struct file *file)
632 +EXPORT_SYMBOL(put_filp);
634 void __init files_init(unsigned long mempages)
636 diff --git a/fs/inode.c b/fs/inode.c
637 index f00b16f..eb7b8b5 100644
640 @@ -58,6 +58,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
641 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
643 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
644 +EXPORT_SYMBOL(inode_sb_list_lock);
647 * Empty aops. Can be used for the cases where the user does not
648 diff --git a/fs/namespace.c b/fs/namespace.c
649 index 82ef140..a3aa4b9 100644
652 @@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
653 mnt_dec_writers(real_mount(mnt));
656 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
659 * mnt_drop_write - give up write access to a mount
660 @@ -1718,6 +1719,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
664 +EXPORT_SYMBOL(iterate_mounts);
666 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
668 diff --git a/fs/notify/group.c b/fs/notify/group.c
669 index d16b62c..06ca6bc 100644
670 --- a/fs/notify/group.c
671 +++ b/fs/notify/group.c
673 #include <linux/srcu.h>
674 #include <linux/rculist.h>
675 #include <linux/wait.h>
676 +#include <linux/module.h>
678 #include <linux/fsnotify_backend.h>
679 #include "fsnotify.h"
680 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
682 atomic_inc(&group->refcnt);
684 +EXPORT_SYMBOL(fsnotify_get_group);
687 * Drop a reference to a group. Free it if it's through.
688 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
689 if (atomic_dec_and_test(&group->refcnt))
690 fsnotify_final_destroy_group(group);
692 +EXPORT_SYMBOL(fsnotify_put_group);
695 * Create a new fsnotify_group and hold a reference for the group returned.
696 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
700 +EXPORT_SYMBOL(fsnotify_alloc_group);
702 int fsnotify_fasync(int fd, struct file *file, int on)
704 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
705 index 92e48c7..d2c4b68 100644
706 --- a/fs/notify/mark.c
707 +++ b/fs/notify/mark.c
708 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
709 mark->free_mark(mark);
712 +EXPORT_SYMBOL(fsnotify_put_mark);
714 /* Calculate mask of events for a list of marks */
715 u32 fsnotify_recalc_mask(struct hlist_head *head)
716 @@ -202,6 +203,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
717 fsnotify_destroy_mark_locked(mark, group);
718 mutex_unlock(&group->mark_mutex);
720 +EXPORT_SYMBOL(fsnotify_destroy_mark);
723 * Destroy all marks in the given list. The marks must be already detached from
724 @@ -376,6 +378,7 @@ err:
728 +EXPORT_SYMBOL(fsnotify_add_mark);
730 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
731 struct inode *inode, struct vfsmount *mnt, int allow_dups)
732 @@ -455,6 +458,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
733 atomic_set(&mark->refcnt, 1);
734 mark->free_mark = free_mark;
736 +EXPORT_SYMBOL(fsnotify_init_mark);
738 static int fsnotify_mark_destroy(void *ignored)
740 diff --git a/fs/open.c b/fs/open.c
741 index 33f9cbf..fcc7eb4 100644
744 @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
745 mutex_unlock(&dentry->d_inode->i_mutex);
748 +EXPORT_SYMBOL(do_truncate);
750 long vfs_truncate(struct path *path, loff_t length)
752 @@ -672,6 +673,7 @@ int open_check_o_direct(struct file *f)
756 +EXPORT_SYMBOL(open_check_o_direct);
758 static int do_dentry_open(struct file *f,
759 int (*open)(struct inode *, struct file *),
760 diff --git a/fs/splice.c b/fs/splice.c
761 index beb9993..813275a 100644
764 @@ -1112,6 +1112,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
766 return splice_write(pipe, out, ppos, len, flags);
768 +EXPORT_SYMBOL(do_splice_from);
771 * Attempt to initiate a splice from a file to a pipe.
772 @@ -1138,6 +1139,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
774 return splice_read(in, ppos, pipe, len, flags);
776 +EXPORT_SYMBOL(do_splice_to);
779 * splice_direct_to_actor - splices data directly between two non-pipes
780 diff --git a/fs/xattr.c b/fs/xattr.c
781 index 4ef6985..6bb6303 100644
784 @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
785 *xattr_value = value;
788 +EXPORT_SYMBOL(vfs_getxattr_alloc);
790 /* Compare an extended attribute value with the given value */
791 int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
792 diff --git a/security/commoncap.c b/security/commoncap.c
793 index f66713b..fd4c4b8 100644
794 --- a/security/commoncap.c
795 +++ b/security/commoncap.c
796 @@ -975,9 +975,11 @@ int cap_mmap_addr(unsigned long addr)
800 +EXPORT_SYMBOL(cap_mmap_addr);
802 int cap_mmap_file(struct file *file, unsigned long reqprot,
803 unsigned long prot, unsigned long flags)
807 +EXPORT_SYMBOL(cap_mmap_file);
808 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
809 index 188c1d2..426d9af 100644
810 --- a/security/device_cgroup.c
811 +++ b/security/device_cgroup.c
813 #include <linux/device_cgroup.h>
814 #include <linux/cgroup.h>
815 #include <linux/ctype.h>
816 +#include <linux/export.h>
817 #include <linux/list.h>
818 #include <linux/uaccess.h>
819 #include <linux/seq_file.h>
820 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
821 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
824 +EXPORT_SYMBOL(__devcgroup_inode_permission);
826 int devcgroup_inode_mknod(int mode, dev_t dev)
828 diff --git a/security/security.c b/security/security.c
829 index e81d5bb..0b7b840 100644
830 --- a/security/security.c
831 +++ b/security/security.c
832 @@ -430,6 +430,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
834 return security_ops->path_rmdir(dir, dentry);
836 +EXPORT_SYMBOL(security_path_rmdir);
838 int security_path_unlink(struct path *dir, struct dentry *dentry)
840 @@ -446,6 +447,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
842 return security_ops->path_symlink(dir, dentry, old_name);
844 +EXPORT_SYMBOL(security_path_symlink);
846 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
847 struct dentry *new_dentry)
848 @@ -454,6 +456,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
850 return security_ops->path_link(old_dentry, new_dir, new_dentry);
852 +EXPORT_SYMBOL(security_path_link);
854 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
855 struct path *new_dir, struct dentry *new_dentry,
856 @@ -481,6 +484,7 @@ int security_path_truncate(struct path *path)
858 return security_ops->path_truncate(path);
860 +EXPORT_SYMBOL(security_path_truncate);
862 int security_path_chmod(struct path *path, umode_t mode)
864 @@ -488,6 +492,7 @@ int security_path_chmod(struct path *path, umode_t mode)
866 return security_ops->path_chmod(path, mode);
868 +EXPORT_SYMBOL(security_path_chmod);
870 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
872 @@ -495,6 +500,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
874 return security_ops->path_chown(path, uid, gid);
876 +EXPORT_SYMBOL(security_path_chown);
878 int security_path_chroot(struct path *path)
880 @@ -580,6 +586,7 @@ int security_inode_readlink(struct dentry *dentry)
882 return security_ops->inode_readlink(dentry);
884 +EXPORT_SYMBOL(security_inode_readlink);
886 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
888 @@ -594,6 +601,7 @@ int security_inode_permission(struct inode *inode, int mask)
890 return security_ops->inode_permission(inode, mask);
892 +EXPORT_SYMBOL(security_inode_permission);
894 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
896 @@ -716,6 +724,7 @@ int security_file_permission(struct file *file, int mask)
898 return fsnotify_perm(file, mask);
900 +EXPORT_SYMBOL(security_file_permission);
902 int security_file_alloc(struct file *file)
904 @@ -775,6 +784,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
906 return ima_file_mmap(file, prot);
908 +EXPORT_SYMBOL(security_mmap_file);
910 int security_mmap_addr(unsigned long addr)
912 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
913 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
914 +++ linux/Documentation/ABI/testing/debugfs-aufs 2014-01-30 21:10:02.794146538 +0100
916 +What: /debug/aufs/si_<id>/
918 +Contact: J. R. Okajima <hooanon05g@gmail.com>
920 + Under /debug/aufs, a directory named si_<id> is created
921 + per aufs mount, where <id> is a unique id generated
924 +What: /debug/aufs/si_<id>/plink
926 +Contact: J. R. Okajima <hooanon05g@gmail.com>
928 + It has three lines and shows the information about the
929 + pseudo-link. The first line is a single number
930 + representing a number of buckets. The second line is a
931 + number of pseudo-links per buckets (separated by a
932 + blank). The last line is a single number representing a
933 + total number of psedo-links.
934 + When the aufs mount option 'noplink' is specified, it
935 + will show "1\n0\n0\n".
937 +What: /debug/aufs/si_<id>/xib
939 +Contact: J. R. Okajima <hooanon05g@gmail.com>
941 + It shows the consumed blocks by xib (External Inode Number
942 + Bitmap), its block size and file size.
943 + When the aufs mount option 'noxino' is specified, it
944 + will be empty. About XINO files, see the aufs manual.
946 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
948 +Contact: J. R. Okajima <hooanon05g@gmail.com>
950 + It shows the consumed blocks by xino (External Inode Number
951 + Translation Table), its link count, block size and file
953 + When the aufs mount option 'noxino' is specified, it
954 + will be empty. About XINO files, see the aufs manual.
956 +What: /debug/aufs/si_<id>/xigen
958 +Contact: J. R. Okajima <hooanon05g@gmail.com>
960 + It shows the consumed blocks by xigen (External Inode
961 + Generation Table), its block size and file size.
962 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
964 + When the aufs mount option 'noxino' is specified, it
965 + will be empty. About XINO files, see the aufs manual.
966 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
967 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
968 +++ linux/Documentation/ABI/testing/sysfs-aufs 2014-01-30 21:10:02.794146538 +0100
970 +What: /sys/fs/aufs/si_<id>/
972 +Contact: J. R. Okajima <hooanon05g@gmail.com>
974 + Under /sys/fs/aufs, a directory named si_<id> is created
975 + per aufs mount, where <id> is a unique id generated
978 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
980 +Contact: J. R. Okajima <hooanon05g@gmail.com>
982 + It shows the abolute path of a member directory (which
983 + is called branch) in aufs, and its permission.
985 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
987 +Contact: J. R. Okajima <hooanon05g@gmail.com>
989 + It shows the id of a member directory (which is called
992 +What: /sys/fs/aufs/si_<id>/xi_path
994 +Contact: J. R. Okajima <hooanon05g@gmail.com>
996 + It shows the abolute path of XINO (External Inode Number
997 + Bitmap, Translation Table and Generation Table) file
998 + even if it is the default path.
999 + When the aufs mount option 'noxino' is specified, it
1000 + will be empty. About XINO files, see the aufs manual.
1001 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1002 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1003 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2015-06-22 08:27:37.867501461 +0200
1006 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1008 +# This program is free software; you can redistribute it and/or modify
1009 +# it under the terms of the GNU General Public License as published by
1010 +# the Free Software Foundation; either version 2 of the License, or
1011 +# (at your option) any later version.
1013 +# This program is distributed in the hope that it will be useful,
1014 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1015 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1016 +# GNU General Public License for more details.
1018 +# You should have received a copy of the GNU General Public License
1019 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1022 +----------------------------------------
1024 +aufs [ei ju: ef es] | [a u f s]
1025 +1. abbrev. for "advanced multi-layered unification filesystem".
1026 +2. abbrev. for "another unionfs".
1027 +3. abbrev. for "auf das" in German which means "on the" in English.
1028 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1029 + But "Filesystem aufs Filesystem" is hard to understand.
1031 +AUFS is a filesystem with features:
1032 +- multi layered stackable unification filesystem, the member directory
1033 + is called as a branch.
1034 +- branch permission and attribute, 'readonly', 'real-readonly',
1035 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1037 +- internal "file copy-on-write".
1038 +- logical deletion, whiteout.
1039 +- dynamic branch manipulation, adding, deleting and changing permission.
1040 +- allow bypassing aufs, user's direct branch access.
1041 +- external inode number translation table and bitmap which maintains the
1042 + persistent aufs inode number.
1043 +- seekable directory, including NFS readdir.
1044 +- file mapping, mmap and sharing pages.
1045 +- pseudo-link, hardlink over branches.
1046 +- loopback mounted filesystem as a branch.
1047 +- several policies to select one among multiple writable branches.
1048 +- revert a single systemcall when an error occurs in aufs.
1052 +Multi Layered Stackable Unification Filesystem
1053 +----------------------------------------------------------------------
1054 +Most people already knows what it is.
1055 +It is a filesystem which unifies several directories and provides a
1056 +merged single directory. When users access a file, the access will be
1057 +passed/re-directed/converted (sorry, I am not sure which English word is
1058 +correct) to the real file on the member filesystem. The member
1059 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1060 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1061 +readonly branch is handled by creating 'whiteout' on the upper writable
1064 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1065 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1066 +different approaches to implement the merged-view.
1067 +The former tries putting it into VFS, and the latter implements as a
1068 +separate filesystem.
1069 +(If I misunderstand about these implementations, please let me know and
1070 +I shall correct it. Because it is a long time ago when I read their
1071 +source files last time).
1073 +UnionMount's approach will be able to small, but may be hard to share
1074 +branches between several UnionMount since the whiteout in it is
1075 +implemented in the inode on branch filesystem and always
1076 +shared. According to Bharata's post, readdir does not seems to be
1078 +There are several missing features known in this implementations such as
1079 +- for users, the inode number may change silently. eg. copy-up.
1080 +- link(2) may break by copy-up.
1081 +- read(2) may get an obsoleted filedata (fstat(2) too).
1082 +- fcntl(F_SETLK) may be broken by copy-up.
1083 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1086 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1087 +merged into mainline. This is another implementation of UnionMount as a
1088 +separated filesystem. All the limitations and known problems which
1089 +UnionMount are equally inherited to "overlay" filesystem.
1091 +Unionfs has a longer history. When I started implementing a stackable
1092 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1093 +inode, dentry and file objects and they have an array pointing lower
1094 +same kind objects. After contributing many patches for Unionfs, I
1095 +re-started my project AUFS (Jun 2006).
1097 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1098 +implemented my own ideas, approaches and enhancements and it became
1099 +totally different one.
1101 +Comparing DM snapshot and fs based implementation
1102 +- the number of bytes to be copied between devices is much smaller.
1103 +- the type of filesystem must be one and only.
1104 +- the fs must be writable, no readonly fs, even for the lower original
1105 + device. so the compression fs will not be usable. but if we use
1106 + loopback mount, we may address this issue.
1108 + mount /cdrom/squashfs.img /sq
1109 + losetup /sq/ext2.img
1110 + losetup /somewhere/cow
1111 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1112 +- it will be difficult (or needs more operations) to extract the
1113 + difference between the original device and COW.
1114 +- DM snapshot-merge may help a lot when users try merging. in the
1115 + fs-layer union, users will use rsync(1).
1117 +You may want to read my old paper "Filesystems in LiveCD"
1118 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1121 +Several characters/aspects/persona of aufs
1122 +----------------------------------------------------------------------
1124 +Aufs has several characters, aspects or persona.
1125 +1. a filesystem, callee of VFS helper
1126 +2. sub-VFS, caller of VFS helper for branches
1127 +3. a virtual filesystem which maintains persistent inode number
1128 +4. reader/writer of files on branches such like an application
1130 +1. Callee of VFS Helper
1131 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1132 +unlink(2) from an application reaches sys_unlink() kernel function and
1133 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1134 +calls filesystem specific unlink operation. Actually aufs implements the
1135 +unlink operation but it behaves like a redirector.
1137 +2. Caller of VFS Helper for Branches
1138 +aufs_unlink() passes the unlink request to the branch filesystem as if
1139 +it were called from VFS. So the called unlink operation of the branch
1140 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1141 +every necessary pre/post operation for the branch filesystem.
1142 +- acquire the lock for the parent dir on a branch
1143 +- lookup in a branch
1144 +- revalidate dentry on a branch
1145 +- mnt_want_write() for a branch
1146 +- vfs_unlink() for a branch
1147 +- mnt_drop_write() for a branch
1148 +- release the lock on a branch
1150 +3. Persistent Inode Number
1151 +One of the most important issue for a filesystem is to maintain inode
1152 +numbers. This is particularly important to support exporting a
1153 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1154 +backend block device for its own. But some storage is necessary to
1155 +keep and maintain the inode numbers. It may be a large space and may not
1156 +suit to keep in memory. Aufs rents some space from its first writable
1157 +branch filesystem (by default) and creates file(s) on it. These files
1158 +are created by aufs internally and removed soon (currently) keeping
1160 +Note: Because these files are removed, they are totally gone after
1161 + unmounting aufs. It means the inode numbers are not persistent
1162 + across unmount or reboot. I have a plan to make them really
1163 + persistent which will be important for aufs on NFS server.
1165 +4. Read/Write Files Internally (copy-on-write)
1166 +Because a branch can be readonly, when you write a file on it, aufs will
1167 +"copy-up" it to the upper writable branch internally. And then write the
1168 +originally requested thing to the file. Generally kernel doesn't
1169 +open/read/write file actively. In aufs, even a single write may cause a
1170 +internal "file copy". This behaviour is very similar to cp(1) command.
1172 +Some people may think it is better to pass such work to user space
1173 +helper, instead of doing in kernel space. Actually I am still thinking
1174 +about it. But currently I have implemented it in kernel space.
1175 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1176 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1177 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2015-06-22 08:27:37.867501461 +0200
1180 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1182 +# This program is free software; you can redistribute it and/or modify
1183 +# it under the terms of the GNU General Public License as published by
1184 +# the Free Software Foundation; either version 2 of the License, or
1185 +# (at your option) any later version.
1187 +# This program is distributed in the hope that it will be useful,
1188 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1189 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1190 +# GNU General Public License for more details.
1192 +# You should have received a copy of the GNU General Public License
1193 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1195 +Basic Aufs Internal Structure
1197 +Superblock/Inode/Dentry/File Objects
1198 +----------------------------------------------------------------------
1199 +As like an ordinary filesystem, aufs has its own
1200 +superblock/inode/dentry/file objects. All these objects have a
1201 +dynamically allocated array and store the same kind of pointers to the
1202 +lower filesystem, branch.
1203 +For example, when you build a union with one readwrite branch and one
1204 +readonly, mounted /au, /rw and /ro respectively.
1206 +- /ro/fileA exists but /rw/fileA
1208 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1209 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1210 +- [0] = NULL (because /rw/fileA doesn't exist)
1213 +This style of an array is essentially same to the aufs
1214 +superblock/inode/dentry/file objects.
1216 +Because aufs supports manipulating branches, ie. add/delete/change
1217 +branches dynamically, these objects has its own generation. When
1218 +branches are changed, the generation in aufs superblock is
1219 +incremented. And a generation in other object are compared when it is
1220 +accessed. When a generation in other objects are obsoleted, aufs
1221 +refreshes the internal array.
1225 +----------------------------------------------------------------------
1226 +Additionally aufs superblock has some data for policies to select one
1227 +among multiple writable branches, XIB files, pseudo-links and kobject.
1228 +See below in detail.
1229 +About the policies which supports copy-down a directory, see
1230 +wbr_policy.txt too.
1233 +Branch and XINO(External Inode Number Translation Table)
1234 +----------------------------------------------------------------------
1235 +Every branch has its own xino (external inode number translation table)
1236 +file. The xino file is created and unlinked by aufs internally. When two
1237 +members of a union exist on the same filesystem, they share the single
1239 +The struct of a xino file is simple, just a sequence of aufs inode
1240 +numbers which is indexed by the lower inode number.
1241 +In the above sample, assume the inode number of /ro/fileA is i111 and
1242 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1243 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1245 +When the inode numbers are not contiguous, the xino file will be sparse
1246 +which has a hole in it and doesn't consume as much disk space as it
1247 +might appear. If your branch filesystem consumes disk space for such
1248 +holes, then you should specify 'xino=' option at mounting aufs.
1250 +Aufs has a mount option to free the disk blocks for such holes in XINO
1251 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1252 +meet a problem of disk shortage due to XINO files, then you should try
1253 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1254 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1255 +the holes in XINO files.
1257 +Also a writable branch has three kinds of "whiteout bases". All these
1258 +are existed when the branch is joined to aufs, and their names are
1259 +whiteout-ed doubly, so that users will never see their names in aufs
1261 +1. a regular file which will be hardlinked to all whiteouts.
1262 +2. a directory to store a pseudo-link.
1263 +3. a directory to store an "orphan"-ed file temporary.
1266 + When you remove a file on a readonly branch, aufs handles it as a
1267 + logical deletion and creates a whiteout on the upper writable branch
1268 + as a hardlink of this file in order not to consume inode on the
1271 + See below, Pseudo-link.
1273 + When "fileC" exists on the lower readonly branch only and it is
1274 + opened and removed with its parent dir, and then user writes
1275 + something into it, then aufs copies-up fileC to this
1276 + directory. Because there is no other dir to store fileC. After
1277 + creating a file under this dir, the file is unlinked.
1279 +Because aufs supports manipulating branches, ie. add/delete/change
1280 +dynamically, a branch has its own id. When the branch order changes,
1281 +aufs finds the new index by searching the branch id.
1285 +----------------------------------------------------------------------
1286 +Assume "fileA" exists on the lower readonly branch only and it is
1287 +hardlinked to "fileB" on the branch. When you write something to fileA,
1288 +aufs copies-up it to the upper writable branch. Additionally aufs
1289 +creates a hardlink under the Pseudo-link Directory of the writable
1290 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1291 +simple list. If fileB is read after unlinking fileA, aufs returns
1292 +filedata from the pseudo-link instead of the lower readonly
1293 +branch. Because the pseudo-link is based upon the inode, to keep the
1294 +inode number by xino (see above) is essentially necessary.
1296 +All the hardlinks under the Pseudo-link Directory of the writable branch
1297 +should be restored in a proper location later. Aufs provides a utility
1298 +to do this. The userspace helpers executed at remounting and unmounting
1300 +During this utility is running, it puts aufs into the pseudo-link
1301 +maintenance mode. In this mode, only the process which began the
1302 +maintenance mode (and its child processes) is allowed to operate in
1303 +aufs. Some other processes which are not related to the pseudo-link will
1304 +be allowed to run too, but the rest have to return an error or wait
1305 +until the maintenance mode ends. If a process already acquires an inode
1306 +mutex (in VFS), it has to return an error.
1309 +XIB(external inode number bitmap)
1310 +----------------------------------------------------------------------
1311 +Addition to the xino file per a branch, aufs has an external inode number
1312 +bitmap in a superblock object. It is also an internal file such like a
1314 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1316 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1318 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1319 +reduce the number of consumed disk blocks for these files.
1322 +Virtual or Vertical Dir, and Readdir in Userspace
1323 +----------------------------------------------------------------------
1324 +In order to support multiple layers (branches), aufs readdir operation
1325 +constructs a virtual dir block on memory. For readdir, aufs calls
1326 +vfs_readdir() internally for each dir on branches, merges their entries
1327 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1328 +object. So the file object has its entry list until it is closed. The
1329 +entry list will be updated when the file position is zero and becomes
1330 +obsoleted. This decision is made in aufs automatically.
1332 +The dynamically allocated memory block for the name of entries has a
1333 +unit of 512 bytes (by default) and stores the names contiguously (no
1334 +padding). Another block for each entry is handled by kmem_cache too.
1335 +During building dir blocks, aufs creates hash list and judging whether
1336 +the entry is whiteouted by its upper branch or already listed.
1337 +The merged result is cached in the corresponding inode object and
1338 +maintained by a customizable life-time option.
1340 +Some people may call it can be a security hole or invite DoS attack
1341 +since the opened and once readdir-ed dir (file object) holds its entry
1342 +list and becomes a pressure for system memory. But I'd say it is similar
1343 +to files under /proc or /sys. The virtual files in them also holds a
1344 +memory page (generally) while they are opened. When an idea to reduce
1345 +memory for them is introduced, it will be applied to aufs too.
1346 +For those who really hate this situation, I've developed readdir(3)
1347 +library which operates this merging in userspace. You just need to set
1348 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1349 +kernel space for readdir(3).
1353 +----------------------------------------------------------------------
1354 +Aufs sometimes requires privilege access to a branch. For instance,
1355 +in copy-up/down operation. When a user process is going to make changes
1356 +to a file which exists in the lower readonly branch only, and the mode
1357 +of one of ancestor directories may not be writable by a user
1358 +process. Here aufs copy-up the file with its ancestors and they may
1359 +require privilege to set its owner/group/mode/etc.
1360 +This is a typical case of a application character of aufs (see
1363 +Aufs uses workqueue synchronously for this case. It creates its own
1364 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1365 +passes the request to call mkdir or write (for example), and wait for
1366 +its completion. This approach solves a problem of a signal handler
1368 +If aufs didn't adopt the workqueue and changed the privilege of the
1369 +process, then the process may receive the unexpected SIGXFSZ or other
1372 +Also aufs uses the system global workqueue ("events" kernel thread) too
1373 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1374 +whiteout base and etc. This is unrelated to a privilege.
1375 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1376 +superblock at the beginning, at the same time waits for the completion
1377 +of all queued asynchronous tasks.
1381 +----------------------------------------------------------------------
1382 +The whiteout in aufs is very similar to Unionfs's. That is represented
1383 +by its filename. UnionMount takes an approach of a file mode, but I am
1384 +afraid several utilities (find(1) or something) will have to support it.
1386 +Basically the whiteout represents "logical deletion" which stops aufs to
1387 +lookup further, but also it represents "dir is opaque" which also stop
1390 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1391 +In order to make several functions in a single systemcall to be
1392 +revertible, aufs adopts an approach to rename a directory to a temporary
1393 +unique whiteouted name.
1394 +For example, in rename(2) dir where the target dir already existed, aufs
1395 +renames the target dir to a temporary unique whiteouted name before the
1396 +actual rename on a branch, and then handles other actions (make it opaque,
1397 +update the attributes, etc). If an error happens in these actions, aufs
1398 +simply renames the whiteouted name back and returns an error. If all are
1399 +succeeded, aufs registers a function to remove the whiteouted unique
1400 +temporary name completely and asynchronously to the system global
1405 +----------------------------------------------------------------------
1406 +It is a well-known feature or concept.
1407 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1408 +internally and makes change to the new file on the upper writable branch.
1409 +When the trigger systemcall does not update the timestamps of the parent
1410 +dir, aufs reverts it after copy-up.
1413 +Move-down (aufs3.9 and later)
1414 +----------------------------------------------------------------------
1415 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1416 +the lower readonly branch to the upper writable branch when a user
1417 +changes something about the file.
1418 +"Move-down" is an opposite action of copy-up. Basically this action is
1419 +ran manually instead of automatically and internally.
1420 +For desgin and implementation, aufs has to consider these issues.
1421 +- whiteout for the file may exist on the lower branch.
1422 +- ancestor directories may not exist on the lower branch.
1423 +- diropq for the ancestor directories may exist on the upper branch.
1424 +- free space on the lower branch will reduce.
1425 +- another access to the file may happen during moving-down, including
1426 + UDBA (see "Revalidate Dentry and UDBA").
1427 +- the file should not be hard-linked nor pseudo-linked. they should be
1428 + handled by auplink utility later.
1430 +Sometimes users want to move-down a file from the upper writable branch
1431 +to the lower readonly or writable branch. For instance,
1432 +- the free space of the upper writable branch is going to run out.
1433 +- create a new intermediate branch between the upper and lower branch.
1436 +For this purpose, use "aumvdown" command in aufs-util.git.
1437 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1438 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1439 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2015-06-22 08:27:37.870834875 +0200
1442 +# Copyright (C) 2015 Junjiro R. Okajima
1444 +# This program is free software; you can redistribute it and/or modify
1445 +# it under the terms of the GNU General Public License as published by
1446 +# the Free Software Foundation; either version 2 of the License, or
1447 +# (at your option) any later version.
1449 +# This program is distributed in the hope that it will be useful,
1450 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1451 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1452 +# GNU General Public License for more details.
1454 +# You should have received a copy of the GNU General Public License
1455 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1457 +Support for a branch who has its ->atomic_open()
1458 +----------------------------------------------------------------------
1459 +The filesystems who implement its ->atomic_open() are not majority. For
1460 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1461 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1462 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1463 +sure whether all filesystems who have ->atomic_open() behave like this,
1464 +but NFSv4 surely returns the error.
1466 +In order to support ->atomic_open() for aufs, there are a few
1469 +A. Introduce aufs_atomic_open()
1470 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1472 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1473 + an aufs user Pip Cet's approach
1474 + - calls aufs_create(), VFS finish_open() and notify_change().
1475 + - pass fake-mode to finish_open(), and then correct the mode by
1477 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1478 + - no aufs_atomic_open().
1479 + - aufs_lookup() registers the TID to an aufs internal object.
1480 + - aufs_create() does nothing when the matching TID is registered, but
1481 + registers the mode.
1482 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1483 + TID is registered.
1484 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1486 + - no aufs_atomic_open().
1487 + - aufs_create() registers the TID to an internal object. this info
1488 + represents "this process created this file just now."
1489 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1490 + registered TID and re-try open() with superuser's credential.
1492 +Pros and cons for each approach.
1495 + - straightforward but highly depends upon VFS internal.
1496 + - the atomic behavaiour is kept.
1497 + - some of parameters such as nameidata are hard to reproduce for
1501 + - easy to implement.
1502 + - the atomic behavaiour is lost.
1504 + - the atomic behavaiour is kept.
1505 + - dirty and tricky.
1506 + - VFS checks whether the file is created correctly after calling
1507 + ->create(), which means this approach doesn't work.
1509 + - easy to implement.
1510 + - the atomic behavaiour is lost.
1511 + - to open a file with superuser's credential and give it to a user
1512 + process is a bad idea, since the file object keeps the credential
1513 + in it. It may affect LSM or something. This approach doesn't work
1516 +The approach A is ideal, but it hard to implement. So here is a
1517 +variation of A, which is to be implemented.
1519 +A-1. Introduce aufs_atomic_open()
1520 + - calls branch fs ->atomic_open() if exists. otherwise calls
1521 + vfs_create() and finish_open().
1522 + - the demerit is that the several checks after branch fs
1523 + ->atomic_open() are lost. in the ordinary case, the checks are
1524 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1525 + be implemented in aufs, but not all I am afraid.
1526 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1527 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1528 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2015-06-22 08:27:37.870834875 +0200
1531 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1533 +# This program is free software; you can redistribute it and/or modify
1534 +# it under the terms of the GNU General Public License as published by
1535 +# the Free Software Foundation; either version 2 of the License, or
1536 +# (at your option) any later version.
1538 +# This program is distributed in the hope that it will be useful,
1539 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1540 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1541 +# GNU General Public License for more details.
1543 +# You should have received a copy of the GNU General Public License
1544 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1547 +----------------------------------------------------------------------
1548 +Since aufs has a character of sub-VFS (see Introduction), it operates
1549 +lookup for branches as VFS does. It may be a heavy work. But almost all
1550 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1551 +directly connected to its parent. Digging down the directory hierarchy
1552 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1555 +When a branch is a remote filesystem, aufs basically relies upon its
1556 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1558 +For d_revalidate, aufs implements three levels of revalidate tests. See
1559 +"Revalidate Dentry and UDBA" in detail.
1562 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1563 +----------------------------------------------------------------------
1564 +Let's try case study.
1565 +- aufs has two branches, upper readwrite and lower readonly.
1567 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1568 +- user invoked "chmod a+rx /au/dirA"
1569 +- the internal copy-up is activated and "/rw/dirA" is created and its
1570 + permission bits are set to world readable.
1571 +- then "/au/dirA" becomes world readable?
1573 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1574 +or it may be a natively readonly filesystem. If aufs respects the lower
1575 +branch, it should not respond readdir request from other users. But user
1576 +allowed it by chmod. Should really aufs rejects showing the entries
1579 +To be honest, I don't have a good solution for this case. So aufs
1580 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1582 +When dirperm1 is specified, aufs checks only the highest one for the
1583 +directory permission, and shows the entries. Otherwise, as usual, checks
1584 +every dir existing on all branches and rejects the request.
1586 +As a side effect, dirperm1 option improves the performance of aufs
1587 +because the number of permission check is reduced when the number of
1591 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1592 +----------------------------------------------------------------------
1593 +Generally VFS helpers re-validate a dentry as a part of lookup.
1594 +0. digging down the directory hierarchy.
1595 +1. lock the parent dir by its i_mutex.
1596 +2. lookup the final (child) entry.
1598 +4. call the actual operation (create, unlink, etc.)
1599 +5. unlock the parent dir
1601 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1602 +called. Actually aufs implements it and checks the dentry on a branch is
1604 +But it is not enough. Because aufs has to release the lock for the
1605 +parent dir on a branch at the end of ->lookup() (step 2) and
1606 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1608 +If the file on a branch is changed directly, eg. bypassing aufs, after
1609 +aufs released the lock, then the subsequent operation may cause
1610 +something unpleasant result.
1612 +This situation is a result of VFS architecture, ->lookup() and
1613 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1614 +design from VFS's point of view. It is just not suitable for sub-VFS
1617 +Aufs supports such case by three level of revalidation which is
1618 +selectable by user.
1619 +1. Simple Revalidate
1620 + Addition to the native flow in VFS's, confirm the child-parent
1621 + relationship on the branch just after locking the parent dir on the
1622 + branch in the "actual operation" (step 4). When this validation
1623 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1624 + checks the validation of the dentry on branches.
1625 +2. Monitor Changes Internally by Inotify/Fsnotify
1626 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1627 + the dentry on the branch, and returns EBUSY if it finds different
1629 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1630 + during it is in cache. When the event is notified, aufs registers a
1631 + function to kernel 'events' thread by schedule_work(). And the
1632 + function sets some special status to the cached aufs dentry and inode
1633 + private data. If they are not cached, then aufs has nothing to
1634 + do. When the same file is accessed through aufs (step 0-3) later,
1635 + aufs will detect the status and refresh all necessary data.
1636 + In this mode, aufs has to ignore the event which is fired by aufs
1638 +3. No Extra Validation
1639 + This is the simplest test and doesn't add any additional revalidation
1640 + test, and skip the revalidation in step 4. It is useful and improves
1641 + aufs performance when system surely hide the aufs branches from user,
1642 + by over-mounting something (or another method).
1643 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1644 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1645 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2015-06-22 08:27:37.870834875 +0200
1648 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1650 +# This program is free software; you can redistribute it and/or modify
1651 +# it under the terms of the GNU General Public License as published by
1652 +# the Free Software Foundation; either version 2 of the License, or
1653 +# (at your option) any later version.
1655 +# This program is distributed in the hope that it will be useful,
1656 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1657 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1658 +# GNU General Public License for more details.
1660 +# You should have received a copy of the GNU General Public License
1661 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1663 +Branch Manipulation
1665 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1666 +and changing its permission/attribute, there are a lot of works to do.
1670 +----------------------------------------------------------------------
1671 +o Confirm the adding dir exists outside of aufs, including loopback
1672 + mount, and its various attributes.
1673 +o Initialize the xino file and whiteout bases if necessary.
1676 +o Check the owner/group/mode of the directory
1677 + When the owner/group/mode of the adding directory differs from the
1678 + existing branch, aufs issues a warning because it may impose a
1680 + For example, when a upper writable branch has a world writable empty
1681 + top directory, a malicious user can create any files on the writable
1682 + branch directly, like copy-up and modify manually. If something like
1683 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1684 + writable branch, and the writable branch is world-writable, then a
1685 + malicious guy may create /etc/passwd on the writable branch directly
1686 + and the infected file will be valid in aufs.
1687 + I am afraid it can be a security issue, but aufs can do nothing except
1688 + producing a warning.
1692 +----------------------------------------------------------------------
1693 +o Confirm the deleting branch is not busy
1694 + To be general, there is one merit to adopt "remount" interface to
1695 + manipulate branches. It is to discard caches. At deleting a branch,
1696 + aufs checks the still cached (and connected) dentries and inodes. If
1697 + there are any, then they are all in-use. An inode without its
1698 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1700 + For the cached one, aufs checks whether the same named entry exists on
1702 + If the cached one is a directory, because aufs provides a merged view
1703 + to users, as long as one dir is left on any branch aufs can show the
1704 + dir to users. In this case, the branch can be removed from aufs.
1705 + Otherwise aufs rejects deleting the branch.
1707 + If any file on the deleting branch is opened by aufs, then aufs
1711 +Modify the Permission of a Branch
1712 +----------------------------------------------------------------------
1713 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1716 +o rw --> ro: Confirm the modifying branch is not busy
1717 + Aufs rejects the request if any of these conditions are true.
1718 + - a file on the branch is mmap-ed.
1719 + - a regular file on the branch is opened for write and there is no
1720 + same named entry on the upper branch.
1721 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1722 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1723 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2015-06-22 08:27:37.870834875 +0200
1726 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1728 +# This program is free software; you can redistribute it and/or modify
1729 +# it under the terms of the GNU General Public License as published by
1730 +# the Free Software Foundation; either version 2 of the License, or
1731 +# (at your option) any later version.
1733 +# This program is distributed in the hope that it will be useful,
1734 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1735 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1736 +# GNU General Public License for more details.
1738 +# You should have received a copy of the GNU General Public License
1739 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1741 +Policies to Select One among Multiple Writable Branches
1742 +----------------------------------------------------------------------
1743 +When the number of writable branch is more than one, aufs has to decide
1744 +the target branch for file creation or copy-up. By default, the highest
1745 +writable branch which has the parent (or ancestor) dir of the target
1746 +file is chosen (top-down-parent policy).
1747 +By user's request, aufs implements some other policies to select the
1748 +writable branch, for file creation several policies, round-robin,
1749 +most-free-space, and other policies. For copy-up, top-down-parent,
1750 +bottom-up-parent, bottom-up and others.
1752 +As expected, the round-robin policy selects the branch in circular. When
1753 +you have two writable branches and creates 10 new files, 5 files will be
1754 +created for each branch. mkdir(2) systemcall is an exception. When you
1755 +create 10 new directories, all will be created on the same branch.
1756 +And the most-free-space policy selects the one which has most free
1757 +space among the writable branches. The amount of free space will be
1758 +checked by aufs internally, and users can specify its time interval.
1760 +The policies for copy-up is more simple,
1761 +top-down-parent is equivalent to the same named on in create policy,
1762 +bottom-up-parent selects the writable branch where the parent dir
1763 +exists and the nearest upper one from the copyup-source,
1764 +bottom-up selects the nearest upper writable branch from the
1765 +copyup-source, regardless the existence of the parent dir.
1767 +There are some rules or exceptions to apply these policies.
1768 +- If there is a readonly branch above the policy-selected branch and
1769 + the parent dir is marked as opaque (a variation of whiteout), or the
1770 + target (creating) file is whiteout-ed on the upper readonly branch,
1771 + then the result of the policy is ignored and the target file will be
1772 + created on the nearest upper writable branch than the readonly branch.
1773 +- If there is a writable branch above the policy-selected branch and
1774 + the parent dir is marked as opaque or the target file is whiteouted
1775 + on the branch, then the result of the policy is ignored and the target
1776 + file will be created on the highest one among the upper writable
1777 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1779 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1780 + They try selecting the branch where the source exists as possible
1781 + since copyup a large file will take long time. If it can't be,
1782 + ie. the branch where the source exists is readonly, then they will
1783 + follow the copyup policy.
1784 +- There is an exception for rename(2) when the target exists.
1785 + If the rename target exists, aufs compares the index of the branches
1786 + where the source and the target exists and selects the higher
1787 + one. If the selected branch is readonly, then aufs follows the
1789 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1790 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1791 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2015-06-22 08:27:37.870834875 +0200
1794 +# Copyright (C) 2011-2015 Junjiro R. Okajima
1796 +# This program is free software; you can redistribute it and/or modify
1797 +# it under the terms of the GNU General Public License as published by
1798 +# the Free Software Foundation; either version 2 of the License, or
1799 +# (at your option) any later version.
1801 +# This program is distributed in the hope that it will be useful,
1802 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1803 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1804 +# GNU General Public License for more details.
1806 +# You should have received a copy of the GNU General Public License
1807 +# along with this program; if not, write to the Free Software
1808 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1811 +File-based Hierarchical Storage Management (FHSM)
1812 +----------------------------------------------------------------------
1813 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1814 +storage world. Aufs provides this feature as file-based with multiple
1815 +writable branches, based upon the principle of "Colder, the Lower".
1816 +Here the word "colder" means that the less used files, and "lower" means
1817 +that the position in the order of the stacked branches vertically.
1818 +These multiple writable branches are prioritized, ie. the topmost one
1819 +should be the fastest drive and be used heavily.
1821 +o Characters in aufs FHSM story
1822 +- aufs itself and a new branch attribute.
1823 +- a new ioctl interface to move-down and to establish a connection with
1824 + the daemon ("move-down" is a converse of "copy-up").
1825 +- userspace tool and daemon.
1827 +The userspace daemon establishes a connection with aufs and waits for
1828 +the notification. The notified information is very similar to struct
1829 +statfs containing the number of consumed blocks and inodes.
1830 +When the consumed blocks/inodes of a branch exceeds the user-specified
1831 +upper watermark, the daemon activates its move-down process until the
1832 +consumed blocks/inodes reaches the user-specified lower watermark.
1834 +The actual move-down is done by aufs based upon the request from
1835 +user-space since we need to maintain the inode number and the internal
1836 +pointer arrays in aufs.
1838 +Currently aufs FHSM handles the regular files only. Additionally they
1839 +must not be hard-linked nor pseudo-linked.
1842 +o Cowork of aufs and the user-space daemon
1843 + During the userspace daemon established the connection, aufs sends a
1844 + small notification to it whenever aufs writes something into the
1845 + writable branch. But it may cost high since aufs issues statfs(2)
1846 + internally. So user can specify a new option to cache the
1847 + info. Actually the notification is controlled by these factors.
1848 + + the specified cache time.
1849 + + classified as "force" by aufs internally.
1850 + Until the specified time expires, aufs doesn't send the info
1851 + except the forced cases. When aufs decide forcing, the info is always
1852 + notified to userspace.
1853 + For example, the number of free inodes is generally large enough and
1854 + the shortage of it happens rarely. So aufs doesn't force the
1855 + notification when creating a new file, directory and others. This is
1856 + the typical case which aufs doesn't force.
1857 + When aufs writes the actual filedata and the files consumes any of new
1858 + blocks, the aufs forces notifying.
1861 +o Interfaces in aufs
1862 +- New branch attribute.
1864 + Specifies that the branch is managed by FHSM feature. In other word,
1865 + participant in the FHSM.
1866 + When nofhsm is set to the branch, it will not be the source/target
1867 + branch of the move-down operation. This attribute is set
1868 + independently from coo and moo attributes, and if you want full
1869 + FHSM, you should specify them as well.
1870 +- New mount option.
1872 + Specifies a second to suppress many less important info to be
1875 + + AUFS_CTL_FHSM_FD
1876 + create a new file descriptor which userspace can read the notification
1877 + (a subset of struct statfs) from aufs.
1878 +- Module parameter 'brs'
1879 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
1881 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
1882 + When there are two or more branches with fhsm attributes,
1883 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
1884 + terminates it. As a result of remounting and branch-manipulation, the
1885 + number of branches with fhsm attribute can be one. In this case,
1886 + /sbin/mount.aufs will terminate the user-space daemon.
1889 +Finally the operation is done as these steps in kernel-space.
1891 + + no one else is using the file.
1892 + + the file is not hard-linked.
1893 + + the file is not pseudo-linked.
1894 + + the file is a regular file.
1895 + + the parent dir is not opaqued.
1896 +- find the target writable branch.
1897 +- make sure the file is not whiteout-ed by the upper (than the target)
1899 +- make the parent dir on the target branch.
1900 +- mutex lock the inode on the branch.
1901 +- unlink the whiteout on the target branch (if exists).
1902 +- lookup and create the whiteout-ed temporary name on the target branch.
1903 +- copy the file as the whiteout-ed temporary name on the target branch.
1904 +- rename the whiteout-ed temporary name to the original name.
1905 +- unlink the file on the source branch.
1906 +- maintain the internal pointer array and the external inode number
1908 +- maintain the timestamps and other attributes of the parent dir and the
1911 +And of course, in every step, an error may happen. So the operation
1912 +should restore the original file state after an error happens.
1913 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1914 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1915 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2015-06-22 08:27:37.870834875 +0200
1918 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1920 +# This program is free software; you can redistribute it and/or modify
1921 +# it under the terms of the GNU General Public License as published by
1922 +# the Free Software Foundation; either version 2 of the License, or
1923 +# (at your option) any later version.
1925 +# This program is distributed in the hope that it will be useful,
1926 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1927 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1928 +# GNU General Public License for more details.
1930 +# You should have received a copy of the GNU General Public License
1931 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1933 +mmap(2) -- File Memory Mapping
1934 +----------------------------------------------------------------------
1935 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1936 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1938 +This approach is simple and good, but there is one problem.
1939 +Under /proc, several entries show the mmapped files by its path (with
1940 +device and inode number), and the printed path will be the path on the
1941 +branch fs's instead of virtual aufs's.
1942 +This is not a problem in most cases, but some utilities lsof(1) (and its
1943 +user) may expect the path on aufs.
1945 +To address this issue, aufs adds a new member called vm_prfile in struct
1946 +vm_area_struct (and struct vm_region). The original vm_file points to
1947 +the file on the branch fs in order to handle everything correctly as
1948 +usual. The new vm_prfile points to a virtual file in aufs, and the
1949 +show-functions in procfs refers to vm_prfile if it is set.
1950 +Also we need to maintain several other places where touching vm_file
1952 +- fork()/clone() copies vma and the reference count of vm_file is
1954 +- merging vma maintains the ref count too.
1956 +This is not a good approach. It just fakes the printed path. But it
1957 +leaves all behaviour around f_mapping unchanged. This is surely an
1959 +Actually aufs had adopted another complicated approach which calls
1960 +generic_file_mmap() and handles struct vm_operations_struct. In this
1961 +approach, aufs met a hard problem and I could not solve it without
1962 +switching the approach.
1964 +There may be one more another approach which is
1965 +- bind-mount the branch-root onto the aufs-root internally
1966 +- grab the new vfsmount (ie. struct mount)
1967 +- lazy-umount the branch-root internally
1968 +- in open(2) the aufs-file, open the branch-file with the hidden
1969 + vfsmount (instead of the original branch's vfsmount)
1970 +- ideally this "bind-mount and lazy-umount" should be done atomically,
1971 + but it may be possible from userspace by the mount helper.
1973 +Adding the internal hidden vfsmount and using it in opening a file, the
1974 +file path under /proc will be printed correctly. This approach looks
1975 +smarter, but is not possible I am afraid.
1976 +- aufs-root may be bind-mount later. when it happens, another hidden
1977 + vfsmount will be required.
1978 +- it is hard to get the chance to bind-mount and lazy-umount
1979 + + in kernel-space, FS can have vfsmount in open(2) via
1980 + file->f_path, and aufs can know its vfsmount. But several locks are
1981 + already acquired, and if aufs tries to bind-mount and lazy-umount
1982 + here, then it may cause a deadlock.
1983 + + in user-space, bind-mount doesn't invoke the mount helper.
1984 +- since /proc shows dev and ino, aufs has to give vma these info. it
1985 + means a new member vm_prinode will be necessary. this is essentially
1986 + equivalent to vm_prfile described above.
1988 +I have to give up this "looks-smater" approach.
1989 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
1990 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
1991 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2015-06-22 08:27:37.870834875 +0200
1994 +# Copyright (C) 2014-2015 Junjiro R. Okajima
1996 +# This program is free software; you can redistribute it and/or modify
1997 +# it under the terms of the GNU General Public License as published by
1998 +# the Free Software Foundation; either version 2 of the License, or
1999 +# (at your option) any later version.
2001 +# This program is distributed in the hope that it will be useful,
2002 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2003 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2004 +# GNU General Public License for more details.
2006 +# You should have received a copy of the GNU General Public License
2007 +# along with this program; if not, write to the Free Software
2008 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2011 +Listing XATTR/EA and getting the value
2012 +----------------------------------------------------------------------
2013 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2014 +shows the values from the topmost existing file. This behaviour is good
2015 +for the non-dir entries since the bahaviour exactly matches the shown
2016 +information. But for the directories, aufs considers all the same named
2017 +entries on the lower branches. Which means, if one of the lower entry
2018 +rejects readdir call, then aufs returns an error even if the topmost
2019 +entry allows it. This behaviour is necessary to respect the branch fs's
2020 +security, but can make users confused since the user-visible standard
2021 +attributes don't match the behaviour.
2022 +To address this issue, aufs has a mount option called dirperm1 which
2023 +checks the permission for the topmost entry only, and ignores the lower
2024 +entry's permission.
2026 +A similar issue can happen around XATTR.
2027 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2028 +always set. Otherwise these very unpleasant situation would happen.
2029 +- listxattr(2) may return the duplicated entries.
2030 +- users may not be able to remove or reset the XATTR forever,
2033 +XATTR/EA support in the internal (copy,move)-(up,down)
2034 +----------------------------------------------------------------------
2035 +Generally the extended attributes of inode are categorized as these.
2036 +- "security" for LSM and capability.
2037 +- "system" for posix ACL, 'acl' mount option is required for the branch
2039 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2040 +- "user" for userspace, 'user_xattr' mount option is required for the
2041 + branch fs generally.
2043 +Moreover there are some other categories. Aufs handles these rather
2044 +unpopular categories as the ordinary ones, ie. there is no special
2045 +condition nor exception.
2047 +In copy-up, the support for XATTR on the dst branch may differ from the
2048 +src branch. In this case, the copy-up operation will get an error and
2049 +the original user operation which triggered the copy-up will fail. It
2050 +can happen that even all copy-up will fail.
2051 +When both of src and dst branches support XATTR and if an error occurs
2052 +during copying XATTR, then the copy-up should fail obviously. That is a
2053 +good reason and aufs should return an error to userspace. But when only
2054 +the src branch support that XATTR, aufs should not return an error.
2055 +For example, the src branch supports ACL but the dst branch doesn't
2056 +because the dst branch may natively un-support it or temporary
2057 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2058 +may NOT return an error even if the XATTR is not supported. It is
2059 +totally up to the branch fs.
2061 +Anyway when the aufs internal copy-up gets an error from the dst branch
2062 +fs, then aufs tries removing the just copied entry and returns the error
2063 +to the userspace. The worst case of this situation will be all copy-up
2066 +For the copy-up operation, there two basic approaches.
2067 +- copy the specified XATTR only (by category above), and return the
2068 + error unconditionally if it happens.
2069 +- copy all XATTR, and ignore the error on the specified category only.
2071 +In order to support XATTR and to implement the correct behaviour, aufs
2072 +chooses the latter approach and introduces some new branch attributes,
2073 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2074 +They correspond to the XATTR namespaces (see above). Additionally, to be
2075 +convenient, "icex" is also provided which means all "icex*" attributes
2076 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2078 +The meaning of these attributes is to ignore the error from setting
2079 +XATTR on that branch.
2080 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2081 +error from the dst branch according to the specified attributes.
2083 +Some XATTR may have its default value. The default value may come from
2084 +the parent dir or the environment. If the default value is set at the
2085 +file creating-time, it will be overwritten by copy-up.
2086 +Some contradiction may happen I am afraid.
2087 +Do we need another attribute to stop copying XATTR? I am unsure. For
2088 +now, aufs implements the branch attributes to ignore the error.
2089 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2090 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2091 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2015-06-22 08:27:37.870834875 +0200
2094 +# Copyright (C) 2005-2015 Junjiro R. Okajima
2096 +# This program is free software; you can redistribute it and/or modify
2097 +# it under the terms of the GNU General Public License as published by
2098 +# the Free Software Foundation; either version 2 of the License, or
2099 +# (at your option) any later version.
2101 +# This program is distributed in the hope that it will be useful,
2102 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2103 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2104 +# GNU General Public License for more details.
2106 +# You should have received a copy of the GNU General Public License
2107 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2109 +Export Aufs via NFS
2110 +----------------------------------------------------------------------
2111 +Here is an approach.
2112 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2114 +- iget_locked(): initialize aufs inode generation for a new inode, and
2115 + store it in xigen file.
2116 +- destroy_inode(): increment aufs inode generation and store it in xigen
2117 + file. it is necessary even if it is not unlinked, because any data of
2118 + inode may be changed by UDBA.
2119 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2120 + build file handle by
2121 + + branch id (4 bytes)
2122 + + superblock generation (4 bytes)
2123 + + inode number (4 or 8 bytes)
2124 + + parent dir inode number (4 or 8 bytes)
2125 + + inode generation (4 bytes))
2126 + + return value of exportfs_encode_fh() for the parent on a branch (4
2128 + + file handle for a branch (by exportfs_encode_fh())
2130 + + find the index of a branch from its id in handle, and check it is
2131 + still exist in aufs.
2132 + + 1st level: get the inode number from handle and search it in cache.
2133 + + 2nd level: if not found in cache, get the parent inode number from
2134 + the handle and search it in cache. and then open the found parent
2135 + dir, find the matching inode number by vfs_readdir() and get its
2136 + name, and call lookup_one_len() for the target dentry.
2137 + + 3rd level: if the parent dir is not cached, call
2138 + exportfs_decode_fh() for a branch and get the parent on a branch,
2139 + build a pathname of it, convert it a pathname in aufs, call
2140 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2142 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2143 + for every branch, but not itself. to get this, (currently) aufs
2144 + searches in current->nsproxy->mnt_ns list. it may not be a good
2145 + idea, but I didn't get other approach.
2146 + + test the generation of the gotten inode.
2147 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2148 + convert it into ESTALE for NFSD.
2149 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2150 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2151 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2152 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2153 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2015-06-22 08:27:37.870834875 +0200
2156 +# Copyright (C) 2005-2015 Junjiro R. Okajima
2158 +# This program is free software; you can redistribute it and/or modify
2159 +# it under the terms of the GNU General Public License as published by
2160 +# the Free Software Foundation; either version 2 of the License, or
2161 +# (at your option) any later version.
2163 +# This program is distributed in the hope that it will be useful,
2164 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2165 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2166 +# GNU General Public License for more details.
2168 +# You should have received a copy of the GNU General Public License
2169 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2171 +Show Whiteout Mode (shwh)
2172 +----------------------------------------------------------------------
2173 +Generally aufs hides the name of whiteouts. But in some cases, to show
2174 +them is very useful for users. For instance, creating a new middle layer
2175 +(branch) by merging existing layers.
2177 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2178 +When you have three branches,
2179 +- Bottom: 'system', squashfs (underlying base system), read-only
2180 +- Middle: 'mods', squashfs, read-only
2181 +- Top: 'overlay', ram (tmpfs), read-write
2183 +The top layer is loaded at boot time and saved at shutdown, to preserve
2184 +the changes made to the system during the session.
2185 +When larger changes have been made, or smaller changes have accumulated,
2186 +the size of the saved top layer data grows. At this point, it would be
2187 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2188 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2189 +restoring save and load speed.
2191 +This merging is simplified by the use of another aufs mount, of just the
2192 +two overlay branches using the 'shwh' option.
2193 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2194 + aufs /livesys/merge_union
2196 +A merged view of these two branches is then available at
2197 +/livesys/merge_union, and the new feature is that the whiteouts are
2199 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2200 +writing to all branches. Also the default mode for all branches is 'ro'.
2201 +It is now possible to save the combined contents of the two overlay
2202 +branches to a new squashfs, e.g.:
2203 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2205 +This new squashfs archive can be stored on the boot device and the
2206 +initramfs will use it to replace the old one at the next boot.
2207 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2208 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2209 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2015-06-22 08:27:37.870834875 +0200
2212 +# Copyright (C) 2010-2015 Junjiro R. Okajima
2214 +# This program is free software; you can redistribute it and/or modify
2215 +# it under the terms of the GNU General Public License as published by
2216 +# the Free Software Foundation; either version 2 of the License, or
2217 +# (at your option) any later version.
2219 +# This program is distributed in the hope that it will be useful,
2220 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2221 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2222 +# GNU General Public License for more details.
2224 +# You should have received a copy of the GNU General Public License
2225 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2227 +Dynamically customizable FS operations
2228 +----------------------------------------------------------------------
2229 +Generally FS operations (struct inode_operations, struct
2230 +address_space_operations, struct file_operations, etc.) are defined as
2231 +"static const", but it never means that FS have only one set of
2232 +operation. Some FS have multiple sets of them. For instance, ext2 has
2233 +three sets, one for XIP, for NOBH, and for normal.
2234 +Since aufs overrides and redirects these operations, sometimes aufs has
2235 +to change its behaviour according to the branch FS type. More importantly
2236 +VFS acts differently if a function (member in the struct) is set or
2237 +not. It means aufs should have several sets of operations and select one
2238 +among them according to the branch FS definition.
2240 +In order to solve this problem and not to affect the behaviour of VFS,
2241 +aufs defines these operations dynamically. For instance, aufs defines
2242 +dummy direct_IO function for struct address_space_operations, but it may
2243 +not be set to the address_space_operations actually. When the branch FS
2244 +doesn't have it, aufs doesn't set it to its address_space_operations
2245 +while the function definition itself is still alive. So the behaviour
2246 +itself will not change, and it will return an error when direct_IO is
2249 +The lifetime of these dynamically generated operation object is
2250 +maintained by aufs branch object. When the branch is removed from aufs,
2251 +the reference counter of the object is decremented. When it reaches
2252 +zero, the dynamically generated operation object will be freed.
2254 +This approach is designed to support AIO (io_submit), Direct I/O and
2256 +Currently this approach is applied to address_space_operations for
2257 +regular files only.
2258 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt linux/Documentation/filesystems/aufs/design/99plan.txt
2259 --- /usr/share/empty/Documentation/filesystems/aufs/design/99plan.txt 1970-01-01 01:00:00.000000000 +0100
2260 +++ linux/Documentation/filesystems/aufs/design/99plan.txt 2015-06-22 08:27:37.870834875 +0200
2263 +# Copyright (C) 2005-2015 Junjiro R. Okajima
2265 +# This program is free software; you can redistribute it and/or modify
2266 +# it under the terms of the GNU General Public License as published by
2267 +# the Free Software Foundation; either version 2 of the License, or
2268 +# (at your option) any later version.
2270 +# This program is distributed in the hope that it will be useful,
2271 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2272 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2273 +# GNU General Public License for more details.
2275 +# You should have received a copy of the GNU General Public License
2276 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2280 +Restoring some features which was implemented in aufs1.
2281 +They were dropped in aufs2 in order to make source files simpler and
2282 +easier to be reviewed.
2285 +Being Another Aufs's Readonly Branch (robr)
2286 +----------------------------------------------------------------------
2287 +Aufs1 allows aufs to be another aufs's readonly branch.
2288 +This feature was developed by a user's request. But it may not be used
2292 +Refresh the Opened File (refrof)
2293 +----------------------------------------------------------------------
2294 +This option is implemented in aufs1 but incomplete.
2296 +When user reads from a file, he expects to get its latest filedata
2297 +generally. If the file is removed and a new same named file is created,
2298 +the content he gets is unchanged, ie. the unlinked filedata.
2300 +Let's try case study again.
2301 +- aufs has two branches.
2303 +- "fileA" exists under /ro, but /rw.
2304 +- user opened "/au/fileA".
2305 +- he or someone else inserts a branch (/new) between /rw and /ro.
2306 + /au = /rw + /new + /ro
2307 +- the new branch contains "fileA".
2308 +- user reads from the opened "fileA"
2309 +- which filedata should aufs return, from /ro or /new?
2311 +Some people says it has to be "from /ro" and it is a semantics of Unix.
2312 +The others say it should be "from /new" because the file is not removed
2313 +and it is equivalent to the case of someone else modifies the file.
2315 +Here again I don't have a best and final answer. I got an idea to
2316 +implement 'refrof' and 'norefrof' option. When 'refrof' (REFResh the
2317 +Opened File) is specified (by default), aufs returns the filedata from
2318 +/new. Otherwise from /ro.
2319 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2320 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2321 +++ linux/Documentation/filesystems/aufs/README 2015-06-22 08:27:37.867501461 +0200
2324 +Aufs3 -- advanced multi layered unification filesystem version 3.x
2330 +----------------------------------------
2331 +In the early days, aufs was entirely re-designed and re-implemented
2332 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2333 +improvements and implementations, it becomes totally different from
2334 +Unionfs while keeping the basic features.
2335 +Recently, Unionfs Version 2.x series begin taking some of the same
2336 +approaches to aufs1's.
2337 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2338 +University and his team.
2340 +Aufs3 supports linux-3.0 and later.
2341 +If you want older kernel version support, try aufs2-2.6.git or
2342 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2344 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2345 + According to Christoph Hellwig, linux rejects all union-type
2346 + filesystems but UnionMount.
2347 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2349 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2350 + UnionMount, and he pointed out an issue around a directory mutex
2351 + lock and aufs addressed it. But it is still unsure whether aufs will
2352 + be merged (or any other union solution).
2353 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2357 +----------------------------------------
2358 +- unite several directories into a single virtual filesystem. The member
2359 + directory is called as a branch.
2360 +- you can specify the permission flags to the branch, which are 'readonly',
2361 + 'readwrite' and 'whiteout-able.'
2362 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2363 + readonly branch are modifiable logically.
2364 +- dynamic branch manipulation, add, del.
2367 +Also there are many enhancements in aufs, such as:
2368 +- test only the highest one for the directory permission (dirperm1)
2369 +- copyup on open (coo=)
2370 +- 'move' policy for copy-up between two writable branches, after
2371 + checking free space.
2373 +- readdir(3) in userspace.
2374 +- keep inode number by external inode number table
2375 +- keep the timestamps of file/dir in internal copyup operation
2376 +- seekable directory, supporting NFS readdir.
2377 +- whiteout is hardlinked in order to reduce the consumption of inodes
2379 +- do not copyup, nor create a whiteout when it is unnecessary
2380 +- revert a single systemcall when an error occurs in aufs
2381 +- remount interface instead of ioctl
2382 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2383 +- loopback mounted filesystem as a branch
2384 +- kernel thread for removing the dir who has a plenty of whiteouts
2385 +- support copyup sparse file (a file which has a 'hole' in it)
2386 +- default permission flags for branches
2387 +- selectable permission flags for ro branch, whether whiteout can
2390 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2391 +- support multiple writable branches, some policies to select one
2392 + among multiple writable branches.
2393 +- a new semantics for link(2) and rename(2) to support multiple
2394 + writable branches.
2395 +- no glibc changes are required.
2396 +- pseudo hardlink (hardlink over branches)
2397 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2398 + including NFS or remote filesystem branch.
2399 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2402 +Currently these features are dropped temporary from aufs3.
2403 +See design/08plan.txt in detail.
2404 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2406 +- statistics of aufs thread (/sys/fs/aufs/stat)
2408 +Features or just an idea in the future (see also design/*.txt),
2409 +- reorder the branch index without del/re-add.
2410 +- permanent xino files for NFSD
2411 +- an option for refreshing the opened files after add/del branches
2412 +- light version, without branch manipulation. (unnecessary?)
2413 +- copyup in userspace
2414 +- inotify in userspace
2419 +----------------------------------------
2420 +There were three GIT trees for aufs3, aufs3-linux.git,
2421 +aufs3-standalone.git, and aufs-util.git. Note that there is no "3" in
2423 +While the aufs-util is always necessary, you need either of aufs3-linux
2424 +or aufs3-standalone.
2426 +The aufs3-linux tree includes the whole linux mainline GIT tree,
2427 +git://git.kernel.org/.../torvalds/linux.git.
2428 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2429 +build aufs3 as an external kernel module.
2430 +Several extra patches are not included in this tree. Only
2431 +aufs3-standalong tree contains them. They are describe in the later
2432 +section "Configuration and Compilation."
2434 +On the other hand, the aufs3-standalone tree has only aufs source files
2435 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2436 +But you need to apply all aufs patches manually.
2438 +You will find GIT branches whose name is in form of "aufs3.x" where "x"
2439 +represents the linux kernel version, "linux-3.x". For instance,
2440 +"aufs3.0" is for linux-3.0. For latest "linux-3.x-rcN", use
2441 +"aufs3.x-rcN" branch.
2444 +$ git clone --reference /your/linux/git/tree \
2445 + git://git.code.sf.net/p/aufs/aufs3-linux aufs3-linux.git
2446 +- if you don't have linux GIT tree, then remove "--reference ..."
2447 +$ cd aufs3-linux.git
2448 +$ git checkout origin/aufs3.0
2450 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2451 +leave the patch-work to GIT.
2452 +$ cd /your/linux/git/tree
2453 +$ git remote add aufs3 https://github.com/sfjro/aufs3-linux.git
2454 +- aufs3-linux.git tree also exists on github.
2456 +$ git checkout -b my3.14 v3.14
2457 +$ (add your change...)
2458 +$ git pull aufs3 aufs3.14
2459 +- now you have v3.14 + your_changes + aufs3.14 in you my3.14 branch.
2460 +- you may need to solve some conflicts between your_changes and
2461 + aufs3.14. in this case, git-rerere is recommended so that you can
2462 + solve the similar confilicts automatically when you upgrade to 3.15 or
2463 + later in the future.
2465 +o aufs3-standalone tree
2466 +$ git clone git://git.code.sf.net/p/aufs/aufs3-standalone \
2467 + aufs3-standalone.git
2468 +$ cd aufs3-standalone.git
2469 +$ git checkout origin/aufs3.0
2472 +$ git clone git://git.code.sf.net/p/aufs/aufs-util \
2475 +$ git checkout origin/aufs3.0
2477 +Note: The 3.x-rcN branch is to be used with `rc' kernel versions ONLY.
2478 +The minor version number, 'x' in '3.x', of aufs may not always
2479 +follow the minor version number of the kernel.
2480 +Because changes in the kernel that cause the use of a new
2481 +minor version number do not always require changes to aufs-util.
2483 +Since aufs-util has its own minor version number, you may not be
2484 +able to find a GIT branch in aufs-util for your kernel's
2485 +exact minor version number.
2486 +In this case, you should git-checkout the branch for the
2487 +nearest lower number.
2489 +For (an unreleased) example:
2490 +If you are using "linux-3.10" and the "aufs3.10" branch
2491 +does not exist in aufs-util repository, then "aufs3.9", "aufs3.8"
2492 +or something numerically smaller is the branch for your kernel.
2494 +Also you can view all branches by
2498 +3. Configuration and Compilation
2499 +----------------------------------------
2500 +Make sure you have git-checkout'ed the correct branch.
2502 +For aufs3-linux tree,
2503 +- enable CONFIG_AUFS_FS.
2504 +- set other aufs configurations if necessary.
2506 +For aufs3-standalone tree,
2507 +There are several ways to build.
2510 +- apply ./aufs3-kbuild.patch to your kernel source files.
2511 +- apply ./aufs3-base.patch too.
2512 +- apply ./aufs3-mmap.patch too.
2513 +- apply ./aufs3-standalone.patch too, if you have a plan to set
2514 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs3-standalone.patch.
2515 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2516 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2517 +- enable CONFIG_AUFS_FS, you can select either
2519 +- and build your kernel as usual.
2520 +- install the built kernel.
2521 + Note: Since linux-3.9, every filesystem module requires an alias
2522 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2523 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2524 +- install the header files too by "make headers_install" to the
2525 + directory where you specify. By default, it is $PWD/usr.
2526 + "make help" shows a brief note for headers_install.
2527 +- and reboot your system.
2530 +- module only (CONFIG_AUFS_FS=m).
2531 +- apply ./aufs3-base.patch to your kernel source files.
2532 +- apply ./aufs3-mmap.patch too.
2533 +- apply ./aufs3-standalone.patch too.
2534 +- build your kernel, don't forget "make headers_install", and reboot.
2535 +- edit ./config.mk and set other aufs configurations if necessary.
2536 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2537 + every aufs configurations.
2538 +- build the module by simple "make".
2539 + Note: Since linux-3.9, every filesystem module requires an alias
2540 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2541 + modules.aliases file.
2542 +- you can specify ${KDIR} make variable which points to your kernel
2544 +- install the files
2545 + + run "make install" to install the aufs module, or copy the built
2546 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2547 + + run "make install_headers" (instead of headers_install) to install
2548 + the modified aufs header file (you can specify DESTDIR which is
2549 + available in aufs standalone version's Makefile only), or copy
2550 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2551 + you like manually. By default, the target directory is $PWD/usr.
2552 +- no need to apply aufs3-kbuild.patch, nor copying source files to your
2553 + kernel source tree.
2555 +Note: The header file aufs_type.h is necessary to build aufs-util
2556 + as well as "make headers_install" in the kernel source tree.
2557 + headers_install is subject to be forgotten, but it is essentially
2558 + necessary, not only for building aufs-util.
2559 + You may not meet problems without headers_install in some older
2563 +- read README in aufs-util, build and install it
2564 +- note that your distribution may contain an obsoleted version of
2565 + aufs_type.h in /usr/include/linux or something. When you build aufs
2566 + utilities, make sure that your compiler refers the correct aufs header
2567 + file which is built by "make headers_install."
2568 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2569 + then run "make install_ulib" too. And refer to the aufs manual in
2572 +There several other patches in aufs3-standalone.git. They are all
2573 +optional. When you meet some problems, they will help you.
2574 +- aufs3-loopback.patch
2575 + Supports a nested loopback mount in a branch-fs. This patch is
2576 + unnecessary until aufs produces a message like "you may want to try
2577 + another patch for loopback file".
2579 + Modifies a system global kernel internal function get_next_ino() in
2580 + order to stop assigning 0 for an inode-number. Not directly related to
2581 + aufs, but recommended generally.
2583 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2584 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2585 + duplication of inode number, which is important for backup tools and
2586 + other utilities. When you find aufs XINO files for tmpfs branch
2587 + growing too much, try this patch.
2591 +----------------------------------------
2592 +At first, make sure aufs-util are installed, and please read the aufs
2593 +manual, aufs.5 in aufs-util.git tree.
2597 +$ mkdir /tmp/rw /tmp/aufs
2598 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2600 +Here is another example. The result is equivalent.
2601 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2603 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2604 +# mount -o remount,append:${HOME} /tmp/aufs
2606 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2607 +you modify a file under /tmp/aufs, the one on your home directory is
2608 +not affected, instead the same named file will be newly created under
2609 +/tmp/rw. And all of your modification to a file will be applied to
2610 +the one under /tmp/rw. This is called the file based Copy on Write
2612 +Aufs mount options are described in aufs.5.
2613 +If you run chroot or something and make your aufs as a root directory,
2614 +then you need to customize the shutdown script. See the aufs manual in
2617 +Additionally, there are some sample usages of aufs which are a
2618 +diskless system with network booting, and LiveCD over NFS.
2619 +See sample dir in CVS tree on SourceForge.
2623 +----------------------------------------
2624 +When you have any problems or strange behaviour in aufs, please let me
2626 +- /proc/mounts (instead of the output of mount(8))
2627 +- /sys/module/aufs/*
2628 +- /sys/fs/aufs/* (if you have them)
2629 +- /debug/aufs/* (if you have them)
2630 +- linux kernel version
2631 + if your kernel is not plain, for example modified by distributor,
2632 + the url where i can download its source is necessary too.
2633 +- aufs version which was printed at loading the module or booting the
2634 + system, instead of the date you downloaded.
2635 +- configuration (define/undefine CONFIG_AUFS_xxx)
2636 +- kernel configuration or /proc/config.gz (if you have it)
2637 +- behaviour which you think to be incorrect
2638 +- actual operation, reproducible one is better
2639 +- mailto: aufs-users at lists.sourceforge.net
2641 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2642 +and Feature Requests) on SourceForge. Please join and write to
2646 +6. Acknowledgements
2647 +----------------------------------------
2648 +Thanks to everyone who have tried and are using aufs, whoever
2649 +have reported a bug or any feedback.
2651 +Especially donators:
2652 +Tomas Matejicek(slax.org) made a donation (much more than once).
2653 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2654 + scripts) is making "doubling" donations.
2655 + Unfortunately I cannot list all of the donators, but I really
2657 + It ends Aug 2010, but the ordinary donation URL is still available.
2658 + <http://sourceforge.net/donate/index.php?group_id=167503>
2659 +Dai Itasaka made a donation (2007/8).
2660 +Chuck Smith made a donation (2008/4, 10 and 12).
2661 +Henk Schoneveld made a donation (2008/9).
2662 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2663 +Francois Dupoux made a donation (2008/11).
2664 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2665 + aufs2 GIT tree (2009/2).
2666 +William Grant made a donation (2009/3).
2667 +Patrick Lane made a donation (2009/4).
2668 +The Mail Archive (mail-archive.com) made donations (2009/5).
2669 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2670 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2671 +Pavel Pronskiy made a donation (2011/2).
2672 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2673 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2674 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2676 +Sam Liddicott made a donation (2011/9).
2677 +Era Scarecrow made a donation (2013/4).
2678 +Bor Ratajc made a donation (2013/4).
2679 +Alessandro Gorreta made a donation (2013/4).
2680 +POIRETTE Marc made a donation (2013/4).
2681 +Alessandro Gorreta made a donation (2013/4).
2682 +lauri kasvandik made a donation (2013/5).
2683 +"pemasu from Finland" made a donation (2013/7).
2684 +The Parted Magic Project made a donation (2013/9 and 11).
2685 +Pavel Barta made a donation (2013/10).
2686 +Nikolay Pertsev made a donation (2014/5).
2687 +James B made a donation (2014/7).
2688 +Stefano Di Biase made a donation (2014/8).
2689 +Daniel Epellei made a donation (2015/1).
2691 +Thank you very much.
2692 +Donations are always, including future donations, very important and
2693 +helpful for me to keep on developing aufs.
2697 +----------------------------------------
2698 +If you are an experienced user, no explanation is needed. Aufs is
2699 +just a linux filesystem.
2704 +# Local variables: ;
2707 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2708 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2709 +++ linux/fs/aufs/aufs.h 2015-06-22 08:27:37.874168290 +0200
2712 + * Copyright (C) 2005-2015 Junjiro R. Okajima
2714 + * This program, aufs is free software; you can redistribute it and/or modify
2715 + * it under the terms of the GNU General Public License as published by
2716 + * the Free Software Foundation; either version 2 of the License, or
2717 + * (at your option) any later version.
2719 + * This program is distributed in the hope that it will be useful,
2720 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2721 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2722 + * GNU General Public License for more details.
2724 + * You should have received a copy of the GNU General Public License
2725 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2729 + * all header files
2737 +#define AuStub(type, name, body, ...) \
2738 + static inline type name(__VA_ARGS__) { body; }
2740 +#define AuStubVoid(name, ...) \
2741 + AuStub(void, name, , __VA_ARGS__)
2742 +#define AuStubInt0(name, ...) \
2743 + AuStub(int, name, return 0, __VA_ARGS__)
2747 +#include "branch.h"
2750 +#include "dbgaufs.h"
2751 +#include "dentry.h"
2755 +#include "fstype.h"
2758 +#include "module.h"
2763 +#include "sysaufs.h"
2768 +#endif /* __KERNEL__ */
2769 +#endif /* __AUFS_H__ */
2770 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2771 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2772 +++ linux/fs/aufs/branch.c 2015-06-22 08:29:23.703424266 +0200
2775 + * Copyright (C) 2005-2015 Junjiro R. Okajima
2777 + * This program, aufs is free software; you can redistribute it and/or modify
2778 + * it under the terms of the GNU General Public License as published by
2779 + * the Free Software Foundation; either version 2 of the License, or
2780 + * (at your option) any later version.
2782 + * This program is distributed in the hope that it will be useful,
2783 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2784 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2785 + * GNU General Public License for more details.
2787 + * You should have received a copy of the GNU General Public License
2788 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2792 + * branch management
2795 +#include <linux/compat.h>
2796 +#include <linux/statfs.h>
2800 + * free a single branch
2802 +static void au_br_do_free(struct au_branch *br)
2805 + struct au_wbr *wbr;
2806 + struct au_dykey **key;
2808 + au_hnotify_fin_br(br);
2810 + if (br->br_xino.xi_file)
2811 + fput(br->br_xino.xi_file);
2812 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2814 + AuDebugOn(atomic_read(&br->br_count));
2818 + for (i = 0; i < AuBrWh_Last; i++)
2819 + dput(wbr->wbr_wh[i]);
2820 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2821 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2824 + if (br->br_fhsm) {
2825 + au_br_fhsm_fin(br->br_fhsm);
2826 + kfree(br->br_fhsm);
2829 + key = br->br_dykey;
2830 + for (i = 0; i < AuBrDynOp; i++, key++)
2836 + /* recursive lock, s_umount of branch's */
2838 + path_put(&br->br_path);
2845 + * frees all branches
2847 +void au_br_free(struct au_sbinfo *sbinfo)
2849 + aufs_bindex_t bmax;
2850 + struct au_branch **br;
2852 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2854 + bmax = sbinfo->si_bend + 1;
2855 + br = sbinfo->si_branch;
2857 + au_br_do_free(*br++);
2861 + * find the index of a branch which is specified by @br_id.
2863 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2865 + aufs_bindex_t bindex, bend;
2867 + bend = au_sbend(sb);
2868 + for (bindex = 0; bindex <= bend; bindex++)
2869 + if (au_sbr_id(sb, bindex) == br_id)
2874 +/* ---------------------------------------------------------------------- */
2880 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2881 + struct dentry *h_root)
2883 + if (unlikely(h_adding == h_root
2884 + || au_test_loopback_overlap(sb, h_adding)))
2886 + if (h_adding->d_sb != h_root->d_sb)
2888 + return au_test_subdir(h_adding, h_root)
2889 + || au_test_subdir(h_root, h_adding);
2893 + * returns a newly allocated branch. @new_nbranch is a number of branches
2894 + * after adding a branch.
2896 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2899 + struct au_branch *add_branch;
2900 + struct dentry *root;
2904 + root = sb->s_root;
2905 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2906 + if (unlikely(!add_branch))
2909 + err = au_hnotify_init_br(add_branch, perm);
2910 + if (unlikely(err))
2913 + add_branch->br_wbr = NULL;
2914 + if (au_br_writable(perm)) {
2915 + /* may be freed separately at changing the branch permission */
2916 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2918 + if (unlikely(!add_branch->br_wbr))
2922 + add_branch->br_fhsm = NULL;
2923 + if (au_br_fhsm(perm)) {
2924 + err = au_fhsm_br_alloc(add_branch);
2925 + if (unlikely(err))
2929 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2931 + err = au_di_realloc(au_di(root), new_nbranch);
2933 + err = au_ii_realloc(au_ii(root->d_inode), new_nbranch);
2935 + return add_branch; /* success */
2938 + kfree(add_branch->br_wbr);
2940 + au_hnotify_fin_br(add_branch);
2942 + kfree(add_branch);
2944 + return ERR_PTR(err);
2948 + * test if the branch permission is legal or not.
2950 +static int test_br(struct inode *inode, int brperm, char *path)
2954 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2959 + pr_err("write permission for readonly mount or inode, %s\n", path);
2967 + * 0: success, the caller will add it
2968 + * plus: success, it is already unified, the caller should ignore it
2971 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2974 + aufs_bindex_t bend, bindex;
2975 + struct dentry *root;
2976 + struct inode *inode, *h_inode;
2978 + root = sb->s_root;
2979 + bend = au_sbend(sb);
2980 + if (unlikely(bend >= 0
2981 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2985 + pr_err("%s duplicated\n", add->pathname);
2990 + err = -ENOSPC; /* -E2BIG; */
2991 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2992 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2993 + pr_err("number of branches exceeded %s\n", add->pathname);
2998 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2999 + pr_err("bad index %d\n", add->bindex);
3003 + inode = add->path.dentry->d_inode;
3005 + if (unlikely(!inode->i_nlink)) {
3006 + pr_err("no existence %s\n", add->pathname);
3011 + if (unlikely(inode->i_sb == sb)) {
3012 + pr_err("%s must be outside\n", add->pathname);
3016 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3017 + pr_err("unsupported filesystem, %s (%s)\n",
3018 + add->pathname, au_sbtype(inode->i_sb));
3022 + if (unlikely(inode->i_sb->s_stack_depth)) {
3023 + pr_err("already stacked, %s (%s)\n",
3024 + add->pathname, au_sbtype(inode->i_sb));
3028 + err = test_br(add->path.dentry->d_inode, add->perm, add->pathname);
3029 + if (unlikely(err))
3033 + return 0; /* success */
3036 + for (bindex = 0; bindex <= bend; bindex++)
3037 + if (unlikely(test_overlap(sb, add->path.dentry,
3038 + au_h_dptr(root, bindex)))) {
3039 + pr_err("%s is overlapped\n", add->pathname);
3044 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3045 + h_inode = au_h_dptr(root, 0)->d_inode;
3046 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3047 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3048 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3049 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3051 + i_uid_read(inode), i_gid_read(inode),
3052 + (inode->i_mode & S_IALLUGO),
3053 + i_uid_read(h_inode), i_gid_read(h_inode),
3054 + (h_inode->i_mode & S_IALLUGO));
3062 + * initialize or clean the whiteouts for an adding branch
3064 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3067 + int err, old_perm;
3068 + aufs_bindex_t bindex;
3069 + struct mutex *h_mtx;
3070 + struct au_wbr *wbr;
3071 + struct au_hinode *hdir;
3073 + err = vfsub_mnt_want_write(au_br_mnt(br));
3074 + if (unlikely(err))
3078 + old_perm = br->br_perm;
3079 + br->br_perm = new_perm;
3082 + bindex = au_br_index(sb, br->br_id);
3083 + if (0 <= bindex) {
3084 + hdir = au_hi(sb->s_root->d_inode, bindex);
3085 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
3087 + h_mtx = &au_br_dentry(br)->d_inode->i_mutex;
3088 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
3091 + err = au_wh_init(br, sb);
3093 + wbr_wh_write_lock(wbr);
3094 + err = au_wh_init(br, sb);
3095 + wbr_wh_write_unlock(wbr);
3098 + au_hn_imtx_unlock(hdir);
3100 + mutex_unlock(h_mtx);
3101 + vfsub_mnt_drop_write(au_br_mnt(br));
3102 + br->br_perm = old_perm;
3104 + if (!err && wbr && !au_br_writable(new_perm)) {
3106 + br->br_wbr = NULL;
3113 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3117 + struct kstatfs kst;
3118 + struct au_wbr *wbr;
3121 + au_rw_init(&wbr->wbr_wh_rwsem);
3122 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
3123 + atomic_set(&wbr->wbr_wh_running, 0);
3124 + wbr->wbr_bytes = 0;
3127 + * a limit for rmdir/rename a dir
3128 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3130 + err = vfs_statfs(&br->br_path, &kst);
3131 + if (unlikely(err))
3134 + if (kst.f_namelen >= NAME_MAX)
3135 + err = au_br_init_wh(sb, br, perm);
3137 + pr_err("%pd(%s), unsupported namelen %ld\n",
3139 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3145 +/* initialize a new branch */
3146 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3147 + struct au_opt_add *add)
3152 + memset(&br->br_xino, 0, sizeof(br->br_xino));
3153 + mutex_init(&br->br_xino.xi_nondir_mtx);
3154 + br->br_perm = add->perm;
3155 + br->br_path = add->path; /* set first, path_get() later */
3156 + spin_lock_init(&br->br_dykey_lock);
3157 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
3158 + atomic_set(&br->br_count, 0);
3159 + atomic_set(&br->br_xino_running, 0);
3160 + br->br_id = au_new_br_id(sb);
3161 + AuDebugOn(br->br_id < 0);
3163 + if (au_br_writable(add->perm)) {
3164 + err = au_wbr_init(br, sb, add->perm);
3165 + if (unlikely(err))
3169 + if (au_opt_test(au_mntflags(sb), XINO)) {
3170 + err = au_xino_br(sb, br, add->path.dentry->d_inode->i_ino,
3171 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3172 + if (unlikely(err)) {
3173 + AuDebugOn(br->br_xino.xi_file);
3178 + sysaufs_br_init(br);
3179 + path_get(&br->br_path);
3180 + goto out; /* success */
3183 + memset(&br->br_path, 0, sizeof(br->br_path));
3188 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3189 + struct au_branch *br, aufs_bindex_t bend,
3190 + aufs_bindex_t amount)
3192 + struct au_branch **brp;
3194 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3196 + brp = sbinfo->si_branch + bindex;
3197 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3199 + sbinfo->si_bend++;
3200 + if (unlikely(bend < 0))
3201 + sbinfo->si_bend = 0;
3204 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3205 + aufs_bindex_t bend, aufs_bindex_t amount)
3207 + struct au_hdentry *hdp;
3209 + AuRwMustWriteLock(&dinfo->di_rwsem);
3211 + hdp = dinfo->di_hdentry + bindex;
3212 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3213 + au_h_dentry_init(hdp);
3215 + if (unlikely(bend < 0))
3216 + dinfo->di_bstart = 0;
3219 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3220 + aufs_bindex_t bend, aufs_bindex_t amount)
3222 + struct au_hinode *hip;
3224 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3226 + hip = iinfo->ii_hinode + bindex;
3227 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3228 + hip->hi_inode = NULL;
3231 + if (unlikely(bend < 0))
3232 + iinfo->ii_bstart = 0;
3235 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3236 + aufs_bindex_t bindex)
3238 + struct dentry *root, *h_dentry;
3239 + struct inode *root_inode;
3240 + aufs_bindex_t bend, amount;
3242 + root = sb->s_root;
3243 + root_inode = root->d_inode;
3244 + bend = au_sbend(sb);
3245 + amount = bend + 1 - bindex;
3246 + h_dentry = au_br_dentry(br);
3247 + au_sbilist_lock();
3248 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
3249 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
3250 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
3251 + au_set_h_dptr(root, bindex, dget(h_dentry));
3252 + au_set_h_iptr(root_inode, bindex, au_igrab(h_dentry->d_inode),
3254 + au_sbilist_unlock();
3257 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3260 + aufs_bindex_t bend, add_bindex;
3261 + struct dentry *root, *h_dentry;
3262 + struct inode *root_inode;
3263 + struct au_branch *add_branch;
3265 + root = sb->s_root;
3266 + root_inode = root->d_inode;
3267 + IMustLock(root_inode);
3268 + err = test_add(sb, add, remount);
3269 + if (unlikely(err < 0))
3273 + goto out; /* success */
3276 + bend = au_sbend(sb);
3277 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
3278 + err = PTR_ERR(add_branch);
3279 + if (IS_ERR(add_branch))
3282 + err = au_br_init(add_branch, sb, add);
3283 + if (unlikely(err)) {
3284 + au_br_do_free(add_branch);
3288 + add_bindex = add->bindex;
3290 + au_br_do_add(sb, add_branch, add_bindex);
3292 + sysaufs_brs_del(sb, add_bindex);
3293 + au_br_do_add(sb, add_branch, add_bindex);
3294 + sysaufs_brs_add(sb, add_bindex);
3297 + h_dentry = add->path.dentry;
3298 + if (!add_bindex) {
3299 + au_cpup_attr_all(root_inode, /*force*/1);
3300 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3302 + au_add_nlink(root_inode, h_dentry->d_inode);
3305 + * this test/set prevents aufs from handling unnecesary notify events
3306 + * of xino files, in case of re-adding a writable branch which was
3307 + * once detached from aufs.
3309 + if (au_xino_brid(sb) < 0
3310 + && au_br_writable(add_branch->br_perm)
3311 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3312 + && add_branch->br_xino.xi_file
3313 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3314 + au_xino_brid_set(sb, add_branch->br_id);
3320 +/* ---------------------------------------------------------------------- */
3322 +static unsigned long long au_farray_cb(void *a,
3323 + unsigned long long max __maybe_unused,
3326 + unsigned long long n;
3327 + struct file **p, *f;
3328 + struct au_sphlhead *files;
3329 + struct au_finfo *finfo;
3330 + struct super_block *sb = arg;
3334 + files = &au_sbi(sb)->si_files;
3335 + spin_lock(&files->spin);
3336 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3337 + f = finfo->fi_file;
3339 + && !special_file(file_inode(f)->i_mode)) {
3343 + AuDebugOn(n > max);
3346 + spin_unlock(&files->spin);
3351 +static struct file **au_farray_alloc(struct super_block *sb,
3352 + unsigned long long *max)
3354 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3355 + return au_array_alloc(max, au_farray_cb, sb);
3358 +static void au_farray_free(struct file **a, unsigned long long max)
3360 + unsigned long long ull;
3362 + for (ull = 0; ull < max; ull++)
3368 +/* ---------------------------------------------------------------------- */
3374 +/* to show the line number, do not make it inlined function */
3375 +#define AuVerbose(do_info, fmt, ...) do { \
3377 + pr_info(fmt, ##__VA_ARGS__); \
3380 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
3381 + aufs_bindex_t bend)
3383 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
3386 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
3387 + aufs_bindex_t bend)
3389 + return au_test_ibusy(dentry->d_inode, bstart, bend);
3393 + * test if the branch is deletable or not.
3395 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3396 + unsigned int sigen, const unsigned int verbose)
3398 + int err, i, j, ndentry;
3399 + aufs_bindex_t bstart, bend;
3400 + struct au_dcsub_pages dpages;
3401 + struct au_dpage *dpage;
3404 + err = au_dpages_init(&dpages, GFP_NOFS);
3405 + if (unlikely(err))
3407 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3408 + if (unlikely(err))
3411 + for (i = 0; !err && i < dpages.ndpage; i++) {
3412 + dpage = dpages.dpages + i;
3413 + ndentry = dpage->ndentry;
3414 + for (j = 0; !err && j < ndentry; j++) {
3415 + d = dpage->dentries[j];
3416 + AuDebugOn(au_dcount(d) <= 0);
3417 + if (!au_digen_test(d, sigen)) {
3418 + di_read_lock_child(d, AuLock_IR);
3419 + if (unlikely(au_dbrange_test(d))) {
3420 + di_read_unlock(d, AuLock_IR);
3424 + di_write_lock_child(d);
3425 + if (unlikely(au_dbrange_test(d))) {
3426 + di_write_unlock(d);
3429 + err = au_reval_dpath(d, sigen);
3431 + di_downgrade_lock(d, AuLock_IR);
3433 + di_write_unlock(d);
3438 + /* AuDbgDentry(d); */
3439 + bstart = au_dbstart(d);
3440 + bend = au_dbend(d);
3441 + if (bstart <= bindex
3443 + && au_h_dptr(d, bindex)
3444 + && au_test_dbusy(d, bstart, bend)) {
3446 + AuVerbose(verbose, "busy %pd\n", d);
3449 + di_read_unlock(d, AuLock_IR);
3454 + au_dpages_free(&dpages);
3459 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3460 + unsigned int sigen, const unsigned int verbose)
3463 + unsigned long long max, ull;
3464 + struct inode *i, **array;
3465 + aufs_bindex_t bstart, bend;
3467 + array = au_iarray_alloc(sb, &max);
3468 + err = PTR_ERR(array);
3469 + if (IS_ERR(array))
3473 + AuDbg("b%d\n", bindex);
3474 + for (ull = 0; !err && ull < max; ull++) {
3478 + if (i->i_ino == AUFS_ROOT_INO)
3481 + /* AuDbgInode(i); */
3482 + if (au_iigen(i, NULL) == sigen)
3483 + ii_read_lock_child(i);
3485 + ii_write_lock_child(i);
3486 + err = au_refresh_hinode_self(i);
3489 + ii_downgrade_lock(i);
3491 + ii_write_unlock(i);
3496 + bstart = au_ibstart(i);
3497 + bend = au_ibend(i);
3498 + if (bstart <= bindex
3500 + && au_h_iptr(i, bindex)
3501 + && au_test_ibusy(i, bstart, bend)) {
3503 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3506 + ii_read_unlock(i);
3508 + au_iarray_free(array, max);
3514 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3515 + const unsigned int verbose)
3518 + unsigned int sigen;
3520 + sigen = au_sigen(root->d_sb);
3521 + DiMustNoWaiters(root);
3522 + IiMustNoWaiters(root->d_inode);
3523 + di_write_unlock(root);
3524 + err = test_dentry_busy(root, bindex, sigen, verbose);
3526 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3527 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3532 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3533 + struct file **to_free, int *idx)
3536 + unsigned char matched, root;
3537 + aufs_bindex_t bindex, bend;
3538 + struct au_fidir *fidir;
3539 + struct au_hfile *hfile;
3542 + root = IS_ROOT(file->f_path.dentry);
3545 + to_free[*idx] = file;
3551 + fidir = au_fi(file)->fi_hdir;
3552 + AuDebugOn(!fidir);
3553 + bend = au_fbend_dir(file);
3554 + for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
3555 + hfile = fidir->fd_hfile + bindex;
3556 + if (!hfile->hf_file)
3559 + if (hfile->hf_br->br_id == br_id) {
3571 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3572 + struct file **to_free, int opened)
3575 + unsigned long long ull, max;
3576 + aufs_bindex_t bstart;
3577 + struct file *file, **array;
3578 + struct dentry *root;
3579 + struct au_hfile *hfile;
3581 + array = au_farray_alloc(sb, &max);
3582 + err = PTR_ERR(array);
3583 + if (IS_ERR(array))
3588 + root = sb->s_root;
3589 + di_write_unlock(root);
3590 + for (ull = 0; ull < max; ull++) {
3591 + file = array[ull];
3592 + if (unlikely(!file))
3595 + /* AuDbg("%pD\n", file); */
3596 + fi_read_lock(file);
3597 + bstart = au_fbstart(file);
3598 + if (!d_is_dir(file->f_path.dentry)) {
3599 + hfile = &au_fi(file)->fi_htop;
3600 + if (hfile->hf_br->br_id == br_id)
3603 + err = test_dir_busy(file, br_id, to_free, &idx);
3604 + fi_read_unlock(file);
3605 + if (unlikely(err))
3608 + di_write_lock_child(root);
3609 + au_farray_free(array, max);
3610 + AuDebugOn(idx > opened);
3616 +static void br_del_file(struct file **to_free, unsigned long long opened,
3617 + aufs_bindex_t br_id)
3619 + unsigned long long ull;
3620 + aufs_bindex_t bindex, bstart, bend, bfound;
3621 + struct file *file;
3622 + struct au_fidir *fidir;
3623 + struct au_hfile *hfile;
3625 + for (ull = 0; ull < opened; ull++) {
3626 + file = to_free[ull];
3627 + if (unlikely(!file))
3630 + /* AuDbg("%pD\n", file); */
3631 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3633 + fidir = au_fi(file)->fi_hdir;
3634 + AuDebugOn(!fidir);
3635 + fi_write_lock(file);
3636 + bstart = au_fbstart(file);
3637 + bend = au_fbend_dir(file);
3638 + for (bindex = bstart; bindex <= bend; bindex++) {
3639 + hfile = fidir->fd_hfile + bindex;
3640 + if (!hfile->hf_file)
3643 + if (hfile->hf_br->br_id == br_id) {
3648 + AuDebugOn(bfound < 0);
3649 + au_set_h_fptr(file, bfound, NULL);
3650 + if (bfound == bstart) {
3651 + for (bstart++; bstart <= bend; bstart++)
3652 + if (au_hf_dir(file, bstart)) {
3653 + au_set_fbstart(file, bstart);
3657 + fi_write_unlock(file);
3661 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3662 + const aufs_bindex_t bindex,
3663 + const aufs_bindex_t bend)
3665 + struct au_branch **brp, **p;
3667 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3669 + brp = sbinfo->si_branch + bindex;
3670 + if (bindex < bend)
3671 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3672 + sbinfo->si_branch[0 + bend] = NULL;
3673 + sbinfo->si_bend--;
3675 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3677 + sbinfo->si_branch = p;
3678 + /* harmless error */
3681 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3682 + const aufs_bindex_t bend)
3684 + struct au_hdentry *hdp, *p;
3686 + AuRwMustWriteLock(&dinfo->di_rwsem);
3688 + hdp = dinfo->di_hdentry;
3689 + if (bindex < bend)
3690 + memmove(hdp + bindex, hdp + bindex + 1,
3691 + sizeof(*hdp) * (bend - bindex));
3692 + hdp[0 + bend].hd_dentry = NULL;
3695 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3697 + dinfo->di_hdentry = p;
3698 + /* harmless error */
3701 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3702 + const aufs_bindex_t bend)
3704 + struct au_hinode *hip, *p;
3706 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3708 + hip = iinfo->ii_hinode + bindex;
3709 + if (bindex < bend)
3710 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3711 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3712 + au_hn_init(iinfo->ii_hinode + bend);
3715 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3717 + iinfo->ii_hinode = p;
3718 + /* harmless error */
3721 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3722 + struct au_branch *br)
3724 + aufs_bindex_t bend;
3725 + struct au_sbinfo *sbinfo;
3726 + struct dentry *root, *h_root;
3727 + struct inode *inode, *h_inode;
3728 + struct au_hinode *hinode;
3730 + SiMustWriteLock(sb);
3732 + root = sb->s_root;
3733 + inode = root->d_inode;
3734 + sbinfo = au_sbi(sb);
3735 + bend = sbinfo->si_bend;
3737 + h_root = au_h_dptr(root, bindex);
3738 + hinode = au_hi(inode, bindex);
3739 + h_inode = au_igrab(hinode->hi_inode);
3742 + au_sbilist_lock();
3743 + au_br_do_del_brp(sbinfo, bindex, bend);
3744 + au_br_do_del_hdp(au_di(root), bindex, bend);
3745 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3746 + au_sbilist_unlock();
3750 + au_br_do_free(br);
3753 +static unsigned long long empty_cb(void *array, unsigned long long max,
3759 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3762 + unsigned long long opened;
3763 + unsigned int mnt_flags;
3764 + aufs_bindex_t bindex, bend, br_id;
3765 + unsigned char do_wh, verbose;
3766 + struct au_branch *br;
3767 + struct au_wbr *wbr;
3768 + struct dentry *root;
3769 + struct file **to_free;
3774 + root = sb->s_root;
3775 + bindex = au_find_dbindex(root, del->h_path.dentry);
3778 + goto out; /* success */
3780 + pr_err("%s no such branch\n", del->pathname);
3783 + AuDbg("bindex b%d\n", bindex);
3786 + mnt_flags = au_mntflags(sb);
3787 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3788 + bend = au_sbend(sb);
3789 + if (unlikely(!bend)) {
3790 + AuVerbose(verbose, "no more branches left\n");
3793 + br = au_sbr(sb, bindex);
3794 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3796 + br_id = br->br_id;
3797 + opened = atomic_read(&br->br_count);
3798 + if (unlikely(opened)) {
3799 + to_free = au_array_alloc(&opened, empty_cb, NULL);
3800 + err = PTR_ERR(to_free);
3801 + if (IS_ERR(to_free))
3804 + err = test_file_busy(sb, br_id, to_free, opened);
3805 + if (unlikely(err)) {
3806 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3812 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3814 + /* instead of WbrWhMustWriteLock(wbr) */
3815 + SiMustWriteLock(sb);
3816 + for (i = 0; i < AuBrWh_Last; i++) {
3817 + dput(wbr->wbr_wh[i]);
3818 + wbr->wbr_wh[i] = NULL;
3822 + err = test_children_busy(root, bindex, verbose);
3823 + if (unlikely(err)) {
3832 + * now we confirmed the branch is deletable.
3833 + * let's free the remaining opened dirs on the branch.
3835 + di_write_unlock(root);
3836 + br_del_file(to_free, opened, br_id);
3837 + di_write_lock_child(root);
3841 + au_br_do_del(sb, bindex, br);
3843 + sysaufs_brs_del(sb, bindex);
3844 + au_br_do_del(sb, bindex, br);
3845 + sysaufs_brs_add(sb, bindex);
3849 + au_cpup_attr_all(root->d_inode, /*force*/1);
3850 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3852 + au_sub_nlink(root->d_inode, del->h_path.dentry->d_inode);
3853 + if (au_opt_test(mnt_flags, PLINK))
3854 + au_plink_half_refresh(sb, br_id);
3856 + if (au_xino_brid(sb) == br_id)
3857 + au_xino_brid_set(sb, -1);
3858 + goto out; /* success */
3862 + rerr = au_br_init_wh(sb, br, br->br_perm);
3864 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3865 + del->pathname, rerr);
3868 + au_farray_free(to_free, opened);
3872 +/* ---------------------------------------------------------------------- */
3874 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3877 + aufs_bindex_t bstart, bend;
3878 + struct aufs_ibusy ibusy;
3879 + struct inode *inode, *h_inode;
3882 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3885 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3887 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3888 + if (unlikely(err)) {
3895 + si_read_lock(sb, AuLock_FLUSH);
3896 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3900 + ibusy.h_ino = 0; /* invalid */
3901 + inode = ilookup(sb, ibusy.ino);
3903 + || inode->i_ino == AUFS_ROOT_INO
3904 + || is_bad_inode(inode))
3907 + ii_read_lock_child(inode);
3908 + bstart = au_ibstart(inode);
3909 + bend = au_ibend(inode);
3910 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3911 + h_inode = au_h_iptr(inode, ibusy.bindex);
3912 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3913 + ibusy.h_ino = h_inode->i_ino;
3915 + ii_read_unlock(inode);
3919 + si_read_unlock(sb);
3921 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3922 + if (unlikely(err)) {
3931 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3933 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
3936 +#ifdef CONFIG_COMPAT
3937 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3939 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
3943 +/* ---------------------------------------------------------------------- */
3946 + * change a branch permission
3949 +static void au_warn_ima(void)
3952 + /* since it doesn't support mark_files_ro() */
3953 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3957 +static int do_need_sigen_inc(int a, int b)
3959 + return au_br_whable(a) && !au_br_whable(b);
3962 +static int need_sigen_inc(int old, int new)
3964 + return do_need_sigen_inc(old, new)
3965 + || do_need_sigen_inc(new, old);
3968 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3971 + unsigned int mnt_flags;
3972 + unsigned long long ull, max;
3973 + aufs_bindex_t br_id;
3974 + unsigned char verbose, writer;
3975 + struct file *file, *hf, **array;
3976 + struct au_hfile *hfile;
3978 + mnt_flags = au_mntflags(sb);
3979 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3981 + array = au_farray_alloc(sb, &max);
3982 + err = PTR_ERR(array);
3983 + if (IS_ERR(array))
3987 + br_id = au_sbr_id(sb, bindex);
3988 + for (ull = 0; ull < max; ull++) {
3989 + file = array[ull];
3990 + if (unlikely(!file))
3993 + /* AuDbg("%pD\n", file); */
3994 + fi_read_lock(file);
3995 + if (unlikely(au_test_mmapped(file))) {
3997 + AuVerbose(verbose, "mmapped %pD\n", file);
3999 + FiMustNoWaiters(file);
4000 + fi_read_unlock(file);
4004 + hfile = &au_fi(file)->fi_htop;
4005 + hf = hfile->hf_file;
4006 + if (!d_is_reg(file->f_path.dentry)
4007 + || !(file->f_mode & FMODE_WRITE)
4008 + || hfile->hf_br->br_id != br_id
4009 + || !(hf->f_mode & FMODE_WRITE))
4010 + array[ull] = NULL;
4016 + FiMustNoWaiters(file);
4017 + fi_read_unlock(file);
4025 + for (ull = 0; ull < max; ull++) {
4026 + file = array[ull];
4030 + /* todo: already flushed? */
4032 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4033 + * approach which resets f_mode and calls mnt_drop_write() and
4034 + * file_release_write() for each file, because the branch
4035 + * attribute in aufs world is totally different from the native
4038 + /* fi_read_lock(file); */
4039 + hfile = &au_fi(file)->fi_htop;
4040 + hf = hfile->hf_file;
4041 + /* fi_read_unlock(file); */
4042 + spin_lock(&hf->f_lock);
4043 + writer = !!(hf->f_mode & FMODE_WRITER);
4044 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4045 + spin_unlock(&hf->f_lock);
4047 + put_write_access(file_inode(hf));
4048 + __mnt_drop_write(hf->f_path.mnt);
4053 + au_farray_free(array, max);
4059 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4063 + aufs_bindex_t bindex;
4064 + struct dentry *root;
4065 + struct au_branch *br;
4066 + struct au_br_fhsm *bf;
4068 + root = sb->s_root;
4069 + bindex = au_find_dbindex(root, mod->h_root);
4072 + return 0; /* success */
4074 + pr_err("%s no such branch\n", mod->path);
4077 + AuDbg("bindex b%d\n", bindex);
4079 + err = test_br(mod->h_root->d_inode, mod->perm, mod->path);
4080 + if (unlikely(err))
4083 + br = au_sbr(sb, bindex);
4084 + AuDebugOn(mod->h_root != au_br_dentry(br));
4085 + if (br->br_perm == mod->perm)
4086 + return 0; /* success */
4088 + /* pre-allocate for non-fhsm --> fhsm */
4090 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4091 + err = au_fhsm_br_alloc(br);
4092 + if (unlikely(err))
4095 + br->br_fhsm = NULL;
4098 + if (au_br_writable(br->br_perm)) {
4099 + /* remove whiteout base */
4100 + err = au_br_init_wh(sb, br, mod->perm);
4101 + if (unlikely(err))
4104 + if (!au_br_writable(mod->perm)) {
4105 + /* rw --> ro, file might be mmapped */
4106 + DiMustNoWaiters(root);
4107 + IiMustNoWaiters(root->d_inode);
4108 + di_write_unlock(root);
4109 + err = au_br_mod_files_ro(sb, bindex);
4110 + /* aufs_write_lock() calls ..._child() */
4111 + di_write_lock_child(root);
4113 + if (unlikely(err)) {
4115 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
4118 + rerr = au_wbr_init(br, sb, br->br_perm);
4119 + if (unlikely(rerr)) {
4120 + AuIOErr("nested error %d (%d)\n",
4122 + br->br_perm = mod->perm;
4126 + } else if (au_br_writable(mod->perm)) {
4129 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
4131 + err = au_wbr_init(br, sb, mod->perm);
4132 + if (unlikely(err)) {
4133 + kfree(br->br_wbr);
4134 + br->br_wbr = NULL;
4138 + if (unlikely(err))
4141 + if (au_br_fhsm(br->br_perm)) {
4142 + if (!au_br_fhsm(mod->perm)) {
4143 + /* fhsm --> non-fhsm */
4144 + au_br_fhsm_fin(br->br_fhsm);
4145 + kfree(br->br_fhsm);
4146 + br->br_fhsm = NULL;
4148 + } else if (au_br_fhsm(mod->perm))
4149 + /* non-fhsm --> fhsm */
4152 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4153 + br->br_perm = mod->perm;
4154 + goto out; /* success */
4163 +/* ---------------------------------------------------------------------- */
4165 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4168 + struct kstatfs kstfs;
4170 + err = vfs_statfs(&br->br_path, &kstfs);
4172 + stfs->f_blocks = kstfs.f_blocks;
4173 + stfs->f_bavail = kstfs.f_bavail;
4174 + stfs->f_files = kstfs.f_files;
4175 + stfs->f_ffree = kstfs.f_ffree;
4180 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4181 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4182 +++ linux/fs/aufs/branch.h 2015-06-22 08:29:23.703424266 +0200
4185 + * Copyright (C) 2005-2015 Junjiro R. Okajima
4187 + * This program, aufs is free software; you can redistribute it and/or modify
4188 + * it under the terms of the GNU General Public License as published by
4189 + * the Free Software Foundation; either version 2 of the License, or
4190 + * (at your option) any later version.
4192 + * This program is distributed in the hope that it will be useful,
4193 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4194 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4195 + * GNU General Public License for more details.
4197 + * You should have received a copy of the GNU General Public License
4198 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4202 + * branch filesystems and xino for them
4205 +#ifndef __AUFS_BRANCH_H__
4206 +#define __AUFS_BRANCH_H__
4210 +#include <linux/mount.h>
4215 +/* ---------------------------------------------------------------------- */
4218 +struct au_xino_file {
4219 + struct file *xi_file;
4220 + struct mutex xi_nondir_mtx;
4222 + /* todo: make xino files an array to support huge inode number */
4224 +#ifdef CONFIG_DEBUG_FS
4225 + struct dentry *xi_dbgaufs;
4229 +/* File-based Hierarchical Storage Management */
4230 +struct au_br_fhsm {
4231 +#ifdef CONFIG_AUFS_FHSM
4232 + struct mutex bf_lock;
4233 + unsigned long bf_jiffy;
4234 + struct aufs_stfs bf_stfs;
4239 +/* members for writable branch only */
4240 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4242 + struct au_rwsem wbr_wh_rwsem;
4243 + struct dentry *wbr_wh[AuBrWh_Last];
4244 + atomic_t wbr_wh_running;
4245 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4246 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4247 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4250 + unsigned long long wbr_bytes;
4253 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4254 +#define AuBrDynOp (AuDyLast * 4)
4256 +#ifdef CONFIG_AUFS_HFSNOTIFY
4257 +/* support for asynchronous destruction */
4258 +struct au_br_hfsnotify {
4259 + struct fsnotify_group *hfsn_group;
4263 +/* sysfs entries */
4264 +struct au_brsysfs {
4266 + struct attribute attr;
4275 +/* protected by superblock rwsem */
4277 + struct au_xino_file br_xino;
4279 + aufs_bindex_t br_id;
4282 + struct path br_path;
4283 + spinlock_t br_dykey_lock;
4284 + struct au_dykey *br_dykey[AuBrDynOp];
4285 + atomic_t br_count;
4287 + struct au_wbr *br_wbr;
4288 + struct au_br_fhsm *br_fhsm;
4290 + /* xino truncation */
4291 + atomic_t br_xino_running;
4293 +#ifdef CONFIG_AUFS_HFSNOTIFY
4294 + struct au_br_hfsnotify *br_hfsn;
4297 +#ifdef CONFIG_SYSFS
4298 + /* entries under sysfs per mount-point */
4299 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4303 +/* ---------------------------------------------------------------------- */
4305 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4307 + return br->br_path.mnt;
4310 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4312 + return br->br_path.dentry;
4315 +static inline struct super_block *au_br_sb(struct au_branch *br)
4317 + return au_br_mnt(br)->mnt_sb;
4320 +static inline int au_br_rdonly(struct au_branch *br)
4322 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4323 + || !au_br_writable(br->br_perm))
4327 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4329 +#ifdef CONFIG_AUFS_HNOTIFY
4330 + return !(brperm & AuBrPerm_RR);
4336 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4338 + int err, exec_flag;
4341 + exec_flag = oflag & __FMODE_EXEC;
4342 + if (unlikely(exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC)))
4348 +/* ---------------------------------------------------------------------- */
4352 +void au_br_free(struct au_sbinfo *sinfo);
4353 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4355 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4357 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4358 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4359 +#ifdef CONFIG_COMPAT
4360 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4363 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4366 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4369 +static const loff_t au_loff_max = LLONG_MAX;
4371 +int au_xib_trunc(struct super_block *sb);
4372 +ssize_t xino_fread(au_readf_t func, struct file *file, void *buf, size_t size,
4374 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
4376 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4377 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4378 +ino_t au_xino_new_ino(struct super_block *sb);
4379 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4380 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4382 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4384 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4385 + struct file *base_file, int do_test);
4386 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4388 +struct au_opt_xino;
4389 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4390 +void au_xino_clr(struct super_block *sb);
4391 +struct file *au_xino_def(struct super_block *sb);
4392 +int au_xino_path(struct seq_file *seq, struct file *file);
4394 +/* ---------------------------------------------------------------------- */
4396 +/* Superblock to branch */
4398 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4400 + return au_sbr(sb, bindex)->br_id;
4404 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4406 + return au_br_mnt(au_sbr(sb, bindex));
4410 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4412 + return au_br_sb(au_sbr(sb, bindex));
4415 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4417 + atomic_dec(&au_sbr(sb, bindex)->br_count);
4420 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4422 + return au_sbr(sb, bindex)->br_perm;
4425 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4427 + return au_br_whable(au_sbr_perm(sb, bindex));
4430 +/* ---------------------------------------------------------------------- */
4433 + * wbr_wh_read_lock, wbr_wh_write_lock
4434 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4436 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4438 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4439 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4440 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4442 +/* ---------------------------------------------------------------------- */
4444 +#ifdef CONFIG_AUFS_FHSM
4445 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4447 + mutex_init(&brfhsm->bf_lock);
4448 + brfhsm->bf_jiffy = 0;
4449 + brfhsm->bf_readable = 0;
4452 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4454 + mutex_destroy(&brfhsm->bf_lock);
4457 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4458 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4461 +#endif /* __KERNEL__ */
4462 +#endif /* __AUFS_BRANCH_H__ */
4463 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4464 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4465 +++ linux/fs/aufs/conf.mk 2015-06-22 08:27:37.874168290 +0200
4468 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4472 +AuConfStr += ${1}=${${1}}
4476 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4478 + HNOTIFY HFSNOTIFY \
4489 +$(foreach i, ${AuConfAll}, \
4490 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4492 +AuConfName = ${obj}/conf.str
4493 +${AuConfName}.tmp: FORCE
4494 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4495 +${AuConfName}: ${AuConfName}.tmp
4496 + @diff -q $< $@ > /dev/null 2>&1 || { \
4497 + echo ' GEN ' $@; \
4501 +clean-files += ${AuConfName} ${AuConfName}.tmp
4502 +${obj}/sysfs.o: ${AuConfName}
4504 +-include ${srctree}/${src}/conf_priv.mk
4505 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4506 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4507 +++ linux/fs/aufs/cpup.c 2015-06-22 08:29:23.703424266 +0200
4510 + * Copyright (C) 2005-2015 Junjiro R. Okajima
4512 + * This program, aufs is free software; you can redistribute it and/or modify
4513 + * it under the terms of the GNU General Public License as published by
4514 + * the Free Software Foundation; either version 2 of the License, or
4515 + * (at your option) any later version.
4517 + * This program is distributed in the hope that it will be useful,
4518 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4519 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4520 + * GNU General Public License for more details.
4522 + * You should have received a copy of the GNU General Public License
4523 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4527 + * copy-up functions, see wbr_policy.c for copy-down
4530 +#include <linux/fs_stack.h>
4531 +#include <linux/mm.h>
4534 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4536 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4537 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4539 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4541 + dst->i_flags |= iflags & ~mask;
4542 + if (au_test_fs_notime(dst->i_sb))
4543 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4546 +void au_cpup_attr_timesizes(struct inode *inode)
4548 + struct inode *h_inode;
4550 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4551 + fsstack_copy_attr_times(inode, h_inode);
4552 + fsstack_copy_inode_size(inode, h_inode);
4555 +void au_cpup_attr_nlink(struct inode *inode, int force)
4557 + struct inode *h_inode;
4558 + struct super_block *sb;
4559 + aufs_bindex_t bindex, bend;
4562 + bindex = au_ibstart(inode);
4563 + h_inode = au_h_iptr(inode, bindex);
4565 + && !S_ISDIR(h_inode->i_mode)
4566 + && au_opt_test(au_mntflags(sb), PLINK)
4567 + && au_plink_test(inode))
4571 + * 0 can happen in revalidating.
4572 + * h_inode->i_mutex may not be held here, but it is harmless since once
4573 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4575 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4576 + * the incorrect link count.
4578 + set_nlink(inode, h_inode->i_nlink);
4581 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4582 + * it may includes whplink directory.
4584 + if (S_ISDIR(h_inode->i_mode)) {
4585 + bend = au_ibend(inode);
4586 + for (bindex++; bindex <= bend; bindex++) {
4587 + h_inode = au_h_iptr(inode, bindex);
4589 + au_add_nlink(inode, h_inode);
4594 +void au_cpup_attr_changeable(struct inode *inode)
4596 + struct inode *h_inode;
4598 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4599 + inode->i_mode = h_inode->i_mode;
4600 + inode->i_uid = h_inode->i_uid;
4601 + inode->i_gid = h_inode->i_gid;
4602 + au_cpup_attr_timesizes(inode);
4603 + au_cpup_attr_flags(inode, h_inode->i_flags);
4606 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4608 + struct au_iinfo *iinfo = au_ii(inode);
4610 + IiMustWriteLock(inode);
4612 + iinfo->ii_higen = h_inode->i_generation;
4613 + iinfo->ii_hsb1 = h_inode->i_sb;
4616 +void au_cpup_attr_all(struct inode *inode, int force)
4618 + struct inode *h_inode;
4620 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4621 + au_cpup_attr_changeable(inode);
4622 + if (inode->i_nlink > 0)
4623 + au_cpup_attr_nlink(inode, force);
4624 + inode->i_rdev = h_inode->i_rdev;
4625 + inode->i_blkbits = h_inode->i_blkbits;
4626 + au_cpup_igen(inode, h_inode);
4629 +/* ---------------------------------------------------------------------- */
4631 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4633 +/* keep the timestamps of the parent dir when cpup */
4634 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4635 + struct path *h_path)
4637 + struct inode *h_inode;
4639 + dt->dt_dentry = dentry;
4640 + dt->dt_h_path = *h_path;
4641 + h_inode = h_path->dentry->d_inode;
4642 + dt->dt_atime = h_inode->i_atime;
4643 + dt->dt_mtime = h_inode->i_mtime;
4647 +void au_dtime_revert(struct au_dtime *dt)
4649 + struct iattr attr;
4652 + attr.ia_atime = dt->dt_atime;
4653 + attr.ia_mtime = dt->dt_mtime;
4654 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4655 + | ATTR_ATIME | ATTR_ATIME_SET;
4657 + /* no delegation since this is a directory */
4658 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4659 + if (unlikely(err))
4660 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4663 +/* ---------------------------------------------------------------------- */
4665 +/* internal use only */
4666 +struct au_cpup_reg_attr {
4669 + unsigned int iflags; /* inode->i_flags */
4672 +static noinline_for_stack
4673 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4674 + struct au_cpup_reg_attr *h_src_attr)
4676 + int err, sbits, icex;
4677 + unsigned int mnt_flags;
4678 + unsigned char verbose;
4680 + struct path h_path;
4681 + struct inode *h_isrc, *h_idst;
4682 + struct kstat *h_st;
4683 + struct au_branch *br;
4685 + h_path.dentry = au_h_dptr(dst, bindex);
4686 + h_idst = h_path.dentry->d_inode;
4687 + br = au_sbr(dst->d_sb, bindex);
4688 + h_path.mnt = au_br_mnt(br);
4689 + h_isrc = h_src->d_inode;
4690 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4691 + | ATTR_ATIME | ATTR_MTIME
4692 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4693 + if (h_src_attr && h_src_attr->valid) {
4694 + h_st = &h_src_attr->st;
4695 + ia.ia_uid = h_st->uid;
4696 + ia.ia_gid = h_st->gid;
4697 + ia.ia_atime = h_st->atime;
4698 + ia.ia_mtime = h_st->mtime;
4699 + if (h_idst->i_mode != h_st->mode
4700 + && !S_ISLNK(h_idst->i_mode)) {
4701 + ia.ia_valid |= ATTR_MODE;
4702 + ia.ia_mode = h_st->mode;
4704 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4705 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4707 + ia.ia_uid = h_isrc->i_uid;
4708 + ia.ia_gid = h_isrc->i_gid;
4709 + ia.ia_atime = h_isrc->i_atime;
4710 + ia.ia_mtime = h_isrc->i_mtime;
4711 + if (h_idst->i_mode != h_isrc->i_mode
4712 + && !S_ISLNK(h_idst->i_mode)) {
4713 + ia.ia_valid |= ATTR_MODE;
4714 + ia.ia_mode = h_isrc->i_mode;
4716 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4717 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4719 + /* no delegation since it is just created */
4720 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4722 + /* is this nfs only? */
4723 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4724 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4725 + ia.ia_mode = h_isrc->i_mode;
4726 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4729 + icex = br->br_perm & AuBrAttr_ICEX;
4731 + mnt_flags = au_mntflags(dst->d_sb);
4732 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4733 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4739 +/* ---------------------------------------------------------------------- */
4741 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4742 + char *buf, unsigned long blksize)
4745 + size_t sz, rbytes, wbytes;
4746 + unsigned char all_zero;
4748 + struct mutex *h_mtx;
4749 + /* reduce stack usage */
4752 + zp = page_address(ZERO_PAGE(0));
4753 + if (unlikely(!zp))
4754 + return -ENOMEM; /* possible? */
4759 + AuDbg("len %lld\n", len);
4761 + if (len < blksize)
4765 + /* todo: signal_pending? */
4766 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4767 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4770 + if (unlikely(err < 0))
4774 + if (len >= rbytes && rbytes == blksize)
4775 + all_zero = !memcmp(buf, zp, rbytes);
4782 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4784 + /* todo: signal_pending? */
4785 + if (unlikely(err == -EAGAIN || err == -EINTR))
4787 + if (unlikely(err < 0))
4792 + if (unlikely(err < 0))
4798 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4800 + if (unlikely(res < 0))
4807 + /* the last block may be a hole */
4808 + if (!err && all_zero) {
4809 + AuLabel(last hole);
4812 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4813 + /* nfs requires this step to make last hole */
4814 + /* is this only nfs? */
4816 + /* todo: signal_pending? */
4817 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4818 + } while (err == -EAGAIN || err == -EINTR);
4825 + ia->ia_size = dst->f_pos;
4826 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4827 + ia->ia_file = dst;
4828 + h_mtx = &file_inode(dst)->i_mutex;
4829 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4830 + /* no delegation since it is just created */
4831 + err = vfsub_notify_change(&dst->f_path, ia,
4832 + /*delegated*/NULL);
4833 + mutex_unlock(h_mtx);
4840 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4843 + unsigned long blksize;
4844 + unsigned char do_kfree;
4848 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
4849 + if (!blksize || PAGE_SIZE < blksize)
4850 + blksize = PAGE_SIZE;
4851 + AuDbg("blksize %lu\n", blksize);
4852 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4854 + buf = kmalloc(blksize, GFP_NOFS);
4856 + buf = (void *)__get_free_page(GFP_NOFS);
4857 + if (unlikely(!buf))
4860 + if (len > (1 << 22))
4861 + AuDbg("copying a large file %lld\n", (long long)len);
4865 + err = au_do_copy_file(dst, src, len, buf, blksize);
4869 + free_page((unsigned long)buf);
4876 + * to support a sparse file which is opened with O_APPEND,
4877 + * we need to close the file.
4879 +static int au_cp_regular(struct au_cp_generic *cpg)
4882 + enum { SRC, DST };
4884 + aufs_bindex_t bindex;
4885 + unsigned int flags;
4886 + struct dentry *dentry;
4888 + struct file *file;
4892 + .bindex = cpg->bsrc,
4893 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4897 + .bindex = cpg->bdst,
4898 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4899 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4900 + .label = &&out_src
4903 + struct super_block *sb;
4905 + /* bsrc branch can be ro/rw. */
4906 + sb = cpg->dentry->d_sb;
4908 + for (i = 0; i < 2; i++, f++) {
4909 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4910 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4911 + /*file*/NULL, f->force_wr);
4912 + err = PTR_ERR(f->file);
4913 + if (IS_ERR(f->file))
4917 + /* try stopping to update while we copyup */
4918 + IMustLock(file[SRC].dentry->d_inode);
4919 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4921 + fput(file[DST].file);
4922 + au_sbr_put(sb, file[DST].bindex);
4925 + fput(file[SRC].file);
4926 + au_sbr_put(sb, file[SRC].bindex);
4931 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4932 + struct au_cpup_reg_attr *h_src_attr)
4936 + struct path h_path;
4937 + struct inode *h_src_inode, *h_dst_inode;
4940 + h_src_inode = au_h_iptr(cpg->dentry->d_inode, cpg->bsrc);
4941 + l = i_size_read(h_src_inode);
4942 + if (cpg->len == -1 || l < cpg->len)
4945 + /* try stopping to update while we are referencing */
4946 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4947 + au_pin_hdir_unlock(cpg->pin);
4949 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4950 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4951 + h_src_attr->iflags = h_src_inode->i_flags;
4952 + err = vfs_getattr(&h_path, &h_src_attr->st);
4953 + if (unlikely(err)) {
4954 + mutex_unlock(&h_src_inode->i_mutex);
4957 + h_src_attr->valid = 1;
4958 + err = au_cp_regular(cpg);
4959 + mutex_unlock(&h_src_inode->i_mutex);
4960 + rerr = au_pin_hdir_relock(cpg->pin);
4964 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
4965 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
4966 + h_dst_inode = h_path.dentry->d_inode;
4967 + spin_lock(&h_dst_inode->i_lock);
4968 + h_dst_inode->i_state |= I_LINKABLE;
4969 + spin_unlock(&h_dst_inode->i_lock);
4976 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4977 + struct inode *h_dir)
4980 + mm_segment_t old_fs;
4987 + if (unlikely(!h_src->d_inode->i_op->readlink))
4991 + sym.k = (void *)__get_free_page(GFP_NOFS);
4992 + if (unlikely(!sym.k))
4995 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
4996 + old_fs = get_fs();
4997 + set_fs(KERNEL_DS);
4998 + symlen = h_src->d_inode->i_op->readlink(h_src, sym.u, PATH_MAX);
5003 + sym.k[symlen] = 0;
5004 + err = vfsub_symlink(h_dir, h_path, sym.k);
5006 + free_page((unsigned long)sym.k);
5012 +static noinline_for_stack
5013 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5014 + struct au_cpup_reg_attr *h_src_attr)
5018 + unsigned int mnt_flags;
5019 + unsigned char isdir, isreg, force;
5020 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5021 + struct au_dtime dt;
5022 + struct path h_path;
5023 + struct dentry *h_src, *h_dst, *h_parent;
5024 + struct inode *h_inode, *h_dir;
5025 + struct super_block *sb;
5027 + /* bsrc branch can be ro/rw. */
5028 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5029 + h_inode = h_src->d_inode;
5030 + AuDebugOn(h_inode != au_h_iptr(cpg->dentry->d_inode, cpg->bsrc));
5032 + /* try stopping to be referenced while we are creating */
5033 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5034 + if (au_ftest_cpup(cpg->flags, RENAME))
5035 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5036 + AUFS_WH_PFX_LEN));
5037 + h_parent = h_dst->d_parent; /* dir inode is locked */
5038 + h_dir = h_parent->d_inode;
5040 + AuDebugOn(h_parent != h_dst->d_parent);
5042 + sb = cpg->dentry->d_sb;
5043 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5045 + h_path.dentry = h_parent;
5046 + au_dtime_store(&dt, dst_parent, &h_path);
5048 + h_path.dentry = h_dst;
5052 + mode = h_inode->i_mode;
5053 + switch (mode & S_IFMT) {
5056 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
5057 + /*want_excl*/true);
5059 + err = au_do_cpup_regular(cpg, h_src_attr);
5063 + err = vfsub_mkdir(h_dir, &h_path, mode);
5066 + * strange behaviour from the users view,
5067 + * particularry setattr case
5069 + if (au_ibstart(dst_parent->d_inode) == cpg->bdst)
5070 + au_cpup_attr_nlink(dst_parent->d_inode,
5072 + au_cpup_attr_nlink(cpg->dentry->d_inode, /*force*/1);
5076 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5080 + AuDebugOn(!capable(CAP_MKNOD));
5084 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5087 + AuIOErr("Unknown inode type 0%o\n", mode);
5091 + mnt_flags = au_mntflags(sb);
5092 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5094 + && au_opt_test(mnt_flags, XINO)
5095 + && (h_inode->i_nlink == 1
5096 + || (h_inode->i_state & I_LINKABLE))
5097 + /* todo: unnecessary? */
5098 + /* && cpg->dentry->d_inode->i_nlink == 1 */
5099 + && cpg->bdst < cpg->bsrc
5100 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5101 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5102 + /* ignore this error */
5107 + force = !!cpg->len;
5108 + if (cpg->len == -1)
5109 + force = !!i_size_read(h_inode);
5111 + au_fhsm_wrote(sb, cpg->bdst, force);
5115 + au_dtime_revert(&dt);
5119 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5122 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5123 + struct inode *h_dir;
5124 + aufs_bindex_t bdst;
5126 + dentry = cpg->dentry;
5128 + h_dentry = au_h_dptr(dentry, bdst);
5129 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5131 + au_set_h_dptr(dentry, bdst, NULL);
5132 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5134 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5135 + au_set_h_dptr(dentry, bdst, h_dentry);
5138 + parent = dget_parent(dentry);
5139 + h_parent = au_h_dptr(parent, bdst);
5141 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5142 + if (IS_ERR(h_path->dentry))
5143 + err = PTR_ERR(h_path->dentry);
5145 + if (unlikely(err))
5148 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5149 + h_dir = h_parent->d_inode;
5151 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5152 + /* no delegation since it is just created */
5153 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
5154 + dput(h_path->dentry);
5161 + * copyup the @dentry from @bsrc to @bdst.
5162 + * the caller must set the both of lower dentries.
5163 + * @len is for truncating when it is -1 copyup the entire file.
5164 + * in link/rename cases, @dst_parent may be different from the real one.
5165 + * basic->bsrc can be larger than basic->bdst.
5167 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5170 + aufs_bindex_t old_ibstart;
5171 + unsigned char isdir, plink;
5172 + struct dentry *h_src, *h_dst, *h_parent;
5173 + struct inode *dst_inode, *h_dir, *inode, *delegated;
5174 + struct super_block *sb;
5175 + struct au_branch *br;
5176 + /* to reuduce stack size */
5178 + struct au_dtime dt;
5179 + struct path h_path;
5180 + struct au_cpup_reg_attr h_src_attr;
5184 + a = kmalloc(sizeof(*a), GFP_NOFS);
5187 + a->h_src_attr.valid = 0;
5189 + sb = cpg->dentry->d_sb;
5190 + br = au_sbr(sb, cpg->bdst);
5191 + a->h_path.mnt = au_br_mnt(br);
5192 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5193 + h_parent = h_dst->d_parent; /* dir inode is locked */
5194 + h_dir = h_parent->d_inode;
5197 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5198 + inode = cpg->dentry->d_inode;
5201 + dst_parent = dget_parent(cpg->dentry);
5205 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5206 + dst_inode = au_h_iptr(inode, cpg->bdst);
5208 + if (unlikely(!plink)) {
5210 + AuIOErr("hi%lu(i%lu) exists on b%d "
5211 + "but plink is disabled\n",
5212 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5216 + if (dst_inode->i_nlink) {
5217 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5219 + h_src = au_plink_lkup(inode, cpg->bdst);
5220 + err = PTR_ERR(h_src);
5221 + if (IS_ERR(h_src))
5223 + if (unlikely(!h_src->d_inode)) {
5225 + AuIOErr("i%lu exists on a upper branch "
5226 + "but not pseudo-linked\n",
5233 + a->h_path.dentry = h_parent;
5234 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5237 + a->h_path.dentry = h_dst;
5239 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5240 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5241 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5243 + au_dtime_revert(&a->dt);
5244 + if (unlikely(err == -EWOULDBLOCK)) {
5245 + pr_warn("cannot retry for NFSv4 delegation"
5246 + " for an internal link\n");
5252 + /* todo: cpup_wh_file? */
5254 + au_update_ibrange(inode, /*do_put_zero*/1);
5257 + isdir = S_ISDIR(inode->i_mode);
5258 + old_ibstart = au_ibstart(inode);
5259 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5260 + if (unlikely(err))
5262 + dst_inode = h_dst->d_inode;
5263 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
5264 + /* todo: necessary? */
5265 + /* au_pin_hdir_unlock(cpg->pin); */
5267 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5268 + if (unlikely(err)) {
5269 + /* todo: necessary? */
5270 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5271 + mutex_unlock(&dst_inode->i_mutex);
5275 + if (cpg->bdst < old_ibstart) {
5276 + if (S_ISREG(inode->i_mode)) {
5277 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5278 + if (unlikely(err)) {
5279 + /* ignore an error */
5280 + /* au_pin_hdir_relock(cpg->pin); */
5281 + mutex_unlock(&dst_inode->i_mutex);
5285 + au_set_ibstart(inode, cpg->bdst);
5287 + au_set_ibend(inode, cpg->bdst);
5288 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5289 + au_hi_flags(inode, isdir));
5291 + /* todo: necessary? */
5292 + /* err = au_pin_hdir_relock(cpg->pin); */
5293 + mutex_unlock(&dst_inode->i_mutex);
5294 + if (unlikely(err))
5298 + && (h_src->d_inode->i_nlink > 1
5299 + || h_src->d_inode->i_state & I_LINKABLE)
5301 + au_plink_append(inode, cpg->bdst, h_dst);
5303 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5304 + a->h_path.dentry = h_dst;
5305 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5308 + goto out_parent; /* success */
5312 + a->h_path.dentry = h_parent;
5313 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5314 + a->h_path.dentry = h_dst;
5316 + if (h_dst->d_inode) {
5318 + /* no delegation since it is just created */
5319 + rerr = vfsub_unlink(h_dir, &a->h_path,
5320 + /*delegated*/NULL, /*force*/0);
5322 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5324 + au_dtime_revert(&a->dt);
5326 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5336 +#if 0 /* reserved */
5337 +struct au_cpup_single_args {
5339 + struct au_cp_generic *cpg;
5340 + struct dentry *dst_parent;
5343 +static void au_call_cpup_single(void *args)
5345 + struct au_cpup_single_args *a = args;
5347 + au_pin_hdir_acquire_nest(a->cpg->pin);
5348 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5349 + au_pin_hdir_release(a->cpg->pin);
5354 + * prevent SIGXFSZ in copy-up.
5355 + * testing CAP_MKNOD is for generic fs,
5356 + * but CAP_FSETID is for xfs only, currently.
5358 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5361 + struct super_block *sb;
5362 + struct inode *h_dir;
5365 + sb = au_pinned_parent(pin)->d_sb;
5366 + if (!au_wkq_test()
5367 + && (!au_sbi(sb)->si_plink_maint_pid
5368 + || au_plink_maint(sb, AuLock_NOPLM))) {
5369 + switch (mode & S_IFMT) {
5371 + /* no condition about RLIMIT_FSIZE and the file size */
5376 + do_sio = !capable(CAP_MKNOD);
5380 + do_sio = ((mode & (S_ISUID | S_ISGID))
5381 + && !capable(CAP_FSETID));
5382 + /* this workaround may be removed in the future */
5384 + h_dir = au_pinned_h_dir(pin);
5385 + do_sio = h_dir->i_mode & S_ISVTX;
5392 +#if 0 /* reserved */
5393 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5396 + struct dentry *h_dentry;
5398 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5399 + if (!au_cpup_sio_test(pin, h_dentry->d_inode->i_mode))
5400 + err = au_cpup_single(cpg, dst_parent);
5402 + struct au_cpup_single_args args = {
5405 + .dst_parent = dst_parent
5407 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5408 + if (unlikely(wkq_err))
5417 + * copyup the @dentry from the first active lower branch to @bdst,
5418 + * using au_cpup_single().
5420 +static int au_cpup_simple(struct au_cp_generic *cpg)
5423 + unsigned int flags_orig;
5424 + struct dentry *dentry;
5426 + AuDebugOn(cpg->bsrc < 0);
5428 + dentry = cpg->dentry;
5429 + DiMustWriteLock(dentry);
5431 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5433 + flags_orig = cpg->flags;
5434 + au_fset_cpup(cpg->flags, RENAME);
5435 + err = au_cpup_single(cpg, NULL);
5436 + cpg->flags = flags_orig;
5438 + return 0; /* success */
5441 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5442 + au_set_dbstart(dentry, cpg->bsrc);
5448 +struct au_cpup_simple_args {
5450 + struct au_cp_generic *cpg;
5453 +static void au_call_cpup_simple(void *args)
5455 + struct au_cpup_simple_args *a = args;
5457 + au_pin_hdir_acquire_nest(a->cpg->pin);
5458 + *a->errp = au_cpup_simple(a->cpg);
5459 + au_pin_hdir_release(a->cpg->pin);
5462 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5465 + struct dentry *dentry, *parent;
5466 + struct file *h_file;
5467 + struct inode *h_dir;
5469 + dentry = cpg->dentry;
5471 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5472 + AuDebugOn(cpg->bsrc < 0);
5473 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5474 + err = PTR_ERR(h_file);
5475 + if (IS_ERR(h_file))
5479 + parent = dget_parent(dentry);
5480 + h_dir = au_h_iptr(parent->d_inode, cpg->bdst);
5481 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5482 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5483 + err = au_cpup_simple(cpg);
5485 + struct au_cpup_simple_args args = {
5489 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5490 + if (unlikely(wkq_err))
5496 + au_h_open_post(dentry, cpg->bsrc, h_file);
5502 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5504 + aufs_bindex_t bsrc, bend;
5505 + struct dentry *dentry, *h_dentry;
5507 + if (cpg->bsrc < 0) {
5508 + dentry = cpg->dentry;
5509 + bend = au_dbend(dentry);
5510 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5511 + h_dentry = au_h_dptr(dentry, bsrc);
5513 + AuDebugOn(!h_dentry->d_inode);
5517 + AuDebugOn(bsrc > bend);
5520 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5521 + return au_do_sio_cpup_simple(cpg);
5524 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5526 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5527 + return au_do_sio_cpup_simple(cpg);
5530 +/* ---------------------------------------------------------------------- */
5533 + * copyup the deleted file for writing.
5535 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5536 + struct file *file)
5539 + unsigned int flags_orig;
5540 + aufs_bindex_t bsrc_orig;
5541 + struct dentry *h_d_dst, *h_d_start;
5542 + struct au_dinfo *dinfo;
5543 + struct au_hdentry *hdp;
5545 + dinfo = au_di(cpg->dentry);
5546 + AuRwMustWriteLock(&dinfo->di_rwsem);
5548 + bsrc_orig = cpg->bsrc;
5549 + cpg->bsrc = dinfo->di_bstart;
5550 + hdp = dinfo->di_hdentry;
5551 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5552 + dinfo->di_bstart = cpg->bdst;
5553 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5556 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5557 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_path.dentry;
5559 + flags_orig = cpg->flags;
5560 + cpg->flags = !AuCpup_DTIME;
5561 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5562 + cpg->flags = flags_orig;
5565 + err = au_reopen_nondir(file);
5566 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5568 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5569 + dinfo->di_bstart = cpg->bsrc;
5570 + cpg->bsrc = bsrc_orig;
5575 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5578 + aufs_bindex_t bdst;
5579 + struct au_dtime dt;
5580 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5581 + struct au_branch *br;
5582 + struct path h_path;
5584 + dentry = cpg->dentry;
5586 + br = au_sbr(dentry->d_sb, bdst);
5587 + parent = dget_parent(dentry);
5588 + h_parent = au_h_dptr(parent, bdst);
5589 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5590 + err = PTR_ERR(wh_dentry);
5591 + if (IS_ERR(wh_dentry))
5594 + h_path.dentry = h_parent;
5595 + h_path.mnt = au_br_mnt(br);
5596 + au_dtime_store(&dt, parent, &h_path);
5597 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5598 + if (unlikely(err))
5602 + h_path.dentry = wh_dentry;
5603 + if (!d_is_dir(wh_dentry)) {
5604 + /* no delegation since it is just created */
5605 + err = vfsub_unlink(h_parent->d_inode, &h_path,
5606 + /*delegated*/NULL, /*force*/0);
5608 + err = vfsub_rmdir(h_parent->d_inode, &h_path);
5609 + if (unlikely(err)) {
5610 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5614 + au_dtime_revert(&dt);
5615 + au_set_hi_wh(dentry->d_inode, bdst, wh_dentry);
5624 +struct au_cpup_wh_args {
5626 + struct au_cp_generic *cpg;
5627 + struct file *file;
5630 +static void au_call_cpup_wh(void *args)
5632 + struct au_cpup_wh_args *a = args;
5634 + au_pin_hdir_acquire_nest(a->cpg->pin);
5635 + *a->errp = au_cpup_wh(a->cpg, a->file);
5636 + au_pin_hdir_release(a->cpg->pin);
5639 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5642 + aufs_bindex_t bdst;
5643 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5644 + struct inode *dir, *h_dir, *h_tmpdir;
5645 + struct au_wbr *wbr;
5646 + struct au_pin wh_pin, *pin_orig;
5648 + dentry = cpg->dentry;
5650 + parent = dget_parent(dentry);
5651 + dir = parent->d_inode;
5654 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5657 + if (!h_dir->i_nlink) {
5658 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5659 + h_orph = wbr->wbr_orph;
5661 + h_parent = dget(au_h_dptr(parent, bdst));
5662 + au_set_h_dptr(parent, bdst, dget(h_orph));
5663 + h_tmpdir = h_orph->d_inode;
5664 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5666 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
5667 + /* todo: au_h_open_pre()? */
5669 + pin_orig = cpg->pin;
5670 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5671 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5672 + cpg->pin = &wh_pin;
5675 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5676 + && !au_cpup_sio_test(cpg->pin, dentry->d_inode->i_mode))
5677 + err = au_cpup_wh(cpg, file);
5679 + struct au_cpup_wh_args args = {
5684 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5685 + if (unlikely(wkq_err))
5690 + mutex_unlock(&h_tmpdir->i_mutex);
5691 + /* todo: au_h_open_post()? */
5692 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5693 + au_set_h_dptr(parent, bdst, h_parent);
5694 + AuDebugOn(!pin_orig);
5695 + cpg->pin = pin_orig;
5703 +/* ---------------------------------------------------------------------- */
5706 + * generic routine for both of copy-up and copy-down.
5708 +/* cf. revalidate function in file.c */
5709 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5710 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5711 + struct au_pin *pin,
5712 + struct dentry *h_parent, void *arg),
5716 + struct au_pin pin;
5717 + struct dentry *d, *parent, *h_parent, *real_parent;
5720 + parent = dget_parent(dentry);
5721 + if (IS_ROOT(parent))
5724 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5725 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5727 + /* do not use au_dpage */
5728 + real_parent = parent;
5731 + parent = dget_parent(dentry);
5732 + h_parent = au_h_dptr(parent, bdst);
5734 + goto out; /* success */
5736 + /* find top dir which is necessary to cpup */
5740 + parent = dget_parent(d);
5741 + di_read_lock_parent3(parent, !AuLock_IR);
5742 + h_parent = au_h_dptr(parent, bdst);
5743 + di_read_unlock(parent, !AuLock_IR);
5744 + } while (!h_parent);
5746 + if (d != real_parent)
5747 + di_write_lock_child3(d);
5749 + /* somebody else might create while we were sleeping */
5750 + if (!au_h_dptr(d, bdst) || !au_h_dptr(d, bdst)->d_inode) {
5751 + if (au_h_dptr(d, bdst))
5752 + au_update_dbstart(d);
5754 + au_pin_set_dentry(&pin, d);
5755 + err = au_do_pin(&pin);
5757 + err = cp(d, bdst, &pin, h_parent, arg);
5762 + if (d != real_parent)
5763 + di_write_unlock(d);
5764 + if (unlikely(err))
5773 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5774 + struct au_pin *pin,
5775 + struct dentry *h_parent __maybe_unused,
5776 + void *arg __maybe_unused)
5778 + struct au_cp_generic cpg = {
5784 + .flags = AuCpup_DTIME
5786 + return au_sio_cpup_simple(&cpg);
5789 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5791 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5794 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5797 + struct dentry *parent;
5798 + struct inode *dir;
5800 + parent = dget_parent(dentry);
5801 + dir = parent->d_inode;
5803 + if (au_h_iptr(dir, bdst))
5806 + di_read_unlock(parent, AuLock_IR);
5807 + di_write_lock_parent(parent);
5808 + /* someone else might change our inode while we were sleeping */
5809 + if (!au_h_iptr(dir, bdst))
5810 + err = au_cpup_dirs(dentry, bdst);
5811 + di_downgrade_lock(parent, AuLock_IR);
5817 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5818 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5819 +++ linux/fs/aufs/cpup.h 2015-06-22 08:27:37.874168290 +0200
5822 + * Copyright (C) 2005-2015 Junjiro R. Okajima
5824 + * This program, aufs is free software; you can redistribute it and/or modify
5825 + * it under the terms of the GNU General Public License as published by
5826 + * the Free Software Foundation; either version 2 of the License, or
5827 + * (at your option) any later version.
5829 + * This program is distributed in the hope that it will be useful,
5830 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5831 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5832 + * GNU General Public License for more details.
5834 + * You should have received a copy of the GNU General Public License
5835 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5839 + * copy-up/down functions
5842 +#ifndef __AUFS_CPUP_H__
5843 +#define __AUFS_CPUP_H__
5847 +#include <linux/path.h>
5853 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5854 +void au_cpup_attr_timesizes(struct inode *inode);
5855 +void au_cpup_attr_nlink(struct inode *inode, int force);
5856 +void au_cpup_attr_changeable(struct inode *inode);
5857 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5858 +void au_cpup_attr_all(struct inode *inode, int force);
5860 +/* ---------------------------------------------------------------------- */
5862 +struct au_cp_generic {
5863 + struct dentry *dentry;
5864 + aufs_bindex_t bdst, bsrc;
5866 + struct au_pin *pin;
5867 + unsigned int flags;
5871 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5872 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5874 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5875 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5877 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5879 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5880 + the branch is marked as RO */
5882 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5883 +#define au_fset_cpup(flags, name) \
5884 + do { (flags) |= AuCpup_##name; } while (0)
5885 +#define au_fclr_cpup(flags, name) \
5886 + do { (flags) &= ~AuCpup_##name; } while (0)
5888 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5889 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5890 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5891 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5893 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5894 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5895 + struct au_pin *pin,
5896 + struct dentry *h_parent, void *arg),
5898 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5899 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5901 +/* ---------------------------------------------------------------------- */
5903 +/* keep timestamps when copyup */
5905 + struct dentry *dt_dentry;
5906 + struct path dt_h_path;
5907 + struct timespec dt_atime, dt_mtime;
5909 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5910 + struct path *h_path);
5911 +void au_dtime_revert(struct au_dtime *dt);
5913 +#endif /* __KERNEL__ */
5914 +#endif /* __AUFS_CPUP_H__ */
5915 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5916 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5917 +++ linux/fs/aufs/dbgaufs.c 2015-06-22 08:29:23.706757681 +0200
5920 + * Copyright (C) 2005-2015 Junjiro R. Okajima
5922 + * This program, aufs is free software; you can redistribute it and/or modify
5923 + * it under the terms of the GNU General Public License as published by
5924 + * the Free Software Foundation; either version 2 of the License, or
5925 + * (at your option) any later version.
5927 + * This program is distributed in the hope that it will be useful,
5928 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5929 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5930 + * GNU General Public License for more details.
5932 + * You should have received a copy of the GNU General Public License
5933 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5937 + * debugfs interface
5940 +#include <linux/debugfs.h>
5943 +#ifndef CONFIG_SYSFS
5944 +#error DEBUG_FS depends upon SYSFS
5947 +static struct dentry *dbgaufs;
5948 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5950 +/* 20 is max digits length of ulong 64 */
5951 +struct dbgaufs_arg {
5957 + * common function for all XINO files
5959 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5960 + struct file *file)
5962 + kfree(file->private_data);
5966 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5970 + struct dbgaufs_arg *p;
5973 + p = kmalloc(sizeof(*p), GFP_NOFS);
5979 + file->private_data = p;
5983 + err = vfs_getattr(&xf->f_path, &st);
5987 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
5988 + (long)file_count(xf), st.blocks, st.blksize,
5989 + (long long)st.size);
5991 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
5992 + st.blocks, st.blksize,
5993 + (long long)st.size);
5994 + AuDebugOn(p->n >= sizeof(p->a));
5996 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6005 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6006 + size_t count, loff_t *ppos)
6008 + struct dbgaufs_arg *p;
6010 + p = file->private_data;
6011 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6014 +/* ---------------------------------------------------------------------- */
6016 +struct dbgaufs_plink_arg {
6021 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6022 + struct file *file)
6024 + free_page((unsigned long)file->private_data);
6028 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6030 + int err, i, limit;
6031 + unsigned long n, sum;
6032 + struct dbgaufs_plink_arg *p;
6033 + struct au_sbinfo *sbinfo;
6034 + struct super_block *sb;
6035 + struct au_sphlhead *sphl;
6038 + p = (void *)get_zeroed_page(GFP_NOFS);
6043 + sbinfo = inode->i_private;
6044 + sb = sbinfo->si_sb;
6045 + si_noflush_read_lock(sb);
6046 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6047 + limit = PAGE_SIZE - sizeof(p->n);
6049 + /* the number of buckets */
6050 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6055 + for (i = 0, sphl = sbinfo->si_plink;
6056 + i < AuPlink_NHASH;
6058 + n = au_sphl_count(sphl);
6061 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6064 + if (unlikely(limit <= 0))
6067 + p->a[p->n - 1] = '\n';
6069 + /* the sum of plinks */
6070 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6073 + if (unlikely(limit <= 0))
6076 +#define str "1\n0\n0\n"
6077 + p->n = sizeof(str) - 1;
6078 + strcpy(p->a, str);
6081 + si_read_unlock(sb);
6084 + file->private_data = p;
6085 + goto out; /* success */
6088 + free_page((unsigned long)p);
6093 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6094 + size_t count, loff_t *ppos)
6096 + struct dbgaufs_plink_arg *p;
6098 + p = file->private_data;
6099 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6102 +static const struct file_operations dbgaufs_plink_fop = {
6103 + .owner = THIS_MODULE,
6104 + .open = dbgaufs_plink_open,
6105 + .release = dbgaufs_plink_release,
6106 + .read = dbgaufs_plink_read
6109 +/* ---------------------------------------------------------------------- */
6111 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6114 + struct au_sbinfo *sbinfo;
6115 + struct super_block *sb;
6117 + sbinfo = inode->i_private;
6118 + sb = sbinfo->si_sb;
6119 + si_noflush_read_lock(sb);
6120 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6121 + si_read_unlock(sb);
6125 +static const struct file_operations dbgaufs_xib_fop = {
6126 + .owner = THIS_MODULE,
6127 + .open = dbgaufs_xib_open,
6128 + .release = dbgaufs_xi_release,
6129 + .read = dbgaufs_xi_read
6132 +/* ---------------------------------------------------------------------- */
6134 +#define DbgaufsXi_PREFIX "xi"
6136 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6140 + struct au_sbinfo *sbinfo;
6141 + struct super_block *sb;
6143 + struct qstr *name;
6147 + name = &file->f_path.dentry->d_name;
6148 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6149 + || memcmp(name->name, DbgaufsXi_PREFIX,
6150 + sizeof(DbgaufsXi_PREFIX) - 1)))
6152 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6153 + if (unlikely(err))
6156 + sbinfo = inode->i_private;
6157 + sb = sbinfo->si_sb;
6158 + si_noflush_read_lock(sb);
6159 + if (l <= au_sbend(sb)) {
6160 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6161 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6164 + si_read_unlock(sb);
6170 +static const struct file_operations dbgaufs_xino_fop = {
6171 + .owner = THIS_MODULE,
6172 + .open = dbgaufs_xino_open,
6173 + .release = dbgaufs_xi_release,
6174 + .read = dbgaufs_xi_read
6177 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6179 + aufs_bindex_t bend;
6180 + struct au_branch *br;
6181 + struct au_xino_file *xi;
6183 + if (!au_sbi(sb)->si_dbgaufs)
6186 + bend = au_sbend(sb);
6187 + for (; bindex <= bend; bindex++) {
6188 + br = au_sbr(sb, bindex);
6189 + xi = &br->br_xino;
6190 + debugfs_remove(xi->xi_dbgaufs);
6191 + xi->xi_dbgaufs = NULL;
6195 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6197 + struct au_sbinfo *sbinfo;
6198 + struct dentry *parent;
6199 + struct au_branch *br;
6200 + struct au_xino_file *xi;
6201 + aufs_bindex_t bend;
6202 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6204 + sbinfo = au_sbi(sb);
6205 + parent = sbinfo->si_dbgaufs;
6209 + bend = au_sbend(sb);
6210 + for (; bindex <= bend; bindex++) {
6211 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6212 + br = au_sbr(sb, bindex);
6213 + xi = &br->br_xino;
6214 + AuDebugOn(xi->xi_dbgaufs);
6215 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6216 + sbinfo, &dbgaufs_xino_fop);
6217 + /* ignore an error */
6218 + if (unlikely(!xi->xi_dbgaufs))
6219 + AuWarn1("failed %s under debugfs\n", name);
6223 +/* ---------------------------------------------------------------------- */
6225 +#ifdef CONFIG_AUFS_EXPORT
6226 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6229 + struct au_sbinfo *sbinfo;
6230 + struct super_block *sb;
6232 + sbinfo = inode->i_private;
6233 + sb = sbinfo->si_sb;
6234 + si_noflush_read_lock(sb);
6235 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6236 + si_read_unlock(sb);
6240 +static const struct file_operations dbgaufs_xigen_fop = {
6241 + .owner = THIS_MODULE,
6242 + .open = dbgaufs_xigen_open,
6243 + .release = dbgaufs_xi_release,
6244 + .read = dbgaufs_xi_read
6247 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6252 + * This function is a dynamic '__init' function actually,
6253 + * so the tiny check for si_rwsem is unnecessary.
6255 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6258 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6259 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6260 + &dbgaufs_xigen_fop);
6261 + if (sbinfo->si_dbgaufs_xigen)
6267 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6271 +#endif /* CONFIG_AUFS_EXPORT */
6273 +/* ---------------------------------------------------------------------- */
6275 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6278 + * This function is a dynamic '__fin' function actually,
6279 + * so the tiny check for si_rwsem is unnecessary.
6281 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6283 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6284 + sbinfo->si_dbgaufs = NULL;
6285 + kobject_put(&sbinfo->si_kobj);
6288 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6291 + char name[SysaufsSiNameLen];
6294 + * This function is a dynamic '__init' function actually,
6295 + * so the tiny check for si_rwsem is unnecessary.
6297 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6301 + AuErr1("/debug/aufs is uninitialized\n");
6306 + sysaufs_name(sbinfo, name);
6307 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6308 + if (unlikely(!sbinfo->si_dbgaufs))
6310 + kobject_get(&sbinfo->si_kobj);
6312 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6313 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6314 + &dbgaufs_xib_fop);
6315 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6318 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6319 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6320 + &dbgaufs_plink_fop);
6321 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6324 + err = dbgaufs_xigen_init(sbinfo);
6326 + goto out; /* success */
6329 + dbgaufs_si_fin(sbinfo);
6334 +/* ---------------------------------------------------------------------- */
6336 +void dbgaufs_fin(void)
6338 + debugfs_remove(dbgaufs);
6341 +int __init dbgaufs_init(void)
6346 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6351 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6352 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6353 +++ linux/fs/aufs/dbgaufs.h 2015-06-22 08:27:37.874168290 +0200
6356 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6358 + * This program, aufs is free software; you can redistribute it and/or modify
6359 + * it under the terms of the GNU General Public License as published by
6360 + * the Free Software Foundation; either version 2 of the License, or
6361 + * (at your option) any later version.
6363 + * This program is distributed in the hope that it will be useful,
6364 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6365 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6366 + * GNU General Public License for more details.
6368 + * You should have received a copy of the GNU General Public License
6369 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6373 + * debugfs interface
6376 +#ifndef __DBGAUFS_H__
6377 +#define __DBGAUFS_H__
6381 +struct super_block;
6384 +#ifdef CONFIG_DEBUG_FS
6386 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6387 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6388 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6389 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6390 +void dbgaufs_fin(void);
6391 +int __init dbgaufs_init(void);
6393 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6394 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6395 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6396 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6397 +AuStubVoid(dbgaufs_fin, void)
6398 +AuStubInt0(__init dbgaufs_init, void)
6399 +#endif /* CONFIG_DEBUG_FS */
6401 +#endif /* __KERNEL__ */
6402 +#endif /* __DBGAUFS_H__ */
6403 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6404 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6405 +++ linux/fs/aufs/dcsub.c 2015-06-22 08:27:37.877501704 +0200
6408 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6410 + * This program, aufs is free software; you can redistribute it and/or modify
6411 + * it under the terms of the GNU General Public License as published by
6412 + * the Free Software Foundation; either version 2 of the License, or
6413 + * (at your option) any later version.
6415 + * This program is distributed in the hope that it will be useful,
6416 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6417 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6418 + * GNU General Public License for more details.
6420 + * You should have received a copy of the GNU General Public License
6421 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6425 + * sub-routines for dentry cache
6430 +static void au_dpage_free(struct au_dpage *dpage)
6433 + struct dentry **p;
6435 + p = dpage->dentries;
6436 + for (i = 0; i < dpage->ndentry; i++)
6438 + free_page((unsigned long)dpage->dentries);
6441 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6447 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6448 + if (unlikely(!dpages->dpages))
6451 + p = (void *)__get_free_page(gfp);
6455 + dpages->dpages[0].ndentry = 0;
6456 + dpages->dpages[0].dentries = p;
6457 + dpages->ndpage = 1;
6458 + return 0; /* success */
6461 + kfree(dpages->dpages);
6466 +void au_dpages_free(struct au_dcsub_pages *dpages)
6469 + struct au_dpage *p;
6471 + p = dpages->dpages;
6472 + for (i = 0; i < dpages->ndpage; i++)
6473 + au_dpage_free(p++);
6474 + kfree(dpages->dpages);
6477 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6478 + struct dentry *dentry, gfp_t gfp)
6481 + struct au_dpage *dpage;
6484 + dpage = dpages->dpages + dpages->ndpage - 1;
6485 + sz = PAGE_SIZE / sizeof(dentry);
6486 + if (unlikely(dpage->ndentry >= sz)) {
6487 + AuLabel(new dpage);
6489 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6490 + p = au_kzrealloc(dpages->dpages, sz,
6491 + sz + sizeof(*dpages->dpages), gfp);
6495 + dpages->dpages = p;
6496 + dpage = dpages->dpages + dpages->ndpage;
6497 + p = (void *)__get_free_page(gfp);
6501 + dpage->ndentry = 0;
6502 + dpage->dentries = p;
6506 + AuDebugOn(au_dcount(dentry) <= 0);
6507 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6508 + return 0; /* success */
6514 +/* todo: BAD approach */
6515 +/* copied from linux/fs/dcache.c */
6523 +extern void d_walk(struct dentry *parent, void *data,
6524 + enum d_walk_ret (*enter)(void *, struct dentry *),
6525 + void (*finish)(void *));
6527 +struct ac_dpages_arg {
6529 + struct au_dcsub_pages *dpages;
6530 + struct super_block *sb;
6531 + au_dpages_test test;
6535 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6537 + enum d_walk_ret ret;
6538 + struct ac_dpages_arg *arg = _arg;
6540 + ret = D_WALK_CONTINUE;
6541 + if (dentry->d_sb == arg->sb
6542 + && !IS_ROOT(dentry)
6543 + && au_dcount(dentry) > 0
6545 + && (!arg->test || arg->test(dentry, arg->arg))) {
6546 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6547 + if (unlikely(arg->err))
6548 + ret = D_WALK_QUIT;
6554 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6555 + au_dpages_test test, void *arg)
6557 + struct ac_dpages_arg args = {
6565 + d_walk(root, &args, au_call_dpages_append, NULL);
6570 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6571 + int do_include, au_dpages_test test, void *arg)
6576 + write_seqlock(&rename_lock);
6577 + spin_lock(&dentry->d_lock);
6579 + && au_dcount(dentry) > 0
6580 + && (!test || test(dentry, arg)))
6581 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6582 + spin_unlock(&dentry->d_lock);
6583 + if (unlikely(err))
6587 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6590 + while (!IS_ROOT(dentry)) {
6591 + dentry = dentry->d_parent; /* rename_lock is locked */
6592 + spin_lock(&dentry->d_lock);
6593 + if (au_dcount(dentry) > 0
6594 + && (!test || test(dentry, arg)))
6595 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6596 + spin_unlock(&dentry->d_lock);
6597 + if (unlikely(err))
6602 + write_sequnlock(&rename_lock);
6606 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6608 + return au_di(dentry) && dentry->d_sb == arg;
6611 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6612 + struct dentry *dentry, int do_include)
6614 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6615 + au_dcsub_dpages_aufs, dentry->d_sb);
6618 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6620 + struct path path[2] = {
6629 + return path_is_under(path + 0, path + 1);
6631 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6632 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6633 +++ linux/fs/aufs/dcsub.h 2015-06-22 08:29:23.706757681 +0200
6636 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6638 + * This program, aufs is free software; you can redistribute it and/or modify
6639 + * it under the terms of the GNU General Public License as published by
6640 + * the Free Software Foundation; either version 2 of the License, or
6641 + * (at your option) any later version.
6643 + * This program is distributed in the hope that it will be useful,
6644 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6645 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6646 + * GNU General Public License for more details.
6648 + * You should have received a copy of the GNU General Public License
6649 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6653 + * sub-routines for dentry cache
6656 +#ifndef __AUFS_DCSUB_H__
6657 +#define __AUFS_DCSUB_H__
6661 +#include <linux/dcache.h>
6662 +#include <linux/fs.h>
6666 + struct dentry **dentries;
6669 +struct au_dcsub_pages {
6671 + struct au_dpage *dpages;
6674 +/* ---------------------------------------------------------------------- */
6677 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6678 +void au_dpages_free(struct au_dcsub_pages *dpages);
6679 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6680 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6681 + au_dpages_test test, void *arg);
6682 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6683 + int do_include, au_dpages_test test, void *arg);
6684 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6685 + struct dentry *dentry, int do_include);
6686 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6688 +/* ---------------------------------------------------------------------- */
6691 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6692 + * include/linux/dcache.h. Try them (in the future).
6695 +static inline int au_d_hashed_positive(struct dentry *d)
6698 + struct inode *inode = d->d_inode;
6701 + if (unlikely(d_unhashed(d) || !inode || !inode->i_nlink))
6706 +static inline int au_d_linkable(struct dentry *d)
6709 + struct inode *inode = d->d_inode;
6711 + err = au_d_hashed_positive(d);
6714 + && (inode->i_state & I_LINKABLE))
6719 +static inline int au_d_alive(struct dentry *d)
6722 + struct inode *inode;
6726 + err = au_d_hashed_positive(d);
6728 + inode = d->d_inode;
6729 + if (unlikely(d_unlinked(d) || !inode || !inode->i_nlink))
6735 +static inline int au_alive_dir(struct dentry *d)
6739 + err = au_d_alive(d);
6740 + if (unlikely(err || IS_DEADDIR(d->d_inode)))
6745 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6747 + return a->len == b->len
6748 + && !memcmp(a->name, b->name, a->len);
6753 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
6755 + * the type of d_lockref.count became int, but the inlined function d_count()
6756 + * still returns unsigned int.
6757 + * I don't know why. Maybe it is for every d_count() users?
6758 + * Anyway au_dcount() lives on.
6760 +static inline int au_dcount(struct dentry *d)
6762 + return (int)d_count(d);
6765 +#endif /* __KERNEL__ */
6766 +#endif /* __AUFS_DCSUB_H__ */
6767 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6768 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6769 +++ linux/fs/aufs/debug.c 2015-06-22 08:29:23.706757681 +0200
6772 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6774 + * This program, aufs is free software; you can redistribute it and/or modify
6775 + * it under the terms of the GNU General Public License as published by
6776 + * the Free Software Foundation; either version 2 of the License, or
6777 + * (at your option) any later version.
6779 + * This program is distributed in the hope that it will be useful,
6780 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6781 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6782 + * GNU General Public License for more details.
6784 + * You should have received a copy of the GNU General Public License
6785 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6789 + * debug print functions
6794 +/* Returns 0, or -errno. arg is in kp->arg. */
6795 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6799 + err = kstrtoint(val, 0, &n);
6809 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6810 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6815 + return sprintf(buffer, "%d", atomic_read(a));
6818 +static struct kernel_param_ops param_ops_atomic_t = {
6819 + .set = param_atomic_t_set,
6820 + .get = param_atomic_t_get
6821 + /* void (*free)(void *arg) */
6824 +atomic_t aufs_debug = ATOMIC_INIT(0);
6825 +MODULE_PARM_DESC(debug, "debug print");
6826 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6828 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
6829 +char *au_plevel = KERN_DEBUG;
6830 +#define dpri(fmt, ...) do { \
6832 + && strcmp(au_plevel, KERN_DEBUG)) \
6833 + || au_debug_test()) \
6834 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6837 +/* ---------------------------------------------------------------------- */
6839 +void au_dpri_whlist(struct au_nhash *whlist)
6841 + unsigned long ul, n;
6842 + struct hlist_head *head;
6843 + struct au_vdir_wh *pos;
6845 + n = whlist->nh_num;
6846 + head = whlist->nh_head;
6847 + for (ul = 0; ul < n; ul++) {
6848 + hlist_for_each_entry(pos, head, wh_hash)
6849 + dpri("b%d, %.*s, %d\n",
6851 + pos->wh_str.len, pos->wh_str.name,
6857 +void au_dpri_vdir(struct au_vdir *vdir)
6860 + union au_vdir_deblk_p p;
6863 + if (!vdir || IS_ERR(vdir)) {
6864 + dpri("err %ld\n", PTR_ERR(vdir));
6868 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6869 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6870 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6871 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6872 + p.deblk = vdir->vd_deblk[ul];
6874 + dpri("[%lu]: %p\n", ul, o);
6878 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6879 + struct dentry *wh)
6884 + if (!inode || IS_ERR(inode)) {
6885 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6889 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6890 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6891 + && sizeof(inode->i_blocks) != sizeof(u64));
6893 + n = (void *)wh->d_name.name;
6894 + l = wh->d_name.len;
6897 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6898 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6900 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6901 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6902 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6903 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6904 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6905 + inode->i_state, inode->i_flags, inode->i_version,
6906 + inode->i_generation,
6907 + l ? ", wh " : "", l, n);
6911 +void au_dpri_inode(struct inode *inode)
6913 + struct au_iinfo *iinfo;
6914 + aufs_bindex_t bindex;
6917 + err = do_pri_inode(-1, inode, -1, NULL);
6918 + if (err || !au_test_aufs(inode->i_sb))
6921 + iinfo = au_ii(inode);
6924 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6925 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6926 + if (iinfo->ii_bstart < 0)
6929 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6930 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6931 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6932 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6936 +void au_dpri_dalias(struct inode *inode)
6940 + spin_lock(&inode->i_lock);
6941 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
6942 + au_dpri_dentry(d);
6943 + spin_unlock(&inode->i_lock);
6946 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6948 + struct dentry *wh = NULL;
6950 + struct au_iinfo *iinfo;
6952 + if (!dentry || IS_ERR(dentry)) {
6953 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6956 + /* do not call dget_parent() here */
6957 + /* note: access d_xxx without d_lock */
6958 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6959 + bindex, dentry, dentry,
6960 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6961 + au_dcount(dentry), dentry->d_flags,
6962 + d_unhashed(dentry) ? "un" : "");
6964 + if (bindex >= 0 && dentry->d_inode && au_test_aufs(dentry->d_sb)) {
6965 + iinfo = au_ii(dentry->d_inode);
6967 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6968 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
6971 + do_pri_inode(bindex, dentry->d_inode, hn, wh);
6975 +void au_dpri_dentry(struct dentry *dentry)
6977 + struct au_dinfo *dinfo;
6978 + aufs_bindex_t bindex;
6980 + struct au_hdentry *hdp;
6982 + err = do_pri_dentry(-1, dentry);
6983 + if (err || !au_test_aufs(dentry->d_sb))
6986 + dinfo = au_di(dentry);
6989 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
6990 + dinfo->di_bstart, dinfo->di_bend,
6991 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
6992 + dinfo->di_tmpfile);
6993 + if (dinfo->di_bstart < 0)
6995 + hdp = dinfo->di_hdentry;
6996 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
6997 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
7000 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7004 + if (!file || IS_ERR(file)) {
7005 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7010 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7011 + && au_test_aufs(file->f_path.dentry->d_sb)
7013 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7014 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7015 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7016 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7017 + file->f_version, file->f_pos, a);
7018 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7019 + do_pri_dentry(bindex, file->f_path.dentry);
7023 +void au_dpri_file(struct file *file)
7025 + struct au_finfo *finfo;
7026 + struct au_fidir *fidir;
7027 + struct au_hfile *hfile;
7028 + aufs_bindex_t bindex;
7031 + err = do_pri_file(-1, file);
7033 + || IS_ERR_OR_NULL(file->f_path.dentry)
7034 + || !au_test_aufs(file->f_path.dentry->d_sb))
7037 + finfo = au_fi(file);
7040 + if (finfo->fi_btop < 0)
7042 + fidir = finfo->fi_hdir;
7044 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7046 + for (bindex = finfo->fi_btop;
7047 + bindex >= 0 && bindex <= fidir->fd_bbot;
7049 + hfile = fidir->fd_hfile + bindex;
7050 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7054 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7056 + struct vfsmount *mnt;
7057 + struct super_block *sb;
7059 + if (!br || IS_ERR(br))
7061 + mnt = au_br_mnt(br);
7062 + if (!mnt || IS_ERR(mnt))
7065 + if (!sb || IS_ERR(sb))
7068 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
7069 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7071 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
7072 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7073 + sb->s_flags, sb->s_count,
7074 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7078 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7082 +void au_dpri_sb(struct super_block *sb)
7084 + struct au_sbinfo *sbinfo;
7085 + aufs_bindex_t bindex;
7087 + /* to reuduce stack size */
7089 + struct vfsmount mnt;
7090 + struct au_branch fake;
7093 + /* this function can be called from magic sysrq */
7094 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7095 + if (unlikely(!a)) {
7096 + dpri("no memory\n");
7100 + a->mnt.mnt_sb = sb;
7101 + a->fake.br_perm = 0;
7102 + a->fake.br_path.mnt = &a->mnt;
7103 + a->fake.br_xino.xi_file = NULL;
7104 + atomic_set(&a->fake.br_count, 0);
7105 + smp_mb(); /* atomic_set */
7106 + err = do_pri_br(-1, &a->fake);
7108 + dpri("dev 0x%x\n", sb->s_dev);
7109 + if (err || !au_test_aufs(sb))
7112 + sbinfo = au_sbi(sb);
7115 + dpri("nw %d, gen %u, kobj %d\n",
7116 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7117 + atomic_read(&sbinfo->si_kobj.kref.refcount));
7118 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
7119 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7122 +/* ---------------------------------------------------------------------- */
7124 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7126 + struct inode *h_inode, *inode = dentry->d_inode;
7127 + struct dentry *h_dentry;
7128 + aufs_bindex_t bindex, bend, bi;
7130 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7133 + bend = au_dbend(dentry);
7134 + bi = au_ibend(inode);
7137 + bindex = au_dbstart(dentry);
7138 + bi = au_ibstart(inode);
7142 + for (; bindex <= bend; bindex++) {
7143 + h_dentry = au_h_dptr(dentry, bindex);
7146 + h_inode = au_h_iptr(inode, bindex);
7147 + if (unlikely(h_inode != h_dentry->d_inode)) {
7149 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7150 + AuDbgDentry(dentry);
7151 + AuDbgInode(inode);
7158 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7161 + struct au_dcsub_pages dpages;
7162 + struct au_dpage *dpage;
7163 + struct dentry **dentries;
7165 + err = au_dpages_init(&dpages, GFP_NOFS);
7167 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7169 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7170 + dpage = dpages.dpages + i;
7171 + dentries = dpage->dentries;
7172 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7173 + AuDebugOn(au_digen_test(dentries[j], sigen));
7175 + au_dpages_free(&dpages);
7178 +void au_dbg_verify_kthread(void)
7180 + if (au_wkq_test()) {
7183 + * It may be recursive, but udba=notify between two aufs mounts,
7184 + * where a single ro branch is shared, is not a problem.
7190 +/* ---------------------------------------------------------------------- */
7192 +int __init au_debug_init(void)
7194 + aufs_bindex_t bindex;
7195 + struct au_vdir_destr destr;
7198 + AuDebugOn(bindex >= 0);
7201 + AuDebugOn(destr.len < NAME_MAX);
7203 +#ifdef CONFIG_4KSTACKS
7204 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7209 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7210 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7211 +++ linux/fs/aufs/debug.h 2015-06-22 08:27:37.877501704 +0200
7214 + * Copyright (C) 2005-2015 Junjiro R. Okajima
7216 + * This program, aufs is free software; you can redistribute it and/or modify
7217 + * it under the terms of the GNU General Public License as published by
7218 + * the Free Software Foundation; either version 2 of the License, or
7219 + * (at your option) any later version.
7221 + * This program is distributed in the hope that it will be useful,
7222 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7223 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7224 + * GNU General Public License for more details.
7226 + * You should have received a copy of the GNU General Public License
7227 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7231 + * debug print functions
7234 +#ifndef __AUFS_DEBUG_H__
7235 +#define __AUFS_DEBUG_H__
7239 +#include <linux/atomic.h>
7240 +#include <linux/module.h>
7241 +#include <linux/kallsyms.h>
7242 +#include <linux/sysrq.h>
7244 +#ifdef CONFIG_AUFS_DEBUG
7245 +#define AuDebugOn(a) BUG_ON(a)
7247 +/* module parameter */
7248 +extern atomic_t aufs_debug;
7249 +static inline void au_debug_on(void)
7251 + atomic_inc(&aufs_debug);
7253 +static inline void au_debug_off(void)
7255 + atomic_dec_if_positive(&aufs_debug);
7258 +static inline int au_debug_test(void)
7260 + return atomic_read(&aufs_debug) > 0;
7263 +#define AuDebugOn(a) do {} while (0)
7264 +AuStubVoid(au_debug_on, void)
7265 +AuStubVoid(au_debug_off, void)
7266 +AuStubInt0(au_debug_test, void)
7267 +#endif /* CONFIG_AUFS_DEBUG */
7269 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7271 +/* ---------------------------------------------------------------------- */
7275 +#define AuDbg(fmt, ...) do { \
7276 + if (au_debug_test()) \
7277 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7279 +#define AuLabel(l) AuDbg(#l "\n")
7280 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7281 +#define AuWarn1(fmt, ...) do { \
7282 + static unsigned char _c; \
7284 + pr_warn(fmt, ##__VA_ARGS__); \
7287 +#define AuErr1(fmt, ...) do { \
7288 + static unsigned char _c; \
7290 + pr_err(fmt, ##__VA_ARGS__); \
7293 +#define AuIOErr1(fmt, ...) do { \
7294 + static unsigned char _c; \
7296 + AuIOErr(fmt, ##__VA_ARGS__); \
7299 +#define AuUnsupportMsg "This operation is not supported." \
7300 + " Please report this application to aufs-users ML."
7301 +#define AuUnsupport(fmt, ...) do { \
7302 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7306 +#define AuTraceErr(e) do { \
7307 + if (unlikely((e) < 0)) \
7308 + AuDbg("err %d\n", (int)(e)); \
7311 +#define AuTraceErrPtr(p) do { \
7313 + AuDbg("err %ld\n", PTR_ERR(p)); \
7316 +/* dirty macros for debug print, use with "%.*s" and caution */
7317 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7319 +/* ---------------------------------------------------------------------- */
7322 +#ifdef CONFIG_AUFS_DEBUG
7323 +extern struct mutex au_dbg_mtx;
7324 +extern char *au_plevel;
7326 +void au_dpri_whlist(struct au_nhash *whlist);
7328 +void au_dpri_vdir(struct au_vdir *vdir);
7330 +void au_dpri_inode(struct inode *inode);
7331 +void au_dpri_dalias(struct inode *inode);
7332 +void au_dpri_dentry(struct dentry *dentry);
7334 +void au_dpri_file(struct file *filp);
7335 +struct super_block;
7336 +void au_dpri_sb(struct super_block *sb);
7338 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7339 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7340 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7341 +void au_dbg_verify_kthread(void);
7343 +int __init au_debug_init(void);
7345 +#define AuDbgWhlist(w) do { \
7346 + mutex_lock(&au_dbg_mtx); \
7348 + au_dpri_whlist(w); \
7349 + mutex_unlock(&au_dbg_mtx); \
7352 +#define AuDbgVdir(v) do { \
7353 + mutex_lock(&au_dbg_mtx); \
7355 + au_dpri_vdir(v); \
7356 + mutex_unlock(&au_dbg_mtx); \
7359 +#define AuDbgInode(i) do { \
7360 + mutex_lock(&au_dbg_mtx); \
7362 + au_dpri_inode(i); \
7363 + mutex_unlock(&au_dbg_mtx); \
7366 +#define AuDbgDAlias(i) do { \
7367 + mutex_lock(&au_dbg_mtx); \
7369 + au_dpri_dalias(i); \
7370 + mutex_unlock(&au_dbg_mtx); \
7373 +#define AuDbgDentry(d) do { \
7374 + mutex_lock(&au_dbg_mtx); \
7376 + au_dpri_dentry(d); \
7377 + mutex_unlock(&au_dbg_mtx); \
7380 +#define AuDbgFile(f) do { \
7381 + mutex_lock(&au_dbg_mtx); \
7383 + au_dpri_file(f); \
7384 + mutex_unlock(&au_dbg_mtx); \
7387 +#define AuDbgSb(sb) do { \
7388 + mutex_lock(&au_dbg_mtx); \
7389 + AuDbg(#sb "\n"); \
7391 + mutex_unlock(&au_dbg_mtx); \
7394 +#define AuDbgSym(addr) do { \
7395 + char sym[KSYM_SYMBOL_LEN]; \
7396 + sprint_symbol(sym, (unsigned long)addr); \
7397 + AuDbg("%s\n", sym); \
7400 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7401 +AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
7402 +AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
7403 + unsigned int sigen)
7404 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7405 +AuStubVoid(au_dbg_verify_kthread, void)
7406 +AuStubInt0(__init au_debug_init, void)
7408 +#define AuDbgWhlist(w) do {} while (0)
7409 +#define AuDbgVdir(v) do {} while (0)
7410 +#define AuDbgInode(i) do {} while (0)
7411 +#define AuDbgDAlias(i) do {} while (0)
7412 +#define AuDbgDentry(d) do {} while (0)
7413 +#define AuDbgFile(f) do {} while (0)
7414 +#define AuDbgSb(sb) do {} while (0)
7415 +#define AuDbgSym(addr) do {} while (0)
7416 +#endif /* CONFIG_AUFS_DEBUG */
7418 +/* ---------------------------------------------------------------------- */
7420 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7421 +int __init au_sysrq_init(void);
7422 +void au_sysrq_fin(void);
7424 +#ifdef CONFIG_HW_CONSOLE
7425 +#define au_dbg_blocked() do { \
7427 + handle_sysrq('w'); \
7430 +AuStubVoid(au_dbg_blocked, void)
7434 +AuStubInt0(__init au_sysrq_init, void)
7435 +AuStubVoid(au_sysrq_fin, void)
7436 +AuStubVoid(au_dbg_blocked, void)
7437 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7439 +#endif /* __KERNEL__ */
7440 +#endif /* __AUFS_DEBUG_H__ */
7441 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7442 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7443 +++ linux/fs/aufs/dentry.c 2015-06-22 08:27:37.877501704 +0200
7446 + * Copyright (C) 2005-2015 Junjiro R. Okajima
7448 + * This program, aufs is free software; you can redistribute it and/or modify
7449 + * it under the terms of the GNU General Public License as published by
7450 + * the Free Software Foundation; either version 2 of the License, or
7451 + * (at your option) any later version.
7453 + * This program is distributed in the hope that it will be useful,
7454 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7455 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7456 + * GNU General Public License for more details.
7458 + * You should have received a copy of the GNU General Public License
7459 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7463 + * lookup and dentry operations
7466 +#include <linux/namei.h>
7469 +#define AuLkup_ALLOW_NEG 1
7470 +#define AuLkup_IGNORE_PERM (1 << 1)
7471 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7472 +#define au_fset_lkup(flags, name) \
7473 + do { (flags) |= AuLkup_##name; } while (0)
7474 +#define au_fclr_lkup(flags, name) \
7475 + do { (flags) &= ~AuLkup_##name; } while (0)
7477 +struct au_do_lookup_args {
7478 + unsigned int flags;
7483 + * returns positive/negative dentry, NULL or an error.
7484 + * NULL means whiteout-ed or not-found.
7486 +static struct dentry*
7487 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7488 + aufs_bindex_t bindex, struct qstr *wh_name,
7489 + struct au_do_lookup_args *args)
7491 + struct dentry *h_dentry;
7492 + struct inode *h_inode;
7493 + struct au_branch *br;
7494 + int wh_found, opq;
7495 + unsigned char wh_able;
7496 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7497 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7501 + br = au_sbr(dentry->d_sb, bindex);
7502 + wh_able = !!au_br_whable(br->br_perm);
7504 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7505 + h_dentry = ERR_PTR(wh_found);
7508 + if (unlikely(wh_found < 0))
7511 + /* We found a whiteout */
7512 + /* au_set_dbend(dentry, bindex); */
7513 + au_set_dbwh(dentry, bindex);
7515 + return NULL; /* success */
7519 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7521 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7522 + if (IS_ERR(h_dentry)) {
7523 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7529 + h_inode = h_dentry->d_inode;
7533 + } else if (wh_found
7534 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7537 + if (au_dbend(dentry) <= bindex)
7538 + au_set_dbend(dentry, bindex);
7539 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7540 + au_set_dbstart(dentry, bindex);
7541 + au_set_h_dptr(dentry, bindex, h_dentry);
7543 + if (!d_is_dir(h_dentry)
7545 + || (d_is_positive(dentry) && !d_is_dir(dentry)))
7546 + goto out; /* success */
7548 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7549 + opq = au_diropq_test(h_dentry);
7550 + mutex_unlock(&h_inode->i_mutex);
7552 + au_set_dbdiropq(dentry, bindex);
7553 + else if (unlikely(opq < 0)) {
7554 + au_set_h_dptr(dentry, bindex, NULL);
7555 + h_dentry = ERR_PTR(opq);
7566 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7568 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7569 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7575 + * returns the number of lower positive dentries,
7576 + * otherwise an error.
7577 + * can be called at unlinking with @type is zero.
7579 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7581 + int npositive, err;
7582 + aufs_bindex_t bindex, btail, bdiropq;
7583 + unsigned char isdir, dirperm1;
7584 + struct qstr whname;
7585 + struct au_do_lookup_args args = {
7589 + const struct qstr *name = &dentry->d_name;
7590 + struct dentry *parent;
7591 + struct inode *inode;
7592 + struct super_block *sb;
7594 + sb = dentry->d_sb;
7595 + err = au_test_shwh(sb, name);
7596 + if (unlikely(err))
7599 + err = au_wh_name_alloc(&whname, name);
7600 + if (unlikely(err))
7603 + inode = dentry->d_inode;
7604 + isdir = !!d_is_dir(dentry);
7606 + au_fset_lkup(args.flags, ALLOW_NEG);
7607 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7610 + parent = dget_parent(dentry);
7611 + btail = au_dbtaildir(parent);
7612 + for (bindex = bstart; bindex <= btail; bindex++) {
7613 + struct dentry *h_parent, *h_dentry;
7614 + struct inode *h_inode, *h_dir;
7616 + h_dentry = au_h_dptr(dentry, bindex);
7618 + if (h_dentry->d_inode)
7620 + if (type != S_IFDIR)
7624 + h_parent = au_h_dptr(parent, bindex);
7625 + if (!h_parent || !d_is_dir(h_parent))
7628 + h_dir = h_parent->d_inode;
7629 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7630 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7632 + mutex_unlock(&h_dir->i_mutex);
7633 + err = PTR_ERR(h_dentry);
7634 + if (IS_ERR(h_dentry))
7637 + au_fclr_lkup(args.flags, ALLOW_NEG);
7639 + au_fset_lkup(args.flags, IGNORE_PERM);
7641 + if (au_dbwh(dentry) >= 0)
7645 + h_inode = h_dentry->d_inode;
7650 + args.type = h_inode->i_mode & S_IFMT;
7651 + if (args.type != S_IFDIR)
7654 + /* the type of lower may be different */
7655 + bdiropq = au_dbdiropq(dentry);
7656 + if (bdiropq >= 0 && bdiropq <= bindex)
7662 + AuLabel(positive);
7663 + au_update_dbstart(dentry);
7666 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7667 + && au_dbstart(dentry) < 0)) {
7669 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7675 + kfree(whname.name);
7680 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7682 + struct dentry *dentry;
7685 + if (!au_test_h_perm_sio(parent->d_inode, MAY_EXEC))
7686 + dentry = vfsub_lkup_one(name, parent);
7688 + struct vfsub_lkup_one_args args = {
7694 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7695 + if (unlikely(wkq_err))
7696 + dentry = ERR_PTR(wkq_err);
7703 + * lookup @dentry on @bindex which should be negative.
7705 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7708 + struct dentry *parent, *h_parent, *h_dentry;
7709 + struct au_branch *br;
7711 + parent = dget_parent(dentry);
7712 + h_parent = au_h_dptr(parent, bindex);
7713 + br = au_sbr(dentry->d_sb, bindex);
7715 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7717 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7718 + err = PTR_ERR(h_dentry);
7719 + if (IS_ERR(h_dentry))
7721 + if (unlikely(h_dentry->d_inode)) {
7723 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7729 + if (bindex < au_dbstart(dentry))
7730 + au_set_dbstart(dentry, bindex);
7731 + if (au_dbend(dentry) < bindex)
7732 + au_set_dbend(dentry, bindex);
7733 + au_set_h_dptr(dentry, bindex, h_dentry);
7740 +/* ---------------------------------------------------------------------- */
7742 +/* subset of struct inode */
7744 + unsigned long i_ino;
7745 + /* unsigned int i_nlink; */
7751 + blkcnt_t i_blocks;
7756 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7758 + ia->i_ino = h_inode->i_ino;
7759 + /* ia->i_nlink = h_inode->i_nlink; */
7760 + ia->i_uid = h_inode->i_uid;
7761 + ia->i_gid = h_inode->i_gid;
7762 + ia->i_version = h_inode->i_version;
7764 + ia->i_size = h_inode->i_size;
7765 + ia->i_blocks = h_inode->i_blocks;
7767 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7770 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7772 + return ia->i_ino != h_inode->i_ino
7773 + /* || ia->i_nlink != h_inode->i_nlink */
7774 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7775 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7776 + || ia->i_version != h_inode->i_version
7778 + || ia->i_size != h_inode->i_size
7779 + || ia->i_blocks != h_inode->i_blocks
7781 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7784 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7785 + struct au_branch *br)
7788 + struct au_iattr ia;
7789 + struct inode *h_inode;
7790 + struct dentry *h_d;
7791 + struct super_block *h_sb;
7794 + memset(&ia, -1, sizeof(ia));
7795 + h_sb = h_dentry->d_sb;
7796 + h_inode = h_dentry->d_inode;
7798 + au_iattr_save(&ia, h_inode);
7799 + else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7800 + /* nfs d_revalidate may return 0 for negative dentry */
7801 + /* fuse d_revalidate always return 0 for negative dentry */
7804 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7805 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7806 + err = PTR_ERR(h_d);
7811 + if (unlikely(h_d != h_dentry
7812 + || h_d->d_inode != h_inode
7813 + || (h_inode && au_iattr_test(&ia, h_inode))))
7814 + err = au_busy_or_stale();
7822 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7823 + struct dentry *h_parent, struct au_branch *br)
7828 + if (udba == AuOpt_UDBA_REVAL
7829 + && !au_test_fs_remote(h_dentry->d_sb)) {
7831 + err = (h_dentry->d_parent->d_inode != h_dir);
7832 + } else if (udba != AuOpt_UDBA_NONE)
7833 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7838 +/* ---------------------------------------------------------------------- */
7840 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7843 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7844 + struct au_hdentry tmp, *p, *q;
7845 + struct au_dinfo *dinfo;
7846 + struct super_block *sb;
7848 + DiMustWriteLock(dentry);
7850 + sb = dentry->d_sb;
7851 + dinfo = au_di(dentry);
7852 + bend = dinfo->di_bend;
7853 + bwh = dinfo->di_bwh;
7854 + bdiropq = dinfo->di_bdiropq;
7855 + p = dinfo->di_hdentry + dinfo->di_bstart;
7856 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7857 + if (!p->hd_dentry)
7860 + new_bindex = au_br_index(sb, p->hd_id);
7861 + if (new_bindex == bindex)
7864 + if (dinfo->di_bwh == bindex)
7866 + if (dinfo->di_bdiropq == bindex)
7867 + bdiropq = new_bindex;
7868 + if (new_bindex < 0) {
7870 + p->hd_dentry = NULL;
7874 + /* swap two lower dentries, and loop again */
7875 + q = dinfo->di_hdentry + new_bindex;
7879 + if (tmp.hd_dentry) {
7885 + dinfo->di_bwh = -1;
7886 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7887 + dinfo->di_bwh = bwh;
7889 + dinfo->di_bdiropq = -1;
7891 + && bdiropq <= au_sbend(sb)
7892 + && au_sbr_whable(sb, bdiropq))
7893 + dinfo->di_bdiropq = bdiropq;
7896 + dinfo->di_bstart = -1;
7897 + dinfo->di_bend = -1;
7898 + bend = au_dbend(parent);
7899 + p = dinfo->di_hdentry;
7900 + for (bindex = 0; bindex <= bend; bindex++, p++)
7901 + if (p->hd_dentry) {
7902 + dinfo->di_bstart = bindex;
7906 + if (dinfo->di_bstart >= 0) {
7907 + p = dinfo->di_hdentry + bend;
7908 + for (bindex = bend; bindex >= 0; bindex--, p--)
7909 + if (p->hd_dentry) {
7910 + dinfo->di_bend = bindex;
7919 +static void au_do_hide(struct dentry *dentry)
7921 + struct inode *inode;
7923 + inode = dentry->d_inode;
7925 + if (!S_ISDIR(inode->i_mode)) {
7926 + if (inode->i_nlink && !d_unhashed(dentry))
7927 + drop_nlink(inode);
7929 + clear_nlink(inode);
7930 + /* stop next lookup */
7931 + inode->i_flags |= S_DEAD;
7933 + smp_mb(); /* necessary? */
7938 +static int au_hide_children(struct dentry *parent)
7940 + int err, i, j, ndentry;
7941 + struct au_dcsub_pages dpages;
7942 + struct au_dpage *dpage;
7943 + struct dentry *dentry;
7945 + err = au_dpages_init(&dpages, GFP_NOFS);
7946 + if (unlikely(err))
7948 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7949 + if (unlikely(err))
7952 + /* in reverse order */
7953 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7954 + dpage = dpages.dpages + i;
7955 + ndentry = dpage->ndentry;
7956 + for (j = ndentry - 1; j >= 0; j--) {
7957 + dentry = dpage->dentries[j];
7958 + if (dentry != parent)
7959 + au_do_hide(dentry);
7964 + au_dpages_free(&dpages);
7969 +static void au_hide(struct dentry *dentry)
7973 + AuDbgDentry(dentry);
7974 + if (d_is_dir(dentry)) {
7975 + /* shrink_dcache_parent(dentry); */
7976 + err = au_hide_children(dentry);
7977 + if (unlikely(err))
7978 + AuIOErr("%pd, failed hiding children, ignored %d\n",
7981 + au_do_hide(dentry);
7985 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7987 + * a dirty branch is added
7988 + * - on the top of layers
7989 + * - in the middle of layers
7990 + * - to the bottom of layers
7992 + * on the added branch there exists
7995 + * - a same named entry
7997 + * * negative --> positive
7998 + * * positive --> positive
7999 + * - type is unchanged
8000 + * - type is changed
8002 + * * negative --> negative
8003 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8006 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8007 + struct au_dinfo *tmp)
8010 + aufs_bindex_t bindex, bend;
8012 + struct dentry *dentry;
8013 + struct inode *inode;
8016 + struct au_hdentry *hd;
8017 + struct inode *inode, *h_inode;
8018 + struct dentry *h_dentry;
8021 + AuDebugOn(dinfo->di_bstart < 0);
8022 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
8023 + orig_h.inode = orig_h.dentry->d_inode;
8026 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8027 + memset(&tmp_h, 0, sizeof(tmp_h));
8028 + if (tmp->di_bstart >= 0) {
8029 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
8030 + tmp_h.inode = tmp_h.dentry->d_inode;
8032 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8035 + inode = dentry->d_inode;
8036 + if (!orig_h.inode) {
8037 + AuDbg("nagative originally\n");
8043 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8044 + AuDebugOn(dinfo->di_bdiropq != -1);
8046 + if (!tmp_h.inode) {
8047 + AuDbg("negative --> negative\n");
8048 + /* should have only one negative lower */
8049 + if (tmp->di_bstart >= 0
8050 + && tmp->di_bstart < dinfo->di_bstart) {
8051 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
8052 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8053 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
8054 + au_di_cp(dinfo, tmp);
8055 + hd = tmp->di_hdentry + tmp->di_bstart;
8056 + au_set_h_dptr(dentry, tmp->di_bstart,
8057 + dget(hd->hd_dentry));
8059 + au_dbg_verify_dinode(dentry);
8061 + AuDbg("negative --> positive\n");
8063 + * similar to the behaviour of creating with bypassing
8065 + * unhash it in order to force an error in the
8066 + * succeeding create operation.
8067 + * we should not set S_DEAD here.
8070 + /* au_di_swap(tmp, dinfo); */
8071 + au_dbg_verify_dinode(dentry);
8074 + AuDbg("positive originally\n");
8075 + /* inode may be NULL */
8076 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8077 + if (!tmp_h.inode) {
8078 + AuDbg("positive --> negative\n");
8079 + /* or bypassing aufs */
8081 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
8082 + dinfo->di_bwh = tmp->di_bwh;
8084 + err = au_refresh_hinode_self(inode);
8085 + au_dbg_verify_dinode(dentry);
8086 + } else if (orig_h.mode == tmp_h.mode) {
8087 + AuDbg("positive --> positive, same type\n");
8088 + if (!S_ISDIR(orig_h.mode)
8089 + && dinfo->di_bstart > tmp->di_bstart) {
8091 + * similar to the behaviour of removing and
8096 + err = au_refresh_hinode_self(inode);
8097 + au_dbg_verify_dinode(dentry);
8099 + /* fill empty slots */
8100 + if (dinfo->di_bstart > tmp->di_bstart)
8101 + dinfo->di_bstart = tmp->di_bstart;
8102 + if (dinfo->di_bend < tmp->di_bend)
8103 + dinfo->di_bend = tmp->di_bend;
8104 + dinfo->di_bwh = tmp->di_bwh;
8105 + dinfo->di_bdiropq = tmp->di_bdiropq;
8106 + hd = tmp->di_hdentry;
8107 + bend = dinfo->di_bend;
8108 + for (bindex = tmp->di_bstart; bindex <= bend;
8110 + if (au_h_dptr(dentry, bindex))
8112 + h_dentry = hd[bindex].hd_dentry;
8115 + h_inode = h_dentry->d_inode;
8116 + AuDebugOn(!h_inode);
8117 + AuDebugOn(orig_h.mode
8118 + != (h_inode->i_mode
8120 + au_set_h_dptr(dentry, bindex,
8123 + err = au_refresh_hinode(inode, dentry);
8124 + au_dbg_verify_dinode(dentry);
8127 + AuDbg("positive --> positive, different type\n");
8128 + /* similar to the behaviour of removing and creating */
8131 + err = au_refresh_hinode_self(inode);
8132 + au_dbg_verify_dinode(dentry);
8140 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8143 + unsigned int sigen;
8144 + struct au_dinfo *dinfo, *tmp;
8145 + struct super_block *sb;
8146 + struct inode *inode;
8148 + DiMustWriteLock(dentry);
8149 + AuDebugOn(IS_ROOT(dentry));
8150 + AuDebugOn(!parent->d_inode);
8152 + sb = dentry->d_sb;
8153 + inode = dentry->d_inode;
8154 + sigen = au_sigen(sb);
8155 + err = au_digen_test(parent, sigen);
8156 + if (unlikely(err))
8159 + dinfo = au_di(dentry);
8160 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
8161 + if (unlikely(err))
8163 + ebrange = au_dbrange_test(dentry);
8165 + ebrange = au_do_refresh_hdentry(dentry, parent);
8167 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8168 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
8170 + err = au_refresh_hinode_self(inode);
8171 + au_dbg_verify_dinode(dentry);
8173 + goto out_dgen; /* success */
8177 + /* temporary dinfo */
8178 + AuDbgDentry(dentry);
8180 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8181 + if (unlikely(!tmp))
8183 + au_di_swap(tmp, dinfo);
8184 + /* returns the number of positive dentries */
8186 + * if current working dir is removed, it returns an error.
8187 + * but the dentry is legal.
8189 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
8190 + AuDbgDentry(dentry);
8191 + au_di_swap(tmp, dinfo);
8192 + if (err == -ENOENT)
8195 + /* compare/refresh by dinfo */
8196 + AuDbgDentry(dentry);
8197 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8198 + au_dbg_verify_dinode(dentry);
8201 + au_rw_write_unlock(&tmp->di_rwsem);
8203 + if (unlikely(err))
8207 + au_update_digen(dentry);
8209 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8210 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8211 + AuDbgDentry(dentry);
8217 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8218 + struct dentry *dentry, aufs_bindex_t bindex)
8223 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8226 + AuDbg("b%d\n", bindex);
8228 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8229 + * due to whiteout and branch permission.
8231 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8232 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8233 + /* it may return tri-state */
8234 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8236 + if (unlikely(valid < 0))
8246 +/* todo: remove this */
8247 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8248 + unsigned int flags, int do_udba)
8251 + umode_t mode, h_mode;
8252 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
8253 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8254 + struct inode *h_inode, *h_cached_inode;
8255 + struct dentry *h_dentry;
8256 + struct qstr *name, *h_name;
8263 + unhashed = !!d_unhashed(dentry);
8264 + is_root = !!IS_ROOT(dentry);
8265 + name = &dentry->d_name;
8266 + tmpfile = au_di(dentry)->di_tmpfile;
8269 + * Theoretically, REVAL test should be unnecessary in case of
8271 + * But {fs,i}notify doesn't fire some necessary events,
8272 + * IN_ATTRIB for atime/nlink/pageio
8273 + * Let's do REVAL test too.
8275 + if (do_udba && inode) {
8276 + mode = (inode->i_mode & S_IFMT);
8277 + plus = (inode->i_nlink > 0);
8278 + ibs = au_ibstart(inode);
8279 + ibe = au_ibend(inode);
8282 + bstart = au_dbstart(dentry);
8284 + if (inode && S_ISDIR(inode->i_mode))
8285 + btail = au_dbtaildir(dentry);
8286 + for (bindex = bstart; bindex <= btail; bindex++) {
8287 + h_dentry = au_h_dptr(dentry, bindex);
8291 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8292 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8293 + spin_lock(&h_dentry->d_lock);
8294 + h_name = &h_dentry->d_name;
8295 + if (unlikely(do_udba
8298 + && (unhashed != !!d_unhashed(h_dentry)
8300 + && !au_qstreq(name, h_name))
8303 + && !(flags & LOOKUP_OPEN)
8304 + && (h_dentry->d_flags
8305 + & DCACHE_NFSFS_RENAMED)))
8309 + h_unhashed = d_unhashed(h_dentry);
8310 + spin_unlock(&h_dentry->d_lock);
8311 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8312 + unhashed, h_unhashed, dentry, h_dentry);
8315 + spin_unlock(&h_dentry->d_lock);
8317 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8318 + if (unlikely(err))
8319 + /* do not goto err, to keep the errno */
8322 + /* todo: plink too? */
8327 + h_inode = h_dentry->d_inode;
8328 + if (unlikely(!!inode != !!h_inode))
8333 + h_cached_inode = h_inode;
8335 + h_mode = (h_inode->i_mode & S_IFMT);
8336 + h_plus = (h_inode->i_nlink > 0);
8338 + if (inode && ibs <= bindex && bindex <= ibe)
8339 + h_cached_inode = au_h_iptr(inode, bindex);
8342 + if (unlikely(plus != h_plus && !tmpfile))
8345 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8347 + && !IS_ROOT(h_dentry)
8348 + && unhashed != d_unhashed(h_dentry)))
8351 + if (unlikely(mode != h_mode
8352 + || h_cached_inode != h_inode))
8365 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8366 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8369 + struct dentry *parent;
8371 + if (!au_digen_test(dentry, sigen))
8374 + parent = dget_parent(dentry);
8375 + di_read_lock_parent(parent, AuLock_IR);
8376 + AuDebugOn(au_digen_test(parent, sigen));
8377 + au_dbg_verify_gen(parent, sigen);
8378 + err = au_refresh_dentry(dentry, parent);
8379 + di_read_unlock(parent, AuLock_IR);
8385 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8388 + struct dentry *d, *parent;
8389 + struct inode *inode;
8391 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8392 + return simple_reval_dpath(dentry, sigen);
8394 + /* slow loop, keep it simple and stupid */
8395 + /* cf: au_cpup_dirs() */
8398 + while (au_digen_test(dentry, sigen)) {
8402 + parent = dget_parent(d);
8403 + if (!au_digen_test(parent, sigen))
8408 + inode = d->d_inode;
8410 + di_write_lock_child2(d);
8412 + /* someone might update our dentry while we were sleeping */
8413 + if (au_digen_test(d, sigen)) {
8415 + * todo: consolidate with simple_reval_dpath(),
8416 + * do_refresh() and au_reval_for_attr().
8418 + di_read_lock_parent(parent, AuLock_IR);
8419 + err = au_refresh_dentry(d, parent);
8420 + di_read_unlock(parent, AuLock_IR);
8424 + di_write_unlock(d);
8426 + if (unlikely(err))
8434 + * if valid returns 1, otherwise 0.
8436 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8439 + unsigned int sigen;
8440 + unsigned char do_udba;
8441 + struct super_block *sb;
8442 + struct inode *inode;
8444 + /* todo: support rcu-walk? */
8445 + if (flags & LOOKUP_RCU)
8449 + if (unlikely(!au_di(dentry)))
8453 + sb = dentry->d_sb;
8456 + * i_mutex of parent dir may be held,
8457 + * but we should not return 'invalid' due to busy.
8459 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8460 + if (unlikely(err)) {
8465 + inode = dentry->d_inode;
8466 + if (unlikely(inode && is_bad_inode(inode))) {
8471 + if (unlikely(au_dbrange_test(dentry))) {
8477 + sigen = au_sigen(sb);
8478 + if (au_digen_test(dentry, sigen)) {
8479 + AuDebugOn(IS_ROOT(dentry));
8480 + err = au_reval_dpath(dentry, sigen);
8481 + if (unlikely(err)) {
8486 + di_downgrade_lock(dentry, AuLock_IR);
8489 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8491 + && !(inode->i_state && I_LINKABLE)
8492 + && (IS_DEADDIR(inode) || !inode->i_nlink))
8495 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8496 + if (do_udba && inode) {
8497 + aufs_bindex_t bstart = au_ibstart(inode);
8498 + struct inode *h_inode;
8500 + if (bstart >= 0) {
8501 + h_inode = au_h_iptr(inode, bstart);
8502 + if (h_inode && au_test_higen(inode, h_inode))
8507 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8508 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8510 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8516 + di_downgrade_lock(dentry, AuLock_IR);
8518 + aufs_read_unlock(dentry, AuLock_IR);
8523 + AuDbg("%pd invalid, %d\n", dentry, valid);
8529 +static void aufs_d_release(struct dentry *dentry)
8531 + if (au_di(dentry)) {
8532 + au_di_fin(dentry);
8533 + au_hn_di_reinit(dentry);
8537 +const struct dentry_operations aufs_dop = {
8538 + .d_revalidate = aufs_d_revalidate,
8539 + .d_weak_revalidate = aufs_d_revalidate,
8540 + .d_release = aufs_d_release
8542 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8543 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8544 +++ linux/fs/aufs/dentry.h 2015-06-22 08:27:37.877501704 +0200
8547 + * Copyright (C) 2005-2015 Junjiro R. Okajima
8549 + * This program, aufs is free software; you can redistribute it and/or modify
8550 + * it under the terms of the GNU General Public License as published by
8551 + * the Free Software Foundation; either version 2 of the License, or
8552 + * (at your option) any later version.
8554 + * This program is distributed in the hope that it will be useful,
8555 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8556 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8557 + * GNU General Public License for more details.
8559 + * You should have received a copy of the GNU General Public License
8560 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8564 + * lookup and dentry operations
8567 +#ifndef __AUFS_DENTRY_H__
8568 +#define __AUFS_DENTRY_H__
8572 +#include <linux/dcache.h>
8575 +struct au_hdentry {
8576 + struct dentry *hd_dentry;
8577 + aufs_bindex_t hd_id;
8581 + atomic_t di_generation;
8583 + struct au_rwsem di_rwsem;
8584 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8585 + unsigned char di_tmpfile; /* to allow the different name */
8586 + struct au_hdentry *di_hdentry;
8587 +} ____cacheline_aligned_in_smp;
8589 +/* ---------------------------------------------------------------------- */
8592 +extern const struct dentry_operations aufs_dop;
8594 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8595 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8596 + struct dentry *h_parent, struct au_branch *br);
8598 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8599 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8600 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8601 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8604 +void au_di_init_once(void *_di);
8605 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8606 +void au_di_free(struct au_dinfo *dinfo);
8607 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8608 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8609 +int au_di_init(struct dentry *dentry);
8610 +void au_di_fin(struct dentry *dentry);
8611 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8613 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8614 +void di_read_unlock(struct dentry *d, int flags);
8615 +void di_downgrade_lock(struct dentry *d, int flags);
8616 +void di_write_lock(struct dentry *d, unsigned int lsc);
8617 +void di_write_unlock(struct dentry *d);
8618 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8619 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8620 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8622 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8623 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8624 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8625 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8627 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8628 + struct dentry *h_dentry);
8629 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8630 +int au_dbrange_test(struct dentry *dentry);
8631 +void au_update_digen(struct dentry *dentry);
8632 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8633 +void au_update_dbstart(struct dentry *dentry);
8634 +void au_update_dbend(struct dentry *dentry);
8635 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8637 +/* ---------------------------------------------------------------------- */
8639 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8641 + return dentry->d_fsdata;
8644 +/* ---------------------------------------------------------------------- */
8646 +/* lock subclass for dinfo */
8648 + AuLsc_DI_CHILD, /* child first */
8649 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8650 + AuLsc_DI_CHILD3, /* copyup dirs */
8654 + AuLsc_DI_TMP /* temp for replacing dinfo */
8658 + * di_read_lock_child, di_write_lock_child,
8659 + * di_read_lock_child2, di_write_lock_child2,
8660 + * di_read_lock_child3, di_write_lock_child3,
8661 + * di_read_lock_parent, di_write_lock_parent,
8662 + * di_read_lock_parent2, di_write_lock_parent2,
8663 + * di_read_lock_parent3, di_write_lock_parent3,
8665 +#define AuReadLockFunc(name, lsc) \
8666 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8667 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8669 +#define AuWriteLockFunc(name, lsc) \
8670 +static inline void di_write_lock_##name(struct dentry *d) \
8671 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8673 +#define AuRWLockFuncs(name, lsc) \
8674 + AuReadLockFunc(name, lsc) \
8675 + AuWriteLockFunc(name, lsc)
8677 +AuRWLockFuncs(child, CHILD);
8678 +AuRWLockFuncs(child2, CHILD2);
8679 +AuRWLockFuncs(child3, CHILD3);
8680 +AuRWLockFuncs(parent, PARENT);
8681 +AuRWLockFuncs(parent2, PARENT2);
8682 +AuRWLockFuncs(parent3, PARENT3);
8684 +#undef AuReadLockFunc
8685 +#undef AuWriteLockFunc
8686 +#undef AuRWLockFuncs
8688 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8689 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8690 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8692 +/* ---------------------------------------------------------------------- */
8694 +/* todo: memory barrier? */
8695 +static inline unsigned int au_digen(struct dentry *d)
8697 + return atomic_read(&au_di(d)->di_generation);
8700 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8702 + hdentry->hd_dentry = NULL;
8705 +static inline void au_hdput(struct au_hdentry *hd)
8708 + dput(hd->hd_dentry);
8711 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8713 + DiMustAnyLock(dentry);
8714 + return au_di(dentry)->di_bstart;
8717 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8719 + DiMustAnyLock(dentry);
8720 + return au_di(dentry)->di_bend;
8723 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8725 + DiMustAnyLock(dentry);
8726 + return au_di(dentry)->di_bwh;
8729 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8731 + DiMustAnyLock(dentry);
8732 + return au_di(dentry)->di_bdiropq;
8735 +/* todo: hard/soft set? */
8736 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8738 + DiMustWriteLock(dentry);
8739 + au_di(dentry)->di_bstart = bindex;
8742 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8744 + DiMustWriteLock(dentry);
8745 + au_di(dentry)->di_bend = bindex;
8748 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8750 + DiMustWriteLock(dentry);
8751 + /* dbwh can be outside of bstart - bend range */
8752 + au_di(dentry)->di_bwh = bindex;
8755 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8757 + DiMustWriteLock(dentry);
8758 + au_di(dentry)->di_bdiropq = bindex;
8761 +/* ---------------------------------------------------------------------- */
8763 +#ifdef CONFIG_AUFS_HNOTIFY
8764 +static inline void au_digen_dec(struct dentry *d)
8766 + atomic_dec(&au_di(d)->di_generation);
8769 +static inline void au_hn_di_reinit(struct dentry *dentry)
8771 + dentry->d_fsdata = NULL;
8774 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8775 +#endif /* CONFIG_AUFS_HNOTIFY */
8777 +#endif /* __KERNEL__ */
8778 +#endif /* __AUFS_DENTRY_H__ */
8779 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8780 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8781 +++ linux/fs/aufs/dinfo.c 2015-06-22 08:27:37.877501704 +0200
8784 + * Copyright (C) 2005-2015 Junjiro R. Okajima
8786 + * This program, aufs is free software; you can redistribute it and/or modify
8787 + * it under the terms of the GNU General Public License as published by
8788 + * the Free Software Foundation; either version 2 of the License, or
8789 + * (at your option) any later version.
8791 + * This program is distributed in the hope that it will be useful,
8792 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8793 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8794 + * GNU General Public License for more details.
8796 + * You should have received a copy of the GNU General Public License
8797 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8801 + * dentry private data
8806 +void au_di_init_once(void *_dinfo)
8808 + struct au_dinfo *dinfo = _dinfo;
8809 + static struct lock_class_key aufs_di;
8811 + au_rw_init(&dinfo->di_rwsem);
8812 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8815 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8817 + struct au_dinfo *dinfo;
8820 + dinfo = au_cache_alloc_dinfo();
8821 + if (unlikely(!dinfo))
8824 + nbr = au_sbend(sb) + 1;
8827 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8828 + if (dinfo->di_hdentry) {
8829 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8830 + dinfo->di_bstart = -1;
8831 + dinfo->di_bend = -1;
8832 + dinfo->di_bwh = -1;
8833 + dinfo->di_bdiropq = -1;
8834 + dinfo->di_tmpfile = 0;
8835 + for (i = 0; i < nbr; i++)
8836 + dinfo->di_hdentry[i].hd_id = -1;
8840 + au_cache_free_dinfo(dinfo);
8847 +void au_di_free(struct au_dinfo *dinfo)
8849 + struct au_hdentry *p;
8850 + aufs_bindex_t bend, bindex;
8852 + /* dentry may not be revalidated */
8853 + bindex = dinfo->di_bstart;
8854 + if (bindex >= 0) {
8855 + bend = dinfo->di_bend;
8856 + p = dinfo->di_hdentry + bindex;
8857 + while (bindex++ <= bend)
8860 + kfree(dinfo->di_hdentry);
8861 + au_cache_free_dinfo(dinfo);
8864 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8866 + struct au_hdentry *p;
8869 + AuRwMustWriteLock(&a->di_rwsem);
8870 + AuRwMustWriteLock(&b->di_rwsem);
8872 +#define DiSwap(v, name) \
8874 + v = a->di_##name; \
8875 + a->di_##name = b->di_##name; \
8876 + b->di_##name = v; \
8879 + DiSwap(p, hdentry);
8880 + DiSwap(bi, bstart);
8883 + DiSwap(bi, bdiropq);
8889 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8891 + AuRwMustWriteLock(&dst->di_rwsem);
8892 + AuRwMustWriteLock(&src->di_rwsem);
8894 + dst->di_bstart = src->di_bstart;
8895 + dst->di_bend = src->di_bend;
8896 + dst->di_bwh = src->di_bwh;
8897 + dst->di_bdiropq = src->di_bdiropq;
8901 +int au_di_init(struct dentry *dentry)
8904 + struct super_block *sb;
8905 + struct au_dinfo *dinfo;
8908 + sb = dentry->d_sb;
8909 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8911 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8912 + /* smp_mb(); */ /* atomic_set */
8913 + dentry->d_fsdata = dinfo;
8920 +void au_di_fin(struct dentry *dentry)
8922 + struct au_dinfo *dinfo;
8924 + dinfo = au_di(dentry);
8925 + AuRwDestroy(&dinfo->di_rwsem);
8926 + au_di_free(dinfo);
8929 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8932 + struct au_hdentry *hdp;
8934 + AuRwMustWriteLock(&dinfo->di_rwsem);
8937 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8939 + sz = sizeof(*hdp);
8940 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8942 + dinfo->di_hdentry = hdp;
8949 +/* ---------------------------------------------------------------------- */
8951 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8954 + case AuLsc_DI_CHILD:
8955 + ii_write_lock_child(inode);
8957 + case AuLsc_DI_CHILD2:
8958 + ii_write_lock_child2(inode);
8960 + case AuLsc_DI_CHILD3:
8961 + ii_write_lock_child3(inode);
8963 + case AuLsc_DI_PARENT:
8964 + ii_write_lock_parent(inode);
8966 + case AuLsc_DI_PARENT2:
8967 + ii_write_lock_parent2(inode);
8969 + case AuLsc_DI_PARENT3:
8970 + ii_write_lock_parent3(inode);
8977 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
8980 + case AuLsc_DI_CHILD:
8981 + ii_read_lock_child(inode);
8983 + case AuLsc_DI_CHILD2:
8984 + ii_read_lock_child2(inode);
8986 + case AuLsc_DI_CHILD3:
8987 + ii_read_lock_child3(inode);
8989 + case AuLsc_DI_PARENT:
8990 + ii_read_lock_parent(inode);
8992 + case AuLsc_DI_PARENT2:
8993 + ii_read_lock_parent2(inode);
8995 + case AuLsc_DI_PARENT3:
8996 + ii_read_lock_parent3(inode);
9003 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9005 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9007 + if (au_ftest_lock(flags, IW))
9008 + do_ii_write_lock(d->d_inode, lsc);
9009 + else if (au_ftest_lock(flags, IR))
9010 + do_ii_read_lock(d->d_inode, lsc);
9014 +void di_read_unlock(struct dentry *d, int flags)
9017 + if (au_ftest_lock(flags, IW)) {
9018 + au_dbg_verify_dinode(d);
9019 + ii_write_unlock(d->d_inode);
9020 + } else if (au_ftest_lock(flags, IR)) {
9021 + au_dbg_verify_dinode(d);
9022 + ii_read_unlock(d->d_inode);
9025 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9028 +void di_downgrade_lock(struct dentry *d, int flags)
9030 + if (d->d_inode && au_ftest_lock(flags, IR))
9031 + ii_downgrade_lock(d->d_inode);
9032 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9035 +void di_write_lock(struct dentry *d, unsigned int lsc)
9037 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9039 + do_ii_write_lock(d->d_inode, lsc);
9042 +void di_write_unlock(struct dentry *d)
9044 + au_dbg_verify_dinode(d);
9046 + ii_write_unlock(d->d_inode);
9047 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9050 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9052 + AuDebugOn(d1 == d2
9053 + || d1->d_inode == d2->d_inode
9054 + || d1->d_sb != d2->d_sb);
9056 + if (isdir && au_test_subdir(d1, d2)) {
9057 + di_write_lock_child(d1);
9058 + di_write_lock_child2(d2);
9060 + /* there should be no races */
9061 + di_write_lock_child(d2);
9062 + di_write_lock_child2(d1);
9066 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9068 + AuDebugOn(d1 == d2
9069 + || d1->d_inode == d2->d_inode
9070 + || d1->d_sb != d2->d_sb);
9072 + if (isdir && au_test_subdir(d1, d2)) {
9073 + di_write_lock_parent(d1);
9074 + di_write_lock_parent2(d2);
9076 + /* there should be no races */
9077 + di_write_lock_parent(d2);
9078 + di_write_lock_parent2(d1);
9082 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9084 + di_write_unlock(d1);
9085 + if (d1->d_inode == d2->d_inode)
9086 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9088 + di_write_unlock(d2);
9091 +/* ---------------------------------------------------------------------- */
9093 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9097 + DiMustAnyLock(dentry);
9099 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
9101 + AuDebugOn(bindex < 0);
9102 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
9103 + AuDebugOn(d && au_dcount(d) <= 0);
9108 + * extended version of au_h_dptr().
9109 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9112 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9114 + struct dentry *h_dentry;
9115 + struct inode *inode, *h_inode;
9117 + inode = dentry->d_inode;
9118 + AuDebugOn(!inode);
9121 + if (au_dbstart(dentry) <= bindex
9122 + && bindex <= au_dbend(dentry))
9123 + h_dentry = au_h_dptr(dentry, bindex);
9124 + if (h_dentry && !au_d_linkable(h_dentry)) {
9126 + goto out; /* success */
9129 + AuDebugOn(bindex < au_ibstart(inode));
9130 + AuDebugOn(au_ibend(inode) < bindex);
9131 + h_inode = au_h_iptr(inode, bindex);
9132 + h_dentry = d_find_alias(h_inode);
9134 + if (!IS_ERR(h_dentry)) {
9135 + if (!au_d_linkable(h_dentry))
9136 + goto out; /* success */
9142 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9143 + h_dentry = au_plink_lkup(inode, bindex);
9144 + AuDebugOn(!h_dentry);
9145 + if (!IS_ERR(h_dentry)) {
9146 + if (!au_d_hashed_positive(h_dentry))
9147 + goto out; /* success */
9154 + AuDbgDentry(h_dentry);
9158 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9160 + aufs_bindex_t bend, bwh;
9162 + bend = au_dbend(dentry);
9164 + bwh = au_dbwh(dentry);
9167 + if (0 < bwh && bwh < bend)
9173 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9175 + aufs_bindex_t bend, bopq;
9177 + bend = au_dbtail(dentry);
9179 + bopq = au_dbdiropq(dentry);
9180 + if (0 <= bopq && bopq < bend)
9186 +/* ---------------------------------------------------------------------- */
9188 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9189 + struct dentry *h_dentry)
9191 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
9192 + struct au_branch *br;
9194 + DiMustWriteLock(dentry);
9197 + hd->hd_dentry = h_dentry;
9199 + br = au_sbr(dentry->d_sb, bindex);
9200 + hd->hd_id = br->br_id;
9204 +int au_dbrange_test(struct dentry *dentry)
9207 + aufs_bindex_t bstart, bend;
9210 + bstart = au_dbstart(dentry);
9211 + bend = au_dbend(dentry);
9213 + AuDebugOn(bend < 0 && bstart > bend);
9216 + AuDebugOn(bend >= 0);
9222 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9227 + if (unlikely(au_digen(dentry) != sigen
9228 + || au_iigen_test(dentry->d_inode, sigen)))
9234 +void au_update_digen(struct dentry *dentry)
9236 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9237 + /* smp_mb(); */ /* atomic_set */
9240 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9242 + struct au_dinfo *dinfo;
9243 + struct dentry *h_d;
9244 + struct au_hdentry *hdp;
9246 + DiMustWriteLock(dentry);
9248 + dinfo = au_di(dentry);
9249 + if (!dinfo || dinfo->di_bstart < 0)
9252 + hdp = dinfo->di_hdentry;
9253 + if (do_put_zero) {
9254 + aufs_bindex_t bindex, bend;
9256 + bend = dinfo->di_bend;
9257 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
9258 + h_d = hdp[0 + bindex].hd_dentry;
9259 + if (h_d && !h_d->d_inode)
9260 + au_set_h_dptr(dentry, bindex, NULL);
9264 + dinfo->di_bstart = -1;
9265 + while (++dinfo->di_bstart <= dinfo->di_bend)
9266 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
9268 + if (dinfo->di_bstart > dinfo->di_bend) {
9269 + dinfo->di_bstart = -1;
9270 + dinfo->di_bend = -1;
9275 + while (0 <= --dinfo->di_bend)
9276 + if (hdp[0 + dinfo->di_bend].hd_dentry)
9278 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
9281 +void au_update_dbstart(struct dentry *dentry)
9283 + aufs_bindex_t bindex, bend;
9284 + struct dentry *h_dentry;
9286 + bend = au_dbend(dentry);
9287 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
9288 + h_dentry = au_h_dptr(dentry, bindex);
9291 + if (h_dentry->d_inode) {
9292 + au_set_dbstart(dentry, bindex);
9295 + au_set_h_dptr(dentry, bindex, NULL);
9299 +void au_update_dbend(struct dentry *dentry)
9301 + aufs_bindex_t bindex, bstart;
9302 + struct dentry *h_dentry;
9304 + bstart = au_dbstart(dentry);
9305 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
9306 + h_dentry = au_h_dptr(dentry, bindex);
9309 + if (h_dentry->d_inode) {
9310 + au_set_dbend(dentry, bindex);
9313 + au_set_h_dptr(dentry, bindex, NULL);
9317 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9319 + aufs_bindex_t bindex, bend;
9321 + bend = au_dbend(dentry);
9322 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
9323 + if (au_h_dptr(dentry, bindex) == h_dentry)
9327 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9328 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9329 +++ linux/fs/aufs/dir.c 2015-06-22 08:29:23.706757681 +0200
9332 + * Copyright (C) 2005-2015 Junjiro R. Okajima
9334 + * This program, aufs is free software; you can redistribute it and/or modify
9335 + * it under the terms of the GNU General Public License as published by
9336 + * the Free Software Foundation; either version 2 of the License, or
9337 + * (at your option) any later version.
9339 + * This program is distributed in the hope that it will be useful,
9340 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9341 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9342 + * GNU General Public License for more details.
9344 + * You should have received a copy of the GNU General Public License
9345 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9349 + * directory operations
9352 +#include <linux/fs_stack.h>
9355 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9357 + unsigned int nlink;
9359 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9361 + nlink = dir->i_nlink;
9362 + nlink += h_dir->i_nlink - 2;
9363 + if (h_dir->i_nlink < 2)
9365 + smp_mb(); /* for i_nlink */
9366 + /* 0 can happen in revaliding */
9367 + set_nlink(dir, nlink);
9370 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9372 + unsigned int nlink;
9374 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9376 + nlink = dir->i_nlink;
9377 + nlink -= h_dir->i_nlink - 2;
9378 + if (h_dir->i_nlink < 2)
9380 + smp_mb(); /* for i_nlink */
9381 + /* nlink == 0 means the branch-fs is broken */
9382 + set_nlink(dir, nlink);
9385 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9388 + aufs_bindex_t bindex, bend;
9389 + struct file *h_file;
9390 + struct dentry *h_dentry;
9394 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9396 + bend = au_fbend_dir(file);
9397 + for (bindex = au_fbstart(file);
9398 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9400 + h_file = au_hf_dir(file, bindex);
9401 + if (h_file && file_inode(h_file))
9402 + sz += vfsub_f_size_read(h_file);
9405 + AuDebugOn(!dentry);
9406 + AuDebugOn(!d_is_dir(dentry));
9408 + bend = au_dbtaildir(dentry);
9409 + for (bindex = au_dbstart(dentry);
9410 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9412 + h_dentry = au_h_dptr(dentry, bindex);
9413 + if (h_dentry && h_dentry->d_inode)
9414 + sz += i_size_read(h_dentry->d_inode);
9417 + if (sz < KMALLOC_MAX_SIZE)
9418 + sz = roundup_pow_of_two(sz);
9419 + if (sz > KMALLOC_MAX_SIZE)
9420 + sz = KMALLOC_MAX_SIZE;
9421 + else if (sz < NAME_MAX) {
9422 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9423 + sz = AUFS_RDBLK_DEF;
9428 +struct au_dir_ts_arg {
9429 + struct dentry *dentry;
9430 + aufs_bindex_t brid;
9433 +static void au_do_dir_ts(void *arg)
9435 + struct au_dir_ts_arg *a = arg;
9436 + struct au_dtime dt;
9437 + struct path h_path;
9438 + struct inode *dir, *h_dir;
9439 + struct super_block *sb;
9440 + struct au_branch *br;
9441 + struct au_hinode *hdir;
9443 + aufs_bindex_t bstart, bindex;
9445 + sb = a->dentry->d_sb;
9446 + dir = a->dentry->d_inode;
9449 + /* no dir->i_mutex lock */
9450 + aufs_read_lock(a->dentry, AuLock_DW | AuLock_DIR); /* noflush */
9452 + bstart = au_ibstart(dir);
9453 + bindex = au_br_index(sb, a->brid);
9454 + if (bindex < bstart)
9457 + br = au_sbr(sb, bindex);
9458 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9459 + if (!h_path.dentry)
9461 + h_path.mnt = au_br_mnt(br);
9462 + au_dtime_store(&dt, a->dentry, &h_path);
9464 + br = au_sbr(sb, bstart);
9465 + if (!au_br_writable(br->br_perm))
9467 + h_path.dentry = au_h_dptr(a->dentry, bstart);
9468 + h_path.mnt = au_br_mnt(br);
9469 + err = vfsub_mnt_want_write(h_path.mnt);
9472 + hdir = au_hi(dir, bstart);
9473 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
9474 + h_dir = au_h_iptr(dir, bstart);
9475 + if (h_dir->i_nlink
9476 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9477 + dt.dt_h_path = h_path;
9478 + au_dtime_revert(&dt);
9480 + au_hn_imtx_unlock(hdir);
9481 + vfsub_mnt_drop_write(h_path.mnt);
9482 + au_cpup_attr_timesizes(dir);
9485 + aufs_read_unlock(a->dentry, AuLock_DW);
9488 + au_nwt_done(&au_sbi(sb)->si_nowait);
9492 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9494 + int perm, wkq_err;
9495 + aufs_bindex_t bstart;
9496 + struct au_dir_ts_arg *arg;
9497 + struct dentry *dentry;
9498 + struct super_block *sb;
9502 + dentry = d_find_any_alias(dir);
9503 + AuDebugOn(!dentry);
9504 + sb = dentry->d_sb;
9505 + bstart = au_ibstart(dir);
9506 + if (bstart == bindex) {
9507 + au_cpup_attr_timesizes(dir);
9511 + perm = au_sbr_perm(sb, bstart);
9512 + if (!au_br_writable(perm))
9515 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9519 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9520 + arg->brid = au_sbr_id(sb, bindex);
9521 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9522 + if (unlikely(wkq_err)) {
9523 + pr_err("wkq %d\n", wkq_err);
9532 +/* ---------------------------------------------------------------------- */
9534 +static int reopen_dir(struct file *file)
9537 + unsigned int flags;
9538 + aufs_bindex_t bindex, btail, bstart;
9539 + struct dentry *dentry, *h_dentry;
9540 + struct file *h_file;
9542 + /* open all lower dirs */
9543 + dentry = file->f_path.dentry;
9544 + bstart = au_dbstart(dentry);
9545 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9546 + au_set_h_fptr(file, bindex, NULL);
9547 + au_set_fbstart(file, bstart);
9549 + btail = au_dbtaildir(dentry);
9550 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9551 + au_set_h_fptr(file, bindex, NULL);
9552 + au_set_fbend_dir(file, btail);
9554 + flags = vfsub_file_flags(file);
9555 + for (bindex = bstart; bindex <= btail; bindex++) {
9556 + h_dentry = au_h_dptr(dentry, bindex);
9559 + h_file = au_hf_dir(file, bindex);
9563 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9564 + err = PTR_ERR(h_file);
9565 + if (IS_ERR(h_file))
9566 + goto out; /* close all? */
9567 + au_set_h_fptr(file, bindex, h_file);
9569 + au_update_figen(file);
9570 + /* todo: necessary? */
9571 + /* file->f_ra = h_file->f_ra; */
9578 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9581 + aufs_bindex_t bindex, btail;
9582 + struct dentry *dentry, *h_dentry;
9584 + FiMustWriteLock(file);
9585 + AuDebugOn(h_file);
9588 + dentry = file->f_path.dentry;
9589 + file->f_version = dentry->d_inode->i_version;
9590 + bindex = au_dbstart(dentry);
9591 + au_set_fbstart(file, bindex);
9592 + btail = au_dbtaildir(dentry);
9593 + au_set_fbend_dir(file, btail);
9594 + for (; !err && bindex <= btail; bindex++) {
9595 + h_dentry = au_h_dptr(dentry, bindex);
9599 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9600 + if (IS_ERR(h_file)) {
9601 + err = PTR_ERR(h_file);
9604 + au_set_h_fptr(file, bindex, h_file);
9606 + au_update_figen(file);
9607 + /* todo: necessary? */
9608 + /* file->f_ra = h_file->f_ra; */
9610 + return 0; /* success */
9613 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9614 + au_set_h_fptr(file, bindex, NULL);
9615 + au_set_fbstart(file, -1);
9616 + au_set_fbend_dir(file, -1);
9621 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9622 + struct file *file)
9625 + struct super_block *sb;
9626 + struct au_fidir *fidir;
9629 + sb = file->f_path.dentry->d_sb;
9630 + si_read_lock(sb, AuLock_FLUSH);
9631 + fidir = au_fidir_alloc(sb);
9633 + struct au_do_open_args args = {
9634 + .open = do_open_dir,
9637 + err = au_do_open(file, &args);
9638 + if (unlikely(err))
9641 + si_read_unlock(sb);
9645 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9646 + struct file *file)
9648 + struct au_vdir *vdir_cache;
9649 + struct au_finfo *finfo;
9650 + struct au_fidir *fidir;
9651 + aufs_bindex_t bindex, bend;
9653 + finfo = au_fi(file);
9654 + fidir = finfo->fi_hdir;
9656 + au_sphl_del(&finfo->fi_hlist,
9657 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9658 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9660 + au_vdir_free(vdir_cache);
9662 + bindex = finfo->fi_btop;
9663 + if (bindex >= 0) {
9665 + * calls fput() instead of filp_close(),
9666 + * since no dnotify or lock for the lower file.
9668 + bend = fidir->fd_bbot;
9669 + for (; bindex <= bend; bindex++)
9670 + au_set_h_fptr(file, bindex, NULL);
9673 + finfo->fi_hdir = NULL;
9675 + au_finfo_fin(file);
9679 +/* ---------------------------------------------------------------------- */
9681 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9684 + aufs_bindex_t bindex, bend;
9685 + struct file *h_file;
9688 + bend = au_fbend_dir(file);
9689 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9690 + h_file = au_hf_dir(file, bindex);
9692 + err = vfsub_flush(h_file, id);
9697 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9699 + return au_do_flush(file, id, au_do_flush_dir);
9702 +/* ---------------------------------------------------------------------- */
9704 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9707 + aufs_bindex_t bend, bindex;
9708 + struct inode *inode;
9709 + struct super_block *sb;
9712 + sb = dentry->d_sb;
9713 + inode = dentry->d_inode;
9715 + bend = au_dbend(dentry);
9716 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9717 + struct path h_path;
9719 + if (au_test_ro(sb, bindex, inode))
9721 + h_path.dentry = au_h_dptr(dentry, bindex);
9722 + if (!h_path.dentry)
9725 + h_path.mnt = au_sbr_mnt(sb, bindex);
9726 + err = vfsub_fsync(NULL, &h_path, datasync);
9732 +static int au_do_fsync_dir(struct file *file, int datasync)
9735 + aufs_bindex_t bend, bindex;
9736 + struct file *h_file;
9737 + struct super_block *sb;
9738 + struct inode *inode;
9740 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9741 + if (unlikely(err))
9744 + inode = file_inode(file);
9746 + bend = au_fbend_dir(file);
9747 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9748 + h_file = au_hf_dir(file, bindex);
9749 + if (!h_file || au_test_ro(sb, bindex, inode))
9752 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9760 + * @file may be NULL
9762 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9766 + struct dentry *dentry;
9767 + struct super_block *sb;
9768 + struct mutex *mtx;
9771 + dentry = file->f_path.dentry;
9772 + mtx = &dentry->d_inode->i_mutex;
9774 + sb = dentry->d_sb;
9775 + si_noflush_read_lock(sb);
9777 + err = au_do_fsync_dir(file, datasync);
9779 + di_write_lock_child(dentry);
9780 + err = au_do_fsync_dir_no_file(dentry, datasync);
9782 + au_cpup_attr_timesizes(dentry->d_inode);
9783 + di_write_unlock(dentry);
9785 + fi_write_unlock(file);
9787 + si_read_unlock(sb);
9788 + mutex_unlock(mtx);
9792 +/* ---------------------------------------------------------------------- */
9794 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9797 + struct dentry *dentry;
9798 + struct inode *inode, *h_inode;
9799 + struct super_block *sb;
9801 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9803 + dentry = file->f_path.dentry;
9804 + inode = dentry->d_inode;
9807 + sb = dentry->d_sb;
9808 + si_read_lock(sb, AuLock_FLUSH);
9809 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9810 + if (unlikely(err))
9812 + err = au_alive_dir(dentry);
9814 + err = au_vdir_init(file);
9815 + di_downgrade_lock(dentry, AuLock_IR);
9816 + if (unlikely(err))
9819 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9820 + if (!au_test_nfsd()) {
9821 + err = au_vdir_fill_de(file, ctx);
9822 + fsstack_copy_attr_atime(inode, h_inode);
9825 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9826 + * encode_fh() and others.
9828 + atomic_inc(&h_inode->i_count);
9829 + di_read_unlock(dentry, AuLock_IR);
9830 + si_read_unlock(sb);
9831 + err = au_vdir_fill_de(file, ctx);
9832 + fsstack_copy_attr_atime(inode, h_inode);
9833 + fi_write_unlock(file);
9841 + di_read_unlock(dentry, AuLock_IR);
9842 + fi_write_unlock(file);
9844 + si_read_unlock(sb);
9848 +/* ---------------------------------------------------------------------- */
9850 +#define AuTestEmpty_WHONLY 1
9851 +#define AuTestEmpty_CALLED (1 << 1)
9852 +#define AuTestEmpty_SHWH (1 << 2)
9853 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9854 +#define au_fset_testempty(flags, name) \
9855 + do { (flags) |= AuTestEmpty_##name; } while (0)
9856 +#define au_fclr_testempty(flags, name) \
9857 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9859 +#ifndef CONFIG_AUFS_SHWH
9860 +#undef AuTestEmpty_SHWH
9861 +#define AuTestEmpty_SHWH 0
9864 +struct test_empty_arg {
9865 + struct dir_context ctx;
9866 + struct au_nhash *whlist;
9867 + unsigned int flags;
9869 + aufs_bindex_t bindex;
9872 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9873 + int namelen, loff_t offset __maybe_unused, u64 ino,
9874 + unsigned int d_type)
9876 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9878 + char *name = (void *)__name;
9881 + au_fset_testempty(arg->flags, CALLED);
9883 + if (name[0] == '.'
9884 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9885 + goto out; /* success */
9887 + if (namelen <= AUFS_WH_PFX_LEN
9888 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9889 + if (au_ftest_testempty(arg->flags, WHONLY)
9890 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9891 + arg->err = -ENOTEMPTY;
9895 + name += AUFS_WH_PFX_LEN;
9896 + namelen -= AUFS_WH_PFX_LEN;
9897 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9898 + arg->err = au_nhash_append_wh
9899 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9900 + au_ftest_testempty(arg->flags, SHWH));
9904 + AuTraceErr(arg->err);
9908 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9911 + struct file *h_file;
9913 + h_file = au_h_open(dentry, arg->bindex,
9914 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9915 + /*file*/NULL, /*force_wr*/0);
9916 + err = PTR_ERR(h_file);
9917 + if (IS_ERR(h_file))
9921 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9922 + && !file_inode(h_file)->i_nlink)
9927 + au_fclr_testempty(arg->flags, CALLED);
9929 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9932 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9936 + au_sbr_put(dentry->d_sb, arg->bindex);
9941 +struct do_test_empty_args {
9943 + struct dentry *dentry;
9944 + struct test_empty_arg *arg;
9947 +static void call_do_test_empty(void *args)
9949 + struct do_test_empty_args *a = args;
9950 + *a->errp = do_test_empty(a->dentry, a->arg);
9953 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9956 + struct dentry *h_dentry;
9957 + struct inode *h_inode;
9959 + h_dentry = au_h_dptr(dentry, arg->bindex);
9960 + h_inode = h_dentry->d_inode;
9961 + /* todo: i_mode changes anytime? */
9962 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
9963 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
9964 + mutex_unlock(&h_inode->i_mutex);
9966 + err = do_test_empty(dentry, arg);
9968 + struct do_test_empty_args args = {
9973 + unsigned int flags = arg->flags;
9975 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
9976 + if (unlikely(wkq_err))
9978 + arg->flags = flags;
9984 +int au_test_empty_lower(struct dentry *dentry)
9987 + unsigned int rdhash;
9988 + aufs_bindex_t bindex, bstart, btail;
9989 + struct au_nhash whlist;
9990 + struct test_empty_arg arg = {
9992 + .actor = test_empty_cb
9995 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
9997 + SiMustAnyLock(dentry->d_sb);
9999 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10001 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10002 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10003 + if (unlikely(err))
10007 + arg.whlist = &whlist;
10008 + bstart = au_dbstart(dentry);
10009 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10010 + au_fset_testempty(arg.flags, SHWH);
10011 + test_empty = do_test_empty;
10012 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10013 + test_empty = sio_test_empty;
10014 + arg.bindex = bstart;
10015 + err = test_empty(dentry, &arg);
10016 + if (unlikely(err))
10019 + au_fset_testempty(arg.flags, WHONLY);
10020 + btail = au_dbtaildir(dentry);
10021 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
10022 + struct dentry *h_dentry;
10024 + h_dentry = au_h_dptr(dentry, bindex);
10025 + if (h_dentry && h_dentry->d_inode) {
10026 + arg.bindex = bindex;
10027 + err = test_empty(dentry, &arg);
10032 + au_nhash_wh_free(&whlist);
10037 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10040 + struct test_empty_arg arg = {
10042 + .actor = test_empty_cb
10045 + aufs_bindex_t bindex, btail;
10048 + arg.whlist = whlist;
10049 + arg.flags = AuTestEmpty_WHONLY;
10050 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10051 + au_fset_testempty(arg.flags, SHWH);
10052 + btail = au_dbtaildir(dentry);
10053 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
10054 + struct dentry *h_dentry;
10056 + h_dentry = au_h_dptr(dentry, bindex);
10057 + if (h_dentry && h_dentry->d_inode) {
10058 + arg.bindex = bindex;
10059 + err = sio_test_empty(dentry, &arg);
10066 +/* ---------------------------------------------------------------------- */
10068 +const struct file_operations aufs_dir_fop = {
10069 + .owner = THIS_MODULE,
10070 + .llseek = default_llseek,
10071 + .read = generic_read_dir,
10072 + .iterate = aufs_iterate,
10073 + .unlocked_ioctl = aufs_ioctl_dir,
10074 +#ifdef CONFIG_COMPAT
10075 + .compat_ioctl = aufs_compat_ioctl_dir,
10077 + .open = aufs_open_dir,
10078 + .release = aufs_release_dir,
10079 + .flush = aufs_flush_dir,
10080 + .fsync = aufs_fsync_dir
10082 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10083 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10084 +++ linux/fs/aufs/dir.h 2015-06-22 08:27:37.877501704 +0200
10087 + * Copyright (C) 2005-2015 Junjiro R. Okajima
10089 + * This program, aufs is free software; you can redistribute it and/or modify
10090 + * it under the terms of the GNU General Public License as published by
10091 + * the Free Software Foundation; either version 2 of the License, or
10092 + * (at your option) any later version.
10094 + * This program is distributed in the hope that it will be useful,
10095 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10096 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10097 + * GNU General Public License for more details.
10099 + * You should have received a copy of the GNU General Public License
10100 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10104 + * directory operations
10107 +#ifndef __AUFS_DIR_H__
10108 +#define __AUFS_DIR_H__
10112 +#include <linux/fs.h>
10114 +/* ---------------------------------------------------------------------- */
10116 +/* need to be faster and smaller */
10119 + unsigned int nh_num;
10120 + struct hlist_head *nh_head;
10123 +struct au_vdir_destr {
10124 + unsigned char len;
10125 + unsigned char name[0];
10128 +struct au_vdir_dehstr {
10129 + struct hlist_node hash;
10130 + struct au_vdir_destr *str;
10131 +} ____cacheline_aligned_in_smp;
10133 +struct au_vdir_de {
10135 + unsigned char de_type;
10136 + /* caution: packed */
10137 + struct au_vdir_destr de_str;
10140 +struct au_vdir_wh {
10141 + struct hlist_node wh_hash;
10142 +#ifdef CONFIG_AUFS_SHWH
10144 + aufs_bindex_t wh_bindex;
10145 + unsigned char wh_type;
10147 + aufs_bindex_t wh_bindex;
10149 + /* caution: packed */
10150 + struct au_vdir_destr wh_str;
10153 +union au_vdir_deblk_p {
10154 + unsigned char *deblk;
10155 + struct au_vdir_de *de;
10159 + unsigned char **vd_deblk;
10160 + unsigned long vd_nblk;
10162 + unsigned long ul;
10163 + union au_vdir_deblk_p p;
10166 + unsigned long vd_version;
10167 + unsigned int vd_deblk_sz;
10168 + unsigned long vd_jiffy;
10169 +} ____cacheline_aligned_in_smp;
10171 +/* ---------------------------------------------------------------------- */
10174 +extern const struct file_operations aufs_dir_fop;
10175 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10176 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10177 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10178 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10179 +int au_test_empty_lower(struct dentry *dentry);
10180 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10183 +unsigned int au_rdhash_est(loff_t sz);
10184 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10185 +void au_nhash_wh_free(struct au_nhash *whlist);
10186 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10188 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10189 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10190 + unsigned int d_type, aufs_bindex_t bindex,
10191 + unsigned char shwh);
10192 +void au_vdir_free(struct au_vdir *vdir);
10193 +int au_vdir_init(struct file *file);
10194 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10197 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10199 +#ifdef CONFIG_AUFS_RDU
10201 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10202 +#ifdef CONFIG_COMPAT
10203 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10204 + unsigned long arg);
10207 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10208 + unsigned int cmd, unsigned long arg)
10209 +#ifdef CONFIG_COMPAT
10210 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10211 + unsigned int cmd, unsigned long arg)
10215 +#endif /* __KERNEL__ */
10216 +#endif /* __AUFS_DIR_H__ */
10217 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10218 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10219 +++ linux/fs/aufs/dynop.c 2015-06-22 08:29:23.706757681 +0200
10222 + * Copyright (C) 2010-2015 Junjiro R. Okajima
10224 + * This program, aufs is free software; you can redistribute it and/or modify
10225 + * it under the terms of the GNU General Public License as published by
10226 + * the Free Software Foundation; either version 2 of the License, or
10227 + * (at your option) any later version.
10229 + * This program is distributed in the hope that it will be useful,
10230 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10231 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10232 + * GNU General Public License for more details.
10234 + * You should have received a copy of the GNU General Public License
10235 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10239 + * dynamically customizable operations for regular files
10244 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10247 + * How large will these lists be?
10248 + * Usually just a few elements, 20-30 at most for each, I guess.
10250 +static struct au_splhead dynop[AuDyLast];
10252 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
10254 + struct au_dykey *key, *tmp;
10255 + struct list_head *head;
10258 + head = &spl->head;
10260 + list_for_each_entry_rcu(tmp, head, dk_list)
10261 + if (tmp->dk_op.dy_hop == h_op) {
10263 + kref_get(&key->dk_kref);
10266 + rcu_read_unlock();
10271 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10273 + struct au_dykey **k, *found;
10274 + const void *h_op = key->dk_op.dy_hop;
10278 + k = br->br_dykey;
10279 + for (i = 0; i < AuBrDynOp; i++)
10281 + if (k[i]->dk_op.dy_hop == h_op) {
10288 + spin_lock(&br->br_dykey_lock);
10289 + for (; i < AuBrDynOp; i++)
10291 + if (k[i]->dk_op.dy_hop == h_op) {
10299 + spin_unlock(&br->br_dykey_lock);
10300 + BUG_ON(i == AuBrDynOp); /* expand the array */
10306 +/* kref_get() if @key is already added */
10307 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
10309 + struct au_dykey *tmp, *found;
10310 + struct list_head *head;
10311 + const void *h_op = key->dk_op.dy_hop;
10314 + head = &spl->head;
10315 + spin_lock(&spl->spin);
10316 + list_for_each_entry(tmp, head, dk_list)
10317 + if (tmp->dk_op.dy_hop == h_op) {
10318 + kref_get(&tmp->dk_kref);
10323 + list_add_rcu(&key->dk_list, head);
10324 + spin_unlock(&spl->spin);
10331 +static void dy_free_rcu(struct rcu_head *rcu)
10333 + struct au_dykey *key;
10335 + key = container_of(rcu, struct au_dykey, dk_rcu);
10340 +static void dy_free(struct kref *kref)
10342 + struct au_dykey *key;
10343 + struct au_splhead *spl;
10345 + key = container_of(kref, struct au_dykey, dk_kref);
10346 + spl = dynop + key->dk_op.dy_type;
10347 + au_spl_del_rcu(&key->dk_list, spl);
10348 + call_rcu(&key->dk_rcu, dy_free_rcu);
10351 +void au_dy_put(struct au_dykey *key)
10353 + kref_put(&key->dk_kref, dy_free);
10356 +/* ---------------------------------------------------------------------- */
10358 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10360 +#ifdef CONFIG_AUFS_DEBUG
10361 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10362 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10364 +#define DyDbgDeclare(cnt) do {} while (0)
10365 +#define DyDbgInc(cnt) do {} while (0)
10368 +#define DySet(func, dst, src, h_op, h_sb) do { \
10370 + if (h_op->func) { \
10372 + dst.func = src.func; \
10374 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10378 +#define DySetForce(func, dst, src) do { \
10379 + AuDebugOn(!src.func); \
10381 + dst.func = src.func; \
10384 +#define DySetAop(func) \
10385 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10386 +#define DySetAopForce(func) \
10387 + DySetForce(func, dyaop->da_op, aufs_aop)
10389 +static void dy_aop(struct au_dykey *key, const void *h_op,
10390 + struct super_block *h_sb __maybe_unused)
10392 + struct au_dyaop *dyaop = (void *)key;
10393 + const struct address_space_operations *h_aop = h_op;
10394 + DyDbgDeclare(cnt);
10396 + AuDbg("%s\n", au_sbtype(h_sb));
10398 + DySetAop(writepage);
10399 + DySetAopForce(readpage); /* force */
10400 + DySetAop(writepages);
10401 + DySetAop(set_page_dirty);
10402 + DySetAop(readpages);
10403 + DySetAop(write_begin);
10404 + DySetAop(write_end);
10406 + DySetAop(invalidatepage);
10407 + DySetAop(releasepage);
10408 + DySetAop(freepage);
10409 + /* this one will be changed according to an aufs mount option */
10410 + DySetAop(direct_IO);
10411 + DySetAop(migratepage);
10412 + DySetAop(launder_page);
10413 + DySetAop(is_partially_uptodate);
10414 + DySetAop(is_dirty_writeback);
10415 + DySetAop(error_remove_page);
10416 + DySetAop(swap_activate);
10417 + DySetAop(swap_deactivate);
10419 + DyDbgSize(cnt, *h_aop);
10422 +/* ---------------------------------------------------------------------- */
10424 +static void dy_bug(struct kref *kref)
10429 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10431 + struct au_dykey *key, *old;
10432 + struct au_splhead *spl;
10435 + void (*set)(struct au_dykey *key, const void *h_op,
10436 + struct super_block *h_sb __maybe_unused);
10438 + static const struct op a[] = {
10440 + .sz = sizeof(struct au_dyaop),
10444 + const struct op *p;
10446 + spl = dynop + op->dy_type;
10447 + key = dy_gfind_get(spl, op->dy_hop);
10449 + goto out_add; /* success */
10451 + p = a + op->dy_type;
10452 + key = kzalloc(p->sz, GFP_NOFS);
10453 + if (unlikely(!key)) {
10454 + key = ERR_PTR(-ENOMEM);
10458 + key->dk_op.dy_hop = op->dy_hop;
10459 + kref_init(&key->dk_kref);
10460 + p->set(key, op->dy_hop, au_br_sb(br));
10461 + old = dy_gadd(spl, key);
10468 + old = dy_bradd(br, key);
10470 + /* its ref-count should never be zero here */
10471 + kref_put(&key->dk_kref, dy_bug);
10476 +/* ---------------------------------------------------------------------- */
10478 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10479 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10480 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10481 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10482 + * See the aufs manual in detail.
10484 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10487 + dyaop->da_op.direct_IO = NULL;
10489 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10492 +static struct au_dyaop *dy_aget(struct au_branch *br,
10493 + const struct address_space_operations *h_aop,
10496 + struct au_dyaop *dyaop;
10497 + struct au_dynop op;
10499 + op.dy_type = AuDy_AOP;
10500 + op.dy_haop = h_aop;
10501 + dyaop = (void *)dy_get(&op, br);
10502 + if (IS_ERR(dyaop))
10504 + dy_adx(dyaop, do_dx);
10510 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10511 + struct inode *h_inode)
10514 + struct super_block *sb;
10515 + struct au_branch *br;
10516 + struct au_dyaop *dyaop;
10518 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10519 + IiMustWriteLock(inode);
10521 + sb = inode->i_sb;
10522 + br = au_sbr(sb, bindex);
10523 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10524 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10525 + err = PTR_ERR(dyaop);
10526 + if (IS_ERR(dyaop))
10527 + /* unnecessary to call dy_fput() */
10531 + inode->i_mapping->a_ops = &dyaop->da_op;
10538 + * Is it safe to replace a_ops during the inode/file is in operation?
10539 + * Yes, I hope so.
10541 +int au_dy_irefresh(struct inode *inode)
10544 + aufs_bindex_t bstart;
10545 + struct inode *h_inode;
10548 + if (S_ISREG(inode->i_mode)) {
10549 + bstart = au_ibstart(inode);
10550 + h_inode = au_h_iptr(inode, bstart);
10551 + err = au_dy_iaop(inode, bstart, h_inode);
10556 +void au_dy_arefresh(int do_dx)
10558 + struct au_splhead *spl;
10559 + struct list_head *head;
10560 + struct au_dykey *key;
10562 + spl = dynop + AuDy_AOP;
10563 + head = &spl->head;
10564 + spin_lock(&spl->spin);
10565 + list_for_each_entry(key, head, dk_list)
10566 + dy_adx((void *)key, do_dx);
10567 + spin_unlock(&spl->spin);
10570 +/* ---------------------------------------------------------------------- */
10572 +void __init au_dy_init(void)
10576 + /* make sure that 'struct au_dykey *' can be any type */
10577 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10579 + for (i = 0; i < AuDyLast; i++)
10580 + au_spl_init(dynop + i);
10583 +void au_dy_fin(void)
10587 + for (i = 0; i < AuDyLast; i++)
10588 + WARN_ON(!list_empty(&dynop[i].head));
10590 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10591 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10592 +++ linux/fs/aufs/dynop.h 2015-06-22 08:29:23.706757681 +0200
10595 + * Copyright (C) 2010-2015 Junjiro R. Okajima
10597 + * This program, aufs is free software; you can redistribute it and/or modify
10598 + * it under the terms of the GNU General Public License as published by
10599 + * the Free Software Foundation; either version 2 of the License, or
10600 + * (at your option) any later version.
10602 + * This program is distributed in the hope that it will be useful,
10603 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10604 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10605 + * GNU General Public License for more details.
10607 + * You should have received a copy of the GNU General Public License
10608 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10612 + * dynamically customizable operations (for regular files only)
10615 +#ifndef __AUFS_DYNOP_H__
10616 +#define __AUFS_DYNOP_H__
10620 +#include <linux/fs.h>
10621 +#include <linux/kref.h>
10623 +enum {AuDy_AOP, AuDyLast};
10628 + const void *dy_hop;
10629 + const struct address_space_operations *dy_haop;
10635 + struct list_head dk_list;
10636 + struct rcu_head dk_rcu;
10638 + struct au_dynop dk_op;
10641 + * during I am in the branch local array, kref is gotten. when the
10642 + * branch is removed, kref is put.
10644 + struct kref dk_kref;
10647 +/* stop unioning since their sizes are very different from each other */
10649 + struct au_dykey da_key;
10650 + struct address_space_operations da_op; /* not const */
10653 +/* ---------------------------------------------------------------------- */
10657 +void au_dy_put(struct au_dykey *key);
10658 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10659 + struct inode *h_inode);
10660 +int au_dy_irefresh(struct inode *inode);
10661 +void au_dy_arefresh(int do_dio);
10663 +void __init au_dy_init(void);
10664 +void au_dy_fin(void);
10666 +#endif /* __KERNEL__ */
10667 +#endif /* __AUFS_DYNOP_H__ */
10668 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10669 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10670 +++ linux/fs/aufs/export.c 2015-06-22 08:29:23.706757681 +0200
10673 + * Copyright (C) 2005-2015 Junjiro R. Okajima
10675 + * This program, aufs is free software; you can redistribute it and/or modify
10676 + * it under the terms of the GNU General Public License as published by
10677 + * the Free Software Foundation; either version 2 of the License, or
10678 + * (at your option) any later version.
10680 + * This program is distributed in the hope that it will be useful,
10681 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10682 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10683 + * GNU General Public License for more details.
10685 + * You should have received a copy of the GNU General Public License
10686 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10693 +#include <linux/exportfs.h>
10694 +#include <linux/fs_struct.h>
10695 +#include <linux/namei.h>
10696 +#include <linux/nsproxy.h>
10697 +#include <linux/random.h>
10698 +#include <linux/writeback.h>
10699 +#include "../fs/mount.h"
10703 +#ifdef CONFIG_AUFS_INO_T_64
10711 +static ino_t decode_ino(__u32 *a)
10715 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10717 +#ifdef CONFIG_AUFS_INO_T_64
10723 +static void encode_ino(__u32 *a, ino_t ino)
10729 +#ifdef CONFIG_AUFS_INO_T_64
10734 +/* NFS file handle */
10738 +#ifdef CONFIG_AUFS_INO_T_64
10739 + /* support 64bit inode number */
10752 + Fh_ino = Fh_ino1,
10753 + Fh_dir_ino = Fh_dir_ino1
10756 +static int au_test_anon(struct dentry *dentry)
10758 + /* note: read d_flags without d_lock */
10759 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10762 +int au_test_nfsd(void)
10765 + struct task_struct *tsk = current;
10766 + char comm[sizeof(tsk->comm)];
10769 + if (tsk->flags & PF_KTHREAD) {
10770 + get_task_comm(comm, tsk);
10771 + ret = !strcmp(comm, "nfsd");
10777 +/* ---------------------------------------------------------------------- */
10778 +/* inode generation external table */
10780 +void au_xigen_inc(struct inode *inode)
10785 + struct super_block *sb;
10786 + struct au_sbinfo *sbinfo;
10788 + sb = inode->i_sb;
10789 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10791 + sbinfo = au_sbi(sb);
10792 + pos = inode->i_ino;
10793 + pos *= sizeof(igen);
10794 + igen = inode->i_generation + 1;
10795 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10796 + sizeof(igen), &pos);
10797 + if (sz == sizeof(igen))
10798 + return; /* success */
10800 + if (unlikely(sz >= 0))
10801 + AuIOErr("xigen error (%zd)\n", sz);
10804 +int au_xigen_new(struct inode *inode)
10809 + struct super_block *sb;
10810 + struct au_sbinfo *sbinfo;
10811 + struct file *file;
10814 + /* todo: dirty, at mount time */
10815 + if (inode->i_ino == AUFS_ROOT_INO)
10817 + sb = inode->i_sb;
10818 + SiMustAnyLock(sb);
10819 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10823 + pos = inode->i_ino;
10824 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10825 + AuIOErr1("too large i%lld\n", pos);
10828 + pos *= sizeof(inode->i_generation);
10831 + sbinfo = au_sbi(sb);
10832 + file = sbinfo->si_xigen;
10835 + if (vfsub_f_size_read(file)
10836 + < pos + sizeof(inode->i_generation)) {
10837 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10838 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10839 + sizeof(inode->i_generation), &pos);
10841 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10842 + sizeof(inode->i_generation), &pos);
10843 + if (sz == sizeof(inode->i_generation))
10844 + goto out; /* success */
10847 + if (unlikely(sz >= 0)) {
10849 + AuIOErr("xigen error (%zd)\n", sz);
10856 +int au_xigen_set(struct super_block *sb, struct file *base)
10859 + struct au_sbinfo *sbinfo;
10860 + struct file *file;
10862 + SiMustWriteLock(sb);
10864 + sbinfo = au_sbi(sb);
10865 + file = au_xino_create2(base, sbinfo->si_xigen);
10866 + err = PTR_ERR(file);
10867 + if (IS_ERR(file))
10870 + if (sbinfo->si_xigen)
10871 + fput(sbinfo->si_xigen);
10872 + sbinfo->si_xigen = file;
10878 +void au_xigen_clr(struct super_block *sb)
10880 + struct au_sbinfo *sbinfo;
10882 + SiMustWriteLock(sb);
10884 + sbinfo = au_sbi(sb);
10885 + if (sbinfo->si_xigen) {
10886 + fput(sbinfo->si_xigen);
10887 + sbinfo->si_xigen = NULL;
10891 +/* ---------------------------------------------------------------------- */
10893 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10896 + struct dentry *dentry, *d;
10897 + struct inode *inode;
10898 + unsigned int sigen;
10901 + inode = ilookup(sb, ino);
10905 + dentry = ERR_PTR(-ESTALE);
10906 + sigen = au_sigen(sb);
10907 + if (unlikely(is_bad_inode(inode)
10908 + || IS_DEADDIR(inode)
10909 + || sigen != au_iigen(inode, NULL)))
10913 + if (!dir_ino || S_ISDIR(inode->i_mode))
10914 + dentry = d_find_alias(inode);
10916 + spin_lock(&inode->i_lock);
10917 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
10918 + spin_lock(&d->d_lock);
10919 + if (!au_test_anon(d)
10920 + && d->d_parent->d_inode->i_ino == dir_ino) {
10921 + dentry = dget_dlock(d);
10922 + spin_unlock(&d->d_lock);
10925 + spin_unlock(&d->d_lock);
10927 + spin_unlock(&inode->i_lock);
10929 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10930 + /* need to refresh */
10938 + AuTraceErrPtr(dentry);
10942 +/* ---------------------------------------------------------------------- */
10944 +/* todo: dirty? */
10945 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10947 +struct au_compare_mnt_args {
10949 + struct super_block *sb;
10952 + struct vfsmount *mnt;
10955 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
10957 + struct au_compare_mnt_args *a = arg;
10959 + if (mnt->mnt_sb != a->sb)
10961 + a->mnt = mntget(mnt);
10965 +static struct vfsmount *au_mnt_get(struct super_block *sb)
10968 + struct path root;
10969 + struct au_compare_mnt_args args = {
10973 + get_fs_root(current->fs, &root);
10975 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
10976 + rcu_read_unlock();
10979 + AuDebugOn(!args.mnt);
10983 +struct au_nfsd_si_lock {
10984 + unsigned int sigen;
10985 + aufs_bindex_t bindex, br_id;
10986 + unsigned char force_lock;
10989 +static int si_nfsd_read_lock(struct super_block *sb,
10990 + struct au_nfsd_si_lock *nsi_lock)
10993 + aufs_bindex_t bindex;
10995 + si_read_lock(sb, AuLock_FLUSH);
10997 + /* branch id may be wrapped around */
10999 + bindex = au_br_index(sb, nsi_lock->br_id);
11000 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11001 + goto out; /* success */
11005 + if (!nsi_lock->force_lock)
11006 + si_read_unlock(sb);
11009 + nsi_lock->bindex = bindex;
11013 +struct find_name_by_ino {
11014 + struct dir_context ctx;
11015 + int called, found;
11022 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11023 + loff_t offset, u64 ino, unsigned int d_type)
11025 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11029 + if (a->ino != ino)
11032 + memcpy(a->name, name, namelen);
11033 + a->namelen = namelen;
11038 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11039 + struct au_nfsd_si_lock *nsi_lock)
11041 + struct dentry *dentry, *parent;
11042 + struct file *file;
11043 + struct inode *dir;
11044 + struct find_name_by_ino arg = {
11046 + .actor = find_name_by_ino
11051 + parent = path->dentry;
11053 + si_read_unlock(parent->d_sb);
11054 + file = vfsub_dentry_open(path, au_dir_roflags);
11055 + dentry = (void *)file;
11056 + if (IS_ERR(file))
11059 + dentry = ERR_PTR(-ENOMEM);
11060 + arg.name = (void *)__get_free_page(GFP_NOFS);
11061 + if (unlikely(!arg.name))
11068 + err = vfsub_iterate_dir(file, &arg.ctx);
11069 + } while (!err && !arg.found && arg.called);
11070 + dentry = ERR_PTR(err);
11071 + if (unlikely(err))
11073 + /* instead of ENOENT */
11074 + dentry = ERR_PTR(-ESTALE);
11078 + /* do not call vfsub_lkup_one() */
11079 + dir = parent->d_inode;
11080 + mutex_lock(&dir->i_mutex);
11081 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
11082 + mutex_unlock(&dir->i_mutex);
11083 + AuTraceErrPtr(dentry);
11084 + if (IS_ERR(dentry))
11086 + AuDebugOn(au_test_anon(dentry));
11087 + if (unlikely(!dentry->d_inode)) {
11089 + dentry = ERR_PTR(-ENOENT);
11093 + free_page((unsigned long)arg.name);
11097 + if (unlikely(nsi_lock
11098 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11099 + if (!IS_ERR(dentry)) {
11101 + dentry = ERR_PTR(-ESTALE);
11103 + AuTraceErrPtr(dentry);
11107 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11109 + struct au_nfsd_si_lock *nsi_lock)
11111 + struct dentry *dentry;
11112 + struct path path;
11114 + if (dir_ino != AUFS_ROOT_INO) {
11115 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11116 + dentry = path.dentry;
11117 + if (!path.dentry || IS_ERR(path.dentry))
11119 + AuDebugOn(au_test_anon(path.dentry));
11121 + path.dentry = dget(sb->s_root);
11123 + path.mnt = au_mnt_get(sb);
11124 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11128 + AuTraceErrPtr(dentry);
11132 +/* ---------------------------------------------------------------------- */
11134 +static int h_acceptable(void *expv, struct dentry *dentry)
11139 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11140 + char *buf, int len, struct super_block *sb)
11144 + struct path path;
11146 + p = d_path(h_rootpath, buf, len);
11151 + path.mnt = h_rootpath->mnt;
11152 + path.dentry = h_parent;
11153 + p = d_path(&path, buf, len);
11159 + path.mnt = au_mnt_get(sb);
11160 + path.dentry = sb->s_root;
11161 + p = d_path(&path, buf, len - strlen(p));
11162 + mntput(path.mnt);
11166 + p[strlen(p)] = '/';
11169 + AuTraceErrPtr(p);
11174 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11175 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11177 + struct dentry *dentry, *h_parent, *root;
11178 + struct super_block *h_sb;
11179 + char *pathname, *p;
11180 + struct vfsmount *h_mnt;
11181 + struct au_branch *br;
11183 + struct path path;
11185 + br = au_sbr(sb, nsi_lock->bindex);
11186 + h_mnt = au_br_mnt(br);
11187 + h_sb = h_mnt->mnt_sb;
11188 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11189 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11190 + fh_len - Fh_tail, fh[Fh_h_type],
11191 + h_acceptable, /*context*/NULL);
11192 + dentry = h_parent;
11193 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11194 + AuWarn1("%s decode_fh failed, %ld\n",
11195 + au_sbtype(h_sb), PTR_ERR(h_parent));
11199 + if (unlikely(au_test_anon(h_parent))) {
11200 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11201 + au_sbtype(h_sb));
11202 + goto out_h_parent;
11205 + dentry = ERR_PTR(-ENOMEM);
11206 + pathname = (void *)__get_free_page(GFP_NOFS);
11207 + if (unlikely(!pathname))
11208 + goto out_h_parent;
11210 + root = sb->s_root;
11211 + path.mnt = h_mnt;
11212 + di_read_lock_parent(root, !AuLock_IR);
11213 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11214 + di_read_unlock(root, !AuLock_IR);
11215 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11216 + dentry = (void *)p;
11218 + goto out_pathname;
11220 + si_read_unlock(sb);
11221 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11222 + dentry = ERR_PTR(err);
11223 + if (unlikely(err))
11226 + dentry = ERR_PTR(-ENOENT);
11227 + AuDebugOn(au_test_anon(path.dentry));
11228 + if (unlikely(!path.dentry->d_inode))
11231 + if (ino != path.dentry->d_inode->i_ino)
11232 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11234 + dentry = dget(path.dentry);
11239 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11240 + if (!IS_ERR(dentry)) {
11242 + dentry = ERR_PTR(-ESTALE);
11245 + free_page((unsigned long)pathname);
11249 + AuTraceErrPtr(dentry);
11253 +/* ---------------------------------------------------------------------- */
11255 +static struct dentry *
11256 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11259 + struct dentry *dentry;
11260 + __u32 *fh = fid->raw;
11261 + struct au_branch *br;
11262 + ino_t ino, dir_ino;
11263 + struct au_nfsd_si_lock nsi_lock = {
11267 + dentry = ERR_PTR(-ESTALE);
11268 + /* it should never happen, but the file handle is unreliable */
11269 + if (unlikely(fh_len < Fh_tail))
11271 + nsi_lock.sigen = fh[Fh_sigen];
11272 + nsi_lock.br_id = fh[Fh_br_id];
11274 + /* branch id may be wrapped around */
11276 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11278 + nsi_lock.force_lock = 1;
11280 + /* is this inode still cached? */
11281 + ino = decode_ino(fh + Fh_ino);
11282 + /* it should never happen */
11283 + if (unlikely(ino == AUFS_ROOT_INO))
11286 + dir_ino = decode_ino(fh + Fh_dir_ino);
11287 + dentry = decode_by_ino(sb, ino, dir_ino);
11288 + if (IS_ERR(dentry))
11293 + /* is the parent dir cached? */
11294 + br = au_sbr(sb, nsi_lock.bindex);
11295 + atomic_inc(&br->br_count);
11296 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11297 + if (IS_ERR(dentry))
11302 + /* lookup path */
11303 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11304 + if (IS_ERR(dentry))
11306 + if (unlikely(!dentry))
11307 + /* todo?: make it ESTALE */
11311 + if (!au_digen_test(dentry, au_sigen(sb))
11312 + && dentry->d_inode->i_generation == fh[Fh_igen])
11313 + goto out_unlock; /* success */
11316 + dentry = ERR_PTR(-ESTALE);
11319 + atomic_dec(&br->br_count);
11320 + si_read_unlock(sb);
11322 + AuTraceErrPtr(dentry);
11326 +#if 0 /* reserved for future use */
11327 +/* support subtreecheck option */
11328 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11329 + int fh_len, int fh_type)
11331 + struct dentry *parent;
11332 + __u32 *fh = fid->raw;
11335 + dir_ino = decode_ino(fh + Fh_dir_ino);
11336 + parent = decode_by_ino(sb, dir_ino, 0);
11337 + if (IS_ERR(parent))
11340 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11341 + dir_ino, fh, fh_len);
11344 + AuTraceErrPtr(parent);
11349 +/* ---------------------------------------------------------------------- */
11351 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11352 + struct inode *dir)
11355 + aufs_bindex_t bindex;
11356 + struct super_block *sb, *h_sb;
11357 + struct dentry *dentry, *parent, *h_parent;
11358 + struct inode *h_dir;
11359 + struct au_branch *br;
11362 + if (unlikely(*max_len <= Fh_tail)) {
11363 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11367 + err = FILEID_ROOT;
11368 + if (inode->i_ino == AUFS_ROOT_INO) {
11369 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11374 + sb = inode->i_sb;
11375 + err = si_read_lock(sb, AuLock_FLUSH);
11376 + if (unlikely(err))
11379 +#ifdef CONFIG_AUFS_DEBUG
11380 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11381 + AuWarn1("NFS-exporting requires xino\n");
11385 + ii_read_lock_child(inode);
11386 + bindex = au_ibstart(inode);
11388 + dentry = d_find_any_alias(inode);
11389 + if (unlikely(!dentry))
11391 + AuDebugOn(au_test_anon(dentry));
11392 + parent = dget_parent(dentry);
11394 + if (unlikely(!parent))
11396 + dir = parent->d_inode;
11399 + ii_read_lock_parent(dir);
11400 + h_dir = au_h_iptr(dir, bindex);
11401 + ii_read_unlock(dir);
11402 + if (unlikely(!h_dir))
11404 + h_parent = d_find_any_alias(h_dir);
11405 + if (unlikely(!h_parent))
11406 + goto out_hparent;
11409 + br = au_sbr(sb, bindex);
11410 + h_sb = au_br_sb(br);
11411 + if (unlikely(!h_sb->s_export_op)) {
11412 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11413 + goto out_hparent;
11416 + fh[Fh_br_id] = br->br_id;
11417 + fh[Fh_sigen] = au_sigen(sb);
11418 + encode_ino(fh + Fh_ino, inode->i_ino);
11419 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11420 + fh[Fh_igen] = inode->i_generation;
11422 + *max_len -= Fh_tail;
11423 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11425 + /*connectable or subtreecheck*/0);
11426 + err = fh[Fh_h_type];
11427 + *max_len += Fh_tail;
11428 + /* todo: macros? */
11429 + if (err != FILEID_INVALID)
11432 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11439 + ii_read_unlock(inode);
11440 + si_read_unlock(sb);
11442 + if (unlikely(err < 0))
11443 + err = FILEID_INVALID;
11447 +/* ---------------------------------------------------------------------- */
11449 +static int aufs_commit_metadata(struct inode *inode)
11452 + aufs_bindex_t bindex;
11453 + struct super_block *sb;
11454 + struct inode *h_inode;
11455 + int (*f)(struct inode *inode);
11457 + sb = inode->i_sb;
11458 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11459 + ii_write_lock_child(inode);
11460 + bindex = au_ibstart(inode);
11461 + AuDebugOn(bindex < 0);
11462 + h_inode = au_h_iptr(inode, bindex);
11464 + f = h_inode->i_sb->s_export_op->commit_metadata;
11466 + err = f(h_inode);
11468 + struct writeback_control wbc = {
11469 + .sync_mode = WB_SYNC_ALL,
11470 + .nr_to_write = 0 /* metadata only */
11473 + err = sync_inode(h_inode, &wbc);
11476 + au_cpup_attr_timesizes(inode);
11477 + ii_write_unlock(inode);
11478 + si_read_unlock(sb);
11482 +/* ---------------------------------------------------------------------- */
11484 +static struct export_operations aufs_export_op = {
11485 + .fh_to_dentry = aufs_fh_to_dentry,
11486 + /* .fh_to_parent = aufs_fh_to_parent, */
11487 + .encode_fh = aufs_encode_fh,
11488 + .commit_metadata = aufs_commit_metadata
11491 +void au_export_init(struct super_block *sb)
11493 + struct au_sbinfo *sbinfo;
11496 + sb->s_export_op = &aufs_export_op;
11497 + sbinfo = au_sbi(sb);
11498 + sbinfo->si_xigen = NULL;
11499 + get_random_bytes(&u, sizeof(u));
11500 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11501 + atomic_set(&sbinfo->si_xigen_next, u);
11503 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11504 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11505 +++ linux/fs/aufs/fhsm.c 2015-06-22 08:27:37.880835119 +0200
11508 + * Copyright (C) 2011-2015 Junjiro R. Okajima
11510 + * This program, aufs is free software; you can redistribute it and/or modify
11511 + * it under the terms of the GNU General Public License as published by
11512 + * the Free Software Foundation; either version 2 of the License, or
11513 + * (at your option) any later version.
11515 + * This program is distributed in the hope that it will be useful,
11516 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11517 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11518 + * GNU General Public License for more details.
11520 + * You should have received a copy of the GNU General Public License
11521 + * along with this program; if not, write to the Free Software
11522 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11526 + * File-based Hierarchy Storage Management
11529 +#include <linux/anon_inodes.h>
11530 +#include <linux/poll.h>
11531 +#include <linux/seq_file.h>
11532 +#include <linux/statfs.h>
11535 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11537 + struct au_sbinfo *sbinfo;
11538 + struct au_fhsm *fhsm;
11540 + SiMustAnyLock(sb);
11542 + sbinfo = au_sbi(sb);
11543 + fhsm = &sbinfo->si_fhsm;
11544 + AuDebugOn(!fhsm);
11545 + return fhsm->fhsm_bottom;
11548 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11550 + struct au_sbinfo *sbinfo;
11551 + struct au_fhsm *fhsm;
11553 + SiMustWriteLock(sb);
11555 + sbinfo = au_sbi(sb);
11556 + fhsm = &sbinfo->si_fhsm;
11557 + AuDebugOn(!fhsm);
11558 + fhsm->fhsm_bottom = bindex;
11561 +/* ---------------------------------------------------------------------- */
11563 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11565 + struct au_br_fhsm *bf;
11567 + bf = br->br_fhsm;
11568 + MtxMustLock(&bf->bf_lock);
11570 + return !bf->bf_readable
11571 + || time_after(jiffies,
11572 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11575 +/* ---------------------------------------------------------------------- */
11577 +static void au_fhsm_notify(struct super_block *sb, int val)
11579 + struct au_sbinfo *sbinfo;
11580 + struct au_fhsm *fhsm;
11582 + SiMustAnyLock(sb);
11584 + sbinfo = au_sbi(sb);
11585 + fhsm = &sbinfo->si_fhsm;
11586 + if (au_fhsm_pid(fhsm)
11587 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11588 + atomic_set(&fhsm->fhsm_readable, val);
11590 + wake_up(&fhsm->fhsm_wqh);
11594 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11595 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11598 + struct au_branch *br;
11599 + struct au_br_fhsm *bf;
11601 + br = au_sbr(sb, bindex);
11602 + AuDebugOn(au_br_rdonly(br));
11603 + bf = br->br_fhsm;
11607 + mutex_lock(&bf->bf_lock);
11609 + MtxMustLock(&bf->bf_lock);
11611 + /* sb->s_root for NFS is unreliable */
11612 + err = au_br_stfs(br, &bf->bf_stfs);
11613 + if (unlikely(err)) {
11614 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11618 + bf->bf_jiffy = jiffies;
11619 + bf->bf_readable = 1;
11621 + au_fhsm_notify(sb, /*val*/1);
11623 + *rstfs = bf->bf_stfs;
11627 + mutex_unlock(&bf->bf_lock);
11628 + au_fhsm_notify(sb, /*val*/1);
11633 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11636 + struct au_sbinfo *sbinfo;
11637 + struct au_fhsm *fhsm;
11638 + struct au_branch *br;
11639 + struct au_br_fhsm *bf;
11641 + AuDbg("b%d, force %d\n", bindex, force);
11642 + SiMustAnyLock(sb);
11644 + sbinfo = au_sbi(sb);
11645 + fhsm = &sbinfo->si_fhsm;
11646 + if (!au_ftest_si(sbinfo, FHSM)
11647 + || fhsm->fhsm_bottom == bindex)
11650 + br = au_sbr(sb, bindex);
11651 + bf = br->br_fhsm;
11653 + mutex_lock(&bf->bf_lock);
11655 + || au_fhsm_pid(fhsm)
11656 + || au_fhsm_test_jiffy(sbinfo, br))
11657 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11659 + mutex_unlock(&bf->bf_lock);
11662 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11664 + aufs_bindex_t bindex, bend;
11665 + struct au_branch *br;
11667 + /* exclude the bottom */
11668 + bend = au_fhsm_bottom(sb);
11669 + for (bindex = 0; bindex < bend; bindex++) {
11670 + br = au_sbr(sb, bindex);
11671 + if (au_br_fhsm(br->br_perm))
11672 + au_fhsm_wrote(sb, bindex, force);
11676 +/* ---------------------------------------------------------------------- */
11678 +static unsigned int au_fhsm_poll(struct file *file,
11679 + struct poll_table_struct *wait)
11681 + unsigned int mask;
11682 + struct au_sbinfo *sbinfo;
11683 + struct au_fhsm *fhsm;
11686 + sbinfo = file->private_data;
11687 + fhsm = &sbinfo->si_fhsm;
11688 + poll_wait(file, &fhsm->fhsm_wqh, wait);
11689 + if (atomic_read(&fhsm->fhsm_readable))
11690 + mask = POLLIN /* | POLLRDNORM */;
11692 + AuTraceErr((int)mask);
11696 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
11697 + struct aufs_stfs *stfs, __s16 brid)
11701 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
11703 + err = __put_user(brid, &stbr->brid);
11704 + if (unlikely(err))
11710 +static ssize_t au_fhsm_do_read(struct super_block *sb,
11711 + struct aufs_stbr __user *stbr, size_t count)
11715 + aufs_bindex_t bindex, bend;
11716 + struct au_branch *br;
11717 + struct au_br_fhsm *bf;
11719 + /* except the bottom branch */
11722 + bend = au_fhsm_bottom(sb);
11723 + for (bindex = 0; !err && bindex < bend; bindex++) {
11724 + br = au_sbr(sb, bindex);
11725 + if (!au_br_fhsm(br->br_perm))
11728 + bf = br->br_fhsm;
11729 + mutex_lock(&bf->bf_lock);
11730 + if (bf->bf_readable) {
11732 + if (count >= sizeof(*stbr))
11733 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
11736 + bf->bf_readable = 0;
11737 + count -= sizeof(*stbr);
11741 + mutex_unlock(&bf->bf_lock);
11744 + err = sizeof(*stbr) * nstbr;
11749 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
11754 + aufs_bindex_t nfhsm, bindex, bend;
11755 + struct au_sbinfo *sbinfo;
11756 + struct au_fhsm *fhsm;
11757 + struct au_branch *br;
11758 + struct super_block *sb;
11761 + sbinfo = file->private_data;
11762 + fhsm = &sbinfo->si_fhsm;
11764 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
11765 + if (!atomic_read(&fhsm->fhsm_readable)) {
11766 + if (vfsub_file_flags(file) & O_NONBLOCK)
11769 + err = wait_event_interruptible_locked_irq
11771 + atomic_read(&fhsm->fhsm_readable));
11773 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
11774 + if (unlikely(err))
11777 + /* sb may already be dead */
11778 + au_rw_read_lock(&sbinfo->si_rwsem);
11779 + readable = atomic_read(&fhsm->fhsm_readable);
11780 + if (readable > 0) {
11781 + sb = sbinfo->si_sb;
11783 + /* exclude the bottom branch */
11785 + bend = au_fhsm_bottom(sb);
11786 + for (bindex = 0; bindex < bend; bindex++) {
11787 + br = au_sbr(sb, bindex);
11788 + if (au_br_fhsm(br->br_perm))
11792 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
11793 + atomic_set(&fhsm->fhsm_readable, 0);
11794 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
11798 + au_rw_read_unlock(&sbinfo->si_rwsem);
11806 +static int au_fhsm_release(struct inode *inode, struct file *file)
11808 + struct au_sbinfo *sbinfo;
11809 + struct au_fhsm *fhsm;
11811 + /* sb may already be dead */
11812 + sbinfo = file->private_data;
11813 + fhsm = &sbinfo->si_fhsm;
11814 + spin_lock(&fhsm->fhsm_spin);
11815 + fhsm->fhsm_pid = 0;
11816 + spin_unlock(&fhsm->fhsm_spin);
11817 + kobject_put(&sbinfo->si_kobj);
11822 +static const struct file_operations au_fhsm_fops = {
11823 + .owner = THIS_MODULE,
11824 + .llseek = noop_llseek,
11825 + .read = au_fhsm_read,
11826 + .poll = au_fhsm_poll,
11827 + .release = au_fhsm_release
11830 +int au_fhsm_fd(struct super_block *sb, int oflags)
11833 + struct au_sbinfo *sbinfo;
11834 + struct au_fhsm *fhsm;
11837 + if (unlikely(!capable(CAP_SYS_ADMIN)))
11841 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
11845 + sbinfo = au_sbi(sb);
11846 + fhsm = &sbinfo->si_fhsm;
11847 + spin_lock(&fhsm->fhsm_spin);
11848 + if (!fhsm->fhsm_pid)
11849 + fhsm->fhsm_pid = current->pid;
11852 + spin_unlock(&fhsm->fhsm_spin);
11853 + if (unlikely(err))
11856 + oflags |= O_RDONLY;
11857 + /* oflags |= FMODE_NONOTIFY; */
11858 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
11860 + if (unlikely(fd < 0))
11863 + /* succeed reglardless 'fhsm' status */
11864 + kobject_get(&sbinfo->si_kobj);
11865 + si_noflush_read_lock(sb);
11866 + if (au_ftest_si(sbinfo, FHSM))
11867 + au_fhsm_wrote_all(sb, /*force*/0);
11868 + si_read_unlock(sb);
11869 + goto out; /* success */
11872 + spin_lock(&fhsm->fhsm_spin);
11873 + fhsm->fhsm_pid = 0;
11874 + spin_unlock(&fhsm->fhsm_spin);
11880 +/* ---------------------------------------------------------------------- */
11882 +int au_fhsm_br_alloc(struct au_branch *br)
11887 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
11889 + au_br_fhsm_init(br->br_fhsm);
11896 +/* ---------------------------------------------------------------------- */
11898 +void au_fhsm_fin(struct super_block *sb)
11900 + au_fhsm_notify(sb, /*val*/-1);
11903 +void au_fhsm_init(struct au_sbinfo *sbinfo)
11905 + struct au_fhsm *fhsm;
11907 + fhsm = &sbinfo->si_fhsm;
11908 + spin_lock_init(&fhsm->fhsm_spin);
11909 + init_waitqueue_head(&fhsm->fhsm_wqh);
11910 + atomic_set(&fhsm->fhsm_readable, 0);
11911 + fhsm->fhsm_expire
11912 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
11913 + fhsm->fhsm_bottom = -1;
11916 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
11918 + sbinfo->si_fhsm.fhsm_expire
11919 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
11922 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
11926 + if (!au_ftest_si(sbinfo, FHSM))
11929 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
11930 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
11931 + seq_printf(seq, ",fhsm_sec=%u", u);
11933 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
11934 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
11935 +++ linux/fs/aufs/file.c 2015-06-22 08:29:23.706757681 +0200
11938 + * Copyright (C) 2005-2015 Junjiro R. Okajima
11940 + * This program, aufs is free software; you can redistribute it and/or modify
11941 + * it under the terms of the GNU General Public License as published by
11942 + * the Free Software Foundation; either version 2 of the License, or
11943 + * (at your option) any later version.
11945 + * This program is distributed in the hope that it will be useful,
11946 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11947 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11948 + * GNU General Public License for more details.
11950 + * You should have received a copy of the GNU General Public License
11951 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11955 + * handling file/dir, and address_space operation
11958 +#ifdef CONFIG_AUFS_DEBUG
11959 +#include <linux/migrate.h>
11961 +#include <linux/pagemap.h>
11964 +/* drop flags for writing */
11965 +unsigned int au_file_roflags(unsigned int flags)
11967 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
11968 + flags |= O_RDONLY | O_NOATIME;
11972 +/* common functions to regular file and dir */
11973 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11974 + struct file *file, int force_wr)
11976 + struct file *h_file;
11977 + struct dentry *h_dentry;
11978 + struct inode *h_inode;
11979 + struct super_block *sb;
11980 + struct au_branch *br;
11981 + struct path h_path;
11984 + /* a race condition can happen between open and unlink/rmdir */
11985 + h_file = ERR_PTR(-ENOENT);
11986 + h_dentry = au_h_dptr(dentry, bindex);
11987 + if (au_test_nfsd() && !h_dentry)
11989 + h_inode = h_dentry->d_inode;
11990 + if (au_test_nfsd() && !h_inode)
11992 + spin_lock(&h_dentry->d_lock);
11993 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
11995 + /* || !dentry->d_inode->i_nlink */
11997 + spin_unlock(&h_dentry->d_lock);
11998 + if (unlikely(err))
12001 + sb = dentry->d_sb;
12002 + br = au_sbr(sb, bindex);
12003 + err = au_br_test_oflag(flags, br);
12004 + h_file = ERR_PTR(err);
12005 + if (unlikely(err))
12008 + /* drop flags for writing */
12009 + if (au_test_ro(sb, bindex, dentry->d_inode)) {
12010 + if (force_wr && !(flags & O_WRONLY))
12012 + flags = au_file_roflags(flags);
12014 + h_file = ERR_PTR(-EROFS);
12015 + flags = au_file_roflags(flags);
12016 + if (unlikely(vfsub_native_ro(h_inode)
12017 + || IS_APPEND(h_inode)))
12019 + flags &= ~O_ACCMODE;
12020 + flags |= O_WRONLY;
12023 + flags &= ~O_CREAT;
12024 + atomic_inc(&br->br_count);
12025 + h_path.dentry = h_dentry;
12026 + h_path.mnt = au_br_mnt(br);
12027 + h_file = vfsub_dentry_open(&h_path, flags);
12028 + if (IS_ERR(h_file))
12031 + if (flags & __FMODE_EXEC) {
12032 + err = deny_write_access(h_file);
12033 + if (unlikely(err)) {
12035 + h_file = ERR_PTR(err);
12039 + fsnotify_open(h_file);
12040 + goto out; /* success */
12043 + atomic_dec(&br->br_count);
12048 +static int au_cmoo(struct dentry *dentry)
12051 + unsigned int udba;
12052 + struct path h_path;
12053 + struct au_pin pin;
12054 + struct au_cp_generic cpg = {
12055 + .dentry = dentry,
12060 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12062 + struct inode *delegated;
12063 + struct super_block *sb;
12064 + struct au_sbinfo *sbinfo;
12065 + struct au_fhsm *fhsm;
12067 + struct au_branch *br;
12068 + struct dentry *parent;
12069 + struct au_hinode *hdir;
12071 + DiMustWriteLock(dentry);
12072 + IiMustWriteLock(dentry->d_inode);
12075 + if (IS_ROOT(dentry))
12077 + cpg.bsrc = au_dbstart(dentry);
12081 + sb = dentry->d_sb;
12082 + sbinfo = au_sbi(sb);
12083 + fhsm = &sbinfo->si_fhsm;
12084 + pid = au_fhsm_pid(fhsm);
12086 + && (current->pid == pid
12087 + || current->real_parent->pid == pid))
12090 + br = au_sbr(sb, cpg.bsrc);
12091 + cmoo = au_br_cmoo(br->br_perm);
12094 + if (!d_is_reg(dentry))
12095 + cmoo &= AuBrAttr_COO_ALL;
12099 + parent = dget_parent(dentry);
12100 + di_write_lock_parent(parent);
12101 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12103 + if (unlikely(err < 0)) {
12104 + err = 0; /* there is no upper writable branch */
12107 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12109 + /* do not respect the coo attrib for the target branch */
12110 + err = au_cpup_dirs(dentry, cpg.bdst);
12111 + if (unlikely(err))
12114 + di_downgrade_lock(parent, AuLock_IR);
12115 + udba = au_opt_udba(sb);
12116 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12117 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12118 + if (unlikely(err))
12121 + err = au_sio_cpup_simple(&cpg);
12123 + if (unlikely(err))
12125 + if (!(cmoo & AuBrWAttr_MOO))
12126 + goto out_parent; /* success */
12128 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12129 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12130 + if (unlikely(err))
12133 + h_path.mnt = au_br_mnt(br);
12134 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12135 + hdir = au_hi(parent->d_inode, cpg.bsrc);
12136 + delegated = NULL;
12137 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12139 + /* todo: keep h_dentry or not? */
12140 + if (unlikely(err == -EWOULDBLOCK)) {
12141 + pr_warn("cannot retry for NFSv4 delegation"
12142 + " for an internal unlink\n");
12145 + if (unlikely(err)) {
12146 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12150 + goto out_parent; /* success */
12153 + di_downgrade_lock(parent, AuLock_IR);
12155 + di_read_unlock(parent, AuLock_IR);
12162 +int au_do_open(struct file *file, struct au_do_open_args *args)
12164 + int err, no_lock = args->no_lock;
12165 + struct dentry *dentry;
12166 + struct au_finfo *finfo;
12169 + err = au_finfo_init(file, args->fidir);
12172 + err = au_finfo_init(file, args->fidir);
12175 + if (unlikely(err))
12178 + dentry = file->f_path.dentry;
12179 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12181 + di_write_lock_child(dentry);
12182 + err = au_cmoo(dentry);
12183 + di_downgrade_lock(dentry, AuLock_IR);
12185 + err = args->open(file, vfsub_file_flags(file), NULL);
12186 + di_read_unlock(dentry, AuLock_IR);
12188 + err = au_cmoo(dentry);
12190 + err = args->open(file, vfsub_file_flags(file),
12192 + if (!err && au_fbstart(file) != au_dbstart(dentry))
12194 + * cmoo happens after h_file was opened.
12195 + * need to refresh file later.
12197 + atomic_dec(&au_fi(file)->fi_generation);
12200 + finfo = au_fi(file);
12202 + finfo->fi_file = file;
12203 + au_sphl_add(&finfo->fi_hlist,
12204 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12207 + fi_write_unlock(file);
12210 + fi_write_unlock(file);
12213 + if (unlikely(err)) {
12214 + finfo->fi_hdir = NULL;
12215 + au_finfo_fin(file);
12222 +int au_reopen_nondir(struct file *file)
12225 + aufs_bindex_t bstart;
12226 + struct dentry *dentry;
12227 + struct file *h_file, *h_file_tmp;
12229 + dentry = file->f_path.dentry;
12230 + bstart = au_dbstart(dentry);
12231 + h_file_tmp = NULL;
12232 + if (au_fbstart(file) == bstart) {
12233 + h_file = au_hf_top(file);
12234 + if (file->f_mode == h_file->f_mode)
12235 + return 0; /* success */
12236 + h_file_tmp = h_file;
12237 + get_file(h_file_tmp);
12238 + au_set_h_fptr(file, bstart, NULL);
12240 + AuDebugOn(au_fi(file)->fi_hdir);
12243 + * file exists on both of rw and ro
12244 + * open --> dbstart and fbstart are both 0
12245 + * prepend a branch as rw, "rw" become ro
12247 + * delete the top branch, "rw" becomes rw again
12248 + * --> dbstart is 1, fbstart is still 0
12249 + * write --> fbstart is 0 but dbstart is 1
12251 + /* AuDebugOn(au_fbstart(file) < bstart); */
12253 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
12254 + file, /*force_wr*/0);
12255 + err = PTR_ERR(h_file);
12256 + if (IS_ERR(h_file)) {
12257 + if (h_file_tmp) {
12258 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
12259 + au_set_h_fptr(file, bstart, h_file_tmp);
12260 + h_file_tmp = NULL;
12262 + goto out; /* todo: close all? */
12266 + au_set_fbstart(file, bstart);
12267 + au_set_h_fptr(file, bstart, h_file);
12268 + au_update_figen(file);
12269 + /* todo: necessary? */
12270 + /* file->f_ra = h_file->f_ra; */
12274 + fput(h_file_tmp);
12278 +/* ---------------------------------------------------------------------- */
12280 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12281 + struct dentry *hi_wh)
12284 + aufs_bindex_t bstart;
12285 + struct au_dinfo *dinfo;
12286 + struct dentry *h_dentry;
12287 + struct au_hdentry *hdp;
12289 + dinfo = au_di(file->f_path.dentry);
12290 + AuRwMustWriteLock(&dinfo->di_rwsem);
12292 + bstart = dinfo->di_bstart;
12293 + dinfo->di_bstart = btgt;
12294 + hdp = dinfo->di_hdentry;
12295 + h_dentry = hdp[0 + btgt].hd_dentry;
12296 + hdp[0 + btgt].hd_dentry = hi_wh;
12297 + err = au_reopen_nondir(file);
12298 + hdp[0 + btgt].hd_dentry = h_dentry;
12299 + dinfo->di_bstart = bstart;
12304 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12305 + aufs_bindex_t bcpup, struct au_pin *pin)
12308 + struct inode *inode, *h_inode;
12309 + struct dentry *h_dentry, *hi_wh;
12310 + struct au_cp_generic cpg = {
12311 + .dentry = file->f_path.dentry,
12318 + au_update_dbstart(cpg.dentry);
12319 + inode = cpg.dentry->d_inode;
12321 + if (au_dbstart(cpg.dentry) <= bcpup
12322 + && au_dbend(cpg.dentry) >= bcpup) {
12323 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12325 + h_inode = h_dentry->d_inode;
12327 + hi_wh = au_hi_wh(inode, bcpup);
12328 + if (!hi_wh && !h_inode)
12329 + err = au_sio_cpup_wh(&cpg, file);
12331 + /* already copied-up after unlink */
12332 + err = au_reopen_wh(file, bcpup, hi_wh);
12335 + && (inode->i_nlink > 1
12336 + || (inode->i_state & I_LINKABLE))
12337 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12338 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12344 + * prepare the @file for writing.
12346 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12349 + aufs_bindex_t dbstart;
12350 + struct dentry *parent;
12351 + struct inode *inode;
12352 + struct super_block *sb;
12353 + struct file *h_file;
12354 + struct au_cp_generic cpg = {
12355 + .dentry = file->f_path.dentry,
12360 + .flags = AuCpup_DTIME
12363 + sb = cpg.dentry->d_sb;
12364 + inode = cpg.dentry->d_inode;
12365 + cpg.bsrc = au_fbstart(file);
12366 + err = au_test_ro(sb, cpg.bsrc, inode);
12367 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12368 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12373 + /* need to cpup or reopen */
12374 + parent = dget_parent(cpg.dentry);
12375 + di_write_lock_parent(parent);
12376 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12378 + if (unlikely(err < 0))
12382 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12383 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12384 + if (unlikely(err))
12388 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12389 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12390 + if (unlikely(err))
12393 + dbstart = au_dbstart(cpg.dentry);
12394 + if (dbstart <= cpg.bdst)
12395 + cpg.bsrc = cpg.bdst;
12397 + if (dbstart <= cpg.bdst /* just reopen */
12398 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12400 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12401 + if (IS_ERR(h_file))
12402 + err = PTR_ERR(h_file);
12404 + di_downgrade_lock(parent, AuLock_IR);
12405 + if (dbstart > cpg.bdst)
12406 + err = au_sio_cpup_simple(&cpg);
12408 + err = au_reopen_nondir(file);
12409 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12411 + } else { /* copyup as wh and reopen */
12413 + * since writable hfsplus branch is not supported,
12414 + * h_open_pre/post() are unnecessary.
12416 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12417 + di_downgrade_lock(parent, AuLock_IR);
12421 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12422 + goto out_dput; /* success */
12428 + di_downgrade_lock(parent, AuLock_IR);
12430 + di_read_unlock(parent, AuLock_IR);
12437 +/* ---------------------------------------------------------------------- */
12439 +int au_do_flush(struct file *file, fl_owner_t id,
12440 + int (*flush)(struct file *file, fl_owner_t id))
12443 + struct super_block *sb;
12444 + struct inode *inode;
12446 + inode = file_inode(file);
12447 + sb = inode->i_sb;
12448 + si_noflush_read_lock(sb);
12449 + fi_read_lock(file);
12450 + ii_read_lock_child(inode);
12452 + err = flush(file, id);
12453 + au_cpup_attr_timesizes(inode);
12455 + ii_read_unlock(inode);
12456 + fi_read_unlock(file);
12457 + si_read_unlock(sb);
12461 +/* ---------------------------------------------------------------------- */
12463 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12466 + struct au_pin pin;
12467 + struct au_finfo *finfo;
12468 + struct dentry *parent, *hi_wh;
12469 + struct inode *inode;
12470 + struct super_block *sb;
12471 + struct au_cp_generic cpg = {
12472 + .dentry = file->f_path.dentry,
12477 + .flags = AuCpup_DTIME
12480 + FiMustWriteLock(file);
12483 + finfo = au_fi(file);
12484 + sb = cpg.dentry->d_sb;
12485 + inode = cpg.dentry->d_inode;
12486 + cpg.bdst = au_ibstart(inode);
12487 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12490 + parent = dget_parent(cpg.dentry);
12491 + if (au_test_ro(sb, cpg.bdst, inode)) {
12492 + di_read_lock_parent(parent, !AuLock_IR);
12493 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12495 + di_read_unlock(parent, !AuLock_IR);
12496 + if (unlikely(err < 0))
12501 + di_read_lock_parent(parent, AuLock_IR);
12502 + hi_wh = au_hi_wh(inode, cpg.bdst);
12503 + if (!S_ISDIR(inode->i_mode)
12504 + && au_opt_test(au_mntflags(sb), PLINK)
12505 + && au_plink_test(inode)
12506 + && !d_unhashed(cpg.dentry)
12507 + && cpg.bdst < au_dbstart(cpg.dentry)) {
12508 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12509 + if (unlikely(err))
12512 + /* always superio. */
12513 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12514 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12516 + err = au_sio_cpup_simple(&cpg);
12519 + } else if (hi_wh) {
12520 + /* already copied-up after unlink */
12521 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12522 + *need_reopen = 0;
12526 + di_read_unlock(parent, AuLock_IR);
12533 +static void au_do_refresh_dir(struct file *file)
12535 + aufs_bindex_t bindex, bend, new_bindex, brid;
12536 + struct au_hfile *p, tmp, *q;
12537 + struct au_finfo *finfo;
12538 + struct super_block *sb;
12539 + struct au_fidir *fidir;
12541 + FiMustWriteLock(file);
12543 + sb = file->f_path.dentry->d_sb;
12544 + finfo = au_fi(file);
12545 + fidir = finfo->fi_hdir;
12546 + AuDebugOn(!fidir);
12547 + p = fidir->fd_hfile + finfo->fi_btop;
12548 + brid = p->hf_br->br_id;
12549 + bend = fidir->fd_bbot;
12550 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
12554 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12555 + if (new_bindex == bindex)
12557 + if (new_bindex < 0) {
12558 + au_set_h_fptr(file, bindex, NULL);
12562 + /* swap two lower inode, and loop again */
12563 + q = fidir->fd_hfile + new_bindex;
12567 + if (tmp.hf_file) {
12573 + p = fidir->fd_hfile;
12574 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12575 + bend = au_sbend(sb);
12576 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
12577 + finfo->fi_btop++, p++)
12578 + if (p->hf_file) {
12579 + if (file_inode(p->hf_file))
12581 + au_hfput(p, file);
12584 + bend = au_br_index(sb, brid);
12585 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
12586 + finfo->fi_btop++, p++)
12588 + au_hfput(p, file);
12589 + bend = au_sbend(sb);
12592 + p = fidir->fd_hfile + bend;
12593 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
12594 + fidir->fd_bbot--, p--)
12595 + if (p->hf_file) {
12596 + if (file_inode(p->hf_file))
12598 + au_hfput(p, file);
12600 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12604 + * after branch manipulating, refresh the file.
12606 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12608 + int err, need_reopen;
12609 + aufs_bindex_t bend, bindex;
12610 + struct dentry *dentry;
12611 + struct au_finfo *finfo;
12612 + struct au_hfile *hfile;
12614 + dentry = file->f_path.dentry;
12615 + finfo = au_fi(file);
12616 + if (!finfo->fi_hdir) {
12617 + hfile = &finfo->fi_htop;
12618 + AuDebugOn(!hfile->hf_file);
12619 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
12620 + AuDebugOn(bindex < 0);
12621 + if (bindex != finfo->fi_btop)
12622 + au_set_fbstart(file, bindex);
12624 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
12625 + if (unlikely(err))
12627 + au_do_refresh_dir(file);
12632 + if (!au_test_mmapped(file))
12633 + err = au_file_refresh_by_inode(file, &need_reopen);
12634 + if (!err && need_reopen && !d_unlinked(dentry))
12635 + err = reopen(file);
12637 + au_update_figen(file);
12638 + goto out; /* success */
12641 + /* error, close all lower files */
12642 + if (finfo->fi_hdir) {
12643 + bend = au_fbend_dir(file);
12644 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
12645 + au_set_h_fptr(file, bindex, NULL);
12652 +/* common function to regular file and dir */
12653 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12657 + unsigned int sigen, figen;
12658 + aufs_bindex_t bstart;
12659 + unsigned char pseudo_link;
12660 + struct dentry *dentry;
12661 + struct inode *inode;
12664 + dentry = file->f_path.dentry;
12665 + inode = dentry->d_inode;
12666 + sigen = au_sigen(dentry->d_sb);
12667 + fi_write_lock(file);
12668 + figen = au_figen(file);
12669 + di_write_lock_child(dentry);
12670 + bstart = au_dbstart(dentry);
12671 + pseudo_link = (bstart != au_ibstart(inode));
12672 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
12674 + di_downgrade_lock(dentry, AuLock_IR);
12675 + fi_downgrade_lock(file);
12677 + goto out; /* success */
12680 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12681 + if (au_digen_test(dentry, sigen)) {
12682 + err = au_reval_dpath(dentry, sigen);
12683 + AuDebugOn(!err && au_digen_test(dentry, sigen));
12687 + err = refresh_file(file, reopen);
12690 + di_downgrade_lock(dentry, AuLock_IR);
12691 + fi_downgrade_lock(file);
12694 + di_write_unlock(dentry);
12695 + fi_write_unlock(file);
12702 +/* ---------------------------------------------------------------------- */
12704 +/* cf. aufs_nopage() */
12705 +/* for madvise(2) */
12706 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
12708 + unlock_page(page);
12712 +/* it will never be called, but necessary to support O_DIRECT */
12713 +static ssize_t aufs_direct_IO(int rw, struct kiocb *iocb,
12714 + struct iov_iter *iter, loff_t offset)
12715 +{ BUG(); return 0; }
12717 +/* they will never be called. */
12718 +#ifdef CONFIG_AUFS_DEBUG
12719 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
12720 + loff_t pos, unsigned len, unsigned flags,
12721 + struct page **pagep, void **fsdata)
12722 +{ AuUnsupport(); return 0; }
12723 +static int aufs_write_end(struct file *file, struct address_space *mapping,
12724 + loff_t pos, unsigned len, unsigned copied,
12725 + struct page *page, void *fsdata)
12726 +{ AuUnsupport(); return 0; }
12727 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
12728 +{ AuUnsupport(); return 0; }
12730 +static int aufs_set_page_dirty(struct page *page)
12731 +{ AuUnsupport(); return 0; }
12732 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
12733 + unsigned int length)
12734 +{ AuUnsupport(); }
12735 +static int aufs_releasepage(struct page *page, gfp_t gfp)
12736 +{ AuUnsupport(); return 0; }
12737 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
12738 + struct page *page, enum migrate_mode mode)
12739 +{ AuUnsupport(); return 0; }
12740 +static int aufs_launder_page(struct page *page)
12741 +{ AuUnsupport(); return 0; }
12742 +static int aufs_is_partially_uptodate(struct page *page,
12743 + unsigned long from,
12744 + unsigned long count)
12745 +{ AuUnsupport(); return 0; }
12746 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
12748 +{ AuUnsupport(); }
12749 +static int aufs_error_remove_page(struct address_space *mapping,
12750 + struct page *page)
12751 +{ AuUnsupport(); return 0; }
12752 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
12754 +{ AuUnsupport(); return 0; }
12755 +static void aufs_swap_deactivate(struct file *file)
12756 +{ AuUnsupport(); }
12757 +#endif /* CONFIG_AUFS_DEBUG */
12759 +const struct address_space_operations aufs_aop = {
12760 + .readpage = aufs_readpage,
12761 + .direct_IO = aufs_direct_IO,
12762 +#ifdef CONFIG_AUFS_DEBUG
12763 + .writepage = aufs_writepage,
12764 + /* no writepages, because of writepage */
12765 + .set_page_dirty = aufs_set_page_dirty,
12766 + /* no readpages, because of readpage */
12767 + .write_begin = aufs_write_begin,
12768 + .write_end = aufs_write_end,
12769 + /* no bmap, no block device */
12770 + .invalidatepage = aufs_invalidatepage,
12771 + .releasepage = aufs_releasepage,
12772 + .migratepage = aufs_migratepage,
12773 + .launder_page = aufs_launder_page,
12774 + .is_partially_uptodate = aufs_is_partially_uptodate,
12775 + .is_dirty_writeback = aufs_is_dirty_writeback,
12776 + .error_remove_page = aufs_error_remove_page,
12777 + .swap_activate = aufs_swap_activate,
12778 + .swap_deactivate = aufs_swap_deactivate
12779 +#endif /* CONFIG_AUFS_DEBUG */
12781 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
12782 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
12783 +++ linux/fs/aufs/file.h 2015-06-22 08:27:37.880835119 +0200
12786 + * Copyright (C) 2005-2015 Junjiro R. Okajima
12788 + * This program, aufs is free software; you can redistribute it and/or modify
12789 + * it under the terms of the GNU General Public License as published by
12790 + * the Free Software Foundation; either version 2 of the License, or
12791 + * (at your option) any later version.
12793 + * This program is distributed in the hope that it will be useful,
12794 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12795 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12796 + * GNU General Public License for more details.
12798 + * You should have received a copy of the GNU General Public License
12799 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12803 + * file operations
12806 +#ifndef __AUFS_FILE_H__
12807 +#define __AUFS_FILE_H__
12811 +#include <linux/file.h>
12812 +#include <linux/fs.h>
12813 +#include <linux/poll.h>
12814 +#include "rwsem.h"
12818 + struct file *hf_file;
12819 + struct au_branch *hf_br;
12824 + aufs_bindex_t fd_bbot;
12825 + aufs_bindex_t fd_nent;
12826 + struct au_vdir *fd_vdir_cache;
12827 + struct au_hfile fd_hfile[];
12830 +static inline int au_fidir_sz(int nent)
12832 + AuDebugOn(nent < 0);
12833 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
12837 + atomic_t fi_generation;
12839 + struct au_rwsem fi_rwsem;
12840 + aufs_bindex_t fi_btop;
12842 + /* do not union them */
12843 + struct { /* for non-dir */
12844 + struct au_hfile fi_htop;
12845 + atomic_t fi_mmapped;
12847 + struct au_fidir *fi_hdir; /* for dir only */
12849 + struct hlist_node fi_hlist;
12850 + struct file *fi_file; /* very ugly */
12851 +} ____cacheline_aligned_in_smp;
12853 +/* ---------------------------------------------------------------------- */
12856 +extern const struct address_space_operations aufs_aop;
12857 +unsigned int au_file_roflags(unsigned int flags);
12858 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12859 + struct file *file, int force_wr);
12860 +struct au_do_open_args {
12862 + int (*open)(struct file *file, int flags,
12863 + struct file *h_file);
12864 + struct au_fidir *fidir;
12865 + struct file *h_file;
12867 +int au_do_open(struct file *file, struct au_do_open_args *args);
12868 +int au_reopen_nondir(struct file *file);
12870 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
12871 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12873 +int au_do_flush(struct file *file, fl_owner_t id,
12874 + int (*flush)(struct file *file, fl_owner_t id));
12877 +#ifdef CONFIG_AUFS_POLL
12878 +unsigned int aufs_poll(struct file *file, poll_table *wait);
12881 +#ifdef CONFIG_AUFS_BR_HFSPLUS
12883 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
12885 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
12886 + struct file *h_file);
12888 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
12889 + aufs_bindex_t bindex, int force_wr)
12890 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
12891 + struct file *h_file);
12895 +extern const struct file_operations aufs_file_fop;
12896 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
12897 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
12898 +struct file *au_read_pre(struct file *file, int keep_fi);
12901 +void au_hfput(struct au_hfile *hf, struct file *file);
12902 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
12903 + struct file *h_file);
12905 +void au_update_figen(struct file *file);
12906 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
12907 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
12909 +void au_fi_init_once(void *_fi);
12910 +void au_finfo_fin(struct file *file);
12911 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
12914 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
12915 +#ifdef CONFIG_COMPAT
12916 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
12917 + unsigned long arg);
12918 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
12919 + unsigned long arg);
12922 +/* ---------------------------------------------------------------------- */
12924 +static inline struct au_finfo *au_fi(struct file *file)
12926 + return file->private_data;
12929 +/* ---------------------------------------------------------------------- */
12932 + * fi_read_lock, fi_write_lock,
12933 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
12935 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
12937 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
12938 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
12939 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
12941 +/* ---------------------------------------------------------------------- */
12943 +/* todo: hard/soft set? */
12944 +static inline aufs_bindex_t au_fbstart(struct file *file)
12946 + FiMustAnyLock(file);
12947 + return au_fi(file)->fi_btop;
12950 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
12952 + FiMustAnyLock(file);
12953 + AuDebugOn(!au_fi(file)->fi_hdir);
12954 + return au_fi(file)->fi_hdir->fd_bbot;
12957 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
12959 + FiMustAnyLock(file);
12960 + AuDebugOn(!au_fi(file)->fi_hdir);
12961 + return au_fi(file)->fi_hdir->fd_vdir_cache;
12964 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
12966 + FiMustWriteLock(file);
12967 + au_fi(file)->fi_btop = bindex;
12970 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
12972 + FiMustWriteLock(file);
12973 + AuDebugOn(!au_fi(file)->fi_hdir);
12974 + au_fi(file)->fi_hdir->fd_bbot = bindex;
12977 +static inline void au_set_fvdir_cache(struct file *file,
12978 + struct au_vdir *vdir_cache)
12980 + FiMustWriteLock(file);
12981 + AuDebugOn(!au_fi(file)->fi_hdir);
12982 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
12985 +static inline struct file *au_hf_top(struct file *file)
12987 + FiMustAnyLock(file);
12988 + AuDebugOn(au_fi(file)->fi_hdir);
12989 + return au_fi(file)->fi_htop.hf_file;
12992 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
12994 + FiMustAnyLock(file);
12995 + AuDebugOn(!au_fi(file)->fi_hdir);
12996 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
12999 +/* todo: memory barrier? */
13000 +static inline unsigned int au_figen(struct file *f)
13002 + return atomic_read(&au_fi(f)->fi_generation);
13005 +static inline void au_set_mmapped(struct file *f)
13007 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13009 + pr_warn("fi_mmapped wrapped around\n");
13010 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13014 +static inline void au_unset_mmapped(struct file *f)
13016 + atomic_dec(&au_fi(f)->fi_mmapped);
13019 +static inline int au_test_mmapped(struct file *f)
13021 + return atomic_read(&au_fi(f)->fi_mmapped);
13024 +/* customize vma->vm_file */
13026 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13027 + struct file *file)
13031 + f = vma->vm_file;
13033 + vma->vm_file = file;
13038 +#define AuDbgVmRegion(file, vma) do {} while (0)
13040 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13041 + struct file *file)
13043 + au_do_vm_file_reset(vma, file);
13046 +#define AuDbgVmRegion(file, vma) \
13047 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13049 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13050 + struct file *file)
13054 + au_do_vm_file_reset(vma, file);
13055 + f = vma->vm_region->vm_file;
13057 + vma->vm_region->vm_file = file;
13060 +#endif /* CONFIG_MMU */
13062 +/* handle vma->vm_prfile */
13063 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13064 + struct file *file)
13067 + vma->vm_prfile = file;
13068 +#ifndef CONFIG_MMU
13070 + vma->vm_region->vm_prfile = file;
13074 +#endif /* __KERNEL__ */
13075 +#endif /* __AUFS_FILE_H__ */
13076 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13077 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13078 +++ linux/fs/aufs/finfo.c 2015-06-22 08:29:23.706757681 +0200
13081 + * Copyright (C) 2005-2015 Junjiro R. Okajima
13083 + * This program, aufs is free software; you can redistribute it and/or modify
13084 + * it under the terms of the GNU General Public License as published by
13085 + * the Free Software Foundation; either version 2 of the License, or
13086 + * (at your option) any later version.
13088 + * This program is distributed in the hope that it will be useful,
13089 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13090 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13091 + * GNU General Public License for more details.
13093 + * You should have received a copy of the GNU General Public License
13094 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13098 + * file private data
13103 +void au_hfput(struct au_hfile *hf, struct file *file)
13105 + /* todo: direct access f_flags */
13106 + if (vfsub_file_flags(file) & __FMODE_EXEC)
13107 + allow_write_access(hf->hf_file);
13108 + fput(hf->hf_file);
13109 + hf->hf_file = NULL;
13110 + atomic_dec(&hf->hf_br->br_count);
13111 + hf->hf_br = NULL;
13114 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13116 + struct au_finfo *finfo = au_fi(file);
13117 + struct au_hfile *hf;
13118 + struct au_fidir *fidir;
13120 + fidir = finfo->fi_hdir;
13122 + AuDebugOn(finfo->fi_btop != bindex);
13123 + hf = &finfo->fi_htop;
13125 + hf = fidir->fd_hfile + bindex;
13127 + if (hf && hf->hf_file)
13128 + au_hfput(hf, file);
13130 + FiMustWriteLock(file);
13131 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13132 + hf->hf_file = val;
13133 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13137 +void au_update_figen(struct file *file)
13139 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13140 + /* smp_mb(); */ /* atomic_set */
13143 +/* ---------------------------------------------------------------------- */
13145 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13147 + struct au_fidir *fidir;
13150 + nbr = au_sbend(sb) + 1;
13152 + nbr = 2; /* initial allocate for 2 branches */
13153 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13155 + fidir->fd_bbot = -1;
13156 + fidir->fd_nent = nbr;
13157 + fidir->fd_vdir_cache = NULL;
13163 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
13166 + struct au_fidir *fidir, *p;
13168 + AuRwMustWriteLock(&finfo->fi_rwsem);
13169 + fidir = finfo->fi_hdir;
13170 + AuDebugOn(!fidir);
13173 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13176 + p->fd_nent = nbr;
13177 + finfo->fi_hdir = p;
13184 +/* ---------------------------------------------------------------------- */
13186 +void au_finfo_fin(struct file *file)
13188 + struct au_finfo *finfo;
13190 + au_nfiles_dec(file->f_path.dentry->d_sb);
13192 + finfo = au_fi(file);
13193 + AuDebugOn(finfo->fi_hdir);
13194 + AuRwDestroy(&finfo->fi_rwsem);
13195 + au_cache_free_finfo(finfo);
13198 +void au_fi_init_once(void *_finfo)
13200 + struct au_finfo *finfo = _finfo;
13201 + static struct lock_class_key aufs_fi;
13203 + au_rw_init(&finfo->fi_rwsem);
13204 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
13207 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13210 + struct au_finfo *finfo;
13211 + struct dentry *dentry;
13214 + dentry = file->f_path.dentry;
13215 + finfo = au_cache_alloc_finfo();
13216 + if (unlikely(!finfo))
13220 + au_nfiles_inc(dentry->d_sb);
13221 + /* verbose coding for lock class name */
13223 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
13225 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
13226 + au_rw_write_lock(&finfo->fi_rwsem);
13227 + finfo->fi_btop = -1;
13228 + finfo->fi_hdir = fidir;
13229 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13230 + /* smp_mb(); */ /* atomic_set */
13232 + file->private_data = finfo;
13237 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13238 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13239 +++ linux/fs/aufs/f_op.c 2015-06-22 08:29:23.706757681 +0200
13242 + * Copyright (C) 2005-2015 Junjiro R. Okajima
13244 + * This program, aufs is free software; you can redistribute it and/or modify
13245 + * it under the terms of the GNU General Public License as published by
13246 + * the Free Software Foundation; either version 2 of the License, or
13247 + * (at your option) any later version.
13249 + * This program is distributed in the hope that it will be useful,
13250 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13251 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13252 + * GNU General Public License for more details.
13254 + * You should have received a copy of the GNU General Public License
13255 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13259 + * file and vm operations
13262 +#include <linux/aio.h>
13263 +#include <linux/fs_stack.h>
13264 +#include <linux/mman.h>
13265 +#include <linux/security.h>
13268 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13271 + aufs_bindex_t bindex;
13272 + struct dentry *dentry;
13273 + struct au_finfo *finfo;
13274 + struct inode *h_inode;
13276 + FiMustWriteLock(file);
13279 + dentry = file->f_path.dentry;
13280 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13281 + finfo = au_fi(file);
13282 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13283 + atomic_set(&finfo->fi_mmapped, 0);
13284 + bindex = au_dbstart(dentry);
13286 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13288 + get_file(h_file);
13289 + if (IS_ERR(h_file))
13290 + err = PTR_ERR(h_file);
13292 + if ((flags & __O_TMPFILE)
13293 + && !(flags & O_EXCL)) {
13294 + h_inode = file_inode(h_file);
13295 + spin_lock(&h_inode->i_lock);
13296 + h_inode->i_state |= I_LINKABLE;
13297 + spin_unlock(&h_inode->i_lock);
13299 + au_set_fbstart(file, bindex);
13300 + au_set_h_fptr(file, bindex, h_file);
13301 + au_update_figen(file);
13302 + /* todo: necessary? */
13303 + /* file->f_ra = h_file->f_ra; */
13309 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13310 + struct file *file)
13313 + struct super_block *sb;
13314 + struct au_do_open_args args = {
13315 + .open = au_do_open_nondir
13318 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13319 + file, vfsub_file_flags(file), file->f_mode);
13321 + sb = file->f_path.dentry->d_sb;
13322 + si_read_lock(sb, AuLock_FLUSH);
13323 + err = au_do_open(file, &args);
13324 + si_read_unlock(sb);
13328 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13330 + struct au_finfo *finfo;
13331 + aufs_bindex_t bindex;
13333 + finfo = au_fi(file);
13334 + au_sphl_del(&finfo->fi_hlist,
13335 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13336 + bindex = finfo->fi_btop;
13338 + au_set_h_fptr(file, bindex, NULL);
13340 + au_finfo_fin(file);
13344 +/* ---------------------------------------------------------------------- */
13346 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13349 + struct file *h_file;
13352 + h_file = au_hf_top(file);
13354 + err = vfsub_flush(h_file, id);
13358 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13360 + return au_do_flush(file, id, au_do_flush_nondir);
13363 +/* ---------------------------------------------------------------------- */
13365 + * read and write functions acquire [fdi]_rwsem once, but release before
13366 + * mmap_sem. This is because to stop a race condition between mmap(2).
13367 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13368 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13369 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13372 +/* Callers should call au_read_post() or fput() in the end */
13373 +struct file *au_read_pre(struct file *file, int keep_fi)
13375 + struct file *h_file;
13378 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13380 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13381 + h_file = au_hf_top(file);
13382 + get_file(h_file);
13384 + fi_read_unlock(file);
13386 + h_file = ERR_PTR(err);
13391 +static void au_read_post(struct inode *inode, struct file *h_file)
13393 + /* update without lock, I don't think it a problem */
13394 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13398 +struct au_write_pre {
13400 + aufs_bindex_t bstart;
13404 + * return with iinfo is write-locked
13405 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13408 +static struct file *au_write_pre(struct file *file, int do_ready,
13409 + struct au_write_pre *wpre)
13411 + struct file *h_file;
13412 + struct dentry *dentry;
13414 + struct au_pin pin;
13416 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13417 + h_file = ERR_PTR(err);
13418 + if (unlikely(err))
13421 + dentry = file->f_path.dentry;
13423 + err = au_ready_to_write(file, -1, &pin);
13424 + if (unlikely(err)) {
13425 + h_file = ERR_PTR(err);
13426 + di_write_unlock(dentry);
13431 + di_downgrade_lock(dentry, /*flags*/0);
13433 + wpre->bstart = au_fbstart(file);
13434 + h_file = au_hf_top(file);
13435 + get_file(h_file);
13437 + wpre->blks = file_inode(h_file)->i_blocks;
13440 + di_read_unlock(dentry, /*flags*/0);
13443 + fi_write_unlock(file);
13448 +static void au_write_post(struct inode *inode, struct file *h_file,
13449 + struct au_write_pre *wpre, ssize_t written)
13451 + struct inode *h_inode;
13453 + au_cpup_attr_timesizes(inode);
13454 + AuDebugOn(au_ibstart(inode) != wpre->bstart);
13455 + h_inode = file_inode(h_file);
13456 + inode->i_mode = h_inode->i_mode;
13457 + ii_write_unlock(inode);
13460 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13462 + au_fhsm_wrote(inode->i_sb, wpre->bstart,
13463 + /*force*/h_inode->i_blocks > wpre->blks);
13466 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13470 + struct inode *inode;
13471 + struct file *h_file;
13472 + struct super_block *sb;
13474 + inode = file_inode(file);
13475 + sb = inode->i_sb;
13476 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13478 + h_file = au_read_pre(file, /*keep_fi*/0);
13479 + err = PTR_ERR(h_file);
13480 + if (IS_ERR(h_file))
13483 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13484 + err = vfsub_read_u(h_file, buf, count, ppos);
13485 + /* todo: necessary? */
13486 + /* file->f_ra = h_file->f_ra; */
13487 + au_read_post(inode, h_file);
13490 + si_read_unlock(sb);
13495 + * todo: very ugly
13496 + * it locks both of i_mutex and si_rwsem for read in safe.
13497 + * if the plink maintenance mode continues forever (that is the problem),
13498 + * may loop forever.
13500 +static void au_mtx_and_read_lock(struct inode *inode)
13503 + struct super_block *sb = inode->i_sb;
13506 + mutex_lock(&inode->i_mutex);
13507 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13510 + mutex_unlock(&inode->i_mutex);
13511 + si_read_lock(sb, AuLock_NOPLMW);
13512 + si_read_unlock(sb);
13516 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13517 + size_t count, loff_t *ppos)
13520 + struct au_write_pre wpre;
13521 + struct inode *inode;
13522 + struct file *h_file;
13523 + char __user *buf = (char __user *)ubuf;
13525 + inode = file_inode(file);
13526 + au_mtx_and_read_lock(inode);
13528 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13529 + err = PTR_ERR(h_file);
13530 + if (IS_ERR(h_file))
13533 + err = vfsub_write_u(h_file, buf, count, ppos);
13534 + au_write_post(inode, h_file, &wpre, err);
13537 + si_read_unlock(inode->i_sb);
13538 + mutex_unlock(&inode->i_mutex);
13542 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13543 + struct iov_iter *iov_iter)
13546 + struct file *file;
13547 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13548 + ssize_t (*aio)(struct kiocb *, const struct iovec *, unsigned long,
13551 + err = security_file_permission(h_file, rw);
13552 + if (unlikely(err))
13558 + if (rw == MAY_READ) {
13559 + iter = h_file->f_op->read_iter;
13560 + aio = h_file->f_op->aio_read;
13561 + } else if (rw == MAY_WRITE) {
13562 + iter = h_file->f_op->write_iter;
13563 + aio = h_file->f_op->aio_write;
13566 + file = kio->ki_filp;
13567 + kio->ki_filp = h_file;
13570 + err = iter(kio, iov_iter);
13572 + } else if (aio) {
13574 + err = aio(kio, iov_iter->iov, iov_iter->nr_segs, kio->ki_pos);
13577 + /* currently there is no such fs */
13579 + kio->ki_filp = file;
13585 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13588 + struct file *file, *h_file;
13589 + struct inode *inode;
13590 + struct super_block *sb;
13592 + file = kio->ki_filp;
13593 + inode = file_inode(file);
13594 + sb = inode->i_sb;
13595 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13597 + h_file = au_read_pre(file, /*keep_fi*/0);
13598 + err = PTR_ERR(h_file);
13599 + if (IS_ERR(h_file))
13602 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13603 + /* todo: necessary? */
13604 + /* file->f_ra = h_file->f_ra; */
13605 + au_read_post(inode, h_file);
13608 + si_read_unlock(sb);
13612 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13615 + struct au_write_pre wpre;
13616 + struct inode *inode;
13617 + struct file *file, *h_file;
13619 + file = kio->ki_filp;
13620 + inode = file_inode(file);
13621 + au_mtx_and_read_lock(inode);
13623 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13624 + err = PTR_ERR(h_file);
13625 + if (IS_ERR(h_file))
13628 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13629 + au_write_post(inode, h_file, &wpre, err);
13632 + si_read_unlock(inode->i_sb);
13633 + mutex_unlock(&inode->i_mutex);
13637 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13638 + struct pipe_inode_info *pipe, size_t len,
13639 + unsigned int flags)
13642 + struct file *h_file;
13643 + struct inode *inode;
13644 + struct super_block *sb;
13646 + inode = file_inode(file);
13647 + sb = inode->i_sb;
13648 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13650 + h_file = au_read_pre(file, /*keep_fi*/1);
13651 + err = PTR_ERR(h_file);
13652 + if (IS_ERR(h_file))
13655 + if (au_test_loopback_kthread()) {
13656 + au_warn_loopback(h_file->f_path.dentry->d_sb);
13657 + if (file->f_mapping != h_file->f_mapping) {
13658 + file->f_mapping = h_file->f_mapping;
13659 + smp_mb(); /* unnecessary? */
13662 + fi_read_unlock(file);
13664 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13665 + /* todo: necessasry? */
13666 + /* file->f_ra = h_file->f_ra; */
13667 + au_read_post(inode, h_file);
13670 + si_read_unlock(sb);
13675 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
13676 + size_t len, unsigned int flags)
13679 + struct au_write_pre wpre;
13680 + struct inode *inode;
13681 + struct file *h_file;
13683 + inode = file_inode(file);
13684 + au_mtx_and_read_lock(inode);
13686 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13687 + err = PTR_ERR(h_file);
13688 + if (IS_ERR(h_file))
13691 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
13692 + au_write_post(inode, h_file, &wpre, err);
13695 + si_read_unlock(inode->i_sb);
13696 + mutex_unlock(&inode->i_mutex);
13700 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
13704 + struct au_write_pre wpre;
13705 + struct inode *inode;
13706 + struct file *h_file;
13708 + inode = file_inode(file);
13709 + au_mtx_and_read_lock(inode);
13711 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13712 + err = PTR_ERR(h_file);
13713 + if (IS_ERR(h_file))
13717 + err = vfs_fallocate(h_file, mode, offset, len);
13719 + au_write_post(inode, h_file, &wpre, /*written*/1);
13722 + si_read_unlock(inode->i_sb);
13723 + mutex_unlock(&inode->i_mutex);
13727 +/* ---------------------------------------------------------------------- */
13730 + * The locking order around current->mmap_sem.
13731 + * - in most and regular cases
13732 + * file I/O syscall -- aufs_read() or something
13733 + * -- si_rwsem for read -- mmap_sem
13734 + * (Note that [fdi]i_rwsem are released before mmap_sem).
13736 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
13737 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
13738 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
13739 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
13740 + * It means that when aufs acquires si_rwsem for write, the process should never
13741 + * acquire mmap_sem.
13743 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
13744 + * problem either since any directory is not able to be mmap-ed.
13745 + * The similar scenario is applied to aufs_readlink() too.
13748 +#if 0 /* stop calling security_file_mmap() */
13749 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
13750 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
13752 +static unsigned long au_arch_prot_conv(unsigned long flags)
13754 + /* currently ppc64 only */
13755 +#ifdef CONFIG_PPC64
13756 + /* cf. linux/arch/powerpc/include/asm/mman.h */
13757 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
13758 + return AuConv_VM_PROT(flags, SAO);
13760 + AuDebugOn(arch_calc_vm_prot_bits(-1));
13765 +static unsigned long au_prot_conv(unsigned long flags)
13767 + return AuConv_VM_PROT(flags, READ)
13768 + | AuConv_VM_PROT(flags, WRITE)
13769 + | AuConv_VM_PROT(flags, EXEC)
13770 + | au_arch_prot_conv(flags);
13773 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
13774 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
13776 +static unsigned long au_flag_conv(unsigned long flags)
13778 + return AuConv_VM_MAP(flags, GROWSDOWN)
13779 + | AuConv_VM_MAP(flags, DENYWRITE)
13780 + | AuConv_VM_MAP(flags, LOCKED);
13784 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
13787 + const unsigned char wlock
13788 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
13789 + struct super_block *sb;
13790 + struct file *h_file;
13791 + struct inode *inode;
13793 + AuDbgVmRegion(file, vma);
13795 + inode = file_inode(file);
13796 + sb = inode->i_sb;
13798 + si_read_lock(sb, AuLock_NOPLMW);
13800 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
13802 + err = PTR_ERR(h_file);
13803 + if (IS_ERR(h_file))
13807 + au_set_mmapped(file);
13808 + au_vm_file_reset(vma, h_file);
13810 + * we cannot call security_mmap_file() here since it may acquire
13811 + * mmap_sem or i_mutex.
13813 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
13814 + * au_flag_conv(vma->vm_flags));
13817 + err = h_file->f_op->mmap(h_file, vma);
13819 + au_vm_prfile_set(vma, file);
13820 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13821 + goto out_fput; /* success */
13823 + au_unset_mmapped(file);
13824 + au_vm_file_reset(vma, file);
13828 + ii_write_unlock(inode);
13833 + si_read_unlock(sb);
13839 +/* ---------------------------------------------------------------------- */
13841 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
13845 + struct au_write_pre wpre;
13846 + struct inode *inode;
13847 + struct file *h_file;
13849 + err = 0; /* -EBADF; */ /* posix? */
13850 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13853 + inode = file_inode(file);
13854 + au_mtx_and_read_lock(inode);
13856 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13857 + err = PTR_ERR(h_file);
13858 + if (IS_ERR(h_file))
13861 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
13862 + au_write_post(inode, h_file, &wpre, /*written*/0);
13865 + si_read_unlock(inode->i_sb);
13866 + mutex_unlock(&inode->i_mutex);
13871 +/* no one supports this operation, currently */
13873 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
13876 + struct au_write_pre wpre;
13877 + struct inode *inode;
13878 + struct file *file, *h_file;
13880 + err = 0; /* -EBADF; */ /* posix? */
13881 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13884 + file = kio->ki_filp;
13885 + inode = file_inode(file);
13886 + au_mtx_and_read_lock(inode);
13888 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13889 + err = PTR_ERR(h_file);
13890 + if (IS_ERR(h_file))
13894 + h_file = au_hf_top(file);
13895 + if (h_file->f_op->aio_fsync) {
13896 + struct mutex *h_mtx;
13898 + h_mtx = &file_inode(h_file)->i_mutex;
13899 + if (!is_sync_kiocb(kio)) {
13900 + get_file(h_file);
13903 + kio->ki_filp = h_file;
13904 + err = h_file->f_op->aio_fsync(kio, datasync);
13905 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13907 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
13909 + mutex_unlock(h_mtx);
13911 + au_write_post(inode, h_file, &wpre, /*written*/0);
13914 + si_read_unlock(inode->sb);
13915 + mutex_unlock(&inode->i_mutex);
13921 +static int aufs_fasync(int fd, struct file *file, int flag)
13924 + struct file *h_file;
13925 + struct super_block *sb;
13927 + sb = file->f_path.dentry->d_sb;
13928 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13930 + h_file = au_read_pre(file, /*keep_fi*/0);
13931 + err = PTR_ERR(h_file);
13932 + if (IS_ERR(h_file))
13935 + if (h_file->f_op->fasync)
13936 + err = h_file->f_op->fasync(fd, h_file, flag);
13937 + fput(h_file); /* instead of au_read_post() */
13940 + si_read_unlock(sb);
13944 +/* ---------------------------------------------------------------------- */
13946 +/* no one supports this operation, currently */
13948 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
13949 + size_t len, loff_t *pos, int more)
13954 +/* ---------------------------------------------------------------------- */
13956 +const struct file_operations aufs_file_fop = {
13957 + .owner = THIS_MODULE,
13959 + .llseek = default_llseek,
13961 + .read = aufs_read,
13962 + .write = aufs_write,
13963 + .read_iter = aufs_read_iter,
13964 + .write_iter = aufs_write_iter,
13966 +#ifdef CONFIG_AUFS_POLL
13967 + .poll = aufs_poll,
13969 + .unlocked_ioctl = aufs_ioctl_nondir,
13970 +#ifdef CONFIG_COMPAT
13971 + .compat_ioctl = aufs_compat_ioctl_nondir,
13973 + .mmap = aufs_mmap,
13974 + .open = aufs_open_nondir,
13975 + .flush = aufs_flush_nondir,
13976 + .release = aufs_release_nondir,
13977 + .fsync = aufs_fsync_nondir,
13978 + /* .aio_fsync = aufs_aio_fsync_nondir, */
13979 + .fasync = aufs_fasync,
13980 + /* .sendpage = aufs_sendpage, */
13981 + .splice_write = aufs_splice_write,
13982 + .splice_read = aufs_splice_read,
13984 + .aio_splice_write = aufs_aio_splice_write,
13985 + .aio_splice_read = aufs_aio_splice_read,
13987 + .fallocate = aufs_fallocate
13989 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
13990 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
13991 +++ linux/fs/aufs/fstype.h 2015-06-22 08:27:37.880835119 +0200
13994 + * Copyright (C) 2005-2015 Junjiro R. Okajima
13996 + * This program, aufs is free software; you can redistribute it and/or modify
13997 + * it under the terms of the GNU General Public License as published by
13998 + * the Free Software Foundation; either version 2 of the License, or
13999 + * (at your option) any later version.
14001 + * This program is distributed in the hope that it will be useful,
14002 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14003 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14004 + * GNU General Public License for more details.
14006 + * You should have received a copy of the GNU General Public License
14007 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14011 + * judging filesystem type
14014 +#ifndef __AUFS_FSTYPE_H__
14015 +#define __AUFS_FSTYPE_H__
14019 +#include <linux/fs.h>
14020 +#include <linux/magic.h>
14021 +#include <linux/romfs_fs.h>
14022 +#include <linux/nfs_fs.h>
14024 +static inline int au_test_aufs(struct super_block *sb)
14026 + return sb->s_magic == AUFS_SUPER_MAGIC;
14029 +static inline const char *au_sbtype(struct super_block *sb)
14031 + return sb->s_type->name;
14034 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14036 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
14037 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14043 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14045 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
14046 + return sb->s_magic == ROMFS_MAGIC;
14052 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14054 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
14055 + return sb->s_magic == CRAMFS_MAGIC;
14060 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14062 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
14063 + return sb->s_magic == NFS_SUPER_MAGIC;
14069 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14071 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
14072 + return sb->s_magic == FUSE_SUPER_MAGIC;
14078 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14080 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
14081 + return sb->s_magic == XFS_SB_MAGIC;
14087 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14089 +#ifdef CONFIG_TMPFS
14090 + return sb->s_magic == TMPFS_MAGIC;
14096 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14098 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
14099 + return !strcmp(au_sbtype(sb), "ecryptfs");
14105 +static inline int au_test_ramfs(struct super_block *sb)
14107 + return sb->s_magic == RAMFS_MAGIC;
14110 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14112 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
14113 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14119 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14121 +#ifdef CONFIG_PROC_FS
14122 + return sb->s_magic == PROC_SUPER_MAGIC;
14128 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14130 +#ifdef CONFIG_SYSFS
14131 + return sb->s_magic == SYSFS_MAGIC;
14137 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14139 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
14140 + return sb->s_magic == CONFIGFS_MAGIC;
14146 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14148 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
14149 + return sb->s_magic == MINIX3_SUPER_MAGIC
14150 + || sb->s_magic == MINIX2_SUPER_MAGIC
14151 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14152 + || sb->s_magic == MINIX_SUPER_MAGIC
14153 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14159 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14161 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
14162 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14168 +static inline int au_test_msdos(struct super_block *sb)
14170 + return au_test_fat(sb);
14173 +static inline int au_test_vfat(struct super_block *sb)
14175 + return au_test_fat(sb);
14178 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14180 +#ifdef CONFIG_SECURITYFS
14181 + return sb->s_magic == SECURITYFS_MAGIC;
14187 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14189 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
14190 + return sb->s_magic == SQUASHFS_MAGIC;
14196 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14198 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
14199 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14205 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14207 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
14208 + return sb->s_magic == XENFS_SUPER_MAGIC;
14214 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14216 +#ifdef CONFIG_DEBUG_FS
14217 + return sb->s_magic == DEBUGFS_MAGIC;
14223 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14225 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
14226 + return sb->s_magic == NILFS_SUPER_MAGIC;
14232 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14234 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
14235 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14241 +/* ---------------------------------------------------------------------- */
14243 + * they can't be an aufs branch.
14245 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14248 +#ifndef CONFIG_AUFS_BR_RAMFS
14249 + au_test_ramfs(sb) ||
14251 + au_test_procfs(sb)
14252 + || au_test_sysfs(sb)
14253 + || au_test_configfs(sb)
14254 + || au_test_debugfs(sb)
14255 + || au_test_securityfs(sb)
14256 + || au_test_xenfs(sb)
14257 + || au_test_ecryptfs(sb)
14258 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14259 + || au_test_aufs(sb); /* will be supported in next version */
14262 +static inline int au_test_fs_remote(struct super_block *sb)
14264 + return !au_test_tmpfs(sb)
14265 +#ifdef CONFIG_AUFS_BR_RAMFS
14266 + && !au_test_ramfs(sb)
14268 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14271 +/* ---------------------------------------------------------------------- */
14274 + * Note: these functions (below) are created after reading ->getattr() in all
14275 + * filesystems under linux/fs. it means we have to do so in every update...
14279 + * some filesystems require getattr to refresh the inode attributes before
14281 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14282 + * and leave the work for d_revalidate()
14284 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14286 + return au_test_nfs(sb)
14287 + || au_test_fuse(sb)
14288 + /* || au_test_btrfs(sb) */ /* untested */
14293 + * filesystems which don't maintain i_size or i_blocks.
14295 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14297 + return au_test_xfs(sb)
14298 + || au_test_btrfs(sb)
14299 + || au_test_ubifs(sb)
14300 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14301 + /* || au_test_minix(sb) */ /* untested */
14306 + * filesystems which don't store the correct value in some of their inode
14309 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14311 + return au_test_fs_bad_iattr_size(sb)
14312 + || au_test_fat(sb)
14313 + || au_test_msdos(sb)
14314 + || au_test_vfat(sb);
14317 +/* they don't check i_nlink in link(2) */
14318 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14320 + return au_test_tmpfs(sb)
14321 +#ifdef CONFIG_AUFS_BR_RAMFS
14322 + || au_test_ramfs(sb)
14324 + || au_test_ubifs(sb)
14325 + || au_test_hfsplus(sb);
14329 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14331 +static inline int au_test_fs_notime(struct super_block *sb)
14333 + return au_test_nfs(sb)
14334 + || au_test_fuse(sb)
14335 + || au_test_ubifs(sb)
14339 +/* temporary support for i#1 in cramfs */
14340 +static inline int au_test_fs_unique_ino(struct inode *inode)
14342 + if (au_test_cramfs(inode->i_sb))
14343 + return inode->i_ino != 1;
14347 +/* ---------------------------------------------------------------------- */
14350 + * the filesystem where the xino files placed must support i/o after unlink and
14351 + * maintain i_size and i_blocks.
14353 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14355 + return au_test_fs_remote(sb)
14356 + || au_test_fs_bad_iattr_size(sb)
14357 + /* don't want unnecessary work for xino */
14358 + || au_test_aufs(sb)
14359 + || au_test_ecryptfs(sb)
14360 + || au_test_nilfs(sb);
14363 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14365 + return au_test_tmpfs(sb)
14366 + || au_test_ramfs(sb);
14370 + * test if the @sb is real-readonly.
14372 +static inline int au_test_fs_rr(struct super_block *sb)
14374 + return au_test_squashfs(sb)
14375 + || au_test_iso9660(sb)
14376 + || au_test_cramfs(sb)
14377 + || au_test_romfs(sb);
14381 + * test if the @inode is nfs with 'noacl' option
14382 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14384 +static inline int au_test_nfs_noacl(struct inode *inode)
14386 + return au_test_nfs(inode->i_sb)
14387 + /* && IS_POSIXACL(inode) */
14388 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14391 +#endif /* __KERNEL__ */
14392 +#endif /* __AUFS_FSTYPE_H__ */
14393 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14394 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14395 +++ linux/fs/aufs/hfsnotify.c 2015-06-22 08:27:37.880835119 +0200
14398 + * Copyright (C) 2005-2015 Junjiro R. Okajima
14400 + * This program, aufs is free software; you can redistribute it and/or modify
14401 + * it under the terms of the GNU General Public License as published by
14402 + * the Free Software Foundation; either version 2 of the License, or
14403 + * (at your option) any later version.
14405 + * This program is distributed in the hope that it will be useful,
14406 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14407 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14408 + * GNU General Public License for more details.
14410 + * You should have received a copy of the GNU General Public License
14411 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14415 + * fsnotify for the lower directories
14420 +/* FS_IN_IGNORED is unnecessary */
14421 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14422 + | FS_CREATE | FS_EVENT_ON_CHILD);
14423 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14424 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14426 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14428 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14431 + au_cache_free_hnotify(hn);
14432 + smp_mb__before_atomic();
14433 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14434 + wake_up(&au_hfsn_wq);
14437 +static int au_hfsn_alloc(struct au_hinode *hinode)
14440 + struct au_hnotify *hn;
14441 + struct super_block *sb;
14442 + struct au_branch *br;
14443 + struct fsnotify_mark *mark;
14444 + aufs_bindex_t bindex;
14446 + hn = hinode->hi_notify;
14447 + sb = hn->hn_aufs_inode->i_sb;
14448 + bindex = au_br_index(sb, hinode->hi_id);
14449 + br = au_sbr(sb, bindex);
14450 + AuDebugOn(!br->br_hfsn);
14452 + mark = &hn->hn_mark;
14453 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14454 + mark->mask = AuHfsnMask;
14456 + * by udba rename or rmdir, aufs assign a new inode to the known
14457 + * h_inode, so specify 1 to allow dups.
14460 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14461 + /*mnt*/NULL, /*allow_dups*/1);
14462 + /* even if err */
14463 + fsnotify_put_mark(mark);
14469 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14471 + struct fsnotify_mark *mark;
14472 + unsigned long long ull;
14473 + struct fsnotify_group *group;
14475 + ull = atomic64_inc_return(&au_hfsn_ifree);
14478 + mark = &hn->hn_mark;
14479 + spin_lock(&mark->lock);
14480 + group = mark->group;
14481 + fsnotify_get_group(group);
14482 + spin_unlock(&mark->lock);
14484 + fsnotify_destroy_mark(mark, group);
14485 + fsnotify_put_group(group);
14488 + /* free hn by myself */
14492 +/* ---------------------------------------------------------------------- */
14494 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14496 + struct fsnotify_mark *mark;
14498 + mark = &hinode->hi_notify->hn_mark;
14499 + spin_lock(&mark->lock);
14501 + AuDebugOn(mark->mask & AuHfsnMask);
14502 + mark->mask |= AuHfsnMask;
14504 + AuDebugOn(!(mark->mask & AuHfsnMask));
14505 + mark->mask &= ~AuHfsnMask;
14507 + spin_unlock(&mark->lock);
14508 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14511 +/* ---------------------------------------------------------------------- */
14513 +/* #define AuDbgHnotify */
14514 +#ifdef AuDbgHnotify
14515 +static char *au_hfsn_name(u32 mask)
14517 +#ifdef CONFIG_AUFS_DEBUG
14518 +#define test_ret(flag) \
14520 + if (mask & flag) \
14523 + test_ret(FS_ACCESS);
14524 + test_ret(FS_MODIFY);
14525 + test_ret(FS_ATTRIB);
14526 + test_ret(FS_CLOSE_WRITE);
14527 + test_ret(FS_CLOSE_NOWRITE);
14528 + test_ret(FS_OPEN);
14529 + test_ret(FS_MOVED_FROM);
14530 + test_ret(FS_MOVED_TO);
14531 + test_ret(FS_CREATE);
14532 + test_ret(FS_DELETE);
14533 + test_ret(FS_DELETE_SELF);
14534 + test_ret(FS_MOVE_SELF);
14535 + test_ret(FS_UNMOUNT);
14536 + test_ret(FS_Q_OVERFLOW);
14537 + test_ret(FS_IN_IGNORED);
14538 + test_ret(FS_ISDIR);
14539 + test_ret(FS_IN_ONESHOT);
14540 + test_ret(FS_EVENT_ON_CHILD);
14549 +/* ---------------------------------------------------------------------- */
14551 +static void au_hfsn_free_group(struct fsnotify_group *group)
14553 + struct au_br_hfsnotify *hfsn = group->private;
14559 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14560 + struct inode *inode,
14561 + struct fsnotify_mark *inode_mark,
14562 + struct fsnotify_mark *vfsmount_mark,
14563 + u32 mask, void *data, int data_type,
14564 + const unsigned char *file_name, u32 cookie)
14567 + struct au_hnotify *hnotify;
14568 + struct inode *h_dir, *h_inode;
14569 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14571 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14574 + /* if FS_UNMOUNT happens, there must be another bug */
14575 + AuDebugOn(mask & FS_UNMOUNT);
14576 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14581 +#ifdef AuDbgHnotify
14583 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14584 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14585 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14586 + h_dir->i_ino, mask, au_hfsn_name(mask),
14587 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14588 + /* WARN_ON(1); */
14593 + AuDebugOn(!inode_mark);
14594 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14595 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14601 +static struct fsnotify_ops au_hfsn_ops = {
14602 + .handle_event = au_hfsn_handle_event,
14603 + .free_group_priv = au_hfsn_free_group
14606 +/* ---------------------------------------------------------------------- */
14608 +static void au_hfsn_fin_br(struct au_branch *br)
14610 + struct au_br_hfsnotify *hfsn;
14612 + hfsn = br->br_hfsn;
14615 + fsnotify_put_group(hfsn->hfsn_group);
14620 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14623 + struct fsnotify_group *group;
14624 + struct au_br_hfsnotify *hfsn;
14627 + br->br_hfsn = NULL;
14628 + if (!au_br_hnotifyable(perm))
14632 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14633 + if (unlikely(!hfsn))
14637 + group = fsnotify_alloc_group(&au_hfsn_ops);
14638 + if (IS_ERR(group)) {
14639 + err = PTR_ERR(group);
14640 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14644 + group->private = hfsn;
14645 + hfsn->hfsn_group = group;
14646 + br->br_hfsn = hfsn;
14647 + goto out; /* success */
14655 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14660 + if (!br->br_hfsn)
14661 + err = au_hfsn_init_br(br, perm);
14666 +/* ---------------------------------------------------------------------- */
14668 +static void au_hfsn_fin(void)
14670 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14671 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14674 +const struct au_hnotify_op au_hnotify_op = {
14675 + .ctl = au_hfsn_ctl,
14676 + .alloc = au_hfsn_alloc,
14677 + .free = au_hfsn_free,
14679 + .fin = au_hfsn_fin,
14681 + .reset_br = au_hfsn_reset_br,
14682 + .fin_br = au_hfsn_fin_br,
14683 + .init_br = au_hfsn_init_br
14685 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14686 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14687 +++ linux/fs/aufs/hfsplus.c 2015-06-22 08:29:23.706757681 +0200
14690 + * Copyright (C) 2010-2015 Junjiro R. Okajima
14692 + * This program, aufs is free software; you can redistribute it and/or modify
14693 + * it under the terms of the GNU General Public License as published by
14694 + * the Free Software Foundation; either version 2 of the License, or
14695 + * (at your option) any later version.
14697 + * This program is distributed in the hope that it will be useful,
14698 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14699 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14700 + * GNU General Public License for more details.
14702 + * You should have received a copy of the GNU General Public License
14703 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14707 + * special support for filesystems which aqucires an inode mutex
14708 + * at final closing a file, eg, hfsplus.
14710 + * This trick is very simple and stupid, just to open the file before really
14711 + * neceeary open to tell hfsplus that this is not the final closing.
14712 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14713 + * and au_h_open_post() after releasing it.
14718 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14721 + struct file *h_file;
14722 + struct dentry *h_dentry;
14724 + h_dentry = au_h_dptr(dentry, bindex);
14725 + AuDebugOn(!h_dentry);
14726 + AuDebugOn(!h_dentry->d_inode);
14729 + if (au_test_hfsplus(h_dentry->d_sb)
14730 + && d_is_reg(h_dentry))
14731 + h_file = au_h_open(dentry, bindex,
14732 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14733 + /*file*/NULL, force_wr);
14737 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14738 + struct file *h_file)
14742 + au_sbr_put(dentry->d_sb, bindex);
14745 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
14746 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14747 +++ linux/fs/aufs/hnotify.c 2015-06-22 08:29:23.706757681 +0200
14750 + * Copyright (C) 2005-2015 Junjiro R. Okajima
14752 + * This program, aufs is free software; you can redistribute it and/or modify
14753 + * it under the terms of the GNU General Public License as published by
14754 + * the Free Software Foundation; either version 2 of the License, or
14755 + * (at your option) any later version.
14757 + * This program is distributed in the hope that it will be useful,
14758 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14759 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14760 + * GNU General Public License for more details.
14762 + * You should have received a copy of the GNU General Public License
14763 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14767 + * abstraction to notify the direct changes on lower directories
14772 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14775 + struct au_hnotify *hn;
14778 + hn = au_cache_alloc_hnotify();
14780 + hn->hn_aufs_inode = inode;
14781 + hinode->hi_notify = hn;
14782 + err = au_hnotify_op.alloc(hinode);
14784 + if (unlikely(err)) {
14785 + hinode->hi_notify = NULL;
14786 + au_cache_free_hnotify(hn);
14788 + * The upper dir was removed by udba, but the same named
14789 + * dir left. In this case, aufs assignes a new inode
14790 + * number and set the monitor again.
14791 + * For the lower dir, the old monitnor is still left.
14793 + if (err == -EEXIST)
14802 +void au_hn_free(struct au_hinode *hinode)
14804 + struct au_hnotify *hn;
14806 + hn = hinode->hi_notify;
14808 + hinode->hi_notify = NULL;
14809 + if (au_hnotify_op.free(hinode, hn))
14810 + au_cache_free_hnotify(hn);
14814 +/* ---------------------------------------------------------------------- */
14816 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
14818 + if (hinode->hi_notify)
14819 + au_hnotify_op.ctl(hinode, do_set);
14822 +void au_hn_reset(struct inode *inode, unsigned int flags)
14824 + aufs_bindex_t bindex, bend;
14825 + struct inode *hi;
14826 + struct dentry *iwhdentry;
14828 + bend = au_ibend(inode);
14829 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14830 + hi = au_h_iptr(inode, bindex);
14834 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
14835 + iwhdentry = au_hi_wh(inode, bindex);
14839 + au_set_h_iptr(inode, bindex, NULL, 0);
14840 + au_set_h_iptr(inode, bindex, au_igrab(hi),
14841 + flags & ~AuHi_XINO);
14844 + /* mutex_unlock(&hi->i_mutex); */
14848 +/* ---------------------------------------------------------------------- */
14850 +static int hn_xino(struct inode *inode, struct inode *h_inode)
14853 + aufs_bindex_t bindex, bend, bfound, bstart;
14854 + struct inode *h_i;
14857 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14858 + pr_warn("branch root dir was changed\n");
14863 + bend = au_ibend(inode);
14864 + bstart = au_ibstart(inode);
14865 +#if 0 /* reserved for future use */
14866 + if (bindex == bend) {
14867 + /* keep this ino in rename case */
14871 + for (bindex = bstart; bindex <= bend; bindex++)
14872 + if (au_h_iptr(inode, bindex) == h_inode) {
14879 + for (bindex = bstart; bindex <= bend; bindex++) {
14880 + h_i = au_h_iptr(inode, bindex);
14884 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
14885 + /* ignore this error */
14886 + /* bad action? */
14889 + /* children inode number will be broken */
14896 +static int hn_gen_tree(struct dentry *dentry)
14898 + int err, i, j, ndentry;
14899 + struct au_dcsub_pages dpages;
14900 + struct au_dpage *dpage;
14901 + struct dentry **dentries;
14903 + err = au_dpages_init(&dpages, GFP_NOFS);
14904 + if (unlikely(err))
14906 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
14907 + if (unlikely(err))
14910 + for (i = 0; i < dpages.ndpage; i++) {
14911 + dpage = dpages.dpages + i;
14912 + dentries = dpage->dentries;
14913 + ndentry = dpage->ndentry;
14914 + for (j = 0; j < ndentry; j++) {
14915 + struct dentry *d;
14923 + /* todo: reset children xino?
14924 + cached children only? */
14925 + au_iigen_dec(d->d_inode);
14930 + au_dpages_free(&dpages);
14933 + /* discard children */
14934 + dentry_unhash(dentry);
14942 + * return 0 if processed.
14944 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
14945 + const unsigned int isdir)
14948 + struct dentry *d;
14949 + struct qstr *dname;
14952 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14953 + pr_warn("branch root dir was changed\n");
14959 + AuDebugOn(!name);
14960 + au_iigen_dec(inode);
14961 + spin_lock(&inode->i_lock);
14962 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
14963 + spin_lock(&d->d_lock);
14964 + dname = &d->d_name;
14965 + if (dname->len != nlen
14966 + && memcmp(dname->name, name, nlen)) {
14967 + spin_unlock(&d->d_lock);
14972 + spin_unlock(&d->d_lock);
14975 + spin_unlock(&inode->i_lock);
14977 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
14978 + d = d_find_any_alias(inode);
14980 + au_iigen_dec(inode);
14984 + spin_lock(&d->d_lock);
14985 + dname = &d->d_name;
14986 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
14987 + spin_unlock(&d->d_lock);
14988 + err = hn_gen_tree(d);
14989 + spin_lock(&d->d_lock);
14991 + spin_unlock(&d->d_lock);
15000 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15003 + struct inode *inode;
15005 + inode = dentry->d_inode;
15006 + if (IS_ROOT(dentry)
15007 + /* || (inode && inode->i_ino == AUFS_ROOT_INO) */
15009 + pr_warn("branch root dir was changed\n");
15015 + au_digen_dec(dentry);
15017 + au_iigen_dec(inode);
15019 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15021 + err = hn_gen_tree(dentry);
15028 +/* ---------------------------------------------------------------------- */
15030 +/* hnotify job flags */
15031 +#define AuHnJob_XINO0 1
15032 +#define AuHnJob_GEN (1 << 1)
15033 +#define AuHnJob_DIRENT (1 << 2)
15034 +#define AuHnJob_ISDIR (1 << 3)
15035 +#define AuHnJob_TRYXINO0 (1 << 4)
15036 +#define AuHnJob_MNTPNT (1 << 5)
15037 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15038 +#define au_fset_hnjob(flags, name) \
15039 + do { (flags) |= AuHnJob_##name; } while (0)
15040 +#define au_fclr_hnjob(flags, name) \
15041 + do { (flags) &= ~AuHnJob_##name; } while (0)
15049 +struct au_hnotify_args {
15050 + struct inode *h_dir, *dir, *h_child_inode;
15052 + unsigned int flags[AuHnLast];
15053 + unsigned int h_child_nlen;
15054 + char h_child_name[];
15057 +struct hn_job_args {
15058 + unsigned int flags;
15059 + struct inode *inode, *h_inode, *dir, *h_dir;
15060 + struct dentry *dentry;
15065 +static int hn_job(struct hn_job_args *a)
15067 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15071 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15072 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15074 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15077 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
15078 + if (!a->h_inode->i_nlink
15079 + && !(a->h_inode->i_state & I_LINKABLE))
15080 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15081 + mutex_unlock(&a->h_inode->i_mutex);
15084 + /* make the generation obsolete */
15085 + if (au_ftest_hnjob(a->flags, GEN)) {
15088 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15090 + if (e && a->dentry)
15091 + hn_gen_by_name(a->dentry, isdir);
15092 + /* ignore this error */
15095 + /* make dir entries obsolete */
15096 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15097 + struct au_vdir *vdir;
15099 + vdir = au_ivdir(a->inode);
15101 + vdir->vd_jiffy = 0;
15102 + /* IMustLock(a->inode); */
15103 + /* a->inode->i_version++; */
15106 + /* can do nothing but warn */
15107 + if (au_ftest_hnjob(a->flags, MNTPNT)
15109 + && d_mountpoint(a->dentry))
15110 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15115 +/* ---------------------------------------------------------------------- */
15117 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15118 + struct inode *dir)
15120 + struct dentry *dentry, *d, *parent;
15121 + struct qstr *dname;
15123 + parent = d_find_any_alias(dir);
15128 + spin_lock(&parent->d_lock);
15129 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15130 + /* AuDbg("%pd\n", d); */
15131 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15132 + dname = &d->d_name;
15133 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15134 + goto cont_unlock;
15138 + goto cont_unlock;
15139 + if (au_dcount(d) > 0) {
15140 + dentry = dget_dlock(d);
15141 + spin_unlock(&d->d_lock);
15146 + spin_unlock(&d->d_lock);
15148 + spin_unlock(&parent->d_lock);
15152 + di_write_lock_child(dentry);
15157 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15158 + aufs_bindex_t bindex, ino_t h_ino)
15160 + struct inode *inode;
15165 + err = au_xino_read(sb, bindex, h_ino, &ino);
15167 + inode = ilookup(sb, ino);
15171 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15172 + pr_warn("wrong root branch\n");
15178 + ii_write_lock_child(inode);
15184 +static void au_hn_bh(void *_args)
15186 + struct au_hnotify_args *a = _args;
15187 + struct super_block *sb;
15188 + aufs_bindex_t bindex, bend, bfound;
15189 + unsigned char xino, try_iput;
15191 + struct inode *inode;
15193 + struct hn_job_args args;
15194 + struct dentry *dentry;
15195 + struct au_sbinfo *sbinfo;
15197 + AuDebugOn(!_args);
15198 + AuDebugOn(!a->h_dir);
15199 + AuDebugOn(!a->dir);
15200 + AuDebugOn(!a->mask);
15201 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15202 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15203 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15208 + * do not lock a->dir->i_mutex here
15209 + * because of d_revalidate() may cause a deadlock.
15211 + sb = a->dir->i_sb;
15213 + sbinfo = au_sbi(sb);
15214 + AuDebugOn(!sbinfo);
15215 + si_write_lock(sb, AuLock_NOPLMW);
15217 + ii_read_lock_parent(a->dir);
15219 + bend = au_ibend(a->dir);
15220 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
15221 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15225 + ii_read_unlock(a->dir);
15226 + if (unlikely(bfound < 0))
15229 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15231 + if (a->h_child_inode)
15232 + h_ino = a->h_child_inode->i_ino;
15234 + if (a->h_child_nlen
15235 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15236 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15237 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15241 + inode = dentry->d_inode;
15242 + if (xino && !inode && h_ino
15243 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15244 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15245 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15246 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15250 + args.flags = a->flags[AuHn_CHILD];
15251 + args.dentry = dentry;
15252 + args.inode = inode;
15253 + args.h_inode = a->h_child_inode;
15254 + args.dir = a->dir;
15255 + args.h_dir = a->h_dir;
15256 + args.h_name = a->h_child_name;
15257 + args.h_nlen = a->h_child_nlen;
15258 + err = hn_job(&args);
15260 + if (au_di(dentry))
15261 + di_write_unlock(dentry);
15264 + if (inode && try_iput) {
15265 + ii_write_unlock(inode);
15269 + ii_write_lock_parent(a->dir);
15270 + args.flags = a->flags[AuHn_PARENT];
15271 + args.dentry = NULL;
15272 + args.inode = a->dir;
15273 + args.h_inode = a->h_dir;
15275 + args.h_dir = NULL;
15276 + args.h_name = NULL;
15278 + err = hn_job(&args);
15279 + ii_write_unlock(a->dir);
15282 + iput(a->h_child_inode);
15285 + si_write_unlock(sb);
15286 + au_nwt_done(&sbinfo->si_nowait);
15290 +/* ---------------------------------------------------------------------- */
15292 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15293 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15296 + unsigned int flags[AuHnLast], f;
15297 + unsigned char isdir, isroot, wh;
15298 + struct inode *dir;
15299 + struct au_hnotify_args *args;
15300 + char *p, *h_child_name;
15303 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15304 + dir = igrab(hnotify->hn_aufs_inode);
15308 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15310 + h_child_name = (void *)h_child_qstr->name;
15311 + len = h_child_qstr->len;
15312 + if (h_child_name) {
15313 + if (len > AUFS_WH_PFX_LEN
15314 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15315 + h_child_name += AUFS_WH_PFX_LEN;
15316 + len -= AUFS_WH_PFX_LEN;
15322 + if (h_child_inode)
15323 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15324 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15325 + flags[AuHn_CHILD] = 0;
15327 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15328 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15329 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15330 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15331 + case FS_MOVED_FROM:
15332 + case FS_MOVED_TO:
15333 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15334 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15337 + AuDebugOn(!h_child_name);
15342 + * aufs never be able to get this child inode.
15343 + * revalidation should be in d_revalidate()
15344 + * by checking i_nlink, i_generation or d_unhashed().
15346 + AuDebugOn(!h_child_name);
15347 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15348 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15356 + h_child_inode = NULL;
15359 + /* iput() and kfree() will be called in au_hnotify() */
15360 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15361 + if (unlikely(!args)) {
15362 + AuErr1("no memory\n");
15366 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15367 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15368 + args->mask = mask;
15370 + args->h_dir = igrab(h_dir);
15371 + if (h_child_inode)
15372 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15373 + args->h_child_inode = h_child_inode;
15374 + args->h_child_nlen = len;
15376 + p = (void *)args;
15377 + p += sizeof(*args);
15378 + memcpy(p, h_child_name, len);
15382 + /* NFS fires the event for silly-renamed one from kworker */
15384 + if (!dir->i_nlink
15385 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15387 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15388 + if (unlikely(err)) {
15389 + pr_err("wkq %d\n", err);
15390 + iput(args->h_child_inode);
15391 + iput(args->h_dir);
15400 +/* ---------------------------------------------------------------------- */
15402 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15406 + AuDebugOn(!(udba & AuOptMask_UDBA));
15409 + if (au_hnotify_op.reset_br)
15410 + err = au_hnotify_op.reset_br(udba, br, perm);
15415 +int au_hnotify_init_br(struct au_branch *br, int perm)
15420 + if (au_hnotify_op.init_br)
15421 + err = au_hnotify_op.init_br(br, perm);
15426 +void au_hnotify_fin_br(struct au_branch *br)
15428 + if (au_hnotify_op.fin_br)
15429 + au_hnotify_op.fin_br(br);
15432 +static void au_hn_destroy_cache(void)
15434 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15435 + au_cachep[AuCache_HNOTIFY] = NULL;
15438 +int __init au_hnotify_init(void)
15443 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15444 + if (au_cachep[AuCache_HNOTIFY]) {
15446 + if (au_hnotify_op.init)
15447 + err = au_hnotify_op.init();
15448 + if (unlikely(err))
15449 + au_hn_destroy_cache();
15455 +void au_hnotify_fin(void)
15457 + if (au_hnotify_op.fin)
15458 + au_hnotify_op.fin();
15459 + /* cf. au_cache_fin() */
15460 + if (au_cachep[AuCache_HNOTIFY])
15461 + au_hn_destroy_cache();
15463 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15464 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15465 +++ linux/fs/aufs/iinfo.c 2015-06-22 08:27:37.884168534 +0200
15468 + * Copyright (C) 2005-2015 Junjiro R. Okajima
15470 + * This program, aufs is free software; you can redistribute it and/or modify
15471 + * it under the terms of the GNU General Public License as published by
15472 + * the Free Software Foundation; either version 2 of the License, or
15473 + * (at your option) any later version.
15475 + * This program is distributed in the hope that it will be useful,
15476 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15477 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15478 + * GNU General Public License for more details.
15480 + * You should have received a copy of the GNU General Public License
15481 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15485 + * inode private data
15490 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15492 + struct inode *h_inode;
15494 + IiMustAnyLock(inode);
15496 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
15497 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15501 +/* todo: hard/soft set? */
15502 +void au_hiput(struct au_hinode *hinode)
15504 + au_hn_free(hinode);
15505 + dput(hinode->hi_whdentry);
15506 + iput(hinode->hi_inode);
15509 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15511 + unsigned int flags;
15512 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15515 + if (au_opt_test(mnt_flags, XINO))
15516 + au_fset_hi(flags, XINO);
15517 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15518 + au_fset_hi(flags, HNOTIFY);
15522 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15523 + struct inode *h_inode, unsigned int flags)
15525 + struct au_hinode *hinode;
15526 + struct inode *hi;
15527 + struct au_iinfo *iinfo = au_ii(inode);
15529 + IiMustWriteLock(inode);
15531 + hinode = iinfo->ii_hinode + bindex;
15532 + hi = hinode->hi_inode;
15533 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15536 + au_hiput(hinode);
15537 + hinode->hi_inode = h_inode;
15540 + struct super_block *sb = inode->i_sb;
15541 + struct au_branch *br;
15543 + AuDebugOn(inode->i_mode
15544 + && (h_inode->i_mode & S_IFMT)
15545 + != (inode->i_mode & S_IFMT));
15546 + if (bindex == iinfo->ii_bstart)
15547 + au_cpup_igen(inode, h_inode);
15548 + br = au_sbr(sb, bindex);
15549 + hinode->hi_id = br->br_id;
15550 + if (au_ftest_hi(flags, XINO)) {
15551 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15553 + if (unlikely(err))
15554 + AuIOErr1("failed au_xino_write() %d\n", err);
15557 + if (au_ftest_hi(flags, HNOTIFY)
15558 + && au_br_hnotifyable(br->br_perm)) {
15559 + err = au_hn_alloc(hinode, inode);
15560 + if (unlikely(err))
15561 + AuIOErr1("au_hn_alloc() %d\n", err);
15566 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15567 + struct dentry *h_wh)
15569 + struct au_hinode *hinode;
15571 + IiMustWriteLock(inode);
15573 + hinode = au_ii(inode)->ii_hinode + bindex;
15574 + AuDebugOn(hinode->hi_whdentry);
15575 + hinode->hi_whdentry = h_wh;
15578 +void au_update_iigen(struct inode *inode, int half)
15580 + struct au_iinfo *iinfo;
15581 + struct au_iigen *iigen;
15582 + unsigned int sigen;
15584 + sigen = au_sigen(inode->i_sb);
15585 + iinfo = au_ii(inode);
15586 + iigen = &iinfo->ii_generation;
15587 + spin_lock(&iinfo->ii_genspin);
15588 + iigen->ig_generation = sigen;
15590 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15592 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15593 + spin_unlock(&iinfo->ii_genspin);
15596 +/* it may be called at remount time, too */
15597 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15599 + struct au_iinfo *iinfo;
15600 + aufs_bindex_t bindex, bend;
15602 + iinfo = au_ii(inode);
15606 + IiMustWriteLock(inode);
15608 + if (do_put_zero && iinfo->ii_bstart >= 0) {
15609 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15611 + struct inode *h_i;
15613 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
15616 + && !(h_i->i_state & I_LINKABLE))
15617 + au_set_h_iptr(inode, bindex, NULL, 0);
15621 + iinfo->ii_bstart = -1;
15622 + iinfo->ii_bend = -1;
15623 + bend = au_sbend(inode->i_sb);
15624 + for (bindex = 0; bindex <= bend; bindex++)
15625 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15626 + iinfo->ii_bstart = bindex;
15629 + if (iinfo->ii_bstart >= 0)
15630 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
15631 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15632 + iinfo->ii_bend = bindex;
15635 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
15638 +/* ---------------------------------------------------------------------- */
15640 +void au_icntnr_init_once(void *_c)
15642 + struct au_icntnr *c = _c;
15643 + struct au_iinfo *iinfo = &c->iinfo;
15644 + static struct lock_class_key aufs_ii;
15646 + spin_lock_init(&iinfo->ii_genspin);
15647 + au_rw_init(&iinfo->ii_rwsem);
15648 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
15649 + inode_init_once(&c->vfs_inode);
15652 +int au_iinfo_init(struct inode *inode)
15654 + struct au_iinfo *iinfo;
15655 + struct super_block *sb;
15658 + sb = inode->i_sb;
15659 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15660 + nbr = au_sbend(sb) + 1;
15661 + if (unlikely(nbr <= 0))
15663 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15664 + if (iinfo->ii_hinode) {
15665 + au_ninodes_inc(sb);
15666 + for (i = 0; i < nbr; i++)
15667 + iinfo->ii_hinode[i].hi_id = -1;
15669 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15670 + iinfo->ii_bstart = -1;
15671 + iinfo->ii_bend = -1;
15672 + iinfo->ii_vdir = NULL;
15678 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
15681 + struct au_hinode *hip;
15683 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15686 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
15688 + sz = sizeof(*hip);
15689 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
15691 + iinfo->ii_hinode = hip;
15698 +void au_iinfo_fin(struct inode *inode)
15700 + struct au_iinfo *iinfo;
15701 + struct au_hinode *hi;
15702 + struct super_block *sb;
15703 + aufs_bindex_t bindex, bend;
15704 + const unsigned char unlinked = !inode->i_nlink;
15706 + iinfo = au_ii(inode);
15707 + /* bad_inode case */
15711 + sb = inode->i_sb;
15712 + au_ninodes_dec(sb);
15713 + if (si_pid_test(sb))
15714 + au_xino_delete_inode(inode, unlinked);
15717 + * it is safe to hide the dependency between sbinfo and
15721 + si_noflush_read_lock(sb);
15722 + au_xino_delete_inode(inode, unlinked);
15723 + si_read_unlock(sb);
15727 + if (iinfo->ii_vdir)
15728 + au_vdir_free(iinfo->ii_vdir);
15730 + bindex = iinfo->ii_bstart;
15731 + if (bindex >= 0) {
15732 + hi = iinfo->ii_hinode + bindex;
15733 + bend = iinfo->ii_bend;
15734 + while (bindex++ <= bend) {
15735 + if (hi->hi_inode)
15740 + kfree(iinfo->ii_hinode);
15741 + iinfo->ii_hinode = NULL;
15742 + AuRwDestroy(&iinfo->ii_rwsem);
15744 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
15745 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
15746 +++ linux/fs/aufs/inode.c 2015-06-22 08:27:37.884168534 +0200
15749 + * Copyright (C) 2005-2015 Junjiro R. Okajima
15751 + * This program, aufs is free software; you can redistribute it and/or modify
15752 + * it under the terms of the GNU General Public License as published by
15753 + * the Free Software Foundation; either version 2 of the License, or
15754 + * (at your option) any later version.
15756 + * This program is distributed in the hope that it will be useful,
15757 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15758 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15759 + * GNU General Public License for more details.
15761 + * You should have received a copy of the GNU General Public License
15762 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15766 + * inode functions
15771 +struct inode *au_igrab(struct inode *inode)
15774 + AuDebugOn(!atomic_read(&inode->i_count));
15780 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
15782 + au_cpup_attr_all(inode, /*force*/0);
15783 + au_update_iigen(inode, /*half*/1);
15785 + inode->i_version++;
15788 +static int au_ii_refresh(struct inode *inode, int *update)
15792 + aufs_bindex_t bindex, new_bindex;
15793 + struct super_block *sb;
15794 + struct au_iinfo *iinfo;
15795 + struct au_hinode *p, *q, tmp;
15797 + IiMustWriteLock(inode);
15800 + sb = inode->i_sb;
15801 + type = inode->i_mode & S_IFMT;
15802 + iinfo = au_ii(inode);
15803 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
15804 + if (unlikely(err))
15807 + AuDebugOn(iinfo->ii_bstart < 0);
15808 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15809 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15811 + if (!p->hi_inode)
15814 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
15815 + new_bindex = au_br_index(sb, p->hi_id);
15816 + if (new_bindex == bindex)
15819 + if (new_bindex < 0) {
15822 + p->hi_inode = NULL;
15826 + if (new_bindex < iinfo->ii_bstart)
15827 + iinfo->ii_bstart = new_bindex;
15828 + if (iinfo->ii_bend < new_bindex)
15829 + iinfo->ii_bend = new_bindex;
15830 + /* swap two lower inode, and loop again */
15831 + q = iinfo->ii_hinode + new_bindex;
15835 + if (tmp.hi_inode) {
15840 + au_update_ibrange(inode, /*do_put_zero*/0);
15841 + e = au_dy_irefresh(inode);
15842 + if (unlikely(e && !err))
15850 +int au_refresh_hinode_self(struct inode *inode)
15854 + err = au_ii_refresh(inode, &update);
15856 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
15862 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
15864 + int err, e, update;
15865 + unsigned int flags;
15867 + aufs_bindex_t bindex, bend;
15868 + unsigned char isdir;
15869 + struct au_hinode *p;
15870 + struct au_iinfo *iinfo;
15872 + err = au_ii_refresh(inode, &update);
15873 + if (unlikely(err))
15877 + iinfo = au_ii(inode);
15878 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15879 + mode = (inode->i_mode & S_IFMT);
15880 + isdir = S_ISDIR(mode);
15881 + flags = au_hi_flags(inode, isdir);
15882 + bend = au_dbend(dentry);
15883 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
15884 + struct inode *h_i;
15885 + struct dentry *h_d;
15887 + h_d = au_h_dptr(dentry, bindex);
15888 + if (!h_d || !h_d->d_inode)
15891 + AuDebugOn(mode != (h_d->d_inode->i_mode & S_IFMT));
15892 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
15893 + h_i = au_h_iptr(inode, bindex);
15895 + if (h_i == h_d->d_inode)
15901 + if (bindex < iinfo->ii_bstart)
15902 + iinfo->ii_bstart = bindex;
15903 + if (iinfo->ii_bend < bindex)
15904 + iinfo->ii_bend = bindex;
15905 + au_set_h_iptr(inode, bindex, au_igrab(h_d->d_inode), flags);
15908 + au_update_ibrange(inode, /*do_put_zero*/0);
15909 + e = au_dy_irefresh(inode);
15910 + if (unlikely(e && !err))
15913 + au_refresh_hinode_attr(inode, update && isdir);
15920 +static int set_inode(struct inode *inode, struct dentry *dentry)
15923 + unsigned int flags;
15925 + aufs_bindex_t bindex, bstart, btail;
15926 + unsigned char isdir;
15927 + struct dentry *h_dentry;
15928 + struct inode *h_inode;
15929 + struct au_iinfo *iinfo;
15931 + IiMustWriteLock(inode);
15935 + bstart = au_dbstart(dentry);
15936 + h_inode = au_h_dptr(dentry, bstart)->d_inode;
15937 + mode = h_inode->i_mode;
15938 + switch (mode & S_IFMT) {
15940 + btail = au_dbtail(dentry);
15941 + inode->i_op = &aufs_iop;
15942 + inode->i_fop = &aufs_file_fop;
15943 + err = au_dy_iaop(inode, bstart, h_inode);
15944 + if (unlikely(err))
15949 + btail = au_dbtaildir(dentry);
15950 + inode->i_op = &aufs_dir_iop;
15951 + inode->i_fop = &aufs_dir_fop;
15954 + btail = au_dbtail(dentry);
15955 + inode->i_op = &aufs_symlink_iop;
15961 + btail = au_dbtail(dentry);
15962 + inode->i_op = &aufs_iop;
15963 + init_special_inode(inode, mode, h_inode->i_rdev);
15966 + AuIOErr("Unknown file type 0%o\n", mode);
15971 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
15972 + flags = au_hi_flags(inode, isdir);
15973 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
15974 + && au_ftest_hi(flags, HNOTIFY)
15975 + && dentry->d_name.len > AUFS_WH_PFX_LEN
15976 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
15977 + au_fclr_hi(flags, HNOTIFY);
15978 + iinfo = au_ii(inode);
15979 + iinfo->ii_bstart = bstart;
15980 + iinfo->ii_bend = btail;
15981 + for (bindex = bstart; bindex <= btail; bindex++) {
15982 + h_dentry = au_h_dptr(dentry, bindex);
15984 + au_set_h_iptr(inode, bindex,
15985 + au_igrab(h_dentry->d_inode), flags);
15987 + au_cpup_attr_all(inode, /*force*/1);
15989 + * to force calling aufs_get_acl() every time,
15990 + * do not call cache_no_acl() for aufs inode.
15998 + * successful returns with iinfo write_locked
16000 + * zero: success, matched
16001 + * plus: no error, but unmatched
16003 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16006 + unsigned int gen;
16007 + struct au_iigen iigen;
16008 + aufs_bindex_t bindex, bend;
16009 + struct inode *h_inode, *h_dinode;
16012 + * before this function, if aufs got any iinfo lock, it must be only
16013 + * one, the parent dir.
16014 + * it can happen by UDBA and the obsoleted inode number.
16017 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16021 + ii_write_lock_new_child(inode);
16022 + h_dinode = au_h_dptr(dentry, au_dbstart(dentry))->d_inode;
16023 + bend = au_ibend(inode);
16024 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
16025 + h_inode = au_h_iptr(inode, bindex);
16026 + if (!h_inode || h_inode != h_dinode)
16030 + gen = au_iigen(inode, &iigen);
16031 + if (gen == au_digen(dentry)
16032 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
16035 + /* fully refresh inode using dentry */
16036 + err = au_refresh_hinode(inode, dentry);
16038 + au_update_iigen(inode, /*half*/0);
16042 + if (unlikely(err))
16043 + ii_write_unlock(inode);
16048 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16049 + unsigned int d_type, ino_t *ino)
16052 + struct mutex *mtx;
16054 + /* prevent hardlinked inode number from race condition */
16056 + if (d_type != DT_DIR) {
16057 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16060 + err = au_xino_read(sb, bindex, h_ino, ino);
16061 + if (unlikely(err))
16066 + *ino = au_xino_new_ino(sb);
16067 + if (unlikely(!*ino))
16069 + err = au_xino_write(sb, bindex, h_ino, *ino);
16070 + if (unlikely(err))
16076 + mutex_unlock(mtx);
16080 +/* successful returns with iinfo write_locked */
16081 +/* todo: return with unlocked? */
16082 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16084 + struct inode *inode;
16085 + struct dentry *h_dentry;
16086 + struct super_block *sb;
16087 + struct mutex *mtx;
16088 + ino_t h_ino, ino;
16090 + aufs_bindex_t bstart;
16092 + sb = dentry->d_sb;
16093 + bstart = au_dbstart(dentry);
16094 + h_dentry = au_h_dptr(dentry, bstart);
16095 + h_ino = h_dentry->d_inode->i_ino;
16098 + * stop 'race'-ing between hardlinks under different
16102 + if (!d_is_dir(h_dentry))
16103 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
16108 + err = au_xino_read(sb, bstart, h_ino, &ino);
16109 + inode = ERR_PTR(err);
16110 + if (unlikely(err))
16114 + ino = au_xino_new_ino(sb);
16115 + if (unlikely(!ino)) {
16116 + inode = ERR_PTR(-EIO);
16121 + AuDbg("i%lu\n", (unsigned long)ino);
16122 + inode = au_iget_locked(sb, ino);
16123 + err = PTR_ERR(inode);
16124 + if (IS_ERR(inode))
16127 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16128 + if (inode->i_state & I_NEW) {
16129 + /* verbose coding for lock class name */
16130 + if (unlikely(d_is_symlink(h_dentry)))
16131 + au_rw_class(&au_ii(inode)->ii_rwsem,
16132 + au_lc_key + AuLcSymlink_IIINFO);
16133 + else if (unlikely(d_is_dir(h_dentry)))
16134 + au_rw_class(&au_ii(inode)->ii_rwsem,
16135 + au_lc_key + AuLcDir_IIINFO);
16136 + else /* likely */
16137 + au_rw_class(&au_ii(inode)->ii_rwsem,
16138 + au_lc_key + AuLcNonDir_IIINFO);
16140 + ii_write_lock_new_child(inode);
16141 + err = set_inode(inode, dentry);
16143 + unlock_new_inode(inode);
16144 + goto out; /* success */
16148 + * iget_failed() calls iput(), but we need to call
16149 + * ii_write_unlock() after iget_failed(). so dirty hack for
16152 + atomic_inc(&inode->i_count);
16153 + iget_failed(inode);
16154 + ii_write_unlock(inode);
16155 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
16156 + /* ignore this error */
16158 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16160 + * horrible race condition between lookup, readdir and copyup
16161 + * (or something).
16164 + mutex_unlock(mtx);
16165 + err = reval_inode(inode, dentry);
16166 + if (unlikely(err < 0)) {
16173 + goto out; /* success */
16178 + if (unlikely(au_test_fs_unique_ino(h_dentry->d_inode)))
16179 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16180 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16181 + bstart, au_sbtype(h_dentry->d_sb), dentry,
16182 + (unsigned long)h_ino, (unsigned long)ino);
16184 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
16188 + mutex_unlock(mtx);
16194 + inode = ERR_PTR(err);
16197 + mutex_unlock(mtx);
16201 +/* ---------------------------------------------------------------------- */
16203 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16204 + struct inode *inode)
16207 + struct inode *hi;
16209 + err = au_br_rdonly(au_sbr(sb, bindex));
16211 + /* pseudo-link after flushed may happen out of bounds */
16214 + && au_ibstart(inode) <= bindex
16215 + && bindex <= au_ibend(inode)) {
16217 + * permission check is unnecessary since vfsub routine
16218 + * will be called later
16220 + hi = au_h_iptr(inode, bindex);
16222 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16228 +int au_test_h_perm(struct inode *h_inode, int mask)
16230 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16232 + return inode_permission(h_inode, mask);
16235 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16237 + if (au_test_nfs(h_inode->i_sb)
16238 + && (mask & MAY_WRITE)
16239 + && S_ISDIR(h_inode->i_mode))
16240 + mask |= MAY_READ; /* force permission check */
16241 + return au_test_h_perm(h_inode, mask);
16243 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16244 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16245 +++ linux/fs/aufs/inode.h 2015-06-22 08:27:37.884168534 +0200
16248 + * Copyright (C) 2005-2015 Junjiro R. Okajima
16250 + * This program, aufs is free software; you can redistribute it and/or modify
16251 + * it under the terms of the GNU General Public License as published by
16252 + * the Free Software Foundation; either version 2 of the License, or
16253 + * (at your option) any later version.
16255 + * This program is distributed in the hope that it will be useful,
16256 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16257 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16258 + * GNU General Public License for more details.
16260 + * You should have received a copy of the GNU General Public License
16261 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16265 + * inode operations
16268 +#ifndef __AUFS_INODE_H__
16269 +#define __AUFS_INODE_H__
16273 +#include <linux/fsnotify.h>
16274 +#include "rwsem.h"
16278 +struct au_hnotify {
16279 +#ifdef CONFIG_AUFS_HNOTIFY
16280 +#ifdef CONFIG_AUFS_HFSNOTIFY
16281 + /* never use fsnotify_add_vfsmount_mark() */
16282 + struct fsnotify_mark hn_mark;
16284 + struct inode *hn_aufs_inode; /* no get/put */
16286 +} ____cacheline_aligned_in_smp;
16288 +struct au_hinode {
16289 + struct inode *hi_inode;
16290 + aufs_bindex_t hi_id;
16291 +#ifdef CONFIG_AUFS_HNOTIFY
16292 + struct au_hnotify *hi_notify;
16295 + /* reference to the copied-up whiteout with get/put */
16296 + struct dentry *hi_whdentry;
16300 +#define AuIG_HALF_REFRESHED 1
16301 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16302 +#define au_ig_fset(flags, name) \
16303 + do { (flags) |= AuIG_##name; } while (0)
16304 +#define au_ig_fclr(flags, name) \
16305 + do { (flags) &= ~AuIG_##name; } while (0)
16308 + __u32 ig_generation, ig_flags;
16313 + spinlock_t ii_genspin;
16314 + struct au_iigen ii_generation;
16315 + struct super_block *ii_hsb1; /* no get/put */
16317 + struct au_rwsem ii_rwsem;
16318 + aufs_bindex_t ii_bstart, ii_bend;
16320 + struct au_hinode *ii_hinode;
16321 + struct au_vdir *ii_vdir;
16324 +struct au_icntnr {
16325 + struct au_iinfo iinfo;
16326 + struct inode vfs_inode;
16327 +} ____cacheline_aligned_in_smp;
16329 +/* au_pin flags */
16330 +#define AuPin_DI_LOCKED 1
16331 +#define AuPin_MNT_WRITE (1 << 1)
16332 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16333 +#define au_fset_pin(flags, name) \
16334 + do { (flags) |= AuPin_##name; } while (0)
16335 +#define au_fclr_pin(flags, name) \
16336 + do { (flags) &= ~AuPin_##name; } while (0)
16340 + struct dentry *dentry;
16341 + unsigned int udba;
16342 + unsigned char lsc_di, lsc_hi, flags;
16343 + aufs_bindex_t bindex;
16346 + struct dentry *parent;
16347 + struct au_hinode *hdir;
16348 + struct vfsmount *h_mnt;
16350 + /* temporary unlock/relock for copyup */
16351 + struct dentry *h_dentry, *h_parent;
16352 + struct au_branch *br;
16353 + struct task_struct *task;
16356 +void au_pin_hdir_unlock(struct au_pin *p);
16357 +int au_pin_hdir_lock(struct au_pin *p);
16358 +int au_pin_hdir_relock(struct au_pin *p);
16359 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
16360 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16361 +void au_pin_hdir_release(struct au_pin *p);
16363 +/* ---------------------------------------------------------------------- */
16365 +static inline struct au_iinfo *au_ii(struct inode *inode)
16367 + struct au_iinfo *iinfo;
16369 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16370 + if (iinfo->ii_hinode)
16372 + return NULL; /* debugging bad_inode case */
16375 +/* ---------------------------------------------------------------------- */
16378 +struct inode *au_igrab(struct inode *inode);
16379 +int au_refresh_hinode_self(struct inode *inode);
16380 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16381 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16382 + unsigned int d_type, ino_t *ino);
16383 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16384 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16385 + struct inode *inode);
16386 +int au_test_h_perm(struct inode *h_inode, int mask);
16387 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16389 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16390 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16392 +#ifdef CONFIG_AUFS_SHWH
16393 + return au_ino(sb, bindex, h_ino, d_type, ino);
16400 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
16402 +/* au_wr_dir flags */
16403 +#define AuWrDir_ADD_ENTRY 1
16404 +#define AuWrDir_ISDIR (1 << 1)
16405 +#define AuWrDir_TMPFILE (1 << 2)
16406 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16407 +#define au_fset_wrdir(flags, name) \
16408 + do { (flags) |= AuWrDir_##name; } while (0)
16409 +#define au_fclr_wrdir(flags, name) \
16410 + do { (flags) &= ~AuWrDir_##name; } while (0)
16412 +struct au_wr_dir_args {
16413 + aufs_bindex_t force_btgt;
16414 + unsigned char flags;
16416 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16417 + struct au_wr_dir_args *args);
16419 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16420 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16421 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16422 + unsigned int udba, unsigned char flags);
16423 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16424 + unsigned int udba, unsigned char flags) __must_check;
16425 +int au_do_pin(struct au_pin *pin) __must_check;
16426 +void au_unpin(struct au_pin *pin);
16427 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16429 +#define AuIcpup_DID_CPUP 1
16430 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16431 +#define au_fset_icpup(flags, name) \
16432 + do { (flags) |= AuIcpup_##name; } while (0)
16433 +#define au_fclr_icpup(flags, name) \
16434 + do { (flags) &= ~AuIcpup_##name; } while (0)
16436 +struct au_icpup_args {
16437 + unsigned char flags;
16438 + unsigned char pin_flags;
16439 + aufs_bindex_t btgt;
16440 + unsigned int udba;
16441 + struct au_pin pin;
16442 + struct path h_path;
16443 + struct inode *h_inode;
16446 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16447 + struct au_icpup_args *a);
16449 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16452 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16453 + struct dentry *h_parent, int isdir);
16454 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16456 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16457 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16459 +struct vfsub_aopen_args;
16460 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
16461 + struct vfsub_aopen_args *args);
16462 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16463 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16464 + struct dentry *dentry);
16465 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16468 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16469 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16470 + struct dentry *h_parent, int isdir);
16471 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16472 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16475 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16476 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16477 + struct inode *dir, struct dentry *dentry);
16480 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16481 +void au_hiput(struct au_hinode *hinode);
16482 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16483 + struct dentry *h_wh);
16484 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16486 +/* hinode flags */
16487 +#define AuHi_XINO 1
16488 +#define AuHi_HNOTIFY (1 << 1)
16489 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16490 +#define au_fset_hi(flags, name) \
16491 + do { (flags) |= AuHi_##name; } while (0)
16492 +#define au_fclr_hi(flags, name) \
16493 + do { (flags) &= ~AuHi_##name; } while (0)
16495 +#ifndef CONFIG_AUFS_HNOTIFY
16496 +#undef AuHi_HNOTIFY
16497 +#define AuHi_HNOTIFY 0
16500 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16501 + struct inode *h_inode, unsigned int flags);
16503 +void au_update_iigen(struct inode *inode, int half);
16504 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16506 +void au_icntnr_init_once(void *_c);
16507 +int au_iinfo_init(struct inode *inode);
16508 +void au_iinfo_fin(struct inode *inode);
16509 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
16511 +#ifdef CONFIG_PROC_FS
16513 +int au_plink_maint(struct super_block *sb, int flags);
16515 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16516 +int au_plink_maint_enter(struct super_block *sb);
16517 +#ifdef CONFIG_AUFS_DEBUG
16518 +void au_plink_list(struct super_block *sb);
16520 +AuStubVoid(au_plink_list, struct super_block *sb)
16522 +int au_plink_test(struct inode *inode);
16523 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16524 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16525 + struct dentry *h_dentry);
16526 +void au_plink_put(struct super_block *sb, int verbose);
16527 +void au_plink_clean(struct super_block *sb, int verbose);
16528 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16530 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16531 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16532 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16533 +AuStubVoid(au_plink_list, struct super_block *sb);
16534 +AuStubInt0(au_plink_test, struct inode *inode);
16535 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16536 + struct inode *inode, aufs_bindex_t bindex);
16537 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16538 + struct dentry *h_dentry);
16539 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16540 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16541 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16542 +#endif /* CONFIG_PROC_FS */
16544 +#ifdef CONFIG_AUFS_XATTR
16546 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
16547 + unsigned int verbose);
16548 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16549 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
16551 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
16552 + size_t size, int flags);
16553 +int aufs_removexattr(struct dentry *dentry, const char *name);
16555 +/* void au_xattr_init(struct super_block *sb); */
16557 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16558 + int ignore_flags, unsigned int verbose);
16559 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
16562 +#ifdef CONFIG_FS_POSIX_ACL
16563 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16564 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16567 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16574 +struct au_srxattr {
16578 + const char *name;
16579 + const void *value;
16584 + const char *name;
16587 + struct posix_acl *acl;
16592 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg);
16595 +/* ---------------------------------------------------------------------- */
16597 +/* lock subclass for iinfo */
16599 + AuLsc_II_CHILD, /* child first */
16600 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16601 + AuLsc_II_CHILD3, /* copyup dirs */
16602 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16603 + AuLsc_II_PARENT2,
16604 + AuLsc_II_PARENT3, /* copyup dirs */
16605 + AuLsc_II_NEW_CHILD
16609 + * ii_read_lock_child, ii_write_lock_child,
16610 + * ii_read_lock_child2, ii_write_lock_child2,
16611 + * ii_read_lock_child3, ii_write_lock_child3,
16612 + * ii_read_lock_parent, ii_write_lock_parent,
16613 + * ii_read_lock_parent2, ii_write_lock_parent2,
16614 + * ii_read_lock_parent3, ii_write_lock_parent3,
16615 + * ii_read_lock_new_child, ii_write_lock_new_child,
16617 +#define AuReadLockFunc(name, lsc) \
16618 +static inline void ii_read_lock_##name(struct inode *i) \
16620 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16623 +#define AuWriteLockFunc(name, lsc) \
16624 +static inline void ii_write_lock_##name(struct inode *i) \
16626 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16629 +#define AuRWLockFuncs(name, lsc) \
16630 + AuReadLockFunc(name, lsc) \
16631 + AuWriteLockFunc(name, lsc)
16633 +AuRWLockFuncs(child, CHILD);
16634 +AuRWLockFuncs(child2, CHILD2);
16635 +AuRWLockFuncs(child3, CHILD3);
16636 +AuRWLockFuncs(parent, PARENT);
16637 +AuRWLockFuncs(parent2, PARENT2);
16638 +AuRWLockFuncs(parent3, PARENT3);
16639 +AuRWLockFuncs(new_child, NEW_CHILD);
16641 +#undef AuReadLockFunc
16642 +#undef AuWriteLockFunc
16643 +#undef AuRWLockFuncs
16646 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
16648 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
16650 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
16651 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
16652 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
16654 +/* ---------------------------------------------------------------------- */
16656 +static inline void au_icntnr_init(struct au_icntnr *c)
16658 +#ifdef CONFIG_AUFS_DEBUG
16659 + c->vfs_inode.i_mode = 0;
16663 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
16665 + unsigned int gen;
16666 + struct au_iinfo *iinfo;
16668 + iinfo = au_ii(inode);
16669 + spin_lock(&iinfo->ii_genspin);
16671 + *iigen = iinfo->ii_generation;
16672 + gen = iinfo->ii_generation.ig_generation;
16673 + spin_unlock(&iinfo->ii_genspin);
16678 +/* tiny test for inode number */
16679 +/* tmpfs generation is too rough */
16680 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
16682 + struct au_iinfo *iinfo;
16684 + iinfo = au_ii(inode);
16685 + AuRwMustAnyLock(&iinfo->ii_rwsem);
16686 + return !(iinfo->ii_hsb1 == h_inode->i_sb
16687 + && iinfo->ii_higen == h_inode->i_generation);
16690 +static inline void au_iigen_dec(struct inode *inode)
16692 + struct au_iinfo *iinfo;
16694 + iinfo = au_ii(inode);
16695 + spin_lock(&iinfo->ii_genspin);
16696 + iinfo->ii_generation.ig_generation--;
16697 + spin_unlock(&iinfo->ii_genspin);
16700 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
16705 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
16711 +/* ---------------------------------------------------------------------- */
16713 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
16714 + aufs_bindex_t bindex)
16716 + IiMustAnyLock(inode);
16717 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
16720 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
16722 + IiMustAnyLock(inode);
16723 + return au_ii(inode)->ii_bstart;
16726 +static inline aufs_bindex_t au_ibend(struct inode *inode)
16728 + IiMustAnyLock(inode);
16729 + return au_ii(inode)->ii_bend;
16732 +static inline struct au_vdir *au_ivdir(struct inode *inode)
16734 + IiMustAnyLock(inode);
16735 + return au_ii(inode)->ii_vdir;
16738 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
16740 + IiMustAnyLock(inode);
16741 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
16744 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
16746 + IiMustWriteLock(inode);
16747 + au_ii(inode)->ii_bstart = bindex;
16750 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
16752 + IiMustWriteLock(inode);
16753 + au_ii(inode)->ii_bend = bindex;
16756 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
16758 + IiMustWriteLock(inode);
16759 + au_ii(inode)->ii_vdir = vdir;
16762 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
16764 + IiMustAnyLock(inode);
16765 + return au_ii(inode)->ii_hinode + bindex;
16768 +/* ---------------------------------------------------------------------- */
16770 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
16773 + return pin->parent;
16777 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
16779 + if (pin && pin->hdir)
16780 + return pin->hdir->hi_inode;
16784 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
16787 + return pin->hdir;
16791 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
16794 + pin->dentry = dentry;
16797 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
16798 + unsigned char lflag)
16802 + au_fset_pin(pin->flags, DI_LOCKED);
16804 + au_fclr_pin(pin->flags, DI_LOCKED);
16808 +#if 0 /* reserved */
16809 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
16812 + dput(pin->parent);
16813 + pin->parent = dget(parent);
16818 +/* ---------------------------------------------------------------------- */
16821 +#ifdef CONFIG_AUFS_HNOTIFY
16822 +struct au_hnotify_op {
16823 + void (*ctl)(struct au_hinode *hinode, int do_set);
16824 + int (*alloc)(struct au_hinode *hinode);
16827 + * if it returns true, the the caller should free hinode->hi_notify,
16828 + * otherwise ->free() frees it.
16830 + int (*free)(struct au_hinode *hinode,
16831 + struct au_hnotify *hn) __must_check;
16833 + void (*fin)(void);
16834 + int (*init)(void);
16836 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
16837 + void (*fin_br)(struct au_branch *br);
16838 + int (*init_br)(struct au_branch *br, int perm);
16842 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
16843 +void au_hn_free(struct au_hinode *hinode);
16844 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
16845 +void au_hn_reset(struct inode *inode, unsigned int flags);
16846 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
16847 + struct qstr *h_child_qstr, struct inode *h_child_inode);
16848 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
16849 +int au_hnotify_init_br(struct au_branch *br, int perm);
16850 +void au_hnotify_fin_br(struct au_branch *br);
16851 +int __init au_hnotify_init(void);
16852 +void au_hnotify_fin(void);
16855 +extern const struct au_hnotify_op au_hnotify_op;
16858 +void au_hn_init(struct au_hinode *hinode)
16860 + hinode->hi_notify = NULL;
16863 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
16865 + return hinode->hi_notify;
16869 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
16870 + struct au_hinode *hinode __maybe_unused,
16871 + struct inode *inode __maybe_unused)
16872 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
16873 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
16874 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
16875 + int do_set __maybe_unused)
16876 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
16877 + unsigned int flags __maybe_unused)
16878 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
16879 + struct au_branch *br __maybe_unused,
16880 + int perm __maybe_unused)
16881 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
16882 + int perm __maybe_unused)
16883 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
16884 +AuStubInt0(__init au_hnotify_init, void)
16885 +AuStubVoid(au_hnotify_fin, void)
16886 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
16887 +#endif /* CONFIG_AUFS_HNOTIFY */
16889 +static inline void au_hn_suspend(struct au_hinode *hdir)
16891 + au_hn_ctl(hdir, /*do_set*/0);
16894 +static inline void au_hn_resume(struct au_hinode *hdir)
16896 + au_hn_ctl(hdir, /*do_set*/1);
16899 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
16901 + mutex_lock(&hdir->hi_inode->i_mutex);
16902 + au_hn_suspend(hdir);
16905 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
16906 + unsigned int sc __maybe_unused)
16908 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
16909 + au_hn_suspend(hdir);
16912 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
16914 + au_hn_resume(hdir);
16915 + mutex_unlock(&hdir->hi_inode->i_mutex);
16918 +#endif /* __KERNEL__ */
16919 +#endif /* __AUFS_INODE_H__ */
16920 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
16921 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
16922 +++ linux/fs/aufs/ioctl.c 2015-06-22 08:29:23.706757681 +0200
16925 + * Copyright (C) 2005-2015 Junjiro R. Okajima
16927 + * This program, aufs is free software; you can redistribute it and/or modify
16928 + * it under the terms of the GNU General Public License as published by
16929 + * the Free Software Foundation; either version 2 of the License, or
16930 + * (at your option) any later version.
16932 + * This program is distributed in the hope that it will be useful,
16933 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16934 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16935 + * GNU General Public License for more details.
16937 + * You should have received a copy of the GNU General Public License
16938 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16943 + * plink-management and readdir in userspace.
16944 + * assist the pathconf(3) wrapper library.
16946 + * File-based Hierarchical Storage Management.
16949 +#include <linux/compat.h>
16950 +#include <linux/file.h>
16953 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
16956 + aufs_bindex_t wbi, bindex, bend;
16957 + struct file *h_file;
16958 + struct super_block *sb;
16959 + struct dentry *root;
16960 + struct au_branch *br;
16961 + struct aufs_wbr_fd wbrfd = {
16962 + .oflags = au_dir_roflags,
16965 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
16966 + | O_NOATIME | O_CLOEXEC;
16968 + AuDebugOn(wbrfd.oflags & ~valid);
16971 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
16972 + if (unlikely(err)) {
16978 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
16979 + wbrfd.oflags |= au_dir_roflags;
16980 + AuDbg("0%o\n", wbrfd.oflags);
16981 + if (unlikely(wbrfd.oflags & ~valid))
16985 + fd = get_unused_fd_flags(0);
16987 + if (unlikely(fd < 0))
16990 + h_file = ERR_PTR(-EINVAL);
16993 + sb = path->dentry->d_sb;
16994 + root = sb->s_root;
16995 + aufs_read_lock(root, AuLock_IR);
16996 + bend = au_sbend(sb);
16997 + if (wbrfd.brid >= 0) {
16998 + wbi = au_br_index(sb, wbrfd.brid);
16999 + if (unlikely(wbi < 0 || wbi > bend))
17003 + h_file = ERR_PTR(-ENOENT);
17004 + br = au_sbr(sb, wbi);
17005 + if (!au_br_writable(br->br_perm)) {
17009 + bindex = wbi + 1;
17011 + for (; bindex <= bend; bindex++) {
17012 + br = au_sbr(sb, bindex);
17013 + if (au_br_writable(br->br_perm)) {
17015 + br = au_sbr(sb, wbi);
17020 + AuDbg("wbi %d\n", wbi);
17022 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17026 + aufs_read_unlock(root, AuLock_IR);
17027 + err = PTR_ERR(h_file);
17028 + if (IS_ERR(h_file))
17031 + atomic_dec(&br->br_count); /* cf. au_h_open() */
17032 + fd_install(fd, h_file);
17034 + goto out; /* success */
17037 + put_unused_fd(fd);
17043 +/* ---------------------------------------------------------------------- */
17045 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17048 + struct dentry *dentry;
17051 + case AUFS_CTL_RDU:
17052 + case AUFS_CTL_RDU_INO:
17053 + err = au_rdu_ioctl(file, cmd, arg);
17056 + case AUFS_CTL_WBR_FD:
17057 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17060 + case AUFS_CTL_IBUSY:
17061 + err = au_ibusy_ioctl(file, arg);
17064 + case AUFS_CTL_BRINFO:
17065 + err = au_brinfo_ioctl(file, arg);
17068 + case AUFS_CTL_FHSM_FD:
17069 + dentry = file->f_path.dentry;
17070 + if (IS_ROOT(dentry))
17071 + err = au_fhsm_fd(dentry->d_sb, arg);
17077 + /* do not call the lower */
17078 + AuDbg("0x%x\n", cmd);
17086 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17091 + case AUFS_CTL_MVDOWN:
17092 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17095 + case AUFS_CTL_WBR_FD:
17096 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17100 + /* do not call the lower */
17101 + AuDbg("0x%x\n", cmd);
17109 +#ifdef CONFIG_COMPAT
17110 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17111 + unsigned long arg)
17116 + case AUFS_CTL_RDU:
17117 + case AUFS_CTL_RDU_INO:
17118 + err = au_rdu_compat_ioctl(file, cmd, arg);
17121 + case AUFS_CTL_IBUSY:
17122 + err = au_ibusy_compat_ioctl(file, arg);
17125 + case AUFS_CTL_BRINFO:
17126 + err = au_brinfo_compat_ioctl(file, arg);
17130 + err = aufs_ioctl_dir(file, cmd, arg);
17137 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17138 + unsigned long arg)
17140 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17143 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17144 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17145 +++ linux/fs/aufs/i_op_add.c 2015-06-22 08:27:37.880835119 +0200
17148 + * Copyright (C) 2005-2015 Junjiro R. Okajima
17150 + * This program, aufs is free software; you can redistribute it and/or modify
17151 + * it under the terms of the GNU General Public License as published by
17152 + * the Free Software Foundation; either version 2 of the License, or
17153 + * (at your option) any later version.
17155 + * This program is distributed in the hope that it will be useful,
17156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17158 + * GNU General Public License for more details.
17160 + * You should have received a copy of the GNU General Public License
17161 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17165 + * inode operations (add entry)
17171 + * final procedure of adding a new entry, except link(2).
17172 + * remove whiteout, instantiate, copyup the parent dir's times and size
17173 + * and update version.
17174 + * if it failed, re-create the removed whiteout.
17176 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17177 + struct dentry *wh_dentry, struct dentry *dentry)
17180 + aufs_bindex_t bwh;
17181 + struct path h_path;
17182 + struct super_block *sb;
17183 + struct inode *inode, *h_dir;
17184 + struct dentry *wh;
17189 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
17190 + IMustLock(h_dir);
17191 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17192 + bwh = au_dbwh(dentry);
17193 + h_path.dentry = wh_dentry;
17194 + h_path.mnt = au_sbr_mnt(sb, bindex);
17195 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17197 + if (unlikely(err))
17201 + inode = au_new_inode(dentry, /*must_new*/1);
17202 + if (!IS_ERR(inode)) {
17203 + d_instantiate(dentry, inode);
17204 + dir = dentry->d_parent->d_inode; /* dir inode is locked */
17206 + au_dir_ts(dir, bindex);
17207 + dir->i_version++;
17208 + au_fhsm_wrote(sb, bindex, /*force*/0);
17209 + return 0; /* success */
17212 + err = PTR_ERR(inode);
17217 + /* dir inode is locked */
17218 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17219 + rerr = PTR_ERR(wh);
17220 + if (IS_ERR(wh)) {
17221 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17222 + dentry, err, rerr);
17231 +static int au_d_may_add(struct dentry *dentry)
17236 + if (unlikely(d_unhashed(dentry)))
17238 + if (unlikely(dentry->d_inode))
17244 + * simple tests for the adding inode operations.
17245 + * following the checks in vfs, plus the parent-child relationship.
17247 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17248 + struct dentry *h_parent, int isdir)
17252 + struct dentry *h_dentry;
17253 + struct inode *h_inode;
17255 + err = -ENAMETOOLONG;
17256 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17259 + h_dentry = au_h_dptr(dentry, bindex);
17260 + h_inode = h_dentry->d_inode;
17261 + if (!dentry->d_inode) {
17263 + if (unlikely(h_inode))
17266 + /* rename(2) case */
17268 + if (unlikely(!h_inode || !h_inode->i_nlink))
17271 + h_mode = h_inode->i_mode;
17274 + if (unlikely(S_ISDIR(h_mode)))
17276 + } else if (unlikely(!S_ISDIR(h_mode))) {
17283 + /* expected parent dir is locked */
17284 + if (unlikely(h_parent != h_dentry->d_parent))
17293 + * initial procedure of adding a new entry.
17294 + * prepare writable branch and the parent dir, lock it,
17295 + * and lookup whiteout for the new entry.
17297 +static struct dentry*
17298 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17299 + struct dentry *src_dentry, struct au_pin *pin,
17300 + struct au_wr_dir_args *wr_dir_args)
17302 + struct dentry *wh_dentry, *h_parent;
17303 + struct super_block *sb;
17304 + struct au_branch *br;
17306 + unsigned int udba;
17307 + aufs_bindex_t bcpup;
17309 + AuDbg("%pd\n", dentry);
17311 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17313 + wh_dentry = ERR_PTR(err);
17314 + if (unlikely(err < 0))
17317 + sb = dentry->d_sb;
17318 + udba = au_opt_udba(sb);
17319 + err = au_pin(pin, dentry, bcpup, udba,
17320 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17321 + wh_dentry = ERR_PTR(err);
17322 + if (unlikely(err))
17325 + h_parent = au_pinned_h_parent(pin);
17326 + if (udba != AuOpt_UDBA_NONE
17327 + && au_dbstart(dentry) == bcpup)
17328 + err = au_may_add(dentry, bcpup, h_parent,
17329 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17330 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17331 + err = -ENAMETOOLONG;
17332 + wh_dentry = ERR_PTR(err);
17333 + if (unlikely(err))
17336 + br = au_sbr(sb, bcpup);
17338 + struct path tmp = {
17339 + .dentry = h_parent,
17340 + .mnt = au_br_mnt(br)
17342 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17345 + wh_dentry = NULL;
17346 + if (bcpup != au_dbwh(dentry))
17347 + goto out; /* success */
17350 + * ENAMETOOLONG here means that if we allowed create such name, then it
17351 + * would not be able to removed in the future. So we don't allow such
17352 + * name here and we don't handle ENAMETOOLONG differently here.
17354 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17357 + if (IS_ERR(wh_dentry))
17360 + return wh_dentry;
17363 +/* ---------------------------------------------------------------------- */
17365 +enum { Mknod, Symlink, Creat };
17366 +struct simple_arg {
17373 + struct vfsub_aopen_args *aopen;
17376 + const char *symname;
17385 +static int add_simple(struct inode *dir, struct dentry *dentry,
17386 + struct simple_arg *arg)
17389 + aufs_bindex_t bstart;
17390 + unsigned char created;
17391 + const unsigned char try_aopen
17392 + = (arg->type == Creat && arg->u.c.try_aopen);
17393 + struct dentry *wh_dentry, *parent;
17394 + struct inode *h_dir;
17395 + struct super_block *sb;
17396 + struct au_branch *br;
17397 + /* to reuduce stack size */
17399 + struct au_dtime dt;
17400 + struct au_pin pin;
17401 + struct path h_path;
17402 + struct au_wr_dir_args wr_dir_args;
17405 + AuDbg("%pd\n", dentry);
17409 + a = kmalloc(sizeof(*a), GFP_NOFS);
17410 + if (unlikely(!a))
17412 + a->wr_dir_args.force_btgt = -1;
17413 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17415 + parent = dentry->d_parent; /* dir inode is locked */
17416 + if (!try_aopen) {
17417 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17418 + if (unlikely(err))
17421 + err = au_d_may_add(dentry);
17422 + if (unlikely(err))
17425 + di_write_lock_parent(parent);
17426 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17427 + &a->pin, &a->wr_dir_args);
17428 + err = PTR_ERR(wh_dentry);
17429 + if (IS_ERR(wh_dentry))
17432 + bstart = au_dbstart(dentry);
17433 + sb = dentry->d_sb;
17434 + br = au_sbr(sb, bstart);
17435 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17436 + a->h_path.mnt = au_br_mnt(br);
17437 + h_dir = au_pinned_h_dir(&a->pin);
17438 + switch (arg->type) {
17441 + if (!try_aopen || !h_dir->i_op->atomic_open)
17442 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17443 + arg->u.c.want_excl);
17445 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
17446 + arg->u.c.aopen, br);
17449 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17452 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17460 + err = epilog(dir, bstart, wh_dentry, dentry);
17463 + if (unlikely(created && err && a->h_path.dentry->d_inode)) {
17464 + /* no delegation since it is just created */
17465 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17468 + AuIOErr("%pd revert failure(%d, %d)\n",
17469 + dentry, err, rerr);
17472 + au_dtime_revert(&a->dt);
17475 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
17476 + *arg->u.c.aopen->opened |= FILE_CREATED;
17478 + au_unpin(&a->pin);
17483 + di_write_unlock(parent);
17485 + if (unlikely(err)) {
17486 + au_update_dbstart(dentry);
17490 + aufs_read_unlock(dentry, AuLock_DW);
17497 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17500 + struct simple_arg arg = {
17507 + return add_simple(dir, dentry, &arg);
17510 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17512 + struct simple_arg arg = {
17514 + .u.s.symname = symname
17516 + return add_simple(dir, dentry, &arg);
17519 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17522 + struct simple_arg arg = {
17526 + .want_excl = want_excl
17529 + return add_simple(dir, dentry, &arg);
17532 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17533 + struct vfsub_aopen_args *aopen_args)
17535 + struct simple_arg arg = {
17538 + .mode = aopen_args->create_mode,
17539 + .want_excl = aopen_args->open_flag & O_EXCL,
17540 + .try_aopen = true,
17541 + .aopen = aopen_args
17544 + return add_simple(dir, dentry, &arg);
17547 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17550 + aufs_bindex_t bindex;
17551 + struct super_block *sb;
17552 + struct dentry *parent, *h_parent, *h_dentry;
17553 + struct inode *h_dir, *inode;
17554 + struct vfsmount *h_mnt;
17555 + struct au_wr_dir_args wr_dir_args = {
17556 + .force_btgt = -1,
17557 + .flags = AuWrDir_TMPFILE
17560 + /* copy-up may happen */
17561 + mutex_lock(&dir->i_mutex);
17564 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17565 + if (unlikely(err))
17568 + err = au_di_init(dentry);
17569 + if (unlikely(err))
17573 + parent = d_find_any_alias(dir);
17574 + AuDebugOn(!parent);
17575 + di_write_lock_parent(parent);
17576 + if (unlikely(parent->d_inode != dir))
17579 + err = au_digen_test(parent, au_sigen(sb));
17580 + if (unlikely(err))
17583 + bindex = au_dbstart(parent);
17584 + au_set_dbstart(dentry, bindex);
17585 + au_set_dbend(dentry, bindex);
17586 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17588 + if (unlikely(err < 0))
17591 + err = -EOPNOTSUPP;
17592 + h_dir = au_h_iptr(dir, bindex);
17593 + if (unlikely(!h_dir->i_op->tmpfile))
17596 + h_mnt = au_sbr_mnt(sb, bindex);
17597 + err = vfsub_mnt_want_write(h_mnt);
17598 + if (unlikely(err))
17601 + h_parent = au_h_dptr(parent, bindex);
17602 + err = inode_permission(h_parent->d_inode, MAY_WRITE | MAY_EXEC);
17603 + if (unlikely(err))
17607 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17608 + if (unlikely(!h_dentry))
17611 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17612 + if (unlikely(err))
17615 + au_set_dbstart(dentry, bindex);
17616 + au_set_dbend(dentry, bindex);
17617 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17618 + inode = au_new_inode(dentry, /*must_new*/1);
17619 + if (IS_ERR(inode)) {
17620 + err = PTR_ERR(inode);
17621 + au_set_h_dptr(dentry, bindex, NULL);
17622 + au_set_dbstart(dentry, -1);
17623 + au_set_dbend(dentry, -1);
17625 + if (!inode->i_nlink)
17626 + set_nlink(inode, 1);
17627 + d_tmpfile(dentry, inode);
17628 + au_di(dentry)->di_tmpfile = 1;
17630 + /* update without i_mutex */
17631 + if (au_ibstart(dir) == au_dbstart(dentry))
17632 + au_cpup_attr_timesizes(dir);
17638 + vfsub_mnt_drop_write(h_mnt);
17640 + di_write_unlock(parent);
17642 + di_write_unlock(dentry);
17645 + /* verbose coding for lock class name */
17646 + au_rw_class(&au_di(dentry)->di_rwsem,
17647 + au_lc_key + AuLcNonDir_DIINFO);
17652 + au_di_fin(dentry);
17653 + dentry->d_fsdata = NULL;
17656 + si_read_unlock(sb);
17658 + mutex_unlock(&dir->i_mutex);
17662 +/* ---------------------------------------------------------------------- */
17664 +struct au_link_args {
17665 + aufs_bindex_t bdst, bsrc;
17666 + struct au_pin pin;
17667 + struct path h_path;
17668 + struct dentry *src_parent, *parent;
17671 +static int au_cpup_before_link(struct dentry *src_dentry,
17672 + struct au_link_args *a)
17675 + struct dentry *h_src_dentry;
17676 + struct au_cp_generic cpg = {
17677 + .dentry = src_dentry,
17682 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
17685 + di_read_lock_parent(a->src_parent, AuLock_IR);
17686 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
17687 + if (unlikely(err))
17690 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
17691 + err = au_pin(&a->pin, src_dentry, a->bdst,
17692 + au_opt_udba(src_dentry->d_sb),
17693 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17694 + if (unlikely(err))
17697 + err = au_sio_cpup_simple(&cpg);
17698 + au_unpin(&a->pin);
17701 + di_read_unlock(a->src_parent, AuLock_IR);
17705 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
17706 + struct au_link_args *a)
17709 + unsigned char plink;
17710 + aufs_bindex_t bend;
17711 + struct dentry *h_src_dentry;
17712 + struct inode *h_inode, *inode, *delegated;
17713 + struct super_block *sb;
17714 + struct file *h_file;
17718 + sb = src_dentry->d_sb;
17719 + inode = src_dentry->d_inode;
17720 + if (au_ibstart(inode) <= a->bdst)
17721 + h_inode = au_h_iptr(inode, a->bdst);
17722 + if (!h_inode || !h_inode->i_nlink) {
17723 + /* copyup src_dentry as the name of dentry. */
17724 + bend = au_dbend(dentry);
17725 + if (bend < a->bsrc)
17726 + au_set_dbend(dentry, a->bsrc);
17727 + au_set_h_dptr(dentry, a->bsrc,
17728 + dget(au_h_dptr(src_dentry, a->bsrc)));
17729 + dget(a->h_path.dentry);
17730 + au_set_h_dptr(dentry, a->bdst, NULL);
17731 + AuDbg("temporary d_inode...\n");
17732 + spin_lock(&dentry->d_lock);
17733 + dentry->d_inode = src_dentry->d_inode; /* tmp */
17734 + spin_unlock(&dentry->d_lock);
17735 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
17736 + if (IS_ERR(h_file))
17737 + err = PTR_ERR(h_file);
17739 + struct au_cp_generic cpg = {
17740 + .dentry = dentry,
17745 + .flags = AuCpup_KEEPLINO
17747 + err = au_sio_cpup_simple(&cpg);
17748 + au_h_open_post(dentry, a->bsrc, h_file);
17750 + dput(a->h_path.dentry);
17751 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17753 + au_set_h_dptr(dentry, a->bdst,
17754 + a->h_path.dentry);
17756 + spin_lock(&dentry->d_lock);
17757 + dentry->d_inode = NULL; /* restore */
17758 + spin_unlock(&dentry->d_lock);
17759 + AuDbg("temporary d_inode...done\n");
17760 + au_set_h_dptr(dentry, a->bsrc, NULL);
17761 + au_set_dbend(dentry, bend);
17763 + /* the inode of src_dentry already exists on a.bdst branch */
17764 + h_src_dentry = d_find_alias(h_inode);
17765 + if (!h_src_dentry && au_plink_test(inode)) {
17767 + h_src_dentry = au_plink_lkup(inode, a->bdst);
17768 + err = PTR_ERR(h_src_dentry);
17769 + if (IS_ERR(h_src_dentry))
17772 + if (unlikely(!h_src_dentry->d_inode)) {
17773 + dput(h_src_dentry);
17774 + h_src_dentry = NULL;
17778 + if (h_src_dentry) {
17779 + delegated = NULL;
17780 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17781 + &a->h_path, &delegated);
17782 + if (unlikely(err == -EWOULDBLOCK)) {
17783 + pr_warn("cannot retry for NFSv4 delegation"
17784 + " for an internal link\n");
17787 + dput(h_src_dentry);
17789 + AuIOErr("no dentry found for hi%lu on b%d\n",
17790 + h_inode->i_ino, a->bdst);
17795 + if (!err && !plink)
17796 + au_plink_append(inode, a->bdst, a->h_path.dentry);
17803 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17804 + struct dentry *dentry)
17807 + struct au_dtime dt;
17808 + struct au_link_args *a;
17809 + struct dentry *wh_dentry, *h_src_dentry;
17810 + struct inode *inode, *delegated;
17811 + struct super_block *sb;
17812 + struct au_wr_dir_args wr_dir_args = {
17813 + /* .force_btgt = -1, */
17814 + .flags = AuWrDir_ADD_ENTRY
17818 + inode = src_dentry->d_inode;
17819 + IMustLock(inode);
17822 + a = kzalloc(sizeof(*a), GFP_NOFS);
17823 + if (unlikely(!a))
17826 + a->parent = dentry->d_parent; /* dir inode is locked */
17827 + err = aufs_read_and_write_lock2(dentry, src_dentry,
17828 + AuLock_NOPLM | AuLock_GEN);
17829 + if (unlikely(err))
17831 + err = au_d_linkable(src_dentry);
17832 + if (unlikely(err))
17834 + err = au_d_may_add(dentry);
17835 + if (unlikely(err))
17838 + a->src_parent = dget_parent(src_dentry);
17839 + wr_dir_args.force_btgt = au_ibstart(inode);
17841 + di_write_lock_parent(a->parent);
17842 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
17843 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
17845 + err = PTR_ERR(wh_dentry);
17846 + if (IS_ERR(wh_dentry))
17850 + sb = dentry->d_sb;
17851 + a->bdst = au_dbstart(dentry);
17852 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17853 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
17854 + a->bsrc = au_ibstart(inode);
17855 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17856 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
17857 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
17858 + if (!h_src_dentry) {
17859 + a->bsrc = au_dbstart(src_dentry);
17860 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17861 + AuDebugOn(!h_src_dentry);
17862 + } else if (IS_ERR(h_src_dentry)) {
17863 + err = PTR_ERR(h_src_dentry);
17867 + if (au_opt_test(au_mntflags(sb), PLINK)) {
17868 + if (a->bdst < a->bsrc
17869 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
17870 + err = au_cpup_or_link(src_dentry, dentry, a);
17872 + delegated = NULL;
17873 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17874 + &a->h_path, &delegated);
17875 + if (unlikely(err == -EWOULDBLOCK)) {
17876 + pr_warn("cannot retry for NFSv4 delegation"
17877 + " for an internal link\n");
17881 + dput(h_src_dentry);
17884 + * copyup src_dentry to the branch we process,
17885 + * and then link(2) to it.
17887 + dput(h_src_dentry);
17888 + if (a->bdst < a->bsrc
17889 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
17890 + au_unpin(&a->pin);
17891 + di_write_unlock(a->parent);
17892 + err = au_cpup_before_link(src_dentry, a);
17893 + di_write_lock_parent(a->parent);
17895 + err = au_pin(&a->pin, dentry, a->bdst,
17897 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17898 + if (unlikely(err))
17902 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
17904 + if (h_src_dentry && h_src_dentry->d_inode) {
17905 + delegated = NULL;
17906 + err = vfsub_link(h_src_dentry,
17907 + au_pinned_h_dir(&a->pin),
17908 + &a->h_path, &delegated);
17909 + if (unlikely(err == -EWOULDBLOCK)) {
17910 + pr_warn("cannot retry"
17911 + " for NFSv4 delegation"
17912 + " for an internal link\n");
17918 + if (unlikely(err))
17922 + a->h_path.dentry = wh_dentry;
17923 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
17925 + if (unlikely(err))
17929 + au_dir_ts(dir, a->bdst);
17930 + dir->i_version++;
17931 + inc_nlink(inode);
17932 + inode->i_ctime = dir->i_ctime;
17933 + d_instantiate(dentry, au_igrab(inode));
17934 + if (d_unhashed(a->h_path.dentry))
17935 + /* some filesystem calls d_drop() */
17937 + /* some filesystems consume an inode even hardlink */
17938 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
17939 + goto out_unpin; /* success */
17942 + /* no delegation since it is just created */
17943 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
17944 + /*delegated*/NULL, /*force*/0);
17945 + if (unlikely(rerr)) {
17946 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
17949 + au_dtime_revert(&dt);
17951 + au_unpin(&a->pin);
17955 + di_write_unlock(a->parent);
17956 + dput(a->src_parent);
17958 + if (unlikely(err)) {
17959 + au_update_dbstart(dentry);
17962 + aufs_read_and_write_unlock2(dentry, src_dentry);
17970 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
17973 + aufs_bindex_t bindex;
17974 + unsigned char diropq;
17975 + struct path h_path;
17976 + struct dentry *wh_dentry, *parent, *opq_dentry;
17977 + struct mutex *h_mtx;
17978 + struct super_block *sb;
17980 + struct au_pin pin;
17981 + struct au_dtime dt;
17982 + } *a; /* reduce the stack usage */
17983 + struct au_wr_dir_args wr_dir_args = {
17984 + .force_btgt = -1,
17985 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
17991 + a = kmalloc(sizeof(*a), GFP_NOFS);
17992 + if (unlikely(!a))
17995 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17996 + if (unlikely(err))
17998 + err = au_d_may_add(dentry);
17999 + if (unlikely(err))
18002 + parent = dentry->d_parent; /* dir inode is locked */
18003 + di_write_lock_parent(parent);
18004 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18005 + &a->pin, &wr_dir_args);
18006 + err = PTR_ERR(wh_dentry);
18007 + if (IS_ERR(wh_dentry))
18010 + sb = dentry->d_sb;
18011 + bindex = au_dbstart(dentry);
18012 + h_path.dentry = au_h_dptr(dentry, bindex);
18013 + h_path.mnt = au_sbr_mnt(sb, bindex);
18014 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18015 + if (unlikely(err))
18018 + /* make the dir opaque */
18020 + h_mtx = &h_path.dentry->d_inode->i_mutex;
18022 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18023 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18024 + opq_dentry = au_diropq_create(dentry, bindex);
18025 + mutex_unlock(h_mtx);
18026 + err = PTR_ERR(opq_dentry);
18027 + if (IS_ERR(opq_dentry))
18029 + dput(opq_dentry);
18033 + err = epilog(dir, bindex, wh_dentry, dentry);
18036 + goto out_unpin; /* success */
18041 + AuLabel(revert opq);
18042 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18043 + rerr = au_diropq_remove(dentry, bindex);
18044 + mutex_unlock(h_mtx);
18046 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18047 + dentry, err, rerr);
18053 + AuLabel(revert dir);
18054 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18056 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18057 + dentry, err, rerr);
18060 + au_dtime_revert(&a->dt);
18062 + au_unpin(&a->pin);
18065 + di_write_unlock(parent);
18067 + if (unlikely(err)) {
18068 + au_update_dbstart(dentry);
18071 + aufs_read_unlock(dentry, AuLock_DW);
18077 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18078 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18079 +++ linux/fs/aufs/i_op.c 2015-06-22 08:29:23.706757681 +0200
18082 + * Copyright (C) 2005-2015 Junjiro R. Okajima
18084 + * This program, aufs is free software; you can redistribute it and/or modify
18085 + * it under the terms of the GNU General Public License as published by
18086 + * the Free Software Foundation; either version 2 of the License, or
18087 + * (at your option) any later version.
18089 + * This program is distributed in the hope that it will be useful,
18090 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18091 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18092 + * GNU General Public License for more details.
18094 + * You should have received a copy of the GNU General Public License
18095 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18099 + * inode operations (except add/del/rename)
18102 +#include <linux/device_cgroup.h>
18103 +#include <linux/fs_stack.h>
18104 +#include <linux/mm.h>
18105 +#include <linux/namei.h>
18106 +#include <linux/security.h>
18109 +static int h_permission(struct inode *h_inode, int mask,
18110 + struct vfsmount *h_mnt, int brperm)
18113 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18116 + if ((write_mask && IS_IMMUTABLE(h_inode))
18117 + || ((mask & MAY_EXEC)
18118 + && S_ISREG(h_inode->i_mode)
18119 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
18120 + || !(h_inode->i_mode & S_IXUGO))))
18124 + * - skip the lower fs test in the case of write to ro branch.
18125 + * - nfs dir permission write check is optimized, but a policy for
18126 + * link/rename requires a real check.
18127 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18128 + * in this case, generic_permission() returns -EOPNOTSUPP.
18130 + if ((write_mask && !au_br_writable(brperm))
18131 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18132 + && write_mask && !(mask & MAY_READ))
18133 + || !h_inode->i_op->permission) {
18134 + /* AuLabel(generic_permission); */
18135 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18136 + err = generic_permission(h_inode, mask);
18137 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18138 + err = h_inode->i_op->permission(h_inode, mask);
18141 + /* AuLabel(h_inode->permission); */
18142 + err = h_inode->i_op->permission(h_inode, mask);
18147 + err = devcgroup_inode_permission(h_inode, mask);
18149 + err = security_inode_permission(h_inode, mask);
18153 + /* todo: do we need to call ima_path_check()? */
18154 + struct path h_path = {
18158 + err = ima_path_check(&h_path,
18159 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18160 + IMA_COUNT_LEAVE);
18168 +static int aufs_permission(struct inode *inode, int mask)
18171 + aufs_bindex_t bindex, bend;
18172 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18173 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18174 + struct inode *h_inode;
18175 + struct super_block *sb;
18176 + struct au_branch *br;
18178 + /* todo: support rcu-walk? */
18179 + if (mask & MAY_NOT_BLOCK)
18182 + sb = inode->i_sb;
18183 + si_read_lock(sb, AuLock_FLUSH);
18184 + ii_read_lock_child(inode);
18186 + err = au_iigen_test(inode, au_sigen(sb));
18187 + if (unlikely(err))
18193 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18194 + err = au_busy_or_stale();
18195 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18196 + if (unlikely(!h_inode
18197 + || (h_inode->i_mode & S_IFMT)
18198 + != (inode->i_mode & S_IFMT)))
18202 + bindex = au_ibstart(inode);
18203 + br = au_sbr(sb, bindex);
18204 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
18207 + && !special_file(h_inode->i_mode)) {
18208 + /* test whether the upper writable branch exists */
18210 + for (; bindex >= 0; bindex--)
18211 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18219 + /* non-write to dir */
18221 + bend = au_ibend(inode);
18222 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
18223 + h_inode = au_h_iptr(inode, bindex);
18225 + err = au_busy_or_stale();
18226 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18229 + br = au_sbr(sb, bindex);
18230 + err = h_permission(h_inode, mask, au_br_mnt(br),
18236 + ii_read_unlock(inode);
18237 + si_read_unlock(sb);
18241 +/* ---------------------------------------------------------------------- */
18243 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18244 + unsigned int flags)
18246 + struct dentry *ret, *parent;
18247 + struct inode *inode;
18248 + struct super_block *sb;
18249 + int err, npositive;
18253 + /* todo: support rcu-walk? */
18254 + ret = ERR_PTR(-ECHILD);
18255 + if (flags & LOOKUP_RCU)
18258 + ret = ERR_PTR(-ENAMETOOLONG);
18259 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18263 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18264 + ret = ERR_PTR(err);
18265 + if (unlikely(err))
18268 + err = au_di_init(dentry);
18269 + ret = ERR_PTR(err);
18270 + if (unlikely(err))
18274 + npositive = 0; /* suppress a warning */
18275 + parent = dentry->d_parent; /* dir inode is locked */
18276 + di_read_lock_parent(parent, AuLock_IR);
18277 + err = au_alive_dir(parent);
18279 + err = au_digen_test(parent, au_sigen(sb));
18281 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
18285 + di_read_unlock(parent, AuLock_IR);
18286 + ret = ERR_PTR(err);
18287 + if (unlikely(err < 0))
18291 + inode = au_new_inode(dentry, /*must_new*/0);
18292 + if (IS_ERR(inode)) {
18293 + ret = (void *)inode;
18300 + atomic_inc(&inode->i_count);
18301 + ret = d_splice_alias(inode, dentry);
18303 + if (unlikely(d_need_lookup(dentry))) {
18304 + spin_lock(&dentry->d_lock);
18305 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18306 + spin_unlock(&dentry->d_lock);
18310 + if (!IS_ERR(ret)) {
18312 + if (ret && ret != dentry)
18313 + ii_write_unlock(inode);
18315 + ii_write_unlock(inode);
18322 + di_write_unlock(dentry);
18324 + /* verbose coding for lock class name */
18325 + if (unlikely(S_ISLNK(inode->i_mode)))
18326 + au_rw_class(&au_di(dentry)->di_rwsem,
18327 + au_lc_key + AuLcSymlink_DIINFO);
18328 + else if (unlikely(S_ISDIR(inode->i_mode)))
18329 + au_rw_class(&au_di(dentry)->di_rwsem,
18330 + au_lc_key + AuLcDir_DIINFO);
18331 + else /* likely */
18332 + au_rw_class(&au_di(dentry)->di_rwsem,
18333 + au_lc_key + AuLcNonDir_DIINFO);
18336 + si_read_unlock(sb);
18341 +/* ---------------------------------------------------------------------- */
18343 +struct aopen_node {
18344 + struct hlist_node hlist;
18345 + struct file *file, *h_file;
18348 +static int au_do_aopen(struct inode *inode, struct file *file)
18350 + struct au_sphlhead *aopen;
18351 + struct aopen_node *node;
18352 + struct au_do_open_args args = {
18354 + .open = au_do_open_nondir
18357 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18358 + spin_lock(&aopen->spin);
18359 + hlist_for_each_entry(node, &aopen->head, hlist)
18360 + if (node->file == file) {
18361 + args.h_file = node->h_file;
18364 + spin_unlock(&aopen->spin);
18365 + /* AuDebugOn(!args.h_file); */
18367 + return au_do_open(file, &args);
18370 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18371 + struct file *file, unsigned int open_flag,
18372 + umode_t create_mode, int *opened)
18374 + int err, h_opened = *opened;
18375 + struct dentry *parent;
18376 + struct dentry *d;
18377 + struct au_sphlhead *aopen;
18378 + struct vfsub_aopen_args args = {
18379 + .open_flag = open_flag,
18380 + .create_mode = create_mode,
18381 + .opened = &h_opened
18383 + struct aopen_node aopen_node = {
18388 + AuDbg("open_flag 0x%x\n", open_flag);
18389 + AuDbgDentry(dentry);
18392 + if (!au_di(dentry)) {
18393 + d = aufs_lookup(dir, dentry, /*flags*/0);
18395 + err = PTR_ERR(d);
18399 + * obsoleted dentry found.
18400 + * another error will be returned later.
18406 + AuDbgDentry(dentry);
18409 + if (d_is_positive(dentry)
18410 + || d_unhashed(dentry)
18411 + || d_unlinked(dentry)
18412 + || !(open_flag & O_CREAT))
18413 + goto out_no_open;
18415 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18416 + if (unlikely(err))
18419 + parent = dentry->d_parent; /* dir is locked */
18420 + di_write_lock_parent(parent);
18421 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
18422 + if (unlikely(err))
18425 + AuDbgDentry(dentry);
18426 + if (d_is_positive(dentry))
18429 + args.file = get_empty_filp();
18430 + err = PTR_ERR(args.file);
18431 + if (IS_ERR(args.file))
18434 + args.file->f_flags = file->f_flags;
18435 + err = au_aopen_or_create(dir, dentry, &args);
18437 + AuDbgFile(args.file);
18438 + if (unlikely(err < 0)) {
18439 + if (h_opened & FILE_OPENED)
18442 + put_filp(args.file);
18446 + /* some filesystems don't set FILE_CREATED while succeeded? */
18447 + *opened |= FILE_CREATED;
18448 + if (h_opened & FILE_OPENED)
18449 + aopen_node.h_file = args.file;
18451 + put_filp(args.file);
18452 + args.file = NULL;
18454 + aopen = &au_sbi(dir->i_sb)->si_aopen;
18455 + au_sphl_add(&aopen_node.hlist, aopen);
18456 + err = finish_open(file, dentry, au_do_aopen, opened);
18457 + au_sphl_del(&aopen_node.hlist, aopen);
18460 + if (aopen_node.h_file)
18461 + fput(aopen_node.h_file);
18464 + di_write_unlock(parent);
18465 + aufs_read_unlock(dentry, AuLock_DW);
18466 + AuDbgDentry(dentry);
18467 + if (unlikely(err))
18470 + if (!err && !(*opened & FILE_CREATED)) {
18471 + AuLabel(out_no_open);
18473 + err = finish_no_open(file, dentry);
18476 + AuDbg("%pd%s%s\n", dentry,
18477 + (*opened & FILE_CREATED) ? " created" : "",
18478 + (*opened & FILE_OPENED) ? " opened" : "");
18484 +/* ---------------------------------------------------------------------- */
18486 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18487 + const unsigned char add_entry, aufs_bindex_t bcpup,
18488 + aufs_bindex_t bstart)
18491 + struct dentry *h_parent;
18492 + struct inode *h_dir;
18495 + IMustLock(parent->d_inode);
18497 + di_write_lock_parent(parent);
18500 + if (!au_h_dptr(parent, bcpup)) {
18501 + if (bstart > bcpup)
18502 + err = au_cpup_dirs(dentry, bcpup);
18503 + else if (bstart < bcpup)
18504 + err = au_cpdown_dirs(dentry, bcpup);
18508 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18509 + h_parent = au_h_dptr(parent, bcpup);
18510 + h_dir = h_parent->d_inode;
18511 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
18512 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
18513 + /* todo: no unlock here */
18514 + mutex_unlock(&h_dir->i_mutex);
18516 + AuDbg("bcpup %d\n", bcpup);
18518 + if (!dentry->d_inode)
18519 + au_set_h_dptr(dentry, bstart, NULL);
18520 + au_update_dbrange(dentry, /*do_put_zero*/0);
18525 + di_write_unlock(parent);
18527 + err = bcpup; /* success */
18534 + * decide the branch and the parent dir where we will create a new entry.
18535 + * returns new bindex or an error.
18536 + * copyup the parent dir if needed.
18538 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18539 + struct au_wr_dir_args *args)
18542 + unsigned int flags;
18543 + aufs_bindex_t bcpup, bstart, src_bstart;
18544 + const unsigned char add_entry
18545 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18546 + | au_ftest_wrdir(args->flags, TMPFILE);
18547 + struct super_block *sb;
18548 + struct dentry *parent;
18549 + struct au_sbinfo *sbinfo;
18551 + sb = dentry->d_sb;
18552 + sbinfo = au_sbi(sb);
18553 + parent = dget_parent(dentry);
18554 + bstart = au_dbstart(dentry);
18556 + if (args->force_btgt < 0) {
18557 + if (src_dentry) {
18558 + src_bstart = au_dbstart(src_dentry);
18559 + if (src_bstart < bstart)
18560 + bcpup = src_bstart;
18561 + } else if (add_entry) {
18563 + if (au_ftest_wrdir(args->flags, ISDIR))
18564 + au_fset_wbr(flags, DIR);
18565 + err = AuWbrCreate(sbinfo, dentry, flags);
18569 + if (bcpup < 0 || au_test_ro(sb, bcpup, dentry->d_inode)) {
18571 + err = AuWbrCopyup(sbinfo, dentry);
18573 + if (!IS_ROOT(dentry)) {
18574 + di_read_lock_parent(parent, !AuLock_IR);
18575 + err = AuWbrCopyup(sbinfo, dentry);
18576 + di_read_unlock(parent, !AuLock_IR);
18578 + err = AuWbrCopyup(sbinfo, dentry);
18581 + if (unlikely(err < 0))
18585 + bcpup = args->force_btgt;
18586 + AuDebugOn(au_test_ro(sb, bcpup, dentry->d_inode));
18589 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
18591 + if (bcpup == bstart)
18592 + goto out; /* success */
18594 + /* copyup the new parent into the branch we process */
18595 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
18597 + if (!dentry->d_inode) {
18598 + au_set_h_dptr(dentry, bstart, NULL);
18599 + au_set_dbstart(dentry, bcpup);
18600 + au_set_dbend(dentry, bcpup);
18602 + AuDebugOn(add_entry
18603 + && !au_ftest_wrdir(args->flags, TMPFILE)
18604 + && !au_h_dptr(dentry, bcpup));
18612 +/* ---------------------------------------------------------------------- */
18614 +void au_pin_hdir_unlock(struct au_pin *p)
18617 + au_hn_imtx_unlock(p->hdir);
18620 +int au_pin_hdir_lock(struct au_pin *p)
18628 + /* even if an error happens later, keep this lock */
18629 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
18632 + if (unlikely(p->hdir->hi_inode != p->h_parent->d_inode))
18637 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18638 + p->h_parent, p->br);
18644 +int au_pin_hdir_relock(struct au_pin *p)
18647 + struct inode *h_i;
18648 + struct dentry *h_d[] = {
18653 + err = au_pin_hdir_lock(p);
18654 + if (unlikely(err))
18657 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
18660 + h_i = h_d[i]->d_inode;
18662 + err = !h_i->i_nlink;
18669 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
18671 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
18672 + p->hdir->hi_inode->i_mutex.owner = task;
18676 +void au_pin_hdir_acquire_nest(struct au_pin *p)
18679 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
18680 + p->lsc_hi, 0, NULL, _RET_IP_);
18681 + au_pin_hdir_set_owner(p, current);
18685 +void au_pin_hdir_release(struct au_pin *p)
18688 + au_pin_hdir_set_owner(p, p->task);
18689 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
18693 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
18695 + if (pin && pin->parent)
18696 + return au_h_dptr(pin->parent, pin->bindex);
18700 +void au_unpin(struct au_pin *p)
18703 + au_pin_hdir_unlock(p);
18704 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
18705 + vfsub_mnt_drop_write(p->h_mnt);
18709 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18710 + di_read_unlock(p->parent, AuLock_IR);
18711 + iput(p->hdir->hi_inode);
18713 + p->parent = NULL;
18716 + /* do not clear p->task */
18719 +int au_do_pin(struct au_pin *p)
18722 + struct super_block *sb;
18723 + struct inode *h_dir;
18726 + sb = p->dentry->d_sb;
18727 + p->br = au_sbr(sb, p->bindex);
18728 + if (IS_ROOT(p->dentry)) {
18729 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18730 + p->h_mnt = au_br_mnt(p->br);
18731 + err = vfsub_mnt_want_write(p->h_mnt);
18732 + if (unlikely(err)) {
18733 + au_fclr_pin(p->flags, MNT_WRITE);
18740 + p->h_dentry = NULL;
18741 + if (p->bindex <= au_dbend(p->dentry))
18742 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
18744 + p->parent = dget_parent(p->dentry);
18745 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18746 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
18749 + p->h_parent = au_h_dptr(p->parent, p->bindex);
18750 + p->hdir = au_hi(p->parent->d_inode, p->bindex);
18752 + h_dir = p->hdir->hi_inode;
18756 + * if DI_LOCKED is not set, then p->parent may be different
18757 + * and h_parent can be NULL.
18759 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
18761 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18762 + di_read_unlock(p->parent, AuLock_IR);
18764 + p->parent = NULL;
18768 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18769 + p->h_mnt = au_br_mnt(p->br);
18770 + err = vfsub_mnt_want_write(p->h_mnt);
18771 + if (unlikely(err)) {
18772 + au_fclr_pin(p->flags, MNT_WRITE);
18773 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18774 + di_read_unlock(p->parent, AuLock_IR);
18776 + p->parent = NULL;
18782 + err = au_pin_hdir_lock(p);
18784 + goto out; /* success */
18789 + pr_err("err %d\n", err);
18790 + err = au_busy_or_stale();
18795 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
18796 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18797 + unsigned int udba, unsigned char flags)
18799 + p->dentry = dentry;
18801 + p->lsc_di = lsc_di;
18802 + p->lsc_hi = lsc_hi;
18803 + p->flags = flags;
18804 + p->bindex = bindex;
18806 + p->parent = NULL;
18810 + p->h_dentry = NULL;
18811 + p->h_parent = NULL;
18813 + p->task = current;
18816 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18817 + unsigned int udba, unsigned char flags)
18819 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
18821 + return au_do_pin(pin);
18824 +/* ---------------------------------------------------------------------- */
18827 + * ->setattr() and ->getattr() are called in various cases.
18828 + * chmod, stat: dentry is revalidated.
18829 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
18831 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
18833 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
18834 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
18837 + struct inode *inode;
18838 + struct dentry *parent;
18841 + inode = dentry->d_inode;
18842 + if (au_digen_test(dentry, sigen)) {
18843 + parent = dget_parent(dentry);
18844 + di_read_lock_parent(parent, AuLock_IR);
18845 + err = au_refresh_dentry(dentry, parent);
18846 + di_read_unlock(parent, AuLock_IR);
18854 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18855 + struct au_icpup_args *a)
18859 + aufs_bindex_t bstart, ibstart;
18860 + struct dentry *hi_wh, *parent;
18861 + struct inode *inode;
18862 + struct au_wr_dir_args wr_dir_args = {
18863 + .force_btgt = -1,
18867 + if (d_is_dir(dentry))
18868 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18869 + /* plink or hi_wh() case */
18870 + bstart = au_dbstart(dentry);
18871 + inode = dentry->d_inode;
18872 + ibstart = au_ibstart(inode);
18873 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
18874 + wr_dir_args.force_btgt = ibstart;
18875 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18876 + if (unlikely(err < 0))
18879 + if (err != bstart)
18880 + au_fset_icpup(a->flags, DID_CPUP);
18883 + a->pin_flags = AuPin_MNT_WRITE;
18885 + if (!IS_ROOT(dentry)) {
18886 + au_fset_pin(a->pin_flags, DI_LOCKED);
18887 + parent = dget_parent(dentry);
18888 + di_write_lock_parent(parent);
18891 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
18892 + if (unlikely(err))
18895 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18896 + a->h_inode = a->h_path.dentry->d_inode;
18898 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
18899 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18900 + if (ia->ia_size < i_size_read(a->h_inode))
18901 + sz = ia->ia_size;
18902 + mutex_unlock(&a->h_inode->i_mutex);
18906 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
18907 + hi_wh = au_hi_wh(inode, a->btgt);
18909 + struct au_cp_generic cpg = {
18910 + .dentry = dentry,
18916 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
18917 + if (unlikely(err))
18919 + hi_wh = au_hi_wh(inode, a->btgt);
18920 + /* todo: revalidate hi_wh? */
18925 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
18926 + di_downgrade_lock(parent, AuLock_IR);
18930 + if (!au_ftest_icpup(a->flags, DID_CPUP))
18931 + goto out; /* success */
18933 + if (!d_unhashed(dentry)) {
18934 + struct au_cp_generic cpg = {
18935 + .dentry = dentry,
18940 + .flags = AuCpup_DTIME | AuCpup_HOPEN
18942 + err = au_sio_cpup_simple(&cpg);
18944 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18945 + } else if (!hi_wh)
18946 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18948 + a->h_path.dentry = hi_wh; /* do not dget here */
18951 + a->h_inode = a->h_path.dentry->d_inode;
18953 + goto out; /* success */
18954 + au_unpin(&a->pin);
18957 + di_write_unlock(parent);
18962 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18966 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
18969 + struct inode *inode, *delegated;
18970 + struct super_block *sb;
18971 + struct file *file;
18972 + struct au_icpup_args *a;
18974 + inode = dentry->d_inode;
18975 + IMustLock(inode);
18978 + a = kzalloc(sizeof(*a), GFP_NOFS);
18979 + if (unlikely(!a))
18982 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
18983 + ia->ia_valid &= ~ATTR_MODE;
18986 + sb = dentry->d_sb;
18987 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18988 + if (unlikely(err))
18991 + if (ia->ia_valid & ATTR_FILE) {
18992 + /* currently ftruncate(2) only */
18993 + AuDebugOn(!d_is_reg(dentry));
18994 + file = ia->ia_file;
18995 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
18996 + if (unlikely(err))
18998 + ia->ia_file = au_hf_top(file);
18999 + a->udba = AuOpt_UDBA_NONE;
19001 + /* fchmod() doesn't pass ia_file */
19002 + a->udba = au_opt_udba(sb);
19003 + di_write_lock_child(dentry);
19004 + /* no d_unlinked(), to set UDBA_NONE for root */
19005 + if (d_unhashed(dentry))
19006 + a->udba = AuOpt_UDBA_NONE;
19007 + if (a->udba != AuOpt_UDBA_NONE) {
19008 + AuDebugOn(IS_ROOT(dentry));
19009 + err = au_reval_for_attr(dentry, au_sigen(sb));
19010 + if (unlikely(err))
19015 + err = au_pin_and_icpup(dentry, ia, a);
19016 + if (unlikely(err < 0))
19018 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19019 + ia->ia_file = NULL;
19020 + ia->ia_valid &= ~ATTR_FILE;
19023 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19024 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19025 + == (ATTR_MODE | ATTR_CTIME)) {
19026 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19027 + if (unlikely(err))
19029 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19030 + && (ia->ia_valid & ATTR_CTIME)) {
19031 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19032 + if (unlikely(err))
19036 + if (ia->ia_valid & ATTR_SIZE) {
19039 + if (ia->ia_size < i_size_read(inode))
19041 + truncate_setsize(inode, ia->ia_size);
19044 + if (ia->ia_valid & ATTR_FILE)
19046 + mutex_unlock(&a->h_inode->i_mutex);
19047 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19048 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
19050 + delegated = NULL;
19052 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19054 + err = break_deleg_wait(&delegated);
19062 + au_cpup_attr_changeable(inode);
19065 + mutex_unlock(&a->h_inode->i_mutex);
19066 + au_unpin(&a->pin);
19067 + if (unlikely(err))
19068 + au_update_dbstart(dentry);
19070 + di_write_unlock(dentry);
19072 + fi_write_unlock(file);
19073 + ia->ia_file = file;
19074 + ia->ia_valid |= ATTR_FILE;
19077 + si_read_unlock(sb);
19085 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19086 +static int au_h_path_to_set_attr(struct dentry *dentry,
19087 + struct au_icpup_args *a, struct path *h_path)
19090 + struct super_block *sb;
19092 + sb = dentry->d_sb;
19093 + a->udba = au_opt_udba(sb);
19094 + /* no d_unlinked(), to set UDBA_NONE for root */
19095 + if (d_unhashed(dentry))
19096 + a->udba = AuOpt_UDBA_NONE;
19097 + if (a->udba != AuOpt_UDBA_NONE) {
19098 + AuDebugOn(IS_ROOT(dentry));
19099 + err = au_reval_for_attr(dentry, au_sigen(sb));
19100 + if (unlikely(err))
19103 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19104 + if (unlikely(err < 0))
19107 + h_path->dentry = a->h_path.dentry;
19108 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19114 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg)
19117 + struct path h_path;
19118 + struct super_block *sb;
19119 + struct au_icpup_args *a;
19120 + struct inode *inode, *h_inode;
19122 + inode = dentry->d_inode;
19123 + IMustLock(inode);
19126 + a = kzalloc(sizeof(*a), GFP_NOFS);
19127 + if (unlikely(!a))
19130 + sb = dentry->d_sb;
19131 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19132 + if (unlikely(err))
19135 + h_path.dentry = NULL; /* silence gcc */
19136 + di_write_lock_child(dentry);
19137 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19138 + if (unlikely(err))
19141 + mutex_unlock(&a->h_inode->i_mutex);
19142 + switch (arg->type) {
19143 + case AU_XATTR_SET:
19144 + err = vfsub_setxattr(h_path.dentry,
19145 + arg->u.set.name, arg->u.set.value,
19146 + arg->u.set.size, arg->u.set.flags);
19148 + case AU_XATTR_REMOVE:
19149 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
19152 + err = -EOPNOTSUPP;
19153 + h_inode = h_path.dentry->d_inode;
19154 + if (h_inode->i_op->set_acl)
19155 + err = h_inode->i_op->set_acl(h_inode,
19156 + arg->u.acl_set.acl,
19157 + arg->u.acl_set.type);
19161 + au_cpup_attr_timesizes(inode);
19163 + au_unpin(&a->pin);
19164 + if (unlikely(err))
19165 + au_update_dbstart(dentry);
19168 + di_write_unlock(dentry);
19169 + si_read_unlock(sb);
19178 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19179 + unsigned int nlink)
19183 + inode->i_mode = st->mode;
19184 + /* don't i_[ug]id_write() here */
19185 + inode->i_uid = st->uid;
19186 + inode->i_gid = st->gid;
19187 + inode->i_atime = st->atime;
19188 + inode->i_mtime = st->mtime;
19189 + inode->i_ctime = st->ctime;
19191 + au_cpup_attr_nlink(inode, /*force*/0);
19192 + if (S_ISDIR(inode->i_mode)) {
19193 + n = inode->i_nlink;
19196 + smp_mb(); /* for i_nlink */
19197 + /* 0 can happen */
19198 + set_nlink(inode, n);
19201 + spin_lock(&inode->i_lock);
19202 + inode->i_blocks = st->blocks;
19203 + i_size_write(inode, st->size);
19204 + spin_unlock(&inode->i_lock);
19208 + * common routine for aufs_getattr() and aufs_getxattr().
19209 + * returns zero or negative (an error).
19210 + * @dentry will be read-locked in success.
19212 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
19215 + unsigned int mnt_flags, sigen;
19216 + unsigned char udba_none;
19217 + aufs_bindex_t bindex;
19218 + struct super_block *sb, *h_sb;
19219 + struct inode *inode;
19221 + h_path->mnt = NULL;
19222 + h_path->dentry = NULL;
19225 + sb = dentry->d_sb;
19226 + mnt_flags = au_mntflags(sb);
19227 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19229 + /* support fstat(2) */
19230 + if (!d_unlinked(dentry) && !udba_none) {
19231 + sigen = au_sigen(sb);
19232 + err = au_digen_test(dentry, sigen);
19234 + di_read_lock_child(dentry, AuLock_IR);
19235 + err = au_dbrange_test(dentry);
19236 + if (unlikely(err)) {
19237 + di_read_unlock(dentry, AuLock_IR);
19241 + AuDebugOn(IS_ROOT(dentry));
19242 + di_write_lock_child(dentry);
19243 + err = au_dbrange_test(dentry);
19245 + err = au_reval_for_attr(dentry, sigen);
19247 + di_downgrade_lock(dentry, AuLock_IR);
19249 + di_write_unlock(dentry);
19254 + di_read_lock_child(dentry, AuLock_IR);
19256 + inode = dentry->d_inode;
19257 + bindex = au_ibstart(inode);
19258 + h_path->mnt = au_sbr_mnt(sb, bindex);
19259 + h_sb = h_path->mnt->mnt_sb;
19261 + && !au_test_fs_bad_iattr(h_sb)
19263 + goto out; /* success */
19265 + if (au_dbstart(dentry) == bindex)
19266 + h_path->dentry = au_h_dptr(dentry, bindex);
19267 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19268 + h_path->dentry = au_plink_lkup(inode, bindex);
19269 + if (IS_ERR(h_path->dentry))
19270 + /* pretending success */
19271 + h_path->dentry = NULL;
19273 + dput(h_path->dentry);
19280 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19281 + struct dentry *dentry, struct kstat *st)
19284 + unsigned char positive;
19285 + struct path h_path;
19286 + struct inode *inode;
19287 + struct super_block *sb;
19289 + inode = dentry->d_inode;
19290 + sb = dentry->d_sb;
19291 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19292 + if (unlikely(err))
19294 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
19295 + if (unlikely(err))
19297 + if (unlikely(!h_path.dentry))
19298 + /* illegally overlapped or something */
19299 + goto out_fill; /* pretending success */
19301 + positive = !!h_path.dentry->d_inode;
19303 + err = vfs_getattr(&h_path, st);
19306 + au_refresh_iattr(inode, st,
19307 + h_path.dentry->d_inode->i_nlink);
19308 + goto out_fill; /* success */
19314 + generic_fillattr(inode, st);
19316 + di_read_unlock(dentry, AuLock_IR);
19318 + si_read_unlock(sb);
19324 +/* ---------------------------------------------------------------------- */
19326 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
19330 + struct super_block *sb;
19331 + struct dentry *h_dentry;
19334 + h_dentry = au_h_dptr(dentry, bindex);
19335 + if (unlikely(!h_dentry->d_inode->i_op->readlink))
19338 + err = security_inode_readlink(h_dentry);
19339 + if (unlikely(err))
19342 + sb = dentry->d_sb;
19343 + if (!au_test_ro(sb, bindex, dentry->d_inode)) {
19344 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
19345 + fsstack_copy_attr_atime(dentry->d_inode, h_dentry->d_inode);
19347 + err = h_dentry->d_inode->i_op->readlink(h_dentry, buf, bufsiz);
19353 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
19357 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19358 + if (unlikely(err))
19360 + err = au_d_hashed_positive(dentry);
19362 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
19363 + aufs_read_unlock(dentry, AuLock_IR);
19369 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
19372 + mm_segment_t old_fs;
19379 + buf.k = (void *)__get_free_page(GFP_NOFS);
19380 + if (unlikely(!buf.k))
19383 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19384 + if (unlikely(err))
19387 + err = au_d_hashed_positive(dentry);
19389 + old_fs = get_fs();
19390 + set_fs(KERNEL_DS);
19391 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
19394 + aufs_read_unlock(dentry, AuLock_IR);
19398 + /* will be freed by put_link */
19399 + nd_set_link(nd, buf.k);
19400 + return NULL; /* success */
19404 + free_page((unsigned long)buf.k);
19407 + return ERR_PTR(err);
19410 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
19411 + struct nameidata *nd, void *cookie __maybe_unused)
19415 + p = nd_get_link(nd);
19416 + if (!IS_ERR_OR_NULL(p))
19417 + free_page((unsigned long)p);
19420 +/* ---------------------------------------------------------------------- */
19422 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19425 + struct super_block *sb;
19426 + struct inode *h_inode;
19428 + sb = inode->i_sb;
19429 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19431 + si_read_lock(sb, AuLock_FLUSH);
19432 + ii_write_lock_child(inode);
19434 + h_inode = au_h_iptr(inode, au_ibstart(inode));
19435 + err = vfsub_update_time(h_inode, ts, flags);
19438 + au_cpup_attr_timesizes(inode);
19439 + ii_write_unlock(inode);
19440 + si_read_unlock(sb);
19443 + if (!err && (flags & S_VERSION))
19444 + inode_inc_iversion(inode);
19449 +/* ---------------------------------------------------------------------- */
19451 +struct inode_operations aufs_symlink_iop = {
19452 + .permission = aufs_permission,
19453 +#ifdef CONFIG_FS_POSIX_ACL
19454 + .get_acl = aufs_get_acl,
19455 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19458 + .setattr = aufs_setattr,
19459 + .getattr = aufs_getattr,
19461 +#ifdef CONFIG_AUFS_XATTR
19462 + .setxattr = aufs_setxattr,
19463 + .getxattr = aufs_getxattr,
19464 + .listxattr = aufs_listxattr,
19465 + .removexattr = aufs_removexattr,
19468 + .readlink = aufs_readlink,
19469 + .follow_link = aufs_follow_link,
19470 + .put_link = aufs_put_link,
19472 + /* .update_time = aufs_update_time */
19475 +struct inode_operations aufs_dir_iop = {
19476 + .create = aufs_create,
19477 + .lookup = aufs_lookup,
19478 + .link = aufs_link,
19479 + .unlink = aufs_unlink,
19480 + .symlink = aufs_symlink,
19481 + .mkdir = aufs_mkdir,
19482 + .rmdir = aufs_rmdir,
19483 + .mknod = aufs_mknod,
19484 + .rename = aufs_rename,
19486 + .permission = aufs_permission,
19487 +#ifdef CONFIG_FS_POSIX_ACL
19488 + .get_acl = aufs_get_acl,
19489 + .set_acl = aufs_set_acl,
19492 + .setattr = aufs_setattr,
19493 + .getattr = aufs_getattr,
19495 +#ifdef CONFIG_AUFS_XATTR
19496 + .setxattr = aufs_setxattr,
19497 + .getxattr = aufs_getxattr,
19498 + .listxattr = aufs_listxattr,
19499 + .removexattr = aufs_removexattr,
19502 + .update_time = aufs_update_time,
19503 + .atomic_open = aufs_atomic_open,
19504 + .tmpfile = aufs_tmpfile
19507 +struct inode_operations aufs_iop = {
19508 + .permission = aufs_permission,
19509 +#ifdef CONFIG_FS_POSIX_ACL
19510 + .get_acl = aufs_get_acl,
19511 + .set_acl = aufs_set_acl,
19514 + .setattr = aufs_setattr,
19515 + .getattr = aufs_getattr,
19517 +#ifdef CONFIG_AUFS_XATTR
19518 + .setxattr = aufs_setxattr,
19519 + .getxattr = aufs_getxattr,
19520 + .listxattr = aufs_listxattr,
19521 + .removexattr = aufs_removexattr,
19524 + .update_time = aufs_update_time
19526 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19527 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19528 +++ linux/fs/aufs/i_op_del.c 2015-06-22 08:27:37.884168534 +0200
19531 + * Copyright (C) 2005-2015 Junjiro R. Okajima
19533 + * This program, aufs is free software; you can redistribute it and/or modify
19534 + * it under the terms of the GNU General Public License as published by
19535 + * the Free Software Foundation; either version 2 of the License, or
19536 + * (at your option) any later version.
19538 + * This program is distributed in the hope that it will be useful,
19539 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19540 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19541 + * GNU General Public License for more details.
19543 + * You should have received a copy of the GNU General Public License
19544 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19548 + * inode operations (del entry)
19554 + * decide if a new whiteout for @dentry is necessary or not.
19555 + * when it is necessary, prepare the parent dir for the upper branch whose
19556 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19557 + * be done by caller.
19559 + * 0: wh is unnecessary
19560 + * plus: wh is necessary
19563 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19565 + int need_wh, err;
19566 + aufs_bindex_t bstart;
19567 + struct super_block *sb;
19569 + sb = dentry->d_sb;
19570 + bstart = au_dbstart(dentry);
19571 + if (*bcpup < 0) {
19573 + if (au_test_ro(sb, bstart, dentry->d_inode)) {
19574 + err = AuWbrCopyup(au_sbi(sb), dentry);
19576 + if (unlikely(err < 0))
19580 + AuDebugOn(bstart < *bcpup
19581 + || au_test_ro(sb, *bcpup, dentry->d_inode));
19582 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
19584 + if (*bcpup != bstart) {
19585 + err = au_cpup_dirs(dentry, *bcpup);
19586 + if (unlikely(err))
19590 + struct au_dinfo *dinfo, *tmp;
19592 + need_wh = -ENOMEM;
19593 + dinfo = au_di(dentry);
19594 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19596 + au_di_cp(tmp, dinfo);
19597 + au_di_swap(tmp, dinfo);
19598 + /* returns the number of positive dentries */
19599 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
19600 + au_di_swap(tmp, dinfo);
19601 + au_rw_write_unlock(&tmp->di_rwsem);
19605 + AuDbg("need_wh %d\n", need_wh);
19613 + * simple tests for the del-entry operations.
19614 + * following the checks in vfs, plus the parent-child relationship.
19616 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19617 + struct dentry *h_parent, int isdir)
19621 + struct dentry *h_dentry, *h_latest;
19622 + struct inode *h_inode;
19624 + h_dentry = au_h_dptr(dentry, bindex);
19625 + h_inode = h_dentry->d_inode;
19626 + if (dentry->d_inode) {
19628 + if (unlikely(!h_inode || !h_inode->i_nlink))
19631 + h_mode = h_inode->i_mode;
19634 + if (unlikely(S_ISDIR(h_mode)))
19636 + } else if (unlikely(!S_ISDIR(h_mode))) {
19641 + /* rename(2) case */
19643 + if (unlikely(h_inode))
19648 + /* expected parent dir is locked */
19649 + if (unlikely(h_parent != h_dentry->d_parent))
19654 + * rmdir a dir may break the consistency on some filesystem.
19655 + * let's try heavy test.
19658 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
19659 + && au_test_h_perm(h_parent->d_inode,
19660 + MAY_EXEC | MAY_WRITE)))
19663 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
19665 + if (IS_ERR(h_latest))
19667 + if (h_latest == h_dentry)
19676 + * decide the branch where we operate for @dentry. the branch index will be set
19677 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
19678 + * dir for reverting.
19679 + * when a new whiteout is necessary, create it.
19681 +static struct dentry*
19682 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
19683 + struct au_dtime *dt, struct au_pin *pin)
19685 + struct dentry *wh_dentry;
19686 + struct super_block *sb;
19687 + struct path h_path;
19688 + int err, need_wh;
19689 + unsigned int udba;
19690 + aufs_bindex_t bcpup;
19692 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
19693 + wh_dentry = ERR_PTR(need_wh);
19694 + if (unlikely(need_wh < 0))
19697 + sb = dentry->d_sb;
19698 + udba = au_opt_udba(sb);
19700 + err = au_pin(pin, dentry, bcpup, udba,
19701 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19702 + wh_dentry = ERR_PTR(err);
19703 + if (unlikely(err))
19706 + h_path.dentry = au_pinned_h_parent(pin);
19707 + if (udba != AuOpt_UDBA_NONE
19708 + && au_dbstart(dentry) == bcpup) {
19709 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
19710 + wh_dentry = ERR_PTR(err);
19711 + if (unlikely(err))
19715 + h_path.mnt = au_sbr_mnt(sb, bcpup);
19716 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
19717 + wh_dentry = NULL;
19719 + goto out; /* success, no need to create whiteout */
19721 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
19722 + if (IS_ERR(wh_dentry))
19725 + /* returns with the parent is locked and wh_dentry is dget-ed */
19726 + goto out; /* success */
19731 + return wh_dentry;
19735 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
19736 + * in order to be revertible and save time for removing many child whiteouts
19738 + * returns 1 when there are too many child whiteout and caller should remove
19739 + * them asynchronously. returns 0 when the number of children is enough small to
19740 + * remove now or the branch fs is a remote fs.
19741 + * otherwise return an error.
19743 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
19744 + struct au_nhash *whlist, struct inode *dir)
19746 + int rmdir_later, err, dirwh;
19747 + struct dentry *h_dentry;
19748 + struct super_block *sb;
19750 + sb = dentry->d_sb;
19751 + SiMustAnyLock(sb);
19752 + h_dentry = au_h_dptr(dentry, bindex);
19753 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
19754 + if (unlikely(err))
19757 + /* stop monitoring */
19758 + au_hn_free(au_hi(dentry->d_inode, bindex));
19760 + if (!au_test_fs_remote(h_dentry->d_sb)) {
19761 + dirwh = au_sbi(sb)->si_dirwh;
19762 + rmdir_later = (dirwh <= 1);
19763 + if (!rmdir_later)
19764 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
19767 + return rmdir_later;
19770 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
19771 + if (unlikely(err)) {
19772 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
19773 + h_dentry, bindex, err);
19783 + * final procedure for deleting a entry.
19784 + * maintain dentry and iattr.
19786 +static void epilog(struct inode *dir, struct dentry *dentry,
19787 + aufs_bindex_t bindex)
19789 + struct inode *inode;
19791 + inode = dentry->d_inode;
19793 + inode->i_ctime = dir->i_ctime;
19795 + au_dir_ts(dir, bindex);
19796 + dir->i_version++;
19800 + * when an error happened, remove the created whiteout and revert everything.
19802 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
19803 + aufs_bindex_t bwh, struct dentry *wh_dentry,
19804 + struct dentry *dentry, struct au_dtime *dt)
19807 + struct path h_path = {
19808 + .dentry = wh_dentry,
19809 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
19812 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
19814 + au_set_dbwh(dentry, bwh);
19815 + au_dtime_revert(dt);
19819 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
19823 +/* ---------------------------------------------------------------------- */
19825 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
19828 + aufs_bindex_t bwh, bindex, bstart;
19829 + struct inode *inode, *h_dir, *delegated;
19830 + struct dentry *parent, *wh_dentry;
19831 + /* to reuduce stack size */
19833 + struct au_dtime dt;
19834 + struct au_pin pin;
19835 + struct path h_path;
19841 + a = kmalloc(sizeof(*a), GFP_NOFS);
19842 + if (unlikely(!a))
19845 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19846 + if (unlikely(err))
19848 + err = au_d_hashed_positive(dentry);
19849 + if (unlikely(err))
19851 + inode = dentry->d_inode;
19852 + IMustLock(inode);
19854 + if (unlikely(d_is_dir(dentry)))
19855 + goto out_unlock; /* possible? */
19857 + bstart = au_dbstart(dentry);
19858 + bwh = au_dbwh(dentry);
19860 + parent = dentry->d_parent; /* dir inode is locked */
19861 + di_write_lock_parent(parent);
19862 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
19864 + err = PTR_ERR(wh_dentry);
19865 + if (IS_ERR(wh_dentry))
19868 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
19869 + a->h_path.dentry = au_h_dptr(dentry, bstart);
19870 + dget(a->h_path.dentry);
19871 + if (bindex == bstart) {
19872 + h_dir = au_pinned_h_dir(&a->pin);
19873 + delegated = NULL;
19874 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
19875 + if (unlikely(err == -EWOULDBLOCK)) {
19876 + pr_warn("cannot retry for NFSv4 delegation"
19877 + " for an internal unlink\n");
19881 + /* dir inode is locked */
19882 + h_dir = wh_dentry->d_parent->d_inode;
19883 + IMustLock(h_dir);
19888 + vfsub_drop_nlink(inode);
19889 + epilog(dir, dentry, bindex);
19891 + /* update target timestamps */
19892 + if (bindex == bstart) {
19893 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
19895 + inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
19897 + /* todo: this timestamp may be reverted later */
19898 + inode->i_ctime = h_dir->i_ctime;
19899 + goto out_unpin; /* success */
19906 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19913 + au_unpin(&a->pin);
19915 + dput(a->h_path.dentry);
19917 + di_write_unlock(parent);
19919 + aufs_read_unlock(dentry, AuLock_DW);
19926 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
19928 + int err, rmdir_later;
19929 + aufs_bindex_t bwh, bindex, bstart;
19930 + struct inode *inode;
19931 + struct dentry *parent, *wh_dentry, *h_dentry;
19932 + struct au_whtmp_rmdir *args;
19933 + /* to reuduce stack size */
19935 + struct au_dtime dt;
19936 + struct au_pin pin;
19942 + a = kmalloc(sizeof(*a), GFP_NOFS);
19943 + if (unlikely(!a))
19946 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
19947 + if (unlikely(err))
19949 + err = au_alive_dir(dentry);
19950 + if (unlikely(err))
19952 + inode = dentry->d_inode;
19953 + IMustLock(inode);
19955 + if (unlikely(!d_is_dir(dentry)))
19956 + goto out_unlock; /* possible? */
19959 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
19960 + if (unlikely(!args))
19963 + parent = dentry->d_parent; /* dir inode is locked */
19964 + di_write_lock_parent(parent);
19965 + err = au_test_empty(dentry, &args->whlist);
19966 + if (unlikely(err))
19969 + bstart = au_dbstart(dentry);
19970 + bwh = au_dbwh(dentry);
19972 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
19974 + err = PTR_ERR(wh_dentry);
19975 + if (IS_ERR(wh_dentry))
19978 + h_dentry = au_h_dptr(dentry, bstart);
19981 + if (bindex == bstart) {
19982 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
19984 + rmdir_later = err;
19988 + /* stop monitoring */
19989 + au_hn_free(au_hi(inode, bstart));
19991 + /* dir inode is locked */
19992 + IMustLock(wh_dentry->d_parent->d_inode);
19997 + vfsub_dead_dir(inode);
19998 + au_set_dbdiropq(dentry, -1);
19999 + epilog(dir, dentry, bindex);
20001 + if (rmdir_later) {
20002 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
20006 + goto out_unpin; /* success */
20014 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20021 + au_unpin(&a->pin);
20025 + di_write_unlock(parent);
20027 + au_whtmp_rmdir_free(args);
20029 + aufs_read_unlock(dentry, AuLock_DW);
20036 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20037 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20038 +++ linux/fs/aufs/i_op_ren.c 2015-06-22 08:27:37.884168534 +0200
20041 + * Copyright (C) 2005-2015 Junjiro R. Okajima
20043 + * This program, aufs is free software; you can redistribute it and/or modify
20044 + * it under the terms of the GNU General Public License as published by
20045 + * the Free Software Foundation; either version 2 of the License, or
20046 + * (at your option) any later version.
20048 + * This program is distributed in the hope that it will be useful,
20049 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20050 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20051 + * GNU General Public License for more details.
20053 + * You should have received a copy of the GNU General Public License
20054 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20058 + * inode operation (rename entry)
20059 + * todo: this is crazy monster
20064 +enum { AuSRC, AuDST, AuSrcDst };
20065 +enum { AuPARENT, AuCHILD, AuParentChild };
20067 +#define AuRen_ISDIR 1
20068 +#define AuRen_ISSAMEDIR (1 << 1)
20069 +#define AuRen_WHSRC (1 << 2)
20070 +#define AuRen_WHDST (1 << 3)
20071 +#define AuRen_MNT_WRITE (1 << 4)
20072 +#define AuRen_DT_DSTDIR (1 << 5)
20073 +#define AuRen_DIROPQ (1 << 6)
20074 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20075 +#define au_fset_ren(flags, name) \
20076 + do { (flags) |= AuRen_##name; } while (0)
20077 +#define au_fclr_ren(flags, name) \
20078 + do { (flags) &= ~AuRen_##name; } while (0)
20080 +struct au_ren_args {
20082 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20084 + struct inode *dir, *inode;
20085 + struct au_hinode *hdir;
20086 + struct au_dtime dt[AuParentChild];
20087 + aufs_bindex_t bstart;
20090 +#define src_dentry sd[AuSRC].dentry
20091 +#define src_dir sd[AuSRC].dir
20092 +#define src_inode sd[AuSRC].inode
20093 +#define src_h_dentry sd[AuSRC].h_dentry
20094 +#define src_parent sd[AuSRC].parent
20095 +#define src_h_parent sd[AuSRC].h_parent
20096 +#define src_wh_dentry sd[AuSRC].wh_dentry
20097 +#define src_hdir sd[AuSRC].hdir
20098 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20099 +#define src_dt sd[AuSRC].dt
20100 +#define src_bstart sd[AuSRC].bstart
20102 +#define dst_dentry sd[AuDST].dentry
20103 +#define dst_dir sd[AuDST].dir
20104 +#define dst_inode sd[AuDST].inode
20105 +#define dst_h_dentry sd[AuDST].h_dentry
20106 +#define dst_parent sd[AuDST].parent
20107 +#define dst_h_parent sd[AuDST].h_parent
20108 +#define dst_wh_dentry sd[AuDST].wh_dentry
20109 +#define dst_hdir sd[AuDST].hdir
20110 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20111 +#define dst_dt sd[AuDST].dt
20112 +#define dst_bstart sd[AuDST].bstart
20114 + struct dentry *h_trap;
20115 + struct au_branch *br;
20116 + struct au_hinode *src_hinode;
20117 + struct path h_path;
20118 + struct au_nhash whlist;
20119 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
20121 + unsigned int flags;
20123 + struct au_whtmp_rmdir *thargs;
20124 + struct dentry *h_dst;
20127 +/* ---------------------------------------------------------------------- */
20130 + * functions for reverting.
20131 + * when an error happened in a single rename systemcall, we should revert
20132 + * everything as if nothing happend.
20133 + * we don't need to revert the copied-up/down the parent dir since they are
20137 +#define RevertFailure(fmt, ...) do { \
20138 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20139 + ##__VA_ARGS__, err, rerr); \
20143 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20147 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20148 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
20149 + au_hn_imtx_unlock(a->src_hinode);
20150 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
20152 + RevertFailure("remove diropq %pd", a->src_dentry);
20155 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20158 + struct inode *delegated;
20160 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20161 + a->src_h_parent);
20162 + rerr = PTR_ERR(a->h_path.dentry);
20163 + if (IS_ERR(a->h_path.dentry)) {
20164 + RevertFailure("lkup one %pd", a->src_dentry);
20168 + delegated = NULL;
20169 + rerr = vfsub_rename(a->dst_h_dir,
20170 + au_h_dptr(a->src_dentry, a->btgt),
20171 + a->src_h_dir, &a->h_path, &delegated);
20172 + if (unlikely(rerr == -EWOULDBLOCK)) {
20173 + pr_warn("cannot retry for NFSv4 delegation"
20174 + " for an internal rename\n");
20177 + d_drop(a->h_path.dentry);
20178 + dput(a->h_path.dentry);
20179 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20181 + RevertFailure("rename %pd", a->src_dentry);
20184 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20187 + struct inode *delegated;
20189 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20190 + a->dst_h_parent);
20191 + rerr = PTR_ERR(a->h_path.dentry);
20192 + if (IS_ERR(a->h_path.dentry)) {
20193 + RevertFailure("lkup one %pd", a->dst_dentry);
20196 + if (a->h_path.dentry->d_inode) {
20197 + d_drop(a->h_path.dentry);
20198 + dput(a->h_path.dentry);
20202 + delegated = NULL;
20203 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20205 + if (unlikely(rerr == -EWOULDBLOCK)) {
20206 + pr_warn("cannot retry for NFSv4 delegation"
20207 + " for an internal rename\n");
20210 + d_drop(a->h_path.dentry);
20211 + dput(a->h_path.dentry);
20213 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20215 + RevertFailure("rename %pd", a->h_dst);
20218 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20222 + a->h_path.dentry = a->src_wh_dentry;
20223 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20224 + au_set_dbwh(a->src_dentry, a->src_bwh);
20226 + RevertFailure("unlink %pd", a->src_wh_dentry);
20228 +#undef RevertFailure
20230 +/* ---------------------------------------------------------------------- */
20233 + * when we have to copyup the renaming entry, do it with the rename-target name
20234 + * in order to minimize the cost (the later actual rename is unnecessary).
20235 + * otherwise rename it on the target branch.
20237 +static int au_ren_or_cpup(struct au_ren_args *a)
20240 + struct dentry *d;
20241 + struct inode *delegated;
20243 + d = a->src_dentry;
20244 + if (au_dbstart(d) == a->btgt) {
20245 + a->h_path.dentry = a->dst_h_dentry;
20246 + if (au_ftest_ren(a->flags, DIROPQ)
20247 + && au_dbdiropq(d) == a->btgt)
20248 + au_fclr_ren(a->flags, DIROPQ);
20249 + AuDebugOn(au_dbstart(d) != a->btgt);
20250 + delegated = NULL;
20251 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20252 + a->dst_h_dir, &a->h_path, &delegated);
20253 + if (unlikely(err == -EWOULDBLOCK)) {
20254 + pr_warn("cannot retry for NFSv4 delegation"
20255 + " for an internal rename\n");
20261 + if (!err && a->h_dst)
20262 + /* it will be set to dinfo later */
20268 +/* cf. aufs_rmdir() */
20269 +static int au_ren_del_whtmp(struct au_ren_args *a)
20272 + struct inode *dir;
20274 + dir = a->dst_dir;
20275 + SiMustAnyLock(dir->i_sb);
20276 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20277 + au_sbi(dir->i_sb)->si_dirwh)
20278 + || au_test_fs_remote(a->h_dst->d_sb)) {
20279 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20280 + if (unlikely(err))
20281 + pr_warn("failed removing whtmp dir %pd (%d), "
20282 + "ignored.\n", a->h_dst, err);
20284 + au_nhash_wh_free(&a->thargs->whlist);
20285 + a->thargs->whlist = a->whlist;
20286 + a->whlist.nh_num = 0;
20287 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20289 + a->thargs = NULL;
20295 +/* make it 'opaque' dir. */
20296 +static int au_ren_diropq(struct au_ren_args *a)
20299 + struct dentry *diropq;
20302 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
20303 + a->src_hinode = au_hi(a->src_inode, a->btgt);
20304 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20305 + diropq = au_diropq_create(a->src_dentry, a->btgt);
20306 + au_hn_imtx_unlock(a->src_hinode);
20307 + if (IS_ERR(diropq))
20308 + err = PTR_ERR(diropq);
20315 +static int do_rename(struct au_ren_args *a)
20318 + struct dentry *d, *h_d;
20320 + /* prepare workqueue args for asynchronous rmdir */
20321 + h_d = a->dst_h_dentry;
20322 + if (au_ftest_ren(a->flags, ISDIR) && h_d->d_inode) {
20324 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
20325 + if (unlikely(!a->thargs))
20327 + a->h_dst = dget(h_d);
20330 + /* create whiteout for src_dentry */
20331 + if (au_ftest_ren(a->flags, WHSRC)) {
20332 + a->src_bwh = au_dbwh(a->src_dentry);
20333 + AuDebugOn(a->src_bwh >= 0);
20335 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
20336 + err = PTR_ERR(a->src_wh_dentry);
20337 + if (IS_ERR(a->src_wh_dentry))
20341 + /* lookup whiteout for dentry */
20342 + if (au_ftest_ren(a->flags, WHDST)) {
20343 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
20345 + err = PTR_ERR(h_d);
20348 + if (!h_d->d_inode)
20351 + a->dst_wh_dentry = h_d;
20354 + /* rename dentry to tmpwh */
20356 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20357 + if (unlikely(err))
20360 + d = a->dst_dentry;
20361 + au_set_h_dptr(d, a->btgt, NULL);
20362 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20363 + if (unlikely(err))
20365 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20368 + BUG_ON(a->dst_h_dentry->d_inode && a->src_bstart != a->btgt);
20370 + /* rename by vfs_rename or cpup */
20371 + d = a->dst_dentry;
20372 + if (au_ftest_ren(a->flags, ISDIR)
20373 + && (a->dst_wh_dentry
20374 + || au_dbdiropq(d) == a->btgt
20375 + /* hide the lower to keep xino */
20376 + || a->btgt < au_dbend(d)
20377 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
20378 + au_fset_ren(a->flags, DIROPQ);
20379 + err = au_ren_or_cpup(a);
20380 + if (unlikely(err))
20381 + /* leave the copied-up one */
20384 + /* make dir opaque */
20385 + if (au_ftest_ren(a->flags, DIROPQ)) {
20386 + err = au_ren_diropq(a);
20387 + if (unlikely(err))
20391 + /* update target timestamps */
20392 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
20393 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20394 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20395 + a->src_inode->i_ctime = a->h_path.dentry->d_inode->i_ctime;
20397 + /* remove whiteout for dentry */
20398 + if (a->dst_wh_dentry) {
20399 + a->h_path.dentry = a->dst_wh_dentry;
20400 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20402 + if (unlikely(err))
20406 + /* remove whtmp */
20408 + au_ren_del_whtmp(a); /* ignore this error */
20410 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20412 + goto out_success;
20415 + if (au_ftest_ren(a->flags, DIROPQ))
20416 + au_ren_rev_diropq(err, a);
20418 + au_ren_rev_rename(err, a);
20422 + au_ren_rev_whtmp(err, a);
20424 + dput(a->dst_wh_dentry);
20425 + a->dst_wh_dentry = NULL;
20427 + if (a->src_wh_dentry)
20428 + au_ren_rev_whsrc(err, a);
20430 + dput(a->src_wh_dentry);
20431 + dput(a->dst_wh_dentry);
20435 + au_whtmp_rmdir_free(a->thargs);
20436 + a->thargs = NULL;
20442 +/* ---------------------------------------------------------------------- */
20445 + * test if @dentry dir can be rename destination or not.
20446 + * success means, it is a logically empty dir.
20448 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20450 + return au_test_empty(dentry, whlist);
20454 + * test if @dentry dir can be rename source or not.
20455 + * if it can, return 0 and @children is filled.
20457 + * - it is a logically empty dir.
20458 + * - or, it exists on writable branch and has no children including whiteouts
20459 + * on the lower branch.
20461 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20464 + unsigned int rdhash;
20465 + aufs_bindex_t bstart;
20467 + bstart = au_dbstart(dentry);
20468 + if (bstart != btgt) {
20469 + struct au_nhash whlist;
20471 + SiMustAnyLock(dentry->d_sb);
20472 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20474 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20476 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20477 + if (unlikely(err))
20479 + err = au_test_empty(dentry, &whlist);
20480 + au_nhash_wh_free(&whlist);
20484 + if (bstart == au_dbtaildir(dentry))
20485 + return 0; /* success */
20487 + err = au_test_empty_lower(dentry);
20490 + if (err == -ENOTEMPTY) {
20491 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20492 + " is not supported\n");
20498 +/* side effect: sets whlist and h_dentry */
20499 +static int au_ren_may_dir(struct au_ren_args *a)
20502 + unsigned int rdhash;
20503 + struct dentry *d;
20505 + d = a->dst_dentry;
20506 + SiMustAnyLock(d->d_sb);
20509 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
20510 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20512 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20513 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20514 + if (unlikely(err))
20517 + au_set_dbstart(d, a->dst_bstart);
20518 + err = may_rename_dstdir(d, &a->whlist);
20519 + au_set_dbstart(d, a->btgt);
20521 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
20522 + if (unlikely(err))
20525 + d = a->src_dentry;
20526 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
20527 + if (au_ftest_ren(a->flags, ISDIR)) {
20528 + err = may_rename_srcdir(d, a->btgt);
20529 + if (unlikely(err)) {
20530 + au_nhash_wh_free(&a->whlist);
20531 + a->whlist.nh_num = 0;
20538 +/* ---------------------------------------------------------------------- */
20541 + * simple tests for rename.
20542 + * following the checks in vfs, plus the parent-child relationship.
20544 +static int au_may_ren(struct au_ren_args *a)
20547 + struct inode *h_inode;
20549 + if (a->src_bstart == a->btgt) {
20550 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20551 + au_ftest_ren(a->flags, ISDIR));
20552 + if (unlikely(err))
20555 + if (unlikely(a->src_h_dentry == a->h_trap))
20560 + if (a->dst_bstart != a->btgt)
20563 + err = -ENOTEMPTY;
20564 + if (unlikely(a->dst_h_dentry == a->h_trap))
20568 + h_inode = a->dst_h_dentry->d_inode;
20569 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20570 + if (!a->dst_dentry->d_inode) {
20571 + if (unlikely(h_inode))
20573 + err = au_may_add(a->dst_dentry, a->btgt, a->dst_h_parent,
20576 + if (unlikely(!h_inode || !h_inode->i_nlink))
20578 + err = au_may_del(a->dst_dentry, a->btgt, a->dst_h_parent,
20580 + if (unlikely(err))
20585 + if (unlikely(err == -ENOENT || err == -EEXIST))
20591 +/* ---------------------------------------------------------------------- */
20596 + * - src_dir and dir by lock_rename()
20597 + * - inode if exitsts
20600 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
20602 + * + di_write_lock2_child()
20603 + * + di_write_lock_child()
20604 + * + ii_write_lock_child()
20605 + * + di_write_lock_child2()
20606 + * + ii_write_lock_child2()
20607 + * + src_parent and parent
20608 + * + di_write_lock_parent()
20609 + * + ii_write_lock_parent()
20610 + * + di_write_lock_parent2()
20611 + * + ii_write_lock_parent2()
20612 + * + lower src_dir and dir by vfsub_lock_rename()
20613 + * + verify the every relationships between child and parent. if any
20614 + * of them failed, unlock all and return -EBUSY.
20616 +static void au_ren_unlock(struct au_ren_args *a)
20618 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
20619 + a->dst_h_parent, a->dst_hdir);
20620 + if (au_ftest_ren(a->flags, MNT_WRITE))
20621 + vfsub_mnt_drop_write(au_br_mnt(a->br));
20624 +static int au_ren_lock(struct au_ren_args *a)
20627 + unsigned int udba;
20630 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
20631 + a->src_hdir = au_hi(a->src_dir, a->btgt);
20632 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
20633 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
20635 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
20636 + if (unlikely(err))
20638 + au_fset_ren(a->flags, MNT_WRITE);
20639 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
20640 + a->dst_h_parent, a->dst_hdir);
20641 + udba = au_opt_udba(a->src_dentry->d_sb);
20642 + if (unlikely(a->src_hdir->hi_inode != a->src_h_parent->d_inode
20643 + || a->dst_hdir->hi_inode != a->dst_h_parent->d_inode))
20644 + err = au_busy_or_stale();
20645 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
20646 + err = au_h_verify(a->src_h_dentry, udba,
20647 + a->src_h_parent->d_inode, a->src_h_parent,
20649 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
20650 + err = au_h_verify(a->dst_h_dentry, udba,
20651 + a->dst_h_parent->d_inode, a->dst_h_parent,
20654 + goto out; /* success */
20656 + err = au_busy_or_stale();
20657 + au_ren_unlock(a);
20663 +/* ---------------------------------------------------------------------- */
20665 +static void au_ren_refresh_dir(struct au_ren_args *a)
20667 + struct inode *dir;
20669 + dir = a->dst_dir;
20670 + dir->i_version++;
20671 + if (au_ftest_ren(a->flags, ISDIR)) {
20672 + /* is this updating defined in POSIX? */
20673 + au_cpup_attr_timesizes(a->src_inode);
20674 + au_cpup_attr_nlink(dir, /*force*/1);
20677 + au_dir_ts(dir, a->btgt);
20679 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20682 + dir = a->src_dir;
20683 + dir->i_version++;
20684 + if (au_ftest_ren(a->flags, ISDIR))
20685 + au_cpup_attr_nlink(dir, /*force*/1);
20686 + au_dir_ts(dir, a->btgt);
20689 +static void au_ren_refresh(struct au_ren_args *a)
20691 + aufs_bindex_t bend, bindex;
20692 + struct dentry *d, *h_d;
20693 + struct inode *i, *h_i;
20694 + struct super_block *sb;
20696 + d = a->dst_dentry;
20699 + /* already dget-ed by au_ren_or_cpup() */
20700 + au_set_h_dptr(d, a->btgt, a->h_dst);
20702 + i = a->dst_inode;
20704 + if (!au_ftest_ren(a->flags, ISDIR))
20705 + vfsub_drop_nlink(i);
20707 + vfsub_dead_dir(i);
20708 + au_cpup_attr_timesizes(i);
20710 + au_update_dbrange(d, /*do_put_zero*/1);
20713 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
20714 + au_set_h_dptr(d, bindex, NULL);
20715 + bend = au_dbend(d);
20716 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
20717 + au_set_h_dptr(d, bindex, NULL);
20718 + au_update_dbrange(d, /*do_put_zero*/0);
20721 + d = a->src_dentry;
20722 + au_set_dbwh(d, -1);
20723 + bend = au_dbend(d);
20724 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20725 + h_d = au_h_dptr(d, bindex);
20727 + au_set_h_dptr(d, bindex, NULL);
20729 + au_set_dbend(d, a->btgt);
20732 + i = a->src_inode;
20733 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
20734 + return; /* success */
20736 + bend = au_ibend(i);
20737 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20738 + h_i = au_h_iptr(i, bindex);
20740 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
20741 + /* ignore this error */
20742 + au_set_h_iptr(i, bindex, NULL, 0);
20745 + au_set_ibend(i, a->btgt);
20748 +/* ---------------------------------------------------------------------- */
20750 +/* mainly for link(2) and rename(2) */
20751 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
20753 + aufs_bindex_t bdiropq, bwh;
20754 + struct dentry *parent;
20755 + struct au_branch *br;
20757 + parent = dentry->d_parent;
20758 + IMustLock(parent->d_inode); /* dir is locked */
20760 + bdiropq = au_dbdiropq(parent);
20761 + bwh = au_dbwh(dentry);
20762 + br = au_sbr(dentry->d_sb, btgt);
20763 + if (au_br_rdonly(br)
20764 + || (0 <= bdiropq && bdiropq < btgt)
20765 + || (0 <= bwh && bwh < btgt))
20768 + AuDbg("btgt %d\n", btgt);
20772 +/* sets src_bstart, dst_bstart and btgt */
20773 +static int au_ren_wbr(struct au_ren_args *a)
20776 + struct au_wr_dir_args wr_dir_args = {
20777 + /* .force_btgt = -1, */
20778 + .flags = AuWrDir_ADD_ENTRY
20781 + a->src_bstart = au_dbstart(a->src_dentry);
20782 + a->dst_bstart = au_dbstart(a->dst_dentry);
20783 + if (au_ftest_ren(a->flags, ISDIR))
20784 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
20785 + wr_dir_args.force_btgt = a->src_bstart;
20786 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
20787 + wr_dir_args.force_btgt = a->dst_bstart;
20788 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
20789 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
20795 +static void au_ren_dt(struct au_ren_args *a)
20797 + a->h_path.dentry = a->src_h_parent;
20798 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
20799 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
20800 + a->h_path.dentry = a->dst_h_parent;
20801 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
20804 + au_fclr_ren(a->flags, DT_DSTDIR);
20805 + if (!au_ftest_ren(a->flags, ISDIR))
20808 + a->h_path.dentry = a->src_h_dentry;
20809 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
20810 + if (a->dst_h_dentry->d_inode) {
20811 + au_fset_ren(a->flags, DT_DSTDIR);
20812 + a->h_path.dentry = a->dst_h_dentry;
20813 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
20817 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
20819 + struct dentry *h_d;
20820 + struct mutex *h_mtx;
20822 + au_dtime_revert(a->src_dt + AuPARENT);
20823 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
20824 + au_dtime_revert(a->dst_dt + AuPARENT);
20826 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
20827 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
20828 + h_mtx = &h_d->d_inode->i_mutex;
20829 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20830 + au_dtime_revert(a->src_dt + AuCHILD);
20831 + mutex_unlock(h_mtx);
20833 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
20834 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
20835 + h_mtx = &h_d->d_inode->i_mutex;
20836 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20837 + au_dtime_revert(a->dst_dt + AuCHILD);
20838 + mutex_unlock(h_mtx);
20843 +/* ---------------------------------------------------------------------- */
20845 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
20846 + struct inode *_dst_dir, struct dentry *_dst_dentry)
20849 + /* reduce stack space */
20850 + struct au_ren_args *a;
20852 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
20853 + IMustLock(_src_dir);
20854 + IMustLock(_dst_dir);
20857 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
20858 + a = kzalloc(sizeof(*a), GFP_NOFS);
20859 + if (unlikely(!a))
20862 + a->src_dir = _src_dir;
20863 + a->src_dentry = _src_dentry;
20864 + a->src_inode = a->src_dentry->d_inode;
20865 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
20866 + a->dst_dir = _dst_dir;
20867 + a->dst_dentry = _dst_dentry;
20868 + a->dst_inode = a->dst_dentry->d_inode;
20869 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
20870 + if (a->dst_inode) {
20871 + IMustLock(a->dst_inode);
20872 + au_igrab(a->dst_inode);
20876 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
20877 + if (d_is_dir(a->src_dentry)) {
20878 + au_fset_ren(a->flags, ISDIR);
20879 + if (unlikely(d_is_positive(a->dst_dentry)
20880 + && !d_is_dir(a->dst_dentry)))
20882 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20883 + AuLock_DIR | flags);
20885 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20887 + if (unlikely(err))
20890 + err = au_d_hashed_positive(a->src_dentry);
20891 + if (unlikely(err))
20894 + if (a->dst_inode) {
20896 + * If it is a dir, VFS unhash dst_dentry before this
20897 + * function. It means we cannot rely upon d_unhashed().
20899 + if (unlikely(!a->dst_inode->i_nlink))
20901 + if (!S_ISDIR(a->dst_inode->i_mode)) {
20902 + err = au_d_hashed_positive(a->dst_dentry);
20903 + if (unlikely(err))
20905 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
20907 + } else if (unlikely(d_unhashed(a->dst_dentry)))
20911 + * is it possible?
20912 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
20913 + * there may exist a problem somewhere else.
20916 + if (unlikely(a->dst_parent->d_inode == a->src_dentry->d_inode))
20919 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
20920 + di_write_lock_parent(a->dst_parent);
20922 + /* which branch we process */
20923 + err = au_ren_wbr(a);
20924 + if (unlikely(err < 0))
20926 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
20927 + a->h_path.mnt = au_br_mnt(a->br);
20929 + /* are they available to be renamed */
20930 + err = au_ren_may_dir(a);
20931 + if (unlikely(err))
20932 + goto out_children;
20934 + /* prepare the writable parent dir on the same branch */
20935 + if (a->dst_bstart == a->btgt) {
20936 + au_fset_ren(a->flags, WHDST);
20938 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
20939 + if (unlikely(err))
20940 + goto out_children;
20943 + if (a->src_dir != a->dst_dir) {
20945 + * this temporary unlock is safe,
20946 + * because both dir->i_mutex are locked.
20948 + di_write_unlock(a->dst_parent);
20949 + di_write_lock_parent(a->src_parent);
20950 + err = au_wr_dir_need_wh(a->src_dentry,
20951 + au_ftest_ren(a->flags, ISDIR),
20953 + di_write_unlock(a->src_parent);
20954 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
20955 + au_fclr_ren(a->flags, ISSAMEDIR);
20957 + err = au_wr_dir_need_wh(a->src_dentry,
20958 + au_ftest_ren(a->flags, ISDIR),
20960 + if (unlikely(err < 0))
20961 + goto out_children;
20963 + au_fset_ren(a->flags, WHSRC);
20966 + if (a->src_bstart != a->btgt) {
20967 + struct au_pin pin;
20969 + err = au_pin(&pin, a->src_dentry, a->btgt,
20970 + au_opt_udba(a->src_dentry->d_sb),
20971 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20973 + struct au_cp_generic cpg = {
20974 + .dentry = a->src_dentry,
20976 + .bsrc = a->src_bstart,
20979 + .flags = AuCpup_DTIME | AuCpup_HOPEN
20981 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
20982 + err = au_sio_cpup_simple(&cpg);
20985 + if (unlikely(err))
20986 + goto out_children;
20987 + a->src_bstart = a->btgt;
20988 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
20989 + au_fset_ren(a->flags, WHSRC);
20992 + /* lock them all */
20993 + err = au_ren_lock(a);
20994 + if (unlikely(err))
20995 + /* leave the copied-up one */
20996 + goto out_children;
20998 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
20999 + err = au_may_ren(a);
21000 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21001 + err = -ENAMETOOLONG;
21002 + if (unlikely(err))
21005 + /* store timestamps to be revertible */
21009 + err = do_rename(a);
21010 + if (unlikely(err))
21013 + /* update dir attributes */
21014 + au_ren_refresh_dir(a);
21016 + /* dput/iput all lower dentries */
21017 + au_ren_refresh(a);
21019 + goto out_hdir; /* success */
21022 + au_ren_rev_dt(err, a);
21024 + au_ren_unlock(a);
21026 + au_nhash_wh_free(&a->whlist);
21027 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
21028 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
21029 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21030 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
21034 + d_move(a->src_dentry, a->dst_dentry);
21036 + au_update_dbstart(a->dst_dentry);
21037 + if (!a->dst_inode)
21038 + d_drop(a->dst_dentry);
21040 + if (au_ftest_ren(a->flags, ISSAMEDIR))
21041 + di_write_unlock(a->dst_parent);
21043 + di_write_unlock2(a->src_parent, a->dst_parent);
21045 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21047 + iput(a->dst_inode);
21049 + au_whtmp_rmdir_free(a->thargs);
21055 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21056 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21057 +++ linux/fs/aufs/Kconfig 2015-06-22 08:27:37.874168290 +0200
21060 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21062 + Aufs is a stackable unification filesystem such as Unionfs,
21063 + which unifies several directories and provides a merged single
21065 + In the early days, aufs was entirely re-designed and
21066 + re-implemented Unionfs Version 1.x series. Introducing many
21067 + original ideas, approaches and improvements, it becomes totally
21068 + different from Unionfs while keeping the basic features.
21072 + prompt "Maximum number of branches"
21073 + default AUFS_BRANCH_MAX_127
21075 + Specifies the maximum number of branches (or member directories)
21076 + in a single aufs. The larger value consumes more system
21077 + resources and has a minor impact to performance.
21078 +config AUFS_BRANCH_MAX_127
21081 + Specifies the maximum number of branches (or member directories)
21082 + in a single aufs. The larger value consumes more system
21083 + resources and has a minor impact to performance.
21084 +config AUFS_BRANCH_MAX_511
21087 + Specifies the maximum number of branches (or member directories)
21088 + in a single aufs. The larger value consumes more system
21089 + resources and has a minor impact to performance.
21090 +config AUFS_BRANCH_MAX_1023
21093 + Specifies the maximum number of branches (or member directories)
21094 + in a single aufs. The larger value consumes more system
21095 + resources and has a minor impact to performance.
21096 +config AUFS_BRANCH_MAX_32767
21099 + Specifies the maximum number of branches (or member directories)
21100 + in a single aufs. The larger value consumes more system
21101 + resources and has a minor impact to performance.
21104 +config AUFS_SBILIST
21106 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21109 + Automatic configuration for internal use.
21110 + When aufs supports Magic SysRq or /proc, enabled automatically.
21112 +config AUFS_HNOTIFY
21113 + bool "Detect direct branch access (bypassing aufs)"
21115 + If you want to modify files on branches directly, eg. bypassing aufs,
21116 + and want aufs to detect the changes of them fully, then enable this
21117 + option and use 'udba=notify' mount option.
21118 + Currently there is only one available configuration, "fsnotify".
21119 + It will have a negative impact to the performance.
21120 + See detail in aufs.5.
21123 + prompt "method" if AUFS_HNOTIFY
21124 + default AUFS_HFSNOTIFY
21125 +config AUFS_HFSNOTIFY
21130 +config AUFS_EXPORT
21131 + bool "NFS-exportable aufs"
21132 + depends on EXPORTFS
21134 + If you want to export your mounted aufs via NFS, then enable this
21135 + option. There are several requirements for this configuration.
21136 + See detail in aufs.5.
21138 +config AUFS_INO_T_64
21140 + depends on AUFS_EXPORT
21141 + depends on 64BIT && !(ALPHA || S390)
21144 + Automatic configuration for internal use.
21145 + /* typedef unsigned long/int __kernel_ino_t */
21146 + /* alpha and s390x are int */
21149 + bool "support for XATTR/EA (including Security Labels)"
21151 + If your branch fs supports XATTR/EA and you want to make them
21152 + available in aufs too, then enable this opsion and specify the
21153 + branch attributes for EA.
21154 + See detail in aufs.5.
21157 + bool "File-based Hierarchical Storage Management"
21159 + Hierarchical Storage Management (or HSM) is a well-known feature
21160 + in the storage world. Aufs provides this feature as file-based.
21161 + with multiple branches.
21162 + These multiple branches are prioritized, ie. the topmost one
21163 + should be the fastest drive and be used heavily.
21166 + bool "Readdir in userspace"
21168 + Aufs has two methods to provide a merged view for a directory,
21169 + by a user-space library and by kernel-space natively. The latter
21170 + is always enabled but sometimes large and slow.
21171 + If you enable this option, install the library in aufs2-util
21172 + package, and set some environment variables for your readdir(3),
21173 + then the work will be handled in user-space which generally
21174 + shows better performance in most cases.
21175 + See detail in aufs.5.
21178 + bool "Show whiteouts"
21180 + If you want to make the whiteouts in aufs visible, then enable
21181 + this option and specify 'shwh' mount option. Although it may
21182 + sounds like philosophy or something, but in technically it
21183 + simply shows the name of whiteout with keeping its behaviour.
21185 +config AUFS_BR_RAMFS
21186 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21188 + If you want to use ramfs as an aufs branch fs, then enable this
21189 + option. Generally tmpfs is recommended.
21190 + Aufs prohibited them to be a branch fs by default, because
21191 + initramfs becomes unusable after switch_root or something
21192 + generally. If you sets initramfs as an aufs branch and boot your
21193 + system by switch_root, you will meet a problem easily since the
21194 + files in initramfs may be inaccessible.
21195 + Unless you are going to use ramfs as an aufs branch fs without
21196 + switch_root or something, leave it N.
21198 +config AUFS_BR_FUSE
21199 + bool "Fuse fs as an aufs branch"
21200 + depends on FUSE_FS
21203 + If you want to use fuse-based userspace filesystem as an aufs
21204 + branch fs, then enable this option.
21205 + It implements the internal poll(2) operation which is
21206 + implemented by fuse only (curretnly).
21211 + Automatic configuration for internal use.
21213 +config AUFS_BR_HFSPLUS
21214 + bool "Hfsplus as an aufs branch"
21215 + depends on HFSPLUS_FS
21218 + If you want to use hfsplus fs as an aufs branch fs, then enable
21219 + this option. This option introduces a small overhead at
21220 + copying-up a file on hfsplus.
21222 +config AUFS_BDEV_LOOP
21224 + depends on BLK_DEV_LOOP
21227 + Automatic configuration for internal use.
21228 + Convert =[ym] into =y.
21231 + bool "Debug aufs"
21233 + Enable this to compile aufs internal debug code.
21234 + It will have a negative impact to the performance.
21236 +config AUFS_MAGIC_SYSRQ
21238 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21241 + Automatic configuration for internal use.
21242 + When aufs supports Magic SysRq, enabled automatically.
21244 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21245 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21246 +++ linux/fs/aufs/loop.c 2015-06-22 08:29:23.706757681 +0200
21249 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21251 + * This program, aufs is free software; you can redistribute it and/or modify
21252 + * it under the terms of the GNU General Public License as published by
21253 + * the Free Software Foundation; either version 2 of the License, or
21254 + * (at your option) any later version.
21256 + * This program is distributed in the hope that it will be useful,
21257 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21258 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21259 + * GNU General Public License for more details.
21261 + * You should have received a copy of the GNU General Public License
21262 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21266 + * support for loopback block device as a branch
21271 +/* added into drivers/block/loop.c */
21272 +static struct file *(*backing_file_func)(struct super_block *sb);
21275 + * test if two lower dentries have overlapping branches.
21277 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21279 + struct super_block *h_sb;
21280 + struct file *backing_file;
21282 + if (unlikely(!backing_file_func)) {
21283 + /* don't load "loop" module here */
21284 + backing_file_func = symbol_get(loop_backing_file);
21285 + if (unlikely(!backing_file_func))
21286 + /* "loop" module is not loaded */
21290 + h_sb = h_adding->d_sb;
21291 + backing_file = backing_file_func(h_sb);
21292 + if (!backing_file)
21295 + h_adding = backing_file->f_path.dentry;
21297 + * h_adding can be local NFS.
21298 + * in this case aufs cannot detect the loop.
21300 + if (unlikely(h_adding->d_sb == sb))
21302 + return !!au_test_subdir(h_adding, sb->s_root);
21305 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21306 +int au_test_loopback_kthread(void)
21309 + struct task_struct *tsk = current;
21310 + char c, comm[sizeof(tsk->comm)];
21313 + if (tsk->flags & PF_KTHREAD) {
21314 + get_task_comm(comm, tsk);
21316 + ret = ('0' <= c && c <= '9'
21317 + && !strncmp(comm, "loop", 4));
21323 +/* ---------------------------------------------------------------------- */
21325 +#define au_warn_loopback_step 16
21326 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21327 +static unsigned long *au_warn_loopback_array;
21329 +void au_warn_loopback(struct super_block *h_sb)
21331 + int i, new_nelem;
21332 + unsigned long *a, magic;
21333 + static DEFINE_SPINLOCK(spin);
21335 + magic = h_sb->s_magic;
21336 + spin_lock(&spin);
21337 + a = au_warn_loopback_array;
21338 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21339 + if (a[i] == magic) {
21340 + spin_unlock(&spin);
21344 + /* h_sb is new to us, print it */
21345 + if (i < au_warn_loopback_nelem) {
21350 + /* expand the array */
21351 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21352 + a = au_kzrealloc(au_warn_loopback_array,
21353 + au_warn_loopback_nelem * sizeof(unsigned long),
21354 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
21356 + au_warn_loopback_nelem = new_nelem;
21357 + au_warn_loopback_array = a;
21362 + spin_unlock(&spin);
21363 + AuWarn1("realloc failed, ignored\n");
21367 + spin_unlock(&spin);
21368 + pr_warn("you may want to try another patch for loopback file "
21369 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21372 +int au_loopback_init(void)
21375 + struct super_block *sb __maybe_unused;
21377 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
21380 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21381 + sizeof(unsigned long), GFP_NOFS);
21382 + if (unlikely(!au_warn_loopback_array))
21388 +void au_loopback_fin(void)
21390 + symbol_put(loop_backing_file);
21391 + kfree(au_warn_loopback_array);
21393 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21394 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21395 +++ linux/fs/aufs/loop.h 2015-06-22 08:27:37.884168534 +0200
21398 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21400 + * This program, aufs is free software; you can redistribute it and/or modify
21401 + * it under the terms of the GNU General Public License as published by
21402 + * the Free Software Foundation; either version 2 of the License, or
21403 + * (at your option) any later version.
21405 + * This program is distributed in the hope that it will be useful,
21406 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21407 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21408 + * GNU General Public License for more details.
21410 + * You should have received a copy of the GNU General Public License
21411 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21415 + * support for loopback mount as a branch
21418 +#ifndef __AUFS_LOOP_H__
21419 +#define __AUFS_LOOP_H__
21424 +struct super_block;
21426 +#ifdef CONFIG_AUFS_BDEV_LOOP
21427 +/* drivers/block/loop.c */
21428 +struct file *loop_backing_file(struct super_block *sb);
21431 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21432 +int au_test_loopback_kthread(void);
21433 +void au_warn_loopback(struct super_block *h_sb);
21435 +int au_loopback_init(void);
21436 +void au_loopback_fin(void);
21438 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21439 + struct dentry *h_adding)
21440 +AuStubInt0(au_test_loopback_kthread, void)
21441 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21443 +AuStubInt0(au_loopback_init, void)
21444 +AuStubVoid(au_loopback_fin, void)
21445 +#endif /* BLK_DEV_LOOP */
21447 +#endif /* __KERNEL__ */
21448 +#endif /* __AUFS_LOOP_H__ */
21449 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21450 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21451 +++ linux/fs/aufs/magic.mk 2015-06-22 08:27:37.884168534 +0200
21454 +# defined in ${srctree}/fs/fuse/inode.c
21456 +ifdef CONFIG_FUSE_FS
21457 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21460 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21462 +ifdef CONFIG_XFS_FS
21463 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21466 +# defined in ${srctree}/fs/configfs/mount.c
21468 +ifdef CONFIG_CONFIGFS_FS
21469 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21472 +# defined in ${srctree}/fs/ubifs/ubifs.h
21474 +ifdef CONFIG_UBIFS_FS
21475 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21478 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21480 +ifdef CONFIG_HFSPLUS_FS
21481 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21483 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
21484 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
21485 +++ linux/fs/aufs/Makefile 2015-06-22 08:27:37.874168290 +0200
21488 +include ${src}/magic.mk
21489 +ifeq (${CONFIG_AUFS_FS},m)
21490 +include ${src}/conf.mk
21492 +-include ${src}/priv_def.mk
21494 +# cf. include/linux/kernel.h
21496 +ccflags-y += -DDEBUG
21497 +# sparse requires the full pathname
21499 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
21501 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
21504 +obj-$(CONFIG_AUFS_FS) += aufs.o
21505 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
21506 + wkq.o vfsub.o dcsub.o \
21507 + cpup.o whout.o wbr_policy.o \
21508 + dinfo.o dentry.o \
21510 + finfo.o file.o f_op.o \
21512 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
21516 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
21517 +aufs-$(CONFIG_SYSFS) += sysfs.o
21518 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
21519 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
21520 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
21521 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
21522 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
21523 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
21524 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
21525 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
21526 +aufs-$(CONFIG_AUFS_POLL) += poll.o
21527 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
21528 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
21529 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
21530 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
21531 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
21532 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21533 +++ linux/fs/aufs/module.c 2015-06-22 08:27:37.884168534 +0200
21536 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21538 + * This program, aufs is free software; you can redistribute it and/or modify
21539 + * it under the terms of the GNU General Public License as published by
21540 + * the Free Software Foundation; either version 2 of the License, or
21541 + * (at your option) any later version.
21543 + * This program is distributed in the hope that it will be useful,
21544 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21545 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21546 + * GNU General Public License for more details.
21548 + * You should have received a copy of the GNU General Public License
21549 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21553 + * module global variables and operations
21556 +#include <linux/module.h>
21557 +#include <linux/seq_file.h>
21560 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21562 + if (new_sz <= nused)
21565 + p = krealloc(p, new_sz, gfp);
21567 + memset(p + nused, 0, new_sz - nused);
21571 +/* ---------------------------------------------------------------------- */
21576 +struct kmem_cache *au_cachep[AuCache_Last];
21577 +static int __init au_cache_init(void)
21579 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21580 + if (au_cachep[AuCache_DINFO])
21581 + /* SLAB_DESTROY_BY_RCU */
21582 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21583 + au_icntnr_init_once);
21584 + if (au_cachep[AuCache_ICNTNR])
21585 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21586 + au_fi_init_once);
21587 + if (au_cachep[AuCache_FINFO])
21588 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21589 + if (au_cachep[AuCache_VDIR])
21590 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21591 + if (au_cachep[AuCache_DEHSTR])
21597 +static void au_cache_fin(void)
21602 + * Make sure all delayed rcu free inodes are flushed before we
21607 + /* excluding AuCache_HNOTIFY */
21608 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21609 + for (i = 0; i < AuCache_HNOTIFY; i++)
21610 + if (au_cachep[i]) {
21611 + kmem_cache_destroy(au_cachep[i]);
21612 + au_cachep[i] = NULL;
21616 +/* ---------------------------------------------------------------------- */
21618 +int au_dir_roflags;
21620 +#ifdef CONFIG_AUFS_SBILIST
21622 + * iterate_supers_type() doesn't protect us from
21623 + * remounting (branch management)
21625 +struct au_splhead au_sbilist;
21628 +struct lock_class_key au_lc_key[AuLcKey_Last];
21631 + * functions for module interface.
21633 +MODULE_LICENSE("GPL");
21634 +/* MODULE_LICENSE("GPL v2"); */
21635 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21636 +MODULE_DESCRIPTION(AUFS_NAME
21637 + " -- Advanced multi layered unification filesystem");
21638 +MODULE_VERSION(AUFS_VERSION);
21639 +MODULE_ALIAS_FS(AUFS_NAME);
21641 +/* this module parameter has no meaning when SYSFS is disabled */
21642 +int sysaufs_brs = 1;
21643 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21644 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21646 +/* this module parameter has no meaning when USER_NS is disabled */
21647 +static bool au_userns;
21648 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21649 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21651 +/* ---------------------------------------------------------------------- */
21653 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21655 +int au_seq_path(struct seq_file *seq, struct path *path)
21657 + return seq_path(seq, path, au_esc_chars);
21660 +/* ---------------------------------------------------------------------- */
21662 +static int __init aufs_init(void)
21667 + p = au_esc_chars;
21668 + for (i = 1; i <= ' '; i++)
21674 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21676 + au_sbilist_init();
21677 + sysaufs_brs_init();
21680 + err = sysaufs_init();
21681 + if (unlikely(err))
21683 + err = au_procfs_init();
21684 + if (unlikely(err))
21685 + goto out_sysaufs;
21686 + err = au_wkq_init();
21687 + if (unlikely(err))
21689 + err = au_loopback_init();
21690 + if (unlikely(err))
21692 + err = au_hnotify_init();
21693 + if (unlikely(err))
21694 + goto out_loopback;
21695 + err = au_sysrq_init();
21696 + if (unlikely(err))
21698 + err = au_cache_init();
21699 + if (unlikely(err))
21702 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
21703 + err = register_filesystem(&aufs_fs_type);
21704 + if (unlikely(err))
21707 + /* since we define pr_fmt, call printk directly */
21708 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
21709 + goto out; /* success */
21716 + au_hnotify_fin();
21718 + au_loopback_fin();
21730 +static void __exit aufs_exit(void)
21732 + unregister_filesystem(&aufs_fs_type);
21735 + au_hnotify_fin();
21736 + au_loopback_fin();
21743 +module_init(aufs_init);
21744 +module_exit(aufs_exit);
21745 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
21746 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
21747 +++ linux/fs/aufs/module.h 2015-06-22 08:27:37.884168534 +0200
21750 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21752 + * This program, aufs is free software; you can redistribute it and/or modify
21753 + * it under the terms of the GNU General Public License as published by
21754 + * the Free Software Foundation; either version 2 of the License, or
21755 + * (at your option) any later version.
21757 + * This program is distributed in the hope that it will be useful,
21758 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21759 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21760 + * GNU General Public License for more details.
21762 + * You should have received a copy of the GNU General Public License
21763 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21767 + * module initialization and module-global
21770 +#ifndef __AUFS_MODULE_H__
21771 +#define __AUFS_MODULE_H__
21775 +#include <linux/slab.h>
21780 +/* module parameters */
21781 +extern int sysaufs_brs;
21783 +/* ---------------------------------------------------------------------- */
21785 +extern int au_dir_roflags;
21788 + AuLcNonDir_FIINFO,
21789 + AuLcNonDir_DIINFO,
21790 + AuLcNonDir_IIINFO,
21796 + AuLcSymlink_DIINFO,
21797 + AuLcSymlink_IIINFO,
21801 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
21803 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
21804 +int au_seq_path(struct seq_file *seq, struct path *path);
21806 +#ifdef CONFIG_PROC_FS
21808 +int __init au_procfs_init(void);
21809 +void au_procfs_fin(void);
21811 +AuStubInt0(au_procfs_init, void);
21812 +AuStubVoid(au_procfs_fin, void);
21815 +/* ---------------------------------------------------------------------- */
21824 + AuCache_HNOTIFY, /* must be last */
21828 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
21829 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
21830 +#define AuCacheCtor(type, ctor) \
21831 + kmem_cache_create(#type, sizeof(struct type), \
21832 + __alignof__(struct type), AuCacheFlags, ctor)
21834 +extern struct kmem_cache *au_cachep[];
21836 +#define AuCacheFuncs(name, index) \
21837 +static inline struct au_##name *au_cache_alloc_##name(void) \
21838 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
21839 +static inline void au_cache_free_##name(struct au_##name *p) \
21840 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
21842 +AuCacheFuncs(dinfo, DINFO);
21843 +AuCacheFuncs(icntnr, ICNTNR);
21844 +AuCacheFuncs(finfo, FINFO);
21845 +AuCacheFuncs(vdir, VDIR);
21846 +AuCacheFuncs(vdir_dehstr, DEHSTR);
21847 +#ifdef CONFIG_AUFS_HNOTIFY
21848 +AuCacheFuncs(hnotify, HNOTIFY);
21851 +#endif /* __KERNEL__ */
21852 +#endif /* __AUFS_MODULE_H__ */
21853 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
21854 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
21855 +++ linux/fs/aufs/mvdown.c 2015-06-22 08:27:37.884168534 +0200
21858 + * Copyright (C) 2011-2015 Junjiro R. Okajima
21860 + * This program, aufs is free software; you can redistribute it and/or modify
21861 + * it under the terms of the GNU General Public License as published by
21862 + * the Free Software Foundation; either version 2 of the License, or
21863 + * (at your option) any later version.
21865 + * This program is distributed in the hope that it will be useful,
21866 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21867 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21868 + * GNU General Public License for more details.
21870 + * You should have received a copy of the GNU General Public License
21871 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21875 + * move-down, opposite of copy-up
21880 +struct au_mvd_args {
21882 + struct super_block *h_sb;
21883 + struct dentry *h_parent;
21884 + struct au_hinode *hdir;
21885 + struct inode *h_dir, *h_inode;
21886 + struct au_pin pin;
21887 + } info[AUFS_MVDOWN_NARRAY];
21889 + struct aufs_mvdown mvdown;
21890 + struct dentry *dentry, *parent;
21891 + struct inode *inode, *dir;
21892 + struct super_block *sb;
21893 + aufs_bindex_t bopq, bwh, bfound;
21894 + unsigned char rename_lock;
21897 +#define mvd_errno mvdown.au_errno
21898 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
21899 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
21900 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
21901 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
21903 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
21904 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
21905 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
21906 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
21907 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
21908 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
21910 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
21911 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
21912 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
21913 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
21914 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
21915 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
21917 +#define AU_MVD_PR(flag, ...) do { \
21919 + pr_err(__VA_ARGS__); \
21922 +static int find_lower_writable(struct au_mvd_args *a)
21924 + struct super_block *sb;
21925 + aufs_bindex_t bindex, bend;
21926 + struct au_branch *br;
21929 + bindex = a->mvd_bsrc;
21930 + bend = au_sbend(sb);
21931 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
21932 + for (bindex++; bindex <= bend; bindex++) {
21933 + br = au_sbr(sb, bindex);
21934 + if (au_br_fhsm(br->br_perm)
21935 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
21938 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
21939 + for (bindex++; bindex <= bend; bindex++) {
21940 + br = au_sbr(sb, bindex);
21941 + if (!au_br_rdonly(br))
21945 + for (bindex++; bindex <= bend; bindex++) {
21946 + br = au_sbr(sb, bindex);
21947 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
21948 + if (au_br_rdonly(br))
21950 + |= AUFS_MVDOWN_ROLOWER_R;
21958 +/* make the parent dir on bdst */
21959 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
21964 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
21965 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
21966 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
21967 + a->mvd_h_dst_parent = NULL;
21968 + if (au_dbend(a->parent) >= a->mvd_bdst)
21969 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21970 + if (!a->mvd_h_dst_parent) {
21971 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
21972 + if (unlikely(err)) {
21973 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
21976 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
21984 +/* lock them all */
21985 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
21988 + struct dentry *h_trap;
21990 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
21991 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
21992 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
21993 + au_opt_udba(a->sb),
21994 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
21996 + if (unlikely(err)) {
21997 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22001 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22002 + a->rename_lock = 0;
22003 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22004 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22005 + au_opt_udba(a->sb),
22006 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22007 + err = au_do_pin(&a->mvd_pin_src);
22009 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
22010 + if (unlikely(err)) {
22011 + AU_MVD_PR(dmsg, "pin_src failed\n");
22014 + goto out; /* success */
22017 + a->rename_lock = 1;
22018 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22019 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22020 + au_opt_udba(a->sb),
22021 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22023 + a->mvd_h_src_dir = a->mvd_h_src_parent->d_inode;
22024 + if (unlikely(err)) {
22025 + AU_MVD_PR(dmsg, "pin_src failed\n");
22026 + au_pin_hdir_lock(&a->mvd_pin_dst);
22029 + au_pin_hdir_unlock(&a->mvd_pin_src);
22030 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22031 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22033 + err = (h_trap != a->mvd_h_src_parent);
22035 + err = (h_trap != a->mvd_h_dst_parent);
22037 + BUG_ON(err); /* it should never happen */
22038 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22041 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22042 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22043 + au_pin_hdir_lock(&a->mvd_pin_src);
22044 + au_unpin(&a->mvd_pin_src);
22045 + au_pin_hdir_lock(&a->mvd_pin_dst);
22048 + goto out; /* success */
22051 + au_unpin(&a->mvd_pin_dst);
22057 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22059 + if (!a->rename_lock)
22060 + au_unpin(&a->mvd_pin_src);
22062 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22063 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22064 + au_pin_hdir_lock(&a->mvd_pin_src);
22065 + au_unpin(&a->mvd_pin_src);
22066 + au_pin_hdir_lock(&a->mvd_pin_dst);
22068 + au_unpin(&a->mvd_pin_dst);
22071 +/* copy-down the file */
22072 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22075 + struct au_cp_generic cpg = {
22076 + .dentry = a->dentry,
22077 + .bdst = a->mvd_bdst,
22078 + .bsrc = a->mvd_bsrc,
22080 + .pin = &a->mvd_pin_dst,
22081 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22084 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22085 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22086 + au_fset_cpup(cpg.flags, OVERWRITE);
22087 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22088 + au_fset_cpup(cpg.flags, RWDST);
22089 + err = au_sio_cpdown_simple(&cpg);
22090 + if (unlikely(err))
22091 + AU_MVD_PR(dmsg, "cpdown failed\n");
22098 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22101 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22104 + struct path h_path;
22105 + struct au_branch *br;
22106 + struct inode *delegated;
22108 + br = au_sbr(a->sb, a->mvd_bdst);
22109 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22110 + err = PTR_ERR(h_path.dentry);
22111 + if (IS_ERR(h_path.dentry)) {
22112 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22117 + if (h_path.dentry->d_inode) {
22118 + h_path.mnt = au_br_mnt(br);
22119 + delegated = NULL;
22120 + err = vfsub_unlink(a->mvd_h_dst_parent->d_inode, &h_path,
22121 + &delegated, /*force*/0);
22122 + if (unlikely(err == -EWOULDBLOCK)) {
22123 + pr_warn("cannot retry for NFSv4 delegation"
22124 + " for an internal unlink\n");
22127 + if (unlikely(err))
22128 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22130 + dput(h_path.dentry);
22138 + * unlink the topmost h_dentry
22140 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22143 + struct path h_path;
22144 + struct inode *delegated;
22146 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22147 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22148 + delegated = NULL;
22149 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22150 + if (unlikely(err == -EWOULDBLOCK)) {
22151 + pr_warn("cannot retry for NFSv4 delegation"
22152 + " for an internal unlink\n");
22155 + if (unlikely(err))
22156 + AU_MVD_PR(dmsg, "unlink failed\n");
22162 +/* Since mvdown succeeded, we ignore an error of this function */
22163 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22166 + struct au_branch *br;
22168 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22169 + br = au_sbr(a->sb, a->mvd_bsrc);
22170 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22172 + br = au_sbr(a->sb, a->mvd_bdst);
22173 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22174 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22177 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22179 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22183 + * copy-down the file and unlink the bsrc file.
22184 + * - unlink the bdst whout if exist
22185 + * - copy-down the file (with whtmp name and rename)
22186 + * - unlink the bsrc file
22188 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22192 + err = au_do_mkdir(dmsg, a);
22194 + err = au_do_lock(dmsg, a);
22195 + if (unlikely(err))
22199 + * do not revert the activities we made on bdst since they should be
22200 + * harmless in aufs.
22203 + err = au_do_cpdown(dmsg, a);
22205 + err = au_do_unlink_wh(dmsg, a);
22206 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22207 + err = au_do_unlink(dmsg, a);
22208 + if (unlikely(err))
22211 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22212 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22213 + if (find_lower_writable(a) < 0)
22214 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22216 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22217 + au_do_stfs(dmsg, a);
22219 + /* maintain internal array */
22220 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22221 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22222 + au_set_dbstart(a->dentry, a->mvd_bdst);
22223 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22224 + au_set_ibstart(a->inode, a->mvd_bdst);
22226 + if (au_dbend(a->dentry) < a->mvd_bdst)
22227 + au_set_dbend(a->dentry, a->mvd_bdst);
22228 + if (au_ibend(a->inode) < a->mvd_bdst)
22229 + au_set_ibend(a->inode, a->mvd_bdst);
22232 + au_do_unlock(dmsg, a);
22238 +/* ---------------------------------------------------------------------- */
22240 +/* make sure the file is idle */
22241 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22243 + int err, plinked;
22246 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22247 + if (au_dbstart(a->dentry) == a->mvd_bsrc
22248 + && au_dcount(a->dentry) == 1
22249 + && atomic_read(&a->inode->i_count) == 1
22250 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22251 + && (!plinked || !au_plink_test(a->inode))
22252 + && a->inode->i_nlink == 1)
22257 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22258 + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry),
22259 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22260 + a->mvd_h_src_inode->i_nlink,
22261 + plinked, plinked ? au_plink_test(a->inode) : 0);
22268 +/* make sure the parent dir is fine */
22269 +static int au_mvd_args_parent(const unsigned char dmsg,
22270 + struct au_mvd_args *a)
22273 + aufs_bindex_t bindex;
22276 + if (unlikely(au_alive_dir(a->parent))) {
22278 + AU_MVD_PR(dmsg, "parent dir is dead\n");
22282 + a->bopq = au_dbdiropq(a->parent);
22283 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
22284 + AuDbg("b%d\n", bindex);
22285 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
22286 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
22288 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
22289 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
22290 + a->bopq, a->mvd_bdst);
22298 +static int au_mvd_args_intermediate(const unsigned char dmsg,
22299 + struct au_mvd_args *a)
22302 + struct au_dinfo *dinfo, *tmp;
22304 + /* lookup the next lower positive entry */
22306 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
22307 + if (unlikely(!tmp))
22312 + dinfo = au_di(a->dentry);
22313 + au_di_cp(tmp, dinfo);
22314 + au_di_swap(tmp, dinfo);
22316 + /* returns the number of positive dentries */
22317 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
22319 + a->bwh = au_dbwh(a->dentry);
22320 + else if (err > 0)
22321 + a->bfound = au_dbstart(a->dentry);
22323 + au_di_swap(tmp, dinfo);
22324 + au_rw_write_unlock(&tmp->di_rwsem);
22326 + if (unlikely(err < 0))
22327 + AU_MVD_PR(dmsg, "failed look-up lower\n");
22330 + * here, we have these cases.
22332 + * no positive dentry under bsrc. there are more sub-cases.
22334 + * there no whiteout, we can safely move-down.
22337 + * bsrc < bwh && bwh < bdst
22338 + * there is a whiteout on RO branch. cannot proceed.
22340 + * there is a whiteout on the RW target branch. it should
22343 + * there is a whiteout somewhere unrelated branch.
22344 + * -1 < bfound && bfound <= bsrc
22347 + * found, but it is on RO branch between bsrc and bdst. cannot
22350 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
22353 + * found, after we create the file on bdst, it will be hidden.
22356 + AuDebugOn(a->bfound == -1
22358 + && a->bwh <= a->mvd_bsrc);
22359 + AuDebugOn(-1 < a->bfound
22360 + && a->bfound <= a->mvd_bsrc);
22363 + if (a->bfound == -1
22364 + && a->mvd_bsrc < a->bwh
22366 + && a->bwh < a->mvd_bdst) {
22367 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
22368 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
22369 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
22371 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
22372 + a->mvd_errno = EAU_MVDOWN_UPPER;
22373 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
22374 + a->mvd_bdst, a->bfound);
22378 + err = 0; /* success */
22385 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
22390 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22391 + && a->bfound == a->mvd_bdst)
22397 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
22400 + struct au_branch *br;
22403 + if (unlikely(S_ISDIR(a->inode->i_mode)))
22407 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
22408 + a->mvd_bsrc = au_ibstart(a->inode);
22410 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
22411 + if (unlikely(a->mvd_bsrc < 0
22412 + || (a->mvd_bsrc < au_dbstart(a->dentry)
22413 + || au_dbend(a->dentry) < a->mvd_bsrc
22414 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
22415 + || (a->mvd_bsrc < au_ibstart(a->inode)
22416 + || au_ibend(a->inode) < a->mvd_bsrc
22417 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
22418 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
22419 + AU_MVD_PR(dmsg, "no upper\n");
22423 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
22424 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22425 + AU_MVD_PR(dmsg, "on the bottom\n");
22428 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
22429 + br = au_sbr(a->sb, a->mvd_bsrc);
22430 + err = au_br_rdonly(br);
22431 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
22432 + if (unlikely(err))
22434 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
22435 + || IS_APPEND(a->mvd_h_src_inode))) {
22437 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
22443 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
22444 + a->mvd_bdst = find_lower_writable(a);
22445 + if (unlikely(a->mvd_bdst < 0)) {
22446 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22447 + AU_MVD_PR(dmsg, "no writable lower branch\n");
22451 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
22452 + if (unlikely(a->mvd_bdst < 0
22453 + || au_sbend(a->sb) < a->mvd_bdst)) {
22454 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
22455 + AU_MVD_PR(dmsg, "no lower brid\n");
22460 + err = au_mvd_args_busy(dmsg, a);
22462 + err = au_mvd_args_parent(dmsg, a);
22464 + err = au_mvd_args_intermediate(dmsg, a);
22466 + err = au_mvd_args_exist(dmsg, a);
22468 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
22475 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
22478 + unsigned char dmsg;
22479 + struct au_mvd_args *args;
22482 + if (unlikely(!capable(CAP_SYS_ADMIN)))
22486 + args = kmalloc(sizeof(*args), GFP_NOFS);
22487 + if (unlikely(!args))
22490 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
22492 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
22493 + if (unlikely(err)) {
22498 + AuDbg("flags 0x%x\n", args->mvdown.flags);
22499 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
22500 + args->mvdown.au_errno = 0;
22501 + args->dentry = dentry;
22502 + args->inode = dentry->d_inode;
22503 + args->sb = dentry->d_sb;
22506 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
22507 + args->parent = dget_parent(dentry);
22508 + args->dir = args->parent->d_inode;
22509 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
22510 + dput(args->parent);
22511 + if (unlikely(args->parent != dentry->d_parent)) {
22512 + AU_MVD_PR(dmsg, "parent dir is moved\n");
22516 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
22517 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
22518 + if (unlikely(err))
22521 + di_write_lock_parent(args->parent);
22522 + err = au_mvd_args(dmsg, args);
22523 + if (unlikely(err))
22526 + err = au_do_mvdown(dmsg, args);
22527 + if (unlikely(err))
22530 + au_cpup_attr_timesizes(args->dir);
22531 + au_cpup_attr_timesizes(args->inode);
22532 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
22533 + /* au_digen_dec(dentry); */
22536 + di_write_unlock(args->parent);
22537 + aufs_read_unlock(dentry, AuLock_DW);
22539 + mutex_unlock(&args->inode->i_mutex);
22541 + mutex_unlock(&args->dir->i_mutex);
22543 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
22551 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
22552 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
22553 +++ linux/fs/aufs/opts.c 2015-06-22 08:29:23.710091096 +0200
22556 + * Copyright (C) 2005-2015 Junjiro R. Okajima
22558 + * This program, aufs is free software; you can redistribute it and/or modify
22559 + * it under the terms of the GNU General Public License as published by
22560 + * the Free Software Foundation; either version 2 of the License, or
22561 + * (at your option) any later version.
22563 + * This program is distributed in the hope that it will be useful,
22564 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22565 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22566 + * GNU General Public License for more details.
22568 + * You should have received a copy of the GNU General Public License
22569 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22573 + * mount options/flags
22576 +#include <linux/namei.h>
22577 +#include <linux/types.h> /* a distribution requires */
22578 +#include <linux/parser.h>
22581 +/* ---------------------------------------------------------------------- */
22585 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
22586 + Opt_idel, Opt_imod,
22587 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
22588 + Opt_rdblk_def, Opt_rdhash_def,
22589 + Opt_xino, Opt_noxino,
22590 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22591 + Opt_trunc_xino_path, Opt_itrunc_xino,
22592 + Opt_trunc_xib, Opt_notrunc_xib,
22593 + Opt_shwh, Opt_noshwh,
22594 + Opt_plink, Opt_noplink, Opt_list_plink,
22596 + Opt_dio, Opt_nodio,
22597 + Opt_diropq_a, Opt_diropq_w,
22598 + Opt_warn_perm, Opt_nowarn_perm,
22599 + Opt_wbr_copyup, Opt_wbr_create,
22601 + Opt_refrof, Opt_norefrof,
22602 + Opt_verbose, Opt_noverbose,
22603 + Opt_sum, Opt_nosum, Opt_wsum,
22604 + Opt_dirperm1, Opt_nodirperm1,
22605 + Opt_acl, Opt_noacl,
22606 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22609 +static match_table_t options = {
22610 + {Opt_br, "br=%s"},
22611 + {Opt_br, "br:%s"},
22613 + {Opt_add, "add=%d:%s"},
22614 + {Opt_add, "add:%d:%s"},
22615 + {Opt_add, "ins=%d:%s"},
22616 + {Opt_add, "ins:%d:%s"},
22617 + {Opt_append, "append=%s"},
22618 + {Opt_append, "append:%s"},
22619 + {Opt_prepend, "prepend=%s"},
22620 + {Opt_prepend, "prepend:%s"},
22622 + {Opt_del, "del=%s"},
22623 + {Opt_del, "del:%s"},
22624 + /* {Opt_idel, "idel:%d"}, */
22625 + {Opt_mod, "mod=%s"},
22626 + {Opt_mod, "mod:%s"},
22627 + /* {Opt_imod, "imod:%d:%s"}, */
22629 + {Opt_dirwh, "dirwh=%d"},
22631 + {Opt_xino, "xino=%s"},
22632 + {Opt_noxino, "noxino"},
22633 + {Opt_trunc_xino, "trunc_xino"},
22634 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22635 + {Opt_notrunc_xino, "notrunc_xino"},
22636 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22637 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22638 + /* {Opt_zxino, "zxino=%s"}, */
22639 + {Opt_trunc_xib, "trunc_xib"},
22640 + {Opt_notrunc_xib, "notrunc_xib"},
22642 +#ifdef CONFIG_PROC_FS
22643 + {Opt_plink, "plink"},
22645 + {Opt_ignore_silent, "plink"},
22648 + {Opt_noplink, "noplink"},
22650 +#ifdef CONFIG_AUFS_DEBUG
22651 + {Opt_list_plink, "list_plink"},
22654 + {Opt_udba, "udba=%s"},
22656 + {Opt_dio, "dio"},
22657 + {Opt_nodio, "nodio"},
22659 +#ifdef CONFIG_AUFS_FHSM
22660 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22662 + {Opt_ignore_silent, "fhsm_sec=%d"},
22665 + {Opt_diropq_a, "diropq=always"},
22666 + {Opt_diropq_a, "diropq=a"},
22667 + {Opt_diropq_w, "diropq=whiteouted"},
22668 + {Opt_diropq_w, "diropq=w"},
22670 + {Opt_warn_perm, "warn_perm"},
22671 + {Opt_nowarn_perm, "nowarn_perm"},
22673 + /* keep them temporary */
22674 + {Opt_ignore_silent, "nodlgt"},
22675 + {Opt_ignore_silent, "clean_plink"},
22677 +#ifdef CONFIG_AUFS_SHWH
22678 + {Opt_shwh, "shwh"},
22680 + {Opt_noshwh, "noshwh"},
22682 + {Opt_dirperm1, "dirperm1"},
22683 + {Opt_nodirperm1, "nodirperm1"},
22685 + {Opt_refrof, "refrof"},
22686 + {Opt_norefrof, "norefrof"},
22688 + {Opt_verbose, "verbose"},
22689 + {Opt_verbose, "v"},
22690 + {Opt_noverbose, "noverbose"},
22691 + {Opt_noverbose, "quiet"},
22692 + {Opt_noverbose, "q"},
22693 + {Opt_noverbose, "silent"},
22695 + {Opt_sum, "sum"},
22696 + {Opt_nosum, "nosum"},
22697 + {Opt_wsum, "wsum"},
22699 + {Opt_rdcache, "rdcache=%d"},
22700 + {Opt_rdblk, "rdblk=%d"},
22701 + {Opt_rdblk_def, "rdblk=def"},
22702 + {Opt_rdhash, "rdhash=%d"},
22703 + {Opt_rdhash_def, "rdhash=def"},
22705 + {Opt_wbr_create, "create=%s"},
22706 + {Opt_wbr_create, "create_policy=%s"},
22707 + {Opt_wbr_copyup, "cpup=%s"},
22708 + {Opt_wbr_copyup, "copyup=%s"},
22709 + {Opt_wbr_copyup, "copyup_policy=%s"},
22711 + /* generic VFS flag */
22712 +#ifdef CONFIG_FS_POSIX_ACL
22713 + {Opt_acl, "acl"},
22714 + {Opt_noacl, "noacl"},
22716 + {Opt_ignore_silent, "acl"},
22717 + {Opt_ignore_silent, "noacl"},
22720 + /* internal use for the scripts */
22721 + {Opt_ignore_silent, "si=%s"},
22723 + {Opt_br, "dirs=%s"},
22724 + {Opt_ignore, "debug=%d"},
22725 + {Opt_ignore, "delete=whiteout"},
22726 + {Opt_ignore, "delete=all"},
22727 + {Opt_ignore, "imap=%s"},
22729 + /* temporary workaround, due to old mount(8)? */
22730 + {Opt_ignore_silent, "relatime"},
22735 +/* ---------------------------------------------------------------------- */
22737 +static const char *au_parser_pattern(int val, match_table_t tbl)
22739 + struct match_token *p;
22742 + while (p->pattern) {
22743 + if (p->token == val)
22744 + return p->pattern;
22751 +static const char *au_optstr(int *val, match_table_t tbl)
22753 + struct match_token *p;
22760 + while (p->pattern) {
22762 + && (v & p->token) == p->token) {
22763 + *val &= ~p->token;
22764 + return p->pattern;
22773 +/* ---------------------------------------------------------------------- */
22775 +static match_table_t brperm = {
22776 + {AuBrPerm_RO, AUFS_BRPERM_RO},
22777 + {AuBrPerm_RR, AUFS_BRPERM_RR},
22778 + {AuBrPerm_RW, AUFS_BRPERM_RW},
22782 +static match_table_t brattr = {
22784 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
22785 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
22786 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
22787 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
22788 +#ifdef CONFIG_AUFS_FHSM
22789 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
22791 +#ifdef CONFIG_AUFS_XATTR
22792 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
22793 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
22794 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
22795 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
22796 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
22797 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
22800 + /* ro/rr branch */
22801 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
22804 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
22805 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
22810 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
22817 + p = strchr(str, '+');
22820 + v = match_token(str, table, args);
22822 + if (v & AuBrAttr_CMOO_Mask)
22823 + attr &= ~AuBrAttr_CMOO_Mask;
22828 + pr_warn("ignored branch attribute %s\n", str);
22838 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
22846 + p = au_optstr(&perm, brattr);
22849 + memcpy(q, p, sz + 1);
22855 + p = au_optstr(&perm, brattr);
22859 + memcpy(q, p, sz + 1);
22865 + return q - str->a;
22868 +static int noinline_for_stack br_perm_val(char *perm)
22870 + int val, bad, sz;
22872 + substring_t args[MAX_OPT_ARGS];
22873 + au_br_perm_str_t attr;
22875 + p = strchr(perm, '+');
22878 + val = match_token(perm, brperm, args);
22882 + pr_warn("ignored branch permission %s\n", perm);
22883 + val = AuBrPerm_RO;
22889 + val |= br_attr_val(p + 1, brattr, args);
22892 + switch (val & AuBrPerm_Mask) {
22893 + case AuBrPerm_RO:
22894 + case AuBrPerm_RR:
22895 + bad = val & AuBrWAttr_Mask;
22896 + val &= ~AuBrWAttr_Mask;
22898 + case AuBrPerm_RW:
22899 + bad = val & AuBrRAttr_Mask;
22900 + val &= ~AuBrRAttr_Mask;
22905 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
22906 + * does not treat it as an error, just warning.
22907 + * this is a tiny guard for the user operation.
22909 + if (val & AuBrAttr_UNPIN) {
22910 + bad |= AuBrAttr_UNPIN;
22911 + val &= ~AuBrAttr_UNPIN;
22914 + if (unlikely(bad)) {
22915 + sz = au_do_optstr_br_attr(&attr, bad);
22917 + pr_warn("ignored branch attribute %s\n", attr.a);
22924 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
22926 + au_br_perm_str_t attr;
22932 + p = au_optstr(&perm, brperm);
22933 + AuDebugOn(!p || !*p);
22935 + memcpy(q, p, sz + 1);
22938 + sz = au_do_optstr_br_attr(&attr, perm);
22941 + memcpy(q, attr.a, sz + 1);
22944 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
22947 +/* ---------------------------------------------------------------------- */
22949 +static match_table_t udbalevel = {
22950 + {AuOpt_UDBA_REVAL, "reval"},
22951 + {AuOpt_UDBA_NONE, "none"},
22952 +#ifdef CONFIG_AUFS_HNOTIFY
22953 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
22954 +#ifdef CONFIG_AUFS_HFSNOTIFY
22955 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
22961 +static int noinline_for_stack udba_val(char *str)
22963 + substring_t args[MAX_OPT_ARGS];
22965 + return match_token(str, udbalevel, args);
22968 +const char *au_optstr_udba(int udba)
22970 + return au_parser_pattern(udba, udbalevel);
22973 +/* ---------------------------------------------------------------------- */
22975 +static match_table_t au_wbr_create_policy = {
22976 + {AuWbrCreate_TDP, "tdp"},
22977 + {AuWbrCreate_TDP, "top-down-parent"},
22978 + {AuWbrCreate_RR, "rr"},
22979 + {AuWbrCreate_RR, "round-robin"},
22980 + {AuWbrCreate_MFS, "mfs"},
22981 + {AuWbrCreate_MFS, "most-free-space"},
22982 + {AuWbrCreate_MFSV, "mfs:%d"},
22983 + {AuWbrCreate_MFSV, "most-free-space:%d"},
22985 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
22986 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
22987 + {AuWbrCreate_PMFS, "pmfs"},
22988 + {AuWbrCreate_PMFSV, "pmfs:%d"},
22989 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
22990 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
22996 + * cf. linux/lib/parser.c and cmdline.c
22997 + * gave up calling memparse() since it uses simple_strtoull() instead of
23000 +static int noinline_for_stack
23001 +au_match_ull(substring_t *s, unsigned long long *result)
23004 + unsigned int len;
23008 + len = s->to - s->from;
23009 + if (len + 1 <= sizeof(a)) {
23010 + memcpy(a, s->from, len);
23012 + err = kstrtoull(a, 0, result);
23017 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23018 + struct au_opt_wbr_create *create)
23021 + unsigned long long ull;
23024 + if (!au_match_ull(arg, &ull))
23025 + create->mfsrr_watermark = ull;
23027 + pr_err("bad integer in %s\n", str);
23034 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23035 + struct au_opt_wbr_create *create)
23040 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23041 + create->mfs_second = n;
23043 + pr_err("bad integer in %s\n", str);
23050 +static int noinline_for_stack
23051 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23054 + substring_t args[MAX_OPT_ARGS];
23056 + err = match_token(str, au_wbr_create_policy, args);
23057 + create->wbr_create = err;
23059 + case AuWbrCreate_MFSRRV:
23060 + case AuWbrCreate_PMFSRRV:
23061 + e = au_wbr_mfs_wmark(&args[0], str, create);
23063 + e = au_wbr_mfs_sec(&args[1], str, create);
23067 + case AuWbrCreate_MFSRR:
23068 + case AuWbrCreate_PMFSRR:
23069 + e = au_wbr_mfs_wmark(&args[0], str, create);
23070 + if (unlikely(e)) {
23075 + case AuWbrCreate_MFS:
23076 + case AuWbrCreate_PMFS:
23077 + create->mfs_second = AUFS_MFS_DEF_SEC;
23079 + case AuWbrCreate_MFSV:
23080 + case AuWbrCreate_PMFSV:
23081 + e = au_wbr_mfs_sec(&args[0], str, create);
23090 +const char *au_optstr_wbr_create(int wbr_create)
23092 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23095 +static match_table_t au_wbr_copyup_policy = {
23096 + {AuWbrCopyup_TDP, "tdp"},
23097 + {AuWbrCopyup_TDP, "top-down-parent"},
23098 + {AuWbrCopyup_BUP, "bup"},
23099 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23100 + {AuWbrCopyup_BU, "bu"},
23101 + {AuWbrCopyup_BU, "bottom-up"},
23105 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23107 + substring_t args[MAX_OPT_ARGS];
23109 + return match_token(str, au_wbr_copyup_policy, args);
23112 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23114 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23117 +/* ---------------------------------------------------------------------- */
23119 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23121 +static void dump_opts(struct au_opts *opts)
23123 +#ifdef CONFIG_AUFS_DEBUG
23124 + /* reduce stack space */
23126 + struct au_opt_add *add;
23127 + struct au_opt_del *del;
23128 + struct au_opt_mod *mod;
23129 + struct au_opt_xino *xino;
23130 + struct au_opt_xino_itrunc *xino_itrunc;
23131 + struct au_opt_wbr_create *create;
23133 + struct au_opt *opt;
23136 + while (opt->type != Opt_tail) {
23137 + switch (opt->type) {
23139 + u.add = &opt->add;
23140 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23141 + u.add->bindex, u.add->pathname, u.add->perm,
23142 + u.add->path.dentry);
23146 + u.del = &opt->del;
23147 + AuDbg("del {%s, %p}\n",
23148 + u.del->pathname, u.del->h_path.dentry);
23152 + u.mod = &opt->mod;
23153 + AuDbg("mod {%s, 0x%x, %p}\n",
23154 + u.mod->path, u.mod->perm, u.mod->h_root);
23157 + u.add = &opt->add;
23158 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23159 + u.add->bindex, u.add->pathname, u.add->perm,
23160 + u.add->path.dentry);
23162 + case Opt_prepend:
23163 + u.add = &opt->add;
23164 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23165 + u.add->bindex, u.add->pathname, u.add->perm,
23166 + u.add->path.dentry);
23169 + AuDbg("dirwh %d\n", opt->dirwh);
23171 + case Opt_rdcache:
23172 + AuDbg("rdcache %d\n", opt->rdcache);
23175 + AuDbg("rdblk %u\n", opt->rdblk);
23177 + case Opt_rdblk_def:
23178 + AuDbg("rdblk_def\n");
23181 + AuDbg("rdhash %u\n", opt->rdhash);
23183 + case Opt_rdhash_def:
23184 + AuDbg("rdhash_def\n");
23187 + u.xino = &opt->xino;
23188 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23190 + case Opt_trunc_xino:
23191 + AuLabel(trunc_xino);
23193 + case Opt_notrunc_xino:
23194 + AuLabel(notrunc_xino);
23196 + case Opt_trunc_xino_path:
23197 + case Opt_itrunc_xino:
23198 + u.xino_itrunc = &opt->xino_itrunc;
23199 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23204 + case Opt_trunc_xib:
23205 + AuLabel(trunc_xib);
23207 + case Opt_notrunc_xib:
23208 + AuLabel(notrunc_xib);
23216 + case Opt_dirperm1:
23217 + AuLabel(dirperm1);
23219 + case Opt_nodirperm1:
23220 + AuLabel(nodirperm1);
23225 + case Opt_noplink:
23226 + AuLabel(noplink);
23228 + case Opt_list_plink:
23229 + AuLabel(list_plink);
23232 + AuDbg("udba %d, %s\n",
23233 + opt->udba, au_optstr_udba(opt->udba));
23241 + case Opt_diropq_a:
23242 + AuLabel(diropq_a);
23244 + case Opt_diropq_w:
23245 + AuLabel(diropq_w);
23247 + case Opt_warn_perm:
23248 + AuLabel(warn_perm);
23250 + case Opt_nowarn_perm:
23251 + AuLabel(nowarn_perm);
23256 + case Opt_norefrof:
23257 + AuLabel(norefrof);
23259 + case Opt_verbose:
23260 + AuLabel(verbose);
23262 + case Opt_noverbose:
23263 + AuLabel(noverbose);
23274 + case Opt_wbr_create:
23275 + u.create = &opt->wbr_create;
23276 + AuDbg("create %d, %s\n", u.create->wbr_create,
23277 + au_optstr_wbr_create(u.create->wbr_create));
23278 + switch (u.create->wbr_create) {
23279 + case AuWbrCreate_MFSV:
23280 + case AuWbrCreate_PMFSV:
23281 + AuDbg("%d sec\n", u.create->mfs_second);
23283 + case AuWbrCreate_MFSRR:
23284 + AuDbg("%llu watermark\n",
23285 + u.create->mfsrr_watermark);
23287 + case AuWbrCreate_MFSRRV:
23288 + case AuWbrCreate_PMFSRRV:
23289 + AuDbg("%llu watermark, %d sec\n",
23290 + u.create->mfsrr_watermark,
23291 + u.create->mfs_second);
23295 + case Opt_wbr_copyup:
23296 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
23297 + au_optstr_wbr_copyup(opt->wbr_copyup));
23299 + case Opt_fhsm_sec:
23300 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
23316 +void au_opts_free(struct au_opts *opts)
23318 + struct au_opt *opt;
23321 + while (opt->type != Opt_tail) {
23322 + switch (opt->type) {
23325 + case Opt_prepend:
23326 + path_put(&opt->add.path);
23330 + path_put(&opt->del.h_path);
23334 + dput(opt->mod.h_root);
23337 + fput(opt->xino.file);
23344 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
23345 + aufs_bindex_t bindex)
23348 + struct au_opt_add *add = &opt->add;
23351 + add->bindex = bindex;
23352 + add->perm = AuBrPerm_RO;
23353 + add->pathname = opt_str;
23354 + p = strchr(opt_str, '=');
23358 + add->perm = br_perm_val(p);
23361 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
23364 + add->perm = AuBrPerm_RO;
23365 + if (au_test_fs_rr(add->path.dentry->d_sb))
23366 + add->perm = AuBrPerm_RR;
23367 + else if (!bindex && !(sb_flags & MS_RDONLY))
23368 + add->perm = AuBrPerm_RW;
23370 + opt->type = Opt_add;
23373 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
23380 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
23384 + del->pathname = args[0].from;
23385 + AuDbg("del path %s\n", del->pathname);
23387 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
23388 + if (unlikely(err))
23389 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
23394 +#if 0 /* reserved for future use */
23395 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
23396 + struct au_opt_del *del, substring_t args[])
23399 + struct dentry *root;
23402 + root = sb->s_root;
23403 + aufs_read_lock(root, AuLock_FLUSH);
23404 + if (bindex < 0 || au_sbend(sb) < bindex) {
23405 + pr_err("out of bounds, %d\n", bindex);
23410 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
23411 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
23414 + aufs_read_unlock(root, !AuLock_IR);
23419 +static int noinline_for_stack
23420 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
23423 + struct path path;
23427 + mod->path = args[0].from;
23428 + p = strchr(mod->path, '=');
23429 + if (unlikely(!p)) {
23430 + pr_err("no permssion %s\n", args[0].from);
23435 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
23436 + if (unlikely(err)) {
23437 + pr_err("lookup failed %s (%d)\n", mod->path, err);
23441 + mod->perm = br_perm_val(p);
23442 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
23443 + mod->h_root = dget(path.dentry);
23450 +#if 0 /* reserved for future use */
23451 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
23452 + struct au_opt_mod *mod, substring_t args[])
23455 + struct dentry *root;
23458 + root = sb->s_root;
23459 + aufs_read_lock(root, AuLock_FLUSH);
23460 + if (bindex < 0 || au_sbend(sb) < bindex) {
23461 + pr_err("out of bounds, %d\n", bindex);
23466 + mod->perm = br_perm_val(args[1].from);
23467 + AuDbg("mod path %s, perm 0x%x, %s\n",
23468 + mod->path, mod->perm, args[1].from);
23469 + mod->h_root = dget(au_h_dptr(root, bindex));
23472 + aufs_read_unlock(root, !AuLock_IR);
23477 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
23478 + substring_t args[])
23481 + struct file *file;
23483 + file = au_xino_create(sb, args[0].from, /*silent*/0);
23484 + err = PTR_ERR(file);
23485 + if (IS_ERR(file))
23489 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
23491 + pr_err("%s must be outside\n", args[0].from);
23496 + xino->file = file;
23497 + xino->path = args[0].from;
23503 +static int noinline_for_stack
23504 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
23505 + struct au_opt_xino_itrunc *xino_itrunc,
23506 + substring_t args[])
23509 + aufs_bindex_t bend, bindex;
23510 + struct path path;
23511 + struct dentry *root;
23513 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
23514 + if (unlikely(err)) {
23515 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
23519 + xino_itrunc->bindex = -1;
23520 + root = sb->s_root;
23521 + aufs_read_lock(root, AuLock_FLUSH);
23522 + bend = au_sbend(sb);
23523 + for (bindex = 0; bindex <= bend; bindex++) {
23524 + if (au_h_dptr(root, bindex) == path.dentry) {
23525 + xino_itrunc->bindex = bindex;
23529 + aufs_read_unlock(root, !AuLock_IR);
23532 + if (unlikely(xino_itrunc->bindex < 0)) {
23533 + pr_err("no such branch %s\n", args[0].from);
23541 +/* called without aufs lock */
23542 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
23544 + int err, n, token;
23545 + aufs_bindex_t bindex;
23546 + unsigned char skipped;
23547 + struct dentry *root;
23548 + struct au_opt *opt, *opt_tail;
23550 + /* reduce the stack space */
23552 + struct au_opt_xino_itrunc *xino_itrunc;
23553 + struct au_opt_wbr_create *create;
23556 + substring_t args[MAX_OPT_ARGS];
23560 + a = kmalloc(sizeof(*a), GFP_NOFS);
23561 + if (unlikely(!a))
23564 + root = sb->s_root;
23568 + opt_tail = opt + opts->max_opt - 1;
23569 + opt->type = Opt_tail;
23570 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
23573 + token = match_token(opt_str, options, a->args);
23577 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
23579 + err = opt_add(opt, opt_str, opts->sb_flags,
23581 + if (unlikely(!err && ++opt > opt_tail)) {
23585 + opt->type = Opt_tail;
23590 + if (unlikely(match_int(&a->args[0], &n))) {
23591 + pr_err("bad integer in %s\n", opt_str);
23595 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
23598 + opt->type = token;
23601 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23602 + /*dummy bindex*/1);
23604 + opt->type = token;
23606 + case Opt_prepend:
23607 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23610 + opt->type = token;
23613 + err = au_opts_parse_del(&opt->del, a->args);
23615 + opt->type = token;
23617 +#if 0 /* reserved for future use */
23619 + del->pathname = "(indexed)";
23620 + if (unlikely(match_int(&args[0], &n))) {
23621 + pr_err("bad integer in %s\n", opt_str);
23624 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23626 + opt->type = token;
23630 + err = au_opts_parse_mod(&opt->mod, a->args);
23632 + opt->type = token;
23634 +#ifdef IMOD /* reserved for future use */
23636 + u.mod->path = "(indexed)";
23637 + if (unlikely(match_int(&a->args[0], &n))) {
23638 + pr_err("bad integer in %s\n", opt_str);
23641 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23643 + opt->type = token;
23647 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23649 + opt->type = token;
23652 + case Opt_trunc_xino_path:
23653 + err = au_opts_parse_xino_itrunc_path
23654 + (sb, &opt->xino_itrunc, a->args);
23656 + opt->type = token;
23659 + case Opt_itrunc_xino:
23660 + u.xino_itrunc = &opt->xino_itrunc;
23661 + if (unlikely(match_int(&a->args[0], &n))) {
23662 + pr_err("bad integer in %s\n", opt_str);
23665 + u.xino_itrunc->bindex = n;
23666 + aufs_read_lock(root, AuLock_FLUSH);
23667 + if (n < 0 || au_sbend(sb) < n) {
23668 + pr_err("out of bounds, %d\n", n);
23669 + aufs_read_unlock(root, !AuLock_IR);
23672 + aufs_read_unlock(root, !AuLock_IR);
23674 + opt->type = token;
23678 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23681 + opt->type = token;
23684 + case Opt_rdcache:
23685 + if (unlikely(match_int(&a->args[0], &n))) {
23686 + pr_err("bad integer in %s\n", opt_str);
23689 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23690 + pr_err("rdcache must be smaller than %d\n",
23691 + AUFS_RDCACHE_MAX);
23694 + opt->rdcache = n;
23696 + opt->type = token;
23699 + if (unlikely(match_int(&a->args[0], &n)
23701 + || n > KMALLOC_MAX_SIZE)) {
23702 + pr_err("bad integer in %s\n", opt_str);
23705 + if (unlikely(n && n < NAME_MAX)) {
23706 + pr_err("rdblk must be larger than %d\n",
23712 + opt->type = token;
23715 + if (unlikely(match_int(&a->args[0], &n)
23717 + || n * sizeof(struct hlist_head)
23718 + > KMALLOC_MAX_SIZE)) {
23719 + pr_err("bad integer in %s\n", opt_str);
23724 + opt->type = token;
23727 + case Opt_trunc_xino:
23728 + case Opt_notrunc_xino:
23730 + case Opt_trunc_xib:
23731 + case Opt_notrunc_xib:
23734 + case Opt_dirperm1:
23735 + case Opt_nodirperm1:
23737 + case Opt_noplink:
23738 + case Opt_list_plink:
23741 + case Opt_diropq_a:
23742 + case Opt_diropq_w:
23743 + case Opt_warn_perm:
23744 + case Opt_nowarn_perm:
23746 + case Opt_norefrof:
23747 + case Opt_verbose:
23748 + case Opt_noverbose:
23752 + case Opt_rdblk_def:
23753 + case Opt_rdhash_def:
23757 + opt->type = token;
23761 + opt->udba = udba_val(a->args[0].from);
23762 + if (opt->udba >= 0) {
23764 + opt->type = token;
23766 + pr_err("wrong value, %s\n", opt_str);
23769 + case Opt_wbr_create:
23770 + u.create = &opt->wbr_create;
23771 + u.create->wbr_create
23772 + = au_wbr_create_val(a->args[0].from, u.create);
23773 + if (u.create->wbr_create >= 0) {
23775 + opt->type = token;
23777 + pr_err("wrong value, %s\n", opt_str);
23779 + case Opt_wbr_copyup:
23780 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
23781 + if (opt->wbr_copyup >= 0) {
23783 + opt->type = token;
23785 + pr_err("wrong value, %s\n", opt_str);
23788 + case Opt_fhsm_sec:
23789 + if (unlikely(match_int(&a->args[0], &n)
23791 + pr_err("bad integer in %s\n", opt_str);
23794 + if (sysaufs_brs) {
23795 + opt->fhsm_second = n;
23796 + opt->type = token;
23798 + pr_warn("ignored %s\n", opt_str);
23803 + pr_warn("ignored %s\n", opt_str);
23805 + case Opt_ignore_silent:
23810 + pr_err("unknown option %s\n", opt_str);
23814 + if (!err && !skipped) {
23815 + if (unlikely(++opt > opt_tail)) {
23818 + opt->type = Opt_tail;
23821 + opt->type = Opt_tail;
23827 + if (unlikely(err))
23828 + au_opts_free(opts);
23834 +static int au_opt_wbr_create(struct super_block *sb,
23835 + struct au_opt_wbr_create *create)
23838 + struct au_sbinfo *sbinfo;
23840 + SiMustWriteLock(sb);
23842 + err = 1; /* handled */
23843 + sbinfo = au_sbi(sb);
23844 + if (sbinfo->si_wbr_create_ops->fin) {
23845 + err = sbinfo->si_wbr_create_ops->fin(sb);
23850 + sbinfo->si_wbr_create = create->wbr_create;
23851 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
23852 + switch (create->wbr_create) {
23853 + case AuWbrCreate_MFSRRV:
23854 + case AuWbrCreate_MFSRR:
23855 + case AuWbrCreate_PMFSRR:
23856 + case AuWbrCreate_PMFSRRV:
23857 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
23859 + case AuWbrCreate_MFS:
23860 + case AuWbrCreate_MFSV:
23861 + case AuWbrCreate_PMFS:
23862 + case AuWbrCreate_PMFSV:
23863 + sbinfo->si_wbr_mfs.mfs_expire
23864 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
23868 + if (sbinfo->si_wbr_create_ops->init)
23869 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
23876 + * plus: processed without an error
23877 + * zero: unprocessed
23879 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
23880 + struct au_opts *opts)
23883 + struct au_sbinfo *sbinfo;
23885 + SiMustWriteLock(sb);
23887 + err = 1; /* handled */
23888 + sbinfo = au_sbi(sb);
23889 + switch (opt->type) {
23891 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23892 + sbinfo->si_mntflags |= opt->udba;
23893 + opts->given_udba |= opt->udba;
23897 + au_opt_set(sbinfo->si_mntflags, PLINK);
23899 + case Opt_noplink:
23900 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23901 + au_plink_put(sb, /*verbose*/1);
23902 + au_opt_clr(sbinfo->si_mntflags, PLINK);
23904 + case Opt_list_plink:
23905 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23906 + au_plink_list(sb);
23910 + au_opt_set(sbinfo->si_mntflags, DIO);
23911 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23914 + au_opt_clr(sbinfo->si_mntflags, DIO);
23915 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23918 + case Opt_fhsm_sec:
23919 + au_fhsm_set(sbinfo, opt->fhsm_second);
23922 + case Opt_diropq_a:
23923 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23925 + case Opt_diropq_w:
23926 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23929 + case Opt_warn_perm:
23930 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
23932 + case Opt_nowarn_perm:
23933 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
23937 + au_opt_set(sbinfo->si_mntflags, REFROF);
23939 + case Opt_norefrof:
23940 + au_opt_clr(sbinfo->si_mntflags, REFROF);
23943 + case Opt_verbose:
23944 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
23946 + case Opt_noverbose:
23947 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
23951 + au_opt_set(sbinfo->si_mntflags, SUM);
23954 + au_opt_clr(sbinfo->si_mntflags, SUM);
23955 + au_opt_set(sbinfo->si_mntflags, SUM_W);
23957 + au_opt_clr(sbinfo->si_mntflags, SUM);
23958 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
23961 + case Opt_wbr_create:
23962 + err = au_opt_wbr_create(sb, &opt->wbr_create);
23964 + case Opt_wbr_copyup:
23965 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
23966 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
23970 + sbinfo->si_dirwh = opt->dirwh;
23973 + case Opt_rdcache:
23974 + sbinfo->si_rdcache
23975 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
23978 + sbinfo->si_rdblk = opt->rdblk;
23980 + case Opt_rdblk_def:
23981 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
23984 + sbinfo->si_rdhash = opt->rdhash;
23986 + case Opt_rdhash_def:
23987 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
23991 + au_opt_set(sbinfo->si_mntflags, SHWH);
23994 + au_opt_clr(sbinfo->si_mntflags, SHWH);
23997 + case Opt_dirperm1:
23998 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24000 + case Opt_nodirperm1:
24001 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24004 + case Opt_trunc_xino:
24005 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24007 + case Opt_notrunc_xino:
24008 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24011 + case Opt_trunc_xino_path:
24012 + case Opt_itrunc_xino:
24013 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24018 + case Opt_trunc_xib:
24019 + au_fset_opts(opts->flags, TRUNC_XIB);
24021 + case Opt_notrunc_xib:
24022 + au_fclr_opts(opts->flags, TRUNC_XIB);
24026 + sb->s_flags |= MS_POSIXACL;
24029 + sb->s_flags &= ~MS_POSIXACL;
24041 + * returns tri-state.
24042 + * plus: processed without an error
24043 + * zero: unprocessed
24046 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24047 + struct au_opts *opts)
24049 + int err, do_refresh;
24052 + switch (opt->type) {
24054 + opt->add.bindex = au_sbend(sb) + 1;
24055 + if (opt->add.bindex < 0)
24056 + opt->add.bindex = 0;
24058 + case Opt_prepend:
24059 + opt->add.bindex = 0;
24060 + add: /* indented label */
24062 + err = au_br_add(sb, &opt->add,
24063 + au_ftest_opts(opts->flags, REMOUNT));
24066 + au_fset_opts(opts->flags, REFRESH);
24072 + err = au_br_del(sb, &opt->del,
24073 + au_ftest_opts(opts->flags, REMOUNT));
24076 + au_fset_opts(opts->flags, TRUNC_XIB);
24077 + au_fset_opts(opts->flags, REFRESH);
24083 + err = au_br_mod(sb, &opt->mod,
24084 + au_ftest_opts(opts->flags, REMOUNT),
24089 + au_fset_opts(opts->flags, REFRESH);
24097 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24098 + struct au_opt_xino **opt_xino,
24099 + struct au_opts *opts)
24102 + aufs_bindex_t bend, bindex;
24103 + struct dentry *root, *parent, *h_root;
24106 + switch (opt->type) {
24108 + err = au_xino_set(sb, &opt->xino,
24109 + !!au_ftest_opts(opts->flags, REMOUNT));
24110 + if (unlikely(err))
24113 + *opt_xino = &opt->xino;
24114 + au_xino_brid_set(sb, -1);
24116 + /* safe d_parent access */
24117 + parent = opt->xino.file->f_path.dentry->d_parent;
24118 + root = sb->s_root;
24119 + bend = au_sbend(sb);
24120 + for (bindex = 0; bindex <= bend; bindex++) {
24121 + h_root = au_h_dptr(root, bindex);
24122 + if (h_root == parent) {
24123 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24131 + au_xino_brid_set(sb, -1);
24132 + *opt_xino = (void *)-1;
24139 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24140 + unsigned int pending)
24143 + aufs_bindex_t bindex, bend;
24144 + unsigned char do_plink, skip, do_free;
24145 + struct au_branch *br;
24146 + struct au_wbr *wbr;
24147 + struct dentry *root;
24148 + struct inode *dir, *h_dir;
24149 + struct au_sbinfo *sbinfo;
24150 + struct au_hinode *hdir;
24152 + SiMustAnyLock(sb);
24154 + sbinfo = au_sbi(sb);
24155 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24157 + if (!(sb_flags & MS_RDONLY)) {
24158 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24159 + pr_warn("first branch should be rw\n");
24160 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24161 + pr_warn("shwh should be used with ro\n");
24164 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24165 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24166 + pr_warn("udba=*notify requires xino\n");
24168 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24169 + pr_warn("dirperm1 breaks the protection"
24170 + " by the permission bits on the lower branch\n");
24174 + root = sb->s_root;
24175 + dir = root->d_inode;
24176 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24177 + bend = au_sbend(sb);
24178 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24180 + h_dir = au_h_iptr(dir, bindex);
24181 + br = au_sbr(sb, bindex);
24183 + if ((br->br_perm & AuBrAttr_ICEX)
24184 + && !h_dir->i_op->listxattr)
24185 + br->br_perm &= ~AuBrAttr_ICEX;
24187 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24188 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24189 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24193 + wbr = br->br_wbr;
24195 + wbr_wh_read_lock(wbr);
24197 + if (!au_br_writable(br->br_perm)) {
24200 + || (!wbr->wbr_whbase
24201 + && !wbr->wbr_plink
24202 + && !wbr->wbr_orph));
24203 + } else if (!au_br_wh_linkable(br->br_perm)) {
24204 + /* skip = (!br->br_whbase && !br->br_orph); */
24205 + skip = (!wbr || !wbr->wbr_whbase);
24206 + if (skip && wbr) {
24208 + skip = !!wbr->wbr_plink;
24210 + skip = !wbr->wbr_plink;
24213 + /* skip = (br->br_whbase && br->br_ohph); */
24214 + skip = (wbr && wbr->wbr_whbase);
24217 + skip = !!wbr->wbr_plink;
24219 + skip = !wbr->wbr_plink;
24223 + wbr_wh_read_unlock(wbr);
24225 + if (au_br_fhsm(br->br_perm)) {
24227 + AuDebugOn(!br->br_fhsm);
24233 + hdir = au_hi(dir, bindex);
24234 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
24236 + wbr_wh_write_lock(wbr);
24237 + err = au_wh_init(br, sb);
24239 + wbr_wh_write_unlock(wbr);
24240 + au_hn_imtx_unlock(hdir);
24242 + if (!err && do_free) {
24244 + br->br_wbr = NULL;
24249 + au_fset_si(sbinfo, FHSM);
24250 + for (bindex = bend; bindex >= 0; bindex--) {
24251 + br = au_sbr(sb, bindex);
24252 + if (au_br_fhsm(br->br_perm)) {
24253 + au_fhsm_set_bottom(sb, bindex);
24258 + au_fclr_si(sbinfo, FHSM);
24259 + au_fhsm_set_bottom(sb, -1);
24265 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24268 + unsigned int tmp;
24269 + aufs_bindex_t bindex, bend;
24270 + struct au_opt *opt;
24271 + struct au_opt_xino *opt_xino, xino;
24272 + struct au_sbinfo *sbinfo;
24273 + struct au_branch *br;
24274 + struct inode *dir;
24276 + SiMustWriteLock(sb);
24281 + while (err >= 0 && opt->type != Opt_tail)
24282 + err = au_opt_simple(sb, opt++, opts);
24285 + else if (unlikely(err < 0))
24288 + /* disable xino and udba temporary */
24289 + sbinfo = au_sbi(sb);
24290 + tmp = sbinfo->si_mntflags;
24291 + au_opt_clr(sbinfo->si_mntflags, XINO);
24292 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
24295 + while (err >= 0 && opt->type != Opt_tail)
24296 + err = au_opt_br(sb, opt++, opts);
24299 + else if (unlikely(err < 0))
24302 + bend = au_sbend(sb);
24303 + if (unlikely(bend < 0)) {
24305 + pr_err("no branches\n");
24309 + if (au_opt_test(tmp, XINO))
24310 + au_opt_set(sbinfo->si_mntflags, XINO);
24312 + while (!err && opt->type != Opt_tail)
24313 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
24314 + if (unlikely(err))
24317 + err = au_opts_verify(sb, sb->s_flags, tmp);
24318 + if (unlikely(err))
24321 + /* restore xino */
24322 + if (au_opt_test(tmp, XINO) && !opt_xino) {
24323 + xino.file = au_xino_def(sb);
24324 + err = PTR_ERR(xino.file);
24325 + if (IS_ERR(xino.file))
24328 + err = au_xino_set(sb, &xino, /*remount*/0);
24330 + if (unlikely(err))
24334 + /* restore udba */
24335 + tmp &= AuOptMask_UDBA;
24336 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24337 + sbinfo->si_mntflags |= tmp;
24338 + bend = au_sbend(sb);
24339 + for (bindex = 0; bindex <= bend; bindex++) {
24340 + br = au_sbr(sb, bindex);
24341 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
24342 + if (unlikely(err))
24343 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24345 + /* go on even if err */
24347 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
24348 + dir = sb->s_root->d_inode;
24349 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
24356 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
24359 + struct inode *dir;
24360 + struct au_opt_xino *opt_xino;
24361 + struct au_opt *opt;
24362 + struct au_sbinfo *sbinfo;
24364 + SiMustWriteLock(sb);
24366 + dir = sb->s_root->d_inode;
24367 + sbinfo = au_sbi(sb);
24371 + while (err >= 0 && opt->type != Opt_tail) {
24372 + err = au_opt_simple(sb, opt, opts);
24374 + err = au_opt_br(sb, opt, opts);
24376 + err = au_opt_xino(sb, opt, &opt_xino, opts);
24382 + /* go on even err */
24384 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
24385 + if (unlikely(rerr && !err))
24388 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
24389 + rerr = au_xib_trunc(sb);
24390 + if (unlikely(rerr && !err))
24394 + /* will be handled by the caller */
24395 + if (!au_ftest_opts(opts->flags, REFRESH)
24396 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
24397 + au_fset_opts(opts->flags, REFRESH);
24399 + AuDbg("status 0x%x\n", opts->flags);
24403 +/* ---------------------------------------------------------------------- */
24405 +unsigned int au_opt_udba(struct super_block *sb)
24407 + return au_mntflags(sb) & AuOptMask_UDBA;
24409 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
24410 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
24411 +++ linux/fs/aufs/opts.h 2015-06-22 08:27:37.887501948 +0200
24414 + * Copyright (C) 2005-2015 Junjiro R. Okajima
24416 + * This program, aufs is free software; you can redistribute it and/or modify
24417 + * it under the terms of the GNU General Public License as published by
24418 + * the Free Software Foundation; either version 2 of the License, or
24419 + * (at your option) any later version.
24421 + * This program is distributed in the hope that it will be useful,
24422 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24423 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24424 + * GNU General Public License for more details.
24426 + * You should have received a copy of the GNU General Public License
24427 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24431 + * mount options/flags
24434 +#ifndef __AUFS_OPTS_H__
24435 +#define __AUFS_OPTS_H__
24439 +#include <linux/path.h>
24442 +struct super_block;
24444 +/* ---------------------------------------------------------------------- */
24447 +#define AuOpt_XINO 1 /* external inode number bitmap
24448 + and translation table */
24449 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
24450 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
24451 +#define AuOpt_UDBA_REVAL (1 << 3)
24452 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
24453 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
24454 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
24455 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
24457 +#define AuOpt_REFROF (1 << 8) /* unimplemented */
24458 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
24459 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
24460 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
24461 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
24462 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
24463 +#define AuOpt_DIO (1 << 14) /* direct io */
24465 +#ifndef CONFIG_AUFS_HNOTIFY
24466 +#undef AuOpt_UDBA_HNOTIFY
24467 +#define AuOpt_UDBA_HNOTIFY 0
24469 +#ifndef CONFIG_AUFS_SHWH
24471 +#define AuOpt_SHWH 0
24474 +#define AuOpt_Def (AuOpt_XINO \
24475 + | AuOpt_UDBA_REVAL \
24477 + /* | AuOpt_DIRPERM1 */ \
24478 + | AuOpt_WARN_PERM)
24479 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
24480 + | AuOpt_UDBA_REVAL \
24481 + | AuOpt_UDBA_HNOTIFY)
24483 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
24484 +#define au_opt_set(flags, name) do { \
24485 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
24486 + ((flags) |= AuOpt_##name); \
24488 +#define au_opt_set_udba(flags, name) do { \
24489 + (flags) &= ~AuOptMask_UDBA; \
24490 + ((flags) |= AuOpt_##name); \
24492 +#define au_opt_clr(flags, name) do { \
24493 + ((flags) &= ~AuOpt_##name); \
24496 +static inline unsigned int au_opts_plink(unsigned int mntflags)
24498 +#ifdef CONFIG_PROC_FS
24501 + return mntflags & ~AuOpt_PLINK;
24505 +/* ---------------------------------------------------------------------- */
24507 +/* policies to select one among multiple writable branches */
24509 + AuWbrCreate_TDP, /* top down parent */
24510 + AuWbrCreate_RR, /* round robin */
24511 + AuWbrCreate_MFS, /* most free space */
24512 + AuWbrCreate_MFSV, /* mfs with seconds */
24513 + AuWbrCreate_MFSRR, /* mfs then rr */
24514 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
24515 + AuWbrCreate_PMFS, /* parent and mfs */
24516 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
24517 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
24518 + AuWbrCreate_PMFSRRV, /* plus seconds */
24520 + AuWbrCreate_Def = AuWbrCreate_TDP
24524 + AuWbrCopyup_TDP, /* top down parent */
24525 + AuWbrCopyup_BUP, /* bottom up parent */
24526 + AuWbrCopyup_BU, /* bottom up */
24528 + AuWbrCopyup_Def = AuWbrCopyup_TDP
24531 +/* ---------------------------------------------------------------------- */
24533 +struct au_opt_add {
24534 + aufs_bindex_t bindex;
24537 + struct path path;
24540 +struct au_opt_del {
24542 + struct path h_path;
24545 +struct au_opt_mod {
24548 + struct dentry *h_root;
24551 +struct au_opt_xino {
24553 + struct file *file;
24556 +struct au_opt_xino_itrunc {
24557 + aufs_bindex_t bindex;
24560 +struct au_opt_wbr_create {
24563 + unsigned long long mfsrr_watermark;
24569 + struct au_opt_xino xino;
24570 + struct au_opt_xino_itrunc xino_itrunc;
24571 + struct au_opt_add add;
24572 + struct au_opt_del del;
24573 + struct au_opt_mod mod;
24576 + unsigned int rdblk;
24577 + unsigned int rdhash;
24579 + struct au_opt_wbr_create wbr_create;
24581 + unsigned int fhsm_second;
24586 +#define AuOpts_REMOUNT 1
24587 +#define AuOpts_REFRESH (1 << 1)
24588 +#define AuOpts_TRUNC_XIB (1 << 2)
24589 +#define AuOpts_REFRESH_DYAOP (1 << 3)
24590 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
24591 +#define au_fset_opts(flags, name) \
24592 + do { (flags) |= AuOpts_##name; } while (0)
24593 +#define au_fclr_opts(flags, name) \
24594 + do { (flags) &= ~AuOpts_##name; } while (0)
24597 + struct au_opt *opt;
24600 + unsigned int given_udba;
24601 + unsigned int flags;
24602 + unsigned long sb_flags;
24605 +/* ---------------------------------------------------------------------- */
24608 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
24609 +const char *au_optstr_udba(int udba);
24610 +const char *au_optstr_wbr_copyup(int wbr_copyup);
24611 +const char *au_optstr_wbr_create(int wbr_create);
24613 +void au_opts_free(struct au_opts *opts);
24614 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
24615 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24616 + unsigned int pending);
24617 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
24618 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
24620 +unsigned int au_opt_udba(struct super_block *sb);
24622 +#endif /* __KERNEL__ */
24623 +#endif /* __AUFS_OPTS_H__ */
24624 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
24625 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
24626 +++ linux/fs/aufs/plink.c 2015-06-22 08:27:37.887501948 +0200
24629 + * Copyright (C) 2005-2015 Junjiro R. Okajima
24631 + * This program, aufs is free software; you can redistribute it and/or modify
24632 + * it under the terms of the GNU General Public License as published by
24633 + * the Free Software Foundation; either version 2 of the License, or
24634 + * (at your option) any later version.
24636 + * This program is distributed in the hope that it will be useful,
24637 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24638 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24639 + * GNU General Public License for more details.
24641 + * You should have received a copy of the GNU General Public License
24642 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24652 + * the pseudo-link maintenance mode.
24653 + * during a user process maintains the pseudo-links,
24654 + * prohibit adding a new plink and branch manipulation.
24658 + * For entry functions which will handle plink, and i_mutex is already held
24660 + * They cannot wait and should return an error at once.
24661 + * Callers has to check the error.
24663 + * For entry functions which will handle plink, but i_mutex is not held
24665 + * They can wait the plink maintenance mode to finish.
24667 + * They behave like F_SETLK and F_SETLKW.
24668 + * If the caller never handle plink, then both flags are unnecessary.
24671 +int au_plink_maint(struct super_block *sb, int flags)
24675 + struct au_sbinfo *sbi;
24677 + SiMustAnyLock(sb);
24680 + if (!au_opt_test(au_mntflags(sb), PLINK))
24683 + sbi = au_sbi(sb);
24684 + pid = sbi->si_plink_maint_pid;
24685 + if (!pid || pid == current->pid)
24688 + /* todo: it highly depends upon /sbin/mount.aufs */
24690 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
24691 + rcu_read_unlock();
24695 + if (au_ftest_lock(flags, NOPLMW)) {
24696 + /* if there is no i_mutex lock in VFS, we don't need to wait */
24697 + /* AuDebugOn(!lockdep_depth(current)); */
24698 + while (sbi->si_plink_maint_pid) {
24699 + si_read_unlock(sb);
24700 + /* gave up wake_up_bit() */
24701 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
24703 + if (au_ftest_lock(flags, FLUSH))
24704 + au_nwt_flush(&sbi->si_nowait);
24705 + si_noflush_read_lock(sb);
24707 + } else if (au_ftest_lock(flags, NOPLM)) {
24708 + AuDbg("ppid %d, pid %d\n", ppid, pid);
24716 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
24718 + spin_lock(&sbinfo->si_plink_maint_lock);
24719 + sbinfo->si_plink_maint_pid = 0;
24720 + spin_unlock(&sbinfo->si_plink_maint_lock);
24721 + wake_up_all(&sbinfo->si_plink_wq);
24724 +int au_plink_maint_enter(struct super_block *sb)
24727 + struct au_sbinfo *sbinfo;
24730 + sbinfo = au_sbi(sb);
24731 + /* make sure i am the only one in this fs */
24732 + si_write_lock(sb, AuLock_FLUSH);
24733 + if (au_opt_test(au_mntflags(sb), PLINK)) {
24734 + spin_lock(&sbinfo->si_plink_maint_lock);
24735 + if (!sbinfo->si_plink_maint_pid)
24736 + sbinfo->si_plink_maint_pid = current->pid;
24739 + spin_unlock(&sbinfo->si_plink_maint_lock);
24741 + si_write_unlock(sb);
24746 +/* ---------------------------------------------------------------------- */
24748 +#ifdef CONFIG_AUFS_DEBUG
24749 +void au_plink_list(struct super_block *sb)
24752 + struct au_sbinfo *sbinfo;
24753 + struct hlist_head *plink_hlist;
24754 + struct pseudo_link *plink;
24756 + SiMustAnyLock(sb);
24758 + sbinfo = au_sbi(sb);
24759 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24760 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24762 + for (i = 0; i < AuPlink_NHASH; i++) {
24763 + plink_hlist = &sbinfo->si_plink[i].head;
24765 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24766 + AuDbg("%lu\n", plink->inode->i_ino);
24767 + rcu_read_unlock();
24772 +/* is the inode pseudo-linked? */
24773 +int au_plink_test(struct inode *inode)
24776 + struct au_sbinfo *sbinfo;
24777 + struct hlist_head *plink_hlist;
24778 + struct pseudo_link *plink;
24780 + sbinfo = au_sbi(inode->i_sb);
24781 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24782 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
24783 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24786 + i = au_plink_hash(inode->i_ino);
24787 + plink_hlist = &sbinfo->si_plink[i].head;
24789 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24790 + if (plink->inode == inode) {
24794 + rcu_read_unlock();
24798 +/* ---------------------------------------------------------------------- */
24801 + * generate a name for plink.
24802 + * the file will be stored under AUFS_WH_PLINKDIR.
24804 +/* 20 is max digits length of ulong 64 */
24805 +#define PLINK_NAME_LEN ((20 + 1) * 2)
24807 +static int plink_name(char *name, int len, struct inode *inode,
24808 + aufs_bindex_t bindex)
24811 + struct inode *h_inode;
24813 + h_inode = au_h_iptr(inode, bindex);
24814 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
24818 +struct au_do_plink_lkup_args {
24819 + struct dentry **errp;
24820 + struct qstr *tgtname;
24821 + struct dentry *h_parent;
24822 + struct au_branch *br;
24825 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
24826 + struct dentry *h_parent,
24827 + struct au_branch *br)
24829 + struct dentry *h_dentry;
24830 + struct mutex *h_mtx;
24832 + h_mtx = &h_parent->d_inode->i_mutex;
24833 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
24834 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
24835 + mutex_unlock(h_mtx);
24839 +static void au_call_do_plink_lkup(void *args)
24841 + struct au_do_plink_lkup_args *a = args;
24842 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
24845 +/* lookup the plink-ed @inode under the branch at @bindex */
24846 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
24848 + struct dentry *h_dentry, *h_parent;
24849 + struct au_branch *br;
24850 + struct inode *h_dir;
24852 + char a[PLINK_NAME_LEN];
24853 + struct qstr tgtname = QSTR_INIT(a, 0);
24855 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24857 + br = au_sbr(inode->i_sb, bindex);
24858 + h_parent = br->br_wbr->wbr_plink;
24859 + h_dir = h_parent->d_inode;
24860 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24862 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24863 + struct au_do_plink_lkup_args args = {
24864 + .errp = &h_dentry,
24865 + .tgtname = &tgtname,
24866 + .h_parent = h_parent,
24870 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
24871 + if (unlikely(wkq_err))
24872 + h_dentry = ERR_PTR(wkq_err);
24874 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
24879 +/* create a pseudo-link */
24880 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
24881 + struct dentry *h_dentry, struct au_branch *br)
24884 + struct path h_path = {
24885 + .mnt = au_br_mnt(br)
24887 + struct inode *h_dir, *delegated;
24889 + h_dir = h_parent->d_inode;
24890 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
24892 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
24893 + err = PTR_ERR(h_path.dentry);
24894 + if (IS_ERR(h_path.dentry))
24898 + /* wh.plink dir is not monitored */
24899 + /* todo: is it really safe? */
24900 + if (h_path.dentry->d_inode
24901 + && h_path.dentry->d_inode != h_dentry->d_inode) {
24902 + delegated = NULL;
24903 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
24904 + if (unlikely(err == -EWOULDBLOCK)) {
24905 + pr_warn("cannot retry for NFSv4 delegation"
24906 + " for an internal unlink\n");
24909 + dput(h_path.dentry);
24910 + h_path.dentry = NULL;
24914 + if (!err && !h_path.dentry->d_inode) {
24915 + delegated = NULL;
24916 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
24917 + if (unlikely(err == -EWOULDBLOCK)) {
24918 + pr_warn("cannot retry for NFSv4 delegation"
24919 + " for an internal link\n");
24923 + dput(h_path.dentry);
24926 + mutex_unlock(&h_dir->i_mutex);
24930 +struct do_whplink_args {
24932 + struct qstr *tgt;
24933 + struct dentry *h_parent;
24934 + struct dentry *h_dentry;
24935 + struct au_branch *br;
24938 +static void call_do_whplink(void *args)
24940 + struct do_whplink_args *a = args;
24941 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
24944 +static int whplink(struct dentry *h_dentry, struct inode *inode,
24945 + aufs_bindex_t bindex, struct au_branch *br)
24947 + int err, wkq_err;
24948 + struct au_wbr *wbr;
24949 + struct dentry *h_parent;
24950 + struct inode *h_dir;
24951 + char a[PLINK_NAME_LEN];
24952 + struct qstr tgtname = QSTR_INIT(a, 0);
24954 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
24955 + h_parent = wbr->wbr_plink;
24956 + h_dir = h_parent->d_inode;
24957 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24959 + /* always superio. */
24960 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24961 + struct do_whplink_args args = {
24964 + .h_parent = h_parent,
24965 + .h_dentry = h_dentry,
24968 + wkq_err = au_wkq_wait(call_do_whplink, &args);
24969 + if (unlikely(wkq_err))
24972 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
24977 +/* free a single plink */
24978 +static void do_put_plink(struct pseudo_link *plink, int do_del)
24981 + hlist_del(&plink->hlist);
24982 + iput(plink->inode);
24986 +static void do_put_plink_rcu(struct rcu_head *rcu)
24988 + struct pseudo_link *plink;
24990 + plink = container_of(rcu, struct pseudo_link, rcu);
24991 + iput(plink->inode);
24996 + * create a new pseudo-link for @h_dentry on @bindex.
24997 + * the linked inode is held in aufs @inode.
24999 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25000 + struct dentry *h_dentry)
25002 + struct super_block *sb;
25003 + struct au_sbinfo *sbinfo;
25004 + struct hlist_head *plink_hlist;
25005 + struct pseudo_link *plink, *tmp;
25006 + struct au_sphlhead *sphl;
25007 + int found, err, cnt, i;
25009 + sb = inode->i_sb;
25010 + sbinfo = au_sbi(sb);
25011 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25012 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25014 + found = au_plink_test(inode);
25018 + i = au_plink_hash(inode->i_ino);
25019 + sphl = sbinfo->si_plink + i;
25020 + plink_hlist = &sphl->head;
25021 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
25023 + tmp->inode = au_igrab(inode);
25029 + spin_lock(&sphl->spin);
25030 + hlist_for_each_entry(plink, plink_hlist, hlist) {
25031 + if (plink->inode == inode) {
25037 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
25038 + spin_unlock(&sphl->spin);
25040 + cnt = au_sphl_count(sphl);
25041 +#define msg "unexpectedly unblanced or too many pseudo-links"
25042 + if (cnt > AUFS_PLINK_WARN)
25043 + AuWarn1(msg ", %d\n", cnt);
25045 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25047 + do_put_plink(tmp, 0);
25052 + if (unlikely(err)) {
25053 + pr_warn("err %d, damaged pseudo link.\n", err);
25055 + au_sphl_del_rcu(&tmp->hlist, sphl);
25056 + call_rcu(&tmp->rcu, do_put_plink_rcu);
25061 +/* free all plinks */
25062 +void au_plink_put(struct super_block *sb, int verbose)
25065 + struct au_sbinfo *sbinfo;
25066 + struct hlist_head *plink_hlist;
25067 + struct hlist_node *tmp;
25068 + struct pseudo_link *plink;
25070 + SiMustWriteLock(sb);
25072 + sbinfo = au_sbi(sb);
25073 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25074 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25076 + /* no spin_lock since sbinfo is write-locked */
25078 + for (i = 0; i < AuPlink_NHASH; i++) {
25079 + plink_hlist = &sbinfo->si_plink[i].head;
25080 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25081 + pr_warn("pseudo-link is not flushed");
25084 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
25085 + do_put_plink(plink, 0);
25086 + INIT_HLIST_HEAD(plink_hlist);
25090 +void au_plink_clean(struct super_block *sb, int verbose)
25092 + struct dentry *root;
25094 + root = sb->s_root;
25095 + aufs_write_lock(root);
25096 + if (au_opt_test(au_mntflags(sb), PLINK))
25097 + au_plink_put(sb, verbose);
25098 + aufs_write_unlock(root);
25101 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25104 + aufs_bindex_t bstart, bend, bindex;
25107 + bstart = au_ibstart(inode);
25108 + bend = au_ibend(inode);
25109 + if (bstart >= 0) {
25110 + for (bindex = bstart; bindex <= bend; bindex++) {
25111 + if (!au_h_iptr(inode, bindex)
25112 + || au_ii_br_id(inode, bindex) != br_id)
25114 + au_set_h_iptr(inode, bindex, NULL, 0);
25119 + for (bindex = bstart; bindex <= bend; bindex++)
25120 + if (au_h_iptr(inode, bindex)) {
25130 +/* free the plinks on a branch specified by @br_id */
25131 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25133 + struct au_sbinfo *sbinfo;
25134 + struct hlist_head *plink_hlist;
25135 + struct hlist_node *tmp;
25136 + struct pseudo_link *plink;
25137 + struct inode *inode;
25140 + SiMustWriteLock(sb);
25142 + sbinfo = au_sbi(sb);
25143 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25144 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25146 + /* no spin_lock since sbinfo is write-locked */
25147 + for (i = 0; i < AuPlink_NHASH; i++) {
25148 + plink_hlist = &sbinfo->si_plink[i].head;
25149 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
25150 + inode = au_igrab(plink->inode);
25151 + ii_write_lock_child(inode);
25152 + do_put = au_plink_do_half_refresh(inode, br_id);
25154 + do_put_plink(plink, 1);
25155 + ii_write_unlock(inode);
25160 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25161 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25162 +++ linux/fs/aufs/poll.c 2015-06-22 08:29:23.710091096 +0200
25165 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25167 + * This program, aufs is free software; you can redistribute it and/or modify
25168 + * it under the terms of the GNU General Public License as published by
25169 + * the Free Software Foundation; either version 2 of the License, or
25170 + * (at your option) any later version.
25172 + * This program is distributed in the hope that it will be useful,
25173 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25174 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25175 + * GNU General Public License for more details.
25177 + * You should have received a copy of the GNU General Public License
25178 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25183 + * There is only one filesystem which implements ->poll operation, currently.
25188 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25190 + unsigned int mask;
25192 + struct file *h_file;
25193 + struct super_block *sb;
25195 + /* We should pretend an error happened. */
25196 + mask = POLLERR /* | POLLIN | POLLOUT */;
25197 + sb = file->f_path.dentry->d_sb;
25198 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25200 + h_file = au_read_pre(file, /*keep_fi*/0);
25201 + err = PTR_ERR(h_file);
25202 + if (IS_ERR(h_file))
25205 + /* it is not an error if h_file has no operation */
25206 + mask = DEFAULT_POLLMASK;
25207 + if (h_file->f_op->poll)
25208 + mask = h_file->f_op->poll(h_file, wait);
25209 + fput(h_file); /* instead of au_read_post() */
25212 + si_read_unlock(sb);
25213 + AuTraceErr((int)mask);
25216 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25217 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25218 +++ linux/fs/aufs/posix_acl.c 2015-06-22 08:27:37.887501948 +0200
25221 + * Copyright (C) 2014-2015 Junjiro R. Okajima
25223 + * This program, aufs is free software; you can redistribute it and/or modify
25224 + * it under the terms of the GNU General Public License as published by
25225 + * the Free Software Foundation; either version 2 of the License, or
25226 + * (at your option) any later version.
25228 + * This program is distributed in the hope that it will be useful,
25229 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25230 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25231 + * GNU General Public License for more details.
25233 + * You should have received a copy of the GNU General Public License
25234 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25238 + * posix acl operations
25241 +#include <linux/fs.h>
25242 +#include <linux/posix_acl.h>
25245 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25247 + struct posix_acl *acl;
25249 + aufs_bindex_t bindex;
25250 + struct inode *h_inode;
25251 + struct super_block *sb;
25254 + sb = inode->i_sb;
25255 + si_read_lock(sb, AuLock_FLUSH);
25256 + ii_read_lock_child(inode);
25257 + if (!(sb->s_flags & MS_POSIXACL))
25260 + bindex = au_ibstart(inode);
25261 + h_inode = au_h_iptr(inode, bindex);
25262 + if (unlikely(!h_inode
25263 + || ((h_inode->i_mode & S_IFMT)
25264 + != (inode->i_mode & S_IFMT)))) {
25265 + err = au_busy_or_stale();
25266 + acl = ERR_PTR(err);
25270 + /* always topmost only */
25271 + acl = get_acl(h_inode, type);
25274 + ii_read_unlock(inode);
25275 + si_read_unlock(sb);
25277 + AuTraceErrPtr(acl);
25281 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25285 + struct dentry *dentry;
25286 + struct au_srxattr arg = {
25287 + .type = AU_ACL_SET,
25294 + mutex_lock(&inode->i_mutex);
25295 + if (inode->i_ino == AUFS_ROOT_INO)
25296 + dentry = dget(inode->i_sb->s_root);
25298 + dentry = d_find_alias(inode);
25300 + dentry = d_find_any_alias(inode);
25302 + pr_warn("cannot handle this inode, "
25303 + "please report to aufs-users ML\n");
25309 + ssz = au_srxattr(dentry, &arg);
25316 + mutex_unlock(&inode->i_mutex);
25319 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
25320 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
25321 +++ linux/fs/aufs/procfs.c 2015-06-22 08:27:37.887501948 +0200
25324 + * Copyright (C) 2010-2015 Junjiro R. Okajima
25326 + * This program, aufs is free software; you can redistribute it and/or modify
25327 + * it under the terms of the GNU General Public License as published by
25328 + * the Free Software Foundation; either version 2 of the License, or
25329 + * (at your option) any later version.
25331 + * This program is distributed in the hope that it will be useful,
25332 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25333 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25334 + * GNU General Public License for more details.
25336 + * You should have received a copy of the GNU General Public License
25337 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25341 + * procfs interfaces
25344 +#include <linux/proc_fs.h>
25347 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
25349 + struct au_sbinfo *sbinfo;
25351 + sbinfo = file->private_data;
25353 + au_plink_maint_leave(sbinfo);
25354 + kobject_put(&sbinfo->si_kobj);
25360 +static void au_procfs_plm_write_clean(struct file *file)
25362 + struct au_sbinfo *sbinfo;
25364 + sbinfo = file->private_data;
25366 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
25369 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
25372 + struct super_block *sb;
25373 + struct au_sbinfo *sbinfo;
25376 + if (unlikely(file->private_data))
25380 + /* don't use au_sbilist_lock() here */
25381 + spin_lock(&au_sbilist.spin);
25382 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
25383 + if (id == sysaufs_si_id(sbinfo)) {
25384 + kobject_get(&sbinfo->si_kobj);
25385 + sb = sbinfo->si_sb;
25388 + spin_unlock(&au_sbilist.spin);
25391 + if (unlikely(!sb))
25394 + err = au_plink_maint_enter(sb);
25396 + /* keep kobject_get() */
25397 + file->private_data = sbinfo;
25399 + kobject_put(&sbinfo->si_kobj);
25405 + * Accept a valid "si=xxxx" only.
25406 + * Once it is accepted successfully, accept "clean" too.
25408 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
25409 + size_t count, loff_t *ppos)
25412 + unsigned long id;
25413 + /* last newline is allowed */
25414 + char buf[3 + sizeof(unsigned long) * 2 + 1];
25417 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25421 + if (unlikely(count > sizeof(buf)))
25424 + err = copy_from_user(buf, ubuf, count);
25425 + if (unlikely(err)) {
25432 + if (!strcmp("clean", buf)) {
25433 + au_procfs_plm_write_clean(file);
25434 + goto out_success;
25435 + } else if (unlikely(strncmp("si=", buf, 3)))
25438 + err = kstrtoul(buf + 3, 16, &id);
25439 + if (unlikely(err))
25442 + err = au_procfs_plm_write_si(file, id);
25443 + if (unlikely(err))
25447 + err = count; /* success */
25452 +static const struct file_operations au_procfs_plm_fop = {
25453 + .write = au_procfs_plm_write,
25454 + .release = au_procfs_plm_release,
25455 + .owner = THIS_MODULE
25458 +/* ---------------------------------------------------------------------- */
25460 +static struct proc_dir_entry *au_procfs_dir;
25462 +void au_procfs_fin(void)
25464 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
25465 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25468 +int __init au_procfs_init(void)
25471 + struct proc_dir_entry *entry;
25474 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
25475 + if (unlikely(!au_procfs_dir))
25478 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
25479 + au_procfs_dir, &au_procfs_plm_fop);
25480 + if (unlikely(!entry))
25484 + goto out; /* success */
25488 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25492 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
25493 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
25494 +++ linux/fs/aufs/rdu.c 2015-06-22 08:29:23.710091096 +0200
25497 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25499 + * This program, aufs is free software; you can redistribute it and/or modify
25500 + * it under the terms of the GNU General Public License as published by
25501 + * the Free Software Foundation; either version 2 of the License, or
25502 + * (at your option) any later version.
25504 + * This program is distributed in the hope that it will be useful,
25505 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25506 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25507 + * GNU General Public License for more details.
25509 + * You should have received a copy of the GNU General Public License
25510 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25514 + * readdir in userspace.
25517 +#include <linux/compat.h>
25518 +#include <linux/fs_stack.h>
25519 +#include <linux/security.h>
25522 +/* bits for struct aufs_rdu.flags */
25523 +#define AuRdu_CALLED 1
25524 +#define AuRdu_CONT (1 << 1)
25525 +#define AuRdu_FULL (1 << 2)
25526 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
25527 +#define au_fset_rdu(flags, name) \
25528 + do { (flags) |= AuRdu_##name; } while (0)
25529 +#define au_fclr_rdu(flags, name) \
25530 + do { (flags) &= ~AuRdu_##name; } while (0)
25532 +struct au_rdu_arg {
25533 + struct dir_context ctx;
25534 + struct aufs_rdu *rdu;
25535 + union au_rdu_ent_ul ent;
25536 + unsigned long end;
25538 + struct super_block *sb;
25542 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
25543 + loff_t offset, u64 h_ino, unsigned int d_type)
25546 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
25547 + struct aufs_rdu *rdu = arg->rdu;
25548 + struct au_rdu_ent ent;
25552 + au_fset_rdu(rdu->cookie.flags, CALLED);
25553 + len = au_rdu_len(nlen);
25554 + if (arg->ent.ul + len < arg->end) {
25556 + ent.bindex = rdu->cookie.bindex;
25557 + ent.type = d_type;
25559 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25560 + ent.type = DT_UNKNOWN;
25562 + /* unnecessary to support mmap_sem since this is a dir */
25564 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
25566 + if (copy_to_user(arg->ent.e->name, name, nlen))
25568 + /* the terminating NULL */
25569 + if (__put_user(0, arg->ent.e->name + nlen))
25572 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
25573 + arg->ent.ul += len;
25577 + au_fset_rdu(rdu->cookie.flags, FULL);
25579 + rdu->tail = arg->ent;
25583 + /* AuTraceErr(err); */
25587 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
25591 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
25593 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
25594 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
25596 + if (unlikely(offset != cookie->h_pos))
25602 + au_fclr_rdu(cookie->flags, CALLED);
25604 + err = vfsub_iterate_dir(h_file, &arg->ctx);
25608 + && au_ftest_rdu(cookie->flags, CALLED)
25609 + && !au_ftest_rdu(cookie->flags, FULL));
25610 + cookie->h_pos = h_file->f_pos;
25617 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
25620 + aufs_bindex_t bend;
25621 + struct au_rdu_arg arg = {
25623 + .actor = au_rdu_fill
25626 + struct dentry *dentry;
25627 + struct inode *inode;
25628 + struct file *h_file;
25629 + struct au_rdu_cookie *cookie = &rdu->cookie;
25631 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
25632 + if (unlikely(err)) {
25638 + rdu->tail = rdu->ent;
25641 + arg.ent = rdu->ent;
25642 + arg.end = arg.ent.ul;
25643 + arg.end += rdu->sz;
25646 + if (unlikely(!file->f_op->iterate))
25649 + err = security_file_permission(file, MAY_READ);
25651 + if (unlikely(err))
25654 + dentry = file->f_path.dentry;
25655 + inode = dentry->d_inode;
25657 + mutex_lock(&inode->i_mutex);
25659 + err = mutex_lock_killable(&inode->i_mutex);
25661 + if (unlikely(err))
25665 + arg.sb = inode->i_sb;
25666 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
25667 + if (unlikely(err))
25669 + err = au_alive_dir(dentry);
25670 + if (unlikely(err))
25672 + /* todo: reval? */
25673 + fi_read_lock(file);
25676 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
25677 + && cookie->generation != au_figen(file)))
25682 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
25684 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
25686 + bend = au_fbstart(file);
25687 + if (cookie->bindex < bend)
25688 + cookie->bindex = bend;
25689 + bend = au_fbend_dir(file);
25690 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
25691 + for (; !err && cookie->bindex <= bend;
25692 + cookie->bindex++, cookie->h_pos = 0) {
25693 + h_file = au_hf_dir(file, cookie->bindex);
25697 + au_fclr_rdu(cookie->flags, FULL);
25698 + err = au_rdu_do(h_file, &arg);
25700 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
25703 + AuDbg("rent %llu\n", rdu->rent);
25705 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
25706 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
25707 + au_fset_rdu(cookie->flags, CONT);
25708 + cookie->generation = au_figen(file);
25711 + ii_read_lock_child(inode);
25712 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
25713 + ii_read_unlock(inode);
25716 + fi_read_unlock(file);
25718 + si_read_unlock(arg.sb);
25720 + mutex_unlock(&inode->i_mutex);
25726 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
25730 + unsigned long long nent;
25731 + union au_rdu_ent_ul *u;
25732 + struct au_rdu_ent ent;
25733 + struct super_block *sb;
25736 + nent = rdu->nent;
25738 + sb = file->f_path.dentry->d_sb;
25739 + si_read_lock(sb, AuLock_FLUSH);
25740 + while (nent-- > 0) {
25741 + /* unnecessary to support mmap_sem since this is a dir */
25742 + err = copy_from_user(&ent, u->e, sizeof(ent));
25744 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
25745 + if (unlikely(err)) {
25751 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
25753 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
25755 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
25757 + if (unlikely(err)) {
25762 + err = __put_user(ino, &u->e->ino);
25763 + if (unlikely(err)) {
25768 + u->ul += au_rdu_len(ent.nlen);
25770 + si_read_unlock(sb);
25775 +/* ---------------------------------------------------------------------- */
25777 +static int au_rdu_verify(struct aufs_rdu *rdu)
25779 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
25780 + "%llu, b%d, 0x%x, g%u}\n",
25781 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
25783 + rdu->rent, rdu->shwh, rdu->full,
25784 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
25785 + rdu->cookie.generation);
25787 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
25791 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
25795 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25798 + struct aufs_rdu rdu;
25799 + void __user *p = (void __user *)arg;
25801 + err = copy_from_user(&rdu, p, sizeof(rdu));
25802 + if (unlikely(err)) {
25807 + err = au_rdu_verify(&rdu);
25808 + if (unlikely(err))
25812 + case AUFS_CTL_RDU:
25813 + err = au_rdu(file, &rdu);
25814 + if (unlikely(err))
25817 + e = copy_to_user(p, &rdu, sizeof(rdu));
25818 + if (unlikely(e)) {
25823 + case AUFS_CTL_RDU_INO:
25824 + err = au_rdu_ino(file, &rdu);
25828 + /* err = -ENOTTY; */
25837 +#ifdef CONFIG_COMPAT
25838 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25841 + struct aufs_rdu rdu;
25842 + void __user *p = compat_ptr(arg);
25844 + /* todo: get_user()? */
25845 + err = copy_from_user(&rdu, p, sizeof(rdu));
25846 + if (unlikely(err)) {
25851 + rdu.ent.e = compat_ptr(rdu.ent.ul);
25852 + err = au_rdu_verify(&rdu);
25853 + if (unlikely(err))
25857 + case AUFS_CTL_RDU:
25858 + err = au_rdu(file, &rdu);
25859 + if (unlikely(err))
25862 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
25863 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
25864 + e = copy_to_user(p, &rdu, sizeof(rdu));
25865 + if (unlikely(e)) {
25870 + case AUFS_CTL_RDU_INO:
25871 + err = au_rdu_ino(file, &rdu);
25875 + /* err = -ENOTTY; */
25884 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
25885 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
25886 +++ linux/fs/aufs/rwsem.h 2015-06-22 08:27:37.887501948 +0200
25889 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25891 + * This program, aufs is free software; you can redistribute it and/or modify
25892 + * it under the terms of the GNU General Public License as published by
25893 + * the Free Software Foundation; either version 2 of the License, or
25894 + * (at your option) any later version.
25896 + * This program is distributed in the hope that it will be useful,
25897 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25898 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25899 + * GNU General Public License for more details.
25901 + * You should have received a copy of the GNU General Public License
25902 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25906 + * simple read-write semaphore wrappers
25909 +#ifndef __AUFS_RWSEM_H__
25910 +#define __AUFS_RWSEM_H__
25914 +#include "debug.h"
25917 + struct rw_semaphore rwsem;
25918 +#ifdef CONFIG_AUFS_DEBUG
25919 + /* just for debugging, not almighty counter */
25920 + atomic_t rcnt, wcnt;
25924 +#ifdef CONFIG_AUFS_DEBUG
25925 +#define AuDbgCntInit(rw) do { \
25926 + atomic_set(&(rw)->rcnt, 0); \
25927 + atomic_set(&(rw)->wcnt, 0); \
25928 + smp_mb(); /* atomic set */ \
25931 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
25932 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
25933 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
25934 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
25936 +#define AuDbgCntInit(rw) do {} while (0)
25937 +#define AuDbgRcntInc(rw) do {} while (0)
25938 +#define AuDbgRcntDec(rw) do {} while (0)
25939 +#define AuDbgWcntInc(rw) do {} while (0)
25940 +#define AuDbgWcntDec(rw) do {} while (0)
25941 +#endif /* CONFIG_AUFS_DEBUG */
25943 +/* to debug easier, do not make them inlined functions */
25944 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
25945 +/* rwsem_is_locked() is unusable */
25946 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
25947 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
25948 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
25949 + && atomic_read(&(rw)->wcnt) <= 0)
25950 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
25951 + || atomic_read(&(rw)->wcnt))
25953 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
25955 +static inline void au_rw_init(struct au_rwsem *rw)
25957 + AuDbgCntInit(rw);
25958 + init_rwsem(&rw->rwsem);
25961 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
25964 + down_write(&rw->rwsem);
25965 + AuDbgWcntInc(rw);
25968 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
25969 + unsigned int lsc)
25972 + down_write_nested(&rw->rwsem, lsc);
25973 + AuDbgWcntInc(rw);
25976 +static inline void au_rw_read_lock(struct au_rwsem *rw)
25978 + down_read(&rw->rwsem);
25979 + AuDbgRcntInc(rw);
25982 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
25984 + down_read_nested(&rw->rwsem, lsc);
25985 + AuDbgRcntInc(rw);
25988 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
25990 + AuRwMustReadLock(rw);
25991 + AuDbgRcntDec(rw);
25992 + up_read(&rw->rwsem);
25995 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
25997 + AuRwMustWriteLock(rw);
25998 + AuDbgRcntInc(rw);
25999 + AuDbgWcntDec(rw);
26000 + downgrade_write(&rw->rwsem);
26003 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26005 + down_write(&rw->rwsem);
26006 + AuDbgWcntInc(rw);
26009 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26010 + unsigned int lsc)
26012 + down_write_nested(&rw->rwsem, lsc);
26013 + AuDbgWcntInc(rw);
26016 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26018 + AuRwMustWriteLock(rw);
26019 + AuDbgWcntDec(rw);
26020 + up_write(&rw->rwsem);
26023 +/* why is not _nested version defined */
26024 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26028 + ret = down_read_trylock(&rw->rwsem);
26030 + AuDbgRcntInc(rw);
26034 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26038 + ret = down_write_trylock(&rw->rwsem);
26040 + AuDbgWcntInc(rw);
26044 +#undef AuDbgCntInit
26045 +#undef AuDbgRcntInc
26046 +#undef AuDbgRcntDec
26047 +#undef AuDbgWcntInc
26048 +#undef AuDbgWcntDec
26050 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26051 +static inline void prefix##_read_lock(param) \
26052 +{ au_rw_read_lock(rwsem); } \
26053 +static inline void prefix##_write_lock(param) \
26054 +{ au_rw_write_lock(rwsem); } \
26055 +static inline int prefix##_read_trylock(param) \
26056 +{ return au_rw_read_trylock(rwsem); } \
26057 +static inline int prefix##_write_trylock(param) \
26058 +{ return au_rw_write_trylock(rwsem); }
26059 +/* why is not _nested version defined */
26060 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26061 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26062 +static inline void prefix##_write_trylock_nestd(param, lsc)
26063 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26065 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26066 +static inline void prefix##_read_unlock(param) \
26067 +{ au_rw_read_unlock(rwsem); } \
26068 +static inline void prefix##_write_unlock(param) \
26069 +{ au_rw_write_unlock(rwsem); } \
26070 +static inline void prefix##_downgrade_lock(param) \
26071 +{ au_rw_dgrade_lock(rwsem); }
26073 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26074 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26075 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26077 +#endif /* __KERNEL__ */
26078 +#endif /* __AUFS_RWSEM_H__ */
26079 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26080 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26081 +++ linux/fs/aufs/sbinfo.c 2015-06-22 08:27:37.887501948 +0200
26084 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26086 + * This program, aufs is free software; you can redistribute it and/or modify
26087 + * it under the terms of the GNU General Public License as published by
26088 + * the Free Software Foundation; either version 2 of the License, or
26089 + * (at your option) any later version.
26091 + * This program is distributed in the hope that it will be useful,
26092 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26093 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26094 + * GNU General Public License for more details.
26096 + * You should have received a copy of the GNU General Public License
26097 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26101 + * superblock private data
26107 + * they are necessary regardless sysfs is disabled.
26109 +void au_si_free(struct kobject *kobj)
26112 + struct au_sbinfo *sbinfo;
26113 + char *locked __maybe_unused; /* debug only */
26115 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26116 + for (i = 0; i < AuPlink_NHASH; i++)
26117 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26118 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
26120 + au_rw_write_lock(&sbinfo->si_rwsem);
26121 + au_br_free(sbinfo);
26122 + au_rw_write_unlock(&sbinfo->si_rwsem);
26124 + AuDebugOn(radix_tree_gang_lookup
26125 + (&sbinfo->au_si_pid.tree, (void **)&locked,
26126 + /*first_index*/PID_MAX_DEFAULT - 1,
26127 + /*max_items*/sizeof(locked)/sizeof(*locked)));
26129 + kfree(sbinfo->si_branch);
26130 + kfree(sbinfo->au_si_pid.bitmap);
26131 + mutex_destroy(&sbinfo->si_xib_mtx);
26132 + AuRwDestroy(&sbinfo->si_rwsem);
26137 +int au_si_alloc(struct super_block *sb)
26140 + struct au_sbinfo *sbinfo;
26141 + static struct lock_class_key aufs_si;
26144 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26145 + if (unlikely(!sbinfo))
26148 + BUILD_BUG_ON(sizeof(unsigned long) !=
26149 + sizeof(*sbinfo->au_si_pid.bitmap));
26150 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
26151 + sizeof(*sbinfo->au_si_pid.bitmap),
26153 + if (unlikely(!sbinfo->au_si_pid.bitmap))
26156 + /* will be reallocated separately */
26157 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26158 + if (unlikely(!sbinfo->si_branch))
26161 + err = sysaufs_si_init(sbinfo);
26162 + if (unlikely(err))
26165 + au_nwt_init(&sbinfo->si_nowait);
26166 + au_rw_init_wlock(&sbinfo->si_rwsem);
26167 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
26168 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
26169 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
26171 + atomic_long_set(&sbinfo->si_ninodes, 0);
26172 + atomic_long_set(&sbinfo->si_nfiles, 0);
26174 + sbinfo->si_bend = -1;
26175 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26177 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26178 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26179 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26180 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26182 + au_fhsm_init(sbinfo);
26184 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26186 + sbinfo->si_xino_jiffy = jiffies;
26187 + sbinfo->si_xino_expire
26188 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26189 + mutex_init(&sbinfo->si_xib_mtx);
26190 + sbinfo->si_xino_brid = -1;
26191 + /* leave si_xib_last_pindex and si_xib_next_bit */
26193 + au_sphl_init(&sbinfo->si_aopen);
26195 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26196 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26197 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26198 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26200 + for (i = 0; i < AuPlink_NHASH; i++)
26201 + au_sphl_init(sbinfo->si_plink + i);
26202 + init_waitqueue_head(&sbinfo->si_plink_wq);
26203 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26205 + au_sphl_init(&sbinfo->si_files);
26207 + /* leave other members for sysaufs and si_mnt. */
26208 + sbinfo->si_sb = sb;
26209 + sb->s_fs_info = sbinfo;
26211 + return 0; /* success */
26214 + kfree(sbinfo->si_branch);
26216 + kfree(sbinfo->au_si_pid.bitmap);
26223 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
26226 + struct au_branch **brp;
26228 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26231 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
26232 + if (unlikely(!sz))
26233 + sz = sizeof(*brp);
26234 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
26236 + sbinfo->si_branch = brp;
26243 +/* ---------------------------------------------------------------------- */
26245 +unsigned int au_sigen_inc(struct super_block *sb)
26247 + unsigned int gen;
26249 + SiMustWriteLock(sb);
26251 + gen = ++au_sbi(sb)->si_generation;
26252 + au_update_digen(sb->s_root);
26253 + au_update_iigen(sb->s_root->d_inode, /*half*/0);
26254 + sb->s_root->d_inode->i_version++;
26258 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26260 + aufs_bindex_t br_id;
26262 + struct au_sbinfo *sbinfo;
26264 + SiMustWriteLock(sb);
26266 + sbinfo = au_sbi(sb);
26267 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26268 + br_id = ++sbinfo->si_last_br_id;
26269 + AuDebugOn(br_id < 0);
26270 + if (br_id && au_br_index(sb, br_id) < 0)
26277 +/* ---------------------------------------------------------------------- */
26279 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26280 +int si_read_lock(struct super_block *sb, int flags)
26285 + if (au_ftest_lock(flags, FLUSH))
26286 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26288 + si_noflush_read_lock(sb);
26289 + err = au_plink_maint(sb, flags);
26290 + if (unlikely(err))
26291 + si_read_unlock(sb);
26296 +int si_write_lock(struct super_block *sb, int flags)
26300 + if (au_ftest_lock(flags, FLUSH))
26301 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26303 + si_noflush_write_lock(sb);
26304 + err = au_plink_maint(sb, flags);
26305 + if (unlikely(err))
26306 + si_write_unlock(sb);
26311 +/* dentry and super_block lock. call at entry point */
26312 +int aufs_read_lock(struct dentry *dentry, int flags)
26315 + struct super_block *sb;
26317 + sb = dentry->d_sb;
26318 + err = si_read_lock(sb, flags);
26319 + if (unlikely(err))
26322 + if (au_ftest_lock(flags, DW))
26323 + di_write_lock_child(dentry);
26325 + di_read_lock_child(dentry, flags);
26327 + if (au_ftest_lock(flags, GEN)) {
26328 + err = au_digen_test(dentry, au_sigen(sb));
26329 + AuDebugOn(!err && au_dbrange_test(dentry));
26330 + if (unlikely(err))
26331 + aufs_read_unlock(dentry, flags);
26338 +void aufs_read_unlock(struct dentry *dentry, int flags)
26340 + if (au_ftest_lock(flags, DW))
26341 + di_write_unlock(dentry);
26343 + di_read_unlock(dentry, flags);
26344 + si_read_unlock(dentry->d_sb);
26347 +void aufs_write_lock(struct dentry *dentry)
26349 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
26350 + di_write_lock_child(dentry);
26353 +void aufs_write_unlock(struct dentry *dentry)
26355 + di_write_unlock(dentry);
26356 + si_write_unlock(dentry->d_sb);
26359 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
26362 + unsigned int sigen;
26363 + struct super_block *sb;
26366 + err = si_read_lock(sb, flags);
26367 + if (unlikely(err))
26370 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
26372 + if (au_ftest_lock(flags, GEN)) {
26373 + sigen = au_sigen(sb);
26374 + err = au_digen_test(d1, sigen);
26375 + AuDebugOn(!err && au_dbrange_test(d1));
26377 + err = au_digen_test(d2, sigen);
26378 + AuDebugOn(!err && au_dbrange_test(d2));
26380 + if (unlikely(err))
26381 + aufs_read_and_write_unlock2(d1, d2);
26388 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
26390 + di_write_unlock2(d1, d2);
26391 + si_read_unlock(d1->d_sb);
26394 +/* ---------------------------------------------------------------------- */
26396 +int si_pid_test_slow(struct super_block *sb)
26401 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
26402 + rcu_read_unlock();
26404 + return (long)!!p;
26407 +void si_pid_set_slow(struct super_block *sb)
26410 + struct au_sbinfo *sbinfo;
26412 + AuDebugOn(si_pid_test_slow(sb));
26414 + sbinfo = au_sbi(sb);
26415 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
26417 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26418 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
26419 + /*any valid ptr*/sb);
26420 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26422 + radix_tree_preload_end();
26425 +void si_pid_clr_slow(struct super_block *sb)
26428 + struct au_sbinfo *sbinfo;
26430 + AuDebugOn(!si_pid_test_slow(sb));
26432 + sbinfo = au_sbi(sb);
26433 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26434 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
26435 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26437 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
26438 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
26439 +++ linux/fs/aufs/spl.h 2015-06-22 08:27:37.887501948 +0200
26442 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26444 + * This program, aufs is free software; you can redistribute it and/or modify
26445 + * it under the terms of the GNU General Public License as published by
26446 + * the Free Software Foundation; either version 2 of the License, or
26447 + * (at your option) any later version.
26449 + * This program is distributed in the hope that it will be useful,
26450 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26451 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26452 + * GNU General Public License for more details.
26454 + * You should have received a copy of the GNU General Public License
26455 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26459 + * simple list protected by a spinlock
26462 +#ifndef __AUFS_SPL_H__
26463 +#define __AUFS_SPL_H__
26467 +struct au_splhead {
26469 + struct list_head head;
26472 +static inline void au_spl_init(struct au_splhead *spl)
26474 + spin_lock_init(&spl->spin);
26475 + INIT_LIST_HEAD(&spl->head);
26478 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
26480 + spin_lock(&spl->spin);
26481 + list_add(list, &spl->head);
26482 + spin_unlock(&spl->spin);
26485 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
26487 + spin_lock(&spl->spin);
26489 + spin_unlock(&spl->spin);
26492 +static inline void au_spl_del_rcu(struct list_head *list,
26493 + struct au_splhead *spl)
26495 + spin_lock(&spl->spin);
26496 + list_del_rcu(list);
26497 + spin_unlock(&spl->spin);
26500 +/* ---------------------------------------------------------------------- */
26502 +struct au_sphlhead {
26504 + struct hlist_head head;
26507 +static inline void au_sphl_init(struct au_sphlhead *sphl)
26509 + spin_lock_init(&sphl->spin);
26510 + INIT_HLIST_HEAD(&sphl->head);
26513 +static inline void au_sphl_add(struct hlist_node *hlist,
26514 + struct au_sphlhead *sphl)
26516 + spin_lock(&sphl->spin);
26517 + hlist_add_head(hlist, &sphl->head);
26518 + spin_unlock(&sphl->spin);
26521 +static inline void au_sphl_del(struct hlist_node *hlist,
26522 + struct au_sphlhead *sphl)
26524 + spin_lock(&sphl->spin);
26525 + hlist_del(hlist);
26526 + spin_unlock(&sphl->spin);
26529 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
26530 + struct au_sphlhead *sphl)
26532 + spin_lock(&sphl->spin);
26533 + hlist_del_rcu(hlist);
26534 + spin_unlock(&sphl->spin);
26537 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
26539 + unsigned long cnt;
26540 + struct hlist_node *pos;
26543 + spin_lock(&sphl->spin);
26544 + hlist_for_each(pos, &sphl->head)
26546 + spin_unlock(&sphl->spin);
26550 +#endif /* __KERNEL__ */
26551 +#endif /* __AUFS_SPL_H__ */
26552 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
26553 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
26554 +++ linux/fs/aufs/super.c 2015-06-22 08:29:23.710091096 +0200
26557 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26559 + * This program, aufs is free software; you can redistribute it and/or modify
26560 + * it under the terms of the GNU General Public License as published by
26561 + * the Free Software Foundation; either version 2 of the License, or
26562 + * (at your option) any later version.
26564 + * This program is distributed in the hope that it will be useful,
26565 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26566 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26567 + * GNU General Public License for more details.
26569 + * You should have received a copy of the GNU General Public License
26570 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26574 + * mount and super_block operations
26577 +#include <linux/mm.h>
26578 +#include <linux/seq_file.h>
26579 +#include <linux/statfs.h>
26580 +#include <linux/vmalloc.h>
26584 + * super_operations
26586 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
26588 + struct au_icntnr *c;
26590 + c = au_cache_alloc_icntnr();
26592 + au_icntnr_init(c);
26593 + c->vfs_inode.i_version = 1; /* sigen(sb); */
26594 + c->iinfo.ii_hinode = NULL;
26595 + return &c->vfs_inode;
26600 +static void aufs_destroy_inode_cb(struct rcu_head *head)
26602 + struct inode *inode = container_of(head, struct inode, i_rcu);
26604 + INIT_HLIST_HEAD(&inode->i_dentry);
26605 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
26608 +static void aufs_destroy_inode(struct inode *inode)
26610 + au_iinfo_fin(inode);
26611 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
26614 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
26616 + struct inode *inode;
26619 + inode = iget_locked(sb, ino);
26620 + if (unlikely(!inode)) {
26621 + inode = ERR_PTR(-ENOMEM);
26624 + if (!(inode->i_state & I_NEW))
26627 + err = au_xigen_new(inode);
26629 + err = au_iinfo_init(inode);
26631 + inode->i_version++;
26633 + iget_failed(inode);
26634 + inode = ERR_PTR(err);
26638 + /* never return NULL */
26639 + AuDebugOn(!inode);
26640 + AuTraceErrPtr(inode);
26644 +/* lock free root dinfo */
26645 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
26648 + aufs_bindex_t bindex, bend;
26649 + struct path path;
26650 + struct au_hdentry *hdp;
26651 + struct au_branch *br;
26652 + au_br_perm_str_t perm;
26655 + bend = au_sbend(sb);
26656 + hdp = au_di(sb->s_root)->di_hdentry;
26657 + for (bindex = 0; !err && bindex <= bend; bindex++) {
26658 + br = au_sbr(sb, bindex);
26659 + path.mnt = au_br_mnt(br);
26660 + path.dentry = hdp[bindex].hd_dentry;
26661 + err = au_seq_path(seq, &path);
26663 + au_optstr_br_perm(&perm, br->br_perm);
26664 + err = seq_printf(seq, "=%s", perm.a);
26668 + if (!err && bindex != bend)
26669 + err = seq_putc(seq, ':');
26675 +static void au_show_wbr_create(struct seq_file *m, int v,
26676 + struct au_sbinfo *sbinfo)
26680 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26682 + seq_puts(m, ",create=");
26683 + pat = au_optstr_wbr_create(v);
26685 + case AuWbrCreate_TDP:
26686 + case AuWbrCreate_RR:
26687 + case AuWbrCreate_MFS:
26688 + case AuWbrCreate_PMFS:
26689 + seq_puts(m, pat);
26691 + case AuWbrCreate_MFSV:
26692 + seq_printf(m, /*pat*/"mfs:%lu",
26693 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26696 + case AuWbrCreate_PMFSV:
26697 + seq_printf(m, /*pat*/"pmfs:%lu",
26698 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26701 + case AuWbrCreate_MFSRR:
26702 + seq_printf(m, /*pat*/"mfsrr:%llu",
26703 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26705 + case AuWbrCreate_MFSRRV:
26706 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
26707 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26708 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26711 + case AuWbrCreate_PMFSRR:
26712 + seq_printf(m, /*pat*/"pmfsrr:%llu",
26713 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26715 + case AuWbrCreate_PMFSRRV:
26716 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
26717 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26718 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26724 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
26726 +#ifdef CONFIG_SYSFS
26730 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
26731 + aufs_bindex_t bindex, brid;
26732 + struct qstr *name;
26734 + struct dentry *d, *h_root;
26735 + struct au_hdentry *hdp;
26737 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26740 + f = au_sbi(sb)->si_xib;
26744 + /* stop printing the default xino path on the first writable branch */
26746 + brid = au_xino_brid(sb);
26748 + bindex = au_br_index(sb, brid);
26749 + hdp = au_di(sb->s_root)->di_hdentry;
26750 + h_root = hdp[0 + bindex].hd_dentry;
26752 + d = f->f_path.dentry;
26753 + name = &d->d_name;
26754 + /* safe ->d_parent because the file is unlinked */
26755 + if (d->d_parent == h_root
26756 + && name->len == len
26757 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
26760 + seq_puts(seq, ",xino=");
26761 + err = au_xino_path(seq, f);
26768 +/* seq_file will re-call me in case of too long string */
26769 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
26772 + unsigned int mnt_flags, v;
26773 + struct super_block *sb;
26774 + struct au_sbinfo *sbinfo;
26776 +#define AuBool(name, str) do { \
26777 + v = au_opt_test(mnt_flags, name); \
26778 + if (v != au_opt_test(AuOpt_Def, name)) \
26779 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
26782 +#define AuStr(name, str) do { \
26783 + v = mnt_flags & AuOptMask_##name; \
26784 + if (v != (AuOpt_Def & AuOptMask_##name)) \
26785 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
26788 +#define AuUInt(name, str, val) do { \
26789 + if (val != AUFS_##name##_DEF) \
26790 + seq_printf(m, "," #str "=%u", val); \
26793 + sb = dentry->d_sb;
26794 + if (sb->s_flags & MS_POSIXACL)
26795 + seq_puts(m, ",acl");
26797 + /* lock free root dinfo */
26798 + si_noflush_read_lock(sb);
26799 + sbinfo = au_sbi(sb);
26800 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
26802 + mnt_flags = au_mntflags(sb);
26803 + if (au_opt_test(mnt_flags, XINO)) {
26804 + err = au_show_xino(m, sb);
26805 + if (unlikely(err))
26808 + seq_puts(m, ",noxino");
26810 + AuBool(TRUNC_XINO, trunc_xino);
26811 + AuStr(UDBA, udba);
26812 + AuBool(SHWH, shwh);
26813 + AuBool(PLINK, plink);
26814 + AuBool(DIO, dio);
26815 + AuBool(DIRPERM1, dirperm1);
26816 + /* AuBool(REFROF, refrof); */
26818 + v = sbinfo->si_wbr_create;
26819 + if (v != AuWbrCreate_Def)
26820 + au_show_wbr_create(m, v, sbinfo);
26822 + v = sbinfo->si_wbr_copyup;
26823 + if (v != AuWbrCopyup_Def)
26824 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
26826 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
26827 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
26828 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
26830 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
26832 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
26833 + AuUInt(RDCACHE, rdcache, v);
26835 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
26836 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
26838 + au_fhsm_show(m, sbinfo);
26840 + AuBool(SUM, sum);
26841 + /* AuBool(SUM_W, wsum); */
26842 + AuBool(WARN_PERM, warn_perm);
26843 + AuBool(VERBOSE, verbose);
26846 + /* be sure to print "br:" last */
26847 + if (!sysaufs_brs) {
26848 + seq_puts(m, ",br:");
26849 + au_show_brs(m, sb);
26851 + si_read_unlock(sb);
26859 +/* ---------------------------------------------------------------------- */
26861 +/* sum mode which returns the summation for statfs(2) */
26863 +static u64 au_add_till_max(u64 a, u64 b)
26871 + return ULLONG_MAX;
26874 +static u64 au_mul_till_max(u64 a, long mul)
26882 + return ULLONG_MAX;
26885 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
26888 + long bsize, factor;
26889 + u64 blocks, bfree, bavail, files, ffree;
26890 + aufs_bindex_t bend, bindex, i;
26891 + unsigned char shared;
26892 + struct path h_path;
26893 + struct super_block *h_sb;
26896 + bsize = LONG_MAX;
26902 + bend = au_sbend(sb);
26903 + for (bindex = 0; bindex <= bend; bindex++) {
26904 + h_path.mnt = au_sbr_mnt(sb, bindex);
26905 + h_sb = h_path.mnt->mnt_sb;
26907 + for (i = 0; !shared && i < bindex; i++)
26908 + shared = (au_sbr_sb(sb, i) == h_sb);
26912 + /* sb->s_root for NFS is unreliable */
26913 + h_path.dentry = h_path.mnt->mnt_root;
26914 + err = vfs_statfs(&h_path, buf);
26915 + if (unlikely(err))
26918 + if (bsize > buf->f_bsize) {
26920 + * we will reduce bsize, so we have to expand blocks
26921 + * etc. to match them again
26923 + factor = (bsize / buf->f_bsize);
26924 + blocks = au_mul_till_max(blocks, factor);
26925 + bfree = au_mul_till_max(bfree, factor);
26926 + bavail = au_mul_till_max(bavail, factor);
26927 + bsize = buf->f_bsize;
26930 + factor = (buf->f_bsize / bsize);
26931 + blocks = au_add_till_max(blocks,
26932 + au_mul_till_max(buf->f_blocks, factor));
26933 + bfree = au_add_till_max(bfree,
26934 + au_mul_till_max(buf->f_bfree, factor));
26935 + bavail = au_add_till_max(bavail,
26936 + au_mul_till_max(buf->f_bavail, factor));
26937 + files = au_add_till_max(files, buf->f_files);
26938 + ffree = au_add_till_max(ffree, buf->f_ffree);
26941 + buf->f_bsize = bsize;
26942 + buf->f_blocks = blocks;
26943 + buf->f_bfree = bfree;
26944 + buf->f_bavail = bavail;
26945 + buf->f_files = files;
26946 + buf->f_ffree = ffree;
26947 + buf->f_frsize = 0;
26953 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
26956 + struct path h_path;
26957 + struct super_block *sb;
26959 + /* lock free root dinfo */
26960 + sb = dentry->d_sb;
26961 + si_noflush_read_lock(sb);
26962 + if (!au_opt_test(au_mntflags(sb), SUM)) {
26963 + /* sb->s_root for NFS is unreliable */
26964 + h_path.mnt = au_sbr_mnt(sb, 0);
26965 + h_path.dentry = h_path.mnt->mnt_root;
26966 + err = vfs_statfs(&h_path, buf);
26968 + err = au_statfs_sum(sb, buf);
26969 + si_read_unlock(sb);
26972 + buf->f_type = AUFS_SUPER_MAGIC;
26973 + buf->f_namelen = AUFS_MAX_NAMELEN;
26974 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
26976 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
26981 +/* ---------------------------------------------------------------------- */
26983 +static int aufs_sync_fs(struct super_block *sb, int wait)
26986 + aufs_bindex_t bend, bindex;
26987 + struct au_branch *br;
26988 + struct super_block *h_sb;
26991 + si_noflush_read_lock(sb);
26992 + bend = au_sbend(sb);
26993 + for (bindex = 0; bindex <= bend; bindex++) {
26994 + br = au_sbr(sb, bindex);
26995 + if (!au_br_writable(br->br_perm))
26998 + h_sb = au_sbr_sb(sb, bindex);
26999 + if (h_sb->s_op->sync_fs) {
27000 + e = h_sb->s_op->sync_fs(h_sb, wait);
27001 + if (unlikely(e && !err))
27003 + /* go on even if an error happens */
27006 + si_read_unlock(sb);
27011 +/* ---------------------------------------------------------------------- */
27013 +/* final actions when unmounting a file system */
27014 +static void aufs_put_super(struct super_block *sb)
27016 + struct au_sbinfo *sbinfo;
27018 + sbinfo = au_sbi(sb);
27022 + dbgaufs_si_fin(sbinfo);
27023 + kobject_put(&sbinfo->si_kobj);
27026 +/* ---------------------------------------------------------------------- */
27028 +void au_array_free(void *array)
27031 + if (!is_vmalloc_addr(array))
27038 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
27041 + unsigned long long n, sz;
27048 + if (*hint > ULLONG_MAX / sizeof(array)) {
27049 + array = ERR_PTR(-EMFILE);
27050 + pr_err("hint %llu\n", *hint);
27054 + sz = sizeof(array) * *hint;
27055 + array = kzalloc(sz, GFP_NOFS);
27056 + if (unlikely(!array))
27057 + array = vzalloc(sz);
27058 + if (unlikely(!array)) {
27059 + array = ERR_PTR(-ENOMEM);
27063 + n = cb(array, *hint, arg);
27064 + AuDebugOn(n > *hint);
27071 +static unsigned long long au_iarray_cb(void *a,
27072 + unsigned long long max __maybe_unused,
27075 + unsigned long long n;
27076 + struct inode **p, *inode;
27077 + struct list_head *head;
27082 + spin_lock(&inode_sb_list_lock);
27083 + list_for_each_entry(inode, head, i_sb_list) {
27084 + if (!is_bad_inode(inode)
27085 + && au_ii(inode)->ii_bstart >= 0) {
27086 + spin_lock(&inode->i_lock);
27087 + if (atomic_read(&inode->i_count)) {
27091 + AuDebugOn(n > max);
27093 + spin_unlock(&inode->i_lock);
27096 + spin_unlock(&inode_sb_list_lock);
27101 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27103 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
27104 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
27107 +void au_iarray_free(struct inode **a, unsigned long long max)
27109 + unsigned long long ull;
27111 + for (ull = 0; ull < max; ull++)
27113 + au_array_free(a);
27116 +/* ---------------------------------------------------------------------- */
27119 + * refresh dentry and inode at remount time.
27121 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27122 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27123 + struct dentry *parent)
27127 + di_write_lock_child(dentry);
27128 + di_read_lock_parent(parent, AuLock_IR);
27129 + err = au_refresh_dentry(dentry, parent);
27130 + if (!err && dir_flags)
27131 + au_hn_reset(dentry->d_inode, dir_flags);
27132 + di_read_unlock(parent, AuLock_IR);
27133 + di_write_unlock(dentry);
27138 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27139 + struct au_sbinfo *sbinfo,
27140 + const unsigned int dir_flags)
27143 + struct dentry *parent;
27144 + struct inode *inode;
27147 + parent = dget_parent(dentry);
27148 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27149 + inode = dentry->d_inode;
27151 + if (!S_ISDIR(inode->i_mode))
27152 + err = au_do_refresh(dentry, /*dir_flags*/0,
27155 + err = au_do_refresh(dentry, dir_flags, parent);
27156 + if (unlikely(err))
27157 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27160 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27161 + AuDbgDentry(dentry);
27169 +static int au_refresh_d(struct super_block *sb)
27171 + int err, i, j, ndentry, e;
27172 + unsigned int sigen;
27173 + struct au_dcsub_pages dpages;
27174 + struct au_dpage *dpage;
27175 + struct dentry **dentries, *d;
27176 + struct au_sbinfo *sbinfo;
27177 + struct dentry *root = sb->s_root;
27178 + const unsigned int dir_flags = au_hi_flags(root->d_inode, /*isdir*/1);
27180 + err = au_dpages_init(&dpages, GFP_NOFS);
27181 + if (unlikely(err))
27183 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27184 + if (unlikely(err))
27187 + sigen = au_sigen(sb);
27188 + sbinfo = au_sbi(sb);
27189 + for (i = 0; i < dpages.ndpage; i++) {
27190 + dpage = dpages.dpages + i;
27191 + dentries = dpage->dentries;
27192 + ndentry = dpage->ndentry;
27193 + for (j = 0; j < ndentry; j++) {
27195 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
27196 + if (unlikely(e && !err))
27198 + /* go on even err */
27203 + au_dpages_free(&dpages);
27208 +static int au_refresh_i(struct super_block *sb)
27211 + unsigned int sigen;
27212 + unsigned long long max, ull;
27213 + struct inode *inode, **array;
27215 + array = au_iarray_alloc(sb, &max);
27216 + err = PTR_ERR(array);
27217 + if (IS_ERR(array))
27221 + sigen = au_sigen(sb);
27222 + for (ull = 0; ull < max; ull++) {
27223 + inode = array[ull];
27224 + if (unlikely(!inode))
27226 + if (au_iigen(inode, NULL) != sigen) {
27227 + ii_write_lock_child(inode);
27228 + e = au_refresh_hinode_self(inode);
27229 + ii_write_unlock(inode);
27230 + if (unlikely(e)) {
27231 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27234 + /* go on even if err */
27239 + au_iarray_free(array, max);
27245 +static void au_remount_refresh(struct super_block *sb)
27248 + unsigned int udba;
27249 + aufs_bindex_t bindex, bend;
27250 + struct dentry *root;
27251 + struct inode *inode;
27252 + struct au_branch *br;
27254 + au_sigen_inc(sb);
27255 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
27257 + root = sb->s_root;
27258 + DiMustNoWaiters(root);
27259 + inode = root->d_inode;
27260 + IiMustNoWaiters(inode);
27262 + udba = au_opt_udba(sb);
27263 + bend = au_sbend(sb);
27264 + for (bindex = 0; bindex <= bend; bindex++) {
27265 + br = au_sbr(sb, bindex);
27266 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27267 + if (unlikely(err))
27268 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27270 + /* go on even if err */
27272 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27274 + di_write_unlock(root);
27275 + err = au_refresh_d(sb);
27276 + e = au_refresh_i(sb);
27277 + if (unlikely(e && !err))
27279 + /* aufs_write_lock() calls ..._child() */
27280 + di_write_lock_child(root);
27282 + au_cpup_attr_all(inode, /*force*/1);
27284 + if (unlikely(err))
27285 + AuIOErr("refresh failed, ignored, %d\n", err);
27288 +/* stop extra interpretation of errno in mount(8), and strange error messages */
27289 +static int cvt_err(int err)
27303 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
27306 + unsigned int mntflags;
27307 + struct au_opts opts;
27308 + struct dentry *root;
27309 + struct inode *inode;
27310 + struct au_sbinfo *sbinfo;
27313 + root = sb->s_root;
27314 + if (!data || !*data) {
27315 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27317 + di_write_lock_child(root);
27318 + err = au_opts_verify(sb, *flags, /*pending*/0);
27319 + aufs_write_unlock(root);
27325 + memset(&opts, 0, sizeof(opts));
27326 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27327 + if (unlikely(!opts.opt))
27329 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27330 + opts.flags = AuOpts_REMOUNT;
27331 + opts.sb_flags = *flags;
27333 + /* parse it before aufs lock */
27334 + err = au_opts_parse(sb, data, &opts);
27335 + if (unlikely(err))
27338 + sbinfo = au_sbi(sb);
27339 + inode = root->d_inode;
27340 + mutex_lock(&inode->i_mutex);
27341 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27342 + if (unlikely(err))
27344 + di_write_lock_child(root);
27346 + /* au_opts_remount() may return an error */
27347 + err = au_opts_remount(sb, &opts);
27348 + au_opts_free(&opts);
27350 + if (au_ftest_opts(opts.flags, REFRESH))
27351 + au_remount_refresh(sb);
27353 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
27354 + mntflags = au_mntflags(sb);
27355 + do_dx = !!au_opt_test(mntflags, DIO);
27356 + au_dy_arefresh(do_dx);
27359 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
27360 + aufs_write_unlock(root);
27363 + mutex_unlock(&inode->i_mutex);
27365 + free_page((unsigned long)opts.opt);
27367 + err = cvt_err(err);
27372 +static const struct super_operations aufs_sop = {
27373 + .alloc_inode = aufs_alloc_inode,
27374 + .destroy_inode = aufs_destroy_inode,
27375 + /* always deleting, no clearing */
27376 + .drop_inode = generic_delete_inode,
27377 + .show_options = aufs_show_options,
27378 + .statfs = aufs_statfs,
27379 + .put_super = aufs_put_super,
27380 + .sync_fs = aufs_sync_fs,
27381 + .remount_fs = aufs_remount_fs
27384 +/* ---------------------------------------------------------------------- */
27386 +static int alloc_root(struct super_block *sb)
27389 + struct inode *inode;
27390 + struct dentry *root;
27393 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
27394 + err = PTR_ERR(inode);
27395 + if (IS_ERR(inode))
27398 + inode->i_op = &aufs_dir_iop;
27399 + inode->i_fop = &aufs_dir_fop;
27400 + inode->i_mode = S_IFDIR;
27401 + set_nlink(inode, 2);
27402 + unlock_new_inode(inode);
27404 + root = d_make_root(inode);
27405 + if (unlikely(!root))
27407 + err = PTR_ERR(root);
27408 + if (IS_ERR(root))
27411 + err = au_di_init(root);
27413 + sb->s_root = root;
27414 + return 0; /* success */
27422 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
27423 + int silent __maybe_unused)
27426 + struct au_opts opts;
27427 + struct dentry *root;
27428 + struct inode *inode;
27429 + char *arg = raw_data;
27431 + if (unlikely(!arg || !*arg)) {
27433 + pr_err("no arg\n");
27438 + memset(&opts, 0, sizeof(opts));
27439 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27440 + if (unlikely(!opts.opt))
27442 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27443 + opts.sb_flags = sb->s_flags;
27445 + err = au_si_alloc(sb);
27446 + if (unlikely(err))
27449 + /* all timestamps always follow the ones on the branch */
27450 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
27451 + sb->s_op = &aufs_sop;
27452 + sb->s_d_op = &aufs_dop;
27453 + sb->s_magic = AUFS_SUPER_MAGIC;
27454 + sb->s_maxbytes = 0;
27455 + sb->s_stack_depth = 1;
27456 + au_export_init(sb);
27457 + /* au_xattr_init(sb); */
27459 + err = alloc_root(sb);
27460 + if (unlikely(err)) {
27461 + si_write_unlock(sb);
27464 + root = sb->s_root;
27465 + inode = root->d_inode;
27468 + * actually we can parse options regardless aufs lock here.
27469 + * but at remount time, parsing must be done before aufs lock.
27470 + * so we follow the same rule.
27472 + ii_write_lock_parent(inode);
27473 + aufs_write_unlock(root);
27474 + err = au_opts_parse(sb, arg, &opts);
27475 + if (unlikely(err))
27478 + /* lock vfs_inode first, then aufs. */
27479 + mutex_lock(&inode->i_mutex);
27480 + aufs_write_lock(root);
27481 + err = au_opts_mount(sb, &opts);
27482 + au_opts_free(&opts);
27483 + aufs_write_unlock(root);
27484 + mutex_unlock(&inode->i_mutex);
27486 + goto out_opts; /* success */
27490 + sb->s_root = NULL;
27492 + dbgaufs_si_fin(au_sbi(sb));
27493 + kobject_put(&au_sbi(sb)->si_kobj);
27494 + sb->s_fs_info = NULL;
27496 + free_page((unsigned long)opts.opt);
27499 + err = cvt_err(err);
27504 +/* ---------------------------------------------------------------------- */
27506 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
27507 + const char *dev_name __maybe_unused,
27510 + struct dentry *root;
27511 + struct super_block *sb;
27513 + /* all timestamps always follow the ones on the branch */
27514 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
27515 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
27516 + if (IS_ERR(root))
27520 + si_write_lock(sb, !AuLock_FLUSH);
27521 + sysaufs_brs_add(sb, 0);
27522 + si_write_unlock(sb);
27523 + au_sbilist_add(sb);
27529 +static void aufs_kill_sb(struct super_block *sb)
27531 + struct au_sbinfo *sbinfo;
27533 + sbinfo = au_sbi(sb);
27535 + au_sbilist_del(sb);
27536 + aufs_write_lock(sb->s_root);
27538 + if (sbinfo->si_wbr_create_ops->fin)
27539 + sbinfo->si_wbr_create_ops->fin(sb);
27540 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
27541 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
27542 + au_remount_refresh(sb);
27544 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27545 + au_plink_put(sb, /*verbose*/1);
27547 + sbinfo->si_sb = NULL;
27548 + aufs_write_unlock(sb->s_root);
27549 + au_nwt_flush(&sbinfo->si_nowait);
27551 + kill_anon_super(sb);
27554 +struct file_system_type aufs_fs_type = {
27555 + .name = AUFS_FSTYPE,
27556 + /* a race between rename and others */
27557 + .fs_flags = FS_RENAME_DOES_D_MOVE,
27558 + .mount = aufs_mount,
27559 + .kill_sb = aufs_kill_sb,
27560 + /* no need to __module_get() and module_put(). */
27561 + .owner = THIS_MODULE,
27563 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
27564 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
27565 +++ linux/fs/aufs/super.h 2015-06-22 08:27:37.887501948 +0200
27568 + * Copyright (C) 2005-2015 Junjiro R. Okajima
27570 + * This program, aufs is free software; you can redistribute it and/or modify
27571 + * it under the terms of the GNU General Public License as published by
27572 + * the Free Software Foundation; either version 2 of the License, or
27573 + * (at your option) any later version.
27575 + * This program is distributed in the hope that it will be useful,
27576 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27577 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27578 + * GNU General Public License for more details.
27580 + * You should have received a copy of the GNU General Public License
27581 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27585 + * super_block operations
27588 +#ifndef __AUFS_SUPER_H__
27589 +#define __AUFS_SUPER_H__
27593 +#include <linux/fs.h>
27594 +#include "rwsem.h"
27598 +typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
27599 +typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
27602 +/* policies to select one among multiple writable branches */
27603 +struct au_wbr_copyup_operations {
27604 + int (*copyup)(struct dentry *dentry);
27607 +#define AuWbr_DIR 1 /* target is a dir */
27608 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
27610 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
27611 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
27612 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
27614 +struct au_wbr_create_operations {
27615 + int (*create)(struct dentry *dentry, unsigned int flags);
27616 + int (*init)(struct super_block *sb);
27617 + int (*fin)(struct super_block *sb);
27620 +struct au_wbr_mfs {
27621 + struct mutex mfs_lock; /* protect this structure */
27622 + unsigned long mfs_jiffy;
27623 + unsigned long mfs_expire;
27624 + aufs_bindex_t mfs_bindex;
27626 + unsigned long long mfsrr_bytes;
27627 + unsigned long long mfsrr_watermark;
27630 +struct pseudo_link {
27632 + struct hlist_node hlist;
27633 + struct rcu_head rcu;
27635 + struct inode *inode;
27638 +#define AuPlink_NHASH 100
27639 +static inline int au_plink_hash(ino_t ino)
27641 + return ino % AuPlink_NHASH;
27644 +/* File-based Hierarchical Storage Management */
27646 +#ifdef CONFIG_AUFS_FHSM
27647 + /* allow only one process who can receive the notification */
27648 + spinlock_t fhsm_spin;
27650 + wait_queue_head_t fhsm_wqh;
27651 + atomic_t fhsm_readable;
27653 + /* these are protected by si_rwsem */
27654 + unsigned long fhsm_expire;
27655 + aufs_bindex_t fhsm_bottom;
27660 +struct au_sbinfo {
27661 + /* nowait tasks in the system-wide workqueue */
27662 + struct au_nowait_tasks si_nowait;
27665 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
27666 + * rwsem for au_sbinfo is necessary.
27668 + struct au_rwsem si_rwsem;
27670 + /* prevent recursive locking in deleting inode */
27672 + unsigned long *bitmap;
27673 + spinlock_t tree_lock;
27674 + struct radix_tree_root tree;
27678 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
27681 + atomic_long_t si_ninodes, si_nfiles;
27683 + /* branch management */
27684 + unsigned int si_generation;
27686 + /* see AuSi_ flags */
27687 + unsigned char au_si_status;
27689 + aufs_bindex_t si_bend;
27691 + /* dirty trick to keep br_id plus */
27692 + unsigned int si_last_br_id :
27693 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
27694 + struct au_branch **si_branch;
27696 + /* policy to select a writable branch */
27697 + unsigned char si_wbr_copyup;
27698 + unsigned char si_wbr_create;
27699 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
27700 + struct au_wbr_create_operations *si_wbr_create_ops;
27702 + /* round robin */
27703 + atomic_t si_wbr_rr_next;
27705 + /* most free space */
27706 + struct au_wbr_mfs si_wbr_mfs;
27708 + /* File-based Hierarchical Storage Management */
27709 + struct au_fhsm si_fhsm;
27711 + /* mount flags */
27712 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
27713 + unsigned int si_mntflags;
27715 + /* external inode number (bitmap and translation table) */
27716 + au_readf_t si_xread;
27717 + au_writef_t si_xwrite;
27718 + struct file *si_xib;
27719 + struct mutex si_xib_mtx; /* protect xib members */
27720 + unsigned long *si_xib_buf;
27721 + unsigned long si_xib_last_pindex;
27722 + int si_xib_next_bit;
27723 + aufs_bindex_t si_xino_brid;
27724 + unsigned long si_xino_jiffy;
27725 + unsigned long si_xino_expire;
27726 + /* reserved for future use */
27727 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
27729 +#ifdef CONFIG_AUFS_EXPORT
27730 + /* i_generation */
27731 + struct file *si_xigen;
27732 + atomic_t si_xigen_next;
27735 + /* dirty trick to suppoer atomic_open */
27736 + struct au_sphlhead si_aopen;
27738 + /* vdir parameters */
27739 + unsigned long si_rdcache; /* max cache time in jiffies */
27740 + unsigned int si_rdblk; /* deblk size */
27741 + unsigned int si_rdhash; /* hash size */
27744 + * If the number of whiteouts are larger than si_dirwh, leave all of
27745 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
27746 + * future fsck.aufs or kernel thread will remove them later.
27747 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
27749 + unsigned int si_dirwh;
27751 + /* pseudo_link list */
27752 + struct au_sphlhead si_plink[AuPlink_NHASH];
27753 + wait_queue_head_t si_plink_wq;
27754 + spinlock_t si_plink_maint_lock;
27755 + pid_t si_plink_maint_pid;
27758 + struct au_sphlhead si_files;
27761 + * sysfs and lifetime management.
27762 + * this is not a small structure and it may be a waste of memory in case
27763 + * of sysfs is disabled, particulary when many aufs-es are mounted.
27764 + * but using sysfs is majority.
27766 + struct kobject si_kobj;
27767 +#ifdef CONFIG_DEBUG_FS
27768 + struct dentry *si_dbgaufs;
27769 + struct dentry *si_dbgaufs_plink;
27770 + struct dentry *si_dbgaufs_xib;
27771 +#ifdef CONFIG_AUFS_EXPORT
27772 + struct dentry *si_dbgaufs_xigen;
27776 +#ifdef CONFIG_AUFS_SBILIST
27777 + struct list_head si_list;
27780 + /* dirty, necessary for unmounting, sysfs and sysrq */
27781 + struct super_block *si_sb;
27784 +/* sbinfo status flags */
27786 + * set true when refresh_dirs() failed at remount time.
27787 + * then try refreshing dirs at access time again.
27788 + * if it is false, refreshing dirs at access time is unnecesary
27790 +#define AuSi_FAILED_REFRESH_DIR 1
27792 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
27794 +#ifndef CONFIG_AUFS_FHSM
27796 +#define AuSi_FHSM 0
27799 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
27800 + unsigned int flag)
27802 + AuRwMustAnyLock(&sbi->si_rwsem);
27803 + return sbi->au_si_status & flag;
27805 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
27806 +#define au_fset_si(sbinfo, name) do { \
27807 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27808 + (sbinfo)->au_si_status |= AuSi_##name; \
27810 +#define au_fclr_si(sbinfo, name) do { \
27811 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27812 + (sbinfo)->au_si_status &= ~AuSi_##name; \
27815 +/* ---------------------------------------------------------------------- */
27817 +/* policy to select one among writable branches */
27818 +#define AuWbrCopyup(sbinfo, ...) \
27819 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
27820 +#define AuWbrCreate(sbinfo, ...) \
27821 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
27823 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
27824 +#define AuLock_DW 1 /* write-lock dentry */
27825 +#define AuLock_IR (1 << 1) /* read-lock inode */
27826 +#define AuLock_IW (1 << 2) /* write-lock inode */
27827 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
27828 +#define AuLock_DIR (1 << 4) /* target is a dir */
27829 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
27830 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
27831 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
27832 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
27833 +#define au_fset_lock(flags, name) \
27834 + do { (flags) |= AuLock_##name; } while (0)
27835 +#define au_fclr_lock(flags, name) \
27836 + do { (flags) &= ~AuLock_##name; } while (0)
27838 +/* ---------------------------------------------------------------------- */
27841 +extern struct file_system_type aufs_fs_type;
27842 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
27843 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
27845 +void au_array_free(void *array);
27846 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
27847 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
27848 +void au_iarray_free(struct inode **a, unsigned long long max);
27851 +void au_si_free(struct kobject *kobj);
27852 +int au_si_alloc(struct super_block *sb);
27853 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
27855 +unsigned int au_sigen_inc(struct super_block *sb);
27856 +aufs_bindex_t au_new_br_id(struct super_block *sb);
27858 +int si_read_lock(struct super_block *sb, int flags);
27859 +int si_write_lock(struct super_block *sb, int flags);
27860 +int aufs_read_lock(struct dentry *dentry, int flags);
27861 +void aufs_read_unlock(struct dentry *dentry, int flags);
27862 +void aufs_write_lock(struct dentry *dentry);
27863 +void aufs_write_unlock(struct dentry *dentry);
27864 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
27865 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
27867 +int si_pid_test_slow(struct super_block *sb);
27868 +void si_pid_set_slow(struct super_block *sb);
27869 +void si_pid_clr_slow(struct super_block *sb);
27871 +/* wbr_policy.c */
27872 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
27873 +extern struct au_wbr_create_operations au_wbr_create_ops[];
27874 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
27875 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
27876 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
27879 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
27881 +#ifdef CONFIG_AUFS_FHSM
27884 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
27888 + spin_lock(&fhsm->fhsm_spin);
27889 + pid = fhsm->fhsm_pid;
27890 + spin_unlock(&fhsm->fhsm_spin);
27895 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
27896 +void au_fhsm_wrote_all(struct super_block *sb, int force);
27897 +int au_fhsm_fd(struct super_block *sb, int oflags);
27898 +int au_fhsm_br_alloc(struct au_branch *br);
27899 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
27900 +void au_fhsm_fin(struct super_block *sb);
27901 +void au_fhsm_init(struct au_sbinfo *sbinfo);
27902 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
27903 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
27905 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
27907 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
27908 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
27909 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
27910 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
27911 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
27912 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
27913 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
27914 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
27915 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
27918 +/* ---------------------------------------------------------------------- */
27920 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
27922 + return sb->s_fs_info;
27925 +/* ---------------------------------------------------------------------- */
27927 +#ifdef CONFIG_AUFS_EXPORT
27928 +int au_test_nfsd(void);
27929 +void au_export_init(struct super_block *sb);
27930 +void au_xigen_inc(struct inode *inode);
27931 +int au_xigen_new(struct inode *inode);
27932 +int au_xigen_set(struct super_block *sb, struct file *base);
27933 +void au_xigen_clr(struct super_block *sb);
27935 +static inline int au_busy_or_stale(void)
27937 + if (!au_test_nfsd())
27942 +AuStubInt0(au_test_nfsd, void)
27943 +AuStubVoid(au_export_init, struct super_block *sb)
27944 +AuStubVoid(au_xigen_inc, struct inode *inode)
27945 +AuStubInt0(au_xigen_new, struct inode *inode)
27946 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
27947 +AuStubVoid(au_xigen_clr, struct super_block *sb)
27948 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
27949 +#endif /* CONFIG_AUFS_EXPORT */
27951 +/* ---------------------------------------------------------------------- */
27953 +#ifdef CONFIG_AUFS_SBILIST
27955 +extern struct au_splhead au_sbilist;
27957 +static inline void au_sbilist_init(void)
27959 + au_spl_init(&au_sbilist);
27962 +static inline void au_sbilist_add(struct super_block *sb)
27964 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
27967 +static inline void au_sbilist_del(struct super_block *sb)
27969 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
27972 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
27973 +static inline void au_sbilist_lock(void)
27975 + spin_lock(&au_sbilist.spin);
27978 +static inline void au_sbilist_unlock(void)
27980 + spin_unlock(&au_sbilist.spin);
27982 +#define AuGFP_SBILIST GFP_ATOMIC
27984 +AuStubVoid(au_sbilist_lock, void)
27985 +AuStubVoid(au_sbilist_unlock, void)
27986 +#define AuGFP_SBILIST GFP_NOFS
27987 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
27989 +AuStubVoid(au_sbilist_init, void)
27990 +AuStubVoid(au_sbilist_add, struct super_block *sb)
27991 +AuStubVoid(au_sbilist_del, struct super_block *sb)
27992 +AuStubVoid(au_sbilist_lock, void)
27993 +AuStubVoid(au_sbilist_unlock, void)
27994 +#define AuGFP_SBILIST GFP_NOFS
27997 +/* ---------------------------------------------------------------------- */
27999 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28002 + * This function is a dynamic '__init' function actually,
28003 + * so the tiny check for si_rwsem is unnecessary.
28005 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28006 +#ifdef CONFIG_DEBUG_FS
28007 + sbinfo->si_dbgaufs = NULL;
28008 + sbinfo->si_dbgaufs_plink = NULL;
28009 + sbinfo->si_dbgaufs_xib = NULL;
28010 +#ifdef CONFIG_AUFS_EXPORT
28011 + sbinfo->si_dbgaufs_xigen = NULL;
28016 +/* ---------------------------------------------------------------------- */
28018 +static inline pid_t si_pid_bit(void)
28020 + /* the origin of pid is 1, but the bitmap's is 0 */
28021 + return current->pid - 1;
28024 +static inline int si_pid_test(struct super_block *sb)
28028 + bit = si_pid_bit();
28029 + if (bit < PID_MAX_DEFAULT)
28030 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28031 + return si_pid_test_slow(sb);
28034 +static inline void si_pid_set(struct super_block *sb)
28038 + bit = si_pid_bit();
28039 + if (bit < PID_MAX_DEFAULT) {
28040 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
28041 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28044 + si_pid_set_slow(sb);
28047 +static inline void si_pid_clr(struct super_block *sb)
28051 + bit = si_pid_bit();
28052 + if (bit < PID_MAX_DEFAULT) {
28053 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
28054 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28057 + si_pid_clr_slow(sb);
28060 +/* ---------------------------------------------------------------------- */
28062 +/* lock superblock. mainly for entry point functions */
28064 + * __si_read_lock, __si_write_lock,
28065 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28067 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28069 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28070 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28071 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28073 +static inline void si_noflush_read_lock(struct super_block *sb)
28075 + __si_read_lock(sb);
28079 +static inline int si_noflush_read_trylock(struct super_block *sb)
28083 + locked = __si_read_trylock(sb);
28089 +static inline void si_noflush_write_lock(struct super_block *sb)
28091 + __si_write_lock(sb);
28095 +static inline int si_noflush_write_trylock(struct super_block *sb)
28099 + locked = __si_write_trylock(sb);
28105 +#if 0 /* reserved */
28106 +static inline int si_read_trylock(struct super_block *sb, int flags)
28108 + if (au_ftest_lock(flags, FLUSH))
28109 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28110 + return si_noflush_read_trylock(sb);
28114 +static inline void si_read_unlock(struct super_block *sb)
28117 + __si_read_unlock(sb);
28120 +#if 0 /* reserved */
28121 +static inline int si_write_trylock(struct super_block *sb, int flags)
28123 + if (au_ftest_lock(flags, FLUSH))
28124 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28125 + return si_noflush_write_trylock(sb);
28129 +static inline void si_write_unlock(struct super_block *sb)
28132 + __si_write_unlock(sb);
28135 +#if 0 /* reserved */
28136 +static inline void si_downgrade_lock(struct super_block *sb)
28138 + __si_downgrade_lock(sb);
28142 +/* ---------------------------------------------------------------------- */
28144 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
28146 + SiMustAnyLock(sb);
28147 + return au_sbi(sb)->si_bend;
28150 +static inline unsigned int au_mntflags(struct super_block *sb)
28152 + SiMustAnyLock(sb);
28153 + return au_sbi(sb)->si_mntflags;
28156 +static inline unsigned int au_sigen(struct super_block *sb)
28158 + SiMustAnyLock(sb);
28159 + return au_sbi(sb)->si_generation;
28162 +static inline void au_ninodes_inc(struct super_block *sb)
28164 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
28167 +static inline void au_ninodes_dec(struct super_block *sb)
28169 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
28170 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
28173 +static inline void au_nfiles_inc(struct super_block *sb)
28175 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
28178 +static inline void au_nfiles_dec(struct super_block *sb)
28180 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
28181 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
28184 +static inline struct au_branch *au_sbr(struct super_block *sb,
28185 + aufs_bindex_t bindex)
28187 + SiMustAnyLock(sb);
28188 + return au_sbi(sb)->si_branch[0 + bindex];
28191 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28193 + SiMustWriteLock(sb);
28194 + au_sbi(sb)->si_xino_brid = brid;
28197 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28199 + SiMustAnyLock(sb);
28200 + return au_sbi(sb)->si_xino_brid;
28203 +#endif /* __KERNEL__ */
28204 +#endif /* __AUFS_SUPER_H__ */
28205 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28206 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28207 +++ linux/fs/aufs/sysaufs.c 2015-06-22 08:27:37.887501948 +0200
28210 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28212 + * This program, aufs is free software; you can redistribute it and/or modify
28213 + * it under the terms of the GNU General Public License as published by
28214 + * the Free Software Foundation; either version 2 of the License, or
28215 + * (at your option) any later version.
28217 + * This program is distributed in the hope that it will be useful,
28218 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28219 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28220 + * GNU General Public License for more details.
28222 + * You should have received a copy of the GNU General Public License
28223 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28227 + * sysfs interface and lifetime management
28228 + * they are necessary regardless sysfs is disabled.
28231 +#include <linux/random.h>
28234 +unsigned long sysaufs_si_mask;
28235 +struct kset *sysaufs_kset;
28237 +#define AuSiAttr(_name) { \
28238 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28239 + .show = sysaufs_si_##_name, \
28242 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28243 +struct attribute *sysaufs_si_attrs[] = {
28244 + &sysaufs_si_attr_xi_path.attr,
28248 +static const struct sysfs_ops au_sbi_ops = {
28249 + .show = sysaufs_si_show
28252 +static struct kobj_type au_sbi_ktype = {
28253 + .release = au_si_free,
28254 + .sysfs_ops = &au_sbi_ops,
28255 + .default_attrs = sysaufs_si_attrs
28258 +/* ---------------------------------------------------------------------- */
28260 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28264 + sbinfo->si_kobj.kset = sysaufs_kset;
28265 + /* cf. sysaufs_name() */
28266 + err = kobject_init_and_add
28267 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28268 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28270 + dbgaufs_si_null(sbinfo);
28272 + err = dbgaufs_si_init(sbinfo);
28273 + if (unlikely(err))
28274 + kobject_put(&sbinfo->si_kobj);
28279 +void sysaufs_fin(void)
28282 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28283 + kset_unregister(sysaufs_kset);
28286 +int __init sysaufs_init(void)
28291 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
28292 + } while (!sysaufs_si_mask);
28295 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
28296 + if (unlikely(!sysaufs_kset))
28298 + err = PTR_ERR(sysaufs_kset);
28299 + if (IS_ERR(sysaufs_kset))
28301 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28302 + if (unlikely(err)) {
28303 + kset_unregister(sysaufs_kset);
28307 + err = dbgaufs_init();
28308 + if (unlikely(err))
28313 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
28314 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
28315 +++ linux/fs/aufs/sysaufs.h 2015-06-22 08:27:37.887501948 +0200
28318 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28320 + * This program, aufs is free software; you can redistribute it and/or modify
28321 + * it under the terms of the GNU General Public License as published by
28322 + * the Free Software Foundation; either version 2 of the License, or
28323 + * (at your option) any later version.
28325 + * This program is distributed in the hope that it will be useful,
28326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28328 + * GNU General Public License for more details.
28330 + * You should have received a copy of the GNU General Public License
28331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28335 + * sysfs interface and mount lifetime management
28338 +#ifndef __SYSAUFS_H__
28339 +#define __SYSAUFS_H__
28343 +#include <linux/sysfs.h>
28344 +#include "module.h"
28346 +struct super_block;
28349 +struct sysaufs_si_attr {
28350 + struct attribute attr;
28351 + int (*show)(struct seq_file *seq, struct super_block *sb);
28354 +/* ---------------------------------------------------------------------- */
28357 +extern unsigned long sysaufs_si_mask;
28358 +extern struct kset *sysaufs_kset;
28359 +extern struct attribute *sysaufs_si_attrs[];
28360 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
28361 +int __init sysaufs_init(void);
28362 +void sysaufs_fin(void);
28364 +/* ---------------------------------------------------------------------- */
28366 +/* some people doesn't like to show a pointer in kernel */
28367 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
28369 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
28372 +#define SysaufsSiNamePrefix "si_"
28373 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
28374 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
28376 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
28377 + sysaufs_si_id(sbinfo));
28381 +#ifdef CONFIG_SYSFS
28383 +extern struct attribute_group *sysaufs_attr_group;
28385 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
28386 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28388 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
28389 +#ifdef CONFIG_COMPAT
28390 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
28393 +void sysaufs_br_init(struct au_branch *br);
28394 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
28395 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
28397 +#define sysaufs_brs_init() do {} while (0)
28400 +#define sysaufs_attr_group NULL
28402 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
28403 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
28404 + struct attribute *attr, char *buf)
28405 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
28406 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
28407 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
28409 +static inline void sysaufs_brs_init(void)
28414 +#endif /* CONFIG_SYSFS */
28416 +#endif /* __KERNEL__ */
28417 +#endif /* __SYSAUFS_H__ */
28418 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
28419 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
28420 +++ linux/fs/aufs/sysfs.c 2015-06-22 08:29:23.710091096 +0200
28423 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28425 + * This program, aufs is free software; you can redistribute it and/or modify
28426 + * it under the terms of the GNU General Public License as published by
28427 + * the Free Software Foundation; either version 2 of the License, or
28428 + * (at your option) any later version.
28430 + * This program is distributed in the hope that it will be useful,
28431 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28432 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28433 + * GNU General Public License for more details.
28435 + * You should have received a copy of the GNU General Public License
28436 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28440 + * sysfs interface
28443 +#include <linux/compat.h>
28444 +#include <linux/seq_file.h>
28447 +#ifdef CONFIG_AUFS_FS_MODULE
28448 +/* this entry violates the "one line per file" policy of sysfs */
28449 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
28453 + static char *conf =
28454 +/* this file is generated at compiling */
28455 +#include "conf.str"
28458 + err = snprintf(buf, PAGE_SIZE, conf);
28459 + if (unlikely(err >= PAGE_SIZE))
28464 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
28467 +static struct attribute *au_attr[] = {
28468 +#ifdef CONFIG_AUFS_FS_MODULE
28469 + &au_config_attr.attr,
28471 + NULL, /* need to NULL terminate the list of attributes */
28474 +static struct attribute_group sysaufs_attr_group_body = {
28478 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
28480 +/* ---------------------------------------------------------------------- */
28482 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
28486 + SiMustAnyLock(sb);
28489 + if (au_opt_test(au_mntflags(sb), XINO)) {
28490 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
28491 + seq_putc(seq, '\n');
28497 + * the lifetime of branch is independent from the entry under sysfs.
28498 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
28501 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
28502 + aufs_bindex_t bindex, int idx)
28505 + struct path path;
28506 + struct dentry *root;
28507 + struct au_branch *br;
28508 + au_br_perm_str_t perm;
28510 + AuDbg("b%d\n", bindex);
28513 + root = sb->s_root;
28514 + di_read_lock_parent(root, !AuLock_IR);
28515 + br = au_sbr(sb, bindex);
28518 + case AuBrSysfs_BR:
28519 + path.mnt = au_br_mnt(br);
28520 + path.dentry = au_h_dptr(root, bindex);
28521 + au_seq_path(seq, &path);
28522 + au_optstr_br_perm(&perm, br->br_perm);
28523 + err = seq_printf(seq, "=%s\n", perm.a);
28525 + case AuBrSysfs_BRID:
28526 + err = seq_printf(seq, "%d\n", br->br_id);
28529 + di_read_unlock(root, !AuLock_IR);
28536 +/* ---------------------------------------------------------------------- */
28538 +static struct seq_file *au_seq(char *p, ssize_t len)
28540 + struct seq_file *seq;
28542 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
28544 + /* mutex_init(&seq.lock); */
28547 + return seq; /* success */
28550 + seq = ERR_PTR(-ENOMEM);
28554 +#define SysaufsBr_PREFIX "br"
28555 +#define SysaufsBrid_PREFIX "brid"
28557 +/* todo: file size may exceed PAGE_SIZE */
28558 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28564 + aufs_bindex_t bend;
28565 + struct au_sbinfo *sbinfo;
28566 + struct super_block *sb;
28567 + struct seq_file *seq;
28569 + struct attribute **cattr;
28571 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28572 + sb = sbinfo->si_sb;
28575 + * prevent a race condition between sysfs and aufs.
28576 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
28577 + * prohibits maintaining the sysfs entries.
28578 + * hew we acquire read lock after sysfs_get_active_two().
28579 + * on the other hand, the remount process may maintain the sysfs/aufs
28580 + * entries after acquiring write lock.
28581 + * it can cause a deadlock.
28582 + * simply we gave up processing read here.
28585 + if (unlikely(!si_noflush_read_trylock(sb)))
28588 + seq = au_seq(buf, PAGE_SIZE);
28589 + err = PTR_ERR(seq);
28593 + name = (void *)attr->name;
28594 + cattr = sysaufs_si_attrs;
28596 + if (!strcmp(name, (*cattr)->name)) {
28597 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
28604 + if (!strncmp(name, SysaufsBrid_PREFIX,
28605 + sizeof(SysaufsBrid_PREFIX) - 1)) {
28606 + idx = AuBrSysfs_BRID;
28607 + name += sizeof(SysaufsBrid_PREFIX) - 1;
28608 + } else if (!strncmp(name, SysaufsBr_PREFIX,
28609 + sizeof(SysaufsBr_PREFIX) - 1)) {
28610 + idx = AuBrSysfs_BR;
28611 + name += sizeof(SysaufsBr_PREFIX) - 1;
28615 + err = kstrtol(name, 10, &l);
28617 + bend = au_sbend(sb);
28619 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
28626 + err = seq->count;
28627 + /* sysfs limit */
28628 + if (unlikely(err == PAGE_SIZE))
28633 + si_read_unlock(sb);
28638 +/* ---------------------------------------------------------------------- */
28640 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
28644 + aufs_bindex_t bindex, bend;
28647 + struct seq_file *seq;
28648 + struct au_branch *br;
28650 + si_read_lock(sb, AuLock_FLUSH);
28651 + bend = au_sbend(sb);
28657 + buf = (void *)__get_free_page(GFP_NOFS);
28658 + if (unlikely(!buf))
28661 + seq = au_seq(buf, PAGE_SIZE);
28662 + err = PTR_ERR(seq);
28666 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
28667 + for (bindex = 0; bindex <= bend; bindex++, arg++) {
28668 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
28669 + if (unlikely(err))
28672 + br = au_sbr(sb, bindex);
28673 + brid = br->br_id;
28674 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
28675 + err = __put_user(brid, &arg->id);
28676 + if (unlikely(err))
28679 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
28680 + err = __put_user(br->br_perm, &arg->perm);
28681 + if (unlikely(err))
28684 + au_seq_path(seq, &br->br_path);
28685 + err = seq_putc(seq, '\0');
28686 + if (!err && seq->count <= sz) {
28687 + err = copy_to_user(arg->path, seq->buf, seq->count);
28689 + if (unlikely(err))
28696 + if (unlikely(err))
28702 + free_page((unsigned long)buf);
28704 + si_read_unlock(sb);
28708 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
28710 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
28713 +#ifdef CONFIG_COMPAT
28714 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
28716 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
28720 +/* ---------------------------------------------------------------------- */
28722 +void sysaufs_br_init(struct au_branch *br)
28725 + struct au_brsysfs *br_sysfs;
28726 + struct attribute *attr;
28728 + br_sysfs = br->br_sysfs;
28729 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28730 + attr = &br_sysfs->attr;
28731 + sysfs_attr_init(attr);
28732 + attr->name = br_sysfs->name;
28733 + attr->mode = S_IRUGO;
28738 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
28740 + struct au_branch *br;
28741 + struct kobject *kobj;
28742 + struct au_brsysfs *br_sysfs;
28744 + aufs_bindex_t bend;
28746 + dbgaufs_brs_del(sb, bindex);
28748 + if (!sysaufs_brs)
28751 + kobj = &au_sbi(sb)->si_kobj;
28752 + bend = au_sbend(sb);
28753 + for (; bindex <= bend; bindex++) {
28754 + br = au_sbr(sb, bindex);
28755 + br_sysfs = br->br_sysfs;
28756 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28757 + sysfs_remove_file(kobj, &br_sysfs->attr);
28763 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
28766 + aufs_bindex_t bend;
28767 + struct kobject *kobj;
28768 + struct au_branch *br;
28769 + struct au_brsysfs *br_sysfs;
28771 + dbgaufs_brs_add(sb, bindex);
28773 + if (!sysaufs_brs)
28776 + kobj = &au_sbi(sb)->si_kobj;
28777 + bend = au_sbend(sb);
28778 + for (; bindex <= bend; bindex++) {
28779 + br = au_sbr(sb, bindex);
28780 + br_sysfs = br->br_sysfs;
28781 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
28782 + SysaufsBr_PREFIX "%d", bindex);
28783 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
28784 + SysaufsBrid_PREFIX "%d", bindex);
28785 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28786 + err = sysfs_create_file(kobj, &br_sysfs->attr);
28787 + if (unlikely(err))
28788 + pr_warn("failed %s under sysfs(%d)\n",
28789 + br_sysfs->name, err);
28794 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
28795 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
28796 +++ linux/fs/aufs/sysrq.c 2015-06-22 08:27:37.887501948 +0200
28799 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28801 + * This program, aufs is free software; you can redistribute it and/or modify
28802 + * it under the terms of the GNU General Public License as published by
28803 + * the Free Software Foundation; either version 2 of the License, or
28804 + * (at your option) any later version.
28806 + * This program is distributed in the hope that it will be useful,
28807 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28808 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28809 + * GNU General Public License for more details.
28811 + * You should have received a copy of the GNU General Public License
28812 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28816 + * magic sysrq hanlder
28819 +/* #include <linux/sysrq.h> */
28820 +#include <linux/writeback.h>
28823 +/* ---------------------------------------------------------------------- */
28825 +static void sysrq_sb(struct super_block *sb)
28828 + struct au_sbinfo *sbinfo;
28829 + struct file *file;
28830 + struct au_sphlhead *files;
28831 + struct au_finfo *finfo;
28833 + plevel = au_plevel;
28834 + au_plevel = KERN_WARNING;
28836 + /* since we define pr_fmt, call printk directly */
28837 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
28839 + sbinfo = au_sbi(sb);
28840 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
28841 + pr("superblock\n");
28845 + pr("root dentry\n");
28846 + au_dpri_dentry(sb->s_root);
28847 + pr("root inode\n");
28848 + au_dpri_inode(sb->s_root->d_inode);
28853 + int err, i, j, ndentry;
28854 + struct au_dcsub_pages dpages;
28855 + struct au_dpage *dpage;
28857 + err = au_dpages_init(&dpages, GFP_ATOMIC);
28858 + if (unlikely(err))
28860 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
28862 + for (i = 0; i < dpages.ndpage; i++) {
28863 + dpage = dpages.dpages + i;
28864 + ndentry = dpage->ndentry;
28865 + for (j = 0; j < ndentry; j++)
28866 + au_dpri_dentry(dpage->dentries[j]);
28868 + au_dpages_free(&dpages);
28876 + pr("isolated inode\n");
28877 + spin_lock(&inode_sb_list_lock);
28878 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
28879 + spin_lock(&i->i_lock);
28880 + if (1 || hlist_empty(&i->i_dentry))
28881 + au_dpri_inode(i);
28882 + spin_unlock(&i->i_lock);
28884 + spin_unlock(&inode_sb_list_lock);
28888 + files = &au_sbi(sb)->si_files;
28889 + spin_lock(&files->spin);
28890 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
28893 + file = finfo->fi_file;
28894 + mode = file_inode(file)->i_mode;
28895 + if (!special_file(mode))
28896 + au_dpri_file(file);
28898 + spin_unlock(&files->spin);
28902 + au_plevel = plevel;
28905 +/* ---------------------------------------------------------------------- */
28907 +/* module parameter */
28908 +static char *aufs_sysrq_key = "a";
28909 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
28910 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
28912 +static void au_sysrq(int key __maybe_unused)
28914 + struct au_sbinfo *sbinfo;
28917 + au_sbilist_lock();
28918 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
28919 + sysrq_sb(sbinfo->si_sb);
28920 + au_sbilist_unlock();
28924 +static struct sysrq_key_op au_sysrq_op = {
28925 + .handler = au_sysrq,
28926 + .help_msg = "Aufs",
28927 + .action_msg = "Aufs",
28928 + .enable_mask = SYSRQ_ENABLE_DUMP
28931 +/* ---------------------------------------------------------------------- */
28933 +int __init au_sysrq_init(void)
28939 + key = *aufs_sysrq_key;
28940 + if ('a' <= key && key <= 'z')
28941 + err = register_sysrq_key(key, &au_sysrq_op);
28942 + if (unlikely(err))
28943 + pr_err("err %d, sysrq=%c\n", err, key);
28947 +void au_sysrq_fin(void)
28951 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
28952 + if (unlikely(err))
28953 + pr_err("err %d (ignored)\n", err);
28955 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
28956 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
28957 +++ linux/fs/aufs/vdir.c 2015-06-22 08:29:23.710091096 +0200
28960 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28962 + * This program, aufs is free software; you can redistribute it and/or modify
28963 + * it under the terms of the GNU General Public License as published by
28964 + * the Free Software Foundation; either version 2 of the License, or
28965 + * (at your option) any later version.
28967 + * This program is distributed in the hope that it will be useful,
28968 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28969 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28970 + * GNU General Public License for more details.
28972 + * You should have received a copy of the GNU General Public License
28973 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28977 + * virtual or vertical directory
28982 +static unsigned int calc_size(int nlen)
28984 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
28987 +static int set_deblk_end(union au_vdir_deblk_p *p,
28988 + union au_vdir_deblk_p *deblk_end)
28990 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
28991 + p->de->de_str.len = 0;
28995 + return -1; /* error */
28998 +/* returns true or false */
28999 +static int is_deblk_end(union au_vdir_deblk_p *p,
29000 + union au_vdir_deblk_p *deblk_end)
29002 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29003 + return !p->de->de_str.len;
29007 +static unsigned char *last_deblk(struct au_vdir *vdir)
29009 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29012 +/* ---------------------------------------------------------------------- */
29014 +/* estimate the apropriate size for name hash table */
29015 +unsigned int au_rdhash_est(loff_t sz)
29023 + if (sz < AUFS_RDHASH_DEF)
29024 + n = AUFS_RDHASH_DEF;
29025 + /* pr_info("n %u\n", n); */
29030 + * the allocated memory has to be freed by
29031 + * au_nhash_wh_free() or au_nhash_de_free().
29033 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29035 + struct hlist_head *head;
29039 + sz = sizeof(*nhash->nh_head) * num_hash;
29040 + head = kmalloc(sz, gfp);
29042 + nhash->nh_num = num_hash;
29043 + nhash->nh_head = head;
29044 + for (u = 0; u < num_hash; u++)
29045 + INIT_HLIST_HEAD(head++);
29046 + return 0; /* success */
29052 +static void nhash_count(struct hlist_head *head)
29056 + struct hlist_node *pos;
29059 + hlist_for_each(pos, head)
29061 + pr_info("%lu\n", n);
29065 +static void au_nhash_wh_do_free(struct hlist_head *head)
29067 + struct au_vdir_wh *pos;
29068 + struct hlist_node *node;
29070 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29074 +static void au_nhash_de_do_free(struct hlist_head *head)
29076 + struct au_vdir_dehstr *pos;
29077 + struct hlist_node *node;
29079 + hlist_for_each_entry_safe(pos, node, head, hash)
29080 + au_cache_free_vdir_dehstr(pos);
29083 +static void au_nhash_do_free(struct au_nhash *nhash,
29084 + void (*free)(struct hlist_head *head))
29087 + struct hlist_head *head;
29089 + n = nhash->nh_num;
29093 + head = nhash->nh_head;
29094 + while (n-- > 0) {
29095 + nhash_count(head);
29098 + kfree(nhash->nh_head);
29101 +void au_nhash_wh_free(struct au_nhash *whlist)
29103 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29106 +static void au_nhash_de_free(struct au_nhash *delist)
29108 + au_nhash_do_free(delist, au_nhash_de_do_free);
29111 +/* ---------------------------------------------------------------------- */
29113 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29117 + unsigned int u, n;
29118 + struct hlist_head *head;
29119 + struct au_vdir_wh *pos;
29122 + n = whlist->nh_num;
29123 + head = whlist->nh_head;
29124 + for (u = 0; u < n; u++, head++)
29125 + hlist_for_each_entry(pos, head, wh_hash)
29126 + if (pos->wh_bindex == btgt && ++num > limit)
29131 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29132 + unsigned char *name,
29133 + unsigned int len)
29136 + /* const unsigned int magic_bit = 12; */
29138 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29143 + /* v = hash_long(v, magic_bit); */
29144 + v %= nhash->nh_num;
29145 + return nhash->nh_head + v;
29148 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29151 + return str->len == nlen && !memcmp(str->name, name, nlen);
29154 +/* returns found or not */
29155 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29157 + struct hlist_head *head;
29158 + struct au_vdir_wh *pos;
29159 + struct au_vdir_destr *str;
29161 + head = au_name_hash(whlist, name, nlen);
29162 + hlist_for_each_entry(pos, head, wh_hash) {
29163 + str = &pos->wh_str;
29164 + AuDbg("%.*s\n", str->len, str->name);
29165 + if (au_nhash_test_name(str, name, nlen))
29171 +/* returns found(true) or not */
29172 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29174 + struct hlist_head *head;
29175 + struct au_vdir_dehstr *pos;
29176 + struct au_vdir_destr *str;
29178 + head = au_name_hash(delist, name, nlen);
29179 + hlist_for_each_entry(pos, head, hash) {
29181 + AuDbg("%.*s\n", str->len, str->name);
29182 + if (au_nhash_test_name(str, name, nlen))
29188 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29189 + unsigned char d_type)
29191 +#ifdef CONFIG_AUFS_SHWH
29192 + wh->wh_ino = ino;
29193 + wh->wh_type = d_type;
29197 +/* ---------------------------------------------------------------------- */
29199 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29200 + unsigned int d_type, aufs_bindex_t bindex,
29201 + unsigned char shwh)
29204 + struct au_vdir_destr *str;
29205 + struct au_vdir_wh *wh;
29207 + AuDbg("%.*s\n", nlen, name);
29208 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29211 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29212 + if (unlikely(!wh))
29216 + wh->wh_bindex = bindex;
29218 + au_shwh_init_wh(wh, ino, d_type);
29219 + str = &wh->wh_str;
29221 + memcpy(str->name, name, nlen);
29222 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29229 +static int append_deblk(struct au_vdir *vdir)
29232 + unsigned long ul;
29233 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29234 + union au_vdir_deblk_p p, deblk_end;
29235 + unsigned char **o;
29238 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29240 + if (unlikely(!o))
29243 + vdir->vd_deblk = o;
29244 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29246 + ul = vdir->vd_nblk++;
29247 + vdir->vd_deblk[ul] = p.deblk;
29248 + vdir->vd_last.ul = ul;
29249 + vdir->vd_last.p.deblk = p.deblk;
29250 + deblk_end.deblk = p.deblk + deblk_sz;
29251 + err = set_deblk_end(&p, &deblk_end);
29258 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29259 + unsigned int d_type, struct au_nhash *delist)
29263 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29264 + union au_vdir_deblk_p p, *room, deblk_end;
29265 + struct au_vdir_dehstr *dehstr;
29267 + p.deblk = last_deblk(vdir);
29268 + deblk_end.deblk = p.deblk + deblk_sz;
29269 + room = &vdir->vd_last.p;
29270 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29271 + || !is_deblk_end(room, &deblk_end));
29273 + sz = calc_size(nlen);
29274 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29275 + err = append_deblk(vdir);
29276 + if (unlikely(err))
29279 + p.deblk = last_deblk(vdir);
29280 + deblk_end.deblk = p.deblk + deblk_sz;
29282 + AuDebugOn(room->deblk != p.deblk);
29286 + dehstr = au_cache_alloc_vdir_dehstr();
29287 + if (unlikely(!dehstr))
29290 + dehstr->str = &room->de->de_str;
29291 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
29292 + room->de->de_ino = ino;
29293 + room->de->de_type = d_type;
29294 + room->de->de_str.len = nlen;
29295 + memcpy(room->de->de_str.name, name, nlen);
29298 + room->deblk += sz;
29299 + if (unlikely(set_deblk_end(room, &deblk_end)))
29300 + err = append_deblk(vdir);
29307 +/* ---------------------------------------------------------------------- */
29309 +void au_vdir_free(struct au_vdir *vdir)
29311 + unsigned char **deblk;
29313 + deblk = vdir->vd_deblk;
29314 + while (vdir->vd_nblk--)
29316 + kfree(vdir->vd_deblk);
29317 + au_cache_free_vdir(vdir);
29320 +static struct au_vdir *alloc_vdir(struct file *file)
29322 + struct au_vdir *vdir;
29323 + struct super_block *sb;
29326 + sb = file->f_path.dentry->d_sb;
29327 + SiMustAnyLock(sb);
29330 + vdir = au_cache_alloc_vdir();
29331 + if (unlikely(!vdir))
29334 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
29335 + if (unlikely(!vdir->vd_deblk))
29338 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
29339 + if (!vdir->vd_deblk_sz) {
29340 + /* estimate the apropriate size for deblk */
29341 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
29342 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
29344 + vdir->vd_nblk = 0;
29345 + vdir->vd_version = 0;
29346 + vdir->vd_jiffy = 0;
29347 + err = append_deblk(vdir);
29349 + return vdir; /* success */
29351 + kfree(vdir->vd_deblk);
29354 + au_cache_free_vdir(vdir);
29356 + vdir = ERR_PTR(err);
29360 +static int reinit_vdir(struct au_vdir *vdir)
29363 + union au_vdir_deblk_p p, deblk_end;
29365 + while (vdir->vd_nblk > 1) {
29366 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
29367 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
29370 + p.deblk = vdir->vd_deblk[0];
29371 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
29372 + err = set_deblk_end(&p, &deblk_end);
29373 + /* keep vd_dblk_sz */
29374 + vdir->vd_last.ul = 0;
29375 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29376 + vdir->vd_version = 0;
29377 + vdir->vd_jiffy = 0;
29382 +/* ---------------------------------------------------------------------- */
29384 +#define AuFillVdir_CALLED 1
29385 +#define AuFillVdir_WHABLE (1 << 1)
29386 +#define AuFillVdir_SHWH (1 << 2)
29387 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
29388 +#define au_fset_fillvdir(flags, name) \
29389 + do { (flags) |= AuFillVdir_##name; } while (0)
29390 +#define au_fclr_fillvdir(flags, name) \
29391 + do { (flags) &= ~AuFillVdir_##name; } while (0)
29393 +#ifndef CONFIG_AUFS_SHWH
29394 +#undef AuFillVdir_SHWH
29395 +#define AuFillVdir_SHWH 0
29398 +struct fillvdir_arg {
29399 + struct dir_context ctx;
29400 + struct file *file;
29401 + struct au_vdir *vdir;
29402 + struct au_nhash delist;
29403 + struct au_nhash whlist;
29404 + aufs_bindex_t bindex;
29405 + unsigned int flags;
29409 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
29410 + loff_t offset __maybe_unused, u64 h_ino,
29411 + unsigned int d_type)
29413 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
29414 + char *name = (void *)__name;
29415 + struct super_block *sb;
29417 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
29420 + sb = arg->file->f_path.dentry->d_sb;
29421 + au_fset_fillvdir(arg->flags, CALLED);
29423 + if (nlen <= AUFS_WH_PFX_LEN
29424 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
29425 + if (test_known(&arg->delist, name, nlen)
29426 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
29427 + goto out; /* already exists or whiteouted */
29429 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
29431 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29432 + d_type = DT_UNKNOWN;
29433 + arg->err = append_de(arg->vdir, name, nlen, ino,
29434 + d_type, &arg->delist);
29436 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
29437 + name += AUFS_WH_PFX_LEN;
29438 + nlen -= AUFS_WH_PFX_LEN;
29439 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
29440 + goto out; /* already whiteouted */
29443 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
29446 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
29447 + d_type = DT_UNKNOWN;
29448 + arg->err = au_nhash_append_wh
29449 + (&arg->whlist, name, nlen, ino, d_type,
29450 + arg->bindex, shwh);
29456 + arg->vdir->vd_jiffy = jiffies;
29458 + AuTraceErr(arg->err);
29462 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
29463 + struct au_nhash *whlist, struct au_nhash *delist)
29465 +#ifdef CONFIG_AUFS_SHWH
29467 + unsigned int nh, u;
29468 + struct hlist_head *head;
29469 + struct au_vdir_wh *pos;
29470 + struct hlist_node *n;
29472 + struct au_vdir_destr *destr;
29474 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
29477 + o = p = (void *)__get_free_page(GFP_NOFS);
29478 + if (unlikely(!p))
29482 + nh = whlist->nh_num;
29483 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29484 + p += AUFS_WH_PFX_LEN;
29485 + for (u = 0; u < nh; u++) {
29486 + head = whlist->nh_head + u;
29487 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
29488 + destr = &pos->wh_str;
29489 + memcpy(p, destr->name, destr->len);
29490 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
29491 + pos->wh_ino, pos->wh_type, delist);
29492 + if (unlikely(err))
29497 + free_page((unsigned long)o);
29507 +static int au_do_read_vdir(struct fillvdir_arg *arg)
29510 + unsigned int rdhash;
29512 + aufs_bindex_t bend, bindex, bstart;
29513 + unsigned char shwh;
29514 + struct file *hf, *file;
29515 + struct super_block *sb;
29517 + file = arg->file;
29518 + sb = file->f_path.dentry->d_sb;
29519 + SiMustAnyLock(sb);
29521 + rdhash = au_sbi(sb)->si_rdhash;
29523 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
29524 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
29525 + if (unlikely(err))
29527 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
29528 + if (unlikely(err))
29534 + if (au_opt_test(au_mntflags(sb), SHWH)) {
29536 + au_fset_fillvdir(arg->flags, SHWH);
29538 + bstart = au_fbstart(file);
29539 + bend = au_fbend_dir(file);
29540 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
29541 + hf = au_hf_dir(file, bindex);
29545 + offset = vfsub_llseek(hf, 0, SEEK_SET);
29547 + if (unlikely(offset))
29550 + arg->bindex = bindex;
29551 + au_fclr_fillvdir(arg->flags, WHABLE);
29553 + || (bindex != bend
29554 + && au_br_whable(au_sbr_perm(sb, bindex))))
29555 + au_fset_fillvdir(arg->flags, WHABLE);
29558 + au_fclr_fillvdir(arg->flags, CALLED);
29560 + err = vfsub_iterate_dir(hf, &arg->ctx);
29563 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
29566 + * dir_relax() may be good for concurrency, but aufs should not
29567 + * use it since it will cause a lockdep problem.
29571 + if (!err && shwh)
29572 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
29574 + au_nhash_wh_free(&arg->whlist);
29577 + au_nhash_de_free(&arg->delist);
29582 +static int read_vdir(struct file *file, int may_read)
29585 + unsigned long expire;
29586 + unsigned char do_read;
29587 + struct fillvdir_arg arg = {
29589 + .actor = fillvdir
29592 + struct inode *inode;
29593 + struct au_vdir *vdir, *allocated;
29596 + inode = file_inode(file);
29597 + IMustLock(inode);
29598 + SiMustAnyLock(inode->i_sb);
29600 + allocated = NULL;
29602 + expire = au_sbi(inode->i_sb)->si_rdcache;
29603 + vdir = au_ivdir(inode);
29606 + vdir = alloc_vdir(file);
29607 + err = PTR_ERR(vdir);
29608 + if (IS_ERR(vdir))
29611 + allocated = vdir;
29612 + } else if (may_read
29613 + && (inode->i_version != vdir->vd_version
29614 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
29616 + err = reinit_vdir(vdir);
29617 + if (unlikely(err))
29622 + return 0; /* success */
29626 + err = au_do_read_vdir(&arg);
29628 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
29629 + vdir->vd_version = inode->i_version;
29630 + vdir->vd_last.ul = 0;
29631 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29633 + au_set_ivdir(inode, allocated);
29634 + } else if (allocated)
29635 + au_vdir_free(allocated);
29641 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
29644 + unsigned long ul, n;
29645 + const unsigned int deblk_sz = src->vd_deblk_sz;
29647 + AuDebugOn(tgt->vd_nblk != 1);
29650 + if (tgt->vd_nblk < src->vd_nblk) {
29651 + unsigned char **p;
29653 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
29655 + if (unlikely(!p))
29657 + tgt->vd_deblk = p;
29660 + if (tgt->vd_deblk_sz != deblk_sz) {
29661 + unsigned char *p;
29663 + tgt->vd_deblk_sz = deblk_sz;
29664 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
29665 + if (unlikely(!p))
29667 + tgt->vd_deblk[0] = p;
29669 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
29670 + tgt->vd_version = src->vd_version;
29671 + tgt->vd_jiffy = src->vd_jiffy;
29673 + n = src->vd_nblk;
29674 + for (ul = 1; ul < n; ul++) {
29675 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
29677 + if (unlikely(!tgt->vd_deblk[ul]))
29681 + tgt->vd_nblk = n;
29682 + tgt->vd_last.ul = tgt->vd_last.ul;
29683 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
29684 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
29685 + - src->vd_deblk[src->vd_last.ul];
29687 + return 0; /* success */
29690 + rerr = reinit_vdir(tgt);
29695 +int au_vdir_init(struct file *file)
29698 + struct inode *inode;
29699 + struct au_vdir *vdir_cache, *allocated;
29701 + /* test file->f_pos here instead of ctx->pos */
29702 + err = read_vdir(file, !file->f_pos);
29703 + if (unlikely(err))
29706 + allocated = NULL;
29707 + vdir_cache = au_fvdir_cache(file);
29708 + if (!vdir_cache) {
29709 + vdir_cache = alloc_vdir(file);
29710 + err = PTR_ERR(vdir_cache);
29711 + if (IS_ERR(vdir_cache))
29713 + allocated = vdir_cache;
29714 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
29715 + /* test file->f_pos here instead of ctx->pos */
29716 + err = reinit_vdir(vdir_cache);
29717 + if (unlikely(err))
29720 + return 0; /* success */
29722 + inode = file_inode(file);
29723 + err = copy_vdir(vdir_cache, au_ivdir(inode));
29725 + file->f_version = inode->i_version;
29727 + au_set_fvdir_cache(file, allocated);
29728 + } else if (allocated)
29729 + au_vdir_free(allocated);
29735 +static loff_t calc_offset(struct au_vdir *vdir)
29738 + union au_vdir_deblk_p p;
29740 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
29741 + offset = vdir->vd_last.p.deblk - p.deblk;
29742 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
29746 +/* returns true or false */
29747 +static int seek_vdir(struct file *file, struct dir_context *ctx)
29750 + unsigned int deblk_sz;
29751 + unsigned long ul, n;
29753 + union au_vdir_deblk_p p, deblk_end;
29754 + struct au_vdir *vdir_cache;
29757 + vdir_cache = au_fvdir_cache(file);
29758 + offset = calc_offset(vdir_cache);
29759 + AuDbg("offset %lld\n", offset);
29760 + if (ctx->pos == offset)
29763 + vdir_cache->vd_last.ul = 0;
29764 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
29769 + deblk_sz = vdir_cache->vd_deblk_sz;
29770 + ul = div64_u64(ctx->pos, deblk_sz);
29771 + AuDbg("ul %lu\n", ul);
29772 + if (ul >= vdir_cache->vd_nblk)
29775 + n = vdir_cache->vd_nblk;
29776 + for (; ul < n; ul++) {
29777 + p.deblk = vdir_cache->vd_deblk[ul];
29778 + deblk_end.deblk = p.deblk + deblk_sz;
29780 + offset *= deblk_sz;
29781 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
29784 + l = calc_size(p.de->de_str.len);
29788 + if (!is_deblk_end(&p, &deblk_end)) {
29790 + vdir_cache->vd_last.ul = ul;
29791 + vdir_cache->vd_last.p = p;
29798 + AuTraceErr(!valid);
29802 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
29804 + unsigned int l, deblk_sz;
29805 + union au_vdir_deblk_p deblk_end;
29806 + struct au_vdir *vdir_cache;
29807 + struct au_vdir_de *de;
29809 + vdir_cache = au_fvdir_cache(file);
29810 + if (!seek_vdir(file, ctx))
29813 + deblk_sz = vdir_cache->vd_deblk_sz;
29815 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29816 + deblk_end.deblk += deblk_sz;
29817 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
29818 + de = vdir_cache->vd_last.p.de;
29819 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
29820 + de->de_str.len, de->de_str.name, ctx->pos,
29821 + (unsigned long)de->de_ino, de->de_type);
29822 + if (unlikely(!dir_emit(ctx, de->de_str.name,
29823 + de->de_str.len, de->de_ino,
29825 + /* todo: ignore the error caused by udba? */
29826 + /* return err; */
29830 + l = calc_size(de->de_str.len);
29831 + vdir_cache->vd_last.p.deblk += l;
29834 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
29835 + vdir_cache->vd_last.ul++;
29836 + vdir_cache->vd_last.p.deblk
29837 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29838 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
29847 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
29848 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
29849 +++ linux/fs/aufs/vfsub.c 2015-06-22 08:29:23.710091096 +0200
29852 + * Copyright (C) 2005-2015 Junjiro R. Okajima
29854 + * This program, aufs is free software; you can redistribute it and/or modify
29855 + * it under the terms of the GNU General Public License as published by
29856 + * the Free Software Foundation; either version 2 of the License, or
29857 + * (at your option) any later version.
29859 + * This program is distributed in the hope that it will be useful,
29860 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29861 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29862 + * GNU General Public License for more details.
29864 + * You should have received a copy of the GNU General Public License
29865 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29869 + * sub-routines for VFS
29872 +#include <linux/namei.h>
29873 +#include <linux/security.h>
29874 +#include <linux/splice.h>
29877 +int vfsub_update_h_iattr(struct path *h_path, int *did)
29881 + struct super_block *h_sb;
29883 + /* for remote fs, leave work for its getattr or d_revalidate */
29884 + /* for bad i_attr fs, handle them in aufs_getattr() */
29885 + /* still some fs may acquire i_mutex. we need to skip them */
29889 + h_sb = h_path->dentry->d_sb;
29890 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
29892 + err = vfs_getattr(h_path, &st);
29897 +/* ---------------------------------------------------------------------- */
29899 +struct file *vfsub_dentry_open(struct path *path, int flags)
29901 + struct file *file;
29903 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
29905 + if (!IS_ERR_OR_NULL(file)
29906 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
29907 + i_readcount_inc(path->dentry->d_inode);
29912 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
29914 + struct file *file;
29917 + file = filp_open(path,
29918 + oflags /* | __FMODE_NONOTIFY */,
29921 + if (IS_ERR(file))
29923 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29930 + * Ideally this function should call VFS:do_last() in order to keep all its
29931 + * checkings. But it is very hard for aufs to regenerate several VFS internal
29932 + * structure such as nameidata. This is a second (or third) best approach.
29933 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
29935 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
29936 + struct vfsub_aopen_args *args, struct au_branch *br)
29939 + struct file *file = args->file;
29940 + /* copied from linux/fs/namei.c:atomic_open() */
29941 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
29944 + AuDebugOn(!dir->i_op->atomic_open);
29946 + err = au_br_test_oflag(args->open_flag, br);
29947 + if (unlikely(err))
29950 + args->file->f_path.dentry = DENTRY_NOT_SET;
29951 + args->file->f_path.mnt = au_br_mnt(br);
29952 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
29953 + args->create_mode, args->opened);
29955 + /* some filesystems don't set FILE_CREATED while succeeded? */
29956 + if (*args->opened & FILE_CREATED)
29957 + fsnotify_create(dir, dentry);
29963 + /* todo: call VFS:may_open() here */
29964 + err = open_check_o_direct(file);
29965 + /* todo: ima_file_check() too? */
29966 + if (!err && (args->open_flag & __FMODE_EXEC))
29967 + err = deny_write_access(file);
29968 + if (unlikely(err))
29969 + /* note that the file is created and still opened */
29973 + atomic_inc(&br->br_count);
29974 + fsnotify_open(file);
29980 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
29984 + err = kern_path(name, flags, path);
29985 + if (!err && path->dentry->d_inode)
29986 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
29990 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
29993 + struct path path = {
29997 + /* VFS checks it too, but by WARN_ON_ONCE() */
29998 + IMustLock(parent->d_inode);
30000 + path.dentry = lookup_one_len(name, parent, len);
30001 + if (IS_ERR(path.dentry))
30003 + if (path.dentry->d_inode)
30004 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30007 + AuTraceErrPtr(path.dentry);
30008 + return path.dentry;
30011 +void vfsub_call_lkup_one(void *args)
30013 + struct vfsub_lkup_one_args *a = args;
30014 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30017 +/* ---------------------------------------------------------------------- */
30019 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30020 + struct dentry *d2, struct au_hinode *hdir2)
30022 + struct dentry *d;
30025 + d = lock_rename(d1, d2);
30027 + au_hn_suspend(hdir1);
30028 + if (hdir1 != hdir2)
30029 + au_hn_suspend(hdir2);
30034 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30035 + struct dentry *d2, struct au_hinode *hdir2)
30037 + au_hn_resume(hdir1);
30038 + if (hdir1 != hdir2)
30039 + au_hn_resume(hdir2);
30041 + unlock_rename(d1, d2);
30045 +/* ---------------------------------------------------------------------- */
30047 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30050 + struct dentry *d;
30054 + d = path->dentry;
30055 + path->dentry = d->d_parent;
30056 + err = security_path_mknod(path, d, mode, 0);
30057 + path->dentry = d;
30058 + if (unlikely(err))
30062 + err = vfs_create(dir, path->dentry, mode, want_excl);
30065 + struct path tmp = *path;
30068 + vfsub_update_h_iattr(&tmp, &did);
30070 + tmp.dentry = path->dentry->d_parent;
30071 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30080 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30083 + struct dentry *d;
30087 + d = path->dentry;
30088 + path->dentry = d->d_parent;
30089 + err = security_path_symlink(path, d, symname);
30090 + path->dentry = d;
30091 + if (unlikely(err))
30095 + err = vfs_symlink(dir, path->dentry, symname);
30098 + struct path tmp = *path;
30101 + vfsub_update_h_iattr(&tmp, &did);
30103 + tmp.dentry = path->dentry->d_parent;
30104 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30113 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30116 + struct dentry *d;
30120 + d = path->dentry;
30121 + path->dentry = d->d_parent;
30122 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30123 + path->dentry = d;
30124 + if (unlikely(err))
30128 + err = vfs_mknod(dir, path->dentry, mode, dev);
30131 + struct path tmp = *path;
30134 + vfsub_update_h_iattr(&tmp, &did);
30136 + tmp.dentry = path->dentry->d_parent;
30137 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30146 +static int au_test_nlink(struct inode *inode)
30148 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30150 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30151 + || inode->i_nlink < link_max)
30156 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30157 + struct inode **delegated_inode)
30160 + struct dentry *d;
30164 + err = au_test_nlink(src_dentry->d_inode);
30165 + if (unlikely(err))
30168 + /* we don't call may_linkat() */
30169 + d = path->dentry;
30170 + path->dentry = d->d_parent;
30171 + err = security_path_link(src_dentry, path, d);
30172 + path->dentry = d;
30173 + if (unlikely(err))
30177 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30180 + struct path tmp = *path;
30183 + /* fuse has different memory inode for the same inumber */
30184 + vfsub_update_h_iattr(&tmp, &did);
30186 + tmp.dentry = path->dentry->d_parent;
30187 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30188 + tmp.dentry = src_dentry;
30189 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30198 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30199 + struct inode *dir, struct path *path,
30200 + struct inode **delegated_inode)
30203 + struct path tmp = {
30206 + struct dentry *d;
30209 + IMustLock(src_dir);
30211 + d = path->dentry;
30212 + path->dentry = d->d_parent;
30213 + tmp.dentry = src_dentry->d_parent;
30214 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30215 + path->dentry = d;
30216 + if (unlikely(err))
30220 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30221 + delegated_inode, /*flags*/0);
30226 + tmp.dentry = d->d_parent;
30227 + vfsub_update_h_iattr(&tmp, &did);
30229 + tmp.dentry = src_dentry;
30230 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30231 + tmp.dentry = src_dentry->d_parent;
30232 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30241 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
30244 + struct dentry *d;
30248 + d = path->dentry;
30249 + path->dentry = d->d_parent;
30250 + err = security_path_mkdir(path, d, mode);
30251 + path->dentry = d;
30252 + if (unlikely(err))
30256 + err = vfs_mkdir(dir, path->dentry, mode);
30259 + struct path tmp = *path;
30262 + vfsub_update_h_iattr(&tmp, &did);
30264 + tmp.dentry = path->dentry->d_parent;
30265 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30274 +int vfsub_rmdir(struct inode *dir, struct path *path)
30277 + struct dentry *d;
30281 + d = path->dentry;
30282 + path->dentry = d->d_parent;
30283 + err = security_path_rmdir(path, d);
30284 + path->dentry = d;
30285 + if (unlikely(err))
30289 + err = vfs_rmdir(dir, path->dentry);
30292 + struct path tmp = {
30293 + .dentry = path->dentry->d_parent,
30297 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30304 +/* ---------------------------------------------------------------------- */
30306 +/* todo: support mmap_sem? */
30307 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30313 + err = vfs_read(file, ubuf, count, ppos);
30316 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30320 +/* todo: kernel_read()? */
30321 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30325 + mm_segment_t oldfs;
30332 + oldfs = get_fs();
30333 + set_fs(KERNEL_DS);
30334 + err = vfsub_read_u(file, buf.u, count, ppos);
30339 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30345 + err = vfs_write(file, ubuf, count, ppos);
30348 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30352 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
30355 + mm_segment_t oldfs;
30358 + const char __user *u;
30362 + oldfs = get_fs();
30363 + set_fs(KERNEL_DS);
30364 + err = vfsub_write_u(file, buf.u, count, ppos);
30369 +int vfsub_flush(struct file *file, fl_owner_t id)
30374 + if (file->f_op->flush) {
30375 + if (!au_test_nfs(file->f_path.dentry->d_sb))
30376 + err = file->f_op->flush(file, id);
30379 + err = file->f_op->flush(file, id);
30383 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
30389 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
30393 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
30396 + err = iterate_dir(file, ctx);
30399 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30403 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30404 + struct pipe_inode_info *pipe, size_t len,
30405 + unsigned int flags)
30410 + err = do_splice_to(in, ppos, pipe, len, flags);
30412 + file_accessed(in);
30414 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
30418 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30419 + loff_t *ppos, size_t len, unsigned int flags)
30424 + err = do_splice_from(pipe, out, ppos, len, flags);
30427 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
30431 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
30435 + /* file can be NULL */
30437 + err = vfs_fsync(file, datasync);
30441 + AuDebugOn(!file);
30442 + path = &file->f_path;
30444 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30449 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
30450 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30451 + struct file *h_file)
30454 + struct inode *h_inode;
30455 + struct super_block *h_sb;
30458 + err = vfsub_truncate(h_path, length);
30462 + h_inode = h_path->dentry->d_inode;
30463 + h_sb = h_inode->i_sb;
30465 + sb_start_write(h_sb);
30467 + err = locks_verify_truncate(h_inode, h_file, length);
30469 + err = security_path_truncate(h_path);
30472 + err = do_truncate(h_path->dentry, length, attr, h_file);
30476 + sb_end_write(h_sb);
30483 +/* ---------------------------------------------------------------------- */
30485 +struct au_vfsub_mkdir_args {
30487 + struct inode *dir;
30488 + struct path *path;
30492 +static void au_call_vfsub_mkdir(void *args)
30494 + struct au_vfsub_mkdir_args *a = args;
30495 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
30498 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
30500 + int err, do_sio, wkq_err;
30502 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30505 + err = vfsub_mkdir(dir, path, mode);
30508 + struct au_vfsub_mkdir_args args = {
30514 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
30515 + if (unlikely(wkq_err))
30522 +struct au_vfsub_rmdir_args {
30524 + struct inode *dir;
30525 + struct path *path;
30528 +static void au_call_vfsub_rmdir(void *args)
30530 + struct au_vfsub_rmdir_args *a = args;
30531 + *a->errp = vfsub_rmdir(a->dir, a->path);
30534 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
30536 + int err, do_sio, wkq_err;
30538 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30541 + err = vfsub_rmdir(dir, path);
30544 + struct au_vfsub_rmdir_args args = {
30549 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
30550 + if (unlikely(wkq_err))
30557 +/* ---------------------------------------------------------------------- */
30559 +struct notify_change_args {
30561 + struct path *path;
30562 + struct iattr *ia;
30563 + struct inode **delegated_inode;
30566 +static void call_notify_change(void *args)
30568 + struct notify_change_args *a = args;
30569 + struct inode *h_inode;
30571 + h_inode = a->path->dentry->d_inode;
30572 + IMustLock(h_inode);
30574 + *a->errp = -EPERM;
30575 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
30577 + *a->errp = notify_change(a->path->dentry, a->ia,
30578 + a->delegated_inode);
30581 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
30583 + AuTraceErr(*a->errp);
30586 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30587 + struct inode **delegated_inode)
30590 + struct notify_change_args args = {
30594 + .delegated_inode = delegated_inode
30597 + call_notify_change(&args);
30602 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30603 + struct inode **delegated_inode)
30605 + int err, wkq_err;
30606 + struct notify_change_args args = {
30610 + .delegated_inode = delegated_inode
30613 + wkq_err = au_wkq_wait(call_notify_change, &args);
30614 + if (unlikely(wkq_err))
30620 +/* ---------------------------------------------------------------------- */
30622 +struct unlink_args {
30624 + struct inode *dir;
30625 + struct path *path;
30626 + struct inode **delegated_inode;
30629 +static void call_unlink(void *args)
30631 + struct unlink_args *a = args;
30632 + struct dentry *d = a->path->dentry;
30633 + struct inode *h_inode;
30634 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
30635 + && au_dcount(d) == 1);
30637 + IMustLock(a->dir);
30639 + a->path->dentry = d->d_parent;
30640 + *a->errp = security_path_unlink(a->path, d);
30641 + a->path->dentry = d;
30642 + if (unlikely(*a->errp))
30645 + if (!stop_sillyrename)
30647 + h_inode = d->d_inode;
30652 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
30655 + struct path tmp = {
30656 + .dentry = d->d_parent,
30657 + .mnt = a->path->mnt
30659 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30662 + if (!stop_sillyrename)
30667 + AuTraceErr(*a->errp);
30671 + * @dir: must be locked.
30672 + * @dentry: target dentry.
30674 +int vfsub_unlink(struct inode *dir, struct path *path,
30675 + struct inode **delegated_inode, int force)
30678 + struct unlink_args args = {
30682 + .delegated_inode = delegated_inode
30686 + call_unlink(&args);
30690 + wkq_err = au_wkq_wait(call_unlink, &args);
30691 + if (unlikely(wkq_err))
30697 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
30698 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
30699 +++ linux/fs/aufs/vfsub.h 2015-06-22 08:29:23.710091096 +0200
30702 + * Copyright (C) 2005-2015 Junjiro R. Okajima
30704 + * This program, aufs is free software; you can redistribute it and/or modify
30705 + * it under the terms of the GNU General Public License as published by
30706 + * the Free Software Foundation; either version 2 of the License, or
30707 + * (at your option) any later version.
30709 + * This program is distributed in the hope that it will be useful,
30710 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30711 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30712 + * GNU General Public License for more details.
30714 + * You should have received a copy of the GNU General Public License
30715 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30719 + * sub-routines for VFS
30722 +#ifndef __AUFS_VFSUB_H__
30723 +#define __AUFS_VFSUB_H__
30727 +#include <linux/fs.h>
30728 +#include <linux/mount.h>
30729 +#include <linux/xattr.h>
30730 +#include "debug.h"
30732 +/* copied from linux/fs/internal.h */
30733 +/* todo: BAD approach!! */
30734 +extern void __mnt_drop_write(struct vfsmount *);
30735 +extern spinlock_t inode_sb_list_lock;
30736 +extern int open_check_o_direct(struct file *f);
30738 +/* ---------------------------------------------------------------------- */
30740 +/* lock subclass for lower inode */
30741 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
30742 +/* reduce? gave up. */
30744 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
30745 + AuLsc_I_PARENT, /* lower inode, parent first */
30746 + AuLsc_I_PARENT2, /* copyup dirs */
30747 + AuLsc_I_PARENT3, /* copyup wh */
30753 +/* to debug easier, do not make them inlined functions */
30754 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
30755 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
30757 +/* ---------------------------------------------------------------------- */
30759 +static inline void vfsub_drop_nlink(struct inode *inode)
30761 + AuDebugOn(!inode->i_nlink);
30762 + drop_nlink(inode);
30765 +static inline void vfsub_dead_dir(struct inode *inode)
30767 + AuDebugOn(!S_ISDIR(inode->i_mode));
30768 + inode->i_flags |= S_DEAD;
30769 + clear_nlink(inode);
30772 +static inline int vfsub_native_ro(struct inode *inode)
30774 + return (inode->i_sb->s_flags & MS_RDONLY)
30775 + || IS_RDONLY(inode)
30776 + /* || IS_APPEND(inode) */
30777 + || IS_IMMUTABLE(inode);
30780 +/* ---------------------------------------------------------------------- */
30782 +int vfsub_update_h_iattr(struct path *h_path, int *did);
30783 +struct file *vfsub_dentry_open(struct path *path, int flags);
30784 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
30785 +struct vfsub_aopen_args {
30786 + struct file *file;
30787 + unsigned int open_flag;
30788 + umode_t create_mode;
30792 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30793 + struct vfsub_aopen_args *args, struct au_branch *br);
30794 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
30796 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30799 +struct vfsub_lkup_one_args {
30800 + struct dentry **errp;
30801 + struct qstr *name;
30802 + struct dentry *parent;
30805 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
30806 + struct dentry *parent)
30808 + return vfsub_lookup_one_len(name->name, parent, name->len);
30811 +void vfsub_call_lkup_one(void *args);
30813 +/* ---------------------------------------------------------------------- */
30815 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
30820 + err = mnt_want_write(mnt);
30825 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
30828 + mnt_drop_write(mnt);
30832 +#if 0 /* reserved */
30833 +static inline void vfsub_mnt_drop_write_file(struct file *file)
30836 + mnt_drop_write_file(file);
30841 +/* ---------------------------------------------------------------------- */
30844 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30845 + struct dentry *d2, struct au_hinode *hdir2);
30846 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30847 + struct dentry *d2, struct au_hinode *hdir2);
30849 +int vfsub_create(struct inode *dir, struct path *path, int mode,
30851 +int vfsub_symlink(struct inode *dir, struct path *path,
30852 + const char *symname);
30853 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
30854 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
30855 + struct path *path, struct inode **delegated_inode);
30856 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
30857 + struct inode *hdir, struct path *path,
30858 + struct inode **delegated_inode);
30859 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
30860 +int vfsub_rmdir(struct inode *dir, struct path *path);
30862 +/* ---------------------------------------------------------------------- */
30864 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30866 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30868 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30870 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
30872 +int vfsub_flush(struct file *file, fl_owner_t id);
30873 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
30875 +static inline loff_t vfsub_f_size_read(struct file *file)
30877 + return i_size_read(file_inode(file));
30880 +static inline unsigned int vfsub_file_flags(struct file *file)
30882 + unsigned int flags;
30884 + spin_lock(&file->f_lock);
30885 + flags = file->f_flags;
30886 + spin_unlock(&file->f_lock);
30891 +#if 0 /* reserved */
30892 +static inline void vfsub_file_accessed(struct file *h_file)
30894 + file_accessed(h_file);
30895 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
30899 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
30900 + struct dentry *h_dentry)
30902 + struct path h_path = {
30903 + .dentry = h_dentry,
30906 + touch_atime(&h_path);
30907 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
30910 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
30913 + return generic_update_time(h_inode, ts, flags);
30914 + /* no vfsub_update_h_iattr() since we don't have struct path */
30917 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30918 + struct pipe_inode_info *pipe, size_t len,
30919 + unsigned int flags);
30920 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30921 + loff_t *ppos, size_t len, unsigned int flags);
30923 +static inline long vfsub_truncate(struct path *path, loff_t length)
30928 + err = vfs_truncate(path, length);
30933 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30934 + struct file *h_file);
30935 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
30937 +/* ---------------------------------------------------------------------- */
30939 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
30944 + err = vfs_llseek(file, offset, origin);
30949 +/* ---------------------------------------------------------------------- */
30951 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
30952 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
30953 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30954 + struct inode **delegated_inode);
30955 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30956 + struct inode **delegated_inode);
30957 +int vfsub_unlink(struct inode *dir, struct path *path,
30958 + struct inode **delegated_inode, int force);
30960 +/* ---------------------------------------------------------------------- */
30962 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
30963 + const void *value, size_t size, int flags)
30968 + err = vfs_setxattr(dentry, name, value, size, flags);
30974 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
30979 + err = vfs_removexattr(dentry, name);
30985 +#endif /* __KERNEL__ */
30986 +#endif /* __AUFS_VFSUB_H__ */
30987 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
30988 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
30989 +++ linux/fs/aufs/wbr_policy.c 2015-06-22 08:27:37.887501948 +0200
30992 + * Copyright (C) 2005-2015 Junjiro R. Okajima
30994 + * This program, aufs is free software; you can redistribute it and/or modify
30995 + * it under the terms of the GNU General Public License as published by
30996 + * the Free Software Foundation; either version 2 of the License, or
30997 + * (at your option) any later version.
30999 + * This program is distributed in the hope that it will be useful,
31000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31002 + * GNU General Public License for more details.
31004 + * You should have received a copy of the GNU General Public License
31005 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31009 + * policies for selecting one among multiple writable branches
31012 +#include <linux/statfs.h>
31015 +/* subset of cpup_attr() */
31016 +static noinline_for_stack
31017 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31021 + struct inode *h_isrc;
31023 + h_isrc = h_src->d_inode;
31024 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31025 + ia.ia_mode = h_isrc->i_mode;
31026 + ia.ia_uid = h_isrc->i_uid;
31027 + ia.ia_gid = h_isrc->i_gid;
31028 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31029 + au_cpup_attr_flags(h_path->dentry->d_inode, h_isrc->i_flags);
31030 + /* no delegation since it is just created */
31031 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31033 + /* is this nfs only? */
31034 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31035 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31036 + ia.ia_mode = h_isrc->i_mode;
31037 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31043 +#define AuCpdown_PARENT_OPQ 1
31044 +#define AuCpdown_WHED (1 << 1)
31045 +#define AuCpdown_MADE_DIR (1 << 2)
31046 +#define AuCpdown_DIROPQ (1 << 3)
31047 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31048 +#define au_fset_cpdown(flags, name) \
31049 + do { (flags) |= AuCpdown_##name; } while (0)
31050 +#define au_fclr_cpdown(flags, name) \
31051 + do { (flags) &= ~AuCpdown_##name; } while (0)
31053 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31054 + unsigned int *flags)
31057 + struct dentry *opq_dentry;
31059 + opq_dentry = au_diropq_create(dentry, bdst);
31060 + err = PTR_ERR(opq_dentry);
31061 + if (IS_ERR(opq_dentry))
31063 + dput(opq_dentry);
31064 + au_fset_cpdown(*flags, DIROPQ);
31070 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31071 + struct inode *dir, aufs_bindex_t bdst)
31074 + struct path h_path;
31075 + struct au_branch *br;
31077 + br = au_sbr(dentry->d_sb, bdst);
31078 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31079 + err = PTR_ERR(h_path.dentry);
31080 + if (IS_ERR(h_path.dentry))
31084 + if (h_path.dentry->d_inode) {
31085 + h_path.mnt = au_br_mnt(br);
31086 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31089 + dput(h_path.dentry);
31095 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31096 + struct au_pin *pin,
31097 + struct dentry *h_parent, void *arg)
31100 + aufs_bindex_t bopq, bstart;
31101 + struct path h_path;
31102 + struct dentry *parent;
31103 + struct inode *h_dir, *h_inode, *inode, *dir;
31104 + unsigned int *flags = arg;
31106 + bstart = au_dbstart(dentry);
31107 + /* dentry is di-locked */
31108 + parent = dget_parent(dentry);
31109 + dir = parent->d_inode;
31110 + h_dir = h_parent->d_inode;
31111 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31112 + IMustLock(h_dir);
31114 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31115 + if (unlikely(err < 0))
31117 + h_path.dentry = au_h_dptr(dentry, bdst);
31118 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31119 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31120 + S_IRWXU | S_IRUGO | S_IXUGO);
31121 + if (unlikely(err))
31123 + au_fset_cpdown(*flags, MADE_DIR);
31125 + bopq = au_dbdiropq(dentry);
31126 + au_fclr_cpdown(*flags, WHED);
31127 + au_fclr_cpdown(*flags, DIROPQ);
31128 + if (au_dbwh(dentry) == bdst)
31129 + au_fset_cpdown(*flags, WHED);
31130 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31131 + au_fset_cpdown(*flags, PARENT_OPQ);
31132 + h_inode = h_path.dentry->d_inode;
31133 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
31134 + if (au_ftest_cpdown(*flags, WHED)) {
31135 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31136 + if (unlikely(err)) {
31137 + mutex_unlock(&h_inode->i_mutex);
31142 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
31143 + mutex_unlock(&h_inode->i_mutex);
31144 + if (unlikely(err))
31147 + if (au_ftest_cpdown(*flags, WHED)) {
31148 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
31149 + if (unlikely(err))
31153 + inode = dentry->d_inode;
31154 + if (au_ibend(inode) < bdst)
31155 + au_set_ibend(inode, bdst);
31156 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
31157 + au_hi_flags(inode, /*isdir*/1));
31158 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
31159 + goto out; /* success */
31163 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31164 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
31165 + rerr = au_diropq_remove(dentry, bdst);
31166 + mutex_unlock(&h_inode->i_mutex);
31167 + if (unlikely(rerr)) {
31168 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
31169 + dentry, bdst, rerr);
31175 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
31176 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
31177 + if (unlikely(rerr)) {
31178 + AuIOErr("failed removing %pd b%d (%d)\n",
31179 + dentry, bdst, rerr);
31184 + au_set_h_dptr(dentry, bdst, NULL);
31185 + if (au_dbend(dentry) == bdst)
31186 + au_update_dbend(dentry);
31192 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
31195 + unsigned int flags;
31198 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
31203 +/* ---------------------------------------------------------------------- */
31205 +/* policies for create */
31207 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
31209 + int err, i, j, ndentry;
31210 + aufs_bindex_t bopq;
31211 + struct au_dcsub_pages dpages;
31212 + struct au_dpage *dpage;
31213 + struct dentry **dentries, *parent, *d;
31215 + err = au_dpages_init(&dpages, GFP_NOFS);
31216 + if (unlikely(err))
31218 + parent = dget_parent(dentry);
31219 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
31220 + if (unlikely(err))
31224 + for (i = 0; i < dpages.ndpage; i++) {
31225 + dpage = dpages.dpages + i;
31226 + dentries = dpage->dentries;
31227 + ndentry = dpage->ndentry;
31228 + for (j = 0; j < ndentry; j++) {
31230 + di_read_lock_parent2(d, !AuLock_IR);
31231 + bopq = au_dbdiropq(d);
31232 + di_read_unlock(d, !AuLock_IR);
31233 + if (bopq >= 0 && bopq < err)
31240 + au_dpages_free(&dpages);
31245 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
31247 + for (; bindex >= 0; bindex--)
31248 + if (!au_br_rdonly(au_sbr(sb, bindex)))
31253 +/* top down parent */
31254 +static int au_wbr_create_tdp(struct dentry *dentry,
31255 + unsigned int flags __maybe_unused)
31258 + aufs_bindex_t bstart, bindex;
31259 + struct super_block *sb;
31260 + struct dentry *parent, *h_parent;
31262 + sb = dentry->d_sb;
31263 + bstart = au_dbstart(dentry);
31265 + if (!au_br_rdonly(au_sbr(sb, bstart)))
31269 + parent = dget_parent(dentry);
31270 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
31271 + h_parent = au_h_dptr(parent, bindex);
31272 + if (!h_parent || !h_parent->d_inode)
31275 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31282 + /* bottom up here */
31283 + if (unlikely(err < 0)) {
31284 + err = au_wbr_bu(sb, bstart - 1);
31286 + err = au_wbr_nonopq(dentry, err);
31290 + AuDbg("b%d\n", err);
31294 +/* ---------------------------------------------------------------------- */
31296 +/* an exception for the policy other than tdp */
31297 +static int au_wbr_create_exp(struct dentry *dentry)
31300 + aufs_bindex_t bwh, bdiropq;
31301 + struct dentry *parent;
31304 + bwh = au_dbwh(dentry);
31305 + parent = dget_parent(dentry);
31306 + bdiropq = au_dbdiropq(parent);
31308 + if (bdiropq >= 0)
31309 + err = min(bdiropq, bwh);
31312 + AuDbg("%d\n", err);
31313 + } else if (bdiropq >= 0) {
31315 + AuDbg("%d\n", err);
31320 + err = au_wbr_nonopq(dentry, err);
31322 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
31325 + AuDbg("%d\n", err);
31329 +/* ---------------------------------------------------------------------- */
31332 +static int au_wbr_create_init_rr(struct super_block *sb)
31336 + err = au_wbr_bu(sb, au_sbend(sb));
31337 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
31340 + AuDbg("b%d\n", err);
31344 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
31348 + aufs_bindex_t bindex, bend;
31349 + struct super_block *sb;
31352 + err = au_wbr_create_exp(dentry);
31356 + sb = dentry->d_sb;
31357 + next = &au_sbi(sb)->si_wbr_rr_next;
31358 + bend = au_sbend(sb);
31360 + for (bindex = 0; bindex <= bend; bindex++) {
31361 + if (!au_ftest_wbr(flags, DIR)) {
31362 + err = atomic_dec_return(next) + 1;
31363 + /* modulo for 0 is meaningless */
31364 + if (unlikely(!err))
31365 + err = atomic_dec_return(next) + 1;
31367 + err = atomic_read(next);
31368 + AuDbg("%d\n", err);
31371 + AuDbg("%d\n", err);
31372 + if (!au_br_rdonly(au_sbr(sb, err)))
31378 + err = au_wbr_nonopq(dentry, err);
31381 + AuDbg("%d\n", err);
31385 +/* ---------------------------------------------------------------------- */
31387 +/* most free space */
31388 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
31390 + struct super_block *sb;
31391 + struct au_branch *br;
31392 + struct au_wbr_mfs *mfs;
31393 + struct dentry *h_parent;
31394 + aufs_bindex_t bindex, bend;
31396 + unsigned long long b, bavail;
31397 + struct path h_path;
31398 + /* reduce the stack usage */
31399 + struct kstatfs *st;
31401 + st = kmalloc(sizeof(*st), GFP_NOFS);
31402 + if (unlikely(!st)) {
31403 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
31408 + sb = dentry->d_sb;
31409 + mfs = &au_sbi(sb)->si_wbr_mfs;
31410 + MtxMustLock(&mfs->mfs_lock);
31411 + mfs->mfs_bindex = -EROFS;
31412 + mfs->mfsrr_bytes = 0;
31415 + bend = au_sbend(sb);
31417 + bindex = au_dbstart(parent);
31418 + bend = au_dbtaildir(parent);
31421 + for (; bindex <= bend; bindex++) {
31423 + h_parent = au_h_dptr(parent, bindex);
31424 + if (!h_parent || !h_parent->d_inode)
31427 + br = au_sbr(sb, bindex);
31428 + if (au_br_rdonly(br))
31431 + /* sb->s_root for NFS is unreliable */
31432 + h_path.mnt = au_br_mnt(br);
31433 + h_path.dentry = h_path.mnt->mnt_root;
31434 + err = vfs_statfs(&h_path, st);
31435 + if (unlikely(err)) {
31436 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
31440 + /* when the available size is equal, select the lower one */
31441 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
31442 + || sizeof(b) < sizeof(st->f_bsize));
31443 + b = st->f_bavail * st->f_bsize;
31444 + br->br_wbr->wbr_bytes = b;
31445 + if (b >= bavail) {
31447 + mfs->mfs_bindex = bindex;
31448 + mfs->mfs_jiffy = jiffies;
31452 + mfs->mfsrr_bytes = bavail;
31453 + AuDbg("b%d\n", mfs->mfs_bindex);
31457 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
31460 + struct dentry *parent;
31461 + struct super_block *sb;
31462 + struct au_wbr_mfs *mfs;
31464 + err = au_wbr_create_exp(dentry);
31468 + sb = dentry->d_sb;
31470 + if (au_ftest_wbr(flags, PARENT))
31471 + parent = dget_parent(dentry);
31472 + mfs = &au_sbi(sb)->si_wbr_mfs;
31473 + mutex_lock(&mfs->mfs_lock);
31474 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
31475 + || mfs->mfs_bindex < 0
31476 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
31477 + au_mfs(dentry, parent);
31478 + mutex_unlock(&mfs->mfs_lock);
31479 + err = mfs->mfs_bindex;
31483 + err = au_wbr_nonopq(dentry, err);
31486 + AuDbg("b%d\n", err);
31490 +static int au_wbr_create_init_mfs(struct super_block *sb)
31492 + struct au_wbr_mfs *mfs;
31494 + mfs = &au_sbi(sb)->si_wbr_mfs;
31495 + mutex_init(&mfs->mfs_lock);
31496 + mfs->mfs_jiffy = 0;
31497 + mfs->mfs_bindex = -EROFS;
31502 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
31504 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
31508 +/* ---------------------------------------------------------------------- */
31510 +/* most free space and then round robin */
31511 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
31514 + struct au_wbr_mfs *mfs;
31516 + err = au_wbr_create_mfs(dentry, flags);
31518 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
31519 + mutex_lock(&mfs->mfs_lock);
31520 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
31521 + err = au_wbr_create_rr(dentry, flags);
31522 + mutex_unlock(&mfs->mfs_lock);
31525 + AuDbg("b%d\n", err);
31529 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
31533 + au_wbr_create_init_mfs(sb); /* ignore */
31534 + err = au_wbr_create_init_rr(sb);
31539 +/* ---------------------------------------------------------------------- */
31541 +/* top down parent and most free space */
31542 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
31545 + unsigned long long b;
31546 + aufs_bindex_t bindex, bstart, bend;
31547 + struct super_block *sb;
31548 + struct dentry *parent, *h_parent;
31549 + struct au_branch *br;
31551 + err = au_wbr_create_tdp(dentry, flags);
31552 + if (unlikely(err < 0))
31554 + parent = dget_parent(dentry);
31555 + bstart = au_dbstart(parent);
31556 + bend = au_dbtaildir(parent);
31557 + if (bstart == bend)
31558 + goto out_parent; /* success */
31560 + e2 = au_wbr_create_mfs(dentry, flags);
31562 + goto out_parent; /* success */
31564 + /* when the available size is equal, select upper one */
31565 + sb = dentry->d_sb;
31566 + br = au_sbr(sb, err);
31567 + b = br->br_wbr->wbr_bytes;
31568 + AuDbg("b%d, %llu\n", err, b);
31570 + for (bindex = bstart; bindex <= bend; bindex++) {
31571 + h_parent = au_h_dptr(parent, bindex);
31572 + if (!h_parent || !h_parent->d_inode)
31575 + br = au_sbr(sb, bindex);
31576 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
31577 + b = br->br_wbr->wbr_bytes;
31579 + AuDbg("b%d, %llu\n", err, b);
31584 + err = au_wbr_nonopq(dentry, err);
31589 + AuDbg("b%d\n", err);
31593 +/* ---------------------------------------------------------------------- */
31596 + * - top down parent
31597 + * - most free space with parent
31598 + * - most free space round-robin regardless parent
31600 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
31603 + unsigned long long watermark;
31604 + struct super_block *sb;
31605 + struct au_branch *br;
31606 + struct au_wbr_mfs *mfs;
31608 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
31609 + if (unlikely(err < 0))
31612 + sb = dentry->d_sb;
31613 + br = au_sbr(sb, err);
31614 + mfs = &au_sbi(sb)->si_wbr_mfs;
31615 + mutex_lock(&mfs->mfs_lock);
31616 + watermark = mfs->mfsrr_watermark;
31617 + mutex_unlock(&mfs->mfs_lock);
31618 + if (br->br_wbr->wbr_bytes < watermark)
31619 + /* regardless the parent dir */
31620 + err = au_wbr_create_mfsrr(dentry, flags);
31623 + AuDbg("b%d\n", err);
31627 +/* ---------------------------------------------------------------------- */
31629 +/* policies for copyup */
31631 +/* top down parent */
31632 +static int au_wbr_copyup_tdp(struct dentry *dentry)
31634 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
31637 +/* bottom up parent */
31638 +static int au_wbr_copyup_bup(struct dentry *dentry)
31641 + aufs_bindex_t bindex, bstart;
31642 + struct dentry *parent, *h_parent;
31643 + struct super_block *sb;
31646 + sb = dentry->d_sb;
31647 + parent = dget_parent(dentry);
31648 + bstart = au_dbstart(parent);
31649 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
31650 + h_parent = au_h_dptr(parent, bindex);
31651 + if (!h_parent || !h_parent->d_inode)
31654 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31661 + /* bottom up here */
31662 + if (unlikely(err < 0))
31663 + err = au_wbr_bu(sb, bstart - 1);
31665 + AuDbg("b%d\n", err);
31670 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
31674 + err = au_wbr_bu(dentry->d_sb, bstart);
31675 + AuDbg("b%d\n", err);
31676 + if (err > bstart)
31677 + err = au_wbr_nonopq(dentry, err);
31679 + AuDbg("b%d\n", err);
31683 +static int au_wbr_copyup_bu(struct dentry *dentry)
31686 + aufs_bindex_t bstart;
31688 + bstart = au_dbstart(dentry);
31689 + err = au_wbr_do_copyup_bu(dentry, bstart);
31693 +/* ---------------------------------------------------------------------- */
31695 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
31696 + [AuWbrCopyup_TDP] = {
31697 + .copyup = au_wbr_copyup_tdp
31699 + [AuWbrCopyup_BUP] = {
31700 + .copyup = au_wbr_copyup_bup
31702 + [AuWbrCopyup_BU] = {
31703 + .copyup = au_wbr_copyup_bu
31707 +struct au_wbr_create_operations au_wbr_create_ops[] = {
31708 + [AuWbrCreate_TDP] = {
31709 + .create = au_wbr_create_tdp
31711 + [AuWbrCreate_RR] = {
31712 + .create = au_wbr_create_rr,
31713 + .init = au_wbr_create_init_rr
31715 + [AuWbrCreate_MFS] = {
31716 + .create = au_wbr_create_mfs,
31717 + .init = au_wbr_create_init_mfs,
31718 + .fin = au_wbr_create_fin_mfs
31720 + [AuWbrCreate_MFSV] = {
31721 + .create = au_wbr_create_mfs,
31722 + .init = au_wbr_create_init_mfs,
31723 + .fin = au_wbr_create_fin_mfs
31725 + [AuWbrCreate_MFSRR] = {
31726 + .create = au_wbr_create_mfsrr,
31727 + .init = au_wbr_create_init_mfsrr,
31728 + .fin = au_wbr_create_fin_mfs
31730 + [AuWbrCreate_MFSRRV] = {
31731 + .create = au_wbr_create_mfsrr,
31732 + .init = au_wbr_create_init_mfsrr,
31733 + .fin = au_wbr_create_fin_mfs
31735 + [AuWbrCreate_PMFS] = {
31736 + .create = au_wbr_create_pmfs,
31737 + .init = au_wbr_create_init_mfs,
31738 + .fin = au_wbr_create_fin_mfs
31740 + [AuWbrCreate_PMFSV] = {
31741 + .create = au_wbr_create_pmfs,
31742 + .init = au_wbr_create_init_mfs,
31743 + .fin = au_wbr_create_fin_mfs
31745 + [AuWbrCreate_PMFSRR] = {
31746 + .create = au_wbr_create_pmfsrr,
31747 + .init = au_wbr_create_init_mfsrr,
31748 + .fin = au_wbr_create_fin_mfs
31750 + [AuWbrCreate_PMFSRRV] = {
31751 + .create = au_wbr_create_pmfsrr,
31752 + .init = au_wbr_create_init_mfsrr,
31753 + .fin = au_wbr_create_fin_mfs
31756 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
31757 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
31758 +++ linux/fs/aufs/whout.c 2015-06-22 08:29:23.710091096 +0200
31761 + * Copyright (C) 2005-2015 Junjiro R. Okajima
31763 + * This program, aufs is free software; you can redistribute it and/or modify
31764 + * it under the terms of the GNU General Public License as published by
31765 + * the Free Software Foundation; either version 2 of the License, or
31766 + * (at your option) any later version.
31768 + * This program is distributed in the hope that it will be useful,
31769 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31770 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31771 + * GNU General Public License for more details.
31773 + * You should have received a copy of the GNU General Public License
31774 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31778 + * whiteout for logical deletion and opaque directory
31783 +#define WH_MASK S_IRUGO
31786 + * If a directory contains this file, then it is opaque. We start with the
31787 + * .wh. flag so that it is blocked by lookup.
31789 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
31790 + sizeof(AUFS_WH_DIROPQ) - 1);
31793 + * generate whiteout name, which is NOT terminated by NULL.
31794 + * @name: original d_name.name
31795 + * @len: original d_name.len
31796 + * @wh: whiteout qstr
31797 + * returns zero when succeeds, otherwise error.
31798 + * succeeded value as wh->name should be freed by kfree().
31800 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
31804 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
31805 + return -ENAMETOOLONG;
31807 + wh->len = name->len + AUFS_WH_PFX_LEN;
31808 + p = kmalloc(wh->len, GFP_NOFS);
31811 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
31812 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
31819 +/* ---------------------------------------------------------------------- */
31822 + * test if the @wh_name exists under @h_parent.
31823 + * @try_sio specifies the necessary of super-io.
31825 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
31828 + struct dentry *wh_dentry;
31831 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
31833 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
31834 + err = PTR_ERR(wh_dentry);
31835 + if (IS_ERR(wh_dentry)) {
31836 + if (err == -ENAMETOOLONG)
31842 + if (!wh_dentry->d_inode)
31843 + goto out_wh; /* success */
31846 + if (d_is_reg(wh_dentry))
31847 + goto out_wh; /* success */
31850 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
31851 + wh_dentry, wh_dentry->d_inode->i_mode);
31860 + * test if the @h_dentry sets opaque or not.
31862 +int au_diropq_test(struct dentry *h_dentry)
31865 + struct inode *h_dir;
31867 + h_dir = h_dentry->d_inode;
31868 + err = au_wh_test(h_dentry, &diropq_name,
31869 + au_test_h_perm_sio(h_dir, MAY_EXEC));
31874 + * returns a negative dentry whose name is unique and temporary.
31876 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
31877 + struct qstr *prefix)
31879 + struct dentry *dentry;
31881 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
31883 + /* strict atomic_t is unnecessary here */
31884 + static unsigned short cnt;
31887 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
31890 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
31891 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
31892 + dentry = ERR_PTR(-ENAMETOOLONG);
31893 + if (unlikely(qs.len > NAME_MAX))
31895 + dentry = ERR_PTR(-ENOMEM);
31896 + name = kmalloc(qs.len + 1, GFP_NOFS);
31897 + if (unlikely(!name))
31901 + /* doubly whiteout-ed */
31902 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
31903 + p = name + AUFS_WH_PFX_LEN * 2;
31904 + memcpy(p, prefix->name, prefix->len);
31905 + p += prefix->len;
31907 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
31910 + for (i = 0; i < 3; i++) {
31911 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
31912 + dentry = au_sio_lkup_one(&qs, h_parent);
31913 + if (IS_ERR(dentry) || !dentry->d_inode)
31917 + /* pr_warn("could not get random name\n"); */
31918 + dentry = ERR_PTR(-EEXIST);
31919 + AuDbg("%.*s\n", AuLNPair(&qs));
31923 + if (name != defname)
31926 + AuTraceErrPtr(dentry);
31931 + * rename the @h_dentry on @br to the whiteouted temporary name.
31933 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
31936 + struct path h_path = {
31937 + .mnt = au_br_mnt(br)
31939 + struct inode *h_dir, *delegated;
31940 + struct dentry *h_parent;
31942 + h_parent = h_dentry->d_parent; /* dir inode is locked */
31943 + h_dir = h_parent->d_inode;
31944 + IMustLock(h_dir);
31946 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
31947 + err = PTR_ERR(h_path.dentry);
31948 + if (IS_ERR(h_path.dentry))
31951 + /* under the same dir, no need to lock_rename() */
31952 + delegated = NULL;
31953 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
31955 + if (unlikely(err == -EWOULDBLOCK)) {
31956 + pr_warn("cannot retry for NFSv4 delegation"
31957 + " for an internal rename\n");
31960 + dput(h_path.dentry);
31967 +/* ---------------------------------------------------------------------- */
31969 + * functions for removing a whiteout
31972 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
31975 + struct inode *delegated;
31978 + * forces superio when the dir has a sticky bit.
31979 + * this may be a violation of unix fs semantics.
31981 + force = (h_dir->i_mode & S_ISVTX)
31982 + && !uid_eq(current_fsuid(), h_path->dentry->d_inode->i_uid);
31983 + delegated = NULL;
31984 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
31985 + if (unlikely(err == -EWOULDBLOCK)) {
31986 + pr_warn("cannot retry for NFSv4 delegation"
31987 + " for an internal unlink\n");
31993 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
31994 + struct dentry *dentry)
31998 + err = do_unlink_wh(h_dir, h_path);
31999 + if (!err && dentry)
32000 + au_set_dbwh(dentry, -1);
32005 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32006 + struct au_branch *br)
32009 + struct path h_path = {
32010 + .mnt = au_br_mnt(br)
32014 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32015 + if (IS_ERR(h_path.dentry))
32016 + err = PTR_ERR(h_path.dentry);
32018 + if (h_path.dentry->d_inode
32019 + && d_is_reg(h_path.dentry))
32020 + err = do_unlink_wh(h_parent->d_inode, &h_path);
32021 + dput(h_path.dentry);
32027 +/* ---------------------------------------------------------------------- */
32029 + * initialize/clean whiteout for a branch
32032 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32036 + struct inode *delegated;
32038 + if (!whpath->dentry->d_inode)
32042 + err = vfsub_rmdir(h_dir, whpath);
32044 + delegated = NULL;
32045 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32046 + if (unlikely(err == -EWOULDBLOCK)) {
32047 + pr_warn("cannot retry for NFSv4 delegation"
32048 + " for an internal unlink\n");
32052 + if (unlikely(err))
32053 + pr_warn("failed removing %pd (%d), ignored.\n",
32054 + whpath->dentry, err);
32057 +static int test_linkable(struct dentry *h_root)
32059 + struct inode *h_dir = h_root->d_inode;
32061 + if (h_dir->i_op->link)
32064 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32065 + h_root, au_sbtype(h_root->d_sb));
32069 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32070 +static int au_whdir(struct inode *h_dir, struct path *path)
32075 + if (!path->dentry->d_inode) {
32076 + int mode = S_IRWXU;
32078 + if (au_test_nfs(path->dentry->d_sb))
32080 + err = vfsub_mkdir(h_dir, path, mode);
32081 + } else if (d_is_dir(path->dentry))
32084 + pr_err("unknown %pd exists\n", path->dentry);
32089 +struct au_wh_base {
32090 + const struct qstr *name;
32091 + struct dentry *dentry;
32094 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
32095 + struct path *h_path)
32097 + h_path->dentry = base[AuBrWh_BASE].dentry;
32098 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32099 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32100 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32101 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32102 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32106 + * returns tri-state,
32107 + * minus: error, caller should print the message
32109 + * plus: error, caller should NOT print the message
32111 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
32112 + int do_plink, struct au_wh_base base[],
32113 + struct path *h_path)
32116 + struct inode *h_dir;
32118 + h_dir = h_root->d_inode;
32119 + h_path->dentry = base[AuBrWh_BASE].dentry;
32120 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32121 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32123 + err = test_linkable(h_root);
32124 + if (unlikely(err)) {
32129 + err = au_whdir(h_dir, h_path);
32130 + if (unlikely(err))
32132 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32134 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32135 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32136 + err = au_whdir(h_dir, h_path);
32137 + if (unlikely(err))
32139 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32146 + * for the moment, aufs supports the branch filesystem which does not support
32147 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
32148 + * copyup failed. finally, such filesystem will not be used as the writable
32151 + * returns tri-state, see above.
32153 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
32154 + int do_plink, struct au_wh_base base[],
32155 + struct path *h_path)
32158 + struct inode *h_dir;
32160 + WbrWhMustWriteLock(wbr);
32162 + err = test_linkable(h_root);
32163 + if (unlikely(err)) {
32169 + * todo: should this create be done in /sbin/mount.aufs helper?
32172 + h_dir = h_root->d_inode;
32173 + if (!base[AuBrWh_BASE].dentry->d_inode) {
32174 + h_path->dentry = base[AuBrWh_BASE].dentry;
32175 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
32176 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
32179 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
32180 + if (unlikely(err))
32183 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32185 + err = au_whdir(h_dir, h_path);
32186 + if (unlikely(err))
32188 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32190 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32191 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
32193 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32194 + err = au_whdir(h_dir, h_path);
32195 + if (unlikely(err))
32197 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32204 + * initialize the whiteout base file/dir for @br.
32206 +int au_wh_init(struct au_branch *br, struct super_block *sb)
32209 + const unsigned char do_plink
32210 + = !!au_opt_test(au_mntflags(sb), PLINK);
32211 + struct inode *h_dir;
32212 + struct path path = br->br_path;
32213 + struct dentry *h_root = path.dentry;
32214 + struct au_wbr *wbr = br->br_wbr;
32215 + static const struct qstr base_name[] = {
32216 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
32217 + sizeof(AUFS_BASE_NAME) - 1),
32218 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
32219 + sizeof(AUFS_PLINKDIR_NAME) - 1),
32220 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
32221 + sizeof(AUFS_ORPHDIR_NAME) - 1)
32223 + struct au_wh_base base[] = {
32224 + [AuBrWh_BASE] = {
32225 + .name = base_name + AuBrWh_BASE,
32228 + [AuBrWh_PLINK] = {
32229 + .name = base_name + AuBrWh_PLINK,
32232 + [AuBrWh_ORPH] = {
32233 + .name = base_name + AuBrWh_ORPH,
32239 + WbrWhMustWriteLock(wbr);
32241 + for (i = 0; i < AuBrWh_Last; i++) {
32242 + /* doubly whiteouted */
32243 + struct dentry *d;
32245 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
32246 + err = PTR_ERR(d);
32250 + base[i].dentry = d;
32252 + && wbr->wbr_wh[i]
32253 + && wbr->wbr_wh[i] != base[i].dentry);
32257 + for (i = 0; i < AuBrWh_Last; i++) {
32258 + dput(wbr->wbr_wh[i]);
32259 + wbr->wbr_wh[i] = NULL;
32263 + if (!au_br_writable(br->br_perm)) {
32264 + h_dir = h_root->d_inode;
32265 + au_wh_init_ro(h_dir, base, &path);
32266 + } else if (!au_br_wh_linkable(br->br_perm)) {
32267 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
32273 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
32279 + goto out; /* success */
32282 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
32283 + err, h_root, au_sbtype(h_root->d_sb));
32285 + for (i = 0; i < AuBrWh_Last; i++)
32286 + dput(base[i].dentry);
32290 +/* ---------------------------------------------------------------------- */
32292 + * whiteouts are all hard-linked usually.
32293 + * when its link count reaches a ceiling, we create a new whiteout base
32294 + * asynchronously.
32297 +struct reinit_br_wh {
32298 + struct super_block *sb;
32299 + struct au_branch *br;
32302 +static void reinit_br_wh(void *arg)
32305 + aufs_bindex_t bindex;
32306 + struct path h_path;
32307 + struct reinit_br_wh *a = arg;
32308 + struct au_wbr *wbr;
32309 + struct inode *dir, *delegated;
32310 + struct dentry *h_root;
32311 + struct au_hinode *hdir;
32314 + wbr = a->br->br_wbr;
32315 + /* big aufs lock */
32316 + si_noflush_write_lock(a->sb);
32317 + if (!au_br_writable(a->br->br_perm))
32319 + bindex = au_br_index(a->sb, a->br->br_id);
32320 + if (unlikely(bindex < 0))
32323 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
32324 + dir = a->sb->s_root->d_inode;
32325 + hdir = au_hi(dir, bindex);
32326 + h_root = au_h_dptr(a->sb->s_root, bindex);
32327 + AuDebugOn(h_root != au_br_dentry(a->br));
32329 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32330 + wbr_wh_write_lock(wbr);
32331 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
32334 + h_path.dentry = wbr->wbr_whbase;
32335 + h_path.mnt = au_br_mnt(a->br);
32336 + delegated = NULL;
32337 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
32339 + if (unlikely(err == -EWOULDBLOCK)) {
32340 + pr_warn("cannot retry for NFSv4 delegation"
32341 + " for an internal unlink\n");
32345 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
32348 + dput(wbr->wbr_whbase);
32349 + wbr->wbr_whbase = NULL;
32351 + err = au_wh_init(a->br, a->sb);
32352 + wbr_wh_write_unlock(wbr);
32353 + au_hn_imtx_unlock(hdir);
32354 + di_read_unlock(a->sb->s_root, AuLock_IR);
32356 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
32360 + atomic_dec(&wbr->wbr_wh_running);
32361 + atomic_dec(&a->br->br_count);
32362 + si_write_unlock(a->sb);
32363 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
32365 + if (unlikely(err))
32366 + AuIOErr("err %d\n", err);
32369 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
32371 + int do_dec, wkq_err;
32372 + struct reinit_br_wh *arg;
32375 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
32378 + /* ignore ENOMEM */
32379 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
32382 + * dec(wh_running), kfree(arg) and dec(br_count)
32383 + * in reinit function
32387 + atomic_inc(&br->br_count);
32388 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
32389 + if (unlikely(wkq_err)) {
32390 + atomic_dec(&br->br_wbr->wbr_wh_running);
32391 + atomic_dec(&br->br_count);
32399 + atomic_dec(&br->br_wbr->wbr_wh_running);
32402 +/* ---------------------------------------------------------------------- */
32405 + * create the whiteout @wh.
32407 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
32408 + struct dentry *wh)
32411 + struct path h_path = {
32414 + struct au_branch *br;
32415 + struct au_wbr *wbr;
32416 + struct dentry *h_parent;
32417 + struct inode *h_dir, *delegated;
32419 + h_parent = wh->d_parent; /* dir inode is locked */
32420 + h_dir = h_parent->d_inode;
32421 + IMustLock(h_dir);
32423 + br = au_sbr(sb, bindex);
32424 + h_path.mnt = au_br_mnt(br);
32425 + wbr = br->br_wbr;
32426 + wbr_wh_read_lock(wbr);
32427 + if (wbr->wbr_whbase) {
32428 + delegated = NULL;
32429 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
32430 + if (unlikely(err == -EWOULDBLOCK)) {
32431 + pr_warn("cannot retry for NFSv4 delegation"
32432 + " for an internal link\n");
32435 + if (!err || err != -EMLINK)
32438 + /* link count full. re-initialize br_whbase. */
32439 + kick_reinit_br_wh(sb, br);
32442 + /* return this error in this context */
32443 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
32445 + au_fhsm_wrote(sb, bindex, /*force*/0);
32448 + wbr_wh_read_unlock(wbr);
32452 +/* ---------------------------------------------------------------------- */
32455 + * create or remove the diropq.
32457 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
32458 + unsigned int flags)
32460 + struct dentry *opq_dentry, *h_dentry;
32461 + struct super_block *sb;
32462 + struct au_branch *br;
32465 + sb = dentry->d_sb;
32466 + br = au_sbr(sb, bindex);
32467 + h_dentry = au_h_dptr(dentry, bindex);
32468 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
32469 + if (IS_ERR(opq_dentry))
32472 + if (au_ftest_diropq(flags, CREATE)) {
32473 + err = link_or_create_wh(sb, bindex, opq_dentry);
32475 + au_set_dbdiropq(dentry, bindex);
32476 + goto out; /* success */
32479 + struct path tmp = {
32480 + .dentry = opq_dentry,
32481 + .mnt = au_br_mnt(br)
32483 + err = do_unlink_wh(au_h_iptr(dentry->d_inode, bindex), &tmp);
32485 + au_set_dbdiropq(dentry, -1);
32487 + dput(opq_dentry);
32488 + opq_dentry = ERR_PTR(err);
32491 + return opq_dentry;
32494 +struct do_diropq_args {
32495 + struct dentry **errp;
32496 + struct dentry *dentry;
32497 + aufs_bindex_t bindex;
32498 + unsigned int flags;
32501 +static void call_do_diropq(void *args)
32503 + struct do_diropq_args *a = args;
32504 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
32507 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32508 + unsigned int flags)
32510 + struct dentry *diropq, *h_dentry;
32512 + h_dentry = au_h_dptr(dentry, bindex);
32513 + if (!au_test_h_perm_sio(h_dentry->d_inode, MAY_EXEC | MAY_WRITE))
32514 + diropq = do_diropq(dentry, bindex, flags);
32517 + struct do_diropq_args args = {
32519 + .dentry = dentry,
32520 + .bindex = bindex,
32524 + wkq_err = au_wkq_wait(call_do_diropq, &args);
32525 + if (unlikely(wkq_err))
32526 + diropq = ERR_PTR(wkq_err);
32532 +/* ---------------------------------------------------------------------- */
32535 + * lookup whiteout dentry.
32536 + * @h_parent: lower parent dentry which must exist and be locked
32537 + * @base_name: name of dentry which will be whiteouted
32538 + * returns dentry for whiteout.
32540 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32541 + struct au_branch *br)
32544 + struct qstr wh_name;
32545 + struct dentry *wh_dentry;
32547 + err = au_wh_name_alloc(&wh_name, base_name);
32548 + wh_dentry = ERR_PTR(err);
32550 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
32551 + kfree(wh_name.name);
32553 + return wh_dentry;
32557 + * link/create a whiteout for @dentry on @bindex.
32559 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32560 + struct dentry *h_parent)
32562 + struct dentry *wh_dentry;
32563 + struct super_block *sb;
32566 + sb = dentry->d_sb;
32567 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
32568 + if (!IS_ERR(wh_dentry) && !wh_dentry->d_inode) {
32569 + err = link_or_create_wh(sb, bindex, wh_dentry);
32571 + au_set_dbwh(dentry, bindex);
32572 + au_fhsm_wrote(sb, bindex, /*force*/0);
32575 + wh_dentry = ERR_PTR(err);
32579 + return wh_dentry;
32582 +/* ---------------------------------------------------------------------- */
32584 +/* Delete all whiteouts in this directory on branch bindex. */
32585 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
32586 + aufs_bindex_t bindex, struct au_branch *br)
32589 + unsigned long ul, n;
32590 + struct qstr wh_name;
32592 + struct hlist_head *head;
32593 + struct au_vdir_wh *pos;
32594 + struct au_vdir_destr *str;
32597 + p = (void *)__get_free_page(GFP_NOFS);
32598 + wh_name.name = p;
32599 + if (unlikely(!wh_name.name))
32603 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32604 + p += AUFS_WH_PFX_LEN;
32605 + n = whlist->nh_num;
32606 + head = whlist->nh_head;
32607 + for (ul = 0; !err && ul < n; ul++, head++) {
32608 + hlist_for_each_entry(pos, head, wh_hash) {
32609 + if (pos->wh_bindex != bindex)
32612 + str = &pos->wh_str;
32613 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
32614 + memcpy(p, str->name, str->len);
32615 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
32616 + err = unlink_wh_name(h_dentry, &wh_name, br);
32621 + AuIOErr("whiteout name too long %.*s\n",
32622 + str->len, str->name);
32627 + free_page((unsigned long)wh_name.name);
32633 +struct del_wh_children_args {
32635 + struct dentry *h_dentry;
32636 + struct au_nhash *whlist;
32637 + aufs_bindex_t bindex;
32638 + struct au_branch *br;
32641 +static void call_del_wh_children(void *args)
32643 + struct del_wh_children_args *a = args;
32644 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
32647 +/* ---------------------------------------------------------------------- */
32649 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
32651 + struct au_whtmp_rmdir *whtmp;
32653 + unsigned int rdhash;
32655 + SiMustAnyLock(sb);
32657 + whtmp = kmalloc(sizeof(*whtmp), gfp);
32658 + if (unlikely(!whtmp)) {
32659 + whtmp = ERR_PTR(-ENOMEM);
32663 + whtmp->dir = NULL;
32664 + whtmp->br = NULL;
32665 + whtmp->wh_dentry = NULL;
32666 + /* no estimation for dir size */
32667 + rdhash = au_sbi(sb)->si_rdhash;
32669 + rdhash = AUFS_RDHASH_DEF;
32670 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
32671 + if (unlikely(err)) {
32673 + whtmp = ERR_PTR(err);
32680 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
32683 + atomic_dec(&whtmp->br->br_count);
32684 + dput(whtmp->wh_dentry);
32685 + iput(whtmp->dir);
32686 + au_nhash_wh_free(&whtmp->whlist);
32691 + * rmdir the whiteouted temporary named dir @h_dentry.
32692 + * @whlist: whiteouted children.
32694 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32695 + struct dentry *wh_dentry, struct au_nhash *whlist)
32698 + unsigned int h_nlink;
32699 + struct path h_tmp;
32700 + struct inode *wh_inode, *h_dir;
32701 + struct au_branch *br;
32703 + h_dir = wh_dentry->d_parent->d_inode; /* dir inode is locked */
32704 + IMustLock(h_dir);
32706 + br = au_sbr(dir->i_sb, bindex);
32707 + wh_inode = wh_dentry->d_inode;
32708 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
32711 + * someone else might change some whiteouts while we were sleeping.
32712 + * it means this whlist may have an obsoleted entry.
32714 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
32715 + err = del_wh_children(wh_dentry, whlist, bindex, br);
32718 + struct del_wh_children_args args = {
32720 + .h_dentry = wh_dentry,
32721 + .whlist = whlist,
32722 + .bindex = bindex,
32726 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
32727 + if (unlikely(wkq_err))
32730 + mutex_unlock(&wh_inode->i_mutex);
32733 + h_tmp.dentry = wh_dentry;
32734 + h_tmp.mnt = au_br_mnt(br);
32735 + h_nlink = h_dir->i_nlink;
32736 + err = vfsub_rmdir(h_dir, &h_tmp);
32737 + /* some fs doesn't change the parent nlink in some cases */
32738 + h_nlink -= h_dir->i_nlink;
32742 + if (au_ibstart(dir) == bindex) {
32743 + /* todo: dir->i_mutex is necessary */
32744 + au_cpup_attr_timesizes(dir);
32746 + vfsub_drop_nlink(dir);
32748 + return 0; /* success */
32751 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
32755 +static void call_rmdir_whtmp(void *args)
32758 + aufs_bindex_t bindex;
32759 + struct au_whtmp_rmdir *a = args;
32760 + struct super_block *sb;
32761 + struct dentry *h_parent;
32762 + struct inode *h_dir;
32763 + struct au_hinode *hdir;
32765 + /* rmdir by nfsd may cause deadlock with this i_mutex */
32766 + /* mutex_lock(&a->dir->i_mutex); */
32768 + sb = a->dir->i_sb;
32769 + si_read_lock(sb, !AuLock_FLUSH);
32770 + if (!au_br_writable(a->br->br_perm))
32772 + bindex = au_br_index(sb, a->br->br_id);
32773 + if (unlikely(bindex < 0))
32777 + ii_write_lock_parent(a->dir);
32778 + h_parent = dget_parent(a->wh_dentry);
32779 + h_dir = h_parent->d_inode;
32780 + hdir = au_hi(a->dir, bindex);
32781 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
32782 + if (unlikely(err))
32784 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32785 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
32788 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
32789 + au_hn_imtx_unlock(hdir);
32790 + vfsub_mnt_drop_write(au_br_mnt(a->br));
32794 + ii_write_unlock(a->dir);
32796 + /* mutex_unlock(&a->dir->i_mutex); */
32797 + au_whtmp_rmdir_free(a);
32798 + si_read_unlock(sb);
32799 + au_nwt_done(&au_sbi(sb)->si_nowait);
32800 + if (unlikely(err))
32801 + AuIOErr("err %d\n", err);
32804 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32805 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
32808 + struct super_block *sb;
32812 + /* all post-process will be done in do_rmdir_whtmp(). */
32814 + args->dir = au_igrab(dir);
32815 + args->br = au_sbr(sb, bindex);
32816 + atomic_inc(&args->br->br_count);
32817 + args->wh_dentry = dget(wh_dentry);
32818 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
32819 + if (unlikely(wkq_err)) {
32820 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
32821 + au_whtmp_rmdir_free(args);
32824 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
32825 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
32826 +++ linux/fs/aufs/whout.h 2015-06-22 08:27:37.890835363 +0200
32829 + * Copyright (C) 2005-2015 Junjiro R. Okajima
32831 + * This program, aufs is free software; you can redistribute it and/or modify
32832 + * it under the terms of the GNU General Public License as published by
32833 + * the Free Software Foundation; either version 2 of the License, or
32834 + * (at your option) any later version.
32836 + * This program is distributed in the hope that it will be useful,
32837 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32838 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32839 + * GNU General Public License for more details.
32841 + * You should have received a copy of the GNU General Public License
32842 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32846 + * whiteout for logical deletion and opaque directory
32849 +#ifndef __AUFS_WHOUT_H__
32850 +#define __AUFS_WHOUT_H__
32857 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
32858 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
32859 +int au_diropq_test(struct dentry *h_dentry);
32861 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32862 + struct qstr *prefix);
32863 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
32864 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32865 + struct dentry *dentry);
32866 +int au_wh_init(struct au_branch *br, struct super_block *sb);
32868 +/* diropq flags */
32869 +#define AuDiropq_CREATE 1
32870 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
32871 +#define au_fset_diropq(flags, name) \
32872 + do { (flags) |= AuDiropq_##name; } while (0)
32873 +#define au_fclr_diropq(flags, name) \
32874 + do { (flags) &= ~AuDiropq_##name; } while (0)
32876 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32877 + unsigned int flags);
32878 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32879 + struct au_branch *br);
32880 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32881 + struct dentry *h_parent);
32883 +/* real rmdir for the whiteout-ed dir */
32884 +struct au_whtmp_rmdir {
32885 + struct inode *dir;
32886 + struct au_branch *br;
32887 + struct dentry *wh_dentry;
32888 + struct au_nhash whlist;
32891 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
32892 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
32893 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32894 + struct dentry *wh_dentry, struct au_nhash *whlist);
32895 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32896 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
32898 +/* ---------------------------------------------------------------------- */
32900 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
32901 + aufs_bindex_t bindex)
32903 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
32906 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
32908 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
32911 +#endif /* __KERNEL__ */
32912 +#endif /* __AUFS_WHOUT_H__ */
32913 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
32914 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
32915 +++ linux/fs/aufs/wkq.c 2015-06-22 08:27:37.890835363 +0200
32918 + * Copyright (C) 2005-2015 Junjiro R. Okajima
32920 + * This program, aufs is free software; you can redistribute it and/or modify
32921 + * it under the terms of the GNU General Public License as published by
32922 + * the Free Software Foundation; either version 2 of the License, or
32923 + * (at your option) any later version.
32925 + * This program is distributed in the hope that it will be useful,
32926 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32927 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32928 + * GNU General Public License for more details.
32930 + * You should have received a copy of the GNU General Public License
32931 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32935 + * workqueue for asynchronous/super-io operations
32936 + * todo: try new dredential scheme
32939 +#include <linux/module.h>
32942 +/* internal workqueue named AUFS_WKQ_NAME */
32944 +static struct workqueue_struct *au_wkq;
32946 +struct au_wkinfo {
32947 + struct work_struct wk;
32948 + struct kobject *kobj;
32950 + unsigned int flags; /* see wkq.h */
32952 + au_wkq_func_t func;
32955 + struct completion *comp;
32958 +/* ---------------------------------------------------------------------- */
32960 +static void wkq_func(struct work_struct *wk)
32962 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
32964 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
32965 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
32967 + wkinfo->func(wkinfo->args);
32968 + if (au_ftest_wkq(wkinfo->flags, WAIT))
32969 + complete(wkinfo->comp);
32971 + kobject_put(wkinfo->kobj);
32972 + module_put(THIS_MODULE); /* todo: ?? */
32978 + * Since struct completion is large, try allocating it dynamically.
32980 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
32981 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
32983 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
32985 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
32987 + init_completion(*comp);
32988 + wkinfo->comp = *comp;
32994 +static void au_wkq_comp_free(struct completion *comp)
33002 +#define AuWkqCompDeclare(name) \
33003 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33004 + struct completion *comp = &_ ## name
33006 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33008 + wkinfo->comp = *comp;
33012 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33016 +#endif /* 4KSTACKS */
33018 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33020 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33021 + if (au_wkq_test()) {
33022 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33023 + " due to a dead dir by UDBA?\n");
33024 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33027 + au_dbg_verify_kthread();
33029 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33030 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33031 + queue_work(au_wkq, &wkinfo->wk);
33033 + INIT_WORK(&wkinfo->wk, wkq_func);
33034 + schedule_work(&wkinfo->wk);
33039 + * Be careful. It is easy to make deadlock happen.
33040 + * processA: lock, wkq and wait
33041 + * processB: wkq and wait, lock in wkq
33044 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33047 + AuWkqCompDeclare(comp);
33048 + struct au_wkinfo wkinfo = {
33054 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33056 + au_wkq_run(&wkinfo);
33057 + /* no timeout, no interrupt */
33058 + wait_for_completion(wkinfo.comp);
33059 + au_wkq_comp_free(comp);
33060 + destroy_work_on_stack(&wkinfo.wk);
33068 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33069 + * problem in a concurrent umounting.
33071 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33072 + unsigned int flags)
33075 + struct au_wkinfo *wkinfo;
33077 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
33080 + * wkq_func() must free this wkinfo.
33081 + * it highly depends upon the implementation of workqueue.
33084 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
33086 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
33087 + wkinfo->flags = flags & ~AuWkq_WAIT;
33088 + wkinfo->func = func;
33089 + wkinfo->args = args;
33090 + wkinfo->comp = NULL;
33091 + kobject_get(wkinfo->kobj);
33092 + __module_get(THIS_MODULE); /* todo: ?? */
33094 + au_wkq_run(wkinfo);
33097 + au_nwt_done(&au_sbi(sb)->si_nowait);
33103 +/* ---------------------------------------------------------------------- */
33105 +void au_nwt_init(struct au_nowait_tasks *nwt)
33107 + atomic_set(&nwt->nw_len, 0);
33108 + /* smp_mb(); */ /* atomic_set */
33109 + init_waitqueue_head(&nwt->nw_wq);
33112 +void au_wkq_fin(void)
33114 + destroy_workqueue(au_wkq);
33117 +int __init au_wkq_init(void)
33122 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
33123 + if (IS_ERR(au_wkq))
33124 + err = PTR_ERR(au_wkq);
33125 + else if (!au_wkq)
33130 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
33131 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
33132 +++ linux/fs/aufs/wkq.h 2015-06-22 08:27:37.890835363 +0200
33135 + * Copyright (C) 2005-2015 Junjiro R. Okajima
33137 + * This program, aufs is free software; you can redistribute it and/or modify
33138 + * it under the terms of the GNU General Public License as published by
33139 + * the Free Software Foundation; either version 2 of the License, or
33140 + * (at your option) any later version.
33142 + * This program is distributed in the hope that it will be useful,
33143 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33144 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33145 + * GNU General Public License for more details.
33147 + * You should have received a copy of the GNU General Public License
33148 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33152 + * workqueue for asynchronous/super-io operations
33153 + * todo: try new credentials management scheme
33156 +#ifndef __AUFS_WKQ_H__
33157 +#define __AUFS_WKQ_H__
33161 +struct super_block;
33163 +/* ---------------------------------------------------------------------- */
33166 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
33168 +struct au_nowait_tasks {
33170 + wait_queue_head_t nw_wq;
33173 +/* ---------------------------------------------------------------------- */
33175 +typedef void (*au_wkq_func_t)(void *args);
33178 +#define AuWkq_WAIT 1
33179 +#define AuWkq_NEST (1 << 1)
33180 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
33181 +#define au_fset_wkq(flags, name) \
33182 + do { (flags) |= AuWkq_##name; } while (0)
33183 +#define au_fclr_wkq(flags, name) \
33184 + do { (flags) &= ~AuWkq_##name; } while (0)
33186 +#ifndef CONFIG_AUFS_HNOTIFY
33188 +#define AuWkq_NEST 0
33192 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
33193 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33194 + unsigned int flags);
33195 +void au_nwt_init(struct au_nowait_tasks *nwt);
33196 +int __init au_wkq_init(void);
33197 +void au_wkq_fin(void);
33199 +/* ---------------------------------------------------------------------- */
33201 +static inline int au_wkq_test(void)
33203 + return current->flags & PF_WQ_WORKER;
33206 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
33208 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
33211 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
33213 + if (atomic_dec_and_test(&nwt->nw_len))
33214 + wake_up_all(&nwt->nw_wq);
33217 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
33219 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
33223 +#endif /* __KERNEL__ */
33224 +#endif /* __AUFS_WKQ_H__ */
33225 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
33226 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
33227 +++ linux/fs/aufs/xattr.c 2015-06-22 08:27:37.890835363 +0200
33230 + * Copyright (C) 2014-2015 Junjiro R. Okajima
33232 + * This program, aufs is free software; you can redistribute it and/or modify
33233 + * it under the terms of the GNU General Public License as published by
33234 + * the Free Software Foundation; either version 2 of the License, or
33235 + * (at your option) any later version.
33237 + * This program is distributed in the hope that it will be useful,
33238 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33239 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33240 + * GNU General Public License for more details.
33242 + * You should have received a copy of the GNU General Public License
33243 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33247 + * handling xattr functions
33250 +#include <linux/xattr.h>
33253 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
33255 + if (!ignore_flags)
33263 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
33268 +#define cmp(brattr, prefix) do { \
33269 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
33270 + XATTR_##prefix##_PREFIX_LEN)) { \
33271 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
33277 + cmp(SEC, SECURITY);
33278 + cmp(SYS, SYSTEM);
33279 + cmp(TR, TRUSTED);
33283 + if (ignore_flags & AuBrAttr_ICEX_OTH)
33290 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
33292 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
33293 + char *name, char **buf, unsigned int ignore_flags,
33294 + unsigned int verbose)
33298 + struct inode *h_idst;
33300 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
33302 + if (unlikely(err <= 0)) {
33303 + if (err == -ENODATA
33304 + || (err == -EOPNOTSUPP
33305 + && ((ignore_flags & au_xattr_out_of_list)
33306 + || (au_test_nfs_noacl(h_src->d_inode)
33307 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
33309 + XATTR_NAME_POSIX_ACL_DEFAULT))))
33312 + if (err && (verbose || au_debug_test()))
33313 + pr_err("%s, err %d\n", name, err);
33317 + /* unlock it temporary */
33318 + h_idst = h_dst->d_inode;
33319 + mutex_unlock(&h_idst->i_mutex);
33320 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
33321 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33322 + if (unlikely(err)) {
33323 + if (verbose || au_debug_test())
33324 + pr_err("%s, err %d\n", name, err);
33325 + err = au_xattr_ignore(err, name, ignore_flags);
33332 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
33333 + unsigned int verbose)
33335 + int err, unlocked, acl_access, acl_default;
33337 + struct inode *h_isrc, *h_idst;
33338 + char *value, *p, *o, *e;
33340 + /* try stopping to update the source inode while we are referencing */
33341 + /* there should not be the parent-child relationship between them */
33342 + h_isrc = h_src->d_inode;
33343 + h_idst = h_dst->d_inode;
33344 + mutex_unlock(&h_idst->i_mutex);
33345 + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD);
33346 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33349 + /* some filesystems don't list POSIX ACL, for example tmpfs */
33350 + ssz = vfs_listxattr(h_src, NULL, 0);
33352 + if (unlikely(err < 0)) {
33354 + if (err == -ENODATA
33355 + || err == -EOPNOTSUPP)
33356 + err = 0; /* ignore */
33365 + p = kmalloc(ssz, GFP_NOFS);
33367 + if (unlikely(!p))
33369 + err = vfs_listxattr(h_src, p, ssz);
33371 + mutex_unlock(&h_isrc->i_mutex);
33373 + AuDbg("err %d, ssz %zd\n", err, ssz);
33374 + if (unlikely(err < 0))
33382 + while (!err && p < e) {
33383 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
33384 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
33385 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
33386 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
33388 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
33390 + p += strlen(p) + 1;
33393 + ignore_flags |= au_xattr_out_of_list;
33394 + if (!err && !acl_access) {
33395 + err = au_do_cpup_xattr(h_dst, h_src,
33396 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
33397 + ignore_flags, verbose);
33400 + if (!err && !acl_default) {
33401 + err = au_do_cpup_xattr(h_dst, h_src,
33402 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
33403 + ignore_flags, verbose);
33413 + mutex_unlock(&h_isrc->i_mutex);
33418 +/* ---------------------------------------------------------------------- */
33425 +struct au_lgxattr {
33433 + const char *name;
33440 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
33443 + struct path h_path;
33444 + struct super_block *sb;
33446 + sb = dentry->d_sb;
33447 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
33448 + if (unlikely(err))
33450 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
33451 + if (unlikely(err))
33453 + if (unlikely(!h_path.dentry))
33454 + /* illegally overlapped or something */
33455 + goto out_di; /* pretending success */
33457 + /* always topmost entry only */
33458 + switch (arg->type) {
33459 + case AU_XATTR_LIST:
33460 + err = vfs_listxattr(h_path.dentry,
33461 + arg->u.list.list, arg->u.list.size);
33463 + case AU_XATTR_GET:
33464 + err = vfs_getxattr(h_path.dentry,
33465 + arg->u.get.name, arg->u.get.value,
33466 + arg->u.get.size);
33471 + di_read_unlock(dentry, AuLock_IR);
33473 + si_read_unlock(sb);
33479 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
33481 + struct au_lgxattr arg = {
33482 + .type = AU_XATTR_LIST,
33489 + return au_lgxattr(dentry, &arg);
33492 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
33495 + struct au_lgxattr arg = {
33496 + .type = AU_XATTR_GET,
33504 + return au_lgxattr(dentry, &arg);
33507 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
33508 + size_t size, int flags)
33510 + struct au_srxattr arg = {
33511 + .type = AU_XATTR_SET,
33520 + return au_srxattr(dentry, &arg);
33523 +int aufs_removexattr(struct dentry *dentry, const char *name)
33525 + struct au_srxattr arg = {
33526 + .type = AU_XATTR_REMOVE,
33532 + return au_srxattr(dentry, &arg);
33535 +/* ---------------------------------------------------------------------- */
33538 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
33539 + const char *name, size_t name_len, int type)
33541 + return aufs_listxattr(dentry, list, list_size);
33544 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
33545 + size_t size, int type)
33547 + return aufs_getxattr(dentry, name, buffer, size);
33550 +static int au_xattr_set(struct dentry *dentry, const char *name,
33551 + const void *value, size_t size, int flags, int type)
33553 + return aufs_setxattr(dentry, name, value, size, flags);
33556 +static const struct xattr_handler au_xattr_handler = {
33557 + /* no prefix, no flags */
33558 + .list = au_xattr_list,
33559 + .get = au_xattr_get,
33560 + .set = au_xattr_set
33561 + /* why no remove? */
33564 +static const struct xattr_handler *au_xattr_handlers[] = {
33565 + &au_xattr_handler
33568 +void au_xattr_init(struct super_block *sb)
33570 + /* sb->s_xattr = au_xattr_handlers; */
33573 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
33574 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
33575 +++ linux/fs/aufs/xino.c 2015-06-22 08:29:23.710091096 +0200
33578 + * Copyright (C) 2005-2015 Junjiro R. Okajima
33580 + * This program, aufs is free software; you can redistribute it and/or modify
33581 + * it under the terms of the GNU General Public License as published by
33582 + * the Free Software Foundation; either version 2 of the License, or
33583 + * (at your option) any later version.
33585 + * This program is distributed in the hope that it will be useful,
33586 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33587 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33588 + * GNU General Public License for more details.
33590 + * You should have received a copy of the GNU General Public License
33591 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33595 + * external inode number translation table and bitmap
33598 +#include <linux/seq_file.h>
33599 +#include <linux/statfs.h>
33602 +/* todo: unnecessary to support mmap_sem since kernel-space? */
33603 +ssize_t xino_fread(au_readf_t func, struct file *file, void *kbuf, size_t size,
33607 + mm_segment_t oldfs;
33614 + oldfs = get_fs();
33615 + set_fs(KERNEL_DS);
33617 + /* todo: signal_pending? */
33618 + err = func(file, buf.u, size, pos);
33619 + } while (err == -EAGAIN || err == -EINTR);
33622 +#if 0 /* reserved for future use */
33624 + fsnotify_access(file->f_path.dentry);
33630 +/* ---------------------------------------------------------------------- */
33632 +static ssize_t do_xino_fwrite(au_writef_t func, struct file *file, void *kbuf,
33633 + size_t size, loff_t *pos)
33636 + mm_segment_t oldfs;
33639 + const char __user *u;
33643 + oldfs = get_fs();
33644 + set_fs(KERNEL_DS);
33646 + /* todo: signal_pending? */
33647 + err = func(file, buf.u, size, pos);
33648 + } while (err == -EAGAIN || err == -EINTR);
33651 +#if 0 /* reserved for future use */
33653 + fsnotify_modify(file->f_path.dentry);
33659 +struct do_xino_fwrite_args {
33661 + au_writef_t func;
33662 + struct file *file;
33668 +static void call_do_xino_fwrite(void *args)
33670 + struct do_xino_fwrite_args *a = args;
33671 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
33674 +ssize_t xino_fwrite(au_writef_t func, struct file *file, void *buf, size_t size,
33679 + /* todo: signal block and no wkq? */
33680 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
33682 + err = do_xino_fwrite(func, file, buf, size, pos);
33686 + * it breaks RLIMIT_FSIZE and normal user's limit,
33687 + * users should care about quota and real 'filesystem full.'
33690 + struct do_xino_fwrite_args args = {
33699 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
33700 + if (unlikely(wkq_err))
33707 +/* ---------------------------------------------------------------------- */
33710 + * create a new xinofile at the same place/path as @base_file.
33712 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
33714 + struct file *file;
33715 + struct dentry *base, *parent;
33716 + struct inode *dir, *delegated;
33717 + struct qstr *name;
33718 + struct path path;
33721 + base = base_file->f_path.dentry;
33722 + parent = base->d_parent; /* dir inode is locked */
33723 + dir = parent->d_inode;
33726 + file = ERR_PTR(-EINVAL);
33727 + name = &base->d_name;
33728 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
33729 + if (IS_ERR(path.dentry)) {
33730 + file = (void *)path.dentry;
33731 + pr_err("%pd lookup err %ld\n",
33732 + base, PTR_ERR(path.dentry));
33736 + /* no need to mnt_want_write() since we call dentry_open() later */
33737 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
33738 + if (unlikely(err)) {
33739 + file = ERR_PTR(err);
33740 + pr_err("%pd create err %d\n", base, err);
33744 + path.mnt = base_file->f_path.mnt;
33745 + file = vfsub_dentry_open(&path,
33746 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
33747 + /* | __FMODE_NONOTIFY */);
33748 + if (IS_ERR(file)) {
33749 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
33753 + delegated = NULL;
33754 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
33755 + if (unlikely(err == -EWOULDBLOCK)) {
33756 + pr_warn("cannot retry for NFSv4 delegation"
33757 + " for an internal unlink\n");
33760 + if (unlikely(err)) {
33761 + pr_err("%pd unlink err %d\n", base, err);
33766 + /* no one can touch copy_src xino */
33767 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
33768 + if (unlikely(err)) {
33769 + pr_err("%pd copy err %d\n", base, err);
33773 + goto out_dput; /* success */
33777 + file = ERR_PTR(err);
33779 + dput(path.dentry);
33784 +struct au_xino_lock_dir {
33785 + struct au_hinode *hdir;
33786 + struct dentry *parent;
33787 + struct mutex *mtx;
33790 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
33791 + struct au_xino_lock_dir *ldir)
33793 + aufs_bindex_t brid, bindex;
33795 + ldir->hdir = NULL;
33797 + brid = au_xino_brid(sb);
33799 + bindex = au_br_index(sb, brid);
33800 + if (bindex >= 0) {
33801 + ldir->hdir = au_hi(sb->s_root->d_inode, bindex);
33802 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
33804 + ldir->parent = dget_parent(xino->f_path.dentry);
33805 + ldir->mtx = &ldir->parent->d_inode->i_mutex;
33806 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
33810 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
33813 + au_hn_imtx_unlock(ldir->hdir);
33815 + mutex_unlock(ldir->mtx);
33816 + dput(ldir->parent);
33820 +/* ---------------------------------------------------------------------- */
33822 +/* trucate xino files asynchronously */
33824 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
33827 + unsigned long jiffy;
33829 + aufs_bindex_t bi, bend;
33830 + struct kstatfs *st;
33831 + struct au_branch *br;
33832 + struct file *new_xino, *file;
33833 + struct super_block *h_sb;
33834 + struct au_xino_lock_dir ldir;
33837 + st = kzalloc(sizeof(*st), GFP_NOFS);
33838 + if (unlikely(!st))
33842 + bend = au_sbend(sb);
33843 + if (unlikely(bindex < 0 || bend < bindex))
33845 + br = au_sbr(sb, bindex);
33846 + file = br->br_xino.xi_file;
33850 + err = vfs_statfs(&file->f_path, st);
33851 + if (unlikely(err))
33852 + AuErr1("statfs err %d, ignored\n", err);
33854 + blocks = file_inode(file)->i_blocks;
33855 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33856 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
33858 + au_xino_lock_dir(sb, file, &ldir);
33859 + /* mnt_want_write() is unnecessary here */
33860 + new_xino = au_xino_create2(file, file);
33861 + au_xino_unlock_dir(&ldir);
33862 + err = PTR_ERR(new_xino);
33863 + if (IS_ERR(new_xino)) {
33864 + pr_err("err %d, ignored\n", err);
33869 + br->br_xino.xi_file = new_xino;
33871 + h_sb = au_br_sb(br);
33872 + for (bi = 0; bi <= bend; bi++) {
33873 + if (unlikely(bi == bindex))
33875 + br = au_sbr(sb, bi);
33876 + if (au_br_sb(br) != h_sb)
33879 + fput(br->br_xino.xi_file);
33880 + br->br_xino.xi_file = new_xino;
33881 + get_file(new_xino);
33884 + err = vfs_statfs(&new_xino->f_path, st);
33886 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33887 + bindex, (u64)file_inode(new_xino)->i_blocks,
33888 + st->f_bfree, st->f_blocks);
33889 + if (file_inode(new_xino)->i_blocks < blocks)
33890 + au_sbi(sb)->si_xino_jiffy = jiffy;
33892 + AuErr1("statfs err %d, ignored\n", err);
33900 +struct xino_do_trunc_args {
33901 + struct super_block *sb;
33902 + struct au_branch *br;
33905 +static void xino_do_trunc(void *_args)
33907 + struct xino_do_trunc_args *args = _args;
33908 + struct super_block *sb;
33909 + struct au_branch *br;
33910 + struct inode *dir;
33912 + aufs_bindex_t bindex;
33916 + dir = sb->s_root->d_inode;
33919 + si_noflush_write_lock(sb);
33920 + ii_read_lock_parent(dir);
33921 + bindex = au_br_index(sb, br->br_id);
33922 + err = au_xino_trunc(sb, bindex);
33923 + ii_read_unlock(dir);
33924 + if (unlikely(err))
33925 + pr_warn("err b%d, (%d)\n", bindex, err);
33926 + atomic_dec(&br->br_xino_running);
33927 + atomic_dec(&br->br_count);
33928 + si_write_unlock(sb);
33929 + au_nwt_done(&au_sbi(sb)->si_nowait);
33933 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
33936 + struct kstatfs st;
33937 + struct au_sbinfo *sbinfo;
33939 + /* todo: si_xino_expire and the ratio should be customizable */
33940 + sbinfo = au_sbi(sb);
33941 + if (time_before(jiffies,
33942 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
33945 + /* truncation border */
33946 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
33947 + if (unlikely(err)) {
33948 + AuErr1("statfs err %d, ignored\n", err);
33951 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
33957 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
33959 + struct xino_do_trunc_args *args;
33962 + if (!xino_trunc_test(sb, br))
33965 + if (atomic_inc_return(&br->br_xino_running) > 1)
33968 + /* lock and kfree() will be called in trunc_xino() */
33969 + args = kmalloc(sizeof(*args), GFP_NOFS);
33970 + if (unlikely(!args)) {
33971 + AuErr1("no memory\n");
33975 + atomic_inc(&br->br_count);
33978 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
33980 + return; /* success */
33982 + pr_err("wkq %d\n", wkq_err);
33983 + atomic_dec(&br->br_count);
33988 + atomic_dec(&br->br_xino_running);
33991 +/* ---------------------------------------------------------------------- */
33993 +static int au_xino_do_write(au_writef_t write, struct file *file,
33994 + ino_t h_ino, ino_t ino)
34000 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34001 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34004 + pos *= sizeof(ino);
34005 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34006 + if (sz == sizeof(ino))
34007 + return 0; /* success */
34009 + AuIOErr("write failed (%zd)\n", sz);
34014 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34015 + * at the position of @h_ino.
34016 + * even if @ino is zero, it is written to the xinofile and means no entry.
34017 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34018 + * try truncating it.
34020 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34024 + unsigned int mnt_flags;
34025 + struct au_branch *br;
34027 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34028 + || ((loff_t)-1) > 0);
34029 + SiMustAnyLock(sb);
34031 + mnt_flags = au_mntflags(sb);
34032 + if (!au_opt_test(mnt_flags, XINO))
34035 + br = au_sbr(sb, bindex);
34036 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34039 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34040 + && au_test_fs_trunc_xino(au_br_sb(br)))
34041 + xino_try_trunc(sb, br);
34042 + return 0; /* success */
34045 + AuIOErr("write failed (%d)\n", err);
34049 +/* ---------------------------------------------------------------------- */
34051 +/* aufs inode number bitmap */
34053 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
34054 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
34058 + AuDebugOn(bit < 0 || page_bits <= bit);
34059 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
34063 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
34065 + AuDebugOn(ino < AUFS_FIRST_INO);
34066 + ino -= AUFS_FIRST_INO;
34067 + *pindex = ino / page_bits;
34068 + *bit = ino % page_bits;
34071 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
34076 + struct au_sbinfo *sbinfo;
34077 + struct file *xib;
34078 + unsigned long *p;
34080 + sbinfo = au_sbi(sb);
34081 + MtxMustLock(&sbinfo->si_xib_mtx);
34082 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
34083 + || !au_opt_test(sbinfo->si_mntflags, XINO));
34085 + if (pindex == sbinfo->si_xib_last_pindex)
34088 + xib = sbinfo->si_xib;
34089 + p = sbinfo->si_xib_buf;
34090 + pos = sbinfo->si_xib_last_pindex;
34091 + pos *= PAGE_SIZE;
34092 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34093 + if (unlikely(sz != PAGE_SIZE))
34097 + pos *= PAGE_SIZE;
34098 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
34099 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
34101 + memset(p, 0, PAGE_SIZE);
34102 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34104 + if (sz == PAGE_SIZE) {
34105 + sbinfo->si_xib_last_pindex = pindex;
34106 + return 0; /* success */
34110 + AuIOErr1("write failed (%zd)\n", sz);
34117 +/* ---------------------------------------------------------------------- */
34119 +static void au_xib_clear_bit(struct inode *inode)
34122 + unsigned long pindex;
34123 + struct super_block *sb;
34124 + struct au_sbinfo *sbinfo;
34126 + AuDebugOn(inode->i_nlink);
34128 + sb = inode->i_sb;
34129 + xib_calc_bit(inode->i_ino, &pindex, &bit);
34130 + AuDebugOn(page_bits <= bit);
34131 + sbinfo = au_sbi(sb);
34132 + mutex_lock(&sbinfo->si_xib_mtx);
34133 + err = xib_pindex(sb, pindex);
34135 + clear_bit(bit, sbinfo->si_xib_buf);
34136 + sbinfo->si_xib_next_bit = bit;
34138 + mutex_unlock(&sbinfo->si_xib_mtx);
34141 +/* for s_op->delete_inode() */
34142 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
34145 + unsigned int mnt_flags;
34146 + aufs_bindex_t bindex, bend, bi;
34147 + unsigned char try_trunc;
34148 + struct au_iinfo *iinfo;
34149 + struct super_block *sb;
34150 + struct au_hinode *hi;
34151 + struct inode *h_inode;
34152 + struct au_branch *br;
34153 + au_writef_t xwrite;
34155 + sb = inode->i_sb;
34156 + mnt_flags = au_mntflags(sb);
34157 + if (!au_opt_test(mnt_flags, XINO)
34158 + || inode->i_ino == AUFS_ROOT_INO)
34162 + au_xigen_inc(inode);
34163 + au_xib_clear_bit(inode);
34166 + iinfo = au_ii(inode);
34170 + bindex = iinfo->ii_bstart;
34174 + xwrite = au_sbi(sb)->si_xwrite;
34175 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
34176 + hi = iinfo->ii_hinode + bindex;
34177 + bend = iinfo->ii_bend;
34178 + for (; bindex <= bend; bindex++, hi++) {
34179 + h_inode = hi->hi_inode;
34181 + || (!unlinked && h_inode->i_nlink))
34184 + /* inode may not be revalidated */
34185 + bi = au_br_index(sb, hi->hi_id);
34189 + br = au_sbr(sb, bi);
34190 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
34191 + h_inode->i_ino, /*ino*/0);
34192 + if (!err && try_trunc
34193 + && au_test_fs_trunc_xino(au_br_sb(br)))
34194 + xino_try_trunc(sb, br);
34198 +/* get an unused inode number from bitmap */
34199 +ino_t au_xino_new_ino(struct super_block *sb)
34202 + unsigned long *p, pindex, ul, pend;
34203 + struct au_sbinfo *sbinfo;
34204 + struct file *file;
34205 + int free_bit, err;
34207 + if (!au_opt_test(au_mntflags(sb), XINO))
34208 + return iunique(sb, AUFS_FIRST_INO);
34210 + sbinfo = au_sbi(sb);
34211 + mutex_lock(&sbinfo->si_xib_mtx);
34212 + p = sbinfo->si_xib_buf;
34213 + free_bit = sbinfo->si_xib_next_bit;
34214 + if (free_bit < page_bits && !test_bit(free_bit, p))
34215 + goto out; /* success */
34216 + free_bit = find_first_zero_bit(p, page_bits);
34217 + if (free_bit < page_bits)
34218 + goto out; /* success */
34220 + pindex = sbinfo->si_xib_last_pindex;
34221 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
34222 + err = xib_pindex(sb, ul);
34223 + if (unlikely(err))
34225 + free_bit = find_first_zero_bit(p, page_bits);
34226 + if (free_bit < page_bits)
34227 + goto out; /* success */
34230 + file = sbinfo->si_xib;
34231 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
34232 + for (ul = pindex + 1; ul <= pend; ul++) {
34233 + err = xib_pindex(sb, ul);
34234 + if (unlikely(err))
34236 + free_bit = find_first_zero_bit(p, page_bits);
34237 + if (free_bit < page_bits)
34238 + goto out; /* success */
34243 + set_bit(free_bit, p);
34244 + sbinfo->si_xib_next_bit = free_bit + 1;
34245 + pindex = sbinfo->si_xib_last_pindex;
34246 + mutex_unlock(&sbinfo->si_xib_mtx);
34247 + ino = xib_calc_ino(pindex, free_bit);
34248 + AuDbg("i%lu\n", (unsigned long)ino);
34251 + mutex_unlock(&sbinfo->si_xib_mtx);
34257 + * read @ino from xinofile for the specified branch{@sb, @bindex}
34258 + * at the position of @h_ino.
34259 + * if @ino does not exist and @do_new is true, get new one.
34261 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34267 + struct file *file;
34268 + struct au_sbinfo *sbinfo;
34271 + if (!au_opt_test(au_mntflags(sb), XINO))
34272 + return 0; /* no xino */
34275 + sbinfo = au_sbi(sb);
34277 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
34278 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34281 + pos *= sizeof(*ino);
34283 + file = au_sbr(sb, bindex)->br_xino.xi_file;
34284 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
34285 + return 0; /* no ino */
34287 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
34288 + if (sz == sizeof(*ino))
34289 + return 0; /* success */
34292 + if (unlikely(sz >= 0)) {
34294 + AuIOErr("xino read error (%zd)\n", sz);
34300 +/* ---------------------------------------------------------------------- */
34302 +/* create and set a new xino file */
34304 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
34306 + struct file *file;
34307 + struct dentry *h_parent, *d;
34308 + struct inode *h_dir, *inode;
34312 + * at mount-time, and the xino file is the default path,
34313 + * hnotify is disabled so we have no notify events to ignore.
34314 + * when a user specified the xino, we cannot get au_hdir to be ignored.
34316 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34317 + /* | __FMODE_NONOTIFY */,
34318 + S_IRUGO | S_IWUGO);
34319 + if (IS_ERR(file)) {
34321 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
34325 + /* keep file count */
34327 + inode = file_inode(file);
34328 + h_parent = dget_parent(file->f_path.dentry);
34329 + h_dir = h_parent->d_inode;
34330 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
34331 + /* mnt_want_write() is unnecessary here */
34332 + /* no delegation since it is just created */
34333 + if (inode->i_nlink)
34334 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
34336 + mutex_unlock(&h_dir->i_mutex);
34338 + if (unlikely(err)) {
34340 + pr_err("unlink %s(%d)\n", fname, err);
34345 + d = file->f_path.dentry;
34346 + if (unlikely(sb == d->d_sb)) {
34348 + pr_err("%s must be outside\n", fname);
34351 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
34353 + pr_err("xino doesn't support %s(%s)\n",
34354 + fname, au_sbtype(d->d_sb));
34357 + return file; /* success */
34361 + file = ERR_PTR(err);
34366 + * find another branch who is on the same filesystem of the specified
34367 + * branch{@btgt}. search until @bend.
34369 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
34370 + aufs_bindex_t bend)
34372 + aufs_bindex_t bindex;
34373 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
34375 + for (bindex = 0; bindex < btgt; bindex++)
34376 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34378 + for (bindex++; bindex <= bend; bindex++)
34379 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34384 +/* ---------------------------------------------------------------------- */
34387 + * initialize the xinofile for the specified branch @br
34388 + * at the place/path where @base_file indicates.
34389 + * test whether another branch is on the same filesystem or not,
34390 + * if @do_test is true.
34392 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
34393 + struct file *base_file, int do_test)
34397 + aufs_bindex_t bend, bindex;
34398 + struct au_branch *shared_br, *b;
34399 + struct file *file;
34400 + struct super_block *tgt_sb;
34402 + shared_br = NULL;
34403 + bend = au_sbend(sb);
34405 + tgt_sb = au_br_sb(br);
34406 + for (bindex = 0; bindex <= bend; bindex++) {
34407 + b = au_sbr(sb, bindex);
34408 + if (tgt_sb == au_br_sb(b)) {
34415 + if (!shared_br || !shared_br->br_xino.xi_file) {
34416 + struct au_xino_lock_dir ldir;
34418 + au_xino_lock_dir(sb, base_file, &ldir);
34419 + /* mnt_want_write() is unnecessary here */
34420 + file = au_xino_create2(base_file, NULL);
34421 + au_xino_unlock_dir(&ldir);
34422 + err = PTR_ERR(file);
34423 + if (IS_ERR(file))
34425 + br->br_xino.xi_file = file;
34427 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
34428 + get_file(br->br_xino.xi_file);
34431 + ino = AUFS_ROOT_INO;
34432 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34434 + if (unlikely(err)) {
34435 + fput(br->br_xino.xi_file);
34436 + br->br_xino.xi_file = NULL;
34443 +/* ---------------------------------------------------------------------- */
34445 +/* trucate a xino bitmap file */
34448 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
34452 + unsigned long pindex;
34453 + loff_t pos, pend;
34454 + struct au_sbinfo *sbinfo;
34457 + unsigned long *p;
34460 + sbinfo = au_sbi(sb);
34461 + MtxMustLock(&sbinfo->si_xib_mtx);
34462 + p = sbinfo->si_xib_buf;
34463 + func = sbinfo->si_xread;
34464 + pend = vfsub_f_size_read(file);
34466 + while (pos < pend) {
34467 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
34469 + if (unlikely(sz <= 0))
34473 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
34474 + if (unlikely(*ino < AUFS_FIRST_INO))
34477 + xib_calc_bit(*ino, &pindex, &bit);
34478 + AuDebugOn(page_bits <= bit);
34479 + err = xib_pindex(sb, pindex);
34491 +static int xib_restore(struct super_block *sb)
34494 + aufs_bindex_t bindex, bend;
34498 + page = (void *)__get_free_page(GFP_NOFS);
34499 + if (unlikely(!page))
34503 + bend = au_sbend(sb);
34504 + for (bindex = 0; !err && bindex <= bend; bindex++)
34505 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
34506 + err = do_xib_restore
34507 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
34509 + AuDbg("b%d\n", bindex);
34510 + free_page((unsigned long)page);
34516 +int au_xib_trunc(struct super_block *sb)
34521 + struct au_xino_lock_dir ldir;
34522 + struct au_sbinfo *sbinfo;
34523 + unsigned long *p;
34524 + struct file *file;
34526 + SiMustWriteLock(sb);
34529 + sbinfo = au_sbi(sb);
34530 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
34533 + file = sbinfo->si_xib;
34534 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
34537 + au_xino_lock_dir(sb, file, &ldir);
34538 + /* mnt_want_write() is unnecessary here */
34539 + file = au_xino_create2(sbinfo->si_xib, NULL);
34540 + au_xino_unlock_dir(&ldir);
34541 + err = PTR_ERR(file);
34542 + if (IS_ERR(file))
34544 + fput(sbinfo->si_xib);
34545 + sbinfo->si_xib = file;
34547 + p = sbinfo->si_xib_buf;
34548 + memset(p, 0, PAGE_SIZE);
34550 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
34551 + if (unlikely(sz != PAGE_SIZE)) {
34553 + AuIOErr("err %d\n", err);
34559 + mutex_lock(&sbinfo->si_xib_mtx);
34560 + /* mnt_want_write() is unnecessary here */
34561 + err = xib_restore(sb);
34562 + mutex_unlock(&sbinfo->si_xib_mtx);
34568 +/* ---------------------------------------------------------------------- */
34571 + * xino mount option handlers
34573 +static au_readf_t find_readf(struct file *h_file)
34575 + const struct file_operations *fop = h_file->f_op;
34578 + return fop->read;
34579 + if (fop->aio_read)
34580 + return do_sync_read;
34581 + if (fop->read_iter)
34582 + return new_sync_read;
34583 + return ERR_PTR(-ENOSYS);
34586 +static au_writef_t find_writef(struct file *h_file)
34588 + const struct file_operations *fop = h_file->f_op;
34591 + return fop->write;
34592 + if (fop->aio_write)
34593 + return do_sync_write;
34594 + if (fop->write_iter)
34595 + return new_sync_write;
34596 + return ERR_PTR(-ENOSYS);
34600 +static void xino_clear_xib(struct super_block *sb)
34602 + struct au_sbinfo *sbinfo;
34604 + SiMustWriteLock(sb);
34606 + sbinfo = au_sbi(sb);
34607 + sbinfo->si_xread = NULL;
34608 + sbinfo->si_xwrite = NULL;
34609 + if (sbinfo->si_xib)
34610 + fput(sbinfo->si_xib);
34611 + sbinfo->si_xib = NULL;
34612 + free_page((unsigned long)sbinfo->si_xib_buf);
34613 + sbinfo->si_xib_buf = NULL;
34616 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
34620 + struct au_sbinfo *sbinfo;
34621 + struct file *file;
34623 + SiMustWriteLock(sb);
34625 + sbinfo = au_sbi(sb);
34626 + file = au_xino_create2(base, sbinfo->si_xib);
34627 + err = PTR_ERR(file);
34628 + if (IS_ERR(file))
34630 + if (sbinfo->si_xib)
34631 + fput(sbinfo->si_xib);
34632 + sbinfo->si_xib = file;
34633 + sbinfo->si_xread = find_readf(file);
34634 + sbinfo->si_xwrite = find_writef(file);
34637 + if (!sbinfo->si_xib_buf)
34638 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
34639 + if (unlikely(!sbinfo->si_xib_buf))
34642 + sbinfo->si_xib_last_pindex = 0;
34643 + sbinfo->si_xib_next_bit = 0;
34644 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
34646 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
34647 + PAGE_SIZE, &pos);
34648 + if (unlikely(err != PAGE_SIZE))
34652 + goto out; /* success */
34655 + free_page((unsigned long)sbinfo->si_xib_buf);
34656 + sbinfo->si_xib_buf = NULL;
34660 + fput(sbinfo->si_xib);
34661 + sbinfo->si_xib = NULL;
34662 + sbinfo->si_xread = NULL;
34663 + sbinfo->si_xwrite = NULL;
34668 +/* xino for each branch */
34669 +static void xino_clear_br(struct super_block *sb)
34671 + aufs_bindex_t bindex, bend;
34672 + struct au_branch *br;
34674 + bend = au_sbend(sb);
34675 + for (bindex = 0; bindex <= bend; bindex++) {
34676 + br = au_sbr(sb, bindex);
34677 + if (!br || !br->br_xino.xi_file)
34680 + fput(br->br_xino.xi_file);
34681 + br->br_xino.xi_file = NULL;
34685 +static int au_xino_set_br(struct super_block *sb, struct file *base)
34689 + aufs_bindex_t bindex, bend, bshared;
34691 + struct file *old, *new;
34693 + struct au_branch *br;
34694 + struct inode *inode;
34695 + au_writef_t writef;
34697 + SiMustWriteLock(sb);
34700 + bend = au_sbend(sb);
34701 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
34702 + if (unlikely(!fpair))
34705 + inode = sb->s_root->d_inode;
34706 + ino = AUFS_ROOT_INO;
34707 + writef = au_sbi(sb)->si_xwrite;
34708 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34709 + br = au_sbr(sb, bindex);
34710 + bshared = is_sb_shared(sb, bindex, bindex - 1);
34711 + if (bshared >= 0) {
34712 + /* shared xino */
34713 + *p = fpair[bshared];
34714 + get_file(p->new);
34719 + p->old = br->br_xino.xi_file;
34720 + p->new = au_xino_create2(base, br->br_xino.xi_file);
34721 + err = PTR_ERR(p->new);
34722 + if (IS_ERR(p->new)) {
34728 + err = au_xino_do_write(writef, p->new,
34729 + au_h_iptr(inode, bindex)->i_ino, ino);
34730 + if (unlikely(err))
34734 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34735 + br = au_sbr(sb, bindex);
34736 + if (br->br_xino.xi_file)
34737 + fput(br->br_xino.xi_file);
34738 + get_file(p->new);
34739 + br->br_xino.xi_file = p->new;
34743 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
34753 +void au_xino_clr(struct super_block *sb)
34755 + struct au_sbinfo *sbinfo;
34757 + au_xigen_clr(sb);
34758 + xino_clear_xib(sb);
34759 + xino_clear_br(sb);
34760 + sbinfo = au_sbi(sb);
34761 + /* lvalue, do not call au_mntflags() */
34762 + au_opt_clr(sbinfo->si_mntflags, XINO);
34765 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
34768 + struct dentry *parent, *cur_parent;
34769 + struct qstr *dname, *cur_name;
34770 + struct file *cur_xino;
34771 + struct inode *dir;
34772 + struct au_sbinfo *sbinfo;
34774 + SiMustWriteLock(sb);
34777 + sbinfo = au_sbi(sb);
34778 + parent = dget_parent(xino->file->f_path.dentry);
34781 + dname = &xino->file->f_path.dentry->d_name;
34782 + cur_xino = sbinfo->si_xib;
34784 + cur_parent = dget_parent(cur_xino->f_path.dentry);
34785 + cur_name = &cur_xino->f_path.dentry->d_name;
34786 + skip = (cur_parent == parent
34787 + && au_qstreq(dname, cur_name));
34788 + dput(cur_parent);
34794 + au_opt_set(sbinfo->si_mntflags, XINO);
34795 + dir = parent->d_inode;
34796 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
34797 + /* mnt_want_write() is unnecessary here */
34798 + err = au_xino_set_xib(sb, xino->file);
34800 + err = au_xigen_set(sb, xino->file);
34802 + err = au_xino_set_br(sb, xino->file);
34803 + mutex_unlock(&dir->i_mutex);
34805 + goto out; /* success */
34808 + AuIOErr("failed creating xino(%d).\n", err);
34809 + au_xigen_clr(sb);
34810 + xino_clear_xib(sb);
34817 +/* ---------------------------------------------------------------------- */
34820 + * create a xinofile at the default place/path.
34822 +struct file *au_xino_def(struct super_block *sb)
34824 + struct file *file;
34826 + struct au_branch *br;
34827 + struct super_block *h_sb;
34828 + struct path path;
34829 + aufs_bindex_t bend, bindex, bwr;
34832 + bend = au_sbend(sb);
34834 + for (bindex = 0; bindex <= bend; bindex++) {
34835 + br = au_sbr(sb, bindex);
34836 + if (au_br_writable(br->br_perm)
34837 + && !au_test_fs_bad_xino(au_br_sb(br))) {
34844 + file = ERR_PTR(-ENOMEM);
34845 + page = (void *)__get_free_page(GFP_NOFS);
34846 + if (unlikely(!page))
34848 + path.mnt = au_br_mnt(br);
34849 + path.dentry = au_h_dptr(sb->s_root, bwr);
34850 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
34851 + file = (void *)p;
34852 + if (!IS_ERR(p)) {
34853 + strcat(p, "/" AUFS_XINO_FNAME);
34854 + AuDbg("%s\n", p);
34855 + file = au_xino_create(sb, p, /*silent*/0);
34856 + if (!IS_ERR(file))
34857 + au_xino_brid_set(sb, br->br_id);
34859 + free_page((unsigned long)page);
34861 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
34862 + if (IS_ERR(file))
34864 + h_sb = file->f_path.dentry->d_sb;
34865 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
34866 + pr_err("xino doesn't support %s(%s)\n",
34867 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
34869 + file = ERR_PTR(-EINVAL);
34871 + if (!IS_ERR(file))
34872 + au_xino_brid_set(sb, -1);
34879 +/* ---------------------------------------------------------------------- */
34881 +int au_xino_path(struct seq_file *seq, struct file *file)
34885 + err = au_seq_path(seq, &file->f_path);
34886 + if (unlikely(err < 0))
34890 +#define Deleted "\\040(deleted)"
34891 + seq->count -= sizeof(Deleted) - 1;
34892 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
34893 + sizeof(Deleted) - 1));
34899 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
34900 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
34901 +++ linux/include/uapi/linux/aufs_type.h 2015-06-22 08:29:23.710091096 +0200
34904 + * Copyright (C) 2005-2015 Junjiro R. Okajima
34906 + * This program, aufs is free software; you can redistribute it and/or modify
34907 + * it under the terms of the GNU General Public License as published by
34908 + * the Free Software Foundation; either version 2 of the License, or
34909 + * (at your option) any later version.
34911 + * This program is distributed in the hope that it will be useful,
34912 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34913 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34914 + * GNU General Public License for more details.
34916 + * You should have received a copy of the GNU General Public License
34917 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34920 +#ifndef __AUFS_TYPE_H__
34921 +#define __AUFS_TYPE_H__
34923 +#define AUFS_NAME "aufs"
34927 + * define it before including all other headers.
34928 + * sched.h may use pr_* macros before defining "current", so define the
34929 + * no-current version first, and re-define later.
34931 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
34932 +#include <linux/sched.h>
34934 +#define pr_fmt(fmt) \
34935 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
34936 + (int)sizeof(current->comm), current->comm, current->pid
34938 +#include <stdint.h>
34939 +#include <sys/types.h>
34940 +#endif /* __KERNEL__ */
34942 +#include <linux/limits.h>
34944 +#define AUFS_VERSION "3.x-rcN-20150622"
34946 +/* todo? move this to linux-2.6.19/include/magic.h */
34947 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
34949 +/* ---------------------------------------------------------------------- */
34951 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
34952 +typedef int8_t aufs_bindex_t;
34953 +#define AUFS_BRANCH_MAX 127
34955 +typedef int16_t aufs_bindex_t;
34956 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
34957 +#define AUFS_BRANCH_MAX 511
34958 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
34959 +#define AUFS_BRANCH_MAX 1023
34960 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
34961 +#define AUFS_BRANCH_MAX 32767
34966 +#ifndef AUFS_BRANCH_MAX
34967 +#error unknown CONFIG_AUFS_BRANCH_MAX value
34969 +#endif /* __KERNEL__ */
34971 +/* ---------------------------------------------------------------------- */
34973 +#define AUFS_FSTYPE AUFS_NAME
34975 +#define AUFS_ROOT_INO 2
34976 +#define AUFS_FIRST_INO 11
34978 +#define AUFS_WH_PFX ".wh."
34979 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
34980 +#define AUFS_WH_TMP_LEN 4
34981 +/* a limit for rmdir/rename a dir and copyup */
34982 +#define AUFS_MAX_NAMELEN (NAME_MAX \
34983 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
34985 + - AUFS_WH_TMP_LEN) /* hex */
34986 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
34987 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
34988 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
34989 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
34990 +#define AUFS_DIRWH_DEF 3
34991 +#define AUFS_RDCACHE_DEF 10 /* seconds */
34992 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
34993 +#define AUFS_RDBLK_DEF 512 /* bytes */
34994 +#define AUFS_RDHASH_DEF 32
34995 +#define AUFS_WKQ_NAME AUFS_NAME "d"
34996 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
34997 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
34998 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
34999 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
35001 +/* pseudo-link maintenace under /proc */
35002 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
35003 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
35004 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
35006 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
35007 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
35009 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
35010 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
35011 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
35013 +/* doubly whiteouted */
35014 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
35015 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
35016 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
35018 +/* branch permissions and attributes */
35019 +#define AUFS_BRPERM_RW "rw"
35020 +#define AUFS_BRPERM_RO "ro"
35021 +#define AUFS_BRPERM_RR "rr"
35022 +#define AUFS_BRATTR_COO_REG "coo_reg"
35023 +#define AUFS_BRATTR_COO_ALL "coo_all"
35024 +#define AUFS_BRATTR_FHSM "fhsm"
35025 +#define AUFS_BRATTR_UNPIN "unpin"
35026 +#define AUFS_BRATTR_ICEX "icex"
35027 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
35028 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
35029 +#define AUFS_BRATTR_ICEX_TR "icextr"
35030 +#define AUFS_BRATTR_ICEX_USR "icexusr"
35031 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
35032 +#define AUFS_BRRATTR_WH "wh"
35033 +#define AUFS_BRWATTR_NLWH "nolwh"
35034 +#define AUFS_BRWATTR_MOO "moo"
35036 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
35037 +#define AuBrPerm_RO (1 << 1) /* readonly */
35038 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
35039 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
35041 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
35042 +#define AuBrAttr_COO_ALL (1 << 4)
35043 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
35045 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
35046 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
35047 + branch. meaningless since
35048 + linux-3.18-rc1 */
35050 +/* ignore error in copying XATTR */
35051 +#define AuBrAttr_ICEX_SEC (1 << 7)
35052 +#define AuBrAttr_ICEX_SYS (1 << 8)
35053 +#define AuBrAttr_ICEX_TR (1 << 9)
35054 +#define AuBrAttr_ICEX_USR (1 << 10)
35055 +#define AuBrAttr_ICEX_OTH (1 << 11)
35056 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
35057 + | AuBrAttr_ICEX_SYS \
35058 + | AuBrAttr_ICEX_TR \
35059 + | AuBrAttr_ICEX_USR \
35060 + | AuBrAttr_ICEX_OTH)
35062 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
35063 +#define AuBrRAttr_Mask AuBrRAttr_WH
35065 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
35066 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
35067 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
35069 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
35071 +/* #warning test userspace */
35073 +#ifndef CONFIG_AUFS_FHSM
35074 +#undef AuBrAttr_FHSM
35075 +#define AuBrAttr_FHSM 0
35077 +#ifndef CONFIG_AUFS_XATTR
35078 +#undef AuBrAttr_ICEX
35079 +#define AuBrAttr_ICEX 0
35080 +#undef AuBrAttr_ICEX_SEC
35081 +#define AuBrAttr_ICEX_SEC 0
35082 +#undef AuBrAttr_ICEX_SYS
35083 +#define AuBrAttr_ICEX_SYS 0
35084 +#undef AuBrAttr_ICEX_TR
35085 +#define AuBrAttr_ICEX_TR 0
35086 +#undef AuBrAttr_ICEX_USR
35087 +#define AuBrAttr_ICEX_USR 0
35088 +#undef AuBrAttr_ICEX_OTH
35089 +#define AuBrAttr_ICEX_OTH 0
35093 +/* the longest combination */
35094 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
35095 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
35096 + "+" AUFS_BRATTR_COO_REG \
35097 + "+" AUFS_BRATTR_FHSM \
35098 + "+" AUFS_BRATTR_UNPIN \
35099 + "+" AUFS_BRATTR_ICEX_SEC \
35100 + "+" AUFS_BRATTR_ICEX_SYS \
35101 + "+" AUFS_BRATTR_ICEX_USR \
35102 + "+" AUFS_BRATTR_ICEX_OTH \
35103 + "+" AUFS_BRWATTR_NLWH)
35106 + char a[AuBrPermStrSz];
35107 +} au_br_perm_str_t;
35109 +static inline int au_br_writable(int brperm)
35111 + return brperm & AuBrPerm_RW;
35114 +static inline int au_br_whable(int brperm)
35116 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
35119 +static inline int au_br_wh_linkable(int brperm)
35121 + return !(brperm & AuBrWAttr_NoLinkWH);
35124 +static inline int au_br_cmoo(int brperm)
35126 + return brperm & AuBrAttr_CMOO_Mask;
35129 +static inline int au_br_fhsm(int brperm)
35131 + return brperm & AuBrAttr_FHSM;
35134 +/* ---------------------------------------------------------------------- */
35138 + /* readdir in userspace */
35142 + AuCtl_WBR_FD, /* pathconf wrapper */
35143 + AuCtl_IBUSY, /* busy inode */
35144 + AuCtl_MVDOWN, /* move-down */
35145 + AuCtl_BR, /* info about branches */
35146 + AuCtl_FHSM_FD /* connection for fhsm */
35149 +/* borrowed from linux/include/linux/kernel.h */
35151 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
35152 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
35155 +/* borrowed from linux/include/linux/compiler-gcc3.h */
35157 +#define __aligned(x) __attribute__((aligned(x)))
35162 +#define __packed __attribute__((packed))
35166 +struct au_rdu_cookie {
35171 + uint32_t generation;
35174 +struct au_rdu_ent {
35183 +static inline int au_rdu_len(int nlen)
35185 + /* include the terminating NULL */
35186 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
35187 + sizeof(uint64_t));
35190 +union au_rdu_ent_ul {
35191 + struct au_rdu_ent __user *e;
35203 + uint64_t sz; /* AuCtl_RDU */
35204 + uint64_t nent; /* AuCtl_RDU_INO */
35206 + union au_rdu_ent_ul ent;
35207 + uint16_t verify[AufsCtlRduV_End];
35209 + /* input/output */
35213 + union au_rdu_ent_ul tail;
35214 + /* number of entries which were added in a single call */
35219 + struct au_rdu_cookie cookie;
35222 +/* ---------------------------------------------------------------------- */
35224 +struct aufs_wbr_fd {
35229 +/* ---------------------------------------------------------------------- */
35231 +struct aufs_ibusy {
35232 + uint64_t ino, h_ino;
35236 +/* ---------------------------------------------------------------------- */
35238 +/* error code for move-down */
35239 +/* the actual message strings are implemented in aufs-util.git */
35241 + EAU_MVDOWN_OPAQUE = 1,
35242 + EAU_MVDOWN_WHITEOUT,
35243 + EAU_MVDOWN_UPPER,
35244 + EAU_MVDOWN_BOTTOM,
35245 + EAU_MVDOWN_NOUPPER,
35246 + EAU_MVDOWN_NOLOWERBR,
35250 +/* flags for move-down */
35251 +#define AUFS_MVDOWN_DMSG 1
35252 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
35253 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
35254 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
35255 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
35256 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
35257 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
35258 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
35259 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
35260 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
35261 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
35262 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
35263 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
35265 +/* index for move-down */
35267 + AUFS_MVDOWN_UPPER,
35268 + AUFS_MVDOWN_LOWER,
35269 + AUFS_MVDOWN_NARRAY
35273 + * additional info of move-down
35274 + * number of free blocks and inodes.
35275 + * subset of struct kstatfs, but smaller and always 64bit.
35277 +struct aufs_stfs {
35278 + uint64_t f_blocks;
35279 + uint64_t f_bavail;
35280 + uint64_t f_files;
35281 + uint64_t f_ffree;
35284 +struct aufs_stbr {
35285 + int16_t brid; /* optional input */
35286 + int16_t bindex; /* output */
35287 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
35290 +struct aufs_mvdown {
35291 + uint32_t flags; /* input/output */
35292 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
35293 + int8_t au_errno; /* output */
35296 +/* ---------------------------------------------------------------------- */
35298 +union aufs_brinfo {
35299 + /* PATH_MAX may differ between kernel-space and user-space */
35300 + char _spacer[4096];
35308 +/* ---------------------------------------------------------------------- */
35310 +#define AuCtlType 'A'
35311 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
35312 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
35313 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
35314 + struct aufs_wbr_fd)
35315 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
35316 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
35317 + struct aufs_mvdown)
35318 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
35319 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
35321 +#endif /* __AUFS_TYPE_H__ */