3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 6ce72d8..4aa31ea 100644
7 @@ -221,6 +221,7 @@ source "fs/pstore/Kconfig"
8 source "fs/sysv/Kconfig"
9 source "fs/ufs/Kconfig"
10 source "fs/exofs/Kconfig"
11 +source "fs/aufs/Kconfig"
13 endif # MISC_FILESYSTEMS
15 diff --git a/fs/Makefile b/fs/Makefile
16 index 79f5225..a7c7f16 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 c2e5d6c..d736c11 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -59,6 +59,7 @@ header-y += atmsvc.h
30 header-y += atm_zatm.h
32 +header-y += aufs_type.h
33 header-y += auto_fs4.h
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index 233f834..c250892 100644
42 @@ -2029,6 +2029,19 @@ 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://github.com/sfjro/aufs4-linux.git
53 +F: Documentation/filesystems/aufs/
54 +F: Documentation/ABI/testing/debugfs-aufs
55 +F: Documentation/ABI/testing/sysfs-aufs
57 +F: include/uapi/linux/aufs_type.h
59 AUXILIARY DISPLAY DRIVERS
60 M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com>
61 W: http://miguelojeda.es/auxdisplay.htm
62 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
63 index 423f4ca..abfdd2b 100644
64 --- a/drivers/block/loop.c
65 +++ b/drivers/block/loop.c
66 @@ -706,6 +706,24 @@ static inline int is_loop_device(struct file *file)
67 return i && S_ISBLK(i->i_mode) && MAJOR(i->i_rdev) == LOOP_MAJOR;
72 + * no get/put for file.
74 +struct file *loop_backing_file(struct super_block *sb)
77 + struct loop_device *l;
80 + if (MAJOR(sb->s_dev) == LOOP_MAJOR) {
81 + l = sb->s_bdev->bd_disk->private_data;
82 + ret = l->lo_backing_file;
86 +EXPORT_SYMBOL(loop_backing_file);
88 /* loop sysfs attributes */
90 static ssize_t loop_attr_show(struct device *dev, char *page,
91 diff --git a/fs/dcache.c b/fs/dcache.c
92 index 5c33aeb..8aa7f26 100644
95 @@ -1167,7 +1167,7 @@ enum d_walk_ret {
97 * The @enter() and @finish() callbacks are called with d_lock held.
99 -static void d_walk(struct dentry *parent, void *data,
100 +void d_walk(struct dentry *parent, void *data,
101 enum d_walk_ret (*enter)(void *, struct dentry *),
102 void (*finish)(void *))
104 diff --git a/fs/read_write.c b/fs/read_write.c
105 index 819ef3f..fd0414e 100644
106 --- a/fs/read_write.c
107 +++ b/fs/read_write.c
108 @@ -494,6 +494,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
110 EXPORT_SYMBOL(__vfs_write);
112 +vfs_readf_t vfs_readf(struct file *file)
114 + const struct file_operations *fop = file->f_op;
118 + if (fop->read_iter)
119 + return new_sync_read;
120 + return ERR_PTR(-ENOSYS);
123 +vfs_writef_t vfs_writef(struct file *file)
125 + const struct file_operations *fop = file->f_op;
129 + if (fop->write_iter)
130 + return new_sync_write;
131 + return ERR_PTR(-ENOSYS);
134 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
137 diff --git a/fs/splice.c b/fs/splice.c
138 index 4cf700d..30a091d 100644
141 @@ -1110,8 +1110,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
143 * Attempt to initiate a splice from pipe to file.
145 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
146 - loff_t *ppos, size_t len, unsigned int flags)
147 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
148 + loff_t *ppos, size_t len, unsigned int flags)
150 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
151 loff_t *, size_t, unsigned int);
152 @@ -1127,9 +1127,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
154 * Attempt to initiate a splice from a file to a pipe.
156 -static long do_splice_to(struct file *in, loff_t *ppos,
157 - struct pipe_inode_info *pipe, size_t len,
158 - unsigned int flags)
159 +long do_splice_to(struct file *in, loff_t *ppos,
160 + struct pipe_inode_info *pipe, size_t len,
161 + unsigned int flags)
163 ssize_t (*splice_read)(struct file *, loff_t *,
164 struct pipe_inode_info *, size_t, unsigned int);
165 diff --git a/include/linux/file.h b/include/linux/file.h
166 index f87d308..9a290b3 100644
167 --- a/include/linux/file.h
168 +++ b/include/linux/file.h
169 @@ -19,6 +19,7 @@ struct dentry;
171 extern struct file *alloc_file(struct path *, fmode_t mode,
172 const struct file_operations *fop);
173 +extern struct file *get_empty_filp(void);
175 static inline void fput_light(struct file *file, int fput_needed)
177 diff --git a/include/linux/fs.h b/include/linux/fs.h
178 index 3aa5142..8d48506 100644
179 --- a/include/linux/fs.h
180 +++ b/include/linux/fs.h
181 @@ -1672,6 +1672,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
182 struct iovec *fast_pointer,
183 struct iovec **ret_pointer);
185 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
186 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
188 +vfs_readf_t vfs_readf(struct file *file);
189 +vfs_writef_t vfs_writef(struct file *file);
191 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
192 extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
193 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
194 diff --git a/include/linux/splice.h b/include/linux/splice.h
195 index da2751d..2e0fca6 100644
196 --- a/include/linux/splice.h
197 +++ b/include/linux/splice.h
198 @@ -83,4 +83,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
199 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
201 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
203 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
204 + loff_t *ppos, size_t len, unsigned int flags);
205 +extern long do_splice_to(struct file *in, loff_t *ppos,
206 + struct pipe_inode_info *pipe, size_t len,
207 + unsigned int flags);
211 diff --git a/fs/proc/base.c b/fs/proc/base.c
212 index 4bd5d31..aa41f2a 100644
215 @@ -1921,7 +1921,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
216 down_read(&mm->mmap_sem);
217 vma = find_exact_vma(mm, vm_start, vm_end);
218 if (vma && vma->vm_file) {
219 - *path = vma->vm_file->f_path;
220 + *path = vma_pr_or_file(vma)->f_path;
224 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
225 index f8595e8..cb8eda0 100644
226 --- a/fs/proc/nommu.c
227 +++ b/fs/proc/nommu.c
228 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
229 file = region->vm_file;
232 - struct inode *inode = file_inode(region->vm_file);
233 + struct inode *inode;
235 + file = vmr_pr_or_file(region);
236 + inode = file_inode(file);
237 dev = inode->i_sb->s_dev;
240 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
241 index 187b3b5..e03793e 100644
242 --- a/fs/proc/task_mmu.c
243 +++ b/fs/proc/task_mmu.c
244 @@ -281,7 +281,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
245 const char *name = NULL;
248 - struct inode *inode = file_inode(vma->vm_file);
249 + struct inode *inode;
251 + file = vma_pr_or_file(vma);
252 + inode = file_inode(file);
253 dev = inode->i_sb->s_dev;
255 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
256 @@ -1505,7 +1508,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
257 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
258 struct vm_area_struct *vma = v;
259 struct numa_maps *md = &numa_priv->md;
260 - struct file *file = vma->vm_file;
261 + struct file *file = vma_pr_or_file(vma);
262 struct mm_struct *mm = vma->vm_mm;
263 struct mm_walk walk = {
264 .hugetlb_entry = gather_hugetlb_stats,
265 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
266 index e0d64c9..7aa92db 100644
267 --- a/fs/proc/task_nommu.c
268 +++ b/fs/proc/task_nommu.c
269 @@ -160,7 +160,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
273 - struct inode *inode = file_inode(vma->vm_file);
274 + struct inode *inode;
276 + file = vma_pr_or_file(vma);
277 + inode = file_inode(file);
278 dev = inode->i_sb->s_dev;
280 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
281 diff --git a/include/linux/mm.h b/include/linux/mm.h
282 index 00bad77..cc616b0 100644
283 --- a/include/linux/mm.h
284 +++ b/include/linux/mm.h
285 @@ -1183,6 +1183,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
289 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
290 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
292 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
293 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
295 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
297 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
299 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
300 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
303 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
304 +extern void vmr_do_fput(struct vm_region *, const char[], int);
306 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
308 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
309 +#endif /* !CONFIG_MMU */
311 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
312 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
313 void *buf, int len, int write);
314 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
315 index f8d1492..c3a3760 100644
316 --- a/include/linux/mm_types.h
317 +++ b/include/linux/mm_types.h
318 @@ -272,6 +272,7 @@ struct vm_region {
319 unsigned long vm_top; /* region allocated to here */
320 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
321 struct file *vm_file; /* the backing file or NULL */
322 + struct file *vm_prfile; /* the virtual backing file or NULL */
324 int vm_usage; /* region usage count (access under nommu_region_sem) */
325 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
326 @@ -346,6 +347,7 @@ struct vm_area_struct {
327 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
328 units, *not* PAGE_CACHE_SIZE */
329 struct file * vm_file; /* File we map to (can be NULL). */
330 + struct file *vm_prfile; /* shadow of vm_file */
331 void * vm_private_data; /* was vm_pte (shared mem) */
334 diff --git a/kernel/fork.c b/kernel/fork.c
335 index 1155eac..c001ea4 100644
338 @@ -465,7 +465,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
339 struct inode *inode = file_inode(file);
340 struct address_space *mapping = file->f_mapping;
344 if (tmp->vm_flags & VM_DENYWRITE)
345 atomic_dec(&inode->i_writecount);
346 i_mmap_lock_write(mapping);
347 diff --git a/mm/Makefile b/mm/Makefile
348 index 2ed4319..e3a53f5 100644
351 @@ -21,7 +21,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
352 mm_init.o mmu_context.o percpu.o slab_common.o \
353 compaction.o vmacache.o \
354 interval_tree.o list_lru.o workingset.o \
356 + prfile.o debug.o $(mmu-y)
360 diff --git a/mm/filemap.c b/mm/filemap.c
361 index 1bb0076..8eaece8 100644
364 @@ -2128,7 +2128,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
365 int ret = VM_FAULT_LOCKED;
367 sb_start_pagefault(inode->i_sb);
368 - file_update_time(vma->vm_file);
369 + vma_file_update_time(vma);
371 if (page->mapping != inode->i_mapping) {
373 diff --git a/mm/memory.c b/mm/memory.c
374 index c387430..d434404 100644
377 @@ -2035,7 +2035,7 @@ static inline int wp_page_reuse(struct mm_struct *mm,
381 - file_update_time(vma->vm_file);
382 + vma_file_update_time(vma);
385 return VM_FAULT_WRITE;
386 diff --git a/mm/mmap.c b/mm/mmap.c
387 index 2ce04a6..f555c0a 100644
390 @@ -275,7 +275,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
391 if (vma->vm_ops && vma->vm_ops->close)
392 vma->vm_ops->close(vma);
394 - fput(vma->vm_file);
396 mpol_put(vma_policy(vma));
397 kmem_cache_free(vm_area_cachep, vma);
399 @@ -887,7 +887,7 @@ again: remove_next = 1 + (end > next->vm_end);
402 uprobe_munmap(next, next->vm_start, next->vm_end);
407 anon_vma_merge(vma, next);
408 @@ -1681,8 +1681,8 @@ out:
416 /* Undo any partial mapping done by a device driver. */
417 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
418 @@ -2488,7 +2488,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
422 - get_file(new->vm_file);
425 if (new->vm_ops && new->vm_ops->open)
426 new->vm_ops->open(new);
427 @@ -2507,7 +2507,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
428 if (new->vm_ops && new->vm_ops->close)
429 new->vm_ops->close(new);
431 - fput(new->vm_file);
433 unlink_anon_vmas(new);
435 mpol_put(vma_policy(new));
436 @@ -2649,7 +2649,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
437 struct vm_area_struct *vma;
438 unsigned long populate = 0;
439 unsigned long ret = -EINVAL;
442 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
443 "See Documentation/vm/remap_file_pages.txt.\n",
444 @@ -2693,10 +2692,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
445 munlock_vma_pages_range(vma, start, start + size);
448 - file = get_file(vma->vm_file);
450 ret = do_mmap_pgoff(vma->vm_file, start, size,
451 prot, flags, pgoff, &populate);
455 up_write(&mm->mmap_sem);
457 @@ -2966,7 +2965,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
458 if (anon_vma_clone(new_vma, vma))
459 goto out_free_mempol;
460 if (new_vma->vm_file)
461 - get_file(new_vma->vm_file);
462 + vma_get_file(new_vma);
463 if (new_vma->vm_ops && new_vma->vm_ops->open)
464 new_vma->vm_ops->open(new_vma);
465 vma_link(mm, new_vma, prev, rb_link, rb_parent);
466 diff --git a/mm/nommu.c b/mm/nommu.c
467 index 92be862..29179f7 100644
470 @@ -671,7 +671,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 @@ -829,7 +829,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 @@ -1355,7 +1355,7 @@ unsigned long do_mmap(struct file *file,
489 goto error_just_free;
492 - fput(region->vm_file);
494 kmem_cache_free(vm_region_jar, region);
497 @@ -1430,10 +1430,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);
510 diff --git a/mm/prfile.c b/mm/prfile.c
512 index 0000000..b323b8a
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, %s\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 aufs4.4 standalone patch
604 diff --git a/fs/dcache.c b/fs/dcache.c
605 index 8aa7f26..f997345 100644
608 @@ -1272,6 +1272,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/exec.c b/fs/exec.c
617 index b06623a..b9206c5 100644
620 @@ -103,6 +103,7 @@ bool path_noexec(const struct path *path)
621 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
622 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
624 +EXPORT_SYMBOL(path_noexec);
628 diff --git a/fs/file_table.c b/fs/file_table.c
629 index ad17e05..38e046a 100644
630 --- a/fs/file_table.c
631 +++ b/fs/file_table.c
632 @@ -147,6 +147,7 @@ over:
634 return ERR_PTR(-ENFILE);
636 +EXPORT_SYMBOL(get_empty_filp);
639 * alloc_file - allocate and initialize a 'struct file'
640 @@ -258,6 +259,7 @@ void flush_delayed_fput(void)
644 +EXPORT_SYMBOL(flush_delayed_fput);
646 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
648 @@ -300,6 +302,7 @@ void __fput_sync(struct file *file)
652 +EXPORT_SYMBOL(__fput_sync);
654 void put_filp(struct file *file)
656 @@ -308,6 +311,7 @@ void put_filp(struct file *file)
660 +EXPORT_SYMBOL(put_filp);
662 void __init files_init(void)
664 diff --git a/fs/namespace.c b/fs/namespace.c
665 index 0570729..ec560d8 100644
668 @@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
669 mnt_dec_writers(real_mount(mnt));
672 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
675 * mnt_drop_write - give up write access to a mount
676 @@ -1803,6 +1804,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
680 +EXPORT_SYMBOL(iterate_mounts);
682 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
684 diff --git a/fs/notify/group.c b/fs/notify/group.c
685 index d16b62c..06ca6bc 100644
686 --- a/fs/notify/group.c
687 +++ b/fs/notify/group.c
689 #include <linux/srcu.h>
690 #include <linux/rculist.h>
691 #include <linux/wait.h>
692 +#include <linux/module.h>
694 #include <linux/fsnotify_backend.h>
695 #include "fsnotify.h"
696 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
698 atomic_inc(&group->refcnt);
700 +EXPORT_SYMBOL(fsnotify_get_group);
703 * Drop a reference to a group. Free it if it's through.
704 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
705 if (atomic_dec_and_test(&group->refcnt))
706 fsnotify_final_destroy_group(group);
708 +EXPORT_SYMBOL(fsnotify_put_group);
711 * Create a new fsnotify_group and hold a reference for the group returned.
712 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
716 +EXPORT_SYMBOL(fsnotify_alloc_group);
718 int fsnotify_fasync(int fd, struct file *file, int on)
720 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
721 index fc0df44..325b5c6 100644
722 --- a/fs/notify/mark.c
723 +++ b/fs/notify/mark.c
724 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
725 mark->free_mark(mark);
728 +EXPORT_SYMBOL(fsnotify_put_mark);
730 /* Calculate mask of events for a list of marks */
731 u32 fsnotify_recalc_mask(struct hlist_head *head)
732 @@ -208,6 +209,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
733 mutex_unlock(&group->mark_mutex);
734 fsnotify_free_mark(mark);
736 +EXPORT_SYMBOL(fsnotify_destroy_mark);
738 void fsnotify_destroy_marks(struct hlist_head *head, spinlock_t *lock)
740 @@ -392,6 +394,7 @@ err:
744 +EXPORT_SYMBOL(fsnotify_add_mark);
746 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
747 struct inode *inode, struct vfsmount *mnt, int allow_dups)
748 @@ -492,6 +495,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
749 atomic_set(&mark->refcnt, 1);
750 mark->free_mark = free_mark;
752 +EXPORT_SYMBOL(fsnotify_init_mark);
754 static int fsnotify_mark_destroy(void *ignored)
756 diff --git a/fs/open.c b/fs/open.c
757 index b6f1e96..4ab0d4e 100644
760 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
761 mutex_unlock(&dentry->d_inode->i_mutex);
764 +EXPORT_SYMBOL(do_truncate);
766 long vfs_truncate(struct path *path, loff_t length)
768 @@ -678,6 +679,7 @@ int open_check_o_direct(struct file *f)
772 +EXPORT_SYMBOL(open_check_o_direct);
774 static int do_dentry_open(struct file *f,
776 diff --git a/fs/read_write.c b/fs/read_write.c
777 index fd0414e..8ace6ec 100644
778 --- a/fs/read_write.c
779 +++ b/fs/read_write.c
780 @@ -504,6 +504,7 @@ vfs_readf_t vfs_readf(struct file *file)
781 return new_sync_read;
782 return ERR_PTR(-ENOSYS);
784 +EXPORT_SYMBOL(vfs_readf);
786 vfs_writef_t vfs_writef(struct file *file)
788 @@ -515,6 +516,7 @@ vfs_writef_t vfs_writef(struct file *file)
789 return new_sync_write;
790 return ERR_PTR(-ENOSYS);
792 +EXPORT_SYMBOL(vfs_writef);
794 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
796 diff --git a/fs/splice.c b/fs/splice.c
797 index 30a091d..c37c311 100644
800 @@ -1123,6 +1123,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
802 return splice_write(pipe, out, ppos, len, flags);
804 +EXPORT_SYMBOL(do_splice_from);
807 * Attempt to initiate a splice from a file to a pipe.
808 @@ -1149,6 +1150,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
810 return splice_read(in, ppos, pipe, len, flags);
812 +EXPORT_SYMBOL(do_splice_to);
815 * splice_direct_to_actor - splices data directly between two non-pipes
816 diff --git a/fs/xattr.c b/fs/xattr.c
817 index 9b932b9..44c457a 100644
820 @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
821 *xattr_value = value;
824 +EXPORT_SYMBOL(vfs_getxattr_alloc);
826 /* Compare an extended attribute value with the given value */
827 int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
828 diff --git a/kernel/task_work.c b/kernel/task_work.c
829 index 53fa971..f80d564 100644
830 --- a/kernel/task_work.c
831 +++ b/kernel/task_work.c
832 @@ -118,3 +118,4 @@ void task_work_run(void)
836 +EXPORT_SYMBOL(task_work_run);
837 diff --git a/security/commoncap.c b/security/commoncap.c
838 index 1832cf7..987ff5f 100644
839 --- a/security/commoncap.c
840 +++ b/security/commoncap.c
841 @@ -1053,12 +1053,14 @@ int cap_mmap_addr(unsigned long addr)
845 +EXPORT_SYMBOL(cap_mmap_addr);
847 int cap_mmap_file(struct file *file, unsigned long reqprot,
848 unsigned long prot, unsigned long flags)
852 +EXPORT_SYMBOL(cap_mmap_file);
854 #ifdef CONFIG_SECURITY
856 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
857 index 03c1652..b00aa76 100644
858 --- a/security/device_cgroup.c
859 +++ b/security/device_cgroup.c
861 #include <linux/device_cgroup.h>
862 #include <linux/cgroup.h>
863 #include <linux/ctype.h>
864 +#include <linux/export.h>
865 #include <linux/list.h>
866 #include <linux/uaccess.h>
867 #include <linux/seq_file.h>
868 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
869 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
872 +EXPORT_SYMBOL(__devcgroup_inode_permission);
874 int devcgroup_inode_mknod(int mode, dev_t dev)
876 diff --git a/security/security.c b/security/security.c
877 index 46f405c..54488b0 100644
878 --- a/security/security.c
879 +++ b/security/security.c
880 @@ -433,6 +433,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
882 return call_int_hook(path_rmdir, 0, dir, dentry);
884 +EXPORT_SYMBOL(security_path_rmdir);
886 int security_path_unlink(struct path *dir, struct dentry *dentry)
888 @@ -449,6 +450,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
890 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
892 +EXPORT_SYMBOL(security_path_symlink);
894 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
895 struct dentry *new_dentry)
896 @@ -457,6 +459,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
898 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
900 +EXPORT_SYMBOL(security_path_link);
902 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
903 struct path *new_dir, struct dentry *new_dentry,
904 @@ -484,6 +487,7 @@ int security_path_truncate(struct path *path)
906 return call_int_hook(path_truncate, 0, path);
908 +EXPORT_SYMBOL(security_path_truncate);
910 int security_path_chmod(struct path *path, umode_t mode)
912 @@ -491,6 +495,7 @@ int security_path_chmod(struct path *path, umode_t mode)
914 return call_int_hook(path_chmod, 0, path, mode);
916 +EXPORT_SYMBOL(security_path_chmod);
918 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
920 @@ -498,6 +503,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
922 return call_int_hook(path_chown, 0, path, uid, gid);
924 +EXPORT_SYMBOL(security_path_chown);
926 int security_path_chroot(struct path *path)
928 @@ -583,6 +589,7 @@ int security_inode_readlink(struct dentry *dentry)
930 return call_int_hook(inode_readlink, 0, dentry);
932 +EXPORT_SYMBOL(security_inode_readlink);
934 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
936 @@ -598,6 +605,7 @@ int security_inode_permission(struct inode *inode, int mask)
938 return call_int_hook(inode_permission, 0, inode, mask);
940 +EXPORT_SYMBOL(security_inode_permission);
942 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
944 @@ -736,6 +744,7 @@ int security_file_permission(struct file *file, int mask)
946 return fsnotify_perm(file, mask);
948 +EXPORT_SYMBOL(security_file_permission);
950 int security_file_alloc(struct file *file)
952 @@ -795,6 +804,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
954 return ima_file_mmap(file, prot);
956 +EXPORT_SYMBOL(security_mmap_file);
958 int security_mmap_addr(unsigned long addr)
960 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
961 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
962 +++ linux/Documentation/ABI/testing/debugfs-aufs 2016-02-28 11:26:32.569971135 +0100
964 +What: /debug/aufs/si_<id>/
966 +Contact: J. R. Okajima <hooanon05g@gmail.com>
968 + Under /debug/aufs, a directory named si_<id> is created
969 + per aufs mount, where <id> is a unique id generated
972 +What: /debug/aufs/si_<id>/plink
974 +Contact: J. R. Okajima <hooanon05g@gmail.com>
976 + It has three lines and shows the information about the
977 + pseudo-link. The first line is a single number
978 + representing a number of buckets. The second line is a
979 + number of pseudo-links per buckets (separated by a
980 + blank). The last line is a single number representing a
981 + total number of psedo-links.
982 + When the aufs mount option 'noplink' is specified, it
983 + will show "1\n0\n0\n".
985 +What: /debug/aufs/si_<id>/xib
987 +Contact: J. R. Okajima <hooanon05g@gmail.com>
989 + It shows the consumed blocks by xib (External Inode Number
990 + Bitmap), its block size and file size.
991 + When the aufs mount option 'noxino' is specified, it
992 + will be empty. About XINO files, see the aufs manual.
994 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
996 +Contact: J. R. Okajima <hooanon05g@gmail.com>
998 + It shows the consumed blocks by xino (External Inode Number
999 + Translation Table), its link count, block size and file
1001 + When the aufs mount option 'noxino' is specified, it
1002 + will be empty. About XINO files, see the aufs manual.
1004 +What: /debug/aufs/si_<id>/xigen
1006 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1008 + It shows the consumed blocks by xigen (External Inode
1009 + Generation Table), its block size and file size.
1010 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1012 + When the aufs mount option 'noxino' is specified, it
1013 + will be empty. About XINO files, see the aufs manual.
1014 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1015 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1016 +++ linux/Documentation/ABI/testing/sysfs-aufs 2016-02-28 11:26:32.569971135 +0100
1018 +What: /sys/fs/aufs/si_<id>/
1020 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1022 + Under /sys/fs/aufs, a directory named si_<id> is created
1023 + per aufs mount, where <id> is a unique id generated
1026 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1028 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1030 + It shows the abolute path of a member directory (which
1031 + is called branch) in aufs, and its permission.
1033 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1035 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1037 + It shows the id of a member directory (which is called
1040 +What: /sys/fs/aufs/si_<id>/xi_path
1042 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1044 + It shows the abolute path of XINO (External Inode Number
1045 + Bitmap, Translation Table and Generation Table) file
1046 + even if it is the default path.
1047 + When the aufs mount option 'noxino' is specified, it
1048 + will be empty. About XINO files, see the aufs manual.
1049 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1050 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1051 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2016-02-28 11:26:32.569971135 +0100
1054 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1056 +# This program is free software; you can redistribute it and/or modify
1057 +# it under the terms of the GNU General Public License as published by
1058 +# the Free Software Foundation; either version 2 of the License, or
1059 +# (at your option) any later version.
1061 +# This program is distributed in the hope that it will be useful,
1062 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1063 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1064 +# GNU General Public License for more details.
1066 +# You should have received a copy of the GNU General Public License
1067 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1070 +----------------------------------------
1072 +aufs [ei ju: ef es] | [a u f s]
1073 +1. abbrev. for "advanced multi-layered unification filesystem".
1074 +2. abbrev. for "another unionfs".
1075 +3. abbrev. for "auf das" in German which means "on the" in English.
1076 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1077 + But "Filesystem aufs Filesystem" is hard to understand.
1079 +AUFS is a filesystem with features:
1080 +- multi layered stackable unification filesystem, the member directory
1081 + is called as a branch.
1082 +- branch permission and attribute, 'readonly', 'real-readonly',
1083 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1085 +- internal "file copy-on-write".
1086 +- logical deletion, whiteout.
1087 +- dynamic branch manipulation, adding, deleting and changing permission.
1088 +- allow bypassing aufs, user's direct branch access.
1089 +- external inode number translation table and bitmap which maintains the
1090 + persistent aufs inode number.
1091 +- seekable directory, including NFS readdir.
1092 +- file mapping, mmap and sharing pages.
1093 +- pseudo-link, hardlink over branches.
1094 +- loopback mounted filesystem as a branch.
1095 +- several policies to select one among multiple writable branches.
1096 +- revert a single systemcall when an error occurs in aufs.
1100 +Multi Layered Stackable Unification Filesystem
1101 +----------------------------------------------------------------------
1102 +Most people already knows what it is.
1103 +It is a filesystem which unifies several directories and provides a
1104 +merged single directory. When users access a file, the access will be
1105 +passed/re-directed/converted (sorry, I am not sure which English word is
1106 +correct) to the real file on the member filesystem. The member
1107 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1108 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1109 +readonly branch is handled by creating 'whiteout' on the upper writable
1112 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1113 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1114 +different approaches to implement the merged-view.
1115 +The former tries putting it into VFS, and the latter implements as a
1116 +separate filesystem.
1117 +(If I misunderstand about these implementations, please let me know and
1118 +I shall correct it. Because it is a long time ago when I read their
1119 +source files last time).
1121 +UnionMount's approach will be able to small, but may be hard to share
1122 +branches between several UnionMount since the whiteout in it is
1123 +implemented in the inode on branch filesystem and always
1124 +shared. According to Bharata's post, readdir does not seems to be
1126 +There are several missing features known in this implementations such as
1127 +- for users, the inode number may change silently. eg. copy-up.
1128 +- link(2) may break by copy-up.
1129 +- read(2) may get an obsoleted filedata (fstat(2) too).
1130 +- fcntl(F_SETLK) may be broken by copy-up.
1131 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1134 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1135 +merged into mainline. This is another implementation of UnionMount as a
1136 +separated filesystem. All the limitations and known problems which
1137 +UnionMount are equally inherited to "overlay" filesystem.
1139 +Unionfs has a longer history. When I started implementing a stackable
1140 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1141 +inode, dentry and file objects and they have an array pointing lower
1142 +same kind objects. After contributing many patches for Unionfs, I
1143 +re-started my project AUFS (Jun 2006).
1145 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1146 +implemented my own ideas, approaches and enhancements and it became
1147 +totally different one.
1149 +Comparing DM snapshot and fs based implementation
1150 +- the number of bytes to be copied between devices is much smaller.
1151 +- the type of filesystem must be one and only.
1152 +- the fs must be writable, no readonly fs, even for the lower original
1153 + device. so the compression fs will not be usable. but if we use
1154 + loopback mount, we may address this issue.
1156 + mount /cdrom/squashfs.img /sq
1157 + losetup /sq/ext2.img
1158 + losetup /somewhere/cow
1159 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1160 +- it will be difficult (or needs more operations) to extract the
1161 + difference between the original device and COW.
1162 +- DM snapshot-merge may help a lot when users try merging. in the
1163 + fs-layer union, users will use rsync(1).
1165 +You may want to read my old paper "Filesystems in LiveCD"
1166 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1169 +Several characters/aspects/persona of aufs
1170 +----------------------------------------------------------------------
1172 +Aufs has several characters, aspects or persona.
1173 +1. a filesystem, callee of VFS helper
1174 +2. sub-VFS, caller of VFS helper for branches
1175 +3. a virtual filesystem which maintains persistent inode number
1176 +4. reader/writer of files on branches such like an application
1178 +1. Callee of VFS Helper
1179 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1180 +unlink(2) from an application reaches sys_unlink() kernel function and
1181 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1182 +calls filesystem specific unlink operation. Actually aufs implements the
1183 +unlink operation but it behaves like a redirector.
1185 +2. Caller of VFS Helper for Branches
1186 +aufs_unlink() passes the unlink request to the branch filesystem as if
1187 +it were called from VFS. So the called unlink operation of the branch
1188 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1189 +every necessary pre/post operation for the branch filesystem.
1190 +- acquire the lock for the parent dir on a branch
1191 +- lookup in a branch
1192 +- revalidate dentry on a branch
1193 +- mnt_want_write() for a branch
1194 +- vfs_unlink() for a branch
1195 +- mnt_drop_write() for a branch
1196 +- release the lock on a branch
1198 +3. Persistent Inode Number
1199 +One of the most important issue for a filesystem is to maintain inode
1200 +numbers. This is particularly important to support exporting a
1201 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1202 +backend block device for its own. But some storage is necessary to
1203 +keep and maintain the inode numbers. It may be a large space and may not
1204 +suit to keep in memory. Aufs rents some space from its first writable
1205 +branch filesystem (by default) and creates file(s) on it. These files
1206 +are created by aufs internally and removed soon (currently) keeping
1208 +Note: Because these files are removed, they are totally gone after
1209 + unmounting aufs. It means the inode numbers are not persistent
1210 + across unmount or reboot. I have a plan to make them really
1211 + persistent which will be important for aufs on NFS server.
1213 +4. Read/Write Files Internally (copy-on-write)
1214 +Because a branch can be readonly, when you write a file on it, aufs will
1215 +"copy-up" it to the upper writable branch internally. And then write the
1216 +originally requested thing to the file. Generally kernel doesn't
1217 +open/read/write file actively. In aufs, even a single write may cause a
1218 +internal "file copy". This behaviour is very similar to cp(1) command.
1220 +Some people may think it is better to pass such work to user space
1221 +helper, instead of doing in kernel space. Actually I am still thinking
1222 +about it. But currently I have implemented it in kernel space.
1223 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1224 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1225 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2016-02-28 11:26:32.569971135 +0100
1228 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1230 +# This program is free software; you can redistribute it and/or modify
1231 +# it under the terms of the GNU General Public License as published by
1232 +# the Free Software Foundation; either version 2 of the License, or
1233 +# (at your option) any later version.
1235 +# This program is distributed in the hope that it will be useful,
1236 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1237 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1238 +# GNU General Public License for more details.
1240 +# You should have received a copy of the GNU General Public License
1241 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1243 +Basic Aufs Internal Structure
1245 +Superblock/Inode/Dentry/File Objects
1246 +----------------------------------------------------------------------
1247 +As like an ordinary filesystem, aufs has its own
1248 +superblock/inode/dentry/file objects. All these objects have a
1249 +dynamically allocated array and store the same kind of pointers to the
1250 +lower filesystem, branch.
1251 +For example, when you build a union with one readwrite branch and one
1252 +readonly, mounted /au, /rw and /ro respectively.
1254 +- /ro/fileA exists but /rw/fileA
1256 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1257 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1258 +- [0] = NULL (because /rw/fileA doesn't exist)
1261 +This style of an array is essentially same to the aufs
1262 +superblock/inode/dentry/file objects.
1264 +Because aufs supports manipulating branches, ie. add/delete/change
1265 +branches dynamically, these objects has its own generation. When
1266 +branches are changed, the generation in aufs superblock is
1267 +incremented. And a generation in other object are compared when it is
1268 +accessed. When a generation in other objects are obsoleted, aufs
1269 +refreshes the internal array.
1273 +----------------------------------------------------------------------
1274 +Additionally aufs superblock has some data for policies to select one
1275 +among multiple writable branches, XIB files, pseudo-links and kobject.
1276 +See below in detail.
1277 +About the policies which supports copy-down a directory, see
1278 +wbr_policy.txt too.
1281 +Branch and XINO(External Inode Number Translation Table)
1282 +----------------------------------------------------------------------
1283 +Every branch has its own xino (external inode number translation table)
1284 +file. The xino file is created and unlinked by aufs internally. When two
1285 +members of a union exist on the same filesystem, they share the single
1287 +The struct of a xino file is simple, just a sequence of aufs inode
1288 +numbers which is indexed by the lower inode number.
1289 +In the above sample, assume the inode number of /ro/fileA is i111 and
1290 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1291 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1293 +When the inode numbers are not contiguous, the xino file will be sparse
1294 +which has a hole in it and doesn't consume as much disk space as it
1295 +might appear. If your branch filesystem consumes disk space for such
1296 +holes, then you should specify 'xino=' option at mounting aufs.
1298 +Aufs has a mount option to free the disk blocks for such holes in XINO
1299 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1300 +meet a problem of disk shortage due to XINO files, then you should try
1301 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1302 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1303 +the holes in XINO files.
1305 +Also a writable branch has three kinds of "whiteout bases". All these
1306 +are existed when the branch is joined to aufs, and their names are
1307 +whiteout-ed doubly, so that users will never see their names in aufs
1309 +1. a regular file which will be hardlinked to all whiteouts.
1310 +2. a directory to store a pseudo-link.
1311 +3. a directory to store an "orphan"-ed file temporary.
1314 + When you remove a file on a readonly branch, aufs handles it as a
1315 + logical deletion and creates a whiteout on the upper writable branch
1316 + as a hardlink of this file in order not to consume inode on the
1319 + See below, Pseudo-link.
1321 + When "fileC" exists on the lower readonly branch only and it is
1322 + opened and removed with its parent dir, and then user writes
1323 + something into it, then aufs copies-up fileC to this
1324 + directory. Because there is no other dir to store fileC. After
1325 + creating a file under this dir, the file is unlinked.
1327 +Because aufs supports manipulating branches, ie. add/delete/change
1328 +dynamically, a branch has its own id. When the branch order changes,
1329 +aufs finds the new index by searching the branch id.
1333 +----------------------------------------------------------------------
1334 +Assume "fileA" exists on the lower readonly branch only and it is
1335 +hardlinked to "fileB" on the branch. When you write something to fileA,
1336 +aufs copies-up it to the upper writable branch. Additionally aufs
1337 +creates a hardlink under the Pseudo-link Directory of the writable
1338 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1339 +simple list. If fileB is read after unlinking fileA, aufs returns
1340 +filedata from the pseudo-link instead of the lower readonly
1341 +branch. Because the pseudo-link is based upon the inode, to keep the
1342 +inode number by xino (see above) is essentially necessary.
1344 +All the hardlinks under the Pseudo-link Directory of the writable branch
1345 +should be restored in a proper location later. Aufs provides a utility
1346 +to do this. The userspace helpers executed at remounting and unmounting
1348 +During this utility is running, it puts aufs into the pseudo-link
1349 +maintenance mode. In this mode, only the process which began the
1350 +maintenance mode (and its child processes) is allowed to operate in
1351 +aufs. Some other processes which are not related to the pseudo-link will
1352 +be allowed to run too, but the rest have to return an error or wait
1353 +until the maintenance mode ends. If a process already acquires an inode
1354 +mutex (in VFS), it has to return an error.
1357 +XIB(external inode number bitmap)
1358 +----------------------------------------------------------------------
1359 +Addition to the xino file per a branch, aufs has an external inode number
1360 +bitmap in a superblock object. It is also an internal file such like a
1362 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1364 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1366 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1367 +reduce the number of consumed disk blocks for these files.
1370 +Virtual or Vertical Dir, and Readdir in Userspace
1371 +----------------------------------------------------------------------
1372 +In order to support multiple layers (branches), aufs readdir operation
1373 +constructs a virtual dir block on memory. For readdir, aufs calls
1374 +vfs_readdir() internally for each dir on branches, merges their entries
1375 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1376 +object. So the file object has its entry list until it is closed. The
1377 +entry list will be updated when the file position is zero and becomes
1378 +obsoleted. This decision is made in aufs automatically.
1380 +The dynamically allocated memory block for the name of entries has a
1381 +unit of 512 bytes (by default) and stores the names contiguously (no
1382 +padding). Another block for each entry is handled by kmem_cache too.
1383 +During building dir blocks, aufs creates hash list and judging whether
1384 +the entry is whiteouted by its upper branch or already listed.
1385 +The merged result is cached in the corresponding inode object and
1386 +maintained by a customizable life-time option.
1388 +Some people may call it can be a security hole or invite DoS attack
1389 +since the opened and once readdir-ed dir (file object) holds its entry
1390 +list and becomes a pressure for system memory. But I'd say it is similar
1391 +to files under /proc or /sys. The virtual files in them also holds a
1392 +memory page (generally) while they are opened. When an idea to reduce
1393 +memory for them is introduced, it will be applied to aufs too.
1394 +For those who really hate this situation, I've developed readdir(3)
1395 +library which operates this merging in userspace. You just need to set
1396 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1397 +kernel space for readdir(3).
1401 +----------------------------------------------------------------------
1402 +Aufs sometimes requires privilege access to a branch. For instance,
1403 +in copy-up/down operation. When a user process is going to make changes
1404 +to a file which exists in the lower readonly branch only, and the mode
1405 +of one of ancestor directories may not be writable by a user
1406 +process. Here aufs copy-up the file with its ancestors and they may
1407 +require privilege to set its owner/group/mode/etc.
1408 +This is a typical case of a application character of aufs (see
1411 +Aufs uses workqueue synchronously for this case. It creates its own
1412 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1413 +passes the request to call mkdir or write (for example), and wait for
1414 +its completion. This approach solves a problem of a signal handler
1416 +If aufs didn't adopt the workqueue and changed the privilege of the
1417 +process, then the process may receive the unexpected SIGXFSZ or other
1420 +Also aufs uses the system global workqueue ("events" kernel thread) too
1421 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1422 +whiteout base and etc. This is unrelated to a privilege.
1423 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1424 +superblock at the beginning, at the same time waits for the completion
1425 +of all queued asynchronous tasks.
1429 +----------------------------------------------------------------------
1430 +The whiteout in aufs is very similar to Unionfs's. That is represented
1431 +by its filename. UnionMount takes an approach of a file mode, but I am
1432 +afraid several utilities (find(1) or something) will have to support it.
1434 +Basically the whiteout represents "logical deletion" which stops aufs to
1435 +lookup further, but also it represents "dir is opaque" which also stop
1438 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1439 +In order to make several functions in a single systemcall to be
1440 +revertible, aufs adopts an approach to rename a directory to a temporary
1441 +unique whiteouted name.
1442 +For example, in rename(2) dir where the target dir already existed, aufs
1443 +renames the target dir to a temporary unique whiteouted name before the
1444 +actual rename on a branch, and then handles other actions (make it opaque,
1445 +update the attributes, etc). If an error happens in these actions, aufs
1446 +simply renames the whiteouted name back and returns an error. If all are
1447 +succeeded, aufs registers a function to remove the whiteouted unique
1448 +temporary name completely and asynchronously to the system global
1453 +----------------------------------------------------------------------
1454 +It is a well-known feature or concept.
1455 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1456 +internally and makes change to the new file on the upper writable branch.
1457 +When the trigger systemcall does not update the timestamps of the parent
1458 +dir, aufs reverts it after copy-up.
1461 +Move-down (aufs3.9 and later)
1462 +----------------------------------------------------------------------
1463 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1464 +the lower readonly branch to the upper writable branch when a user
1465 +changes something about the file.
1466 +"Move-down" is an opposite action of copy-up. Basically this action is
1467 +ran manually instead of automatically and internally.
1468 +For desgin and implementation, aufs has to consider these issues.
1469 +- whiteout for the file may exist on the lower branch.
1470 +- ancestor directories may not exist on the lower branch.
1471 +- diropq for the ancestor directories may exist on the upper branch.
1472 +- free space on the lower branch will reduce.
1473 +- another access to the file may happen during moving-down, including
1474 + UDBA (see "Revalidate Dentry and UDBA").
1475 +- the file should not be hard-linked nor pseudo-linked. they should be
1476 + handled by auplink utility later.
1478 +Sometimes users want to move-down a file from the upper writable branch
1479 +to the lower readonly or writable branch. For instance,
1480 +- the free space of the upper writable branch is going to run out.
1481 +- create a new intermediate branch between the upper and lower branch.
1484 +For this purpose, use "aumvdown" command in aufs-util.git.
1485 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1486 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1487 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2016-02-28 11:26:32.569971135 +0100
1490 +# Copyright (C) 2015-2016 Junjiro R. Okajima
1492 +# This program is free software; you can redistribute it and/or modify
1493 +# it under the terms of the GNU General Public License as published by
1494 +# the Free Software Foundation; either version 2 of the License, or
1495 +# (at your option) any later version.
1497 +# This program is distributed in the hope that it will be useful,
1498 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1499 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1500 +# GNU General Public License for more details.
1502 +# You should have received a copy of the GNU General Public License
1503 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1505 +Support for a branch who has its ->atomic_open()
1506 +----------------------------------------------------------------------
1507 +The filesystems who implement its ->atomic_open() are not majority. For
1508 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1509 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1510 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1511 +sure whether all filesystems who have ->atomic_open() behave like this,
1512 +but NFSv4 surely returns the error.
1514 +In order to support ->atomic_open() for aufs, there are a few
1517 +A. Introduce aufs_atomic_open()
1518 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1520 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1521 + an aufs user Pip Cet's approach
1522 + - calls aufs_create(), VFS finish_open() and notify_change().
1523 + - pass fake-mode to finish_open(), and then correct the mode by
1525 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1526 + - no aufs_atomic_open().
1527 + - aufs_lookup() registers the TID to an aufs internal object.
1528 + - aufs_create() does nothing when the matching TID is registered, but
1529 + registers the mode.
1530 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1531 + TID is registered.
1532 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1534 + - no aufs_atomic_open().
1535 + - aufs_create() registers the TID to an internal object. this info
1536 + represents "this process created this file just now."
1537 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1538 + registered TID and re-try open() with superuser's credential.
1540 +Pros and cons for each approach.
1543 + - straightforward but highly depends upon VFS internal.
1544 + - the atomic behavaiour is kept.
1545 + - some of parameters such as nameidata are hard to reproduce for
1549 + - easy to implement.
1550 + - the atomic behavaiour is lost.
1552 + - the atomic behavaiour is kept.
1553 + - dirty and tricky.
1554 + - VFS checks whether the file is created correctly after calling
1555 + ->create(), which means this approach doesn't work.
1557 + - easy to implement.
1558 + - the atomic behavaiour is lost.
1559 + - to open a file with superuser's credential and give it to a user
1560 + process is a bad idea, since the file object keeps the credential
1561 + in it. It may affect LSM or something. This approach doesn't work
1564 +The approach A is ideal, but it hard to implement. So here is a
1565 +variation of A, which is to be implemented.
1567 +A-1. Introduce aufs_atomic_open()
1568 + - calls branch fs ->atomic_open() if exists. otherwise calls
1569 + vfs_create() and finish_open().
1570 + - the demerit is that the several checks after branch fs
1571 + ->atomic_open() are lost. in the ordinary case, the checks are
1572 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1573 + be implemented in aufs, but not all I am afraid.
1574 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1575 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1576 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2016-02-28 11:26:32.569971135 +0100
1579 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1581 +# This program is free software; you can redistribute it and/or modify
1582 +# it under the terms of the GNU General Public License as published by
1583 +# the Free Software Foundation; either version 2 of the License, or
1584 +# (at your option) any later version.
1586 +# This program is distributed in the hope that it will be useful,
1587 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1588 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1589 +# GNU General Public License for more details.
1591 +# You should have received a copy of the GNU General Public License
1592 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1595 +----------------------------------------------------------------------
1596 +Since aufs has a character of sub-VFS (see Introduction), it operates
1597 +lookup for branches as VFS does. It may be a heavy work. But almost all
1598 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1599 +directly connected to its parent. Digging down the directory hierarchy
1600 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1603 +When a branch is a remote filesystem, aufs basically relies upon its
1604 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1606 +For d_revalidate, aufs implements three levels of revalidate tests. See
1607 +"Revalidate Dentry and UDBA" in detail.
1610 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1611 +----------------------------------------------------------------------
1612 +Let's try case study.
1613 +- aufs has two branches, upper readwrite and lower readonly.
1615 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1616 +- user invoked "chmod a+rx /au/dirA"
1617 +- the internal copy-up is activated and "/rw/dirA" is created and its
1618 + permission bits are set to world readable.
1619 +- then "/au/dirA" becomes world readable?
1621 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1622 +or it may be a natively readonly filesystem. If aufs respects the lower
1623 +branch, it should not respond readdir request from other users. But user
1624 +allowed it by chmod. Should really aufs rejects showing the entries
1627 +To be honest, I don't have a good solution for this case. So aufs
1628 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1630 +When dirperm1 is specified, aufs checks only the highest one for the
1631 +directory permission, and shows the entries. Otherwise, as usual, checks
1632 +every dir existing on all branches and rejects the request.
1634 +As a side effect, dirperm1 option improves the performance of aufs
1635 +because the number of permission check is reduced when the number of
1639 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1640 +----------------------------------------------------------------------
1641 +Generally VFS helpers re-validate a dentry as a part of lookup.
1642 +0. digging down the directory hierarchy.
1643 +1. lock the parent dir by its i_mutex.
1644 +2. lookup the final (child) entry.
1646 +4. call the actual operation (create, unlink, etc.)
1647 +5. unlock the parent dir
1649 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1650 +called. Actually aufs implements it and checks the dentry on a branch is
1652 +But it is not enough. Because aufs has to release the lock for the
1653 +parent dir on a branch at the end of ->lookup() (step 2) and
1654 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1656 +If the file on a branch is changed directly, eg. bypassing aufs, after
1657 +aufs released the lock, then the subsequent operation may cause
1658 +something unpleasant result.
1660 +This situation is a result of VFS architecture, ->lookup() and
1661 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1662 +design from VFS's point of view. It is just not suitable for sub-VFS
1665 +Aufs supports such case by three level of revalidation which is
1666 +selectable by user.
1667 +1. Simple Revalidate
1668 + Addition to the native flow in VFS's, confirm the child-parent
1669 + relationship on the branch just after locking the parent dir on the
1670 + branch in the "actual operation" (step 4). When this validation
1671 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1672 + checks the validation of the dentry on branches.
1673 +2. Monitor Changes Internally by Inotify/Fsnotify
1674 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1675 + the dentry on the branch, and returns EBUSY if it finds different
1677 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1678 + during it is in cache. When the event is notified, aufs registers a
1679 + function to kernel 'events' thread by schedule_work(). And the
1680 + function sets some special status to the cached aufs dentry and inode
1681 + private data. If they are not cached, then aufs has nothing to
1682 + do. When the same file is accessed through aufs (step 0-3) later,
1683 + aufs will detect the status and refresh all necessary data.
1684 + In this mode, aufs has to ignore the event which is fired by aufs
1686 +3. No Extra Validation
1687 + This is the simplest test and doesn't add any additional revalidation
1688 + test, and skip the revalidation in step 4. It is useful and improves
1689 + aufs performance when system surely hide the aufs branches from user,
1690 + by over-mounting something (or another method).
1691 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1692 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1693 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2016-02-28 11:26:32.569971135 +0100
1696 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1698 +# This program is free software; you can redistribute it and/or modify
1699 +# it under the terms of the GNU General Public License as published by
1700 +# the Free Software Foundation; either version 2 of the License, or
1701 +# (at your option) any later version.
1703 +# This program is distributed in the hope that it will be useful,
1704 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1705 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1706 +# GNU General Public License for more details.
1708 +# You should have received a copy of the GNU General Public License
1709 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1711 +Branch Manipulation
1713 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1714 +and changing its permission/attribute, there are a lot of works to do.
1718 +----------------------------------------------------------------------
1719 +o Confirm the adding dir exists outside of aufs, including loopback
1720 + mount, and its various attributes.
1721 +o Initialize the xino file and whiteout bases if necessary.
1724 +o Check the owner/group/mode of the directory
1725 + When the owner/group/mode of the adding directory differs from the
1726 + existing branch, aufs issues a warning because it may impose a
1728 + For example, when a upper writable branch has a world writable empty
1729 + top directory, a malicious user can create any files on the writable
1730 + branch directly, like copy-up and modify manually. If something like
1731 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1732 + writable branch, and the writable branch is world-writable, then a
1733 + malicious guy may create /etc/passwd on the writable branch directly
1734 + and the infected file will be valid in aufs.
1735 + I am afraid it can be a security issue, but aufs can do nothing except
1736 + producing a warning.
1740 +----------------------------------------------------------------------
1741 +o Confirm the deleting branch is not busy
1742 + To be general, there is one merit to adopt "remount" interface to
1743 + manipulate branches. It is to discard caches. At deleting a branch,
1744 + aufs checks the still cached (and connected) dentries and inodes. If
1745 + there are any, then they are all in-use. An inode without its
1746 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1748 + For the cached one, aufs checks whether the same named entry exists on
1750 + If the cached one is a directory, because aufs provides a merged view
1751 + to users, as long as one dir is left on any branch aufs can show the
1752 + dir to users. In this case, the branch can be removed from aufs.
1753 + Otherwise aufs rejects deleting the branch.
1755 + If any file on the deleting branch is opened by aufs, then aufs
1759 +Modify the Permission of a Branch
1760 +----------------------------------------------------------------------
1761 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1764 +o rw --> ro: Confirm the modifying branch is not busy
1765 + Aufs rejects the request if any of these conditions are true.
1766 + - a file on the branch is mmap-ed.
1767 + - a regular file on the branch is opened for write and there is no
1768 + same named entry on the upper branch.
1769 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1770 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1771 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2016-02-28 11:26:32.569971135 +0100
1774 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1776 +# This program is free software; you can redistribute it and/or modify
1777 +# it under the terms of the GNU General Public License as published by
1778 +# the Free Software Foundation; either version 2 of the License, or
1779 +# (at your option) any later version.
1781 +# This program is distributed in the hope that it will be useful,
1782 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1783 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1784 +# GNU General Public License for more details.
1786 +# You should have received a copy of the GNU General Public License
1787 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1789 +Policies to Select One among Multiple Writable Branches
1790 +----------------------------------------------------------------------
1791 +When the number of writable branch is more than one, aufs has to decide
1792 +the target branch for file creation or copy-up. By default, the highest
1793 +writable branch which has the parent (or ancestor) dir of the target
1794 +file is chosen (top-down-parent policy).
1795 +By user's request, aufs implements some other policies to select the
1796 +writable branch, for file creation several policies, round-robin,
1797 +most-free-space, and other policies. For copy-up, top-down-parent,
1798 +bottom-up-parent, bottom-up and others.
1800 +As expected, the round-robin policy selects the branch in circular. When
1801 +you have two writable branches and creates 10 new files, 5 files will be
1802 +created for each branch. mkdir(2) systemcall is an exception. When you
1803 +create 10 new directories, all will be created on the same branch.
1804 +And the most-free-space policy selects the one which has most free
1805 +space among the writable branches. The amount of free space will be
1806 +checked by aufs internally, and users can specify its time interval.
1808 +The policies for copy-up is more simple,
1809 +top-down-parent is equivalent to the same named on in create policy,
1810 +bottom-up-parent selects the writable branch where the parent dir
1811 +exists and the nearest upper one from the copyup-source,
1812 +bottom-up selects the nearest upper writable branch from the
1813 +copyup-source, regardless the existence of the parent dir.
1815 +There are some rules or exceptions to apply these policies.
1816 +- If there is a readonly branch above the policy-selected branch and
1817 + the parent dir is marked as opaque (a variation of whiteout), or the
1818 + target (creating) file is whiteout-ed on the upper readonly branch,
1819 + then the result of the policy is ignored and the target file will be
1820 + created on the nearest upper writable branch than the readonly branch.
1821 +- If there is a writable branch above the policy-selected branch and
1822 + the parent dir is marked as opaque or the target file is whiteouted
1823 + on the branch, then the result of the policy is ignored and the target
1824 + file will be created on the highest one among the upper writable
1825 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1827 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1828 + They try selecting the branch where the source exists as possible
1829 + since copyup a large file will take long time. If it can't be,
1830 + ie. the branch where the source exists is readonly, then they will
1831 + follow the copyup policy.
1832 +- There is an exception for rename(2) when the target exists.
1833 + If the rename target exists, aufs compares the index of the branches
1834 + where the source and the target exists and selects the higher
1835 + one. If the selected branch is readonly, then aufs follows the
1837 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1838 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1839 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2016-02-28 11:26:32.569971135 +0100
1842 +# Copyright (C) 2011-2016 Junjiro R. Okajima
1844 +# This program is free software; you can redistribute it and/or modify
1845 +# it under the terms of the GNU General Public License as published by
1846 +# the Free Software Foundation; either version 2 of the License, or
1847 +# (at your option) any later version.
1849 +# This program is distributed in the hope that it will be useful,
1850 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1851 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1852 +# GNU General Public License for more details.
1854 +# You should have received a copy of the GNU General Public License
1855 +# along with this program; if not, write to the Free Software
1856 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1859 +File-based Hierarchical Storage Management (FHSM)
1860 +----------------------------------------------------------------------
1861 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1862 +storage world. Aufs provides this feature as file-based with multiple
1863 +writable branches, based upon the principle of "Colder, the Lower".
1864 +Here the word "colder" means that the less used files, and "lower" means
1865 +that the position in the order of the stacked branches vertically.
1866 +These multiple writable branches are prioritized, ie. the topmost one
1867 +should be the fastest drive and be used heavily.
1869 +o Characters in aufs FHSM story
1870 +- aufs itself and a new branch attribute.
1871 +- a new ioctl interface to move-down and to establish a connection with
1872 + the daemon ("move-down" is a converse of "copy-up").
1873 +- userspace tool and daemon.
1875 +The userspace daemon establishes a connection with aufs and waits for
1876 +the notification. The notified information is very similar to struct
1877 +statfs containing the number of consumed blocks and inodes.
1878 +When the consumed blocks/inodes of a branch exceeds the user-specified
1879 +upper watermark, the daemon activates its move-down process until the
1880 +consumed blocks/inodes reaches the user-specified lower watermark.
1882 +The actual move-down is done by aufs based upon the request from
1883 +user-space since we need to maintain the inode number and the internal
1884 +pointer arrays in aufs.
1886 +Currently aufs FHSM handles the regular files only. Additionally they
1887 +must not be hard-linked nor pseudo-linked.
1890 +o Cowork of aufs and the user-space daemon
1891 + During the userspace daemon established the connection, aufs sends a
1892 + small notification to it whenever aufs writes something into the
1893 + writable branch. But it may cost high since aufs issues statfs(2)
1894 + internally. So user can specify a new option to cache the
1895 + info. Actually the notification is controlled by these factors.
1896 + + the specified cache time.
1897 + + classified as "force" by aufs internally.
1898 + Until the specified time expires, aufs doesn't send the info
1899 + except the forced cases. When aufs decide forcing, the info is always
1900 + notified to userspace.
1901 + For example, the number of free inodes is generally large enough and
1902 + the shortage of it happens rarely. So aufs doesn't force the
1903 + notification when creating a new file, directory and others. This is
1904 + the typical case which aufs doesn't force.
1905 + When aufs writes the actual filedata and the files consumes any of new
1906 + blocks, the aufs forces notifying.
1909 +o Interfaces in aufs
1910 +- New branch attribute.
1912 + Specifies that the branch is managed by FHSM feature. In other word,
1913 + participant in the FHSM.
1914 + When nofhsm is set to the branch, it will not be the source/target
1915 + branch of the move-down operation. This attribute is set
1916 + independently from coo and moo attributes, and if you want full
1917 + FHSM, you should specify them as well.
1918 +- New mount option.
1920 + Specifies a second to suppress many less important info to be
1923 + + AUFS_CTL_FHSM_FD
1924 + create a new file descriptor which userspace can read the notification
1925 + (a subset of struct statfs) from aufs.
1926 +- Module parameter 'brs'
1927 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
1929 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
1930 + When there are two or more branches with fhsm attributes,
1931 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
1932 + terminates it. As a result of remounting and branch-manipulation, the
1933 + number of branches with fhsm attribute can be one. In this case,
1934 + /sbin/mount.aufs will terminate the user-space daemon.
1937 +Finally the operation is done as these steps in kernel-space.
1939 + + no one else is using the file.
1940 + + the file is not hard-linked.
1941 + + the file is not pseudo-linked.
1942 + + the file is a regular file.
1943 + + the parent dir is not opaqued.
1944 +- find the target writable branch.
1945 +- make sure the file is not whiteout-ed by the upper (than the target)
1947 +- make the parent dir on the target branch.
1948 +- mutex lock the inode on the branch.
1949 +- unlink the whiteout on the target branch (if exists).
1950 +- lookup and create the whiteout-ed temporary name on the target branch.
1951 +- copy the file as the whiteout-ed temporary name on the target branch.
1952 +- rename the whiteout-ed temporary name to the original name.
1953 +- unlink the file on the source branch.
1954 +- maintain the internal pointer array and the external inode number
1956 +- maintain the timestamps and other attributes of the parent dir and the
1959 +And of course, in every step, an error may happen. So the operation
1960 +should restore the original file state after an error happens.
1961 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1962 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1963 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2016-02-28 11:26:32.569971135 +0100
1966 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1968 +# This program is free software; you can redistribute it and/or modify
1969 +# it under the terms of the GNU General Public License as published by
1970 +# the Free Software Foundation; either version 2 of the License, or
1971 +# (at your option) any later version.
1973 +# This program is distributed in the hope that it will be useful,
1974 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1975 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1976 +# GNU General Public License for more details.
1978 +# You should have received a copy of the GNU General Public License
1979 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1981 +mmap(2) -- File Memory Mapping
1982 +----------------------------------------------------------------------
1983 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1984 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1986 +This approach is simple and good, but there is one problem.
1987 +Under /proc, several entries show the mmapped files by its path (with
1988 +device and inode number), and the printed path will be the path on the
1989 +branch fs's instead of virtual aufs's.
1990 +This is not a problem in most cases, but some utilities lsof(1) (and its
1991 +user) may expect the path on aufs.
1993 +To address this issue, aufs adds a new member called vm_prfile in struct
1994 +vm_area_struct (and struct vm_region). The original vm_file points to
1995 +the file on the branch fs in order to handle everything correctly as
1996 +usual. The new vm_prfile points to a virtual file in aufs, and the
1997 +show-functions in procfs refers to vm_prfile if it is set.
1998 +Also we need to maintain several other places where touching vm_file
2000 +- fork()/clone() copies vma and the reference count of vm_file is
2002 +- merging vma maintains the ref count too.
2004 +This is not a good approach. It just fakes the printed path. But it
2005 +leaves all behaviour around f_mapping unchanged. This is surely an
2007 +Actually aufs had adopted another complicated approach which calls
2008 +generic_file_mmap() and handles struct vm_operations_struct. In this
2009 +approach, aufs met a hard problem and I could not solve it without
2010 +switching the approach.
2012 +There may be one more another approach which is
2013 +- bind-mount the branch-root onto the aufs-root internally
2014 +- grab the new vfsmount (ie. struct mount)
2015 +- lazy-umount the branch-root internally
2016 +- in open(2) the aufs-file, open the branch-file with the hidden
2017 + vfsmount (instead of the original branch's vfsmount)
2018 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2019 + but it may be possible from userspace by the mount helper.
2021 +Adding the internal hidden vfsmount and using it in opening a file, the
2022 +file path under /proc will be printed correctly. This approach looks
2023 +smarter, but is not possible I am afraid.
2024 +- aufs-root may be bind-mount later. when it happens, another hidden
2025 + vfsmount will be required.
2026 +- it is hard to get the chance to bind-mount and lazy-umount
2027 + + in kernel-space, FS can have vfsmount in open(2) via
2028 + file->f_path, and aufs can know its vfsmount. But several locks are
2029 + already acquired, and if aufs tries to bind-mount and lazy-umount
2030 + here, then it may cause a deadlock.
2031 + + in user-space, bind-mount doesn't invoke the mount helper.
2032 +- since /proc shows dev and ino, aufs has to give vma these info. it
2033 + means a new member vm_prinode will be necessary. this is essentially
2034 + equivalent to vm_prfile described above.
2036 +I have to give up this "looks-smater" approach.
2037 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2038 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2039 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2016-02-28 11:26:32.569971135 +0100
2042 +# Copyright (C) 2014-2016 Junjiro R. Okajima
2044 +# This program is free software; you can redistribute it and/or modify
2045 +# it under the terms of the GNU General Public License as published by
2046 +# the Free Software Foundation; either version 2 of the License, or
2047 +# (at your option) any later version.
2049 +# This program is distributed in the hope that it will be useful,
2050 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2051 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2052 +# GNU General Public License for more details.
2054 +# You should have received a copy of the GNU General Public License
2055 +# along with this program; if not, write to the Free Software
2056 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2059 +Listing XATTR/EA and getting the value
2060 +----------------------------------------------------------------------
2061 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2062 +shows the values from the topmost existing file. This behaviour is good
2063 +for the non-dir entries since the bahaviour exactly matches the shown
2064 +information. But for the directories, aufs considers all the same named
2065 +entries on the lower branches. Which means, if one of the lower entry
2066 +rejects readdir call, then aufs returns an error even if the topmost
2067 +entry allows it. This behaviour is necessary to respect the branch fs's
2068 +security, but can make users confused since the user-visible standard
2069 +attributes don't match the behaviour.
2070 +To address this issue, aufs has a mount option called dirperm1 which
2071 +checks the permission for the topmost entry only, and ignores the lower
2072 +entry's permission.
2074 +A similar issue can happen around XATTR.
2075 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2076 +always set. Otherwise these very unpleasant situation would happen.
2077 +- listxattr(2) may return the duplicated entries.
2078 +- users may not be able to remove or reset the XATTR forever,
2081 +XATTR/EA support in the internal (copy,move)-(up,down)
2082 +----------------------------------------------------------------------
2083 +Generally the extended attributes of inode are categorized as these.
2084 +- "security" for LSM and capability.
2085 +- "system" for posix ACL, 'acl' mount option is required for the branch
2087 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2088 +- "user" for userspace, 'user_xattr' mount option is required for the
2089 + branch fs generally.
2091 +Moreover there are some other categories. Aufs handles these rather
2092 +unpopular categories as the ordinary ones, ie. there is no special
2093 +condition nor exception.
2095 +In copy-up, the support for XATTR on the dst branch may differ from the
2096 +src branch. In this case, the copy-up operation will get an error and
2097 +the original user operation which triggered the copy-up will fail. It
2098 +can happen that even all copy-up will fail.
2099 +When both of src and dst branches support XATTR and if an error occurs
2100 +during copying XATTR, then the copy-up should fail obviously. That is a
2101 +good reason and aufs should return an error to userspace. But when only
2102 +the src branch support that XATTR, aufs should not return an error.
2103 +For example, the src branch supports ACL but the dst branch doesn't
2104 +because the dst branch may natively un-support it or temporary
2105 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2106 +may NOT return an error even if the XATTR is not supported. It is
2107 +totally up to the branch fs.
2109 +Anyway when the aufs internal copy-up gets an error from the dst branch
2110 +fs, then aufs tries removing the just copied entry and returns the error
2111 +to the userspace. The worst case of this situation will be all copy-up
2114 +For the copy-up operation, there two basic approaches.
2115 +- copy the specified XATTR only (by category above), and return the
2116 + error unconditionally if it happens.
2117 +- copy all XATTR, and ignore the error on the specified category only.
2119 +In order to support XATTR and to implement the correct behaviour, aufs
2120 +chooses the latter approach and introduces some new branch attributes,
2121 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2122 +They correspond to the XATTR namespaces (see above). Additionally, to be
2123 +convenient, "icex" is also provided which means all "icex*" attributes
2124 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2126 +The meaning of these attributes is to ignore the error from setting
2127 +XATTR on that branch.
2128 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2129 +error from the dst branch according to the specified attributes.
2131 +Some XATTR may have its default value. The default value may come from
2132 +the parent dir or the environment. If the default value is set at the
2133 +file creating-time, it will be overwritten by copy-up.
2134 +Some contradiction may happen I am afraid.
2135 +Do we need another attribute to stop copying XATTR? I am unsure. For
2136 +now, aufs implements the branch attributes to ignore the error.
2137 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2138 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2139 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2016-02-28 11:26:32.569971135 +0100
2142 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2144 +# This program is free software; you can redistribute it and/or modify
2145 +# it under the terms of the GNU General Public License as published by
2146 +# the Free Software Foundation; either version 2 of the License, or
2147 +# (at your option) any later version.
2149 +# This program is distributed in the hope that it will be useful,
2150 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2151 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2152 +# GNU General Public License for more details.
2154 +# You should have received a copy of the GNU General Public License
2155 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2157 +Export Aufs via NFS
2158 +----------------------------------------------------------------------
2159 +Here is an approach.
2160 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2162 +- iget_locked(): initialize aufs inode generation for a new inode, and
2163 + store it in xigen file.
2164 +- destroy_inode(): increment aufs inode generation and store it in xigen
2165 + file. it is necessary even if it is not unlinked, because any data of
2166 + inode may be changed by UDBA.
2167 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2168 + build file handle by
2169 + + branch id (4 bytes)
2170 + + superblock generation (4 bytes)
2171 + + inode number (4 or 8 bytes)
2172 + + parent dir inode number (4 or 8 bytes)
2173 + + inode generation (4 bytes))
2174 + + return value of exportfs_encode_fh() for the parent on a branch (4
2176 + + file handle for a branch (by exportfs_encode_fh())
2178 + + find the index of a branch from its id in handle, and check it is
2179 + still exist in aufs.
2180 + + 1st level: get the inode number from handle and search it in cache.
2181 + + 2nd level: if not found in cache, get the parent inode number from
2182 + the handle and search it in cache. and then open the found parent
2183 + dir, find the matching inode number by vfs_readdir() and get its
2184 + name, and call lookup_one_len() for the target dentry.
2185 + + 3rd level: if the parent dir is not cached, call
2186 + exportfs_decode_fh() for a branch and get the parent on a branch,
2187 + build a pathname of it, convert it a pathname in aufs, call
2188 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2190 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2191 + for every branch, but not itself. to get this, (currently) aufs
2192 + searches in current->nsproxy->mnt_ns list. it may not be a good
2193 + idea, but I didn't get other approach.
2194 + + test the generation of the gotten inode.
2195 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2196 + convert it into ESTALE for NFSD.
2197 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2198 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2199 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2200 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2201 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2016-02-28 11:26:32.569971135 +0100
2204 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2206 +# This program is free software; you can redistribute it and/or modify
2207 +# it under the terms of the GNU General Public License as published by
2208 +# the Free Software Foundation; either version 2 of the License, or
2209 +# (at your option) any later version.
2211 +# This program is distributed in the hope that it will be useful,
2212 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2213 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2214 +# GNU General Public License for more details.
2216 +# You should have received a copy of the GNU General Public License
2217 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2219 +Show Whiteout Mode (shwh)
2220 +----------------------------------------------------------------------
2221 +Generally aufs hides the name of whiteouts. But in some cases, to show
2222 +them is very useful for users. For instance, creating a new middle layer
2223 +(branch) by merging existing layers.
2225 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2226 +When you have three branches,
2227 +- Bottom: 'system', squashfs (underlying base system), read-only
2228 +- Middle: 'mods', squashfs, read-only
2229 +- Top: 'overlay', ram (tmpfs), read-write
2231 +The top layer is loaded at boot time and saved at shutdown, to preserve
2232 +the changes made to the system during the session.
2233 +When larger changes have been made, or smaller changes have accumulated,
2234 +the size of the saved top layer data grows. At this point, it would be
2235 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2236 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2237 +restoring save and load speed.
2239 +This merging is simplified by the use of another aufs mount, of just the
2240 +two overlay branches using the 'shwh' option.
2241 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2242 + aufs /livesys/merge_union
2244 +A merged view of these two branches is then available at
2245 +/livesys/merge_union, and the new feature is that the whiteouts are
2247 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2248 +writing to all branches. Also the default mode for all branches is 'ro'.
2249 +It is now possible to save the combined contents of the two overlay
2250 +branches to a new squashfs, e.g.:
2251 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2253 +This new squashfs archive can be stored on the boot device and the
2254 +initramfs will use it to replace the old one at the next boot.
2255 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2256 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2257 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2016-02-28 11:26:32.569971135 +0100
2260 +# Copyright (C) 2010-2016 Junjiro R. Okajima
2262 +# This program is free software; you can redistribute it and/or modify
2263 +# it under the terms of the GNU General Public License as published by
2264 +# the Free Software Foundation; either version 2 of the License, or
2265 +# (at your option) any later version.
2267 +# This program is distributed in the hope that it will be useful,
2268 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2269 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2270 +# GNU General Public License for more details.
2272 +# You should have received a copy of the GNU General Public License
2273 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2275 +Dynamically customizable FS operations
2276 +----------------------------------------------------------------------
2277 +Generally FS operations (struct inode_operations, struct
2278 +address_space_operations, struct file_operations, etc.) are defined as
2279 +"static const", but it never means that FS have only one set of
2280 +operation. Some FS have multiple sets of them. For instance, ext2 has
2281 +three sets, one for XIP, for NOBH, and for normal.
2282 +Since aufs overrides and redirects these operations, sometimes aufs has
2283 +to change its behaviour according to the branch FS type. More importantly
2284 +VFS acts differently if a function (member in the struct) is set or
2285 +not. It means aufs should have several sets of operations and select one
2286 +among them according to the branch FS definition.
2288 +In order to solve this problem and not to affect the behaviour of VFS,
2289 +aufs defines these operations dynamically. For instance, aufs defines
2290 +dummy direct_IO function for struct address_space_operations, but it may
2291 +not be set to the address_space_operations actually. When the branch FS
2292 +doesn't have it, aufs doesn't set it to its address_space_operations
2293 +while the function definition itself is still alive. So the behaviour
2294 +itself will not change, and it will return an error when direct_IO is
2297 +The lifetime of these dynamically generated operation object is
2298 +maintained by aufs branch object. When the branch is removed from aufs,
2299 +the reference counter of the object is decremented. When it reaches
2300 +zero, the dynamically generated operation object will be freed.
2302 +This approach is designed to support AIO (io_submit), Direct I/O and
2304 +Currently this approach is applied to address_space_operations for
2305 +regular files only.
2306 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2307 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2308 +++ linux/Documentation/filesystems/aufs/README 2016-02-28 11:26:32.569971135 +0100
2311 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2317 +----------------------------------------
2318 +In the early days, aufs was entirely re-designed and re-implemented
2319 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2320 +improvements and implementations, it becomes totally different from
2321 +Unionfs while keeping the basic features.
2322 +Recently, Unionfs Version 2.x series begin taking some of the same
2323 +approaches to aufs1's.
2324 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2325 +University and his team.
2327 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2328 +If you want older kernel version support, try aufs2-2.6.git or
2329 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2331 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2332 + According to Christoph Hellwig, linux rejects all union-type
2333 + filesystems but UnionMount.
2334 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2336 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2337 + UnionMount, and he pointed out an issue around a directory mutex
2338 + lock and aufs addressed it. But it is still unsure whether aufs will
2339 + be merged (or any other union solution).
2340 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2344 +----------------------------------------
2345 +- unite several directories into a single virtual filesystem. The member
2346 + directory is called as a branch.
2347 +- you can specify the permission flags to the branch, which are 'readonly',
2348 + 'readwrite' and 'whiteout-able.'
2349 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2350 + readonly branch are modifiable logically.
2351 +- dynamic branch manipulation, add, del.
2354 +Also there are many enhancements in aufs, such as:
2355 +- test only the highest one for the directory permission (dirperm1)
2356 +- copyup on open (coo=)
2357 +- 'move' policy for copy-up between two writable branches, after
2358 + checking free space.
2360 +- readdir(3) in userspace.
2361 +- keep inode number by external inode number table
2362 +- keep the timestamps of file/dir in internal copyup operation
2363 +- seekable directory, supporting NFS readdir.
2364 +- whiteout is hardlinked in order to reduce the consumption of inodes
2366 +- do not copyup, nor create a whiteout when it is unnecessary
2367 +- revert a single systemcall when an error occurs in aufs
2368 +- remount interface instead of ioctl
2369 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2370 +- loopback mounted filesystem as a branch
2371 +- kernel thread for removing the dir who has a plenty of whiteouts
2372 +- support copyup sparse file (a file which has a 'hole' in it)
2373 +- default permission flags for branches
2374 +- selectable permission flags for ro branch, whether whiteout can
2377 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2378 +- support multiple writable branches, some policies to select one
2379 + among multiple writable branches.
2380 +- a new semantics for link(2) and rename(2) to support multiple
2381 + writable branches.
2382 +- no glibc changes are required.
2383 +- pseudo hardlink (hardlink over branches)
2384 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2385 + including NFS or remote filesystem branch.
2386 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2389 +Currently these features are dropped temporary from aufs4.
2390 +See design/08plan.txt in detail.
2391 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2393 +- statistics of aufs thread (/sys/fs/aufs/stat)
2395 +Features or just an idea in the future (see also design/*.txt),
2396 +- reorder the branch index without del/re-add.
2397 +- permanent xino files for NFSD
2398 +- an option for refreshing the opened files after add/del branches
2399 +- light version, without branch manipulation. (unnecessary?)
2400 +- copyup in userspace
2401 +- inotify in userspace
2406 +----------------------------------------
2407 +There are three GIT trees for aufs4, aufs4-linux.git,
2408 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2410 +While the aufs-util is always necessary, you need either of aufs4-linux
2411 +or aufs4-standalone.
2413 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2414 +git://git.kernel.org/.../torvalds/linux.git.
2415 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2416 +build aufs4 as an external kernel module.
2417 +Several extra patches are not included in this tree. Only
2418 +aufs4-standalone tree contains them. They are described in the later
2419 +section "Configuration and Compilation."
2421 +On the other hand, the aufs4-standalone tree has only aufs source files
2422 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2423 +But you need to apply all aufs patches manually.
2425 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2426 +represents the linux kernel version, "linux-4.x". For instance,
2427 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2428 +"aufs4.x-rcN" branch.
2431 +$ git clone --reference /your/linux/git/tree \
2432 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2433 +- if you don't have linux GIT tree, then remove "--reference ..."
2434 +$ cd aufs4-linux.git
2435 +$ git checkout origin/aufs4.0
2437 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2438 +leave the patch-work to GIT.
2439 +$ cd /your/linux/git/tree
2440 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2442 +$ git checkout -b my4.0 v4.0
2443 +$ (add your local change...)
2444 +$ git pull aufs4 aufs4.0
2445 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2446 +- you may need to solve some conflicts between your_changes and
2447 + aufs4.0. in this case, git-rerere is recommended so that you can
2448 + solve the similar conflicts automatically when you upgrade to 4.1 or
2449 + later in the future.
2451 +o aufs4-standalone tree
2452 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2453 +$ cd aufs4-standalone.git
2454 +$ git checkout origin/aufs4.0
2457 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2458 +- note that the public aufs-util.git is on SourceForge instead of
2461 +$ git checkout origin/aufs4.0
2463 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2464 +The minor version number, 'x' in '4.x', of aufs may not always
2465 +follow the minor version number of the kernel.
2466 +Because changes in the kernel that cause the use of a new
2467 +minor version number do not always require changes to aufs-util.
2469 +Since aufs-util has its own minor version number, you may not be
2470 +able to find a GIT branch in aufs-util for your kernel's
2471 +exact minor version number.
2472 +In this case, you should git-checkout the branch for the
2473 +nearest lower number.
2475 +For (an unreleased) example:
2476 +If you are using "linux-4.10" and the "aufs4.10" branch
2477 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2478 +or something numerically smaller is the branch for your kernel.
2480 +Also you can view all branches by
2484 +3. Configuration and Compilation
2485 +----------------------------------------
2486 +Make sure you have git-checkout'ed the correct branch.
2488 +For aufs4-linux tree,
2489 +- enable CONFIG_AUFS_FS.
2490 +- set other aufs configurations if necessary.
2492 +For aufs4-standalone tree,
2493 +There are several ways to build.
2496 +- apply ./aufs4-kbuild.patch to your kernel source files.
2497 +- apply ./aufs4-base.patch too.
2498 +- apply ./aufs4-mmap.patch too.
2499 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2500 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2501 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2502 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2503 +- enable CONFIG_AUFS_FS, you can select either
2505 +- and build your kernel as usual.
2506 +- install the built kernel.
2507 + Note: Since linux-3.9, every filesystem module requires an alias
2508 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2509 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2510 +- install the header files too by "make headers_install" to the
2511 + directory where you specify. By default, it is $PWD/usr.
2512 + "make help" shows a brief note for headers_install.
2513 +- and reboot your system.
2516 +- module only (CONFIG_AUFS_FS=m).
2517 +- apply ./aufs4-base.patch to your kernel source files.
2518 +- apply ./aufs4-mmap.patch too.
2519 +- apply ./aufs4-standalone.patch too.
2520 +- build your kernel, don't forget "make headers_install", and reboot.
2521 +- edit ./config.mk and set other aufs configurations if necessary.
2522 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2523 + every aufs configurations.
2524 +- build the module by simple "make".
2525 + Note: Since linux-3.9, every filesystem module requires an alias
2526 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2527 + modules.aliases file.
2528 +- you can specify ${KDIR} make variable which points to your kernel
2530 +- install the files
2531 + + run "make install" to install the aufs module, or copy the built
2532 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2533 + + run "make install_headers" (instead of headers_install) to install
2534 + the modified aufs header file (you can specify DESTDIR which is
2535 + available in aufs standalone version's Makefile only), or copy
2536 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2537 + you like manually. By default, the target directory is $PWD/usr.
2538 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2539 + kernel source tree.
2541 +Note: The header file aufs_type.h is necessary to build aufs-util
2542 + as well as "make headers_install" in the kernel source tree.
2543 + headers_install is subject to be forgotten, but it is essentially
2544 + necessary, not only for building aufs-util.
2545 + You may not meet problems without headers_install in some older
2549 +- read README in aufs-util, build and install it
2550 +- note that your distribution may contain an obsoleted version of
2551 + aufs_type.h in /usr/include/linux or something. When you build aufs
2552 + utilities, make sure that your compiler refers the correct aufs header
2553 + file which is built by "make headers_install."
2554 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2555 + then run "make install_ulib" too. And refer to the aufs manual in
2558 +There several other patches in aufs4-standalone.git. They are all
2559 +optional. When you meet some problems, they will help you.
2560 +- aufs4-loopback.patch
2561 + Supports a nested loopback mount in a branch-fs. This patch is
2562 + unnecessary until aufs produces a message like "you may want to try
2563 + another patch for loopback file".
2565 + Modifies a system global kernel internal function get_next_ino() in
2566 + order to stop assigning 0 for an inode-number. Not directly related to
2567 + aufs, but recommended generally.
2569 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2570 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2571 + duplication of inode number, which is important for backup tools and
2572 + other utilities. When you find aufs XINO files for tmpfs branch
2573 + growing too much, try this patch.
2574 +- lockdep-debug.patch
2575 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2576 + also a caller of VFS functions for branch filesystems, subclassing of
2577 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2578 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2579 + need to apply this debug patch to expand several constant values.
2580 + If don't know what LOCKDEP, then you don't have apply this patch.
2584 +----------------------------------------
2585 +At first, make sure aufs-util are installed, and please read the aufs
2586 +manual, aufs.5 in aufs-util.git tree.
2590 +$ mkdir /tmp/rw /tmp/aufs
2591 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2593 +Here is another example. The result is equivalent.
2594 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2596 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2597 +# mount -o remount,append:${HOME} /tmp/aufs
2599 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2600 +you modify a file under /tmp/aufs, the one on your home directory is
2601 +not affected, instead the same named file will be newly created under
2602 +/tmp/rw. And all of your modification to a file will be applied to
2603 +the one under /tmp/rw. This is called the file based Copy on Write
2605 +Aufs mount options are described in aufs.5.
2606 +If you run chroot or something and make your aufs as a root directory,
2607 +then you need to customize the shutdown script. See the aufs manual in
2610 +Additionally, there are some sample usages of aufs which are a
2611 +diskless system with network booting, and LiveCD over NFS.
2612 +See sample dir in CVS tree on SourceForge.
2616 +----------------------------------------
2617 +When you have any problems or strange behaviour in aufs, please let me
2619 +- /proc/mounts (instead of the output of mount(8))
2620 +- /sys/module/aufs/*
2621 +- /sys/fs/aufs/* (if you have them)
2622 +- /debug/aufs/* (if you have them)
2623 +- linux kernel version
2624 + if your kernel is not plain, for example modified by distributor,
2625 + the url where i can download its source is necessary too.
2626 +- aufs version which was printed at loading the module or booting the
2627 + system, instead of the date you downloaded.
2628 +- configuration (define/undefine CONFIG_AUFS_xxx)
2629 +- kernel configuration or /proc/config.gz (if you have it)
2630 +- behaviour which you think to be incorrect
2631 +- actual operation, reproducible one is better
2632 +- mailto: aufs-users at lists.sourceforge.net
2634 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2635 +and Feature Requests) on SourceForge. Please join and write to
2639 +6. Acknowledgements
2640 +----------------------------------------
2641 +Thanks to everyone who have tried and are using aufs, whoever
2642 +have reported a bug or any feedback.
2644 +Especially donators:
2645 +Tomas Matejicek(slax.org) made a donation (much more than once).
2646 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2647 + scripts) is making "doubling" donations.
2648 + Unfortunately I cannot list all of the donators, but I really
2650 + It ends Aug 2010, but the ordinary donation URL is still available.
2651 + <http://sourceforge.net/donate/index.php?group_id=167503>
2652 +Dai Itasaka made a donation (2007/8).
2653 +Chuck Smith made a donation (2008/4, 10 and 12).
2654 +Henk Schoneveld made a donation (2008/9).
2655 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2656 +Francois Dupoux made a donation (2008/11).
2657 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2658 + aufs2 GIT tree (2009/2).
2659 +William Grant made a donation (2009/3).
2660 +Patrick Lane made a donation (2009/4).
2661 +The Mail Archive (mail-archive.com) made donations (2009/5).
2662 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2663 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2664 +Pavel Pronskiy made a donation (2011/2).
2665 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2666 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2667 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2669 +Sam Liddicott made a donation (2011/9).
2670 +Era Scarecrow made a donation (2013/4).
2671 +Bor Ratajc made a donation (2013/4).
2672 +Alessandro Gorreta made a donation (2013/4).
2673 +POIRETTE Marc made a donation (2013/4).
2674 +Alessandro Gorreta made a donation (2013/4).
2675 +lauri kasvandik made a donation (2013/5).
2676 +"pemasu from Finland" made a donation (2013/7).
2677 +The Parted Magic Project made a donation (2013/9 and 11).
2678 +Pavel Barta made a donation (2013/10).
2679 +Nikolay Pertsev made a donation (2014/5).
2680 +James B made a donation (2014/7 and 2015/7).
2681 +Stefano Di Biase made a donation (2014/8).
2682 +Daniel Epellei made a donation (2015/1).
2683 +OmegaPhil made a donation (2016/1).
2685 +Thank you very much.
2686 +Donations are always, including future donations, very important and
2687 +helpful for me to keep on developing aufs.
2691 +----------------------------------------
2692 +If you are an experienced user, no explanation is needed. Aufs is
2693 +just a linux filesystem.
2698 +# Local variables: ;
2701 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2702 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2703 +++ linux/fs/aufs/aufs.h 2016-02-28 11:26:32.569971135 +0100
2706 + * Copyright (C) 2005-2016 Junjiro R. Okajima
2708 + * This program, aufs is free software; you can redistribute it and/or modify
2709 + * it under the terms of the GNU General Public License as published by
2710 + * the Free Software Foundation; either version 2 of the License, or
2711 + * (at your option) any later version.
2713 + * This program is distributed in the hope that it will be useful,
2714 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2715 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2716 + * GNU General Public License for more details.
2718 + * You should have received a copy of the GNU General Public License
2719 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2723 + * all header files
2731 +#define AuStub(type, name, body, ...) \
2732 + static inline type name(__VA_ARGS__) { body; }
2734 +#define AuStubVoid(name, ...) \
2735 + AuStub(void, name, , __VA_ARGS__)
2736 +#define AuStubInt0(name, ...) \
2737 + AuStub(int, name, return 0, __VA_ARGS__)
2741 +#include "branch.h"
2744 +#include "dbgaufs.h"
2745 +#include "dentry.h"
2749 +#include "fstype.h"
2752 +#include "module.h"
2757 +#include "sysaufs.h"
2762 +#endif /* __KERNEL__ */
2763 +#endif /* __AUFS_H__ */
2764 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2765 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2766 +++ linux/fs/aufs/branch.c 2016-02-28 11:26:32.569971135 +0100
2769 + * Copyright (C) 2005-2016 Junjiro R. Okajima
2771 + * This program, aufs is free software; you can redistribute it and/or modify
2772 + * it under the terms of the GNU General Public License as published by
2773 + * the Free Software Foundation; either version 2 of the License, or
2774 + * (at your option) any later version.
2776 + * This program is distributed in the hope that it will be useful,
2777 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2778 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2779 + * GNU General Public License for more details.
2781 + * You should have received a copy of the GNU General Public License
2782 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2786 + * branch management
2789 +#include <linux/compat.h>
2790 +#include <linux/statfs.h>
2794 + * free a single branch
2796 +static void au_br_do_free(struct au_branch *br)
2799 + struct au_wbr *wbr;
2800 + struct au_dykey **key;
2802 + au_hnotify_fin_br(br);
2804 + if (br->br_xino.xi_file)
2805 + fput(br->br_xino.xi_file);
2806 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2808 + AuDebugOn(atomic_read(&br->br_count));
2812 + for (i = 0; i < AuBrWh_Last; i++)
2813 + dput(wbr->wbr_wh[i]);
2814 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2815 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2818 + if (br->br_fhsm) {
2819 + au_br_fhsm_fin(br->br_fhsm);
2820 + kfree(br->br_fhsm);
2823 + key = br->br_dykey;
2824 + for (i = 0; i < AuBrDynOp; i++, key++)
2830 + /* recursive lock, s_umount of branch's */
2832 + path_put(&br->br_path);
2839 + * frees all branches
2841 +void au_br_free(struct au_sbinfo *sbinfo)
2843 + aufs_bindex_t bmax;
2844 + struct au_branch **br;
2846 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2848 + bmax = sbinfo->si_bend + 1;
2849 + br = sbinfo->si_branch;
2851 + au_br_do_free(*br++);
2855 + * find the index of a branch which is specified by @br_id.
2857 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2859 + aufs_bindex_t bindex, bend;
2861 + bend = au_sbend(sb);
2862 + for (bindex = 0; bindex <= bend; bindex++)
2863 + if (au_sbr_id(sb, bindex) == br_id)
2868 +/* ---------------------------------------------------------------------- */
2874 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2875 + struct dentry *h_root)
2877 + if (unlikely(h_adding == h_root
2878 + || au_test_loopback_overlap(sb, h_adding)))
2880 + if (h_adding->d_sb != h_root->d_sb)
2882 + return au_test_subdir(h_adding, h_root)
2883 + || au_test_subdir(h_root, h_adding);
2887 + * returns a newly allocated branch. @new_nbranch is a number of branches
2888 + * after adding a branch.
2890 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2893 + struct au_branch *add_branch;
2894 + struct dentry *root;
2895 + struct inode *inode;
2899 + root = sb->s_root;
2900 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
2901 + if (unlikely(!add_branch))
2904 + err = au_hnotify_init_br(add_branch, perm);
2905 + if (unlikely(err))
2908 + if (au_br_writable(perm)) {
2909 + /* may be freed separately at changing the branch permission */
2910 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
2912 + if (unlikely(!add_branch->br_wbr))
2916 + if (au_br_fhsm(perm)) {
2917 + err = au_fhsm_br_alloc(add_branch);
2918 + if (unlikely(err))
2922 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2924 + err = au_di_realloc(au_di(root), new_nbranch);
2926 + inode = d_inode(root);
2927 + err = au_ii_realloc(au_ii(inode), new_nbranch);
2930 + return add_branch; /* success */
2933 + kfree(add_branch->br_wbr);
2935 + au_hnotify_fin_br(add_branch);
2937 + kfree(add_branch);
2939 + return ERR_PTR(err);
2943 + * test if the branch permission is legal or not.
2945 +static int test_br(struct inode *inode, int brperm, char *path)
2949 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2954 + pr_err("write permission for readonly mount or inode, %s\n", path);
2962 + * 0: success, the caller will add it
2963 + * plus: success, it is already unified, the caller should ignore it
2966 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2969 + aufs_bindex_t bend, bindex;
2970 + struct dentry *root, *h_dentry;
2971 + struct inode *inode, *h_inode;
2973 + root = sb->s_root;
2974 + bend = au_sbend(sb);
2975 + if (unlikely(bend >= 0
2976 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2980 + pr_err("%s duplicated\n", add->pathname);
2985 + err = -ENOSPC; /* -E2BIG; */
2986 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2987 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2988 + pr_err("number of branches exceeded %s\n", add->pathname);
2993 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2994 + pr_err("bad index %d\n", add->bindex);
2998 + inode = d_inode(add->path.dentry);
3000 + if (unlikely(!inode->i_nlink)) {
3001 + pr_err("no existence %s\n", add->pathname);
3006 + if (unlikely(inode->i_sb == sb)) {
3007 + pr_err("%s must be outside\n", add->pathname);
3011 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3012 + pr_err("unsupported filesystem, %s (%s)\n",
3013 + add->pathname, au_sbtype(inode->i_sb));
3017 + if (unlikely(inode->i_sb->s_stack_depth)) {
3018 + pr_err("already stacked, %s (%s)\n",
3019 + add->pathname, au_sbtype(inode->i_sb));
3023 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3024 + if (unlikely(err))
3028 + return 0; /* success */
3031 + for (bindex = 0; bindex <= bend; bindex++)
3032 + if (unlikely(test_overlap(sb, add->path.dentry,
3033 + au_h_dptr(root, bindex)))) {
3034 + pr_err("%s is overlapped\n", add->pathname);
3039 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3040 + h_dentry = au_h_dptr(root, 0);
3041 + h_inode = d_inode(h_dentry);
3042 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3043 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3044 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3045 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3047 + i_uid_read(inode), i_gid_read(inode),
3048 + (inode->i_mode & S_IALLUGO),
3049 + i_uid_read(h_inode), i_gid_read(h_inode),
3050 + (h_inode->i_mode & S_IALLUGO));
3058 + * initialize or clean the whiteouts for an adding branch
3060 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3063 + int err, old_perm;
3064 + aufs_bindex_t bindex;
3065 + struct mutex *h_mtx;
3066 + struct au_wbr *wbr;
3067 + struct au_hinode *hdir;
3068 + struct dentry *h_dentry;
3070 + err = vfsub_mnt_want_write(au_br_mnt(br));
3071 + if (unlikely(err))
3075 + old_perm = br->br_perm;
3076 + br->br_perm = new_perm;
3079 + bindex = au_br_index(sb, br->br_id);
3080 + if (0 <= bindex) {
3081 + hdir = au_hi(d_inode(sb->s_root), bindex);
3082 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
3084 + h_dentry = au_br_dentry(br);
3085 + h_mtx = &d_inode(h_dentry)->i_mutex;
3086 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
3089 + err = au_wh_init(br, sb);
3091 + wbr_wh_write_lock(wbr);
3092 + err = au_wh_init(br, sb);
3093 + wbr_wh_write_unlock(wbr);
3096 + au_hn_imtx_unlock(hdir);
3098 + mutex_unlock(h_mtx);
3099 + vfsub_mnt_drop_write(au_br_mnt(br));
3100 + br->br_perm = old_perm;
3102 + if (!err && wbr && !au_br_writable(new_perm)) {
3104 + br->br_wbr = NULL;
3111 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3115 + struct kstatfs kst;
3116 + struct au_wbr *wbr;
3119 + au_rw_init(&wbr->wbr_wh_rwsem);
3120 + atomic_set(&wbr->wbr_wh_running, 0);
3123 + * a limit for rmdir/rename a dir
3124 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3126 + err = vfs_statfs(&br->br_path, &kst);
3127 + if (unlikely(err))
3130 + if (kst.f_namelen >= NAME_MAX)
3131 + err = au_br_init_wh(sb, br, perm);
3133 + pr_err("%pd(%s), unsupported namelen %ld\n",
3135 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3141 +/* initialize a new branch */
3142 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3143 + struct au_opt_add *add)
3146 + struct inode *h_inode;
3149 + mutex_init(&br->br_xino.xi_nondir_mtx);
3150 + br->br_perm = add->perm;
3151 + br->br_path = add->path; /* set first, path_get() later */
3152 + spin_lock_init(&br->br_dykey_lock);
3153 + atomic_set(&br->br_count, 0);
3154 + atomic_set(&br->br_xino_running, 0);
3155 + br->br_id = au_new_br_id(sb);
3156 + AuDebugOn(br->br_id < 0);
3158 + if (au_br_writable(add->perm)) {
3159 + err = au_wbr_init(br, sb, add->perm);
3160 + if (unlikely(err))
3164 + if (au_opt_test(au_mntflags(sb), XINO)) {
3165 + h_inode = d_inode(add->path.dentry);
3166 + err = au_xino_br(sb, br, h_inode->i_ino,
3167 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3168 + if (unlikely(err)) {
3169 + AuDebugOn(br->br_xino.xi_file);
3174 + sysaufs_br_init(br);
3175 + path_get(&br->br_path);
3176 + goto out; /* success */
3179 + memset(&br->br_path, 0, sizeof(br->br_path));
3184 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3185 + struct au_branch *br, aufs_bindex_t bend,
3186 + aufs_bindex_t amount)
3188 + struct au_branch **brp;
3190 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3192 + brp = sbinfo->si_branch + bindex;
3193 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3195 + sbinfo->si_bend++;
3196 + if (unlikely(bend < 0))
3197 + sbinfo->si_bend = 0;
3200 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3201 + aufs_bindex_t bend, aufs_bindex_t amount)
3203 + struct au_hdentry *hdp;
3205 + AuRwMustWriteLock(&dinfo->di_rwsem);
3207 + hdp = dinfo->di_hdentry + bindex;
3208 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3209 + au_h_dentry_init(hdp);
3211 + if (unlikely(bend < 0))
3212 + dinfo->di_bstart = 0;
3215 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3216 + aufs_bindex_t bend, aufs_bindex_t amount)
3218 + struct au_hinode *hip;
3220 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3222 + hip = iinfo->ii_hinode + bindex;
3223 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3224 + hip->hi_inode = NULL;
3227 + if (unlikely(bend < 0))
3228 + iinfo->ii_bstart = 0;
3231 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3232 + aufs_bindex_t bindex)
3234 + struct dentry *root, *h_dentry;
3235 + struct inode *root_inode, *h_inode;
3236 + aufs_bindex_t bend, amount;
3238 + root = sb->s_root;
3239 + root_inode = d_inode(root);
3240 + bend = au_sbend(sb);
3241 + amount = bend + 1 - bindex;
3242 + h_dentry = au_br_dentry(br);
3243 + au_sbilist_lock();
3244 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
3245 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
3246 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
3247 + au_set_h_dptr(root, bindex, dget(h_dentry));
3248 + h_inode = d_inode(h_dentry);
3249 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3250 + au_sbilist_unlock();
3253 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3256 + aufs_bindex_t bend, add_bindex;
3257 + struct dentry *root, *h_dentry;
3258 + struct inode *root_inode;
3259 + struct au_branch *add_branch;
3261 + root = sb->s_root;
3262 + root_inode = d_inode(root);
3263 + IMustLock(root_inode);
3264 + err = test_add(sb, add, remount);
3265 + if (unlikely(err < 0))
3269 + goto out; /* success */
3272 + bend = au_sbend(sb);
3273 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
3274 + err = PTR_ERR(add_branch);
3275 + if (IS_ERR(add_branch))
3278 + err = au_br_init(add_branch, sb, add);
3279 + if (unlikely(err)) {
3280 + au_br_do_free(add_branch);
3284 + add_bindex = add->bindex;
3286 + au_br_do_add(sb, add_branch, add_bindex);
3288 + sysaufs_brs_del(sb, add_bindex);
3289 + au_br_do_add(sb, add_branch, add_bindex);
3290 + sysaufs_brs_add(sb, add_bindex);
3293 + h_dentry = add->path.dentry;
3294 + if (!add_bindex) {
3295 + au_cpup_attr_all(root_inode, /*force*/1);
3296 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3298 + au_add_nlink(root_inode, d_inode(h_dentry));
3301 + * this test/set prevents aufs from handling unnecesary notify events
3302 + * of xino files, in case of re-adding a writable branch which was
3303 + * once detached from aufs.
3305 + if (au_xino_brid(sb) < 0
3306 + && au_br_writable(add_branch->br_perm)
3307 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3308 + && add_branch->br_xino.xi_file
3309 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3310 + au_xino_brid_set(sb, add_branch->br_id);
3316 +/* ---------------------------------------------------------------------- */
3318 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3319 + unsigned long long max __maybe_unused,
3322 + unsigned long long n;
3323 + struct file **p, *f;
3324 + struct au_sphlhead *files;
3325 + struct au_finfo *finfo;
3329 + files = &au_sbi(sb)->si_files;
3330 + spin_lock(&files->spin);
3331 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3332 + f = finfo->fi_file;
3334 + && !special_file(file_inode(f)->i_mode)) {
3338 + AuDebugOn(n > max);
3341 + spin_unlock(&files->spin);
3346 +static struct file **au_farray_alloc(struct super_block *sb,
3347 + unsigned long long *max)
3349 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3350 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3353 +static void au_farray_free(struct file **a, unsigned long long max)
3355 + unsigned long long ull;
3357 + for (ull = 0; ull < max; ull++)
3363 +/* ---------------------------------------------------------------------- */
3369 +/* to show the line number, do not make it inlined function */
3370 +#define AuVerbose(do_info, fmt, ...) do { \
3372 + pr_info(fmt, ##__VA_ARGS__); \
3375 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
3376 + aufs_bindex_t bend)
3378 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
3381 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
3382 + aufs_bindex_t bend)
3384 + return au_test_ibusy(d_inode(dentry), bstart, bend);
3388 + * test if the branch is deletable or not.
3390 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3391 + unsigned int sigen, const unsigned int verbose)
3393 + int err, i, j, ndentry;
3394 + aufs_bindex_t bstart, bend;
3395 + struct au_dcsub_pages dpages;
3396 + struct au_dpage *dpage;
3399 + err = au_dpages_init(&dpages, GFP_NOFS);
3400 + if (unlikely(err))
3402 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3403 + if (unlikely(err))
3406 + for (i = 0; !err && i < dpages.ndpage; i++) {
3407 + dpage = dpages.dpages + i;
3408 + ndentry = dpage->ndentry;
3409 + for (j = 0; !err && j < ndentry; j++) {
3410 + d = dpage->dentries[j];
3411 + AuDebugOn(au_dcount(d) <= 0);
3412 + if (!au_digen_test(d, sigen)) {
3413 + di_read_lock_child(d, AuLock_IR);
3414 + if (unlikely(au_dbrange_test(d))) {
3415 + di_read_unlock(d, AuLock_IR);
3419 + di_write_lock_child(d);
3420 + if (unlikely(au_dbrange_test(d))) {
3421 + di_write_unlock(d);
3424 + err = au_reval_dpath(d, sigen);
3426 + di_downgrade_lock(d, AuLock_IR);
3428 + di_write_unlock(d);
3433 + /* AuDbgDentry(d); */
3434 + bstart = au_dbstart(d);
3435 + bend = au_dbend(d);
3436 + if (bstart <= bindex
3438 + && au_h_dptr(d, bindex)
3439 + && au_test_dbusy(d, bstart, bend)) {
3441 + AuVerbose(verbose, "busy %pd\n", d);
3444 + di_read_unlock(d, AuLock_IR);
3449 + au_dpages_free(&dpages);
3454 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3455 + unsigned int sigen, const unsigned int verbose)
3458 + unsigned long long max, ull;
3459 + struct inode *i, **array;
3460 + aufs_bindex_t bstart, bend;
3462 + array = au_iarray_alloc(sb, &max);
3463 + err = PTR_ERR(array);
3464 + if (IS_ERR(array))
3468 + AuDbg("b%d\n", bindex);
3469 + for (ull = 0; !err && ull < max; ull++) {
3473 + if (i->i_ino == AUFS_ROOT_INO)
3476 + /* AuDbgInode(i); */
3477 + if (au_iigen(i, NULL) == sigen)
3478 + ii_read_lock_child(i);
3480 + ii_write_lock_child(i);
3481 + err = au_refresh_hinode_self(i);
3484 + ii_downgrade_lock(i);
3486 + ii_write_unlock(i);
3491 + bstart = au_ibstart(i);
3492 + bend = au_ibend(i);
3493 + if (bstart <= bindex
3495 + && au_h_iptr(i, bindex)
3496 + && au_test_ibusy(i, bstart, bend)) {
3498 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3501 + ii_read_unlock(i);
3503 + au_iarray_free(array, max);
3509 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3510 + const unsigned int verbose)
3513 + unsigned int sigen;
3515 + sigen = au_sigen(root->d_sb);
3516 + DiMustNoWaiters(root);
3517 + IiMustNoWaiters(d_inode(root));
3518 + di_write_unlock(root);
3519 + err = test_dentry_busy(root, bindex, sigen, verbose);
3521 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3522 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3527 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3528 + struct file **to_free, int *idx)
3531 + unsigned char matched, root;
3532 + aufs_bindex_t bindex, bend;
3533 + struct au_fidir *fidir;
3534 + struct au_hfile *hfile;
3537 + root = IS_ROOT(file->f_path.dentry);
3540 + to_free[*idx] = file;
3546 + fidir = au_fi(file)->fi_hdir;
3547 + AuDebugOn(!fidir);
3548 + bend = au_fbend_dir(file);
3549 + for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
3550 + hfile = fidir->fd_hfile + bindex;
3551 + if (!hfile->hf_file)
3554 + if (hfile->hf_br->br_id == br_id) {
3566 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3567 + struct file **to_free, int opened)
3570 + unsigned long long ull, max;
3571 + aufs_bindex_t bstart;
3572 + struct file *file, **array;
3573 + struct dentry *root;
3574 + struct au_hfile *hfile;
3576 + array = au_farray_alloc(sb, &max);
3577 + err = PTR_ERR(array);
3578 + if (IS_ERR(array))
3583 + root = sb->s_root;
3584 + di_write_unlock(root);
3585 + for (ull = 0; ull < max; ull++) {
3586 + file = array[ull];
3587 + if (unlikely(!file))
3590 + /* AuDbg("%pD\n", file); */
3591 + fi_read_lock(file);
3592 + bstart = au_fbstart(file);
3593 + if (!d_is_dir(file->f_path.dentry)) {
3594 + hfile = &au_fi(file)->fi_htop;
3595 + if (hfile->hf_br->br_id == br_id)
3598 + err = test_dir_busy(file, br_id, to_free, &idx);
3599 + fi_read_unlock(file);
3600 + if (unlikely(err))
3603 + di_write_lock_child(root);
3604 + au_farray_free(array, max);
3605 + AuDebugOn(idx > opened);
3611 +static void br_del_file(struct file **to_free, unsigned long long opened,
3612 + aufs_bindex_t br_id)
3614 + unsigned long long ull;
3615 + aufs_bindex_t bindex, bstart, bend, bfound;
3616 + struct file *file;
3617 + struct au_fidir *fidir;
3618 + struct au_hfile *hfile;
3620 + for (ull = 0; ull < opened; ull++) {
3621 + file = to_free[ull];
3622 + if (unlikely(!file))
3625 + /* AuDbg("%pD\n", file); */
3626 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3628 + fidir = au_fi(file)->fi_hdir;
3629 + AuDebugOn(!fidir);
3630 + fi_write_lock(file);
3631 + bstart = au_fbstart(file);
3632 + bend = au_fbend_dir(file);
3633 + for (bindex = bstart; bindex <= bend; bindex++) {
3634 + hfile = fidir->fd_hfile + bindex;
3635 + if (!hfile->hf_file)
3638 + if (hfile->hf_br->br_id == br_id) {
3643 + AuDebugOn(bfound < 0);
3644 + au_set_h_fptr(file, bfound, NULL);
3645 + if (bfound == bstart) {
3646 + for (bstart++; bstart <= bend; bstart++)
3647 + if (au_hf_dir(file, bstart)) {
3648 + au_set_fbstart(file, bstart);
3652 + fi_write_unlock(file);
3656 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3657 + const aufs_bindex_t bindex,
3658 + const aufs_bindex_t bend)
3660 + struct au_branch **brp, **p;
3662 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3664 + brp = sbinfo->si_branch + bindex;
3665 + if (bindex < bend)
3666 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3667 + sbinfo->si_branch[0 + bend] = NULL;
3668 + sbinfo->si_bend--;
3670 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3672 + sbinfo->si_branch = p;
3673 + /* harmless error */
3676 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3677 + const aufs_bindex_t bend)
3679 + struct au_hdentry *hdp, *p;
3681 + AuRwMustWriteLock(&dinfo->di_rwsem);
3683 + hdp = dinfo->di_hdentry;
3684 + if (bindex < bend)
3685 + memmove(hdp + bindex, hdp + bindex + 1,
3686 + sizeof(*hdp) * (bend - bindex));
3687 + hdp[0 + bend].hd_dentry = NULL;
3690 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3692 + dinfo->di_hdentry = p;
3693 + /* harmless error */
3696 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3697 + const aufs_bindex_t bend)
3699 + struct au_hinode *hip, *p;
3701 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3703 + hip = iinfo->ii_hinode + bindex;
3704 + if (bindex < bend)
3705 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3706 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3707 + au_hn_init(iinfo->ii_hinode + bend);
3710 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3712 + iinfo->ii_hinode = p;
3713 + /* harmless error */
3716 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3717 + struct au_branch *br)
3719 + aufs_bindex_t bend;
3720 + struct au_sbinfo *sbinfo;
3721 + struct dentry *root, *h_root;
3722 + struct inode *inode, *h_inode;
3723 + struct au_hinode *hinode;
3725 + SiMustWriteLock(sb);
3727 + root = sb->s_root;
3728 + inode = d_inode(root);
3729 + sbinfo = au_sbi(sb);
3730 + bend = sbinfo->si_bend;
3732 + h_root = au_h_dptr(root, bindex);
3733 + hinode = au_hi(inode, bindex);
3734 + h_inode = au_igrab(hinode->hi_inode);
3737 + au_sbilist_lock();
3738 + au_br_do_del_brp(sbinfo, bindex, bend);
3739 + au_br_do_del_hdp(au_di(root), bindex, bend);
3740 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3741 + au_sbilist_unlock();
3745 + au_br_do_free(br);
3748 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3749 + unsigned long long max, void *arg)
3754 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3757 + unsigned long long opened;
3758 + unsigned int mnt_flags;
3759 + aufs_bindex_t bindex, bend, br_id;
3760 + unsigned char do_wh, verbose;
3761 + struct au_branch *br;
3762 + struct au_wbr *wbr;
3763 + struct dentry *root;
3764 + struct file **to_free;
3769 + root = sb->s_root;
3770 + bindex = au_find_dbindex(root, del->h_path.dentry);
3773 + goto out; /* success */
3775 + pr_err("%s no such branch\n", del->pathname);
3778 + AuDbg("bindex b%d\n", bindex);
3781 + mnt_flags = au_mntflags(sb);
3782 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3783 + bend = au_sbend(sb);
3784 + if (unlikely(!bend)) {
3785 + AuVerbose(verbose, "no more branches left\n");
3788 + br = au_sbr(sb, bindex);
3789 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3791 + br_id = br->br_id;
3792 + opened = atomic_read(&br->br_count);
3793 + if (unlikely(opened)) {
3794 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3795 + err = PTR_ERR(to_free);
3796 + if (IS_ERR(to_free))
3799 + err = test_file_busy(sb, br_id, to_free, opened);
3800 + if (unlikely(err)) {
3801 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3807 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3809 + /* instead of WbrWhMustWriteLock(wbr) */
3810 + SiMustWriteLock(sb);
3811 + for (i = 0; i < AuBrWh_Last; i++) {
3812 + dput(wbr->wbr_wh[i]);
3813 + wbr->wbr_wh[i] = NULL;
3817 + err = test_children_busy(root, bindex, verbose);
3818 + if (unlikely(err)) {
3827 + * now we confirmed the branch is deletable.
3828 + * let's free the remaining opened dirs on the branch.
3830 + di_write_unlock(root);
3831 + br_del_file(to_free, opened, br_id);
3832 + di_write_lock_child(root);
3836 + au_br_do_del(sb, bindex, br);
3838 + sysaufs_brs_del(sb, bindex);
3839 + au_br_do_del(sb, bindex, br);
3840 + sysaufs_brs_add(sb, bindex);
3844 + au_cpup_attr_all(d_inode(root), /*force*/1);
3845 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3847 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3848 + if (au_opt_test(mnt_flags, PLINK))
3849 + au_plink_half_refresh(sb, br_id);
3851 + if (au_xino_brid(sb) == br_id)
3852 + au_xino_brid_set(sb, -1);
3853 + goto out; /* success */
3857 + rerr = au_br_init_wh(sb, br, br->br_perm);
3859 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3860 + del->pathname, rerr);
3863 + au_farray_free(to_free, opened);
3867 +/* ---------------------------------------------------------------------- */
3869 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3872 + aufs_bindex_t bstart, bend;
3873 + struct aufs_ibusy ibusy;
3874 + struct inode *inode, *h_inode;
3877 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3880 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3882 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3883 + if (unlikely(err)) {
3890 + si_read_lock(sb, AuLock_FLUSH);
3891 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3895 + ibusy.h_ino = 0; /* invalid */
3896 + inode = ilookup(sb, ibusy.ino);
3898 + || inode->i_ino == AUFS_ROOT_INO
3899 + || is_bad_inode(inode))
3902 + ii_read_lock_child(inode);
3903 + bstart = au_ibstart(inode);
3904 + bend = au_ibend(inode);
3905 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3906 + h_inode = au_h_iptr(inode, ibusy.bindex);
3907 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3908 + ibusy.h_ino = h_inode->i_ino;
3910 + ii_read_unlock(inode);
3914 + si_read_unlock(sb);
3916 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3917 + if (unlikely(err)) {
3926 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3928 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
3931 +#ifdef CONFIG_COMPAT
3932 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3934 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
3938 +/* ---------------------------------------------------------------------- */
3941 + * change a branch permission
3944 +static void au_warn_ima(void)
3947 + /* since it doesn't support mark_files_ro() */
3948 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3952 +static int do_need_sigen_inc(int a, int b)
3954 + return au_br_whable(a) && !au_br_whable(b);
3957 +static int need_sigen_inc(int old, int new)
3959 + return do_need_sigen_inc(old, new)
3960 + || do_need_sigen_inc(new, old);
3963 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3966 + unsigned int mnt_flags;
3967 + unsigned long long ull, max;
3968 + aufs_bindex_t br_id;
3969 + unsigned char verbose, writer;
3970 + struct file *file, *hf, **array;
3971 + struct au_hfile *hfile;
3973 + mnt_flags = au_mntflags(sb);
3974 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3976 + array = au_farray_alloc(sb, &max);
3977 + err = PTR_ERR(array);
3978 + if (IS_ERR(array))
3982 + br_id = au_sbr_id(sb, bindex);
3983 + for (ull = 0; ull < max; ull++) {
3984 + file = array[ull];
3985 + if (unlikely(!file))
3988 + /* AuDbg("%pD\n", file); */
3989 + fi_read_lock(file);
3990 + if (unlikely(au_test_mmapped(file))) {
3992 + AuVerbose(verbose, "mmapped %pD\n", file);
3994 + FiMustNoWaiters(file);
3995 + fi_read_unlock(file);
3999 + hfile = &au_fi(file)->fi_htop;
4000 + hf = hfile->hf_file;
4001 + if (!d_is_reg(file->f_path.dentry)
4002 + || !(file->f_mode & FMODE_WRITE)
4003 + || hfile->hf_br->br_id != br_id
4004 + || !(hf->f_mode & FMODE_WRITE))
4005 + array[ull] = NULL;
4011 + FiMustNoWaiters(file);
4012 + fi_read_unlock(file);
4020 + for (ull = 0; ull < max; ull++) {
4021 + file = array[ull];
4025 + /* todo: already flushed? */
4027 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4028 + * approach which resets f_mode and calls mnt_drop_write() and
4029 + * file_release_write() for each file, because the branch
4030 + * attribute in aufs world is totally different from the native
4033 + /* fi_read_lock(file); */
4034 + hfile = &au_fi(file)->fi_htop;
4035 + hf = hfile->hf_file;
4036 + /* fi_read_unlock(file); */
4037 + spin_lock(&hf->f_lock);
4038 + writer = !!(hf->f_mode & FMODE_WRITER);
4039 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4040 + spin_unlock(&hf->f_lock);
4042 + put_write_access(file_inode(hf));
4043 + __mnt_drop_write(hf->f_path.mnt);
4048 + au_farray_free(array, max);
4054 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4058 + aufs_bindex_t bindex;
4059 + struct dentry *root;
4060 + struct au_branch *br;
4061 + struct au_br_fhsm *bf;
4063 + root = sb->s_root;
4064 + bindex = au_find_dbindex(root, mod->h_root);
4067 + return 0; /* success */
4069 + pr_err("%s no such branch\n", mod->path);
4072 + AuDbg("bindex b%d\n", bindex);
4074 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4075 + if (unlikely(err))
4078 + br = au_sbr(sb, bindex);
4079 + AuDebugOn(mod->h_root != au_br_dentry(br));
4080 + if (br->br_perm == mod->perm)
4081 + return 0; /* success */
4083 + /* pre-allocate for non-fhsm --> fhsm */
4085 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4086 + err = au_fhsm_br_alloc(br);
4087 + if (unlikely(err))
4090 + br->br_fhsm = NULL;
4093 + if (au_br_writable(br->br_perm)) {
4094 + /* remove whiteout base */
4095 + err = au_br_init_wh(sb, br, mod->perm);
4096 + if (unlikely(err))
4099 + if (!au_br_writable(mod->perm)) {
4100 + /* rw --> ro, file might be mmapped */
4101 + DiMustNoWaiters(root);
4102 + IiMustNoWaiters(d_inode(root));
4103 + di_write_unlock(root);
4104 + err = au_br_mod_files_ro(sb, bindex);
4105 + /* aufs_write_lock() calls ..._child() */
4106 + di_write_lock_child(root);
4108 + if (unlikely(err)) {
4110 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4113 + rerr = au_wbr_init(br, sb, br->br_perm);
4114 + if (unlikely(rerr)) {
4115 + AuIOErr("nested error %d (%d)\n",
4117 + br->br_perm = mod->perm;
4121 + } else if (au_br_writable(mod->perm)) {
4124 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4126 + err = au_wbr_init(br, sb, mod->perm);
4127 + if (unlikely(err)) {
4128 + kfree(br->br_wbr);
4129 + br->br_wbr = NULL;
4133 + if (unlikely(err))
4136 + if (au_br_fhsm(br->br_perm)) {
4137 + if (!au_br_fhsm(mod->perm)) {
4138 + /* fhsm --> non-fhsm */
4139 + au_br_fhsm_fin(br->br_fhsm);
4140 + kfree(br->br_fhsm);
4141 + br->br_fhsm = NULL;
4143 + } else if (au_br_fhsm(mod->perm))
4144 + /* non-fhsm --> fhsm */
4147 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4148 + br->br_perm = mod->perm;
4149 + goto out; /* success */
4158 +/* ---------------------------------------------------------------------- */
4160 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4163 + struct kstatfs kstfs;
4165 + err = vfs_statfs(&br->br_path, &kstfs);
4167 + stfs->f_blocks = kstfs.f_blocks;
4168 + stfs->f_bavail = kstfs.f_bavail;
4169 + stfs->f_files = kstfs.f_files;
4170 + stfs->f_ffree = kstfs.f_ffree;
4175 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4176 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4177 +++ linux/fs/aufs/branch.h 2016-02-28 11:26:32.569971135 +0100
4180 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4182 + * This program, aufs is free software; you can redistribute it and/or modify
4183 + * it under the terms of the GNU General Public License as published by
4184 + * the Free Software Foundation; either version 2 of the License, or
4185 + * (at your option) any later version.
4187 + * This program is distributed in the hope that it will be useful,
4188 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4189 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4190 + * GNU General Public License for more details.
4192 + * You should have received a copy of the GNU General Public License
4193 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4197 + * branch filesystems and xino for them
4200 +#ifndef __AUFS_BRANCH_H__
4201 +#define __AUFS_BRANCH_H__
4205 +#include <linux/mount.h>
4210 +/* ---------------------------------------------------------------------- */
4213 +struct au_xino_file {
4214 + struct file *xi_file;
4215 + struct mutex xi_nondir_mtx;
4217 + /* todo: make xino files an array to support huge inode number */
4219 +#ifdef CONFIG_DEBUG_FS
4220 + struct dentry *xi_dbgaufs;
4224 +/* File-based Hierarchical Storage Management */
4225 +struct au_br_fhsm {
4226 +#ifdef CONFIG_AUFS_FHSM
4227 + struct mutex bf_lock;
4228 + unsigned long bf_jiffy;
4229 + struct aufs_stfs bf_stfs;
4234 +/* members for writable branch only */
4235 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4237 + struct au_rwsem wbr_wh_rwsem;
4238 + struct dentry *wbr_wh[AuBrWh_Last];
4239 + atomic_t wbr_wh_running;
4240 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4241 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4242 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4245 + unsigned long long wbr_bytes;
4248 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4249 +#define AuBrDynOp (AuDyLast * 4)
4251 +#ifdef CONFIG_AUFS_HFSNOTIFY
4252 +/* support for asynchronous destruction */
4253 +struct au_br_hfsnotify {
4254 + struct fsnotify_group *hfsn_group;
4258 +/* sysfs entries */
4259 +struct au_brsysfs {
4261 + struct attribute attr;
4270 +/* protected by superblock rwsem */
4272 + struct au_xino_file br_xino;
4274 + aufs_bindex_t br_id;
4277 + struct path br_path;
4278 + spinlock_t br_dykey_lock;
4279 + struct au_dykey *br_dykey[AuBrDynOp];
4280 + atomic_t br_count;
4282 + struct au_wbr *br_wbr;
4283 + struct au_br_fhsm *br_fhsm;
4285 + /* xino truncation */
4286 + atomic_t br_xino_running;
4288 +#ifdef CONFIG_AUFS_HFSNOTIFY
4289 + struct au_br_hfsnotify *br_hfsn;
4292 +#ifdef CONFIG_SYSFS
4293 + /* entries under sysfs per mount-point */
4294 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4298 +/* ---------------------------------------------------------------------- */
4300 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4302 + return br->br_path.mnt;
4305 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4307 + return br->br_path.dentry;
4310 +static inline struct super_block *au_br_sb(struct au_branch *br)
4312 + return au_br_mnt(br)->mnt_sb;
4315 +static inline int au_br_rdonly(struct au_branch *br)
4317 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4318 + || !au_br_writable(br->br_perm))
4322 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4324 +#ifdef CONFIG_AUFS_HNOTIFY
4325 + return !(brperm & AuBrPerm_RR);
4331 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4333 + int err, exec_flag;
4336 + exec_flag = oflag & __FMODE_EXEC;
4337 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4343 +/* ---------------------------------------------------------------------- */
4347 +void au_br_free(struct au_sbinfo *sinfo);
4348 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4350 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4352 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4353 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4354 +#ifdef CONFIG_COMPAT
4355 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4358 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4361 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4364 +static const loff_t au_loff_max = LLONG_MAX;
4366 +int au_xib_trunc(struct super_block *sb);
4367 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4369 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4370 + size_t size, loff_t *pos);
4371 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4372 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4373 +ino_t au_xino_new_ino(struct super_block *sb);
4374 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4375 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4377 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4379 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4380 + struct file *base_file, int do_test);
4381 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4383 +struct au_opt_xino;
4384 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4385 +void au_xino_clr(struct super_block *sb);
4386 +struct file *au_xino_def(struct super_block *sb);
4387 +int au_xino_path(struct seq_file *seq, struct file *file);
4389 +/* ---------------------------------------------------------------------- */
4391 +/* Superblock to branch */
4393 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4395 + return au_sbr(sb, bindex)->br_id;
4399 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4401 + return au_br_mnt(au_sbr(sb, bindex));
4405 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4407 + return au_br_sb(au_sbr(sb, bindex));
4410 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4412 + atomic_dec(&au_sbr(sb, bindex)->br_count);
4415 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4417 + return au_sbr(sb, bindex)->br_perm;
4420 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4422 + return au_br_whable(au_sbr_perm(sb, bindex));
4425 +/* ---------------------------------------------------------------------- */
4428 + * wbr_wh_read_lock, wbr_wh_write_lock
4429 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4431 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4433 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4434 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4435 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4437 +/* ---------------------------------------------------------------------- */
4439 +#ifdef CONFIG_AUFS_FHSM
4440 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4442 + mutex_init(&brfhsm->bf_lock);
4443 + brfhsm->bf_jiffy = 0;
4444 + brfhsm->bf_readable = 0;
4447 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4449 + mutex_destroy(&brfhsm->bf_lock);
4452 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4453 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4456 +#endif /* __KERNEL__ */
4457 +#endif /* __AUFS_BRANCH_H__ */
4458 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4459 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4460 +++ linux/fs/aufs/conf.mk 2016-02-28 11:26:32.569971135 +0100
4463 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4467 +AuConfStr += ${1}=${${1}}
4471 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4473 + HNOTIFY HFSNOTIFY \
4484 +$(foreach i, ${AuConfAll}, \
4485 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4487 +AuConfName = ${obj}/conf.str
4488 +${AuConfName}.tmp: FORCE
4489 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4490 +${AuConfName}: ${AuConfName}.tmp
4491 + @diff -q $< $@ > /dev/null 2>&1 || { \
4492 + echo ' GEN ' $@; \
4496 +clean-files += ${AuConfName} ${AuConfName}.tmp
4497 +${obj}/sysfs.o: ${AuConfName}
4499 +-include ${srctree}/${src}/conf_priv.mk
4500 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4501 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4502 +++ linux/fs/aufs/cpup.c 2016-02-28 11:26:32.569971135 +0100
4505 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4507 + * This program, aufs is free software; you can redistribute it and/or modify
4508 + * it under the terms of the GNU General Public License as published by
4509 + * the Free Software Foundation; either version 2 of the License, or
4510 + * (at your option) any later version.
4512 + * This program is distributed in the hope that it will be useful,
4513 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4514 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4515 + * GNU General Public License for more details.
4517 + * You should have received a copy of the GNU General Public License
4518 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4522 + * copy-up functions, see wbr_policy.c for copy-down
4525 +#include <linux/fs_stack.h>
4526 +#include <linux/mm.h>
4527 +#include <linux/task_work.h>
4530 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4532 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4533 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4535 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4537 + dst->i_flags |= iflags & ~mask;
4538 + if (au_test_fs_notime(dst->i_sb))
4539 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4542 +void au_cpup_attr_timesizes(struct inode *inode)
4544 + struct inode *h_inode;
4546 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4547 + fsstack_copy_attr_times(inode, h_inode);
4548 + fsstack_copy_inode_size(inode, h_inode);
4551 +void au_cpup_attr_nlink(struct inode *inode, int force)
4553 + struct inode *h_inode;
4554 + struct super_block *sb;
4555 + aufs_bindex_t bindex, bend;
4558 + bindex = au_ibstart(inode);
4559 + h_inode = au_h_iptr(inode, bindex);
4561 + && !S_ISDIR(h_inode->i_mode)
4562 + && au_opt_test(au_mntflags(sb), PLINK)
4563 + && au_plink_test(inode))
4567 + * 0 can happen in revalidating.
4568 + * h_inode->i_mutex may not be held here, but it is harmless since once
4569 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4571 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4572 + * the incorrect link count.
4574 + set_nlink(inode, h_inode->i_nlink);
4577 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4578 + * it may includes whplink directory.
4580 + if (S_ISDIR(h_inode->i_mode)) {
4581 + bend = au_ibend(inode);
4582 + for (bindex++; bindex <= bend; bindex++) {
4583 + h_inode = au_h_iptr(inode, bindex);
4585 + au_add_nlink(inode, h_inode);
4590 +void au_cpup_attr_changeable(struct inode *inode)
4592 + struct inode *h_inode;
4594 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4595 + inode->i_mode = h_inode->i_mode;
4596 + inode->i_uid = h_inode->i_uid;
4597 + inode->i_gid = h_inode->i_gid;
4598 + au_cpup_attr_timesizes(inode);
4599 + au_cpup_attr_flags(inode, h_inode->i_flags);
4602 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4604 + struct au_iinfo *iinfo = au_ii(inode);
4606 + IiMustWriteLock(inode);
4608 + iinfo->ii_higen = h_inode->i_generation;
4609 + iinfo->ii_hsb1 = h_inode->i_sb;
4612 +void au_cpup_attr_all(struct inode *inode, int force)
4614 + struct inode *h_inode;
4616 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4617 + au_cpup_attr_changeable(inode);
4618 + if (inode->i_nlink > 0)
4619 + au_cpup_attr_nlink(inode, force);
4620 + inode->i_rdev = h_inode->i_rdev;
4621 + inode->i_blkbits = h_inode->i_blkbits;
4622 + au_cpup_igen(inode, h_inode);
4625 +/* ---------------------------------------------------------------------- */
4627 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4629 +/* keep the timestamps of the parent dir when cpup */
4630 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4631 + struct path *h_path)
4633 + struct inode *h_inode;
4635 + dt->dt_dentry = dentry;
4636 + dt->dt_h_path = *h_path;
4637 + h_inode = d_inode(h_path->dentry);
4638 + dt->dt_atime = h_inode->i_atime;
4639 + dt->dt_mtime = h_inode->i_mtime;
4643 +void au_dtime_revert(struct au_dtime *dt)
4645 + struct iattr attr;
4648 + attr.ia_atime = dt->dt_atime;
4649 + attr.ia_mtime = dt->dt_mtime;
4650 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4651 + | ATTR_ATIME | ATTR_ATIME_SET;
4653 + /* no delegation since this is a directory */
4654 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4655 + if (unlikely(err))
4656 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4659 +/* ---------------------------------------------------------------------- */
4661 +/* internal use only */
4662 +struct au_cpup_reg_attr {
4665 + unsigned int iflags; /* inode->i_flags */
4668 +static noinline_for_stack
4669 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4670 + struct au_cpup_reg_attr *h_src_attr)
4672 + int err, sbits, icex;
4673 + unsigned int mnt_flags;
4674 + unsigned char verbose;
4676 + struct path h_path;
4677 + struct inode *h_isrc, *h_idst;
4678 + struct kstat *h_st;
4679 + struct au_branch *br;
4681 + h_path.dentry = au_h_dptr(dst, bindex);
4682 + h_idst = d_inode(h_path.dentry);
4683 + br = au_sbr(dst->d_sb, bindex);
4684 + h_path.mnt = au_br_mnt(br);
4685 + h_isrc = d_inode(h_src);
4686 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4687 + | ATTR_ATIME | ATTR_MTIME
4688 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4689 + if (h_src_attr && h_src_attr->valid) {
4690 + h_st = &h_src_attr->st;
4691 + ia.ia_uid = h_st->uid;
4692 + ia.ia_gid = h_st->gid;
4693 + ia.ia_atime = h_st->atime;
4694 + ia.ia_mtime = h_st->mtime;
4695 + if (h_idst->i_mode != h_st->mode
4696 + && !S_ISLNK(h_idst->i_mode)) {
4697 + ia.ia_valid |= ATTR_MODE;
4698 + ia.ia_mode = h_st->mode;
4700 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4701 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4703 + ia.ia_uid = h_isrc->i_uid;
4704 + ia.ia_gid = h_isrc->i_gid;
4705 + ia.ia_atime = h_isrc->i_atime;
4706 + ia.ia_mtime = h_isrc->i_mtime;
4707 + if (h_idst->i_mode != h_isrc->i_mode
4708 + && !S_ISLNK(h_idst->i_mode)) {
4709 + ia.ia_valid |= ATTR_MODE;
4710 + ia.ia_mode = h_isrc->i_mode;
4712 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4713 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4715 + /* no delegation since it is just created */
4716 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4718 + /* is this nfs only? */
4719 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4720 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4721 + ia.ia_mode = h_isrc->i_mode;
4722 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4725 + icex = br->br_perm & AuBrAttr_ICEX;
4727 + mnt_flags = au_mntflags(dst->d_sb);
4728 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4729 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4735 +/* ---------------------------------------------------------------------- */
4737 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4738 + char *buf, unsigned long blksize)
4741 + size_t sz, rbytes, wbytes;
4742 + unsigned char all_zero;
4744 + struct mutex *h_mtx;
4745 + /* reduce stack usage */
4748 + zp = page_address(ZERO_PAGE(0));
4749 + if (unlikely(!zp))
4750 + return -ENOMEM; /* possible? */
4755 + AuDbg("len %lld\n", len);
4757 + if (len < blksize)
4761 + /* todo: signal_pending? */
4762 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4763 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4766 + if (unlikely(err < 0))
4770 + if (len >= rbytes && rbytes == blksize)
4771 + all_zero = !memcmp(buf, zp, rbytes);
4778 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4780 + /* todo: signal_pending? */
4781 + if (unlikely(err == -EAGAIN || err == -EINTR))
4783 + if (unlikely(err < 0))
4788 + if (unlikely(err < 0))
4794 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4796 + if (unlikely(res < 0))
4803 + /* the last block may be a hole */
4804 + if (!err && all_zero) {
4805 + AuLabel(last hole);
4808 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4809 + /* nfs requires this step to make last hole */
4810 + /* is this only nfs? */
4812 + /* todo: signal_pending? */
4813 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4814 + } while (err == -EAGAIN || err == -EINTR);
4821 + ia->ia_size = dst->f_pos;
4822 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4823 + ia->ia_file = dst;
4824 + h_mtx = &file_inode(dst)->i_mutex;
4825 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4826 + /* no delegation since it is just created */
4827 + err = vfsub_notify_change(&dst->f_path, ia,
4828 + /*delegated*/NULL);
4829 + mutex_unlock(h_mtx);
4836 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4839 + unsigned long blksize;
4840 + unsigned char do_kfree;
4844 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
4845 + if (!blksize || PAGE_SIZE < blksize)
4846 + blksize = PAGE_SIZE;
4847 + AuDbg("blksize %lu\n", blksize);
4848 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4850 + buf = kmalloc(blksize, GFP_NOFS);
4852 + buf = (void *)__get_free_page(GFP_NOFS);
4853 + if (unlikely(!buf))
4856 + if (len > (1 << 22))
4857 + AuDbg("copying a large file %lld\n", (long long)len);
4861 + err = au_do_copy_file(dst, src, len, buf, blksize);
4865 + free_page((unsigned long)buf);
4872 + * to support a sparse file which is opened with O_APPEND,
4873 + * we need to close the file.
4875 +static int au_cp_regular(struct au_cp_generic *cpg)
4878 + enum { SRC, DST };
4880 + aufs_bindex_t bindex;
4881 + unsigned int flags;
4882 + struct dentry *dentry;
4884 + struct file *file;
4888 + .bindex = cpg->bsrc,
4889 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4893 + .bindex = cpg->bdst,
4894 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4895 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4896 + .label = &&out_src
4899 + struct super_block *sb;
4900 + struct task_struct *tsk = current;
4902 + /* bsrc branch can be ro/rw. */
4903 + sb = cpg->dentry->d_sb;
4905 + for (i = 0; i < 2; i++, f++) {
4906 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4907 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4908 + /*file*/NULL, f->force_wr);
4909 + err = PTR_ERR(f->file);
4910 + if (IS_ERR(f->file))
4914 + /* try stopping to update while we copyup */
4915 + IMustLock(d_inode(file[SRC].dentry));
4916 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4918 + /* i wonder if we had O_NO_DELAY_FPUT flag */
4919 + if (tsk->flags & PF_KTHREAD)
4920 + __fput_sync(file[DST].file);
4922 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
4924 + fput(file[DST].file);
4927 + * we have to call both since we don't know which place the file
4931 + flush_delayed_fput();
4933 + au_sbr_put(sb, file[DST].bindex);
4936 + fput(file[SRC].file);
4937 + au_sbr_put(sb, file[SRC].bindex);
4942 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4943 + struct au_cpup_reg_attr *h_src_attr)
4947 + struct path h_path;
4948 + struct inode *h_src_inode, *h_dst_inode;
4951 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
4952 + l = i_size_read(h_src_inode);
4953 + if (cpg->len == -1 || l < cpg->len)
4956 + /* try stopping to update while we are referencing */
4957 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4958 + au_pin_hdir_unlock(cpg->pin);
4960 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4961 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4962 + h_src_attr->iflags = h_src_inode->i_flags;
4963 + if (!au_test_nfs(h_src_inode->i_sb))
4964 + err = vfs_getattr(&h_path, &h_src_attr->st);
4966 + mutex_unlock(&h_src_inode->i_mutex);
4967 + err = vfs_getattr(&h_path, &h_src_attr->st);
4968 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4970 + if (unlikely(err)) {
4971 + mutex_unlock(&h_src_inode->i_mutex);
4974 + h_src_attr->valid = 1;
4975 + err = au_cp_regular(cpg);
4976 + mutex_unlock(&h_src_inode->i_mutex);
4977 + rerr = au_pin_hdir_relock(cpg->pin);
4981 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
4982 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
4983 + h_dst_inode = d_inode(h_path.dentry);
4984 + spin_lock(&h_dst_inode->i_lock);
4985 + h_dst_inode->i_state |= I_LINKABLE;
4986 + spin_unlock(&h_dst_inode->i_lock);
4993 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4994 + struct inode *h_dir)
4997 + mm_segment_t old_fs;
5002 + struct inode *h_inode = d_inode(h_src);
5003 + const struct inode_operations *h_iop = h_inode->i_op;
5006 + if (unlikely(!h_iop->readlink))
5010 + sym.k = (void *)__get_free_page(GFP_NOFS);
5011 + if (unlikely(!sym.k))
5014 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5015 + old_fs = get_fs();
5016 + set_fs(KERNEL_DS);
5017 + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX);
5022 + sym.k[symlen] = 0;
5023 + err = vfsub_symlink(h_dir, h_path, sym.k);
5025 + free_page((unsigned long)sym.k);
5032 + * regardless 'acl' option, reset all ACL.
5033 + * All ACL will be copied up later from the original entry on the lower branch.
5035 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5038 + struct dentry *h_dentry;
5039 + struct inode *h_inode;
5041 + h_dentry = h_path->dentry;
5042 + h_inode = d_inode(h_dentry);
5043 + /* forget_all_cached_acls(h_inode)); */
5044 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5046 + if (err == -EOPNOTSUPP)
5049 + err = vfsub_acl_chmod(h_inode, mode);
5055 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5056 + struct inode *h_dir, struct path *h_path)
5059 + struct inode *dir, *inode;
5061 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5063 + if (err == -EOPNOTSUPP)
5065 + if (unlikely(err))
5069 + * strange behaviour from the users view,
5070 + * particularry setattr case
5072 + dir = d_inode(dst_parent);
5073 + if (au_ibstart(dir) == cpg->bdst)
5074 + au_cpup_attr_nlink(dir, /*force*/1);
5075 + inode = d_inode(cpg->dentry);
5076 + au_cpup_attr_nlink(inode, /*force*/1);
5082 +static noinline_for_stack
5083 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5084 + struct au_cpup_reg_attr *h_src_attr)
5088 + unsigned int mnt_flags;
5089 + unsigned char isdir, isreg, force;
5090 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5091 + struct au_dtime dt;
5092 + struct path h_path;
5093 + struct dentry *h_src, *h_dst, *h_parent;
5094 + struct inode *h_inode, *h_dir;
5095 + struct super_block *sb;
5097 + /* bsrc branch can be ro/rw. */
5098 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5099 + h_inode = d_inode(h_src);
5100 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5102 + /* try stopping to be referenced while we are creating */
5103 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5104 + if (au_ftest_cpup(cpg->flags, RENAME))
5105 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5106 + AUFS_WH_PFX_LEN));
5107 + h_parent = h_dst->d_parent; /* dir inode is locked */
5108 + h_dir = d_inode(h_parent);
5110 + AuDebugOn(h_parent != h_dst->d_parent);
5112 + sb = cpg->dentry->d_sb;
5113 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5115 + h_path.dentry = h_parent;
5116 + au_dtime_store(&dt, dst_parent, &h_path);
5118 + h_path.dentry = h_dst;
5122 + mode = h_inode->i_mode;
5123 + switch (mode & S_IFMT) {
5126 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5127 + /*want_excl*/true);
5129 + err = au_do_cpup_regular(cpg, h_src_attr);
5133 + err = vfsub_mkdir(h_dir, &h_path, mode);
5135 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5138 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5142 + AuDebugOn(!capable(CAP_MKNOD));
5146 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5149 + AuIOErr("Unknown inode type 0%o\n", mode);
5153 + err = au_reset_acl(h_dir, &h_path, mode);
5155 + mnt_flags = au_mntflags(sb);
5156 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5158 + && au_opt_test(mnt_flags, XINO)
5159 + && (h_inode->i_nlink == 1
5160 + || (h_inode->i_state & I_LINKABLE))
5161 + /* todo: unnecessary? */
5162 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5163 + && cpg->bdst < cpg->bsrc
5164 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5165 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5166 + /* ignore this error */
5171 + force = !!cpg->len;
5172 + if (cpg->len == -1)
5173 + force = !!i_size_read(h_inode);
5175 + au_fhsm_wrote(sb, cpg->bdst, force);
5179 + au_dtime_revert(&dt);
5183 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5186 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5187 + struct inode *h_dir;
5188 + aufs_bindex_t bdst;
5190 + dentry = cpg->dentry;
5192 + h_dentry = au_h_dptr(dentry, bdst);
5193 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5195 + au_set_h_dptr(dentry, bdst, NULL);
5196 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5198 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5199 + au_set_h_dptr(dentry, bdst, h_dentry);
5202 + parent = dget_parent(dentry);
5203 + h_parent = au_h_dptr(parent, bdst);
5205 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5206 + if (IS_ERR(h_path->dentry))
5207 + err = PTR_ERR(h_path->dentry);
5209 + if (unlikely(err))
5212 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5213 + h_dir = d_inode(h_parent);
5215 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5216 + /* no delegation since it is just created */
5217 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
5218 + dput(h_path->dentry);
5225 + * copyup the @dentry from @bsrc to @bdst.
5226 + * the caller must set the both of lower dentries.
5227 + * @len is for truncating when it is -1 copyup the entire file.
5228 + * in link/rename cases, @dst_parent may be different from the real one.
5229 + * basic->bsrc can be larger than basic->bdst.
5231 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5234 + aufs_bindex_t old_ibstart;
5235 + unsigned char isdir, plink;
5236 + struct dentry *h_src, *h_dst, *h_parent;
5237 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5238 + struct super_block *sb;
5239 + struct au_branch *br;
5240 + /* to reuduce stack size */
5242 + struct au_dtime dt;
5243 + struct path h_path;
5244 + struct au_cpup_reg_attr h_src_attr;
5248 + a = kmalloc(sizeof(*a), GFP_NOFS);
5251 + a->h_src_attr.valid = 0;
5253 + sb = cpg->dentry->d_sb;
5254 + br = au_sbr(sb, cpg->bdst);
5255 + a->h_path.mnt = au_br_mnt(br);
5256 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5257 + h_parent = h_dst->d_parent; /* dir inode is locked */
5258 + h_dir = d_inode(h_parent);
5261 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5262 + inode = d_inode(cpg->dentry);
5265 + dst_parent = dget_parent(cpg->dentry);
5269 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5270 + dst_inode = au_h_iptr(inode, cpg->bdst);
5272 + if (unlikely(!plink)) {
5274 + AuIOErr("hi%lu(i%lu) exists on b%d "
5275 + "but plink is disabled\n",
5276 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5280 + if (dst_inode->i_nlink) {
5281 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5283 + h_src = au_plink_lkup(inode, cpg->bdst);
5284 + err = PTR_ERR(h_src);
5285 + if (IS_ERR(h_src))
5287 + if (unlikely(d_is_negative(h_src))) {
5289 + AuIOErr("i%lu exists on b%d "
5290 + "but not pseudo-linked\n",
5291 + inode->i_ino, cpg->bdst);
5297 + a->h_path.dentry = h_parent;
5298 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5301 + a->h_path.dentry = h_dst;
5303 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5304 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5305 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5307 + au_dtime_revert(&a->dt);
5308 + if (unlikely(err == -EWOULDBLOCK)) {
5309 + pr_warn("cannot retry for NFSv4 delegation"
5310 + " for an internal link\n");
5316 + /* todo: cpup_wh_file? */
5318 + au_update_ibrange(inode, /*do_put_zero*/1);
5321 + isdir = S_ISDIR(inode->i_mode);
5322 + old_ibstart = au_ibstart(inode);
5323 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5324 + if (unlikely(err))
5326 + dst_inode = d_inode(h_dst);
5327 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
5328 + /* todo: necessary? */
5329 + /* au_pin_hdir_unlock(cpg->pin); */
5331 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5332 + if (unlikely(err)) {
5333 + /* todo: necessary? */
5334 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5335 + mutex_unlock(&dst_inode->i_mutex);
5339 + if (cpg->bdst < old_ibstart) {
5340 + if (S_ISREG(inode->i_mode)) {
5341 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5342 + if (unlikely(err)) {
5343 + /* ignore an error */
5344 + /* au_pin_hdir_relock(cpg->pin); */
5345 + mutex_unlock(&dst_inode->i_mutex);
5349 + au_set_ibstart(inode, cpg->bdst);
5351 + au_set_ibend(inode, cpg->bdst);
5352 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5353 + au_hi_flags(inode, isdir));
5355 + /* todo: necessary? */
5356 + /* err = au_pin_hdir_relock(cpg->pin); */
5357 + mutex_unlock(&dst_inode->i_mutex);
5358 + if (unlikely(err))
5361 + src_inode = d_inode(h_src);
5363 + && (src_inode->i_nlink > 1
5364 + || src_inode->i_state & I_LINKABLE)
5366 + au_plink_append(inode, cpg->bdst, h_dst);
5368 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5369 + a->h_path.dentry = h_dst;
5370 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5373 + goto out_parent; /* success */
5377 + a->h_path.dentry = h_parent;
5378 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5379 + a->h_path.dentry = h_dst;
5381 + if (d_is_positive(h_dst)) {
5383 + /* no delegation since it is just created */
5384 + rerr = vfsub_unlink(h_dir, &a->h_path,
5385 + /*delegated*/NULL, /*force*/0);
5387 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5389 + au_dtime_revert(&a->dt);
5391 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5401 +#if 0 /* reserved */
5402 +struct au_cpup_single_args {
5404 + struct au_cp_generic *cpg;
5405 + struct dentry *dst_parent;
5408 +static void au_call_cpup_single(void *args)
5410 + struct au_cpup_single_args *a = args;
5412 + au_pin_hdir_acquire_nest(a->cpg->pin);
5413 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5414 + au_pin_hdir_release(a->cpg->pin);
5419 + * prevent SIGXFSZ in copy-up.
5420 + * testing CAP_MKNOD is for generic fs,
5421 + * but CAP_FSETID is for xfs only, currently.
5423 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5426 + struct super_block *sb;
5427 + struct inode *h_dir;
5430 + sb = au_pinned_parent(pin)->d_sb;
5431 + if (!au_wkq_test()
5432 + && (!au_sbi(sb)->si_plink_maint_pid
5433 + || au_plink_maint(sb, AuLock_NOPLM))) {
5434 + switch (mode & S_IFMT) {
5436 + /* no condition about RLIMIT_FSIZE and the file size */
5441 + do_sio = !capable(CAP_MKNOD);
5445 + do_sio = ((mode & (S_ISUID | S_ISGID))
5446 + && !capable(CAP_FSETID));
5447 + /* this workaround may be removed in the future */
5449 + h_dir = au_pinned_h_dir(pin);
5450 + do_sio = h_dir->i_mode & S_ISVTX;
5457 +#if 0 /* reserved */
5458 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5461 + struct dentry *h_dentry;
5463 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5464 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5465 + err = au_cpup_single(cpg, dst_parent);
5467 + struct au_cpup_single_args args = {
5470 + .dst_parent = dst_parent
5472 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5473 + if (unlikely(wkq_err))
5482 + * copyup the @dentry from the first active lower branch to @bdst,
5483 + * using au_cpup_single().
5485 +static int au_cpup_simple(struct au_cp_generic *cpg)
5488 + unsigned int flags_orig;
5489 + struct dentry *dentry;
5491 + AuDebugOn(cpg->bsrc < 0);
5493 + dentry = cpg->dentry;
5494 + DiMustWriteLock(dentry);
5496 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5498 + flags_orig = cpg->flags;
5499 + au_fset_cpup(cpg->flags, RENAME);
5500 + err = au_cpup_single(cpg, NULL);
5501 + cpg->flags = flags_orig;
5503 + return 0; /* success */
5506 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5507 + au_set_dbstart(dentry, cpg->bsrc);
5513 +struct au_cpup_simple_args {
5515 + struct au_cp_generic *cpg;
5518 +static void au_call_cpup_simple(void *args)
5520 + struct au_cpup_simple_args *a = args;
5522 + au_pin_hdir_acquire_nest(a->cpg->pin);
5523 + *a->errp = au_cpup_simple(a->cpg);
5524 + au_pin_hdir_release(a->cpg->pin);
5527 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5530 + struct dentry *dentry, *parent;
5531 + struct file *h_file;
5532 + struct inode *h_dir;
5534 + dentry = cpg->dentry;
5536 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5537 + AuDebugOn(cpg->bsrc < 0);
5538 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5539 + err = PTR_ERR(h_file);
5540 + if (IS_ERR(h_file))
5544 + parent = dget_parent(dentry);
5545 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5546 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5547 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5548 + err = au_cpup_simple(cpg);
5550 + struct au_cpup_simple_args args = {
5554 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5555 + if (unlikely(wkq_err))
5561 + au_h_open_post(dentry, cpg->bsrc, h_file);
5567 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5569 + aufs_bindex_t bsrc, bend;
5570 + struct dentry *dentry, *h_dentry;
5572 + if (cpg->bsrc < 0) {
5573 + dentry = cpg->dentry;
5574 + bend = au_dbend(dentry);
5575 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5576 + h_dentry = au_h_dptr(dentry, bsrc);
5578 + AuDebugOn(d_is_negative(h_dentry));
5582 + AuDebugOn(bsrc > bend);
5585 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5586 + return au_do_sio_cpup_simple(cpg);
5589 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5591 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5592 + return au_do_sio_cpup_simple(cpg);
5595 +/* ---------------------------------------------------------------------- */
5598 + * copyup the deleted file for writing.
5600 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5601 + struct file *file)
5604 + unsigned int flags_orig;
5605 + aufs_bindex_t bsrc_orig;
5606 + struct dentry *h_d_dst, *h_d_start;
5607 + struct au_dinfo *dinfo;
5608 + struct au_hdentry *hdp;
5610 + dinfo = au_di(cpg->dentry);
5611 + AuRwMustWriteLock(&dinfo->di_rwsem);
5613 + bsrc_orig = cpg->bsrc;
5614 + cpg->bsrc = dinfo->di_bstart;
5615 + hdp = dinfo->di_hdentry;
5616 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5617 + dinfo->di_bstart = cpg->bdst;
5618 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5621 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5622 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_path.dentry;
5624 + flags_orig = cpg->flags;
5625 + cpg->flags = !AuCpup_DTIME;
5626 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5627 + cpg->flags = flags_orig;
5630 + err = au_reopen_nondir(file);
5631 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5633 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5634 + dinfo->di_bstart = cpg->bsrc;
5635 + cpg->bsrc = bsrc_orig;
5640 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5643 + aufs_bindex_t bdst;
5644 + struct au_dtime dt;
5645 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5646 + struct au_branch *br;
5647 + struct path h_path;
5649 + dentry = cpg->dentry;
5651 + br = au_sbr(dentry->d_sb, bdst);
5652 + parent = dget_parent(dentry);
5653 + h_parent = au_h_dptr(parent, bdst);
5654 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5655 + err = PTR_ERR(wh_dentry);
5656 + if (IS_ERR(wh_dentry))
5659 + h_path.dentry = h_parent;
5660 + h_path.mnt = au_br_mnt(br);
5661 + au_dtime_store(&dt, parent, &h_path);
5662 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5663 + if (unlikely(err))
5667 + h_path.dentry = wh_dentry;
5668 + if (!d_is_dir(wh_dentry)) {
5669 + /* no delegation since it is just created */
5670 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5671 + /*delegated*/NULL, /*force*/0);
5673 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5674 + if (unlikely(err)) {
5675 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5679 + au_dtime_revert(&dt);
5680 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5689 +struct au_cpup_wh_args {
5691 + struct au_cp_generic *cpg;
5692 + struct file *file;
5695 +static void au_call_cpup_wh(void *args)
5697 + struct au_cpup_wh_args *a = args;
5699 + au_pin_hdir_acquire_nest(a->cpg->pin);
5700 + *a->errp = au_cpup_wh(a->cpg, a->file);
5701 + au_pin_hdir_release(a->cpg->pin);
5704 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5707 + aufs_bindex_t bdst;
5708 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5709 + struct inode *dir, *h_dir, *h_tmpdir;
5710 + struct au_wbr *wbr;
5711 + struct au_pin wh_pin, *pin_orig;
5713 + dentry = cpg->dentry;
5715 + parent = dget_parent(dentry);
5716 + dir = d_inode(parent);
5719 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5722 + if (!h_dir->i_nlink) {
5723 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5724 + h_orph = wbr->wbr_orph;
5726 + h_parent = dget(au_h_dptr(parent, bdst));
5727 + au_set_h_dptr(parent, bdst, dget(h_orph));
5728 + h_tmpdir = d_inode(h_orph);
5729 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5731 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
5732 + /* todo: au_h_open_pre()? */
5734 + pin_orig = cpg->pin;
5735 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5736 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5737 + cpg->pin = &wh_pin;
5740 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5741 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5742 + err = au_cpup_wh(cpg, file);
5744 + struct au_cpup_wh_args args = {
5749 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5750 + if (unlikely(wkq_err))
5755 + mutex_unlock(&h_tmpdir->i_mutex);
5756 + /* todo: au_h_open_post()? */
5757 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5758 + au_set_h_dptr(parent, bdst, h_parent);
5759 + AuDebugOn(!pin_orig);
5760 + cpg->pin = pin_orig;
5768 +/* ---------------------------------------------------------------------- */
5771 + * generic routine for both of copy-up and copy-down.
5773 +/* cf. revalidate function in file.c */
5774 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5775 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5776 + struct au_pin *pin,
5777 + struct dentry *h_parent, void *arg),
5781 + struct au_pin pin;
5782 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
5785 + parent = dget_parent(dentry);
5786 + if (IS_ROOT(parent))
5789 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5790 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5792 + /* do not use au_dpage */
5793 + real_parent = parent;
5796 + parent = dget_parent(dentry);
5797 + h_parent = au_h_dptr(parent, bdst);
5799 + goto out; /* success */
5801 + /* find top dir which is necessary to cpup */
5805 + parent = dget_parent(d);
5806 + di_read_lock_parent3(parent, !AuLock_IR);
5807 + h_parent = au_h_dptr(parent, bdst);
5808 + di_read_unlock(parent, !AuLock_IR);
5809 + } while (!h_parent);
5811 + if (d != real_parent)
5812 + di_write_lock_child3(d);
5814 + /* somebody else might create while we were sleeping */
5815 + h_dentry = au_h_dptr(d, bdst);
5816 + if (!h_dentry || d_is_negative(h_dentry)) {
5818 + au_update_dbstart(d);
5820 + au_pin_set_dentry(&pin, d);
5821 + err = au_do_pin(&pin);
5823 + err = cp(d, bdst, &pin, h_parent, arg);
5828 + if (d != real_parent)
5829 + di_write_unlock(d);
5830 + if (unlikely(err))
5839 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5840 + struct au_pin *pin,
5841 + struct dentry *h_parent __maybe_unused,
5842 + void *arg __maybe_unused)
5844 + struct au_cp_generic cpg = {
5850 + .flags = AuCpup_DTIME
5852 + return au_sio_cpup_simple(&cpg);
5855 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5857 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5860 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5863 + struct dentry *parent;
5864 + struct inode *dir;
5866 + parent = dget_parent(dentry);
5867 + dir = d_inode(parent);
5869 + if (au_h_iptr(dir, bdst))
5872 + di_read_unlock(parent, AuLock_IR);
5873 + di_write_lock_parent(parent);
5874 + /* someone else might change our inode while we were sleeping */
5875 + if (!au_h_iptr(dir, bdst))
5876 + err = au_cpup_dirs(dentry, bdst);
5877 + di_downgrade_lock(parent, AuLock_IR);
5883 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5884 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5885 +++ linux/fs/aufs/cpup.h 2016-02-28 11:26:32.569971135 +0100
5888 + * Copyright (C) 2005-2016 Junjiro R. Okajima
5890 + * This program, aufs is free software; you can redistribute it and/or modify
5891 + * it under the terms of the GNU General Public License as published by
5892 + * the Free Software Foundation; either version 2 of the License, or
5893 + * (at your option) any later version.
5895 + * This program is distributed in the hope that it will be useful,
5896 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5897 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5898 + * GNU General Public License for more details.
5900 + * You should have received a copy of the GNU General Public License
5901 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5905 + * copy-up/down functions
5908 +#ifndef __AUFS_CPUP_H__
5909 +#define __AUFS_CPUP_H__
5913 +#include <linux/path.h>
5919 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5920 +void au_cpup_attr_timesizes(struct inode *inode);
5921 +void au_cpup_attr_nlink(struct inode *inode, int force);
5922 +void au_cpup_attr_changeable(struct inode *inode);
5923 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5924 +void au_cpup_attr_all(struct inode *inode, int force);
5926 +/* ---------------------------------------------------------------------- */
5928 +struct au_cp_generic {
5929 + struct dentry *dentry;
5930 + aufs_bindex_t bdst, bsrc;
5932 + struct au_pin *pin;
5933 + unsigned int flags;
5937 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5938 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5940 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5941 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5943 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5945 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5946 + the branch is marked as RO */
5948 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5949 +#define au_fset_cpup(flags, name) \
5950 + do { (flags) |= AuCpup_##name; } while (0)
5951 +#define au_fclr_cpup(flags, name) \
5952 + do { (flags) &= ~AuCpup_##name; } while (0)
5954 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5955 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5956 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5957 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5959 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5960 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5961 + struct au_pin *pin,
5962 + struct dentry *h_parent, void *arg),
5964 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5965 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5967 +/* ---------------------------------------------------------------------- */
5969 +/* keep timestamps when copyup */
5971 + struct dentry *dt_dentry;
5972 + struct path dt_h_path;
5973 + struct timespec dt_atime, dt_mtime;
5975 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5976 + struct path *h_path);
5977 +void au_dtime_revert(struct au_dtime *dt);
5979 +#endif /* __KERNEL__ */
5980 +#endif /* __AUFS_CPUP_H__ */
5981 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5982 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5983 +++ linux/fs/aufs/dbgaufs.c 2016-02-28 11:26:32.569971135 +0100
5986 + * Copyright (C) 2005-2016 Junjiro R. Okajima
5988 + * This program, aufs is free software; you can redistribute it and/or modify
5989 + * it under the terms of the GNU General Public License as published by
5990 + * the Free Software Foundation; either version 2 of the License, or
5991 + * (at your option) any later version.
5993 + * This program is distributed in the hope that it will be useful,
5994 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5995 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5996 + * GNU General Public License for more details.
5998 + * You should have received a copy of the GNU General Public License
5999 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6003 + * debugfs interface
6006 +#include <linux/debugfs.h>
6009 +#ifndef CONFIG_SYSFS
6010 +#error DEBUG_FS depends upon SYSFS
6013 +static struct dentry *dbgaufs;
6014 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6016 +/* 20 is max digits length of ulong 64 */
6017 +struct dbgaufs_arg {
6023 + * common function for all XINO files
6025 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6026 + struct file *file)
6028 + kfree(file->private_data);
6032 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6036 + struct dbgaufs_arg *p;
6039 + p = kmalloc(sizeof(*p), GFP_NOFS);
6045 + file->private_data = p;
6049 + err = vfs_getattr(&xf->f_path, &st);
6053 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
6054 + (long)file_count(xf), st.blocks, st.blksize,
6055 + (long long)st.size);
6057 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
6058 + st.blocks, st.blksize,
6059 + (long long)st.size);
6060 + AuDebugOn(p->n >= sizeof(p->a));
6062 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6071 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6072 + size_t count, loff_t *ppos)
6074 + struct dbgaufs_arg *p;
6076 + p = file->private_data;
6077 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6080 +/* ---------------------------------------------------------------------- */
6082 +struct dbgaufs_plink_arg {
6087 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6088 + struct file *file)
6090 + free_page((unsigned long)file->private_data);
6094 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6096 + int err, i, limit;
6097 + unsigned long n, sum;
6098 + struct dbgaufs_plink_arg *p;
6099 + struct au_sbinfo *sbinfo;
6100 + struct super_block *sb;
6101 + struct au_sphlhead *sphl;
6104 + p = (void *)get_zeroed_page(GFP_NOFS);
6109 + sbinfo = inode->i_private;
6110 + sb = sbinfo->si_sb;
6111 + si_noflush_read_lock(sb);
6112 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6113 + limit = PAGE_SIZE - sizeof(p->n);
6115 + /* the number of buckets */
6116 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6121 + for (i = 0, sphl = sbinfo->si_plink;
6122 + i < AuPlink_NHASH;
6124 + n = au_sphl_count(sphl);
6127 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6130 + if (unlikely(limit <= 0))
6133 + p->a[p->n - 1] = '\n';
6135 + /* the sum of plinks */
6136 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6139 + if (unlikely(limit <= 0))
6142 +#define str "1\n0\n0\n"
6143 + p->n = sizeof(str) - 1;
6144 + strcpy(p->a, str);
6147 + si_read_unlock(sb);
6150 + file->private_data = p;
6151 + goto out; /* success */
6154 + free_page((unsigned long)p);
6159 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6160 + size_t count, loff_t *ppos)
6162 + struct dbgaufs_plink_arg *p;
6164 + p = file->private_data;
6165 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6168 +static const struct file_operations dbgaufs_plink_fop = {
6169 + .owner = THIS_MODULE,
6170 + .open = dbgaufs_plink_open,
6171 + .release = dbgaufs_plink_release,
6172 + .read = dbgaufs_plink_read
6175 +/* ---------------------------------------------------------------------- */
6177 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6180 + struct au_sbinfo *sbinfo;
6181 + struct super_block *sb;
6183 + sbinfo = inode->i_private;
6184 + sb = sbinfo->si_sb;
6185 + si_noflush_read_lock(sb);
6186 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6187 + si_read_unlock(sb);
6191 +static const struct file_operations dbgaufs_xib_fop = {
6192 + .owner = THIS_MODULE,
6193 + .open = dbgaufs_xib_open,
6194 + .release = dbgaufs_xi_release,
6195 + .read = dbgaufs_xi_read
6198 +/* ---------------------------------------------------------------------- */
6200 +#define DbgaufsXi_PREFIX "xi"
6202 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6206 + struct au_sbinfo *sbinfo;
6207 + struct super_block *sb;
6209 + struct qstr *name;
6213 + name = &file->f_path.dentry->d_name;
6214 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6215 + || memcmp(name->name, DbgaufsXi_PREFIX,
6216 + sizeof(DbgaufsXi_PREFIX) - 1)))
6218 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6219 + if (unlikely(err))
6222 + sbinfo = inode->i_private;
6223 + sb = sbinfo->si_sb;
6224 + si_noflush_read_lock(sb);
6225 + if (l <= au_sbend(sb)) {
6226 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6227 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6230 + si_read_unlock(sb);
6236 +static const struct file_operations dbgaufs_xino_fop = {
6237 + .owner = THIS_MODULE,
6238 + .open = dbgaufs_xino_open,
6239 + .release = dbgaufs_xi_release,
6240 + .read = dbgaufs_xi_read
6243 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6245 + aufs_bindex_t bend;
6246 + struct au_branch *br;
6247 + struct au_xino_file *xi;
6249 + if (!au_sbi(sb)->si_dbgaufs)
6252 + bend = au_sbend(sb);
6253 + for (; bindex <= bend; bindex++) {
6254 + br = au_sbr(sb, bindex);
6255 + xi = &br->br_xino;
6256 + debugfs_remove(xi->xi_dbgaufs);
6257 + xi->xi_dbgaufs = NULL;
6261 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6263 + struct au_sbinfo *sbinfo;
6264 + struct dentry *parent;
6265 + struct au_branch *br;
6266 + struct au_xino_file *xi;
6267 + aufs_bindex_t bend;
6268 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6270 + sbinfo = au_sbi(sb);
6271 + parent = sbinfo->si_dbgaufs;
6275 + bend = au_sbend(sb);
6276 + for (; bindex <= bend; bindex++) {
6277 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6278 + br = au_sbr(sb, bindex);
6279 + xi = &br->br_xino;
6280 + AuDebugOn(xi->xi_dbgaufs);
6281 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6282 + sbinfo, &dbgaufs_xino_fop);
6283 + /* ignore an error */
6284 + if (unlikely(!xi->xi_dbgaufs))
6285 + AuWarn1("failed %s under debugfs\n", name);
6289 +/* ---------------------------------------------------------------------- */
6291 +#ifdef CONFIG_AUFS_EXPORT
6292 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6295 + struct au_sbinfo *sbinfo;
6296 + struct super_block *sb;
6298 + sbinfo = inode->i_private;
6299 + sb = sbinfo->si_sb;
6300 + si_noflush_read_lock(sb);
6301 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6302 + si_read_unlock(sb);
6306 +static const struct file_operations dbgaufs_xigen_fop = {
6307 + .owner = THIS_MODULE,
6308 + .open = dbgaufs_xigen_open,
6309 + .release = dbgaufs_xi_release,
6310 + .read = dbgaufs_xi_read
6313 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6318 + * This function is a dynamic '__init' function actually,
6319 + * so the tiny check for si_rwsem is unnecessary.
6321 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6324 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6325 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6326 + &dbgaufs_xigen_fop);
6327 + if (sbinfo->si_dbgaufs_xigen)
6333 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6337 +#endif /* CONFIG_AUFS_EXPORT */
6339 +/* ---------------------------------------------------------------------- */
6341 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6344 + * This function is a dynamic '__fin' function actually,
6345 + * so the tiny check for si_rwsem is unnecessary.
6347 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6349 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6350 + sbinfo->si_dbgaufs = NULL;
6351 + kobject_put(&sbinfo->si_kobj);
6354 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6357 + char name[SysaufsSiNameLen];
6360 + * This function is a dynamic '__init' function actually,
6361 + * so the tiny check for si_rwsem is unnecessary.
6363 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6367 + AuErr1("/debug/aufs is uninitialized\n");
6372 + sysaufs_name(sbinfo, name);
6373 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6374 + if (unlikely(!sbinfo->si_dbgaufs))
6376 + kobject_get(&sbinfo->si_kobj);
6378 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6379 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6380 + &dbgaufs_xib_fop);
6381 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6384 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6385 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6386 + &dbgaufs_plink_fop);
6387 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6390 + err = dbgaufs_xigen_init(sbinfo);
6392 + goto out; /* success */
6395 + dbgaufs_si_fin(sbinfo);
6400 +/* ---------------------------------------------------------------------- */
6402 +void dbgaufs_fin(void)
6404 + debugfs_remove(dbgaufs);
6407 +int __init dbgaufs_init(void)
6412 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6417 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6418 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6419 +++ linux/fs/aufs/dbgaufs.h 2016-02-28 11:26:32.569971135 +0100
6422 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6424 + * This program, aufs is free software; you can redistribute it and/or modify
6425 + * it under the terms of the GNU General Public License as published by
6426 + * the Free Software Foundation; either version 2 of the License, or
6427 + * (at your option) any later version.
6429 + * This program is distributed in the hope that it will be useful,
6430 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6431 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6432 + * GNU General Public License for more details.
6434 + * You should have received a copy of the GNU General Public License
6435 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6439 + * debugfs interface
6442 +#ifndef __DBGAUFS_H__
6443 +#define __DBGAUFS_H__
6447 +struct super_block;
6450 +#ifdef CONFIG_DEBUG_FS
6452 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6453 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6454 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6455 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6456 +void dbgaufs_fin(void);
6457 +int __init dbgaufs_init(void);
6459 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6460 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6461 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6462 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6463 +AuStubVoid(dbgaufs_fin, void)
6464 +AuStubInt0(__init dbgaufs_init, void)
6465 +#endif /* CONFIG_DEBUG_FS */
6467 +#endif /* __KERNEL__ */
6468 +#endif /* __DBGAUFS_H__ */
6469 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6470 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6471 +++ linux/fs/aufs/dcsub.c 2016-02-28 11:26:32.569971135 +0100
6474 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6476 + * This program, aufs is free software; you can redistribute it and/or modify
6477 + * it under the terms of the GNU General Public License as published by
6478 + * the Free Software Foundation; either version 2 of the License, or
6479 + * (at your option) any later version.
6481 + * This program is distributed in the hope that it will be useful,
6482 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6483 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6484 + * GNU General Public License for more details.
6486 + * You should have received a copy of the GNU General Public License
6487 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6491 + * sub-routines for dentry cache
6496 +static void au_dpage_free(struct au_dpage *dpage)
6499 + struct dentry **p;
6501 + p = dpage->dentries;
6502 + for (i = 0; i < dpage->ndentry; i++)
6504 + free_page((unsigned long)dpage->dentries);
6507 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6513 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6514 + if (unlikely(!dpages->dpages))
6517 + p = (void *)__get_free_page(gfp);
6521 + dpages->dpages[0].ndentry = 0;
6522 + dpages->dpages[0].dentries = p;
6523 + dpages->ndpage = 1;
6524 + return 0; /* success */
6527 + kfree(dpages->dpages);
6532 +void au_dpages_free(struct au_dcsub_pages *dpages)
6535 + struct au_dpage *p;
6537 + p = dpages->dpages;
6538 + for (i = 0; i < dpages->ndpage; i++)
6539 + au_dpage_free(p++);
6540 + kfree(dpages->dpages);
6543 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6544 + struct dentry *dentry, gfp_t gfp)
6547 + struct au_dpage *dpage;
6550 + dpage = dpages->dpages + dpages->ndpage - 1;
6551 + sz = PAGE_SIZE / sizeof(dentry);
6552 + if (unlikely(dpage->ndentry >= sz)) {
6553 + AuLabel(new dpage);
6555 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6556 + p = au_kzrealloc(dpages->dpages, sz,
6557 + sz + sizeof(*dpages->dpages), gfp);
6561 + dpages->dpages = p;
6562 + dpage = dpages->dpages + dpages->ndpage;
6563 + p = (void *)__get_free_page(gfp);
6567 + dpage->ndentry = 0;
6568 + dpage->dentries = p;
6572 + AuDebugOn(au_dcount(dentry) <= 0);
6573 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6574 + return 0; /* success */
6580 +/* todo: BAD approach */
6581 +/* copied from linux/fs/dcache.c */
6589 +extern void d_walk(struct dentry *parent, void *data,
6590 + enum d_walk_ret (*enter)(void *, struct dentry *),
6591 + void (*finish)(void *));
6593 +struct ac_dpages_arg {
6595 + struct au_dcsub_pages *dpages;
6596 + struct super_block *sb;
6597 + au_dpages_test test;
6601 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6603 + enum d_walk_ret ret;
6604 + struct ac_dpages_arg *arg = _arg;
6606 + ret = D_WALK_CONTINUE;
6607 + if (dentry->d_sb == arg->sb
6608 + && !IS_ROOT(dentry)
6609 + && au_dcount(dentry) > 0
6611 + && (!arg->test || arg->test(dentry, arg->arg))) {
6612 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6613 + if (unlikely(arg->err))
6614 + ret = D_WALK_QUIT;
6620 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6621 + au_dpages_test test, void *arg)
6623 + struct ac_dpages_arg args = {
6631 + d_walk(root, &args, au_call_dpages_append, NULL);
6636 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6637 + int do_include, au_dpages_test test, void *arg)
6642 + write_seqlock(&rename_lock);
6643 + spin_lock(&dentry->d_lock);
6645 + && au_dcount(dentry) > 0
6646 + && (!test || test(dentry, arg)))
6647 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6648 + spin_unlock(&dentry->d_lock);
6649 + if (unlikely(err))
6653 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6656 + while (!IS_ROOT(dentry)) {
6657 + dentry = dentry->d_parent; /* rename_lock is locked */
6658 + spin_lock(&dentry->d_lock);
6659 + if (au_dcount(dentry) > 0
6660 + && (!test || test(dentry, arg)))
6661 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6662 + spin_unlock(&dentry->d_lock);
6663 + if (unlikely(err))
6668 + write_sequnlock(&rename_lock);
6672 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6674 + return au_di(dentry) && dentry->d_sb == arg;
6677 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6678 + struct dentry *dentry, int do_include)
6680 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6681 + au_dcsub_dpages_aufs, dentry->d_sb);
6684 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6686 + struct path path[2] = {
6695 + return path_is_under(path + 0, path + 1);
6697 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6698 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6699 +++ linux/fs/aufs/dcsub.h 2016-02-28 11:26:32.569971135 +0100
6702 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6704 + * This program, aufs is free software; you can redistribute it and/or modify
6705 + * it under the terms of the GNU General Public License as published by
6706 + * the Free Software Foundation; either version 2 of the License, or
6707 + * (at your option) any later version.
6709 + * This program is distributed in the hope that it will be useful,
6710 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6711 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6712 + * GNU General Public License for more details.
6714 + * You should have received a copy of the GNU General Public License
6715 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6719 + * sub-routines for dentry cache
6722 +#ifndef __AUFS_DCSUB_H__
6723 +#define __AUFS_DCSUB_H__
6727 +#include <linux/dcache.h>
6728 +#include <linux/fs.h>
6732 + struct dentry **dentries;
6735 +struct au_dcsub_pages {
6737 + struct au_dpage *dpages;
6740 +/* ---------------------------------------------------------------------- */
6743 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6744 +void au_dpages_free(struct au_dcsub_pages *dpages);
6745 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6746 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6747 + au_dpages_test test, void *arg);
6748 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6749 + int do_include, au_dpages_test test, void *arg);
6750 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6751 + struct dentry *dentry, int do_include);
6752 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6754 +/* ---------------------------------------------------------------------- */
6757 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6758 + * include/linux/dcache.h. Try them (in the future).
6761 +static inline int au_d_hashed_positive(struct dentry *d)
6764 + struct inode *inode = d_inode(d);
6767 + if (unlikely(d_unhashed(d)
6768 + || d_is_negative(d)
6769 + || !inode->i_nlink))
6774 +static inline int au_d_linkable(struct dentry *d)
6777 + struct inode *inode = d_inode(d);
6779 + err = au_d_hashed_positive(d);
6781 + && d_is_positive(d)
6782 + && (inode->i_state & I_LINKABLE))
6787 +static inline int au_d_alive(struct dentry *d)
6790 + struct inode *inode;
6794 + err = au_d_hashed_positive(d);
6796 + inode = d_inode(d);
6797 + if (unlikely(d_unlinked(d)
6798 + || d_is_negative(d)
6799 + || !inode->i_nlink))
6805 +static inline int au_alive_dir(struct dentry *d)
6809 + err = au_d_alive(d);
6810 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
6815 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6817 + return a->len == b->len
6818 + && !memcmp(a->name, b->name, a->len);
6823 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
6825 + * the type of d_lockref.count became int, but the inlined function d_count()
6826 + * still returns unsigned int.
6827 + * I don't know why. Maybe it is for every d_count() users?
6828 + * Anyway au_dcount() lives on.
6830 +static inline int au_dcount(struct dentry *d)
6832 + return (int)d_count(d);
6835 +#endif /* __KERNEL__ */
6836 +#endif /* __AUFS_DCSUB_H__ */
6837 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6838 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6839 +++ linux/fs/aufs/debug.c 2016-02-28 11:26:32.569971135 +0100
6842 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6844 + * This program, aufs is free software; you can redistribute it and/or modify
6845 + * it under the terms of the GNU General Public License as published by
6846 + * the Free Software Foundation; either version 2 of the License, or
6847 + * (at your option) any later version.
6849 + * This program is distributed in the hope that it will be useful,
6850 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6851 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6852 + * GNU General Public License for more details.
6854 + * You should have received a copy of the GNU General Public License
6855 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6859 + * debug print functions
6864 +/* Returns 0, or -errno. arg is in kp->arg. */
6865 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6869 + err = kstrtoint(val, 0, &n);
6879 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6880 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6885 + return sprintf(buffer, "%d", atomic_read(a));
6888 +static struct kernel_param_ops param_ops_atomic_t = {
6889 + .set = param_atomic_t_set,
6890 + .get = param_atomic_t_get
6891 + /* void (*free)(void *arg) */
6894 +atomic_t aufs_debug = ATOMIC_INIT(0);
6895 +MODULE_PARM_DESC(debug, "debug print");
6896 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6898 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
6899 +char *au_plevel = KERN_DEBUG;
6900 +#define dpri(fmt, ...) do { \
6902 + && strcmp(au_plevel, KERN_DEBUG)) \
6903 + || au_debug_test()) \
6904 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6907 +/* ---------------------------------------------------------------------- */
6909 +void au_dpri_whlist(struct au_nhash *whlist)
6911 + unsigned long ul, n;
6912 + struct hlist_head *head;
6913 + struct au_vdir_wh *pos;
6915 + n = whlist->nh_num;
6916 + head = whlist->nh_head;
6917 + for (ul = 0; ul < n; ul++) {
6918 + hlist_for_each_entry(pos, head, wh_hash)
6919 + dpri("b%d, %.*s, %d\n",
6921 + pos->wh_str.len, pos->wh_str.name,
6927 +void au_dpri_vdir(struct au_vdir *vdir)
6930 + union au_vdir_deblk_p p;
6933 + if (!vdir || IS_ERR(vdir)) {
6934 + dpri("err %ld\n", PTR_ERR(vdir));
6938 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6939 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6940 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6941 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6942 + p.deblk = vdir->vd_deblk[ul];
6944 + dpri("[%lu]: %p\n", ul, o);
6948 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6949 + struct dentry *wh)
6954 + if (!inode || IS_ERR(inode)) {
6955 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6959 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6960 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6961 + && sizeof(inode->i_blocks) != sizeof(u64));
6963 + n = (void *)wh->d_name.name;
6964 + l = wh->d_name.len;
6967 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6968 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6970 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6971 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6972 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6973 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6974 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6975 + inode->i_state, inode->i_flags, inode->i_version,
6976 + inode->i_generation,
6977 + l ? ", wh " : "", l, n);
6981 +void au_dpri_inode(struct inode *inode)
6983 + struct au_iinfo *iinfo;
6984 + aufs_bindex_t bindex;
6987 + err = do_pri_inode(-1, inode, -1, NULL);
6988 + if (err || !au_test_aufs(inode->i_sb))
6991 + iinfo = au_ii(inode);
6994 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6995 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6996 + if (iinfo->ii_bstart < 0)
6999 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
7000 + hn = !!au_hn(iinfo->ii_hinode + bindex);
7001 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
7002 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
7006 +void au_dpri_dalias(struct inode *inode)
7010 + spin_lock(&inode->i_lock);
7011 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7012 + au_dpri_dentry(d);
7013 + spin_unlock(&inode->i_lock);
7016 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7018 + struct dentry *wh = NULL;
7020 + struct au_iinfo *iinfo;
7022 + if (!dentry || IS_ERR(dentry)) {
7023 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7026 + /* do not call dget_parent() here */
7027 + /* note: access d_xxx without d_lock */
7028 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7029 + bindex, dentry, dentry,
7030 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7031 + au_dcount(dentry), dentry->d_flags,
7032 + d_unhashed(dentry) ? "un" : "");
7035 + && d_is_positive(dentry)
7036 + && au_test_aufs(dentry->d_sb)) {
7037 + iinfo = au_ii(d_inode(dentry));
7039 + hn = !!au_hn(iinfo->ii_hinode + bindex);
7040 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
7043 + do_pri_inode(bindex, d_inode(dentry), hn, wh);
7047 +void au_dpri_dentry(struct dentry *dentry)
7049 + struct au_dinfo *dinfo;
7050 + aufs_bindex_t bindex;
7052 + struct au_hdentry *hdp;
7054 + err = do_pri_dentry(-1, dentry);
7055 + if (err || !au_test_aufs(dentry->d_sb))
7058 + dinfo = au_di(dentry);
7061 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7062 + dinfo->di_bstart, dinfo->di_bend,
7063 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7064 + dinfo->di_tmpfile);
7065 + if (dinfo->di_bstart < 0)
7067 + hdp = dinfo->di_hdentry;
7068 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
7069 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
7072 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7076 + if (!file || IS_ERR(file)) {
7077 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7082 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7083 + && au_test_aufs(file->f_path.dentry->d_sb)
7085 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7086 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7087 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7088 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7089 + file->f_version, file->f_pos, a);
7090 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7091 + do_pri_dentry(bindex, file->f_path.dentry);
7095 +void au_dpri_file(struct file *file)
7097 + struct au_finfo *finfo;
7098 + struct au_fidir *fidir;
7099 + struct au_hfile *hfile;
7100 + aufs_bindex_t bindex;
7103 + err = do_pri_file(-1, file);
7105 + || IS_ERR_OR_NULL(file->f_path.dentry)
7106 + || !au_test_aufs(file->f_path.dentry->d_sb))
7109 + finfo = au_fi(file);
7112 + if (finfo->fi_btop < 0)
7114 + fidir = finfo->fi_hdir;
7116 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7118 + for (bindex = finfo->fi_btop;
7119 + bindex >= 0 && bindex <= fidir->fd_bbot;
7121 + hfile = fidir->fd_hfile + bindex;
7122 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7126 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7128 + struct vfsmount *mnt;
7129 + struct super_block *sb;
7131 + if (!br || IS_ERR(br))
7133 + mnt = au_br_mnt(br);
7134 + if (!mnt || IS_ERR(mnt))
7137 + if (!sb || IS_ERR(sb))
7140 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
7141 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7143 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
7144 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7145 + sb->s_flags, sb->s_count,
7146 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7150 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7154 +void au_dpri_sb(struct super_block *sb)
7156 + struct au_sbinfo *sbinfo;
7157 + aufs_bindex_t bindex;
7159 + /* to reuduce stack size */
7161 + struct vfsmount mnt;
7162 + struct au_branch fake;
7165 + /* this function can be called from magic sysrq */
7166 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7167 + if (unlikely(!a)) {
7168 + dpri("no memory\n");
7172 + a->mnt.mnt_sb = sb;
7173 + a->fake.br_path.mnt = &a->mnt;
7174 + atomic_set(&a->fake.br_count, 0);
7175 + smp_mb(); /* atomic_set */
7176 + err = do_pri_br(-1, &a->fake);
7178 + dpri("dev 0x%x\n", sb->s_dev);
7179 + if (err || !au_test_aufs(sb))
7182 + sbinfo = au_sbi(sb);
7185 + dpri("nw %d, gen %u, kobj %d\n",
7186 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7187 + atomic_read(&sbinfo->si_kobj.kref.refcount));
7188 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
7189 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7192 +/* ---------------------------------------------------------------------- */
7194 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7196 + struct inode *h_inode, *inode = d_inode(dentry);
7197 + struct dentry *h_dentry;
7198 + aufs_bindex_t bindex, bend, bi;
7200 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7203 + bend = au_dbend(dentry);
7204 + bi = au_ibend(inode);
7207 + bindex = au_dbstart(dentry);
7208 + bi = au_ibstart(inode);
7212 + for (; bindex <= bend; bindex++) {
7213 + h_dentry = au_h_dptr(dentry, bindex);
7216 + h_inode = au_h_iptr(inode, bindex);
7217 + if (unlikely(h_inode != d_inode(h_dentry))) {
7219 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7220 + AuDbgDentry(dentry);
7221 + AuDbgInode(inode);
7228 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7231 + struct au_dcsub_pages dpages;
7232 + struct au_dpage *dpage;
7233 + struct dentry **dentries;
7235 + err = au_dpages_init(&dpages, GFP_NOFS);
7237 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7239 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7240 + dpage = dpages.dpages + i;
7241 + dentries = dpage->dentries;
7242 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7243 + AuDebugOn(au_digen_test(dentries[j], sigen));
7245 + au_dpages_free(&dpages);
7248 +void au_dbg_verify_kthread(void)
7250 + if (au_wkq_test()) {
7253 + * It may be recursive, but udba=notify between two aufs mounts,
7254 + * where a single ro branch is shared, is not a problem.
7260 +/* ---------------------------------------------------------------------- */
7262 +int __init au_debug_init(void)
7264 + aufs_bindex_t bindex;
7265 + struct au_vdir_destr destr;
7268 + AuDebugOn(bindex >= 0);
7271 + AuDebugOn(destr.len < NAME_MAX);
7273 +#ifdef CONFIG_4KSTACKS
7274 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7279 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7280 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7281 +++ linux/fs/aufs/debug.h 2016-02-28 11:26:32.569971135 +0100
7284 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7286 + * This program, aufs is free software; you can redistribute it and/or modify
7287 + * it under the terms of the GNU General Public License as published by
7288 + * the Free Software Foundation; either version 2 of the License, or
7289 + * (at your option) any later version.
7291 + * This program is distributed in the hope that it will be useful,
7292 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7293 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7294 + * GNU General Public License for more details.
7296 + * You should have received a copy of the GNU General Public License
7297 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7301 + * debug print functions
7304 +#ifndef __AUFS_DEBUG_H__
7305 +#define __AUFS_DEBUG_H__
7309 +#include <linux/atomic.h>
7310 +#include <linux/module.h>
7311 +#include <linux/kallsyms.h>
7312 +#include <linux/sysrq.h>
7314 +#ifdef CONFIG_AUFS_DEBUG
7315 +#define AuDebugOn(a) BUG_ON(a)
7317 +/* module parameter */
7318 +extern atomic_t aufs_debug;
7319 +static inline void au_debug_on(void)
7321 + atomic_inc(&aufs_debug);
7323 +static inline void au_debug_off(void)
7325 + atomic_dec_if_positive(&aufs_debug);
7328 +static inline int au_debug_test(void)
7330 + return atomic_read(&aufs_debug) > 0;
7333 +#define AuDebugOn(a) do {} while (0)
7334 +AuStubVoid(au_debug_on, void)
7335 +AuStubVoid(au_debug_off, void)
7336 +AuStubInt0(au_debug_test, void)
7337 +#endif /* CONFIG_AUFS_DEBUG */
7339 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7341 +/* ---------------------------------------------------------------------- */
7345 +#define AuDbg(fmt, ...) do { \
7346 + if (au_debug_test()) \
7347 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7349 +#define AuLabel(l) AuDbg(#l "\n")
7350 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7351 +#define AuWarn1(fmt, ...) do { \
7352 + static unsigned char _c; \
7354 + pr_warn(fmt, ##__VA_ARGS__); \
7357 +#define AuErr1(fmt, ...) do { \
7358 + static unsigned char _c; \
7360 + pr_err(fmt, ##__VA_ARGS__); \
7363 +#define AuIOErr1(fmt, ...) do { \
7364 + static unsigned char _c; \
7366 + AuIOErr(fmt, ##__VA_ARGS__); \
7369 +#define AuUnsupportMsg "This operation is not supported." \
7370 + " Please report this application to aufs-users ML."
7371 +#define AuUnsupport(fmt, ...) do { \
7372 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7376 +#define AuTraceErr(e) do { \
7377 + if (unlikely((e) < 0)) \
7378 + AuDbg("err %d\n", (int)(e)); \
7381 +#define AuTraceErrPtr(p) do { \
7383 + AuDbg("err %ld\n", PTR_ERR(p)); \
7386 +/* dirty macros for debug print, use with "%.*s" and caution */
7387 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7389 +/* ---------------------------------------------------------------------- */
7392 +#ifdef CONFIG_AUFS_DEBUG
7393 +extern struct mutex au_dbg_mtx;
7394 +extern char *au_plevel;
7396 +void au_dpri_whlist(struct au_nhash *whlist);
7398 +void au_dpri_vdir(struct au_vdir *vdir);
7400 +void au_dpri_inode(struct inode *inode);
7401 +void au_dpri_dalias(struct inode *inode);
7402 +void au_dpri_dentry(struct dentry *dentry);
7404 +void au_dpri_file(struct file *filp);
7405 +struct super_block;
7406 +void au_dpri_sb(struct super_block *sb);
7408 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7409 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7410 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7411 +void au_dbg_verify_kthread(void);
7413 +int __init au_debug_init(void);
7415 +#define AuDbgWhlist(w) do { \
7416 + mutex_lock(&au_dbg_mtx); \
7418 + au_dpri_whlist(w); \
7419 + mutex_unlock(&au_dbg_mtx); \
7422 +#define AuDbgVdir(v) do { \
7423 + mutex_lock(&au_dbg_mtx); \
7425 + au_dpri_vdir(v); \
7426 + mutex_unlock(&au_dbg_mtx); \
7429 +#define AuDbgInode(i) do { \
7430 + mutex_lock(&au_dbg_mtx); \
7432 + au_dpri_inode(i); \
7433 + mutex_unlock(&au_dbg_mtx); \
7436 +#define AuDbgDAlias(i) do { \
7437 + mutex_lock(&au_dbg_mtx); \
7439 + au_dpri_dalias(i); \
7440 + mutex_unlock(&au_dbg_mtx); \
7443 +#define AuDbgDentry(d) do { \
7444 + mutex_lock(&au_dbg_mtx); \
7446 + au_dpri_dentry(d); \
7447 + mutex_unlock(&au_dbg_mtx); \
7450 +#define AuDbgFile(f) do { \
7451 + mutex_lock(&au_dbg_mtx); \
7453 + au_dpri_file(f); \
7454 + mutex_unlock(&au_dbg_mtx); \
7457 +#define AuDbgSb(sb) do { \
7458 + mutex_lock(&au_dbg_mtx); \
7459 + AuDbg(#sb "\n"); \
7461 + mutex_unlock(&au_dbg_mtx); \
7464 +#define AuDbgSym(addr) do { \
7465 + char sym[KSYM_SYMBOL_LEN]; \
7466 + sprint_symbol(sym, (unsigned long)addr); \
7467 + AuDbg("%s\n", sym); \
7470 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7471 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7472 +AuStubVoid(au_dbg_verify_kthread, void)
7473 +AuStubInt0(__init au_debug_init, void)
7475 +#define AuDbgWhlist(w) do {} while (0)
7476 +#define AuDbgVdir(v) do {} while (0)
7477 +#define AuDbgInode(i) do {} while (0)
7478 +#define AuDbgDAlias(i) do {} while (0)
7479 +#define AuDbgDentry(d) do {} while (0)
7480 +#define AuDbgFile(f) do {} while (0)
7481 +#define AuDbgSb(sb) do {} while (0)
7482 +#define AuDbgSym(addr) do {} while (0)
7483 +#endif /* CONFIG_AUFS_DEBUG */
7485 +/* ---------------------------------------------------------------------- */
7487 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7488 +int __init au_sysrq_init(void);
7489 +void au_sysrq_fin(void);
7491 +#ifdef CONFIG_HW_CONSOLE
7492 +#define au_dbg_blocked() do { \
7494 + handle_sysrq('w'); \
7497 +AuStubVoid(au_dbg_blocked, void)
7501 +AuStubInt0(__init au_sysrq_init, void)
7502 +AuStubVoid(au_sysrq_fin, void)
7503 +AuStubVoid(au_dbg_blocked, void)
7504 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7506 +#endif /* __KERNEL__ */
7507 +#endif /* __AUFS_DEBUG_H__ */
7508 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7509 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7510 +++ linux/fs/aufs/dentry.c 2016-02-28 11:26:32.569971135 +0100
7513 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7515 + * This program, aufs is free software; you can redistribute it and/or modify
7516 + * it under the terms of the GNU General Public License as published by
7517 + * the Free Software Foundation; either version 2 of the License, or
7518 + * (at your option) any later version.
7520 + * This program is distributed in the hope that it will be useful,
7521 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7522 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7523 + * GNU General Public License for more details.
7525 + * You should have received a copy of the GNU General Public License
7526 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7530 + * lookup and dentry operations
7533 +#include <linux/namei.h>
7536 +#define AuLkup_ALLOW_NEG 1
7537 +#define AuLkup_IGNORE_PERM (1 << 1)
7538 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7539 +#define au_fset_lkup(flags, name) \
7540 + do { (flags) |= AuLkup_##name; } while (0)
7541 +#define au_fclr_lkup(flags, name) \
7542 + do { (flags) &= ~AuLkup_##name; } while (0)
7544 +struct au_do_lookup_args {
7545 + unsigned int flags;
7550 + * returns positive/negative dentry, NULL or an error.
7551 + * NULL means whiteout-ed or not-found.
7553 +static struct dentry*
7554 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7555 + aufs_bindex_t bindex, struct qstr *wh_name,
7556 + struct au_do_lookup_args *args)
7558 + struct dentry *h_dentry;
7559 + struct inode *h_inode;
7560 + struct au_branch *br;
7561 + int wh_found, opq;
7562 + unsigned char wh_able;
7563 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7564 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7568 + br = au_sbr(dentry->d_sb, bindex);
7569 + wh_able = !!au_br_whable(br->br_perm);
7571 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7572 + h_dentry = ERR_PTR(wh_found);
7575 + if (unlikely(wh_found < 0))
7578 + /* We found a whiteout */
7579 + /* au_set_dbend(dentry, bindex); */
7580 + au_set_dbwh(dentry, bindex);
7582 + return NULL; /* success */
7586 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7588 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7589 + if (IS_ERR(h_dentry)) {
7590 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7596 + h_inode = d_inode(h_dentry);
7597 + if (d_is_negative(h_dentry)) {
7600 + } else if (wh_found
7601 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7604 + if (au_dbend(dentry) <= bindex)
7605 + au_set_dbend(dentry, bindex);
7606 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7607 + au_set_dbstart(dentry, bindex);
7608 + au_set_h_dptr(dentry, bindex, h_dentry);
7610 + if (!d_is_dir(h_dentry)
7612 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7613 + goto out; /* success */
7615 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7616 + opq = au_diropq_test(h_dentry);
7617 + mutex_unlock(&h_inode->i_mutex);
7619 + au_set_dbdiropq(dentry, bindex);
7620 + else if (unlikely(opq < 0)) {
7621 + au_set_h_dptr(dentry, bindex, NULL);
7622 + h_dentry = ERR_PTR(opq);
7633 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7635 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7636 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7642 + * returns the number of lower positive dentries,
7643 + * otherwise an error.
7644 + * can be called at unlinking with @type is zero.
7646 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7648 + int npositive, err;
7649 + aufs_bindex_t bindex, btail, bdiropq;
7650 + unsigned char isdir, dirperm1;
7651 + struct qstr whname;
7652 + struct au_do_lookup_args args = {
7656 + const struct qstr *name = &dentry->d_name;
7657 + struct dentry *parent;
7658 + struct super_block *sb;
7660 + sb = dentry->d_sb;
7661 + err = au_test_shwh(sb, name);
7662 + if (unlikely(err))
7665 + err = au_wh_name_alloc(&whname, name);
7666 + if (unlikely(err))
7669 + isdir = !!d_is_dir(dentry);
7671 + au_fset_lkup(args.flags, ALLOW_NEG);
7672 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7675 + parent = dget_parent(dentry);
7676 + btail = au_dbtaildir(parent);
7677 + for (bindex = bstart; bindex <= btail; bindex++) {
7678 + struct dentry *h_parent, *h_dentry;
7679 + struct inode *h_inode, *h_dir;
7681 + h_dentry = au_h_dptr(dentry, bindex);
7683 + if (d_is_positive(h_dentry))
7685 + if (type != S_IFDIR)
7689 + h_parent = au_h_dptr(parent, bindex);
7690 + if (!h_parent || !d_is_dir(h_parent))
7693 + h_dir = d_inode(h_parent);
7694 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7695 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7697 + mutex_unlock(&h_dir->i_mutex);
7698 + err = PTR_ERR(h_dentry);
7699 + if (IS_ERR(h_dentry))
7702 + au_fclr_lkup(args.flags, ALLOW_NEG);
7704 + au_fset_lkup(args.flags, IGNORE_PERM);
7706 + if (au_dbwh(dentry) == bindex)
7710 + if (d_is_negative(h_dentry))
7712 + h_inode = d_inode(h_dentry);
7715 + args.type = h_inode->i_mode & S_IFMT;
7716 + if (args.type != S_IFDIR)
7719 + /* the type of lower may be different */
7720 + bdiropq = au_dbdiropq(dentry);
7721 + if (bdiropq >= 0 && bdiropq <= bindex)
7727 + AuLabel(positive);
7728 + au_update_dbstart(dentry);
7731 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7732 + && au_dbstart(dentry) < 0)) {
7734 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7740 + kfree(whname.name);
7745 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7747 + struct dentry *dentry;
7750 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7751 + dentry = vfsub_lkup_one(name, parent);
7753 + struct vfsub_lkup_one_args args = {
7759 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7760 + if (unlikely(wkq_err))
7761 + dentry = ERR_PTR(wkq_err);
7768 + * lookup @dentry on @bindex which should be negative.
7770 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7773 + struct dentry *parent, *h_parent, *h_dentry;
7774 + struct au_branch *br;
7776 + parent = dget_parent(dentry);
7777 + h_parent = au_h_dptr(parent, bindex);
7778 + br = au_sbr(dentry->d_sb, bindex);
7780 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7782 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7783 + err = PTR_ERR(h_dentry);
7784 + if (IS_ERR(h_dentry))
7786 + if (unlikely(d_is_positive(h_dentry))) {
7788 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7794 + if (bindex < au_dbstart(dentry))
7795 + au_set_dbstart(dentry, bindex);
7796 + if (au_dbend(dentry) < bindex)
7797 + au_set_dbend(dentry, bindex);
7798 + au_set_h_dptr(dentry, bindex, h_dentry);
7805 +/* ---------------------------------------------------------------------- */
7807 +/* subset of struct inode */
7809 + unsigned long i_ino;
7810 + /* unsigned int i_nlink; */
7816 + blkcnt_t i_blocks;
7821 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7823 + ia->i_ino = h_inode->i_ino;
7824 + /* ia->i_nlink = h_inode->i_nlink; */
7825 + ia->i_uid = h_inode->i_uid;
7826 + ia->i_gid = h_inode->i_gid;
7827 + ia->i_version = h_inode->i_version;
7829 + ia->i_size = h_inode->i_size;
7830 + ia->i_blocks = h_inode->i_blocks;
7832 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7835 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7837 + return ia->i_ino != h_inode->i_ino
7838 + /* || ia->i_nlink != h_inode->i_nlink */
7839 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7840 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7841 + || ia->i_version != h_inode->i_version
7843 + || ia->i_size != h_inode->i_size
7844 + || ia->i_blocks != h_inode->i_blocks
7846 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7849 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7850 + struct au_branch *br)
7853 + struct au_iattr ia;
7854 + struct inode *h_inode;
7855 + struct dentry *h_d;
7856 + struct super_block *h_sb;
7859 + memset(&ia, -1, sizeof(ia));
7860 + h_sb = h_dentry->d_sb;
7862 + if (d_is_positive(h_dentry)) {
7863 + h_inode = d_inode(h_dentry);
7864 + au_iattr_save(&ia, h_inode);
7865 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7866 + /* nfs d_revalidate may return 0 for negative dentry */
7867 + /* fuse d_revalidate always return 0 for negative dentry */
7870 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7871 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7872 + err = PTR_ERR(h_d);
7877 + if (unlikely(h_d != h_dentry
7878 + || d_inode(h_d) != h_inode
7879 + || (h_inode && au_iattr_test(&ia, h_inode))))
7880 + err = au_busy_or_stale();
7888 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7889 + struct dentry *h_parent, struct au_branch *br)
7894 + if (udba == AuOpt_UDBA_REVAL
7895 + && !au_test_fs_remote(h_dentry->d_sb)) {
7897 + err = (d_inode(h_dentry->d_parent) != h_dir);
7898 + } else if (udba != AuOpt_UDBA_NONE)
7899 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7904 +/* ---------------------------------------------------------------------- */
7906 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7909 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7910 + struct au_hdentry tmp, *p, *q;
7911 + struct au_dinfo *dinfo;
7912 + struct super_block *sb;
7914 + DiMustWriteLock(dentry);
7916 + sb = dentry->d_sb;
7917 + dinfo = au_di(dentry);
7918 + bend = dinfo->di_bend;
7919 + bwh = dinfo->di_bwh;
7920 + bdiropq = dinfo->di_bdiropq;
7921 + p = dinfo->di_hdentry + dinfo->di_bstart;
7922 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7923 + if (!p->hd_dentry)
7926 + new_bindex = au_br_index(sb, p->hd_id);
7927 + if (new_bindex == bindex)
7930 + if (dinfo->di_bwh == bindex)
7932 + if (dinfo->di_bdiropq == bindex)
7933 + bdiropq = new_bindex;
7934 + if (new_bindex < 0) {
7936 + p->hd_dentry = NULL;
7940 + /* swap two lower dentries, and loop again */
7941 + q = dinfo->di_hdentry + new_bindex;
7945 + if (tmp.hd_dentry) {
7951 + dinfo->di_bwh = -1;
7952 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7953 + dinfo->di_bwh = bwh;
7955 + dinfo->di_bdiropq = -1;
7957 + && bdiropq <= au_sbend(sb)
7958 + && au_sbr_whable(sb, bdiropq))
7959 + dinfo->di_bdiropq = bdiropq;
7962 + dinfo->di_bstart = -1;
7963 + dinfo->di_bend = -1;
7964 + bend = au_dbend(parent);
7965 + p = dinfo->di_hdentry;
7966 + for (bindex = 0; bindex <= bend; bindex++, p++)
7967 + if (p->hd_dentry) {
7968 + dinfo->di_bstart = bindex;
7972 + if (dinfo->di_bstart >= 0) {
7973 + p = dinfo->di_hdentry + bend;
7974 + for (bindex = bend; bindex >= 0; bindex--, p--)
7975 + if (p->hd_dentry) {
7976 + dinfo->di_bend = bindex;
7985 +static void au_do_hide(struct dentry *dentry)
7987 + struct inode *inode;
7989 + if (d_really_is_positive(dentry)) {
7990 + inode = d_inode(dentry);
7991 + if (!d_is_dir(dentry)) {
7992 + if (inode->i_nlink && !d_unhashed(dentry))
7993 + drop_nlink(inode);
7995 + clear_nlink(inode);
7996 + /* stop next lookup */
7997 + inode->i_flags |= S_DEAD;
7999 + smp_mb(); /* necessary? */
8004 +static int au_hide_children(struct dentry *parent)
8006 + int err, i, j, ndentry;
8007 + struct au_dcsub_pages dpages;
8008 + struct au_dpage *dpage;
8009 + struct dentry *dentry;
8011 + err = au_dpages_init(&dpages, GFP_NOFS);
8012 + if (unlikely(err))
8014 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8015 + if (unlikely(err))
8018 + /* in reverse order */
8019 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8020 + dpage = dpages.dpages + i;
8021 + ndentry = dpage->ndentry;
8022 + for (j = ndentry - 1; j >= 0; j--) {
8023 + dentry = dpage->dentries[j];
8024 + if (dentry != parent)
8025 + au_do_hide(dentry);
8030 + au_dpages_free(&dpages);
8035 +static void au_hide(struct dentry *dentry)
8039 + AuDbgDentry(dentry);
8040 + if (d_is_dir(dentry)) {
8041 + /* shrink_dcache_parent(dentry); */
8042 + err = au_hide_children(dentry);
8043 + if (unlikely(err))
8044 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8047 + au_do_hide(dentry);
8051 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8053 + * a dirty branch is added
8054 + * - on the top of layers
8055 + * - in the middle of layers
8056 + * - to the bottom of layers
8058 + * on the added branch there exists
8061 + * - a same named entry
8063 + * * negative --> positive
8064 + * * positive --> positive
8065 + * - type is unchanged
8066 + * - type is changed
8068 + * * negative --> negative
8069 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8072 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8073 + struct au_dinfo *tmp)
8076 + aufs_bindex_t bindex, bend;
8078 + struct dentry *dentry;
8079 + struct inode *inode;
8081 + } orig_h, tmp_h = {
8084 + struct au_hdentry *hd;
8085 + struct inode *inode, *h_inode;
8086 + struct dentry *h_dentry;
8089 + AuDebugOn(dinfo->di_bstart < 0);
8091 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
8092 + orig_h.inode = NULL;
8093 + if (d_is_positive(orig_h.dentry)) {
8094 + orig_h.inode = d_inode(orig_h.dentry);
8095 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8097 + if (tmp->di_bstart >= 0) {
8098 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
8099 + if (d_is_positive(tmp_h.dentry)) {
8100 + tmp_h.inode = d_inode(tmp_h.dentry);
8101 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8106 + if (d_really_is_positive(dentry))
8107 + inode = d_inode(dentry);
8108 + if (!orig_h.inode) {
8109 + AuDbg("nagative originally\n");
8115 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8116 + AuDebugOn(dinfo->di_bdiropq != -1);
8118 + if (!tmp_h.inode) {
8119 + AuDbg("negative --> negative\n");
8120 + /* should have only one negative lower */
8121 + if (tmp->di_bstart >= 0
8122 + && tmp->di_bstart < dinfo->di_bstart) {
8123 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
8124 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8125 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
8126 + au_di_cp(dinfo, tmp);
8127 + hd = tmp->di_hdentry + tmp->di_bstart;
8128 + au_set_h_dptr(dentry, tmp->di_bstart,
8129 + dget(hd->hd_dentry));
8131 + au_dbg_verify_dinode(dentry);
8133 + AuDbg("negative --> positive\n");
8135 + * similar to the behaviour of creating with bypassing
8137 + * unhash it in order to force an error in the
8138 + * succeeding create operation.
8139 + * we should not set S_DEAD here.
8142 + /* au_di_swap(tmp, dinfo); */
8143 + au_dbg_verify_dinode(dentry);
8146 + AuDbg("positive originally\n");
8147 + /* inode may be NULL */
8148 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8149 + if (!tmp_h.inode) {
8150 + AuDbg("positive --> negative\n");
8151 + /* or bypassing aufs */
8153 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
8154 + dinfo->di_bwh = tmp->di_bwh;
8156 + err = au_refresh_hinode_self(inode);
8157 + au_dbg_verify_dinode(dentry);
8158 + } else if (orig_h.mode == tmp_h.mode) {
8159 + AuDbg("positive --> positive, same type\n");
8160 + if (!S_ISDIR(orig_h.mode)
8161 + && dinfo->di_bstart > tmp->di_bstart) {
8163 + * similar to the behaviour of removing and
8168 + err = au_refresh_hinode_self(inode);
8169 + au_dbg_verify_dinode(dentry);
8171 + /* fill empty slots */
8172 + if (dinfo->di_bstart > tmp->di_bstart)
8173 + dinfo->di_bstart = tmp->di_bstart;
8174 + if (dinfo->di_bend < tmp->di_bend)
8175 + dinfo->di_bend = tmp->di_bend;
8176 + dinfo->di_bwh = tmp->di_bwh;
8177 + dinfo->di_bdiropq = tmp->di_bdiropq;
8178 + hd = tmp->di_hdentry;
8179 + bend = dinfo->di_bend;
8180 + for (bindex = tmp->di_bstart; bindex <= bend;
8182 + if (au_h_dptr(dentry, bindex))
8184 + h_dentry = hd[bindex].hd_dentry;
8187 + AuDebugOn(d_is_negative(h_dentry));
8188 + h_inode = d_inode(h_dentry);
8189 + AuDebugOn(orig_h.mode
8190 + != (h_inode->i_mode
8192 + au_set_h_dptr(dentry, bindex,
8195 + err = au_refresh_hinode(inode, dentry);
8196 + au_dbg_verify_dinode(dentry);
8199 + AuDbg("positive --> positive, different type\n");
8200 + /* similar to the behaviour of removing and creating */
8203 + err = au_refresh_hinode_self(inode);
8204 + au_dbg_verify_dinode(dentry);
8212 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8214 + const struct dentry_operations *dop
8215 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8216 + static const unsigned int mask
8217 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8219 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8221 + if (dentry->d_op == dop)
8224 + AuDbg("%pd\n", dentry);
8225 + spin_lock(&dentry->d_lock);
8226 + if (dop == &aufs_dop)
8227 + dentry->d_flags |= mask;
8229 + dentry->d_flags &= ~mask;
8230 + dentry->d_op = dop;
8231 + spin_unlock(&dentry->d_lock);
8234 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8237 + unsigned int sigen;
8238 + struct au_dinfo *dinfo, *tmp;
8239 + struct super_block *sb;
8240 + struct inode *inode;
8242 + DiMustWriteLock(dentry);
8243 + AuDebugOn(IS_ROOT(dentry));
8244 + AuDebugOn(d_really_is_negative(parent));
8246 + sb = dentry->d_sb;
8247 + sigen = au_sigen(sb);
8248 + err = au_digen_test(parent, sigen);
8249 + if (unlikely(err))
8252 + dinfo = au_di(dentry);
8253 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
8254 + if (unlikely(err))
8256 + ebrange = au_dbrange_test(dentry);
8258 + ebrange = au_do_refresh_hdentry(dentry, parent);
8260 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8261 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
8262 + if (d_really_is_positive(dentry)) {
8263 + inode = d_inode(dentry);
8264 + err = au_refresh_hinode_self(inode);
8266 + au_dbg_verify_dinode(dentry);
8268 + goto out_dgen; /* success */
8272 + /* temporary dinfo */
8273 + AuDbgDentry(dentry);
8275 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8276 + if (unlikely(!tmp))
8278 + au_di_swap(tmp, dinfo);
8279 + /* returns the number of positive dentries */
8281 + * if current working dir is removed, it returns an error.
8282 + * but the dentry is legal.
8284 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
8285 + AuDbgDentry(dentry);
8286 + au_di_swap(tmp, dinfo);
8287 + if (err == -ENOENT)
8290 + /* compare/refresh by dinfo */
8291 + AuDbgDentry(dentry);
8292 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8293 + au_dbg_verify_dinode(dentry);
8296 + au_rw_write_unlock(&tmp->di_rwsem);
8298 + if (unlikely(err))
8302 + au_update_digen(dentry);
8304 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8305 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8306 + AuDbgDentry(dentry);
8312 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8313 + struct dentry *dentry, aufs_bindex_t bindex)
8318 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8321 + AuDbg("b%d\n", bindex);
8323 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8324 + * due to whiteout and branch permission.
8326 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8327 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8328 + /* it may return tri-state */
8329 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8331 + if (unlikely(valid < 0))
8341 +/* todo: remove this */
8342 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8343 + unsigned int flags, int do_udba)
8346 + umode_t mode, h_mode;
8347 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
8348 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8349 + struct inode *h_inode, *h_cached_inode;
8350 + struct dentry *h_dentry;
8351 + struct qstr *name, *h_name;
8358 + unhashed = !!d_unhashed(dentry);
8359 + is_root = !!IS_ROOT(dentry);
8360 + name = &dentry->d_name;
8361 + tmpfile = au_di(dentry)->di_tmpfile;
8364 + * Theoretically, REVAL test should be unnecessary in case of
8366 + * But {fs,i}notify doesn't fire some necessary events,
8367 + * IN_ATTRIB for atime/nlink/pageio
8368 + * Let's do REVAL test too.
8370 + if (do_udba && inode) {
8371 + mode = (inode->i_mode & S_IFMT);
8372 + plus = (inode->i_nlink > 0);
8373 + ibs = au_ibstart(inode);
8374 + ibe = au_ibend(inode);
8377 + bstart = au_dbstart(dentry);
8379 + if (inode && S_ISDIR(inode->i_mode))
8380 + btail = au_dbtaildir(dentry);
8381 + for (bindex = bstart; bindex <= btail; bindex++) {
8382 + h_dentry = au_h_dptr(dentry, bindex);
8386 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8387 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8388 + spin_lock(&h_dentry->d_lock);
8389 + h_name = &h_dentry->d_name;
8390 + if (unlikely(do_udba
8393 + && (unhashed != !!d_unhashed(h_dentry)
8395 + && !au_qstreq(name, h_name))
8398 + && !(flags & LOOKUP_OPEN)
8399 + && (h_dentry->d_flags
8400 + & DCACHE_NFSFS_RENAMED)))
8404 + h_unhashed = d_unhashed(h_dentry);
8405 + spin_unlock(&h_dentry->d_lock);
8406 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8407 + unhashed, h_unhashed, dentry, h_dentry);
8410 + spin_unlock(&h_dentry->d_lock);
8412 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8413 + if (unlikely(err))
8414 + /* do not goto err, to keep the errno */
8417 + /* todo: plink too? */
8422 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8426 + if (d_is_positive(h_dentry))
8427 + h_inode = d_inode(h_dentry);
8430 + h_cached_inode = h_inode;
8432 + h_mode = (h_inode->i_mode & S_IFMT);
8433 + h_plus = (h_inode->i_nlink > 0);
8435 + if (inode && ibs <= bindex && bindex <= ibe)
8436 + h_cached_inode = au_h_iptr(inode, bindex);
8439 + if (unlikely(plus != h_plus && !tmpfile))
8442 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8444 + && !IS_ROOT(h_dentry)
8445 + && unhashed != d_unhashed(h_dentry)))
8448 + if (unlikely(mode != h_mode
8449 + || h_cached_inode != h_inode))
8462 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8463 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8466 + struct dentry *parent;
8468 + if (!au_digen_test(dentry, sigen))
8471 + parent = dget_parent(dentry);
8472 + di_read_lock_parent(parent, AuLock_IR);
8473 + AuDebugOn(au_digen_test(parent, sigen));
8474 + au_dbg_verify_gen(parent, sigen);
8475 + err = au_refresh_dentry(dentry, parent);
8476 + di_read_unlock(parent, AuLock_IR);
8482 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8485 + struct dentry *d, *parent;
8487 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8488 + return simple_reval_dpath(dentry, sigen);
8490 + /* slow loop, keep it simple and stupid */
8491 + /* cf: au_cpup_dirs() */
8494 + while (au_digen_test(dentry, sigen)) {
8498 + parent = dget_parent(d);
8499 + if (!au_digen_test(parent, sigen))
8505 + di_write_lock_child2(d);
8507 + /* someone might update our dentry while we were sleeping */
8508 + if (au_digen_test(d, sigen)) {
8510 + * todo: consolidate with simple_reval_dpath(),
8511 + * do_refresh() and au_reval_for_attr().
8513 + di_read_lock_parent(parent, AuLock_IR);
8514 + err = au_refresh_dentry(d, parent);
8515 + di_read_unlock(parent, AuLock_IR);
8519 + di_write_unlock(d);
8521 + if (unlikely(err))
8529 + * if valid returns 1, otherwise 0.
8531 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8534 + unsigned int sigen;
8535 + unsigned char do_udba;
8536 + struct super_block *sb;
8537 + struct inode *inode;
8539 + /* todo: support rcu-walk? */
8540 + if (flags & LOOKUP_RCU)
8544 + if (unlikely(!au_di(dentry)))
8548 + sb = dentry->d_sb;
8551 + * i_mutex of parent dir may be held,
8552 + * but we should not return 'invalid' due to busy.
8554 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8555 + if (unlikely(err)) {
8561 + if (d_really_is_positive(dentry))
8562 + inode = d_inode(dentry);
8563 + if (unlikely(inode && is_bad_inode(inode))) {
8568 + if (unlikely(au_dbrange_test(dentry))) {
8574 + sigen = au_sigen(sb);
8575 + if (au_digen_test(dentry, sigen)) {
8576 + AuDebugOn(IS_ROOT(dentry));
8577 + err = au_reval_dpath(dentry, sigen);
8578 + if (unlikely(err)) {
8583 + di_downgrade_lock(dentry, AuLock_IR);
8586 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8588 + && !(inode->i_state && I_LINKABLE)
8589 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
8594 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8595 + if (do_udba && inode) {
8596 + aufs_bindex_t bstart = au_ibstart(inode);
8597 + struct inode *h_inode;
8599 + if (bstart >= 0) {
8600 + h_inode = au_h_iptr(inode, bstart);
8601 + if (h_inode && au_test_higen(inode, h_inode)) {
8608 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8609 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8611 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8617 + di_downgrade_lock(dentry, AuLock_IR);
8619 + aufs_read_unlock(dentry, AuLock_IR);
8624 + AuDbg("%pd invalid, %d\n", dentry, valid);
8630 +static void aufs_d_release(struct dentry *dentry)
8632 + if (au_di(dentry)) {
8633 + au_di_fin(dentry);
8634 + au_hn_di_reinit(dentry);
8638 +const struct dentry_operations aufs_dop = {
8639 + .d_revalidate = aufs_d_revalidate,
8640 + .d_weak_revalidate = aufs_d_revalidate,
8641 + .d_release = aufs_d_release
8644 +/* aufs_dop without d_revalidate */
8645 +const struct dentry_operations aufs_dop_noreval = {
8646 + .d_release = aufs_d_release
8648 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8649 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8650 +++ linux/fs/aufs/dentry.h 2016-02-28 11:26:32.569971135 +0100
8653 + * Copyright (C) 2005-2016 Junjiro R. Okajima
8655 + * This program, aufs is free software; you can redistribute it and/or modify
8656 + * it under the terms of the GNU General Public License as published by
8657 + * the Free Software Foundation; either version 2 of the License, or
8658 + * (at your option) any later version.
8660 + * This program is distributed in the hope that it will be useful,
8661 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8662 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8663 + * GNU General Public License for more details.
8665 + * You should have received a copy of the GNU General Public License
8666 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8670 + * lookup and dentry operations
8673 +#ifndef __AUFS_DENTRY_H__
8674 +#define __AUFS_DENTRY_H__
8678 +#include <linux/dcache.h>
8681 +struct au_hdentry {
8682 + struct dentry *hd_dentry;
8683 + aufs_bindex_t hd_id;
8687 + atomic_t di_generation;
8689 + struct au_rwsem di_rwsem;
8690 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8691 + unsigned char di_tmpfile; /* to allow the different name */
8692 + struct au_hdentry *di_hdentry;
8693 +} ____cacheline_aligned_in_smp;
8695 +/* ---------------------------------------------------------------------- */
8698 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
8700 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8701 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8702 + struct dentry *h_parent, struct au_branch *br);
8704 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8705 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8706 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8707 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8708 +void au_refresh_dop(struct dentry *dentry, int force_reval);
8711 +void au_di_init_once(void *_di);
8712 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8713 +void au_di_free(struct au_dinfo *dinfo);
8714 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8715 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8716 +int au_di_init(struct dentry *dentry);
8717 +void au_di_fin(struct dentry *dentry);
8718 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8720 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8721 +void di_read_unlock(struct dentry *d, int flags);
8722 +void di_downgrade_lock(struct dentry *d, int flags);
8723 +void di_write_lock(struct dentry *d, unsigned int lsc);
8724 +void di_write_unlock(struct dentry *d);
8725 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8726 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8727 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8729 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8730 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8731 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8732 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8734 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8735 + struct dentry *h_dentry);
8736 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8737 +int au_dbrange_test(struct dentry *dentry);
8738 +void au_update_digen(struct dentry *dentry);
8739 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8740 +void au_update_dbstart(struct dentry *dentry);
8741 +void au_update_dbend(struct dentry *dentry);
8742 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8744 +/* ---------------------------------------------------------------------- */
8746 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8748 + return dentry->d_fsdata;
8751 +/* ---------------------------------------------------------------------- */
8753 +/* lock subclass for dinfo */
8755 + AuLsc_DI_CHILD, /* child first */
8756 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8757 + AuLsc_DI_CHILD3, /* copyup dirs */
8761 + AuLsc_DI_TMP /* temp for replacing dinfo */
8765 + * di_read_lock_child, di_write_lock_child,
8766 + * di_read_lock_child2, di_write_lock_child2,
8767 + * di_read_lock_child3, di_write_lock_child3,
8768 + * di_read_lock_parent, di_write_lock_parent,
8769 + * di_read_lock_parent2, di_write_lock_parent2,
8770 + * di_read_lock_parent3, di_write_lock_parent3,
8772 +#define AuReadLockFunc(name, lsc) \
8773 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8774 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8776 +#define AuWriteLockFunc(name, lsc) \
8777 +static inline void di_write_lock_##name(struct dentry *d) \
8778 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8780 +#define AuRWLockFuncs(name, lsc) \
8781 + AuReadLockFunc(name, lsc) \
8782 + AuWriteLockFunc(name, lsc)
8784 +AuRWLockFuncs(child, CHILD);
8785 +AuRWLockFuncs(child2, CHILD2);
8786 +AuRWLockFuncs(child3, CHILD3);
8787 +AuRWLockFuncs(parent, PARENT);
8788 +AuRWLockFuncs(parent2, PARENT2);
8789 +AuRWLockFuncs(parent3, PARENT3);
8791 +#undef AuReadLockFunc
8792 +#undef AuWriteLockFunc
8793 +#undef AuRWLockFuncs
8795 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8796 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8797 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8799 +/* ---------------------------------------------------------------------- */
8801 +/* todo: memory barrier? */
8802 +static inline unsigned int au_digen(struct dentry *d)
8804 + return atomic_read(&au_di(d)->di_generation);
8807 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8809 + hdentry->hd_dentry = NULL;
8812 +static inline void au_hdput(struct au_hdentry *hd)
8815 + dput(hd->hd_dentry);
8818 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8820 + DiMustAnyLock(dentry);
8821 + return au_di(dentry)->di_bstart;
8824 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8826 + DiMustAnyLock(dentry);
8827 + return au_di(dentry)->di_bend;
8830 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8832 + DiMustAnyLock(dentry);
8833 + return au_di(dentry)->di_bwh;
8836 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8838 + DiMustAnyLock(dentry);
8839 + return au_di(dentry)->di_bdiropq;
8842 +/* todo: hard/soft set? */
8843 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8845 + DiMustWriteLock(dentry);
8846 + au_di(dentry)->di_bstart = bindex;
8849 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8851 + DiMustWriteLock(dentry);
8852 + au_di(dentry)->di_bend = bindex;
8855 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8857 + DiMustWriteLock(dentry);
8858 + /* dbwh can be outside of bstart - bend range */
8859 + au_di(dentry)->di_bwh = bindex;
8862 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8864 + DiMustWriteLock(dentry);
8865 + au_di(dentry)->di_bdiropq = bindex;
8868 +/* ---------------------------------------------------------------------- */
8870 +#ifdef CONFIG_AUFS_HNOTIFY
8871 +static inline void au_digen_dec(struct dentry *d)
8873 + atomic_dec(&au_di(d)->di_generation);
8876 +static inline void au_hn_di_reinit(struct dentry *dentry)
8878 + dentry->d_fsdata = NULL;
8881 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8882 +#endif /* CONFIG_AUFS_HNOTIFY */
8884 +#endif /* __KERNEL__ */
8885 +#endif /* __AUFS_DENTRY_H__ */
8886 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8887 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8888 +++ linux/fs/aufs/dinfo.c 2016-02-28 11:26:32.569971135 +0100
8891 + * Copyright (C) 2005-2016 Junjiro R. Okajima
8893 + * This program, aufs is free software; you can redistribute it and/or modify
8894 + * it under the terms of the GNU General Public License as published by
8895 + * the Free Software Foundation; either version 2 of the License, or
8896 + * (at your option) any later version.
8898 + * This program is distributed in the hope that it will be useful,
8899 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8900 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8901 + * GNU General Public License for more details.
8903 + * You should have received a copy of the GNU General Public License
8904 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8908 + * dentry private data
8913 +void au_di_init_once(void *_dinfo)
8915 + struct au_dinfo *dinfo = _dinfo;
8916 + static struct lock_class_key aufs_di;
8918 + au_rw_init(&dinfo->di_rwsem);
8919 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8922 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8924 + struct au_dinfo *dinfo;
8927 + dinfo = au_cache_alloc_dinfo();
8928 + if (unlikely(!dinfo))
8931 + nbr = au_sbend(sb) + 1;
8934 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8935 + if (dinfo->di_hdentry) {
8936 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8937 + dinfo->di_bstart = -1;
8938 + dinfo->di_bend = -1;
8939 + dinfo->di_bwh = -1;
8940 + dinfo->di_bdiropq = -1;
8941 + dinfo->di_tmpfile = 0;
8942 + for (i = 0; i < nbr; i++)
8943 + dinfo->di_hdentry[i].hd_id = -1;
8947 + au_cache_free_dinfo(dinfo);
8954 +void au_di_free(struct au_dinfo *dinfo)
8956 + struct au_hdentry *p;
8957 + aufs_bindex_t bend, bindex;
8959 + /* dentry may not be revalidated */
8960 + bindex = dinfo->di_bstart;
8961 + if (bindex >= 0) {
8962 + bend = dinfo->di_bend;
8963 + p = dinfo->di_hdentry + bindex;
8964 + while (bindex++ <= bend)
8967 + kfree(dinfo->di_hdentry);
8968 + au_cache_free_dinfo(dinfo);
8971 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8973 + struct au_hdentry *p;
8976 + AuRwMustWriteLock(&a->di_rwsem);
8977 + AuRwMustWriteLock(&b->di_rwsem);
8979 +#define DiSwap(v, name) \
8981 + v = a->di_##name; \
8982 + a->di_##name = b->di_##name; \
8983 + b->di_##name = v; \
8986 + DiSwap(p, hdentry);
8987 + DiSwap(bi, bstart);
8990 + DiSwap(bi, bdiropq);
8996 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8998 + AuRwMustWriteLock(&dst->di_rwsem);
8999 + AuRwMustWriteLock(&src->di_rwsem);
9001 + dst->di_bstart = src->di_bstart;
9002 + dst->di_bend = src->di_bend;
9003 + dst->di_bwh = src->di_bwh;
9004 + dst->di_bdiropq = src->di_bdiropq;
9008 +int au_di_init(struct dentry *dentry)
9011 + struct super_block *sb;
9012 + struct au_dinfo *dinfo;
9015 + sb = dentry->d_sb;
9016 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9018 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9019 + /* smp_mb(); */ /* atomic_set */
9020 + dentry->d_fsdata = dinfo;
9027 +void au_di_fin(struct dentry *dentry)
9029 + struct au_dinfo *dinfo;
9031 + dinfo = au_di(dentry);
9032 + AuRwDestroy(&dinfo->di_rwsem);
9033 + au_di_free(dinfo);
9036 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
9039 + struct au_hdentry *hdp;
9041 + AuRwMustWriteLock(&dinfo->di_rwsem);
9044 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
9046 + sz = sizeof(*hdp);
9047 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
9049 + dinfo->di_hdentry = hdp;
9056 +/* ---------------------------------------------------------------------- */
9058 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9061 + case AuLsc_DI_CHILD:
9062 + ii_write_lock_child(inode);
9064 + case AuLsc_DI_CHILD2:
9065 + ii_write_lock_child2(inode);
9067 + case AuLsc_DI_CHILD3:
9068 + ii_write_lock_child3(inode);
9070 + case AuLsc_DI_PARENT:
9071 + ii_write_lock_parent(inode);
9073 + case AuLsc_DI_PARENT2:
9074 + ii_write_lock_parent2(inode);
9076 + case AuLsc_DI_PARENT3:
9077 + ii_write_lock_parent3(inode);
9084 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9087 + case AuLsc_DI_CHILD:
9088 + ii_read_lock_child(inode);
9090 + case AuLsc_DI_CHILD2:
9091 + ii_read_lock_child2(inode);
9093 + case AuLsc_DI_CHILD3:
9094 + ii_read_lock_child3(inode);
9096 + case AuLsc_DI_PARENT:
9097 + ii_read_lock_parent(inode);
9099 + case AuLsc_DI_PARENT2:
9100 + ii_read_lock_parent2(inode);
9102 + case AuLsc_DI_PARENT3:
9103 + ii_read_lock_parent3(inode);
9110 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9112 + struct inode *inode;
9114 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9115 + if (d_really_is_positive(d)) {
9116 + inode = d_inode(d);
9117 + if (au_ftest_lock(flags, IW))
9118 + do_ii_write_lock(inode, lsc);
9119 + else if (au_ftest_lock(flags, IR))
9120 + do_ii_read_lock(inode, lsc);
9124 +void di_read_unlock(struct dentry *d, int flags)
9126 + struct inode *inode;
9128 + if (d_really_is_positive(d)) {
9129 + inode = d_inode(d);
9130 + if (au_ftest_lock(flags, IW)) {
9131 + au_dbg_verify_dinode(d);
9132 + ii_write_unlock(inode);
9133 + } else if (au_ftest_lock(flags, IR)) {
9134 + au_dbg_verify_dinode(d);
9135 + ii_read_unlock(inode);
9138 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9141 +void di_downgrade_lock(struct dentry *d, int flags)
9143 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9144 + ii_downgrade_lock(d_inode(d));
9145 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9148 +void di_write_lock(struct dentry *d, unsigned int lsc)
9150 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9151 + if (d_really_is_positive(d))
9152 + do_ii_write_lock(d_inode(d), lsc);
9155 +void di_write_unlock(struct dentry *d)
9157 + au_dbg_verify_dinode(d);
9158 + if (d_really_is_positive(d))
9159 + ii_write_unlock(d_inode(d));
9160 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9163 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9165 + AuDebugOn(d1 == d2
9166 + || d_inode(d1) == d_inode(d2)
9167 + || d1->d_sb != d2->d_sb);
9169 + if (isdir && au_test_subdir(d1, d2)) {
9170 + di_write_lock_child(d1);
9171 + di_write_lock_child2(d2);
9173 + /* there should be no races */
9174 + di_write_lock_child(d2);
9175 + di_write_lock_child2(d1);
9179 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9181 + AuDebugOn(d1 == d2
9182 + || d_inode(d1) == d_inode(d2)
9183 + || d1->d_sb != d2->d_sb);
9185 + if (isdir && au_test_subdir(d1, d2)) {
9186 + di_write_lock_parent(d1);
9187 + di_write_lock_parent2(d2);
9189 + /* there should be no races */
9190 + di_write_lock_parent(d2);
9191 + di_write_lock_parent2(d1);
9195 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9197 + di_write_unlock(d1);
9198 + if (d_inode(d1) == d_inode(d2))
9199 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9201 + di_write_unlock(d2);
9204 +/* ---------------------------------------------------------------------- */
9206 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9210 + DiMustAnyLock(dentry);
9212 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
9214 + AuDebugOn(bindex < 0);
9215 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
9216 + AuDebugOn(d && au_dcount(d) <= 0);
9221 + * extended version of au_h_dptr().
9222 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9225 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9227 + struct dentry *h_dentry;
9228 + struct inode *inode, *h_inode;
9230 + AuDebugOn(d_really_is_negative(dentry));
9233 + if (au_dbstart(dentry) <= bindex
9234 + && bindex <= au_dbend(dentry))
9235 + h_dentry = au_h_dptr(dentry, bindex);
9236 + if (h_dentry && !au_d_linkable(h_dentry)) {
9238 + goto out; /* success */
9241 + inode = d_inode(dentry);
9242 + AuDebugOn(bindex < au_ibstart(inode));
9243 + AuDebugOn(au_ibend(inode) < bindex);
9244 + h_inode = au_h_iptr(inode, bindex);
9245 + h_dentry = d_find_alias(h_inode);
9247 + if (!IS_ERR(h_dentry)) {
9248 + if (!au_d_linkable(h_dentry))
9249 + goto out; /* success */
9255 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9256 + h_dentry = au_plink_lkup(inode, bindex);
9257 + AuDebugOn(!h_dentry);
9258 + if (!IS_ERR(h_dentry)) {
9259 + if (!au_d_hashed_positive(h_dentry))
9260 + goto out; /* success */
9267 + AuDbgDentry(h_dentry);
9271 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9273 + aufs_bindex_t bend, bwh;
9275 + bend = au_dbend(dentry);
9277 + bwh = au_dbwh(dentry);
9280 + if (0 < bwh && bwh < bend)
9286 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9288 + aufs_bindex_t bend, bopq;
9290 + bend = au_dbtail(dentry);
9292 + bopq = au_dbdiropq(dentry);
9293 + if (0 <= bopq && bopq < bend)
9299 +/* ---------------------------------------------------------------------- */
9301 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9302 + struct dentry *h_dentry)
9304 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
9305 + struct au_branch *br;
9307 + DiMustWriteLock(dentry);
9310 + hd->hd_dentry = h_dentry;
9312 + br = au_sbr(dentry->d_sb, bindex);
9313 + hd->hd_id = br->br_id;
9317 +int au_dbrange_test(struct dentry *dentry)
9320 + aufs_bindex_t bstart, bend;
9323 + bstart = au_dbstart(dentry);
9324 + bend = au_dbend(dentry);
9326 + AuDebugOn(bend < 0 && bstart > bend);
9329 + AuDebugOn(bend >= 0);
9335 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9340 + if (unlikely(au_digen(dentry) != sigen
9341 + || au_iigen_test(d_inode(dentry), sigen)))
9347 +void au_update_digen(struct dentry *dentry)
9349 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9350 + /* smp_mb(); */ /* atomic_set */
9353 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9355 + struct au_dinfo *dinfo;
9356 + struct dentry *h_d;
9357 + struct au_hdentry *hdp;
9359 + DiMustWriteLock(dentry);
9361 + dinfo = au_di(dentry);
9362 + if (!dinfo || dinfo->di_bstart < 0)
9365 + hdp = dinfo->di_hdentry;
9366 + if (do_put_zero) {
9367 + aufs_bindex_t bindex, bend;
9369 + bend = dinfo->di_bend;
9370 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
9371 + h_d = hdp[0 + bindex].hd_dentry;
9372 + if (h_d && d_is_negative(h_d))
9373 + au_set_h_dptr(dentry, bindex, NULL);
9377 + dinfo->di_bstart = -1;
9378 + while (++dinfo->di_bstart <= dinfo->di_bend)
9379 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
9381 + if (dinfo->di_bstart > dinfo->di_bend) {
9382 + dinfo->di_bstart = -1;
9383 + dinfo->di_bend = -1;
9388 + while (0 <= --dinfo->di_bend)
9389 + if (hdp[0 + dinfo->di_bend].hd_dentry)
9391 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
9394 +void au_update_dbstart(struct dentry *dentry)
9396 + aufs_bindex_t bindex, bend;
9397 + struct dentry *h_dentry;
9399 + bend = au_dbend(dentry);
9400 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
9401 + h_dentry = au_h_dptr(dentry, bindex);
9404 + if (d_is_positive(h_dentry)) {
9405 + au_set_dbstart(dentry, bindex);
9408 + au_set_h_dptr(dentry, bindex, NULL);
9412 +void au_update_dbend(struct dentry *dentry)
9414 + aufs_bindex_t bindex, bstart;
9415 + struct dentry *h_dentry;
9417 + bstart = au_dbstart(dentry);
9418 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
9419 + h_dentry = au_h_dptr(dentry, bindex);
9422 + if (d_is_positive(h_dentry)) {
9423 + au_set_dbend(dentry, bindex);
9426 + au_set_h_dptr(dentry, bindex, NULL);
9430 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9432 + aufs_bindex_t bindex, bend;
9434 + bend = au_dbend(dentry);
9435 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
9436 + if (au_h_dptr(dentry, bindex) == h_dentry)
9440 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9441 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9442 +++ linux/fs/aufs/dir.c 2016-02-28 11:26:32.569971135 +0100
9445 + * Copyright (C) 2005-2016 Junjiro R. Okajima
9447 + * This program, aufs is free software; you can redistribute it and/or modify
9448 + * it under the terms of the GNU General Public License as published by
9449 + * the Free Software Foundation; either version 2 of the License, or
9450 + * (at your option) any later version.
9452 + * This program is distributed in the hope that it will be useful,
9453 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9454 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9455 + * GNU General Public License for more details.
9457 + * You should have received a copy of the GNU General Public License
9458 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9462 + * directory operations
9465 +#include <linux/fs_stack.h>
9468 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9470 + unsigned int nlink;
9472 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9474 + nlink = dir->i_nlink;
9475 + nlink += h_dir->i_nlink - 2;
9476 + if (h_dir->i_nlink < 2)
9478 + smp_mb(); /* for i_nlink */
9479 + /* 0 can happen in revaliding */
9480 + set_nlink(dir, nlink);
9483 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9485 + unsigned int nlink;
9487 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9489 + nlink = dir->i_nlink;
9490 + nlink -= h_dir->i_nlink - 2;
9491 + if (h_dir->i_nlink < 2)
9493 + smp_mb(); /* for i_nlink */
9494 + /* nlink == 0 means the branch-fs is broken */
9495 + set_nlink(dir, nlink);
9498 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9501 + aufs_bindex_t bindex, bend;
9502 + struct file *h_file;
9503 + struct dentry *h_dentry;
9507 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9509 + bend = au_fbend_dir(file);
9510 + for (bindex = au_fbstart(file);
9511 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9513 + h_file = au_hf_dir(file, bindex);
9514 + if (h_file && file_inode(h_file))
9515 + sz += vfsub_f_size_read(h_file);
9518 + AuDebugOn(!dentry);
9519 + AuDebugOn(!d_is_dir(dentry));
9521 + bend = au_dbtaildir(dentry);
9522 + for (bindex = au_dbstart(dentry);
9523 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9525 + h_dentry = au_h_dptr(dentry, bindex);
9526 + if (h_dentry && d_is_positive(h_dentry))
9527 + sz += i_size_read(d_inode(h_dentry));
9530 + if (sz < KMALLOC_MAX_SIZE)
9531 + sz = roundup_pow_of_two(sz);
9532 + if (sz > KMALLOC_MAX_SIZE)
9533 + sz = KMALLOC_MAX_SIZE;
9534 + else if (sz < NAME_MAX) {
9535 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9536 + sz = AUFS_RDBLK_DEF;
9541 +struct au_dir_ts_arg {
9542 + struct dentry *dentry;
9543 + aufs_bindex_t brid;
9546 +static void au_do_dir_ts(void *arg)
9548 + struct au_dir_ts_arg *a = arg;
9549 + struct au_dtime dt;
9550 + struct path h_path;
9551 + struct inode *dir, *h_dir;
9552 + struct super_block *sb;
9553 + struct au_branch *br;
9554 + struct au_hinode *hdir;
9556 + aufs_bindex_t bstart, bindex;
9558 + sb = a->dentry->d_sb;
9559 + if (d_really_is_negative(a->dentry))
9561 + /* no dir->i_mutex lock */
9562 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
9564 + dir = d_inode(a->dentry);
9565 + bstart = au_ibstart(dir);
9566 + bindex = au_br_index(sb, a->brid);
9567 + if (bindex < bstart)
9570 + br = au_sbr(sb, bindex);
9571 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9572 + if (!h_path.dentry)
9574 + h_path.mnt = au_br_mnt(br);
9575 + au_dtime_store(&dt, a->dentry, &h_path);
9577 + br = au_sbr(sb, bstart);
9578 + if (!au_br_writable(br->br_perm))
9580 + h_path.dentry = au_h_dptr(a->dentry, bstart);
9581 + h_path.mnt = au_br_mnt(br);
9582 + err = vfsub_mnt_want_write(h_path.mnt);
9585 + hdir = au_hi(dir, bstart);
9586 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
9587 + h_dir = au_h_iptr(dir, bstart);
9588 + if (h_dir->i_nlink
9589 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9590 + dt.dt_h_path = h_path;
9591 + au_dtime_revert(&dt);
9593 + au_hn_imtx_unlock(hdir);
9594 + vfsub_mnt_drop_write(h_path.mnt);
9595 + au_cpup_attr_timesizes(dir);
9598 + aufs_read_unlock(a->dentry, AuLock_DW);
9601 + au_nwt_done(&au_sbi(sb)->si_nowait);
9605 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9607 + int perm, wkq_err;
9608 + aufs_bindex_t bstart;
9609 + struct au_dir_ts_arg *arg;
9610 + struct dentry *dentry;
9611 + struct super_block *sb;
9615 + dentry = d_find_any_alias(dir);
9616 + AuDebugOn(!dentry);
9617 + sb = dentry->d_sb;
9618 + bstart = au_ibstart(dir);
9619 + if (bstart == bindex) {
9620 + au_cpup_attr_timesizes(dir);
9624 + perm = au_sbr_perm(sb, bstart);
9625 + if (!au_br_writable(perm))
9628 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9632 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9633 + arg->brid = au_sbr_id(sb, bindex);
9634 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9635 + if (unlikely(wkq_err)) {
9636 + pr_err("wkq %d\n", wkq_err);
9645 +/* ---------------------------------------------------------------------- */
9647 +static int reopen_dir(struct file *file)
9650 + unsigned int flags;
9651 + aufs_bindex_t bindex, btail, bstart;
9652 + struct dentry *dentry, *h_dentry;
9653 + struct file *h_file;
9655 + /* open all lower dirs */
9656 + dentry = file->f_path.dentry;
9657 + bstart = au_dbstart(dentry);
9658 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9659 + au_set_h_fptr(file, bindex, NULL);
9660 + au_set_fbstart(file, bstart);
9662 + btail = au_dbtaildir(dentry);
9663 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9664 + au_set_h_fptr(file, bindex, NULL);
9665 + au_set_fbend_dir(file, btail);
9667 + flags = vfsub_file_flags(file);
9668 + for (bindex = bstart; bindex <= btail; bindex++) {
9669 + h_dentry = au_h_dptr(dentry, bindex);
9672 + h_file = au_hf_dir(file, bindex);
9676 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9677 + err = PTR_ERR(h_file);
9678 + if (IS_ERR(h_file))
9679 + goto out; /* close all? */
9680 + au_set_h_fptr(file, bindex, h_file);
9682 + au_update_figen(file);
9683 + /* todo: necessary? */
9684 + /* file->f_ra = h_file->f_ra; */
9691 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9694 + aufs_bindex_t bindex, btail;
9695 + struct dentry *dentry, *h_dentry;
9696 + struct vfsmount *mnt;
9698 + FiMustWriteLock(file);
9699 + AuDebugOn(h_file);
9702 + mnt = file->f_path.mnt;
9703 + dentry = file->f_path.dentry;
9704 + file->f_version = d_inode(dentry)->i_version;
9705 + bindex = au_dbstart(dentry);
9706 + au_set_fbstart(file, bindex);
9707 + btail = au_dbtaildir(dentry);
9708 + au_set_fbend_dir(file, btail);
9709 + for (; !err && bindex <= btail; bindex++) {
9710 + h_dentry = au_h_dptr(dentry, bindex);
9714 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
9715 + if (unlikely(err))
9717 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9718 + if (IS_ERR(h_file)) {
9719 + err = PTR_ERR(h_file);
9722 + au_set_h_fptr(file, bindex, h_file);
9724 + au_update_figen(file);
9725 + /* todo: necessary? */
9726 + /* file->f_ra = h_file->f_ra; */
9728 + return 0; /* success */
9731 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9732 + au_set_h_fptr(file, bindex, NULL);
9733 + au_set_fbstart(file, -1);
9734 + au_set_fbend_dir(file, -1);
9739 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9740 + struct file *file)
9743 + struct super_block *sb;
9744 + struct au_fidir *fidir;
9747 + sb = file->f_path.dentry->d_sb;
9748 + si_read_lock(sb, AuLock_FLUSH);
9749 + fidir = au_fidir_alloc(sb);
9751 + struct au_do_open_args args = {
9752 + .open = do_open_dir,
9755 + err = au_do_open(file, &args);
9756 + if (unlikely(err))
9759 + si_read_unlock(sb);
9763 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9764 + struct file *file)
9766 + struct au_vdir *vdir_cache;
9767 + struct au_finfo *finfo;
9768 + struct au_fidir *fidir;
9769 + aufs_bindex_t bindex, bend;
9771 + finfo = au_fi(file);
9772 + fidir = finfo->fi_hdir;
9774 + au_sphl_del(&finfo->fi_hlist,
9775 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9776 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9778 + au_vdir_free(vdir_cache);
9780 + bindex = finfo->fi_btop;
9781 + if (bindex >= 0) {
9783 + * calls fput() instead of filp_close(),
9784 + * since no dnotify or lock for the lower file.
9786 + bend = fidir->fd_bbot;
9787 + for (; bindex <= bend; bindex++)
9788 + au_set_h_fptr(file, bindex, NULL);
9791 + finfo->fi_hdir = NULL;
9793 + au_finfo_fin(file);
9797 +/* ---------------------------------------------------------------------- */
9799 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9802 + aufs_bindex_t bindex, bend;
9803 + struct file *h_file;
9806 + bend = au_fbend_dir(file);
9807 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9808 + h_file = au_hf_dir(file, bindex);
9810 + err = vfsub_flush(h_file, id);
9815 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9817 + return au_do_flush(file, id, au_do_flush_dir);
9820 +/* ---------------------------------------------------------------------- */
9822 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9825 + aufs_bindex_t bend, bindex;
9826 + struct inode *inode;
9827 + struct super_block *sb;
9830 + sb = dentry->d_sb;
9831 + inode = d_inode(dentry);
9833 + bend = au_dbend(dentry);
9834 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9835 + struct path h_path;
9837 + if (au_test_ro(sb, bindex, inode))
9839 + h_path.dentry = au_h_dptr(dentry, bindex);
9840 + if (!h_path.dentry)
9843 + h_path.mnt = au_sbr_mnt(sb, bindex);
9844 + err = vfsub_fsync(NULL, &h_path, datasync);
9850 +static int au_do_fsync_dir(struct file *file, int datasync)
9853 + aufs_bindex_t bend, bindex;
9854 + struct file *h_file;
9855 + struct super_block *sb;
9856 + struct inode *inode;
9858 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9859 + if (unlikely(err))
9862 + inode = file_inode(file);
9864 + bend = au_fbend_dir(file);
9865 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9866 + h_file = au_hf_dir(file, bindex);
9867 + if (!h_file || au_test_ro(sb, bindex, inode))
9870 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9878 + * @file may be NULL
9880 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9884 + struct dentry *dentry;
9885 + struct inode *inode;
9886 + struct super_block *sb;
9887 + struct mutex *mtx;
9890 + dentry = file->f_path.dentry;
9891 + inode = d_inode(dentry);
9892 + mtx = &inode->i_mutex;
9894 + sb = dentry->d_sb;
9895 + si_noflush_read_lock(sb);
9897 + err = au_do_fsync_dir(file, datasync);
9899 + di_write_lock_child(dentry);
9900 + err = au_do_fsync_dir_no_file(dentry, datasync);
9902 + au_cpup_attr_timesizes(inode);
9903 + di_write_unlock(dentry);
9905 + fi_write_unlock(file);
9907 + si_read_unlock(sb);
9908 + mutex_unlock(mtx);
9912 +/* ---------------------------------------------------------------------- */
9914 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9917 + struct dentry *dentry;
9918 + struct inode *inode, *h_inode;
9919 + struct super_block *sb;
9921 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9923 + dentry = file->f_path.dentry;
9924 + inode = d_inode(dentry);
9927 + sb = dentry->d_sb;
9928 + si_read_lock(sb, AuLock_FLUSH);
9929 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9930 + if (unlikely(err))
9932 + err = au_alive_dir(dentry);
9934 + err = au_vdir_init(file);
9935 + di_downgrade_lock(dentry, AuLock_IR);
9936 + if (unlikely(err))
9939 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9940 + if (!au_test_nfsd()) {
9941 + err = au_vdir_fill_de(file, ctx);
9942 + fsstack_copy_attr_atime(inode, h_inode);
9945 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9946 + * encode_fh() and others.
9948 + atomic_inc(&h_inode->i_count);
9949 + di_read_unlock(dentry, AuLock_IR);
9950 + si_read_unlock(sb);
9951 + err = au_vdir_fill_de(file, ctx);
9952 + fsstack_copy_attr_atime(inode, h_inode);
9953 + fi_write_unlock(file);
9961 + di_read_unlock(dentry, AuLock_IR);
9962 + fi_write_unlock(file);
9964 + si_read_unlock(sb);
9968 +/* ---------------------------------------------------------------------- */
9970 +#define AuTestEmpty_WHONLY 1
9971 +#define AuTestEmpty_CALLED (1 << 1)
9972 +#define AuTestEmpty_SHWH (1 << 2)
9973 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9974 +#define au_fset_testempty(flags, name) \
9975 + do { (flags) |= AuTestEmpty_##name; } while (0)
9976 +#define au_fclr_testempty(flags, name) \
9977 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9979 +#ifndef CONFIG_AUFS_SHWH
9980 +#undef AuTestEmpty_SHWH
9981 +#define AuTestEmpty_SHWH 0
9984 +struct test_empty_arg {
9985 + struct dir_context ctx;
9986 + struct au_nhash *whlist;
9987 + unsigned int flags;
9989 + aufs_bindex_t bindex;
9992 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9993 + int namelen, loff_t offset __maybe_unused, u64 ino,
9994 + unsigned int d_type)
9996 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9998 + char *name = (void *)__name;
10001 + au_fset_testempty(arg->flags, CALLED);
10003 + if (name[0] == '.'
10004 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10005 + goto out; /* success */
10007 + if (namelen <= AUFS_WH_PFX_LEN
10008 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10009 + if (au_ftest_testempty(arg->flags, WHONLY)
10010 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10011 + arg->err = -ENOTEMPTY;
10015 + name += AUFS_WH_PFX_LEN;
10016 + namelen -= AUFS_WH_PFX_LEN;
10017 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10018 + arg->err = au_nhash_append_wh
10019 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10020 + au_ftest_testempty(arg->flags, SHWH));
10024 + AuTraceErr(arg->err);
10028 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10031 + struct file *h_file;
10033 + h_file = au_h_open(dentry, arg->bindex,
10034 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10035 + /*file*/NULL, /*force_wr*/0);
10036 + err = PTR_ERR(h_file);
10037 + if (IS_ERR(h_file))
10041 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10042 + && !file_inode(h_file)->i_nlink)
10047 + au_fclr_testempty(arg->flags, CALLED);
10049 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10052 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10056 + au_sbr_put(dentry->d_sb, arg->bindex);
10061 +struct do_test_empty_args {
10063 + struct dentry *dentry;
10064 + struct test_empty_arg *arg;
10067 +static void call_do_test_empty(void *args)
10069 + struct do_test_empty_args *a = args;
10070 + *a->errp = do_test_empty(a->dentry, a->arg);
10073 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10075 + int err, wkq_err;
10076 + struct dentry *h_dentry;
10077 + struct inode *h_inode;
10079 + h_dentry = au_h_dptr(dentry, arg->bindex);
10080 + h_inode = d_inode(h_dentry);
10081 + /* todo: i_mode changes anytime? */
10082 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
10083 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10084 + mutex_unlock(&h_inode->i_mutex);
10086 + err = do_test_empty(dentry, arg);
10088 + struct do_test_empty_args args = {
10090 + .dentry = dentry,
10093 + unsigned int flags = arg->flags;
10095 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10096 + if (unlikely(wkq_err))
10098 + arg->flags = flags;
10104 +int au_test_empty_lower(struct dentry *dentry)
10107 + unsigned int rdhash;
10108 + aufs_bindex_t bindex, bstart, btail;
10109 + struct au_nhash whlist;
10110 + struct test_empty_arg arg = {
10112 + .actor = test_empty_cb
10115 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10117 + SiMustAnyLock(dentry->d_sb);
10119 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10121 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10122 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10123 + if (unlikely(err))
10127 + arg.whlist = &whlist;
10128 + bstart = au_dbstart(dentry);
10129 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10130 + au_fset_testempty(arg.flags, SHWH);
10131 + test_empty = do_test_empty;
10132 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10133 + test_empty = sio_test_empty;
10134 + arg.bindex = bstart;
10135 + err = test_empty(dentry, &arg);
10136 + if (unlikely(err))
10139 + au_fset_testempty(arg.flags, WHONLY);
10140 + btail = au_dbtaildir(dentry);
10141 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
10142 + struct dentry *h_dentry;
10144 + h_dentry = au_h_dptr(dentry, bindex);
10145 + if (h_dentry && d_is_positive(h_dentry)) {
10146 + arg.bindex = bindex;
10147 + err = test_empty(dentry, &arg);
10152 + au_nhash_wh_free(&whlist);
10157 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10160 + struct test_empty_arg arg = {
10162 + .actor = test_empty_cb
10165 + aufs_bindex_t bindex, btail;
10168 + arg.whlist = whlist;
10169 + arg.flags = AuTestEmpty_WHONLY;
10170 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10171 + au_fset_testempty(arg.flags, SHWH);
10172 + btail = au_dbtaildir(dentry);
10173 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
10174 + struct dentry *h_dentry;
10176 + h_dentry = au_h_dptr(dentry, bindex);
10177 + if (h_dentry && d_is_positive(h_dentry)) {
10178 + arg.bindex = bindex;
10179 + err = sio_test_empty(dentry, &arg);
10186 +/* ---------------------------------------------------------------------- */
10188 +const struct file_operations aufs_dir_fop = {
10189 + .owner = THIS_MODULE,
10190 + .llseek = default_llseek,
10191 + .read = generic_read_dir,
10192 + .iterate = aufs_iterate,
10193 + .unlocked_ioctl = aufs_ioctl_dir,
10194 +#ifdef CONFIG_COMPAT
10195 + .compat_ioctl = aufs_compat_ioctl_dir,
10197 + .open = aufs_open_dir,
10198 + .release = aufs_release_dir,
10199 + .flush = aufs_flush_dir,
10200 + .fsync = aufs_fsync_dir
10202 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10203 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10204 +++ linux/fs/aufs/dir.h 2016-02-28 11:26:32.569971135 +0100
10207 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10209 + * This program, aufs is free software; you can redistribute it and/or modify
10210 + * it under the terms of the GNU General Public License as published by
10211 + * the Free Software Foundation; either version 2 of the License, or
10212 + * (at your option) any later version.
10214 + * This program is distributed in the hope that it will be useful,
10215 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10216 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10217 + * GNU General Public License for more details.
10219 + * You should have received a copy of the GNU General Public License
10220 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10224 + * directory operations
10227 +#ifndef __AUFS_DIR_H__
10228 +#define __AUFS_DIR_H__
10232 +#include <linux/fs.h>
10234 +/* ---------------------------------------------------------------------- */
10236 +/* need to be faster and smaller */
10239 + unsigned int nh_num;
10240 + struct hlist_head *nh_head;
10243 +struct au_vdir_destr {
10244 + unsigned char len;
10245 + unsigned char name[0];
10248 +struct au_vdir_dehstr {
10249 + struct hlist_node hash;
10250 + struct au_vdir_destr *str;
10251 +} ____cacheline_aligned_in_smp;
10253 +struct au_vdir_de {
10255 + unsigned char de_type;
10256 + /* caution: packed */
10257 + struct au_vdir_destr de_str;
10260 +struct au_vdir_wh {
10261 + struct hlist_node wh_hash;
10262 +#ifdef CONFIG_AUFS_SHWH
10264 + aufs_bindex_t wh_bindex;
10265 + unsigned char wh_type;
10267 + aufs_bindex_t wh_bindex;
10269 + /* caution: packed */
10270 + struct au_vdir_destr wh_str;
10273 +union au_vdir_deblk_p {
10274 + unsigned char *deblk;
10275 + struct au_vdir_de *de;
10279 + unsigned char **vd_deblk;
10280 + unsigned long vd_nblk;
10282 + unsigned long ul;
10283 + union au_vdir_deblk_p p;
10286 + unsigned long vd_version;
10287 + unsigned int vd_deblk_sz;
10288 + unsigned long vd_jiffy;
10289 +} ____cacheline_aligned_in_smp;
10291 +/* ---------------------------------------------------------------------- */
10294 +extern const struct file_operations aufs_dir_fop;
10295 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10296 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10297 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10298 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10299 +int au_test_empty_lower(struct dentry *dentry);
10300 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10303 +unsigned int au_rdhash_est(loff_t sz);
10304 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10305 +void au_nhash_wh_free(struct au_nhash *whlist);
10306 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10308 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10309 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10310 + unsigned int d_type, aufs_bindex_t bindex,
10311 + unsigned char shwh);
10312 +void au_vdir_free(struct au_vdir *vdir);
10313 +int au_vdir_init(struct file *file);
10314 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10317 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10319 +#ifdef CONFIG_AUFS_RDU
10321 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10322 +#ifdef CONFIG_COMPAT
10323 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10324 + unsigned long arg);
10327 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10328 + unsigned int cmd, unsigned long arg)
10329 +#ifdef CONFIG_COMPAT
10330 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10331 + unsigned int cmd, unsigned long arg)
10335 +#endif /* __KERNEL__ */
10336 +#endif /* __AUFS_DIR_H__ */
10337 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10338 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10339 +++ linux/fs/aufs/dynop.c 2016-02-28 11:26:32.569971135 +0100
10342 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10344 + * This program, aufs is free software; you can redistribute it and/or modify
10345 + * it under the terms of the GNU General Public License as published by
10346 + * the Free Software Foundation; either version 2 of the License, or
10347 + * (at your option) any later version.
10349 + * This program is distributed in the hope that it will be useful,
10350 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10351 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10352 + * GNU General Public License for more details.
10354 + * You should have received a copy of the GNU General Public License
10355 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10359 + * dynamically customizable operations for regular files
10364 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10367 + * How large will these lists be?
10368 + * Usually just a few elements, 20-30 at most for each, I guess.
10370 +static struct au_splhead dynop[AuDyLast];
10372 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
10374 + struct au_dykey *key, *tmp;
10375 + struct list_head *head;
10378 + head = &spl->head;
10380 + list_for_each_entry_rcu(tmp, head, dk_list)
10381 + if (tmp->dk_op.dy_hop == h_op) {
10383 + kref_get(&key->dk_kref);
10386 + rcu_read_unlock();
10391 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10393 + struct au_dykey **k, *found;
10394 + const void *h_op = key->dk_op.dy_hop;
10398 + k = br->br_dykey;
10399 + for (i = 0; i < AuBrDynOp; i++)
10401 + if (k[i]->dk_op.dy_hop == h_op) {
10408 + spin_lock(&br->br_dykey_lock);
10409 + for (; i < AuBrDynOp; i++)
10411 + if (k[i]->dk_op.dy_hop == h_op) {
10419 + spin_unlock(&br->br_dykey_lock);
10420 + BUG_ON(i == AuBrDynOp); /* expand the array */
10426 +/* kref_get() if @key is already added */
10427 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
10429 + struct au_dykey *tmp, *found;
10430 + struct list_head *head;
10431 + const void *h_op = key->dk_op.dy_hop;
10434 + head = &spl->head;
10435 + spin_lock(&spl->spin);
10436 + list_for_each_entry(tmp, head, dk_list)
10437 + if (tmp->dk_op.dy_hop == h_op) {
10438 + kref_get(&tmp->dk_kref);
10443 + list_add_rcu(&key->dk_list, head);
10444 + spin_unlock(&spl->spin);
10451 +static void dy_free_rcu(struct rcu_head *rcu)
10453 + struct au_dykey *key;
10455 + key = container_of(rcu, struct au_dykey, dk_rcu);
10460 +static void dy_free(struct kref *kref)
10462 + struct au_dykey *key;
10463 + struct au_splhead *spl;
10465 + key = container_of(kref, struct au_dykey, dk_kref);
10466 + spl = dynop + key->dk_op.dy_type;
10467 + au_spl_del_rcu(&key->dk_list, spl);
10468 + call_rcu(&key->dk_rcu, dy_free_rcu);
10471 +void au_dy_put(struct au_dykey *key)
10473 + kref_put(&key->dk_kref, dy_free);
10476 +/* ---------------------------------------------------------------------- */
10478 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10480 +#ifdef CONFIG_AUFS_DEBUG
10481 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10482 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10484 +#define DyDbgDeclare(cnt) do {} while (0)
10485 +#define DyDbgInc(cnt) do {} while (0)
10488 +#define DySet(func, dst, src, h_op, h_sb) do { \
10490 + if (h_op->func) { \
10492 + dst.func = src.func; \
10494 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10498 +#define DySetForce(func, dst, src) do { \
10499 + AuDebugOn(!src.func); \
10501 + dst.func = src.func; \
10504 +#define DySetAop(func) \
10505 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10506 +#define DySetAopForce(func) \
10507 + DySetForce(func, dyaop->da_op, aufs_aop)
10509 +static void dy_aop(struct au_dykey *key, const void *h_op,
10510 + struct super_block *h_sb __maybe_unused)
10512 + struct au_dyaop *dyaop = (void *)key;
10513 + const struct address_space_operations *h_aop = h_op;
10514 + DyDbgDeclare(cnt);
10516 + AuDbg("%s\n", au_sbtype(h_sb));
10518 + DySetAop(writepage);
10519 + DySetAopForce(readpage); /* force */
10520 + DySetAop(writepages);
10521 + DySetAop(set_page_dirty);
10522 + DySetAop(readpages);
10523 + DySetAop(write_begin);
10524 + DySetAop(write_end);
10526 + DySetAop(invalidatepage);
10527 + DySetAop(releasepage);
10528 + DySetAop(freepage);
10529 + /* this one will be changed according to an aufs mount option */
10530 + DySetAop(direct_IO);
10531 + DySetAop(migratepage);
10532 + DySetAop(launder_page);
10533 + DySetAop(is_partially_uptodate);
10534 + DySetAop(is_dirty_writeback);
10535 + DySetAop(error_remove_page);
10536 + DySetAop(swap_activate);
10537 + DySetAop(swap_deactivate);
10539 + DyDbgSize(cnt, *h_aop);
10542 +/* ---------------------------------------------------------------------- */
10544 +static void dy_bug(struct kref *kref)
10549 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10551 + struct au_dykey *key, *old;
10552 + struct au_splhead *spl;
10555 + void (*set)(struct au_dykey *key, const void *h_op,
10556 + struct super_block *h_sb __maybe_unused);
10558 + static const struct op a[] = {
10560 + .sz = sizeof(struct au_dyaop),
10564 + const struct op *p;
10566 + spl = dynop + op->dy_type;
10567 + key = dy_gfind_get(spl, op->dy_hop);
10569 + goto out_add; /* success */
10571 + p = a + op->dy_type;
10572 + key = kzalloc(p->sz, GFP_NOFS);
10573 + if (unlikely(!key)) {
10574 + key = ERR_PTR(-ENOMEM);
10578 + key->dk_op.dy_hop = op->dy_hop;
10579 + kref_init(&key->dk_kref);
10580 + p->set(key, op->dy_hop, au_br_sb(br));
10581 + old = dy_gadd(spl, key);
10588 + old = dy_bradd(br, key);
10590 + /* its ref-count should never be zero here */
10591 + kref_put(&key->dk_kref, dy_bug);
10596 +/* ---------------------------------------------------------------------- */
10598 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10599 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10600 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10601 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10602 + * See the aufs manual in detail.
10604 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10607 + dyaop->da_op.direct_IO = NULL;
10609 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10612 +static struct au_dyaop *dy_aget(struct au_branch *br,
10613 + const struct address_space_operations *h_aop,
10616 + struct au_dyaop *dyaop;
10617 + struct au_dynop op;
10619 + op.dy_type = AuDy_AOP;
10620 + op.dy_haop = h_aop;
10621 + dyaop = (void *)dy_get(&op, br);
10622 + if (IS_ERR(dyaop))
10624 + dy_adx(dyaop, do_dx);
10630 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10631 + struct inode *h_inode)
10634 + struct super_block *sb;
10635 + struct au_branch *br;
10636 + struct au_dyaop *dyaop;
10638 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10639 + IiMustWriteLock(inode);
10641 + sb = inode->i_sb;
10642 + br = au_sbr(sb, bindex);
10643 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10644 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10645 + err = PTR_ERR(dyaop);
10646 + if (IS_ERR(dyaop))
10647 + /* unnecessary to call dy_fput() */
10651 + inode->i_mapping->a_ops = &dyaop->da_op;
10658 + * Is it safe to replace a_ops during the inode/file is in operation?
10659 + * Yes, I hope so.
10661 +int au_dy_irefresh(struct inode *inode)
10664 + aufs_bindex_t bstart;
10665 + struct inode *h_inode;
10668 + if (S_ISREG(inode->i_mode)) {
10669 + bstart = au_ibstart(inode);
10670 + h_inode = au_h_iptr(inode, bstart);
10671 + err = au_dy_iaop(inode, bstart, h_inode);
10676 +void au_dy_arefresh(int do_dx)
10678 + struct au_splhead *spl;
10679 + struct list_head *head;
10680 + struct au_dykey *key;
10682 + spl = dynop + AuDy_AOP;
10683 + head = &spl->head;
10684 + spin_lock(&spl->spin);
10685 + list_for_each_entry(key, head, dk_list)
10686 + dy_adx((void *)key, do_dx);
10687 + spin_unlock(&spl->spin);
10690 +/* ---------------------------------------------------------------------- */
10692 +void __init au_dy_init(void)
10696 + /* make sure that 'struct au_dykey *' can be any type */
10697 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10699 + for (i = 0; i < AuDyLast; i++)
10700 + au_spl_init(dynop + i);
10703 +void au_dy_fin(void)
10707 + for (i = 0; i < AuDyLast; i++)
10708 + WARN_ON(!list_empty(&dynop[i].head));
10710 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10711 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10712 +++ linux/fs/aufs/dynop.h 2016-02-28 11:26:32.569971135 +0100
10715 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10717 + * This program, aufs is free software; you can redistribute it and/or modify
10718 + * it under the terms of the GNU General Public License as published by
10719 + * the Free Software Foundation; either version 2 of the License, or
10720 + * (at your option) any later version.
10722 + * This program is distributed in the hope that it will be useful,
10723 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10724 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10725 + * GNU General Public License for more details.
10727 + * You should have received a copy of the GNU General Public License
10728 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10732 + * dynamically customizable operations (for regular files only)
10735 +#ifndef __AUFS_DYNOP_H__
10736 +#define __AUFS_DYNOP_H__
10740 +#include <linux/fs.h>
10741 +#include <linux/kref.h>
10743 +enum {AuDy_AOP, AuDyLast};
10748 + const void *dy_hop;
10749 + const struct address_space_operations *dy_haop;
10755 + struct list_head dk_list;
10756 + struct rcu_head dk_rcu;
10758 + struct au_dynop dk_op;
10761 + * during I am in the branch local array, kref is gotten. when the
10762 + * branch is removed, kref is put.
10764 + struct kref dk_kref;
10767 +/* stop unioning since their sizes are very different from each other */
10769 + struct au_dykey da_key;
10770 + struct address_space_operations da_op; /* not const */
10773 +/* ---------------------------------------------------------------------- */
10777 +void au_dy_put(struct au_dykey *key);
10778 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10779 + struct inode *h_inode);
10780 +int au_dy_irefresh(struct inode *inode);
10781 +void au_dy_arefresh(int do_dio);
10783 +void __init au_dy_init(void);
10784 +void au_dy_fin(void);
10786 +#endif /* __KERNEL__ */
10787 +#endif /* __AUFS_DYNOP_H__ */
10788 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10789 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10790 +++ linux/fs/aufs/export.c 2016-02-28 11:26:32.569971135 +0100
10793 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10795 + * This program, aufs is free software; you can redistribute it and/or modify
10796 + * it under the terms of the GNU General Public License as published by
10797 + * the Free Software Foundation; either version 2 of the License, or
10798 + * (at your option) any later version.
10800 + * This program is distributed in the hope that it will be useful,
10801 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10802 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10803 + * GNU General Public License for more details.
10805 + * You should have received a copy of the GNU General Public License
10806 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10813 +#include <linux/exportfs.h>
10814 +#include <linux/fs_struct.h>
10815 +#include <linux/namei.h>
10816 +#include <linux/nsproxy.h>
10817 +#include <linux/random.h>
10818 +#include <linux/writeback.h>
10819 +#include "../fs/mount.h"
10823 +#ifdef CONFIG_AUFS_INO_T_64
10831 +static ino_t decode_ino(__u32 *a)
10835 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10837 +#ifdef CONFIG_AUFS_INO_T_64
10843 +static void encode_ino(__u32 *a, ino_t ino)
10849 +#ifdef CONFIG_AUFS_INO_T_64
10854 +/* NFS file handle */
10858 +#ifdef CONFIG_AUFS_INO_T_64
10859 + /* support 64bit inode number */
10872 + Fh_ino = Fh_ino1,
10873 + Fh_dir_ino = Fh_dir_ino1
10876 +static int au_test_anon(struct dentry *dentry)
10878 + /* note: read d_flags without d_lock */
10879 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10882 +int au_test_nfsd(void)
10885 + struct task_struct *tsk = current;
10886 + char comm[sizeof(tsk->comm)];
10889 + if (tsk->flags & PF_KTHREAD) {
10890 + get_task_comm(comm, tsk);
10891 + ret = !strcmp(comm, "nfsd");
10897 +/* ---------------------------------------------------------------------- */
10898 +/* inode generation external table */
10900 +void au_xigen_inc(struct inode *inode)
10905 + struct super_block *sb;
10906 + struct au_sbinfo *sbinfo;
10908 + sb = inode->i_sb;
10909 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10911 + sbinfo = au_sbi(sb);
10912 + pos = inode->i_ino;
10913 + pos *= sizeof(igen);
10914 + igen = inode->i_generation + 1;
10915 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10916 + sizeof(igen), &pos);
10917 + if (sz == sizeof(igen))
10918 + return; /* success */
10920 + if (unlikely(sz >= 0))
10921 + AuIOErr("xigen error (%zd)\n", sz);
10924 +int au_xigen_new(struct inode *inode)
10929 + struct super_block *sb;
10930 + struct au_sbinfo *sbinfo;
10931 + struct file *file;
10934 + /* todo: dirty, at mount time */
10935 + if (inode->i_ino == AUFS_ROOT_INO)
10937 + sb = inode->i_sb;
10938 + SiMustAnyLock(sb);
10939 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10943 + pos = inode->i_ino;
10944 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10945 + AuIOErr1("too large i%lld\n", pos);
10948 + pos *= sizeof(inode->i_generation);
10951 + sbinfo = au_sbi(sb);
10952 + file = sbinfo->si_xigen;
10955 + if (vfsub_f_size_read(file)
10956 + < pos + sizeof(inode->i_generation)) {
10957 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10958 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10959 + sizeof(inode->i_generation), &pos);
10961 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10962 + sizeof(inode->i_generation), &pos);
10963 + if (sz == sizeof(inode->i_generation))
10964 + goto out; /* success */
10967 + if (unlikely(sz >= 0)) {
10969 + AuIOErr("xigen error (%zd)\n", sz);
10976 +int au_xigen_set(struct super_block *sb, struct file *base)
10979 + struct au_sbinfo *sbinfo;
10980 + struct file *file;
10982 + SiMustWriteLock(sb);
10984 + sbinfo = au_sbi(sb);
10985 + file = au_xino_create2(base, sbinfo->si_xigen);
10986 + err = PTR_ERR(file);
10987 + if (IS_ERR(file))
10990 + if (sbinfo->si_xigen)
10991 + fput(sbinfo->si_xigen);
10992 + sbinfo->si_xigen = file;
10998 +void au_xigen_clr(struct super_block *sb)
11000 + struct au_sbinfo *sbinfo;
11002 + SiMustWriteLock(sb);
11004 + sbinfo = au_sbi(sb);
11005 + if (sbinfo->si_xigen) {
11006 + fput(sbinfo->si_xigen);
11007 + sbinfo->si_xigen = NULL;
11011 +/* ---------------------------------------------------------------------- */
11013 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
11016 + struct dentry *dentry, *d;
11017 + struct inode *inode;
11018 + unsigned int sigen;
11021 + inode = ilookup(sb, ino);
11025 + dentry = ERR_PTR(-ESTALE);
11026 + sigen = au_sigen(sb);
11027 + if (unlikely(is_bad_inode(inode)
11028 + || IS_DEADDIR(inode)
11029 + || sigen != au_iigen(inode, NULL)))
11033 + if (!dir_ino || S_ISDIR(inode->i_mode))
11034 + dentry = d_find_alias(inode);
11036 + spin_lock(&inode->i_lock);
11037 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
11038 + spin_lock(&d->d_lock);
11039 + if (!au_test_anon(d)
11040 + && d_inode(d->d_parent)->i_ino == dir_ino) {
11041 + dentry = dget_dlock(d);
11042 + spin_unlock(&d->d_lock);
11045 + spin_unlock(&d->d_lock);
11047 + spin_unlock(&inode->i_lock);
11049 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
11050 + /* need to refresh */
11058 + AuTraceErrPtr(dentry);
11062 +/* ---------------------------------------------------------------------- */
11064 +/* todo: dirty? */
11065 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
11067 +struct au_compare_mnt_args {
11069 + struct super_block *sb;
11072 + struct vfsmount *mnt;
11075 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
11077 + struct au_compare_mnt_args *a = arg;
11079 + if (mnt->mnt_sb != a->sb)
11081 + a->mnt = mntget(mnt);
11085 +static struct vfsmount *au_mnt_get(struct super_block *sb)
11088 + struct path root;
11089 + struct au_compare_mnt_args args = {
11093 + get_fs_root(current->fs, &root);
11095 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
11096 + rcu_read_unlock();
11099 + AuDebugOn(!args.mnt);
11103 +struct au_nfsd_si_lock {
11104 + unsigned int sigen;
11105 + aufs_bindex_t bindex, br_id;
11106 + unsigned char force_lock;
11109 +static int si_nfsd_read_lock(struct super_block *sb,
11110 + struct au_nfsd_si_lock *nsi_lock)
11113 + aufs_bindex_t bindex;
11115 + si_read_lock(sb, AuLock_FLUSH);
11117 + /* branch id may be wrapped around */
11119 + bindex = au_br_index(sb, nsi_lock->br_id);
11120 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11121 + goto out; /* success */
11125 + if (!nsi_lock->force_lock)
11126 + si_read_unlock(sb);
11129 + nsi_lock->bindex = bindex;
11133 +struct find_name_by_ino {
11134 + struct dir_context ctx;
11135 + int called, found;
11142 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11143 + loff_t offset, u64 ino, unsigned int d_type)
11145 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11149 + if (a->ino != ino)
11152 + memcpy(a->name, name, namelen);
11153 + a->namelen = namelen;
11158 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11159 + struct au_nfsd_si_lock *nsi_lock)
11161 + struct dentry *dentry, *parent;
11162 + struct file *file;
11163 + struct inode *dir;
11164 + struct find_name_by_ino arg = {
11166 + .actor = find_name_by_ino
11171 + parent = path->dentry;
11173 + si_read_unlock(parent->d_sb);
11174 + file = vfsub_dentry_open(path, au_dir_roflags);
11175 + dentry = (void *)file;
11176 + if (IS_ERR(file))
11179 + dentry = ERR_PTR(-ENOMEM);
11180 + arg.name = (void *)__get_free_page(GFP_NOFS);
11181 + if (unlikely(!arg.name))
11188 + err = vfsub_iterate_dir(file, &arg.ctx);
11189 + } while (!err && !arg.found && arg.called);
11190 + dentry = ERR_PTR(err);
11191 + if (unlikely(err))
11193 + /* instead of ENOENT */
11194 + dentry = ERR_PTR(-ESTALE);
11198 + /* do not call vfsub_lkup_one() */
11199 + dir = d_inode(parent);
11200 + mutex_lock(&dir->i_mutex);
11201 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
11202 + mutex_unlock(&dir->i_mutex);
11203 + AuTraceErrPtr(dentry);
11204 + if (IS_ERR(dentry))
11206 + AuDebugOn(au_test_anon(dentry));
11207 + if (unlikely(d_really_is_negative(dentry))) {
11209 + dentry = ERR_PTR(-ENOENT);
11213 + free_page((unsigned long)arg.name);
11217 + if (unlikely(nsi_lock
11218 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11219 + if (!IS_ERR(dentry)) {
11221 + dentry = ERR_PTR(-ESTALE);
11223 + AuTraceErrPtr(dentry);
11227 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11229 + struct au_nfsd_si_lock *nsi_lock)
11231 + struct dentry *dentry;
11232 + struct path path;
11234 + if (dir_ino != AUFS_ROOT_INO) {
11235 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11236 + dentry = path.dentry;
11237 + if (!path.dentry || IS_ERR(path.dentry))
11239 + AuDebugOn(au_test_anon(path.dentry));
11241 + path.dentry = dget(sb->s_root);
11243 + path.mnt = au_mnt_get(sb);
11244 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11248 + AuTraceErrPtr(dentry);
11252 +/* ---------------------------------------------------------------------- */
11254 +static int h_acceptable(void *expv, struct dentry *dentry)
11259 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11260 + char *buf, int len, struct super_block *sb)
11264 + struct path path;
11266 + p = d_path(h_rootpath, buf, len);
11271 + path.mnt = h_rootpath->mnt;
11272 + path.dentry = h_parent;
11273 + p = d_path(&path, buf, len);
11279 + path.mnt = au_mnt_get(sb);
11280 + path.dentry = sb->s_root;
11281 + p = d_path(&path, buf, len - strlen(p));
11282 + mntput(path.mnt);
11286 + p[strlen(p)] = '/';
11289 + AuTraceErrPtr(p);
11294 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11295 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11297 + struct dentry *dentry, *h_parent, *root;
11298 + struct super_block *h_sb;
11299 + char *pathname, *p;
11300 + struct vfsmount *h_mnt;
11301 + struct au_branch *br;
11303 + struct path path;
11305 + br = au_sbr(sb, nsi_lock->bindex);
11306 + h_mnt = au_br_mnt(br);
11307 + h_sb = h_mnt->mnt_sb;
11308 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11309 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11310 + fh_len - Fh_tail, fh[Fh_h_type],
11311 + h_acceptable, /*context*/NULL);
11312 + dentry = h_parent;
11313 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11314 + AuWarn1("%s decode_fh failed, %ld\n",
11315 + au_sbtype(h_sb), PTR_ERR(h_parent));
11319 + if (unlikely(au_test_anon(h_parent))) {
11320 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11321 + au_sbtype(h_sb));
11322 + goto out_h_parent;
11325 + dentry = ERR_PTR(-ENOMEM);
11326 + pathname = (void *)__get_free_page(GFP_NOFS);
11327 + if (unlikely(!pathname))
11328 + goto out_h_parent;
11330 + root = sb->s_root;
11331 + path.mnt = h_mnt;
11332 + di_read_lock_parent(root, !AuLock_IR);
11333 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11334 + di_read_unlock(root, !AuLock_IR);
11335 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11336 + dentry = (void *)p;
11338 + goto out_pathname;
11340 + si_read_unlock(sb);
11341 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11342 + dentry = ERR_PTR(err);
11343 + if (unlikely(err))
11346 + dentry = ERR_PTR(-ENOENT);
11347 + AuDebugOn(au_test_anon(path.dentry));
11348 + if (unlikely(d_really_is_negative(path.dentry)))
11351 + if (ino != d_inode(path.dentry)->i_ino)
11352 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11354 + dentry = dget(path.dentry);
11359 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11360 + if (!IS_ERR(dentry)) {
11362 + dentry = ERR_PTR(-ESTALE);
11365 + free_page((unsigned long)pathname);
11369 + AuTraceErrPtr(dentry);
11373 +/* ---------------------------------------------------------------------- */
11375 +static struct dentry *
11376 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11379 + struct dentry *dentry;
11380 + __u32 *fh = fid->raw;
11381 + struct au_branch *br;
11382 + ino_t ino, dir_ino;
11383 + struct au_nfsd_si_lock nsi_lock = {
11387 + dentry = ERR_PTR(-ESTALE);
11388 + /* it should never happen, but the file handle is unreliable */
11389 + if (unlikely(fh_len < Fh_tail))
11391 + nsi_lock.sigen = fh[Fh_sigen];
11392 + nsi_lock.br_id = fh[Fh_br_id];
11394 + /* branch id may be wrapped around */
11396 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11398 + nsi_lock.force_lock = 1;
11400 + /* is this inode still cached? */
11401 + ino = decode_ino(fh + Fh_ino);
11402 + /* it should never happen */
11403 + if (unlikely(ino == AUFS_ROOT_INO))
11406 + dir_ino = decode_ino(fh + Fh_dir_ino);
11407 + dentry = decode_by_ino(sb, ino, dir_ino);
11408 + if (IS_ERR(dentry))
11413 + /* is the parent dir cached? */
11414 + br = au_sbr(sb, nsi_lock.bindex);
11415 + atomic_inc(&br->br_count);
11416 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11417 + if (IS_ERR(dentry))
11422 + /* lookup path */
11423 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11424 + if (IS_ERR(dentry))
11426 + if (unlikely(!dentry))
11427 + /* todo?: make it ESTALE */
11431 + if (!au_digen_test(dentry, au_sigen(sb))
11432 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11433 + goto out_unlock; /* success */
11436 + dentry = ERR_PTR(-ESTALE);
11439 + atomic_dec(&br->br_count);
11440 + si_read_unlock(sb);
11442 + AuTraceErrPtr(dentry);
11446 +#if 0 /* reserved for future use */
11447 +/* support subtreecheck option */
11448 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11449 + int fh_len, int fh_type)
11451 + struct dentry *parent;
11452 + __u32 *fh = fid->raw;
11455 + dir_ino = decode_ino(fh + Fh_dir_ino);
11456 + parent = decode_by_ino(sb, dir_ino, 0);
11457 + if (IS_ERR(parent))
11460 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11461 + dir_ino, fh, fh_len);
11464 + AuTraceErrPtr(parent);
11469 +/* ---------------------------------------------------------------------- */
11471 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11472 + struct inode *dir)
11475 + aufs_bindex_t bindex;
11476 + struct super_block *sb, *h_sb;
11477 + struct dentry *dentry, *parent, *h_parent;
11478 + struct inode *h_dir;
11479 + struct au_branch *br;
11482 + if (unlikely(*max_len <= Fh_tail)) {
11483 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11487 + err = FILEID_ROOT;
11488 + if (inode->i_ino == AUFS_ROOT_INO) {
11489 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11494 + sb = inode->i_sb;
11495 + err = si_read_lock(sb, AuLock_FLUSH);
11496 + if (unlikely(err))
11499 +#ifdef CONFIG_AUFS_DEBUG
11500 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11501 + AuWarn1("NFS-exporting requires xino\n");
11505 + ii_read_lock_child(inode);
11506 + bindex = au_ibstart(inode);
11508 + dentry = d_find_any_alias(inode);
11509 + if (unlikely(!dentry))
11511 + AuDebugOn(au_test_anon(dentry));
11512 + parent = dget_parent(dentry);
11514 + if (unlikely(!parent))
11516 + if (d_really_is_positive(parent))
11517 + dir = d_inode(parent);
11520 + ii_read_lock_parent(dir);
11521 + h_dir = au_h_iptr(dir, bindex);
11522 + ii_read_unlock(dir);
11523 + if (unlikely(!h_dir))
11525 + h_parent = d_find_any_alias(h_dir);
11526 + if (unlikely(!h_parent))
11527 + goto out_hparent;
11530 + br = au_sbr(sb, bindex);
11531 + h_sb = au_br_sb(br);
11532 + if (unlikely(!h_sb->s_export_op)) {
11533 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11534 + goto out_hparent;
11537 + fh[Fh_br_id] = br->br_id;
11538 + fh[Fh_sigen] = au_sigen(sb);
11539 + encode_ino(fh + Fh_ino, inode->i_ino);
11540 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11541 + fh[Fh_igen] = inode->i_generation;
11543 + *max_len -= Fh_tail;
11544 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11546 + /*connectable or subtreecheck*/0);
11547 + err = fh[Fh_h_type];
11548 + *max_len += Fh_tail;
11549 + /* todo: macros? */
11550 + if (err != FILEID_INVALID)
11553 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11560 + ii_read_unlock(inode);
11561 + si_read_unlock(sb);
11563 + if (unlikely(err < 0))
11564 + err = FILEID_INVALID;
11568 +/* ---------------------------------------------------------------------- */
11570 +static int aufs_commit_metadata(struct inode *inode)
11573 + aufs_bindex_t bindex;
11574 + struct super_block *sb;
11575 + struct inode *h_inode;
11576 + int (*f)(struct inode *inode);
11578 + sb = inode->i_sb;
11579 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11580 + ii_write_lock_child(inode);
11581 + bindex = au_ibstart(inode);
11582 + AuDebugOn(bindex < 0);
11583 + h_inode = au_h_iptr(inode, bindex);
11585 + f = h_inode->i_sb->s_export_op->commit_metadata;
11587 + err = f(h_inode);
11589 + struct writeback_control wbc = {
11590 + .sync_mode = WB_SYNC_ALL,
11591 + .nr_to_write = 0 /* metadata only */
11594 + err = sync_inode(h_inode, &wbc);
11597 + au_cpup_attr_timesizes(inode);
11598 + ii_write_unlock(inode);
11599 + si_read_unlock(sb);
11603 +/* ---------------------------------------------------------------------- */
11605 +static struct export_operations aufs_export_op = {
11606 + .fh_to_dentry = aufs_fh_to_dentry,
11607 + /* .fh_to_parent = aufs_fh_to_parent, */
11608 + .encode_fh = aufs_encode_fh,
11609 + .commit_metadata = aufs_commit_metadata
11612 +void au_export_init(struct super_block *sb)
11614 + struct au_sbinfo *sbinfo;
11617 + sb->s_export_op = &aufs_export_op;
11618 + sbinfo = au_sbi(sb);
11619 + sbinfo->si_xigen = NULL;
11620 + get_random_bytes(&u, sizeof(u));
11621 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11622 + atomic_set(&sbinfo->si_xigen_next, u);
11624 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11625 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11626 +++ linux/fs/aufs/fhsm.c 2016-02-28 11:26:32.573304539 +0100
11629 + * Copyright (C) 2011-2016 Junjiro R. Okajima
11631 + * This program, aufs is free software; you can redistribute it and/or modify
11632 + * it under the terms of the GNU General Public License as published by
11633 + * the Free Software Foundation; either version 2 of the License, or
11634 + * (at your option) any later version.
11636 + * This program is distributed in the hope that it will be useful,
11637 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11638 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11639 + * GNU General Public License for more details.
11641 + * You should have received a copy of the GNU General Public License
11642 + * along with this program; if not, write to the Free Software
11643 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11647 + * File-based Hierarchy Storage Management
11650 +#include <linux/anon_inodes.h>
11651 +#include <linux/poll.h>
11652 +#include <linux/seq_file.h>
11653 +#include <linux/statfs.h>
11656 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11658 + struct au_sbinfo *sbinfo;
11659 + struct au_fhsm *fhsm;
11661 + SiMustAnyLock(sb);
11663 + sbinfo = au_sbi(sb);
11664 + fhsm = &sbinfo->si_fhsm;
11665 + AuDebugOn(!fhsm);
11666 + return fhsm->fhsm_bottom;
11669 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11671 + struct au_sbinfo *sbinfo;
11672 + struct au_fhsm *fhsm;
11674 + SiMustWriteLock(sb);
11676 + sbinfo = au_sbi(sb);
11677 + fhsm = &sbinfo->si_fhsm;
11678 + AuDebugOn(!fhsm);
11679 + fhsm->fhsm_bottom = bindex;
11682 +/* ---------------------------------------------------------------------- */
11684 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11686 + struct au_br_fhsm *bf;
11688 + bf = br->br_fhsm;
11689 + MtxMustLock(&bf->bf_lock);
11691 + return !bf->bf_readable
11692 + || time_after(jiffies,
11693 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11696 +/* ---------------------------------------------------------------------- */
11698 +static void au_fhsm_notify(struct super_block *sb, int val)
11700 + struct au_sbinfo *sbinfo;
11701 + struct au_fhsm *fhsm;
11703 + SiMustAnyLock(sb);
11705 + sbinfo = au_sbi(sb);
11706 + fhsm = &sbinfo->si_fhsm;
11707 + if (au_fhsm_pid(fhsm)
11708 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11709 + atomic_set(&fhsm->fhsm_readable, val);
11711 + wake_up(&fhsm->fhsm_wqh);
11715 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11716 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11719 + struct au_branch *br;
11720 + struct au_br_fhsm *bf;
11722 + br = au_sbr(sb, bindex);
11723 + AuDebugOn(au_br_rdonly(br));
11724 + bf = br->br_fhsm;
11728 + mutex_lock(&bf->bf_lock);
11730 + MtxMustLock(&bf->bf_lock);
11732 + /* sb->s_root for NFS is unreliable */
11733 + err = au_br_stfs(br, &bf->bf_stfs);
11734 + if (unlikely(err)) {
11735 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11739 + bf->bf_jiffy = jiffies;
11740 + bf->bf_readable = 1;
11742 + au_fhsm_notify(sb, /*val*/1);
11744 + *rstfs = bf->bf_stfs;
11748 + mutex_unlock(&bf->bf_lock);
11749 + au_fhsm_notify(sb, /*val*/1);
11754 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11757 + struct au_sbinfo *sbinfo;
11758 + struct au_fhsm *fhsm;
11759 + struct au_branch *br;
11760 + struct au_br_fhsm *bf;
11762 + AuDbg("b%d, force %d\n", bindex, force);
11763 + SiMustAnyLock(sb);
11765 + sbinfo = au_sbi(sb);
11766 + fhsm = &sbinfo->si_fhsm;
11767 + if (!au_ftest_si(sbinfo, FHSM)
11768 + || fhsm->fhsm_bottom == bindex)
11771 + br = au_sbr(sb, bindex);
11772 + bf = br->br_fhsm;
11774 + mutex_lock(&bf->bf_lock);
11776 + || au_fhsm_pid(fhsm)
11777 + || au_fhsm_test_jiffy(sbinfo, br))
11778 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11780 + mutex_unlock(&bf->bf_lock);
11783 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11785 + aufs_bindex_t bindex, bend;
11786 + struct au_branch *br;
11788 + /* exclude the bottom */
11789 + bend = au_fhsm_bottom(sb);
11790 + for (bindex = 0; bindex < bend; bindex++) {
11791 + br = au_sbr(sb, bindex);
11792 + if (au_br_fhsm(br->br_perm))
11793 + au_fhsm_wrote(sb, bindex, force);
11797 +/* ---------------------------------------------------------------------- */
11799 +static unsigned int au_fhsm_poll(struct file *file,
11800 + struct poll_table_struct *wait)
11802 + unsigned int mask;
11803 + struct au_sbinfo *sbinfo;
11804 + struct au_fhsm *fhsm;
11807 + sbinfo = file->private_data;
11808 + fhsm = &sbinfo->si_fhsm;
11809 + poll_wait(file, &fhsm->fhsm_wqh, wait);
11810 + if (atomic_read(&fhsm->fhsm_readable))
11811 + mask = POLLIN /* | POLLRDNORM */;
11813 + AuTraceErr((int)mask);
11817 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
11818 + struct aufs_stfs *stfs, __s16 brid)
11822 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
11824 + err = __put_user(brid, &stbr->brid);
11825 + if (unlikely(err))
11831 +static ssize_t au_fhsm_do_read(struct super_block *sb,
11832 + struct aufs_stbr __user *stbr, size_t count)
11836 + aufs_bindex_t bindex, bend;
11837 + struct au_branch *br;
11838 + struct au_br_fhsm *bf;
11840 + /* except the bottom branch */
11843 + bend = au_fhsm_bottom(sb);
11844 + for (bindex = 0; !err && bindex < bend; bindex++) {
11845 + br = au_sbr(sb, bindex);
11846 + if (!au_br_fhsm(br->br_perm))
11849 + bf = br->br_fhsm;
11850 + mutex_lock(&bf->bf_lock);
11851 + if (bf->bf_readable) {
11853 + if (count >= sizeof(*stbr))
11854 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
11857 + bf->bf_readable = 0;
11858 + count -= sizeof(*stbr);
11862 + mutex_unlock(&bf->bf_lock);
11865 + err = sizeof(*stbr) * nstbr;
11870 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
11875 + aufs_bindex_t nfhsm, bindex, bend;
11876 + struct au_sbinfo *sbinfo;
11877 + struct au_fhsm *fhsm;
11878 + struct au_branch *br;
11879 + struct super_block *sb;
11882 + sbinfo = file->private_data;
11883 + fhsm = &sbinfo->si_fhsm;
11885 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
11886 + if (!atomic_read(&fhsm->fhsm_readable)) {
11887 + if (vfsub_file_flags(file) & O_NONBLOCK)
11890 + err = wait_event_interruptible_locked_irq
11892 + atomic_read(&fhsm->fhsm_readable));
11894 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
11895 + if (unlikely(err))
11898 + /* sb may already be dead */
11899 + au_rw_read_lock(&sbinfo->si_rwsem);
11900 + readable = atomic_read(&fhsm->fhsm_readable);
11901 + if (readable > 0) {
11902 + sb = sbinfo->si_sb;
11904 + /* exclude the bottom branch */
11906 + bend = au_fhsm_bottom(sb);
11907 + for (bindex = 0; bindex < bend; bindex++) {
11908 + br = au_sbr(sb, bindex);
11909 + if (au_br_fhsm(br->br_perm))
11913 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
11914 + atomic_set(&fhsm->fhsm_readable, 0);
11915 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
11919 + au_rw_read_unlock(&sbinfo->si_rwsem);
11927 +static int au_fhsm_release(struct inode *inode, struct file *file)
11929 + struct au_sbinfo *sbinfo;
11930 + struct au_fhsm *fhsm;
11932 + /* sb may already be dead */
11933 + sbinfo = file->private_data;
11934 + fhsm = &sbinfo->si_fhsm;
11935 + spin_lock(&fhsm->fhsm_spin);
11936 + fhsm->fhsm_pid = 0;
11937 + spin_unlock(&fhsm->fhsm_spin);
11938 + kobject_put(&sbinfo->si_kobj);
11943 +static const struct file_operations au_fhsm_fops = {
11944 + .owner = THIS_MODULE,
11945 + .llseek = noop_llseek,
11946 + .read = au_fhsm_read,
11947 + .poll = au_fhsm_poll,
11948 + .release = au_fhsm_release
11951 +int au_fhsm_fd(struct super_block *sb, int oflags)
11954 + struct au_sbinfo *sbinfo;
11955 + struct au_fhsm *fhsm;
11958 + if (unlikely(!capable(CAP_SYS_ADMIN)))
11962 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
11966 + sbinfo = au_sbi(sb);
11967 + fhsm = &sbinfo->si_fhsm;
11968 + spin_lock(&fhsm->fhsm_spin);
11969 + if (!fhsm->fhsm_pid)
11970 + fhsm->fhsm_pid = current->pid;
11973 + spin_unlock(&fhsm->fhsm_spin);
11974 + if (unlikely(err))
11977 + oflags |= O_RDONLY;
11978 + /* oflags |= FMODE_NONOTIFY; */
11979 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
11981 + if (unlikely(fd < 0))
11984 + /* succeed reglardless 'fhsm' status */
11985 + kobject_get(&sbinfo->si_kobj);
11986 + si_noflush_read_lock(sb);
11987 + if (au_ftest_si(sbinfo, FHSM))
11988 + au_fhsm_wrote_all(sb, /*force*/0);
11989 + si_read_unlock(sb);
11990 + goto out; /* success */
11993 + spin_lock(&fhsm->fhsm_spin);
11994 + fhsm->fhsm_pid = 0;
11995 + spin_unlock(&fhsm->fhsm_spin);
12001 +/* ---------------------------------------------------------------------- */
12003 +int au_fhsm_br_alloc(struct au_branch *br)
12008 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
12010 + au_br_fhsm_init(br->br_fhsm);
12017 +/* ---------------------------------------------------------------------- */
12019 +void au_fhsm_fin(struct super_block *sb)
12021 + au_fhsm_notify(sb, /*val*/-1);
12024 +void au_fhsm_init(struct au_sbinfo *sbinfo)
12026 + struct au_fhsm *fhsm;
12028 + fhsm = &sbinfo->si_fhsm;
12029 + spin_lock_init(&fhsm->fhsm_spin);
12030 + init_waitqueue_head(&fhsm->fhsm_wqh);
12031 + atomic_set(&fhsm->fhsm_readable, 0);
12032 + fhsm->fhsm_expire
12033 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
12034 + fhsm->fhsm_bottom = -1;
12037 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
12039 + sbinfo->si_fhsm.fhsm_expire
12040 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
12043 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
12047 + if (!au_ftest_si(sbinfo, FHSM))
12050 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
12051 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
12052 + seq_printf(seq, ",fhsm_sec=%u", u);
12054 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
12055 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
12056 +++ linux/fs/aufs/file.c 2016-02-28 11:26:32.573304539 +0100
12059 + * Copyright (C) 2005-2016 Junjiro R. Okajima
12061 + * This program, aufs is free software; you can redistribute it and/or modify
12062 + * it under the terms of the GNU General Public License as published by
12063 + * the Free Software Foundation; either version 2 of the License, or
12064 + * (at your option) any later version.
12066 + * This program is distributed in the hope that it will be useful,
12067 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12068 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12069 + * GNU General Public License for more details.
12071 + * You should have received a copy of the GNU General Public License
12072 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12076 + * handling file/dir, and address_space operation
12079 +#ifdef CONFIG_AUFS_DEBUG
12080 +#include <linux/migrate.h>
12082 +#include <linux/pagemap.h>
12085 +/* drop flags for writing */
12086 +unsigned int au_file_roflags(unsigned int flags)
12088 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12089 + flags |= O_RDONLY | O_NOATIME;
12093 +/* common functions to regular file and dir */
12094 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12095 + struct file *file, int force_wr)
12097 + struct file *h_file;
12098 + struct dentry *h_dentry;
12099 + struct inode *h_inode;
12100 + struct super_block *sb;
12101 + struct au_branch *br;
12102 + struct path h_path;
12105 + /* a race condition can happen between open and unlink/rmdir */
12106 + h_file = ERR_PTR(-ENOENT);
12107 + h_dentry = au_h_dptr(dentry, bindex);
12108 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12110 + h_inode = d_inode(h_dentry);
12111 + spin_lock(&h_dentry->d_lock);
12112 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12113 + /* || !d_inode(dentry)->i_nlink */
12115 + spin_unlock(&h_dentry->d_lock);
12116 + if (unlikely(err))
12119 + sb = dentry->d_sb;
12120 + br = au_sbr(sb, bindex);
12121 + err = au_br_test_oflag(flags, br);
12122 + h_file = ERR_PTR(err);
12123 + if (unlikely(err))
12126 + /* drop flags for writing */
12127 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12128 + if (force_wr && !(flags & O_WRONLY))
12130 + flags = au_file_roflags(flags);
12132 + h_file = ERR_PTR(-EROFS);
12133 + flags = au_file_roflags(flags);
12134 + if (unlikely(vfsub_native_ro(h_inode)
12135 + || IS_APPEND(h_inode)))
12137 + flags &= ~O_ACCMODE;
12138 + flags |= O_WRONLY;
12141 + flags &= ~O_CREAT;
12142 + atomic_inc(&br->br_count);
12143 + h_path.dentry = h_dentry;
12144 + h_path.mnt = au_br_mnt(br);
12145 + h_file = vfsub_dentry_open(&h_path, flags);
12146 + if (IS_ERR(h_file))
12149 + if (flags & __FMODE_EXEC) {
12150 + err = deny_write_access(h_file);
12151 + if (unlikely(err)) {
12153 + h_file = ERR_PTR(err);
12157 + fsnotify_open(h_file);
12158 + goto out; /* success */
12161 + atomic_dec(&br->br_count);
12166 +static int au_cmoo(struct dentry *dentry)
12169 + unsigned int udba;
12170 + struct path h_path;
12171 + struct au_pin pin;
12172 + struct au_cp_generic cpg = {
12173 + .dentry = dentry,
12178 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12180 + struct inode *delegated;
12181 + struct super_block *sb;
12182 + struct au_sbinfo *sbinfo;
12183 + struct au_fhsm *fhsm;
12185 + struct au_branch *br;
12186 + struct dentry *parent;
12187 + struct au_hinode *hdir;
12189 + DiMustWriteLock(dentry);
12190 + IiMustWriteLock(d_inode(dentry));
12193 + if (IS_ROOT(dentry))
12195 + cpg.bsrc = au_dbstart(dentry);
12199 + sb = dentry->d_sb;
12200 + sbinfo = au_sbi(sb);
12201 + fhsm = &sbinfo->si_fhsm;
12202 + pid = au_fhsm_pid(fhsm);
12204 + && (current->pid == pid
12205 + || current->real_parent->pid == pid))
12208 + br = au_sbr(sb, cpg.bsrc);
12209 + cmoo = au_br_cmoo(br->br_perm);
12212 + if (!d_is_reg(dentry))
12213 + cmoo &= AuBrAttr_COO_ALL;
12217 + parent = dget_parent(dentry);
12218 + di_write_lock_parent(parent);
12219 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12221 + if (unlikely(err < 0)) {
12222 + err = 0; /* there is no upper writable branch */
12225 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12227 + /* do not respect the coo attrib for the target branch */
12228 + err = au_cpup_dirs(dentry, cpg.bdst);
12229 + if (unlikely(err))
12232 + di_downgrade_lock(parent, AuLock_IR);
12233 + udba = au_opt_udba(sb);
12234 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12235 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12236 + if (unlikely(err))
12239 + err = au_sio_cpup_simple(&cpg);
12241 + if (unlikely(err))
12243 + if (!(cmoo & AuBrWAttr_MOO))
12244 + goto out_parent; /* success */
12246 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12247 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12248 + if (unlikely(err))
12251 + h_path.mnt = au_br_mnt(br);
12252 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12253 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12254 + delegated = NULL;
12255 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12257 + /* todo: keep h_dentry or not? */
12258 + if (unlikely(err == -EWOULDBLOCK)) {
12259 + pr_warn("cannot retry for NFSv4 delegation"
12260 + " for an internal unlink\n");
12263 + if (unlikely(err)) {
12264 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12268 + goto out_parent; /* success */
12271 + di_downgrade_lock(parent, AuLock_IR);
12273 + di_read_unlock(parent, AuLock_IR);
12280 +int au_do_open(struct file *file, struct au_do_open_args *args)
12282 + int err, no_lock = args->no_lock;
12283 + struct dentry *dentry;
12284 + struct au_finfo *finfo;
12287 + err = au_finfo_init(file, args->fidir);
12290 + err = au_finfo_init(file, args->fidir);
12293 + if (unlikely(err))
12296 + dentry = file->f_path.dentry;
12297 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12299 + di_write_lock_child(dentry);
12300 + err = au_cmoo(dentry);
12301 + di_downgrade_lock(dentry, AuLock_IR);
12303 + err = args->open(file, vfsub_file_flags(file), NULL);
12304 + di_read_unlock(dentry, AuLock_IR);
12306 + err = au_cmoo(dentry);
12308 + err = args->open(file, vfsub_file_flags(file),
12310 + if (!err && au_fbstart(file) != au_dbstart(dentry))
12312 + * cmoo happens after h_file was opened.
12313 + * need to refresh file later.
12315 + atomic_dec(&au_fi(file)->fi_generation);
12318 + finfo = au_fi(file);
12320 + finfo->fi_file = file;
12321 + au_sphl_add(&finfo->fi_hlist,
12322 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12325 + fi_write_unlock(file);
12328 + fi_write_unlock(file);
12331 + if (unlikely(err)) {
12332 + finfo->fi_hdir = NULL;
12333 + au_finfo_fin(file);
12340 +int au_reopen_nondir(struct file *file)
12343 + aufs_bindex_t bstart;
12344 + struct dentry *dentry;
12345 + struct file *h_file, *h_file_tmp;
12347 + dentry = file->f_path.dentry;
12348 + bstart = au_dbstart(dentry);
12349 + h_file_tmp = NULL;
12350 + if (au_fbstart(file) == bstart) {
12351 + h_file = au_hf_top(file);
12352 + if (file->f_mode == h_file->f_mode)
12353 + return 0; /* success */
12354 + h_file_tmp = h_file;
12355 + get_file(h_file_tmp);
12356 + au_set_h_fptr(file, bstart, NULL);
12358 + AuDebugOn(au_fi(file)->fi_hdir);
12361 + * file exists on both of rw and ro
12362 + * open --> dbstart and fbstart are both 0
12363 + * prepend a branch as rw, "rw" become ro
12365 + * delete the top branch, "rw" becomes rw again
12366 + * --> dbstart is 1, fbstart is still 0
12367 + * write --> fbstart is 0 but dbstart is 1
12369 + /* AuDebugOn(au_fbstart(file) < bstart); */
12371 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
12372 + file, /*force_wr*/0);
12373 + err = PTR_ERR(h_file);
12374 + if (IS_ERR(h_file)) {
12375 + if (h_file_tmp) {
12376 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
12377 + au_set_h_fptr(file, bstart, h_file_tmp);
12378 + h_file_tmp = NULL;
12380 + goto out; /* todo: close all? */
12384 + au_set_fbstart(file, bstart);
12385 + au_set_h_fptr(file, bstart, h_file);
12386 + au_update_figen(file);
12387 + /* todo: necessary? */
12388 + /* file->f_ra = h_file->f_ra; */
12392 + fput(h_file_tmp);
12396 +/* ---------------------------------------------------------------------- */
12398 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12399 + struct dentry *hi_wh)
12402 + aufs_bindex_t bstart;
12403 + struct au_dinfo *dinfo;
12404 + struct dentry *h_dentry;
12405 + struct au_hdentry *hdp;
12407 + dinfo = au_di(file->f_path.dentry);
12408 + AuRwMustWriteLock(&dinfo->di_rwsem);
12410 + bstart = dinfo->di_bstart;
12411 + dinfo->di_bstart = btgt;
12412 + hdp = dinfo->di_hdentry;
12413 + h_dentry = hdp[0 + btgt].hd_dentry;
12414 + hdp[0 + btgt].hd_dentry = hi_wh;
12415 + err = au_reopen_nondir(file);
12416 + hdp[0 + btgt].hd_dentry = h_dentry;
12417 + dinfo->di_bstart = bstart;
12422 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12423 + aufs_bindex_t bcpup, struct au_pin *pin)
12426 + struct inode *inode, *h_inode;
12427 + struct dentry *h_dentry, *hi_wh;
12428 + struct au_cp_generic cpg = {
12429 + .dentry = file->f_path.dentry,
12436 + au_update_dbstart(cpg.dentry);
12437 + inode = d_inode(cpg.dentry);
12439 + if (au_dbstart(cpg.dentry) <= bcpup
12440 + && au_dbend(cpg.dentry) >= bcpup) {
12441 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12442 + if (h_dentry && d_is_positive(h_dentry))
12443 + h_inode = d_inode(h_dentry);
12445 + hi_wh = au_hi_wh(inode, bcpup);
12446 + if (!hi_wh && !h_inode)
12447 + err = au_sio_cpup_wh(&cpg, file);
12449 + /* already copied-up after unlink */
12450 + err = au_reopen_wh(file, bcpup, hi_wh);
12453 + && (inode->i_nlink > 1
12454 + || (inode->i_state & I_LINKABLE))
12455 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12456 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12462 + * prepare the @file for writing.
12464 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12467 + aufs_bindex_t dbstart;
12468 + struct dentry *parent;
12469 + struct inode *inode;
12470 + struct super_block *sb;
12471 + struct file *h_file;
12472 + struct au_cp_generic cpg = {
12473 + .dentry = file->f_path.dentry,
12478 + .flags = AuCpup_DTIME
12481 + sb = cpg.dentry->d_sb;
12482 + inode = d_inode(cpg.dentry);
12483 + cpg.bsrc = au_fbstart(file);
12484 + err = au_test_ro(sb, cpg.bsrc, inode);
12485 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12486 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12491 + /* need to cpup or reopen */
12492 + parent = dget_parent(cpg.dentry);
12493 + di_write_lock_parent(parent);
12494 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12496 + if (unlikely(err < 0))
12500 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12501 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12502 + if (unlikely(err))
12506 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12507 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12508 + if (unlikely(err))
12511 + dbstart = au_dbstart(cpg.dentry);
12512 + if (dbstart <= cpg.bdst)
12513 + cpg.bsrc = cpg.bdst;
12515 + if (dbstart <= cpg.bdst /* just reopen */
12516 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12518 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12519 + if (IS_ERR(h_file))
12520 + err = PTR_ERR(h_file);
12522 + di_downgrade_lock(parent, AuLock_IR);
12523 + if (dbstart > cpg.bdst)
12524 + err = au_sio_cpup_simple(&cpg);
12526 + err = au_reopen_nondir(file);
12527 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12529 + } else { /* copyup as wh and reopen */
12531 + * since writable hfsplus branch is not supported,
12532 + * h_open_pre/post() are unnecessary.
12534 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12535 + di_downgrade_lock(parent, AuLock_IR);
12539 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12540 + goto out_dput; /* success */
12546 + di_downgrade_lock(parent, AuLock_IR);
12548 + di_read_unlock(parent, AuLock_IR);
12555 +/* ---------------------------------------------------------------------- */
12557 +int au_do_flush(struct file *file, fl_owner_t id,
12558 + int (*flush)(struct file *file, fl_owner_t id))
12561 + struct super_block *sb;
12562 + struct inode *inode;
12564 + inode = file_inode(file);
12565 + sb = inode->i_sb;
12566 + si_noflush_read_lock(sb);
12567 + fi_read_lock(file);
12568 + ii_read_lock_child(inode);
12570 + err = flush(file, id);
12571 + au_cpup_attr_timesizes(inode);
12573 + ii_read_unlock(inode);
12574 + fi_read_unlock(file);
12575 + si_read_unlock(sb);
12579 +/* ---------------------------------------------------------------------- */
12581 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12584 + struct au_pin pin;
12585 + struct au_finfo *finfo;
12586 + struct dentry *parent, *hi_wh;
12587 + struct inode *inode;
12588 + struct super_block *sb;
12589 + struct au_cp_generic cpg = {
12590 + .dentry = file->f_path.dentry,
12595 + .flags = AuCpup_DTIME
12598 + FiMustWriteLock(file);
12601 + finfo = au_fi(file);
12602 + sb = cpg.dentry->d_sb;
12603 + inode = d_inode(cpg.dentry);
12604 + cpg.bdst = au_ibstart(inode);
12605 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12608 + parent = dget_parent(cpg.dentry);
12609 + if (au_test_ro(sb, cpg.bdst, inode)) {
12610 + di_read_lock_parent(parent, !AuLock_IR);
12611 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12613 + di_read_unlock(parent, !AuLock_IR);
12614 + if (unlikely(err < 0))
12619 + di_read_lock_parent(parent, AuLock_IR);
12620 + hi_wh = au_hi_wh(inode, cpg.bdst);
12621 + if (!S_ISDIR(inode->i_mode)
12622 + && au_opt_test(au_mntflags(sb), PLINK)
12623 + && au_plink_test(inode)
12624 + && !d_unhashed(cpg.dentry)
12625 + && cpg.bdst < au_dbstart(cpg.dentry)) {
12626 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12627 + if (unlikely(err))
12630 + /* always superio. */
12631 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12632 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12634 + err = au_sio_cpup_simple(&cpg);
12637 + } else if (hi_wh) {
12638 + /* already copied-up after unlink */
12639 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12640 + *need_reopen = 0;
12644 + di_read_unlock(parent, AuLock_IR);
12651 +static void au_do_refresh_dir(struct file *file)
12653 + aufs_bindex_t bindex, bend, new_bindex, brid;
12654 + struct au_hfile *p, tmp, *q;
12655 + struct au_finfo *finfo;
12656 + struct super_block *sb;
12657 + struct au_fidir *fidir;
12659 + FiMustWriteLock(file);
12661 + sb = file->f_path.dentry->d_sb;
12662 + finfo = au_fi(file);
12663 + fidir = finfo->fi_hdir;
12664 + AuDebugOn(!fidir);
12665 + p = fidir->fd_hfile + finfo->fi_btop;
12666 + brid = p->hf_br->br_id;
12667 + bend = fidir->fd_bbot;
12668 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
12672 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12673 + if (new_bindex == bindex)
12675 + if (new_bindex < 0) {
12676 + au_set_h_fptr(file, bindex, NULL);
12680 + /* swap two lower inode, and loop again */
12681 + q = fidir->fd_hfile + new_bindex;
12685 + if (tmp.hf_file) {
12691 + p = fidir->fd_hfile;
12692 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12693 + bend = au_sbend(sb);
12694 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
12695 + finfo->fi_btop++, p++)
12696 + if (p->hf_file) {
12697 + if (file_inode(p->hf_file))
12699 + au_hfput(p, file);
12702 + bend = au_br_index(sb, brid);
12703 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
12704 + finfo->fi_btop++, p++)
12706 + au_hfput(p, file);
12707 + bend = au_sbend(sb);
12710 + p = fidir->fd_hfile + bend;
12711 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
12712 + fidir->fd_bbot--, p--)
12713 + if (p->hf_file) {
12714 + if (file_inode(p->hf_file))
12716 + au_hfput(p, file);
12718 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12722 + * after branch manipulating, refresh the file.
12724 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12726 + int err, need_reopen;
12727 + aufs_bindex_t bend, bindex;
12728 + struct dentry *dentry;
12729 + struct au_finfo *finfo;
12730 + struct au_hfile *hfile;
12732 + dentry = file->f_path.dentry;
12733 + finfo = au_fi(file);
12734 + if (!finfo->fi_hdir) {
12735 + hfile = &finfo->fi_htop;
12736 + AuDebugOn(!hfile->hf_file);
12737 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
12738 + AuDebugOn(bindex < 0);
12739 + if (bindex != finfo->fi_btop)
12740 + au_set_fbstart(file, bindex);
12742 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
12743 + if (unlikely(err))
12745 + au_do_refresh_dir(file);
12750 + if (!au_test_mmapped(file))
12751 + err = au_file_refresh_by_inode(file, &need_reopen);
12752 + if (!err && need_reopen && !d_unlinked(dentry))
12753 + err = reopen(file);
12755 + au_update_figen(file);
12756 + goto out; /* success */
12759 + /* error, close all lower files */
12760 + if (finfo->fi_hdir) {
12761 + bend = au_fbend_dir(file);
12762 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
12763 + au_set_h_fptr(file, bindex, NULL);
12770 +/* common function to regular file and dir */
12771 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12775 + unsigned int sigen, figen;
12776 + aufs_bindex_t bstart;
12777 + unsigned char pseudo_link;
12778 + struct dentry *dentry;
12779 + struct inode *inode;
12782 + dentry = file->f_path.dentry;
12783 + inode = d_inode(dentry);
12784 + sigen = au_sigen(dentry->d_sb);
12785 + fi_write_lock(file);
12786 + figen = au_figen(file);
12787 + di_write_lock_child(dentry);
12788 + bstart = au_dbstart(dentry);
12789 + pseudo_link = (bstart != au_ibstart(inode));
12790 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
12792 + di_downgrade_lock(dentry, AuLock_IR);
12793 + fi_downgrade_lock(file);
12795 + goto out; /* success */
12798 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12799 + if (au_digen_test(dentry, sigen)) {
12800 + err = au_reval_dpath(dentry, sigen);
12801 + AuDebugOn(!err && au_digen_test(dentry, sigen));
12805 + err = refresh_file(file, reopen);
12808 + di_downgrade_lock(dentry, AuLock_IR);
12809 + fi_downgrade_lock(file);
12812 + di_write_unlock(dentry);
12813 + fi_write_unlock(file);
12820 +/* ---------------------------------------------------------------------- */
12822 +/* cf. aufs_nopage() */
12823 +/* for madvise(2) */
12824 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
12826 + unlock_page(page);
12830 +/* it will never be called, but necessary to support O_DIRECT */
12831 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
12833 +{ BUG(); return 0; }
12835 +/* they will never be called. */
12836 +#ifdef CONFIG_AUFS_DEBUG
12837 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
12838 + loff_t pos, unsigned len, unsigned flags,
12839 + struct page **pagep, void **fsdata)
12840 +{ AuUnsupport(); return 0; }
12841 +static int aufs_write_end(struct file *file, struct address_space *mapping,
12842 + loff_t pos, unsigned len, unsigned copied,
12843 + struct page *page, void *fsdata)
12844 +{ AuUnsupport(); return 0; }
12845 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
12846 +{ AuUnsupport(); return 0; }
12848 +static int aufs_set_page_dirty(struct page *page)
12849 +{ AuUnsupport(); return 0; }
12850 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
12851 + unsigned int length)
12852 +{ AuUnsupport(); }
12853 +static int aufs_releasepage(struct page *page, gfp_t gfp)
12854 +{ AuUnsupport(); return 0; }
12855 +#if 0 /* called by memory compaction regardless file */
12856 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
12857 + struct page *page, enum migrate_mode mode)
12858 +{ AuUnsupport(); return 0; }
12860 +static int aufs_launder_page(struct page *page)
12861 +{ AuUnsupport(); return 0; }
12862 +static int aufs_is_partially_uptodate(struct page *page,
12863 + unsigned long from,
12864 + unsigned long count)
12865 +{ AuUnsupport(); return 0; }
12866 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
12868 +{ AuUnsupport(); }
12869 +static int aufs_error_remove_page(struct address_space *mapping,
12870 + struct page *page)
12871 +{ AuUnsupport(); return 0; }
12872 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
12874 +{ AuUnsupport(); return 0; }
12875 +static void aufs_swap_deactivate(struct file *file)
12876 +{ AuUnsupport(); }
12877 +#endif /* CONFIG_AUFS_DEBUG */
12879 +const struct address_space_operations aufs_aop = {
12880 + .readpage = aufs_readpage,
12881 + .direct_IO = aufs_direct_IO,
12882 +#ifdef CONFIG_AUFS_DEBUG
12883 + .writepage = aufs_writepage,
12884 + /* no writepages, because of writepage */
12885 + .set_page_dirty = aufs_set_page_dirty,
12886 + /* no readpages, because of readpage */
12887 + .write_begin = aufs_write_begin,
12888 + .write_end = aufs_write_end,
12889 + /* no bmap, no block device */
12890 + .invalidatepage = aufs_invalidatepage,
12891 + .releasepage = aufs_releasepage,
12892 + /* is fallback_migrate_page ok? */
12893 + /* .migratepage = aufs_migratepage, */
12894 + .launder_page = aufs_launder_page,
12895 + .is_partially_uptodate = aufs_is_partially_uptodate,
12896 + .is_dirty_writeback = aufs_is_dirty_writeback,
12897 + .error_remove_page = aufs_error_remove_page,
12898 + .swap_activate = aufs_swap_activate,
12899 + .swap_deactivate = aufs_swap_deactivate
12900 +#endif /* CONFIG_AUFS_DEBUG */
12902 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
12903 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
12904 +++ linux/fs/aufs/file.h 2016-02-28 11:26:32.573304539 +0100
12907 + * Copyright (C) 2005-2016 Junjiro R. Okajima
12909 + * This program, aufs is free software; you can redistribute it and/or modify
12910 + * it under the terms of the GNU General Public License as published by
12911 + * the Free Software Foundation; either version 2 of the License, or
12912 + * (at your option) any later version.
12914 + * This program is distributed in the hope that it will be useful,
12915 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12916 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12917 + * GNU General Public License for more details.
12919 + * You should have received a copy of the GNU General Public License
12920 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12924 + * file operations
12927 +#ifndef __AUFS_FILE_H__
12928 +#define __AUFS_FILE_H__
12932 +#include <linux/file.h>
12933 +#include <linux/fs.h>
12934 +#include <linux/poll.h>
12935 +#include "rwsem.h"
12939 + struct file *hf_file;
12940 + struct au_branch *hf_br;
12945 + aufs_bindex_t fd_bbot;
12946 + aufs_bindex_t fd_nent;
12947 + struct au_vdir *fd_vdir_cache;
12948 + struct au_hfile fd_hfile[];
12951 +static inline int au_fidir_sz(int nent)
12953 + AuDebugOn(nent < 0);
12954 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
12958 + atomic_t fi_generation;
12960 + struct au_rwsem fi_rwsem;
12961 + aufs_bindex_t fi_btop;
12963 + /* do not union them */
12964 + struct { /* for non-dir */
12965 + struct au_hfile fi_htop;
12966 + atomic_t fi_mmapped;
12968 + struct au_fidir *fi_hdir; /* for dir only */
12970 + struct hlist_node fi_hlist;
12971 + struct file *fi_file; /* very ugly */
12972 +} ____cacheline_aligned_in_smp;
12974 +/* ---------------------------------------------------------------------- */
12977 +extern const struct address_space_operations aufs_aop;
12978 +unsigned int au_file_roflags(unsigned int flags);
12979 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12980 + struct file *file, int force_wr);
12981 +struct au_do_open_args {
12983 + int (*open)(struct file *file, int flags,
12984 + struct file *h_file);
12985 + struct au_fidir *fidir;
12986 + struct file *h_file;
12988 +int au_do_open(struct file *file, struct au_do_open_args *args);
12989 +int au_reopen_nondir(struct file *file);
12991 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
12992 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12994 +int au_do_flush(struct file *file, fl_owner_t id,
12995 + int (*flush)(struct file *file, fl_owner_t id));
12998 +#ifdef CONFIG_AUFS_POLL
12999 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13002 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13004 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13006 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13007 + struct file *h_file);
13009 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13010 + aufs_bindex_t bindex, int force_wr)
13011 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13012 + struct file *h_file);
13016 +extern const struct file_operations aufs_file_fop;
13017 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13018 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13019 +struct file *au_read_pre(struct file *file, int keep_fi);
13022 +void au_hfput(struct au_hfile *hf, struct file *file);
13023 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13024 + struct file *h_file);
13026 +void au_update_figen(struct file *file);
13027 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13028 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
13030 +void au_fi_init_once(void *_fi);
13031 +void au_finfo_fin(struct file *file);
13032 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13035 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13036 +#ifdef CONFIG_COMPAT
13037 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13038 + unsigned long arg);
13039 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13040 + unsigned long arg);
13043 +/* ---------------------------------------------------------------------- */
13045 +static inline struct au_finfo *au_fi(struct file *file)
13047 + return file->private_data;
13050 +/* ---------------------------------------------------------------------- */
13053 + * fi_read_lock, fi_write_lock,
13054 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13056 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13058 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13059 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13060 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13062 +/* ---------------------------------------------------------------------- */
13064 +/* todo: hard/soft set? */
13065 +static inline aufs_bindex_t au_fbstart(struct file *file)
13067 + FiMustAnyLock(file);
13068 + return au_fi(file)->fi_btop;
13071 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
13073 + FiMustAnyLock(file);
13074 + AuDebugOn(!au_fi(file)->fi_hdir);
13075 + return au_fi(file)->fi_hdir->fd_bbot;
13078 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13080 + FiMustAnyLock(file);
13081 + AuDebugOn(!au_fi(file)->fi_hdir);
13082 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13085 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
13087 + FiMustWriteLock(file);
13088 + au_fi(file)->fi_btop = bindex;
13091 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
13093 + FiMustWriteLock(file);
13094 + AuDebugOn(!au_fi(file)->fi_hdir);
13095 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13098 +static inline void au_set_fvdir_cache(struct file *file,
13099 + struct au_vdir *vdir_cache)
13101 + FiMustWriteLock(file);
13102 + AuDebugOn(!au_fi(file)->fi_hdir);
13103 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13106 +static inline struct file *au_hf_top(struct file *file)
13108 + FiMustAnyLock(file);
13109 + AuDebugOn(au_fi(file)->fi_hdir);
13110 + return au_fi(file)->fi_htop.hf_file;
13113 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13115 + FiMustAnyLock(file);
13116 + AuDebugOn(!au_fi(file)->fi_hdir);
13117 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13120 +/* todo: memory barrier? */
13121 +static inline unsigned int au_figen(struct file *f)
13123 + return atomic_read(&au_fi(f)->fi_generation);
13126 +static inline void au_set_mmapped(struct file *f)
13128 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13130 + pr_warn("fi_mmapped wrapped around\n");
13131 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13135 +static inline void au_unset_mmapped(struct file *f)
13137 + atomic_dec(&au_fi(f)->fi_mmapped);
13140 +static inline int au_test_mmapped(struct file *f)
13142 + return atomic_read(&au_fi(f)->fi_mmapped);
13145 +/* customize vma->vm_file */
13147 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13148 + struct file *file)
13152 + f = vma->vm_file;
13154 + vma->vm_file = file;
13159 +#define AuDbgVmRegion(file, vma) do {} while (0)
13161 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13162 + struct file *file)
13164 + au_do_vm_file_reset(vma, file);
13167 +#define AuDbgVmRegion(file, vma) \
13168 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13170 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13171 + struct file *file)
13175 + au_do_vm_file_reset(vma, file);
13176 + f = vma->vm_region->vm_file;
13178 + vma->vm_region->vm_file = file;
13181 +#endif /* CONFIG_MMU */
13183 +/* handle vma->vm_prfile */
13184 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13185 + struct file *file)
13188 + vma->vm_prfile = file;
13189 +#ifndef CONFIG_MMU
13191 + vma->vm_region->vm_prfile = file;
13195 +#endif /* __KERNEL__ */
13196 +#endif /* __AUFS_FILE_H__ */
13197 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13198 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13199 +++ linux/fs/aufs/finfo.c 2016-02-28 11:26:32.573304539 +0100
13202 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13204 + * This program, aufs is free software; you can redistribute it and/or modify
13205 + * it under the terms of the GNU General Public License as published by
13206 + * the Free Software Foundation; either version 2 of the License, or
13207 + * (at your option) any later version.
13209 + * This program is distributed in the hope that it will be useful,
13210 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13211 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13212 + * GNU General Public License for more details.
13214 + * You should have received a copy of the GNU General Public License
13215 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13219 + * file private data
13224 +void au_hfput(struct au_hfile *hf, struct file *file)
13226 + /* todo: direct access f_flags */
13227 + if (vfsub_file_flags(file) & __FMODE_EXEC)
13228 + allow_write_access(hf->hf_file);
13229 + fput(hf->hf_file);
13230 + hf->hf_file = NULL;
13231 + atomic_dec(&hf->hf_br->br_count);
13232 + hf->hf_br = NULL;
13235 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13237 + struct au_finfo *finfo = au_fi(file);
13238 + struct au_hfile *hf;
13239 + struct au_fidir *fidir;
13241 + fidir = finfo->fi_hdir;
13243 + AuDebugOn(finfo->fi_btop != bindex);
13244 + hf = &finfo->fi_htop;
13246 + hf = fidir->fd_hfile + bindex;
13248 + if (hf && hf->hf_file)
13249 + au_hfput(hf, file);
13251 + FiMustWriteLock(file);
13252 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13253 + hf->hf_file = val;
13254 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13258 +void au_update_figen(struct file *file)
13260 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13261 + /* smp_mb(); */ /* atomic_set */
13264 +/* ---------------------------------------------------------------------- */
13266 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13268 + struct au_fidir *fidir;
13271 + nbr = au_sbend(sb) + 1;
13273 + nbr = 2; /* initial allocate for 2 branches */
13274 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13276 + fidir->fd_bbot = -1;
13277 + fidir->fd_nent = nbr;
13283 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
13286 + struct au_fidir *fidir, *p;
13288 + AuRwMustWriteLock(&finfo->fi_rwsem);
13289 + fidir = finfo->fi_hdir;
13290 + AuDebugOn(!fidir);
13293 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13296 + p->fd_nent = nbr;
13297 + finfo->fi_hdir = p;
13304 +/* ---------------------------------------------------------------------- */
13306 +void au_finfo_fin(struct file *file)
13308 + struct au_finfo *finfo;
13310 + au_nfiles_dec(file->f_path.dentry->d_sb);
13312 + finfo = au_fi(file);
13313 + AuDebugOn(finfo->fi_hdir);
13314 + AuRwDestroy(&finfo->fi_rwsem);
13315 + au_cache_free_finfo(finfo);
13318 +void au_fi_init_once(void *_finfo)
13320 + struct au_finfo *finfo = _finfo;
13321 + static struct lock_class_key aufs_fi;
13323 + au_rw_init(&finfo->fi_rwsem);
13324 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
13327 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13330 + struct au_finfo *finfo;
13331 + struct dentry *dentry;
13334 + dentry = file->f_path.dentry;
13335 + finfo = au_cache_alloc_finfo();
13336 + if (unlikely(!finfo))
13340 + au_nfiles_inc(dentry->d_sb);
13341 + /* verbose coding for lock class name */
13343 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
13345 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
13346 + au_rw_write_lock(&finfo->fi_rwsem);
13347 + finfo->fi_btop = -1;
13348 + finfo->fi_hdir = fidir;
13349 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13350 + /* smp_mb(); */ /* atomic_set */
13352 + file->private_data = finfo;
13357 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13358 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13359 +++ linux/fs/aufs/f_op.c 2016-02-28 11:26:32.569971135 +0100
13362 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13364 + * This program, aufs is free software; you can redistribute it and/or modify
13365 + * it under the terms of the GNU General Public License as published by
13366 + * the Free Software Foundation; either version 2 of the License, or
13367 + * (at your option) any later version.
13369 + * This program is distributed in the hope that it will be useful,
13370 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13371 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13372 + * GNU General Public License for more details.
13374 + * You should have received a copy of the GNU General Public License
13375 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13379 + * file and vm operations
13382 +#include <linux/aio.h>
13383 +#include <linux/fs_stack.h>
13384 +#include <linux/mman.h>
13385 +#include <linux/security.h>
13388 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13391 + aufs_bindex_t bindex;
13392 + struct dentry *dentry, *h_dentry;
13393 + struct au_finfo *finfo;
13394 + struct inode *h_inode;
13396 + FiMustWriteLock(file);
13399 + dentry = file->f_path.dentry;
13400 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13401 + finfo = au_fi(file);
13402 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13403 + atomic_set(&finfo->fi_mmapped, 0);
13404 + bindex = au_dbstart(dentry);
13406 + h_dentry = au_h_dptr(dentry, bindex);
13407 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13408 + if (unlikely(err))
13410 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13412 + h_dentry = h_file->f_path.dentry;
13413 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13414 + if (unlikely(err))
13416 + get_file(h_file);
13418 + if (IS_ERR(h_file))
13419 + err = PTR_ERR(h_file);
13421 + if ((flags & __O_TMPFILE)
13422 + && !(flags & O_EXCL)) {
13423 + h_inode = file_inode(h_file);
13424 + spin_lock(&h_inode->i_lock);
13425 + h_inode->i_state |= I_LINKABLE;
13426 + spin_unlock(&h_inode->i_lock);
13428 + au_set_fbstart(file, bindex);
13429 + au_set_h_fptr(file, bindex, h_file);
13430 + au_update_figen(file);
13431 + /* todo: necessary? */
13432 + /* file->f_ra = h_file->f_ra; */
13439 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13440 + struct file *file)
13443 + struct super_block *sb;
13444 + struct au_do_open_args args = {
13445 + .open = au_do_open_nondir
13448 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13449 + file, vfsub_file_flags(file), file->f_mode);
13451 + sb = file->f_path.dentry->d_sb;
13452 + si_read_lock(sb, AuLock_FLUSH);
13453 + err = au_do_open(file, &args);
13454 + si_read_unlock(sb);
13458 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13460 + struct au_finfo *finfo;
13461 + aufs_bindex_t bindex;
13463 + finfo = au_fi(file);
13464 + au_sphl_del(&finfo->fi_hlist,
13465 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13466 + bindex = finfo->fi_btop;
13468 + au_set_h_fptr(file, bindex, NULL);
13470 + au_finfo_fin(file);
13474 +/* ---------------------------------------------------------------------- */
13476 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13479 + struct file *h_file;
13482 + h_file = au_hf_top(file);
13484 + err = vfsub_flush(h_file, id);
13488 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13490 + return au_do_flush(file, id, au_do_flush_nondir);
13493 +/* ---------------------------------------------------------------------- */
13495 + * read and write functions acquire [fdi]_rwsem once, but release before
13496 + * mmap_sem. This is because to stop a race condition between mmap(2).
13497 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13498 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13499 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13502 +/* Callers should call au_read_post() or fput() in the end */
13503 +struct file *au_read_pre(struct file *file, int keep_fi)
13505 + struct file *h_file;
13508 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13510 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13511 + h_file = au_hf_top(file);
13512 + get_file(h_file);
13514 + fi_read_unlock(file);
13516 + h_file = ERR_PTR(err);
13521 +static void au_read_post(struct inode *inode, struct file *h_file)
13523 + /* update without lock, I don't think it a problem */
13524 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13528 +struct au_write_pre {
13530 + aufs_bindex_t bstart;
13534 + * return with iinfo is write-locked
13535 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13538 +static struct file *au_write_pre(struct file *file, int do_ready,
13539 + struct au_write_pre *wpre)
13541 + struct file *h_file;
13542 + struct dentry *dentry;
13544 + struct au_pin pin;
13546 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13547 + h_file = ERR_PTR(err);
13548 + if (unlikely(err))
13551 + dentry = file->f_path.dentry;
13553 + err = au_ready_to_write(file, -1, &pin);
13554 + if (unlikely(err)) {
13555 + h_file = ERR_PTR(err);
13556 + di_write_unlock(dentry);
13561 + di_downgrade_lock(dentry, /*flags*/0);
13563 + wpre->bstart = au_fbstart(file);
13564 + h_file = au_hf_top(file);
13565 + get_file(h_file);
13567 + wpre->blks = file_inode(h_file)->i_blocks;
13570 + di_read_unlock(dentry, /*flags*/0);
13573 + fi_write_unlock(file);
13578 +static void au_write_post(struct inode *inode, struct file *h_file,
13579 + struct au_write_pre *wpre, ssize_t written)
13581 + struct inode *h_inode;
13583 + au_cpup_attr_timesizes(inode);
13584 + AuDebugOn(au_ibstart(inode) != wpre->bstart);
13585 + h_inode = file_inode(h_file);
13586 + inode->i_mode = h_inode->i_mode;
13587 + ii_write_unlock(inode);
13590 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13592 + au_fhsm_wrote(inode->i_sb, wpre->bstart,
13593 + /*force*/h_inode->i_blocks > wpre->blks);
13596 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13600 + struct inode *inode;
13601 + struct file *h_file;
13602 + struct super_block *sb;
13604 + inode = file_inode(file);
13605 + sb = inode->i_sb;
13606 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13608 + h_file = au_read_pre(file, /*keep_fi*/0);
13609 + err = PTR_ERR(h_file);
13610 + if (IS_ERR(h_file))
13613 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13614 + err = vfsub_read_u(h_file, buf, count, ppos);
13615 + /* todo: necessary? */
13616 + /* file->f_ra = h_file->f_ra; */
13617 + au_read_post(inode, h_file);
13620 + si_read_unlock(sb);
13625 + * todo: very ugly
13626 + * it locks both of i_mutex and si_rwsem for read in safe.
13627 + * if the plink maintenance mode continues forever (that is the problem),
13628 + * may loop forever.
13630 +static void au_mtx_and_read_lock(struct inode *inode)
13633 + struct super_block *sb = inode->i_sb;
13636 + mutex_lock(&inode->i_mutex);
13637 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13640 + mutex_unlock(&inode->i_mutex);
13641 + si_read_lock(sb, AuLock_NOPLMW);
13642 + si_read_unlock(sb);
13646 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13647 + size_t count, loff_t *ppos)
13650 + struct au_write_pre wpre;
13651 + struct inode *inode;
13652 + struct file *h_file;
13653 + char __user *buf = (char __user *)ubuf;
13655 + inode = file_inode(file);
13656 + au_mtx_and_read_lock(inode);
13658 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13659 + err = PTR_ERR(h_file);
13660 + if (IS_ERR(h_file))
13663 + err = vfsub_write_u(h_file, buf, count, ppos);
13664 + au_write_post(inode, h_file, &wpre, err);
13667 + si_read_unlock(inode->i_sb);
13668 + mutex_unlock(&inode->i_mutex);
13672 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13673 + struct iov_iter *iov_iter)
13676 + struct file *file;
13677 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13679 + err = security_file_permission(h_file, rw);
13680 + if (unlikely(err))
13685 + if (rw == MAY_READ)
13686 + iter = h_file->f_op->read_iter;
13687 + else if (rw == MAY_WRITE)
13688 + iter = h_file->f_op->write_iter;
13690 + file = kio->ki_filp;
13691 + kio->ki_filp = h_file;
13694 + err = iter(kio, iov_iter);
13697 + /* currently there is no such fs */
13699 + kio->ki_filp = file;
13705 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13708 + struct file *file, *h_file;
13709 + struct inode *inode;
13710 + struct super_block *sb;
13712 + file = kio->ki_filp;
13713 + inode = file_inode(file);
13714 + sb = inode->i_sb;
13715 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13717 + h_file = au_read_pre(file, /*keep_fi*/0);
13718 + err = PTR_ERR(h_file);
13719 + if (IS_ERR(h_file))
13722 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13723 + /* todo: necessary? */
13724 + /* file->f_ra = h_file->f_ra; */
13725 + au_read_post(inode, h_file);
13728 + si_read_unlock(sb);
13732 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13735 + struct au_write_pre wpre;
13736 + struct inode *inode;
13737 + struct file *file, *h_file;
13739 + file = kio->ki_filp;
13740 + inode = file_inode(file);
13741 + au_mtx_and_read_lock(inode);
13743 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13744 + err = PTR_ERR(h_file);
13745 + if (IS_ERR(h_file))
13748 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13749 + au_write_post(inode, h_file, &wpre, err);
13752 + si_read_unlock(inode->i_sb);
13753 + mutex_unlock(&inode->i_mutex);
13757 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13758 + struct pipe_inode_info *pipe, size_t len,
13759 + unsigned int flags)
13762 + struct file *h_file;
13763 + struct inode *inode;
13764 + struct super_block *sb;
13766 + inode = file_inode(file);
13767 + sb = inode->i_sb;
13768 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13770 + h_file = au_read_pre(file, /*keep_fi*/1);
13771 + err = PTR_ERR(h_file);
13772 + if (IS_ERR(h_file))
13775 + if (au_test_loopback_kthread()) {
13776 + au_warn_loopback(h_file->f_path.dentry->d_sb);
13777 + if (file->f_mapping != h_file->f_mapping) {
13778 + file->f_mapping = h_file->f_mapping;
13779 + smp_mb(); /* unnecessary? */
13782 + fi_read_unlock(file);
13784 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13785 + /* todo: necessasry? */
13786 + /* file->f_ra = h_file->f_ra; */
13787 + au_read_post(inode, h_file);
13790 + si_read_unlock(sb);
13795 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
13796 + size_t len, unsigned int flags)
13799 + struct au_write_pre wpre;
13800 + struct inode *inode;
13801 + struct file *h_file;
13803 + inode = file_inode(file);
13804 + au_mtx_and_read_lock(inode);
13806 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13807 + err = PTR_ERR(h_file);
13808 + if (IS_ERR(h_file))
13811 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
13812 + au_write_post(inode, h_file, &wpre, err);
13815 + si_read_unlock(inode->i_sb);
13816 + mutex_unlock(&inode->i_mutex);
13820 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
13824 + struct au_write_pre wpre;
13825 + struct inode *inode;
13826 + struct file *h_file;
13828 + inode = file_inode(file);
13829 + au_mtx_and_read_lock(inode);
13831 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13832 + err = PTR_ERR(h_file);
13833 + if (IS_ERR(h_file))
13837 + err = vfs_fallocate(h_file, mode, offset, len);
13839 + au_write_post(inode, h_file, &wpre, /*written*/1);
13842 + si_read_unlock(inode->i_sb);
13843 + mutex_unlock(&inode->i_mutex);
13847 +/* ---------------------------------------------------------------------- */
13850 + * The locking order around current->mmap_sem.
13851 + * - in most and regular cases
13852 + * file I/O syscall -- aufs_read() or something
13853 + * -- si_rwsem for read -- mmap_sem
13854 + * (Note that [fdi]i_rwsem are released before mmap_sem).
13856 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
13857 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
13858 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
13859 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
13860 + * It means that when aufs acquires si_rwsem for write, the process should never
13861 + * acquire mmap_sem.
13863 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
13864 + * problem either since any directory is not able to be mmap-ed.
13865 + * The similar scenario is applied to aufs_readlink() too.
13868 +#if 0 /* stop calling security_file_mmap() */
13869 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
13870 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
13872 +static unsigned long au_arch_prot_conv(unsigned long flags)
13874 + /* currently ppc64 only */
13875 +#ifdef CONFIG_PPC64
13876 + /* cf. linux/arch/powerpc/include/asm/mman.h */
13877 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
13878 + return AuConv_VM_PROT(flags, SAO);
13880 + AuDebugOn(arch_calc_vm_prot_bits(-1));
13885 +static unsigned long au_prot_conv(unsigned long flags)
13887 + return AuConv_VM_PROT(flags, READ)
13888 + | AuConv_VM_PROT(flags, WRITE)
13889 + | AuConv_VM_PROT(flags, EXEC)
13890 + | au_arch_prot_conv(flags);
13893 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
13894 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
13896 +static unsigned long au_flag_conv(unsigned long flags)
13898 + return AuConv_VM_MAP(flags, GROWSDOWN)
13899 + | AuConv_VM_MAP(flags, DENYWRITE)
13900 + | AuConv_VM_MAP(flags, LOCKED);
13904 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
13907 + const unsigned char wlock
13908 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
13909 + struct super_block *sb;
13910 + struct file *h_file;
13911 + struct inode *inode;
13913 + AuDbgVmRegion(file, vma);
13915 + inode = file_inode(file);
13916 + sb = inode->i_sb;
13918 + si_read_lock(sb, AuLock_NOPLMW);
13920 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
13922 + err = PTR_ERR(h_file);
13923 + if (IS_ERR(h_file))
13927 + au_set_mmapped(file);
13928 + au_vm_file_reset(vma, h_file);
13930 + * we cannot call security_mmap_file() here since it may acquire
13931 + * mmap_sem or i_mutex.
13933 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
13934 + * au_flag_conv(vma->vm_flags));
13937 + err = h_file->f_op->mmap(h_file, vma);
13939 + au_vm_prfile_set(vma, file);
13940 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13941 + goto out_fput; /* success */
13943 + au_unset_mmapped(file);
13944 + au_vm_file_reset(vma, file);
13948 + ii_write_unlock(inode);
13953 + si_read_unlock(sb);
13959 +/* ---------------------------------------------------------------------- */
13961 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
13965 + struct au_write_pre wpre;
13966 + struct inode *inode;
13967 + struct file *h_file;
13969 + err = 0; /* -EBADF; */ /* posix? */
13970 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13973 + inode = file_inode(file);
13974 + au_mtx_and_read_lock(inode);
13976 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13977 + err = PTR_ERR(h_file);
13978 + if (IS_ERR(h_file))
13981 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
13982 + au_write_post(inode, h_file, &wpre, /*written*/0);
13985 + si_read_unlock(inode->i_sb);
13986 + mutex_unlock(&inode->i_mutex);
13991 +/* no one supports this operation, currently */
13993 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
13996 + struct au_write_pre wpre;
13997 + struct inode *inode;
13998 + struct file *file, *h_file;
14000 + err = 0; /* -EBADF; */ /* posix? */
14001 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14004 + file = kio->ki_filp;
14005 + inode = file_inode(file);
14006 + au_mtx_and_read_lock(inode);
14008 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14009 + err = PTR_ERR(h_file);
14010 + if (IS_ERR(h_file))
14014 + h_file = au_hf_top(file);
14015 + if (h_file->f_op->aio_fsync) {
14016 + struct mutex *h_mtx;
14018 + h_mtx = &file_inode(h_file)->i_mutex;
14019 + if (!is_sync_kiocb(kio)) {
14020 + get_file(h_file);
14023 + kio->ki_filp = h_file;
14024 + err = h_file->f_op->aio_fsync(kio, datasync);
14025 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
14027 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
14029 + mutex_unlock(h_mtx);
14031 + au_write_post(inode, h_file, &wpre, /*written*/0);
14034 + si_read_unlock(inode->sb);
14035 + mutex_unlock(&inode->i_mutex);
14041 +static int aufs_fasync(int fd, struct file *file, int flag)
14044 + struct file *h_file;
14045 + struct super_block *sb;
14047 + sb = file->f_path.dentry->d_sb;
14048 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14050 + h_file = au_read_pre(file, /*keep_fi*/0);
14051 + err = PTR_ERR(h_file);
14052 + if (IS_ERR(h_file))
14055 + if (h_file->f_op->fasync)
14056 + err = h_file->f_op->fasync(fd, h_file, flag);
14057 + fput(h_file); /* instead of au_read_post() */
14060 + si_read_unlock(sb);
14064 +/* ---------------------------------------------------------------------- */
14066 +/* no one supports this operation, currently */
14068 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
14069 + size_t len, loff_t *pos, int more)
14074 +/* ---------------------------------------------------------------------- */
14076 +const struct file_operations aufs_file_fop = {
14077 + .owner = THIS_MODULE,
14079 + .llseek = default_llseek,
14081 + .read = aufs_read,
14082 + .write = aufs_write,
14083 + .read_iter = aufs_read_iter,
14084 + .write_iter = aufs_write_iter,
14086 +#ifdef CONFIG_AUFS_POLL
14087 + .poll = aufs_poll,
14089 + .unlocked_ioctl = aufs_ioctl_nondir,
14090 +#ifdef CONFIG_COMPAT
14091 + .compat_ioctl = aufs_compat_ioctl_nondir,
14093 + .mmap = aufs_mmap,
14094 + .open = aufs_open_nondir,
14095 + .flush = aufs_flush_nondir,
14096 + .release = aufs_release_nondir,
14097 + .fsync = aufs_fsync_nondir,
14098 + /* .aio_fsync = aufs_aio_fsync_nondir, */
14099 + .fasync = aufs_fasync,
14100 + /* .sendpage = aufs_sendpage, */
14101 + .splice_write = aufs_splice_write,
14102 + .splice_read = aufs_splice_read,
14104 + .aio_splice_write = aufs_aio_splice_write,
14105 + .aio_splice_read = aufs_aio_splice_read,
14107 + .fallocate = aufs_fallocate
14109 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14110 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14111 +++ linux/fs/aufs/fstype.h 2016-02-28 11:26:32.573304539 +0100
14114 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14116 + * This program, aufs is free software; you can redistribute it and/or modify
14117 + * it under the terms of the GNU General Public License as published by
14118 + * the Free Software Foundation; either version 2 of the License, or
14119 + * (at your option) any later version.
14121 + * This program is distributed in the hope that it will be useful,
14122 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14123 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14124 + * GNU General Public License for more details.
14126 + * You should have received a copy of the GNU General Public License
14127 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14131 + * judging filesystem type
14134 +#ifndef __AUFS_FSTYPE_H__
14135 +#define __AUFS_FSTYPE_H__
14139 +#include <linux/fs.h>
14140 +#include <linux/magic.h>
14141 +#include <linux/nfs_fs.h>
14142 +#include <linux/romfs_fs.h>
14144 +static inline int au_test_aufs(struct super_block *sb)
14146 + return sb->s_magic == AUFS_SUPER_MAGIC;
14149 +static inline const char *au_sbtype(struct super_block *sb)
14151 + return sb->s_type->name;
14154 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14156 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
14157 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14163 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14165 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
14166 + return sb->s_magic == ROMFS_MAGIC;
14172 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14174 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
14175 + return sb->s_magic == CRAMFS_MAGIC;
14180 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14182 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
14183 + return sb->s_magic == NFS_SUPER_MAGIC;
14189 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14191 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
14192 + return sb->s_magic == FUSE_SUPER_MAGIC;
14198 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14200 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
14201 + return sb->s_magic == XFS_SB_MAGIC;
14207 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14209 +#ifdef CONFIG_TMPFS
14210 + return sb->s_magic == TMPFS_MAGIC;
14216 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14218 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
14219 + return !strcmp(au_sbtype(sb), "ecryptfs");
14225 +static inline int au_test_ramfs(struct super_block *sb)
14227 + return sb->s_magic == RAMFS_MAGIC;
14230 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14232 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
14233 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14239 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14241 +#ifdef CONFIG_PROC_FS
14242 + return sb->s_magic == PROC_SUPER_MAGIC;
14248 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14250 +#ifdef CONFIG_SYSFS
14251 + return sb->s_magic == SYSFS_MAGIC;
14257 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14259 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
14260 + return sb->s_magic == CONFIGFS_MAGIC;
14266 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14268 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
14269 + return sb->s_magic == MINIX3_SUPER_MAGIC
14270 + || sb->s_magic == MINIX2_SUPER_MAGIC
14271 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14272 + || sb->s_magic == MINIX_SUPER_MAGIC
14273 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14279 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14281 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
14282 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14288 +static inline int au_test_msdos(struct super_block *sb)
14290 + return au_test_fat(sb);
14293 +static inline int au_test_vfat(struct super_block *sb)
14295 + return au_test_fat(sb);
14298 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14300 +#ifdef CONFIG_SECURITYFS
14301 + return sb->s_magic == SECURITYFS_MAGIC;
14307 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14309 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
14310 + return sb->s_magic == SQUASHFS_MAGIC;
14316 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14318 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
14319 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14325 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14327 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
14328 + return sb->s_magic == XENFS_SUPER_MAGIC;
14334 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14336 +#ifdef CONFIG_DEBUG_FS
14337 + return sb->s_magic == DEBUGFS_MAGIC;
14343 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14345 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
14346 + return sb->s_magic == NILFS_SUPER_MAGIC;
14352 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14354 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
14355 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14361 +/* ---------------------------------------------------------------------- */
14363 + * they can't be an aufs branch.
14365 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14368 +#ifndef CONFIG_AUFS_BR_RAMFS
14369 + au_test_ramfs(sb) ||
14371 + au_test_procfs(sb)
14372 + || au_test_sysfs(sb)
14373 + || au_test_configfs(sb)
14374 + || au_test_debugfs(sb)
14375 + || au_test_securityfs(sb)
14376 + || au_test_xenfs(sb)
14377 + || au_test_ecryptfs(sb)
14378 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14379 + || au_test_aufs(sb); /* will be supported in next version */
14382 +static inline int au_test_fs_remote(struct super_block *sb)
14384 + return !au_test_tmpfs(sb)
14385 +#ifdef CONFIG_AUFS_BR_RAMFS
14386 + && !au_test_ramfs(sb)
14388 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14391 +/* ---------------------------------------------------------------------- */
14394 + * Note: these functions (below) are created after reading ->getattr() in all
14395 + * filesystems under linux/fs. it means we have to do so in every update...
14399 + * some filesystems require getattr to refresh the inode attributes before
14401 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14402 + * and leave the work for d_revalidate()
14404 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14406 + return au_test_nfs(sb)
14407 + || au_test_fuse(sb)
14408 + /* || au_test_btrfs(sb) */ /* untested */
14413 + * filesystems which don't maintain i_size or i_blocks.
14415 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14417 + return au_test_xfs(sb)
14418 + || au_test_btrfs(sb)
14419 + || au_test_ubifs(sb)
14420 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14421 + /* || au_test_minix(sb) */ /* untested */
14426 + * filesystems which don't store the correct value in some of their inode
14429 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14431 + return au_test_fs_bad_iattr_size(sb)
14432 + || au_test_fat(sb)
14433 + || au_test_msdos(sb)
14434 + || au_test_vfat(sb);
14437 +/* they don't check i_nlink in link(2) */
14438 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14440 + return au_test_tmpfs(sb)
14441 +#ifdef CONFIG_AUFS_BR_RAMFS
14442 + || au_test_ramfs(sb)
14444 + || au_test_ubifs(sb)
14445 + || au_test_hfsplus(sb);
14449 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14451 +static inline int au_test_fs_notime(struct super_block *sb)
14453 + return au_test_nfs(sb)
14454 + || au_test_fuse(sb)
14455 + || au_test_ubifs(sb)
14459 +/* temporary support for i#1 in cramfs */
14460 +static inline int au_test_fs_unique_ino(struct inode *inode)
14462 + if (au_test_cramfs(inode->i_sb))
14463 + return inode->i_ino != 1;
14467 +/* ---------------------------------------------------------------------- */
14470 + * the filesystem where the xino files placed must support i/o after unlink and
14471 + * maintain i_size and i_blocks.
14473 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14475 + return au_test_fs_remote(sb)
14476 + || au_test_fs_bad_iattr_size(sb)
14477 + /* don't want unnecessary work for xino */
14478 + || au_test_aufs(sb)
14479 + || au_test_ecryptfs(sb)
14480 + || au_test_nilfs(sb);
14483 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14485 + return au_test_tmpfs(sb)
14486 + || au_test_ramfs(sb);
14490 + * test if the @sb is real-readonly.
14492 +static inline int au_test_fs_rr(struct super_block *sb)
14494 + return au_test_squashfs(sb)
14495 + || au_test_iso9660(sb)
14496 + || au_test_cramfs(sb)
14497 + || au_test_romfs(sb);
14501 + * test if the @inode is nfs with 'noacl' option
14502 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14504 +static inline int au_test_nfs_noacl(struct inode *inode)
14506 + return au_test_nfs(inode->i_sb)
14507 + /* && IS_POSIXACL(inode) */
14508 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14511 +#endif /* __KERNEL__ */
14512 +#endif /* __AUFS_FSTYPE_H__ */
14513 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14514 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14515 +++ linux/fs/aufs/hfsnotify.c 2016-02-28 11:26:32.573304539 +0100
14518 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14520 + * This program, aufs is free software; you can redistribute it and/or modify
14521 + * it under the terms of the GNU General Public License as published by
14522 + * the Free Software Foundation; either version 2 of the License, or
14523 + * (at your option) any later version.
14525 + * This program is distributed in the hope that it will be useful,
14526 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14527 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14528 + * GNU General Public License for more details.
14530 + * You should have received a copy of the GNU General Public License
14531 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14535 + * fsnotify for the lower directories
14540 +/* FS_IN_IGNORED is unnecessary */
14541 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14542 + | FS_CREATE | FS_EVENT_ON_CHILD);
14543 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14544 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14546 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14548 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14551 + au_cache_free_hnotify(hn);
14552 + smp_mb__before_atomic();
14553 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14554 + wake_up(&au_hfsn_wq);
14557 +static int au_hfsn_alloc(struct au_hinode *hinode)
14560 + struct au_hnotify *hn;
14561 + struct super_block *sb;
14562 + struct au_branch *br;
14563 + struct fsnotify_mark *mark;
14564 + aufs_bindex_t bindex;
14566 + hn = hinode->hi_notify;
14567 + sb = hn->hn_aufs_inode->i_sb;
14568 + bindex = au_br_index(sb, hinode->hi_id);
14569 + br = au_sbr(sb, bindex);
14570 + AuDebugOn(!br->br_hfsn);
14572 + mark = &hn->hn_mark;
14573 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14574 + mark->mask = AuHfsnMask;
14576 + * by udba rename or rmdir, aufs assign a new inode to the known
14577 + * h_inode, so specify 1 to allow dups.
14580 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14581 + /*mnt*/NULL, /*allow_dups*/1);
14582 + /* even if err */
14583 + fsnotify_put_mark(mark);
14589 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14591 + struct fsnotify_mark *mark;
14592 + unsigned long long ull;
14593 + struct fsnotify_group *group;
14595 + ull = atomic64_inc_return(&au_hfsn_ifree);
14598 + mark = &hn->hn_mark;
14599 + spin_lock(&mark->lock);
14600 + group = mark->group;
14601 + fsnotify_get_group(group);
14602 + spin_unlock(&mark->lock);
14604 + fsnotify_destroy_mark(mark, group);
14605 + fsnotify_put_group(group);
14608 + /* free hn by myself */
14612 +/* ---------------------------------------------------------------------- */
14614 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14616 + struct fsnotify_mark *mark;
14618 + mark = &hinode->hi_notify->hn_mark;
14619 + spin_lock(&mark->lock);
14621 + AuDebugOn(mark->mask & AuHfsnMask);
14622 + mark->mask |= AuHfsnMask;
14624 + AuDebugOn(!(mark->mask & AuHfsnMask));
14625 + mark->mask &= ~AuHfsnMask;
14627 + spin_unlock(&mark->lock);
14628 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14631 +/* ---------------------------------------------------------------------- */
14633 +/* #define AuDbgHnotify */
14634 +#ifdef AuDbgHnotify
14635 +static char *au_hfsn_name(u32 mask)
14637 +#ifdef CONFIG_AUFS_DEBUG
14638 +#define test_ret(flag) \
14640 + if (mask & flag) \
14643 + test_ret(FS_ACCESS);
14644 + test_ret(FS_MODIFY);
14645 + test_ret(FS_ATTRIB);
14646 + test_ret(FS_CLOSE_WRITE);
14647 + test_ret(FS_CLOSE_NOWRITE);
14648 + test_ret(FS_OPEN);
14649 + test_ret(FS_MOVED_FROM);
14650 + test_ret(FS_MOVED_TO);
14651 + test_ret(FS_CREATE);
14652 + test_ret(FS_DELETE);
14653 + test_ret(FS_DELETE_SELF);
14654 + test_ret(FS_MOVE_SELF);
14655 + test_ret(FS_UNMOUNT);
14656 + test_ret(FS_Q_OVERFLOW);
14657 + test_ret(FS_IN_IGNORED);
14658 + test_ret(FS_ISDIR);
14659 + test_ret(FS_IN_ONESHOT);
14660 + test_ret(FS_EVENT_ON_CHILD);
14669 +/* ---------------------------------------------------------------------- */
14671 +static void au_hfsn_free_group(struct fsnotify_group *group)
14673 + struct au_br_hfsnotify *hfsn = group->private;
14679 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14680 + struct inode *inode,
14681 + struct fsnotify_mark *inode_mark,
14682 + struct fsnotify_mark *vfsmount_mark,
14683 + u32 mask, void *data, int data_type,
14684 + const unsigned char *file_name, u32 cookie)
14687 + struct au_hnotify *hnotify;
14688 + struct inode *h_dir, *h_inode;
14689 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14691 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14694 + /* if FS_UNMOUNT happens, there must be another bug */
14695 + AuDebugOn(mask & FS_UNMOUNT);
14696 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14701 +#ifdef AuDbgHnotify
14703 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14704 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14705 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14706 + h_dir->i_ino, mask, au_hfsn_name(mask),
14707 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14708 + /* WARN_ON(1); */
14713 + AuDebugOn(!inode_mark);
14714 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14715 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14721 +static struct fsnotify_ops au_hfsn_ops = {
14722 + .handle_event = au_hfsn_handle_event,
14723 + .free_group_priv = au_hfsn_free_group
14726 +/* ---------------------------------------------------------------------- */
14728 +static void au_hfsn_fin_br(struct au_branch *br)
14730 + struct au_br_hfsnotify *hfsn;
14732 + hfsn = br->br_hfsn;
14735 + fsnotify_put_group(hfsn->hfsn_group);
14740 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14743 + struct fsnotify_group *group;
14744 + struct au_br_hfsnotify *hfsn;
14747 + br->br_hfsn = NULL;
14748 + if (!au_br_hnotifyable(perm))
14752 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14753 + if (unlikely(!hfsn))
14757 + group = fsnotify_alloc_group(&au_hfsn_ops);
14758 + if (IS_ERR(group)) {
14759 + err = PTR_ERR(group);
14760 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14764 + group->private = hfsn;
14765 + hfsn->hfsn_group = group;
14766 + br->br_hfsn = hfsn;
14767 + goto out; /* success */
14775 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14780 + if (!br->br_hfsn)
14781 + err = au_hfsn_init_br(br, perm);
14786 +/* ---------------------------------------------------------------------- */
14788 +static void au_hfsn_fin(void)
14790 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14791 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14794 +const struct au_hnotify_op au_hnotify_op = {
14795 + .ctl = au_hfsn_ctl,
14796 + .alloc = au_hfsn_alloc,
14797 + .free = au_hfsn_free,
14799 + .fin = au_hfsn_fin,
14801 + .reset_br = au_hfsn_reset_br,
14802 + .fin_br = au_hfsn_fin_br,
14803 + .init_br = au_hfsn_init_br
14805 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14806 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14807 +++ linux/fs/aufs/hfsplus.c 2016-02-28 11:26:32.573304539 +0100
14810 + * Copyright (C) 2010-2016 Junjiro R. Okajima
14812 + * This program, aufs is free software; you can redistribute it and/or modify
14813 + * it under the terms of the GNU General Public License as published by
14814 + * the Free Software Foundation; either version 2 of the License, or
14815 + * (at your option) any later version.
14817 + * This program is distributed in the hope that it will be useful,
14818 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14819 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14820 + * GNU General Public License for more details.
14822 + * You should have received a copy of the GNU General Public License
14823 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14827 + * special support for filesystems which aqucires an inode mutex
14828 + * at final closing a file, eg, hfsplus.
14830 + * This trick is very simple and stupid, just to open the file before really
14831 + * neceeary open to tell hfsplus that this is not the final closing.
14832 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14833 + * and au_h_open_post() after releasing it.
14838 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14841 + struct file *h_file;
14842 + struct dentry *h_dentry;
14844 + h_dentry = au_h_dptr(dentry, bindex);
14845 + AuDebugOn(!h_dentry);
14846 + AuDebugOn(d_is_negative(h_dentry));
14849 + if (au_test_hfsplus(h_dentry->d_sb)
14850 + && d_is_reg(h_dentry))
14851 + h_file = au_h_open(dentry, bindex,
14852 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14853 + /*file*/NULL, force_wr);
14857 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14858 + struct file *h_file)
14862 + au_sbr_put(dentry->d_sb, bindex);
14865 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
14866 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14867 +++ linux/fs/aufs/hnotify.c 2016-02-28 11:26:32.573304539 +0100
14870 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14872 + * This program, aufs is free software; you can redistribute it and/or modify
14873 + * it under the terms of the GNU General Public License as published by
14874 + * the Free Software Foundation; either version 2 of the License, or
14875 + * (at your option) any later version.
14877 + * This program is distributed in the hope that it will be useful,
14878 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14879 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14880 + * GNU General Public License for more details.
14882 + * You should have received a copy of the GNU General Public License
14883 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14887 + * abstraction to notify the direct changes on lower directories
14892 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14895 + struct au_hnotify *hn;
14898 + hn = au_cache_alloc_hnotify();
14900 + hn->hn_aufs_inode = inode;
14901 + hinode->hi_notify = hn;
14902 + err = au_hnotify_op.alloc(hinode);
14904 + if (unlikely(err)) {
14905 + hinode->hi_notify = NULL;
14906 + au_cache_free_hnotify(hn);
14908 + * The upper dir was removed by udba, but the same named
14909 + * dir left. In this case, aufs assignes a new inode
14910 + * number and set the monitor again.
14911 + * For the lower dir, the old monitnor is still left.
14913 + if (err == -EEXIST)
14922 +void au_hn_free(struct au_hinode *hinode)
14924 + struct au_hnotify *hn;
14926 + hn = hinode->hi_notify;
14928 + hinode->hi_notify = NULL;
14929 + if (au_hnotify_op.free(hinode, hn))
14930 + au_cache_free_hnotify(hn);
14934 +/* ---------------------------------------------------------------------- */
14936 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
14938 + if (hinode->hi_notify)
14939 + au_hnotify_op.ctl(hinode, do_set);
14942 +void au_hn_reset(struct inode *inode, unsigned int flags)
14944 + aufs_bindex_t bindex, bend;
14945 + struct inode *hi;
14946 + struct dentry *iwhdentry;
14948 + bend = au_ibend(inode);
14949 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14950 + hi = au_h_iptr(inode, bindex);
14954 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
14955 + iwhdentry = au_hi_wh(inode, bindex);
14959 + au_set_h_iptr(inode, bindex, NULL, 0);
14960 + au_set_h_iptr(inode, bindex, au_igrab(hi),
14961 + flags & ~AuHi_XINO);
14964 + /* mutex_unlock(&hi->i_mutex); */
14968 +/* ---------------------------------------------------------------------- */
14970 +static int hn_xino(struct inode *inode, struct inode *h_inode)
14973 + aufs_bindex_t bindex, bend, bfound, bstart;
14974 + struct inode *h_i;
14977 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14978 + pr_warn("branch root dir was changed\n");
14983 + bend = au_ibend(inode);
14984 + bstart = au_ibstart(inode);
14985 +#if 0 /* reserved for future use */
14986 + if (bindex == bend) {
14987 + /* keep this ino in rename case */
14991 + for (bindex = bstart; bindex <= bend; bindex++)
14992 + if (au_h_iptr(inode, bindex) == h_inode) {
14999 + for (bindex = bstart; bindex <= bend; bindex++) {
15000 + h_i = au_h_iptr(inode, bindex);
15004 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
15005 + /* ignore this error */
15006 + /* bad action? */
15009 + /* children inode number will be broken */
15016 +static int hn_gen_tree(struct dentry *dentry)
15018 + int err, i, j, ndentry;
15019 + struct au_dcsub_pages dpages;
15020 + struct au_dpage *dpage;
15021 + struct dentry **dentries;
15023 + err = au_dpages_init(&dpages, GFP_NOFS);
15024 + if (unlikely(err))
15026 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
15027 + if (unlikely(err))
15030 + for (i = 0; i < dpages.ndpage; i++) {
15031 + dpage = dpages.dpages + i;
15032 + dentries = dpage->dentries;
15033 + ndentry = dpage->ndentry;
15034 + for (j = 0; j < ndentry; j++) {
15035 + struct dentry *d;
15042 + if (d_really_is_positive(d))
15043 + /* todo: reset children xino?
15044 + cached children only? */
15045 + au_iigen_dec(d_inode(d));
15050 + au_dpages_free(&dpages);
15053 + /* discard children */
15054 + dentry_unhash(dentry);
15062 + * return 0 if processed.
15064 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
15065 + const unsigned int isdir)
15068 + struct dentry *d;
15069 + struct qstr *dname;
15072 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15073 + pr_warn("branch root dir was changed\n");
15079 + AuDebugOn(!name);
15080 + au_iigen_dec(inode);
15081 + spin_lock(&inode->i_lock);
15082 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
15083 + spin_lock(&d->d_lock);
15084 + dname = &d->d_name;
15085 + if (dname->len != nlen
15086 + && memcmp(dname->name, name, nlen)) {
15087 + spin_unlock(&d->d_lock);
15092 + spin_unlock(&d->d_lock);
15095 + spin_unlock(&inode->i_lock);
15097 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15098 + d = d_find_any_alias(inode);
15100 + au_iigen_dec(inode);
15104 + spin_lock(&d->d_lock);
15105 + dname = &d->d_name;
15106 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15107 + spin_unlock(&d->d_lock);
15108 + err = hn_gen_tree(d);
15109 + spin_lock(&d->d_lock);
15111 + spin_unlock(&d->d_lock);
15120 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15124 + if (IS_ROOT(dentry)) {
15125 + pr_warn("branch root dir was changed\n");
15131 + au_digen_dec(dentry);
15132 + if (d_really_is_positive(dentry))
15133 + au_iigen_dec(d_inode(dentry));
15135 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15136 + if (d_really_is_positive(dentry))
15137 + err = hn_gen_tree(dentry);
15144 +/* ---------------------------------------------------------------------- */
15146 +/* hnotify job flags */
15147 +#define AuHnJob_XINO0 1
15148 +#define AuHnJob_GEN (1 << 1)
15149 +#define AuHnJob_DIRENT (1 << 2)
15150 +#define AuHnJob_ISDIR (1 << 3)
15151 +#define AuHnJob_TRYXINO0 (1 << 4)
15152 +#define AuHnJob_MNTPNT (1 << 5)
15153 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15154 +#define au_fset_hnjob(flags, name) \
15155 + do { (flags) |= AuHnJob_##name; } while (0)
15156 +#define au_fclr_hnjob(flags, name) \
15157 + do { (flags) &= ~AuHnJob_##name; } while (0)
15165 +struct au_hnotify_args {
15166 + struct inode *h_dir, *dir, *h_child_inode;
15168 + unsigned int flags[AuHnLast];
15169 + unsigned int h_child_nlen;
15170 + char h_child_name[];
15173 +struct hn_job_args {
15174 + unsigned int flags;
15175 + struct inode *inode, *h_inode, *dir, *h_dir;
15176 + struct dentry *dentry;
15181 +static int hn_job(struct hn_job_args *a)
15183 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15187 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15188 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15190 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15193 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
15194 + if (!a->h_inode->i_nlink
15195 + && !(a->h_inode->i_state & I_LINKABLE))
15196 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15197 + mutex_unlock(&a->h_inode->i_mutex);
15200 + /* make the generation obsolete */
15201 + if (au_ftest_hnjob(a->flags, GEN)) {
15204 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15206 + if (e && a->dentry)
15207 + hn_gen_by_name(a->dentry, isdir);
15208 + /* ignore this error */
15211 + /* make dir entries obsolete */
15212 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15213 + struct au_vdir *vdir;
15215 + vdir = au_ivdir(a->inode);
15217 + vdir->vd_jiffy = 0;
15218 + /* IMustLock(a->inode); */
15219 + /* a->inode->i_version++; */
15222 + /* can do nothing but warn */
15223 + if (au_ftest_hnjob(a->flags, MNTPNT)
15225 + && d_mountpoint(a->dentry))
15226 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15231 +/* ---------------------------------------------------------------------- */
15233 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15234 + struct inode *dir)
15236 + struct dentry *dentry, *d, *parent;
15237 + struct qstr *dname;
15239 + parent = d_find_any_alias(dir);
15244 + spin_lock(&parent->d_lock);
15245 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15246 + /* AuDbg("%pd\n", d); */
15247 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15248 + dname = &d->d_name;
15249 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15250 + goto cont_unlock;
15254 + goto cont_unlock;
15255 + if (au_dcount(d) > 0) {
15256 + dentry = dget_dlock(d);
15257 + spin_unlock(&d->d_lock);
15262 + spin_unlock(&d->d_lock);
15264 + spin_unlock(&parent->d_lock);
15268 + di_write_lock_child(dentry);
15273 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15274 + aufs_bindex_t bindex, ino_t h_ino)
15276 + struct inode *inode;
15281 + err = au_xino_read(sb, bindex, h_ino, &ino);
15283 + inode = ilookup(sb, ino);
15287 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15288 + pr_warn("wrong root branch\n");
15294 + ii_write_lock_child(inode);
15300 +static void au_hn_bh(void *_args)
15302 + struct au_hnotify_args *a = _args;
15303 + struct super_block *sb;
15304 + aufs_bindex_t bindex, bend, bfound;
15305 + unsigned char xino, try_iput;
15307 + struct inode *inode;
15309 + struct hn_job_args args;
15310 + struct dentry *dentry;
15311 + struct au_sbinfo *sbinfo;
15313 + AuDebugOn(!_args);
15314 + AuDebugOn(!a->h_dir);
15315 + AuDebugOn(!a->dir);
15316 + AuDebugOn(!a->mask);
15317 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15318 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15319 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15324 + * do not lock a->dir->i_mutex here
15325 + * because of d_revalidate() may cause a deadlock.
15327 + sb = a->dir->i_sb;
15329 + sbinfo = au_sbi(sb);
15330 + AuDebugOn(!sbinfo);
15331 + si_write_lock(sb, AuLock_NOPLMW);
15333 + ii_read_lock_parent(a->dir);
15335 + bend = au_ibend(a->dir);
15336 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
15337 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15341 + ii_read_unlock(a->dir);
15342 + if (unlikely(bfound < 0))
15345 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15347 + if (a->h_child_inode)
15348 + h_ino = a->h_child_inode->i_ino;
15350 + if (a->h_child_nlen
15351 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15352 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15353 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15356 + if (dentry && d_really_is_positive(dentry))
15357 + inode = d_inode(dentry);
15358 + if (xino && !inode && h_ino
15359 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15360 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15361 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15362 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15366 + args.flags = a->flags[AuHn_CHILD];
15367 + args.dentry = dentry;
15368 + args.inode = inode;
15369 + args.h_inode = a->h_child_inode;
15370 + args.dir = a->dir;
15371 + args.h_dir = a->h_dir;
15372 + args.h_name = a->h_child_name;
15373 + args.h_nlen = a->h_child_nlen;
15374 + err = hn_job(&args);
15376 + if (au_di(dentry))
15377 + di_write_unlock(dentry);
15380 + if (inode && try_iput) {
15381 + ii_write_unlock(inode);
15385 + ii_write_lock_parent(a->dir);
15386 + args.flags = a->flags[AuHn_PARENT];
15387 + args.dentry = NULL;
15388 + args.inode = a->dir;
15389 + args.h_inode = a->h_dir;
15391 + args.h_dir = NULL;
15392 + args.h_name = NULL;
15394 + err = hn_job(&args);
15395 + ii_write_unlock(a->dir);
15398 + iput(a->h_child_inode);
15401 + si_write_unlock(sb);
15402 + au_nwt_done(&sbinfo->si_nowait);
15406 +/* ---------------------------------------------------------------------- */
15408 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15409 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15412 + unsigned int flags[AuHnLast], f;
15413 + unsigned char isdir, isroot, wh;
15414 + struct inode *dir;
15415 + struct au_hnotify_args *args;
15416 + char *p, *h_child_name;
15419 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15420 + dir = igrab(hnotify->hn_aufs_inode);
15424 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15426 + h_child_name = (void *)h_child_qstr->name;
15427 + len = h_child_qstr->len;
15428 + if (h_child_name) {
15429 + if (len > AUFS_WH_PFX_LEN
15430 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15431 + h_child_name += AUFS_WH_PFX_LEN;
15432 + len -= AUFS_WH_PFX_LEN;
15438 + if (h_child_inode)
15439 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15440 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15441 + flags[AuHn_CHILD] = 0;
15443 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15444 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15445 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15446 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15447 + case FS_MOVED_FROM:
15448 + case FS_MOVED_TO:
15449 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15450 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15453 + AuDebugOn(!h_child_name);
15458 + * aufs never be able to get this child inode.
15459 + * revalidation should be in d_revalidate()
15460 + * by checking i_nlink, i_generation or d_unhashed().
15462 + AuDebugOn(!h_child_name);
15463 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15464 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15472 + h_child_inode = NULL;
15475 + /* iput() and kfree() will be called in au_hnotify() */
15476 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15477 + if (unlikely(!args)) {
15478 + AuErr1("no memory\n");
15482 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15483 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15484 + args->mask = mask;
15486 + args->h_dir = igrab(h_dir);
15487 + if (h_child_inode)
15488 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15489 + args->h_child_inode = h_child_inode;
15490 + args->h_child_nlen = len;
15492 + p = (void *)args;
15493 + p += sizeof(*args);
15494 + memcpy(p, h_child_name, len);
15498 + /* NFS fires the event for silly-renamed one from kworker */
15500 + if (!dir->i_nlink
15501 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15503 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15504 + if (unlikely(err)) {
15505 + pr_err("wkq %d\n", err);
15506 + iput(args->h_child_inode);
15507 + iput(args->h_dir);
15516 +/* ---------------------------------------------------------------------- */
15518 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15522 + AuDebugOn(!(udba & AuOptMask_UDBA));
15525 + if (au_hnotify_op.reset_br)
15526 + err = au_hnotify_op.reset_br(udba, br, perm);
15531 +int au_hnotify_init_br(struct au_branch *br, int perm)
15536 + if (au_hnotify_op.init_br)
15537 + err = au_hnotify_op.init_br(br, perm);
15542 +void au_hnotify_fin_br(struct au_branch *br)
15544 + if (au_hnotify_op.fin_br)
15545 + au_hnotify_op.fin_br(br);
15548 +static void au_hn_destroy_cache(void)
15550 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15551 + au_cachep[AuCache_HNOTIFY] = NULL;
15554 +int __init au_hnotify_init(void)
15559 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15560 + if (au_cachep[AuCache_HNOTIFY]) {
15562 + if (au_hnotify_op.init)
15563 + err = au_hnotify_op.init();
15564 + if (unlikely(err))
15565 + au_hn_destroy_cache();
15571 +void au_hnotify_fin(void)
15573 + if (au_hnotify_op.fin)
15574 + au_hnotify_op.fin();
15575 + /* cf. au_cache_fin() */
15576 + if (au_cachep[AuCache_HNOTIFY])
15577 + au_hn_destroy_cache();
15579 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15580 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15581 +++ linux/fs/aufs/iinfo.c 2016-02-28 11:26:32.573304539 +0100
15584 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15586 + * This program, aufs is free software; you can redistribute it and/or modify
15587 + * it under the terms of the GNU General Public License as published by
15588 + * the Free Software Foundation; either version 2 of the License, or
15589 + * (at your option) any later version.
15591 + * This program is distributed in the hope that it will be useful,
15592 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15593 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15594 + * GNU General Public License for more details.
15596 + * You should have received a copy of the GNU General Public License
15597 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15601 + * inode private data
15606 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15608 + struct inode *h_inode;
15610 + IiMustAnyLock(inode);
15612 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
15613 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15617 +/* todo: hard/soft set? */
15618 +void au_hiput(struct au_hinode *hinode)
15620 + au_hn_free(hinode);
15621 + dput(hinode->hi_whdentry);
15622 + iput(hinode->hi_inode);
15625 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15627 + unsigned int flags;
15628 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15631 + if (au_opt_test(mnt_flags, XINO))
15632 + au_fset_hi(flags, XINO);
15633 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15634 + au_fset_hi(flags, HNOTIFY);
15638 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15639 + struct inode *h_inode, unsigned int flags)
15641 + struct au_hinode *hinode;
15642 + struct inode *hi;
15643 + struct au_iinfo *iinfo = au_ii(inode);
15645 + IiMustWriteLock(inode);
15647 + hinode = iinfo->ii_hinode + bindex;
15648 + hi = hinode->hi_inode;
15649 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15652 + au_hiput(hinode);
15653 + hinode->hi_inode = h_inode;
15656 + struct super_block *sb = inode->i_sb;
15657 + struct au_branch *br;
15659 + AuDebugOn(inode->i_mode
15660 + && (h_inode->i_mode & S_IFMT)
15661 + != (inode->i_mode & S_IFMT));
15662 + if (bindex == iinfo->ii_bstart)
15663 + au_cpup_igen(inode, h_inode);
15664 + br = au_sbr(sb, bindex);
15665 + hinode->hi_id = br->br_id;
15666 + if (au_ftest_hi(flags, XINO)) {
15667 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15669 + if (unlikely(err))
15670 + AuIOErr1("failed au_xino_write() %d\n", err);
15673 + if (au_ftest_hi(flags, HNOTIFY)
15674 + && au_br_hnotifyable(br->br_perm)) {
15675 + err = au_hn_alloc(hinode, inode);
15676 + if (unlikely(err))
15677 + AuIOErr1("au_hn_alloc() %d\n", err);
15682 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15683 + struct dentry *h_wh)
15685 + struct au_hinode *hinode;
15687 + IiMustWriteLock(inode);
15689 + hinode = au_ii(inode)->ii_hinode + bindex;
15690 + AuDebugOn(hinode->hi_whdentry);
15691 + hinode->hi_whdentry = h_wh;
15694 +void au_update_iigen(struct inode *inode, int half)
15696 + struct au_iinfo *iinfo;
15697 + struct au_iigen *iigen;
15698 + unsigned int sigen;
15700 + sigen = au_sigen(inode->i_sb);
15701 + iinfo = au_ii(inode);
15702 + iigen = &iinfo->ii_generation;
15703 + spin_lock(&iigen->ig_spin);
15704 + iigen->ig_generation = sigen;
15706 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15708 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15709 + spin_unlock(&iigen->ig_spin);
15712 +/* it may be called at remount time, too */
15713 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15715 + struct au_iinfo *iinfo;
15716 + aufs_bindex_t bindex, bend;
15718 + iinfo = au_ii(inode);
15722 + IiMustWriteLock(inode);
15724 + if (do_put_zero && iinfo->ii_bstart >= 0) {
15725 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15727 + struct inode *h_i;
15729 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
15732 + && !(h_i->i_state & I_LINKABLE))
15733 + au_set_h_iptr(inode, bindex, NULL, 0);
15737 + iinfo->ii_bstart = -1;
15738 + iinfo->ii_bend = -1;
15739 + bend = au_sbend(inode->i_sb);
15740 + for (bindex = 0; bindex <= bend; bindex++)
15741 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15742 + iinfo->ii_bstart = bindex;
15745 + if (iinfo->ii_bstart >= 0)
15746 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
15747 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15748 + iinfo->ii_bend = bindex;
15751 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
15754 +/* ---------------------------------------------------------------------- */
15756 +void au_icntnr_init_once(void *_c)
15758 + struct au_icntnr *c = _c;
15759 + struct au_iinfo *iinfo = &c->iinfo;
15760 + static struct lock_class_key aufs_ii;
15762 + spin_lock_init(&iinfo->ii_generation.ig_spin);
15763 + au_rw_init(&iinfo->ii_rwsem);
15764 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
15765 + inode_init_once(&c->vfs_inode);
15768 +int au_iinfo_init(struct inode *inode)
15770 + struct au_iinfo *iinfo;
15771 + struct super_block *sb;
15774 + sb = inode->i_sb;
15775 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15776 + nbr = au_sbend(sb) + 1;
15777 + if (unlikely(nbr <= 0))
15779 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15780 + if (iinfo->ii_hinode) {
15781 + au_ninodes_inc(sb);
15782 + for (i = 0; i < nbr; i++)
15783 + iinfo->ii_hinode[i].hi_id = -1;
15785 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15786 + iinfo->ii_bstart = -1;
15787 + iinfo->ii_bend = -1;
15788 + iinfo->ii_vdir = NULL;
15794 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
15797 + struct au_hinode *hip;
15799 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15802 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
15804 + sz = sizeof(*hip);
15805 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
15807 + iinfo->ii_hinode = hip;
15814 +void au_iinfo_fin(struct inode *inode)
15816 + struct au_iinfo *iinfo;
15817 + struct au_hinode *hi;
15818 + struct super_block *sb;
15819 + aufs_bindex_t bindex, bend;
15820 + const unsigned char unlinked = !inode->i_nlink;
15822 + iinfo = au_ii(inode);
15823 + /* bad_inode case */
15827 + sb = inode->i_sb;
15828 + au_ninodes_dec(sb);
15829 + if (si_pid_test(sb))
15830 + au_xino_delete_inode(inode, unlinked);
15833 + * it is safe to hide the dependency between sbinfo and
15837 + si_noflush_read_lock(sb);
15838 + au_xino_delete_inode(inode, unlinked);
15839 + si_read_unlock(sb);
15843 + if (iinfo->ii_vdir)
15844 + au_vdir_free(iinfo->ii_vdir);
15846 + bindex = iinfo->ii_bstart;
15847 + if (bindex >= 0) {
15848 + hi = iinfo->ii_hinode + bindex;
15849 + bend = iinfo->ii_bend;
15850 + while (bindex++ <= bend) {
15851 + if (hi->hi_inode)
15856 + kfree(iinfo->ii_hinode);
15857 + iinfo->ii_hinode = NULL;
15858 + AuRwDestroy(&iinfo->ii_rwsem);
15860 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
15861 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
15862 +++ linux/fs/aufs/inode.c 2016-02-28 11:26:32.573304539 +0100
15865 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15867 + * This program, aufs is free software; you can redistribute it and/or modify
15868 + * it under the terms of the GNU General Public License as published by
15869 + * the Free Software Foundation; either version 2 of the License, or
15870 + * (at your option) any later version.
15872 + * This program is distributed in the hope that it will be useful,
15873 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15874 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15875 + * GNU General Public License for more details.
15877 + * You should have received a copy of the GNU General Public License
15878 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15882 + * inode functions
15887 +struct inode *au_igrab(struct inode *inode)
15890 + AuDebugOn(!atomic_read(&inode->i_count));
15896 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
15898 + au_cpup_attr_all(inode, /*force*/0);
15899 + au_update_iigen(inode, /*half*/1);
15901 + inode->i_version++;
15904 +static int au_ii_refresh(struct inode *inode, int *update)
15908 + aufs_bindex_t bindex, new_bindex;
15909 + struct super_block *sb;
15910 + struct au_iinfo *iinfo;
15911 + struct au_hinode *p, *q, tmp;
15913 + IiMustWriteLock(inode);
15916 + sb = inode->i_sb;
15917 + type = inode->i_mode & S_IFMT;
15918 + iinfo = au_ii(inode);
15919 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
15920 + if (unlikely(err))
15923 + AuDebugOn(iinfo->ii_bstart < 0);
15924 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15925 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15927 + if (!p->hi_inode)
15930 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
15931 + new_bindex = au_br_index(sb, p->hi_id);
15932 + if (new_bindex == bindex)
15935 + if (new_bindex < 0) {
15938 + p->hi_inode = NULL;
15942 + if (new_bindex < iinfo->ii_bstart)
15943 + iinfo->ii_bstart = new_bindex;
15944 + if (iinfo->ii_bend < new_bindex)
15945 + iinfo->ii_bend = new_bindex;
15946 + /* swap two lower inode, and loop again */
15947 + q = iinfo->ii_hinode + new_bindex;
15951 + if (tmp.hi_inode) {
15956 + au_update_ibrange(inode, /*do_put_zero*/0);
15957 + e = au_dy_irefresh(inode);
15958 + if (unlikely(e && !err))
15966 +void au_refresh_iop(struct inode *inode, int force_getattr)
15969 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
15970 + const struct inode_operations *iop
15971 + = force_getattr ? aufs_iop : sbi->si_iop_array;
15973 + if (inode->i_op == iop)
15976 + switch (inode->i_mode & S_IFMT) {
15978 + type = AuIop_DIR;
15981 + type = AuIop_SYMLINK;
15984 + type = AuIop_OTHER;
15988 + inode->i_op = iop + type;
15989 + /* unnecessary smp_wmb() */
15992 +int au_refresh_hinode_self(struct inode *inode)
15996 + err = au_ii_refresh(inode, &update);
15998 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
16004 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
16006 + int err, e, update;
16007 + unsigned int flags;
16009 + aufs_bindex_t bindex, bend;
16010 + unsigned char isdir;
16011 + struct au_hinode *p;
16012 + struct au_iinfo *iinfo;
16014 + err = au_ii_refresh(inode, &update);
16015 + if (unlikely(err))
16019 + iinfo = au_ii(inode);
16020 + p = iinfo->ii_hinode + iinfo->ii_bstart;
16021 + mode = (inode->i_mode & S_IFMT);
16022 + isdir = S_ISDIR(mode);
16023 + flags = au_hi_flags(inode, isdir);
16024 + bend = au_dbend(dentry);
16025 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
16026 + struct inode *h_i, *h_inode;
16027 + struct dentry *h_d;
16029 + h_d = au_h_dptr(dentry, bindex);
16030 + if (!h_d || d_is_negative(h_d))
16033 + h_inode = d_inode(h_d);
16034 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
16035 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
16036 + h_i = au_h_iptr(inode, bindex);
16038 + if (h_i == h_inode)
16044 + if (bindex < iinfo->ii_bstart)
16045 + iinfo->ii_bstart = bindex;
16046 + if (iinfo->ii_bend < bindex)
16047 + iinfo->ii_bend = bindex;
16048 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
16051 + au_update_ibrange(inode, /*do_put_zero*/0);
16052 + e = au_dy_irefresh(inode);
16053 + if (unlikely(e && !err))
16056 + au_refresh_hinode_attr(inode, update && isdir);
16063 +static int set_inode(struct inode *inode, struct dentry *dentry)
16066 + unsigned int flags;
16068 + aufs_bindex_t bindex, bstart, btail;
16069 + unsigned char isdir;
16070 + struct dentry *h_dentry;
16071 + struct inode *h_inode;
16072 + struct au_iinfo *iinfo;
16073 + struct inode_operations *iop;
16075 + IiMustWriteLock(inode);
16079 + iop = au_sbi(inode->i_sb)->si_iop_array;
16080 + bstart = au_dbstart(dentry);
16081 + h_dentry = au_h_dptr(dentry, bstart);
16082 + h_inode = d_inode(h_dentry);
16083 + mode = h_inode->i_mode;
16084 + switch (mode & S_IFMT) {
16086 + btail = au_dbtail(dentry);
16087 + inode->i_op = iop + AuIop_OTHER;
16088 + inode->i_fop = &aufs_file_fop;
16089 + err = au_dy_iaop(inode, bstart, h_inode);
16090 + if (unlikely(err))
16095 + btail = au_dbtaildir(dentry);
16096 + inode->i_op = iop + AuIop_DIR;
16097 + inode->i_fop = &aufs_dir_fop;
16100 + btail = au_dbtail(dentry);
16101 + inode->i_op = iop + AuIop_SYMLINK;
16107 + btail = au_dbtail(dentry);
16108 + inode->i_op = iop + AuIop_OTHER;
16109 + init_special_inode(inode, mode, h_inode->i_rdev);
16112 + AuIOErr("Unknown file type 0%o\n", mode);
16117 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
16118 + flags = au_hi_flags(inode, isdir);
16119 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
16120 + && au_ftest_hi(flags, HNOTIFY)
16121 + && dentry->d_name.len > AUFS_WH_PFX_LEN
16122 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
16123 + au_fclr_hi(flags, HNOTIFY);
16124 + iinfo = au_ii(inode);
16125 + iinfo->ii_bstart = bstart;
16126 + iinfo->ii_bend = btail;
16127 + for (bindex = bstart; bindex <= btail; bindex++) {
16128 + h_dentry = au_h_dptr(dentry, bindex);
16130 + au_set_h_iptr(inode, bindex,
16131 + au_igrab(d_inode(h_dentry)), flags);
16133 + au_cpup_attr_all(inode, /*force*/1);
16135 + * to force calling aufs_get_acl() every time,
16136 + * do not call cache_no_acl() for aufs inode.
16144 + * successful returns with iinfo write_locked
16146 + * zero: success, matched
16147 + * plus: no error, but unmatched
16149 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16152 + unsigned int gen, igflags;
16153 + aufs_bindex_t bindex, bend;
16154 + struct inode *h_inode, *h_dinode;
16155 + struct dentry *h_dentry;
16158 + * before this function, if aufs got any iinfo lock, it must be only
16159 + * one, the parent dir.
16160 + * it can happen by UDBA and the obsoleted inode number.
16163 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16167 + ii_write_lock_new_child(inode);
16168 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
16169 + h_dinode = d_inode(h_dentry);
16170 + bend = au_ibend(inode);
16171 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
16172 + h_inode = au_h_iptr(inode, bindex);
16173 + if (!h_inode || h_inode != h_dinode)
16177 + gen = au_iigen(inode, &igflags);
16178 + if (gen == au_digen(dentry)
16179 + && !au_ig_ftest(igflags, HALF_REFRESHED))
16182 + /* fully refresh inode using dentry */
16183 + err = au_refresh_hinode(inode, dentry);
16185 + au_update_iigen(inode, /*half*/0);
16189 + if (unlikely(err))
16190 + ii_write_unlock(inode);
16195 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16196 + unsigned int d_type, ino_t *ino)
16199 + struct mutex *mtx;
16201 + /* prevent hardlinked inode number from race condition */
16203 + if (d_type != DT_DIR) {
16204 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16207 + err = au_xino_read(sb, bindex, h_ino, ino);
16208 + if (unlikely(err))
16213 + *ino = au_xino_new_ino(sb);
16214 + if (unlikely(!*ino))
16216 + err = au_xino_write(sb, bindex, h_ino, *ino);
16217 + if (unlikely(err))
16223 + mutex_unlock(mtx);
16227 +/* successful returns with iinfo write_locked */
16228 +/* todo: return with unlocked? */
16229 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16231 + struct inode *inode, *h_inode;
16232 + struct dentry *h_dentry;
16233 + struct super_block *sb;
16234 + struct mutex *mtx;
16235 + ino_t h_ino, ino;
16237 + aufs_bindex_t bstart;
16239 + sb = dentry->d_sb;
16240 + bstart = au_dbstart(dentry);
16241 + h_dentry = au_h_dptr(dentry, bstart);
16242 + h_inode = d_inode(h_dentry);
16243 + h_ino = h_inode->i_ino;
16246 + * stop 'race'-ing between hardlinks under different
16250 + if (!d_is_dir(h_dentry))
16251 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
16256 + err = au_xino_read(sb, bstart, h_ino, &ino);
16257 + inode = ERR_PTR(err);
16258 + if (unlikely(err))
16262 + ino = au_xino_new_ino(sb);
16263 + if (unlikely(!ino)) {
16264 + inode = ERR_PTR(-EIO);
16269 + AuDbg("i%lu\n", (unsigned long)ino);
16270 + inode = au_iget_locked(sb, ino);
16271 + err = PTR_ERR(inode);
16272 + if (IS_ERR(inode))
16275 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16276 + if (inode->i_state & I_NEW) {
16277 + /* verbose coding for lock class name */
16278 + if (unlikely(d_is_symlink(h_dentry)))
16279 + au_rw_class(&au_ii(inode)->ii_rwsem,
16280 + au_lc_key + AuLcSymlink_IIINFO);
16281 + else if (unlikely(d_is_dir(h_dentry)))
16282 + au_rw_class(&au_ii(inode)->ii_rwsem,
16283 + au_lc_key + AuLcDir_IIINFO);
16284 + else /* likely */
16285 + au_rw_class(&au_ii(inode)->ii_rwsem,
16286 + au_lc_key + AuLcNonDir_IIINFO);
16288 + ii_write_lock_new_child(inode);
16289 + err = set_inode(inode, dentry);
16291 + unlock_new_inode(inode);
16292 + goto out; /* success */
16296 + * iget_failed() calls iput(), but we need to call
16297 + * ii_write_unlock() after iget_failed(). so dirty hack for
16300 + atomic_inc(&inode->i_count);
16301 + iget_failed(inode);
16302 + ii_write_unlock(inode);
16303 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
16304 + /* ignore this error */
16306 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16308 + * horrible race condition between lookup, readdir and copyup
16309 + * (or something).
16312 + mutex_unlock(mtx);
16313 + err = reval_inode(inode, dentry);
16314 + if (unlikely(err < 0)) {
16321 + goto out; /* success */
16326 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16327 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16328 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16329 + bstart, au_sbtype(h_dentry->d_sb), dentry,
16330 + (unsigned long)h_ino, (unsigned long)ino);
16332 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
16336 + mutex_unlock(mtx);
16342 + inode = ERR_PTR(err);
16345 + mutex_unlock(mtx);
16349 +/* ---------------------------------------------------------------------- */
16351 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16352 + struct inode *inode)
16355 + struct inode *hi;
16357 + err = au_br_rdonly(au_sbr(sb, bindex));
16359 + /* pseudo-link after flushed may happen out of bounds */
16362 + && au_ibstart(inode) <= bindex
16363 + && bindex <= au_ibend(inode)) {
16365 + * permission check is unnecessary since vfsub routine
16366 + * will be called later
16368 + hi = au_h_iptr(inode, bindex);
16370 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16376 +int au_test_h_perm(struct inode *h_inode, int mask)
16378 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16380 + return inode_permission(h_inode, mask);
16383 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16385 + if (au_test_nfs(h_inode->i_sb)
16386 + && (mask & MAY_WRITE)
16387 + && S_ISDIR(h_inode->i_mode))
16388 + mask |= MAY_READ; /* force permission check */
16389 + return au_test_h_perm(h_inode, mask);
16391 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16392 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16393 +++ linux/fs/aufs/inode.h 2016-02-28 11:26:32.573304539 +0100
16396 + * Copyright (C) 2005-2016 Junjiro R. Okajima
16398 + * This program, aufs is free software; you can redistribute it and/or modify
16399 + * it under the terms of the GNU General Public License as published by
16400 + * the Free Software Foundation; either version 2 of the License, or
16401 + * (at your option) any later version.
16403 + * This program is distributed in the hope that it will be useful,
16404 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16405 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16406 + * GNU General Public License for more details.
16408 + * You should have received a copy of the GNU General Public License
16409 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16413 + * inode operations
16416 +#ifndef __AUFS_INODE_H__
16417 +#define __AUFS_INODE_H__
16421 +#include <linux/fsnotify.h>
16422 +#include "rwsem.h"
16426 +struct au_hnotify {
16427 +#ifdef CONFIG_AUFS_HNOTIFY
16428 +#ifdef CONFIG_AUFS_HFSNOTIFY
16429 + /* never use fsnotify_add_vfsmount_mark() */
16430 + struct fsnotify_mark hn_mark;
16432 + struct inode *hn_aufs_inode; /* no get/put */
16434 +} ____cacheline_aligned_in_smp;
16436 +struct au_hinode {
16437 + struct inode *hi_inode;
16438 + aufs_bindex_t hi_id;
16439 +#ifdef CONFIG_AUFS_HNOTIFY
16440 + struct au_hnotify *hi_notify;
16443 + /* reference to the copied-up whiteout with get/put */
16444 + struct dentry *hi_whdentry;
16448 +#define AuIG_HALF_REFRESHED 1
16449 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16450 +#define au_ig_fset(flags, name) \
16451 + do { (flags) |= AuIG_##name; } while (0)
16452 +#define au_ig_fclr(flags, name) \
16453 + do { (flags) &= ~AuIG_##name; } while (0)
16456 + spinlock_t ig_spin;
16457 + __u32 ig_generation, ig_flags;
16462 + struct au_iigen ii_generation;
16463 + struct super_block *ii_hsb1; /* no get/put */
16465 + struct au_rwsem ii_rwsem;
16466 + aufs_bindex_t ii_bstart, ii_bend;
16468 + struct au_hinode *ii_hinode;
16469 + struct au_vdir *ii_vdir;
16472 +struct au_icntnr {
16473 + struct au_iinfo iinfo;
16474 + struct inode vfs_inode;
16475 +} ____cacheline_aligned_in_smp;
16477 +/* au_pin flags */
16478 +#define AuPin_DI_LOCKED 1
16479 +#define AuPin_MNT_WRITE (1 << 1)
16480 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16481 +#define au_fset_pin(flags, name) \
16482 + do { (flags) |= AuPin_##name; } while (0)
16483 +#define au_fclr_pin(flags, name) \
16484 + do { (flags) &= ~AuPin_##name; } while (0)
16488 + struct dentry *dentry;
16489 + unsigned int udba;
16490 + unsigned char lsc_di, lsc_hi, flags;
16491 + aufs_bindex_t bindex;
16494 + struct dentry *parent;
16495 + struct au_hinode *hdir;
16496 + struct vfsmount *h_mnt;
16498 + /* temporary unlock/relock for copyup */
16499 + struct dentry *h_dentry, *h_parent;
16500 + struct au_branch *br;
16501 + struct task_struct *task;
16504 +void au_pin_hdir_unlock(struct au_pin *p);
16505 +int au_pin_hdir_lock(struct au_pin *p);
16506 +int au_pin_hdir_relock(struct au_pin *p);
16507 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
16508 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16509 +void au_pin_hdir_release(struct au_pin *p);
16511 +/* ---------------------------------------------------------------------- */
16513 +static inline struct au_iinfo *au_ii(struct inode *inode)
16515 + struct au_iinfo *iinfo;
16517 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16518 + if (iinfo->ii_hinode)
16520 + return NULL; /* debugging bad_inode case */
16523 +/* ---------------------------------------------------------------------- */
16526 +struct inode *au_igrab(struct inode *inode);
16527 +void au_refresh_iop(struct inode *inode, int force_getattr);
16528 +int au_refresh_hinode_self(struct inode *inode);
16529 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16530 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16531 + unsigned int d_type, ino_t *ino);
16532 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16533 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16534 + struct inode *inode);
16535 +int au_test_h_perm(struct inode *h_inode, int mask);
16536 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16538 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16539 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16541 +#ifdef CONFIG_AUFS_SHWH
16542 + return au_ino(sb, bindex, h_ino, d_type, ino);
16555 +extern struct inode_operations aufs_iop[AuIop_Last],
16556 + aufs_iop_nogetattr[AuIop_Last];
16558 +/* au_wr_dir flags */
16559 +#define AuWrDir_ADD_ENTRY 1
16560 +#define AuWrDir_ISDIR (1 << 1)
16561 +#define AuWrDir_TMPFILE (1 << 2)
16562 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16563 +#define au_fset_wrdir(flags, name) \
16564 + do { (flags) |= AuWrDir_##name; } while (0)
16565 +#define au_fclr_wrdir(flags, name) \
16566 + do { (flags) &= ~AuWrDir_##name; } while (0)
16568 +struct au_wr_dir_args {
16569 + aufs_bindex_t force_btgt;
16570 + unsigned char flags;
16572 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16573 + struct au_wr_dir_args *args);
16575 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16576 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16577 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16578 + unsigned int udba, unsigned char flags);
16579 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16580 + unsigned int udba, unsigned char flags) __must_check;
16581 +int au_do_pin(struct au_pin *pin) __must_check;
16582 +void au_unpin(struct au_pin *pin);
16583 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16585 +#define AuIcpup_DID_CPUP 1
16586 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16587 +#define au_fset_icpup(flags, name) \
16588 + do { (flags) |= AuIcpup_##name; } while (0)
16589 +#define au_fclr_icpup(flags, name) \
16590 + do { (flags) &= ~AuIcpup_##name; } while (0)
16592 +struct au_icpup_args {
16593 + unsigned char flags;
16594 + unsigned char pin_flags;
16595 + aufs_bindex_t btgt;
16596 + unsigned int udba;
16597 + struct au_pin pin;
16598 + struct path h_path;
16599 + struct inode *h_inode;
16602 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16603 + struct au_icpup_args *a);
16605 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16608 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16609 + struct dentry *h_parent, int isdir);
16610 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16612 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16613 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16615 +struct vfsub_aopen_args;
16616 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
16617 + struct vfsub_aopen_args *args);
16618 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16619 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16620 + struct dentry *dentry);
16621 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16624 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16625 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16626 + struct dentry *h_parent, int isdir);
16627 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16628 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16631 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16632 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16633 + struct inode *dir, struct dentry *dentry);
16636 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16637 +void au_hiput(struct au_hinode *hinode);
16638 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16639 + struct dentry *h_wh);
16640 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16642 +/* hinode flags */
16643 +#define AuHi_XINO 1
16644 +#define AuHi_HNOTIFY (1 << 1)
16645 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16646 +#define au_fset_hi(flags, name) \
16647 + do { (flags) |= AuHi_##name; } while (0)
16648 +#define au_fclr_hi(flags, name) \
16649 + do { (flags) &= ~AuHi_##name; } while (0)
16651 +#ifndef CONFIG_AUFS_HNOTIFY
16652 +#undef AuHi_HNOTIFY
16653 +#define AuHi_HNOTIFY 0
16656 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16657 + struct inode *h_inode, unsigned int flags);
16659 +void au_update_iigen(struct inode *inode, int half);
16660 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16662 +void au_icntnr_init_once(void *_c);
16663 +int au_iinfo_init(struct inode *inode);
16664 +void au_iinfo_fin(struct inode *inode);
16665 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
16667 +#ifdef CONFIG_PROC_FS
16669 +int au_plink_maint(struct super_block *sb, int flags);
16671 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16672 +int au_plink_maint_enter(struct super_block *sb);
16673 +#ifdef CONFIG_AUFS_DEBUG
16674 +void au_plink_list(struct super_block *sb);
16676 +AuStubVoid(au_plink_list, struct super_block *sb)
16678 +int au_plink_test(struct inode *inode);
16679 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16680 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16681 + struct dentry *h_dentry);
16682 +void au_plink_put(struct super_block *sb, int verbose);
16683 +void au_plink_clean(struct super_block *sb, int verbose);
16684 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16686 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16687 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16688 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16689 +AuStubVoid(au_plink_list, struct super_block *sb);
16690 +AuStubInt0(au_plink_test, struct inode *inode);
16691 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16692 + struct inode *inode, aufs_bindex_t bindex);
16693 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16694 + struct dentry *h_dentry);
16695 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16696 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16697 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16698 +#endif /* CONFIG_PROC_FS */
16700 +#ifdef CONFIG_AUFS_XATTR
16702 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
16703 + unsigned int verbose);
16704 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16705 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
16707 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
16708 + size_t size, int flags);
16709 +int aufs_removexattr(struct dentry *dentry, const char *name);
16711 +/* void au_xattr_init(struct super_block *sb); */
16713 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16714 + int ignore_flags, unsigned int verbose);
16715 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
16718 +#ifdef CONFIG_FS_POSIX_ACL
16719 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16720 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16723 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16730 +struct au_srxattr {
16734 + const char *name;
16735 + const void *value;
16740 + const char *name;
16743 + struct posix_acl *acl;
16748 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg);
16751 +/* ---------------------------------------------------------------------- */
16753 +/* lock subclass for iinfo */
16755 + AuLsc_II_CHILD, /* child first */
16756 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16757 + AuLsc_II_CHILD3, /* copyup dirs */
16758 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16759 + AuLsc_II_PARENT2,
16760 + AuLsc_II_PARENT3, /* copyup dirs */
16761 + AuLsc_II_NEW_CHILD
16765 + * ii_read_lock_child, ii_write_lock_child,
16766 + * ii_read_lock_child2, ii_write_lock_child2,
16767 + * ii_read_lock_child3, ii_write_lock_child3,
16768 + * ii_read_lock_parent, ii_write_lock_parent,
16769 + * ii_read_lock_parent2, ii_write_lock_parent2,
16770 + * ii_read_lock_parent3, ii_write_lock_parent3,
16771 + * ii_read_lock_new_child, ii_write_lock_new_child,
16773 +#define AuReadLockFunc(name, lsc) \
16774 +static inline void ii_read_lock_##name(struct inode *i) \
16776 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16779 +#define AuWriteLockFunc(name, lsc) \
16780 +static inline void ii_write_lock_##name(struct inode *i) \
16782 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16785 +#define AuRWLockFuncs(name, lsc) \
16786 + AuReadLockFunc(name, lsc) \
16787 + AuWriteLockFunc(name, lsc)
16789 +AuRWLockFuncs(child, CHILD);
16790 +AuRWLockFuncs(child2, CHILD2);
16791 +AuRWLockFuncs(child3, CHILD3);
16792 +AuRWLockFuncs(parent, PARENT);
16793 +AuRWLockFuncs(parent2, PARENT2);
16794 +AuRWLockFuncs(parent3, PARENT3);
16795 +AuRWLockFuncs(new_child, NEW_CHILD);
16797 +#undef AuReadLockFunc
16798 +#undef AuWriteLockFunc
16799 +#undef AuRWLockFuncs
16802 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
16804 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
16806 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
16807 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
16808 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
16810 +/* ---------------------------------------------------------------------- */
16812 +static inline void au_icntnr_init(struct au_icntnr *c)
16814 +#ifdef CONFIG_AUFS_DEBUG
16815 + c->vfs_inode.i_mode = 0;
16819 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
16821 + unsigned int gen;
16822 + struct au_iinfo *iinfo;
16823 + struct au_iigen *iigen;
16825 + iinfo = au_ii(inode);
16826 + iigen = &iinfo->ii_generation;
16827 + spin_lock(&iigen->ig_spin);
16829 + *igflags = iigen->ig_flags;
16830 + gen = iigen->ig_generation;
16831 + spin_unlock(&iigen->ig_spin);
16836 +/* tiny test for inode number */
16837 +/* tmpfs generation is too rough */
16838 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
16840 + struct au_iinfo *iinfo;
16842 + iinfo = au_ii(inode);
16843 + AuRwMustAnyLock(&iinfo->ii_rwsem);
16844 + return !(iinfo->ii_hsb1 == h_inode->i_sb
16845 + && iinfo->ii_higen == h_inode->i_generation);
16848 +static inline void au_iigen_dec(struct inode *inode)
16850 + struct au_iinfo *iinfo;
16851 + struct au_iigen *iigen;
16853 + iinfo = au_ii(inode);
16854 + iigen = &iinfo->ii_generation;
16855 + spin_lock(&iigen->ig_spin);
16856 + iigen->ig_generation--;
16857 + spin_unlock(&iigen->ig_spin);
16860 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
16865 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
16871 +/* ---------------------------------------------------------------------- */
16873 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
16874 + aufs_bindex_t bindex)
16876 + IiMustAnyLock(inode);
16877 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
16880 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
16882 + IiMustAnyLock(inode);
16883 + return au_ii(inode)->ii_bstart;
16886 +static inline aufs_bindex_t au_ibend(struct inode *inode)
16888 + IiMustAnyLock(inode);
16889 + return au_ii(inode)->ii_bend;
16892 +static inline struct au_vdir *au_ivdir(struct inode *inode)
16894 + IiMustAnyLock(inode);
16895 + return au_ii(inode)->ii_vdir;
16898 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
16900 + IiMustAnyLock(inode);
16901 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
16904 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
16906 + IiMustWriteLock(inode);
16907 + au_ii(inode)->ii_bstart = bindex;
16910 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
16912 + IiMustWriteLock(inode);
16913 + au_ii(inode)->ii_bend = bindex;
16916 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
16918 + IiMustWriteLock(inode);
16919 + au_ii(inode)->ii_vdir = vdir;
16922 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
16924 + IiMustAnyLock(inode);
16925 + return au_ii(inode)->ii_hinode + bindex;
16928 +/* ---------------------------------------------------------------------- */
16930 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
16933 + return pin->parent;
16937 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
16939 + if (pin && pin->hdir)
16940 + return pin->hdir->hi_inode;
16944 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
16947 + return pin->hdir;
16951 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
16954 + pin->dentry = dentry;
16957 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
16958 + unsigned char lflag)
16962 + au_fset_pin(pin->flags, DI_LOCKED);
16964 + au_fclr_pin(pin->flags, DI_LOCKED);
16968 +#if 0 /* reserved */
16969 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
16972 + dput(pin->parent);
16973 + pin->parent = dget(parent);
16978 +/* ---------------------------------------------------------------------- */
16981 +#ifdef CONFIG_AUFS_HNOTIFY
16982 +struct au_hnotify_op {
16983 + void (*ctl)(struct au_hinode *hinode, int do_set);
16984 + int (*alloc)(struct au_hinode *hinode);
16987 + * if it returns true, the the caller should free hinode->hi_notify,
16988 + * otherwise ->free() frees it.
16990 + int (*free)(struct au_hinode *hinode,
16991 + struct au_hnotify *hn) __must_check;
16993 + void (*fin)(void);
16994 + int (*init)(void);
16996 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
16997 + void (*fin_br)(struct au_branch *br);
16998 + int (*init_br)(struct au_branch *br, int perm);
17002 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
17003 +void au_hn_free(struct au_hinode *hinode);
17004 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
17005 +void au_hn_reset(struct inode *inode, unsigned int flags);
17006 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17007 + struct qstr *h_child_qstr, struct inode *h_child_inode);
17008 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
17009 +int au_hnotify_init_br(struct au_branch *br, int perm);
17010 +void au_hnotify_fin_br(struct au_branch *br);
17011 +int __init au_hnotify_init(void);
17012 +void au_hnotify_fin(void);
17015 +extern const struct au_hnotify_op au_hnotify_op;
17018 +void au_hn_init(struct au_hinode *hinode)
17020 + hinode->hi_notify = NULL;
17023 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
17025 + return hinode->hi_notify;
17029 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
17030 + struct au_hinode *hinode __maybe_unused,
17031 + struct inode *inode __maybe_unused)
17032 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
17033 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
17034 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
17035 + int do_set __maybe_unused)
17036 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
17037 + unsigned int flags __maybe_unused)
17038 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
17039 + struct au_branch *br __maybe_unused,
17040 + int perm __maybe_unused)
17041 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
17042 + int perm __maybe_unused)
17043 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
17044 +AuStubInt0(__init au_hnotify_init, void)
17045 +AuStubVoid(au_hnotify_fin, void)
17046 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
17047 +#endif /* CONFIG_AUFS_HNOTIFY */
17049 +static inline void au_hn_suspend(struct au_hinode *hdir)
17051 + au_hn_ctl(hdir, /*do_set*/0);
17054 +static inline void au_hn_resume(struct au_hinode *hdir)
17056 + au_hn_ctl(hdir, /*do_set*/1);
17059 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
17061 + mutex_lock(&hdir->hi_inode->i_mutex);
17062 + au_hn_suspend(hdir);
17065 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
17066 + unsigned int sc __maybe_unused)
17068 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
17069 + au_hn_suspend(hdir);
17072 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
17074 + au_hn_resume(hdir);
17075 + mutex_unlock(&hdir->hi_inode->i_mutex);
17078 +#endif /* __KERNEL__ */
17079 +#endif /* __AUFS_INODE_H__ */
17080 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
17081 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
17082 +++ linux/fs/aufs/ioctl.c 2016-02-28 11:26:32.573304539 +0100
17085 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17087 + * This program, aufs is free software; you can redistribute it and/or modify
17088 + * it under the terms of the GNU General Public License as published by
17089 + * the Free Software Foundation; either version 2 of the License, or
17090 + * (at your option) any later version.
17092 + * This program is distributed in the hope that it will be useful,
17093 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17094 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17095 + * GNU General Public License for more details.
17097 + * You should have received a copy of the GNU General Public License
17098 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17103 + * plink-management and readdir in userspace.
17104 + * assist the pathconf(3) wrapper library.
17106 + * File-based Hierarchical Storage Management.
17109 +#include <linux/compat.h>
17110 +#include <linux/file.h>
17113 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
17116 + aufs_bindex_t wbi, bindex, bend;
17117 + struct file *h_file;
17118 + struct super_block *sb;
17119 + struct dentry *root;
17120 + struct au_branch *br;
17121 + struct aufs_wbr_fd wbrfd = {
17122 + .oflags = au_dir_roflags,
17125 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17126 + | O_NOATIME | O_CLOEXEC;
17128 + AuDebugOn(wbrfd.oflags & ~valid);
17131 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17132 + if (unlikely(err)) {
17138 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17139 + wbrfd.oflags |= au_dir_roflags;
17140 + AuDbg("0%o\n", wbrfd.oflags);
17141 + if (unlikely(wbrfd.oflags & ~valid))
17145 + fd = get_unused_fd_flags(0);
17147 + if (unlikely(fd < 0))
17150 + h_file = ERR_PTR(-EINVAL);
17153 + sb = path->dentry->d_sb;
17154 + root = sb->s_root;
17155 + aufs_read_lock(root, AuLock_IR);
17156 + bend = au_sbend(sb);
17157 + if (wbrfd.brid >= 0) {
17158 + wbi = au_br_index(sb, wbrfd.brid);
17159 + if (unlikely(wbi < 0 || wbi > bend))
17163 + h_file = ERR_PTR(-ENOENT);
17164 + br = au_sbr(sb, wbi);
17165 + if (!au_br_writable(br->br_perm)) {
17169 + bindex = wbi + 1;
17171 + for (; bindex <= bend; bindex++) {
17172 + br = au_sbr(sb, bindex);
17173 + if (au_br_writable(br->br_perm)) {
17175 + br = au_sbr(sb, wbi);
17180 + AuDbg("wbi %d\n", wbi);
17182 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17186 + aufs_read_unlock(root, AuLock_IR);
17187 + err = PTR_ERR(h_file);
17188 + if (IS_ERR(h_file))
17191 + atomic_dec(&br->br_count); /* cf. au_h_open() */
17192 + fd_install(fd, h_file);
17194 + goto out; /* success */
17197 + put_unused_fd(fd);
17203 +/* ---------------------------------------------------------------------- */
17205 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17208 + struct dentry *dentry;
17211 + case AUFS_CTL_RDU:
17212 + case AUFS_CTL_RDU_INO:
17213 + err = au_rdu_ioctl(file, cmd, arg);
17216 + case AUFS_CTL_WBR_FD:
17217 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17220 + case AUFS_CTL_IBUSY:
17221 + err = au_ibusy_ioctl(file, arg);
17224 + case AUFS_CTL_BRINFO:
17225 + err = au_brinfo_ioctl(file, arg);
17228 + case AUFS_CTL_FHSM_FD:
17229 + dentry = file->f_path.dentry;
17230 + if (IS_ROOT(dentry))
17231 + err = au_fhsm_fd(dentry->d_sb, arg);
17237 + /* do not call the lower */
17238 + AuDbg("0x%x\n", cmd);
17246 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17251 + case AUFS_CTL_MVDOWN:
17252 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17255 + case AUFS_CTL_WBR_FD:
17256 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17260 + /* do not call the lower */
17261 + AuDbg("0x%x\n", cmd);
17269 +#ifdef CONFIG_COMPAT
17270 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17271 + unsigned long arg)
17276 + case AUFS_CTL_RDU:
17277 + case AUFS_CTL_RDU_INO:
17278 + err = au_rdu_compat_ioctl(file, cmd, arg);
17281 + case AUFS_CTL_IBUSY:
17282 + err = au_ibusy_compat_ioctl(file, arg);
17285 + case AUFS_CTL_BRINFO:
17286 + err = au_brinfo_compat_ioctl(file, arg);
17290 + err = aufs_ioctl_dir(file, cmd, arg);
17297 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17298 + unsigned long arg)
17300 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17303 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17304 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17305 +++ linux/fs/aufs/i_op_add.c 2016-02-28 11:26:32.573304539 +0100
17308 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17310 + * This program, aufs is free software; you can redistribute it and/or modify
17311 + * it under the terms of the GNU General Public License as published by
17312 + * the Free Software Foundation; either version 2 of the License, or
17313 + * (at your option) any later version.
17315 + * This program is distributed in the hope that it will be useful,
17316 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17317 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17318 + * GNU General Public License for more details.
17320 + * You should have received a copy of the GNU General Public License
17321 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17325 + * inode operations (add entry)
17331 + * final procedure of adding a new entry, except link(2).
17332 + * remove whiteout, instantiate, copyup the parent dir's times and size
17333 + * and update version.
17334 + * if it failed, re-create the removed whiteout.
17336 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17337 + struct dentry *wh_dentry, struct dentry *dentry)
17340 + aufs_bindex_t bwh;
17341 + struct path h_path;
17342 + struct super_block *sb;
17343 + struct inode *inode, *h_dir;
17344 + struct dentry *wh;
17349 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17350 + IMustLock(h_dir);
17351 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17352 + bwh = au_dbwh(dentry);
17353 + h_path.dentry = wh_dentry;
17354 + h_path.mnt = au_sbr_mnt(sb, bindex);
17355 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17357 + if (unlikely(err))
17361 + inode = au_new_inode(dentry, /*must_new*/1);
17362 + if (!IS_ERR(inode)) {
17363 + d_instantiate(dentry, inode);
17364 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17366 + au_dir_ts(dir, bindex);
17367 + dir->i_version++;
17368 + au_fhsm_wrote(sb, bindex, /*force*/0);
17369 + return 0; /* success */
17372 + err = PTR_ERR(inode);
17377 + /* dir inode is locked */
17378 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17379 + rerr = PTR_ERR(wh);
17380 + if (IS_ERR(wh)) {
17381 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17382 + dentry, err, rerr);
17391 +static int au_d_may_add(struct dentry *dentry)
17396 + if (unlikely(d_unhashed(dentry)))
17398 + if (unlikely(d_really_is_positive(dentry)))
17404 + * simple tests for the adding inode operations.
17405 + * following the checks in vfs, plus the parent-child relationship.
17407 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17408 + struct dentry *h_parent, int isdir)
17412 + struct dentry *h_dentry;
17413 + struct inode *h_inode;
17415 + err = -ENAMETOOLONG;
17416 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17419 + h_dentry = au_h_dptr(dentry, bindex);
17420 + if (d_really_is_negative(dentry)) {
17422 + if (unlikely(d_is_positive(h_dentry)))
17425 + /* rename(2) case */
17427 + if (unlikely(d_is_negative(h_dentry)))
17429 + h_inode = d_inode(h_dentry);
17430 + if (unlikely(!h_inode->i_nlink))
17433 + h_mode = h_inode->i_mode;
17436 + if (unlikely(S_ISDIR(h_mode)))
17438 + } else if (unlikely(!S_ISDIR(h_mode))) {
17445 + /* expected parent dir is locked */
17446 + if (unlikely(h_parent != h_dentry->d_parent))
17455 + * initial procedure of adding a new entry.
17456 + * prepare writable branch and the parent dir, lock it,
17457 + * and lookup whiteout for the new entry.
17459 +static struct dentry*
17460 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17461 + struct dentry *src_dentry, struct au_pin *pin,
17462 + struct au_wr_dir_args *wr_dir_args)
17464 + struct dentry *wh_dentry, *h_parent;
17465 + struct super_block *sb;
17466 + struct au_branch *br;
17468 + unsigned int udba;
17469 + aufs_bindex_t bcpup;
17471 + AuDbg("%pd\n", dentry);
17473 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17475 + wh_dentry = ERR_PTR(err);
17476 + if (unlikely(err < 0))
17479 + sb = dentry->d_sb;
17480 + udba = au_opt_udba(sb);
17481 + err = au_pin(pin, dentry, bcpup, udba,
17482 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17483 + wh_dentry = ERR_PTR(err);
17484 + if (unlikely(err))
17487 + h_parent = au_pinned_h_parent(pin);
17488 + if (udba != AuOpt_UDBA_NONE
17489 + && au_dbstart(dentry) == bcpup)
17490 + err = au_may_add(dentry, bcpup, h_parent,
17491 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17492 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17493 + err = -ENAMETOOLONG;
17494 + wh_dentry = ERR_PTR(err);
17495 + if (unlikely(err))
17498 + br = au_sbr(sb, bcpup);
17500 + struct path tmp = {
17501 + .dentry = h_parent,
17502 + .mnt = au_br_mnt(br)
17504 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17507 + wh_dentry = NULL;
17508 + if (bcpup != au_dbwh(dentry))
17509 + goto out; /* success */
17512 + * ENAMETOOLONG here means that if we allowed create such name, then it
17513 + * would not be able to removed in the future. So we don't allow such
17514 + * name here and we don't handle ENAMETOOLONG differently here.
17516 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17519 + if (IS_ERR(wh_dentry))
17522 + return wh_dentry;
17525 +/* ---------------------------------------------------------------------- */
17527 +enum { Mknod, Symlink, Creat };
17528 +struct simple_arg {
17535 + struct vfsub_aopen_args *aopen;
17538 + const char *symname;
17547 +static int add_simple(struct inode *dir, struct dentry *dentry,
17548 + struct simple_arg *arg)
17551 + aufs_bindex_t bstart;
17552 + unsigned char created;
17553 + const unsigned char try_aopen
17554 + = (arg->type == Creat && arg->u.c.try_aopen);
17555 + struct dentry *wh_dentry, *parent;
17556 + struct inode *h_dir;
17557 + struct super_block *sb;
17558 + struct au_branch *br;
17559 + /* to reuduce stack size */
17561 + struct au_dtime dt;
17562 + struct au_pin pin;
17563 + struct path h_path;
17564 + struct au_wr_dir_args wr_dir_args;
17567 + AuDbg("%pd\n", dentry);
17571 + a = kmalloc(sizeof(*a), GFP_NOFS);
17572 + if (unlikely(!a))
17574 + a->wr_dir_args.force_btgt = -1;
17575 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17577 + parent = dentry->d_parent; /* dir inode is locked */
17578 + if (!try_aopen) {
17579 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17580 + if (unlikely(err))
17583 + err = au_d_may_add(dentry);
17584 + if (unlikely(err))
17587 + di_write_lock_parent(parent);
17588 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17589 + &a->pin, &a->wr_dir_args);
17590 + err = PTR_ERR(wh_dentry);
17591 + if (IS_ERR(wh_dentry))
17594 + bstart = au_dbstart(dentry);
17595 + sb = dentry->d_sb;
17596 + br = au_sbr(sb, bstart);
17597 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17598 + a->h_path.mnt = au_br_mnt(br);
17599 + h_dir = au_pinned_h_dir(&a->pin);
17600 + switch (arg->type) {
17603 + if (!try_aopen || !h_dir->i_op->atomic_open)
17604 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17605 + arg->u.c.want_excl);
17607 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
17608 + arg->u.c.aopen, br);
17611 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17614 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17622 + err = epilog(dir, bstart, wh_dentry, dentry);
17625 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
17626 + /* no delegation since it is just created */
17627 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17630 + AuIOErr("%pd revert failure(%d, %d)\n",
17631 + dentry, err, rerr);
17634 + au_dtime_revert(&a->dt);
17637 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
17638 + *arg->u.c.aopen->opened |= FILE_CREATED;
17640 + au_unpin(&a->pin);
17645 + di_write_unlock(parent);
17647 + if (unlikely(err)) {
17648 + au_update_dbstart(dentry);
17652 + aufs_read_unlock(dentry, AuLock_DW);
17659 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17662 + struct simple_arg arg = {
17669 + return add_simple(dir, dentry, &arg);
17672 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17674 + struct simple_arg arg = {
17676 + .u.s.symname = symname
17678 + return add_simple(dir, dentry, &arg);
17681 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17684 + struct simple_arg arg = {
17688 + .want_excl = want_excl
17691 + return add_simple(dir, dentry, &arg);
17694 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17695 + struct vfsub_aopen_args *aopen_args)
17697 + struct simple_arg arg = {
17700 + .mode = aopen_args->create_mode,
17701 + .want_excl = aopen_args->open_flag & O_EXCL,
17702 + .try_aopen = true,
17703 + .aopen = aopen_args
17706 + return add_simple(dir, dentry, &arg);
17709 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17712 + aufs_bindex_t bindex;
17713 + struct super_block *sb;
17714 + struct dentry *parent, *h_parent, *h_dentry;
17715 + struct inode *h_dir, *inode;
17716 + struct vfsmount *h_mnt;
17717 + struct au_wr_dir_args wr_dir_args = {
17718 + .force_btgt = -1,
17719 + .flags = AuWrDir_TMPFILE
17722 + /* copy-up may happen */
17723 + mutex_lock(&dir->i_mutex);
17726 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17727 + if (unlikely(err))
17730 + err = au_di_init(dentry);
17731 + if (unlikely(err))
17735 + parent = d_find_any_alias(dir);
17736 + AuDebugOn(!parent);
17737 + di_write_lock_parent(parent);
17738 + if (unlikely(d_inode(parent) != dir))
17741 + err = au_digen_test(parent, au_sigen(sb));
17742 + if (unlikely(err))
17745 + bindex = au_dbstart(parent);
17746 + au_set_dbstart(dentry, bindex);
17747 + au_set_dbend(dentry, bindex);
17748 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17750 + if (unlikely(err < 0))
17753 + err = -EOPNOTSUPP;
17754 + h_dir = au_h_iptr(dir, bindex);
17755 + if (unlikely(!h_dir->i_op->tmpfile))
17758 + h_mnt = au_sbr_mnt(sb, bindex);
17759 + err = vfsub_mnt_want_write(h_mnt);
17760 + if (unlikely(err))
17763 + h_parent = au_h_dptr(parent, bindex);
17764 + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC);
17765 + if (unlikely(err))
17769 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17770 + if (unlikely(!h_dentry))
17773 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17774 + if (unlikely(err))
17777 + au_set_dbstart(dentry, bindex);
17778 + au_set_dbend(dentry, bindex);
17779 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17780 + inode = au_new_inode(dentry, /*must_new*/1);
17781 + if (IS_ERR(inode)) {
17782 + err = PTR_ERR(inode);
17783 + au_set_h_dptr(dentry, bindex, NULL);
17784 + au_set_dbstart(dentry, -1);
17785 + au_set_dbend(dentry, -1);
17787 + if (!inode->i_nlink)
17788 + set_nlink(inode, 1);
17789 + d_tmpfile(dentry, inode);
17790 + au_di(dentry)->di_tmpfile = 1;
17792 + /* update without i_mutex */
17793 + if (au_ibstart(dir) == au_dbstart(dentry))
17794 + au_cpup_attr_timesizes(dir);
17800 + vfsub_mnt_drop_write(h_mnt);
17802 + di_write_unlock(parent);
17804 + di_write_unlock(dentry);
17807 + /* verbose coding for lock class name */
17808 + au_rw_class(&au_di(dentry)->di_rwsem,
17809 + au_lc_key + AuLcNonDir_DIINFO);
17814 + au_di_fin(dentry);
17815 + dentry->d_fsdata = NULL;
17818 + si_read_unlock(sb);
17820 + mutex_unlock(&dir->i_mutex);
17824 +/* ---------------------------------------------------------------------- */
17826 +struct au_link_args {
17827 + aufs_bindex_t bdst, bsrc;
17828 + struct au_pin pin;
17829 + struct path h_path;
17830 + struct dentry *src_parent, *parent;
17833 +static int au_cpup_before_link(struct dentry *src_dentry,
17834 + struct au_link_args *a)
17837 + struct dentry *h_src_dentry;
17838 + struct au_cp_generic cpg = {
17839 + .dentry = src_dentry,
17844 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
17847 + di_read_lock_parent(a->src_parent, AuLock_IR);
17848 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
17849 + if (unlikely(err))
17852 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
17853 + err = au_pin(&a->pin, src_dentry, a->bdst,
17854 + au_opt_udba(src_dentry->d_sb),
17855 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17856 + if (unlikely(err))
17859 + err = au_sio_cpup_simple(&cpg);
17860 + au_unpin(&a->pin);
17863 + di_read_unlock(a->src_parent, AuLock_IR);
17867 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
17868 + struct au_link_args *a)
17871 + unsigned char plink;
17872 + aufs_bindex_t bend;
17873 + struct dentry *h_src_dentry;
17874 + struct inode *h_inode, *inode, *delegated;
17875 + struct super_block *sb;
17876 + struct file *h_file;
17880 + sb = src_dentry->d_sb;
17881 + inode = d_inode(src_dentry);
17882 + if (au_ibstart(inode) <= a->bdst)
17883 + h_inode = au_h_iptr(inode, a->bdst);
17884 + if (!h_inode || !h_inode->i_nlink) {
17885 + /* copyup src_dentry as the name of dentry. */
17886 + bend = au_dbend(dentry);
17887 + if (bend < a->bsrc)
17888 + au_set_dbend(dentry, a->bsrc);
17889 + au_set_h_dptr(dentry, a->bsrc,
17890 + dget(au_h_dptr(src_dentry, a->bsrc)));
17891 + dget(a->h_path.dentry);
17892 + au_set_h_dptr(dentry, a->bdst, NULL);
17893 + AuDbg("temporary d_inode...\n");
17894 + spin_lock(&dentry->d_lock);
17895 + dentry->d_inode = d_inode(src_dentry); /* tmp */
17896 + spin_unlock(&dentry->d_lock);
17897 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
17898 + if (IS_ERR(h_file))
17899 + err = PTR_ERR(h_file);
17901 + struct au_cp_generic cpg = {
17902 + .dentry = dentry,
17907 + .flags = AuCpup_KEEPLINO
17909 + err = au_sio_cpup_simple(&cpg);
17910 + au_h_open_post(dentry, a->bsrc, h_file);
17912 + dput(a->h_path.dentry);
17913 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17915 + au_set_h_dptr(dentry, a->bdst,
17916 + a->h_path.dentry);
17918 + spin_lock(&dentry->d_lock);
17919 + dentry->d_inode = NULL; /* restore */
17920 + spin_unlock(&dentry->d_lock);
17921 + AuDbg("temporary d_inode...done\n");
17922 + au_set_h_dptr(dentry, a->bsrc, NULL);
17923 + au_set_dbend(dentry, bend);
17925 + /* the inode of src_dentry already exists on a.bdst branch */
17926 + h_src_dentry = d_find_alias(h_inode);
17927 + if (!h_src_dentry && au_plink_test(inode)) {
17929 + h_src_dentry = au_plink_lkup(inode, a->bdst);
17930 + err = PTR_ERR(h_src_dentry);
17931 + if (IS_ERR(h_src_dentry))
17934 + if (unlikely(d_is_negative(h_src_dentry))) {
17935 + dput(h_src_dentry);
17936 + h_src_dentry = NULL;
17940 + if (h_src_dentry) {
17941 + delegated = NULL;
17942 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17943 + &a->h_path, &delegated);
17944 + if (unlikely(err == -EWOULDBLOCK)) {
17945 + pr_warn("cannot retry for NFSv4 delegation"
17946 + " for an internal link\n");
17949 + dput(h_src_dentry);
17951 + AuIOErr("no dentry found for hi%lu on b%d\n",
17952 + h_inode->i_ino, a->bdst);
17957 + if (!err && !plink)
17958 + au_plink_append(inode, a->bdst, a->h_path.dentry);
17965 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17966 + struct dentry *dentry)
17969 + struct au_dtime dt;
17970 + struct au_link_args *a;
17971 + struct dentry *wh_dentry, *h_src_dentry;
17972 + struct inode *inode, *delegated;
17973 + struct super_block *sb;
17974 + struct au_wr_dir_args wr_dir_args = {
17975 + /* .force_btgt = -1, */
17976 + .flags = AuWrDir_ADD_ENTRY
17980 + inode = d_inode(src_dentry);
17981 + IMustLock(inode);
17984 + a = kzalloc(sizeof(*a), GFP_NOFS);
17985 + if (unlikely(!a))
17988 + a->parent = dentry->d_parent; /* dir inode is locked */
17989 + err = aufs_read_and_write_lock2(dentry, src_dentry,
17990 + AuLock_NOPLM | AuLock_GEN);
17991 + if (unlikely(err))
17993 + err = au_d_linkable(src_dentry);
17994 + if (unlikely(err))
17996 + err = au_d_may_add(dentry);
17997 + if (unlikely(err))
18000 + a->src_parent = dget_parent(src_dentry);
18001 + wr_dir_args.force_btgt = au_ibstart(inode);
18003 + di_write_lock_parent(a->parent);
18004 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
18005 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
18007 + err = PTR_ERR(wh_dentry);
18008 + if (IS_ERR(wh_dentry))
18012 + sb = dentry->d_sb;
18013 + a->bdst = au_dbstart(dentry);
18014 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18015 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
18016 + a->bsrc = au_ibstart(inode);
18017 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18018 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
18019 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
18020 + if (!h_src_dentry) {
18021 + a->bsrc = au_dbstart(src_dentry);
18022 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18023 + AuDebugOn(!h_src_dentry);
18024 + } else if (IS_ERR(h_src_dentry)) {
18025 + err = PTR_ERR(h_src_dentry);
18029 + if (au_opt_test(au_mntflags(sb), PLINK)) {
18030 + if (a->bdst < a->bsrc
18031 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
18032 + err = au_cpup_or_link(src_dentry, dentry, a);
18034 + delegated = NULL;
18035 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18036 + &a->h_path, &delegated);
18037 + if (unlikely(err == -EWOULDBLOCK)) {
18038 + pr_warn("cannot retry for NFSv4 delegation"
18039 + " for an internal link\n");
18043 + dput(h_src_dentry);
18046 + * copyup src_dentry to the branch we process,
18047 + * and then link(2) to it.
18049 + dput(h_src_dentry);
18050 + if (a->bdst < a->bsrc
18051 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
18052 + au_unpin(&a->pin);
18053 + di_write_unlock(a->parent);
18054 + err = au_cpup_before_link(src_dentry, a);
18055 + di_write_lock_parent(a->parent);
18057 + err = au_pin(&a->pin, dentry, a->bdst,
18059 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18060 + if (unlikely(err))
18064 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
18066 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
18067 + delegated = NULL;
18068 + err = vfsub_link(h_src_dentry,
18069 + au_pinned_h_dir(&a->pin),
18070 + &a->h_path, &delegated);
18071 + if (unlikely(err == -EWOULDBLOCK)) {
18072 + pr_warn("cannot retry"
18073 + " for NFSv4 delegation"
18074 + " for an internal link\n");
18080 + if (unlikely(err))
18084 + a->h_path.dentry = wh_dentry;
18085 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
18087 + if (unlikely(err))
18091 + au_dir_ts(dir, a->bdst);
18092 + dir->i_version++;
18093 + inc_nlink(inode);
18094 + inode->i_ctime = dir->i_ctime;
18095 + d_instantiate(dentry, au_igrab(inode));
18096 + if (d_unhashed(a->h_path.dentry))
18097 + /* some filesystem calls d_drop() */
18099 + /* some filesystems consume an inode even hardlink */
18100 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
18101 + goto out_unpin; /* success */
18104 + /* no delegation since it is just created */
18105 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
18106 + /*delegated*/NULL, /*force*/0);
18107 + if (unlikely(rerr)) {
18108 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
18111 + au_dtime_revert(&dt);
18113 + au_unpin(&a->pin);
18117 + di_write_unlock(a->parent);
18118 + dput(a->src_parent);
18120 + if (unlikely(err)) {
18121 + au_update_dbstart(dentry);
18124 + aufs_read_and_write_unlock2(dentry, src_dentry);
18132 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18135 + aufs_bindex_t bindex;
18136 + unsigned char diropq;
18137 + struct path h_path;
18138 + struct dentry *wh_dentry, *parent, *opq_dentry;
18139 + struct mutex *h_mtx;
18140 + struct super_block *sb;
18142 + struct au_pin pin;
18143 + struct au_dtime dt;
18144 + } *a; /* reduce the stack usage */
18145 + struct au_wr_dir_args wr_dir_args = {
18146 + .force_btgt = -1,
18147 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18153 + a = kmalloc(sizeof(*a), GFP_NOFS);
18154 + if (unlikely(!a))
18157 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18158 + if (unlikely(err))
18160 + err = au_d_may_add(dentry);
18161 + if (unlikely(err))
18164 + parent = dentry->d_parent; /* dir inode is locked */
18165 + di_write_lock_parent(parent);
18166 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18167 + &a->pin, &wr_dir_args);
18168 + err = PTR_ERR(wh_dentry);
18169 + if (IS_ERR(wh_dentry))
18172 + sb = dentry->d_sb;
18173 + bindex = au_dbstart(dentry);
18174 + h_path.dentry = au_h_dptr(dentry, bindex);
18175 + h_path.mnt = au_sbr_mnt(sb, bindex);
18176 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18177 + if (unlikely(err))
18180 + /* make the dir opaque */
18182 + h_mtx = &d_inode(h_path.dentry)->i_mutex;
18184 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18185 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18186 + opq_dentry = au_diropq_create(dentry, bindex);
18187 + mutex_unlock(h_mtx);
18188 + err = PTR_ERR(opq_dentry);
18189 + if (IS_ERR(opq_dentry))
18191 + dput(opq_dentry);
18195 + err = epilog(dir, bindex, wh_dentry, dentry);
18198 + goto out_unpin; /* success */
18203 + AuLabel(revert opq);
18204 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18205 + rerr = au_diropq_remove(dentry, bindex);
18206 + mutex_unlock(h_mtx);
18208 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18209 + dentry, err, rerr);
18215 + AuLabel(revert dir);
18216 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18218 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18219 + dentry, err, rerr);
18222 + au_dtime_revert(&a->dt);
18224 + au_unpin(&a->pin);
18227 + di_write_unlock(parent);
18229 + if (unlikely(err)) {
18230 + au_update_dbstart(dentry);
18233 + aufs_read_unlock(dentry, AuLock_DW);
18239 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18240 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18241 +++ linux/fs/aufs/i_op.c 2016-02-28 11:26:32.573304539 +0100
18244 + * Copyright (C) 2005-2016 Junjiro R. Okajima
18246 + * This program, aufs is free software; you can redistribute it and/or modify
18247 + * it under the terms of the GNU General Public License as published by
18248 + * the Free Software Foundation; either version 2 of the License, or
18249 + * (at your option) any later version.
18251 + * This program is distributed in the hope that it will be useful,
18252 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18253 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18254 + * GNU General Public License for more details.
18256 + * You should have received a copy of the GNU General Public License
18257 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18261 + * inode operations (except add/del/rename)
18264 +#include <linux/device_cgroup.h>
18265 +#include <linux/fs_stack.h>
18266 +#include <linux/namei.h>
18267 +#include <linux/security.h>
18270 +static int h_permission(struct inode *h_inode, int mask,
18271 + struct path *h_path, int brperm)
18274 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18277 + if ((write_mask && IS_IMMUTABLE(h_inode))
18278 + || ((mask & MAY_EXEC)
18279 + && S_ISREG(h_inode->i_mode)
18280 + && (path_noexec(h_path)
18281 + || !(h_inode->i_mode & S_IXUGO))))
18285 + * - skip the lower fs test in the case of write to ro branch.
18286 + * - nfs dir permission write check is optimized, but a policy for
18287 + * link/rename requires a real check.
18288 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18289 + * in this case, generic_permission() returns -EOPNOTSUPP.
18291 + if ((write_mask && !au_br_writable(brperm))
18292 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18293 + && write_mask && !(mask & MAY_READ))
18294 + || !h_inode->i_op->permission) {
18295 + /* AuLabel(generic_permission); */
18296 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18297 + err = generic_permission(h_inode, mask);
18298 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18299 + err = h_inode->i_op->permission(h_inode, mask);
18302 + /* AuLabel(h_inode->permission); */
18303 + err = h_inode->i_op->permission(h_inode, mask);
18308 + err = devcgroup_inode_permission(h_inode, mask);
18310 + err = security_inode_permission(h_inode, mask);
18314 + /* todo: do we need to call ima_path_check()? */
18315 + struct path h_path = {
18319 + err = ima_path_check(&h_path,
18320 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18321 + IMA_COUNT_LEAVE);
18329 +static int aufs_permission(struct inode *inode, int mask)
18332 + aufs_bindex_t bindex, bend;
18333 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18334 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18335 + struct inode *h_inode;
18336 + struct super_block *sb;
18337 + struct au_branch *br;
18339 + /* todo: support rcu-walk? */
18340 + if (mask & MAY_NOT_BLOCK)
18343 + sb = inode->i_sb;
18344 + si_read_lock(sb, AuLock_FLUSH);
18345 + ii_read_lock_child(inode);
18347 + err = au_iigen_test(inode, au_sigen(sb));
18348 + if (unlikely(err))
18354 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18355 + err = au_busy_or_stale();
18356 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18357 + if (unlikely(!h_inode
18358 + || (h_inode->i_mode & S_IFMT)
18359 + != (inode->i_mode & S_IFMT)))
18363 + bindex = au_ibstart(inode);
18364 + br = au_sbr(sb, bindex);
18365 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
18368 + && !special_file(h_inode->i_mode)) {
18369 + /* test whether the upper writable branch exists */
18371 + for (; bindex >= 0; bindex--)
18372 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18380 + /* non-write to dir */
18382 + bend = au_ibend(inode);
18383 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
18384 + h_inode = au_h_iptr(inode, bindex);
18386 + err = au_busy_or_stale();
18387 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18390 + br = au_sbr(sb, bindex);
18391 + err = h_permission(h_inode, mask, &br->br_path,
18397 + ii_read_unlock(inode);
18398 + si_read_unlock(sb);
18402 +/* ---------------------------------------------------------------------- */
18404 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18405 + unsigned int flags)
18407 + struct dentry *ret, *parent;
18408 + struct inode *inode;
18409 + struct super_block *sb;
18410 + int err, npositive;
18414 + /* todo: support rcu-walk? */
18415 + ret = ERR_PTR(-ECHILD);
18416 + if (flags & LOOKUP_RCU)
18419 + ret = ERR_PTR(-ENAMETOOLONG);
18420 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18424 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18425 + ret = ERR_PTR(err);
18426 + if (unlikely(err))
18429 + err = au_di_init(dentry);
18430 + ret = ERR_PTR(err);
18431 + if (unlikely(err))
18435 + npositive = 0; /* suppress a warning */
18436 + parent = dentry->d_parent; /* dir inode is locked */
18437 + di_read_lock_parent(parent, AuLock_IR);
18438 + err = au_alive_dir(parent);
18440 + err = au_digen_test(parent, au_sigen(sb));
18442 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
18446 + di_read_unlock(parent, AuLock_IR);
18447 + ret = ERR_PTR(err);
18448 + if (unlikely(err < 0))
18452 + inode = au_new_inode(dentry, /*must_new*/0);
18453 + if (IS_ERR(inode)) {
18454 + ret = (void *)inode;
18461 + atomic_inc(&inode->i_count);
18462 + ret = d_splice_alias(inode, dentry);
18464 + if (unlikely(d_need_lookup(dentry))) {
18465 + spin_lock(&dentry->d_lock);
18466 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18467 + spin_unlock(&dentry->d_lock);
18471 + if (!IS_ERR(ret)) {
18473 + if (ret && ret != dentry)
18474 + ii_write_unlock(inode);
18476 + ii_write_unlock(inode);
18483 + di_write_unlock(dentry);
18485 + /* verbose coding for lock class name */
18486 + if (unlikely(S_ISLNK(inode->i_mode)))
18487 + au_rw_class(&au_di(dentry)->di_rwsem,
18488 + au_lc_key + AuLcSymlink_DIINFO);
18489 + else if (unlikely(S_ISDIR(inode->i_mode)))
18490 + au_rw_class(&au_di(dentry)->di_rwsem,
18491 + au_lc_key + AuLcDir_DIINFO);
18492 + else /* likely */
18493 + au_rw_class(&au_di(dentry)->di_rwsem,
18494 + au_lc_key + AuLcNonDir_DIINFO);
18497 + si_read_unlock(sb);
18502 +/* ---------------------------------------------------------------------- */
18504 +struct aopen_node {
18505 + struct hlist_node hlist;
18506 + struct file *file, *h_file;
18509 +static int au_do_aopen(struct inode *inode, struct file *file)
18511 + struct au_sphlhead *aopen;
18512 + struct aopen_node *node;
18513 + struct au_do_open_args args = {
18515 + .open = au_do_open_nondir
18518 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18519 + spin_lock(&aopen->spin);
18520 + hlist_for_each_entry(node, &aopen->head, hlist)
18521 + if (node->file == file) {
18522 + args.h_file = node->h_file;
18525 + spin_unlock(&aopen->spin);
18526 + /* AuDebugOn(!args.h_file); */
18528 + return au_do_open(file, &args);
18531 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18532 + struct file *file, unsigned int open_flag,
18533 + umode_t create_mode, int *opened)
18535 + int err, h_opened = *opened;
18536 + struct dentry *parent;
18537 + struct dentry *d;
18538 + struct au_sphlhead *aopen;
18539 + struct vfsub_aopen_args args = {
18540 + .open_flag = open_flag,
18541 + .create_mode = create_mode,
18542 + .opened = &h_opened
18544 + struct aopen_node aopen_node = {
18549 + AuDbg("open_flag 0x%x\n", open_flag);
18550 + AuDbgDentry(dentry);
18553 + if (!au_di(dentry)) {
18554 + d = aufs_lookup(dir, dentry, /*flags*/0);
18556 + err = PTR_ERR(d);
18560 + * obsoleted dentry found.
18561 + * another error will be returned later.
18567 + AuDbgDentry(dentry);
18570 + if (d_is_positive(dentry)
18571 + || d_unhashed(dentry)
18572 + || d_unlinked(dentry)
18573 + || !(open_flag & O_CREAT))
18574 + goto out_no_open;
18576 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18577 + if (unlikely(err))
18580 + parent = dentry->d_parent; /* dir is locked */
18581 + di_write_lock_parent(parent);
18582 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
18583 + if (unlikely(err))
18586 + AuDbgDentry(dentry);
18587 + if (d_is_positive(dentry))
18590 + args.file = get_empty_filp();
18591 + err = PTR_ERR(args.file);
18592 + if (IS_ERR(args.file))
18595 + args.file->f_flags = file->f_flags;
18596 + err = au_aopen_or_create(dir, dentry, &args);
18598 + AuDbgFile(args.file);
18599 + if (unlikely(err < 0)) {
18600 + if (h_opened & FILE_OPENED)
18603 + put_filp(args.file);
18607 + /* some filesystems don't set FILE_CREATED while succeeded? */
18608 + *opened |= FILE_CREATED;
18609 + if (h_opened & FILE_OPENED)
18610 + aopen_node.h_file = args.file;
18612 + put_filp(args.file);
18613 + args.file = NULL;
18615 + aopen = &au_sbi(dir->i_sb)->si_aopen;
18616 + au_sphl_add(&aopen_node.hlist, aopen);
18617 + err = finish_open(file, dentry, au_do_aopen, opened);
18618 + au_sphl_del(&aopen_node.hlist, aopen);
18621 + if (aopen_node.h_file)
18622 + fput(aopen_node.h_file);
18625 + di_write_unlock(parent);
18626 + aufs_read_unlock(dentry, AuLock_DW);
18627 + AuDbgDentry(dentry);
18628 + if (unlikely(err))
18631 + if (!err && !(*opened & FILE_CREATED)) {
18632 + AuLabel(out_no_open);
18634 + err = finish_no_open(file, dentry);
18637 + AuDbg("%pd%s%s\n", dentry,
18638 + (*opened & FILE_CREATED) ? " created" : "",
18639 + (*opened & FILE_OPENED) ? " opened" : "");
18645 +/* ---------------------------------------------------------------------- */
18647 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18648 + const unsigned char add_entry, aufs_bindex_t bcpup,
18649 + aufs_bindex_t bstart)
18652 + struct dentry *h_parent;
18653 + struct inode *h_dir;
18656 + IMustLock(d_inode(parent));
18658 + di_write_lock_parent(parent);
18661 + if (!au_h_dptr(parent, bcpup)) {
18662 + if (bstart > bcpup)
18663 + err = au_cpup_dirs(dentry, bcpup);
18664 + else if (bstart < bcpup)
18665 + err = au_cpdown_dirs(dentry, bcpup);
18669 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18670 + h_parent = au_h_dptr(parent, bcpup);
18671 + h_dir = d_inode(h_parent);
18672 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
18673 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
18674 + /* todo: no unlock here */
18675 + mutex_unlock(&h_dir->i_mutex);
18677 + AuDbg("bcpup %d\n", bcpup);
18679 + if (d_really_is_negative(dentry))
18680 + au_set_h_dptr(dentry, bstart, NULL);
18681 + au_update_dbrange(dentry, /*do_put_zero*/0);
18686 + di_write_unlock(parent);
18688 + err = bcpup; /* success */
18695 + * decide the branch and the parent dir where we will create a new entry.
18696 + * returns new bindex or an error.
18697 + * copyup the parent dir if needed.
18699 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18700 + struct au_wr_dir_args *args)
18703 + unsigned int flags;
18704 + aufs_bindex_t bcpup, bstart, src_bstart;
18705 + const unsigned char add_entry
18706 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18707 + | au_ftest_wrdir(args->flags, TMPFILE);
18708 + struct super_block *sb;
18709 + struct dentry *parent;
18710 + struct au_sbinfo *sbinfo;
18712 + sb = dentry->d_sb;
18713 + sbinfo = au_sbi(sb);
18714 + parent = dget_parent(dentry);
18715 + bstart = au_dbstart(dentry);
18717 + if (args->force_btgt < 0) {
18718 + if (src_dentry) {
18719 + src_bstart = au_dbstart(src_dentry);
18720 + if (src_bstart < bstart)
18721 + bcpup = src_bstart;
18722 + } else if (add_entry) {
18724 + if (au_ftest_wrdir(args->flags, ISDIR))
18725 + au_fset_wbr(flags, DIR);
18726 + err = AuWbrCreate(sbinfo, dentry, flags);
18730 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
18732 + err = AuWbrCopyup(sbinfo, dentry);
18734 + if (!IS_ROOT(dentry)) {
18735 + di_read_lock_parent(parent, !AuLock_IR);
18736 + err = AuWbrCopyup(sbinfo, dentry);
18737 + di_read_unlock(parent, !AuLock_IR);
18739 + err = AuWbrCopyup(sbinfo, dentry);
18742 + if (unlikely(err < 0))
18746 + bcpup = args->force_btgt;
18747 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
18750 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
18752 + if (bcpup == bstart)
18753 + goto out; /* success */
18755 + /* copyup the new parent into the branch we process */
18756 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
18758 + if (d_really_is_negative(dentry)) {
18759 + au_set_h_dptr(dentry, bstart, NULL);
18760 + au_set_dbstart(dentry, bcpup);
18761 + au_set_dbend(dentry, bcpup);
18763 + AuDebugOn(add_entry
18764 + && !au_ftest_wrdir(args->flags, TMPFILE)
18765 + && !au_h_dptr(dentry, bcpup));
18773 +/* ---------------------------------------------------------------------- */
18775 +void au_pin_hdir_unlock(struct au_pin *p)
18778 + au_hn_imtx_unlock(p->hdir);
18781 +int au_pin_hdir_lock(struct au_pin *p)
18789 + /* even if an error happens later, keep this lock */
18790 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
18793 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
18798 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18799 + p->h_parent, p->br);
18805 +int au_pin_hdir_relock(struct au_pin *p)
18808 + struct inode *h_i;
18809 + struct dentry *h_d[] = {
18814 + err = au_pin_hdir_lock(p);
18815 + if (unlikely(err))
18818 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
18821 + if (d_is_positive(h_d[i])) {
18822 + h_i = d_inode(h_d[i]);
18823 + err = !h_i->i_nlink;
18831 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
18833 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
18834 + p->hdir->hi_inode->i_mutex.owner = task;
18838 +void au_pin_hdir_acquire_nest(struct au_pin *p)
18841 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
18842 + p->lsc_hi, 0, NULL, _RET_IP_);
18843 + au_pin_hdir_set_owner(p, current);
18847 +void au_pin_hdir_release(struct au_pin *p)
18850 + au_pin_hdir_set_owner(p, p->task);
18851 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
18855 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
18857 + if (pin && pin->parent)
18858 + return au_h_dptr(pin->parent, pin->bindex);
18862 +void au_unpin(struct au_pin *p)
18865 + au_pin_hdir_unlock(p);
18866 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
18867 + vfsub_mnt_drop_write(p->h_mnt);
18871 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18872 + di_read_unlock(p->parent, AuLock_IR);
18873 + iput(p->hdir->hi_inode);
18875 + p->parent = NULL;
18878 + /* do not clear p->task */
18881 +int au_do_pin(struct au_pin *p)
18884 + struct super_block *sb;
18885 + struct inode *h_dir;
18888 + sb = p->dentry->d_sb;
18889 + p->br = au_sbr(sb, p->bindex);
18890 + if (IS_ROOT(p->dentry)) {
18891 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18892 + p->h_mnt = au_br_mnt(p->br);
18893 + err = vfsub_mnt_want_write(p->h_mnt);
18894 + if (unlikely(err)) {
18895 + au_fclr_pin(p->flags, MNT_WRITE);
18902 + p->h_dentry = NULL;
18903 + if (p->bindex <= au_dbend(p->dentry))
18904 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
18906 + p->parent = dget_parent(p->dentry);
18907 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18908 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
18911 + p->h_parent = au_h_dptr(p->parent, p->bindex);
18912 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
18914 + h_dir = p->hdir->hi_inode;
18918 + * if DI_LOCKED is not set, then p->parent may be different
18919 + * and h_parent can be NULL.
18921 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
18923 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18924 + di_read_unlock(p->parent, AuLock_IR);
18926 + p->parent = NULL;
18930 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18931 + p->h_mnt = au_br_mnt(p->br);
18932 + err = vfsub_mnt_want_write(p->h_mnt);
18933 + if (unlikely(err)) {
18934 + au_fclr_pin(p->flags, MNT_WRITE);
18935 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18936 + di_read_unlock(p->parent, AuLock_IR);
18938 + p->parent = NULL;
18944 + err = au_pin_hdir_lock(p);
18946 + goto out; /* success */
18951 + pr_err("err %d\n", err);
18952 + err = au_busy_or_stale();
18957 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
18958 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18959 + unsigned int udba, unsigned char flags)
18961 + p->dentry = dentry;
18963 + p->lsc_di = lsc_di;
18964 + p->lsc_hi = lsc_hi;
18965 + p->flags = flags;
18966 + p->bindex = bindex;
18968 + p->parent = NULL;
18972 + p->h_dentry = NULL;
18973 + p->h_parent = NULL;
18975 + p->task = current;
18978 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18979 + unsigned int udba, unsigned char flags)
18981 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
18983 + return au_do_pin(pin);
18986 +/* ---------------------------------------------------------------------- */
18989 + * ->setattr() and ->getattr() are called in various cases.
18990 + * chmod, stat: dentry is revalidated.
18991 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
18993 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
18995 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
18996 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
18999 + struct dentry *parent;
19002 + if (au_digen_test(dentry, sigen)) {
19003 + parent = dget_parent(dentry);
19004 + di_read_lock_parent(parent, AuLock_IR);
19005 + err = au_refresh_dentry(dentry, parent);
19006 + di_read_unlock(parent, AuLock_IR);
19014 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19015 + struct au_icpup_args *a)
19019 + aufs_bindex_t bstart, ibstart;
19020 + struct dentry *hi_wh, *parent;
19021 + struct inode *inode;
19022 + struct au_wr_dir_args wr_dir_args = {
19023 + .force_btgt = -1,
19027 + if (d_is_dir(dentry))
19028 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19029 + /* plink or hi_wh() case */
19030 + bstart = au_dbstart(dentry);
19031 + inode = d_inode(dentry);
19032 + ibstart = au_ibstart(inode);
19033 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
19034 + wr_dir_args.force_btgt = ibstart;
19035 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19036 + if (unlikely(err < 0))
19039 + if (err != bstart)
19040 + au_fset_icpup(a->flags, DID_CPUP);
19043 + a->pin_flags = AuPin_MNT_WRITE;
19045 + if (!IS_ROOT(dentry)) {
19046 + au_fset_pin(a->pin_flags, DI_LOCKED);
19047 + parent = dget_parent(dentry);
19048 + di_write_lock_parent(parent);
19051 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
19052 + if (unlikely(err))
19055 + a->h_path.dentry = au_h_dptr(dentry, bstart);
19057 + a->h_inode = d_inode(a->h_path.dentry);
19058 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
19059 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
19060 + if (ia->ia_size < i_size_read(a->h_inode))
19061 + sz = ia->ia_size;
19062 + mutex_unlock(&a->h_inode->i_mutex);
19066 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
19067 + hi_wh = au_hi_wh(inode, a->btgt);
19069 + struct au_cp_generic cpg = {
19070 + .dentry = dentry,
19076 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
19077 + if (unlikely(err))
19079 + hi_wh = au_hi_wh(inode, a->btgt);
19080 + /* todo: revalidate hi_wh? */
19085 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
19086 + di_downgrade_lock(parent, AuLock_IR);
19090 + if (!au_ftest_icpup(a->flags, DID_CPUP))
19091 + goto out; /* success */
19093 + if (!d_unhashed(dentry)) {
19094 + struct au_cp_generic cpg = {
19095 + .dentry = dentry,
19100 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19102 + err = au_sio_cpup_simple(&cpg);
19104 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19105 + } else if (!hi_wh)
19106 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19108 + a->h_path.dentry = hi_wh; /* do not dget here */
19111 + a->h_inode = d_inode(a->h_path.dentry);
19113 + goto out; /* success */
19114 + au_unpin(&a->pin);
19117 + di_write_unlock(parent);
19122 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
19126 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19129 + struct inode *inode, *delegated;
19130 + struct super_block *sb;
19131 + struct file *file;
19132 + struct au_icpup_args *a;
19134 + inode = d_inode(dentry);
19135 + IMustLock(inode);
19138 + a = kzalloc(sizeof(*a), GFP_NOFS);
19139 + if (unlikely(!a))
19142 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19143 + ia->ia_valid &= ~ATTR_MODE;
19146 + sb = dentry->d_sb;
19147 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19148 + if (unlikely(err))
19151 + if (ia->ia_valid & ATTR_FILE) {
19152 + /* currently ftruncate(2) only */
19153 + AuDebugOn(!d_is_reg(dentry));
19154 + file = ia->ia_file;
19155 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
19156 + if (unlikely(err))
19158 + ia->ia_file = au_hf_top(file);
19159 + a->udba = AuOpt_UDBA_NONE;
19161 + /* fchmod() doesn't pass ia_file */
19162 + a->udba = au_opt_udba(sb);
19163 + di_write_lock_child(dentry);
19164 + /* no d_unlinked(), to set UDBA_NONE for root */
19165 + if (d_unhashed(dentry))
19166 + a->udba = AuOpt_UDBA_NONE;
19167 + if (a->udba != AuOpt_UDBA_NONE) {
19168 + AuDebugOn(IS_ROOT(dentry));
19169 + err = au_reval_for_attr(dentry, au_sigen(sb));
19170 + if (unlikely(err))
19175 + err = au_pin_and_icpup(dentry, ia, a);
19176 + if (unlikely(err < 0))
19178 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19179 + ia->ia_file = NULL;
19180 + ia->ia_valid &= ~ATTR_FILE;
19183 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19184 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19185 + == (ATTR_MODE | ATTR_CTIME)) {
19186 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19187 + if (unlikely(err))
19189 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19190 + && (ia->ia_valid & ATTR_CTIME)) {
19191 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19192 + if (unlikely(err))
19196 + if (ia->ia_valid & ATTR_SIZE) {
19199 + if (ia->ia_size < i_size_read(inode))
19201 + truncate_setsize(inode, ia->ia_size);
19204 + if (ia->ia_valid & ATTR_FILE)
19206 + mutex_unlock(&a->h_inode->i_mutex);
19207 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19208 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
19210 + delegated = NULL;
19212 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19214 + err = break_deleg_wait(&delegated);
19222 + * regardless aufs 'acl' option setting.
19223 + * why don't all acl-aware fs call this func from their ->setattr()?
19225 + if (!err && (ia->ia_valid & ATTR_MODE))
19226 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
19228 + au_cpup_attr_changeable(inode);
19231 + mutex_unlock(&a->h_inode->i_mutex);
19232 + au_unpin(&a->pin);
19233 + if (unlikely(err))
19234 + au_update_dbstart(dentry);
19236 + di_write_unlock(dentry);
19238 + fi_write_unlock(file);
19239 + ia->ia_file = file;
19240 + ia->ia_valid |= ATTR_FILE;
19243 + si_read_unlock(sb);
19251 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19252 +static int au_h_path_to_set_attr(struct dentry *dentry,
19253 + struct au_icpup_args *a, struct path *h_path)
19256 + struct super_block *sb;
19258 + sb = dentry->d_sb;
19259 + a->udba = au_opt_udba(sb);
19260 + /* no d_unlinked(), to set UDBA_NONE for root */
19261 + if (d_unhashed(dentry))
19262 + a->udba = AuOpt_UDBA_NONE;
19263 + if (a->udba != AuOpt_UDBA_NONE) {
19264 + AuDebugOn(IS_ROOT(dentry));
19265 + err = au_reval_for_attr(dentry, au_sigen(sb));
19266 + if (unlikely(err))
19269 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19270 + if (unlikely(err < 0))
19273 + h_path->dentry = a->h_path.dentry;
19274 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19280 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg)
19283 + struct path h_path;
19284 + struct super_block *sb;
19285 + struct au_icpup_args *a;
19286 + struct inode *inode, *h_inode;
19288 + inode = d_inode(dentry);
19289 + IMustLock(inode);
19292 + a = kzalloc(sizeof(*a), GFP_NOFS);
19293 + if (unlikely(!a))
19296 + sb = dentry->d_sb;
19297 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19298 + if (unlikely(err))
19301 + h_path.dentry = NULL; /* silence gcc */
19302 + di_write_lock_child(dentry);
19303 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19304 + if (unlikely(err))
19307 + mutex_unlock(&a->h_inode->i_mutex);
19308 + switch (arg->type) {
19309 + case AU_XATTR_SET:
19310 + err = vfsub_setxattr(h_path.dentry,
19311 + arg->u.set.name, arg->u.set.value,
19312 + arg->u.set.size, arg->u.set.flags);
19314 + case AU_XATTR_REMOVE:
19315 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
19318 + err = -EOPNOTSUPP;
19319 + h_inode = d_inode(h_path.dentry);
19320 + if (h_inode->i_op->set_acl)
19321 + err = h_inode->i_op->set_acl(h_inode,
19322 + arg->u.acl_set.acl,
19323 + arg->u.acl_set.type);
19327 + au_cpup_attr_timesizes(inode);
19329 + au_unpin(&a->pin);
19330 + if (unlikely(err))
19331 + au_update_dbstart(dentry);
19334 + di_write_unlock(dentry);
19335 + si_read_unlock(sb);
19344 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19345 + unsigned int nlink)
19349 + inode->i_mode = st->mode;
19350 + /* don't i_[ug]id_write() here */
19351 + inode->i_uid = st->uid;
19352 + inode->i_gid = st->gid;
19353 + inode->i_atime = st->atime;
19354 + inode->i_mtime = st->mtime;
19355 + inode->i_ctime = st->ctime;
19357 + au_cpup_attr_nlink(inode, /*force*/0);
19358 + if (S_ISDIR(inode->i_mode)) {
19359 + n = inode->i_nlink;
19362 + smp_mb(); /* for i_nlink */
19363 + /* 0 can happen */
19364 + set_nlink(inode, n);
19367 + spin_lock(&inode->i_lock);
19368 + inode->i_blocks = st->blocks;
19369 + i_size_write(inode, st->size);
19370 + spin_unlock(&inode->i_lock);
19374 + * common routine for aufs_getattr() and aufs_getxattr().
19375 + * returns zero or negative (an error).
19376 + * @dentry will be read-locked in success.
19378 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
19381 + unsigned int mnt_flags, sigen;
19382 + unsigned char udba_none;
19383 + aufs_bindex_t bindex;
19384 + struct super_block *sb, *h_sb;
19385 + struct inode *inode;
19387 + h_path->mnt = NULL;
19388 + h_path->dentry = NULL;
19391 + sb = dentry->d_sb;
19392 + mnt_flags = au_mntflags(sb);
19393 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19395 + /* support fstat(2) */
19396 + if (!d_unlinked(dentry) && !udba_none) {
19397 + sigen = au_sigen(sb);
19398 + err = au_digen_test(dentry, sigen);
19400 + di_read_lock_child(dentry, AuLock_IR);
19401 + err = au_dbrange_test(dentry);
19402 + if (unlikely(err)) {
19403 + di_read_unlock(dentry, AuLock_IR);
19407 + AuDebugOn(IS_ROOT(dentry));
19408 + di_write_lock_child(dentry);
19409 + err = au_dbrange_test(dentry);
19411 + err = au_reval_for_attr(dentry, sigen);
19413 + di_downgrade_lock(dentry, AuLock_IR);
19415 + di_write_unlock(dentry);
19420 + di_read_lock_child(dentry, AuLock_IR);
19422 + inode = d_inode(dentry);
19423 + bindex = au_ibstart(inode);
19424 + h_path->mnt = au_sbr_mnt(sb, bindex);
19425 + h_sb = h_path->mnt->mnt_sb;
19427 + && !au_test_fs_bad_iattr(h_sb)
19429 + goto out; /* success */
19431 + if (au_dbstart(dentry) == bindex)
19432 + h_path->dentry = au_h_dptr(dentry, bindex);
19433 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19434 + h_path->dentry = au_plink_lkup(inode, bindex);
19435 + if (IS_ERR(h_path->dentry))
19436 + /* pretending success */
19437 + h_path->dentry = NULL;
19439 + dput(h_path->dentry);
19446 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19447 + struct dentry *dentry, struct kstat *st)
19450 + unsigned char positive;
19451 + struct path h_path;
19452 + struct inode *inode;
19453 + struct super_block *sb;
19455 + inode = d_inode(dentry);
19456 + sb = dentry->d_sb;
19457 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19458 + if (unlikely(err))
19460 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
19461 + if (unlikely(err))
19463 + if (unlikely(!h_path.dentry))
19464 + /* illegally overlapped or something */
19465 + goto out_fill; /* pretending success */
19467 + positive = d_is_positive(h_path.dentry);
19469 + err = vfs_getattr(&h_path, st);
19472 + au_refresh_iattr(inode, st,
19473 + d_inode(h_path.dentry)->i_nlink);
19474 + goto out_fill; /* success */
19480 + generic_fillattr(inode, st);
19482 + di_read_unlock(dentry, AuLock_IR);
19484 + si_read_unlock(sb);
19490 +/* ---------------------------------------------------------------------- */
19494 + * - the number of symlinks is not so many.
19497 + * - sbinfo (instead of iinfo) contains an hlist of struct au_symlink.
19498 + * If iinfo contained the hlist, then it would be rather large waste of memory
19500 + * - struct au_symlink contains the necessary info for h_inode follow_link() and
19504 +struct au_symlink {
19506 + struct hlist_node hlist;
19507 + struct rcu_head rcu;
19510 + struct inode *h_inode;
19514 +static void au_symlink_add(struct super_block *sb, struct au_symlink *slink,
19515 + struct inode *h_inode, void *cookie)
19517 + struct au_sbinfo *sbinfo;
19520 + slink->h_inode = h_inode;
19521 + slink->h_cookie = cookie;
19522 + sbinfo = au_sbi(sb);
19523 + au_sphl_add(&slink->hlist, &sbinfo->si_symlink);
19526 +static void au_symlink_del(struct super_block *sb, struct au_symlink *slink)
19528 + struct au_sbinfo *sbinfo;
19530 + /* do not iput() within rcu */
19531 + iput(slink->h_inode);
19532 + slink->h_inode = NULL;
19533 + sbinfo = au_sbi(sb);
19534 + au_sphl_del_rcu(&slink->hlist, &sbinfo->si_symlink);
19535 + kfree_rcu(slink, rcu);
19538 +static const char *aufs_follow_link(struct dentry *dentry, void **cookie)
19541 + struct inode *inode, *h_inode;
19542 + struct dentry *h_dentry;
19543 + struct au_symlink *slink;
19545 + aufs_bindex_t bindex;
19547 + ret = NULL; /* suppress a warning */
19548 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19549 + if (unlikely(err))
19552 + err = au_d_hashed_positive(dentry);
19553 + if (unlikely(err))
19557 + inode = d_inode(dentry);
19558 + bindex = au_ibstart(inode);
19559 + h_inode = au_h_iptr(inode, bindex);
19560 + if (unlikely(!h_inode->i_op->follow_link))
19564 + slink = kmalloc(sizeof(*slink), GFP_NOFS);
19565 + if (unlikely(!slink))
19570 + if (au_dbstart(dentry) <= bindex) {
19571 + h_dentry = au_h_dptr(dentry, bindex);
19576 + h_dentry = d_find_any_alias(h_inode);
19577 + if (IS_ERR(h_dentry)) {
19578 + err = PTR_ERR(h_dentry);
19582 + if (unlikely(!h_dentry))
19586 + AuDbg("%pf\n", h_inode->i_op->follow_link);
19587 + AuDbgDentry(h_dentry);
19588 + ret = h_inode->i_op->follow_link(h_dentry, cookie);
19591 + if (!IS_ERR_OR_NULL(ret)) {
19592 + au_symlink_add(inode->i_sb, slink, h_inode, *cookie);
19594 + AuDbg("slink %p\n", slink);
19595 + goto out_unlock; /* success */
19599 + slink->h_inode = NULL;
19600 + kfree_rcu(slink, rcu);
19602 + aufs_read_unlock(dentry, AuLock_IR);
19604 + if (unlikely(err))
19605 + ret = ERR_PTR(err);
19606 + AuTraceErrPtr(ret);
19610 +static void aufs_put_link(struct inode *inode, void *cookie)
19612 + struct au_symlink *slink;
19613 + struct inode *h_inode;
19616 + AuDbg("slink %p\n", slink);
19617 + h_inode = slink->h_inode;
19618 + AuDbg("%pf\n", h_inode->i_op->put_link);
19619 + AuDbgInode(h_inode);
19620 + if (h_inode->i_op->put_link)
19621 + h_inode->i_op->put_link(h_inode, slink->h_cookie);
19622 + au_symlink_del(inode->i_sb, slink);
19625 +/* ---------------------------------------------------------------------- */
19627 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19630 + struct super_block *sb;
19631 + struct inode *h_inode;
19633 + sb = inode->i_sb;
19634 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19636 + si_read_lock(sb, AuLock_FLUSH);
19637 + ii_write_lock_child(inode);
19639 + h_inode = au_h_iptr(inode, au_ibstart(inode));
19640 + err = vfsub_update_time(h_inode, ts, flags);
19643 + au_cpup_attr_timesizes(inode);
19644 + ii_write_unlock(inode);
19645 + si_read_unlock(sb);
19648 + if (!err && (flags & S_VERSION))
19649 + inode_inc_iversion(inode);
19654 +/* ---------------------------------------------------------------------- */
19656 +/* no getattr version will be set by module.c:aufs_init() */
19657 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
19659 + [AuIop_SYMLINK] = {
19660 + .permission = aufs_permission,
19661 +#ifdef CONFIG_FS_POSIX_ACL
19662 + .get_acl = aufs_get_acl,
19663 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19666 + .setattr = aufs_setattr,
19667 + .getattr = aufs_getattr,
19669 +#ifdef CONFIG_AUFS_XATTR
19670 + .setxattr = aufs_setxattr,
19671 + .getxattr = aufs_getxattr,
19672 + .listxattr = aufs_listxattr,
19673 + .removexattr = aufs_removexattr,
19676 + .readlink = generic_readlink,
19677 + .follow_link = aufs_follow_link,
19678 + .put_link = aufs_put_link,
19680 + /* .update_time = aufs_update_time */
19683 + .create = aufs_create,
19684 + .lookup = aufs_lookup,
19685 + .link = aufs_link,
19686 + .unlink = aufs_unlink,
19687 + .symlink = aufs_symlink,
19688 + .mkdir = aufs_mkdir,
19689 + .rmdir = aufs_rmdir,
19690 + .mknod = aufs_mknod,
19691 + .rename = aufs_rename,
19693 + .permission = aufs_permission,
19694 +#ifdef CONFIG_FS_POSIX_ACL
19695 + .get_acl = aufs_get_acl,
19696 + .set_acl = aufs_set_acl,
19699 + .setattr = aufs_setattr,
19700 + .getattr = aufs_getattr,
19702 +#ifdef CONFIG_AUFS_XATTR
19703 + .setxattr = aufs_setxattr,
19704 + .getxattr = aufs_getxattr,
19705 + .listxattr = aufs_listxattr,
19706 + .removexattr = aufs_removexattr,
19709 + .update_time = aufs_update_time,
19710 + .atomic_open = aufs_atomic_open,
19711 + .tmpfile = aufs_tmpfile
19713 + [AuIop_OTHER] = {
19714 + .permission = aufs_permission,
19715 +#ifdef CONFIG_FS_POSIX_ACL
19716 + .get_acl = aufs_get_acl,
19717 + .set_acl = aufs_set_acl,
19720 + .setattr = aufs_setattr,
19721 + .getattr = aufs_getattr,
19723 +#ifdef CONFIG_AUFS_XATTR
19724 + .setxattr = aufs_setxattr,
19725 + .getxattr = aufs_getxattr,
19726 + .listxattr = aufs_listxattr,
19727 + .removexattr = aufs_removexattr,
19730 + .update_time = aufs_update_time
19733 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19734 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19735 +++ linux/fs/aufs/i_op_del.c 2016-02-28 11:26:32.573304539 +0100
19738 + * Copyright (C) 2005-2016 Junjiro R. Okajima
19740 + * This program, aufs is free software; you can redistribute it and/or modify
19741 + * it under the terms of the GNU General Public License as published by
19742 + * the Free Software Foundation; either version 2 of the License, or
19743 + * (at your option) any later version.
19745 + * This program is distributed in the hope that it will be useful,
19746 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19747 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19748 + * GNU General Public License for more details.
19750 + * You should have received a copy of the GNU General Public License
19751 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19755 + * inode operations (del entry)
19761 + * decide if a new whiteout for @dentry is necessary or not.
19762 + * when it is necessary, prepare the parent dir for the upper branch whose
19763 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19764 + * be done by caller.
19766 + * 0: wh is unnecessary
19767 + * plus: wh is necessary
19770 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19772 + int need_wh, err;
19773 + aufs_bindex_t bstart;
19774 + struct super_block *sb;
19776 + sb = dentry->d_sb;
19777 + bstart = au_dbstart(dentry);
19778 + if (*bcpup < 0) {
19780 + if (au_test_ro(sb, bstart, d_inode(dentry))) {
19781 + err = AuWbrCopyup(au_sbi(sb), dentry);
19783 + if (unlikely(err < 0))
19787 + AuDebugOn(bstart < *bcpup
19788 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
19789 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
19791 + if (*bcpup != bstart) {
19792 + err = au_cpup_dirs(dentry, *bcpup);
19793 + if (unlikely(err))
19797 + struct au_dinfo *dinfo, *tmp;
19799 + need_wh = -ENOMEM;
19800 + dinfo = au_di(dentry);
19801 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19803 + au_di_cp(tmp, dinfo);
19804 + au_di_swap(tmp, dinfo);
19805 + /* returns the number of positive dentries */
19806 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
19807 + au_di_swap(tmp, dinfo);
19808 + au_rw_write_unlock(&tmp->di_rwsem);
19812 + AuDbg("need_wh %d\n", need_wh);
19820 + * simple tests for the del-entry operations.
19821 + * following the checks in vfs, plus the parent-child relationship.
19823 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19824 + struct dentry *h_parent, int isdir)
19828 + struct dentry *h_dentry, *h_latest;
19829 + struct inode *h_inode;
19831 + h_dentry = au_h_dptr(dentry, bindex);
19832 + if (d_really_is_positive(dentry)) {
19834 + if (unlikely(d_is_negative(h_dentry)))
19836 + h_inode = d_inode(h_dentry);
19837 + if (unlikely(!h_inode->i_nlink))
19840 + h_mode = h_inode->i_mode;
19843 + if (unlikely(S_ISDIR(h_mode)))
19845 + } else if (unlikely(!S_ISDIR(h_mode))) {
19850 + /* rename(2) case */
19852 + if (unlikely(d_is_positive(h_dentry)))
19857 + /* expected parent dir is locked */
19858 + if (unlikely(h_parent != h_dentry->d_parent))
19863 + * rmdir a dir may break the consistency on some filesystem.
19864 + * let's try heavy test.
19867 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
19868 + && au_test_h_perm(d_inode(h_parent),
19869 + MAY_EXEC | MAY_WRITE)))
19872 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
19874 + if (IS_ERR(h_latest))
19876 + if (h_latest == h_dentry)
19885 + * decide the branch where we operate for @dentry. the branch index will be set
19886 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
19887 + * dir for reverting.
19888 + * when a new whiteout is necessary, create it.
19890 +static struct dentry*
19891 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
19892 + struct au_dtime *dt, struct au_pin *pin)
19894 + struct dentry *wh_dentry;
19895 + struct super_block *sb;
19896 + struct path h_path;
19897 + int err, need_wh;
19898 + unsigned int udba;
19899 + aufs_bindex_t bcpup;
19901 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
19902 + wh_dentry = ERR_PTR(need_wh);
19903 + if (unlikely(need_wh < 0))
19906 + sb = dentry->d_sb;
19907 + udba = au_opt_udba(sb);
19909 + err = au_pin(pin, dentry, bcpup, udba,
19910 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19911 + wh_dentry = ERR_PTR(err);
19912 + if (unlikely(err))
19915 + h_path.dentry = au_pinned_h_parent(pin);
19916 + if (udba != AuOpt_UDBA_NONE
19917 + && au_dbstart(dentry) == bcpup) {
19918 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
19919 + wh_dentry = ERR_PTR(err);
19920 + if (unlikely(err))
19924 + h_path.mnt = au_sbr_mnt(sb, bcpup);
19925 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
19926 + wh_dentry = NULL;
19928 + goto out; /* success, no need to create whiteout */
19930 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
19931 + if (IS_ERR(wh_dentry))
19934 + /* returns with the parent is locked and wh_dentry is dget-ed */
19935 + goto out; /* success */
19940 + return wh_dentry;
19944 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
19945 + * in order to be revertible and save time for removing many child whiteouts
19947 + * returns 1 when there are too many child whiteout and caller should remove
19948 + * them asynchronously. returns 0 when the number of children is enough small to
19949 + * remove now or the branch fs is a remote fs.
19950 + * otherwise return an error.
19952 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
19953 + struct au_nhash *whlist, struct inode *dir)
19955 + int rmdir_later, err, dirwh;
19956 + struct dentry *h_dentry;
19957 + struct super_block *sb;
19958 + struct inode *inode;
19960 + sb = dentry->d_sb;
19961 + SiMustAnyLock(sb);
19962 + h_dentry = au_h_dptr(dentry, bindex);
19963 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
19964 + if (unlikely(err))
19967 + /* stop monitoring */
19968 + inode = d_inode(dentry);
19969 + au_hn_free(au_hi(inode, bindex));
19971 + if (!au_test_fs_remote(h_dentry->d_sb)) {
19972 + dirwh = au_sbi(sb)->si_dirwh;
19973 + rmdir_later = (dirwh <= 1);
19974 + if (!rmdir_later)
19975 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
19978 + return rmdir_later;
19981 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
19982 + if (unlikely(err)) {
19983 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
19984 + h_dentry, bindex, err);
19994 + * final procedure for deleting a entry.
19995 + * maintain dentry and iattr.
19997 +static void epilog(struct inode *dir, struct dentry *dentry,
19998 + aufs_bindex_t bindex)
20000 + struct inode *inode;
20002 + inode = d_inode(dentry);
20004 + inode->i_ctime = dir->i_ctime;
20006 + au_dir_ts(dir, bindex);
20007 + dir->i_version++;
20011 + * when an error happened, remove the created whiteout and revert everything.
20013 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
20014 + aufs_bindex_t bwh, struct dentry *wh_dentry,
20015 + struct dentry *dentry, struct au_dtime *dt)
20018 + struct path h_path = {
20019 + .dentry = wh_dentry,
20020 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
20023 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
20025 + au_set_dbwh(dentry, bwh);
20026 + au_dtime_revert(dt);
20030 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
20034 +/* ---------------------------------------------------------------------- */
20036 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
20039 + aufs_bindex_t bwh, bindex, bstart;
20040 + struct inode *inode, *h_dir, *delegated;
20041 + struct dentry *parent, *wh_dentry;
20042 + /* to reuduce stack size */
20044 + struct au_dtime dt;
20045 + struct au_pin pin;
20046 + struct path h_path;
20052 + a = kmalloc(sizeof(*a), GFP_NOFS);
20053 + if (unlikely(!a))
20056 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20057 + if (unlikely(err))
20059 + err = au_d_hashed_positive(dentry);
20060 + if (unlikely(err))
20062 + inode = d_inode(dentry);
20063 + IMustLock(inode);
20065 + if (unlikely(d_is_dir(dentry)))
20066 + goto out_unlock; /* possible? */
20068 + bstart = au_dbstart(dentry);
20069 + bwh = au_dbwh(dentry);
20071 + parent = dentry->d_parent; /* dir inode is locked */
20072 + di_write_lock_parent(parent);
20073 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
20075 + err = PTR_ERR(wh_dentry);
20076 + if (IS_ERR(wh_dentry))
20079 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
20080 + a->h_path.dentry = au_h_dptr(dentry, bstart);
20081 + dget(a->h_path.dentry);
20082 + if (bindex == bstart) {
20083 + h_dir = au_pinned_h_dir(&a->pin);
20084 + delegated = NULL;
20085 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
20086 + if (unlikely(err == -EWOULDBLOCK)) {
20087 + pr_warn("cannot retry for NFSv4 delegation"
20088 + " for an internal unlink\n");
20092 + /* dir inode is locked */
20093 + h_dir = d_inode(wh_dentry->d_parent);
20094 + IMustLock(h_dir);
20099 + vfsub_drop_nlink(inode);
20100 + epilog(dir, dentry, bindex);
20102 + /* update target timestamps */
20103 + if (bindex == bstart) {
20104 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
20106 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20108 + /* todo: this timestamp may be reverted later */
20109 + inode->i_ctime = h_dir->i_ctime;
20110 + goto out_unpin; /* success */
20117 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20124 + au_unpin(&a->pin);
20126 + dput(a->h_path.dentry);
20128 + di_write_unlock(parent);
20130 + aufs_read_unlock(dentry, AuLock_DW);
20137 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
20139 + int err, rmdir_later;
20140 + aufs_bindex_t bwh, bindex, bstart;
20141 + struct inode *inode;
20142 + struct dentry *parent, *wh_dentry, *h_dentry;
20143 + struct au_whtmp_rmdir *args;
20144 + /* to reuduce stack size */
20146 + struct au_dtime dt;
20147 + struct au_pin pin;
20153 + a = kmalloc(sizeof(*a), GFP_NOFS);
20154 + if (unlikely(!a))
20157 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20158 + if (unlikely(err))
20160 + err = au_alive_dir(dentry);
20161 + if (unlikely(err))
20163 + inode = d_inode(dentry);
20164 + IMustLock(inode);
20166 + if (unlikely(!d_is_dir(dentry)))
20167 + goto out_unlock; /* possible? */
20170 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20171 + if (unlikely(!args))
20174 + parent = dentry->d_parent; /* dir inode is locked */
20175 + di_write_lock_parent(parent);
20176 + err = au_test_empty(dentry, &args->whlist);
20177 + if (unlikely(err))
20180 + bstart = au_dbstart(dentry);
20181 + bwh = au_dbwh(dentry);
20183 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20185 + err = PTR_ERR(wh_dentry);
20186 + if (IS_ERR(wh_dentry))
20189 + h_dentry = au_h_dptr(dentry, bstart);
20192 + if (bindex == bstart) {
20193 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
20195 + rmdir_later = err;
20199 + /* stop monitoring */
20200 + au_hn_free(au_hi(inode, bstart));
20202 + /* dir inode is locked */
20203 + IMustLock(d_inode(wh_dentry->d_parent));
20208 + vfsub_dead_dir(inode);
20209 + au_set_dbdiropq(dentry, -1);
20210 + epilog(dir, dentry, bindex);
20212 + if (rmdir_later) {
20213 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
20217 + goto out_unpin; /* success */
20225 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20232 + au_unpin(&a->pin);
20236 + di_write_unlock(parent);
20238 + au_whtmp_rmdir_free(args);
20240 + aufs_read_unlock(dentry, AuLock_DW);
20247 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20248 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20249 +++ linux/fs/aufs/i_op_ren.c 2016-02-28 11:26:32.573304539 +0100
20252 + * Copyright (C) 2005-2016 Junjiro R. Okajima
20254 + * This program, aufs is free software; you can redistribute it and/or modify
20255 + * it under the terms of the GNU General Public License as published by
20256 + * the Free Software Foundation; either version 2 of the License, or
20257 + * (at your option) any later version.
20259 + * This program is distributed in the hope that it will be useful,
20260 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20261 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20262 + * GNU General Public License for more details.
20264 + * You should have received a copy of the GNU General Public License
20265 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20269 + * inode operation (rename entry)
20270 + * todo: this is crazy monster
20275 +enum { AuSRC, AuDST, AuSrcDst };
20276 +enum { AuPARENT, AuCHILD, AuParentChild };
20278 +#define AuRen_ISDIR 1
20279 +#define AuRen_ISSAMEDIR (1 << 1)
20280 +#define AuRen_WHSRC (1 << 2)
20281 +#define AuRen_WHDST (1 << 3)
20282 +#define AuRen_MNT_WRITE (1 << 4)
20283 +#define AuRen_DT_DSTDIR (1 << 5)
20284 +#define AuRen_DIROPQ (1 << 6)
20285 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20286 +#define au_fset_ren(flags, name) \
20287 + do { (flags) |= AuRen_##name; } while (0)
20288 +#define au_fclr_ren(flags, name) \
20289 + do { (flags) &= ~AuRen_##name; } while (0)
20291 +struct au_ren_args {
20293 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20295 + struct inode *dir, *inode;
20296 + struct au_hinode *hdir;
20297 + struct au_dtime dt[AuParentChild];
20298 + aufs_bindex_t bstart;
20301 +#define src_dentry sd[AuSRC].dentry
20302 +#define src_dir sd[AuSRC].dir
20303 +#define src_inode sd[AuSRC].inode
20304 +#define src_h_dentry sd[AuSRC].h_dentry
20305 +#define src_parent sd[AuSRC].parent
20306 +#define src_h_parent sd[AuSRC].h_parent
20307 +#define src_wh_dentry sd[AuSRC].wh_dentry
20308 +#define src_hdir sd[AuSRC].hdir
20309 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20310 +#define src_dt sd[AuSRC].dt
20311 +#define src_bstart sd[AuSRC].bstart
20313 +#define dst_dentry sd[AuDST].dentry
20314 +#define dst_dir sd[AuDST].dir
20315 +#define dst_inode sd[AuDST].inode
20316 +#define dst_h_dentry sd[AuDST].h_dentry
20317 +#define dst_parent sd[AuDST].parent
20318 +#define dst_h_parent sd[AuDST].h_parent
20319 +#define dst_wh_dentry sd[AuDST].wh_dentry
20320 +#define dst_hdir sd[AuDST].hdir
20321 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20322 +#define dst_dt sd[AuDST].dt
20323 +#define dst_bstart sd[AuDST].bstart
20325 + struct dentry *h_trap;
20326 + struct au_branch *br;
20327 + struct au_hinode *src_hinode;
20328 + struct path h_path;
20329 + struct au_nhash whlist;
20330 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
20332 + unsigned int flags;
20334 + struct au_whtmp_rmdir *thargs;
20335 + struct dentry *h_dst;
20338 +/* ---------------------------------------------------------------------- */
20341 + * functions for reverting.
20342 + * when an error happened in a single rename systemcall, we should revert
20343 + * everything as if nothing happened.
20344 + * we don't need to revert the copied-up/down the parent dir since they are
20348 +#define RevertFailure(fmt, ...) do { \
20349 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20350 + ##__VA_ARGS__, err, rerr); \
20354 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20358 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20359 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
20360 + au_hn_imtx_unlock(a->src_hinode);
20361 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
20363 + RevertFailure("remove diropq %pd", a->src_dentry);
20366 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20369 + struct inode *delegated;
20371 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20372 + a->src_h_parent);
20373 + rerr = PTR_ERR(a->h_path.dentry);
20374 + if (IS_ERR(a->h_path.dentry)) {
20375 + RevertFailure("lkup one %pd", a->src_dentry);
20379 + delegated = NULL;
20380 + rerr = vfsub_rename(a->dst_h_dir,
20381 + au_h_dptr(a->src_dentry, a->btgt),
20382 + a->src_h_dir, &a->h_path, &delegated);
20383 + if (unlikely(rerr == -EWOULDBLOCK)) {
20384 + pr_warn("cannot retry for NFSv4 delegation"
20385 + " for an internal rename\n");
20388 + d_drop(a->h_path.dentry);
20389 + dput(a->h_path.dentry);
20390 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20392 + RevertFailure("rename %pd", a->src_dentry);
20395 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20398 + struct inode *delegated;
20400 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20401 + a->dst_h_parent);
20402 + rerr = PTR_ERR(a->h_path.dentry);
20403 + if (IS_ERR(a->h_path.dentry)) {
20404 + RevertFailure("lkup one %pd", a->dst_dentry);
20407 + if (d_is_positive(a->h_path.dentry)) {
20408 + d_drop(a->h_path.dentry);
20409 + dput(a->h_path.dentry);
20413 + delegated = NULL;
20414 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20416 + if (unlikely(rerr == -EWOULDBLOCK)) {
20417 + pr_warn("cannot retry for NFSv4 delegation"
20418 + " for an internal rename\n");
20421 + d_drop(a->h_path.dentry);
20422 + dput(a->h_path.dentry);
20424 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20426 + RevertFailure("rename %pd", a->h_dst);
20429 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20433 + a->h_path.dentry = a->src_wh_dentry;
20434 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20435 + au_set_dbwh(a->src_dentry, a->src_bwh);
20437 + RevertFailure("unlink %pd", a->src_wh_dentry);
20439 +#undef RevertFailure
20441 +/* ---------------------------------------------------------------------- */
20444 + * when we have to copyup the renaming entry, do it with the rename-target name
20445 + * in order to minimize the cost (the later actual rename is unnecessary).
20446 + * otherwise rename it on the target branch.
20448 +static int au_ren_or_cpup(struct au_ren_args *a)
20451 + struct dentry *d;
20452 + struct inode *delegated;
20454 + d = a->src_dentry;
20455 + if (au_dbstart(d) == a->btgt) {
20456 + a->h_path.dentry = a->dst_h_dentry;
20457 + if (au_ftest_ren(a->flags, DIROPQ)
20458 + && au_dbdiropq(d) == a->btgt)
20459 + au_fclr_ren(a->flags, DIROPQ);
20460 + AuDebugOn(au_dbstart(d) != a->btgt);
20461 + delegated = NULL;
20462 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20463 + a->dst_h_dir, &a->h_path, &delegated);
20464 + if (unlikely(err == -EWOULDBLOCK)) {
20465 + pr_warn("cannot retry for NFSv4 delegation"
20466 + " for an internal rename\n");
20472 + if (!err && a->h_dst)
20473 + /* it will be set to dinfo later */
20479 +/* cf. aufs_rmdir() */
20480 +static int au_ren_del_whtmp(struct au_ren_args *a)
20483 + struct inode *dir;
20485 + dir = a->dst_dir;
20486 + SiMustAnyLock(dir->i_sb);
20487 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20488 + au_sbi(dir->i_sb)->si_dirwh)
20489 + || au_test_fs_remote(a->h_dst->d_sb)) {
20490 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20491 + if (unlikely(err))
20492 + pr_warn("failed removing whtmp dir %pd (%d), "
20493 + "ignored.\n", a->h_dst, err);
20495 + au_nhash_wh_free(&a->thargs->whlist);
20496 + a->thargs->whlist = a->whlist;
20497 + a->whlist.nh_num = 0;
20498 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20500 + a->thargs = NULL;
20506 +/* make it 'opaque' dir. */
20507 +static int au_ren_diropq(struct au_ren_args *a)
20510 + struct dentry *diropq;
20513 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
20514 + a->src_hinode = au_hi(a->src_inode, a->btgt);
20515 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20516 + diropq = au_diropq_create(a->src_dentry, a->btgt);
20517 + au_hn_imtx_unlock(a->src_hinode);
20518 + if (IS_ERR(diropq))
20519 + err = PTR_ERR(diropq);
20526 +static int do_rename(struct au_ren_args *a)
20529 + struct dentry *d, *h_d;
20531 + /* prepare workqueue args for asynchronous rmdir */
20532 + h_d = a->dst_h_dentry;
20533 + if (au_ftest_ren(a->flags, ISDIR) && d_is_positive(h_d)) {
20535 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
20536 + if (unlikely(!a->thargs))
20538 + a->h_dst = dget(h_d);
20541 + /* create whiteout for src_dentry */
20542 + if (au_ftest_ren(a->flags, WHSRC)) {
20543 + a->src_bwh = au_dbwh(a->src_dentry);
20544 + AuDebugOn(a->src_bwh >= 0);
20546 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
20547 + err = PTR_ERR(a->src_wh_dentry);
20548 + if (IS_ERR(a->src_wh_dentry))
20552 + /* lookup whiteout for dentry */
20553 + if (au_ftest_ren(a->flags, WHDST)) {
20554 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
20556 + err = PTR_ERR(h_d);
20559 + if (d_is_negative(h_d))
20562 + a->dst_wh_dentry = h_d;
20565 + /* rename dentry to tmpwh */
20567 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20568 + if (unlikely(err))
20571 + d = a->dst_dentry;
20572 + au_set_h_dptr(d, a->btgt, NULL);
20573 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20574 + if (unlikely(err))
20576 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20579 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_bstart != a->btgt);
20581 + /* rename by vfs_rename or cpup */
20582 + d = a->dst_dentry;
20583 + if (au_ftest_ren(a->flags, ISDIR)
20584 + && (a->dst_wh_dentry
20585 + || au_dbdiropq(d) == a->btgt
20586 + /* hide the lower to keep xino */
20587 + || a->btgt < au_dbend(d)
20588 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
20589 + au_fset_ren(a->flags, DIROPQ);
20590 + err = au_ren_or_cpup(a);
20591 + if (unlikely(err))
20592 + /* leave the copied-up one */
20595 + /* make dir opaque */
20596 + if (au_ftest_ren(a->flags, DIROPQ)) {
20597 + err = au_ren_diropq(a);
20598 + if (unlikely(err))
20602 + /* update target timestamps */
20603 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
20604 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20605 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20606 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20608 + /* remove whiteout for dentry */
20609 + if (a->dst_wh_dentry) {
20610 + a->h_path.dentry = a->dst_wh_dentry;
20611 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20613 + if (unlikely(err))
20617 + /* remove whtmp */
20619 + au_ren_del_whtmp(a); /* ignore this error */
20621 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20623 + goto out_success;
20626 + if (au_ftest_ren(a->flags, DIROPQ))
20627 + au_ren_rev_diropq(err, a);
20629 + au_ren_rev_rename(err, a);
20633 + au_ren_rev_whtmp(err, a);
20635 + dput(a->dst_wh_dentry);
20636 + a->dst_wh_dentry = NULL;
20638 + if (a->src_wh_dentry)
20639 + au_ren_rev_whsrc(err, a);
20641 + dput(a->src_wh_dentry);
20642 + dput(a->dst_wh_dentry);
20646 + au_whtmp_rmdir_free(a->thargs);
20647 + a->thargs = NULL;
20653 +/* ---------------------------------------------------------------------- */
20656 + * test if @dentry dir can be rename destination or not.
20657 + * success means, it is a logically empty dir.
20659 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20661 + return au_test_empty(dentry, whlist);
20665 + * test if @dentry dir can be rename source or not.
20666 + * if it can, return 0 and @children is filled.
20668 + * - it is a logically empty dir.
20669 + * - or, it exists on writable branch and has no children including whiteouts
20670 + * on the lower branch.
20672 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20675 + unsigned int rdhash;
20676 + aufs_bindex_t bstart;
20678 + bstart = au_dbstart(dentry);
20679 + if (bstart != btgt) {
20680 + struct au_nhash whlist;
20682 + SiMustAnyLock(dentry->d_sb);
20683 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20685 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20687 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20688 + if (unlikely(err))
20690 + err = au_test_empty(dentry, &whlist);
20691 + au_nhash_wh_free(&whlist);
20695 + if (bstart == au_dbtaildir(dentry))
20696 + return 0; /* success */
20698 + err = au_test_empty_lower(dentry);
20701 + if (err == -ENOTEMPTY) {
20702 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20703 + " is not supported\n");
20709 +/* side effect: sets whlist and h_dentry */
20710 +static int au_ren_may_dir(struct au_ren_args *a)
20713 + unsigned int rdhash;
20714 + struct dentry *d;
20716 + d = a->dst_dentry;
20717 + SiMustAnyLock(d->d_sb);
20720 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
20721 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20723 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20724 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20725 + if (unlikely(err))
20728 + au_set_dbstart(d, a->dst_bstart);
20729 + err = may_rename_dstdir(d, &a->whlist);
20730 + au_set_dbstart(d, a->btgt);
20732 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
20733 + if (unlikely(err))
20736 + d = a->src_dentry;
20737 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
20738 + if (au_ftest_ren(a->flags, ISDIR)) {
20739 + err = may_rename_srcdir(d, a->btgt);
20740 + if (unlikely(err)) {
20741 + au_nhash_wh_free(&a->whlist);
20742 + a->whlist.nh_num = 0;
20749 +/* ---------------------------------------------------------------------- */
20752 + * simple tests for rename.
20753 + * following the checks in vfs, plus the parent-child relationship.
20755 +static int au_may_ren(struct au_ren_args *a)
20758 + struct inode *h_inode;
20760 + if (a->src_bstart == a->btgt) {
20761 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20762 + au_ftest_ren(a->flags, ISDIR));
20763 + if (unlikely(err))
20766 + if (unlikely(a->src_h_dentry == a->h_trap))
20771 + if (a->dst_bstart != a->btgt)
20774 + err = -ENOTEMPTY;
20775 + if (unlikely(a->dst_h_dentry == a->h_trap))
20779 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20780 + if (d_really_is_negative(a->dst_dentry)) {
20781 + if (d_is_negative(a->dst_h_dentry))
20782 + err = au_may_add(a->dst_dentry, a->btgt,
20783 + a->dst_h_parent, isdir);
20785 + if (unlikely(d_is_negative(a->dst_h_dentry)))
20787 + h_inode = d_inode(a->dst_h_dentry);
20788 + if (h_inode->i_nlink)
20789 + err = au_may_del(a->dst_dentry, a->btgt,
20790 + a->dst_h_parent, isdir);
20794 + if (unlikely(err == -ENOENT || err == -EEXIST))
20800 +/* ---------------------------------------------------------------------- */
20805 + * - src_dir and dir by lock_rename()
20806 + * - inode if exitsts
20809 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
20811 + * + di_write_lock2_child()
20812 + * + di_write_lock_child()
20813 + * + ii_write_lock_child()
20814 + * + di_write_lock_child2()
20815 + * + ii_write_lock_child2()
20816 + * + src_parent and parent
20817 + * + di_write_lock_parent()
20818 + * + ii_write_lock_parent()
20819 + * + di_write_lock_parent2()
20820 + * + ii_write_lock_parent2()
20821 + * + lower src_dir and dir by vfsub_lock_rename()
20822 + * + verify the every relationships between child and parent. if any
20823 + * of them failed, unlock all and return -EBUSY.
20825 +static void au_ren_unlock(struct au_ren_args *a)
20827 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
20828 + a->dst_h_parent, a->dst_hdir);
20829 + if (au_ftest_ren(a->flags, MNT_WRITE))
20830 + vfsub_mnt_drop_write(au_br_mnt(a->br));
20833 +static int au_ren_lock(struct au_ren_args *a)
20836 + unsigned int udba;
20839 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
20840 + a->src_hdir = au_hi(a->src_dir, a->btgt);
20841 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
20842 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
20844 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
20845 + if (unlikely(err))
20847 + au_fset_ren(a->flags, MNT_WRITE);
20848 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
20849 + a->dst_h_parent, a->dst_hdir);
20850 + udba = au_opt_udba(a->src_dentry->d_sb);
20851 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
20852 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
20853 + err = au_busy_or_stale();
20854 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
20855 + err = au_h_verify(a->src_h_dentry, udba,
20856 + d_inode(a->src_h_parent), a->src_h_parent,
20858 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
20859 + err = au_h_verify(a->dst_h_dentry, udba,
20860 + d_inode(a->dst_h_parent), a->dst_h_parent,
20863 + goto out; /* success */
20865 + err = au_busy_or_stale();
20866 + au_ren_unlock(a);
20872 +/* ---------------------------------------------------------------------- */
20874 +static void au_ren_refresh_dir(struct au_ren_args *a)
20876 + struct inode *dir;
20878 + dir = a->dst_dir;
20879 + dir->i_version++;
20880 + if (au_ftest_ren(a->flags, ISDIR)) {
20881 + /* is this updating defined in POSIX? */
20882 + au_cpup_attr_timesizes(a->src_inode);
20883 + au_cpup_attr_nlink(dir, /*force*/1);
20886 + au_dir_ts(dir, a->btgt);
20888 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20891 + dir = a->src_dir;
20892 + dir->i_version++;
20893 + if (au_ftest_ren(a->flags, ISDIR))
20894 + au_cpup_attr_nlink(dir, /*force*/1);
20895 + au_dir_ts(dir, a->btgt);
20898 +static void au_ren_refresh(struct au_ren_args *a)
20900 + aufs_bindex_t bend, bindex;
20901 + struct dentry *d, *h_d;
20902 + struct inode *i, *h_i;
20903 + struct super_block *sb;
20905 + d = a->dst_dentry;
20908 + /* already dget-ed by au_ren_or_cpup() */
20909 + au_set_h_dptr(d, a->btgt, a->h_dst);
20911 + i = a->dst_inode;
20913 + if (!au_ftest_ren(a->flags, ISDIR))
20914 + vfsub_drop_nlink(i);
20916 + vfsub_dead_dir(i);
20917 + au_cpup_attr_timesizes(i);
20919 + au_update_dbrange(d, /*do_put_zero*/1);
20922 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
20923 + au_set_h_dptr(d, bindex, NULL);
20924 + bend = au_dbend(d);
20925 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
20926 + au_set_h_dptr(d, bindex, NULL);
20927 + au_update_dbrange(d, /*do_put_zero*/0);
20930 + d = a->src_dentry;
20931 + au_set_dbwh(d, -1);
20932 + bend = au_dbend(d);
20933 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20934 + h_d = au_h_dptr(d, bindex);
20936 + au_set_h_dptr(d, bindex, NULL);
20938 + au_set_dbend(d, a->btgt);
20941 + i = a->src_inode;
20942 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
20943 + return; /* success */
20945 + bend = au_ibend(i);
20946 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20947 + h_i = au_h_iptr(i, bindex);
20949 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
20950 + /* ignore this error */
20951 + au_set_h_iptr(i, bindex, NULL, 0);
20954 + au_set_ibend(i, a->btgt);
20957 +/* ---------------------------------------------------------------------- */
20959 +/* mainly for link(2) and rename(2) */
20960 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
20962 + aufs_bindex_t bdiropq, bwh;
20963 + struct dentry *parent;
20964 + struct au_branch *br;
20966 + parent = dentry->d_parent;
20967 + IMustLock(d_inode(parent)); /* dir is locked */
20969 + bdiropq = au_dbdiropq(parent);
20970 + bwh = au_dbwh(dentry);
20971 + br = au_sbr(dentry->d_sb, btgt);
20972 + if (au_br_rdonly(br)
20973 + || (0 <= bdiropq && bdiropq < btgt)
20974 + || (0 <= bwh && bwh < btgt))
20977 + AuDbg("btgt %d\n", btgt);
20981 +/* sets src_bstart, dst_bstart and btgt */
20982 +static int au_ren_wbr(struct au_ren_args *a)
20985 + struct au_wr_dir_args wr_dir_args = {
20986 + /* .force_btgt = -1, */
20987 + .flags = AuWrDir_ADD_ENTRY
20990 + a->src_bstart = au_dbstart(a->src_dentry);
20991 + a->dst_bstart = au_dbstart(a->dst_dentry);
20992 + if (au_ftest_ren(a->flags, ISDIR))
20993 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
20994 + wr_dir_args.force_btgt = a->src_bstart;
20995 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
20996 + wr_dir_args.force_btgt = a->dst_bstart;
20997 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
20998 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
21004 +static void au_ren_dt(struct au_ren_args *a)
21006 + a->h_path.dentry = a->src_h_parent;
21007 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
21008 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
21009 + a->h_path.dentry = a->dst_h_parent;
21010 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
21013 + au_fclr_ren(a->flags, DT_DSTDIR);
21014 + if (!au_ftest_ren(a->flags, ISDIR))
21017 + a->h_path.dentry = a->src_h_dentry;
21018 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
21019 + if (d_is_positive(a->dst_h_dentry)) {
21020 + au_fset_ren(a->flags, DT_DSTDIR);
21021 + a->h_path.dentry = a->dst_h_dentry;
21022 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
21026 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
21028 + struct dentry *h_d;
21029 + struct mutex *h_mtx;
21031 + au_dtime_revert(a->src_dt + AuPARENT);
21032 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
21033 + au_dtime_revert(a->dst_dt + AuPARENT);
21035 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
21036 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
21037 + h_mtx = &d_inode(h_d)->i_mutex;
21038 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
21039 + au_dtime_revert(a->src_dt + AuCHILD);
21040 + mutex_unlock(h_mtx);
21042 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
21043 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
21044 + h_mtx = &d_inode(h_d)->i_mutex;
21045 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
21046 + au_dtime_revert(a->dst_dt + AuCHILD);
21047 + mutex_unlock(h_mtx);
21052 +/* ---------------------------------------------------------------------- */
21054 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
21055 + struct inode *_dst_dir, struct dentry *_dst_dentry)
21058 + /* reduce stack space */
21059 + struct au_ren_args *a;
21061 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
21062 + IMustLock(_src_dir);
21063 + IMustLock(_dst_dir);
21066 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
21067 + a = kzalloc(sizeof(*a), GFP_NOFS);
21068 + if (unlikely(!a))
21071 + a->src_dir = _src_dir;
21072 + a->src_dentry = _src_dentry;
21073 + a->src_inode = NULL;
21074 + if (d_really_is_positive(a->src_dentry))
21075 + a->src_inode = d_inode(a->src_dentry);
21076 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
21077 + a->dst_dir = _dst_dir;
21078 + a->dst_dentry = _dst_dentry;
21079 + a->dst_inode = NULL;
21080 + if (d_really_is_positive(a->dst_dentry))
21081 + a->dst_inode = d_inode(a->dst_dentry);
21082 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
21083 + if (a->dst_inode) {
21084 + IMustLock(a->dst_inode);
21085 + au_igrab(a->dst_inode);
21089 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
21090 + if (d_is_dir(a->src_dentry)) {
21091 + au_fset_ren(a->flags, ISDIR);
21092 + if (unlikely(d_really_is_positive(a->dst_dentry)
21093 + && !d_is_dir(a->dst_dentry)))
21095 + flags |= AuLock_DIRS;
21097 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, flags);
21098 + if (unlikely(err))
21101 + err = au_d_hashed_positive(a->src_dentry);
21102 + if (unlikely(err))
21105 + if (a->dst_inode) {
21107 + * If it is a dir, VFS unhash dst_dentry before this
21108 + * function. It means we cannot rely upon d_unhashed().
21110 + if (unlikely(!a->dst_inode->i_nlink))
21112 + if (!S_ISDIR(a->dst_inode->i_mode)) {
21113 + err = au_d_hashed_positive(a->dst_dentry);
21114 + if (unlikely(err))
21116 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
21118 + } else if (unlikely(d_unhashed(a->dst_dentry)))
21122 + * is it possible?
21123 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
21124 + * there may exist a problem somewhere else.
21127 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
21130 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
21131 + di_write_lock_parent(a->dst_parent);
21133 + /* which branch we process */
21134 + err = au_ren_wbr(a);
21135 + if (unlikely(err < 0))
21137 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
21138 + a->h_path.mnt = au_br_mnt(a->br);
21140 + /* are they available to be renamed */
21141 + err = au_ren_may_dir(a);
21142 + if (unlikely(err))
21143 + goto out_children;
21145 + /* prepare the writable parent dir on the same branch */
21146 + if (a->dst_bstart == a->btgt) {
21147 + au_fset_ren(a->flags, WHDST);
21149 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
21150 + if (unlikely(err))
21151 + goto out_children;
21154 + if (a->src_dir != a->dst_dir) {
21156 + * this temporary unlock is safe,
21157 + * because both dir->i_mutex are locked.
21159 + di_write_unlock(a->dst_parent);
21160 + di_write_lock_parent(a->src_parent);
21161 + err = au_wr_dir_need_wh(a->src_dentry,
21162 + au_ftest_ren(a->flags, ISDIR),
21164 + di_write_unlock(a->src_parent);
21165 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
21166 + au_fclr_ren(a->flags, ISSAMEDIR);
21168 + err = au_wr_dir_need_wh(a->src_dentry,
21169 + au_ftest_ren(a->flags, ISDIR),
21171 + if (unlikely(err < 0))
21172 + goto out_children;
21174 + au_fset_ren(a->flags, WHSRC);
21177 + if (a->src_bstart != a->btgt) {
21178 + struct au_pin pin;
21180 + err = au_pin(&pin, a->src_dentry, a->btgt,
21181 + au_opt_udba(a->src_dentry->d_sb),
21182 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21184 + struct au_cp_generic cpg = {
21185 + .dentry = a->src_dentry,
21187 + .bsrc = a->src_bstart,
21190 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21192 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
21193 + err = au_sio_cpup_simple(&cpg);
21196 + if (unlikely(err))
21197 + goto out_children;
21198 + a->src_bstart = a->btgt;
21199 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21200 + au_fset_ren(a->flags, WHSRC);
21203 + /* lock them all */
21204 + err = au_ren_lock(a);
21205 + if (unlikely(err))
21206 + /* leave the copied-up one */
21207 + goto out_children;
21209 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21210 + err = au_may_ren(a);
21211 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21212 + err = -ENAMETOOLONG;
21213 + if (unlikely(err))
21216 + /* store timestamps to be revertible */
21220 + err = do_rename(a);
21221 + if (unlikely(err))
21224 + /* update dir attributes */
21225 + au_ren_refresh_dir(a);
21227 + /* dput/iput all lower dentries */
21228 + au_ren_refresh(a);
21230 + goto out_hdir; /* success */
21233 + au_ren_rev_dt(err, a);
21235 + au_ren_unlock(a);
21237 + au_nhash_wh_free(&a->whlist);
21238 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
21239 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
21240 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21241 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
21245 + d_move(a->src_dentry, a->dst_dentry);
21247 + au_update_dbstart(a->dst_dentry);
21248 + if (!a->dst_inode)
21249 + d_drop(a->dst_dentry);
21251 + if (au_ftest_ren(a->flags, ISSAMEDIR))
21252 + di_write_unlock(a->dst_parent);
21254 + di_write_unlock2(a->src_parent, a->dst_parent);
21256 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21258 + iput(a->dst_inode);
21260 + au_whtmp_rmdir_free(a->thargs);
21266 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21267 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21268 +++ linux/fs/aufs/Kconfig 2016-02-28 11:26:32.569971135 +0100
21271 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21273 + Aufs is a stackable unification filesystem such as Unionfs,
21274 + which unifies several directories and provides a merged single
21276 + In the early days, aufs was entirely re-designed and
21277 + re-implemented Unionfs Version 1.x series. Introducing many
21278 + original ideas, approaches and improvements, it becomes totally
21279 + different from Unionfs while keeping the basic features.
21283 + prompt "Maximum number of branches"
21284 + default AUFS_BRANCH_MAX_127
21286 + Specifies the maximum number of branches (or member directories)
21287 + in a single aufs. The larger value consumes more system
21288 + resources and has a minor impact to performance.
21289 +config AUFS_BRANCH_MAX_127
21292 + Specifies the maximum number of branches (or member directories)
21293 + in a single aufs. The larger value consumes more system
21294 + resources and has a minor impact to performance.
21295 +config AUFS_BRANCH_MAX_511
21298 + Specifies the maximum number of branches (or member directories)
21299 + in a single aufs. The larger value consumes more system
21300 + resources and has a minor impact to performance.
21301 +config AUFS_BRANCH_MAX_1023
21304 + Specifies the maximum number of branches (or member directories)
21305 + in a single aufs. The larger value consumes more system
21306 + resources and has a minor impact to performance.
21307 +config AUFS_BRANCH_MAX_32767
21310 + Specifies the maximum number of branches (or member directories)
21311 + in a single aufs. The larger value consumes more system
21312 + resources and has a minor impact to performance.
21315 +config AUFS_SBILIST
21317 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21320 + Automatic configuration for internal use.
21321 + When aufs supports Magic SysRq or /proc, enabled automatically.
21323 +config AUFS_HNOTIFY
21324 + bool "Detect direct branch access (bypassing aufs)"
21326 + If you want to modify files on branches directly, eg. bypassing aufs,
21327 + and want aufs to detect the changes of them fully, then enable this
21328 + option and use 'udba=notify' mount option.
21329 + Currently there is only one available configuration, "fsnotify".
21330 + It will have a negative impact to the performance.
21331 + See detail in aufs.5.
21334 + prompt "method" if AUFS_HNOTIFY
21335 + default AUFS_HFSNOTIFY
21336 +config AUFS_HFSNOTIFY
21341 +config AUFS_EXPORT
21342 + bool "NFS-exportable aufs"
21343 + depends on EXPORTFS
21345 + If you want to export your mounted aufs via NFS, then enable this
21346 + option. There are several requirements for this configuration.
21347 + See detail in aufs.5.
21349 +config AUFS_INO_T_64
21351 + depends on AUFS_EXPORT
21352 + depends on 64BIT && !(ALPHA || S390)
21355 + Automatic configuration for internal use.
21356 + /* typedef unsigned long/int __kernel_ino_t */
21357 + /* alpha and s390x are int */
21360 + bool "support for XATTR/EA (including Security Labels)"
21362 + If your branch fs supports XATTR/EA and you want to make them
21363 + available in aufs too, then enable this opsion and specify the
21364 + branch attributes for EA.
21365 + See detail in aufs.5.
21368 + bool "File-based Hierarchical Storage Management"
21370 + Hierarchical Storage Management (or HSM) is a well-known feature
21371 + in the storage world. Aufs provides this feature as file-based.
21372 + with multiple branches.
21373 + These multiple branches are prioritized, ie. the topmost one
21374 + should be the fastest drive and be used heavily.
21377 + bool "Readdir in userspace"
21379 + Aufs has two methods to provide a merged view for a directory,
21380 + by a user-space library and by kernel-space natively. The latter
21381 + is always enabled but sometimes large and slow.
21382 + If you enable this option, install the library in aufs2-util
21383 + package, and set some environment variables for your readdir(3),
21384 + then the work will be handled in user-space which generally
21385 + shows better performance in most cases.
21386 + See detail in aufs.5.
21389 + bool "Show whiteouts"
21391 + If you want to make the whiteouts in aufs visible, then enable
21392 + this option and specify 'shwh' mount option. Although it may
21393 + sounds like philosophy or something, but in technically it
21394 + simply shows the name of whiteout with keeping its behaviour.
21396 +config AUFS_BR_RAMFS
21397 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21399 + If you want to use ramfs as an aufs branch fs, then enable this
21400 + option. Generally tmpfs is recommended.
21401 + Aufs prohibited them to be a branch fs by default, because
21402 + initramfs becomes unusable after switch_root or something
21403 + generally. If you sets initramfs as an aufs branch and boot your
21404 + system by switch_root, you will meet a problem easily since the
21405 + files in initramfs may be inaccessible.
21406 + Unless you are going to use ramfs as an aufs branch fs without
21407 + switch_root or something, leave it N.
21409 +config AUFS_BR_FUSE
21410 + bool "Fuse fs as an aufs branch"
21411 + depends on FUSE_FS
21414 + If you want to use fuse-based userspace filesystem as an aufs
21415 + branch fs, then enable this option.
21416 + It implements the internal poll(2) operation which is
21417 + implemented by fuse only (curretnly).
21422 + Automatic configuration for internal use.
21424 +config AUFS_BR_HFSPLUS
21425 + bool "Hfsplus as an aufs branch"
21426 + depends on HFSPLUS_FS
21429 + If you want to use hfsplus fs as an aufs branch fs, then enable
21430 + this option. This option introduces a small overhead at
21431 + copying-up a file on hfsplus.
21433 +config AUFS_BDEV_LOOP
21435 + depends on BLK_DEV_LOOP
21438 + Automatic configuration for internal use.
21439 + Convert =[ym] into =y.
21442 + bool "Debug aufs"
21444 + Enable this to compile aufs internal debug code.
21445 + It will have a negative impact to the performance.
21447 +config AUFS_MAGIC_SYSRQ
21449 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21452 + Automatic configuration for internal use.
21453 + When aufs supports Magic SysRq, enabled automatically.
21455 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21456 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21457 +++ linux/fs/aufs/loop.c 2016-02-28 11:26:32.573304539 +0100
21460 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21462 + * This program, aufs is free software; you can redistribute it and/or modify
21463 + * it under the terms of the GNU General Public License as published by
21464 + * the Free Software Foundation; either version 2 of the License, or
21465 + * (at your option) any later version.
21467 + * This program is distributed in the hope that it will be useful,
21468 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21469 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21470 + * GNU General Public License for more details.
21472 + * You should have received a copy of the GNU General Public License
21473 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21477 + * support for loopback block device as a branch
21482 +/* added into drivers/block/loop.c */
21483 +static struct file *(*backing_file_func)(struct super_block *sb);
21486 + * test if two lower dentries have overlapping branches.
21488 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21490 + struct super_block *h_sb;
21491 + struct file *backing_file;
21493 + if (unlikely(!backing_file_func)) {
21494 + /* don't load "loop" module here */
21495 + backing_file_func = symbol_get(loop_backing_file);
21496 + if (unlikely(!backing_file_func))
21497 + /* "loop" module is not loaded */
21501 + h_sb = h_adding->d_sb;
21502 + backing_file = backing_file_func(h_sb);
21503 + if (!backing_file)
21506 + h_adding = backing_file->f_path.dentry;
21508 + * h_adding can be local NFS.
21509 + * in this case aufs cannot detect the loop.
21511 + if (unlikely(h_adding->d_sb == sb))
21513 + return !!au_test_subdir(h_adding, sb->s_root);
21516 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21517 +int au_test_loopback_kthread(void)
21520 + struct task_struct *tsk = current;
21521 + char c, comm[sizeof(tsk->comm)];
21524 + if (tsk->flags & PF_KTHREAD) {
21525 + get_task_comm(comm, tsk);
21527 + ret = ('0' <= c && c <= '9'
21528 + && !strncmp(comm, "loop", 4));
21534 +/* ---------------------------------------------------------------------- */
21536 +#define au_warn_loopback_step 16
21537 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21538 +static unsigned long *au_warn_loopback_array;
21540 +void au_warn_loopback(struct super_block *h_sb)
21542 + int i, new_nelem;
21543 + unsigned long *a, magic;
21544 + static DEFINE_SPINLOCK(spin);
21546 + magic = h_sb->s_magic;
21547 + spin_lock(&spin);
21548 + a = au_warn_loopback_array;
21549 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21550 + if (a[i] == magic) {
21551 + spin_unlock(&spin);
21555 + /* h_sb is new to us, print it */
21556 + if (i < au_warn_loopback_nelem) {
21561 + /* expand the array */
21562 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21563 + a = au_kzrealloc(au_warn_loopback_array,
21564 + au_warn_loopback_nelem * sizeof(unsigned long),
21565 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
21567 + au_warn_loopback_nelem = new_nelem;
21568 + au_warn_loopback_array = a;
21573 + spin_unlock(&spin);
21574 + AuWarn1("realloc failed, ignored\n");
21578 + spin_unlock(&spin);
21579 + pr_warn("you may want to try another patch for loopback file "
21580 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21583 +int au_loopback_init(void)
21586 + struct super_block *sb __maybe_unused;
21588 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
21591 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21592 + sizeof(unsigned long), GFP_NOFS);
21593 + if (unlikely(!au_warn_loopback_array))
21599 +void au_loopback_fin(void)
21601 + if (backing_file_func)
21602 + symbol_put(loop_backing_file);
21603 + kfree(au_warn_loopback_array);
21605 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21606 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21607 +++ linux/fs/aufs/loop.h 2016-02-28 11:26:32.573304539 +0100
21610 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21612 + * This program, aufs is free software; you can redistribute it and/or modify
21613 + * it under the terms of the GNU General Public License as published by
21614 + * the Free Software Foundation; either version 2 of the License, or
21615 + * (at your option) any later version.
21617 + * This program is distributed in the hope that it will be useful,
21618 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21619 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21620 + * GNU General Public License for more details.
21622 + * You should have received a copy of the GNU General Public License
21623 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21627 + * support for loopback mount as a branch
21630 +#ifndef __AUFS_LOOP_H__
21631 +#define __AUFS_LOOP_H__
21636 +struct super_block;
21638 +#ifdef CONFIG_AUFS_BDEV_LOOP
21639 +/* drivers/block/loop.c */
21640 +struct file *loop_backing_file(struct super_block *sb);
21643 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21644 +int au_test_loopback_kthread(void);
21645 +void au_warn_loopback(struct super_block *h_sb);
21647 +int au_loopback_init(void);
21648 +void au_loopback_fin(void);
21650 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21651 + struct dentry *h_adding)
21652 +AuStubInt0(au_test_loopback_kthread, void)
21653 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21655 +AuStubInt0(au_loopback_init, void)
21656 +AuStubVoid(au_loopback_fin, void)
21657 +#endif /* BLK_DEV_LOOP */
21659 +#endif /* __KERNEL__ */
21660 +#endif /* __AUFS_LOOP_H__ */
21661 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21662 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21663 +++ linux/fs/aufs/magic.mk 2016-02-28 11:26:32.573304539 +0100
21666 +# defined in ${srctree}/fs/fuse/inode.c
21668 +ifdef CONFIG_FUSE_FS
21669 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21672 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21674 +ifdef CONFIG_XFS_FS
21675 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21678 +# defined in ${srctree}/fs/configfs/mount.c
21680 +ifdef CONFIG_CONFIGFS_FS
21681 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21684 +# defined in ${srctree}/fs/ubifs/ubifs.h
21686 +ifdef CONFIG_UBIFS_FS
21687 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21690 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21692 +ifdef CONFIG_HFSPLUS_FS
21693 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21695 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
21696 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
21697 +++ linux/fs/aufs/Makefile 2016-02-28 11:26:32.569971135 +0100
21700 +include ${src}/magic.mk
21701 +ifeq (${CONFIG_AUFS_FS},m)
21702 +include ${src}/conf.mk
21704 +-include ${src}/priv_def.mk
21706 +# cf. include/linux/kernel.h
21708 +ccflags-y += -DDEBUG
21709 +# sparse requires the full pathname
21711 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
21713 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
21716 +obj-$(CONFIG_AUFS_FS) += aufs.o
21717 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
21718 + wkq.o vfsub.o dcsub.o \
21719 + cpup.o whout.o wbr_policy.o \
21720 + dinfo.o dentry.o \
21722 + finfo.o file.o f_op.o \
21724 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
21728 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
21729 +aufs-$(CONFIG_SYSFS) += sysfs.o
21730 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
21731 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
21732 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
21733 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
21734 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
21735 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
21736 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
21737 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
21738 +aufs-$(CONFIG_AUFS_POLL) += poll.o
21739 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
21740 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
21741 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
21742 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
21743 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
21744 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21745 +++ linux/fs/aufs/module.c 2016-02-28 11:26:32.573304539 +0100
21748 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21750 + * This program, aufs is free software; you can redistribute it and/or modify
21751 + * it under the terms of the GNU General Public License as published by
21752 + * the Free Software Foundation; either version 2 of the License, or
21753 + * (at your option) any later version.
21755 + * This program is distributed in the hope that it will be useful,
21756 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21757 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21758 + * GNU General Public License for more details.
21760 + * You should have received a copy of the GNU General Public License
21761 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21765 + * module global variables and operations
21768 +#include <linux/module.h>
21769 +#include <linux/seq_file.h>
21772 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21774 + if (new_sz <= nused)
21777 + p = krealloc(p, new_sz, gfp);
21779 + memset(p + nused, 0, new_sz - nused);
21783 +/* ---------------------------------------------------------------------- */
21788 +struct kmem_cache *au_cachep[AuCache_Last];
21789 +static int __init au_cache_init(void)
21791 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21792 + if (au_cachep[AuCache_DINFO])
21793 + /* SLAB_DESTROY_BY_RCU */
21794 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21795 + au_icntnr_init_once);
21796 + if (au_cachep[AuCache_ICNTNR])
21797 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21798 + au_fi_init_once);
21799 + if (au_cachep[AuCache_FINFO])
21800 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21801 + if (au_cachep[AuCache_VDIR])
21802 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21803 + if (au_cachep[AuCache_DEHSTR])
21809 +static void au_cache_fin(void)
21814 + * Make sure all delayed rcu free inodes are flushed before we
21819 + /* excluding AuCache_HNOTIFY */
21820 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21821 + for (i = 0; i < AuCache_HNOTIFY; i++) {
21822 + kmem_cache_destroy(au_cachep[i]);
21823 + au_cachep[i] = NULL;
21827 +/* ---------------------------------------------------------------------- */
21829 +int au_dir_roflags;
21831 +#ifdef CONFIG_AUFS_SBILIST
21833 + * iterate_supers_type() doesn't protect us from
21834 + * remounting (branch management)
21836 +struct au_splhead au_sbilist;
21839 +struct lock_class_key au_lc_key[AuLcKey_Last];
21842 + * functions for module interface.
21844 +MODULE_LICENSE("GPL");
21845 +/* MODULE_LICENSE("GPL v2"); */
21846 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21847 +MODULE_DESCRIPTION(AUFS_NAME
21848 + " -- Advanced multi layered unification filesystem");
21849 +MODULE_VERSION(AUFS_VERSION);
21850 +MODULE_ALIAS_FS(AUFS_NAME);
21852 +/* this module parameter has no meaning when SYSFS is disabled */
21853 +int sysaufs_brs = 1;
21854 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21855 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21857 +/* this module parameter has no meaning when USER_NS is disabled */
21859 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21860 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21862 +/* ---------------------------------------------------------------------- */
21864 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21866 +int au_seq_path(struct seq_file *seq, struct path *path)
21870 + err = seq_path(seq, path, au_esc_chars);
21873 + else if (err < 0)
21879 +/* ---------------------------------------------------------------------- */
21881 +static int __init aufs_init(void)
21886 + p = au_esc_chars;
21887 + for (i = 1; i <= ' '; i++)
21893 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21895 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
21896 + for (i = 0; i < AuIop_Last; i++)
21897 + aufs_iop_nogetattr[i].getattr = NULL;
21899 + au_sbilist_init();
21900 + sysaufs_brs_init();
21903 + err = sysaufs_init();
21904 + if (unlikely(err))
21906 + err = au_procfs_init();
21907 + if (unlikely(err))
21908 + goto out_sysaufs;
21909 + err = au_wkq_init();
21910 + if (unlikely(err))
21912 + err = au_loopback_init();
21913 + if (unlikely(err))
21915 + err = au_hnotify_init();
21916 + if (unlikely(err))
21917 + goto out_loopback;
21918 + err = au_sysrq_init();
21919 + if (unlikely(err))
21921 + err = au_cache_init();
21922 + if (unlikely(err))
21925 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
21926 + err = register_filesystem(&aufs_fs_type);
21927 + if (unlikely(err))
21930 + /* since we define pr_fmt, call printk directly */
21931 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
21932 + goto out; /* success */
21939 + au_hnotify_fin();
21941 + au_loopback_fin();
21953 +static void __exit aufs_exit(void)
21955 + unregister_filesystem(&aufs_fs_type);
21958 + au_hnotify_fin();
21959 + au_loopback_fin();
21966 +module_init(aufs_init);
21967 +module_exit(aufs_exit);
21968 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
21969 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
21970 +++ linux/fs/aufs/module.h 2016-02-28 11:26:32.573304539 +0100
21973 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21975 + * This program, aufs is free software; you can redistribute it and/or modify
21976 + * it under the terms of the GNU General Public License as published by
21977 + * the Free Software Foundation; either version 2 of the License, or
21978 + * (at your option) any later version.
21980 + * This program is distributed in the hope that it will be useful,
21981 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21982 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21983 + * GNU General Public License for more details.
21985 + * You should have received a copy of the GNU General Public License
21986 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21990 + * module initialization and module-global
21993 +#ifndef __AUFS_MODULE_H__
21994 +#define __AUFS_MODULE_H__
21998 +#include <linux/slab.h>
22003 +/* module parameters */
22004 +extern int sysaufs_brs;
22005 +extern bool au_userns;
22007 +/* ---------------------------------------------------------------------- */
22009 +extern int au_dir_roflags;
22012 + AuLcNonDir_FIINFO,
22013 + AuLcNonDir_DIINFO,
22014 + AuLcNonDir_IIINFO,
22020 + AuLcSymlink_DIINFO,
22021 + AuLcSymlink_IIINFO,
22025 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
22027 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
22028 +int au_seq_path(struct seq_file *seq, struct path *path);
22030 +#ifdef CONFIG_PROC_FS
22032 +int __init au_procfs_init(void);
22033 +void au_procfs_fin(void);
22035 +AuStubInt0(au_procfs_init, void);
22036 +AuStubVoid(au_procfs_fin, void);
22039 +/* ---------------------------------------------------------------------- */
22048 + AuCache_HNOTIFY, /* must be last */
22052 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
22053 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
22054 +#define AuCacheCtor(type, ctor) \
22055 + kmem_cache_create(#type, sizeof(struct type), \
22056 + __alignof__(struct type), AuCacheFlags, ctor)
22058 +extern struct kmem_cache *au_cachep[];
22060 +#define AuCacheFuncs(name, index) \
22061 +static inline struct au_##name *au_cache_alloc_##name(void) \
22062 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
22063 +static inline void au_cache_free_##name(struct au_##name *p) \
22064 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
22066 +AuCacheFuncs(dinfo, DINFO);
22067 +AuCacheFuncs(icntnr, ICNTNR);
22068 +AuCacheFuncs(finfo, FINFO);
22069 +AuCacheFuncs(vdir, VDIR);
22070 +AuCacheFuncs(vdir_dehstr, DEHSTR);
22071 +#ifdef CONFIG_AUFS_HNOTIFY
22072 +AuCacheFuncs(hnotify, HNOTIFY);
22075 +#endif /* __KERNEL__ */
22076 +#endif /* __AUFS_MODULE_H__ */
22077 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
22078 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
22079 +++ linux/fs/aufs/mvdown.c 2016-02-28 11:26:32.573304539 +0100
22082 + * Copyright (C) 2011-2016 Junjiro R. Okajima
22084 + * This program, aufs is free software; you can redistribute it and/or modify
22085 + * it under the terms of the GNU General Public License as published by
22086 + * the Free Software Foundation; either version 2 of the License, or
22087 + * (at your option) any later version.
22089 + * This program is distributed in the hope that it will be useful,
22090 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22091 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22092 + * GNU General Public License for more details.
22094 + * You should have received a copy of the GNU General Public License
22095 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22099 + * move-down, opposite of copy-up
22104 +struct au_mvd_args {
22106 + struct super_block *h_sb;
22107 + struct dentry *h_parent;
22108 + struct au_hinode *hdir;
22109 + struct inode *h_dir, *h_inode;
22110 + struct au_pin pin;
22111 + } info[AUFS_MVDOWN_NARRAY];
22113 + struct aufs_mvdown mvdown;
22114 + struct dentry *dentry, *parent;
22115 + struct inode *inode, *dir;
22116 + struct super_block *sb;
22117 + aufs_bindex_t bopq, bwh, bfound;
22118 + unsigned char rename_lock;
22121 +#define mvd_errno mvdown.au_errno
22122 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
22123 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
22124 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
22125 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
22127 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
22128 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
22129 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
22130 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
22131 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
22132 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
22134 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
22135 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
22136 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
22137 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
22138 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
22139 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
22141 +#define AU_MVD_PR(flag, ...) do { \
22143 + pr_err(__VA_ARGS__); \
22146 +static int find_lower_writable(struct au_mvd_args *a)
22148 + struct super_block *sb;
22149 + aufs_bindex_t bindex, bend;
22150 + struct au_branch *br;
22153 + bindex = a->mvd_bsrc;
22154 + bend = au_sbend(sb);
22155 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
22156 + for (bindex++; bindex <= bend; bindex++) {
22157 + br = au_sbr(sb, bindex);
22158 + if (au_br_fhsm(br->br_perm)
22159 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
22162 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
22163 + for (bindex++; bindex <= bend; bindex++) {
22164 + br = au_sbr(sb, bindex);
22165 + if (!au_br_rdonly(br))
22169 + for (bindex++; bindex <= bend; bindex++) {
22170 + br = au_sbr(sb, bindex);
22171 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
22172 + if (au_br_rdonly(br))
22174 + |= AUFS_MVDOWN_ROLOWER_R;
22182 +/* make the parent dir on bdst */
22183 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22188 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22189 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22190 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22191 + a->mvd_h_dst_parent = NULL;
22192 + if (au_dbend(a->parent) >= a->mvd_bdst)
22193 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22194 + if (!a->mvd_h_dst_parent) {
22195 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22196 + if (unlikely(err)) {
22197 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22200 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22208 +/* lock them all */
22209 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22212 + struct dentry *h_trap;
22214 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22215 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22216 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22217 + au_opt_udba(a->sb),
22218 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22220 + if (unlikely(err)) {
22221 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22225 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22226 + a->rename_lock = 0;
22227 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22228 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22229 + au_opt_udba(a->sb),
22230 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22231 + err = au_do_pin(&a->mvd_pin_src);
22233 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22234 + if (unlikely(err)) {
22235 + AU_MVD_PR(dmsg, "pin_src failed\n");
22238 + goto out; /* success */
22241 + a->rename_lock = 1;
22242 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22243 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22244 + au_opt_udba(a->sb),
22245 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22247 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22248 + if (unlikely(err)) {
22249 + AU_MVD_PR(dmsg, "pin_src failed\n");
22250 + au_pin_hdir_lock(&a->mvd_pin_dst);
22253 + au_pin_hdir_unlock(&a->mvd_pin_src);
22254 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22255 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22257 + err = (h_trap != a->mvd_h_src_parent);
22259 + err = (h_trap != a->mvd_h_dst_parent);
22261 + BUG_ON(err); /* it should never happen */
22262 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22265 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22266 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22267 + au_pin_hdir_lock(&a->mvd_pin_src);
22268 + au_unpin(&a->mvd_pin_src);
22269 + au_pin_hdir_lock(&a->mvd_pin_dst);
22272 + goto out; /* success */
22275 + au_unpin(&a->mvd_pin_dst);
22281 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22283 + if (!a->rename_lock)
22284 + au_unpin(&a->mvd_pin_src);
22286 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22287 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22288 + au_pin_hdir_lock(&a->mvd_pin_src);
22289 + au_unpin(&a->mvd_pin_src);
22290 + au_pin_hdir_lock(&a->mvd_pin_dst);
22292 + au_unpin(&a->mvd_pin_dst);
22295 +/* copy-down the file */
22296 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22299 + struct au_cp_generic cpg = {
22300 + .dentry = a->dentry,
22301 + .bdst = a->mvd_bdst,
22302 + .bsrc = a->mvd_bsrc,
22304 + .pin = &a->mvd_pin_dst,
22305 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22308 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22309 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22310 + au_fset_cpup(cpg.flags, OVERWRITE);
22311 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22312 + au_fset_cpup(cpg.flags, RWDST);
22313 + err = au_sio_cpdown_simple(&cpg);
22314 + if (unlikely(err))
22315 + AU_MVD_PR(dmsg, "cpdown failed\n");
22322 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22325 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22328 + struct path h_path;
22329 + struct au_branch *br;
22330 + struct inode *delegated;
22332 + br = au_sbr(a->sb, a->mvd_bdst);
22333 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22334 + err = PTR_ERR(h_path.dentry);
22335 + if (IS_ERR(h_path.dentry)) {
22336 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22341 + if (d_is_positive(h_path.dentry)) {
22342 + h_path.mnt = au_br_mnt(br);
22343 + delegated = NULL;
22344 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22345 + &delegated, /*force*/0);
22346 + if (unlikely(err == -EWOULDBLOCK)) {
22347 + pr_warn("cannot retry for NFSv4 delegation"
22348 + " for an internal unlink\n");
22351 + if (unlikely(err))
22352 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22354 + dput(h_path.dentry);
22362 + * unlink the topmost h_dentry
22364 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22367 + struct path h_path;
22368 + struct inode *delegated;
22370 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22371 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22372 + delegated = NULL;
22373 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22374 + if (unlikely(err == -EWOULDBLOCK)) {
22375 + pr_warn("cannot retry for NFSv4 delegation"
22376 + " for an internal unlink\n");
22379 + if (unlikely(err))
22380 + AU_MVD_PR(dmsg, "unlink failed\n");
22386 +/* Since mvdown succeeded, we ignore an error of this function */
22387 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22390 + struct au_branch *br;
22392 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22393 + br = au_sbr(a->sb, a->mvd_bsrc);
22394 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22396 + br = au_sbr(a->sb, a->mvd_bdst);
22397 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22398 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22401 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22403 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22407 + * copy-down the file and unlink the bsrc file.
22408 + * - unlink the bdst whout if exist
22409 + * - copy-down the file (with whtmp name and rename)
22410 + * - unlink the bsrc file
22412 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22416 + err = au_do_mkdir(dmsg, a);
22418 + err = au_do_lock(dmsg, a);
22419 + if (unlikely(err))
22423 + * do not revert the activities we made on bdst since they should be
22424 + * harmless in aufs.
22427 + err = au_do_cpdown(dmsg, a);
22429 + err = au_do_unlink_wh(dmsg, a);
22430 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22431 + err = au_do_unlink(dmsg, a);
22432 + if (unlikely(err))
22435 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22436 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22437 + if (find_lower_writable(a) < 0)
22438 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22440 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22441 + au_do_stfs(dmsg, a);
22443 + /* maintain internal array */
22444 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22445 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22446 + au_set_dbstart(a->dentry, a->mvd_bdst);
22447 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22448 + au_set_ibstart(a->inode, a->mvd_bdst);
22450 + /* hide the lower */
22451 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
22452 + au_set_dbend(a->dentry, a->mvd_bsrc);
22453 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
22454 + au_set_ibend(a->inode, a->mvd_bsrc);
22456 + if (au_dbend(a->dentry) < a->mvd_bdst)
22457 + au_set_dbend(a->dentry, a->mvd_bdst);
22458 + if (au_ibend(a->inode) < a->mvd_bdst)
22459 + au_set_ibend(a->inode, a->mvd_bdst);
22462 + au_do_unlock(dmsg, a);
22468 +/* ---------------------------------------------------------------------- */
22470 +/* make sure the file is idle */
22471 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22473 + int err, plinked;
22476 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22477 + if (au_dbstart(a->dentry) == a->mvd_bsrc
22478 + && au_dcount(a->dentry) == 1
22479 + && atomic_read(&a->inode->i_count) == 1
22480 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22481 + && (!plinked || !au_plink_test(a->inode))
22482 + && a->inode->i_nlink == 1)
22487 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22488 + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry),
22489 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22490 + a->mvd_h_src_inode->i_nlink,
22491 + plinked, plinked ? au_plink_test(a->inode) : 0);
22498 +/* make sure the parent dir is fine */
22499 +static int au_mvd_args_parent(const unsigned char dmsg,
22500 + struct au_mvd_args *a)
22503 + aufs_bindex_t bindex;
22506 + if (unlikely(au_alive_dir(a->parent))) {
22508 + AU_MVD_PR(dmsg, "parent dir is dead\n");
22512 + a->bopq = au_dbdiropq(a->parent);
22513 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
22514 + AuDbg("b%d\n", bindex);
22515 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
22516 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
22518 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
22519 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
22520 + a->bopq, a->mvd_bdst);
22528 +static int au_mvd_args_intermediate(const unsigned char dmsg,
22529 + struct au_mvd_args *a)
22532 + struct au_dinfo *dinfo, *tmp;
22534 + /* lookup the next lower positive entry */
22536 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
22537 + if (unlikely(!tmp))
22542 + dinfo = au_di(a->dentry);
22543 + au_di_cp(tmp, dinfo);
22544 + au_di_swap(tmp, dinfo);
22546 + /* returns the number of positive dentries */
22547 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
22549 + a->bwh = au_dbwh(a->dentry);
22550 + else if (err > 0)
22551 + a->bfound = au_dbstart(a->dentry);
22553 + au_di_swap(tmp, dinfo);
22554 + au_rw_write_unlock(&tmp->di_rwsem);
22556 + if (unlikely(err < 0))
22557 + AU_MVD_PR(dmsg, "failed look-up lower\n");
22560 + * here, we have these cases.
22562 + * no positive dentry under bsrc. there are more sub-cases.
22564 + * there no whiteout, we can safely move-down.
22567 + * bsrc < bwh && bwh < bdst
22568 + * there is a whiteout on RO branch. cannot proceed.
22570 + * there is a whiteout on the RW target branch. it should
22573 + * there is a whiteout somewhere unrelated branch.
22574 + * -1 < bfound && bfound <= bsrc
22577 + * found, but it is on RO branch between bsrc and bdst. cannot
22580 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
22583 + * found, after we create the file on bdst, it will be hidden.
22586 + AuDebugOn(a->bfound == -1
22588 + && a->bwh <= a->mvd_bsrc);
22589 + AuDebugOn(-1 < a->bfound
22590 + && a->bfound <= a->mvd_bsrc);
22593 + if (a->bfound == -1
22594 + && a->mvd_bsrc < a->bwh
22596 + && a->bwh < a->mvd_bdst) {
22597 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
22598 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
22599 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
22601 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
22602 + a->mvd_errno = EAU_MVDOWN_UPPER;
22603 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
22604 + a->mvd_bdst, a->bfound);
22608 + err = 0; /* success */
22615 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
22620 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22621 + && a->bfound == a->mvd_bdst)
22627 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
22630 + struct au_branch *br;
22633 + if (unlikely(S_ISDIR(a->inode->i_mode)))
22637 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
22638 + a->mvd_bsrc = au_ibstart(a->inode);
22640 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
22641 + if (unlikely(a->mvd_bsrc < 0
22642 + || (a->mvd_bsrc < au_dbstart(a->dentry)
22643 + || au_dbend(a->dentry) < a->mvd_bsrc
22644 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
22645 + || (a->mvd_bsrc < au_ibstart(a->inode)
22646 + || au_ibend(a->inode) < a->mvd_bsrc
22647 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
22648 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
22649 + AU_MVD_PR(dmsg, "no upper\n");
22653 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
22654 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22655 + AU_MVD_PR(dmsg, "on the bottom\n");
22658 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
22659 + br = au_sbr(a->sb, a->mvd_bsrc);
22660 + err = au_br_rdonly(br);
22661 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
22662 + if (unlikely(err))
22664 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
22665 + || IS_APPEND(a->mvd_h_src_inode))) {
22667 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
22673 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
22674 + a->mvd_bdst = find_lower_writable(a);
22675 + if (unlikely(a->mvd_bdst < 0)) {
22676 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22677 + AU_MVD_PR(dmsg, "no writable lower branch\n");
22681 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
22682 + if (unlikely(a->mvd_bdst < 0
22683 + || au_sbend(a->sb) < a->mvd_bdst)) {
22684 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
22685 + AU_MVD_PR(dmsg, "no lower brid\n");
22690 + err = au_mvd_args_busy(dmsg, a);
22692 + err = au_mvd_args_parent(dmsg, a);
22694 + err = au_mvd_args_intermediate(dmsg, a);
22696 + err = au_mvd_args_exist(dmsg, a);
22698 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
22705 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
22708 + unsigned char dmsg;
22709 + struct au_mvd_args *args;
22710 + struct inode *inode;
22712 + inode = d_inode(dentry);
22714 + if (unlikely(!capable(CAP_SYS_ADMIN)))
22718 + args = kmalloc(sizeof(*args), GFP_NOFS);
22719 + if (unlikely(!args))
22722 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
22724 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
22725 + if (unlikely(err)) {
22730 + AuDbg("flags 0x%x\n", args->mvdown.flags);
22731 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
22732 + args->mvdown.au_errno = 0;
22733 + args->dentry = dentry;
22734 + args->inode = inode;
22735 + args->sb = dentry->d_sb;
22738 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
22739 + args->parent = dget_parent(dentry);
22740 + args->dir = d_inode(args->parent);
22741 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
22742 + dput(args->parent);
22743 + if (unlikely(args->parent != dentry->d_parent)) {
22744 + AU_MVD_PR(dmsg, "parent dir is moved\n");
22748 + mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD);
22749 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
22750 + if (unlikely(err))
22753 + di_write_lock_parent(args->parent);
22754 + err = au_mvd_args(dmsg, args);
22755 + if (unlikely(err))
22758 + err = au_do_mvdown(dmsg, args);
22759 + if (unlikely(err))
22762 + au_cpup_attr_timesizes(args->dir);
22763 + au_cpup_attr_timesizes(inode);
22764 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
22765 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
22766 + /* au_digen_dec(dentry); */
22769 + di_write_unlock(args->parent);
22770 + aufs_read_unlock(dentry, AuLock_DW);
22772 + mutex_unlock(&inode->i_mutex);
22774 + mutex_unlock(&args->dir->i_mutex);
22776 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
22784 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
22785 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
22786 +++ linux/fs/aufs/opts.c 2016-02-28 11:26:32.573304539 +0100
22789 + * Copyright (C) 2005-2016 Junjiro R. Okajima
22791 + * This program, aufs is free software; you can redistribute it and/or modify
22792 + * it under the terms of the GNU General Public License as published by
22793 + * the Free Software Foundation; either version 2 of the License, or
22794 + * (at your option) any later version.
22796 + * This program is distributed in the hope that it will be useful,
22797 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22798 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22799 + * GNU General Public License for more details.
22801 + * You should have received a copy of the GNU General Public License
22802 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22806 + * mount options/flags
22809 +#include <linux/namei.h>
22810 +#include <linux/types.h> /* a distribution requires */
22811 +#include <linux/parser.h>
22814 +/* ---------------------------------------------------------------------- */
22818 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
22819 + Opt_idel, Opt_imod,
22820 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
22821 + Opt_rdblk_def, Opt_rdhash_def,
22822 + Opt_xino, Opt_noxino,
22823 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22824 + Opt_trunc_xino_path, Opt_itrunc_xino,
22825 + Opt_trunc_xib, Opt_notrunc_xib,
22826 + Opt_shwh, Opt_noshwh,
22827 + Opt_plink, Opt_noplink, Opt_list_plink,
22829 + Opt_dio, Opt_nodio,
22830 + Opt_diropq_a, Opt_diropq_w,
22831 + Opt_warn_perm, Opt_nowarn_perm,
22832 + Opt_wbr_copyup, Opt_wbr_create,
22834 + Opt_verbose, Opt_noverbose,
22835 + Opt_sum, Opt_nosum, Opt_wsum,
22836 + Opt_dirperm1, Opt_nodirperm1,
22837 + Opt_acl, Opt_noacl,
22838 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22841 +static match_table_t options = {
22842 + {Opt_br, "br=%s"},
22843 + {Opt_br, "br:%s"},
22845 + {Opt_add, "add=%d:%s"},
22846 + {Opt_add, "add:%d:%s"},
22847 + {Opt_add, "ins=%d:%s"},
22848 + {Opt_add, "ins:%d:%s"},
22849 + {Opt_append, "append=%s"},
22850 + {Opt_append, "append:%s"},
22851 + {Opt_prepend, "prepend=%s"},
22852 + {Opt_prepend, "prepend:%s"},
22854 + {Opt_del, "del=%s"},
22855 + {Opt_del, "del:%s"},
22856 + /* {Opt_idel, "idel:%d"}, */
22857 + {Opt_mod, "mod=%s"},
22858 + {Opt_mod, "mod:%s"},
22859 + /* {Opt_imod, "imod:%d:%s"}, */
22861 + {Opt_dirwh, "dirwh=%d"},
22863 + {Opt_xino, "xino=%s"},
22864 + {Opt_noxino, "noxino"},
22865 + {Opt_trunc_xino, "trunc_xino"},
22866 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22867 + {Opt_notrunc_xino, "notrunc_xino"},
22868 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22869 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22870 + /* {Opt_zxino, "zxino=%s"}, */
22871 + {Opt_trunc_xib, "trunc_xib"},
22872 + {Opt_notrunc_xib, "notrunc_xib"},
22874 +#ifdef CONFIG_PROC_FS
22875 + {Opt_plink, "plink"},
22877 + {Opt_ignore_silent, "plink"},
22880 + {Opt_noplink, "noplink"},
22882 +#ifdef CONFIG_AUFS_DEBUG
22883 + {Opt_list_plink, "list_plink"},
22886 + {Opt_udba, "udba=%s"},
22888 + {Opt_dio, "dio"},
22889 + {Opt_nodio, "nodio"},
22891 +#ifdef CONFIG_AUFS_FHSM
22892 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22894 + {Opt_ignore_silent, "fhsm_sec=%d"},
22897 + {Opt_diropq_a, "diropq=always"},
22898 + {Opt_diropq_a, "diropq=a"},
22899 + {Opt_diropq_w, "diropq=whiteouted"},
22900 + {Opt_diropq_w, "diropq=w"},
22902 + {Opt_warn_perm, "warn_perm"},
22903 + {Opt_nowarn_perm, "nowarn_perm"},
22905 + /* keep them temporary */
22906 + {Opt_ignore_silent, "nodlgt"},
22907 + {Opt_ignore_silent, "clean_plink"},
22909 +#ifdef CONFIG_AUFS_SHWH
22910 + {Opt_shwh, "shwh"},
22912 + {Opt_noshwh, "noshwh"},
22914 + {Opt_dirperm1, "dirperm1"},
22915 + {Opt_nodirperm1, "nodirperm1"},
22917 + {Opt_verbose, "verbose"},
22918 + {Opt_verbose, "v"},
22919 + {Opt_noverbose, "noverbose"},
22920 + {Opt_noverbose, "quiet"},
22921 + {Opt_noverbose, "q"},
22922 + {Opt_noverbose, "silent"},
22924 + {Opt_sum, "sum"},
22925 + {Opt_nosum, "nosum"},
22926 + {Opt_wsum, "wsum"},
22928 + {Opt_rdcache, "rdcache=%d"},
22929 + {Opt_rdblk, "rdblk=%d"},
22930 + {Opt_rdblk_def, "rdblk=def"},
22931 + {Opt_rdhash, "rdhash=%d"},
22932 + {Opt_rdhash_def, "rdhash=def"},
22934 + {Opt_wbr_create, "create=%s"},
22935 + {Opt_wbr_create, "create_policy=%s"},
22936 + {Opt_wbr_copyup, "cpup=%s"},
22937 + {Opt_wbr_copyup, "copyup=%s"},
22938 + {Opt_wbr_copyup, "copyup_policy=%s"},
22940 + /* generic VFS flag */
22941 +#ifdef CONFIG_FS_POSIX_ACL
22942 + {Opt_acl, "acl"},
22943 + {Opt_noacl, "noacl"},
22945 + {Opt_ignore_silent, "acl"},
22946 + {Opt_ignore_silent, "noacl"},
22949 + /* internal use for the scripts */
22950 + {Opt_ignore_silent, "si=%s"},
22952 + {Opt_br, "dirs=%s"},
22953 + {Opt_ignore, "debug=%d"},
22954 + {Opt_ignore, "delete=whiteout"},
22955 + {Opt_ignore, "delete=all"},
22956 + {Opt_ignore, "imap=%s"},
22958 + /* temporary workaround, due to old mount(8)? */
22959 + {Opt_ignore_silent, "relatime"},
22964 +/* ---------------------------------------------------------------------- */
22966 +static const char *au_parser_pattern(int val, match_table_t tbl)
22968 + struct match_token *p;
22971 + while (p->pattern) {
22972 + if (p->token == val)
22973 + return p->pattern;
22980 +static const char *au_optstr(int *val, match_table_t tbl)
22982 + struct match_token *p;
22989 + while (p->pattern) {
22991 + && (v & p->token) == p->token) {
22992 + *val &= ~p->token;
22993 + return p->pattern;
23002 +/* ---------------------------------------------------------------------- */
23004 +static match_table_t brperm = {
23005 + {AuBrPerm_RO, AUFS_BRPERM_RO},
23006 + {AuBrPerm_RR, AUFS_BRPERM_RR},
23007 + {AuBrPerm_RW, AUFS_BRPERM_RW},
23011 +static match_table_t brattr = {
23013 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
23014 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
23015 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
23016 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
23017 +#ifdef CONFIG_AUFS_FHSM
23018 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
23020 +#ifdef CONFIG_AUFS_XATTR
23021 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
23022 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
23023 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
23024 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
23025 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
23026 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
23029 + /* ro/rr branch */
23030 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
23033 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
23034 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
23039 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
23046 + p = strchr(str, '+');
23049 + v = match_token(str, table, args);
23051 + if (v & AuBrAttr_CMOO_Mask)
23052 + attr &= ~AuBrAttr_CMOO_Mask;
23057 + pr_warn("ignored branch attribute %s\n", str);
23067 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
23075 + p = au_optstr(&perm, brattr);
23078 + memcpy(q, p, sz + 1);
23084 + p = au_optstr(&perm, brattr);
23088 + memcpy(q, p, sz + 1);
23094 + return q - str->a;
23097 +static int noinline_for_stack br_perm_val(char *perm)
23099 + int val, bad, sz;
23101 + substring_t args[MAX_OPT_ARGS];
23102 + au_br_perm_str_t attr;
23104 + p = strchr(perm, '+');
23107 + val = match_token(perm, brperm, args);
23111 + pr_warn("ignored branch permission %s\n", perm);
23112 + val = AuBrPerm_RO;
23118 + val |= br_attr_val(p + 1, brattr, args);
23121 + switch (val & AuBrPerm_Mask) {
23122 + case AuBrPerm_RO:
23123 + case AuBrPerm_RR:
23124 + bad = val & AuBrWAttr_Mask;
23125 + val &= ~AuBrWAttr_Mask;
23127 + case AuBrPerm_RW:
23128 + bad = val & AuBrRAttr_Mask;
23129 + val &= ~AuBrRAttr_Mask;
23134 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
23135 + * does not treat it as an error, just warning.
23136 + * this is a tiny guard for the user operation.
23138 + if (val & AuBrAttr_UNPIN) {
23139 + bad |= AuBrAttr_UNPIN;
23140 + val &= ~AuBrAttr_UNPIN;
23143 + if (unlikely(bad)) {
23144 + sz = au_do_optstr_br_attr(&attr, bad);
23146 + pr_warn("ignored branch attribute %s\n", attr.a);
23153 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
23155 + au_br_perm_str_t attr;
23161 + p = au_optstr(&perm, brperm);
23162 + AuDebugOn(!p || !*p);
23164 + memcpy(q, p, sz + 1);
23167 + sz = au_do_optstr_br_attr(&attr, perm);
23170 + memcpy(q, attr.a, sz + 1);
23173 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
23176 +/* ---------------------------------------------------------------------- */
23178 +static match_table_t udbalevel = {
23179 + {AuOpt_UDBA_REVAL, "reval"},
23180 + {AuOpt_UDBA_NONE, "none"},
23181 +#ifdef CONFIG_AUFS_HNOTIFY
23182 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
23183 +#ifdef CONFIG_AUFS_HFSNOTIFY
23184 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23190 +static int noinline_for_stack udba_val(char *str)
23192 + substring_t args[MAX_OPT_ARGS];
23194 + return match_token(str, udbalevel, args);
23197 +const char *au_optstr_udba(int udba)
23199 + return au_parser_pattern(udba, udbalevel);
23202 +/* ---------------------------------------------------------------------- */
23204 +static match_table_t au_wbr_create_policy = {
23205 + {AuWbrCreate_TDP, "tdp"},
23206 + {AuWbrCreate_TDP, "top-down-parent"},
23207 + {AuWbrCreate_RR, "rr"},
23208 + {AuWbrCreate_RR, "round-robin"},
23209 + {AuWbrCreate_MFS, "mfs"},
23210 + {AuWbrCreate_MFS, "most-free-space"},
23211 + {AuWbrCreate_MFSV, "mfs:%d"},
23212 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23214 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23215 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23216 + {AuWbrCreate_PMFS, "pmfs"},
23217 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23218 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23219 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23225 + * cf. linux/lib/parser.c and cmdline.c
23226 + * gave up calling memparse() since it uses simple_strtoull() instead of
23229 +static int noinline_for_stack
23230 +au_match_ull(substring_t *s, unsigned long long *result)
23233 + unsigned int len;
23237 + len = s->to - s->from;
23238 + if (len + 1 <= sizeof(a)) {
23239 + memcpy(a, s->from, len);
23241 + err = kstrtoull(a, 0, result);
23246 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23247 + struct au_opt_wbr_create *create)
23250 + unsigned long long ull;
23253 + if (!au_match_ull(arg, &ull))
23254 + create->mfsrr_watermark = ull;
23256 + pr_err("bad integer in %s\n", str);
23263 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23264 + struct au_opt_wbr_create *create)
23269 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23270 + create->mfs_second = n;
23272 + pr_err("bad integer in %s\n", str);
23279 +static int noinline_for_stack
23280 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23283 + substring_t args[MAX_OPT_ARGS];
23285 + err = match_token(str, au_wbr_create_policy, args);
23286 + create->wbr_create = err;
23288 + case AuWbrCreate_MFSRRV:
23289 + case AuWbrCreate_PMFSRRV:
23290 + e = au_wbr_mfs_wmark(&args[0], str, create);
23292 + e = au_wbr_mfs_sec(&args[1], str, create);
23296 + case AuWbrCreate_MFSRR:
23297 + case AuWbrCreate_PMFSRR:
23298 + e = au_wbr_mfs_wmark(&args[0], str, create);
23299 + if (unlikely(e)) {
23304 + case AuWbrCreate_MFS:
23305 + case AuWbrCreate_PMFS:
23306 + create->mfs_second = AUFS_MFS_DEF_SEC;
23308 + case AuWbrCreate_MFSV:
23309 + case AuWbrCreate_PMFSV:
23310 + e = au_wbr_mfs_sec(&args[0], str, create);
23319 +const char *au_optstr_wbr_create(int wbr_create)
23321 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23324 +static match_table_t au_wbr_copyup_policy = {
23325 + {AuWbrCopyup_TDP, "tdp"},
23326 + {AuWbrCopyup_TDP, "top-down-parent"},
23327 + {AuWbrCopyup_BUP, "bup"},
23328 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23329 + {AuWbrCopyup_BU, "bu"},
23330 + {AuWbrCopyup_BU, "bottom-up"},
23334 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23336 + substring_t args[MAX_OPT_ARGS];
23338 + return match_token(str, au_wbr_copyup_policy, args);
23341 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23343 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23346 +/* ---------------------------------------------------------------------- */
23348 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23350 +static void dump_opts(struct au_opts *opts)
23352 +#ifdef CONFIG_AUFS_DEBUG
23353 + /* reduce stack space */
23355 + struct au_opt_add *add;
23356 + struct au_opt_del *del;
23357 + struct au_opt_mod *mod;
23358 + struct au_opt_xino *xino;
23359 + struct au_opt_xino_itrunc *xino_itrunc;
23360 + struct au_opt_wbr_create *create;
23362 + struct au_opt *opt;
23365 + while (opt->type != Opt_tail) {
23366 + switch (opt->type) {
23368 + u.add = &opt->add;
23369 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23370 + u.add->bindex, u.add->pathname, u.add->perm,
23371 + u.add->path.dentry);
23375 + u.del = &opt->del;
23376 + AuDbg("del {%s, %p}\n",
23377 + u.del->pathname, u.del->h_path.dentry);
23381 + u.mod = &opt->mod;
23382 + AuDbg("mod {%s, 0x%x, %p}\n",
23383 + u.mod->path, u.mod->perm, u.mod->h_root);
23386 + u.add = &opt->add;
23387 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23388 + u.add->bindex, u.add->pathname, u.add->perm,
23389 + u.add->path.dentry);
23391 + case Opt_prepend:
23392 + u.add = &opt->add;
23393 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23394 + u.add->bindex, u.add->pathname, u.add->perm,
23395 + u.add->path.dentry);
23398 + AuDbg("dirwh %d\n", opt->dirwh);
23400 + case Opt_rdcache:
23401 + AuDbg("rdcache %d\n", opt->rdcache);
23404 + AuDbg("rdblk %u\n", opt->rdblk);
23406 + case Opt_rdblk_def:
23407 + AuDbg("rdblk_def\n");
23410 + AuDbg("rdhash %u\n", opt->rdhash);
23412 + case Opt_rdhash_def:
23413 + AuDbg("rdhash_def\n");
23416 + u.xino = &opt->xino;
23417 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23419 + case Opt_trunc_xino:
23420 + AuLabel(trunc_xino);
23422 + case Opt_notrunc_xino:
23423 + AuLabel(notrunc_xino);
23425 + case Opt_trunc_xino_path:
23426 + case Opt_itrunc_xino:
23427 + u.xino_itrunc = &opt->xino_itrunc;
23428 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23433 + case Opt_trunc_xib:
23434 + AuLabel(trunc_xib);
23436 + case Opt_notrunc_xib:
23437 + AuLabel(notrunc_xib);
23445 + case Opt_dirperm1:
23446 + AuLabel(dirperm1);
23448 + case Opt_nodirperm1:
23449 + AuLabel(nodirperm1);
23454 + case Opt_noplink:
23455 + AuLabel(noplink);
23457 + case Opt_list_plink:
23458 + AuLabel(list_plink);
23461 + AuDbg("udba %d, %s\n",
23462 + opt->udba, au_optstr_udba(opt->udba));
23470 + case Opt_diropq_a:
23471 + AuLabel(diropq_a);
23473 + case Opt_diropq_w:
23474 + AuLabel(diropq_w);
23476 + case Opt_warn_perm:
23477 + AuLabel(warn_perm);
23479 + case Opt_nowarn_perm:
23480 + AuLabel(nowarn_perm);
23482 + case Opt_verbose:
23483 + AuLabel(verbose);
23485 + case Opt_noverbose:
23486 + AuLabel(noverbose);
23497 + case Opt_wbr_create:
23498 + u.create = &opt->wbr_create;
23499 + AuDbg("create %d, %s\n", u.create->wbr_create,
23500 + au_optstr_wbr_create(u.create->wbr_create));
23501 + switch (u.create->wbr_create) {
23502 + case AuWbrCreate_MFSV:
23503 + case AuWbrCreate_PMFSV:
23504 + AuDbg("%d sec\n", u.create->mfs_second);
23506 + case AuWbrCreate_MFSRR:
23507 + AuDbg("%llu watermark\n",
23508 + u.create->mfsrr_watermark);
23510 + case AuWbrCreate_MFSRRV:
23511 + case AuWbrCreate_PMFSRRV:
23512 + AuDbg("%llu watermark, %d sec\n",
23513 + u.create->mfsrr_watermark,
23514 + u.create->mfs_second);
23518 + case Opt_wbr_copyup:
23519 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
23520 + au_optstr_wbr_copyup(opt->wbr_copyup));
23522 + case Opt_fhsm_sec:
23523 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
23539 +void au_opts_free(struct au_opts *opts)
23541 + struct au_opt *opt;
23544 + while (opt->type != Opt_tail) {
23545 + switch (opt->type) {
23548 + case Opt_prepend:
23549 + path_put(&opt->add.path);
23553 + path_put(&opt->del.h_path);
23557 + dput(opt->mod.h_root);
23560 + fput(opt->xino.file);
23567 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
23568 + aufs_bindex_t bindex)
23571 + struct au_opt_add *add = &opt->add;
23574 + add->bindex = bindex;
23575 + add->perm = AuBrPerm_RO;
23576 + add->pathname = opt_str;
23577 + p = strchr(opt_str, '=');
23581 + add->perm = br_perm_val(p);
23584 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
23587 + add->perm = AuBrPerm_RO;
23588 + if (au_test_fs_rr(add->path.dentry->d_sb))
23589 + add->perm = AuBrPerm_RR;
23590 + else if (!bindex && !(sb_flags & MS_RDONLY))
23591 + add->perm = AuBrPerm_RW;
23593 + opt->type = Opt_add;
23596 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
23603 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
23607 + del->pathname = args[0].from;
23608 + AuDbg("del path %s\n", del->pathname);
23610 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
23611 + if (unlikely(err))
23612 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
23617 +#if 0 /* reserved for future use */
23618 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
23619 + struct au_opt_del *del, substring_t args[])
23622 + struct dentry *root;
23625 + root = sb->s_root;
23626 + aufs_read_lock(root, AuLock_FLUSH);
23627 + if (bindex < 0 || au_sbend(sb) < bindex) {
23628 + pr_err("out of bounds, %d\n", bindex);
23633 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
23634 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
23637 + aufs_read_unlock(root, !AuLock_IR);
23642 +static int noinline_for_stack
23643 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
23646 + struct path path;
23650 + mod->path = args[0].from;
23651 + p = strchr(mod->path, '=');
23652 + if (unlikely(!p)) {
23653 + pr_err("no permssion %s\n", args[0].from);
23658 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
23659 + if (unlikely(err)) {
23660 + pr_err("lookup failed %s (%d)\n", mod->path, err);
23664 + mod->perm = br_perm_val(p);
23665 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
23666 + mod->h_root = dget(path.dentry);
23673 +#if 0 /* reserved for future use */
23674 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
23675 + struct au_opt_mod *mod, substring_t args[])
23678 + struct dentry *root;
23681 + root = sb->s_root;
23682 + aufs_read_lock(root, AuLock_FLUSH);
23683 + if (bindex < 0 || au_sbend(sb) < bindex) {
23684 + pr_err("out of bounds, %d\n", bindex);
23689 + mod->perm = br_perm_val(args[1].from);
23690 + AuDbg("mod path %s, perm 0x%x, %s\n",
23691 + mod->path, mod->perm, args[1].from);
23692 + mod->h_root = dget(au_h_dptr(root, bindex));
23695 + aufs_read_unlock(root, !AuLock_IR);
23700 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
23701 + substring_t args[])
23704 + struct file *file;
23706 + file = au_xino_create(sb, args[0].from, /*silent*/0);
23707 + err = PTR_ERR(file);
23708 + if (IS_ERR(file))
23712 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
23714 + pr_err("%s must be outside\n", args[0].from);
23719 + xino->file = file;
23720 + xino->path = args[0].from;
23726 +static int noinline_for_stack
23727 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
23728 + struct au_opt_xino_itrunc *xino_itrunc,
23729 + substring_t args[])
23732 + aufs_bindex_t bend, bindex;
23733 + struct path path;
23734 + struct dentry *root;
23736 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
23737 + if (unlikely(err)) {
23738 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
23742 + xino_itrunc->bindex = -1;
23743 + root = sb->s_root;
23744 + aufs_read_lock(root, AuLock_FLUSH);
23745 + bend = au_sbend(sb);
23746 + for (bindex = 0; bindex <= bend; bindex++) {
23747 + if (au_h_dptr(root, bindex) == path.dentry) {
23748 + xino_itrunc->bindex = bindex;
23752 + aufs_read_unlock(root, !AuLock_IR);
23755 + if (unlikely(xino_itrunc->bindex < 0)) {
23756 + pr_err("no such branch %s\n", args[0].from);
23764 +/* called without aufs lock */
23765 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
23767 + int err, n, token;
23768 + aufs_bindex_t bindex;
23769 + unsigned char skipped;
23770 + struct dentry *root;
23771 + struct au_opt *opt, *opt_tail;
23773 + /* reduce the stack space */
23775 + struct au_opt_xino_itrunc *xino_itrunc;
23776 + struct au_opt_wbr_create *create;
23779 + substring_t args[MAX_OPT_ARGS];
23783 + a = kmalloc(sizeof(*a), GFP_NOFS);
23784 + if (unlikely(!a))
23787 + root = sb->s_root;
23791 + opt_tail = opt + opts->max_opt - 1;
23792 + opt->type = Opt_tail;
23793 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
23796 + token = match_token(opt_str, options, a->args);
23800 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
23802 + err = opt_add(opt, opt_str, opts->sb_flags,
23804 + if (unlikely(!err && ++opt > opt_tail)) {
23808 + opt->type = Opt_tail;
23813 + if (unlikely(match_int(&a->args[0], &n))) {
23814 + pr_err("bad integer in %s\n", opt_str);
23818 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
23821 + opt->type = token;
23824 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23825 + /*dummy bindex*/1);
23827 + opt->type = token;
23829 + case Opt_prepend:
23830 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23833 + opt->type = token;
23836 + err = au_opts_parse_del(&opt->del, a->args);
23838 + opt->type = token;
23840 +#if 0 /* reserved for future use */
23842 + del->pathname = "(indexed)";
23843 + if (unlikely(match_int(&args[0], &n))) {
23844 + pr_err("bad integer in %s\n", opt_str);
23847 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23849 + opt->type = token;
23853 + err = au_opts_parse_mod(&opt->mod, a->args);
23855 + opt->type = token;
23857 +#ifdef IMOD /* reserved for future use */
23859 + u.mod->path = "(indexed)";
23860 + if (unlikely(match_int(&a->args[0], &n))) {
23861 + pr_err("bad integer in %s\n", opt_str);
23864 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23866 + opt->type = token;
23870 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23872 + opt->type = token;
23875 + case Opt_trunc_xino_path:
23876 + err = au_opts_parse_xino_itrunc_path
23877 + (sb, &opt->xino_itrunc, a->args);
23879 + opt->type = token;
23882 + case Opt_itrunc_xino:
23883 + u.xino_itrunc = &opt->xino_itrunc;
23884 + if (unlikely(match_int(&a->args[0], &n))) {
23885 + pr_err("bad integer in %s\n", opt_str);
23888 + u.xino_itrunc->bindex = n;
23889 + aufs_read_lock(root, AuLock_FLUSH);
23890 + if (n < 0 || au_sbend(sb) < n) {
23891 + pr_err("out of bounds, %d\n", n);
23892 + aufs_read_unlock(root, !AuLock_IR);
23895 + aufs_read_unlock(root, !AuLock_IR);
23897 + opt->type = token;
23901 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23904 + opt->type = token;
23907 + case Opt_rdcache:
23908 + if (unlikely(match_int(&a->args[0], &n))) {
23909 + pr_err("bad integer in %s\n", opt_str);
23912 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23913 + pr_err("rdcache must be smaller than %d\n",
23914 + AUFS_RDCACHE_MAX);
23917 + opt->rdcache = n;
23919 + opt->type = token;
23922 + if (unlikely(match_int(&a->args[0], &n)
23924 + || n > KMALLOC_MAX_SIZE)) {
23925 + pr_err("bad integer in %s\n", opt_str);
23928 + if (unlikely(n && n < NAME_MAX)) {
23929 + pr_err("rdblk must be larger than %d\n",
23935 + opt->type = token;
23938 + if (unlikely(match_int(&a->args[0], &n)
23940 + || n * sizeof(struct hlist_head)
23941 + > KMALLOC_MAX_SIZE)) {
23942 + pr_err("bad integer in %s\n", opt_str);
23947 + opt->type = token;
23950 + case Opt_trunc_xino:
23951 + case Opt_notrunc_xino:
23953 + case Opt_trunc_xib:
23954 + case Opt_notrunc_xib:
23957 + case Opt_dirperm1:
23958 + case Opt_nodirperm1:
23960 + case Opt_noplink:
23961 + case Opt_list_plink:
23964 + case Opt_diropq_a:
23965 + case Opt_diropq_w:
23966 + case Opt_warn_perm:
23967 + case Opt_nowarn_perm:
23968 + case Opt_verbose:
23969 + case Opt_noverbose:
23973 + case Opt_rdblk_def:
23974 + case Opt_rdhash_def:
23978 + opt->type = token;
23982 + opt->udba = udba_val(a->args[0].from);
23983 + if (opt->udba >= 0) {
23985 + opt->type = token;
23987 + pr_err("wrong value, %s\n", opt_str);
23990 + case Opt_wbr_create:
23991 + u.create = &opt->wbr_create;
23992 + u.create->wbr_create
23993 + = au_wbr_create_val(a->args[0].from, u.create);
23994 + if (u.create->wbr_create >= 0) {
23996 + opt->type = token;
23998 + pr_err("wrong value, %s\n", opt_str);
24000 + case Opt_wbr_copyup:
24001 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
24002 + if (opt->wbr_copyup >= 0) {
24004 + opt->type = token;
24006 + pr_err("wrong value, %s\n", opt_str);
24009 + case Opt_fhsm_sec:
24010 + if (unlikely(match_int(&a->args[0], &n)
24012 + pr_err("bad integer in %s\n", opt_str);
24015 + if (sysaufs_brs) {
24016 + opt->fhsm_second = n;
24017 + opt->type = token;
24019 + pr_warn("ignored %s\n", opt_str);
24024 + pr_warn("ignored %s\n", opt_str);
24026 + case Opt_ignore_silent:
24031 + pr_err("unknown option %s\n", opt_str);
24035 + if (!err && !skipped) {
24036 + if (unlikely(++opt > opt_tail)) {
24039 + opt->type = Opt_tail;
24042 + opt->type = Opt_tail;
24048 + if (unlikely(err))
24049 + au_opts_free(opts);
24055 +static int au_opt_wbr_create(struct super_block *sb,
24056 + struct au_opt_wbr_create *create)
24059 + struct au_sbinfo *sbinfo;
24061 + SiMustWriteLock(sb);
24063 + err = 1; /* handled */
24064 + sbinfo = au_sbi(sb);
24065 + if (sbinfo->si_wbr_create_ops->fin) {
24066 + err = sbinfo->si_wbr_create_ops->fin(sb);
24071 + sbinfo->si_wbr_create = create->wbr_create;
24072 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
24073 + switch (create->wbr_create) {
24074 + case AuWbrCreate_MFSRRV:
24075 + case AuWbrCreate_MFSRR:
24076 + case AuWbrCreate_PMFSRR:
24077 + case AuWbrCreate_PMFSRRV:
24078 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
24080 + case AuWbrCreate_MFS:
24081 + case AuWbrCreate_MFSV:
24082 + case AuWbrCreate_PMFS:
24083 + case AuWbrCreate_PMFSV:
24084 + sbinfo->si_wbr_mfs.mfs_expire
24085 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
24089 + if (sbinfo->si_wbr_create_ops->init)
24090 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
24097 + * plus: processed without an error
24098 + * zero: unprocessed
24100 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
24101 + struct au_opts *opts)
24104 + struct au_sbinfo *sbinfo;
24106 + SiMustWriteLock(sb);
24108 + err = 1; /* handled */
24109 + sbinfo = au_sbi(sb);
24110 + switch (opt->type) {
24112 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24113 + sbinfo->si_mntflags |= opt->udba;
24114 + opts->given_udba |= opt->udba;
24118 + au_opt_set(sbinfo->si_mntflags, PLINK);
24120 + case Opt_noplink:
24121 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24122 + au_plink_put(sb, /*verbose*/1);
24123 + au_opt_clr(sbinfo->si_mntflags, PLINK);
24125 + case Opt_list_plink:
24126 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24127 + au_plink_list(sb);
24131 + au_opt_set(sbinfo->si_mntflags, DIO);
24132 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24135 + au_opt_clr(sbinfo->si_mntflags, DIO);
24136 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24139 + case Opt_fhsm_sec:
24140 + au_fhsm_set(sbinfo, opt->fhsm_second);
24143 + case Opt_diropq_a:
24144 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24146 + case Opt_diropq_w:
24147 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24150 + case Opt_warn_perm:
24151 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
24153 + case Opt_nowarn_perm:
24154 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
24157 + case Opt_verbose:
24158 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
24160 + case Opt_noverbose:
24161 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
24165 + au_opt_set(sbinfo->si_mntflags, SUM);
24168 + au_opt_clr(sbinfo->si_mntflags, SUM);
24169 + au_opt_set(sbinfo->si_mntflags, SUM_W);
24171 + au_opt_clr(sbinfo->si_mntflags, SUM);
24172 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
24175 + case Opt_wbr_create:
24176 + err = au_opt_wbr_create(sb, &opt->wbr_create);
24178 + case Opt_wbr_copyup:
24179 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
24180 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
24184 + sbinfo->si_dirwh = opt->dirwh;
24187 + case Opt_rdcache:
24188 + sbinfo->si_rdcache
24189 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24192 + sbinfo->si_rdblk = opt->rdblk;
24194 + case Opt_rdblk_def:
24195 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24198 + sbinfo->si_rdhash = opt->rdhash;
24200 + case Opt_rdhash_def:
24201 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24205 + au_opt_set(sbinfo->si_mntflags, SHWH);
24208 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24211 + case Opt_dirperm1:
24212 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24214 + case Opt_nodirperm1:
24215 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24218 + case Opt_trunc_xino:
24219 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24221 + case Opt_notrunc_xino:
24222 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24225 + case Opt_trunc_xino_path:
24226 + case Opt_itrunc_xino:
24227 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24232 + case Opt_trunc_xib:
24233 + au_fset_opts(opts->flags, TRUNC_XIB);
24235 + case Opt_notrunc_xib:
24236 + au_fclr_opts(opts->flags, TRUNC_XIB);
24240 + sb->s_flags |= MS_POSIXACL;
24243 + sb->s_flags &= ~MS_POSIXACL;
24255 + * returns tri-state.
24256 + * plus: processed without an error
24257 + * zero: unprocessed
24260 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24261 + struct au_opts *opts)
24263 + int err, do_refresh;
24266 + switch (opt->type) {
24268 + opt->add.bindex = au_sbend(sb) + 1;
24269 + if (opt->add.bindex < 0)
24270 + opt->add.bindex = 0;
24272 + case Opt_prepend:
24273 + opt->add.bindex = 0;
24274 + add: /* indented label */
24276 + err = au_br_add(sb, &opt->add,
24277 + au_ftest_opts(opts->flags, REMOUNT));
24280 + au_fset_opts(opts->flags, REFRESH);
24286 + err = au_br_del(sb, &opt->del,
24287 + au_ftest_opts(opts->flags, REMOUNT));
24290 + au_fset_opts(opts->flags, TRUNC_XIB);
24291 + au_fset_opts(opts->flags, REFRESH);
24297 + err = au_br_mod(sb, &opt->mod,
24298 + au_ftest_opts(opts->flags, REMOUNT),
24303 + au_fset_opts(opts->flags, REFRESH);
24311 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24312 + struct au_opt_xino **opt_xino,
24313 + struct au_opts *opts)
24316 + aufs_bindex_t bend, bindex;
24317 + struct dentry *root, *parent, *h_root;
24320 + switch (opt->type) {
24322 + err = au_xino_set(sb, &opt->xino,
24323 + !!au_ftest_opts(opts->flags, REMOUNT));
24324 + if (unlikely(err))
24327 + *opt_xino = &opt->xino;
24328 + au_xino_brid_set(sb, -1);
24330 + /* safe d_parent access */
24331 + parent = opt->xino.file->f_path.dentry->d_parent;
24332 + root = sb->s_root;
24333 + bend = au_sbend(sb);
24334 + for (bindex = 0; bindex <= bend; bindex++) {
24335 + h_root = au_h_dptr(root, bindex);
24336 + if (h_root == parent) {
24337 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24345 + au_xino_brid_set(sb, -1);
24346 + *opt_xino = (void *)-1;
24353 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24354 + unsigned int pending)
24357 + aufs_bindex_t bindex, bend;
24358 + unsigned char do_plink, skip, do_free, can_no_dreval;
24359 + struct au_branch *br;
24360 + struct au_wbr *wbr;
24361 + struct dentry *root, *dentry;
24362 + struct inode *dir, *h_dir;
24363 + struct au_sbinfo *sbinfo;
24364 + struct au_hinode *hdir;
24366 + SiMustAnyLock(sb);
24368 + sbinfo = au_sbi(sb);
24369 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24371 + if (!(sb_flags & MS_RDONLY)) {
24372 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24373 + pr_warn("first branch should be rw\n");
24374 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24375 + pr_warn("shwh should be used with ro\n");
24378 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24379 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24380 + pr_warn("udba=*notify requires xino\n");
24382 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24383 + pr_warn("dirperm1 breaks the protection"
24384 + " by the permission bits on the lower branch\n");
24388 + root = sb->s_root;
24389 + dir = d_inode(root);
24390 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24391 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
24393 + bend = au_sbend(sb);
24394 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24396 + h_dir = au_h_iptr(dir, bindex);
24397 + br = au_sbr(sb, bindex);
24399 + if ((br->br_perm & AuBrAttr_ICEX)
24400 + && !h_dir->i_op->listxattr)
24401 + br->br_perm &= ~AuBrAttr_ICEX;
24403 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24404 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24405 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24409 + wbr = br->br_wbr;
24411 + wbr_wh_read_lock(wbr);
24413 + if (!au_br_writable(br->br_perm)) {
24416 + || (!wbr->wbr_whbase
24417 + && !wbr->wbr_plink
24418 + && !wbr->wbr_orph));
24419 + } else if (!au_br_wh_linkable(br->br_perm)) {
24420 + /* skip = (!br->br_whbase && !br->br_orph); */
24421 + skip = (!wbr || !wbr->wbr_whbase);
24422 + if (skip && wbr) {
24424 + skip = !!wbr->wbr_plink;
24426 + skip = !wbr->wbr_plink;
24429 + /* skip = (br->br_whbase && br->br_ohph); */
24430 + skip = (wbr && wbr->wbr_whbase);
24433 + skip = !!wbr->wbr_plink;
24435 + skip = !wbr->wbr_plink;
24439 + wbr_wh_read_unlock(wbr);
24441 + if (can_no_dreval) {
24442 + dentry = br->br_path.dentry;
24443 + spin_lock(&dentry->d_lock);
24444 + if (dentry->d_flags &
24445 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
24446 + can_no_dreval = 0;
24447 + spin_unlock(&dentry->d_lock);
24450 + if (au_br_fhsm(br->br_perm)) {
24452 + AuDebugOn(!br->br_fhsm);
24458 + hdir = au_hi(dir, bindex);
24459 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
24461 + wbr_wh_write_lock(wbr);
24462 + err = au_wh_init(br, sb);
24464 + wbr_wh_write_unlock(wbr);
24465 + au_hn_imtx_unlock(hdir);
24467 + if (!err && do_free) {
24469 + br->br_wbr = NULL;
24473 + if (can_no_dreval)
24474 + au_fset_si(sbinfo, NO_DREVAL);
24476 + au_fclr_si(sbinfo, NO_DREVAL);
24479 + au_fset_si(sbinfo, FHSM);
24480 + for (bindex = bend; bindex >= 0; bindex--) {
24481 + br = au_sbr(sb, bindex);
24482 + if (au_br_fhsm(br->br_perm)) {
24483 + au_fhsm_set_bottom(sb, bindex);
24488 + au_fclr_si(sbinfo, FHSM);
24489 + au_fhsm_set_bottom(sb, -1);
24495 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24498 + unsigned int tmp;
24499 + aufs_bindex_t bindex, bend;
24500 + struct au_opt *opt;
24501 + struct au_opt_xino *opt_xino, xino;
24502 + struct au_sbinfo *sbinfo;
24503 + struct au_branch *br;
24504 + struct inode *dir;
24506 + SiMustWriteLock(sb);
24511 + while (err >= 0 && opt->type != Opt_tail)
24512 + err = au_opt_simple(sb, opt++, opts);
24515 + else if (unlikely(err < 0))
24518 + /* disable xino and udba temporary */
24519 + sbinfo = au_sbi(sb);
24520 + tmp = sbinfo->si_mntflags;
24521 + au_opt_clr(sbinfo->si_mntflags, XINO);
24522 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
24525 + while (err >= 0 && opt->type != Opt_tail)
24526 + err = au_opt_br(sb, opt++, opts);
24529 + else if (unlikely(err < 0))
24532 + bend = au_sbend(sb);
24533 + if (unlikely(bend < 0)) {
24535 + pr_err("no branches\n");
24539 + if (au_opt_test(tmp, XINO))
24540 + au_opt_set(sbinfo->si_mntflags, XINO);
24542 + while (!err && opt->type != Opt_tail)
24543 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
24544 + if (unlikely(err))
24547 + err = au_opts_verify(sb, sb->s_flags, tmp);
24548 + if (unlikely(err))
24551 + /* restore xino */
24552 + if (au_opt_test(tmp, XINO) && !opt_xino) {
24553 + xino.file = au_xino_def(sb);
24554 + err = PTR_ERR(xino.file);
24555 + if (IS_ERR(xino.file))
24558 + err = au_xino_set(sb, &xino, /*remount*/0);
24560 + if (unlikely(err))
24564 + /* restore udba */
24565 + tmp &= AuOptMask_UDBA;
24566 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24567 + sbinfo->si_mntflags |= tmp;
24568 + bend = au_sbend(sb);
24569 + for (bindex = 0; bindex <= bend; bindex++) {
24570 + br = au_sbr(sb, bindex);
24571 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
24572 + if (unlikely(err))
24573 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24575 + /* go on even if err */
24577 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
24578 + dir = d_inode(sb->s_root);
24579 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
24586 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
24589 + unsigned char no_dreval;
24590 + struct inode *dir;
24591 + struct au_opt_xino *opt_xino;
24592 + struct au_opt *opt;
24593 + struct au_sbinfo *sbinfo;
24595 + SiMustWriteLock(sb);
24598 + dir = d_inode(sb->s_root);
24599 + sbinfo = au_sbi(sb);
24602 + while (err >= 0 && opt->type != Opt_tail) {
24603 + err = au_opt_simple(sb, opt, opts);
24605 + err = au_opt_br(sb, opt, opts);
24607 + err = au_opt_xino(sb, opt, &opt_xino, opts);
24613 + /* go on even err */
24615 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
24616 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
24617 + if (unlikely(rerr && !err))
24620 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
24621 + au_fset_opts(opts->flags, REFRESH_IDOP);
24623 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
24624 + rerr = au_xib_trunc(sb);
24625 + if (unlikely(rerr && !err))
24629 + /* will be handled by the caller */
24630 + if (!au_ftest_opts(opts->flags, REFRESH)
24631 + && (opts->given_udba
24632 + || au_opt_test(sbinfo->si_mntflags, XINO)
24633 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
24635 + au_fset_opts(opts->flags, REFRESH);
24637 + AuDbg("status 0x%x\n", opts->flags);
24641 +/* ---------------------------------------------------------------------- */
24643 +unsigned int au_opt_udba(struct super_block *sb)
24645 + return au_mntflags(sb) & AuOptMask_UDBA;
24647 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
24648 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
24649 +++ linux/fs/aufs/opts.h 2016-02-28 11:26:32.573304539 +0100
24652 + * Copyright (C) 2005-2016 Junjiro R. Okajima
24654 + * This program, aufs is free software; you can redistribute it and/or modify
24655 + * it under the terms of the GNU General Public License as published by
24656 + * the Free Software Foundation; either version 2 of the License, or
24657 + * (at your option) any later version.
24659 + * This program is distributed in the hope that it will be useful,
24660 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24661 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24662 + * GNU General Public License for more details.
24664 + * You should have received a copy of the GNU General Public License
24665 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24669 + * mount options/flags
24672 +#ifndef __AUFS_OPTS_H__
24673 +#define __AUFS_OPTS_H__
24677 +#include <linux/path.h>
24680 +struct super_block;
24682 +/* ---------------------------------------------------------------------- */
24685 +#define AuOpt_XINO 1 /* external inode number bitmap
24686 + and translation table */
24687 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
24688 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
24689 +#define AuOpt_UDBA_REVAL (1 << 3)
24690 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
24691 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
24692 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
24693 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
24695 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
24696 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
24697 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
24698 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
24699 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
24700 +#define AuOpt_DIO (1 << 14) /* direct io */
24702 +#ifndef CONFIG_AUFS_HNOTIFY
24703 +#undef AuOpt_UDBA_HNOTIFY
24704 +#define AuOpt_UDBA_HNOTIFY 0
24706 +#ifndef CONFIG_AUFS_SHWH
24708 +#define AuOpt_SHWH 0
24711 +#define AuOpt_Def (AuOpt_XINO \
24712 + | AuOpt_UDBA_REVAL \
24714 + /* | AuOpt_DIRPERM1 */ \
24715 + | AuOpt_WARN_PERM)
24716 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
24717 + | AuOpt_UDBA_REVAL \
24718 + | AuOpt_UDBA_HNOTIFY)
24720 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
24721 +#define au_opt_set(flags, name) do { \
24722 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
24723 + ((flags) |= AuOpt_##name); \
24725 +#define au_opt_set_udba(flags, name) do { \
24726 + (flags) &= ~AuOptMask_UDBA; \
24727 + ((flags) |= AuOpt_##name); \
24729 +#define au_opt_clr(flags, name) do { \
24730 + ((flags) &= ~AuOpt_##name); \
24733 +static inline unsigned int au_opts_plink(unsigned int mntflags)
24735 +#ifdef CONFIG_PROC_FS
24738 + return mntflags & ~AuOpt_PLINK;
24742 +/* ---------------------------------------------------------------------- */
24744 +/* policies to select one among multiple writable branches */
24746 + AuWbrCreate_TDP, /* top down parent */
24747 + AuWbrCreate_RR, /* round robin */
24748 + AuWbrCreate_MFS, /* most free space */
24749 + AuWbrCreate_MFSV, /* mfs with seconds */
24750 + AuWbrCreate_MFSRR, /* mfs then rr */
24751 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
24752 + AuWbrCreate_PMFS, /* parent and mfs */
24753 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
24754 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
24755 + AuWbrCreate_PMFSRRV, /* plus seconds */
24757 + AuWbrCreate_Def = AuWbrCreate_TDP
24761 + AuWbrCopyup_TDP, /* top down parent */
24762 + AuWbrCopyup_BUP, /* bottom up parent */
24763 + AuWbrCopyup_BU, /* bottom up */
24765 + AuWbrCopyup_Def = AuWbrCopyup_TDP
24768 +/* ---------------------------------------------------------------------- */
24770 +struct au_opt_add {
24771 + aufs_bindex_t bindex;
24774 + struct path path;
24777 +struct au_opt_del {
24779 + struct path h_path;
24782 +struct au_opt_mod {
24785 + struct dentry *h_root;
24788 +struct au_opt_xino {
24790 + struct file *file;
24793 +struct au_opt_xino_itrunc {
24794 + aufs_bindex_t bindex;
24797 +struct au_opt_wbr_create {
24800 + unsigned long long mfsrr_watermark;
24806 + struct au_opt_xino xino;
24807 + struct au_opt_xino_itrunc xino_itrunc;
24808 + struct au_opt_add add;
24809 + struct au_opt_del del;
24810 + struct au_opt_mod mod;
24813 + unsigned int rdblk;
24814 + unsigned int rdhash;
24816 + struct au_opt_wbr_create wbr_create;
24818 + unsigned int fhsm_second;
24823 +#define AuOpts_REMOUNT 1
24824 +#define AuOpts_REFRESH (1 << 1)
24825 +#define AuOpts_TRUNC_XIB (1 << 2)
24826 +#define AuOpts_REFRESH_DYAOP (1 << 3)
24827 +#define AuOpts_REFRESH_IDOP (1 << 4)
24828 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
24829 +#define au_fset_opts(flags, name) \
24830 + do { (flags) |= AuOpts_##name; } while (0)
24831 +#define au_fclr_opts(flags, name) \
24832 + do { (flags) &= ~AuOpts_##name; } while (0)
24835 + struct au_opt *opt;
24838 + unsigned int given_udba;
24839 + unsigned int flags;
24840 + unsigned long sb_flags;
24843 +/* ---------------------------------------------------------------------- */
24846 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
24847 +const char *au_optstr_udba(int udba);
24848 +const char *au_optstr_wbr_copyup(int wbr_copyup);
24849 +const char *au_optstr_wbr_create(int wbr_create);
24851 +void au_opts_free(struct au_opts *opts);
24852 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
24853 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24854 + unsigned int pending);
24855 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
24856 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
24858 +unsigned int au_opt_udba(struct super_block *sb);
24860 +#endif /* __KERNEL__ */
24861 +#endif /* __AUFS_OPTS_H__ */
24862 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
24863 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
24864 +++ linux/fs/aufs/plink.c 2016-02-28 11:26:32.573304539 +0100
24867 + * Copyright (C) 2005-2016 Junjiro R. Okajima
24869 + * This program, aufs is free software; you can redistribute it and/or modify
24870 + * it under the terms of the GNU General Public License as published by
24871 + * the Free Software Foundation; either version 2 of the License, or
24872 + * (at your option) any later version.
24874 + * This program is distributed in the hope that it will be useful,
24875 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24876 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24877 + * GNU General Public License for more details.
24879 + * You should have received a copy of the GNU General Public License
24880 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24890 + * the pseudo-link maintenance mode.
24891 + * during a user process maintains the pseudo-links,
24892 + * prohibit adding a new plink and branch manipulation.
24896 + * For entry functions which will handle plink, and i_mutex is already held
24898 + * They cannot wait and should return an error at once.
24899 + * Callers has to check the error.
24901 + * For entry functions which will handle plink, but i_mutex is not held
24903 + * They can wait the plink maintenance mode to finish.
24905 + * They behave like F_SETLK and F_SETLKW.
24906 + * If the caller never handle plink, then both flags are unnecessary.
24909 +int au_plink_maint(struct super_block *sb, int flags)
24913 + struct au_sbinfo *sbi;
24915 + SiMustAnyLock(sb);
24918 + if (!au_opt_test(au_mntflags(sb), PLINK))
24921 + sbi = au_sbi(sb);
24922 + pid = sbi->si_plink_maint_pid;
24923 + if (!pid || pid == current->pid)
24926 + /* todo: it highly depends upon /sbin/mount.aufs */
24928 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
24929 + rcu_read_unlock();
24933 + if (au_ftest_lock(flags, NOPLMW)) {
24934 + /* if there is no i_mutex lock in VFS, we don't need to wait */
24935 + /* AuDebugOn(!lockdep_depth(current)); */
24936 + while (sbi->si_plink_maint_pid) {
24937 + si_read_unlock(sb);
24938 + /* gave up wake_up_bit() */
24939 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
24941 + if (au_ftest_lock(flags, FLUSH))
24942 + au_nwt_flush(&sbi->si_nowait);
24943 + si_noflush_read_lock(sb);
24945 + } else if (au_ftest_lock(flags, NOPLM)) {
24946 + AuDbg("ppid %d, pid %d\n", ppid, pid);
24954 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
24956 + spin_lock(&sbinfo->si_plink_maint_lock);
24957 + sbinfo->si_plink_maint_pid = 0;
24958 + spin_unlock(&sbinfo->si_plink_maint_lock);
24959 + wake_up_all(&sbinfo->si_plink_wq);
24962 +int au_plink_maint_enter(struct super_block *sb)
24965 + struct au_sbinfo *sbinfo;
24968 + sbinfo = au_sbi(sb);
24969 + /* make sure i am the only one in this fs */
24970 + si_write_lock(sb, AuLock_FLUSH);
24971 + if (au_opt_test(au_mntflags(sb), PLINK)) {
24972 + spin_lock(&sbinfo->si_plink_maint_lock);
24973 + if (!sbinfo->si_plink_maint_pid)
24974 + sbinfo->si_plink_maint_pid = current->pid;
24977 + spin_unlock(&sbinfo->si_plink_maint_lock);
24979 + si_write_unlock(sb);
24984 +/* ---------------------------------------------------------------------- */
24986 +#ifdef CONFIG_AUFS_DEBUG
24987 +void au_plink_list(struct super_block *sb)
24990 + struct au_sbinfo *sbinfo;
24991 + struct hlist_head *plink_hlist;
24992 + struct pseudo_link *plink;
24994 + SiMustAnyLock(sb);
24996 + sbinfo = au_sbi(sb);
24997 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24998 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25000 + for (i = 0; i < AuPlink_NHASH; i++) {
25001 + plink_hlist = &sbinfo->si_plink[i].head;
25003 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
25004 + AuDbg("%lu\n", plink->inode->i_ino);
25005 + rcu_read_unlock();
25010 +/* is the inode pseudo-linked? */
25011 +int au_plink_test(struct inode *inode)
25014 + struct au_sbinfo *sbinfo;
25015 + struct hlist_head *plink_hlist;
25016 + struct pseudo_link *plink;
25018 + sbinfo = au_sbi(inode->i_sb);
25019 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25020 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
25021 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25024 + i = au_plink_hash(inode->i_ino);
25025 + plink_hlist = &sbinfo->si_plink[i].head;
25027 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
25028 + if (plink->inode == inode) {
25032 + rcu_read_unlock();
25036 +/* ---------------------------------------------------------------------- */
25039 + * generate a name for plink.
25040 + * the file will be stored under AUFS_WH_PLINKDIR.
25042 +/* 20 is max digits length of ulong 64 */
25043 +#define PLINK_NAME_LEN ((20 + 1) * 2)
25045 +static int plink_name(char *name, int len, struct inode *inode,
25046 + aufs_bindex_t bindex)
25049 + struct inode *h_inode;
25051 + h_inode = au_h_iptr(inode, bindex);
25052 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
25056 +struct au_do_plink_lkup_args {
25057 + struct dentry **errp;
25058 + struct qstr *tgtname;
25059 + struct dentry *h_parent;
25060 + struct au_branch *br;
25063 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
25064 + struct dentry *h_parent,
25065 + struct au_branch *br)
25067 + struct dentry *h_dentry;
25068 + struct mutex *h_mtx;
25070 + h_mtx = &d_inode(h_parent)->i_mutex;
25071 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
25072 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
25073 + mutex_unlock(h_mtx);
25077 +static void au_call_do_plink_lkup(void *args)
25079 + struct au_do_plink_lkup_args *a = args;
25080 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
25083 +/* lookup the plink-ed @inode under the branch at @bindex */
25084 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
25086 + struct dentry *h_dentry, *h_parent;
25087 + struct au_branch *br;
25089 + char a[PLINK_NAME_LEN];
25090 + struct qstr tgtname = QSTR_INIT(a, 0);
25092 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25094 + br = au_sbr(inode->i_sb, bindex);
25095 + h_parent = br->br_wbr->wbr_plink;
25096 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25098 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25099 + struct au_do_plink_lkup_args args = {
25100 + .errp = &h_dentry,
25101 + .tgtname = &tgtname,
25102 + .h_parent = h_parent,
25106 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
25107 + if (unlikely(wkq_err))
25108 + h_dentry = ERR_PTR(wkq_err);
25110 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
25115 +/* create a pseudo-link */
25116 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
25117 + struct dentry *h_dentry, struct au_branch *br)
25120 + struct path h_path = {
25121 + .mnt = au_br_mnt(br)
25123 + struct inode *h_dir, *delegated;
25125 + h_dir = d_inode(h_parent);
25126 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
25128 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
25129 + err = PTR_ERR(h_path.dentry);
25130 + if (IS_ERR(h_path.dentry))
25134 + /* wh.plink dir is not monitored */
25135 + /* todo: is it really safe? */
25136 + if (d_is_positive(h_path.dentry)
25137 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
25138 + delegated = NULL;
25139 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
25140 + if (unlikely(err == -EWOULDBLOCK)) {
25141 + pr_warn("cannot retry for NFSv4 delegation"
25142 + " for an internal unlink\n");
25145 + dput(h_path.dentry);
25146 + h_path.dentry = NULL;
25150 + if (!err && d_is_negative(h_path.dentry)) {
25151 + delegated = NULL;
25152 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
25153 + if (unlikely(err == -EWOULDBLOCK)) {
25154 + pr_warn("cannot retry for NFSv4 delegation"
25155 + " for an internal link\n");
25159 + dput(h_path.dentry);
25162 + mutex_unlock(&h_dir->i_mutex);
25166 +struct do_whplink_args {
25168 + struct qstr *tgt;
25169 + struct dentry *h_parent;
25170 + struct dentry *h_dentry;
25171 + struct au_branch *br;
25174 +static void call_do_whplink(void *args)
25176 + struct do_whplink_args *a = args;
25177 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
25180 +static int whplink(struct dentry *h_dentry, struct inode *inode,
25181 + aufs_bindex_t bindex, struct au_branch *br)
25183 + int err, wkq_err;
25184 + struct au_wbr *wbr;
25185 + struct dentry *h_parent;
25186 + char a[PLINK_NAME_LEN];
25187 + struct qstr tgtname = QSTR_INIT(a, 0);
25189 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
25190 + h_parent = wbr->wbr_plink;
25191 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25193 + /* always superio. */
25194 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25195 + struct do_whplink_args args = {
25198 + .h_parent = h_parent,
25199 + .h_dentry = h_dentry,
25202 + wkq_err = au_wkq_wait(call_do_whplink, &args);
25203 + if (unlikely(wkq_err))
25206 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
25211 +/* free a single plink */
25212 +static void do_put_plink(struct pseudo_link *plink, int do_del)
25215 + hlist_del(&plink->hlist);
25216 + iput(plink->inode);
25220 +static void do_put_plink_rcu(struct rcu_head *rcu)
25222 + struct pseudo_link *plink;
25224 + plink = container_of(rcu, struct pseudo_link, rcu);
25225 + iput(plink->inode);
25230 + * create a new pseudo-link for @h_dentry on @bindex.
25231 + * the linked inode is held in aufs @inode.
25233 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25234 + struct dentry *h_dentry)
25236 + struct super_block *sb;
25237 + struct au_sbinfo *sbinfo;
25238 + struct hlist_head *plink_hlist;
25239 + struct pseudo_link *plink, *tmp;
25240 + struct au_sphlhead *sphl;
25241 + int found, err, cnt, i;
25243 + sb = inode->i_sb;
25244 + sbinfo = au_sbi(sb);
25245 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25246 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25248 + found = au_plink_test(inode);
25252 + i = au_plink_hash(inode->i_ino);
25253 + sphl = sbinfo->si_plink + i;
25254 + plink_hlist = &sphl->head;
25255 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
25257 + tmp->inode = au_igrab(inode);
25263 + spin_lock(&sphl->spin);
25264 + hlist_for_each_entry(plink, plink_hlist, hlist) {
25265 + if (plink->inode == inode) {
25271 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
25272 + spin_unlock(&sphl->spin);
25274 + cnt = au_sphl_count(sphl);
25275 +#define msg "unexpectedly unblanced or too many pseudo-links"
25276 + if (cnt > AUFS_PLINK_WARN)
25277 + AuWarn1(msg ", %d\n", cnt);
25279 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25281 + do_put_plink(tmp, 0);
25286 + if (unlikely(err)) {
25287 + pr_warn("err %d, damaged pseudo link.\n", err);
25289 + au_sphl_del_rcu(&tmp->hlist, sphl);
25290 + call_rcu(&tmp->rcu, do_put_plink_rcu);
25295 +/* free all plinks */
25296 +void au_plink_put(struct super_block *sb, int verbose)
25299 + struct au_sbinfo *sbinfo;
25300 + struct hlist_head *plink_hlist;
25301 + struct hlist_node *tmp;
25302 + struct pseudo_link *plink;
25304 + SiMustWriteLock(sb);
25306 + sbinfo = au_sbi(sb);
25307 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25308 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25310 + /* no spin_lock since sbinfo is write-locked */
25312 + for (i = 0; i < AuPlink_NHASH; i++) {
25313 + plink_hlist = &sbinfo->si_plink[i].head;
25314 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25315 + pr_warn("pseudo-link is not flushed");
25318 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
25319 + do_put_plink(plink, 0);
25320 + INIT_HLIST_HEAD(plink_hlist);
25324 +void au_plink_clean(struct super_block *sb, int verbose)
25326 + struct dentry *root;
25328 + root = sb->s_root;
25329 + aufs_write_lock(root);
25330 + if (au_opt_test(au_mntflags(sb), PLINK))
25331 + au_plink_put(sb, verbose);
25332 + aufs_write_unlock(root);
25335 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25338 + aufs_bindex_t bstart, bend, bindex;
25341 + bstart = au_ibstart(inode);
25342 + bend = au_ibend(inode);
25343 + if (bstart >= 0) {
25344 + for (bindex = bstart; bindex <= bend; bindex++) {
25345 + if (!au_h_iptr(inode, bindex)
25346 + || au_ii_br_id(inode, bindex) != br_id)
25348 + au_set_h_iptr(inode, bindex, NULL, 0);
25353 + for (bindex = bstart; bindex <= bend; bindex++)
25354 + if (au_h_iptr(inode, bindex)) {
25364 +/* free the plinks on a branch specified by @br_id */
25365 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25367 + struct au_sbinfo *sbinfo;
25368 + struct hlist_head *plink_hlist;
25369 + struct hlist_node *tmp;
25370 + struct pseudo_link *plink;
25371 + struct inode *inode;
25374 + SiMustWriteLock(sb);
25376 + sbinfo = au_sbi(sb);
25377 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25378 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25380 + /* no spin_lock since sbinfo is write-locked */
25381 + for (i = 0; i < AuPlink_NHASH; i++) {
25382 + plink_hlist = &sbinfo->si_plink[i].head;
25383 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
25384 + inode = au_igrab(plink->inode);
25385 + ii_write_lock_child(inode);
25386 + do_put = au_plink_do_half_refresh(inode, br_id);
25388 + do_put_plink(plink, 1);
25389 + ii_write_unlock(inode);
25394 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25395 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25396 +++ linux/fs/aufs/poll.c 2016-02-28 11:26:32.573304539 +0100
25399 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25401 + * This program, aufs is free software; you can redistribute it and/or modify
25402 + * it under the terms of the GNU General Public License as published by
25403 + * the Free Software Foundation; either version 2 of the License, or
25404 + * (at your option) any later version.
25406 + * This program is distributed in the hope that it will be useful,
25407 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25408 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25409 + * GNU General Public License for more details.
25411 + * You should have received a copy of the GNU General Public License
25412 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25417 + * There is only one filesystem which implements ->poll operation, currently.
25422 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25424 + unsigned int mask;
25426 + struct file *h_file;
25427 + struct super_block *sb;
25429 + /* We should pretend an error happened. */
25430 + mask = POLLERR /* | POLLIN | POLLOUT */;
25431 + sb = file->f_path.dentry->d_sb;
25432 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25434 + h_file = au_read_pre(file, /*keep_fi*/0);
25435 + err = PTR_ERR(h_file);
25436 + if (IS_ERR(h_file))
25439 + /* it is not an error if h_file has no operation */
25440 + mask = DEFAULT_POLLMASK;
25441 + if (h_file->f_op->poll)
25442 + mask = h_file->f_op->poll(h_file, wait);
25443 + fput(h_file); /* instead of au_read_post() */
25446 + si_read_unlock(sb);
25447 + AuTraceErr((int)mask);
25450 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25451 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25452 +++ linux/fs/aufs/posix_acl.c 2016-02-28 11:26:32.573304539 +0100
25455 + * Copyright (C) 2014-2016 Junjiro R. Okajima
25457 + * This program, aufs is free software; you can redistribute it and/or modify
25458 + * it under the terms of the GNU General Public License as published by
25459 + * the Free Software Foundation; either version 2 of the License, or
25460 + * (at your option) any later version.
25462 + * This program is distributed in the hope that it will be useful,
25463 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25464 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25465 + * GNU General Public License for more details.
25467 + * You should have received a copy of the GNU General Public License
25468 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25472 + * posix acl operations
25475 +#include <linux/fs.h>
25478 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25480 + struct posix_acl *acl;
25482 + aufs_bindex_t bindex;
25483 + struct inode *h_inode;
25484 + struct super_block *sb;
25487 + sb = inode->i_sb;
25488 + si_read_lock(sb, AuLock_FLUSH);
25489 + ii_read_lock_child(inode);
25490 + if (!(sb->s_flags & MS_POSIXACL))
25493 + bindex = au_ibstart(inode);
25494 + h_inode = au_h_iptr(inode, bindex);
25495 + if (unlikely(!h_inode
25496 + || ((h_inode->i_mode & S_IFMT)
25497 + != (inode->i_mode & S_IFMT)))) {
25498 + err = au_busy_or_stale();
25499 + acl = ERR_PTR(err);
25503 + /* always topmost only */
25504 + acl = get_acl(h_inode, type);
25507 + ii_read_unlock(inode);
25508 + si_read_unlock(sb);
25510 + AuTraceErrPtr(acl);
25514 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25518 + struct dentry *dentry;
25519 + struct au_srxattr arg = {
25520 + .type = AU_ACL_SET,
25527 + mutex_lock(&inode->i_mutex);
25528 + if (inode->i_ino == AUFS_ROOT_INO)
25529 + dentry = dget(inode->i_sb->s_root);
25531 + dentry = d_find_alias(inode);
25533 + dentry = d_find_any_alias(inode);
25535 + pr_warn("cannot handle this inode, "
25536 + "please report to aufs-users ML\n");
25542 + ssz = au_srxattr(dentry, &arg);
25549 + mutex_unlock(&inode->i_mutex);
25552 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
25553 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
25554 +++ linux/fs/aufs/procfs.c 2016-02-28 11:26:32.573304539 +0100
25557 + * Copyright (C) 2010-2016 Junjiro R. Okajima
25559 + * This program, aufs is free software; you can redistribute it and/or modify
25560 + * it under the terms of the GNU General Public License as published by
25561 + * the Free Software Foundation; either version 2 of the License, or
25562 + * (at your option) any later version.
25564 + * This program is distributed in the hope that it will be useful,
25565 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25566 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25567 + * GNU General Public License for more details.
25569 + * You should have received a copy of the GNU General Public License
25570 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25574 + * procfs interfaces
25577 +#include <linux/proc_fs.h>
25580 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
25582 + struct au_sbinfo *sbinfo;
25584 + sbinfo = file->private_data;
25586 + au_plink_maint_leave(sbinfo);
25587 + kobject_put(&sbinfo->si_kobj);
25593 +static void au_procfs_plm_write_clean(struct file *file)
25595 + struct au_sbinfo *sbinfo;
25597 + sbinfo = file->private_data;
25599 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
25602 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
25605 + struct super_block *sb;
25606 + struct au_sbinfo *sbinfo;
25609 + if (unlikely(file->private_data))
25613 + /* don't use au_sbilist_lock() here */
25614 + spin_lock(&au_sbilist.spin);
25615 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
25616 + if (id == sysaufs_si_id(sbinfo)) {
25617 + kobject_get(&sbinfo->si_kobj);
25618 + sb = sbinfo->si_sb;
25621 + spin_unlock(&au_sbilist.spin);
25624 + if (unlikely(!sb))
25627 + err = au_plink_maint_enter(sb);
25629 + /* keep kobject_get() */
25630 + file->private_data = sbinfo;
25632 + kobject_put(&sbinfo->si_kobj);
25638 + * Accept a valid "si=xxxx" only.
25639 + * Once it is accepted successfully, accept "clean" too.
25641 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
25642 + size_t count, loff_t *ppos)
25645 + unsigned long id;
25646 + /* last newline is allowed */
25647 + char buf[3 + sizeof(unsigned long) * 2 + 1];
25650 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25654 + if (unlikely(count > sizeof(buf)))
25657 + err = copy_from_user(buf, ubuf, count);
25658 + if (unlikely(err)) {
25665 + if (!strcmp("clean", buf)) {
25666 + au_procfs_plm_write_clean(file);
25667 + goto out_success;
25668 + } else if (unlikely(strncmp("si=", buf, 3)))
25671 + err = kstrtoul(buf + 3, 16, &id);
25672 + if (unlikely(err))
25675 + err = au_procfs_plm_write_si(file, id);
25676 + if (unlikely(err))
25680 + err = count; /* success */
25685 +static const struct file_operations au_procfs_plm_fop = {
25686 + .write = au_procfs_plm_write,
25687 + .release = au_procfs_plm_release,
25688 + .owner = THIS_MODULE
25691 +/* ---------------------------------------------------------------------- */
25693 +static struct proc_dir_entry *au_procfs_dir;
25695 +void au_procfs_fin(void)
25697 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
25698 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25701 +int __init au_procfs_init(void)
25704 + struct proc_dir_entry *entry;
25707 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
25708 + if (unlikely(!au_procfs_dir))
25711 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
25712 + au_procfs_dir, &au_procfs_plm_fop);
25713 + if (unlikely(!entry))
25717 + goto out; /* success */
25721 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25725 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
25726 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
25727 +++ linux/fs/aufs/rdu.c 2016-02-28 11:26:32.573304539 +0100
25730 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25732 + * This program, aufs is free software; you can redistribute it and/or modify
25733 + * it under the terms of the GNU General Public License as published by
25734 + * the Free Software Foundation; either version 2 of the License, or
25735 + * (at your option) any later version.
25737 + * This program is distributed in the hope that it will be useful,
25738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25740 + * GNU General Public License for more details.
25742 + * You should have received a copy of the GNU General Public License
25743 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25747 + * readdir in userspace.
25750 +#include <linux/compat.h>
25751 +#include <linux/fs_stack.h>
25752 +#include <linux/security.h>
25755 +/* bits for struct aufs_rdu.flags */
25756 +#define AuRdu_CALLED 1
25757 +#define AuRdu_CONT (1 << 1)
25758 +#define AuRdu_FULL (1 << 2)
25759 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
25760 +#define au_fset_rdu(flags, name) \
25761 + do { (flags) |= AuRdu_##name; } while (0)
25762 +#define au_fclr_rdu(flags, name) \
25763 + do { (flags) &= ~AuRdu_##name; } while (0)
25765 +struct au_rdu_arg {
25766 + struct dir_context ctx;
25767 + struct aufs_rdu *rdu;
25768 + union au_rdu_ent_ul ent;
25769 + unsigned long end;
25771 + struct super_block *sb;
25775 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
25776 + loff_t offset, u64 h_ino, unsigned int d_type)
25779 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
25780 + struct aufs_rdu *rdu = arg->rdu;
25781 + struct au_rdu_ent ent;
25785 + au_fset_rdu(rdu->cookie.flags, CALLED);
25786 + len = au_rdu_len(nlen);
25787 + if (arg->ent.ul + len < arg->end) {
25789 + ent.bindex = rdu->cookie.bindex;
25790 + ent.type = d_type;
25792 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25793 + ent.type = DT_UNKNOWN;
25795 + /* unnecessary to support mmap_sem since this is a dir */
25797 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
25799 + if (copy_to_user(arg->ent.e->name, name, nlen))
25801 + /* the terminating NULL */
25802 + if (__put_user(0, arg->ent.e->name + nlen))
25805 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
25806 + arg->ent.ul += len;
25810 + au_fset_rdu(rdu->cookie.flags, FULL);
25812 + rdu->tail = arg->ent;
25816 + /* AuTraceErr(err); */
25820 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
25824 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
25826 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
25827 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
25829 + if (unlikely(offset != cookie->h_pos))
25835 + au_fclr_rdu(cookie->flags, CALLED);
25837 + err = vfsub_iterate_dir(h_file, &arg->ctx);
25841 + && au_ftest_rdu(cookie->flags, CALLED)
25842 + && !au_ftest_rdu(cookie->flags, FULL));
25843 + cookie->h_pos = h_file->f_pos;
25850 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
25853 + aufs_bindex_t bend;
25854 + struct au_rdu_arg arg = {
25856 + .actor = au_rdu_fill
25859 + struct dentry *dentry;
25860 + struct inode *inode;
25861 + struct file *h_file;
25862 + struct au_rdu_cookie *cookie = &rdu->cookie;
25864 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
25865 + if (unlikely(err)) {
25871 + rdu->tail = rdu->ent;
25874 + arg.ent = rdu->ent;
25875 + arg.end = arg.ent.ul;
25876 + arg.end += rdu->sz;
25879 + if (unlikely(!file->f_op->iterate))
25882 + err = security_file_permission(file, MAY_READ);
25884 + if (unlikely(err))
25887 + dentry = file->f_path.dentry;
25888 + inode = d_inode(dentry);
25890 + mutex_lock(&inode->i_mutex);
25892 + err = mutex_lock_killable(&inode->i_mutex);
25894 + if (unlikely(err))
25898 + arg.sb = inode->i_sb;
25899 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
25900 + if (unlikely(err))
25902 + err = au_alive_dir(dentry);
25903 + if (unlikely(err))
25905 + /* todo: reval? */
25906 + fi_read_lock(file);
25909 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
25910 + && cookie->generation != au_figen(file)))
25915 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
25917 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
25919 + bend = au_fbstart(file);
25920 + if (cookie->bindex < bend)
25921 + cookie->bindex = bend;
25922 + bend = au_fbend_dir(file);
25923 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
25924 + for (; !err && cookie->bindex <= bend;
25925 + cookie->bindex++, cookie->h_pos = 0) {
25926 + h_file = au_hf_dir(file, cookie->bindex);
25930 + au_fclr_rdu(cookie->flags, FULL);
25931 + err = au_rdu_do(h_file, &arg);
25933 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
25936 + AuDbg("rent %llu\n", rdu->rent);
25938 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
25939 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
25940 + au_fset_rdu(cookie->flags, CONT);
25941 + cookie->generation = au_figen(file);
25944 + ii_read_lock_child(inode);
25945 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
25946 + ii_read_unlock(inode);
25949 + fi_read_unlock(file);
25951 + si_read_unlock(arg.sb);
25953 + mutex_unlock(&inode->i_mutex);
25959 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
25963 + unsigned long long nent;
25964 + union au_rdu_ent_ul *u;
25965 + struct au_rdu_ent ent;
25966 + struct super_block *sb;
25969 + nent = rdu->nent;
25971 + sb = file->f_path.dentry->d_sb;
25972 + si_read_lock(sb, AuLock_FLUSH);
25973 + while (nent-- > 0) {
25974 + /* unnecessary to support mmap_sem since this is a dir */
25975 + err = copy_from_user(&ent, u->e, sizeof(ent));
25977 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
25978 + if (unlikely(err)) {
25984 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
25986 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
25988 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
25990 + if (unlikely(err)) {
25995 + err = __put_user(ino, &u->e->ino);
25996 + if (unlikely(err)) {
26001 + u->ul += au_rdu_len(ent.nlen);
26003 + si_read_unlock(sb);
26008 +/* ---------------------------------------------------------------------- */
26010 +static int au_rdu_verify(struct aufs_rdu *rdu)
26012 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
26013 + "%llu, b%d, 0x%x, g%u}\n",
26014 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
26016 + rdu->rent, rdu->shwh, rdu->full,
26017 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
26018 + rdu->cookie.generation);
26020 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
26024 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
26028 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26031 + struct aufs_rdu rdu;
26032 + void __user *p = (void __user *)arg;
26034 + err = copy_from_user(&rdu, p, sizeof(rdu));
26035 + if (unlikely(err)) {
26040 + err = au_rdu_verify(&rdu);
26041 + if (unlikely(err))
26045 + case AUFS_CTL_RDU:
26046 + err = au_rdu(file, &rdu);
26047 + if (unlikely(err))
26050 + e = copy_to_user(p, &rdu, sizeof(rdu));
26051 + if (unlikely(e)) {
26056 + case AUFS_CTL_RDU_INO:
26057 + err = au_rdu_ino(file, &rdu);
26061 + /* err = -ENOTTY; */
26070 +#ifdef CONFIG_COMPAT
26071 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26074 + struct aufs_rdu rdu;
26075 + void __user *p = compat_ptr(arg);
26077 + /* todo: get_user()? */
26078 + err = copy_from_user(&rdu, p, sizeof(rdu));
26079 + if (unlikely(err)) {
26084 + rdu.ent.e = compat_ptr(rdu.ent.ul);
26085 + err = au_rdu_verify(&rdu);
26086 + if (unlikely(err))
26090 + case AUFS_CTL_RDU:
26091 + err = au_rdu(file, &rdu);
26092 + if (unlikely(err))
26095 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
26096 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
26097 + e = copy_to_user(p, &rdu, sizeof(rdu));
26098 + if (unlikely(e)) {
26103 + case AUFS_CTL_RDU_INO:
26104 + err = au_rdu_ino(file, &rdu);
26108 + /* err = -ENOTTY; */
26117 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
26118 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
26119 +++ linux/fs/aufs/rwsem.h 2016-02-28 11:26:32.573304539 +0100
26122 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26124 + * This program, aufs is free software; you can redistribute it and/or modify
26125 + * it under the terms of the GNU General Public License as published by
26126 + * the Free Software Foundation; either version 2 of the License, or
26127 + * (at your option) any later version.
26129 + * This program is distributed in the hope that it will be useful,
26130 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26131 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26132 + * GNU General Public License for more details.
26134 + * You should have received a copy of the GNU General Public License
26135 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26139 + * simple read-write semaphore wrappers
26142 +#ifndef __AUFS_RWSEM_H__
26143 +#define __AUFS_RWSEM_H__
26147 +#include "debug.h"
26150 + struct rw_semaphore rwsem;
26151 +#ifdef CONFIG_AUFS_DEBUG
26152 + /* just for debugging, not almighty counter */
26153 + atomic_t rcnt, wcnt;
26157 +#ifdef CONFIG_AUFS_DEBUG
26158 +#define AuDbgCntInit(rw) do { \
26159 + atomic_set(&(rw)->rcnt, 0); \
26160 + atomic_set(&(rw)->wcnt, 0); \
26161 + smp_mb(); /* atomic set */ \
26164 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
26165 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
26166 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
26167 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
26169 +#define AuDbgCntInit(rw) do {} while (0)
26170 +#define AuDbgRcntInc(rw) do {} while (0)
26171 +#define AuDbgRcntDec(rw) do {} while (0)
26172 +#define AuDbgWcntInc(rw) do {} while (0)
26173 +#define AuDbgWcntDec(rw) do {} while (0)
26174 +#endif /* CONFIG_AUFS_DEBUG */
26176 +/* to debug easier, do not make them inlined functions */
26177 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
26178 +/* rwsem_is_locked() is unusable */
26179 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
26180 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
26181 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
26182 + && atomic_read(&(rw)->wcnt) <= 0)
26183 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
26184 + || atomic_read(&(rw)->wcnt))
26186 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
26188 +static inline void au_rw_init(struct au_rwsem *rw)
26190 + AuDbgCntInit(rw);
26191 + init_rwsem(&rw->rwsem);
26194 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
26197 + down_write(&rw->rwsem);
26198 + AuDbgWcntInc(rw);
26201 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
26202 + unsigned int lsc)
26205 + down_write_nested(&rw->rwsem, lsc);
26206 + AuDbgWcntInc(rw);
26209 +static inline void au_rw_read_lock(struct au_rwsem *rw)
26211 + down_read(&rw->rwsem);
26212 + AuDbgRcntInc(rw);
26215 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26217 + down_read_nested(&rw->rwsem, lsc);
26218 + AuDbgRcntInc(rw);
26221 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26223 + AuRwMustReadLock(rw);
26224 + AuDbgRcntDec(rw);
26225 + up_read(&rw->rwsem);
26228 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26230 + AuRwMustWriteLock(rw);
26231 + AuDbgRcntInc(rw);
26232 + AuDbgWcntDec(rw);
26233 + downgrade_write(&rw->rwsem);
26236 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26238 + down_write(&rw->rwsem);
26239 + AuDbgWcntInc(rw);
26242 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26243 + unsigned int lsc)
26245 + down_write_nested(&rw->rwsem, lsc);
26246 + AuDbgWcntInc(rw);
26249 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26251 + AuRwMustWriteLock(rw);
26252 + AuDbgWcntDec(rw);
26253 + up_write(&rw->rwsem);
26256 +/* why is not _nested version defined */
26257 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26261 + ret = down_read_trylock(&rw->rwsem);
26263 + AuDbgRcntInc(rw);
26267 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26271 + ret = down_write_trylock(&rw->rwsem);
26273 + AuDbgWcntInc(rw);
26277 +#undef AuDbgCntInit
26278 +#undef AuDbgRcntInc
26279 +#undef AuDbgRcntDec
26280 +#undef AuDbgWcntInc
26281 +#undef AuDbgWcntDec
26283 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26284 +static inline void prefix##_read_lock(param) \
26285 +{ au_rw_read_lock(rwsem); } \
26286 +static inline void prefix##_write_lock(param) \
26287 +{ au_rw_write_lock(rwsem); } \
26288 +static inline int prefix##_read_trylock(param) \
26289 +{ return au_rw_read_trylock(rwsem); } \
26290 +static inline int prefix##_write_trylock(param) \
26291 +{ return au_rw_write_trylock(rwsem); }
26292 +/* why is not _nested version defined */
26293 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26294 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26295 +static inline void prefix##_write_trylock_nestd(param, lsc)
26296 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26298 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26299 +static inline void prefix##_read_unlock(param) \
26300 +{ au_rw_read_unlock(rwsem); } \
26301 +static inline void prefix##_write_unlock(param) \
26302 +{ au_rw_write_unlock(rwsem); } \
26303 +static inline void prefix##_downgrade_lock(param) \
26304 +{ au_rw_dgrade_lock(rwsem); }
26306 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26307 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26308 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26310 +#endif /* __KERNEL__ */
26311 +#endif /* __AUFS_RWSEM_H__ */
26312 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26313 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26314 +++ linux/fs/aufs/sbinfo.c 2016-02-28 11:26:32.573304539 +0100
26317 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26319 + * This program, aufs is free software; you can redistribute it and/or modify
26320 + * it under the terms of the GNU General Public License as published by
26321 + * the Free Software Foundation; either version 2 of the License, or
26322 + * (at your option) any later version.
26324 + * This program is distributed in the hope that it will be useful,
26325 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26326 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26327 + * GNU General Public License for more details.
26329 + * You should have received a copy of the GNU General Public License
26330 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26334 + * superblock private data
26340 + * they are necessary regardless sysfs is disabled.
26342 +void au_si_free(struct kobject *kobj)
26345 + struct au_sbinfo *sbinfo;
26346 + char *locked __maybe_unused; /* debug only */
26348 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26349 + for (i = 0; i < AuPlink_NHASH; i++)
26350 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26351 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
26353 + AuDebugOn(!hlist_empty(&sbinfo->si_symlink.head));
26355 + au_rw_write_lock(&sbinfo->si_rwsem);
26356 + au_br_free(sbinfo);
26357 + au_rw_write_unlock(&sbinfo->si_rwsem);
26359 + AuDebugOn(radix_tree_gang_lookup
26360 + (&sbinfo->au_si_pid.tree, (void **)&locked,
26361 + /*first_index*/PID_MAX_DEFAULT - 1,
26362 + /*max_items*/sizeof(locked)/sizeof(*locked)));
26364 + kfree(sbinfo->si_branch);
26365 + kfree(sbinfo->au_si_pid.bitmap);
26366 + mutex_destroy(&sbinfo->si_xib_mtx);
26367 + AuRwDestroy(&sbinfo->si_rwsem);
26372 +int au_si_alloc(struct super_block *sb)
26375 + struct au_sbinfo *sbinfo;
26376 + static struct lock_class_key aufs_si;
26379 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26380 + if (unlikely(!sbinfo))
26383 + BUILD_BUG_ON(sizeof(unsigned long) !=
26384 + sizeof(*sbinfo->au_si_pid.bitmap));
26385 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
26386 + sizeof(*sbinfo->au_si_pid.bitmap),
26388 + if (unlikely(!sbinfo->au_si_pid.bitmap))
26391 + /* will be reallocated separately */
26392 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26393 + if (unlikely(!sbinfo->si_branch))
26396 + err = sysaufs_si_init(sbinfo);
26397 + if (unlikely(err))
26400 + au_nwt_init(&sbinfo->si_nowait);
26401 + au_rw_init_wlock(&sbinfo->si_rwsem);
26402 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
26403 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
26404 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
26406 + atomic_long_set(&sbinfo->si_ninodes, 0);
26407 + atomic_long_set(&sbinfo->si_nfiles, 0);
26409 + sbinfo->si_bend = -1;
26410 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26412 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26413 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26414 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26415 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26417 + au_fhsm_init(sbinfo);
26419 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26421 + au_sphl_init(&sbinfo->si_symlink);
26423 + sbinfo->si_xino_jiffy = jiffies;
26424 + sbinfo->si_xino_expire
26425 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26426 + mutex_init(&sbinfo->si_xib_mtx);
26427 + sbinfo->si_xino_brid = -1;
26428 + /* leave si_xib_last_pindex and si_xib_next_bit */
26430 + au_sphl_init(&sbinfo->si_aopen);
26432 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26433 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26434 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26435 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26437 + for (i = 0; i < AuPlink_NHASH; i++)
26438 + au_sphl_init(sbinfo->si_plink + i);
26439 + init_waitqueue_head(&sbinfo->si_plink_wq);
26440 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26442 + au_sphl_init(&sbinfo->si_files);
26444 + /* with getattr by default */
26445 + sbinfo->si_iop_array = aufs_iop;
26447 + /* leave other members for sysaufs and si_mnt. */
26448 + sbinfo->si_sb = sb;
26449 + sb->s_fs_info = sbinfo;
26451 + return 0; /* success */
26454 + kfree(sbinfo->si_branch);
26456 + kfree(sbinfo->au_si_pid.bitmap);
26463 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
26466 + struct au_branch **brp;
26468 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26471 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
26472 + if (unlikely(!sz))
26473 + sz = sizeof(*brp);
26474 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
26476 + sbinfo->si_branch = brp;
26483 +/* ---------------------------------------------------------------------- */
26485 +unsigned int au_sigen_inc(struct super_block *sb)
26487 + unsigned int gen;
26488 + struct inode *inode;
26490 + SiMustWriteLock(sb);
26492 + gen = ++au_sbi(sb)->si_generation;
26493 + au_update_digen(sb->s_root);
26494 + inode = d_inode(sb->s_root);
26495 + au_update_iigen(inode, /*half*/0);
26496 + inode->i_version++;
26500 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26502 + aufs_bindex_t br_id;
26504 + struct au_sbinfo *sbinfo;
26506 + SiMustWriteLock(sb);
26508 + sbinfo = au_sbi(sb);
26509 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26510 + br_id = ++sbinfo->si_last_br_id;
26511 + AuDebugOn(br_id < 0);
26512 + if (br_id && au_br_index(sb, br_id) < 0)
26519 +/* ---------------------------------------------------------------------- */
26521 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26522 +int si_read_lock(struct super_block *sb, int flags)
26527 + if (au_ftest_lock(flags, FLUSH))
26528 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26530 + si_noflush_read_lock(sb);
26531 + err = au_plink_maint(sb, flags);
26532 + if (unlikely(err))
26533 + si_read_unlock(sb);
26538 +int si_write_lock(struct super_block *sb, int flags)
26542 + if (au_ftest_lock(flags, FLUSH))
26543 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26545 + si_noflush_write_lock(sb);
26546 + err = au_plink_maint(sb, flags);
26547 + if (unlikely(err))
26548 + si_write_unlock(sb);
26553 +/* dentry and super_block lock. call at entry point */
26554 +int aufs_read_lock(struct dentry *dentry, int flags)
26557 + struct super_block *sb;
26559 + sb = dentry->d_sb;
26560 + err = si_read_lock(sb, flags);
26561 + if (unlikely(err))
26564 + if (au_ftest_lock(flags, DW))
26565 + di_write_lock_child(dentry);
26567 + di_read_lock_child(dentry, flags);
26569 + if (au_ftest_lock(flags, GEN)) {
26570 + err = au_digen_test(dentry, au_sigen(sb));
26571 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
26572 + AuDebugOn(!err && au_dbrange_test(dentry));
26574 + err = au_dbrange_test(dentry);
26575 + if (unlikely(err))
26576 + aufs_read_unlock(dentry, flags);
26583 +void aufs_read_unlock(struct dentry *dentry, int flags)
26585 + if (au_ftest_lock(flags, DW))
26586 + di_write_unlock(dentry);
26588 + di_read_unlock(dentry, flags);
26589 + si_read_unlock(dentry->d_sb);
26592 +void aufs_write_lock(struct dentry *dentry)
26594 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
26595 + di_write_lock_child(dentry);
26598 +void aufs_write_unlock(struct dentry *dentry)
26600 + di_write_unlock(dentry);
26601 + si_write_unlock(dentry->d_sb);
26604 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
26607 + unsigned int sigen;
26608 + struct super_block *sb;
26611 + err = si_read_lock(sb, flags);
26612 + if (unlikely(err))
26615 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
26617 + if (au_ftest_lock(flags, GEN)) {
26618 + sigen = au_sigen(sb);
26619 + err = au_digen_test(d1, sigen);
26620 + AuDebugOn(!err && au_dbrange_test(d1));
26622 + err = au_digen_test(d2, sigen);
26623 + AuDebugOn(!err && au_dbrange_test(d2));
26625 + if (unlikely(err))
26626 + aufs_read_and_write_unlock2(d1, d2);
26633 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
26635 + di_write_unlock2(d1, d2);
26636 + si_read_unlock(d1->d_sb);
26639 +/* ---------------------------------------------------------------------- */
26641 +int si_pid_test_slow(struct super_block *sb)
26646 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
26647 + rcu_read_unlock();
26649 + return (long)!!p;
26652 +void si_pid_set_slow(struct super_block *sb)
26655 + struct au_sbinfo *sbinfo;
26657 + AuDebugOn(si_pid_test_slow(sb));
26659 + sbinfo = au_sbi(sb);
26660 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
26662 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26663 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
26664 + /*any valid ptr*/sb);
26665 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26667 + radix_tree_preload_end();
26670 +void si_pid_clr_slow(struct super_block *sb)
26673 + struct au_sbinfo *sbinfo;
26675 + AuDebugOn(!si_pid_test_slow(sb));
26677 + sbinfo = au_sbi(sb);
26678 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26679 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
26680 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26682 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
26683 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
26684 +++ linux/fs/aufs/spl.h 2016-02-28 11:26:32.573304539 +0100
26687 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26689 + * This program, aufs is free software; you can redistribute it and/or modify
26690 + * it under the terms of the GNU General Public License as published by
26691 + * the Free Software Foundation; either version 2 of the License, or
26692 + * (at your option) any later version.
26694 + * This program is distributed in the hope that it will be useful,
26695 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26696 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26697 + * GNU General Public License for more details.
26699 + * You should have received a copy of the GNU General Public License
26700 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26704 + * simple list protected by a spinlock
26707 +#ifndef __AUFS_SPL_H__
26708 +#define __AUFS_SPL_H__
26712 +struct au_splhead {
26714 + struct list_head head;
26717 +static inline void au_spl_init(struct au_splhead *spl)
26719 + spin_lock_init(&spl->spin);
26720 + INIT_LIST_HEAD(&spl->head);
26723 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
26725 + spin_lock(&spl->spin);
26726 + list_add(list, &spl->head);
26727 + spin_unlock(&spl->spin);
26730 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
26732 + spin_lock(&spl->spin);
26734 + spin_unlock(&spl->spin);
26737 +static inline void au_spl_del_rcu(struct list_head *list,
26738 + struct au_splhead *spl)
26740 + spin_lock(&spl->spin);
26741 + list_del_rcu(list);
26742 + spin_unlock(&spl->spin);
26745 +/* ---------------------------------------------------------------------- */
26747 +struct au_sphlhead {
26749 + struct hlist_head head;
26752 +static inline void au_sphl_init(struct au_sphlhead *sphl)
26754 + spin_lock_init(&sphl->spin);
26755 + INIT_HLIST_HEAD(&sphl->head);
26758 +static inline void au_sphl_add(struct hlist_node *hlist,
26759 + struct au_sphlhead *sphl)
26761 + spin_lock(&sphl->spin);
26762 + hlist_add_head(hlist, &sphl->head);
26763 + spin_unlock(&sphl->spin);
26766 +static inline void au_sphl_del(struct hlist_node *hlist,
26767 + struct au_sphlhead *sphl)
26769 + spin_lock(&sphl->spin);
26770 + hlist_del(hlist);
26771 + spin_unlock(&sphl->spin);
26774 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
26775 + struct au_sphlhead *sphl)
26777 + spin_lock(&sphl->spin);
26778 + hlist_del_rcu(hlist);
26779 + spin_unlock(&sphl->spin);
26782 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
26784 + unsigned long cnt;
26785 + struct hlist_node *pos;
26788 + spin_lock(&sphl->spin);
26789 + hlist_for_each(pos, &sphl->head)
26791 + spin_unlock(&sphl->spin);
26795 +#endif /* __KERNEL__ */
26796 +#endif /* __AUFS_SPL_H__ */
26797 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
26798 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
26799 +++ linux/fs/aufs/super.c 2016-02-28 11:26:32.573304539 +0100
26802 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26804 + * This program, aufs is free software; you can redistribute it and/or modify
26805 + * it under the terms of the GNU General Public License as published by
26806 + * the Free Software Foundation; either version 2 of the License, or
26807 + * (at your option) any later version.
26809 + * This program is distributed in the hope that it will be useful,
26810 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26811 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26812 + * GNU General Public License for more details.
26814 + * You should have received a copy of the GNU General Public License
26815 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26819 + * mount and super_block operations
26822 +#include <linux/mm.h>
26823 +#include <linux/seq_file.h>
26824 +#include <linux/statfs.h>
26825 +#include <linux/vmalloc.h>
26829 + * super_operations
26831 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
26833 + struct au_icntnr *c;
26835 + c = au_cache_alloc_icntnr();
26837 + au_icntnr_init(c);
26838 + c->vfs_inode.i_version = 1; /* sigen(sb); */
26839 + c->iinfo.ii_hinode = NULL;
26840 + return &c->vfs_inode;
26845 +static void aufs_destroy_inode_cb(struct rcu_head *head)
26847 + struct inode *inode = container_of(head, struct inode, i_rcu);
26849 + INIT_HLIST_HEAD(&inode->i_dentry);
26850 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
26853 +static void aufs_destroy_inode(struct inode *inode)
26855 + au_iinfo_fin(inode);
26856 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
26859 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
26861 + struct inode *inode;
26864 + inode = iget_locked(sb, ino);
26865 + if (unlikely(!inode)) {
26866 + inode = ERR_PTR(-ENOMEM);
26869 + if (!(inode->i_state & I_NEW))
26872 + err = au_xigen_new(inode);
26874 + err = au_iinfo_init(inode);
26876 + inode->i_version++;
26878 + iget_failed(inode);
26879 + inode = ERR_PTR(err);
26883 + /* never return NULL */
26884 + AuDebugOn(!inode);
26885 + AuTraceErrPtr(inode);
26889 +/* lock free root dinfo */
26890 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
26893 + aufs_bindex_t bindex, bend;
26894 + struct path path;
26895 + struct au_hdentry *hdp;
26896 + struct au_branch *br;
26897 + au_br_perm_str_t perm;
26900 + bend = au_sbend(sb);
26901 + hdp = au_di(sb->s_root)->di_hdentry;
26902 + for (bindex = 0; !err && bindex <= bend; bindex++) {
26903 + br = au_sbr(sb, bindex);
26904 + path.mnt = au_br_mnt(br);
26905 + path.dentry = hdp[bindex].hd_dentry;
26906 + err = au_seq_path(seq, &path);
26908 + au_optstr_br_perm(&perm, br->br_perm);
26909 + seq_printf(seq, "=%s", perm.a);
26910 + if (bindex != bend)
26911 + seq_putc(seq, ':');
26914 + if (unlikely(err || seq_has_overflowed(seq)))
26920 +static void au_show_wbr_create(struct seq_file *m, int v,
26921 + struct au_sbinfo *sbinfo)
26925 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26927 + seq_puts(m, ",create=");
26928 + pat = au_optstr_wbr_create(v);
26930 + case AuWbrCreate_TDP:
26931 + case AuWbrCreate_RR:
26932 + case AuWbrCreate_MFS:
26933 + case AuWbrCreate_PMFS:
26934 + seq_puts(m, pat);
26936 + case AuWbrCreate_MFSV:
26937 + seq_printf(m, /*pat*/"mfs:%lu",
26938 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26941 + case AuWbrCreate_PMFSV:
26942 + seq_printf(m, /*pat*/"pmfs:%lu",
26943 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26946 + case AuWbrCreate_MFSRR:
26947 + seq_printf(m, /*pat*/"mfsrr:%llu",
26948 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26950 + case AuWbrCreate_MFSRRV:
26951 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
26952 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26953 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26956 + case AuWbrCreate_PMFSRR:
26957 + seq_printf(m, /*pat*/"pmfsrr:%llu",
26958 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26960 + case AuWbrCreate_PMFSRRV:
26961 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
26962 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26963 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26969 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
26971 +#ifdef CONFIG_SYSFS
26975 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
26976 + aufs_bindex_t bindex, brid;
26977 + struct qstr *name;
26979 + struct dentry *d, *h_root;
26980 + struct au_hdentry *hdp;
26982 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26985 + f = au_sbi(sb)->si_xib;
26989 + /* stop printing the default xino path on the first writable branch */
26991 + brid = au_xino_brid(sb);
26993 + bindex = au_br_index(sb, brid);
26994 + hdp = au_di(sb->s_root)->di_hdentry;
26995 + h_root = hdp[0 + bindex].hd_dentry;
26997 + d = f->f_path.dentry;
26998 + name = &d->d_name;
26999 + /* safe ->d_parent because the file is unlinked */
27000 + if (d->d_parent == h_root
27001 + && name->len == len
27002 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
27005 + seq_puts(seq, ",xino=");
27006 + err = au_xino_path(seq, f);
27013 +/* seq_file will re-call me in case of too long string */
27014 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
27017 + unsigned int mnt_flags, v;
27018 + struct super_block *sb;
27019 + struct au_sbinfo *sbinfo;
27021 +#define AuBool(name, str) do { \
27022 + v = au_opt_test(mnt_flags, name); \
27023 + if (v != au_opt_test(AuOpt_Def, name)) \
27024 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
27027 +#define AuStr(name, str) do { \
27028 + v = mnt_flags & AuOptMask_##name; \
27029 + if (v != (AuOpt_Def & AuOptMask_##name)) \
27030 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
27033 +#define AuUInt(name, str, val) do { \
27034 + if (val != AUFS_##name##_DEF) \
27035 + seq_printf(m, "," #str "=%u", val); \
27038 + sb = dentry->d_sb;
27039 + if (sb->s_flags & MS_POSIXACL)
27040 + seq_puts(m, ",acl");
27042 + /* lock free root dinfo */
27043 + si_noflush_read_lock(sb);
27044 + sbinfo = au_sbi(sb);
27045 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
27047 + mnt_flags = au_mntflags(sb);
27048 + if (au_opt_test(mnt_flags, XINO)) {
27049 + err = au_show_xino(m, sb);
27050 + if (unlikely(err))
27053 + seq_puts(m, ",noxino");
27055 + AuBool(TRUNC_XINO, trunc_xino);
27056 + AuStr(UDBA, udba);
27057 + AuBool(SHWH, shwh);
27058 + AuBool(PLINK, plink);
27059 + AuBool(DIO, dio);
27060 + AuBool(DIRPERM1, dirperm1);
27062 + v = sbinfo->si_wbr_create;
27063 + if (v != AuWbrCreate_Def)
27064 + au_show_wbr_create(m, v, sbinfo);
27066 + v = sbinfo->si_wbr_copyup;
27067 + if (v != AuWbrCopyup_Def)
27068 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
27070 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
27071 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
27072 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
27074 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
27076 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
27077 + AuUInt(RDCACHE, rdcache, v);
27079 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
27080 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
27082 + au_fhsm_show(m, sbinfo);
27084 + AuBool(SUM, sum);
27085 + /* AuBool(SUM_W, wsum); */
27086 + AuBool(WARN_PERM, warn_perm);
27087 + AuBool(VERBOSE, verbose);
27090 + /* be sure to print "br:" last */
27091 + if (!sysaufs_brs) {
27092 + seq_puts(m, ",br:");
27093 + au_show_brs(m, sb);
27095 + si_read_unlock(sb);
27103 +/* ---------------------------------------------------------------------- */
27105 +/* sum mode which returns the summation for statfs(2) */
27107 +static u64 au_add_till_max(u64 a, u64 b)
27115 + return ULLONG_MAX;
27118 +static u64 au_mul_till_max(u64 a, long mul)
27126 + return ULLONG_MAX;
27129 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
27132 + long bsize, factor;
27133 + u64 blocks, bfree, bavail, files, ffree;
27134 + aufs_bindex_t bend, bindex, i;
27135 + unsigned char shared;
27136 + struct path h_path;
27137 + struct super_block *h_sb;
27140 + bsize = LONG_MAX;
27146 + bend = au_sbend(sb);
27147 + for (bindex = 0; bindex <= bend; bindex++) {
27148 + h_path.mnt = au_sbr_mnt(sb, bindex);
27149 + h_sb = h_path.mnt->mnt_sb;
27151 + for (i = 0; !shared && i < bindex; i++)
27152 + shared = (au_sbr_sb(sb, i) == h_sb);
27156 + /* sb->s_root for NFS is unreliable */
27157 + h_path.dentry = h_path.mnt->mnt_root;
27158 + err = vfs_statfs(&h_path, buf);
27159 + if (unlikely(err))
27162 + if (bsize > buf->f_bsize) {
27164 + * we will reduce bsize, so we have to expand blocks
27165 + * etc. to match them again
27167 + factor = (bsize / buf->f_bsize);
27168 + blocks = au_mul_till_max(blocks, factor);
27169 + bfree = au_mul_till_max(bfree, factor);
27170 + bavail = au_mul_till_max(bavail, factor);
27171 + bsize = buf->f_bsize;
27174 + factor = (buf->f_bsize / bsize);
27175 + blocks = au_add_till_max(blocks,
27176 + au_mul_till_max(buf->f_blocks, factor));
27177 + bfree = au_add_till_max(bfree,
27178 + au_mul_till_max(buf->f_bfree, factor));
27179 + bavail = au_add_till_max(bavail,
27180 + au_mul_till_max(buf->f_bavail, factor));
27181 + files = au_add_till_max(files, buf->f_files);
27182 + ffree = au_add_till_max(ffree, buf->f_ffree);
27185 + buf->f_bsize = bsize;
27186 + buf->f_blocks = blocks;
27187 + buf->f_bfree = bfree;
27188 + buf->f_bavail = bavail;
27189 + buf->f_files = files;
27190 + buf->f_ffree = ffree;
27191 + buf->f_frsize = 0;
27197 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
27200 + struct path h_path;
27201 + struct super_block *sb;
27203 + /* lock free root dinfo */
27204 + sb = dentry->d_sb;
27205 + si_noflush_read_lock(sb);
27206 + if (!au_opt_test(au_mntflags(sb), SUM)) {
27207 + /* sb->s_root for NFS is unreliable */
27208 + h_path.mnt = au_sbr_mnt(sb, 0);
27209 + h_path.dentry = h_path.mnt->mnt_root;
27210 + err = vfs_statfs(&h_path, buf);
27212 + err = au_statfs_sum(sb, buf);
27213 + si_read_unlock(sb);
27216 + buf->f_type = AUFS_SUPER_MAGIC;
27217 + buf->f_namelen = AUFS_MAX_NAMELEN;
27218 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
27220 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27225 +/* ---------------------------------------------------------------------- */
27227 +static int aufs_sync_fs(struct super_block *sb, int wait)
27230 + aufs_bindex_t bend, bindex;
27231 + struct au_branch *br;
27232 + struct super_block *h_sb;
27235 + si_noflush_read_lock(sb);
27236 + bend = au_sbend(sb);
27237 + for (bindex = 0; bindex <= bend; bindex++) {
27238 + br = au_sbr(sb, bindex);
27239 + if (!au_br_writable(br->br_perm))
27242 + h_sb = au_sbr_sb(sb, bindex);
27243 + if (h_sb->s_op->sync_fs) {
27244 + e = h_sb->s_op->sync_fs(h_sb, wait);
27245 + if (unlikely(e && !err))
27247 + /* go on even if an error happens */
27250 + si_read_unlock(sb);
27255 +/* ---------------------------------------------------------------------- */
27257 +/* final actions when unmounting a file system */
27258 +static void aufs_put_super(struct super_block *sb)
27260 + struct au_sbinfo *sbinfo;
27262 + sbinfo = au_sbi(sb);
27266 + dbgaufs_si_fin(sbinfo);
27267 + kobject_put(&sbinfo->si_kobj);
27270 +/* ---------------------------------------------------------------------- */
27272 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
27273 + struct super_block *sb, void *arg)
27276 + unsigned long long n, sz;
27283 + if (*hint > ULLONG_MAX / sizeof(array)) {
27284 + array = ERR_PTR(-EMFILE);
27285 + pr_err("hint %llu\n", *hint);
27289 + sz = sizeof(array) * *hint;
27290 + array = kzalloc(sz, GFP_NOFS);
27291 + if (unlikely(!array))
27292 + array = vzalloc(sz);
27293 + if (unlikely(!array)) {
27294 + array = ERR_PTR(-ENOMEM);
27298 + n = cb(sb, array, *hint, arg);
27299 + AuDebugOn(n > *hint);
27306 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
27307 + unsigned long long max __maybe_unused,
27310 + unsigned long long n;
27311 + struct inode **p, *inode;
27312 + struct list_head *head;
27317 + spin_lock(&sb->s_inode_list_lock);
27318 + list_for_each_entry(inode, head, i_sb_list) {
27319 + if (!is_bad_inode(inode)
27320 + && au_ii(inode)->ii_bstart >= 0) {
27321 + spin_lock(&inode->i_lock);
27322 + if (atomic_read(&inode->i_count)) {
27326 + AuDebugOn(n > max);
27328 + spin_unlock(&inode->i_lock);
27331 + spin_unlock(&sb->s_inode_list_lock);
27336 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27338 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
27339 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
27342 +void au_iarray_free(struct inode **a, unsigned long long max)
27344 + unsigned long long ull;
27346 + for (ull = 0; ull < max; ull++)
27351 +/* ---------------------------------------------------------------------- */
27354 + * refresh dentry and inode at remount time.
27356 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27357 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27358 + struct dentry *parent)
27362 + di_write_lock_child(dentry);
27363 + di_read_lock_parent(parent, AuLock_IR);
27364 + err = au_refresh_dentry(dentry, parent);
27365 + if (!err && dir_flags)
27366 + au_hn_reset(d_inode(dentry), dir_flags);
27367 + di_read_unlock(parent, AuLock_IR);
27368 + di_write_unlock(dentry);
27373 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27374 + struct au_sbinfo *sbinfo,
27375 + const unsigned int dir_flags, unsigned int do_idop)
27378 + struct dentry *parent;
27381 + parent = dget_parent(dentry);
27382 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27383 + if (d_really_is_positive(dentry)) {
27384 + if (!d_is_dir(dentry))
27385 + err = au_do_refresh(dentry, /*dir_flags*/0,
27388 + err = au_do_refresh(dentry, dir_flags, parent);
27389 + if (unlikely(err))
27390 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27393 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27394 + AuDbgDentry(dentry);
27400 + au_refresh_dop(dentry, /*force_reval*/0);
27402 + au_refresh_dop(dentry, /*force_reval*/1);
27408 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
27410 + int err, i, j, ndentry, e;
27411 + unsigned int sigen;
27412 + struct au_dcsub_pages dpages;
27413 + struct au_dpage *dpage;
27414 + struct dentry **dentries, *d;
27415 + struct au_sbinfo *sbinfo;
27416 + struct dentry *root = sb->s_root;
27417 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
27420 + au_refresh_dop(root, /*force_reval*/0);
27422 + err = au_dpages_init(&dpages, GFP_NOFS);
27423 + if (unlikely(err))
27425 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27426 + if (unlikely(err))
27429 + sigen = au_sigen(sb);
27430 + sbinfo = au_sbi(sb);
27431 + for (i = 0; i < dpages.ndpage; i++) {
27432 + dpage = dpages.dpages + i;
27433 + dentries = dpage->dentries;
27434 + ndentry = dpage->ndentry;
27435 + for (j = 0; j < ndentry; j++) {
27437 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
27439 + if (unlikely(e && !err))
27441 + /* go on even err */
27446 + au_dpages_free(&dpages);
27451 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
27454 + unsigned int sigen;
27455 + unsigned long long max, ull;
27456 + struct inode *inode, **array;
27458 + array = au_iarray_alloc(sb, &max);
27459 + err = PTR_ERR(array);
27460 + if (IS_ERR(array))
27464 + sigen = au_sigen(sb);
27465 + for (ull = 0; ull < max; ull++) {
27466 + inode = array[ull];
27467 + if (unlikely(!inode))
27471 + ii_write_lock_child(inode);
27472 + if (au_iigen(inode, NULL) != sigen) {
27473 + e = au_refresh_hinode_self(inode);
27474 + if (unlikely(e)) {
27475 + au_refresh_iop(inode, /*force_getattr*/1);
27476 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27479 + /* go on even if err */
27482 + if (!e && do_idop)
27483 + au_refresh_iop(inode, /*force_getattr*/0);
27484 + ii_write_unlock(inode);
27487 + au_iarray_free(array, max);
27493 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
27496 + unsigned int udba;
27497 + aufs_bindex_t bindex, bend;
27498 + struct dentry *root;
27499 + struct inode *inode;
27500 + struct au_branch *br;
27501 + struct au_sbinfo *sbi;
27503 + au_sigen_inc(sb);
27504 + sbi = au_sbi(sb);
27505 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
27507 + root = sb->s_root;
27508 + DiMustNoWaiters(root);
27509 + inode = d_inode(root);
27510 + IiMustNoWaiters(inode);
27512 + udba = au_opt_udba(sb);
27513 + bend = au_sbend(sb);
27514 + for (bindex = 0; bindex <= bend; bindex++) {
27515 + br = au_sbr(sb, bindex);
27516 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27517 + if (unlikely(err))
27518 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27520 + /* go on even if err */
27522 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27525 + if (au_ftest_si(sbi, NO_DREVAL)) {
27526 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
27527 + sb->s_d_op = &aufs_dop_noreval;
27528 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
27529 + sbi->si_iop_array = aufs_iop_nogetattr;
27531 + AuDebugOn(sb->s_d_op == &aufs_dop);
27532 + sb->s_d_op = &aufs_dop;
27533 + AuDebugOn(sbi->si_iop_array == aufs_iop);
27534 + sbi->si_iop_array = aufs_iop;
27536 + pr_info("reset to %pf and %pf\n",
27537 + sb->s_d_op, sbi->si_iop_array);
27540 + di_write_unlock(root);
27541 + err = au_refresh_d(sb, do_idop);
27542 + e = au_refresh_i(sb, do_idop);
27543 + if (unlikely(e && !err))
27545 + /* aufs_write_lock() calls ..._child() */
27546 + di_write_lock_child(root);
27548 + au_cpup_attr_all(inode, /*force*/1);
27550 + if (unlikely(err))
27551 + AuIOErr("refresh failed, ignored, %d\n", err);
27554 +/* stop extra interpretation of errno in mount(8), and strange error messages */
27555 +static int cvt_err(int err)
27569 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
27572 + unsigned int mntflags;
27573 + struct au_opts opts = {
27576 + struct dentry *root;
27577 + struct inode *inode;
27578 + struct au_sbinfo *sbinfo;
27581 + root = sb->s_root;
27582 + if (!data || !*data) {
27583 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27585 + di_write_lock_child(root);
27586 + err = au_opts_verify(sb, *flags, /*pending*/0);
27587 + aufs_write_unlock(root);
27593 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27594 + if (unlikely(!opts.opt))
27596 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27597 + opts.flags = AuOpts_REMOUNT;
27598 + opts.sb_flags = *flags;
27600 + /* parse it before aufs lock */
27601 + err = au_opts_parse(sb, data, &opts);
27602 + if (unlikely(err))
27605 + sbinfo = au_sbi(sb);
27606 + inode = d_inode(root);
27607 + mutex_lock(&inode->i_mutex);
27608 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27609 + if (unlikely(err))
27611 + di_write_lock_child(root);
27613 + /* au_opts_remount() may return an error */
27614 + err = au_opts_remount(sb, &opts);
27615 + au_opts_free(&opts);
27617 + if (au_ftest_opts(opts.flags, REFRESH))
27618 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
27620 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
27621 + mntflags = au_mntflags(sb);
27622 + do_dx = !!au_opt_test(mntflags, DIO);
27623 + au_dy_arefresh(do_dx);
27626 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
27627 + aufs_write_unlock(root);
27630 + mutex_unlock(&inode->i_mutex);
27632 + free_page((unsigned long)opts.opt);
27634 + err = cvt_err(err);
27639 +static const struct super_operations aufs_sop = {
27640 + .alloc_inode = aufs_alloc_inode,
27641 + .destroy_inode = aufs_destroy_inode,
27642 + /* always deleting, no clearing */
27643 + .drop_inode = generic_delete_inode,
27644 + .show_options = aufs_show_options,
27645 + .statfs = aufs_statfs,
27646 + .put_super = aufs_put_super,
27647 + .sync_fs = aufs_sync_fs,
27648 + .remount_fs = aufs_remount_fs
27651 +/* ---------------------------------------------------------------------- */
27653 +static int alloc_root(struct super_block *sb)
27656 + struct inode *inode;
27657 + struct dentry *root;
27660 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
27661 + err = PTR_ERR(inode);
27662 + if (IS_ERR(inode))
27665 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
27666 + inode->i_fop = &aufs_dir_fop;
27667 + inode->i_mode = S_IFDIR;
27668 + set_nlink(inode, 2);
27669 + unlock_new_inode(inode);
27671 + root = d_make_root(inode);
27672 + if (unlikely(!root))
27674 + err = PTR_ERR(root);
27675 + if (IS_ERR(root))
27678 + err = au_di_init(root);
27680 + sb->s_root = root;
27681 + return 0; /* success */
27689 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
27690 + int silent __maybe_unused)
27693 + struct au_opts opts = {
27696 + struct au_sbinfo *sbinfo;
27697 + struct dentry *root;
27698 + struct inode *inode;
27699 + char *arg = raw_data;
27701 + if (unlikely(!arg || !*arg)) {
27703 + pr_err("no arg\n");
27708 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27709 + if (unlikely(!opts.opt))
27711 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27712 + opts.sb_flags = sb->s_flags;
27714 + err = au_si_alloc(sb);
27715 + if (unlikely(err))
27717 + sbinfo = au_sbi(sb);
27719 + /* all timestamps always follow the ones on the branch */
27720 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
27721 + sb->s_op = &aufs_sop;
27722 + sb->s_d_op = &aufs_dop;
27723 + sb->s_magic = AUFS_SUPER_MAGIC;
27724 + sb->s_maxbytes = 0;
27725 + sb->s_stack_depth = 1;
27726 + au_export_init(sb);
27727 + /* au_xattr_init(sb); */
27729 + err = alloc_root(sb);
27730 + if (unlikely(err)) {
27731 + si_write_unlock(sb);
27734 + root = sb->s_root;
27735 + inode = d_inode(root);
27738 + * actually we can parse options regardless aufs lock here.
27739 + * but at remount time, parsing must be done before aufs lock.
27740 + * so we follow the same rule.
27742 + ii_write_lock_parent(inode);
27743 + aufs_write_unlock(root);
27744 + err = au_opts_parse(sb, arg, &opts);
27745 + if (unlikely(err))
27748 + /* lock vfs_inode first, then aufs. */
27749 + mutex_lock(&inode->i_mutex);
27750 + aufs_write_lock(root);
27751 + err = au_opts_mount(sb, &opts);
27752 + au_opts_free(&opts);
27753 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
27754 + sb->s_d_op = &aufs_dop_noreval;
27755 + pr_info("%pf\n", sb->s_d_op);
27756 + au_refresh_dop(root, /*force_reval*/0);
27757 + sbinfo->si_iop_array = aufs_iop_nogetattr;
27758 + au_refresh_iop(inode, /*force_getattr*/0);
27760 + aufs_write_unlock(root);
27761 + mutex_unlock(&inode->i_mutex);
27763 + goto out_opts; /* success */
27767 + sb->s_root = NULL;
27769 + dbgaufs_si_fin(sbinfo);
27770 + kobject_put(&sbinfo->si_kobj);
27771 + sb->s_fs_info = NULL;
27773 + free_page((unsigned long)opts.opt);
27776 + err = cvt_err(err);
27781 +/* ---------------------------------------------------------------------- */
27783 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
27784 + const char *dev_name __maybe_unused,
27787 + struct dentry *root;
27788 + struct super_block *sb;
27790 + /* all timestamps always follow the ones on the branch */
27791 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
27792 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
27793 + if (IS_ERR(root))
27797 + si_write_lock(sb, !AuLock_FLUSH);
27798 + sysaufs_brs_add(sb, 0);
27799 + si_write_unlock(sb);
27800 + au_sbilist_add(sb);
27806 +static void aufs_kill_sb(struct super_block *sb)
27808 + struct au_sbinfo *sbinfo;
27810 + sbinfo = au_sbi(sb);
27812 + au_sbilist_del(sb);
27813 + aufs_write_lock(sb->s_root);
27815 + if (sbinfo->si_wbr_create_ops->fin)
27816 + sbinfo->si_wbr_create_ops->fin(sb);
27817 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
27818 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
27819 + au_remount_refresh(sb, /*do_idop*/0);
27821 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27822 + au_plink_put(sb, /*verbose*/1);
27824 + sbinfo->si_sb = NULL;
27825 + aufs_write_unlock(sb->s_root);
27826 + au_nwt_flush(&sbinfo->si_nowait);
27828 + kill_anon_super(sb);
27831 +struct file_system_type aufs_fs_type = {
27832 + .name = AUFS_FSTYPE,
27833 + /* a race between rename and others */
27834 + .fs_flags = FS_RENAME_DOES_D_MOVE,
27835 + .mount = aufs_mount,
27836 + .kill_sb = aufs_kill_sb,
27837 + /* no need to __module_get() and module_put(). */
27838 + .owner = THIS_MODULE,
27840 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
27841 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
27842 +++ linux/fs/aufs/super.h 2016-02-28 11:26:32.573304539 +0100
27845 + * Copyright (C) 2005-2016 Junjiro R. Okajima
27847 + * This program, aufs is free software; you can redistribute it and/or modify
27848 + * it under the terms of the GNU General Public License as published by
27849 + * the Free Software Foundation; either version 2 of the License, or
27850 + * (at your option) any later version.
27852 + * This program is distributed in the hope that it will be useful,
27853 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27854 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27855 + * GNU General Public License for more details.
27857 + * You should have received a copy of the GNU General Public License
27858 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27862 + * super_block operations
27865 +#ifndef __AUFS_SUPER_H__
27866 +#define __AUFS_SUPER_H__
27870 +#include <linux/fs.h>
27871 +#include <linux/kobject.h>
27872 +#include "rwsem.h"
27876 +/* policies to select one among multiple writable branches */
27877 +struct au_wbr_copyup_operations {
27878 + int (*copyup)(struct dentry *dentry);
27881 +#define AuWbr_DIR 1 /* target is a dir */
27882 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
27884 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
27885 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
27886 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
27888 +struct au_wbr_create_operations {
27889 + int (*create)(struct dentry *dentry, unsigned int flags);
27890 + int (*init)(struct super_block *sb);
27891 + int (*fin)(struct super_block *sb);
27894 +struct au_wbr_mfs {
27895 + struct mutex mfs_lock; /* protect this structure */
27896 + unsigned long mfs_jiffy;
27897 + unsigned long mfs_expire;
27898 + aufs_bindex_t mfs_bindex;
27900 + unsigned long long mfsrr_bytes;
27901 + unsigned long long mfsrr_watermark;
27904 +struct pseudo_link {
27906 + struct hlist_node hlist;
27907 + struct rcu_head rcu;
27909 + struct inode *inode;
27912 +#define AuPlink_NHASH 100
27913 +static inline int au_plink_hash(ino_t ino)
27915 + return ino % AuPlink_NHASH;
27918 +/* File-based Hierarchical Storage Management */
27920 +#ifdef CONFIG_AUFS_FHSM
27921 + /* allow only one process who can receive the notification */
27922 + spinlock_t fhsm_spin;
27924 + wait_queue_head_t fhsm_wqh;
27925 + atomic_t fhsm_readable;
27927 + /* these are protected by si_rwsem */
27928 + unsigned long fhsm_expire;
27929 + aufs_bindex_t fhsm_bottom;
27934 +struct au_sbinfo {
27935 + /* nowait tasks in the system-wide workqueue */
27936 + struct au_nowait_tasks si_nowait;
27939 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
27940 + * rwsem for au_sbinfo is necessary.
27942 + struct au_rwsem si_rwsem;
27944 + /* prevent recursive locking in deleting inode */
27946 + unsigned long *bitmap;
27947 + spinlock_t tree_lock;
27948 + struct radix_tree_root tree;
27952 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
27955 + atomic_long_t si_ninodes, si_nfiles;
27957 + /* branch management */
27958 + unsigned int si_generation;
27960 + /* see AuSi_ flags */
27961 + unsigned char au_si_status;
27963 + aufs_bindex_t si_bend;
27965 + /* dirty trick to keep br_id plus */
27966 + unsigned int si_last_br_id :
27967 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
27968 + struct au_branch **si_branch;
27970 + /* policy to select a writable branch */
27971 + unsigned char si_wbr_copyup;
27972 + unsigned char si_wbr_create;
27973 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
27974 + struct au_wbr_create_operations *si_wbr_create_ops;
27976 + /* round robin */
27977 + atomic_t si_wbr_rr_next;
27979 + /* most free space */
27980 + struct au_wbr_mfs si_wbr_mfs;
27982 + /* File-based Hierarchical Storage Management */
27983 + struct au_fhsm si_fhsm;
27985 + /* mount flags */
27986 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
27987 + unsigned int si_mntflags;
27989 + /* symlink to follow_link() and put_link() */
27990 + struct au_sphlhead si_symlink;
27992 + /* external inode number (bitmap and translation table) */
27993 + vfs_readf_t si_xread;
27994 + vfs_writef_t si_xwrite;
27995 + struct file *si_xib;
27996 + struct mutex si_xib_mtx; /* protect xib members */
27997 + unsigned long *si_xib_buf;
27998 + unsigned long si_xib_last_pindex;
27999 + int si_xib_next_bit;
28000 + aufs_bindex_t si_xino_brid;
28001 + unsigned long si_xino_jiffy;
28002 + unsigned long si_xino_expire;
28003 + /* reserved for future use */
28004 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
28006 +#ifdef CONFIG_AUFS_EXPORT
28007 + /* i_generation */
28008 + struct file *si_xigen;
28009 + atomic_t si_xigen_next;
28012 + /* dirty trick to suppoer atomic_open */
28013 + struct au_sphlhead si_aopen;
28015 + /* vdir parameters */
28016 + unsigned long si_rdcache; /* max cache time in jiffies */
28017 + unsigned int si_rdblk; /* deblk size */
28018 + unsigned int si_rdhash; /* hash size */
28021 + * If the number of whiteouts are larger than si_dirwh, leave all of
28022 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
28023 + * future fsck.aufs or kernel thread will remove them later.
28024 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
28026 + unsigned int si_dirwh;
28028 + /* pseudo_link list */
28029 + struct au_sphlhead si_plink[AuPlink_NHASH];
28030 + wait_queue_head_t si_plink_wq;
28031 + spinlock_t si_plink_maint_lock;
28032 + pid_t si_plink_maint_pid;
28035 + struct au_sphlhead si_files;
28037 + /* with/without getattr, brother of sb->s_d_op */
28038 + struct inode_operations *si_iop_array;
28041 + * sysfs and lifetime management.
28042 + * this is not a small structure and it may be a waste of memory in case
28043 + * of sysfs is disabled, particulary when many aufs-es are mounted.
28044 + * but using sysfs is majority.
28046 + struct kobject si_kobj;
28047 +#ifdef CONFIG_DEBUG_FS
28048 + struct dentry *si_dbgaufs;
28049 + struct dentry *si_dbgaufs_plink;
28050 + struct dentry *si_dbgaufs_xib;
28051 +#ifdef CONFIG_AUFS_EXPORT
28052 + struct dentry *si_dbgaufs_xigen;
28056 +#ifdef CONFIG_AUFS_SBILIST
28057 + struct list_head si_list;
28060 + /* dirty, necessary for unmounting, sysfs and sysrq */
28061 + struct super_block *si_sb;
28064 +/* sbinfo status flags */
28066 + * set true when refresh_dirs() failed at remount time.
28067 + * then try refreshing dirs at access time again.
28068 + * if it is false, refreshing dirs at access time is unnecesary
28070 +#define AuSi_FAILED_REFRESH_DIR 1
28071 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
28072 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
28074 +#ifndef CONFIG_AUFS_FHSM
28076 +#define AuSi_FHSM 0
28079 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
28080 + unsigned int flag)
28082 + AuRwMustAnyLock(&sbi->si_rwsem);
28083 + return sbi->au_si_status & flag;
28085 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
28086 +#define au_fset_si(sbinfo, name) do { \
28087 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28088 + (sbinfo)->au_si_status |= AuSi_##name; \
28090 +#define au_fclr_si(sbinfo, name) do { \
28091 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28092 + (sbinfo)->au_si_status &= ~AuSi_##name; \
28095 +/* ---------------------------------------------------------------------- */
28097 +/* policy to select one among writable branches */
28098 +#define AuWbrCopyup(sbinfo, ...) \
28099 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
28100 +#define AuWbrCreate(sbinfo, ...) \
28101 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
28103 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
28104 +#define AuLock_DW 1 /* write-lock dentry */
28105 +#define AuLock_IR (1 << 1) /* read-lock inode */
28106 +#define AuLock_IW (1 << 2) /* write-lock inode */
28107 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
28108 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
28109 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
28110 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
28111 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
28112 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
28113 +#define au_fset_lock(flags, name) \
28114 + do { (flags) |= AuLock_##name; } while (0)
28115 +#define au_fclr_lock(flags, name) \
28116 + do { (flags) &= ~AuLock_##name; } while (0)
28118 +/* ---------------------------------------------------------------------- */
28121 +extern struct file_system_type aufs_fs_type;
28122 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
28123 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
28124 + unsigned long long max, void *arg);
28125 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
28126 + struct super_block *sb, void *arg);
28127 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
28128 +void au_iarray_free(struct inode **a, unsigned long long max);
28131 +void au_si_free(struct kobject *kobj);
28132 +int au_si_alloc(struct super_block *sb);
28133 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
28135 +unsigned int au_sigen_inc(struct super_block *sb);
28136 +aufs_bindex_t au_new_br_id(struct super_block *sb);
28138 +int si_read_lock(struct super_block *sb, int flags);
28139 +int si_write_lock(struct super_block *sb, int flags);
28140 +int aufs_read_lock(struct dentry *dentry, int flags);
28141 +void aufs_read_unlock(struct dentry *dentry, int flags);
28142 +void aufs_write_lock(struct dentry *dentry);
28143 +void aufs_write_unlock(struct dentry *dentry);
28144 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
28145 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
28147 +int si_pid_test_slow(struct super_block *sb);
28148 +void si_pid_set_slow(struct super_block *sb);
28149 +void si_pid_clr_slow(struct super_block *sb);
28151 +/* wbr_policy.c */
28152 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
28153 +extern struct au_wbr_create_operations au_wbr_create_ops[];
28154 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
28155 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
28156 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
28159 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
28161 +#ifdef CONFIG_AUFS_FHSM
28164 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
28168 + spin_lock(&fhsm->fhsm_spin);
28169 + pid = fhsm->fhsm_pid;
28170 + spin_unlock(&fhsm->fhsm_spin);
28175 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
28176 +void au_fhsm_wrote_all(struct super_block *sb, int force);
28177 +int au_fhsm_fd(struct super_block *sb, int oflags);
28178 +int au_fhsm_br_alloc(struct au_branch *br);
28179 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
28180 +void au_fhsm_fin(struct super_block *sb);
28181 +void au_fhsm_init(struct au_sbinfo *sbinfo);
28182 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
28183 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
28185 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
28187 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
28188 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
28189 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
28190 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
28191 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
28192 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
28193 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
28194 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
28195 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
28198 +/* ---------------------------------------------------------------------- */
28200 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
28202 + return sb->s_fs_info;
28205 +/* ---------------------------------------------------------------------- */
28207 +#ifdef CONFIG_AUFS_EXPORT
28208 +int au_test_nfsd(void);
28209 +void au_export_init(struct super_block *sb);
28210 +void au_xigen_inc(struct inode *inode);
28211 +int au_xigen_new(struct inode *inode);
28212 +int au_xigen_set(struct super_block *sb, struct file *base);
28213 +void au_xigen_clr(struct super_block *sb);
28215 +static inline int au_busy_or_stale(void)
28217 + if (!au_test_nfsd())
28222 +AuStubInt0(au_test_nfsd, void)
28223 +AuStubVoid(au_export_init, struct super_block *sb)
28224 +AuStubVoid(au_xigen_inc, struct inode *inode)
28225 +AuStubInt0(au_xigen_new, struct inode *inode)
28226 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
28227 +AuStubVoid(au_xigen_clr, struct super_block *sb)
28228 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
28229 +#endif /* CONFIG_AUFS_EXPORT */
28231 +/* ---------------------------------------------------------------------- */
28233 +#ifdef CONFIG_AUFS_SBILIST
28235 +extern struct au_splhead au_sbilist;
28237 +static inline void au_sbilist_init(void)
28239 + au_spl_init(&au_sbilist);
28242 +static inline void au_sbilist_add(struct super_block *sb)
28244 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
28247 +static inline void au_sbilist_del(struct super_block *sb)
28249 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
28252 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
28253 +static inline void au_sbilist_lock(void)
28255 + spin_lock(&au_sbilist.spin);
28258 +static inline void au_sbilist_unlock(void)
28260 + spin_unlock(&au_sbilist.spin);
28262 +#define AuGFP_SBILIST GFP_ATOMIC
28264 +AuStubVoid(au_sbilist_lock, void)
28265 +AuStubVoid(au_sbilist_unlock, void)
28266 +#define AuGFP_SBILIST GFP_NOFS
28267 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28269 +AuStubVoid(au_sbilist_init, void)
28270 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28271 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28272 +AuStubVoid(au_sbilist_lock, void)
28273 +AuStubVoid(au_sbilist_unlock, void)
28274 +#define AuGFP_SBILIST GFP_NOFS
28277 +/* ---------------------------------------------------------------------- */
28279 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28282 + * This function is a dynamic '__init' function actually,
28283 + * so the tiny check for si_rwsem is unnecessary.
28285 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28286 +#ifdef CONFIG_DEBUG_FS
28287 + sbinfo->si_dbgaufs = NULL;
28288 + sbinfo->si_dbgaufs_plink = NULL;
28289 + sbinfo->si_dbgaufs_xib = NULL;
28290 +#ifdef CONFIG_AUFS_EXPORT
28291 + sbinfo->si_dbgaufs_xigen = NULL;
28296 +/* ---------------------------------------------------------------------- */
28298 +static inline pid_t si_pid_bit(void)
28300 + /* the origin of pid is 1, but the bitmap's is 0 */
28301 + return current->pid - 1;
28304 +static inline int si_pid_test(struct super_block *sb)
28308 + bit = si_pid_bit();
28309 + if (bit < PID_MAX_DEFAULT)
28310 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28311 + return si_pid_test_slow(sb);
28314 +static inline void si_pid_set(struct super_block *sb)
28318 + bit = si_pid_bit();
28319 + if (bit < PID_MAX_DEFAULT) {
28320 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
28321 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28324 + si_pid_set_slow(sb);
28327 +static inline void si_pid_clr(struct super_block *sb)
28331 + bit = si_pid_bit();
28332 + if (bit < PID_MAX_DEFAULT) {
28333 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
28334 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28337 + si_pid_clr_slow(sb);
28340 +/* ---------------------------------------------------------------------- */
28342 +/* lock superblock. mainly for entry point functions */
28344 + * __si_read_lock, __si_write_lock,
28345 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28347 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28349 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28350 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28351 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28353 +static inline void si_noflush_read_lock(struct super_block *sb)
28355 + __si_read_lock(sb);
28359 +static inline int si_noflush_read_trylock(struct super_block *sb)
28363 + locked = __si_read_trylock(sb);
28369 +static inline void si_noflush_write_lock(struct super_block *sb)
28371 + __si_write_lock(sb);
28375 +static inline int si_noflush_write_trylock(struct super_block *sb)
28379 + locked = __si_write_trylock(sb);
28385 +#if 0 /* reserved */
28386 +static inline int si_read_trylock(struct super_block *sb, int flags)
28388 + if (au_ftest_lock(flags, FLUSH))
28389 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28390 + return si_noflush_read_trylock(sb);
28394 +static inline void si_read_unlock(struct super_block *sb)
28397 + __si_read_unlock(sb);
28400 +#if 0 /* reserved */
28401 +static inline int si_write_trylock(struct super_block *sb, int flags)
28403 + if (au_ftest_lock(flags, FLUSH))
28404 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28405 + return si_noflush_write_trylock(sb);
28409 +static inline void si_write_unlock(struct super_block *sb)
28412 + __si_write_unlock(sb);
28415 +#if 0 /* reserved */
28416 +static inline void si_downgrade_lock(struct super_block *sb)
28418 + __si_downgrade_lock(sb);
28422 +/* ---------------------------------------------------------------------- */
28424 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
28426 + SiMustAnyLock(sb);
28427 + return au_sbi(sb)->si_bend;
28430 +static inline unsigned int au_mntflags(struct super_block *sb)
28432 + SiMustAnyLock(sb);
28433 + return au_sbi(sb)->si_mntflags;
28436 +static inline unsigned int au_sigen(struct super_block *sb)
28438 + SiMustAnyLock(sb);
28439 + return au_sbi(sb)->si_generation;
28442 +static inline void au_ninodes_inc(struct super_block *sb)
28444 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
28447 +static inline void au_ninodes_dec(struct super_block *sb)
28449 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
28450 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
28453 +static inline void au_nfiles_inc(struct super_block *sb)
28455 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
28458 +static inline void au_nfiles_dec(struct super_block *sb)
28460 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
28461 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
28464 +static inline struct au_branch *au_sbr(struct super_block *sb,
28465 + aufs_bindex_t bindex)
28467 + SiMustAnyLock(sb);
28468 + return au_sbi(sb)->si_branch[0 + bindex];
28471 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28473 + SiMustWriteLock(sb);
28474 + au_sbi(sb)->si_xino_brid = brid;
28477 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28479 + SiMustAnyLock(sb);
28480 + return au_sbi(sb)->si_xino_brid;
28483 +#endif /* __KERNEL__ */
28484 +#endif /* __AUFS_SUPER_H__ */
28485 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28486 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28487 +++ linux/fs/aufs/sysaufs.c 2016-02-28 11:26:32.573304539 +0100
28490 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28492 + * This program, aufs is free software; you can redistribute it and/or modify
28493 + * it under the terms of the GNU General Public License as published by
28494 + * the Free Software Foundation; either version 2 of the License, or
28495 + * (at your option) any later version.
28497 + * This program is distributed in the hope that it will be useful,
28498 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28499 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28500 + * GNU General Public License for more details.
28502 + * You should have received a copy of the GNU General Public License
28503 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28507 + * sysfs interface and lifetime management
28508 + * they are necessary regardless sysfs is disabled.
28511 +#include <linux/random.h>
28514 +unsigned long sysaufs_si_mask;
28515 +struct kset *sysaufs_kset;
28517 +#define AuSiAttr(_name) { \
28518 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28519 + .show = sysaufs_si_##_name, \
28522 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28523 +struct attribute *sysaufs_si_attrs[] = {
28524 + &sysaufs_si_attr_xi_path.attr,
28528 +static const struct sysfs_ops au_sbi_ops = {
28529 + .show = sysaufs_si_show
28532 +static struct kobj_type au_sbi_ktype = {
28533 + .release = au_si_free,
28534 + .sysfs_ops = &au_sbi_ops,
28535 + .default_attrs = sysaufs_si_attrs
28538 +/* ---------------------------------------------------------------------- */
28540 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28544 + sbinfo->si_kobj.kset = sysaufs_kset;
28545 + /* cf. sysaufs_name() */
28546 + err = kobject_init_and_add
28547 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28548 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28550 + dbgaufs_si_null(sbinfo);
28552 + err = dbgaufs_si_init(sbinfo);
28553 + if (unlikely(err))
28554 + kobject_put(&sbinfo->si_kobj);
28559 +void sysaufs_fin(void)
28562 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28563 + kset_unregister(sysaufs_kset);
28566 +int __init sysaufs_init(void)
28571 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
28572 + } while (!sysaufs_si_mask);
28575 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
28576 + if (unlikely(!sysaufs_kset))
28578 + err = PTR_ERR(sysaufs_kset);
28579 + if (IS_ERR(sysaufs_kset))
28581 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28582 + if (unlikely(err)) {
28583 + kset_unregister(sysaufs_kset);
28587 + err = dbgaufs_init();
28588 + if (unlikely(err))
28593 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
28594 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
28595 +++ linux/fs/aufs/sysaufs.h 2016-02-28 11:26:32.573304539 +0100
28598 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28600 + * This program, aufs is free software; you can redistribute it and/or modify
28601 + * it under the terms of the GNU General Public License as published by
28602 + * the Free Software Foundation; either version 2 of the License, or
28603 + * (at your option) any later version.
28605 + * This program is distributed in the hope that it will be useful,
28606 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28607 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28608 + * GNU General Public License for more details.
28610 + * You should have received a copy of the GNU General Public License
28611 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28615 + * sysfs interface and mount lifetime management
28618 +#ifndef __SYSAUFS_H__
28619 +#define __SYSAUFS_H__
28623 +#include <linux/sysfs.h>
28624 +#include "module.h"
28626 +struct super_block;
28629 +struct sysaufs_si_attr {
28630 + struct attribute attr;
28631 + int (*show)(struct seq_file *seq, struct super_block *sb);
28634 +/* ---------------------------------------------------------------------- */
28637 +extern unsigned long sysaufs_si_mask;
28638 +extern struct kset *sysaufs_kset;
28639 +extern struct attribute *sysaufs_si_attrs[];
28640 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
28641 +int __init sysaufs_init(void);
28642 +void sysaufs_fin(void);
28644 +/* ---------------------------------------------------------------------- */
28646 +/* some people doesn't like to show a pointer in kernel */
28647 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
28649 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
28652 +#define SysaufsSiNamePrefix "si_"
28653 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
28654 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
28656 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
28657 + sysaufs_si_id(sbinfo));
28661 +#ifdef CONFIG_SYSFS
28663 +extern struct attribute_group *sysaufs_attr_group;
28665 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
28666 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28668 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
28669 +#ifdef CONFIG_COMPAT
28670 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
28673 +void sysaufs_br_init(struct au_branch *br);
28674 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
28675 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
28677 +#define sysaufs_brs_init() do {} while (0)
28680 +#define sysaufs_attr_group NULL
28682 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
28683 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
28684 + struct attribute *attr, char *buf)
28685 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
28686 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
28687 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
28689 +static inline void sysaufs_brs_init(void)
28694 +#endif /* CONFIG_SYSFS */
28696 +#endif /* __KERNEL__ */
28697 +#endif /* __SYSAUFS_H__ */
28698 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
28699 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
28700 +++ linux/fs/aufs/sysfs.c 2016-02-28 11:26:32.573304539 +0100
28703 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28705 + * This program, aufs is free software; you can redistribute it and/or modify
28706 + * it under the terms of the GNU General Public License as published by
28707 + * the Free Software Foundation; either version 2 of the License, or
28708 + * (at your option) any later version.
28710 + * This program is distributed in the hope that it will be useful,
28711 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28712 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28713 + * GNU General Public License for more details.
28715 + * You should have received a copy of the GNU General Public License
28716 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28720 + * sysfs interface
28723 +#include <linux/compat.h>
28724 +#include <linux/seq_file.h>
28727 +#ifdef CONFIG_AUFS_FS_MODULE
28728 +/* this entry violates the "one line per file" policy of sysfs */
28729 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
28733 + static char *conf =
28734 +/* this file is generated at compiling */
28735 +#include "conf.str"
28738 + err = snprintf(buf, PAGE_SIZE, conf);
28739 + if (unlikely(err >= PAGE_SIZE))
28744 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
28747 +static struct attribute *au_attr[] = {
28748 +#ifdef CONFIG_AUFS_FS_MODULE
28749 + &au_config_attr.attr,
28751 + NULL, /* need to NULL terminate the list of attributes */
28754 +static struct attribute_group sysaufs_attr_group_body = {
28758 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
28760 +/* ---------------------------------------------------------------------- */
28762 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
28766 + SiMustAnyLock(sb);
28769 + if (au_opt_test(au_mntflags(sb), XINO)) {
28770 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
28771 + seq_putc(seq, '\n');
28777 + * the lifetime of branch is independent from the entry under sysfs.
28778 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
28781 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
28782 + aufs_bindex_t bindex, int idx)
28785 + struct path path;
28786 + struct dentry *root;
28787 + struct au_branch *br;
28788 + au_br_perm_str_t perm;
28790 + AuDbg("b%d\n", bindex);
28793 + root = sb->s_root;
28794 + di_read_lock_parent(root, !AuLock_IR);
28795 + br = au_sbr(sb, bindex);
28798 + case AuBrSysfs_BR:
28799 + path.mnt = au_br_mnt(br);
28800 + path.dentry = au_h_dptr(root, bindex);
28801 + err = au_seq_path(seq, &path);
28803 + au_optstr_br_perm(&perm, br->br_perm);
28804 + seq_printf(seq, "=%s\n", perm.a);
28807 + case AuBrSysfs_BRID:
28808 + seq_printf(seq, "%d\n", br->br_id);
28811 + di_read_unlock(root, !AuLock_IR);
28812 + if (unlikely(err || seq_has_overflowed(seq)))
28818 +/* ---------------------------------------------------------------------- */
28820 +static struct seq_file *au_seq(char *p, ssize_t len)
28822 + struct seq_file *seq;
28824 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
28826 + /* mutex_init(&seq.lock); */
28829 + return seq; /* success */
28832 + seq = ERR_PTR(-ENOMEM);
28836 +#define SysaufsBr_PREFIX "br"
28837 +#define SysaufsBrid_PREFIX "brid"
28839 +/* todo: file size may exceed PAGE_SIZE */
28840 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28846 + aufs_bindex_t bend;
28847 + struct au_sbinfo *sbinfo;
28848 + struct super_block *sb;
28849 + struct seq_file *seq;
28851 + struct attribute **cattr;
28853 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28854 + sb = sbinfo->si_sb;
28857 + * prevent a race condition between sysfs and aufs.
28858 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
28859 + * prohibits maintaining the sysfs entries.
28860 + * hew we acquire read lock after sysfs_get_active_two().
28861 + * on the other hand, the remount process may maintain the sysfs/aufs
28862 + * entries after acquiring write lock.
28863 + * it can cause a deadlock.
28864 + * simply we gave up processing read here.
28867 + if (unlikely(!si_noflush_read_trylock(sb)))
28870 + seq = au_seq(buf, PAGE_SIZE);
28871 + err = PTR_ERR(seq);
28875 + name = (void *)attr->name;
28876 + cattr = sysaufs_si_attrs;
28878 + if (!strcmp(name, (*cattr)->name)) {
28879 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
28886 + if (!strncmp(name, SysaufsBrid_PREFIX,
28887 + sizeof(SysaufsBrid_PREFIX) - 1)) {
28888 + idx = AuBrSysfs_BRID;
28889 + name += sizeof(SysaufsBrid_PREFIX) - 1;
28890 + } else if (!strncmp(name, SysaufsBr_PREFIX,
28891 + sizeof(SysaufsBr_PREFIX) - 1)) {
28892 + idx = AuBrSysfs_BR;
28893 + name += sizeof(SysaufsBr_PREFIX) - 1;
28897 + err = kstrtol(name, 10, &l);
28899 + bend = au_sbend(sb);
28901 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
28908 + err = seq->count;
28909 + /* sysfs limit */
28910 + if (unlikely(err == PAGE_SIZE))
28915 + si_read_unlock(sb);
28920 +/* ---------------------------------------------------------------------- */
28922 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
28926 + aufs_bindex_t bindex, bend;
28929 + struct seq_file *seq;
28930 + struct au_branch *br;
28932 + si_read_lock(sb, AuLock_FLUSH);
28933 + bend = au_sbend(sb);
28939 + buf = (void *)__get_free_page(GFP_NOFS);
28940 + if (unlikely(!buf))
28943 + seq = au_seq(buf, PAGE_SIZE);
28944 + err = PTR_ERR(seq);
28948 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
28949 + for (bindex = 0; bindex <= bend; bindex++, arg++) {
28950 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
28951 + if (unlikely(err))
28954 + br = au_sbr(sb, bindex);
28955 + brid = br->br_id;
28956 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
28957 + err = __put_user(brid, &arg->id);
28958 + if (unlikely(err))
28961 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
28962 + err = __put_user(br->br_perm, &arg->perm);
28963 + if (unlikely(err))
28966 + err = au_seq_path(seq, &br->br_path);
28967 + if (unlikely(err))
28969 + seq_putc(seq, '\0');
28970 + if (!seq_has_overflowed(seq)) {
28971 + err = copy_to_user(arg->path, seq->buf, seq->count);
28973 + if (unlikely(err))
28980 + if (unlikely(err))
28986 + free_page((unsigned long)buf);
28988 + si_read_unlock(sb);
28992 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
28994 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
28997 +#ifdef CONFIG_COMPAT
28998 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
29000 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
29004 +/* ---------------------------------------------------------------------- */
29006 +void sysaufs_br_init(struct au_branch *br)
29009 + struct au_brsysfs *br_sysfs;
29010 + struct attribute *attr;
29012 + br_sysfs = br->br_sysfs;
29013 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29014 + attr = &br_sysfs->attr;
29015 + sysfs_attr_init(attr);
29016 + attr->name = br_sysfs->name;
29017 + attr->mode = S_IRUGO;
29022 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
29024 + struct au_branch *br;
29025 + struct kobject *kobj;
29026 + struct au_brsysfs *br_sysfs;
29028 + aufs_bindex_t bend;
29030 + dbgaufs_brs_del(sb, bindex);
29032 + if (!sysaufs_brs)
29035 + kobj = &au_sbi(sb)->si_kobj;
29036 + bend = au_sbend(sb);
29037 + for (; bindex <= bend; bindex++) {
29038 + br = au_sbr(sb, bindex);
29039 + br_sysfs = br->br_sysfs;
29040 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29041 + sysfs_remove_file(kobj, &br_sysfs->attr);
29047 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
29050 + aufs_bindex_t bend;
29051 + struct kobject *kobj;
29052 + struct au_branch *br;
29053 + struct au_brsysfs *br_sysfs;
29055 + dbgaufs_brs_add(sb, bindex);
29057 + if (!sysaufs_brs)
29060 + kobj = &au_sbi(sb)->si_kobj;
29061 + bend = au_sbend(sb);
29062 + for (; bindex <= bend; bindex++) {
29063 + br = au_sbr(sb, bindex);
29064 + br_sysfs = br->br_sysfs;
29065 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
29066 + SysaufsBr_PREFIX "%d", bindex);
29067 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
29068 + SysaufsBrid_PREFIX "%d", bindex);
29069 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29070 + err = sysfs_create_file(kobj, &br_sysfs->attr);
29071 + if (unlikely(err))
29072 + pr_warn("failed %s under sysfs(%d)\n",
29073 + br_sysfs->name, err);
29078 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
29079 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
29080 +++ linux/fs/aufs/sysrq.c 2016-02-28 11:26:32.573304539 +0100
29083 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29085 + * This program, aufs is free software; you can redistribute it and/or modify
29086 + * it under the terms of the GNU General Public License as published by
29087 + * the Free Software Foundation; either version 2 of the License, or
29088 + * (at your option) any later version.
29090 + * This program is distributed in the hope that it will be useful,
29091 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29092 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29093 + * GNU General Public License for more details.
29095 + * You should have received a copy of the GNU General Public License
29096 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29100 + * magic sysrq hanlder
29103 +/* #include <linux/sysrq.h> */
29104 +#include <linux/writeback.h>
29107 +/* ---------------------------------------------------------------------- */
29109 +static void sysrq_sb(struct super_block *sb)
29112 + struct au_sbinfo *sbinfo;
29113 + struct file *file;
29114 + struct au_sphlhead *files;
29115 + struct au_finfo *finfo;
29117 + plevel = au_plevel;
29118 + au_plevel = KERN_WARNING;
29120 + /* since we define pr_fmt, call printk directly */
29121 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
29123 + sbinfo = au_sbi(sb);
29124 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
29125 + pr("superblock\n");
29129 + pr("root dentry\n");
29130 + au_dpri_dentry(sb->s_root);
29131 + pr("root inode\n");
29132 + au_dpri_inode(d_inode(sb->s_root));
29137 + int err, i, j, ndentry;
29138 + struct au_dcsub_pages dpages;
29139 + struct au_dpage *dpage;
29141 + err = au_dpages_init(&dpages, GFP_ATOMIC);
29142 + if (unlikely(err))
29144 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
29146 + for (i = 0; i < dpages.ndpage; i++) {
29147 + dpage = dpages.dpages + i;
29148 + ndentry = dpage->ndentry;
29149 + for (j = 0; j < ndentry; j++)
29150 + au_dpri_dentry(dpage->dentries[j]);
29152 + au_dpages_free(&dpages);
29160 + pr("isolated inode\n");
29161 + spin_lock(&sb->s_inode_list_lock);
29162 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
29163 + spin_lock(&i->i_lock);
29164 + if (1 || hlist_empty(&i->i_dentry))
29165 + au_dpri_inode(i);
29166 + spin_unlock(&i->i_lock);
29168 + spin_unlock(&sb->s_inode_list_lock);
29172 + files = &au_sbi(sb)->si_files;
29173 + spin_lock(&files->spin);
29174 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
29177 + file = finfo->fi_file;
29178 + mode = file_inode(file)->i_mode;
29179 + if (!special_file(mode))
29180 + au_dpri_file(file);
29182 + spin_unlock(&files->spin);
29186 + au_plevel = plevel;
29189 +/* ---------------------------------------------------------------------- */
29191 +/* module parameter */
29192 +static char *aufs_sysrq_key = "a";
29193 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
29194 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
29196 +static void au_sysrq(int key __maybe_unused)
29198 + struct au_sbinfo *sbinfo;
29201 + au_sbilist_lock();
29202 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
29203 + sysrq_sb(sbinfo->si_sb);
29204 + au_sbilist_unlock();
29208 +static struct sysrq_key_op au_sysrq_op = {
29209 + .handler = au_sysrq,
29210 + .help_msg = "Aufs",
29211 + .action_msg = "Aufs",
29212 + .enable_mask = SYSRQ_ENABLE_DUMP
29215 +/* ---------------------------------------------------------------------- */
29217 +int __init au_sysrq_init(void)
29223 + key = *aufs_sysrq_key;
29224 + if ('a' <= key && key <= 'z')
29225 + err = register_sysrq_key(key, &au_sysrq_op);
29226 + if (unlikely(err))
29227 + pr_err("err %d, sysrq=%c\n", err, key);
29231 +void au_sysrq_fin(void)
29235 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
29236 + if (unlikely(err))
29237 + pr_err("err %d (ignored)\n", err);
29239 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
29240 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
29241 +++ linux/fs/aufs/vdir.c 2016-02-28 11:26:32.573304539 +0100
29244 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29246 + * This program, aufs is free software; you can redistribute it and/or modify
29247 + * it under the terms of the GNU General Public License as published by
29248 + * the Free Software Foundation; either version 2 of the License, or
29249 + * (at your option) any later version.
29251 + * This program is distributed in the hope that it will be useful,
29252 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29253 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29254 + * GNU General Public License for more details.
29256 + * You should have received a copy of the GNU General Public License
29257 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29261 + * virtual or vertical directory
29266 +static unsigned int calc_size(int nlen)
29268 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29271 +static int set_deblk_end(union au_vdir_deblk_p *p,
29272 + union au_vdir_deblk_p *deblk_end)
29274 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29275 + p->de->de_str.len = 0;
29279 + return -1; /* error */
29282 +/* returns true or false */
29283 +static int is_deblk_end(union au_vdir_deblk_p *p,
29284 + union au_vdir_deblk_p *deblk_end)
29286 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29287 + return !p->de->de_str.len;
29291 +static unsigned char *last_deblk(struct au_vdir *vdir)
29293 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29296 +/* ---------------------------------------------------------------------- */
29298 +/* estimate the appropriate size for name hash table */
29299 +unsigned int au_rdhash_est(loff_t sz)
29307 + if (sz < AUFS_RDHASH_DEF)
29308 + n = AUFS_RDHASH_DEF;
29309 + /* pr_info("n %u\n", n); */
29314 + * the allocated memory has to be freed by
29315 + * au_nhash_wh_free() or au_nhash_de_free().
29317 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29319 + struct hlist_head *head;
29323 + sz = sizeof(*nhash->nh_head) * num_hash;
29324 + head = kmalloc(sz, gfp);
29326 + nhash->nh_num = num_hash;
29327 + nhash->nh_head = head;
29328 + for (u = 0; u < num_hash; u++)
29329 + INIT_HLIST_HEAD(head++);
29330 + return 0; /* success */
29336 +static void nhash_count(struct hlist_head *head)
29340 + struct hlist_node *pos;
29343 + hlist_for_each(pos, head)
29345 + pr_info("%lu\n", n);
29349 +static void au_nhash_wh_do_free(struct hlist_head *head)
29351 + struct au_vdir_wh *pos;
29352 + struct hlist_node *node;
29354 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29358 +static void au_nhash_de_do_free(struct hlist_head *head)
29360 + struct au_vdir_dehstr *pos;
29361 + struct hlist_node *node;
29363 + hlist_for_each_entry_safe(pos, node, head, hash)
29364 + au_cache_free_vdir_dehstr(pos);
29367 +static void au_nhash_do_free(struct au_nhash *nhash,
29368 + void (*free)(struct hlist_head *head))
29371 + struct hlist_head *head;
29373 + n = nhash->nh_num;
29377 + head = nhash->nh_head;
29378 + while (n-- > 0) {
29379 + nhash_count(head);
29382 + kfree(nhash->nh_head);
29385 +void au_nhash_wh_free(struct au_nhash *whlist)
29387 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29390 +static void au_nhash_de_free(struct au_nhash *delist)
29392 + au_nhash_do_free(delist, au_nhash_de_do_free);
29395 +/* ---------------------------------------------------------------------- */
29397 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29401 + unsigned int u, n;
29402 + struct hlist_head *head;
29403 + struct au_vdir_wh *pos;
29406 + n = whlist->nh_num;
29407 + head = whlist->nh_head;
29408 + for (u = 0; u < n; u++, head++)
29409 + hlist_for_each_entry(pos, head, wh_hash)
29410 + if (pos->wh_bindex == btgt && ++num > limit)
29415 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29416 + unsigned char *name,
29417 + unsigned int len)
29420 + /* const unsigned int magic_bit = 12; */
29422 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29427 + /* v = hash_long(v, magic_bit); */
29428 + v %= nhash->nh_num;
29429 + return nhash->nh_head + v;
29432 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29435 + return str->len == nlen && !memcmp(str->name, name, nlen);
29438 +/* returns found or not */
29439 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29441 + struct hlist_head *head;
29442 + struct au_vdir_wh *pos;
29443 + struct au_vdir_destr *str;
29445 + head = au_name_hash(whlist, name, nlen);
29446 + hlist_for_each_entry(pos, head, wh_hash) {
29447 + str = &pos->wh_str;
29448 + AuDbg("%.*s\n", str->len, str->name);
29449 + if (au_nhash_test_name(str, name, nlen))
29455 +/* returns found(true) or not */
29456 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29458 + struct hlist_head *head;
29459 + struct au_vdir_dehstr *pos;
29460 + struct au_vdir_destr *str;
29462 + head = au_name_hash(delist, name, nlen);
29463 + hlist_for_each_entry(pos, head, hash) {
29465 + AuDbg("%.*s\n", str->len, str->name);
29466 + if (au_nhash_test_name(str, name, nlen))
29472 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29473 + unsigned char d_type)
29475 +#ifdef CONFIG_AUFS_SHWH
29476 + wh->wh_ino = ino;
29477 + wh->wh_type = d_type;
29481 +/* ---------------------------------------------------------------------- */
29483 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29484 + unsigned int d_type, aufs_bindex_t bindex,
29485 + unsigned char shwh)
29488 + struct au_vdir_destr *str;
29489 + struct au_vdir_wh *wh;
29491 + AuDbg("%.*s\n", nlen, name);
29492 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29495 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29496 + if (unlikely(!wh))
29500 + wh->wh_bindex = bindex;
29502 + au_shwh_init_wh(wh, ino, d_type);
29503 + str = &wh->wh_str;
29505 + memcpy(str->name, name, nlen);
29506 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29513 +static int append_deblk(struct au_vdir *vdir)
29516 + unsigned long ul;
29517 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29518 + union au_vdir_deblk_p p, deblk_end;
29519 + unsigned char **o;
29522 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29524 + if (unlikely(!o))
29527 + vdir->vd_deblk = o;
29528 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29530 + ul = vdir->vd_nblk++;
29531 + vdir->vd_deblk[ul] = p.deblk;
29532 + vdir->vd_last.ul = ul;
29533 + vdir->vd_last.p.deblk = p.deblk;
29534 + deblk_end.deblk = p.deblk + deblk_sz;
29535 + err = set_deblk_end(&p, &deblk_end);
29542 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29543 + unsigned int d_type, struct au_nhash *delist)
29547 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29548 + union au_vdir_deblk_p p, *room, deblk_end;
29549 + struct au_vdir_dehstr *dehstr;
29551 + p.deblk = last_deblk(vdir);
29552 + deblk_end.deblk = p.deblk + deblk_sz;
29553 + room = &vdir->vd_last.p;
29554 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29555 + || !is_deblk_end(room, &deblk_end));
29557 + sz = calc_size(nlen);
29558 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29559 + err = append_deblk(vdir);
29560 + if (unlikely(err))
29563 + p.deblk = last_deblk(vdir);
29564 + deblk_end.deblk = p.deblk + deblk_sz;
29566 + AuDebugOn(room->deblk != p.deblk);
29570 + dehstr = au_cache_alloc_vdir_dehstr();
29571 + if (unlikely(!dehstr))
29574 + dehstr->str = &room->de->de_str;
29575 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
29576 + room->de->de_ino = ino;
29577 + room->de->de_type = d_type;
29578 + room->de->de_str.len = nlen;
29579 + memcpy(room->de->de_str.name, name, nlen);
29582 + room->deblk += sz;
29583 + if (unlikely(set_deblk_end(room, &deblk_end)))
29584 + err = append_deblk(vdir);
29591 +/* ---------------------------------------------------------------------- */
29593 +void au_vdir_free(struct au_vdir *vdir)
29595 + unsigned char **deblk;
29597 + deblk = vdir->vd_deblk;
29598 + while (vdir->vd_nblk--)
29600 + kfree(vdir->vd_deblk);
29601 + au_cache_free_vdir(vdir);
29604 +static struct au_vdir *alloc_vdir(struct file *file)
29606 + struct au_vdir *vdir;
29607 + struct super_block *sb;
29610 + sb = file->f_path.dentry->d_sb;
29611 + SiMustAnyLock(sb);
29614 + vdir = au_cache_alloc_vdir();
29615 + if (unlikely(!vdir))
29618 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
29619 + if (unlikely(!vdir->vd_deblk))
29622 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
29623 + if (!vdir->vd_deblk_sz) {
29624 + /* estimate the appropriate size for deblk */
29625 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
29626 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
29628 + vdir->vd_nblk = 0;
29629 + vdir->vd_version = 0;
29630 + vdir->vd_jiffy = 0;
29631 + err = append_deblk(vdir);
29633 + return vdir; /* success */
29635 + kfree(vdir->vd_deblk);
29638 + au_cache_free_vdir(vdir);
29640 + vdir = ERR_PTR(err);
29644 +static int reinit_vdir(struct au_vdir *vdir)
29647 + union au_vdir_deblk_p p, deblk_end;
29649 + while (vdir->vd_nblk > 1) {
29650 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
29651 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
29654 + p.deblk = vdir->vd_deblk[0];
29655 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
29656 + err = set_deblk_end(&p, &deblk_end);
29657 + /* keep vd_dblk_sz */
29658 + vdir->vd_last.ul = 0;
29659 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29660 + vdir->vd_version = 0;
29661 + vdir->vd_jiffy = 0;
29666 +/* ---------------------------------------------------------------------- */
29668 +#define AuFillVdir_CALLED 1
29669 +#define AuFillVdir_WHABLE (1 << 1)
29670 +#define AuFillVdir_SHWH (1 << 2)
29671 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
29672 +#define au_fset_fillvdir(flags, name) \
29673 + do { (flags) |= AuFillVdir_##name; } while (0)
29674 +#define au_fclr_fillvdir(flags, name) \
29675 + do { (flags) &= ~AuFillVdir_##name; } while (0)
29677 +#ifndef CONFIG_AUFS_SHWH
29678 +#undef AuFillVdir_SHWH
29679 +#define AuFillVdir_SHWH 0
29682 +struct fillvdir_arg {
29683 + struct dir_context ctx;
29684 + struct file *file;
29685 + struct au_vdir *vdir;
29686 + struct au_nhash delist;
29687 + struct au_nhash whlist;
29688 + aufs_bindex_t bindex;
29689 + unsigned int flags;
29693 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
29694 + loff_t offset __maybe_unused, u64 h_ino,
29695 + unsigned int d_type)
29697 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
29698 + char *name = (void *)__name;
29699 + struct super_block *sb;
29701 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
29704 + sb = arg->file->f_path.dentry->d_sb;
29705 + au_fset_fillvdir(arg->flags, CALLED);
29707 + if (nlen <= AUFS_WH_PFX_LEN
29708 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
29709 + if (test_known(&arg->delist, name, nlen)
29710 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
29711 + goto out; /* already exists or whiteouted */
29713 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
29715 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29716 + d_type = DT_UNKNOWN;
29717 + arg->err = append_de(arg->vdir, name, nlen, ino,
29718 + d_type, &arg->delist);
29720 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
29721 + name += AUFS_WH_PFX_LEN;
29722 + nlen -= AUFS_WH_PFX_LEN;
29723 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
29724 + goto out; /* already whiteouted */
29727 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
29730 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
29731 + d_type = DT_UNKNOWN;
29732 + arg->err = au_nhash_append_wh
29733 + (&arg->whlist, name, nlen, ino, d_type,
29734 + arg->bindex, shwh);
29740 + arg->vdir->vd_jiffy = jiffies;
29742 + AuTraceErr(arg->err);
29746 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
29747 + struct au_nhash *whlist, struct au_nhash *delist)
29749 +#ifdef CONFIG_AUFS_SHWH
29751 + unsigned int nh, u;
29752 + struct hlist_head *head;
29753 + struct au_vdir_wh *pos;
29754 + struct hlist_node *n;
29756 + struct au_vdir_destr *destr;
29758 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
29761 + o = p = (void *)__get_free_page(GFP_NOFS);
29762 + if (unlikely(!p))
29766 + nh = whlist->nh_num;
29767 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29768 + p += AUFS_WH_PFX_LEN;
29769 + for (u = 0; u < nh; u++) {
29770 + head = whlist->nh_head + u;
29771 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
29772 + destr = &pos->wh_str;
29773 + memcpy(p, destr->name, destr->len);
29774 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
29775 + pos->wh_ino, pos->wh_type, delist);
29776 + if (unlikely(err))
29781 + free_page((unsigned long)o);
29791 +static int au_do_read_vdir(struct fillvdir_arg *arg)
29794 + unsigned int rdhash;
29796 + aufs_bindex_t bend, bindex, bstart;
29797 + unsigned char shwh;
29798 + struct file *hf, *file;
29799 + struct super_block *sb;
29801 + file = arg->file;
29802 + sb = file->f_path.dentry->d_sb;
29803 + SiMustAnyLock(sb);
29805 + rdhash = au_sbi(sb)->si_rdhash;
29807 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
29808 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
29809 + if (unlikely(err))
29811 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
29812 + if (unlikely(err))
29818 + if (au_opt_test(au_mntflags(sb), SHWH)) {
29820 + au_fset_fillvdir(arg->flags, SHWH);
29822 + bstart = au_fbstart(file);
29823 + bend = au_fbend_dir(file);
29824 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
29825 + hf = au_hf_dir(file, bindex);
29829 + offset = vfsub_llseek(hf, 0, SEEK_SET);
29831 + if (unlikely(offset))
29834 + arg->bindex = bindex;
29835 + au_fclr_fillvdir(arg->flags, WHABLE);
29837 + || (bindex != bend
29838 + && au_br_whable(au_sbr_perm(sb, bindex))))
29839 + au_fset_fillvdir(arg->flags, WHABLE);
29842 + au_fclr_fillvdir(arg->flags, CALLED);
29844 + err = vfsub_iterate_dir(hf, &arg->ctx);
29847 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
29850 + * dir_relax() may be good for concurrency, but aufs should not
29851 + * use it since it will cause a lockdep problem.
29855 + if (!err && shwh)
29856 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
29858 + au_nhash_wh_free(&arg->whlist);
29861 + au_nhash_de_free(&arg->delist);
29866 +static int read_vdir(struct file *file, int may_read)
29869 + unsigned long expire;
29870 + unsigned char do_read;
29871 + struct fillvdir_arg arg = {
29873 + .actor = fillvdir
29876 + struct inode *inode;
29877 + struct au_vdir *vdir, *allocated;
29880 + inode = file_inode(file);
29881 + IMustLock(inode);
29882 + SiMustAnyLock(inode->i_sb);
29884 + allocated = NULL;
29886 + expire = au_sbi(inode->i_sb)->si_rdcache;
29887 + vdir = au_ivdir(inode);
29890 + vdir = alloc_vdir(file);
29891 + err = PTR_ERR(vdir);
29892 + if (IS_ERR(vdir))
29895 + allocated = vdir;
29896 + } else if (may_read
29897 + && (inode->i_version != vdir->vd_version
29898 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
29900 + err = reinit_vdir(vdir);
29901 + if (unlikely(err))
29906 + return 0; /* success */
29910 + err = au_do_read_vdir(&arg);
29912 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
29913 + vdir->vd_version = inode->i_version;
29914 + vdir->vd_last.ul = 0;
29915 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29917 + au_set_ivdir(inode, allocated);
29918 + } else if (allocated)
29919 + au_vdir_free(allocated);
29925 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
29928 + unsigned long ul, n;
29929 + const unsigned int deblk_sz = src->vd_deblk_sz;
29931 + AuDebugOn(tgt->vd_nblk != 1);
29934 + if (tgt->vd_nblk < src->vd_nblk) {
29935 + unsigned char **p;
29937 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
29939 + if (unlikely(!p))
29941 + tgt->vd_deblk = p;
29944 + if (tgt->vd_deblk_sz != deblk_sz) {
29945 + unsigned char *p;
29947 + tgt->vd_deblk_sz = deblk_sz;
29948 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
29949 + if (unlikely(!p))
29951 + tgt->vd_deblk[0] = p;
29953 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
29954 + tgt->vd_version = src->vd_version;
29955 + tgt->vd_jiffy = src->vd_jiffy;
29957 + n = src->vd_nblk;
29958 + for (ul = 1; ul < n; ul++) {
29959 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
29961 + if (unlikely(!tgt->vd_deblk[ul]))
29965 + tgt->vd_nblk = n;
29966 + tgt->vd_last.ul = tgt->vd_last.ul;
29967 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
29968 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
29969 + - src->vd_deblk[src->vd_last.ul];
29971 + return 0; /* success */
29974 + rerr = reinit_vdir(tgt);
29979 +int au_vdir_init(struct file *file)
29982 + struct inode *inode;
29983 + struct au_vdir *vdir_cache, *allocated;
29985 + /* test file->f_pos here instead of ctx->pos */
29986 + err = read_vdir(file, !file->f_pos);
29987 + if (unlikely(err))
29990 + allocated = NULL;
29991 + vdir_cache = au_fvdir_cache(file);
29992 + if (!vdir_cache) {
29993 + vdir_cache = alloc_vdir(file);
29994 + err = PTR_ERR(vdir_cache);
29995 + if (IS_ERR(vdir_cache))
29997 + allocated = vdir_cache;
29998 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
29999 + /* test file->f_pos here instead of ctx->pos */
30000 + err = reinit_vdir(vdir_cache);
30001 + if (unlikely(err))
30004 + return 0; /* success */
30006 + inode = file_inode(file);
30007 + err = copy_vdir(vdir_cache, au_ivdir(inode));
30009 + file->f_version = inode->i_version;
30011 + au_set_fvdir_cache(file, allocated);
30012 + } else if (allocated)
30013 + au_vdir_free(allocated);
30019 +static loff_t calc_offset(struct au_vdir *vdir)
30022 + union au_vdir_deblk_p p;
30024 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
30025 + offset = vdir->vd_last.p.deblk - p.deblk;
30026 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
30030 +/* returns true or false */
30031 +static int seek_vdir(struct file *file, struct dir_context *ctx)
30034 + unsigned int deblk_sz;
30035 + unsigned long ul, n;
30037 + union au_vdir_deblk_p p, deblk_end;
30038 + struct au_vdir *vdir_cache;
30041 + vdir_cache = au_fvdir_cache(file);
30042 + offset = calc_offset(vdir_cache);
30043 + AuDbg("offset %lld\n", offset);
30044 + if (ctx->pos == offset)
30047 + vdir_cache->vd_last.ul = 0;
30048 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
30053 + deblk_sz = vdir_cache->vd_deblk_sz;
30054 + ul = div64_u64(ctx->pos, deblk_sz);
30055 + AuDbg("ul %lu\n", ul);
30056 + if (ul >= vdir_cache->vd_nblk)
30059 + n = vdir_cache->vd_nblk;
30060 + for (; ul < n; ul++) {
30061 + p.deblk = vdir_cache->vd_deblk[ul];
30062 + deblk_end.deblk = p.deblk + deblk_sz;
30064 + offset *= deblk_sz;
30065 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
30068 + l = calc_size(p.de->de_str.len);
30072 + if (!is_deblk_end(&p, &deblk_end)) {
30074 + vdir_cache->vd_last.ul = ul;
30075 + vdir_cache->vd_last.p = p;
30082 + AuTraceErr(!valid);
30086 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
30088 + unsigned int l, deblk_sz;
30089 + union au_vdir_deblk_p deblk_end;
30090 + struct au_vdir *vdir_cache;
30091 + struct au_vdir_de *de;
30093 + vdir_cache = au_fvdir_cache(file);
30094 + if (!seek_vdir(file, ctx))
30097 + deblk_sz = vdir_cache->vd_deblk_sz;
30099 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30100 + deblk_end.deblk += deblk_sz;
30101 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
30102 + de = vdir_cache->vd_last.p.de;
30103 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
30104 + de->de_str.len, de->de_str.name, ctx->pos,
30105 + (unsigned long)de->de_ino, de->de_type);
30106 + if (unlikely(!dir_emit(ctx, de->de_str.name,
30107 + de->de_str.len, de->de_ino,
30109 + /* todo: ignore the error caused by udba? */
30110 + /* return err; */
30114 + l = calc_size(de->de_str.len);
30115 + vdir_cache->vd_last.p.deblk += l;
30118 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
30119 + vdir_cache->vd_last.ul++;
30120 + vdir_cache->vd_last.p.deblk
30121 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30122 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
30131 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
30132 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
30133 +++ linux/fs/aufs/vfsub.c 2016-02-28 11:26:32.573304539 +0100
30136 + * Copyright (C) 2005-2016 Junjiro R. Okajima
30138 + * This program, aufs is free software; you can redistribute it and/or modify
30139 + * it under the terms of the GNU General Public License as published by
30140 + * the Free Software Foundation; either version 2 of the License, or
30141 + * (at your option) any later version.
30143 + * This program is distributed in the hope that it will be useful,
30144 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30145 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30146 + * GNU General Public License for more details.
30148 + * You should have received a copy of the GNU General Public License
30149 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30153 + * sub-routines for VFS
30156 +#include <linux/namei.h>
30157 +#include <linux/nsproxy.h>
30158 +#include <linux/security.h>
30159 +#include <linux/splice.h>
30160 +#include "../fs/mount.h"
30163 +#ifdef CONFIG_AUFS_BR_FUSE
30164 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
30166 + struct nsproxy *ns;
30168 + if (!au_test_fuse(h_sb) || !au_userns)
30171 + ns = current->nsproxy;
30172 + /* no {get,put}_nsproxy(ns) */
30173 + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES;
30177 +/* ---------------------------------------------------------------------- */
30179 +int vfsub_update_h_iattr(struct path *h_path, int *did)
30183 + struct super_block *h_sb;
30185 + /* for remote fs, leave work for its getattr or d_revalidate */
30186 + /* for bad i_attr fs, handle them in aufs_getattr() */
30187 + /* still some fs may acquire i_mutex. we need to skip them */
30191 + h_sb = h_path->dentry->d_sb;
30192 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
30194 + err = vfs_getattr(h_path, &st);
30199 +/* ---------------------------------------------------------------------- */
30201 +struct file *vfsub_dentry_open(struct path *path, int flags)
30203 + struct file *file;
30205 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
30207 + if (!IS_ERR_OR_NULL(file)
30208 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
30209 + i_readcount_inc(d_inode(path->dentry));
30214 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
30216 + struct file *file;
30219 + file = filp_open(path,
30220 + oflags /* | __FMODE_NONOTIFY */,
30223 + if (IS_ERR(file))
30225 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30232 + * Ideally this function should call VFS:do_last() in order to keep all its
30233 + * checkings. But it is very hard for aufs to regenerate several VFS internal
30234 + * structure such as nameidata. This is a second (or third) best approach.
30235 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
30237 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30238 + struct vfsub_aopen_args *args, struct au_branch *br)
30241 + struct file *file = args->file;
30242 + /* copied from linux/fs/namei.c:atomic_open() */
30243 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
30246 + AuDebugOn(!dir->i_op->atomic_open);
30248 + err = au_br_test_oflag(args->open_flag, br);
30249 + if (unlikely(err))
30252 + args->file->f_path.dentry = DENTRY_NOT_SET;
30253 + args->file->f_path.mnt = au_br_mnt(br);
30254 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
30255 + args->create_mode, args->opened);
30257 + /* some filesystems don't set FILE_CREATED while succeeded? */
30258 + if (*args->opened & FILE_CREATED)
30259 + fsnotify_create(dir, dentry);
30265 + /* todo: call VFS:may_open() here */
30266 + err = open_check_o_direct(file);
30267 + /* todo: ima_file_check() too? */
30268 + if (!err && (args->open_flag & __FMODE_EXEC))
30269 + err = deny_write_access(file);
30270 + if (unlikely(err))
30271 + /* note that the file is created and still opened */
30275 + atomic_inc(&br->br_count);
30276 + fsnotify_open(file);
30282 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30286 + err = kern_path(name, flags, path);
30287 + if (!err && d_is_positive(path->dentry))
30288 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30292 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30295 + struct path path = {
30299 + /* VFS checks it too, but by WARN_ON_ONCE() */
30300 + IMustLock(d_inode(parent));
30302 + path.dentry = lookup_one_len(name, parent, len);
30303 + if (IS_ERR(path.dentry))
30305 + if (d_is_positive(path.dentry))
30306 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30309 + AuTraceErrPtr(path.dentry);
30310 + return path.dentry;
30313 +void vfsub_call_lkup_one(void *args)
30315 + struct vfsub_lkup_one_args *a = args;
30316 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30319 +/* ---------------------------------------------------------------------- */
30321 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30322 + struct dentry *d2, struct au_hinode *hdir2)
30324 + struct dentry *d;
30327 + d = lock_rename(d1, d2);
30329 + au_hn_suspend(hdir1);
30330 + if (hdir1 != hdir2)
30331 + au_hn_suspend(hdir2);
30336 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30337 + struct dentry *d2, struct au_hinode *hdir2)
30339 + au_hn_resume(hdir1);
30340 + if (hdir1 != hdir2)
30341 + au_hn_resume(hdir2);
30343 + unlock_rename(d1, d2);
30347 +/* ---------------------------------------------------------------------- */
30349 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30352 + struct dentry *d;
30356 + d = path->dentry;
30357 + path->dentry = d->d_parent;
30358 + err = security_path_mknod(path, d, mode, 0);
30359 + path->dentry = d;
30360 + if (unlikely(err))
30364 + err = vfs_create(dir, path->dentry, mode, want_excl);
30367 + struct path tmp = *path;
30370 + vfsub_update_h_iattr(&tmp, &did);
30372 + tmp.dentry = path->dentry->d_parent;
30373 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30382 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30385 + struct dentry *d;
30389 + d = path->dentry;
30390 + path->dentry = d->d_parent;
30391 + err = security_path_symlink(path, d, symname);
30392 + path->dentry = d;
30393 + if (unlikely(err))
30397 + err = vfs_symlink(dir, path->dentry, symname);
30400 + struct path tmp = *path;
30403 + vfsub_update_h_iattr(&tmp, &did);
30405 + tmp.dentry = path->dentry->d_parent;
30406 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30415 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30418 + struct dentry *d;
30422 + d = path->dentry;
30423 + path->dentry = d->d_parent;
30424 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30425 + path->dentry = d;
30426 + if (unlikely(err))
30430 + err = vfs_mknod(dir, path->dentry, mode, dev);
30433 + struct path tmp = *path;
30436 + vfsub_update_h_iattr(&tmp, &did);
30438 + tmp.dentry = path->dentry->d_parent;
30439 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30448 +static int au_test_nlink(struct inode *inode)
30450 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30452 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30453 + || inode->i_nlink < link_max)
30458 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30459 + struct inode **delegated_inode)
30462 + struct dentry *d;
30466 + err = au_test_nlink(d_inode(src_dentry));
30467 + if (unlikely(err))
30470 + /* we don't call may_linkat() */
30471 + d = path->dentry;
30472 + path->dentry = d->d_parent;
30473 + err = security_path_link(src_dentry, path, d);
30474 + path->dentry = d;
30475 + if (unlikely(err))
30479 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30482 + struct path tmp = *path;
30485 + /* fuse has different memory inode for the same inumber */
30486 + vfsub_update_h_iattr(&tmp, &did);
30488 + tmp.dentry = path->dentry->d_parent;
30489 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30490 + tmp.dentry = src_dentry;
30491 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30500 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30501 + struct inode *dir, struct path *path,
30502 + struct inode **delegated_inode)
30505 + struct path tmp = {
30508 + struct dentry *d;
30511 + IMustLock(src_dir);
30513 + d = path->dentry;
30514 + path->dentry = d->d_parent;
30515 + tmp.dentry = src_dentry->d_parent;
30516 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30517 + path->dentry = d;
30518 + if (unlikely(err))
30522 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30523 + delegated_inode, /*flags*/0);
30528 + tmp.dentry = d->d_parent;
30529 + vfsub_update_h_iattr(&tmp, &did);
30531 + tmp.dentry = src_dentry;
30532 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30533 + tmp.dentry = src_dentry->d_parent;
30534 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30543 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
30546 + struct dentry *d;
30550 + d = path->dentry;
30551 + path->dentry = d->d_parent;
30552 + err = security_path_mkdir(path, d, mode);
30553 + path->dentry = d;
30554 + if (unlikely(err))
30558 + err = vfs_mkdir(dir, path->dentry, mode);
30561 + struct path tmp = *path;
30564 + vfsub_update_h_iattr(&tmp, &did);
30566 + tmp.dentry = path->dentry->d_parent;
30567 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30576 +int vfsub_rmdir(struct inode *dir, struct path *path)
30579 + struct dentry *d;
30583 + d = path->dentry;
30584 + path->dentry = d->d_parent;
30585 + err = security_path_rmdir(path, d);
30586 + path->dentry = d;
30587 + if (unlikely(err))
30591 + err = vfs_rmdir(dir, path->dentry);
30594 + struct path tmp = {
30595 + .dentry = path->dentry->d_parent,
30599 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30606 +/* ---------------------------------------------------------------------- */
30608 +/* todo: support mmap_sem? */
30609 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30615 + err = vfs_read(file, ubuf, count, ppos);
30618 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30622 +/* todo: kernel_read()? */
30623 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30627 + mm_segment_t oldfs;
30634 + oldfs = get_fs();
30635 + set_fs(KERNEL_DS);
30636 + err = vfsub_read_u(file, buf.u, count, ppos);
30641 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30647 + err = vfs_write(file, ubuf, count, ppos);
30650 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30654 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
30657 + mm_segment_t oldfs;
30660 + const char __user *u;
30664 + oldfs = get_fs();
30665 + set_fs(KERNEL_DS);
30666 + err = vfsub_write_u(file, buf.u, count, ppos);
30671 +int vfsub_flush(struct file *file, fl_owner_t id)
30676 + if (file->f_op->flush) {
30677 + if (!au_test_nfs(file->f_path.dentry->d_sb))
30678 + err = file->f_op->flush(file, id);
30681 + err = file->f_op->flush(file, id);
30685 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
30691 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
30695 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
30698 + err = iterate_dir(file, ctx);
30701 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30705 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30706 + struct pipe_inode_info *pipe, size_t len,
30707 + unsigned int flags)
30712 + err = do_splice_to(in, ppos, pipe, len, flags);
30714 + file_accessed(in);
30716 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
30720 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30721 + loff_t *ppos, size_t len, unsigned int flags)
30726 + err = do_splice_from(pipe, out, ppos, len, flags);
30729 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
30733 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
30737 + /* file can be NULL */
30739 + err = vfs_fsync(file, datasync);
30743 + AuDebugOn(!file);
30744 + path = &file->f_path;
30746 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30751 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
30752 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30753 + struct file *h_file)
30756 + struct inode *h_inode;
30757 + struct super_block *h_sb;
30760 + err = vfsub_truncate(h_path, length);
30764 + h_inode = d_inode(h_path->dentry);
30765 + h_sb = h_inode->i_sb;
30767 + sb_start_write(h_sb);
30769 + err = locks_verify_truncate(h_inode, h_file, length);
30771 + err = security_path_truncate(h_path);
30774 + err = do_truncate(h_path->dentry, length, attr, h_file);
30778 + sb_end_write(h_sb);
30785 +/* ---------------------------------------------------------------------- */
30787 +struct au_vfsub_mkdir_args {
30789 + struct inode *dir;
30790 + struct path *path;
30794 +static void au_call_vfsub_mkdir(void *args)
30796 + struct au_vfsub_mkdir_args *a = args;
30797 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
30800 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
30802 + int err, do_sio, wkq_err;
30804 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30807 + err = vfsub_mkdir(dir, path, mode);
30810 + struct au_vfsub_mkdir_args args = {
30816 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
30817 + if (unlikely(wkq_err))
30824 +struct au_vfsub_rmdir_args {
30826 + struct inode *dir;
30827 + struct path *path;
30830 +static void au_call_vfsub_rmdir(void *args)
30832 + struct au_vfsub_rmdir_args *a = args;
30833 + *a->errp = vfsub_rmdir(a->dir, a->path);
30836 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
30838 + int err, do_sio, wkq_err;
30840 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30843 + err = vfsub_rmdir(dir, path);
30846 + struct au_vfsub_rmdir_args args = {
30851 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
30852 + if (unlikely(wkq_err))
30859 +/* ---------------------------------------------------------------------- */
30861 +struct notify_change_args {
30863 + struct path *path;
30864 + struct iattr *ia;
30865 + struct inode **delegated_inode;
30868 +static void call_notify_change(void *args)
30870 + struct notify_change_args *a = args;
30871 + struct inode *h_inode;
30873 + h_inode = d_inode(a->path->dentry);
30874 + IMustLock(h_inode);
30876 + *a->errp = -EPERM;
30877 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
30879 + *a->errp = notify_change(a->path->dentry, a->ia,
30880 + a->delegated_inode);
30883 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
30885 + AuTraceErr(*a->errp);
30888 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30889 + struct inode **delegated_inode)
30892 + struct notify_change_args args = {
30896 + .delegated_inode = delegated_inode
30899 + call_notify_change(&args);
30904 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30905 + struct inode **delegated_inode)
30907 + int err, wkq_err;
30908 + struct notify_change_args args = {
30912 + .delegated_inode = delegated_inode
30915 + wkq_err = au_wkq_wait(call_notify_change, &args);
30916 + if (unlikely(wkq_err))
30922 +/* ---------------------------------------------------------------------- */
30924 +struct unlink_args {
30926 + struct inode *dir;
30927 + struct path *path;
30928 + struct inode **delegated_inode;
30931 +static void call_unlink(void *args)
30933 + struct unlink_args *a = args;
30934 + struct dentry *d = a->path->dentry;
30935 + struct inode *h_inode;
30936 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
30937 + && au_dcount(d) == 1);
30939 + IMustLock(a->dir);
30941 + a->path->dentry = d->d_parent;
30942 + *a->errp = security_path_unlink(a->path, d);
30943 + a->path->dentry = d;
30944 + if (unlikely(*a->errp))
30947 + if (!stop_sillyrename)
30950 + if (d_is_positive(d)) {
30951 + h_inode = d_inode(d);
30956 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
30959 + struct path tmp = {
30960 + .dentry = d->d_parent,
30961 + .mnt = a->path->mnt
30963 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30966 + if (!stop_sillyrename)
30971 + AuTraceErr(*a->errp);
30975 + * @dir: must be locked.
30976 + * @dentry: target dentry.
30978 +int vfsub_unlink(struct inode *dir, struct path *path,
30979 + struct inode **delegated_inode, int force)
30982 + struct unlink_args args = {
30986 + .delegated_inode = delegated_inode
30990 + call_unlink(&args);
30994 + wkq_err = au_wkq_wait(call_unlink, &args);
30995 + if (unlikely(wkq_err))
31001 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
31002 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
31003 +++ linux/fs/aufs/vfsub.h 2016-02-28 11:26:32.576637942 +0100
31006 + * Copyright (C) 2005-2016 Junjiro R. Okajima
31008 + * This program, aufs is free software; you can redistribute it and/or modify
31009 + * it under the terms of the GNU General Public License as published by
31010 + * the Free Software Foundation; either version 2 of the License, or
31011 + * (at your option) any later version.
31013 + * This program is distributed in the hope that it will be useful,
31014 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31015 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31016 + * GNU General Public License for more details.
31018 + * You should have received a copy of the GNU General Public License
31019 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31023 + * sub-routines for VFS
31026 +#ifndef __AUFS_VFSUB_H__
31027 +#define __AUFS_VFSUB_H__
31031 +#include <linux/fs.h>
31032 +#include <linux/mount.h>
31033 +#include <linux/posix_acl.h>
31034 +#include <linux/xattr.h>
31035 +#include "debug.h"
31037 +/* copied from linux/fs/internal.h */
31038 +/* todo: BAD approach!! */
31039 +extern void __mnt_drop_write(struct vfsmount *);
31040 +extern int open_check_o_direct(struct file *f);
31042 +/* ---------------------------------------------------------------------- */
31044 +/* lock subclass for lower inode */
31045 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
31046 +/* reduce? gave up. */
31048 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
31049 + AuLsc_I_PARENT, /* lower inode, parent first */
31050 + AuLsc_I_PARENT2, /* copyup dirs */
31051 + AuLsc_I_PARENT3, /* copyup wh */
31057 +/* to debug easier, do not make them inlined functions */
31058 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
31059 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
31061 +/* ---------------------------------------------------------------------- */
31063 +static inline void vfsub_drop_nlink(struct inode *inode)
31065 + AuDebugOn(!inode->i_nlink);
31066 + drop_nlink(inode);
31069 +static inline void vfsub_dead_dir(struct inode *inode)
31071 + AuDebugOn(!S_ISDIR(inode->i_mode));
31072 + inode->i_flags |= S_DEAD;
31073 + clear_nlink(inode);
31076 +static inline int vfsub_native_ro(struct inode *inode)
31078 + return (inode->i_sb->s_flags & MS_RDONLY)
31079 + || IS_RDONLY(inode)
31080 + /* || IS_APPEND(inode) */
31081 + || IS_IMMUTABLE(inode);
31084 +#ifdef CONFIG_AUFS_BR_FUSE
31085 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
31087 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
31090 +/* ---------------------------------------------------------------------- */
31092 +int vfsub_update_h_iattr(struct path *h_path, int *did);
31093 +struct file *vfsub_dentry_open(struct path *path, int flags);
31094 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
31095 +struct vfsub_aopen_args {
31096 + struct file *file;
31097 + unsigned int open_flag;
31098 + umode_t create_mode;
31102 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
31103 + struct vfsub_aopen_args *args, struct au_branch *br);
31104 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
31106 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
31109 +struct vfsub_lkup_one_args {
31110 + struct dentry **errp;
31111 + struct qstr *name;
31112 + struct dentry *parent;
31115 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
31116 + struct dentry *parent)
31118 + return vfsub_lookup_one_len(name->name, parent, name->len);
31121 +void vfsub_call_lkup_one(void *args);
31123 +/* ---------------------------------------------------------------------- */
31125 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
31130 + err = mnt_want_write(mnt);
31135 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
31138 + mnt_drop_write(mnt);
31142 +#if 0 /* reserved */
31143 +static inline void vfsub_mnt_drop_write_file(struct file *file)
31146 + mnt_drop_write_file(file);
31151 +/* ---------------------------------------------------------------------- */
31154 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
31155 + struct dentry *d2, struct au_hinode *hdir2);
31156 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
31157 + struct dentry *d2, struct au_hinode *hdir2);
31159 +int vfsub_create(struct inode *dir, struct path *path, int mode,
31161 +int vfsub_symlink(struct inode *dir, struct path *path,
31162 + const char *symname);
31163 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
31164 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
31165 + struct path *path, struct inode **delegated_inode);
31166 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
31167 + struct inode *hdir, struct path *path,
31168 + struct inode **delegated_inode);
31169 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
31170 +int vfsub_rmdir(struct inode *dir, struct path *path);
31172 +/* ---------------------------------------------------------------------- */
31174 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31176 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31178 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31180 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
31182 +int vfsub_flush(struct file *file, fl_owner_t id);
31183 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
31185 +static inline loff_t vfsub_f_size_read(struct file *file)
31187 + return i_size_read(file_inode(file));
31190 +static inline unsigned int vfsub_file_flags(struct file *file)
31192 + unsigned int flags;
31194 + spin_lock(&file->f_lock);
31195 + flags = file->f_flags;
31196 + spin_unlock(&file->f_lock);
31201 +#if 0 /* reserved */
31202 +static inline void vfsub_file_accessed(struct file *h_file)
31204 + file_accessed(h_file);
31205 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
31209 +#if 0 /* reserved */
31210 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
31211 + struct dentry *h_dentry)
31213 + struct path h_path = {
31214 + .dentry = h_dentry,
31217 + touch_atime(&h_path);
31218 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
31222 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
31225 + return generic_update_time(h_inode, ts, flags);
31226 + /* no vfsub_update_h_iattr() since we don't have struct path */
31229 +#ifdef CONFIG_FS_POSIX_ACL
31230 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
31234 + err = posix_acl_chmod(h_inode, h_mode);
31235 + if (err == -EOPNOTSUPP)
31240 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
31243 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31244 + struct pipe_inode_info *pipe, size_t len,
31245 + unsigned int flags);
31246 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31247 + loff_t *ppos, size_t len, unsigned int flags);
31249 +static inline long vfsub_truncate(struct path *path, loff_t length)
31254 + err = vfs_truncate(path, length);
31259 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31260 + struct file *h_file);
31261 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
31263 +/* ---------------------------------------------------------------------- */
31265 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
31270 + err = vfs_llseek(file, offset, origin);
31275 +/* ---------------------------------------------------------------------- */
31277 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
31278 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
31279 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31280 + struct inode **delegated_inode);
31281 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31282 + struct inode **delegated_inode);
31283 +int vfsub_unlink(struct inode *dir, struct path *path,
31284 + struct inode **delegated_inode, int force);
31286 +/* ---------------------------------------------------------------------- */
31288 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
31289 + const void *value, size_t size, int flags)
31294 + err = vfs_setxattr(dentry, name, value, size, flags);
31300 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31305 + err = vfs_removexattr(dentry, name);
31311 +#endif /* __KERNEL__ */
31312 +#endif /* __AUFS_VFSUB_H__ */
31313 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31314 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31315 +++ linux/fs/aufs/wbr_policy.c 2016-02-28 11:26:32.576637942 +0100
31318 + * Copyright (C) 2005-2016 Junjiro R. Okajima
31320 + * This program, aufs is free software; you can redistribute it and/or modify
31321 + * it under the terms of the GNU General Public License as published by
31322 + * the Free Software Foundation; either version 2 of the License, or
31323 + * (at your option) any later version.
31325 + * This program is distributed in the hope that it will be useful,
31326 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31327 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31328 + * GNU General Public License for more details.
31330 + * You should have received a copy of the GNU General Public License
31331 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31335 + * policies for selecting one among multiple writable branches
31338 +#include <linux/statfs.h>
31341 +/* subset of cpup_attr() */
31342 +static noinline_for_stack
31343 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31347 + struct inode *h_isrc;
31349 + h_isrc = d_inode(h_src);
31350 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31351 + ia.ia_mode = h_isrc->i_mode;
31352 + ia.ia_uid = h_isrc->i_uid;
31353 + ia.ia_gid = h_isrc->i_gid;
31354 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31355 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31356 + /* no delegation since it is just created */
31357 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31359 + /* is this nfs only? */
31360 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31361 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31362 + ia.ia_mode = h_isrc->i_mode;
31363 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31369 +#define AuCpdown_PARENT_OPQ 1
31370 +#define AuCpdown_WHED (1 << 1)
31371 +#define AuCpdown_MADE_DIR (1 << 2)
31372 +#define AuCpdown_DIROPQ (1 << 3)
31373 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31374 +#define au_fset_cpdown(flags, name) \
31375 + do { (flags) |= AuCpdown_##name; } while (0)
31376 +#define au_fclr_cpdown(flags, name) \
31377 + do { (flags) &= ~AuCpdown_##name; } while (0)
31379 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31380 + unsigned int *flags)
31383 + struct dentry *opq_dentry;
31385 + opq_dentry = au_diropq_create(dentry, bdst);
31386 + err = PTR_ERR(opq_dentry);
31387 + if (IS_ERR(opq_dentry))
31389 + dput(opq_dentry);
31390 + au_fset_cpdown(*flags, DIROPQ);
31396 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31397 + struct inode *dir, aufs_bindex_t bdst)
31400 + struct path h_path;
31401 + struct au_branch *br;
31403 + br = au_sbr(dentry->d_sb, bdst);
31404 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31405 + err = PTR_ERR(h_path.dentry);
31406 + if (IS_ERR(h_path.dentry))
31410 + if (d_is_positive(h_path.dentry)) {
31411 + h_path.mnt = au_br_mnt(br);
31412 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31415 + dput(h_path.dentry);
31421 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31422 + struct au_pin *pin,
31423 + struct dentry *h_parent, void *arg)
31426 + aufs_bindex_t bopq, bstart;
31427 + struct path h_path;
31428 + struct dentry *parent;
31429 + struct inode *h_dir, *h_inode, *inode, *dir;
31430 + unsigned int *flags = arg;
31432 + bstart = au_dbstart(dentry);
31433 + /* dentry is di-locked */
31434 + parent = dget_parent(dentry);
31435 + dir = d_inode(parent);
31436 + h_dir = d_inode(h_parent);
31437 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31438 + IMustLock(h_dir);
31440 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31441 + if (unlikely(err < 0))
31443 + h_path.dentry = au_h_dptr(dentry, bdst);
31444 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31445 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31446 + S_IRWXU | S_IRUGO | S_IXUGO);
31447 + if (unlikely(err))
31449 + au_fset_cpdown(*flags, MADE_DIR);
31451 + bopq = au_dbdiropq(dentry);
31452 + au_fclr_cpdown(*flags, WHED);
31453 + au_fclr_cpdown(*flags, DIROPQ);
31454 + if (au_dbwh(dentry) == bdst)
31455 + au_fset_cpdown(*flags, WHED);
31456 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31457 + au_fset_cpdown(*flags, PARENT_OPQ);
31458 + h_inode = d_inode(h_path.dentry);
31459 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
31460 + if (au_ftest_cpdown(*flags, WHED)) {
31461 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31462 + if (unlikely(err)) {
31463 + mutex_unlock(&h_inode->i_mutex);
31468 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
31469 + mutex_unlock(&h_inode->i_mutex);
31470 + if (unlikely(err))
31473 + if (au_ftest_cpdown(*flags, WHED)) {
31474 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
31475 + if (unlikely(err))
31479 + inode = d_inode(dentry);
31480 + if (au_ibend(inode) < bdst)
31481 + au_set_ibend(inode, bdst);
31482 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
31483 + au_hi_flags(inode, /*isdir*/1));
31484 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
31485 + goto out; /* success */
31489 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31490 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
31491 + rerr = au_diropq_remove(dentry, bdst);
31492 + mutex_unlock(&h_inode->i_mutex);
31493 + if (unlikely(rerr)) {
31494 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
31495 + dentry, bdst, rerr);
31501 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
31502 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
31503 + if (unlikely(rerr)) {
31504 + AuIOErr("failed removing %pd b%d (%d)\n",
31505 + dentry, bdst, rerr);
31510 + au_set_h_dptr(dentry, bdst, NULL);
31511 + if (au_dbend(dentry) == bdst)
31512 + au_update_dbend(dentry);
31518 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
31521 + unsigned int flags;
31524 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
31529 +/* ---------------------------------------------------------------------- */
31531 +/* policies for create */
31533 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
31535 + int err, i, j, ndentry;
31536 + aufs_bindex_t bopq;
31537 + struct au_dcsub_pages dpages;
31538 + struct au_dpage *dpage;
31539 + struct dentry **dentries, *parent, *d;
31541 + err = au_dpages_init(&dpages, GFP_NOFS);
31542 + if (unlikely(err))
31544 + parent = dget_parent(dentry);
31545 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
31546 + if (unlikely(err))
31550 + for (i = 0; i < dpages.ndpage; i++) {
31551 + dpage = dpages.dpages + i;
31552 + dentries = dpage->dentries;
31553 + ndentry = dpage->ndentry;
31554 + for (j = 0; j < ndentry; j++) {
31556 + di_read_lock_parent2(d, !AuLock_IR);
31557 + bopq = au_dbdiropq(d);
31558 + di_read_unlock(d, !AuLock_IR);
31559 + if (bopq >= 0 && bopq < err)
31566 + au_dpages_free(&dpages);
31571 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
31573 + for (; bindex >= 0; bindex--)
31574 + if (!au_br_rdonly(au_sbr(sb, bindex)))
31579 +/* top down parent */
31580 +static int au_wbr_create_tdp(struct dentry *dentry,
31581 + unsigned int flags __maybe_unused)
31584 + aufs_bindex_t bstart, bindex;
31585 + struct super_block *sb;
31586 + struct dentry *parent, *h_parent;
31588 + sb = dentry->d_sb;
31589 + bstart = au_dbstart(dentry);
31591 + if (!au_br_rdonly(au_sbr(sb, bstart)))
31595 + parent = dget_parent(dentry);
31596 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
31597 + h_parent = au_h_dptr(parent, bindex);
31598 + if (!h_parent || d_is_negative(h_parent))
31601 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31608 + /* bottom up here */
31609 + if (unlikely(err < 0)) {
31610 + err = au_wbr_bu(sb, bstart - 1);
31612 + err = au_wbr_nonopq(dentry, err);
31616 + AuDbg("b%d\n", err);
31620 +/* ---------------------------------------------------------------------- */
31622 +/* an exception for the policy other than tdp */
31623 +static int au_wbr_create_exp(struct dentry *dentry)
31626 + aufs_bindex_t bwh, bdiropq;
31627 + struct dentry *parent;
31630 + bwh = au_dbwh(dentry);
31631 + parent = dget_parent(dentry);
31632 + bdiropq = au_dbdiropq(parent);
31634 + if (bdiropq >= 0)
31635 + err = min(bdiropq, bwh);
31638 + AuDbg("%d\n", err);
31639 + } else if (bdiropq >= 0) {
31641 + AuDbg("%d\n", err);
31646 + err = au_wbr_nonopq(dentry, err);
31648 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
31651 + AuDbg("%d\n", err);
31655 +/* ---------------------------------------------------------------------- */
31658 +static int au_wbr_create_init_rr(struct super_block *sb)
31662 + err = au_wbr_bu(sb, au_sbend(sb));
31663 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
31666 + AuDbg("b%d\n", err);
31670 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
31674 + aufs_bindex_t bindex, bend;
31675 + struct super_block *sb;
31678 + err = au_wbr_create_exp(dentry);
31682 + sb = dentry->d_sb;
31683 + next = &au_sbi(sb)->si_wbr_rr_next;
31684 + bend = au_sbend(sb);
31686 + for (bindex = 0; bindex <= bend; bindex++) {
31687 + if (!au_ftest_wbr(flags, DIR)) {
31688 + err = atomic_dec_return(next) + 1;
31689 + /* modulo for 0 is meaningless */
31690 + if (unlikely(!err))
31691 + err = atomic_dec_return(next) + 1;
31693 + err = atomic_read(next);
31694 + AuDbg("%d\n", err);
31697 + AuDbg("%d\n", err);
31698 + if (!au_br_rdonly(au_sbr(sb, err)))
31704 + err = au_wbr_nonopq(dentry, err);
31707 + AuDbg("%d\n", err);
31711 +/* ---------------------------------------------------------------------- */
31713 +/* most free space */
31714 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
31716 + struct super_block *sb;
31717 + struct au_branch *br;
31718 + struct au_wbr_mfs *mfs;
31719 + struct dentry *h_parent;
31720 + aufs_bindex_t bindex, bend;
31722 + unsigned long long b, bavail;
31723 + struct path h_path;
31724 + /* reduce the stack usage */
31725 + struct kstatfs *st;
31727 + st = kmalloc(sizeof(*st), GFP_NOFS);
31728 + if (unlikely(!st)) {
31729 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
31734 + sb = dentry->d_sb;
31735 + mfs = &au_sbi(sb)->si_wbr_mfs;
31736 + MtxMustLock(&mfs->mfs_lock);
31737 + mfs->mfs_bindex = -EROFS;
31738 + mfs->mfsrr_bytes = 0;
31741 + bend = au_sbend(sb);
31743 + bindex = au_dbstart(parent);
31744 + bend = au_dbtaildir(parent);
31747 + for (; bindex <= bend; bindex++) {
31749 + h_parent = au_h_dptr(parent, bindex);
31750 + if (!h_parent || d_is_negative(h_parent))
31753 + br = au_sbr(sb, bindex);
31754 + if (au_br_rdonly(br))
31757 + /* sb->s_root for NFS is unreliable */
31758 + h_path.mnt = au_br_mnt(br);
31759 + h_path.dentry = h_path.mnt->mnt_root;
31760 + err = vfs_statfs(&h_path, st);
31761 + if (unlikely(err)) {
31762 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
31766 + /* when the available size is equal, select the lower one */
31767 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
31768 + || sizeof(b) < sizeof(st->f_bsize));
31769 + b = st->f_bavail * st->f_bsize;
31770 + br->br_wbr->wbr_bytes = b;
31771 + if (b >= bavail) {
31773 + mfs->mfs_bindex = bindex;
31774 + mfs->mfs_jiffy = jiffies;
31778 + mfs->mfsrr_bytes = bavail;
31779 + AuDbg("b%d\n", mfs->mfs_bindex);
31783 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
31786 + struct dentry *parent;
31787 + struct super_block *sb;
31788 + struct au_wbr_mfs *mfs;
31790 + err = au_wbr_create_exp(dentry);
31794 + sb = dentry->d_sb;
31796 + if (au_ftest_wbr(flags, PARENT))
31797 + parent = dget_parent(dentry);
31798 + mfs = &au_sbi(sb)->si_wbr_mfs;
31799 + mutex_lock(&mfs->mfs_lock);
31800 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
31801 + || mfs->mfs_bindex < 0
31802 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
31803 + au_mfs(dentry, parent);
31804 + mutex_unlock(&mfs->mfs_lock);
31805 + err = mfs->mfs_bindex;
31809 + err = au_wbr_nonopq(dentry, err);
31812 + AuDbg("b%d\n", err);
31816 +static int au_wbr_create_init_mfs(struct super_block *sb)
31818 + struct au_wbr_mfs *mfs;
31820 + mfs = &au_sbi(sb)->si_wbr_mfs;
31821 + mutex_init(&mfs->mfs_lock);
31822 + mfs->mfs_jiffy = 0;
31823 + mfs->mfs_bindex = -EROFS;
31828 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
31830 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
31834 +/* ---------------------------------------------------------------------- */
31836 +/* most free space and then round robin */
31837 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
31840 + struct au_wbr_mfs *mfs;
31842 + err = au_wbr_create_mfs(dentry, flags);
31844 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
31845 + mutex_lock(&mfs->mfs_lock);
31846 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
31847 + err = au_wbr_create_rr(dentry, flags);
31848 + mutex_unlock(&mfs->mfs_lock);
31851 + AuDbg("b%d\n", err);
31855 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
31859 + au_wbr_create_init_mfs(sb); /* ignore */
31860 + err = au_wbr_create_init_rr(sb);
31865 +/* ---------------------------------------------------------------------- */
31867 +/* top down parent and most free space */
31868 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
31871 + unsigned long long b;
31872 + aufs_bindex_t bindex, bstart, bend;
31873 + struct super_block *sb;
31874 + struct dentry *parent, *h_parent;
31875 + struct au_branch *br;
31877 + err = au_wbr_create_tdp(dentry, flags);
31878 + if (unlikely(err < 0))
31880 + parent = dget_parent(dentry);
31881 + bstart = au_dbstart(parent);
31882 + bend = au_dbtaildir(parent);
31883 + if (bstart == bend)
31884 + goto out_parent; /* success */
31886 + e2 = au_wbr_create_mfs(dentry, flags);
31888 + goto out_parent; /* success */
31890 + /* when the available size is equal, select upper one */
31891 + sb = dentry->d_sb;
31892 + br = au_sbr(sb, err);
31893 + b = br->br_wbr->wbr_bytes;
31894 + AuDbg("b%d, %llu\n", err, b);
31896 + for (bindex = bstart; bindex <= bend; bindex++) {
31897 + h_parent = au_h_dptr(parent, bindex);
31898 + if (!h_parent || d_is_negative(h_parent))
31901 + br = au_sbr(sb, bindex);
31902 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
31903 + b = br->br_wbr->wbr_bytes;
31905 + AuDbg("b%d, %llu\n", err, b);
31910 + err = au_wbr_nonopq(dentry, err);
31915 + AuDbg("b%d\n", err);
31919 +/* ---------------------------------------------------------------------- */
31922 + * - top down parent
31923 + * - most free space with parent
31924 + * - most free space round-robin regardless parent
31926 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
31929 + unsigned long long watermark;
31930 + struct super_block *sb;
31931 + struct au_branch *br;
31932 + struct au_wbr_mfs *mfs;
31934 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
31935 + if (unlikely(err < 0))
31938 + sb = dentry->d_sb;
31939 + br = au_sbr(sb, err);
31940 + mfs = &au_sbi(sb)->si_wbr_mfs;
31941 + mutex_lock(&mfs->mfs_lock);
31942 + watermark = mfs->mfsrr_watermark;
31943 + mutex_unlock(&mfs->mfs_lock);
31944 + if (br->br_wbr->wbr_bytes < watermark)
31945 + /* regardless the parent dir */
31946 + err = au_wbr_create_mfsrr(dentry, flags);
31949 + AuDbg("b%d\n", err);
31953 +/* ---------------------------------------------------------------------- */
31955 +/* policies for copyup */
31957 +/* top down parent */
31958 +static int au_wbr_copyup_tdp(struct dentry *dentry)
31960 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
31963 +/* bottom up parent */
31964 +static int au_wbr_copyup_bup(struct dentry *dentry)
31967 + aufs_bindex_t bindex, bstart;
31968 + struct dentry *parent, *h_parent;
31969 + struct super_block *sb;
31972 + sb = dentry->d_sb;
31973 + parent = dget_parent(dentry);
31974 + bstart = au_dbstart(parent);
31975 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
31976 + h_parent = au_h_dptr(parent, bindex);
31977 + if (!h_parent || d_is_negative(h_parent))
31980 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31987 + /* bottom up here */
31988 + if (unlikely(err < 0))
31989 + err = au_wbr_bu(sb, bstart - 1);
31991 + AuDbg("b%d\n", err);
31996 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
32000 + err = au_wbr_bu(dentry->d_sb, bstart);
32001 + AuDbg("b%d\n", err);
32002 + if (err > bstart)
32003 + err = au_wbr_nonopq(dentry, err);
32005 + AuDbg("b%d\n", err);
32009 +static int au_wbr_copyup_bu(struct dentry *dentry)
32012 + aufs_bindex_t bstart;
32014 + bstart = au_dbstart(dentry);
32015 + err = au_wbr_do_copyup_bu(dentry, bstart);
32019 +/* ---------------------------------------------------------------------- */
32021 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
32022 + [AuWbrCopyup_TDP] = {
32023 + .copyup = au_wbr_copyup_tdp
32025 + [AuWbrCopyup_BUP] = {
32026 + .copyup = au_wbr_copyup_bup
32028 + [AuWbrCopyup_BU] = {
32029 + .copyup = au_wbr_copyup_bu
32033 +struct au_wbr_create_operations au_wbr_create_ops[] = {
32034 + [AuWbrCreate_TDP] = {
32035 + .create = au_wbr_create_tdp
32037 + [AuWbrCreate_RR] = {
32038 + .create = au_wbr_create_rr,
32039 + .init = au_wbr_create_init_rr
32041 + [AuWbrCreate_MFS] = {
32042 + .create = au_wbr_create_mfs,
32043 + .init = au_wbr_create_init_mfs,
32044 + .fin = au_wbr_create_fin_mfs
32046 + [AuWbrCreate_MFSV] = {
32047 + .create = au_wbr_create_mfs,
32048 + .init = au_wbr_create_init_mfs,
32049 + .fin = au_wbr_create_fin_mfs
32051 + [AuWbrCreate_MFSRR] = {
32052 + .create = au_wbr_create_mfsrr,
32053 + .init = au_wbr_create_init_mfsrr,
32054 + .fin = au_wbr_create_fin_mfs
32056 + [AuWbrCreate_MFSRRV] = {
32057 + .create = au_wbr_create_mfsrr,
32058 + .init = au_wbr_create_init_mfsrr,
32059 + .fin = au_wbr_create_fin_mfs
32061 + [AuWbrCreate_PMFS] = {
32062 + .create = au_wbr_create_pmfs,
32063 + .init = au_wbr_create_init_mfs,
32064 + .fin = au_wbr_create_fin_mfs
32066 + [AuWbrCreate_PMFSV] = {
32067 + .create = au_wbr_create_pmfs,
32068 + .init = au_wbr_create_init_mfs,
32069 + .fin = au_wbr_create_fin_mfs
32071 + [AuWbrCreate_PMFSRR] = {
32072 + .create = au_wbr_create_pmfsrr,
32073 + .init = au_wbr_create_init_mfsrr,
32074 + .fin = au_wbr_create_fin_mfs
32076 + [AuWbrCreate_PMFSRRV] = {
32077 + .create = au_wbr_create_pmfsrr,
32078 + .init = au_wbr_create_init_mfsrr,
32079 + .fin = au_wbr_create_fin_mfs
32082 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
32083 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
32084 +++ linux/fs/aufs/whout.c 2016-02-28 11:26:32.576637942 +0100
32087 + * Copyright (C) 2005-2016 Junjiro R. Okajima
32089 + * This program, aufs is free software; you can redistribute it and/or modify
32090 + * it under the terms of the GNU General Public License as published by
32091 + * the Free Software Foundation; either version 2 of the License, or
32092 + * (at your option) any later version.
32094 + * This program is distributed in the hope that it will be useful,
32095 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32096 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32097 + * GNU General Public License for more details.
32099 + * You should have received a copy of the GNU General Public License
32100 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32104 + * whiteout for logical deletion and opaque directory
32109 +#define WH_MASK S_IRUGO
32112 + * If a directory contains this file, then it is opaque. We start with the
32113 + * .wh. flag so that it is blocked by lookup.
32115 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
32116 + sizeof(AUFS_WH_DIROPQ) - 1);
32119 + * generate whiteout name, which is NOT terminated by NULL.
32120 + * @name: original d_name.name
32121 + * @len: original d_name.len
32122 + * @wh: whiteout qstr
32123 + * returns zero when succeeds, otherwise error.
32124 + * succeeded value as wh->name should be freed by kfree().
32126 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
32130 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
32131 + return -ENAMETOOLONG;
32133 + wh->len = name->len + AUFS_WH_PFX_LEN;
32134 + p = kmalloc(wh->len, GFP_NOFS);
32137 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32138 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
32145 +/* ---------------------------------------------------------------------- */
32148 + * test if the @wh_name exists under @h_parent.
32149 + * @try_sio specifies the necessary of super-io.
32151 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
32154 + struct dentry *wh_dentry;
32157 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
32159 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
32160 + err = PTR_ERR(wh_dentry);
32161 + if (IS_ERR(wh_dentry)) {
32162 + if (err == -ENAMETOOLONG)
32168 + if (d_is_negative(wh_dentry))
32169 + goto out_wh; /* success */
32172 + if (d_is_reg(wh_dentry))
32173 + goto out_wh; /* success */
32176 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
32177 + wh_dentry, d_inode(wh_dentry)->i_mode);
32186 + * test if the @h_dentry sets opaque or not.
32188 +int au_diropq_test(struct dentry *h_dentry)
32191 + struct inode *h_dir;
32193 + h_dir = d_inode(h_dentry);
32194 + err = au_wh_test(h_dentry, &diropq_name,
32195 + au_test_h_perm_sio(h_dir, MAY_EXEC));
32200 + * returns a negative dentry whose name is unique and temporary.
32202 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32203 + struct qstr *prefix)
32205 + struct dentry *dentry;
32207 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
32209 + /* strict atomic_t is unnecessary here */
32210 + static unsigned short cnt;
32213 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
32216 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
32217 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
32218 + dentry = ERR_PTR(-ENAMETOOLONG);
32219 + if (unlikely(qs.len > NAME_MAX))
32221 + dentry = ERR_PTR(-ENOMEM);
32222 + name = kmalloc(qs.len + 1, GFP_NOFS);
32223 + if (unlikely(!name))
32227 + /* doubly whiteout-ed */
32228 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
32229 + p = name + AUFS_WH_PFX_LEN * 2;
32230 + memcpy(p, prefix->name, prefix->len);
32231 + p += prefix->len;
32233 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
32236 + for (i = 0; i < 3; i++) {
32237 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
32238 + dentry = au_sio_lkup_one(&qs, h_parent);
32239 + if (IS_ERR(dentry) || d_is_negative(dentry))
32243 + /* pr_warn("could not get random name\n"); */
32244 + dentry = ERR_PTR(-EEXIST);
32245 + AuDbg("%.*s\n", AuLNPair(&qs));
32249 + if (name != defname)
32252 + AuTraceErrPtr(dentry);
32257 + * rename the @h_dentry on @br to the whiteouted temporary name.
32259 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
32262 + struct path h_path = {
32263 + .mnt = au_br_mnt(br)
32265 + struct inode *h_dir, *delegated;
32266 + struct dentry *h_parent;
32268 + h_parent = h_dentry->d_parent; /* dir inode is locked */
32269 + h_dir = d_inode(h_parent);
32270 + IMustLock(h_dir);
32272 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
32273 + err = PTR_ERR(h_path.dentry);
32274 + if (IS_ERR(h_path.dentry))
32277 + /* under the same dir, no need to lock_rename() */
32278 + delegated = NULL;
32279 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
32281 + if (unlikely(err == -EWOULDBLOCK)) {
32282 + pr_warn("cannot retry for NFSv4 delegation"
32283 + " for an internal rename\n");
32286 + dput(h_path.dentry);
32293 +/* ---------------------------------------------------------------------- */
32295 + * functions for removing a whiteout
32298 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
32301 + struct inode *delegated;
32304 + * forces superio when the dir has a sticky bit.
32305 + * this may be a violation of unix fs semantics.
32307 + force = (h_dir->i_mode & S_ISVTX)
32308 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32309 + delegated = NULL;
32310 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32311 + if (unlikely(err == -EWOULDBLOCK)) {
32312 + pr_warn("cannot retry for NFSv4 delegation"
32313 + " for an internal unlink\n");
32319 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32320 + struct dentry *dentry)
32324 + err = do_unlink_wh(h_dir, h_path);
32325 + if (!err && dentry)
32326 + au_set_dbwh(dentry, -1);
32331 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32332 + struct au_branch *br)
32335 + struct path h_path = {
32336 + .mnt = au_br_mnt(br)
32340 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32341 + if (IS_ERR(h_path.dentry))
32342 + err = PTR_ERR(h_path.dentry);
32344 + if (d_is_reg(h_path.dentry))
32345 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32346 + dput(h_path.dentry);
32352 +/* ---------------------------------------------------------------------- */
32354 + * initialize/clean whiteout for a branch
32357 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32361 + struct inode *delegated;
32363 + if (d_is_negative(whpath->dentry))
32367 + err = vfsub_rmdir(h_dir, whpath);
32369 + delegated = NULL;
32370 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32371 + if (unlikely(err == -EWOULDBLOCK)) {
32372 + pr_warn("cannot retry for NFSv4 delegation"
32373 + " for an internal unlink\n");
32377 + if (unlikely(err))
32378 + pr_warn("failed removing %pd (%d), ignored.\n",
32379 + whpath->dentry, err);
32382 +static int test_linkable(struct dentry *h_root)
32384 + struct inode *h_dir = d_inode(h_root);
32386 + if (h_dir->i_op->link)
32389 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32390 + h_root, au_sbtype(h_root->d_sb));
32394 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32395 +static int au_whdir(struct inode *h_dir, struct path *path)
32400 + if (d_is_negative(path->dentry)) {
32401 + int mode = S_IRWXU;
32403 + if (au_test_nfs(path->dentry->d_sb))
32405 + err = vfsub_mkdir(h_dir, path, mode);
32406 + } else if (d_is_dir(path->dentry))
32409 + pr_err("unknown %pd exists\n", path->dentry);
32414 +struct au_wh_base {
32415 + const struct qstr *name;
32416 + struct dentry *dentry;
32419 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
32420 + struct path *h_path)
32422 + h_path->dentry = base[AuBrWh_BASE].dentry;
32423 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32424 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32425 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32426 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32427 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32431 + * returns tri-state,
32432 + * minus: error, caller should print the message
32434 + * plus: error, caller should NOT print the message
32436 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
32437 + int do_plink, struct au_wh_base base[],
32438 + struct path *h_path)
32441 + struct inode *h_dir;
32443 + h_dir = d_inode(h_root);
32444 + h_path->dentry = base[AuBrWh_BASE].dentry;
32445 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32446 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32448 + err = test_linkable(h_root);
32449 + if (unlikely(err)) {
32454 + err = au_whdir(h_dir, h_path);
32455 + if (unlikely(err))
32457 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32459 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32460 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32461 + err = au_whdir(h_dir, h_path);
32462 + if (unlikely(err))
32464 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32471 + * for the moment, aufs supports the branch filesystem which does not support
32472 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
32473 + * copyup failed. finally, such filesystem will not be used as the writable
32476 + * returns tri-state, see above.
32478 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
32479 + int do_plink, struct au_wh_base base[],
32480 + struct path *h_path)
32483 + struct inode *h_dir;
32485 + WbrWhMustWriteLock(wbr);
32487 + err = test_linkable(h_root);
32488 + if (unlikely(err)) {
32494 + * todo: should this create be done in /sbin/mount.aufs helper?
32497 + h_dir = d_inode(h_root);
32498 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
32499 + h_path->dentry = base[AuBrWh_BASE].dentry;
32500 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
32501 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
32504 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
32505 + if (unlikely(err))
32508 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32510 + err = au_whdir(h_dir, h_path);
32511 + if (unlikely(err))
32513 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32515 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32516 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
32518 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32519 + err = au_whdir(h_dir, h_path);
32520 + if (unlikely(err))
32522 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32529 + * initialize the whiteout base file/dir for @br.
32531 +int au_wh_init(struct au_branch *br, struct super_block *sb)
32534 + const unsigned char do_plink
32535 + = !!au_opt_test(au_mntflags(sb), PLINK);
32536 + struct inode *h_dir;
32537 + struct path path = br->br_path;
32538 + struct dentry *h_root = path.dentry;
32539 + struct au_wbr *wbr = br->br_wbr;
32540 + static const struct qstr base_name[] = {
32541 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
32542 + sizeof(AUFS_BASE_NAME) - 1),
32543 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
32544 + sizeof(AUFS_PLINKDIR_NAME) - 1),
32545 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
32546 + sizeof(AUFS_ORPHDIR_NAME) - 1)
32548 + struct au_wh_base base[] = {
32549 + [AuBrWh_BASE] = {
32550 + .name = base_name + AuBrWh_BASE,
32553 + [AuBrWh_PLINK] = {
32554 + .name = base_name + AuBrWh_PLINK,
32557 + [AuBrWh_ORPH] = {
32558 + .name = base_name + AuBrWh_ORPH,
32564 + WbrWhMustWriteLock(wbr);
32566 + for (i = 0; i < AuBrWh_Last; i++) {
32567 + /* doubly whiteouted */
32568 + struct dentry *d;
32570 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
32571 + err = PTR_ERR(d);
32575 + base[i].dentry = d;
32577 + && wbr->wbr_wh[i]
32578 + && wbr->wbr_wh[i] != base[i].dentry);
32582 + for (i = 0; i < AuBrWh_Last; i++) {
32583 + dput(wbr->wbr_wh[i]);
32584 + wbr->wbr_wh[i] = NULL;
32588 + if (!au_br_writable(br->br_perm)) {
32589 + h_dir = d_inode(h_root);
32590 + au_wh_init_ro(h_dir, base, &path);
32591 + } else if (!au_br_wh_linkable(br->br_perm)) {
32592 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
32598 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
32604 + goto out; /* success */
32607 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
32608 + err, h_root, au_sbtype(h_root->d_sb));
32610 + for (i = 0; i < AuBrWh_Last; i++)
32611 + dput(base[i].dentry);
32615 +/* ---------------------------------------------------------------------- */
32617 + * whiteouts are all hard-linked usually.
32618 + * when its link count reaches a ceiling, we create a new whiteout base
32619 + * asynchronously.
32622 +struct reinit_br_wh {
32623 + struct super_block *sb;
32624 + struct au_branch *br;
32627 +static void reinit_br_wh(void *arg)
32630 + aufs_bindex_t bindex;
32631 + struct path h_path;
32632 + struct reinit_br_wh *a = arg;
32633 + struct au_wbr *wbr;
32634 + struct inode *dir, *delegated;
32635 + struct dentry *h_root;
32636 + struct au_hinode *hdir;
32639 + wbr = a->br->br_wbr;
32640 + /* big aufs lock */
32641 + si_noflush_write_lock(a->sb);
32642 + if (!au_br_writable(a->br->br_perm))
32644 + bindex = au_br_index(a->sb, a->br->br_id);
32645 + if (unlikely(bindex < 0))
32648 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
32649 + dir = d_inode(a->sb->s_root);
32650 + hdir = au_hi(dir, bindex);
32651 + h_root = au_h_dptr(a->sb->s_root, bindex);
32652 + AuDebugOn(h_root != au_br_dentry(a->br));
32654 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32655 + wbr_wh_write_lock(wbr);
32656 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
32659 + h_path.dentry = wbr->wbr_whbase;
32660 + h_path.mnt = au_br_mnt(a->br);
32661 + delegated = NULL;
32662 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
32664 + if (unlikely(err == -EWOULDBLOCK)) {
32665 + pr_warn("cannot retry for NFSv4 delegation"
32666 + " for an internal unlink\n");
32670 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
32673 + dput(wbr->wbr_whbase);
32674 + wbr->wbr_whbase = NULL;
32676 + err = au_wh_init(a->br, a->sb);
32677 + wbr_wh_write_unlock(wbr);
32678 + au_hn_imtx_unlock(hdir);
32679 + di_read_unlock(a->sb->s_root, AuLock_IR);
32681 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
32685 + atomic_dec(&wbr->wbr_wh_running);
32686 + atomic_dec(&a->br->br_count);
32687 + si_write_unlock(a->sb);
32688 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
32690 + if (unlikely(err))
32691 + AuIOErr("err %d\n", err);
32694 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
32696 + int do_dec, wkq_err;
32697 + struct reinit_br_wh *arg;
32700 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
32703 + /* ignore ENOMEM */
32704 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
32707 + * dec(wh_running), kfree(arg) and dec(br_count)
32708 + * in reinit function
32712 + atomic_inc(&br->br_count);
32713 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
32714 + if (unlikely(wkq_err)) {
32715 + atomic_dec(&br->br_wbr->wbr_wh_running);
32716 + atomic_dec(&br->br_count);
32724 + atomic_dec(&br->br_wbr->wbr_wh_running);
32727 +/* ---------------------------------------------------------------------- */
32730 + * create the whiteout @wh.
32732 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
32733 + struct dentry *wh)
32736 + struct path h_path = {
32739 + struct au_branch *br;
32740 + struct au_wbr *wbr;
32741 + struct dentry *h_parent;
32742 + struct inode *h_dir, *delegated;
32744 + h_parent = wh->d_parent; /* dir inode is locked */
32745 + h_dir = d_inode(h_parent);
32746 + IMustLock(h_dir);
32748 + br = au_sbr(sb, bindex);
32749 + h_path.mnt = au_br_mnt(br);
32750 + wbr = br->br_wbr;
32751 + wbr_wh_read_lock(wbr);
32752 + if (wbr->wbr_whbase) {
32753 + delegated = NULL;
32754 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
32755 + if (unlikely(err == -EWOULDBLOCK)) {
32756 + pr_warn("cannot retry for NFSv4 delegation"
32757 + " for an internal link\n");
32760 + if (!err || err != -EMLINK)
32763 + /* link count full. re-initialize br_whbase. */
32764 + kick_reinit_br_wh(sb, br);
32767 + /* return this error in this context */
32768 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
32770 + au_fhsm_wrote(sb, bindex, /*force*/0);
32773 + wbr_wh_read_unlock(wbr);
32777 +/* ---------------------------------------------------------------------- */
32780 + * create or remove the diropq.
32782 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
32783 + unsigned int flags)
32785 + struct dentry *opq_dentry, *h_dentry;
32786 + struct super_block *sb;
32787 + struct au_branch *br;
32790 + sb = dentry->d_sb;
32791 + br = au_sbr(sb, bindex);
32792 + h_dentry = au_h_dptr(dentry, bindex);
32793 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
32794 + if (IS_ERR(opq_dentry))
32797 + if (au_ftest_diropq(flags, CREATE)) {
32798 + err = link_or_create_wh(sb, bindex, opq_dentry);
32800 + au_set_dbdiropq(dentry, bindex);
32801 + goto out; /* success */
32804 + struct path tmp = {
32805 + .dentry = opq_dentry,
32806 + .mnt = au_br_mnt(br)
32808 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
32810 + au_set_dbdiropq(dentry, -1);
32812 + dput(opq_dentry);
32813 + opq_dentry = ERR_PTR(err);
32816 + return opq_dentry;
32819 +struct do_diropq_args {
32820 + struct dentry **errp;
32821 + struct dentry *dentry;
32822 + aufs_bindex_t bindex;
32823 + unsigned int flags;
32826 +static void call_do_diropq(void *args)
32828 + struct do_diropq_args *a = args;
32829 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
32832 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32833 + unsigned int flags)
32835 + struct dentry *diropq, *h_dentry;
32837 + h_dentry = au_h_dptr(dentry, bindex);
32838 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
32839 + diropq = do_diropq(dentry, bindex, flags);
32842 + struct do_diropq_args args = {
32844 + .dentry = dentry,
32845 + .bindex = bindex,
32849 + wkq_err = au_wkq_wait(call_do_diropq, &args);
32850 + if (unlikely(wkq_err))
32851 + diropq = ERR_PTR(wkq_err);
32857 +/* ---------------------------------------------------------------------- */
32860 + * lookup whiteout dentry.
32861 + * @h_parent: lower parent dentry which must exist and be locked
32862 + * @base_name: name of dentry which will be whiteouted
32863 + * returns dentry for whiteout.
32865 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32866 + struct au_branch *br)
32869 + struct qstr wh_name;
32870 + struct dentry *wh_dentry;
32872 + err = au_wh_name_alloc(&wh_name, base_name);
32873 + wh_dentry = ERR_PTR(err);
32875 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
32876 + kfree(wh_name.name);
32878 + return wh_dentry;
32882 + * link/create a whiteout for @dentry on @bindex.
32884 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32885 + struct dentry *h_parent)
32887 + struct dentry *wh_dentry;
32888 + struct super_block *sb;
32891 + sb = dentry->d_sb;
32892 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
32893 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
32894 + err = link_or_create_wh(sb, bindex, wh_dentry);
32896 + au_set_dbwh(dentry, bindex);
32897 + au_fhsm_wrote(sb, bindex, /*force*/0);
32900 + wh_dentry = ERR_PTR(err);
32904 + return wh_dentry;
32907 +/* ---------------------------------------------------------------------- */
32909 +/* Delete all whiteouts in this directory on branch bindex. */
32910 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
32911 + aufs_bindex_t bindex, struct au_branch *br)
32914 + unsigned long ul, n;
32915 + struct qstr wh_name;
32917 + struct hlist_head *head;
32918 + struct au_vdir_wh *pos;
32919 + struct au_vdir_destr *str;
32922 + p = (void *)__get_free_page(GFP_NOFS);
32923 + wh_name.name = p;
32924 + if (unlikely(!wh_name.name))
32928 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32929 + p += AUFS_WH_PFX_LEN;
32930 + n = whlist->nh_num;
32931 + head = whlist->nh_head;
32932 + for (ul = 0; !err && ul < n; ul++, head++) {
32933 + hlist_for_each_entry(pos, head, wh_hash) {
32934 + if (pos->wh_bindex != bindex)
32937 + str = &pos->wh_str;
32938 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
32939 + memcpy(p, str->name, str->len);
32940 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
32941 + err = unlink_wh_name(h_dentry, &wh_name, br);
32946 + AuIOErr("whiteout name too long %.*s\n",
32947 + str->len, str->name);
32952 + free_page((unsigned long)wh_name.name);
32958 +struct del_wh_children_args {
32960 + struct dentry *h_dentry;
32961 + struct au_nhash *whlist;
32962 + aufs_bindex_t bindex;
32963 + struct au_branch *br;
32966 +static void call_del_wh_children(void *args)
32968 + struct del_wh_children_args *a = args;
32969 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
32972 +/* ---------------------------------------------------------------------- */
32974 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
32976 + struct au_whtmp_rmdir *whtmp;
32978 + unsigned int rdhash;
32980 + SiMustAnyLock(sb);
32982 + whtmp = kzalloc(sizeof(*whtmp), gfp);
32983 + if (unlikely(!whtmp)) {
32984 + whtmp = ERR_PTR(-ENOMEM);
32988 + /* no estimation for dir size */
32989 + rdhash = au_sbi(sb)->si_rdhash;
32991 + rdhash = AUFS_RDHASH_DEF;
32992 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
32993 + if (unlikely(err)) {
32995 + whtmp = ERR_PTR(err);
33002 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
33005 + atomic_dec(&whtmp->br->br_count);
33006 + dput(whtmp->wh_dentry);
33007 + iput(whtmp->dir);
33008 + au_nhash_wh_free(&whtmp->whlist);
33013 + * rmdir the whiteouted temporary named dir @h_dentry.
33014 + * @whlist: whiteouted children.
33016 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33017 + struct dentry *wh_dentry, struct au_nhash *whlist)
33020 + unsigned int h_nlink;
33021 + struct path h_tmp;
33022 + struct inode *wh_inode, *h_dir;
33023 + struct au_branch *br;
33025 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
33026 + IMustLock(h_dir);
33028 + br = au_sbr(dir->i_sb, bindex);
33029 + wh_inode = d_inode(wh_dentry);
33030 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
33033 + * someone else might change some whiteouts while we were sleeping.
33034 + * it means this whlist may have an obsoleted entry.
33036 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
33037 + err = del_wh_children(wh_dentry, whlist, bindex, br);
33040 + struct del_wh_children_args args = {
33042 + .h_dentry = wh_dentry,
33043 + .whlist = whlist,
33044 + .bindex = bindex,
33048 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
33049 + if (unlikely(wkq_err))
33052 + mutex_unlock(&wh_inode->i_mutex);
33055 + h_tmp.dentry = wh_dentry;
33056 + h_tmp.mnt = au_br_mnt(br);
33057 + h_nlink = h_dir->i_nlink;
33058 + err = vfsub_rmdir(h_dir, &h_tmp);
33059 + /* some fs doesn't change the parent nlink in some cases */
33060 + h_nlink -= h_dir->i_nlink;
33064 + if (au_ibstart(dir) == bindex) {
33065 + /* todo: dir->i_mutex is necessary */
33066 + au_cpup_attr_timesizes(dir);
33068 + vfsub_drop_nlink(dir);
33070 + return 0; /* success */
33073 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
33077 +static void call_rmdir_whtmp(void *args)
33080 + aufs_bindex_t bindex;
33081 + struct au_whtmp_rmdir *a = args;
33082 + struct super_block *sb;
33083 + struct dentry *h_parent;
33084 + struct inode *h_dir;
33085 + struct au_hinode *hdir;
33087 + /* rmdir by nfsd may cause deadlock with this i_mutex */
33088 + /* mutex_lock(&a->dir->i_mutex); */
33090 + sb = a->dir->i_sb;
33091 + si_read_lock(sb, !AuLock_FLUSH);
33092 + if (!au_br_writable(a->br->br_perm))
33094 + bindex = au_br_index(sb, a->br->br_id);
33095 + if (unlikely(bindex < 0))
33099 + ii_write_lock_parent(a->dir);
33100 + h_parent = dget_parent(a->wh_dentry);
33101 + h_dir = d_inode(h_parent);
33102 + hdir = au_hi(a->dir, bindex);
33103 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
33104 + if (unlikely(err))
33106 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
33107 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
33110 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
33111 + au_hn_imtx_unlock(hdir);
33112 + vfsub_mnt_drop_write(au_br_mnt(a->br));
33116 + ii_write_unlock(a->dir);
33118 + /* mutex_unlock(&a->dir->i_mutex); */
33119 + au_whtmp_rmdir_free(a);
33120 + si_read_unlock(sb);
33121 + au_nwt_done(&au_sbi(sb)->si_nowait);
33122 + if (unlikely(err))
33123 + AuIOErr("err %d\n", err);
33126 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33127 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
33130 + struct super_block *sb;
33134 + /* all post-process will be done in do_rmdir_whtmp(). */
33136 + args->dir = au_igrab(dir);
33137 + args->br = au_sbr(sb, bindex);
33138 + atomic_inc(&args->br->br_count);
33139 + args->wh_dentry = dget(wh_dentry);
33140 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
33141 + if (unlikely(wkq_err)) {
33142 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
33143 + au_whtmp_rmdir_free(args);
33146 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
33147 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
33148 +++ linux/fs/aufs/whout.h 2016-02-28 11:26:32.576637942 +0100
33151 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33153 + * This program, aufs is free software; you can redistribute it and/or modify
33154 + * it under the terms of the GNU General Public License as published by
33155 + * the Free Software Foundation; either version 2 of the License, or
33156 + * (at your option) any later version.
33158 + * This program is distributed in the hope that it will be useful,
33159 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33160 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33161 + * GNU General Public License for more details.
33163 + * You should have received a copy of the GNU General Public License
33164 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33168 + * whiteout for logical deletion and opaque directory
33171 +#ifndef __AUFS_WHOUT_H__
33172 +#define __AUFS_WHOUT_H__
33179 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
33180 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
33181 +int au_diropq_test(struct dentry *h_dentry);
33183 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
33184 + struct qstr *prefix);
33185 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
33186 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33187 + struct dentry *dentry);
33188 +int au_wh_init(struct au_branch *br, struct super_block *sb);
33190 +/* diropq flags */
33191 +#define AuDiropq_CREATE 1
33192 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
33193 +#define au_fset_diropq(flags, name) \
33194 + do { (flags) |= AuDiropq_##name; } while (0)
33195 +#define au_fclr_diropq(flags, name) \
33196 + do { (flags) &= ~AuDiropq_##name; } while (0)
33198 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33199 + unsigned int flags);
33200 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33201 + struct au_branch *br);
33202 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33203 + struct dentry *h_parent);
33205 +/* real rmdir for the whiteout-ed dir */
33206 +struct au_whtmp_rmdir {
33207 + struct inode *dir;
33208 + struct au_branch *br;
33209 + struct dentry *wh_dentry;
33210 + struct au_nhash whlist;
33213 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
33214 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
33215 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33216 + struct dentry *wh_dentry, struct au_nhash *whlist);
33217 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33218 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
33220 +/* ---------------------------------------------------------------------- */
33222 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
33223 + aufs_bindex_t bindex)
33225 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
33228 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
33230 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
33233 +#endif /* __KERNEL__ */
33234 +#endif /* __AUFS_WHOUT_H__ */
33235 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
33236 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
33237 +++ linux/fs/aufs/wkq.c 2016-02-28 11:26:32.576637942 +0100
33240 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33242 + * This program, aufs is free software; you can redistribute it and/or modify
33243 + * it under the terms of the GNU General Public License as published by
33244 + * the Free Software Foundation; either version 2 of the License, or
33245 + * (at your option) any later version.
33247 + * This program is distributed in the hope that it will be useful,
33248 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33249 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33250 + * GNU General Public License for more details.
33252 + * You should have received a copy of the GNU General Public License
33253 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33257 + * workqueue for asynchronous/super-io operations
33258 + * todo: try new dredential scheme
33261 +#include <linux/module.h>
33264 +/* internal workqueue named AUFS_WKQ_NAME */
33266 +static struct workqueue_struct *au_wkq;
33268 +struct au_wkinfo {
33269 + struct work_struct wk;
33270 + struct kobject *kobj;
33272 + unsigned int flags; /* see wkq.h */
33274 + au_wkq_func_t func;
33277 + struct completion *comp;
33280 +/* ---------------------------------------------------------------------- */
33282 +static void wkq_func(struct work_struct *wk)
33284 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
33286 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
33287 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
33289 + wkinfo->func(wkinfo->args);
33290 + if (au_ftest_wkq(wkinfo->flags, WAIT))
33291 + complete(wkinfo->comp);
33293 + kobject_put(wkinfo->kobj);
33294 + module_put(THIS_MODULE); /* todo: ?? */
33300 + * Since struct completion is large, try allocating it dynamically.
33302 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
33303 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33305 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33307 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33309 + init_completion(*comp);
33310 + wkinfo->comp = *comp;
33316 +static void au_wkq_comp_free(struct completion *comp)
33324 +#define AuWkqCompDeclare(name) \
33325 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33326 + struct completion *comp = &_ ## name
33328 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33330 + wkinfo->comp = *comp;
33334 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33338 +#endif /* 4KSTACKS */
33340 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33342 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33343 + if (au_wkq_test()) {
33344 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33345 + " due to a dead dir by UDBA?\n");
33346 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33349 + au_dbg_verify_kthread();
33351 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33352 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33353 + queue_work(au_wkq, &wkinfo->wk);
33355 + INIT_WORK(&wkinfo->wk, wkq_func);
33356 + schedule_work(&wkinfo->wk);
33361 + * Be careful. It is easy to make deadlock happen.
33362 + * processA: lock, wkq and wait
33363 + * processB: wkq and wait, lock in wkq
33366 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33369 + AuWkqCompDeclare(comp);
33370 + struct au_wkinfo wkinfo = {
33376 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33378 + au_wkq_run(&wkinfo);
33379 + /* no timeout, no interrupt */
33380 + wait_for_completion(wkinfo.comp);
33381 + au_wkq_comp_free(comp);
33382 + destroy_work_on_stack(&wkinfo.wk);
33390 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33391 + * problem in a concurrent umounting.
33393 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33394 + unsigned int flags)
33397 + struct au_wkinfo *wkinfo;
33399 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
33402 + * wkq_func() must free this wkinfo.
33403 + * it highly depends upon the implementation of workqueue.
33406 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
33408 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
33409 + wkinfo->flags = flags & ~AuWkq_WAIT;
33410 + wkinfo->func = func;
33411 + wkinfo->args = args;
33412 + wkinfo->comp = NULL;
33413 + kobject_get(wkinfo->kobj);
33414 + __module_get(THIS_MODULE); /* todo: ?? */
33416 + au_wkq_run(wkinfo);
33419 + au_nwt_done(&au_sbi(sb)->si_nowait);
33425 +/* ---------------------------------------------------------------------- */
33427 +void au_nwt_init(struct au_nowait_tasks *nwt)
33429 + atomic_set(&nwt->nw_len, 0);
33430 + /* smp_mb(); */ /* atomic_set */
33431 + init_waitqueue_head(&nwt->nw_wq);
33434 +void au_wkq_fin(void)
33436 + destroy_workqueue(au_wkq);
33439 +int __init au_wkq_init(void)
33444 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
33445 + if (IS_ERR(au_wkq))
33446 + err = PTR_ERR(au_wkq);
33447 + else if (!au_wkq)
33452 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
33453 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
33454 +++ linux/fs/aufs/wkq.h 2016-02-28 11:26:32.576637942 +0100
33457 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33459 + * This program, aufs is free software; you can redistribute it and/or modify
33460 + * it under the terms of the GNU General Public License as published by
33461 + * the Free Software Foundation; either version 2 of the License, or
33462 + * (at your option) any later version.
33464 + * This program is distributed in the hope that it will be useful,
33465 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33466 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33467 + * GNU General Public License for more details.
33469 + * You should have received a copy of the GNU General Public License
33470 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33474 + * workqueue for asynchronous/super-io operations
33475 + * todo: try new credentials management scheme
33478 +#ifndef __AUFS_WKQ_H__
33479 +#define __AUFS_WKQ_H__
33483 +struct super_block;
33485 +/* ---------------------------------------------------------------------- */
33488 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
33490 +struct au_nowait_tasks {
33492 + wait_queue_head_t nw_wq;
33495 +/* ---------------------------------------------------------------------- */
33497 +typedef void (*au_wkq_func_t)(void *args);
33500 +#define AuWkq_WAIT 1
33501 +#define AuWkq_NEST (1 << 1)
33502 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
33503 +#define au_fset_wkq(flags, name) \
33504 + do { (flags) |= AuWkq_##name; } while (0)
33505 +#define au_fclr_wkq(flags, name) \
33506 + do { (flags) &= ~AuWkq_##name; } while (0)
33508 +#ifndef CONFIG_AUFS_HNOTIFY
33510 +#define AuWkq_NEST 0
33514 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
33515 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33516 + unsigned int flags);
33517 +void au_nwt_init(struct au_nowait_tasks *nwt);
33518 +int __init au_wkq_init(void);
33519 +void au_wkq_fin(void);
33521 +/* ---------------------------------------------------------------------- */
33523 +static inline int au_wkq_test(void)
33525 + return current->flags & PF_WQ_WORKER;
33528 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
33530 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
33533 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
33535 + if (atomic_dec_and_test(&nwt->nw_len))
33536 + wake_up_all(&nwt->nw_wq);
33539 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
33541 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
33545 +#endif /* __KERNEL__ */
33546 +#endif /* __AUFS_WKQ_H__ */
33547 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
33548 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
33549 +++ linux/fs/aufs/xattr.c 2016-02-28 11:26:32.576637942 +0100
33552 + * Copyright (C) 2014-2016 Junjiro R. Okajima
33554 + * This program, aufs is free software; you can redistribute it and/or modify
33555 + * it under the terms of the GNU General Public License as published by
33556 + * the Free Software Foundation; either version 2 of the License, or
33557 + * (at your option) any later version.
33559 + * This program is distributed in the hope that it will be useful,
33560 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33561 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33562 + * GNU General Public License for more details.
33564 + * You should have received a copy of the GNU General Public License
33565 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33569 + * handling xattr functions
33572 +#include <linux/xattr.h>
33575 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
33577 + if (!ignore_flags)
33585 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
33590 +#define cmp(brattr, prefix) do { \
33591 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
33592 + XATTR_##prefix##_PREFIX_LEN)) { \
33593 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
33599 + cmp(SEC, SECURITY);
33600 + cmp(SYS, SYSTEM);
33601 + cmp(TR, TRUSTED);
33605 + if (ignore_flags & AuBrAttr_ICEX_OTH)
33612 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
33614 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
33615 + char *name, char **buf, unsigned int ignore_flags,
33616 + unsigned int verbose)
33620 + struct inode *h_idst;
33622 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
33624 + if (unlikely(err <= 0)) {
33625 + if (err == -ENODATA
33626 + || (err == -EOPNOTSUPP
33627 + && ((ignore_flags & au_xattr_out_of_list)
33628 + || (au_test_nfs_noacl(d_inode(h_src))
33629 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
33631 + XATTR_NAME_POSIX_ACL_DEFAULT))))
33634 + if (err && (verbose || au_debug_test()))
33635 + pr_err("%s, err %d\n", name, err);
33639 + /* unlock it temporary */
33640 + h_idst = d_inode(h_dst);
33641 + mutex_unlock(&h_idst->i_mutex);
33642 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
33643 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33644 + if (unlikely(err)) {
33645 + if (verbose || au_debug_test())
33646 + pr_err("%s, err %d\n", name, err);
33647 + err = au_xattr_ignore(err, name, ignore_flags);
33654 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
33655 + unsigned int verbose)
33657 + int err, unlocked, acl_access, acl_default;
33659 + struct inode *h_isrc, *h_idst;
33660 + char *value, *p, *o, *e;
33662 + /* try stopping to update the source inode while we are referencing */
33663 + /* there should not be the parent-child relationship between them */
33664 + h_isrc = d_inode(h_src);
33665 + h_idst = d_inode(h_dst);
33666 + mutex_unlock(&h_idst->i_mutex);
33667 + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD);
33668 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33671 + /* some filesystems don't list POSIX ACL, for example tmpfs */
33672 + ssz = vfs_listxattr(h_src, NULL, 0);
33674 + if (unlikely(err < 0)) {
33676 + if (err == -ENODATA
33677 + || err == -EOPNOTSUPP)
33678 + err = 0; /* ignore */
33687 + p = kmalloc(ssz, GFP_NOFS);
33689 + if (unlikely(!p))
33691 + err = vfs_listxattr(h_src, p, ssz);
33693 + mutex_unlock(&h_isrc->i_mutex);
33695 + AuDbg("err %d, ssz %zd\n", err, ssz);
33696 + if (unlikely(err < 0))
33704 + while (!err && p < e) {
33705 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
33706 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
33707 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
33708 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
33710 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
33712 + p += strlen(p) + 1;
33715 + ignore_flags |= au_xattr_out_of_list;
33716 + if (!err && !acl_access) {
33717 + err = au_do_cpup_xattr(h_dst, h_src,
33718 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
33719 + ignore_flags, verbose);
33722 + if (!err && !acl_default) {
33723 + err = au_do_cpup_xattr(h_dst, h_src,
33724 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
33725 + ignore_flags, verbose);
33735 + mutex_unlock(&h_isrc->i_mutex);
33740 +/* ---------------------------------------------------------------------- */
33747 +struct au_lgxattr {
33755 + const char *name;
33762 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
33765 + struct path h_path;
33766 + struct super_block *sb;
33768 + sb = dentry->d_sb;
33769 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
33770 + if (unlikely(err))
33772 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
33773 + if (unlikely(err))
33775 + if (unlikely(!h_path.dentry))
33776 + /* illegally overlapped or something */
33777 + goto out_di; /* pretending success */
33779 + /* always topmost entry only */
33780 + switch (arg->type) {
33781 + case AU_XATTR_LIST:
33782 + err = vfs_listxattr(h_path.dentry,
33783 + arg->u.list.list, arg->u.list.size);
33785 + case AU_XATTR_GET:
33786 + err = vfs_getxattr(h_path.dentry,
33787 + arg->u.get.name, arg->u.get.value,
33788 + arg->u.get.size);
33793 + di_read_unlock(dentry, AuLock_IR);
33795 + si_read_unlock(sb);
33801 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
33803 + struct au_lgxattr arg = {
33804 + .type = AU_XATTR_LIST,
33811 + return au_lgxattr(dentry, &arg);
33814 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
33817 + struct au_lgxattr arg = {
33818 + .type = AU_XATTR_GET,
33826 + return au_lgxattr(dentry, &arg);
33829 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
33830 + size_t size, int flags)
33832 + struct au_srxattr arg = {
33833 + .type = AU_XATTR_SET,
33842 + return au_srxattr(dentry, &arg);
33845 +int aufs_removexattr(struct dentry *dentry, const char *name)
33847 + struct au_srxattr arg = {
33848 + .type = AU_XATTR_REMOVE,
33854 + return au_srxattr(dentry, &arg);
33857 +/* ---------------------------------------------------------------------- */
33860 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
33861 + const char *name, size_t name_len, int type)
33863 + return aufs_listxattr(dentry, list, list_size);
33866 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
33867 + size_t size, int type)
33869 + return aufs_getxattr(dentry, name, buffer, size);
33872 +static int au_xattr_set(struct dentry *dentry, const char *name,
33873 + const void *value, size_t size, int flags, int type)
33875 + return aufs_setxattr(dentry, name, value, size, flags);
33878 +static const struct xattr_handler au_xattr_handler = {
33879 + /* no prefix, no flags */
33880 + .list = au_xattr_list,
33881 + .get = au_xattr_get,
33882 + .set = au_xattr_set
33883 + /* why no remove? */
33886 +static const struct xattr_handler *au_xattr_handlers[] = {
33887 + &au_xattr_handler
33890 +void au_xattr_init(struct super_block *sb)
33892 + /* sb->s_xattr = au_xattr_handlers; */
33895 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
33896 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
33897 +++ linux/fs/aufs/xino.c 2016-02-28 11:26:32.576637942 +0100
33900 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33902 + * This program, aufs is free software; you can redistribute it and/or modify
33903 + * it under the terms of the GNU General Public License as published by
33904 + * the Free Software Foundation; either version 2 of the License, or
33905 + * (at your option) any later version.
33907 + * This program is distributed in the hope that it will be useful,
33908 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33909 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33910 + * GNU General Public License for more details.
33912 + * You should have received a copy of the GNU General Public License
33913 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33917 + * external inode number translation table and bitmap
33920 +#include <linux/seq_file.h>
33921 +#include <linux/statfs.h>
33924 +/* todo: unnecessary to support mmap_sem since kernel-space? */
33925 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
33929 + mm_segment_t oldfs;
33936 + oldfs = get_fs();
33937 + set_fs(KERNEL_DS);
33939 + /* todo: signal_pending? */
33940 + err = func(file, buf.u, size, pos);
33941 + } while (err == -EAGAIN || err == -EINTR);
33944 +#if 0 /* reserved for future use */
33946 + fsnotify_access(file->f_path.dentry);
33952 +/* ---------------------------------------------------------------------- */
33954 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
33955 + size_t size, loff_t *pos);
33957 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
33958 + size_t size, loff_t *pos)
33961 + mm_segment_t oldfs;
33964 + const char __user *u;
33967 + const int prevent_endless = 10;
33971 + oldfs = get_fs();
33972 + set_fs(KERNEL_DS);
33974 + err = func(file, buf.u, size, pos);
33975 + if (err == -EINTR
33976 + && !au_wkq_test()
33977 + && fatal_signal_pending(current)) {
33979 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
33980 + BUG_ON(err == -EINTR);
33981 + oldfs = get_fs();
33982 + set_fs(KERNEL_DS);
33984 + } while (i++ < prevent_endless
33985 + && (err == -EAGAIN || err == -EINTR));
33988 +#if 0 /* reserved for future use */
33990 + fsnotify_modify(file->f_path.dentry);
33996 +struct do_xino_fwrite_args {
33998 + vfs_writef_t func;
33999 + struct file *file;
34005 +static void call_do_xino_fwrite(void *args)
34007 + struct do_xino_fwrite_args *a = args;
34008 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
34011 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34012 + size_t size, loff_t *pos)
34016 + struct do_xino_fwrite_args args = {
34026 + * it breaks RLIMIT_FSIZE and normal user's limit,
34027 + * users should care about quota and real 'filesystem full.'
34029 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
34030 + if (unlikely(wkq_err))
34036 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
34037 + size_t size, loff_t *pos)
34041 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
34043 + err = do_xino_fwrite(func, file, buf, size, pos);
34046 + err = xino_fwrite_wkq(func, file, buf, size, pos);
34051 +/* ---------------------------------------------------------------------- */
34054 + * create a new xinofile at the same place/path as @base_file.
34056 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
34058 + struct file *file;
34059 + struct dentry *base, *parent;
34060 + struct inode *dir, *delegated;
34061 + struct qstr *name;
34062 + struct path path;
34065 + base = base_file->f_path.dentry;
34066 + parent = base->d_parent; /* dir inode is locked */
34067 + dir = d_inode(parent);
34070 + file = ERR_PTR(-EINVAL);
34071 + name = &base->d_name;
34072 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
34073 + if (IS_ERR(path.dentry)) {
34074 + file = (void *)path.dentry;
34075 + pr_err("%pd lookup err %ld\n",
34076 + base, PTR_ERR(path.dentry));
34080 + /* no need to mnt_want_write() since we call dentry_open() later */
34081 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
34082 + if (unlikely(err)) {
34083 + file = ERR_PTR(err);
34084 + pr_err("%pd create err %d\n", base, err);
34088 + path.mnt = base_file->f_path.mnt;
34089 + file = vfsub_dentry_open(&path,
34090 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34091 + /* | __FMODE_NONOTIFY */);
34092 + if (IS_ERR(file)) {
34093 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
34097 + delegated = NULL;
34098 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
34099 + if (unlikely(err == -EWOULDBLOCK)) {
34100 + pr_warn("cannot retry for NFSv4 delegation"
34101 + " for an internal unlink\n");
34104 + if (unlikely(err)) {
34105 + pr_err("%pd unlink err %d\n", base, err);
34110 + /* no one can touch copy_src xino */
34111 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
34112 + if (unlikely(err)) {
34113 + pr_err("%pd copy err %d\n", base, err);
34117 + goto out_dput; /* success */
34121 + file = ERR_PTR(err);
34123 + dput(path.dentry);
34128 +struct au_xino_lock_dir {
34129 + struct au_hinode *hdir;
34130 + struct dentry *parent;
34131 + struct mutex *mtx;
34134 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
34135 + struct au_xino_lock_dir *ldir)
34137 + aufs_bindex_t brid, bindex;
34139 + ldir->hdir = NULL;
34141 + brid = au_xino_brid(sb);
34143 + bindex = au_br_index(sb, brid);
34144 + if (bindex >= 0) {
34145 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
34146 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
34148 + ldir->parent = dget_parent(xino->f_path.dentry);
34149 + ldir->mtx = &d_inode(ldir->parent)->i_mutex;
34150 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
34154 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
34157 + au_hn_imtx_unlock(ldir->hdir);
34159 + mutex_unlock(ldir->mtx);
34160 + dput(ldir->parent);
34164 +/* ---------------------------------------------------------------------- */
34166 +/* trucate xino files asynchronously */
34168 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
34171 + unsigned long jiffy;
34173 + aufs_bindex_t bi, bend;
34174 + struct kstatfs *st;
34175 + struct au_branch *br;
34176 + struct file *new_xino, *file;
34177 + struct super_block *h_sb;
34178 + struct au_xino_lock_dir ldir;
34181 + st = kmalloc(sizeof(*st), GFP_NOFS);
34182 + if (unlikely(!st))
34186 + bend = au_sbend(sb);
34187 + if (unlikely(bindex < 0 || bend < bindex))
34189 + br = au_sbr(sb, bindex);
34190 + file = br->br_xino.xi_file;
34194 + err = vfs_statfs(&file->f_path, st);
34195 + if (unlikely(err))
34196 + AuErr1("statfs err %d, ignored\n", err);
34198 + blocks = file_inode(file)->i_blocks;
34199 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34200 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
34202 + au_xino_lock_dir(sb, file, &ldir);
34203 + /* mnt_want_write() is unnecessary here */
34204 + new_xino = au_xino_create2(file, file);
34205 + au_xino_unlock_dir(&ldir);
34206 + err = PTR_ERR(new_xino);
34207 + if (IS_ERR(new_xino)) {
34208 + pr_err("err %d, ignored\n", err);
34213 + br->br_xino.xi_file = new_xino;
34215 + h_sb = au_br_sb(br);
34216 + for (bi = 0; bi <= bend; bi++) {
34217 + if (unlikely(bi == bindex))
34219 + br = au_sbr(sb, bi);
34220 + if (au_br_sb(br) != h_sb)
34223 + fput(br->br_xino.xi_file);
34224 + br->br_xino.xi_file = new_xino;
34225 + get_file(new_xino);
34228 + err = vfs_statfs(&new_xino->f_path, st);
34230 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34231 + bindex, (u64)file_inode(new_xino)->i_blocks,
34232 + st->f_bfree, st->f_blocks);
34233 + if (file_inode(new_xino)->i_blocks < blocks)
34234 + au_sbi(sb)->si_xino_jiffy = jiffy;
34236 + AuErr1("statfs err %d, ignored\n", err);
34244 +struct xino_do_trunc_args {
34245 + struct super_block *sb;
34246 + struct au_branch *br;
34249 +static void xino_do_trunc(void *_args)
34251 + struct xino_do_trunc_args *args = _args;
34252 + struct super_block *sb;
34253 + struct au_branch *br;
34254 + struct inode *dir;
34256 + aufs_bindex_t bindex;
34260 + dir = d_inode(sb->s_root);
34263 + si_noflush_write_lock(sb);
34264 + ii_read_lock_parent(dir);
34265 + bindex = au_br_index(sb, br->br_id);
34266 + err = au_xino_trunc(sb, bindex);
34267 + ii_read_unlock(dir);
34268 + if (unlikely(err))
34269 + pr_warn("err b%d, (%d)\n", bindex, err);
34270 + atomic_dec(&br->br_xino_running);
34271 + atomic_dec(&br->br_count);
34272 + si_write_unlock(sb);
34273 + au_nwt_done(&au_sbi(sb)->si_nowait);
34277 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
34280 + struct kstatfs st;
34281 + struct au_sbinfo *sbinfo;
34283 + /* todo: si_xino_expire and the ratio should be customizable */
34284 + sbinfo = au_sbi(sb);
34285 + if (time_before(jiffies,
34286 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
34289 + /* truncation border */
34290 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
34291 + if (unlikely(err)) {
34292 + AuErr1("statfs err %d, ignored\n", err);
34295 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
34301 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
34303 + struct xino_do_trunc_args *args;
34306 + if (!xino_trunc_test(sb, br))
34309 + if (atomic_inc_return(&br->br_xino_running) > 1)
34312 + /* lock and kfree() will be called in trunc_xino() */
34313 + args = kmalloc(sizeof(*args), GFP_NOFS);
34314 + if (unlikely(!args)) {
34315 + AuErr1("no memory\n");
34319 + atomic_inc(&br->br_count);
34322 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
34324 + return; /* success */
34326 + pr_err("wkq %d\n", wkq_err);
34327 + atomic_dec(&br->br_count);
34332 + atomic_dec(&br->br_xino_running);
34335 +/* ---------------------------------------------------------------------- */
34337 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34338 + ino_t h_ino, ino_t ino)
34344 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34345 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34348 + pos *= sizeof(ino);
34349 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34350 + if (sz == sizeof(ino))
34351 + return 0; /* success */
34353 + AuIOErr("write failed (%zd)\n", sz);
34358 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34359 + * at the position of @h_ino.
34360 + * even if @ino is zero, it is written to the xinofile and means no entry.
34361 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34362 + * try truncating it.
34364 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34368 + unsigned int mnt_flags;
34369 + struct au_branch *br;
34371 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34372 + || ((loff_t)-1) > 0);
34373 + SiMustAnyLock(sb);
34375 + mnt_flags = au_mntflags(sb);
34376 + if (!au_opt_test(mnt_flags, XINO))
34379 + br = au_sbr(sb, bindex);
34380 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34383 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34384 + && au_test_fs_trunc_xino(au_br_sb(br)))
34385 + xino_try_trunc(sb, br);
34386 + return 0; /* success */
34389 + AuIOErr("write failed (%d)\n", err);
34393 +/* ---------------------------------------------------------------------- */
34395 +/* aufs inode number bitmap */
34397 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
34398 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
34402 + AuDebugOn(bit < 0 || page_bits <= bit);
34403 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
34407 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
34409 + AuDebugOn(ino < AUFS_FIRST_INO);
34410 + ino -= AUFS_FIRST_INO;
34411 + *pindex = ino / page_bits;
34412 + *bit = ino % page_bits;
34415 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
34420 + struct au_sbinfo *sbinfo;
34421 + struct file *xib;
34422 + unsigned long *p;
34424 + sbinfo = au_sbi(sb);
34425 + MtxMustLock(&sbinfo->si_xib_mtx);
34426 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
34427 + || !au_opt_test(sbinfo->si_mntflags, XINO));
34429 + if (pindex == sbinfo->si_xib_last_pindex)
34432 + xib = sbinfo->si_xib;
34433 + p = sbinfo->si_xib_buf;
34434 + pos = sbinfo->si_xib_last_pindex;
34435 + pos *= PAGE_SIZE;
34436 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34437 + if (unlikely(sz != PAGE_SIZE))
34441 + pos *= PAGE_SIZE;
34442 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
34443 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
34445 + memset(p, 0, PAGE_SIZE);
34446 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34448 + if (sz == PAGE_SIZE) {
34449 + sbinfo->si_xib_last_pindex = pindex;
34450 + return 0; /* success */
34454 + AuIOErr1("write failed (%zd)\n", sz);
34461 +/* ---------------------------------------------------------------------- */
34463 +static void au_xib_clear_bit(struct inode *inode)
34466 + unsigned long pindex;
34467 + struct super_block *sb;
34468 + struct au_sbinfo *sbinfo;
34470 + AuDebugOn(inode->i_nlink);
34472 + sb = inode->i_sb;
34473 + xib_calc_bit(inode->i_ino, &pindex, &bit);
34474 + AuDebugOn(page_bits <= bit);
34475 + sbinfo = au_sbi(sb);
34476 + mutex_lock(&sbinfo->si_xib_mtx);
34477 + err = xib_pindex(sb, pindex);
34479 + clear_bit(bit, sbinfo->si_xib_buf);
34480 + sbinfo->si_xib_next_bit = bit;
34482 + mutex_unlock(&sbinfo->si_xib_mtx);
34485 +/* for s_op->delete_inode() */
34486 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
34489 + unsigned int mnt_flags;
34490 + aufs_bindex_t bindex, bend, bi;
34491 + unsigned char try_trunc;
34492 + struct au_iinfo *iinfo;
34493 + struct super_block *sb;
34494 + struct au_hinode *hi;
34495 + struct inode *h_inode;
34496 + struct au_branch *br;
34497 + vfs_writef_t xwrite;
34499 + sb = inode->i_sb;
34500 + mnt_flags = au_mntflags(sb);
34501 + if (!au_opt_test(mnt_flags, XINO)
34502 + || inode->i_ino == AUFS_ROOT_INO)
34506 + au_xigen_inc(inode);
34507 + au_xib_clear_bit(inode);
34510 + iinfo = au_ii(inode);
34514 + bindex = iinfo->ii_bstart;
34518 + xwrite = au_sbi(sb)->si_xwrite;
34519 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
34520 + hi = iinfo->ii_hinode + bindex;
34521 + bend = iinfo->ii_bend;
34522 + for (; bindex <= bend; bindex++, hi++) {
34523 + h_inode = hi->hi_inode;
34525 + || (!unlinked && h_inode->i_nlink))
34528 + /* inode may not be revalidated */
34529 + bi = au_br_index(sb, hi->hi_id);
34533 + br = au_sbr(sb, bi);
34534 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
34535 + h_inode->i_ino, /*ino*/0);
34536 + if (!err && try_trunc
34537 + && au_test_fs_trunc_xino(au_br_sb(br)))
34538 + xino_try_trunc(sb, br);
34542 +/* get an unused inode number from bitmap */
34543 +ino_t au_xino_new_ino(struct super_block *sb)
34546 + unsigned long *p, pindex, ul, pend;
34547 + struct au_sbinfo *sbinfo;
34548 + struct file *file;
34549 + int free_bit, err;
34551 + if (!au_opt_test(au_mntflags(sb), XINO))
34552 + return iunique(sb, AUFS_FIRST_INO);
34554 + sbinfo = au_sbi(sb);
34555 + mutex_lock(&sbinfo->si_xib_mtx);
34556 + p = sbinfo->si_xib_buf;
34557 + free_bit = sbinfo->si_xib_next_bit;
34558 + if (free_bit < page_bits && !test_bit(free_bit, p))
34559 + goto out; /* success */
34560 + free_bit = find_first_zero_bit(p, page_bits);
34561 + if (free_bit < page_bits)
34562 + goto out; /* success */
34564 + pindex = sbinfo->si_xib_last_pindex;
34565 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
34566 + err = xib_pindex(sb, ul);
34567 + if (unlikely(err))
34569 + free_bit = find_first_zero_bit(p, page_bits);
34570 + if (free_bit < page_bits)
34571 + goto out; /* success */
34574 + file = sbinfo->si_xib;
34575 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
34576 + for (ul = pindex + 1; ul <= pend; ul++) {
34577 + err = xib_pindex(sb, ul);
34578 + if (unlikely(err))
34580 + free_bit = find_first_zero_bit(p, page_bits);
34581 + if (free_bit < page_bits)
34582 + goto out; /* success */
34587 + set_bit(free_bit, p);
34588 + sbinfo->si_xib_next_bit = free_bit + 1;
34589 + pindex = sbinfo->si_xib_last_pindex;
34590 + mutex_unlock(&sbinfo->si_xib_mtx);
34591 + ino = xib_calc_ino(pindex, free_bit);
34592 + AuDbg("i%lu\n", (unsigned long)ino);
34595 + mutex_unlock(&sbinfo->si_xib_mtx);
34601 + * read @ino from xinofile for the specified branch{@sb, @bindex}
34602 + * at the position of @h_ino.
34603 + * if @ino does not exist and @do_new is true, get new one.
34605 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34611 + struct file *file;
34612 + struct au_sbinfo *sbinfo;
34615 + if (!au_opt_test(au_mntflags(sb), XINO))
34616 + return 0; /* no xino */
34619 + sbinfo = au_sbi(sb);
34621 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
34622 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34625 + pos *= sizeof(*ino);
34627 + file = au_sbr(sb, bindex)->br_xino.xi_file;
34628 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
34629 + return 0; /* no ino */
34631 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
34632 + if (sz == sizeof(*ino))
34633 + return 0; /* success */
34636 + if (unlikely(sz >= 0)) {
34638 + AuIOErr("xino read error (%zd)\n", sz);
34644 +/* ---------------------------------------------------------------------- */
34646 +/* create and set a new xino file */
34648 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
34650 + struct file *file;
34651 + struct dentry *h_parent, *d;
34652 + struct inode *h_dir, *inode;
34656 + * at mount-time, and the xino file is the default path,
34657 + * hnotify is disabled so we have no notify events to ignore.
34658 + * when a user specified the xino, we cannot get au_hdir to be ignored.
34660 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34661 + /* | __FMODE_NONOTIFY */,
34662 + S_IRUGO | S_IWUGO);
34663 + if (IS_ERR(file)) {
34665 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
34669 + /* keep file count */
34671 + inode = file_inode(file);
34672 + h_parent = dget_parent(file->f_path.dentry);
34673 + h_dir = d_inode(h_parent);
34674 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
34675 + /* mnt_want_write() is unnecessary here */
34676 + /* no delegation since it is just created */
34677 + if (inode->i_nlink)
34678 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
34680 + mutex_unlock(&h_dir->i_mutex);
34682 + if (unlikely(err)) {
34684 + pr_err("unlink %s(%d)\n", fname, err);
34689 + d = file->f_path.dentry;
34690 + if (unlikely(sb == d->d_sb)) {
34692 + pr_err("%s must be outside\n", fname);
34695 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
34697 + pr_err("xino doesn't support %s(%s)\n",
34698 + fname, au_sbtype(d->d_sb));
34701 + return file; /* success */
34705 + file = ERR_PTR(err);
34710 + * find another branch who is on the same filesystem of the specified
34711 + * branch{@btgt}. search until @bend.
34713 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
34714 + aufs_bindex_t bend)
34716 + aufs_bindex_t bindex;
34717 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
34719 + for (bindex = 0; bindex < btgt; bindex++)
34720 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34722 + for (bindex++; bindex <= bend; bindex++)
34723 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34728 +/* ---------------------------------------------------------------------- */
34731 + * initialize the xinofile for the specified branch @br
34732 + * at the place/path where @base_file indicates.
34733 + * test whether another branch is on the same filesystem or not,
34734 + * if @do_test is true.
34736 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
34737 + struct file *base_file, int do_test)
34741 + aufs_bindex_t bend, bindex;
34742 + struct au_branch *shared_br, *b;
34743 + struct file *file;
34744 + struct super_block *tgt_sb;
34746 + shared_br = NULL;
34747 + bend = au_sbend(sb);
34749 + tgt_sb = au_br_sb(br);
34750 + for (bindex = 0; bindex <= bend; bindex++) {
34751 + b = au_sbr(sb, bindex);
34752 + if (tgt_sb == au_br_sb(b)) {
34759 + if (!shared_br || !shared_br->br_xino.xi_file) {
34760 + struct au_xino_lock_dir ldir;
34762 + au_xino_lock_dir(sb, base_file, &ldir);
34763 + /* mnt_want_write() is unnecessary here */
34764 + file = au_xino_create2(base_file, NULL);
34765 + au_xino_unlock_dir(&ldir);
34766 + err = PTR_ERR(file);
34767 + if (IS_ERR(file))
34769 + br->br_xino.xi_file = file;
34771 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
34772 + get_file(br->br_xino.xi_file);
34775 + ino = AUFS_ROOT_INO;
34776 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34778 + if (unlikely(err)) {
34779 + fput(br->br_xino.xi_file);
34780 + br->br_xino.xi_file = NULL;
34787 +/* ---------------------------------------------------------------------- */
34789 +/* trucate a xino bitmap file */
34792 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
34796 + unsigned long pindex;
34797 + loff_t pos, pend;
34798 + struct au_sbinfo *sbinfo;
34799 + vfs_readf_t func;
34801 + unsigned long *p;
34804 + sbinfo = au_sbi(sb);
34805 + MtxMustLock(&sbinfo->si_xib_mtx);
34806 + p = sbinfo->si_xib_buf;
34807 + func = sbinfo->si_xread;
34808 + pend = vfsub_f_size_read(file);
34810 + while (pos < pend) {
34811 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
34813 + if (unlikely(sz <= 0))
34817 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
34818 + if (unlikely(*ino < AUFS_FIRST_INO))
34821 + xib_calc_bit(*ino, &pindex, &bit);
34822 + AuDebugOn(page_bits <= bit);
34823 + err = xib_pindex(sb, pindex);
34835 +static int xib_restore(struct super_block *sb)
34838 + aufs_bindex_t bindex, bend;
34842 + page = (void *)__get_free_page(GFP_NOFS);
34843 + if (unlikely(!page))
34847 + bend = au_sbend(sb);
34848 + for (bindex = 0; !err && bindex <= bend; bindex++)
34849 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
34850 + err = do_xib_restore
34851 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
34853 + AuDbg("b%d\n", bindex);
34854 + free_page((unsigned long)page);
34860 +int au_xib_trunc(struct super_block *sb)
34865 + struct au_xino_lock_dir ldir;
34866 + struct au_sbinfo *sbinfo;
34867 + unsigned long *p;
34868 + struct file *file;
34870 + SiMustWriteLock(sb);
34873 + sbinfo = au_sbi(sb);
34874 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
34877 + file = sbinfo->si_xib;
34878 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
34881 + au_xino_lock_dir(sb, file, &ldir);
34882 + /* mnt_want_write() is unnecessary here */
34883 + file = au_xino_create2(sbinfo->si_xib, NULL);
34884 + au_xino_unlock_dir(&ldir);
34885 + err = PTR_ERR(file);
34886 + if (IS_ERR(file))
34888 + fput(sbinfo->si_xib);
34889 + sbinfo->si_xib = file;
34891 + p = sbinfo->si_xib_buf;
34892 + memset(p, 0, PAGE_SIZE);
34894 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
34895 + if (unlikely(sz != PAGE_SIZE)) {
34897 + AuIOErr("err %d\n", err);
34903 + mutex_lock(&sbinfo->si_xib_mtx);
34904 + /* mnt_want_write() is unnecessary here */
34905 + err = xib_restore(sb);
34906 + mutex_unlock(&sbinfo->si_xib_mtx);
34912 +/* ---------------------------------------------------------------------- */
34915 + * xino mount option handlers
34919 +static void xino_clear_xib(struct super_block *sb)
34921 + struct au_sbinfo *sbinfo;
34923 + SiMustWriteLock(sb);
34925 + sbinfo = au_sbi(sb);
34926 + sbinfo->si_xread = NULL;
34927 + sbinfo->si_xwrite = NULL;
34928 + if (sbinfo->si_xib)
34929 + fput(sbinfo->si_xib);
34930 + sbinfo->si_xib = NULL;
34931 + free_page((unsigned long)sbinfo->si_xib_buf);
34932 + sbinfo->si_xib_buf = NULL;
34935 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
34939 + struct au_sbinfo *sbinfo;
34940 + struct file *file;
34942 + SiMustWriteLock(sb);
34944 + sbinfo = au_sbi(sb);
34945 + file = au_xino_create2(base, sbinfo->si_xib);
34946 + err = PTR_ERR(file);
34947 + if (IS_ERR(file))
34949 + if (sbinfo->si_xib)
34950 + fput(sbinfo->si_xib);
34951 + sbinfo->si_xib = file;
34952 + sbinfo->si_xread = vfs_readf(file);
34953 + sbinfo->si_xwrite = vfs_writef(file);
34956 + if (!sbinfo->si_xib_buf)
34957 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
34958 + if (unlikely(!sbinfo->si_xib_buf))
34961 + sbinfo->si_xib_last_pindex = 0;
34962 + sbinfo->si_xib_next_bit = 0;
34963 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
34965 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
34966 + PAGE_SIZE, &pos);
34967 + if (unlikely(err != PAGE_SIZE))
34971 + goto out; /* success */
34974 + free_page((unsigned long)sbinfo->si_xib_buf);
34975 + sbinfo->si_xib_buf = NULL;
34979 + fput(sbinfo->si_xib);
34980 + sbinfo->si_xib = NULL;
34981 + sbinfo->si_xread = NULL;
34982 + sbinfo->si_xwrite = NULL;
34987 +/* xino for each branch */
34988 +static void xino_clear_br(struct super_block *sb)
34990 + aufs_bindex_t bindex, bend;
34991 + struct au_branch *br;
34993 + bend = au_sbend(sb);
34994 + for (bindex = 0; bindex <= bend; bindex++) {
34995 + br = au_sbr(sb, bindex);
34996 + if (!br || !br->br_xino.xi_file)
34999 + fput(br->br_xino.xi_file);
35000 + br->br_xino.xi_file = NULL;
35004 +static int au_xino_set_br(struct super_block *sb, struct file *base)
35008 + aufs_bindex_t bindex, bend, bshared;
35010 + struct file *old, *new;
35012 + struct au_branch *br;
35013 + struct inode *inode;
35014 + vfs_writef_t writef;
35016 + SiMustWriteLock(sb);
35019 + bend = au_sbend(sb);
35020 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
35021 + if (unlikely(!fpair))
35024 + inode = d_inode(sb->s_root);
35025 + ino = AUFS_ROOT_INO;
35026 + writef = au_sbi(sb)->si_xwrite;
35027 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
35028 + br = au_sbr(sb, bindex);
35029 + bshared = is_sb_shared(sb, bindex, bindex - 1);
35030 + if (bshared >= 0) {
35031 + /* shared xino */
35032 + *p = fpair[bshared];
35033 + get_file(p->new);
35038 + p->old = br->br_xino.xi_file;
35039 + p->new = au_xino_create2(base, br->br_xino.xi_file);
35040 + err = PTR_ERR(p->new);
35041 + if (IS_ERR(p->new)) {
35047 + err = au_xino_do_write(writef, p->new,
35048 + au_h_iptr(inode, bindex)->i_ino, ino);
35049 + if (unlikely(err))
35053 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
35054 + br = au_sbr(sb, bindex);
35055 + if (br->br_xino.xi_file)
35056 + fput(br->br_xino.xi_file);
35057 + get_file(p->new);
35058 + br->br_xino.xi_file = p->new;
35062 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
35072 +void au_xino_clr(struct super_block *sb)
35074 + struct au_sbinfo *sbinfo;
35076 + au_xigen_clr(sb);
35077 + xino_clear_xib(sb);
35078 + xino_clear_br(sb);
35079 + sbinfo = au_sbi(sb);
35080 + /* lvalue, do not call au_mntflags() */
35081 + au_opt_clr(sbinfo->si_mntflags, XINO);
35084 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
35087 + struct dentry *parent, *cur_parent;
35088 + struct qstr *dname, *cur_name;
35089 + struct file *cur_xino;
35090 + struct inode *dir;
35091 + struct au_sbinfo *sbinfo;
35093 + SiMustWriteLock(sb);
35096 + sbinfo = au_sbi(sb);
35097 + parent = dget_parent(xino->file->f_path.dentry);
35100 + dname = &xino->file->f_path.dentry->d_name;
35101 + cur_xino = sbinfo->si_xib;
35103 + cur_parent = dget_parent(cur_xino->f_path.dentry);
35104 + cur_name = &cur_xino->f_path.dentry->d_name;
35105 + skip = (cur_parent == parent
35106 + && au_qstreq(dname, cur_name));
35107 + dput(cur_parent);
35113 + au_opt_set(sbinfo->si_mntflags, XINO);
35114 + dir = d_inode(parent);
35115 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
35116 + /* mnt_want_write() is unnecessary here */
35117 + err = au_xino_set_xib(sb, xino->file);
35119 + err = au_xigen_set(sb, xino->file);
35121 + err = au_xino_set_br(sb, xino->file);
35122 + mutex_unlock(&dir->i_mutex);
35124 + goto out; /* success */
35127 + AuIOErr("failed creating xino(%d).\n", err);
35128 + au_xigen_clr(sb);
35129 + xino_clear_xib(sb);
35136 +/* ---------------------------------------------------------------------- */
35139 + * create a xinofile at the default place/path.
35141 +struct file *au_xino_def(struct super_block *sb)
35143 + struct file *file;
35145 + struct au_branch *br;
35146 + struct super_block *h_sb;
35147 + struct path path;
35148 + aufs_bindex_t bend, bindex, bwr;
35151 + bend = au_sbend(sb);
35153 + for (bindex = 0; bindex <= bend; bindex++) {
35154 + br = au_sbr(sb, bindex);
35155 + if (au_br_writable(br->br_perm)
35156 + && !au_test_fs_bad_xino(au_br_sb(br))) {
35163 + file = ERR_PTR(-ENOMEM);
35164 + page = (void *)__get_free_page(GFP_NOFS);
35165 + if (unlikely(!page))
35167 + path.mnt = au_br_mnt(br);
35168 + path.dentry = au_h_dptr(sb->s_root, bwr);
35169 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
35170 + file = (void *)p;
35171 + if (!IS_ERR(p)) {
35172 + strcat(p, "/" AUFS_XINO_FNAME);
35173 + AuDbg("%s\n", p);
35174 + file = au_xino_create(sb, p, /*silent*/0);
35175 + if (!IS_ERR(file))
35176 + au_xino_brid_set(sb, br->br_id);
35178 + free_page((unsigned long)page);
35180 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
35181 + if (IS_ERR(file))
35183 + h_sb = file->f_path.dentry->d_sb;
35184 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
35185 + pr_err("xino doesn't support %s(%s)\n",
35186 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
35188 + file = ERR_PTR(-EINVAL);
35190 + if (!IS_ERR(file))
35191 + au_xino_brid_set(sb, -1);
35198 +/* ---------------------------------------------------------------------- */
35200 +int au_xino_path(struct seq_file *seq, struct file *file)
35204 + err = au_seq_path(seq, &file->f_path);
35205 + if (unlikely(err))
35208 +#define Deleted "\\040(deleted)"
35209 + seq->count -= sizeof(Deleted) - 1;
35210 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
35211 + sizeof(Deleted) - 1));
35217 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
35218 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
35219 +++ linux/include/uapi/linux/aufs_type.h 2016-02-28 11:26:32.576637942 +0100
35222 + * Copyright (C) 2005-2016 Junjiro R. Okajima
35224 + * This program, aufs is free software; you can redistribute it and/or modify
35225 + * it under the terms of the GNU General Public License as published by
35226 + * the Free Software Foundation; either version 2 of the License, or
35227 + * (at your option) any later version.
35229 + * This program is distributed in the hope that it will be useful,
35230 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35231 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35232 + * GNU General Public License for more details.
35234 + * You should have received a copy of the GNU General Public License
35235 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35238 +#ifndef __AUFS_TYPE_H__
35239 +#define __AUFS_TYPE_H__
35241 +#define AUFS_NAME "aufs"
35245 + * define it before including all other headers.
35246 + * sched.h may use pr_* macros before defining "current", so define the
35247 + * no-current version first, and re-define later.
35249 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
35250 +#include <linux/sched.h>
35252 +#define pr_fmt(fmt) \
35253 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
35254 + (int)sizeof(current->comm), current->comm, current->pid
35256 +#include <stdint.h>
35257 +#include <sys/types.h>
35258 +#endif /* __KERNEL__ */
35260 +#include <linux/limits.h>
35262 +#define AUFS_VERSION "4.4-20160223"
35264 +/* todo? move this to linux-2.6.19/include/magic.h */
35265 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
35267 +/* ---------------------------------------------------------------------- */
35269 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
35270 +typedef int8_t aufs_bindex_t;
35271 +#define AUFS_BRANCH_MAX 127
35273 +typedef int16_t aufs_bindex_t;
35274 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
35275 +#define AUFS_BRANCH_MAX 511
35276 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
35277 +#define AUFS_BRANCH_MAX 1023
35278 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
35279 +#define AUFS_BRANCH_MAX 32767
35284 +#ifndef AUFS_BRANCH_MAX
35285 +#error unknown CONFIG_AUFS_BRANCH_MAX value
35287 +#endif /* __KERNEL__ */
35289 +/* ---------------------------------------------------------------------- */
35291 +#define AUFS_FSTYPE AUFS_NAME
35293 +#define AUFS_ROOT_INO 2
35294 +#define AUFS_FIRST_INO 11
35296 +#define AUFS_WH_PFX ".wh."
35297 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
35298 +#define AUFS_WH_TMP_LEN 4
35299 +/* a limit for rmdir/rename a dir and copyup */
35300 +#define AUFS_MAX_NAMELEN (NAME_MAX \
35301 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
35303 + - AUFS_WH_TMP_LEN) /* hex */
35304 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
35305 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
35306 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
35307 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
35308 +#define AUFS_DIRWH_DEF 3
35309 +#define AUFS_RDCACHE_DEF 10 /* seconds */
35310 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
35311 +#define AUFS_RDBLK_DEF 512 /* bytes */
35312 +#define AUFS_RDHASH_DEF 32
35313 +#define AUFS_WKQ_NAME AUFS_NAME "d"
35314 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
35315 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
35316 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
35317 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
35319 +/* pseudo-link maintenace under /proc */
35320 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
35321 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
35322 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
35324 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
35325 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
35327 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
35328 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
35329 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
35331 +/* doubly whiteouted */
35332 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
35333 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
35334 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
35336 +/* branch permissions and attributes */
35337 +#define AUFS_BRPERM_RW "rw"
35338 +#define AUFS_BRPERM_RO "ro"
35339 +#define AUFS_BRPERM_RR "rr"
35340 +#define AUFS_BRATTR_COO_REG "coo_reg"
35341 +#define AUFS_BRATTR_COO_ALL "coo_all"
35342 +#define AUFS_BRATTR_FHSM "fhsm"
35343 +#define AUFS_BRATTR_UNPIN "unpin"
35344 +#define AUFS_BRATTR_ICEX "icex"
35345 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
35346 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
35347 +#define AUFS_BRATTR_ICEX_TR "icextr"
35348 +#define AUFS_BRATTR_ICEX_USR "icexusr"
35349 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
35350 +#define AUFS_BRRATTR_WH "wh"
35351 +#define AUFS_BRWATTR_NLWH "nolwh"
35352 +#define AUFS_BRWATTR_MOO "moo"
35354 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
35355 +#define AuBrPerm_RO (1 << 1) /* readonly */
35356 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
35357 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
35359 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
35360 +#define AuBrAttr_COO_ALL (1 << 4)
35361 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
35363 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
35364 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
35365 + branch. meaningless since
35366 + linux-3.18-rc1 */
35368 +/* ignore error in copying XATTR */
35369 +#define AuBrAttr_ICEX_SEC (1 << 7)
35370 +#define AuBrAttr_ICEX_SYS (1 << 8)
35371 +#define AuBrAttr_ICEX_TR (1 << 9)
35372 +#define AuBrAttr_ICEX_USR (1 << 10)
35373 +#define AuBrAttr_ICEX_OTH (1 << 11)
35374 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
35375 + | AuBrAttr_ICEX_SYS \
35376 + | AuBrAttr_ICEX_TR \
35377 + | AuBrAttr_ICEX_USR \
35378 + | AuBrAttr_ICEX_OTH)
35380 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
35381 +#define AuBrRAttr_Mask AuBrRAttr_WH
35383 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
35384 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
35385 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
35387 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
35389 +/* #warning test userspace */
35391 +#ifndef CONFIG_AUFS_FHSM
35392 +#undef AuBrAttr_FHSM
35393 +#define AuBrAttr_FHSM 0
35395 +#ifndef CONFIG_AUFS_XATTR
35396 +#undef AuBrAttr_ICEX
35397 +#define AuBrAttr_ICEX 0
35398 +#undef AuBrAttr_ICEX_SEC
35399 +#define AuBrAttr_ICEX_SEC 0
35400 +#undef AuBrAttr_ICEX_SYS
35401 +#define AuBrAttr_ICEX_SYS 0
35402 +#undef AuBrAttr_ICEX_TR
35403 +#define AuBrAttr_ICEX_TR 0
35404 +#undef AuBrAttr_ICEX_USR
35405 +#define AuBrAttr_ICEX_USR 0
35406 +#undef AuBrAttr_ICEX_OTH
35407 +#define AuBrAttr_ICEX_OTH 0
35411 +/* the longest combination */
35412 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
35413 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
35414 + "+" AUFS_BRATTR_COO_REG \
35415 + "+" AUFS_BRATTR_FHSM \
35416 + "+" AUFS_BRATTR_UNPIN \
35417 + "+" AUFS_BRATTR_ICEX_SEC \
35418 + "+" AUFS_BRATTR_ICEX_SYS \
35419 + "+" AUFS_BRATTR_ICEX_USR \
35420 + "+" AUFS_BRATTR_ICEX_OTH \
35421 + "+" AUFS_BRWATTR_NLWH)
35424 + char a[AuBrPermStrSz];
35425 +} au_br_perm_str_t;
35427 +static inline int au_br_writable(int brperm)
35429 + return brperm & AuBrPerm_RW;
35432 +static inline int au_br_whable(int brperm)
35434 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
35437 +static inline int au_br_wh_linkable(int brperm)
35439 + return !(brperm & AuBrWAttr_NoLinkWH);
35442 +static inline int au_br_cmoo(int brperm)
35444 + return brperm & AuBrAttr_CMOO_Mask;
35447 +static inline int au_br_fhsm(int brperm)
35449 + return brperm & AuBrAttr_FHSM;
35452 +/* ---------------------------------------------------------------------- */
35456 + /* readdir in userspace */
35460 + AuCtl_WBR_FD, /* pathconf wrapper */
35461 + AuCtl_IBUSY, /* busy inode */
35462 + AuCtl_MVDOWN, /* move-down */
35463 + AuCtl_BR, /* info about branches */
35464 + AuCtl_FHSM_FD /* connection for fhsm */
35467 +/* borrowed from linux/include/linux/kernel.h */
35469 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
35470 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
35473 +/* borrowed from linux/include/linux/compiler-gcc3.h */
35475 +#define __aligned(x) __attribute__((aligned(x)))
35480 +#define __packed __attribute__((packed))
35484 +struct au_rdu_cookie {
35489 + uint32_t generation;
35492 +struct au_rdu_ent {
35501 +static inline int au_rdu_len(int nlen)
35503 + /* include the terminating NULL */
35504 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
35505 + sizeof(uint64_t));
35508 +union au_rdu_ent_ul {
35509 + struct au_rdu_ent __user *e;
35521 + uint64_t sz; /* AuCtl_RDU */
35522 + uint64_t nent; /* AuCtl_RDU_INO */
35524 + union au_rdu_ent_ul ent;
35525 + uint16_t verify[AufsCtlRduV_End];
35527 + /* input/output */
35531 + union au_rdu_ent_ul tail;
35532 + /* number of entries which were added in a single call */
35537 + struct au_rdu_cookie cookie;
35540 +/* ---------------------------------------------------------------------- */
35542 +struct aufs_wbr_fd {
35547 +/* ---------------------------------------------------------------------- */
35549 +struct aufs_ibusy {
35550 + uint64_t ino, h_ino;
35554 +/* ---------------------------------------------------------------------- */
35556 +/* error code for move-down */
35557 +/* the actual message strings are implemented in aufs-util.git */
35559 + EAU_MVDOWN_OPAQUE = 1,
35560 + EAU_MVDOWN_WHITEOUT,
35561 + EAU_MVDOWN_UPPER,
35562 + EAU_MVDOWN_BOTTOM,
35563 + EAU_MVDOWN_NOUPPER,
35564 + EAU_MVDOWN_NOLOWERBR,
35568 +/* flags for move-down */
35569 +#define AUFS_MVDOWN_DMSG 1
35570 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
35571 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
35572 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
35573 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
35574 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
35575 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
35576 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
35577 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
35578 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
35579 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
35580 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
35581 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
35583 +/* index for move-down */
35585 + AUFS_MVDOWN_UPPER,
35586 + AUFS_MVDOWN_LOWER,
35587 + AUFS_MVDOWN_NARRAY
35591 + * additional info of move-down
35592 + * number of free blocks and inodes.
35593 + * subset of struct kstatfs, but smaller and always 64bit.
35595 +struct aufs_stfs {
35596 + uint64_t f_blocks;
35597 + uint64_t f_bavail;
35598 + uint64_t f_files;
35599 + uint64_t f_ffree;
35602 +struct aufs_stbr {
35603 + int16_t brid; /* optional input */
35604 + int16_t bindex; /* output */
35605 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
35608 +struct aufs_mvdown {
35609 + uint32_t flags; /* input/output */
35610 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
35611 + int8_t au_errno; /* output */
35614 +/* ---------------------------------------------------------------------- */
35616 +union aufs_brinfo {
35617 + /* PATH_MAX may differ between kernel-space and user-space */
35618 + char _spacer[4096];
35626 +/* ---------------------------------------------------------------------- */
35628 +#define AuCtlType 'A'
35629 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
35630 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
35631 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
35632 + struct aufs_wbr_fd)
35633 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
35634 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
35635 + struct aufs_mvdown)
35636 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
35637 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
35639 +#endif /* __AUFS_TYPE_H__ */
35640 aufs4.4 loopback patch
35642 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
35643 index abfdd2b..a2e3c43 100644
35644 --- a/drivers/block/loop.c
35645 +++ b/drivers/block/loop.c
35646 @@ -556,7 +556,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
35649 struct switch_request {
35650 - struct file *file;
35651 + struct file *file, *virt_file;
35652 struct completion wait;
35655 @@ -582,6 +582,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35656 mapping = file->f_mapping;
35657 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
35658 lo->lo_backing_file = file;
35659 + lo->lo_backing_virt_file = p->virt_file;
35660 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
35661 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
35662 lo->old_gfp_mask = mapping_gfp_mask(mapping);
35663 @@ -594,11 +595,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35664 * First it needs to flush existing IO, it does this by sending a magic
35665 * BIO down the pipe. The completion of this BIO does the actual switch.
35667 -static int loop_switch(struct loop_device *lo, struct file *file)
35668 +static int loop_switch(struct loop_device *lo, struct file *file,
35669 + struct file *virt_file)
35671 struct switch_request w;
35674 + w.virt_file = virt_file;
35676 /* freeze queue and wait for completion of scheduled requests */
35677 blk_mq_freeze_queue(lo->lo_queue);
35678 @@ -617,7 +620,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
35680 static int loop_flush(struct loop_device *lo)
35682 - return loop_switch(lo, NULL);
35683 + return loop_switch(lo, NULL, NULL);
35686 +static struct file *loop_real_file(struct file *file)
35688 + struct file *f = NULL;
35690 + if (file->f_path.dentry->d_sb->s_op->real_loop)
35691 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
35695 static void loop_reread_partitions(struct loop_device *lo,
35696 @@ -654,6 +666,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35699 struct file *file, *old_file;
35700 + struct file *f, *virt_file = NULL, *old_virt_file;
35701 struct inode *inode;
35704 @@ -670,9 +683,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35708 + f = loop_real_file(file);
35710 + virt_file = file;
35715 inode = file->f_mapping->host;
35716 old_file = lo->lo_backing_file;
35717 + old_virt_file = lo->lo_backing_virt_file;
35721 @@ -684,17 +704,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35724 /* and ... switch */
35725 - error = loop_switch(lo, file);
35726 + error = loop_switch(lo, file, virt_file);
35731 + if (old_virt_file)
35732 + fput(old_virt_file);
35733 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
35734 loop_reread_partitions(lo, bdev);
35744 @@ -881,7 +905,7 @@ static int loop_prepare_queue(struct loop_device *lo)
35745 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35746 struct block_device *bdev, unsigned int arg)
35748 - struct file *file, *f;
35749 + struct file *file, *f, *virt_file = NULL;
35750 struct inode *inode;
35751 struct address_space *mapping;
35752 unsigned lo_blocksize;
35753 @@ -896,6 +920,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35757 + f = loop_real_file(file);
35759 + virt_file = file;
35765 if (lo->lo_state != Lo_unbound)
35766 @@ -948,6 +978,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35767 lo->lo_device = bdev;
35768 lo->lo_flags = lo_flags;
35769 lo->lo_backing_file = file;
35770 + lo->lo_backing_virt_file = virt_file;
35771 lo->transfer = NULL;
35773 lo->lo_sizelimit = 0;
35774 @@ -980,6 +1011,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35781 /* This is safe: open() is still holding a reference. */
35782 module_put(THIS_MODULE);
35783 @@ -1026,6 +1059,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
35784 static int loop_clr_fd(struct loop_device *lo)
35786 struct file *filp = lo->lo_backing_file;
35787 + struct file *virt_filp = lo->lo_backing_virt_file;
35788 gfp_t gfp = lo->old_gfp_mask;
35789 struct block_device *bdev = lo->lo_device;
35791 @@ -1057,6 +1091,7 @@ static int loop_clr_fd(struct loop_device *lo)
35792 spin_lock_irq(&lo->lo_lock);
35793 lo->lo_state = Lo_rundown;
35794 lo->lo_backing_file = NULL;
35795 + lo->lo_backing_virt_file = NULL;
35796 spin_unlock_irq(&lo->lo_lock);
35798 loop_release_xfer(lo);
35799 @@ -1101,6 +1136,8 @@ static int loop_clr_fd(struct loop_device *lo)
35800 * bd_mutex which is usually taken before lo_ctl_mutex.
35808 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
35809 index fb2237c..c3888c5 100644
35810 --- a/drivers/block/loop.h
35811 +++ b/drivers/block/loop.h
35812 @@ -46,7 +46,7 @@ struct loop_device {
35813 int (*ioctl)(struct loop_device *, int cmd,
35814 unsigned long arg);
35816 - struct file * lo_backing_file;
35817 + struct file * lo_backing_file, *lo_backing_virt_file;
35818 struct block_device *lo_device;
35819 unsigned lo_blocksize;
35821 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
35822 index 2baacd7..22bcb89 100644
35823 --- a/fs/aufs/f_op.c
35824 +++ b/fs/aufs/f_op.c
35825 @@ -399,7 +399,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
35826 if (IS_ERR(h_file))
35829 - if (au_test_loopback_kthread()) {
35830 + if (0 && au_test_loopback_kthread()) {
35831 au_warn_loopback(h_file->f_path.dentry->d_sb);
35832 if (file->f_mapping != h_file->f_mapping) {
35833 file->f_mapping = h_file->f_mapping;
35834 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
35835 index 5711e7a..9df5d16 100644
35836 --- a/fs/aufs/loop.c
35837 +++ b/fs/aufs/loop.c
35838 @@ -131,3 +131,19 @@ void au_loopback_fin(void)
35839 symbol_put(loop_backing_file);
35840 kfree(au_warn_loopback_array);
35843 +/* ---------------------------------------------------------------------- */
35845 +/* support the loopback block device insude aufs */
35847 +struct file *aufs_real_loop(struct file *file)
35851 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
35852 + fi_read_lock(file);
35853 + f = au_hf_top(file);
35854 + fi_read_unlock(file);
35858 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
35859 index 48bf070..66afec7 100644
35860 --- a/fs/aufs/loop.h
35861 +++ b/fs/aufs/loop.h
35862 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
35864 int au_loopback_init(void);
35865 void au_loopback_fin(void);
35867 +struct file *aufs_real_loop(struct file *file);
35869 +AuStub(struct file *, loop_backing_file, return NULL)
35871 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
35872 struct dentry *h_adding)
35873 AuStubInt0(au_test_loopback_kthread, void)
35874 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
35876 AuStubInt0(au_loopback_init, void)
35877 AuStubVoid(au_loopback_fin, void)
35879 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
35880 #endif /* BLK_DEV_LOOP */
35882 #endif /* __KERNEL__ */
35883 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
35884 index b41d789..51d2fb9 100644
35885 --- a/fs/aufs/super.c
35886 +++ b/fs/aufs/super.c
35887 @@ -832,7 +832,10 @@ static const struct super_operations aufs_sop = {
35888 .statfs = aufs_statfs,
35889 .put_super = aufs_put_super,
35890 .sync_fs = aufs_sync_fs,
35891 - .remount_fs = aufs_remount_fs
35892 + .remount_fs = aufs_remount_fs,
35893 +#ifdef CONFIG_AUFS_BDEV_LOOP
35894 + .real_loop = aufs_real_loop
35898 /* ---------------------------------------------------------------------- */
35899 diff --git a/include/linux/fs.h b/include/linux/fs.h
35900 index 8d48506..5246785 100644
35901 --- a/include/linux/fs.h
35902 +++ b/include/linux/fs.h
35903 @@ -1719,6 +1719,10 @@ struct super_operations {
35904 struct shrink_control *);
35905 long (*free_cached_objects)(struct super_block *,
35906 struct shrink_control *);
35907 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
35909 + struct file *(*real_loop)(struct file *);