1 aufs4.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 011f433..b1083f6 100644
7 @@ -218,6 +218,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 cb92fd4..8c2df12 100644
19 @@ -127,3 +127,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 1a0006a..ddad01a 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
36 aufs4.x-rcN base patch
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index d8afd29..feac5ea 100644
42 @@ -1880,6 +1880,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 d7173cb..0160952 100644
64 --- a/drivers/block/loop.c
65 +++ b/drivers/block/loop.c
66 @@ -540,6 +540,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 37b5afd..bc261e2 100644
95 @@ -1164,7 +1164,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 bfe62ae..fa5eee5 100644
141 @@ -1101,8 +1101,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 @@ -1118,9 +1118,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 35ec87e..3229f97 100644
179 --- a/include/linux/fs.h
180 +++ b/include/linux/fs.h
181 @@ -1649,6 +1649,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);
209 aufs4.x-rcN mmap patch
211 diff --git a/fs/buffer.c b/fs/buffer.c
212 index c7a5602..8c50a22 100644
215 @@ -2450,7 +2450,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
216 * Update file times before taking page lock. We may end up failing the
217 * fault so this update may be superfluous but who really cares...
219 - file_update_time(vma->vm_file);
220 + vma_file_update_time(vma);
222 ret = __block_page_mkwrite(vma, vmf, get_block);
223 sb_end_pagefault(sb);
224 diff --git a/fs/proc/base.c b/fs/proc/base.c
225 index 093ca14..fc1ac03 100644
228 @@ -1744,7 +1744,7 @@ static int proc_map_files_get_link(struct dentry *dentry, struct path *path)
229 down_read(&mm->mmap_sem);
230 vma = find_exact_vma(mm, vm_start, vm_end);
231 if (vma && vma->vm_file) {
232 - *path = vma->vm_file->f_path;
233 + *path = vma_pr_or_file(vma)->f_path;
237 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
238 index d4a3574..1397181 100644
239 --- a/fs/proc/nommu.c
240 +++ b/fs/proc/nommu.c
241 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
242 file = region->vm_file;
245 - struct inode *inode = file_inode(region->vm_file);
246 + struct inode *inode;
248 + file = vmr_pr_or_file(region);
249 + inode = file_inode(file);
250 dev = inode->i_sb->s_dev;
253 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
254 index 6dee68d..9afa35d 100644
255 --- a/fs/proc/task_mmu.c
256 +++ b/fs/proc/task_mmu.c
257 @@ -279,7 +279,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
258 const char *name = NULL;
261 - struct inode *inode = file_inode(vma->vm_file);
262 + struct inode *inode;
264 + file = vma_pr_or_file(vma);
265 + inode = file_inode(file);
266 dev = inode->i_sb->s_dev;
268 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
269 @@ -1479,7 +1482,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
270 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
271 struct vm_area_struct *vma = v;
272 struct numa_maps *md = &numa_priv->md;
273 - struct file *file = vma->vm_file;
274 + struct file *file = vma_pr_or_file(vma);
275 struct mm_struct *mm = vma->vm_mm;
276 struct mm_walk walk = {
277 .hugetlb_entry = gather_hugetlb_stats,
278 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
279 index 599ec2e..1740207 100644
280 --- a/fs/proc/task_nommu.c
281 +++ b/fs/proc/task_nommu.c
282 @@ -160,7 +160,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
286 - struct inode *inode = file_inode(vma->vm_file);
287 + struct inode *inode;
289 + file = vma_pr_or_file(vma);
290 + inode = file_inode(file);
291 dev = inode->i_sb->s_dev;
293 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
294 diff --git a/include/linux/mm.h b/include/linux/mm.h
295 index 0755b9f..2ee5500 100644
296 --- a/include/linux/mm.h
297 +++ b/include/linux/mm.h
298 @@ -1172,6 +1172,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
302 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
303 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
305 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
306 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
308 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
310 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
312 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
313 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
316 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
317 +extern void vmr_do_fput(struct vm_region *, const char[], int);
319 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
321 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
322 +#endif /* !CONFIG_MMU */
324 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
325 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
326 void *buf, int len, int write);
327 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
328 index 8d37e26..ce89d4c 100644
329 --- a/include/linux/mm_types.h
330 +++ b/include/linux/mm_types.h
331 @@ -241,6 +241,7 @@ struct vm_region {
332 unsigned long vm_top; /* region allocated to here */
333 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
334 struct file *vm_file; /* the backing file or NULL */
335 + struct file *vm_prfile; /* the virtual backing file or NULL */
337 int vm_usage; /* region usage count (access under nommu_region_sem) */
338 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
339 @@ -305,6 +306,7 @@ struct vm_area_struct {
340 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
341 units, *not* PAGE_CACHE_SIZE */
342 struct file * vm_file; /* File we map to (can be NULL). */
343 + struct file *vm_prfile; /* shadow of vm_file */
344 void * vm_private_data; /* was vm_pte (shared mem) */
347 diff --git a/kernel/fork.c b/kernel/fork.c
348 index 03c1eaa..7e215ba 100644
351 @@ -456,7 +456,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
352 struct inode *inode = file_inode(file);
353 struct address_space *mapping = file->f_mapping;
357 if (tmp->vm_flags & VM_DENYWRITE)
358 atomic_dec(&inode->i_writecount);
359 i_mmap_lock_write(mapping);
360 diff --git a/mm/Makefile b/mm/Makefile
361 index 98c4eae..3f0c9b9 100644
364 @@ -21,7 +21,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
365 mm_init.o mmu_context.o percpu.o slab_common.o \
366 compaction.o vmacache.o \
367 interval_tree.o list_lru.o workingset.o \
369 + prfile.o debug.o $(mmu-y)
373 diff --git a/mm/filemap.c b/mm/filemap.c
374 index 6bf5e42..a863d0f 100644
377 @@ -2062,7 +2062,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
378 int ret = VM_FAULT_LOCKED;
380 sb_start_pagefault(inode->i_sb);
381 - file_update_time(vma->vm_file);
382 + vma_file_update_time(vma);
384 if (page->mapping != inode->i_mapping) {
386 diff --git a/mm/madvise.c b/mm/madvise.c
387 index d551475..1ebf71b 100644
390 @@ -320,12 +320,12 @@ static long madvise_remove(struct vm_area_struct *vma,
391 * vma's reference to the file) can go away as soon as we drop
396 up_read(¤t->mm->mmap_sem);
397 error = vfs_fallocate(f,
398 FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
399 offset, end - start);
402 down_read(¤t->mm->mmap_sem);
405 diff --git a/mm/memory.c b/mm/memory.c
406 index 22e037e..62096a2 100644
409 @@ -2034,7 +2034,7 @@ static inline int wp_page_reuse(struct mm_struct *mm,
413 - file_update_time(vma->vm_file);
414 + vma_file_update_time(vma);
417 return VM_FAULT_WRITE;
418 diff --git a/mm/mmap.c b/mm/mmap.c
419 index bb50cac..1ab5e596 100644
422 @@ -274,7 +274,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
423 if (vma->vm_ops && vma->vm_ops->close)
424 vma->vm_ops->close(vma);
426 - fput(vma->vm_file);
428 mpol_put(vma_policy(vma));
429 kmem_cache_free(vm_area_cachep, vma);
431 @@ -886,7 +886,7 @@ again: remove_next = 1 + (end > next->vm_end);
434 uprobe_munmap(next, next->vm_start, next->vm_end);
439 anon_vma_merge(vma, next);
440 @@ -1671,8 +1671,8 @@ out:
448 /* Undo any partial mapping done by a device driver. */
449 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
450 @@ -2473,7 +2473,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
454 - get_file(new->vm_file);
457 if (new->vm_ops && new->vm_ops->open)
458 new->vm_ops->open(new);
459 @@ -2492,7 +2492,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
460 if (new->vm_ops && new->vm_ops->close)
461 new->vm_ops->close(new);
463 - fput(new->vm_file);
465 unlink_anon_vmas(new);
467 mpol_put(vma_policy(new));
468 @@ -2635,7 +2635,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
469 struct vm_area_struct *vma;
470 unsigned long populate = 0;
471 unsigned long ret = -EINVAL;
474 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
475 "See Documentation/vm/remap_file_pages.txt.\n",
476 @@ -2679,10 +2678,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
477 munlock_vma_pages_range(vma, start, start + size);
480 - file = get_file(vma->vm_file);
482 ret = do_mmap_pgoff(vma->vm_file, start, size,
483 prot, flags, pgoff, &populate);
487 up_write(&mm->mmap_sem);
489 @@ -2949,7 +2948,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
490 if (anon_vma_clone(new_vma, vma))
491 goto out_free_mempol;
492 if (new_vma->vm_file)
493 - get_file(new_vma->vm_file);
494 + vma_get_file(new_vma);
495 if (new_vma->vm_ops && new_vma->vm_ops->open)
496 new_vma->vm_ops->open(new_vma);
497 vma_link(mm, new_vma, prev, rb_link, rb_parent);
498 diff --git a/mm/msync.c b/mm/msync.c
499 index bb04d53..5c24c54 100644
502 @@ -84,10 +84,10 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
504 if ((flags & MS_SYNC) && file &&
505 (vma->vm_flags & VM_SHARED)) {
508 up_read(&mm->mmap_sem);
509 error = vfs_fsync_range(file, fstart, fend, 1);
512 if (error || start >= end)
514 down_read(&mm->mmap_sem);
515 diff --git a/mm/nommu.c b/mm/nommu.c
516 index e544508..dd6f74a 100644
519 @@ -693,7 +693,7 @@ static void __put_nommu_region(struct vm_region *region)
520 up_write(&nommu_region_sem);
523 - fput(region->vm_file);
526 /* IO memory and memory shared directly out of the pagecache
527 * from ramfs/tmpfs mustn't be released here */
528 @@ -858,7 +858,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
529 if (vma->vm_ops && vma->vm_ops->close)
530 vma->vm_ops->close(vma);
532 - fput(vma->vm_file);
534 put_nommu_region(vma->vm_region);
535 kmem_cache_free(vm_area_cachep, vma);
537 @@ -1398,7 +1398,7 @@ unsigned long do_mmap_pgoff(struct file *file,
538 goto error_just_free;
541 - fput(region->vm_file);
543 kmem_cache_free(vm_region_jar, region);
546 @@ -1474,10 +1474,10 @@ error_just_free:
547 up_write(&nommu_region_sem);
550 - fput(region->vm_file);
552 kmem_cache_free(vm_region_jar, region);
554 - fput(vma->vm_file);
556 kmem_cache_free(vm_area_cachep, vma);
557 kleave(" = %d", ret);
559 diff --git a/mm/prfile.c b/mm/prfile.c
561 index 0000000..6aa5ab5
566 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
567 + * in /proc/PID/maps.
568 + * Call these functions via macros defined in linux/mm.h.
570 + * See Documentation/filesystems/aufs/design/06mmap.txt
572 + * Copyright (c) 2014 Junjro R. Okajima
573 + * Copyright (c) 2014 Ian Campbell
576 +#include <linux/mm.h>
577 +#include <linux/file.h>
578 +#include <linux/fs.h>
580 +/* #define PRFILE_TRACE */
581 +static inline void prfile_trace(struct file *f, struct file *pr,
582 + const char func[], int line, const char func2[])
586 + pr_info("%s:%d: %s, %p\n", func, line, func2,
587 + f ? (char *)f->f_path.dentry->d_name.name : "(null)");
591 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
594 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
596 + prfile_trace(f, pr, func, line, __func__);
597 + file_update_time(f);
599 + file_update_time(pr);
602 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
605 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
607 + prfile_trace(f, pr, func, line, __func__);
608 + return (f && pr) ? pr : f;
611 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
613 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
615 + prfile_trace(f, pr, func, line, __func__);
621 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
623 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
625 + prfile_trace(f, pr, func, line, __func__);
632 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
635 + struct file *f = region->vm_file, *pr = region->vm_prfile;
637 + prfile_trace(f, pr, func, line, __func__);
638 + return (f && pr) ? pr : f;
641 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
643 + struct file *f = region->vm_file, *pr = region->vm_prfile;
645 + prfile_trace(f, pr, func, line, __func__);
650 +#endif /* !CONFIG_MMU */
651 aufs4.x-rcN standalone patch
653 diff --git a/fs/dcache.c b/fs/dcache.c
654 index bc261e2..8d7951d 100644
657 @@ -1269,6 +1269,7 @@ rename_retry:
661 +EXPORT_SYMBOL(d_walk);
664 * Search for at least 1 mount point in the dentry's subdirs.
665 diff --git a/fs/file_table.c b/fs/file_table.c
666 index 294174d..3cea027 100644
667 --- a/fs/file_table.c
668 +++ b/fs/file_table.c
669 @@ -147,6 +147,7 @@ over:
671 return ERR_PTR(-ENFILE);
673 +EXPORT_SYMBOL(get_empty_filp);
676 * alloc_file - allocate and initialize a 'struct file'
677 @@ -308,6 +309,7 @@ void put_filp(struct file *file)
681 +EXPORT_SYMBOL(put_filp);
683 void __init files_init(unsigned long mempages)
685 diff --git a/fs/inode.c b/fs/inode.c
686 index ea37cd1..58f5f58 100644
689 @@ -58,6 +58,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
690 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
692 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
693 +EXPORT_SYMBOL(inode_sb_list_lock);
696 * Empty aops. Can be used for the cases where the user does not
697 diff --git a/fs/namespace.c b/fs/namespace.c
698 index 1b9e111..d45b81b 100644
701 @@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
702 mnt_dec_writers(real_mount(mnt));
705 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
708 * mnt_drop_write - give up write access to a mount
709 @@ -1768,6 +1769,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
713 +EXPORT_SYMBOL(iterate_mounts);
715 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
717 diff --git a/fs/notify/group.c b/fs/notify/group.c
718 index d16b62c..06ca6bc 100644
719 --- a/fs/notify/group.c
720 +++ b/fs/notify/group.c
722 #include <linux/srcu.h>
723 #include <linux/rculist.h>
724 #include <linux/wait.h>
725 +#include <linux/module.h>
727 #include <linux/fsnotify_backend.h>
728 #include "fsnotify.h"
729 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
731 atomic_inc(&group->refcnt);
733 +EXPORT_SYMBOL(fsnotify_get_group);
736 * Drop a reference to a group. Free it if it's through.
737 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
738 if (atomic_dec_and_test(&group->refcnt))
739 fsnotify_final_destroy_group(group);
741 +EXPORT_SYMBOL(fsnotify_put_group);
744 * Create a new fsnotify_group and hold a reference for the group returned.
745 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
749 +EXPORT_SYMBOL(fsnotify_alloc_group);
751 int fsnotify_fasync(int fd, struct file *file, int on)
753 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
754 index 92e48c7..d2c4b68 100644
755 --- a/fs/notify/mark.c
756 +++ b/fs/notify/mark.c
757 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
758 mark->free_mark(mark);
761 +EXPORT_SYMBOL(fsnotify_put_mark);
763 /* Calculate mask of events for a list of marks */
764 u32 fsnotify_recalc_mask(struct hlist_head *head)
765 @@ -202,6 +203,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
766 fsnotify_destroy_mark_locked(mark, group);
767 mutex_unlock(&group->mark_mutex);
769 +EXPORT_SYMBOL(fsnotify_destroy_mark);
772 * Destroy all marks in the given list. The marks must be already detached from
773 @@ -376,6 +378,7 @@ err:
777 +EXPORT_SYMBOL(fsnotify_add_mark);
779 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
780 struct inode *inode, struct vfsmount *mnt, int allow_dups)
781 @@ -455,6 +458,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
782 atomic_set(&mark->refcnt, 1);
783 mark->free_mark = free_mark;
785 +EXPORT_SYMBOL(fsnotify_init_mark);
787 static int fsnotify_mark_destroy(void *ignored)
789 diff --git a/fs/open.c b/fs/open.c
790 index 98e5a52..a94e2e7 100644
793 @@ -62,6 +62,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
794 mutex_unlock(&dentry->d_inode->i_mutex);
797 +EXPORT_SYMBOL(do_truncate);
799 long vfs_truncate(struct path *path, loff_t length)
801 @@ -676,6 +677,7 @@ int open_check_o_direct(struct file *f)
805 +EXPORT_SYMBOL(open_check_o_direct);
807 static int do_dentry_open(struct file *f,
808 int (*open)(struct inode *, struct file *),
809 diff --git a/fs/read_write.c b/fs/read_write.c
810 index fd0414e..8ace6ec 100644
811 --- a/fs/read_write.c
812 +++ b/fs/read_write.c
813 @@ -504,6 +504,7 @@ vfs_readf_t vfs_readf(struct file *file)
814 return new_sync_read;
815 return ERR_PTR(-ENOSYS);
817 +EXPORT_SYMBOL(vfs_readf);
819 vfs_writef_t vfs_writef(struct file *file)
821 @@ -515,6 +516,7 @@ vfs_writef_t vfs_writef(struct file *file)
822 return new_sync_write;
823 return ERR_PTR(-ENOSYS);
825 +EXPORT_SYMBOL(vfs_writef);
827 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
829 diff --git a/fs/splice.c b/fs/splice.c
830 index fa5eee5..bfb3324 100644
833 @@ -1114,6 +1114,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
835 return splice_write(pipe, out, ppos, len, flags);
837 +EXPORT_SYMBOL(do_splice_from);
840 * Attempt to initiate a splice from a file to a pipe.
841 @@ -1140,6 +1141,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
843 return splice_read(in, ppos, pipe, len, flags);
845 +EXPORT_SYMBOL(do_splice_to);
848 * splice_direct_to_actor - splices data directly between two non-pipes
849 diff --git a/fs/xattr.c b/fs/xattr.c
850 index 4ef6985..6bb6303 100644
853 @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
854 *xattr_value = value;
857 +EXPORT_SYMBOL(vfs_getxattr_alloc);
859 /* Compare an extended attribute value with the given value */
860 int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
861 diff --git a/security/commoncap.c b/security/commoncap.c
862 index f2875cd..ebf06ec 100644
863 --- a/security/commoncap.c
864 +++ b/security/commoncap.c
865 @@ -975,9 +975,11 @@ int cap_mmap_addr(unsigned long addr)
869 +EXPORT_SYMBOL(cap_mmap_addr);
871 int cap_mmap_file(struct file *file, unsigned long reqprot,
872 unsigned long prot, unsigned long flags)
876 +EXPORT_SYMBOL(cap_mmap_file);
877 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
878 index 188c1d2..426d9af 100644
879 --- a/security/device_cgroup.c
880 +++ b/security/device_cgroup.c
882 #include <linux/device_cgroup.h>
883 #include <linux/cgroup.h>
884 #include <linux/ctype.h>
885 +#include <linux/export.h>
886 #include <linux/list.h>
887 #include <linux/uaccess.h>
888 #include <linux/seq_file.h>
889 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
890 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
893 +EXPORT_SYMBOL(__devcgroup_inode_permission);
895 int devcgroup_inode_mknod(int mode, dev_t dev)
897 diff --git a/security/security.c b/security/security.c
898 index 8e9b1f4..c1c7cd1 100644
899 --- a/security/security.c
900 +++ b/security/security.c
901 @@ -430,6 +430,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
903 return security_ops->path_rmdir(dir, dentry);
905 +EXPORT_SYMBOL(security_path_rmdir);
907 int security_path_unlink(struct path *dir, struct dentry *dentry)
909 @@ -446,6 +447,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
911 return security_ops->path_symlink(dir, dentry, old_name);
913 +EXPORT_SYMBOL(security_path_symlink);
915 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
916 struct dentry *new_dentry)
917 @@ -454,6 +456,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
919 return security_ops->path_link(old_dentry, new_dir, new_dentry);
921 +EXPORT_SYMBOL(security_path_link);
923 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
924 struct path *new_dir, struct dentry *new_dentry,
925 @@ -481,6 +484,7 @@ int security_path_truncate(struct path *path)
927 return security_ops->path_truncate(path);
929 +EXPORT_SYMBOL(security_path_truncate);
931 int security_path_chmod(struct path *path, umode_t mode)
933 @@ -488,6 +492,7 @@ int security_path_chmod(struct path *path, umode_t mode)
935 return security_ops->path_chmod(path, mode);
937 +EXPORT_SYMBOL(security_path_chmod);
939 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
941 @@ -495,6 +500,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
943 return security_ops->path_chown(path, uid, gid);
945 +EXPORT_SYMBOL(security_path_chown);
947 int security_path_chroot(struct path *path)
949 @@ -580,6 +586,7 @@ int security_inode_readlink(struct dentry *dentry)
951 return security_ops->inode_readlink(dentry);
953 +EXPORT_SYMBOL(security_inode_readlink);
955 int security_inode_follow_link(struct dentry *dentry, struct nameidata *nd)
957 @@ -594,6 +601,7 @@ int security_inode_permission(struct inode *inode, int mask)
959 return security_ops->inode_permission(inode, mask);
961 +EXPORT_SYMBOL(security_inode_permission);
963 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
965 @@ -716,6 +724,7 @@ int security_file_permission(struct file *file, int mask)
967 return fsnotify_perm(file, mask);
969 +EXPORT_SYMBOL(security_file_permission);
971 int security_file_alloc(struct file *file)
973 @@ -775,6 +784,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
975 return ima_file_mmap(file, prot);
977 +EXPORT_SYMBOL(security_mmap_file);
979 int security_mmap_addr(unsigned long addr)
981 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
982 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
983 +++ linux/Documentation/ABI/testing/debugfs-aufs 2015-06-28 17:35:44.344717109 +0200
985 +What: /debug/aufs/si_<id>/
987 +Contact: J. R. Okajima <hooanon05g@gmail.com>
989 + Under /debug/aufs, a directory named si_<id> is created
990 + per aufs mount, where <id> is a unique id generated
993 +What: /debug/aufs/si_<id>/plink
995 +Contact: J. R. Okajima <hooanon05g@gmail.com>
997 + It has three lines and shows the information about the
998 + pseudo-link. The first line is a single number
999 + representing a number of buckets. The second line is a
1000 + number of pseudo-links per buckets (separated by a
1001 + blank). The last line is a single number representing a
1002 + total number of psedo-links.
1003 + When the aufs mount option 'noplink' is specified, it
1004 + will show "1\n0\n0\n".
1006 +What: /debug/aufs/si_<id>/xib
1008 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1010 + It shows the consumed blocks by xib (External Inode Number
1011 + Bitmap), its block size and file size.
1012 + When the aufs mount option 'noxino' is specified, it
1013 + will be empty. About XINO files, see the aufs manual.
1015 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1017 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1019 + It shows the consumed blocks by xino (External Inode Number
1020 + Translation Table), its link count, block size and file
1022 + When the aufs mount option 'noxino' is specified, it
1023 + will be empty. About XINO files, see the aufs manual.
1025 +What: /debug/aufs/si_<id>/xigen
1027 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1029 + It shows the consumed blocks by xigen (External Inode
1030 + Generation Table), its block size and file size.
1031 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1033 + When the aufs mount option 'noxino' is specified, it
1034 + will be empty. About XINO files, see the aufs manual.
1035 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1036 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1037 +++ linux/Documentation/ABI/testing/sysfs-aufs 2015-06-28 17:35:44.344717109 +0200
1039 +What: /sys/fs/aufs/si_<id>/
1041 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1043 + Under /sys/fs/aufs, a directory named si_<id> is created
1044 + per aufs mount, where <id> is a unique id generated
1047 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1049 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1051 + It shows the abolute path of a member directory (which
1052 + is called branch) in aufs, and its permission.
1054 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1056 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1058 + It shows the id of a member directory (which is called
1061 +What: /sys/fs/aufs/si_<id>/xi_path
1063 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1065 + It shows the abolute path of XINO (External Inode Number
1066 + Bitmap, Translation Table and Generation Table) file
1067 + even if it is the default path.
1068 + When the aufs mount option 'noxino' is specified, it
1069 + will be empty. About XINO files, see the aufs manual.
1070 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1071 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1072 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2015-06-28 17:35:44.344717109 +0200
1075 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1077 +# This program is free software; you can redistribute it and/or modify
1078 +# it under the terms of the GNU General Public License as published by
1079 +# the Free Software Foundation; either version 2 of the License, or
1080 +# (at your option) any later version.
1082 +# This program is distributed in the hope that it will be useful,
1083 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1084 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1085 +# GNU General Public License for more details.
1087 +# You should have received a copy of the GNU General Public License
1088 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1091 +----------------------------------------
1093 +aufs [ei ju: ef es] | [a u f s]
1094 +1. abbrev. for "advanced multi-layered unification filesystem".
1095 +2. abbrev. for "another unionfs".
1096 +3. abbrev. for "auf das" in German which means "on the" in English.
1097 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1098 + But "Filesystem aufs Filesystem" is hard to understand.
1100 +AUFS is a filesystem with features:
1101 +- multi layered stackable unification filesystem, the member directory
1102 + is called as a branch.
1103 +- branch permission and attribute, 'readonly', 'real-readonly',
1104 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1106 +- internal "file copy-on-write".
1107 +- logical deletion, whiteout.
1108 +- dynamic branch manipulation, adding, deleting and changing permission.
1109 +- allow bypassing aufs, user's direct branch access.
1110 +- external inode number translation table and bitmap which maintains the
1111 + persistent aufs inode number.
1112 +- seekable directory, including NFS readdir.
1113 +- file mapping, mmap and sharing pages.
1114 +- pseudo-link, hardlink over branches.
1115 +- loopback mounted filesystem as a branch.
1116 +- several policies to select one among multiple writable branches.
1117 +- revert a single systemcall when an error occurs in aufs.
1121 +Multi Layered Stackable Unification Filesystem
1122 +----------------------------------------------------------------------
1123 +Most people already knows what it is.
1124 +It is a filesystem which unifies several directories and provides a
1125 +merged single directory. When users access a file, the access will be
1126 +passed/re-directed/converted (sorry, I am not sure which English word is
1127 +correct) to the real file on the member filesystem. The member
1128 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1129 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1130 +readonly branch is handled by creating 'whiteout' on the upper writable
1133 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1134 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1135 +different approaches to implement the merged-view.
1136 +The former tries putting it into VFS, and the latter implements as a
1137 +separate filesystem.
1138 +(If I misunderstand about these implementations, please let me know and
1139 +I shall correct it. Because it is a long time ago when I read their
1140 +source files last time).
1142 +UnionMount's approach will be able to small, but may be hard to share
1143 +branches between several UnionMount since the whiteout in it is
1144 +implemented in the inode on branch filesystem and always
1145 +shared. According to Bharata's post, readdir does not seems to be
1147 +There are several missing features known in this implementations such as
1148 +- for users, the inode number may change silently. eg. copy-up.
1149 +- link(2) may break by copy-up.
1150 +- read(2) may get an obsoleted filedata (fstat(2) too).
1151 +- fcntl(F_SETLK) may be broken by copy-up.
1152 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1155 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1156 +merged into mainline. This is another implementation of UnionMount as a
1157 +separated filesystem. All the limitations and known problems which
1158 +UnionMount are equally inherited to "overlay" filesystem.
1160 +Unionfs has a longer history. When I started implementing a stackable
1161 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1162 +inode, dentry and file objects and they have an array pointing lower
1163 +same kind objects. After contributing many patches for Unionfs, I
1164 +re-started my project AUFS (Jun 2006).
1166 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1167 +implemented my own ideas, approaches and enhancements and it became
1168 +totally different one.
1170 +Comparing DM snapshot and fs based implementation
1171 +- the number of bytes to be copied between devices is much smaller.
1172 +- the type of filesystem must be one and only.
1173 +- the fs must be writable, no readonly fs, even for the lower original
1174 + device. so the compression fs will not be usable. but if we use
1175 + loopback mount, we may address this issue.
1177 + mount /cdrom/squashfs.img /sq
1178 + losetup /sq/ext2.img
1179 + losetup /somewhere/cow
1180 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1181 +- it will be difficult (or needs more operations) to extract the
1182 + difference between the original device and COW.
1183 +- DM snapshot-merge may help a lot when users try merging. in the
1184 + fs-layer union, users will use rsync(1).
1186 +You may want to read my old paper "Filesystems in LiveCD"
1187 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1190 +Several characters/aspects/persona of aufs
1191 +----------------------------------------------------------------------
1193 +Aufs has several characters, aspects or persona.
1194 +1. a filesystem, callee of VFS helper
1195 +2. sub-VFS, caller of VFS helper for branches
1196 +3. a virtual filesystem which maintains persistent inode number
1197 +4. reader/writer of files on branches such like an application
1199 +1. Callee of VFS Helper
1200 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1201 +unlink(2) from an application reaches sys_unlink() kernel function and
1202 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1203 +calls filesystem specific unlink operation. Actually aufs implements the
1204 +unlink operation but it behaves like a redirector.
1206 +2. Caller of VFS Helper for Branches
1207 +aufs_unlink() passes the unlink request to the branch filesystem as if
1208 +it were called from VFS. So the called unlink operation of the branch
1209 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1210 +every necessary pre/post operation for the branch filesystem.
1211 +- acquire the lock for the parent dir on a branch
1212 +- lookup in a branch
1213 +- revalidate dentry on a branch
1214 +- mnt_want_write() for a branch
1215 +- vfs_unlink() for a branch
1216 +- mnt_drop_write() for a branch
1217 +- release the lock on a branch
1219 +3. Persistent Inode Number
1220 +One of the most important issue for a filesystem is to maintain inode
1221 +numbers. This is particularly important to support exporting a
1222 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1223 +backend block device for its own. But some storage is necessary to
1224 +keep and maintain the inode numbers. It may be a large space and may not
1225 +suit to keep in memory. Aufs rents some space from its first writable
1226 +branch filesystem (by default) and creates file(s) on it. These files
1227 +are created by aufs internally and removed soon (currently) keeping
1229 +Note: Because these files are removed, they are totally gone after
1230 + unmounting aufs. It means the inode numbers are not persistent
1231 + across unmount or reboot. I have a plan to make them really
1232 + persistent which will be important for aufs on NFS server.
1234 +4. Read/Write Files Internally (copy-on-write)
1235 +Because a branch can be readonly, when you write a file on it, aufs will
1236 +"copy-up" it to the upper writable branch internally. And then write the
1237 +originally requested thing to the file. Generally kernel doesn't
1238 +open/read/write file actively. In aufs, even a single write may cause a
1239 +internal "file copy". This behaviour is very similar to cp(1) command.
1241 +Some people may think it is better to pass such work to user space
1242 +helper, instead of doing in kernel space. Actually I am still thinking
1243 +about it. But currently I have implemented it in kernel space.
1244 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1245 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1246 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2015-06-28 17:35:44.344717109 +0200
1249 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1251 +# This program is free software; you can redistribute it and/or modify
1252 +# it under the terms of the GNU General Public License as published by
1253 +# the Free Software Foundation; either version 2 of the License, or
1254 +# (at your option) any later version.
1256 +# This program is distributed in the hope that it will be useful,
1257 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1258 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1259 +# GNU General Public License for more details.
1261 +# You should have received a copy of the GNU General Public License
1262 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1264 +Basic Aufs Internal Structure
1266 +Superblock/Inode/Dentry/File Objects
1267 +----------------------------------------------------------------------
1268 +As like an ordinary filesystem, aufs has its own
1269 +superblock/inode/dentry/file objects. All these objects have a
1270 +dynamically allocated array and store the same kind of pointers to the
1271 +lower filesystem, branch.
1272 +For example, when you build a union with one readwrite branch and one
1273 +readonly, mounted /au, /rw and /ro respectively.
1275 +- /ro/fileA exists but /rw/fileA
1277 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1278 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1279 +- [0] = NULL (because /rw/fileA doesn't exist)
1282 +This style of an array is essentially same to the aufs
1283 +superblock/inode/dentry/file objects.
1285 +Because aufs supports manipulating branches, ie. add/delete/change
1286 +branches dynamically, these objects has its own generation. When
1287 +branches are changed, the generation in aufs superblock is
1288 +incremented. And a generation in other object are compared when it is
1289 +accessed. When a generation in other objects are obsoleted, aufs
1290 +refreshes the internal array.
1294 +----------------------------------------------------------------------
1295 +Additionally aufs superblock has some data for policies to select one
1296 +among multiple writable branches, XIB files, pseudo-links and kobject.
1297 +See below in detail.
1298 +About the policies which supports copy-down a directory, see
1299 +wbr_policy.txt too.
1302 +Branch and XINO(External Inode Number Translation Table)
1303 +----------------------------------------------------------------------
1304 +Every branch has its own xino (external inode number translation table)
1305 +file. The xino file is created and unlinked by aufs internally. When two
1306 +members of a union exist on the same filesystem, they share the single
1308 +The struct of a xino file is simple, just a sequence of aufs inode
1309 +numbers which is indexed by the lower inode number.
1310 +In the above sample, assume the inode number of /ro/fileA is i111 and
1311 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1312 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1314 +When the inode numbers are not contiguous, the xino file will be sparse
1315 +which has a hole in it and doesn't consume as much disk space as it
1316 +might appear. If your branch filesystem consumes disk space for such
1317 +holes, then you should specify 'xino=' option at mounting aufs.
1319 +Aufs has a mount option to free the disk blocks for such holes in XINO
1320 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1321 +meet a problem of disk shortage due to XINO files, then you should try
1322 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1323 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1324 +the holes in XINO files.
1326 +Also a writable branch has three kinds of "whiteout bases". All these
1327 +are existed when the branch is joined to aufs, and their names are
1328 +whiteout-ed doubly, so that users will never see their names in aufs
1330 +1. a regular file which will be hardlinked to all whiteouts.
1331 +2. a directory to store a pseudo-link.
1332 +3. a directory to store an "orphan"-ed file temporary.
1335 + When you remove a file on a readonly branch, aufs handles it as a
1336 + logical deletion and creates a whiteout on the upper writable branch
1337 + as a hardlink of this file in order not to consume inode on the
1340 + See below, Pseudo-link.
1342 + When "fileC" exists on the lower readonly branch only and it is
1343 + opened and removed with its parent dir, and then user writes
1344 + something into it, then aufs copies-up fileC to this
1345 + directory. Because there is no other dir to store fileC. After
1346 + creating a file under this dir, the file is unlinked.
1348 +Because aufs supports manipulating branches, ie. add/delete/change
1349 +dynamically, a branch has its own id. When the branch order changes,
1350 +aufs finds the new index by searching the branch id.
1354 +----------------------------------------------------------------------
1355 +Assume "fileA" exists on the lower readonly branch only and it is
1356 +hardlinked to "fileB" on the branch. When you write something to fileA,
1357 +aufs copies-up it to the upper writable branch. Additionally aufs
1358 +creates a hardlink under the Pseudo-link Directory of the writable
1359 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1360 +simple list. If fileB is read after unlinking fileA, aufs returns
1361 +filedata from the pseudo-link instead of the lower readonly
1362 +branch. Because the pseudo-link is based upon the inode, to keep the
1363 +inode number by xino (see above) is essentially necessary.
1365 +All the hardlinks under the Pseudo-link Directory of the writable branch
1366 +should be restored in a proper location later. Aufs provides a utility
1367 +to do this. The userspace helpers executed at remounting and unmounting
1369 +During this utility is running, it puts aufs into the pseudo-link
1370 +maintenance mode. In this mode, only the process which began the
1371 +maintenance mode (and its child processes) is allowed to operate in
1372 +aufs. Some other processes which are not related to the pseudo-link will
1373 +be allowed to run too, but the rest have to return an error or wait
1374 +until the maintenance mode ends. If a process already acquires an inode
1375 +mutex (in VFS), it has to return an error.
1378 +XIB(external inode number bitmap)
1379 +----------------------------------------------------------------------
1380 +Addition to the xino file per a branch, aufs has an external inode number
1381 +bitmap in a superblock object. It is also an internal file such like a
1383 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1385 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1387 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1388 +reduce the number of consumed disk blocks for these files.
1391 +Virtual or Vertical Dir, and Readdir in Userspace
1392 +----------------------------------------------------------------------
1393 +In order to support multiple layers (branches), aufs readdir operation
1394 +constructs a virtual dir block on memory. For readdir, aufs calls
1395 +vfs_readdir() internally for each dir on branches, merges their entries
1396 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1397 +object. So the file object has its entry list until it is closed. The
1398 +entry list will be updated when the file position is zero and becomes
1399 +obsoleted. This decision is made in aufs automatically.
1401 +The dynamically allocated memory block for the name of entries has a
1402 +unit of 512 bytes (by default) and stores the names contiguously (no
1403 +padding). Another block for each entry is handled by kmem_cache too.
1404 +During building dir blocks, aufs creates hash list and judging whether
1405 +the entry is whiteouted by its upper branch or already listed.
1406 +The merged result is cached in the corresponding inode object and
1407 +maintained by a customizable life-time option.
1409 +Some people may call it can be a security hole or invite DoS attack
1410 +since the opened and once readdir-ed dir (file object) holds its entry
1411 +list and becomes a pressure for system memory. But I'd say it is similar
1412 +to files under /proc or /sys. The virtual files in them also holds a
1413 +memory page (generally) while they are opened. When an idea to reduce
1414 +memory for them is introduced, it will be applied to aufs too.
1415 +For those who really hate this situation, I've developed readdir(3)
1416 +library which operates this merging in userspace. You just need to set
1417 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1418 +kernel space for readdir(3).
1422 +----------------------------------------------------------------------
1423 +Aufs sometimes requires privilege access to a branch. For instance,
1424 +in copy-up/down operation. When a user process is going to make changes
1425 +to a file which exists in the lower readonly branch only, and the mode
1426 +of one of ancestor directories may not be writable by a user
1427 +process. Here aufs copy-up the file with its ancestors and they may
1428 +require privilege to set its owner/group/mode/etc.
1429 +This is a typical case of a application character of aufs (see
1432 +Aufs uses workqueue synchronously for this case. It creates its own
1433 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1434 +passes the request to call mkdir or write (for example), and wait for
1435 +its completion. This approach solves a problem of a signal handler
1437 +If aufs didn't adopt the workqueue and changed the privilege of the
1438 +process, then the process may receive the unexpected SIGXFSZ or other
1441 +Also aufs uses the system global workqueue ("events" kernel thread) too
1442 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1443 +whiteout base and etc. This is unrelated to a privilege.
1444 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1445 +superblock at the beginning, at the same time waits for the completion
1446 +of all queued asynchronous tasks.
1450 +----------------------------------------------------------------------
1451 +The whiteout in aufs is very similar to Unionfs's. That is represented
1452 +by its filename. UnionMount takes an approach of a file mode, but I am
1453 +afraid several utilities (find(1) or something) will have to support it.
1455 +Basically the whiteout represents "logical deletion" which stops aufs to
1456 +lookup further, but also it represents "dir is opaque" which also stop
1459 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1460 +In order to make several functions in a single systemcall to be
1461 +revertible, aufs adopts an approach to rename a directory to a temporary
1462 +unique whiteouted name.
1463 +For example, in rename(2) dir where the target dir already existed, aufs
1464 +renames the target dir to a temporary unique whiteouted name before the
1465 +actual rename on a branch, and then handles other actions (make it opaque,
1466 +update the attributes, etc). If an error happens in these actions, aufs
1467 +simply renames the whiteouted name back and returns an error. If all are
1468 +succeeded, aufs registers a function to remove the whiteouted unique
1469 +temporary name completely and asynchronously to the system global
1474 +----------------------------------------------------------------------
1475 +It is a well-known feature or concept.
1476 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1477 +internally and makes change to the new file on the upper writable branch.
1478 +When the trigger systemcall does not update the timestamps of the parent
1479 +dir, aufs reverts it after copy-up.
1482 +Move-down (aufs3.9 and later)
1483 +----------------------------------------------------------------------
1484 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1485 +the lower readonly branch to the upper writable branch when a user
1486 +changes something about the file.
1487 +"Move-down" is an opposite action of copy-up. Basically this action is
1488 +ran manually instead of automatically and internally.
1489 +For desgin and implementation, aufs has to consider these issues.
1490 +- whiteout for the file may exist on the lower branch.
1491 +- ancestor directories may not exist on the lower branch.
1492 +- diropq for the ancestor directories may exist on the upper branch.
1493 +- free space on the lower branch will reduce.
1494 +- another access to the file may happen during moving-down, including
1495 + UDBA (see "Revalidate Dentry and UDBA").
1496 +- the file should not be hard-linked nor pseudo-linked. they should be
1497 + handled by auplink utility later.
1499 +Sometimes users want to move-down a file from the upper writable branch
1500 +to the lower readonly or writable branch. For instance,
1501 +- the free space of the upper writable branch is going to run out.
1502 +- create a new intermediate branch between the upper and lower branch.
1505 +For this purpose, use "aumvdown" command in aufs-util.git.
1506 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1507 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1508 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2015-06-28 17:35:44.344717109 +0200
1511 +# Copyright (C) 2015 Junjiro R. Okajima
1513 +# This program is free software; you can redistribute it and/or modify
1514 +# it under the terms of the GNU General Public License as published by
1515 +# the Free Software Foundation; either version 2 of the License, or
1516 +# (at your option) any later version.
1518 +# This program is distributed in the hope that it will be useful,
1519 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1520 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1521 +# GNU General Public License for more details.
1523 +# You should have received a copy of the GNU General Public License
1524 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1526 +Support for a branch who has its ->atomic_open()
1527 +----------------------------------------------------------------------
1528 +The filesystems who implement its ->atomic_open() are not majority. For
1529 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1530 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1531 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1532 +sure whether all filesystems who have ->atomic_open() behave like this,
1533 +but NFSv4 surely returns the error.
1535 +In order to support ->atomic_open() for aufs, there are a few
1538 +A. Introduce aufs_atomic_open()
1539 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1541 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1542 + an aufs user Pip Cet's approach
1543 + - calls aufs_create(), VFS finish_open() and notify_change().
1544 + - pass fake-mode to finish_open(), and then correct the mode by
1546 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1547 + - no aufs_atomic_open().
1548 + - aufs_lookup() registers the TID to an aufs internal object.
1549 + - aufs_create() does nothing when the matching TID is registered, but
1550 + registers the mode.
1551 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1552 + TID is registered.
1553 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1555 + - no aufs_atomic_open().
1556 + - aufs_create() registers the TID to an internal object. this info
1557 + represents "this process created this file just now."
1558 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1559 + registered TID and re-try open() with superuser's credential.
1561 +Pros and cons for each approach.
1564 + - straightforward but highly depends upon VFS internal.
1565 + - the atomic behavaiour is kept.
1566 + - some of parameters such as nameidata are hard to reproduce for
1570 + - easy to implement.
1571 + - the atomic behavaiour is lost.
1573 + - the atomic behavaiour is kept.
1574 + - dirty and tricky.
1575 + - VFS checks whether the file is created correctly after calling
1576 + ->create(), which means this approach doesn't work.
1578 + - easy to implement.
1579 + - the atomic behavaiour is lost.
1580 + - to open a file with superuser's credential and give it to a user
1581 + process is a bad idea, since the file object keeps the credential
1582 + in it. It may affect LSM or something. This approach doesn't work
1585 +The approach A is ideal, but it hard to implement. So here is a
1586 +variation of A, which is to be implemented.
1588 +A-1. Introduce aufs_atomic_open()
1589 + - calls branch fs ->atomic_open() if exists. otherwise calls
1590 + vfs_create() and finish_open().
1591 + - the demerit is that the several checks after branch fs
1592 + ->atomic_open() are lost. in the ordinary case, the checks are
1593 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1594 + be implemented in aufs, but not all I am afraid.
1595 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1596 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1597 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2015-06-28 17:35:44.344717109 +0200
1600 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1602 +# This program is free software; you can redistribute it and/or modify
1603 +# it under the terms of the GNU General Public License as published by
1604 +# the Free Software Foundation; either version 2 of the License, or
1605 +# (at your option) any later version.
1607 +# This program is distributed in the hope that it will be useful,
1608 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1609 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1610 +# GNU General Public License for more details.
1612 +# You should have received a copy of the GNU General Public License
1613 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616 +----------------------------------------------------------------------
1617 +Since aufs has a character of sub-VFS (see Introduction), it operates
1618 +lookup for branches as VFS does. It may be a heavy work. But almost all
1619 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1620 +directly connected to its parent. Digging down the directory hierarchy
1621 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1624 +When a branch is a remote filesystem, aufs basically relies upon its
1625 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1627 +For d_revalidate, aufs implements three levels of revalidate tests. See
1628 +"Revalidate Dentry and UDBA" in detail.
1631 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1632 +----------------------------------------------------------------------
1633 +Let's try case study.
1634 +- aufs has two branches, upper readwrite and lower readonly.
1636 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1637 +- user invoked "chmod a+rx /au/dirA"
1638 +- the internal copy-up is activated and "/rw/dirA" is created and its
1639 + permission bits are set to world readable.
1640 +- then "/au/dirA" becomes world readable?
1642 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1643 +or it may be a natively readonly filesystem. If aufs respects the lower
1644 +branch, it should not respond readdir request from other users. But user
1645 +allowed it by chmod. Should really aufs rejects showing the entries
1648 +To be honest, I don't have a good solution for this case. So aufs
1649 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1651 +When dirperm1 is specified, aufs checks only the highest one for the
1652 +directory permission, and shows the entries. Otherwise, as usual, checks
1653 +every dir existing on all branches and rejects the request.
1655 +As a side effect, dirperm1 option improves the performance of aufs
1656 +because the number of permission check is reduced when the number of
1660 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1661 +----------------------------------------------------------------------
1662 +Generally VFS helpers re-validate a dentry as a part of lookup.
1663 +0. digging down the directory hierarchy.
1664 +1. lock the parent dir by its i_mutex.
1665 +2. lookup the final (child) entry.
1667 +4. call the actual operation (create, unlink, etc.)
1668 +5. unlock the parent dir
1670 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1671 +called. Actually aufs implements it and checks the dentry on a branch is
1673 +But it is not enough. Because aufs has to release the lock for the
1674 +parent dir on a branch at the end of ->lookup() (step 2) and
1675 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1677 +If the file on a branch is changed directly, eg. bypassing aufs, after
1678 +aufs released the lock, then the subsequent operation may cause
1679 +something unpleasant result.
1681 +This situation is a result of VFS architecture, ->lookup() and
1682 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1683 +design from VFS's point of view. It is just not suitable for sub-VFS
1686 +Aufs supports such case by three level of revalidation which is
1687 +selectable by user.
1688 +1. Simple Revalidate
1689 + Addition to the native flow in VFS's, confirm the child-parent
1690 + relationship on the branch just after locking the parent dir on the
1691 + branch in the "actual operation" (step 4). When this validation
1692 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1693 + checks the validation of the dentry on branches.
1694 +2. Monitor Changes Internally by Inotify/Fsnotify
1695 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1696 + the dentry on the branch, and returns EBUSY if it finds different
1698 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1699 + during it is in cache. When the event is notified, aufs registers a
1700 + function to kernel 'events' thread by schedule_work(). And the
1701 + function sets some special status to the cached aufs dentry and inode
1702 + private data. If they are not cached, then aufs has nothing to
1703 + do. When the same file is accessed through aufs (step 0-3) later,
1704 + aufs will detect the status and refresh all necessary data.
1705 + In this mode, aufs has to ignore the event which is fired by aufs
1707 +3. No Extra Validation
1708 + This is the simplest test and doesn't add any additional revalidation
1709 + test, and skip the revalidation in step 4. It is useful and improves
1710 + aufs performance when system surely hide the aufs branches from user,
1711 + by over-mounting something (or another method).
1712 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1713 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1714 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2015-06-28 17:35:44.344717109 +0200
1717 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1719 +# This program is free software; you can redistribute it and/or modify
1720 +# it under the terms of the GNU General Public License as published by
1721 +# the Free Software Foundation; either version 2 of the License, or
1722 +# (at your option) any later version.
1724 +# This program is distributed in the hope that it will be useful,
1725 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1726 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1727 +# GNU General Public License for more details.
1729 +# You should have received a copy of the GNU General Public License
1730 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1732 +Branch Manipulation
1734 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1735 +and changing its permission/attribute, there are a lot of works to do.
1739 +----------------------------------------------------------------------
1740 +o Confirm the adding dir exists outside of aufs, including loopback
1741 + mount, and its various attributes.
1742 +o Initialize the xino file and whiteout bases if necessary.
1745 +o Check the owner/group/mode of the directory
1746 + When the owner/group/mode of the adding directory differs from the
1747 + existing branch, aufs issues a warning because it may impose a
1749 + For example, when a upper writable branch has a world writable empty
1750 + top directory, a malicious user can create any files on the writable
1751 + branch directly, like copy-up and modify manually. If something like
1752 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1753 + writable branch, and the writable branch is world-writable, then a
1754 + malicious guy may create /etc/passwd on the writable branch directly
1755 + and the infected file will be valid in aufs.
1756 + I am afraid it can be a security issue, but aufs can do nothing except
1757 + producing a warning.
1761 +----------------------------------------------------------------------
1762 +o Confirm the deleting branch is not busy
1763 + To be general, there is one merit to adopt "remount" interface to
1764 + manipulate branches. It is to discard caches. At deleting a branch,
1765 + aufs checks the still cached (and connected) dentries and inodes. If
1766 + there are any, then they are all in-use. An inode without its
1767 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1769 + For the cached one, aufs checks whether the same named entry exists on
1771 + If the cached one is a directory, because aufs provides a merged view
1772 + to users, as long as one dir is left on any branch aufs can show the
1773 + dir to users. In this case, the branch can be removed from aufs.
1774 + Otherwise aufs rejects deleting the branch.
1776 + If any file on the deleting branch is opened by aufs, then aufs
1780 +Modify the Permission of a Branch
1781 +----------------------------------------------------------------------
1782 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1785 +o rw --> ro: Confirm the modifying branch is not busy
1786 + Aufs rejects the request if any of these conditions are true.
1787 + - a file on the branch is mmap-ed.
1788 + - a regular file on the branch is opened for write and there is no
1789 + same named entry on the upper branch.
1790 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1791 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1792 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2015-06-28 17:35:44.344717109 +0200
1795 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1797 +# This program is free software; you can redistribute it and/or modify
1798 +# it under the terms of the GNU General Public License as published by
1799 +# the Free Software Foundation; either version 2 of the License, or
1800 +# (at your option) any later version.
1802 +# This program is distributed in the hope that it will be useful,
1803 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1804 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1805 +# GNU General Public License for more details.
1807 +# You should have received a copy of the GNU General Public License
1808 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1810 +Policies to Select One among Multiple Writable Branches
1811 +----------------------------------------------------------------------
1812 +When the number of writable branch is more than one, aufs has to decide
1813 +the target branch for file creation or copy-up. By default, the highest
1814 +writable branch which has the parent (or ancestor) dir of the target
1815 +file is chosen (top-down-parent policy).
1816 +By user's request, aufs implements some other policies to select the
1817 +writable branch, for file creation several policies, round-robin,
1818 +most-free-space, and other policies. For copy-up, top-down-parent,
1819 +bottom-up-parent, bottom-up and others.
1821 +As expected, the round-robin policy selects the branch in circular. When
1822 +you have two writable branches and creates 10 new files, 5 files will be
1823 +created for each branch. mkdir(2) systemcall is an exception. When you
1824 +create 10 new directories, all will be created on the same branch.
1825 +And the most-free-space policy selects the one which has most free
1826 +space among the writable branches. The amount of free space will be
1827 +checked by aufs internally, and users can specify its time interval.
1829 +The policies for copy-up is more simple,
1830 +top-down-parent is equivalent to the same named on in create policy,
1831 +bottom-up-parent selects the writable branch where the parent dir
1832 +exists and the nearest upper one from the copyup-source,
1833 +bottom-up selects the nearest upper writable branch from the
1834 +copyup-source, regardless the existence of the parent dir.
1836 +There are some rules or exceptions to apply these policies.
1837 +- If there is a readonly branch above the policy-selected branch and
1838 + the parent dir is marked as opaque (a variation of whiteout), or the
1839 + target (creating) file is whiteout-ed on the upper readonly branch,
1840 + then the result of the policy is ignored and the target file will be
1841 + created on the nearest upper writable branch than the readonly branch.
1842 +- If there is a writable branch above the policy-selected branch and
1843 + the parent dir is marked as opaque or the target file is whiteouted
1844 + on the branch, then the result of the policy is ignored and the target
1845 + file will be created on the highest one among the upper writable
1846 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1848 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1849 + They try selecting the branch where the source exists as possible
1850 + since copyup a large file will take long time. If it can't be,
1851 + ie. the branch where the source exists is readonly, then they will
1852 + follow the copyup policy.
1853 +- There is an exception for rename(2) when the target exists.
1854 + If the rename target exists, aufs compares the index of the branches
1855 + where the source and the target exists and selects the higher
1856 + one. If the selected branch is readonly, then aufs follows the
1858 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1859 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1860 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2015-06-28 17:35:44.344717109 +0200
1863 +# Copyright (C) 2011-2015 Junjiro R. Okajima
1865 +# This program is free software; you can redistribute it and/or modify
1866 +# it under the terms of the GNU General Public License as published by
1867 +# the Free Software Foundation; either version 2 of the License, or
1868 +# (at your option) any later version.
1870 +# This program is distributed in the hope that it will be useful,
1871 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1872 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1873 +# GNU General Public License for more details.
1875 +# You should have received a copy of the GNU General Public License
1876 +# along with this program; if not, write to the Free Software
1877 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1880 +File-based Hierarchical Storage Management (FHSM)
1881 +----------------------------------------------------------------------
1882 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1883 +storage world. Aufs provides this feature as file-based with multiple
1884 +writable branches, based upon the principle of "Colder, the Lower".
1885 +Here the word "colder" means that the less used files, and "lower" means
1886 +that the position in the order of the stacked branches vertically.
1887 +These multiple writable branches are prioritized, ie. the topmost one
1888 +should be the fastest drive and be used heavily.
1890 +o Characters in aufs FHSM story
1891 +- aufs itself and a new branch attribute.
1892 +- a new ioctl interface to move-down and to establish a connection with
1893 + the daemon ("move-down" is a converse of "copy-up").
1894 +- userspace tool and daemon.
1896 +The userspace daemon establishes a connection with aufs and waits for
1897 +the notification. The notified information is very similar to struct
1898 +statfs containing the number of consumed blocks and inodes.
1899 +When the consumed blocks/inodes of a branch exceeds the user-specified
1900 +upper watermark, the daemon activates its move-down process until the
1901 +consumed blocks/inodes reaches the user-specified lower watermark.
1903 +The actual move-down is done by aufs based upon the request from
1904 +user-space since we need to maintain the inode number and the internal
1905 +pointer arrays in aufs.
1907 +Currently aufs FHSM handles the regular files only. Additionally they
1908 +must not be hard-linked nor pseudo-linked.
1911 +o Cowork of aufs and the user-space daemon
1912 + During the userspace daemon established the connection, aufs sends a
1913 + small notification to it whenever aufs writes something into the
1914 + writable branch. But it may cost high since aufs issues statfs(2)
1915 + internally. So user can specify a new option to cache the
1916 + info. Actually the notification is controlled by these factors.
1917 + + the specified cache time.
1918 + + classified as "force" by aufs internally.
1919 + Until the specified time expires, aufs doesn't send the info
1920 + except the forced cases. When aufs decide forcing, the info is always
1921 + notified to userspace.
1922 + For example, the number of free inodes is generally large enough and
1923 + the shortage of it happens rarely. So aufs doesn't force the
1924 + notification when creating a new file, directory and others. This is
1925 + the typical case which aufs doesn't force.
1926 + When aufs writes the actual filedata and the files consumes any of new
1927 + blocks, the aufs forces notifying.
1930 +o Interfaces in aufs
1931 +- New branch attribute.
1933 + Specifies that the branch is managed by FHSM feature. In other word,
1934 + participant in the FHSM.
1935 + When nofhsm is set to the branch, it will not be the source/target
1936 + branch of the move-down operation. This attribute is set
1937 + independently from coo and moo attributes, and if you want full
1938 + FHSM, you should specify them as well.
1939 +- New mount option.
1941 + Specifies a second to suppress many less important info to be
1944 + + AUFS_CTL_FHSM_FD
1945 + create a new file descriptor which userspace can read the notification
1946 + (a subset of struct statfs) from aufs.
1947 +- Module parameter 'brs'
1948 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
1950 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
1951 + When there are two or more branches with fhsm attributes,
1952 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
1953 + terminates it. As a result of remounting and branch-manipulation, the
1954 + number of branches with fhsm attribute can be one. In this case,
1955 + /sbin/mount.aufs will terminate the user-space daemon.
1958 +Finally the operation is done as these steps in kernel-space.
1960 + + no one else is using the file.
1961 + + the file is not hard-linked.
1962 + + the file is not pseudo-linked.
1963 + + the file is a regular file.
1964 + + the parent dir is not opaqued.
1965 +- find the target writable branch.
1966 +- make sure the file is not whiteout-ed by the upper (than the target)
1968 +- make the parent dir on the target branch.
1969 +- mutex lock the inode on the branch.
1970 +- unlink the whiteout on the target branch (if exists).
1971 +- lookup and create the whiteout-ed temporary name on the target branch.
1972 +- copy the file as the whiteout-ed temporary name on the target branch.
1973 +- rename the whiteout-ed temporary name to the original name.
1974 +- unlink the file on the source branch.
1975 +- maintain the internal pointer array and the external inode number
1977 +- maintain the timestamps and other attributes of the parent dir and the
1980 +And of course, in every step, an error may happen. So the operation
1981 +should restore the original file state after an error happens.
1982 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1983 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1984 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2015-06-28 17:35:44.344717109 +0200
1987 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1989 +# This program is free software; you can redistribute it and/or modify
1990 +# it under the terms of the GNU General Public License as published by
1991 +# the Free Software Foundation; either version 2 of the License, or
1992 +# (at your option) any later version.
1994 +# This program is distributed in the hope that it will be useful,
1995 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1996 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1997 +# GNU General Public License for more details.
1999 +# You should have received a copy of the GNU General Public License
2000 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2002 +mmap(2) -- File Memory Mapping
2003 +----------------------------------------------------------------------
2004 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2005 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2007 +This approach is simple and good, but there is one problem.
2008 +Under /proc, several entries show the mmapped files by its path (with
2009 +device and inode number), and the printed path will be the path on the
2010 +branch fs's instead of virtual aufs's.
2011 +This is not a problem in most cases, but some utilities lsof(1) (and its
2012 +user) may expect the path on aufs.
2014 +To address this issue, aufs adds a new member called vm_prfile in struct
2015 +vm_area_struct (and struct vm_region). The original vm_file points to
2016 +the file on the branch fs in order to handle everything correctly as
2017 +usual. The new vm_prfile points to a virtual file in aufs, and the
2018 +show-functions in procfs refers to vm_prfile if it is set.
2019 +Also we need to maintain several other places where touching vm_file
2021 +- fork()/clone() copies vma and the reference count of vm_file is
2023 +- merging vma maintains the ref count too.
2025 +This is not a good approach. It just fakes the printed path. But it
2026 +leaves all behaviour around f_mapping unchanged. This is surely an
2028 +Actually aufs had adopted another complicated approach which calls
2029 +generic_file_mmap() and handles struct vm_operations_struct. In this
2030 +approach, aufs met a hard problem and I could not solve it without
2031 +switching the approach.
2033 +There may be one more another approach which is
2034 +- bind-mount the branch-root onto the aufs-root internally
2035 +- grab the new vfsmount (ie. struct mount)
2036 +- lazy-umount the branch-root internally
2037 +- in open(2) the aufs-file, open the branch-file with the hidden
2038 + vfsmount (instead of the original branch's vfsmount)
2039 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2040 + but it may be possible from userspace by the mount helper.
2042 +Adding the internal hidden vfsmount and using it in opening a file, the
2043 +file path under /proc will be printed correctly. This approach looks
2044 +smarter, but is not possible I am afraid.
2045 +- aufs-root may be bind-mount later. when it happens, another hidden
2046 + vfsmount will be required.
2047 +- it is hard to get the chance to bind-mount and lazy-umount
2048 + + in kernel-space, FS can have vfsmount in open(2) via
2049 + file->f_path, and aufs can know its vfsmount. But several locks are
2050 + already acquired, and if aufs tries to bind-mount and lazy-umount
2051 + here, then it may cause a deadlock.
2052 + + in user-space, bind-mount doesn't invoke the mount helper.
2053 +- since /proc shows dev and ino, aufs has to give vma these info. it
2054 + means a new member vm_prinode will be necessary. this is essentially
2055 + equivalent to vm_prfile described above.
2057 +I have to give up this "looks-smater" approach.
2058 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2059 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2060 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2015-06-28 17:35:44.344717109 +0200
2063 +# Copyright (C) 2014-2015 Junjiro R. Okajima
2065 +# This program is free software; you can redistribute it and/or modify
2066 +# it under the terms of the GNU General Public License as published by
2067 +# the Free Software Foundation; either version 2 of the License, or
2068 +# (at your option) any later version.
2070 +# This program is distributed in the hope that it will be useful,
2071 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2072 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2073 +# GNU General Public License for more details.
2075 +# You should have received a copy of the GNU General Public License
2076 +# along with this program; if not, write to the Free Software
2077 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2080 +Listing XATTR/EA and getting the value
2081 +----------------------------------------------------------------------
2082 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2083 +shows the values from the topmost existing file. This behaviour is good
2084 +for the non-dir entries since the bahaviour exactly matches the shown
2085 +information. But for the directories, aufs considers all the same named
2086 +entries on the lower branches. Which means, if one of the lower entry
2087 +rejects readdir call, then aufs returns an error even if the topmost
2088 +entry allows it. This behaviour is necessary to respect the branch fs's
2089 +security, but can make users confused since the user-visible standard
2090 +attributes don't match the behaviour.
2091 +To address this issue, aufs has a mount option called dirperm1 which
2092 +checks the permission for the topmost entry only, and ignores the lower
2093 +entry's permission.
2095 +A similar issue can happen around XATTR.
2096 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2097 +always set. Otherwise these very unpleasant situation would happen.
2098 +- listxattr(2) may return the duplicated entries.
2099 +- users may not be able to remove or reset the XATTR forever,
2102 +XATTR/EA support in the internal (copy,move)-(up,down)
2103 +----------------------------------------------------------------------
2104 +Generally the extended attributes of inode are categorized as these.
2105 +- "security" for LSM and capability.
2106 +- "system" for posix ACL, 'acl' mount option is required for the branch
2108 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2109 +- "user" for userspace, 'user_xattr' mount option is required for the
2110 + branch fs generally.
2112 +Moreover there are some other categories. Aufs handles these rather
2113 +unpopular categories as the ordinary ones, ie. there is no special
2114 +condition nor exception.
2116 +In copy-up, the support for XATTR on the dst branch may differ from the
2117 +src branch. In this case, the copy-up operation will get an error and
2118 +the original user operation which triggered the copy-up will fail. It
2119 +can happen that even all copy-up will fail.
2120 +When both of src and dst branches support XATTR and if an error occurs
2121 +during copying XATTR, then the copy-up should fail obviously. That is a
2122 +good reason and aufs should return an error to userspace. But when only
2123 +the src branch support that XATTR, aufs should not return an error.
2124 +For example, the src branch supports ACL but the dst branch doesn't
2125 +because the dst branch may natively un-support it or temporary
2126 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2127 +may NOT return an error even if the XATTR is not supported. It is
2128 +totally up to the branch fs.
2130 +Anyway when the aufs internal copy-up gets an error from the dst branch
2131 +fs, then aufs tries removing the just copied entry and returns the error
2132 +to the userspace. The worst case of this situation will be all copy-up
2135 +For the copy-up operation, there two basic approaches.
2136 +- copy the specified XATTR only (by category above), and return the
2137 + error unconditionally if it happens.
2138 +- copy all XATTR, and ignore the error on the specified category only.
2140 +In order to support XATTR and to implement the correct behaviour, aufs
2141 +chooses the latter approach and introduces some new branch attributes,
2142 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2143 +They correspond to the XATTR namespaces (see above). Additionally, to be
2144 +convenient, "icex" is also provided which means all "icex*" attributes
2145 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2147 +The meaning of these attributes is to ignore the error from setting
2148 +XATTR on that branch.
2149 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2150 +error from the dst branch according to the specified attributes.
2152 +Some XATTR may have its default value. The default value may come from
2153 +the parent dir or the environment. If the default value is set at the
2154 +file creating-time, it will be overwritten by copy-up.
2155 +Some contradiction may happen I am afraid.
2156 +Do we need another attribute to stop copying XATTR? I am unsure. For
2157 +now, aufs implements the branch attributes to ignore the error.
2158 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2159 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2160 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2015-06-28 17:35:44.344717109 +0200
2163 +# Copyright (C) 2005-2015 Junjiro R. Okajima
2165 +# This program is free software; you can redistribute it and/or modify
2166 +# it under the terms of the GNU General Public License as published by
2167 +# the Free Software Foundation; either version 2 of the License, or
2168 +# (at your option) any later version.
2170 +# This program is distributed in the hope that it will be useful,
2171 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2172 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2173 +# GNU General Public License for more details.
2175 +# You should have received a copy of the GNU General Public License
2176 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2178 +Export Aufs via NFS
2179 +----------------------------------------------------------------------
2180 +Here is an approach.
2181 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2183 +- iget_locked(): initialize aufs inode generation for a new inode, and
2184 + store it in xigen file.
2185 +- destroy_inode(): increment aufs inode generation and store it in xigen
2186 + file. it is necessary even if it is not unlinked, because any data of
2187 + inode may be changed by UDBA.
2188 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2189 + build file handle by
2190 + + branch id (4 bytes)
2191 + + superblock generation (4 bytes)
2192 + + inode number (4 or 8 bytes)
2193 + + parent dir inode number (4 or 8 bytes)
2194 + + inode generation (4 bytes))
2195 + + return value of exportfs_encode_fh() for the parent on a branch (4
2197 + + file handle for a branch (by exportfs_encode_fh())
2199 + + find the index of a branch from its id in handle, and check it is
2200 + still exist in aufs.
2201 + + 1st level: get the inode number from handle and search it in cache.
2202 + + 2nd level: if not found in cache, get the parent inode number from
2203 + the handle and search it in cache. and then open the found parent
2204 + dir, find the matching inode number by vfs_readdir() and get its
2205 + name, and call lookup_one_len() for the target dentry.
2206 + + 3rd level: if the parent dir is not cached, call
2207 + exportfs_decode_fh() for a branch and get the parent on a branch,
2208 + build a pathname of it, convert it a pathname in aufs, call
2209 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2211 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2212 + for every branch, but not itself. to get this, (currently) aufs
2213 + searches in current->nsproxy->mnt_ns list. it may not be a good
2214 + idea, but I didn't get other approach.
2215 + + test the generation of the gotten inode.
2216 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2217 + convert it into ESTALE for NFSD.
2218 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2219 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2220 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2221 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2222 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2015-06-28 17:35:44.344717109 +0200
2225 +# Copyright (C) 2005-2015 Junjiro R. Okajima
2227 +# This program is free software; you can redistribute it and/or modify
2228 +# it under the terms of the GNU General Public License as published by
2229 +# the Free Software Foundation; either version 2 of the License, or
2230 +# (at your option) any later version.
2232 +# This program is distributed in the hope that it will be useful,
2233 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2234 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2235 +# GNU General Public License for more details.
2237 +# You should have received a copy of the GNU General Public License
2238 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2240 +Show Whiteout Mode (shwh)
2241 +----------------------------------------------------------------------
2242 +Generally aufs hides the name of whiteouts. But in some cases, to show
2243 +them is very useful for users. For instance, creating a new middle layer
2244 +(branch) by merging existing layers.
2246 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2247 +When you have three branches,
2248 +- Bottom: 'system', squashfs (underlying base system), read-only
2249 +- Middle: 'mods', squashfs, read-only
2250 +- Top: 'overlay', ram (tmpfs), read-write
2252 +The top layer is loaded at boot time and saved at shutdown, to preserve
2253 +the changes made to the system during the session.
2254 +When larger changes have been made, or smaller changes have accumulated,
2255 +the size of the saved top layer data grows. At this point, it would be
2256 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2257 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2258 +restoring save and load speed.
2260 +This merging is simplified by the use of another aufs mount, of just the
2261 +two overlay branches using the 'shwh' option.
2262 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2263 + aufs /livesys/merge_union
2265 +A merged view of these two branches is then available at
2266 +/livesys/merge_union, and the new feature is that the whiteouts are
2268 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2269 +writing to all branches. Also the default mode for all branches is 'ro'.
2270 +It is now possible to save the combined contents of the two overlay
2271 +branches to a new squashfs, e.g.:
2272 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2274 +This new squashfs archive can be stored on the boot device and the
2275 +initramfs will use it to replace the old one at the next boot.
2276 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2277 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2278 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2015-06-28 17:35:44.344717109 +0200
2281 +# Copyright (C) 2010-2015 Junjiro R. Okajima
2283 +# This program is free software; you can redistribute it and/or modify
2284 +# it under the terms of the GNU General Public License as published by
2285 +# the Free Software Foundation; either version 2 of the License, or
2286 +# (at your option) any later version.
2288 +# This program is distributed in the hope that it will be useful,
2289 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2290 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2291 +# GNU General Public License for more details.
2293 +# You should have received a copy of the GNU General Public License
2294 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2296 +Dynamically customizable FS operations
2297 +----------------------------------------------------------------------
2298 +Generally FS operations (struct inode_operations, struct
2299 +address_space_operations, struct file_operations, etc.) are defined as
2300 +"static const", but it never means that FS have only one set of
2301 +operation. Some FS have multiple sets of them. For instance, ext2 has
2302 +three sets, one for XIP, for NOBH, and for normal.
2303 +Since aufs overrides and redirects these operations, sometimes aufs has
2304 +to change its behaviour according to the branch FS type. More importantly
2305 +VFS acts differently if a function (member in the struct) is set or
2306 +not. It means aufs should have several sets of operations and select one
2307 +among them according to the branch FS definition.
2309 +In order to solve this problem and not to affect the behaviour of VFS,
2310 +aufs defines these operations dynamically. For instance, aufs defines
2311 +dummy direct_IO function for struct address_space_operations, but it may
2312 +not be set to the address_space_operations actually. When the branch FS
2313 +doesn't have it, aufs doesn't set it to its address_space_operations
2314 +while the function definition itself is still alive. So the behaviour
2315 +itself will not change, and it will return an error when direct_IO is
2318 +The lifetime of these dynamically generated operation object is
2319 +maintained by aufs branch object. When the branch is removed from aufs,
2320 +the reference counter of the object is decremented. When it reaches
2321 +zero, the dynamically generated operation object will be freed.
2323 +This approach is designed to support AIO (io_submit), Direct I/O and
2325 +Currently this approach is applied to address_space_operations for
2326 +regular files only.
2327 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2328 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2329 +++ linux/Documentation/filesystems/aufs/README 2015-06-28 17:35:44.344717109 +0200
2332 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2338 +----------------------------------------
2339 +In the early days, aufs was entirely re-designed and re-implemented
2340 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2341 +improvements and implementations, it becomes totally different from
2342 +Unionfs while keeping the basic features.
2343 +Recently, Unionfs Version 2.x series begin taking some of the same
2344 +approaches to aufs1's.
2345 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2346 +University and his team.
2348 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2349 +If you want older kernel version support, try aufs2-2.6.git or
2350 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2352 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2353 + According to Christoph Hellwig, linux rejects all union-type
2354 + filesystems but UnionMount.
2355 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2357 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2358 + UnionMount, and he pointed out an issue around a directory mutex
2359 + lock and aufs addressed it. But it is still unsure whether aufs will
2360 + be merged (or any other union solution).
2361 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2365 +----------------------------------------
2366 +- unite several directories into a single virtual filesystem. The member
2367 + directory is called as a branch.
2368 +- you can specify the permission flags to the branch, which are 'readonly',
2369 + 'readwrite' and 'whiteout-able.'
2370 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2371 + readonly branch are modifiable logically.
2372 +- dynamic branch manipulation, add, del.
2375 +Also there are many enhancements in aufs, such as:
2376 +- test only the highest one for the directory permission (dirperm1)
2377 +- copyup on open (coo=)
2378 +- 'move' policy for copy-up between two writable branches, after
2379 + checking free space.
2381 +- readdir(3) in userspace.
2382 +- keep inode number by external inode number table
2383 +- keep the timestamps of file/dir in internal copyup operation
2384 +- seekable directory, supporting NFS readdir.
2385 +- whiteout is hardlinked in order to reduce the consumption of inodes
2387 +- do not copyup, nor create a whiteout when it is unnecessary
2388 +- revert a single systemcall when an error occurs in aufs
2389 +- remount interface instead of ioctl
2390 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2391 +- loopback mounted filesystem as a branch
2392 +- kernel thread for removing the dir who has a plenty of whiteouts
2393 +- support copyup sparse file (a file which has a 'hole' in it)
2394 +- default permission flags for branches
2395 +- selectable permission flags for ro branch, whether whiteout can
2398 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2399 +- support multiple writable branches, some policies to select one
2400 + among multiple writable branches.
2401 +- a new semantics for link(2) and rename(2) to support multiple
2402 + writable branches.
2403 +- no glibc changes are required.
2404 +- pseudo hardlink (hardlink over branches)
2405 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2406 + including NFS or remote filesystem branch.
2407 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2410 +Currently these features are dropped temporary from aufs4.
2411 +See design/08plan.txt in detail.
2412 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2414 +- statistics of aufs thread (/sys/fs/aufs/stat)
2416 +Features or just an idea in the future (see also design/*.txt),
2417 +- reorder the branch index without del/re-add.
2418 +- permanent xino files for NFSD
2419 +- an option for refreshing the opened files after add/del branches
2420 +- light version, without branch manipulation. (unnecessary?)
2421 +- copyup in userspace
2422 +- inotify in userspace
2427 +----------------------------------------
2428 +There are three GIT trees for aufs4, aufs4-linux.git,
2429 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2431 +While the aufs-util is always necessary, you need either of aufs4-linux
2432 +or aufs4-standalone.
2434 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2435 +git://git.kernel.org/.../torvalds/linux.git.
2436 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2437 +build aufs4 as an external kernel module.
2438 +Several extra patches are not included in this tree. Only
2439 +aufs4-standalone tree contains them. They are describe in the later
2440 +section "Configuration and Compilation."
2442 +On the other hand, the aufs4-standalone tree has only aufs source files
2443 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2444 +But you need to apply all aufs patches manually.
2446 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2447 +represents the linux kernel version, "linux-4.x". For instance,
2448 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2449 +"aufs4.x-rcN" branch.
2452 +$ git clone --reference /your/linux/git/tree \
2453 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2454 +- if you don't have linux GIT tree, then remove "--reference ..."
2455 +$ cd aufs4-linux.git
2456 +$ git checkout origin/aufs4.0
2458 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2459 +leave the patch-work to GIT.
2460 +$ cd /your/linux/git/tree
2461 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2463 +$ git checkout -b my4.0 v4.0
2464 +$ (add your local change...)
2465 +$ git pull aufs4 aufs4.0
2466 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2467 +- you may need to solve some conflicts between your_changes and
2468 + aufs4.0. in this case, git-rerere is recommended so that you can
2469 + solve the similar conflicts automatically when you upgrade to 4.1 or
2470 + later in the future.
2472 +o aufs4-standalone tree
2473 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2474 +$ cd aufs4-standalone.git
2475 +$ git checkout origin/aufs4.0
2478 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2479 +- note that the public aufs-util.git is on SourceForge instead of
2482 +$ git checkout origin/aufs4.0
2484 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2485 +The minor version number, 'x' in '4.x', of aufs may not always
2486 +follow the minor version number of the kernel.
2487 +Because changes in the kernel that cause the use of a new
2488 +minor version number do not always require changes to aufs-util.
2490 +Since aufs-util has its own minor version number, you may not be
2491 +able to find a GIT branch in aufs-util for your kernel's
2492 +exact minor version number.
2493 +In this case, you should git-checkout the branch for the
2494 +nearest lower number.
2496 +For (an unreleased) example:
2497 +If you are using "linux-4.10" and the "aufs4.10" branch
2498 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2499 +or something numerically smaller is the branch for your kernel.
2501 +Also you can view all branches by
2505 +3. Configuration and Compilation
2506 +----------------------------------------
2507 +Make sure you have git-checkout'ed the correct branch.
2509 +For aufs4-linux tree,
2510 +- enable CONFIG_AUFS_FS.
2511 +- set other aufs configurations if necessary.
2513 +For aufs4-standalone tree,
2514 +There are several ways to build.
2517 +- apply ./aufs4-kbuild.patch to your kernel source files.
2518 +- apply ./aufs4-base.patch too.
2519 +- apply ./aufs4-mmap.patch too.
2520 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2521 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2522 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2523 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2524 +- enable CONFIG_AUFS_FS, you can select either
2526 +- and build your kernel as usual.
2527 +- install the built kernel.
2528 + Note: Since linux-3.9, every filesystem module requires an alias
2529 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2530 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2531 +- install the header files too by "make headers_install" to the
2532 + directory where you specify. By default, it is $PWD/usr.
2533 + "make help" shows a brief note for headers_install.
2534 +- and reboot your system.
2537 +- module only (CONFIG_AUFS_FS=m).
2538 +- apply ./aufs4-base.patch to your kernel source files.
2539 +- apply ./aufs4-mmap.patch too.
2540 +- apply ./aufs4-standalone.patch too.
2541 +- build your kernel, don't forget "make headers_install", and reboot.
2542 +- edit ./config.mk and set other aufs configurations if necessary.
2543 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2544 + every aufs configurations.
2545 +- build the module by simple "make".
2546 + Note: Since linux-3.9, every filesystem module requires an alias
2547 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2548 + modules.aliases file.
2549 +- you can specify ${KDIR} make variable which points to your kernel
2551 +- install the files
2552 + + run "make install" to install the aufs module, or copy the built
2553 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2554 + + run "make install_headers" (instead of headers_install) to install
2555 + the modified aufs header file (you can specify DESTDIR which is
2556 + available in aufs standalone version's Makefile only), or copy
2557 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2558 + you like manually. By default, the target directory is $PWD/usr.
2559 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2560 + kernel source tree.
2562 +Note: The header file aufs_type.h is necessary to build aufs-util
2563 + as well as "make headers_install" in the kernel source tree.
2564 + headers_install is subject to be forgotten, but it is essentially
2565 + necessary, not only for building aufs-util.
2566 + You may not meet problems without headers_install in some older
2570 +- read README in aufs-util, build and install it
2571 +- note that your distribution may contain an obsoleted version of
2572 + aufs_type.h in /usr/include/linux or something. When you build aufs
2573 + utilities, make sure that your compiler refers the correct aufs header
2574 + file which is built by "make headers_install."
2575 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2576 + then run "make install_ulib" too. And refer to the aufs manual in
2579 +There several other patches in aufs4-standalone.git. They are all
2580 +optional. When you meet some problems, they will help you.
2581 +- aufs4-loopback.patch
2582 + Supports a nested loopback mount in a branch-fs. This patch is
2583 + unnecessary until aufs produces a message like "you may want to try
2584 + another patch for loopback file".
2586 + Modifies a system global kernel internal function get_next_ino() in
2587 + order to stop assigning 0 for an inode-number. Not directly related to
2588 + aufs, but recommended generally.
2590 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2591 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2592 + duplication of inode number, which is important for backup tools and
2593 + other utilities. When you find aufs XINO files for tmpfs branch
2594 + growing too much, try this patch.
2598 +----------------------------------------
2599 +At first, make sure aufs-util are installed, and please read the aufs
2600 +manual, aufs.5 in aufs-util.git tree.
2604 +$ mkdir /tmp/rw /tmp/aufs
2605 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2607 +Here is another example. The result is equivalent.
2608 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2610 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2611 +# mount -o remount,append:${HOME} /tmp/aufs
2613 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2614 +you modify a file under /tmp/aufs, the one on your home directory is
2615 +not affected, instead the same named file will be newly created under
2616 +/tmp/rw. And all of your modification to a file will be applied to
2617 +the one under /tmp/rw. This is called the file based Copy on Write
2619 +Aufs mount options are described in aufs.5.
2620 +If you run chroot or something and make your aufs as a root directory,
2621 +then you need to customize the shutdown script. See the aufs manual in
2624 +Additionally, there are some sample usages of aufs which are a
2625 +diskless system with network booting, and LiveCD over NFS.
2626 +See sample dir in CVS tree on SourceForge.
2630 +----------------------------------------
2631 +When you have any problems or strange behaviour in aufs, please let me
2633 +- /proc/mounts (instead of the output of mount(8))
2634 +- /sys/module/aufs/*
2635 +- /sys/fs/aufs/* (if you have them)
2636 +- /debug/aufs/* (if you have them)
2637 +- linux kernel version
2638 + if your kernel is not plain, for example modified by distributor,
2639 + the url where i can download its source is necessary too.
2640 +- aufs version which was printed at loading the module or booting the
2641 + system, instead of the date you downloaded.
2642 +- configuration (define/undefine CONFIG_AUFS_xxx)
2643 +- kernel configuration or /proc/config.gz (if you have it)
2644 +- behaviour which you think to be incorrect
2645 +- actual operation, reproducible one is better
2646 +- mailto: aufs-users at lists.sourceforge.net
2648 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2649 +and Feature Requests) on SourceForge. Please join and write to
2653 +6. Acknowledgements
2654 +----------------------------------------
2655 +Thanks to everyone who have tried and are using aufs, whoever
2656 +have reported a bug or any feedback.
2658 +Especially donators:
2659 +Tomas Matejicek(slax.org) made a donation (much more than once).
2660 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2661 + scripts) is making "doubling" donations.
2662 + Unfortunately I cannot list all of the donators, but I really
2664 + It ends Aug 2010, but the ordinary donation URL is still available.
2665 + <http://sourceforge.net/donate/index.php?group_id=167503>
2666 +Dai Itasaka made a donation (2007/8).
2667 +Chuck Smith made a donation (2008/4, 10 and 12).
2668 +Henk Schoneveld made a donation (2008/9).
2669 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2670 +Francois Dupoux made a donation (2008/11).
2671 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2672 + aufs2 GIT tree (2009/2).
2673 +William Grant made a donation (2009/3).
2674 +Patrick Lane made a donation (2009/4).
2675 +The Mail Archive (mail-archive.com) made donations (2009/5).
2676 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2677 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2678 +Pavel Pronskiy made a donation (2011/2).
2679 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2680 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2681 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2683 +Sam Liddicott made a donation (2011/9).
2684 +Era Scarecrow made a donation (2013/4).
2685 +Bor Ratajc made a donation (2013/4).
2686 +Alessandro Gorreta made a donation (2013/4).
2687 +POIRETTE Marc made a donation (2013/4).
2688 +Alessandro Gorreta made a donation (2013/4).
2689 +lauri kasvandik made a donation (2013/5).
2690 +"pemasu from Finland" made a donation (2013/7).
2691 +The Parted Magic Project made a donation (2013/9 and 11).
2692 +Pavel Barta made a donation (2013/10).
2693 +Nikolay Pertsev made a donation (2014/5).
2694 +James B made a donation (2014/7).
2695 +Stefano Di Biase made a donation (2014/8).
2696 +Daniel Epellei made a donation (2015/1).
2698 +Thank you very much.
2699 +Donations are always, including future donations, very important and
2700 +helpful for me to keep on developing aufs.
2704 +----------------------------------------
2705 +If you are an experienced user, no explanation is needed. Aufs is
2706 +just a linux filesystem.
2711 +# Local variables: ;
2714 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2715 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2716 +++ linux/fs/aufs/aufs.h 2015-06-28 17:35:44.344717109 +0200
2719 + * Copyright (C) 2005-2015 Junjiro R. Okajima
2721 + * This program, aufs is free software; you can redistribute it and/or modify
2722 + * it under the terms of the GNU General Public License as published by
2723 + * the Free Software Foundation; either version 2 of the License, or
2724 + * (at your option) any later version.
2726 + * This program is distributed in the hope that it will be useful,
2727 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2728 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2729 + * GNU General Public License for more details.
2731 + * You should have received a copy of the GNU General Public License
2732 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2736 + * all header files
2744 +#define AuStub(type, name, body, ...) \
2745 + static inline type name(__VA_ARGS__) { body; }
2747 +#define AuStubVoid(name, ...) \
2748 + AuStub(void, name, , __VA_ARGS__)
2749 +#define AuStubInt0(name, ...) \
2750 + AuStub(int, name, return 0, __VA_ARGS__)
2754 +#include "branch.h"
2757 +#include "dbgaufs.h"
2758 +#include "dentry.h"
2762 +#include "fstype.h"
2765 +#include "module.h"
2770 +#include "sysaufs.h"
2775 +#endif /* __KERNEL__ */
2776 +#endif /* __AUFS_H__ */
2777 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2778 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2779 +++ linux/fs/aufs/branch.c 2015-06-28 17:36:09.025073697 +0200
2782 + * Copyright (C) 2005-2015 Junjiro R. Okajima
2784 + * This program, aufs is free software; you can redistribute it and/or modify
2785 + * it under the terms of the GNU General Public License as published by
2786 + * the Free Software Foundation; either version 2 of the License, or
2787 + * (at your option) any later version.
2789 + * This program is distributed in the hope that it will be useful,
2790 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2791 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2792 + * GNU General Public License for more details.
2794 + * You should have received a copy of the GNU General Public License
2795 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2799 + * branch management
2802 +#include <linux/compat.h>
2803 +#include <linux/statfs.h>
2807 + * free a single branch
2809 +static void au_br_do_free(struct au_branch *br)
2812 + struct au_wbr *wbr;
2813 + struct au_dykey **key;
2815 + au_hnotify_fin_br(br);
2817 + if (br->br_xino.xi_file)
2818 + fput(br->br_xino.xi_file);
2819 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2821 + AuDebugOn(atomic_read(&br->br_count));
2825 + for (i = 0; i < AuBrWh_Last; i++)
2826 + dput(wbr->wbr_wh[i]);
2827 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2828 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2831 + if (br->br_fhsm) {
2832 + au_br_fhsm_fin(br->br_fhsm);
2833 + kfree(br->br_fhsm);
2836 + key = br->br_dykey;
2837 + for (i = 0; i < AuBrDynOp; i++, key++)
2843 + /* recursive lock, s_umount of branch's */
2845 + path_put(&br->br_path);
2852 + * frees all branches
2854 +void au_br_free(struct au_sbinfo *sbinfo)
2856 + aufs_bindex_t bmax;
2857 + struct au_branch **br;
2859 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2861 + bmax = sbinfo->si_bend + 1;
2862 + br = sbinfo->si_branch;
2864 + au_br_do_free(*br++);
2868 + * find the index of a branch which is specified by @br_id.
2870 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2872 + aufs_bindex_t bindex, bend;
2874 + bend = au_sbend(sb);
2875 + for (bindex = 0; bindex <= bend; bindex++)
2876 + if (au_sbr_id(sb, bindex) == br_id)
2881 +/* ---------------------------------------------------------------------- */
2887 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2888 + struct dentry *h_root)
2890 + if (unlikely(h_adding == h_root
2891 + || au_test_loopback_overlap(sb, h_adding)))
2893 + if (h_adding->d_sb != h_root->d_sb)
2895 + return au_test_subdir(h_adding, h_root)
2896 + || au_test_subdir(h_root, h_adding);
2900 + * returns a newly allocated branch. @new_nbranch is a number of branches
2901 + * after adding a branch.
2903 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2906 + struct au_branch *add_branch;
2907 + struct dentry *root;
2908 + struct inode *inode;
2912 + root = sb->s_root;
2913 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2914 + if (unlikely(!add_branch))
2917 + err = au_hnotify_init_br(add_branch, perm);
2918 + if (unlikely(err))
2921 + add_branch->br_wbr = NULL;
2922 + if (au_br_writable(perm)) {
2923 + /* may be freed separately at changing the branch permission */
2924 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2926 + if (unlikely(!add_branch->br_wbr))
2930 + add_branch->br_fhsm = NULL;
2931 + if (au_br_fhsm(perm)) {
2932 + err = au_fhsm_br_alloc(add_branch);
2933 + if (unlikely(err))
2937 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2939 + err = au_di_realloc(au_di(root), new_nbranch);
2941 + inode = d_inode(root);
2942 + err = au_ii_realloc(au_ii(inode), new_nbranch);
2945 + return add_branch; /* success */
2948 + kfree(add_branch->br_wbr);
2950 + au_hnotify_fin_br(add_branch);
2952 + kfree(add_branch);
2954 + return ERR_PTR(err);
2958 + * test if the branch permission is legal or not.
2960 +static int test_br(struct inode *inode, int brperm, char *path)
2964 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2969 + pr_err("write permission for readonly mount or inode, %s\n", path);
2977 + * 0: success, the caller will add it
2978 + * plus: success, it is already unified, the caller should ignore it
2981 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2984 + aufs_bindex_t bend, bindex;
2985 + struct dentry *root, *h_dentry;
2986 + struct inode *inode, *h_inode;
2988 + root = sb->s_root;
2989 + bend = au_sbend(sb);
2990 + if (unlikely(bend >= 0
2991 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2995 + pr_err("%s duplicated\n", add->pathname);
3000 + err = -ENOSPC; /* -E2BIG; */
3001 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3002 + || AUFS_BRANCH_MAX - 1 <= bend)) {
3003 + pr_err("number of branches exceeded %s\n", add->pathname);
3008 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
3009 + pr_err("bad index %d\n", add->bindex);
3013 + inode = d_inode(add->path.dentry);
3015 + if (unlikely(!inode->i_nlink)) {
3016 + pr_err("no existence %s\n", add->pathname);
3021 + if (unlikely(inode->i_sb == sb)) {
3022 + pr_err("%s must be outside\n", add->pathname);
3026 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3027 + pr_err("unsupported filesystem, %s (%s)\n",
3028 + add->pathname, au_sbtype(inode->i_sb));
3032 + if (unlikely(inode->i_sb->s_stack_depth)) {
3033 + pr_err("already stacked, %s (%s)\n",
3034 + add->pathname, au_sbtype(inode->i_sb));
3038 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3039 + if (unlikely(err))
3043 + return 0; /* success */
3046 + for (bindex = 0; bindex <= bend; bindex++)
3047 + if (unlikely(test_overlap(sb, add->path.dentry,
3048 + au_h_dptr(root, bindex)))) {
3049 + pr_err("%s is overlapped\n", add->pathname);
3054 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3055 + h_dentry = au_h_dptr(root, 0);
3056 + h_inode = d_inode(h_dentry);
3057 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3058 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3059 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3060 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3062 + i_uid_read(inode), i_gid_read(inode),
3063 + (inode->i_mode & S_IALLUGO),
3064 + i_uid_read(h_inode), i_gid_read(h_inode),
3065 + (h_inode->i_mode & S_IALLUGO));
3073 + * initialize or clean the whiteouts for an adding branch
3075 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3078 + int err, old_perm;
3079 + aufs_bindex_t bindex;
3080 + struct mutex *h_mtx;
3081 + struct au_wbr *wbr;
3082 + struct au_hinode *hdir;
3083 + struct dentry *h_dentry;
3085 + err = vfsub_mnt_want_write(au_br_mnt(br));
3086 + if (unlikely(err))
3090 + old_perm = br->br_perm;
3091 + br->br_perm = new_perm;
3094 + bindex = au_br_index(sb, br->br_id);
3095 + if (0 <= bindex) {
3096 + hdir = au_hi(d_inode(sb->s_root), bindex);
3097 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
3099 + h_dentry = au_br_dentry(br);
3100 + h_mtx = &d_inode(h_dentry)->i_mutex;
3101 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
3104 + err = au_wh_init(br, sb);
3106 + wbr_wh_write_lock(wbr);
3107 + err = au_wh_init(br, sb);
3108 + wbr_wh_write_unlock(wbr);
3111 + au_hn_imtx_unlock(hdir);
3113 + mutex_unlock(h_mtx);
3114 + vfsub_mnt_drop_write(au_br_mnt(br));
3115 + br->br_perm = old_perm;
3117 + if (!err && wbr && !au_br_writable(new_perm)) {
3119 + br->br_wbr = NULL;
3126 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3130 + struct kstatfs kst;
3131 + struct au_wbr *wbr;
3134 + au_rw_init(&wbr->wbr_wh_rwsem);
3135 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
3136 + atomic_set(&wbr->wbr_wh_running, 0);
3137 + wbr->wbr_bytes = 0;
3140 + * a limit for rmdir/rename a dir
3141 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3143 + err = vfs_statfs(&br->br_path, &kst);
3144 + if (unlikely(err))
3147 + if (kst.f_namelen >= NAME_MAX)
3148 + err = au_br_init_wh(sb, br, perm);
3150 + pr_err("%pd(%s), unsupported namelen %ld\n",
3152 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3158 +/* initialize a new branch */
3159 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3160 + struct au_opt_add *add)
3163 + struct inode *h_inode;
3166 + memset(&br->br_xino, 0, sizeof(br->br_xino));
3167 + mutex_init(&br->br_xino.xi_nondir_mtx);
3168 + br->br_perm = add->perm;
3169 + br->br_path = add->path; /* set first, path_get() later */
3170 + spin_lock_init(&br->br_dykey_lock);
3171 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
3172 + atomic_set(&br->br_count, 0);
3173 + atomic_set(&br->br_xino_running, 0);
3174 + br->br_id = au_new_br_id(sb);
3175 + AuDebugOn(br->br_id < 0);
3177 + if (au_br_writable(add->perm)) {
3178 + err = au_wbr_init(br, sb, add->perm);
3179 + if (unlikely(err))
3183 + if (au_opt_test(au_mntflags(sb), XINO)) {
3184 + h_inode = d_inode(add->path.dentry);
3185 + err = au_xino_br(sb, br, h_inode->i_ino,
3186 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3187 + if (unlikely(err)) {
3188 + AuDebugOn(br->br_xino.xi_file);
3193 + sysaufs_br_init(br);
3194 + path_get(&br->br_path);
3195 + goto out; /* success */
3198 + memset(&br->br_path, 0, sizeof(br->br_path));
3203 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3204 + struct au_branch *br, aufs_bindex_t bend,
3205 + aufs_bindex_t amount)
3207 + struct au_branch **brp;
3209 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3211 + brp = sbinfo->si_branch + bindex;
3212 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3214 + sbinfo->si_bend++;
3215 + if (unlikely(bend < 0))
3216 + sbinfo->si_bend = 0;
3219 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3220 + aufs_bindex_t bend, aufs_bindex_t amount)
3222 + struct au_hdentry *hdp;
3224 + AuRwMustWriteLock(&dinfo->di_rwsem);
3226 + hdp = dinfo->di_hdentry + bindex;
3227 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3228 + au_h_dentry_init(hdp);
3230 + if (unlikely(bend < 0))
3231 + dinfo->di_bstart = 0;
3234 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3235 + aufs_bindex_t bend, aufs_bindex_t amount)
3237 + struct au_hinode *hip;
3239 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3241 + hip = iinfo->ii_hinode + bindex;
3242 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3243 + hip->hi_inode = NULL;
3246 + if (unlikely(bend < 0))
3247 + iinfo->ii_bstart = 0;
3250 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3251 + aufs_bindex_t bindex)
3253 + struct dentry *root, *h_dentry;
3254 + struct inode *root_inode, *h_inode;
3255 + aufs_bindex_t bend, amount;
3257 + root = sb->s_root;
3258 + root_inode = d_inode(root);
3259 + bend = au_sbend(sb);
3260 + amount = bend + 1 - bindex;
3261 + h_dentry = au_br_dentry(br);
3262 + au_sbilist_lock();
3263 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
3264 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
3265 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
3266 + au_set_h_dptr(root, bindex, dget(h_dentry));
3267 + h_inode = d_inode(h_dentry);
3268 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3269 + au_sbilist_unlock();
3272 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3275 + aufs_bindex_t bend, add_bindex;
3276 + struct dentry *root, *h_dentry;
3277 + struct inode *root_inode;
3278 + struct au_branch *add_branch;
3280 + root = sb->s_root;
3281 + root_inode = d_inode(root);
3282 + IMustLock(root_inode);
3283 + err = test_add(sb, add, remount);
3284 + if (unlikely(err < 0))
3288 + goto out; /* success */
3291 + bend = au_sbend(sb);
3292 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
3293 + err = PTR_ERR(add_branch);
3294 + if (IS_ERR(add_branch))
3297 + err = au_br_init(add_branch, sb, add);
3298 + if (unlikely(err)) {
3299 + au_br_do_free(add_branch);
3303 + add_bindex = add->bindex;
3305 + au_br_do_add(sb, add_branch, add_bindex);
3307 + sysaufs_brs_del(sb, add_bindex);
3308 + au_br_do_add(sb, add_branch, add_bindex);
3309 + sysaufs_brs_add(sb, add_bindex);
3312 + h_dentry = add->path.dentry;
3313 + if (!add_bindex) {
3314 + au_cpup_attr_all(root_inode, /*force*/1);
3315 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3317 + au_add_nlink(root_inode, d_inode(h_dentry));
3320 + * this test/set prevents aufs from handling unnecesary notify events
3321 + * of xino files, in case of re-adding a writable branch which was
3322 + * once detached from aufs.
3324 + if (au_xino_brid(sb) < 0
3325 + && au_br_writable(add_branch->br_perm)
3326 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3327 + && add_branch->br_xino.xi_file
3328 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3329 + au_xino_brid_set(sb, add_branch->br_id);
3335 +/* ---------------------------------------------------------------------- */
3337 +static unsigned long long au_farray_cb(void *a,
3338 + unsigned long long max __maybe_unused,
3341 + unsigned long long n;
3342 + struct file **p, *f;
3343 + struct au_sphlhead *files;
3344 + struct au_finfo *finfo;
3345 + struct super_block *sb = arg;
3349 + files = &au_sbi(sb)->si_files;
3350 + spin_lock(&files->spin);
3351 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3352 + f = finfo->fi_file;
3354 + && !special_file(file_inode(f)->i_mode)) {
3358 + AuDebugOn(n > max);
3361 + spin_unlock(&files->spin);
3366 +static struct file **au_farray_alloc(struct super_block *sb,
3367 + unsigned long long *max)
3369 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3370 + return au_array_alloc(max, au_farray_cb, sb);
3373 +static void au_farray_free(struct file **a, unsigned long long max)
3375 + unsigned long long ull;
3377 + for (ull = 0; ull < max; ull++)
3383 +/* ---------------------------------------------------------------------- */
3389 +/* to show the line number, do not make it inlined function */
3390 +#define AuVerbose(do_info, fmt, ...) do { \
3392 + pr_info(fmt, ##__VA_ARGS__); \
3395 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
3396 + aufs_bindex_t bend)
3398 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
3401 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
3402 + aufs_bindex_t bend)
3404 + return au_test_ibusy(d_inode(dentry), bstart, bend);
3408 + * test if the branch is deletable or not.
3410 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3411 + unsigned int sigen, const unsigned int verbose)
3413 + int err, i, j, ndentry;
3414 + aufs_bindex_t bstart, bend;
3415 + struct au_dcsub_pages dpages;
3416 + struct au_dpage *dpage;
3419 + err = au_dpages_init(&dpages, GFP_NOFS);
3420 + if (unlikely(err))
3422 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3423 + if (unlikely(err))
3426 + for (i = 0; !err && i < dpages.ndpage; i++) {
3427 + dpage = dpages.dpages + i;
3428 + ndentry = dpage->ndentry;
3429 + for (j = 0; !err && j < ndentry; j++) {
3430 + d = dpage->dentries[j];
3431 + AuDebugOn(au_dcount(d) <= 0);
3432 + if (!au_digen_test(d, sigen)) {
3433 + di_read_lock_child(d, AuLock_IR);
3434 + if (unlikely(au_dbrange_test(d))) {
3435 + di_read_unlock(d, AuLock_IR);
3439 + di_write_lock_child(d);
3440 + if (unlikely(au_dbrange_test(d))) {
3441 + di_write_unlock(d);
3444 + err = au_reval_dpath(d, sigen);
3446 + di_downgrade_lock(d, AuLock_IR);
3448 + di_write_unlock(d);
3453 + /* AuDbgDentry(d); */
3454 + bstart = au_dbstart(d);
3455 + bend = au_dbend(d);
3456 + if (bstart <= bindex
3458 + && au_h_dptr(d, bindex)
3459 + && au_test_dbusy(d, bstart, bend)) {
3461 + AuVerbose(verbose, "busy %pd\n", d);
3464 + di_read_unlock(d, AuLock_IR);
3469 + au_dpages_free(&dpages);
3474 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3475 + unsigned int sigen, const unsigned int verbose)
3478 + unsigned long long max, ull;
3479 + struct inode *i, **array;
3480 + aufs_bindex_t bstart, bend;
3482 + array = au_iarray_alloc(sb, &max);
3483 + err = PTR_ERR(array);
3484 + if (IS_ERR(array))
3488 + AuDbg("b%d\n", bindex);
3489 + for (ull = 0; !err && ull < max; ull++) {
3493 + if (i->i_ino == AUFS_ROOT_INO)
3496 + /* AuDbgInode(i); */
3497 + if (au_iigen(i, NULL) == sigen)
3498 + ii_read_lock_child(i);
3500 + ii_write_lock_child(i);
3501 + err = au_refresh_hinode_self(i);
3504 + ii_downgrade_lock(i);
3506 + ii_write_unlock(i);
3511 + bstart = au_ibstart(i);
3512 + bend = au_ibend(i);
3513 + if (bstart <= bindex
3515 + && au_h_iptr(i, bindex)
3516 + && au_test_ibusy(i, bstart, bend)) {
3518 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3521 + ii_read_unlock(i);
3523 + au_iarray_free(array, max);
3529 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3530 + const unsigned int verbose)
3533 + unsigned int sigen;
3535 + sigen = au_sigen(root->d_sb);
3536 + DiMustNoWaiters(root);
3537 + IiMustNoWaiters(d_inode(root));
3538 + di_write_unlock(root);
3539 + err = test_dentry_busy(root, bindex, sigen, verbose);
3541 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3542 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3547 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3548 + struct file **to_free, int *idx)
3551 + unsigned char matched, root;
3552 + aufs_bindex_t bindex, bend;
3553 + struct au_fidir *fidir;
3554 + struct au_hfile *hfile;
3557 + root = IS_ROOT(file->f_path.dentry);
3560 + to_free[*idx] = file;
3566 + fidir = au_fi(file)->fi_hdir;
3567 + AuDebugOn(!fidir);
3568 + bend = au_fbend_dir(file);
3569 + for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
3570 + hfile = fidir->fd_hfile + bindex;
3571 + if (!hfile->hf_file)
3574 + if (hfile->hf_br->br_id == br_id) {
3586 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3587 + struct file **to_free, int opened)
3590 + unsigned long long ull, max;
3591 + aufs_bindex_t bstart;
3592 + struct file *file, **array;
3593 + struct dentry *root;
3594 + struct au_hfile *hfile;
3596 + array = au_farray_alloc(sb, &max);
3597 + err = PTR_ERR(array);
3598 + if (IS_ERR(array))
3603 + root = sb->s_root;
3604 + di_write_unlock(root);
3605 + for (ull = 0; ull < max; ull++) {
3606 + file = array[ull];
3607 + if (unlikely(!file))
3610 + /* AuDbg("%pD\n", file); */
3611 + fi_read_lock(file);
3612 + bstart = au_fbstart(file);
3613 + if (!d_is_dir(file->f_path.dentry)) {
3614 + hfile = &au_fi(file)->fi_htop;
3615 + if (hfile->hf_br->br_id == br_id)
3618 + err = test_dir_busy(file, br_id, to_free, &idx);
3619 + fi_read_unlock(file);
3620 + if (unlikely(err))
3623 + di_write_lock_child(root);
3624 + au_farray_free(array, max);
3625 + AuDebugOn(idx > opened);
3631 +static void br_del_file(struct file **to_free, unsigned long long opened,
3632 + aufs_bindex_t br_id)
3634 + unsigned long long ull;
3635 + aufs_bindex_t bindex, bstart, bend, bfound;
3636 + struct file *file;
3637 + struct au_fidir *fidir;
3638 + struct au_hfile *hfile;
3640 + for (ull = 0; ull < opened; ull++) {
3641 + file = to_free[ull];
3642 + if (unlikely(!file))
3645 + /* AuDbg("%pD\n", file); */
3646 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3648 + fidir = au_fi(file)->fi_hdir;
3649 + AuDebugOn(!fidir);
3650 + fi_write_lock(file);
3651 + bstart = au_fbstart(file);
3652 + bend = au_fbend_dir(file);
3653 + for (bindex = bstart; bindex <= bend; bindex++) {
3654 + hfile = fidir->fd_hfile + bindex;
3655 + if (!hfile->hf_file)
3658 + if (hfile->hf_br->br_id == br_id) {
3663 + AuDebugOn(bfound < 0);
3664 + au_set_h_fptr(file, bfound, NULL);
3665 + if (bfound == bstart) {
3666 + for (bstart++; bstart <= bend; bstart++)
3667 + if (au_hf_dir(file, bstart)) {
3668 + au_set_fbstart(file, bstart);
3672 + fi_write_unlock(file);
3676 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3677 + const aufs_bindex_t bindex,
3678 + const aufs_bindex_t bend)
3680 + struct au_branch **brp, **p;
3682 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3684 + brp = sbinfo->si_branch + bindex;
3685 + if (bindex < bend)
3686 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3687 + sbinfo->si_branch[0 + bend] = NULL;
3688 + sbinfo->si_bend--;
3690 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3692 + sbinfo->si_branch = p;
3693 + /* harmless error */
3696 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3697 + const aufs_bindex_t bend)
3699 + struct au_hdentry *hdp, *p;
3701 + AuRwMustWriteLock(&dinfo->di_rwsem);
3703 + hdp = dinfo->di_hdentry;
3704 + if (bindex < bend)
3705 + memmove(hdp + bindex, hdp + bindex + 1,
3706 + sizeof(*hdp) * (bend - bindex));
3707 + hdp[0 + bend].hd_dentry = NULL;
3710 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3712 + dinfo->di_hdentry = p;
3713 + /* harmless error */
3716 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3717 + const aufs_bindex_t bend)
3719 + struct au_hinode *hip, *p;
3721 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3723 + hip = iinfo->ii_hinode + bindex;
3724 + if (bindex < bend)
3725 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3726 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3727 + au_hn_init(iinfo->ii_hinode + bend);
3730 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3732 + iinfo->ii_hinode = p;
3733 + /* harmless error */
3736 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3737 + struct au_branch *br)
3739 + aufs_bindex_t bend;
3740 + struct au_sbinfo *sbinfo;
3741 + struct dentry *root, *h_root;
3742 + struct inode *inode, *h_inode;
3743 + struct au_hinode *hinode;
3745 + SiMustWriteLock(sb);
3747 + root = sb->s_root;
3748 + inode = d_inode(root);
3749 + sbinfo = au_sbi(sb);
3750 + bend = sbinfo->si_bend;
3752 + h_root = au_h_dptr(root, bindex);
3753 + hinode = au_hi(inode, bindex);
3754 + h_inode = au_igrab(hinode->hi_inode);
3757 + au_sbilist_lock();
3758 + au_br_do_del_brp(sbinfo, bindex, bend);
3759 + au_br_do_del_hdp(au_di(root), bindex, bend);
3760 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3761 + au_sbilist_unlock();
3765 + au_br_do_free(br);
3768 +static unsigned long long empty_cb(void *array, unsigned long long max,
3774 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3777 + unsigned long long opened;
3778 + unsigned int mnt_flags;
3779 + aufs_bindex_t bindex, bend, br_id;
3780 + unsigned char do_wh, verbose;
3781 + struct au_branch *br;
3782 + struct au_wbr *wbr;
3783 + struct dentry *root;
3784 + struct file **to_free;
3789 + root = sb->s_root;
3790 + bindex = au_find_dbindex(root, del->h_path.dentry);
3793 + goto out; /* success */
3795 + pr_err("%s no such branch\n", del->pathname);
3798 + AuDbg("bindex b%d\n", bindex);
3801 + mnt_flags = au_mntflags(sb);
3802 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3803 + bend = au_sbend(sb);
3804 + if (unlikely(!bend)) {
3805 + AuVerbose(verbose, "no more branches left\n");
3808 + br = au_sbr(sb, bindex);
3809 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3811 + br_id = br->br_id;
3812 + opened = atomic_read(&br->br_count);
3813 + if (unlikely(opened)) {
3814 + to_free = au_array_alloc(&opened, empty_cb, NULL);
3815 + err = PTR_ERR(to_free);
3816 + if (IS_ERR(to_free))
3819 + err = test_file_busy(sb, br_id, to_free, opened);
3820 + if (unlikely(err)) {
3821 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3827 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3829 + /* instead of WbrWhMustWriteLock(wbr) */
3830 + SiMustWriteLock(sb);
3831 + for (i = 0; i < AuBrWh_Last; i++) {
3832 + dput(wbr->wbr_wh[i]);
3833 + wbr->wbr_wh[i] = NULL;
3837 + err = test_children_busy(root, bindex, verbose);
3838 + if (unlikely(err)) {
3847 + * now we confirmed the branch is deletable.
3848 + * let's free the remaining opened dirs on the branch.
3850 + di_write_unlock(root);
3851 + br_del_file(to_free, opened, br_id);
3852 + di_write_lock_child(root);
3856 + au_br_do_del(sb, bindex, br);
3858 + sysaufs_brs_del(sb, bindex);
3859 + au_br_do_del(sb, bindex, br);
3860 + sysaufs_brs_add(sb, bindex);
3864 + au_cpup_attr_all(d_inode(root), /*force*/1);
3865 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3867 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3868 + if (au_opt_test(mnt_flags, PLINK))
3869 + au_plink_half_refresh(sb, br_id);
3871 + if (au_xino_brid(sb) == br_id)
3872 + au_xino_brid_set(sb, -1);
3873 + goto out; /* success */
3877 + rerr = au_br_init_wh(sb, br, br->br_perm);
3879 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3880 + del->pathname, rerr);
3883 + au_farray_free(to_free, opened);
3887 +/* ---------------------------------------------------------------------- */
3889 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3892 + aufs_bindex_t bstart, bend;
3893 + struct aufs_ibusy ibusy;
3894 + struct inode *inode, *h_inode;
3897 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3900 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3902 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3903 + if (unlikely(err)) {
3910 + si_read_lock(sb, AuLock_FLUSH);
3911 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3915 + ibusy.h_ino = 0; /* invalid */
3916 + inode = ilookup(sb, ibusy.ino);
3918 + || inode->i_ino == AUFS_ROOT_INO
3919 + || is_bad_inode(inode))
3922 + ii_read_lock_child(inode);
3923 + bstart = au_ibstart(inode);
3924 + bend = au_ibend(inode);
3925 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3926 + h_inode = au_h_iptr(inode, ibusy.bindex);
3927 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3928 + ibusy.h_ino = h_inode->i_ino;
3930 + ii_read_unlock(inode);
3934 + si_read_unlock(sb);
3936 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3937 + if (unlikely(err)) {
3946 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3948 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
3951 +#ifdef CONFIG_COMPAT
3952 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3954 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
3958 +/* ---------------------------------------------------------------------- */
3961 + * change a branch permission
3964 +static void au_warn_ima(void)
3967 + /* since it doesn't support mark_files_ro() */
3968 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3972 +static int do_need_sigen_inc(int a, int b)
3974 + return au_br_whable(a) && !au_br_whable(b);
3977 +static int need_sigen_inc(int old, int new)
3979 + return do_need_sigen_inc(old, new)
3980 + || do_need_sigen_inc(new, old);
3983 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3986 + unsigned int mnt_flags;
3987 + unsigned long long ull, max;
3988 + aufs_bindex_t br_id;
3989 + unsigned char verbose, writer;
3990 + struct file *file, *hf, **array;
3991 + struct au_hfile *hfile;
3993 + mnt_flags = au_mntflags(sb);
3994 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3996 + array = au_farray_alloc(sb, &max);
3997 + err = PTR_ERR(array);
3998 + if (IS_ERR(array))
4002 + br_id = au_sbr_id(sb, bindex);
4003 + for (ull = 0; ull < max; ull++) {
4004 + file = array[ull];
4005 + if (unlikely(!file))
4008 + /* AuDbg("%pD\n", file); */
4009 + fi_read_lock(file);
4010 + if (unlikely(au_test_mmapped(file))) {
4012 + AuVerbose(verbose, "mmapped %pD\n", file);
4014 + FiMustNoWaiters(file);
4015 + fi_read_unlock(file);
4019 + hfile = &au_fi(file)->fi_htop;
4020 + hf = hfile->hf_file;
4021 + if (!d_is_reg(file->f_path.dentry)
4022 + || !(file->f_mode & FMODE_WRITE)
4023 + || hfile->hf_br->br_id != br_id
4024 + || !(hf->f_mode & FMODE_WRITE))
4025 + array[ull] = NULL;
4031 + FiMustNoWaiters(file);
4032 + fi_read_unlock(file);
4040 + for (ull = 0; ull < max; ull++) {
4041 + file = array[ull];
4045 + /* todo: already flushed? */
4047 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4048 + * approach which resets f_mode and calls mnt_drop_write() and
4049 + * file_release_write() for each file, because the branch
4050 + * attribute in aufs world is totally different from the native
4053 + /* fi_read_lock(file); */
4054 + hfile = &au_fi(file)->fi_htop;
4055 + hf = hfile->hf_file;
4056 + /* fi_read_unlock(file); */
4057 + spin_lock(&hf->f_lock);
4058 + writer = !!(hf->f_mode & FMODE_WRITER);
4059 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4060 + spin_unlock(&hf->f_lock);
4062 + put_write_access(file_inode(hf));
4063 + __mnt_drop_write(hf->f_path.mnt);
4068 + au_farray_free(array, max);
4074 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4078 + aufs_bindex_t bindex;
4079 + struct dentry *root;
4080 + struct au_branch *br;
4081 + struct au_br_fhsm *bf;
4083 + root = sb->s_root;
4084 + bindex = au_find_dbindex(root, mod->h_root);
4087 + return 0; /* success */
4089 + pr_err("%s no such branch\n", mod->path);
4092 + AuDbg("bindex b%d\n", bindex);
4094 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4095 + if (unlikely(err))
4098 + br = au_sbr(sb, bindex);
4099 + AuDebugOn(mod->h_root != au_br_dentry(br));
4100 + if (br->br_perm == mod->perm)
4101 + return 0; /* success */
4103 + /* pre-allocate for non-fhsm --> fhsm */
4105 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4106 + err = au_fhsm_br_alloc(br);
4107 + if (unlikely(err))
4110 + br->br_fhsm = NULL;
4113 + if (au_br_writable(br->br_perm)) {
4114 + /* remove whiteout base */
4115 + err = au_br_init_wh(sb, br, mod->perm);
4116 + if (unlikely(err))
4119 + if (!au_br_writable(mod->perm)) {
4120 + /* rw --> ro, file might be mmapped */
4121 + DiMustNoWaiters(root);
4122 + IiMustNoWaiters(d_inode(root));
4123 + di_write_unlock(root);
4124 + err = au_br_mod_files_ro(sb, bindex);
4125 + /* aufs_write_lock() calls ..._child() */
4126 + di_write_lock_child(root);
4128 + if (unlikely(err)) {
4130 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
4133 + rerr = au_wbr_init(br, sb, br->br_perm);
4134 + if (unlikely(rerr)) {
4135 + AuIOErr("nested error %d (%d)\n",
4137 + br->br_perm = mod->perm;
4141 + } else if (au_br_writable(mod->perm)) {
4144 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
4146 + err = au_wbr_init(br, sb, mod->perm);
4147 + if (unlikely(err)) {
4148 + kfree(br->br_wbr);
4149 + br->br_wbr = NULL;
4153 + if (unlikely(err))
4156 + if (au_br_fhsm(br->br_perm)) {
4157 + if (!au_br_fhsm(mod->perm)) {
4158 + /* fhsm --> non-fhsm */
4159 + au_br_fhsm_fin(br->br_fhsm);
4160 + kfree(br->br_fhsm);
4161 + br->br_fhsm = NULL;
4163 + } else if (au_br_fhsm(mod->perm))
4164 + /* non-fhsm --> fhsm */
4167 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4168 + br->br_perm = mod->perm;
4169 + goto out; /* success */
4178 +/* ---------------------------------------------------------------------- */
4180 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4183 + struct kstatfs kstfs;
4185 + err = vfs_statfs(&br->br_path, &kstfs);
4187 + stfs->f_blocks = kstfs.f_blocks;
4188 + stfs->f_bavail = kstfs.f_bavail;
4189 + stfs->f_files = kstfs.f_files;
4190 + stfs->f_ffree = kstfs.f_ffree;
4195 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4196 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4197 +++ linux/fs/aufs/branch.h 2015-06-28 17:36:09.025073697 +0200
4200 + * Copyright (C) 2005-2015 Junjiro R. Okajima
4202 + * This program, aufs is free software; you can redistribute it and/or modify
4203 + * it under the terms of the GNU General Public License as published by
4204 + * the Free Software Foundation; either version 2 of the License, or
4205 + * (at your option) any later version.
4207 + * This program is distributed in the hope that it will be useful,
4208 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4209 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4210 + * GNU General Public License for more details.
4212 + * You should have received a copy of the GNU General Public License
4213 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4217 + * branch filesystems and xino for them
4220 +#ifndef __AUFS_BRANCH_H__
4221 +#define __AUFS_BRANCH_H__
4225 +#include <linux/mount.h>
4230 +/* ---------------------------------------------------------------------- */
4233 +struct au_xino_file {
4234 + struct file *xi_file;
4235 + struct mutex xi_nondir_mtx;
4237 + /* todo: make xino files an array to support huge inode number */
4239 +#ifdef CONFIG_DEBUG_FS
4240 + struct dentry *xi_dbgaufs;
4244 +/* File-based Hierarchical Storage Management */
4245 +struct au_br_fhsm {
4246 +#ifdef CONFIG_AUFS_FHSM
4247 + struct mutex bf_lock;
4248 + unsigned long bf_jiffy;
4249 + struct aufs_stfs bf_stfs;
4254 +/* members for writable branch only */
4255 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4257 + struct au_rwsem wbr_wh_rwsem;
4258 + struct dentry *wbr_wh[AuBrWh_Last];
4259 + atomic_t wbr_wh_running;
4260 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4261 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4262 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4265 + unsigned long long wbr_bytes;
4268 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4269 +#define AuBrDynOp (AuDyLast * 4)
4271 +#ifdef CONFIG_AUFS_HFSNOTIFY
4272 +/* support for asynchronous destruction */
4273 +struct au_br_hfsnotify {
4274 + struct fsnotify_group *hfsn_group;
4278 +/* sysfs entries */
4279 +struct au_brsysfs {
4281 + struct attribute attr;
4290 +/* protected by superblock rwsem */
4292 + struct au_xino_file br_xino;
4294 + aufs_bindex_t br_id;
4297 + struct path br_path;
4298 + spinlock_t br_dykey_lock;
4299 + struct au_dykey *br_dykey[AuBrDynOp];
4300 + atomic_t br_count;
4302 + struct au_wbr *br_wbr;
4303 + struct au_br_fhsm *br_fhsm;
4305 + /* xino truncation */
4306 + atomic_t br_xino_running;
4308 +#ifdef CONFIG_AUFS_HFSNOTIFY
4309 + struct au_br_hfsnotify *br_hfsn;
4312 +#ifdef CONFIG_SYSFS
4313 + /* entries under sysfs per mount-point */
4314 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4318 +/* ---------------------------------------------------------------------- */
4320 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4322 + return br->br_path.mnt;
4325 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4327 + return br->br_path.dentry;
4330 +static inline struct super_block *au_br_sb(struct au_branch *br)
4332 + return au_br_mnt(br)->mnt_sb;
4335 +static inline int au_br_rdonly(struct au_branch *br)
4337 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4338 + || !au_br_writable(br->br_perm))
4342 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4344 +#ifdef CONFIG_AUFS_HNOTIFY
4345 + return !(brperm & AuBrPerm_RR);
4351 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4353 + int err, exec_flag;
4356 + exec_flag = oflag & __FMODE_EXEC;
4357 + if (unlikely(exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC)))
4363 +/* ---------------------------------------------------------------------- */
4367 +void au_br_free(struct au_sbinfo *sinfo);
4368 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4370 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4372 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4373 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4374 +#ifdef CONFIG_COMPAT
4375 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4378 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4381 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4384 +static const loff_t au_loff_max = LLONG_MAX;
4386 +int au_xib_trunc(struct super_block *sb);
4387 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4389 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4390 + size_t size, loff_t *pos);
4391 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4392 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4393 +ino_t au_xino_new_ino(struct super_block *sb);
4394 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4395 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4397 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4399 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4400 + struct file *base_file, int do_test);
4401 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4403 +struct au_opt_xino;
4404 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4405 +void au_xino_clr(struct super_block *sb);
4406 +struct file *au_xino_def(struct super_block *sb);
4407 +int au_xino_path(struct seq_file *seq, struct file *file);
4409 +/* ---------------------------------------------------------------------- */
4411 +/* Superblock to branch */
4413 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4415 + return au_sbr(sb, bindex)->br_id;
4419 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4421 + return au_br_mnt(au_sbr(sb, bindex));
4425 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4427 + return au_br_sb(au_sbr(sb, bindex));
4430 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4432 + atomic_dec(&au_sbr(sb, bindex)->br_count);
4435 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4437 + return au_sbr(sb, bindex)->br_perm;
4440 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4442 + return au_br_whable(au_sbr_perm(sb, bindex));
4445 +/* ---------------------------------------------------------------------- */
4448 + * wbr_wh_read_lock, wbr_wh_write_lock
4449 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4451 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4453 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4454 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4455 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4457 +/* ---------------------------------------------------------------------- */
4459 +#ifdef CONFIG_AUFS_FHSM
4460 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4462 + mutex_init(&brfhsm->bf_lock);
4463 + brfhsm->bf_jiffy = 0;
4464 + brfhsm->bf_readable = 0;
4467 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4469 + mutex_destroy(&brfhsm->bf_lock);
4472 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4473 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4476 +#endif /* __KERNEL__ */
4477 +#endif /* __AUFS_BRANCH_H__ */
4478 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4479 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4480 +++ linux/fs/aufs/conf.mk 2015-06-28 17:35:44.348050491 +0200
4483 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4487 +AuConfStr += ${1}=${${1}}
4491 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4493 + HNOTIFY HFSNOTIFY \
4504 +$(foreach i, ${AuConfAll}, \
4505 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4507 +AuConfName = ${obj}/conf.str
4508 +${AuConfName}.tmp: FORCE
4509 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4510 +${AuConfName}: ${AuConfName}.tmp
4511 + @diff -q $< $@ > /dev/null 2>&1 || { \
4512 + echo ' GEN ' $@; \
4516 +clean-files += ${AuConfName} ${AuConfName}.tmp
4517 +${obj}/sysfs.o: ${AuConfName}
4519 +-include ${srctree}/${src}/conf_priv.mk
4520 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4521 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4522 +++ linux/fs/aufs/cpup.c 2015-06-28 17:36:09.025073697 +0200
4525 + * Copyright (C) 2005-2015 Junjiro R. Okajima
4527 + * This program, aufs is free software; you can redistribute it and/or modify
4528 + * it under the terms of the GNU General Public License as published by
4529 + * the Free Software Foundation; either version 2 of the License, or
4530 + * (at your option) any later version.
4532 + * This program is distributed in the hope that it will be useful,
4533 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4534 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4535 + * GNU General Public License for more details.
4537 + * You should have received a copy of the GNU General Public License
4538 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4542 + * copy-up functions, see wbr_policy.c for copy-down
4545 +#include <linux/fs_stack.h>
4546 +#include <linux/mm.h>
4549 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4551 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4552 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4554 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4556 + dst->i_flags |= iflags & ~mask;
4557 + if (au_test_fs_notime(dst->i_sb))
4558 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4561 +void au_cpup_attr_timesizes(struct inode *inode)
4563 + struct inode *h_inode;
4565 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4566 + fsstack_copy_attr_times(inode, h_inode);
4567 + fsstack_copy_inode_size(inode, h_inode);
4570 +void au_cpup_attr_nlink(struct inode *inode, int force)
4572 + struct inode *h_inode;
4573 + struct super_block *sb;
4574 + aufs_bindex_t bindex, bend;
4577 + bindex = au_ibstart(inode);
4578 + h_inode = au_h_iptr(inode, bindex);
4580 + && !S_ISDIR(h_inode->i_mode)
4581 + && au_opt_test(au_mntflags(sb), PLINK)
4582 + && au_plink_test(inode))
4586 + * 0 can happen in revalidating.
4587 + * h_inode->i_mutex may not be held here, but it is harmless since once
4588 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4590 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4591 + * the incorrect link count.
4593 + set_nlink(inode, h_inode->i_nlink);
4596 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4597 + * it may includes whplink directory.
4599 + if (S_ISDIR(h_inode->i_mode)) {
4600 + bend = au_ibend(inode);
4601 + for (bindex++; bindex <= bend; bindex++) {
4602 + h_inode = au_h_iptr(inode, bindex);
4604 + au_add_nlink(inode, h_inode);
4609 +void au_cpup_attr_changeable(struct inode *inode)
4611 + struct inode *h_inode;
4613 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4614 + inode->i_mode = h_inode->i_mode;
4615 + inode->i_uid = h_inode->i_uid;
4616 + inode->i_gid = h_inode->i_gid;
4617 + au_cpup_attr_timesizes(inode);
4618 + au_cpup_attr_flags(inode, h_inode->i_flags);
4621 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4623 + struct au_iinfo *iinfo = au_ii(inode);
4625 + IiMustWriteLock(inode);
4627 + iinfo->ii_higen = h_inode->i_generation;
4628 + iinfo->ii_hsb1 = h_inode->i_sb;
4631 +void au_cpup_attr_all(struct inode *inode, int force)
4633 + struct inode *h_inode;
4635 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4636 + au_cpup_attr_changeable(inode);
4637 + if (inode->i_nlink > 0)
4638 + au_cpup_attr_nlink(inode, force);
4639 + inode->i_rdev = h_inode->i_rdev;
4640 + inode->i_blkbits = h_inode->i_blkbits;
4641 + au_cpup_igen(inode, h_inode);
4644 +/* ---------------------------------------------------------------------- */
4646 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4648 +/* keep the timestamps of the parent dir when cpup */
4649 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4650 + struct path *h_path)
4652 + struct inode *h_inode;
4654 + dt->dt_dentry = dentry;
4655 + dt->dt_h_path = *h_path;
4656 + h_inode = d_inode(h_path->dentry);
4657 + dt->dt_atime = h_inode->i_atime;
4658 + dt->dt_mtime = h_inode->i_mtime;
4662 +void au_dtime_revert(struct au_dtime *dt)
4664 + struct iattr attr;
4667 + attr.ia_atime = dt->dt_atime;
4668 + attr.ia_mtime = dt->dt_mtime;
4669 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4670 + | ATTR_ATIME | ATTR_ATIME_SET;
4672 + /* no delegation since this is a directory */
4673 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4674 + if (unlikely(err))
4675 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4678 +/* ---------------------------------------------------------------------- */
4680 +/* internal use only */
4681 +struct au_cpup_reg_attr {
4684 + unsigned int iflags; /* inode->i_flags */
4687 +static noinline_for_stack
4688 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4689 + struct au_cpup_reg_attr *h_src_attr)
4691 + int err, sbits, icex;
4692 + unsigned int mnt_flags;
4693 + unsigned char verbose;
4695 + struct path h_path;
4696 + struct inode *h_isrc, *h_idst;
4697 + struct kstat *h_st;
4698 + struct au_branch *br;
4700 + h_path.dentry = au_h_dptr(dst, bindex);
4701 + h_idst = d_inode(h_path.dentry);
4702 + br = au_sbr(dst->d_sb, bindex);
4703 + h_path.mnt = au_br_mnt(br);
4704 + h_isrc = d_inode(h_src);
4705 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4706 + | ATTR_ATIME | ATTR_MTIME
4707 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4708 + if (h_src_attr && h_src_attr->valid) {
4709 + h_st = &h_src_attr->st;
4710 + ia.ia_uid = h_st->uid;
4711 + ia.ia_gid = h_st->gid;
4712 + ia.ia_atime = h_st->atime;
4713 + ia.ia_mtime = h_st->mtime;
4714 + if (h_idst->i_mode != h_st->mode
4715 + && !S_ISLNK(h_idst->i_mode)) {
4716 + ia.ia_valid |= ATTR_MODE;
4717 + ia.ia_mode = h_st->mode;
4719 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4720 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4722 + ia.ia_uid = h_isrc->i_uid;
4723 + ia.ia_gid = h_isrc->i_gid;
4724 + ia.ia_atime = h_isrc->i_atime;
4725 + ia.ia_mtime = h_isrc->i_mtime;
4726 + if (h_idst->i_mode != h_isrc->i_mode
4727 + && !S_ISLNK(h_idst->i_mode)) {
4728 + ia.ia_valid |= ATTR_MODE;
4729 + ia.ia_mode = h_isrc->i_mode;
4731 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4732 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4734 + /* no delegation since it is just created */
4735 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4737 + /* is this nfs only? */
4738 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4739 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4740 + ia.ia_mode = h_isrc->i_mode;
4741 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4744 + icex = br->br_perm & AuBrAttr_ICEX;
4746 + mnt_flags = au_mntflags(dst->d_sb);
4747 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4748 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4754 +/* ---------------------------------------------------------------------- */
4756 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4757 + char *buf, unsigned long blksize)
4760 + size_t sz, rbytes, wbytes;
4761 + unsigned char all_zero;
4763 + struct mutex *h_mtx;
4764 + /* reduce stack usage */
4767 + zp = page_address(ZERO_PAGE(0));
4768 + if (unlikely(!zp))
4769 + return -ENOMEM; /* possible? */
4774 + AuDbg("len %lld\n", len);
4776 + if (len < blksize)
4780 + /* todo: signal_pending? */
4781 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4782 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4785 + if (unlikely(err < 0))
4789 + if (len >= rbytes && rbytes == blksize)
4790 + all_zero = !memcmp(buf, zp, rbytes);
4797 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4799 + /* todo: signal_pending? */
4800 + if (unlikely(err == -EAGAIN || err == -EINTR))
4802 + if (unlikely(err < 0))
4807 + if (unlikely(err < 0))
4813 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4815 + if (unlikely(res < 0))
4822 + /* the last block may be a hole */
4823 + if (!err && all_zero) {
4824 + AuLabel(last hole);
4827 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4828 + /* nfs requires this step to make last hole */
4829 + /* is this only nfs? */
4831 + /* todo: signal_pending? */
4832 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4833 + } while (err == -EAGAIN || err == -EINTR);
4840 + ia->ia_size = dst->f_pos;
4841 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4842 + ia->ia_file = dst;
4843 + h_mtx = &file_inode(dst)->i_mutex;
4844 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4845 + /* no delegation since it is just created */
4846 + err = vfsub_notify_change(&dst->f_path, ia,
4847 + /*delegated*/NULL);
4848 + mutex_unlock(h_mtx);
4855 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4858 + unsigned long blksize;
4859 + unsigned char do_kfree;
4863 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
4864 + if (!blksize || PAGE_SIZE < blksize)
4865 + blksize = PAGE_SIZE;
4866 + AuDbg("blksize %lu\n", blksize);
4867 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4869 + buf = kmalloc(blksize, GFP_NOFS);
4871 + buf = (void *)__get_free_page(GFP_NOFS);
4872 + if (unlikely(!buf))
4875 + if (len > (1 << 22))
4876 + AuDbg("copying a large file %lld\n", (long long)len);
4880 + err = au_do_copy_file(dst, src, len, buf, blksize);
4884 + free_page((unsigned long)buf);
4891 + * to support a sparse file which is opened with O_APPEND,
4892 + * we need to close the file.
4894 +static int au_cp_regular(struct au_cp_generic *cpg)
4897 + enum { SRC, DST };
4899 + aufs_bindex_t bindex;
4900 + unsigned int flags;
4901 + struct dentry *dentry;
4903 + struct file *file;
4907 + .bindex = cpg->bsrc,
4908 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4912 + .bindex = cpg->bdst,
4913 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4914 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4915 + .label = &&out_src
4918 + struct super_block *sb;
4920 + /* bsrc branch can be ro/rw. */
4921 + sb = cpg->dentry->d_sb;
4923 + for (i = 0; i < 2; i++, f++) {
4924 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4925 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4926 + /*file*/NULL, f->force_wr);
4927 + err = PTR_ERR(f->file);
4928 + if (IS_ERR(f->file))
4932 + /* try stopping to update while we copyup */
4933 + IMustLock(d_inode(file[SRC].dentry));
4934 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4936 + fput(file[DST].file);
4937 + au_sbr_put(sb, file[DST].bindex);
4940 + fput(file[SRC].file);
4941 + au_sbr_put(sb, file[SRC].bindex);
4946 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4947 + struct au_cpup_reg_attr *h_src_attr)
4951 + struct path h_path;
4952 + struct inode *h_src_inode, *h_dst_inode;
4955 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
4956 + l = i_size_read(h_src_inode);
4957 + if (cpg->len == -1 || l < cpg->len)
4960 + /* try stopping to update while we are referencing */
4961 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4962 + au_pin_hdir_unlock(cpg->pin);
4964 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4965 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4966 + h_src_attr->iflags = h_src_inode->i_flags;
4967 + if (!au_test_nfs(h_src_inode->i_sb))
4968 + err = vfs_getattr(&h_path, &h_src_attr->st);
4970 + mutex_unlock(&h_src_inode->i_mutex);
4971 + err = vfs_getattr(&h_path, &h_src_attr->st);
4972 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4974 + if (unlikely(err)) {
4975 + mutex_unlock(&h_src_inode->i_mutex);
4978 + h_src_attr->valid = 1;
4979 + err = au_cp_regular(cpg);
4980 + mutex_unlock(&h_src_inode->i_mutex);
4981 + rerr = au_pin_hdir_relock(cpg->pin);
4985 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
4986 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
4987 + h_dst_inode = d_inode(h_path.dentry);
4988 + spin_lock(&h_dst_inode->i_lock);
4989 + h_dst_inode->i_state |= I_LINKABLE;
4990 + spin_unlock(&h_dst_inode->i_lock);
4997 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4998 + struct inode *h_dir)
5001 + mm_segment_t old_fs;
5006 + struct inode *h_inode = d_inode(h_src);
5007 + const struct inode_operations *h_iop = h_inode->i_op;
5010 + if (unlikely(!h_iop->readlink))
5014 + sym.k = (void *)__get_free_page(GFP_NOFS);
5015 + if (unlikely(!sym.k))
5018 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5019 + old_fs = get_fs();
5020 + set_fs(KERNEL_DS);
5021 + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX);
5026 + sym.k[symlen] = 0;
5027 + err = vfsub_symlink(h_dir, h_path, sym.k);
5029 + free_page((unsigned long)sym.k);
5035 +static noinline_for_stack
5036 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5037 + struct au_cpup_reg_attr *h_src_attr)
5041 + unsigned int mnt_flags;
5042 + unsigned char isdir, isreg, force;
5043 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5044 + struct au_dtime dt;
5045 + struct path h_path;
5046 + struct dentry *h_src, *h_dst, *h_parent;
5047 + struct inode *h_inode, *h_dir, *dir, *inode;
5048 + struct super_block *sb;
5050 + /* bsrc branch can be ro/rw. */
5051 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5052 + h_inode = d_inode(h_src);
5053 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5055 + /* try stopping to be referenced while we are creating */
5056 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5057 + if (au_ftest_cpup(cpg->flags, RENAME))
5058 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5059 + AUFS_WH_PFX_LEN));
5060 + h_parent = h_dst->d_parent; /* dir inode is locked */
5061 + h_dir = d_inode(h_parent);
5063 + AuDebugOn(h_parent != h_dst->d_parent);
5065 + sb = cpg->dentry->d_sb;
5066 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5068 + h_path.dentry = h_parent;
5069 + au_dtime_store(&dt, dst_parent, &h_path);
5071 + h_path.dentry = h_dst;
5075 + mode = h_inode->i_mode;
5076 + switch (mode & S_IFMT) {
5079 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
5080 + /*want_excl*/true);
5082 + err = au_do_cpup_regular(cpg, h_src_attr);
5086 + err = vfsub_mkdir(h_dir, &h_path, mode);
5089 + * strange behaviour from the users view,
5090 + * particularry setattr case
5092 + dir = d_inode(dst_parent);
5093 + if (au_ibstart(dir) == cpg->bdst)
5094 + au_cpup_attr_nlink(dir, /*force*/1);
5095 + inode = d_inode(cpg->dentry);
5096 + au_cpup_attr_nlink(inode, /*force*/1);
5100 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5104 + AuDebugOn(!capable(CAP_MKNOD));
5108 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5111 + AuIOErr("Unknown inode type 0%o\n", mode);
5115 + mnt_flags = au_mntflags(sb);
5116 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5118 + && au_opt_test(mnt_flags, XINO)
5119 + && (h_inode->i_nlink == 1
5120 + || (h_inode->i_state & I_LINKABLE))
5121 + /* todo: unnecessary? */
5122 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5123 + && cpg->bdst < cpg->bsrc
5124 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5125 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5126 + /* ignore this error */
5131 + force = !!cpg->len;
5132 + if (cpg->len == -1)
5133 + force = !!i_size_read(h_inode);
5135 + au_fhsm_wrote(sb, cpg->bdst, force);
5139 + au_dtime_revert(&dt);
5143 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5146 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5147 + struct inode *h_dir;
5148 + aufs_bindex_t bdst;
5150 + dentry = cpg->dentry;
5152 + h_dentry = au_h_dptr(dentry, bdst);
5153 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5155 + au_set_h_dptr(dentry, bdst, NULL);
5156 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5158 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5159 + au_set_h_dptr(dentry, bdst, h_dentry);
5162 + parent = dget_parent(dentry);
5163 + h_parent = au_h_dptr(parent, bdst);
5165 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5166 + if (IS_ERR(h_path->dentry))
5167 + err = PTR_ERR(h_path->dentry);
5169 + if (unlikely(err))
5172 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5173 + h_dir = d_inode(h_parent);
5175 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5176 + /* no delegation since it is just created */
5177 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
5178 + dput(h_path->dentry);
5185 + * copyup the @dentry from @bsrc to @bdst.
5186 + * the caller must set the both of lower dentries.
5187 + * @len is for truncating when it is -1 copyup the entire file.
5188 + * in link/rename cases, @dst_parent may be different from the real one.
5189 + * basic->bsrc can be larger than basic->bdst.
5191 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5194 + aufs_bindex_t old_ibstart;
5195 + unsigned char isdir, plink;
5196 + struct dentry *h_src, *h_dst, *h_parent;
5197 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5198 + struct super_block *sb;
5199 + struct au_branch *br;
5200 + /* to reuduce stack size */
5202 + struct au_dtime dt;
5203 + struct path h_path;
5204 + struct au_cpup_reg_attr h_src_attr;
5208 + a = kmalloc(sizeof(*a), GFP_NOFS);
5211 + a->h_src_attr.valid = 0;
5213 + sb = cpg->dentry->d_sb;
5214 + br = au_sbr(sb, cpg->bdst);
5215 + a->h_path.mnt = au_br_mnt(br);
5216 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5217 + h_parent = h_dst->d_parent; /* dir inode is locked */
5218 + h_dir = d_inode(h_parent);
5221 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5222 + inode = d_inode(cpg->dentry);
5225 + dst_parent = dget_parent(cpg->dentry);
5229 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5230 + dst_inode = au_h_iptr(inode, cpg->bdst);
5232 + if (unlikely(!plink)) {
5234 + AuIOErr("hi%lu(i%lu) exists on b%d "
5235 + "but plink is disabled\n",
5236 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5240 + if (dst_inode->i_nlink) {
5241 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5243 + h_src = au_plink_lkup(inode, cpg->bdst);
5244 + err = PTR_ERR(h_src);
5245 + if (IS_ERR(h_src))
5247 + if (unlikely(d_is_negative(h_src))) {
5249 + AuIOErr("i%lu exists on a upper branch "
5250 + "but not pseudo-linked\n",
5257 + a->h_path.dentry = h_parent;
5258 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5261 + a->h_path.dentry = h_dst;
5263 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5264 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5265 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5267 + au_dtime_revert(&a->dt);
5268 + if (unlikely(err == -EWOULDBLOCK)) {
5269 + pr_warn("cannot retry for NFSv4 delegation"
5270 + " for an internal link\n");
5276 + /* todo: cpup_wh_file? */
5278 + au_update_ibrange(inode, /*do_put_zero*/1);
5281 + isdir = S_ISDIR(inode->i_mode);
5282 + old_ibstart = au_ibstart(inode);
5283 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5284 + if (unlikely(err))
5286 + dst_inode = d_inode(h_dst);
5287 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
5288 + /* todo: necessary? */
5289 + /* au_pin_hdir_unlock(cpg->pin); */
5291 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5292 + if (unlikely(err)) {
5293 + /* todo: necessary? */
5294 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5295 + mutex_unlock(&dst_inode->i_mutex);
5299 + if (cpg->bdst < old_ibstart) {
5300 + if (S_ISREG(inode->i_mode)) {
5301 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5302 + if (unlikely(err)) {
5303 + /* ignore an error */
5304 + /* au_pin_hdir_relock(cpg->pin); */
5305 + mutex_unlock(&dst_inode->i_mutex);
5309 + au_set_ibstart(inode, cpg->bdst);
5311 + au_set_ibend(inode, cpg->bdst);
5312 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5313 + au_hi_flags(inode, isdir));
5315 + /* todo: necessary? */
5316 + /* err = au_pin_hdir_relock(cpg->pin); */
5317 + mutex_unlock(&dst_inode->i_mutex);
5318 + if (unlikely(err))
5321 + src_inode = d_inode(h_src);
5323 + && (src_inode->i_nlink > 1
5324 + || src_inode->i_state & I_LINKABLE)
5326 + au_plink_append(inode, cpg->bdst, h_dst);
5328 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5329 + a->h_path.dentry = h_dst;
5330 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5333 + goto out_parent; /* success */
5337 + a->h_path.dentry = h_parent;
5338 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5339 + a->h_path.dentry = h_dst;
5341 + if (d_is_positive(h_dst)) {
5343 + /* no delegation since it is just created */
5344 + rerr = vfsub_unlink(h_dir, &a->h_path,
5345 + /*delegated*/NULL, /*force*/0);
5347 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5349 + au_dtime_revert(&a->dt);
5351 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5361 +#if 0 /* reserved */
5362 +struct au_cpup_single_args {
5364 + struct au_cp_generic *cpg;
5365 + struct dentry *dst_parent;
5368 +static void au_call_cpup_single(void *args)
5370 + struct au_cpup_single_args *a = args;
5372 + au_pin_hdir_acquire_nest(a->cpg->pin);
5373 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5374 + au_pin_hdir_release(a->cpg->pin);
5379 + * prevent SIGXFSZ in copy-up.
5380 + * testing CAP_MKNOD is for generic fs,
5381 + * but CAP_FSETID is for xfs only, currently.
5383 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5386 + struct super_block *sb;
5387 + struct inode *h_dir;
5390 + sb = au_pinned_parent(pin)->d_sb;
5391 + if (!au_wkq_test()
5392 + && (!au_sbi(sb)->si_plink_maint_pid
5393 + || au_plink_maint(sb, AuLock_NOPLM))) {
5394 + switch (mode & S_IFMT) {
5396 + /* no condition about RLIMIT_FSIZE and the file size */
5401 + do_sio = !capable(CAP_MKNOD);
5405 + do_sio = ((mode & (S_ISUID | S_ISGID))
5406 + && !capable(CAP_FSETID));
5407 + /* this workaround may be removed in the future */
5409 + h_dir = au_pinned_h_dir(pin);
5410 + do_sio = h_dir->i_mode & S_ISVTX;
5417 +#if 0 /* reserved */
5418 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5421 + struct dentry *h_dentry;
5423 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5424 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5425 + err = au_cpup_single(cpg, dst_parent);
5427 + struct au_cpup_single_args args = {
5430 + .dst_parent = dst_parent
5432 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5433 + if (unlikely(wkq_err))
5442 + * copyup the @dentry from the first active lower branch to @bdst,
5443 + * using au_cpup_single().
5445 +static int au_cpup_simple(struct au_cp_generic *cpg)
5448 + unsigned int flags_orig;
5449 + struct dentry *dentry;
5451 + AuDebugOn(cpg->bsrc < 0);
5453 + dentry = cpg->dentry;
5454 + DiMustWriteLock(dentry);
5456 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5458 + flags_orig = cpg->flags;
5459 + au_fset_cpup(cpg->flags, RENAME);
5460 + err = au_cpup_single(cpg, NULL);
5461 + cpg->flags = flags_orig;
5463 + return 0; /* success */
5466 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5467 + au_set_dbstart(dentry, cpg->bsrc);
5473 +struct au_cpup_simple_args {
5475 + struct au_cp_generic *cpg;
5478 +static void au_call_cpup_simple(void *args)
5480 + struct au_cpup_simple_args *a = args;
5482 + au_pin_hdir_acquire_nest(a->cpg->pin);
5483 + *a->errp = au_cpup_simple(a->cpg);
5484 + au_pin_hdir_release(a->cpg->pin);
5487 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5490 + struct dentry *dentry, *parent;
5491 + struct file *h_file;
5492 + struct inode *h_dir;
5494 + dentry = cpg->dentry;
5496 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5497 + AuDebugOn(cpg->bsrc < 0);
5498 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5499 + err = PTR_ERR(h_file);
5500 + if (IS_ERR(h_file))
5504 + parent = dget_parent(dentry);
5505 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5506 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5507 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5508 + err = au_cpup_simple(cpg);
5510 + struct au_cpup_simple_args args = {
5514 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5515 + if (unlikely(wkq_err))
5521 + au_h_open_post(dentry, cpg->bsrc, h_file);
5527 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5529 + aufs_bindex_t bsrc, bend;
5530 + struct dentry *dentry, *h_dentry;
5532 + if (cpg->bsrc < 0) {
5533 + dentry = cpg->dentry;
5534 + bend = au_dbend(dentry);
5535 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5536 + h_dentry = au_h_dptr(dentry, bsrc);
5538 + AuDebugOn(d_is_negative(h_dentry));
5542 + AuDebugOn(bsrc > bend);
5545 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5546 + return au_do_sio_cpup_simple(cpg);
5549 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5551 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5552 + return au_do_sio_cpup_simple(cpg);
5555 +/* ---------------------------------------------------------------------- */
5558 + * copyup the deleted file for writing.
5560 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5561 + struct file *file)
5564 + unsigned int flags_orig;
5565 + aufs_bindex_t bsrc_orig;
5566 + struct dentry *h_d_dst, *h_d_start;
5567 + struct au_dinfo *dinfo;
5568 + struct au_hdentry *hdp;
5570 + dinfo = au_di(cpg->dentry);
5571 + AuRwMustWriteLock(&dinfo->di_rwsem);
5573 + bsrc_orig = cpg->bsrc;
5574 + cpg->bsrc = dinfo->di_bstart;
5575 + hdp = dinfo->di_hdentry;
5576 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5577 + dinfo->di_bstart = cpg->bdst;
5578 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5581 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5582 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_path.dentry;
5584 + flags_orig = cpg->flags;
5585 + cpg->flags = !AuCpup_DTIME;
5586 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5587 + cpg->flags = flags_orig;
5590 + err = au_reopen_nondir(file);
5591 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5593 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5594 + dinfo->di_bstart = cpg->bsrc;
5595 + cpg->bsrc = bsrc_orig;
5600 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5603 + aufs_bindex_t bdst;
5604 + struct au_dtime dt;
5605 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5606 + struct au_branch *br;
5607 + struct path h_path;
5609 + dentry = cpg->dentry;
5611 + br = au_sbr(dentry->d_sb, bdst);
5612 + parent = dget_parent(dentry);
5613 + h_parent = au_h_dptr(parent, bdst);
5614 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5615 + err = PTR_ERR(wh_dentry);
5616 + if (IS_ERR(wh_dentry))
5619 + h_path.dentry = h_parent;
5620 + h_path.mnt = au_br_mnt(br);
5621 + au_dtime_store(&dt, parent, &h_path);
5622 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5623 + if (unlikely(err))
5627 + h_path.dentry = wh_dentry;
5628 + if (!d_is_dir(wh_dentry)) {
5629 + /* no delegation since it is just created */
5630 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5631 + /*delegated*/NULL, /*force*/0);
5633 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5634 + if (unlikely(err)) {
5635 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5639 + au_dtime_revert(&dt);
5640 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5649 +struct au_cpup_wh_args {
5651 + struct au_cp_generic *cpg;
5652 + struct file *file;
5655 +static void au_call_cpup_wh(void *args)
5657 + struct au_cpup_wh_args *a = args;
5659 + au_pin_hdir_acquire_nest(a->cpg->pin);
5660 + *a->errp = au_cpup_wh(a->cpg, a->file);
5661 + au_pin_hdir_release(a->cpg->pin);
5664 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5667 + aufs_bindex_t bdst;
5668 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5669 + struct inode *dir, *h_dir, *h_tmpdir;
5670 + struct au_wbr *wbr;
5671 + struct au_pin wh_pin, *pin_orig;
5673 + dentry = cpg->dentry;
5675 + parent = dget_parent(dentry);
5676 + dir = d_inode(parent);
5679 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5682 + if (!h_dir->i_nlink) {
5683 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5684 + h_orph = wbr->wbr_orph;
5686 + h_parent = dget(au_h_dptr(parent, bdst));
5687 + au_set_h_dptr(parent, bdst, dget(h_orph));
5688 + h_tmpdir = d_inode(h_orph);
5689 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5691 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
5692 + /* todo: au_h_open_pre()? */
5694 + pin_orig = cpg->pin;
5695 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5696 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5697 + cpg->pin = &wh_pin;
5700 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5701 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5702 + err = au_cpup_wh(cpg, file);
5704 + struct au_cpup_wh_args args = {
5709 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5710 + if (unlikely(wkq_err))
5715 + mutex_unlock(&h_tmpdir->i_mutex);
5716 + /* todo: au_h_open_post()? */
5717 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5718 + au_set_h_dptr(parent, bdst, h_parent);
5719 + AuDebugOn(!pin_orig);
5720 + cpg->pin = pin_orig;
5728 +/* ---------------------------------------------------------------------- */
5731 + * generic routine for both of copy-up and copy-down.
5733 +/* cf. revalidate function in file.c */
5734 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5735 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5736 + struct au_pin *pin,
5737 + struct dentry *h_parent, void *arg),
5741 + struct au_pin pin;
5742 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
5745 + parent = dget_parent(dentry);
5746 + if (IS_ROOT(parent))
5749 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5750 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5752 + /* do not use au_dpage */
5753 + real_parent = parent;
5756 + parent = dget_parent(dentry);
5757 + h_parent = au_h_dptr(parent, bdst);
5759 + goto out; /* success */
5761 + /* find top dir which is necessary to cpup */
5765 + parent = dget_parent(d);
5766 + di_read_lock_parent3(parent, !AuLock_IR);
5767 + h_parent = au_h_dptr(parent, bdst);
5768 + di_read_unlock(parent, !AuLock_IR);
5769 + } while (!h_parent);
5771 + if (d != real_parent)
5772 + di_write_lock_child3(d);
5774 + /* somebody else might create while we were sleeping */
5775 + h_dentry = au_h_dptr(d, bdst);
5776 + if (!h_dentry || d_is_negative(h_dentry)) {
5778 + au_update_dbstart(d);
5780 + au_pin_set_dentry(&pin, d);
5781 + err = au_do_pin(&pin);
5783 + err = cp(d, bdst, &pin, h_parent, arg);
5788 + if (d != real_parent)
5789 + di_write_unlock(d);
5790 + if (unlikely(err))
5799 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5800 + struct au_pin *pin,
5801 + struct dentry *h_parent __maybe_unused,
5802 + void *arg __maybe_unused)
5804 + struct au_cp_generic cpg = {
5810 + .flags = AuCpup_DTIME
5812 + return au_sio_cpup_simple(&cpg);
5815 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5817 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5820 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5823 + struct dentry *parent;
5824 + struct inode *dir;
5826 + parent = dget_parent(dentry);
5827 + dir = d_inode(parent);
5829 + if (au_h_iptr(dir, bdst))
5832 + di_read_unlock(parent, AuLock_IR);
5833 + di_write_lock_parent(parent);
5834 + /* someone else might change our inode while we were sleeping */
5835 + if (!au_h_iptr(dir, bdst))
5836 + err = au_cpup_dirs(dentry, bdst);
5837 + di_downgrade_lock(parent, AuLock_IR);
5843 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5844 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5845 +++ linux/fs/aufs/cpup.h 2015-06-28 17:35:44.348050491 +0200
5848 + * Copyright (C) 2005-2015 Junjiro R. Okajima
5850 + * This program, aufs is free software; you can redistribute it and/or modify
5851 + * it under the terms of the GNU General Public License as published by
5852 + * the Free Software Foundation; either version 2 of the License, or
5853 + * (at your option) any later version.
5855 + * This program is distributed in the hope that it will be useful,
5856 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5857 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5858 + * GNU General Public License for more details.
5860 + * You should have received a copy of the GNU General Public License
5861 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5865 + * copy-up/down functions
5868 +#ifndef __AUFS_CPUP_H__
5869 +#define __AUFS_CPUP_H__
5873 +#include <linux/path.h>
5879 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5880 +void au_cpup_attr_timesizes(struct inode *inode);
5881 +void au_cpup_attr_nlink(struct inode *inode, int force);
5882 +void au_cpup_attr_changeable(struct inode *inode);
5883 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5884 +void au_cpup_attr_all(struct inode *inode, int force);
5886 +/* ---------------------------------------------------------------------- */
5888 +struct au_cp_generic {
5889 + struct dentry *dentry;
5890 + aufs_bindex_t bdst, bsrc;
5892 + struct au_pin *pin;
5893 + unsigned int flags;
5897 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5898 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5900 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5901 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5903 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5905 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5906 + the branch is marked as RO */
5908 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5909 +#define au_fset_cpup(flags, name) \
5910 + do { (flags) |= AuCpup_##name; } while (0)
5911 +#define au_fclr_cpup(flags, name) \
5912 + do { (flags) &= ~AuCpup_##name; } while (0)
5914 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5915 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5916 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5917 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5919 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5920 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5921 + struct au_pin *pin,
5922 + struct dentry *h_parent, void *arg),
5924 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5925 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5927 +/* ---------------------------------------------------------------------- */
5929 +/* keep timestamps when copyup */
5931 + struct dentry *dt_dentry;
5932 + struct path dt_h_path;
5933 + struct timespec dt_atime, dt_mtime;
5935 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5936 + struct path *h_path);
5937 +void au_dtime_revert(struct au_dtime *dt);
5939 +#endif /* __KERNEL__ */
5940 +#endif /* __AUFS_CPUP_H__ */
5941 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5942 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5943 +++ linux/fs/aufs/dbgaufs.c 2015-06-28 17:35:44.348050491 +0200
5946 + * Copyright (C) 2005-2015 Junjiro R. Okajima
5948 + * This program, aufs is free software; you can redistribute it and/or modify
5949 + * it under the terms of the GNU General Public License as published by
5950 + * the Free Software Foundation; either version 2 of the License, or
5951 + * (at your option) any later version.
5953 + * This program is distributed in the hope that it will be useful,
5954 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5955 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5956 + * GNU General Public License for more details.
5958 + * You should have received a copy of the GNU General Public License
5959 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5963 + * debugfs interface
5966 +#include <linux/debugfs.h>
5969 +#ifndef CONFIG_SYSFS
5970 +#error DEBUG_FS depends upon SYSFS
5973 +static struct dentry *dbgaufs;
5974 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5976 +/* 20 is max digits length of ulong 64 */
5977 +struct dbgaufs_arg {
5983 + * common function for all XINO files
5985 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5986 + struct file *file)
5988 + kfree(file->private_data);
5992 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5996 + struct dbgaufs_arg *p;
5999 + p = kmalloc(sizeof(*p), GFP_NOFS);
6005 + file->private_data = p;
6009 + err = vfs_getattr(&xf->f_path, &st);
6013 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
6014 + (long)file_count(xf), st.blocks, st.blksize,
6015 + (long long)st.size);
6017 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
6018 + st.blocks, st.blksize,
6019 + (long long)st.size);
6020 + AuDebugOn(p->n >= sizeof(p->a));
6022 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6031 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6032 + size_t count, loff_t *ppos)
6034 + struct dbgaufs_arg *p;
6036 + p = file->private_data;
6037 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6040 +/* ---------------------------------------------------------------------- */
6042 +struct dbgaufs_plink_arg {
6047 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6048 + struct file *file)
6050 + free_page((unsigned long)file->private_data);
6054 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6056 + int err, i, limit;
6057 + unsigned long n, sum;
6058 + struct dbgaufs_plink_arg *p;
6059 + struct au_sbinfo *sbinfo;
6060 + struct super_block *sb;
6061 + struct au_sphlhead *sphl;
6064 + p = (void *)get_zeroed_page(GFP_NOFS);
6069 + sbinfo = inode->i_private;
6070 + sb = sbinfo->si_sb;
6071 + si_noflush_read_lock(sb);
6072 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6073 + limit = PAGE_SIZE - sizeof(p->n);
6075 + /* the number of buckets */
6076 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6081 + for (i = 0, sphl = sbinfo->si_plink;
6082 + i < AuPlink_NHASH;
6084 + n = au_sphl_count(sphl);
6087 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6090 + if (unlikely(limit <= 0))
6093 + p->a[p->n - 1] = '\n';
6095 + /* the sum of plinks */
6096 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6099 + if (unlikely(limit <= 0))
6102 +#define str "1\n0\n0\n"
6103 + p->n = sizeof(str) - 1;
6104 + strcpy(p->a, str);
6107 + si_read_unlock(sb);
6110 + file->private_data = p;
6111 + goto out; /* success */
6114 + free_page((unsigned long)p);
6119 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6120 + size_t count, loff_t *ppos)
6122 + struct dbgaufs_plink_arg *p;
6124 + p = file->private_data;
6125 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6128 +static const struct file_operations dbgaufs_plink_fop = {
6129 + .owner = THIS_MODULE,
6130 + .open = dbgaufs_plink_open,
6131 + .release = dbgaufs_plink_release,
6132 + .read = dbgaufs_plink_read
6135 +/* ---------------------------------------------------------------------- */
6137 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6140 + struct au_sbinfo *sbinfo;
6141 + struct super_block *sb;
6143 + sbinfo = inode->i_private;
6144 + sb = sbinfo->si_sb;
6145 + si_noflush_read_lock(sb);
6146 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6147 + si_read_unlock(sb);
6151 +static const struct file_operations dbgaufs_xib_fop = {
6152 + .owner = THIS_MODULE,
6153 + .open = dbgaufs_xib_open,
6154 + .release = dbgaufs_xi_release,
6155 + .read = dbgaufs_xi_read
6158 +/* ---------------------------------------------------------------------- */
6160 +#define DbgaufsXi_PREFIX "xi"
6162 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6166 + struct au_sbinfo *sbinfo;
6167 + struct super_block *sb;
6169 + struct qstr *name;
6173 + name = &file->f_path.dentry->d_name;
6174 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6175 + || memcmp(name->name, DbgaufsXi_PREFIX,
6176 + sizeof(DbgaufsXi_PREFIX) - 1)))
6178 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6179 + if (unlikely(err))
6182 + sbinfo = inode->i_private;
6183 + sb = sbinfo->si_sb;
6184 + si_noflush_read_lock(sb);
6185 + if (l <= au_sbend(sb)) {
6186 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6187 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6190 + si_read_unlock(sb);
6196 +static const struct file_operations dbgaufs_xino_fop = {
6197 + .owner = THIS_MODULE,
6198 + .open = dbgaufs_xino_open,
6199 + .release = dbgaufs_xi_release,
6200 + .read = dbgaufs_xi_read
6203 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6205 + aufs_bindex_t bend;
6206 + struct au_branch *br;
6207 + struct au_xino_file *xi;
6209 + if (!au_sbi(sb)->si_dbgaufs)
6212 + bend = au_sbend(sb);
6213 + for (; bindex <= bend; bindex++) {
6214 + br = au_sbr(sb, bindex);
6215 + xi = &br->br_xino;
6216 + debugfs_remove(xi->xi_dbgaufs);
6217 + xi->xi_dbgaufs = NULL;
6221 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6223 + struct au_sbinfo *sbinfo;
6224 + struct dentry *parent;
6225 + struct au_branch *br;
6226 + struct au_xino_file *xi;
6227 + aufs_bindex_t bend;
6228 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6230 + sbinfo = au_sbi(sb);
6231 + parent = sbinfo->si_dbgaufs;
6235 + bend = au_sbend(sb);
6236 + for (; bindex <= bend; bindex++) {
6237 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6238 + br = au_sbr(sb, bindex);
6239 + xi = &br->br_xino;
6240 + AuDebugOn(xi->xi_dbgaufs);
6241 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6242 + sbinfo, &dbgaufs_xino_fop);
6243 + /* ignore an error */
6244 + if (unlikely(!xi->xi_dbgaufs))
6245 + AuWarn1("failed %s under debugfs\n", name);
6249 +/* ---------------------------------------------------------------------- */
6251 +#ifdef CONFIG_AUFS_EXPORT
6252 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6255 + struct au_sbinfo *sbinfo;
6256 + struct super_block *sb;
6258 + sbinfo = inode->i_private;
6259 + sb = sbinfo->si_sb;
6260 + si_noflush_read_lock(sb);
6261 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6262 + si_read_unlock(sb);
6266 +static const struct file_operations dbgaufs_xigen_fop = {
6267 + .owner = THIS_MODULE,
6268 + .open = dbgaufs_xigen_open,
6269 + .release = dbgaufs_xi_release,
6270 + .read = dbgaufs_xi_read
6273 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6278 + * This function is a dynamic '__init' function actually,
6279 + * so the tiny check for si_rwsem is unnecessary.
6281 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6284 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6285 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6286 + &dbgaufs_xigen_fop);
6287 + if (sbinfo->si_dbgaufs_xigen)
6293 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6297 +#endif /* CONFIG_AUFS_EXPORT */
6299 +/* ---------------------------------------------------------------------- */
6301 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6304 + * This function is a dynamic '__fin' function actually,
6305 + * so the tiny check for si_rwsem is unnecessary.
6307 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6309 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6310 + sbinfo->si_dbgaufs = NULL;
6311 + kobject_put(&sbinfo->si_kobj);
6314 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6317 + char name[SysaufsSiNameLen];
6320 + * This function is a dynamic '__init' function actually,
6321 + * so the tiny check for si_rwsem is unnecessary.
6323 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6327 + AuErr1("/debug/aufs is uninitialized\n");
6332 + sysaufs_name(sbinfo, name);
6333 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6334 + if (unlikely(!sbinfo->si_dbgaufs))
6336 + kobject_get(&sbinfo->si_kobj);
6338 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6339 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6340 + &dbgaufs_xib_fop);
6341 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6344 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6345 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6346 + &dbgaufs_plink_fop);
6347 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6350 + err = dbgaufs_xigen_init(sbinfo);
6352 + goto out; /* success */
6355 + dbgaufs_si_fin(sbinfo);
6360 +/* ---------------------------------------------------------------------- */
6362 +void dbgaufs_fin(void)
6364 + debugfs_remove(dbgaufs);
6367 +int __init dbgaufs_init(void)
6372 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6377 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6378 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6379 +++ linux/fs/aufs/dbgaufs.h 2015-06-28 17:35:44.348050491 +0200
6382 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6384 + * This program, aufs is free software; you can redistribute it and/or modify
6385 + * it under the terms of the GNU General Public License as published by
6386 + * the Free Software Foundation; either version 2 of the License, or
6387 + * (at your option) any later version.
6389 + * This program is distributed in the hope that it will be useful,
6390 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6391 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6392 + * GNU General Public License for more details.
6394 + * You should have received a copy of the GNU General Public License
6395 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6399 + * debugfs interface
6402 +#ifndef __DBGAUFS_H__
6403 +#define __DBGAUFS_H__
6407 +struct super_block;
6410 +#ifdef CONFIG_DEBUG_FS
6412 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6413 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6414 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6415 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6416 +void dbgaufs_fin(void);
6417 +int __init dbgaufs_init(void);
6419 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6420 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6421 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6422 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6423 +AuStubVoid(dbgaufs_fin, void)
6424 +AuStubInt0(__init dbgaufs_init, void)
6425 +#endif /* CONFIG_DEBUG_FS */
6427 +#endif /* __KERNEL__ */
6428 +#endif /* __DBGAUFS_H__ */
6429 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6430 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6431 +++ linux/fs/aufs/dcsub.c 2015-06-28 17:35:44.348050491 +0200
6434 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6436 + * This program, aufs is free software; you can redistribute it and/or modify
6437 + * it under the terms of the GNU General Public License as published by
6438 + * the Free Software Foundation; either version 2 of the License, or
6439 + * (at your option) any later version.
6441 + * This program is distributed in the hope that it will be useful,
6442 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6443 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6444 + * GNU General Public License for more details.
6446 + * You should have received a copy of the GNU General Public License
6447 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6451 + * sub-routines for dentry cache
6456 +static void au_dpage_free(struct au_dpage *dpage)
6459 + struct dentry **p;
6461 + p = dpage->dentries;
6462 + for (i = 0; i < dpage->ndentry; i++)
6464 + free_page((unsigned long)dpage->dentries);
6467 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6473 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6474 + if (unlikely(!dpages->dpages))
6477 + p = (void *)__get_free_page(gfp);
6481 + dpages->dpages[0].ndentry = 0;
6482 + dpages->dpages[0].dentries = p;
6483 + dpages->ndpage = 1;
6484 + return 0; /* success */
6487 + kfree(dpages->dpages);
6492 +void au_dpages_free(struct au_dcsub_pages *dpages)
6495 + struct au_dpage *p;
6497 + p = dpages->dpages;
6498 + for (i = 0; i < dpages->ndpage; i++)
6499 + au_dpage_free(p++);
6500 + kfree(dpages->dpages);
6503 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6504 + struct dentry *dentry, gfp_t gfp)
6507 + struct au_dpage *dpage;
6510 + dpage = dpages->dpages + dpages->ndpage - 1;
6511 + sz = PAGE_SIZE / sizeof(dentry);
6512 + if (unlikely(dpage->ndentry >= sz)) {
6513 + AuLabel(new dpage);
6515 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6516 + p = au_kzrealloc(dpages->dpages, sz,
6517 + sz + sizeof(*dpages->dpages), gfp);
6521 + dpages->dpages = p;
6522 + dpage = dpages->dpages + dpages->ndpage;
6523 + p = (void *)__get_free_page(gfp);
6527 + dpage->ndentry = 0;
6528 + dpage->dentries = p;
6532 + AuDebugOn(au_dcount(dentry) <= 0);
6533 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6534 + return 0; /* success */
6540 +/* todo: BAD approach */
6541 +/* copied from linux/fs/dcache.c */
6549 +extern void d_walk(struct dentry *parent, void *data,
6550 + enum d_walk_ret (*enter)(void *, struct dentry *),
6551 + void (*finish)(void *));
6553 +struct ac_dpages_arg {
6555 + struct au_dcsub_pages *dpages;
6556 + struct super_block *sb;
6557 + au_dpages_test test;
6561 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6563 + enum d_walk_ret ret;
6564 + struct ac_dpages_arg *arg = _arg;
6566 + ret = D_WALK_CONTINUE;
6567 + if (dentry->d_sb == arg->sb
6568 + && !IS_ROOT(dentry)
6569 + && au_dcount(dentry) > 0
6571 + && (!arg->test || arg->test(dentry, arg->arg))) {
6572 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6573 + if (unlikely(arg->err))
6574 + ret = D_WALK_QUIT;
6580 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6581 + au_dpages_test test, void *arg)
6583 + struct ac_dpages_arg args = {
6591 + d_walk(root, &args, au_call_dpages_append, NULL);
6596 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6597 + int do_include, au_dpages_test test, void *arg)
6602 + write_seqlock(&rename_lock);
6603 + spin_lock(&dentry->d_lock);
6605 + && au_dcount(dentry) > 0
6606 + && (!test || test(dentry, arg)))
6607 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6608 + spin_unlock(&dentry->d_lock);
6609 + if (unlikely(err))
6613 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6616 + while (!IS_ROOT(dentry)) {
6617 + dentry = dentry->d_parent; /* rename_lock is locked */
6618 + spin_lock(&dentry->d_lock);
6619 + if (au_dcount(dentry) > 0
6620 + && (!test || test(dentry, arg)))
6621 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6622 + spin_unlock(&dentry->d_lock);
6623 + if (unlikely(err))
6628 + write_sequnlock(&rename_lock);
6632 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6634 + return au_di(dentry) && dentry->d_sb == arg;
6637 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6638 + struct dentry *dentry, int do_include)
6640 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6641 + au_dcsub_dpages_aufs, dentry->d_sb);
6644 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6646 + struct path path[2] = {
6655 + return path_is_under(path + 0, path + 1);
6657 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6658 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6659 +++ linux/fs/aufs/dcsub.h 2015-06-28 17:36:09.025073697 +0200
6662 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6664 + * This program, aufs is free software; you can redistribute it and/or modify
6665 + * it under the terms of the GNU General Public License as published by
6666 + * the Free Software Foundation; either version 2 of the License, or
6667 + * (at your option) any later version.
6669 + * This program is distributed in the hope that it will be useful,
6670 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6671 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6672 + * GNU General Public License for more details.
6674 + * You should have received a copy of the GNU General Public License
6675 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6679 + * sub-routines for dentry cache
6682 +#ifndef __AUFS_DCSUB_H__
6683 +#define __AUFS_DCSUB_H__
6687 +#include <linux/dcache.h>
6688 +#include <linux/fs.h>
6692 + struct dentry **dentries;
6695 +struct au_dcsub_pages {
6697 + struct au_dpage *dpages;
6700 +/* ---------------------------------------------------------------------- */
6703 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6704 +void au_dpages_free(struct au_dcsub_pages *dpages);
6705 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6706 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6707 + au_dpages_test test, void *arg);
6708 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6709 + int do_include, au_dpages_test test, void *arg);
6710 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6711 + struct dentry *dentry, int do_include);
6712 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6714 +/* ---------------------------------------------------------------------- */
6717 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6718 + * include/linux/dcache.h. Try them (in the future).
6721 +static inline int au_d_hashed_positive(struct dentry *d)
6724 + struct inode *inode = d_inode(d);
6727 + if (unlikely(d_unhashed(d)
6728 + || d_is_negative(d)
6729 + || !inode->i_nlink))
6734 +static inline int au_d_linkable(struct dentry *d)
6737 + struct inode *inode = d_inode(d);
6739 + err = au_d_hashed_positive(d);
6741 + && d_is_positive(d)
6742 + && (inode->i_state & I_LINKABLE))
6747 +static inline int au_d_alive(struct dentry *d)
6750 + struct inode *inode;
6754 + err = au_d_hashed_positive(d);
6756 + inode = d_inode(d);
6757 + if (unlikely(d_unlinked(d)
6758 + || d_is_negative(d)
6759 + || !inode->i_nlink))
6765 +static inline int au_alive_dir(struct dentry *d)
6769 + err = au_d_alive(d);
6770 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
6775 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6777 + return a->len == b->len
6778 + && !memcmp(a->name, b->name, a->len);
6783 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
6785 + * the type of d_lockref.count became int, but the inlined function d_count()
6786 + * still returns unsigned int.
6787 + * I don't know why. Maybe it is for every d_count() users?
6788 + * Anyway au_dcount() lives on.
6790 +static inline int au_dcount(struct dentry *d)
6792 + return (int)d_count(d);
6795 +#endif /* __KERNEL__ */
6796 +#endif /* __AUFS_DCSUB_H__ */
6797 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6798 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6799 +++ linux/fs/aufs/debug.c 2015-06-28 17:36:09.025073697 +0200
6802 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6804 + * This program, aufs is free software; you can redistribute it and/or modify
6805 + * it under the terms of the GNU General Public License as published by
6806 + * the Free Software Foundation; either version 2 of the License, or
6807 + * (at your option) any later version.
6809 + * This program is distributed in the hope that it will be useful,
6810 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6811 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6812 + * GNU General Public License for more details.
6814 + * You should have received a copy of the GNU General Public License
6815 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6819 + * debug print functions
6824 +/* Returns 0, or -errno. arg is in kp->arg. */
6825 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6829 + err = kstrtoint(val, 0, &n);
6839 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6840 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6845 + return sprintf(buffer, "%d", atomic_read(a));
6848 +static struct kernel_param_ops param_ops_atomic_t = {
6849 + .set = param_atomic_t_set,
6850 + .get = param_atomic_t_get
6851 + /* void (*free)(void *arg) */
6854 +atomic_t aufs_debug = ATOMIC_INIT(0);
6855 +MODULE_PARM_DESC(debug, "debug print");
6856 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6858 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
6859 +char *au_plevel = KERN_DEBUG;
6860 +#define dpri(fmt, ...) do { \
6862 + && strcmp(au_plevel, KERN_DEBUG)) \
6863 + || au_debug_test()) \
6864 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6867 +/* ---------------------------------------------------------------------- */
6869 +void au_dpri_whlist(struct au_nhash *whlist)
6871 + unsigned long ul, n;
6872 + struct hlist_head *head;
6873 + struct au_vdir_wh *pos;
6875 + n = whlist->nh_num;
6876 + head = whlist->nh_head;
6877 + for (ul = 0; ul < n; ul++) {
6878 + hlist_for_each_entry(pos, head, wh_hash)
6879 + dpri("b%d, %.*s, %d\n",
6881 + pos->wh_str.len, pos->wh_str.name,
6887 +void au_dpri_vdir(struct au_vdir *vdir)
6890 + union au_vdir_deblk_p p;
6893 + if (!vdir || IS_ERR(vdir)) {
6894 + dpri("err %ld\n", PTR_ERR(vdir));
6898 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6899 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6900 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6901 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6902 + p.deblk = vdir->vd_deblk[ul];
6904 + dpri("[%lu]: %p\n", ul, o);
6908 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6909 + struct dentry *wh)
6914 + if (!inode || IS_ERR(inode)) {
6915 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6919 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6920 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6921 + && sizeof(inode->i_blocks) != sizeof(u64));
6923 + n = (void *)wh->d_name.name;
6924 + l = wh->d_name.len;
6927 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6928 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6930 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6931 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6932 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6933 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6934 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6935 + inode->i_state, inode->i_flags, inode->i_version,
6936 + inode->i_generation,
6937 + l ? ", wh " : "", l, n);
6941 +void au_dpri_inode(struct inode *inode)
6943 + struct au_iinfo *iinfo;
6944 + aufs_bindex_t bindex;
6947 + err = do_pri_inode(-1, inode, -1, NULL);
6948 + if (err || !au_test_aufs(inode->i_sb))
6951 + iinfo = au_ii(inode);
6954 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6955 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6956 + if (iinfo->ii_bstart < 0)
6959 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6960 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6961 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6962 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6966 +void au_dpri_dalias(struct inode *inode)
6970 + spin_lock(&inode->i_lock);
6971 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
6972 + au_dpri_dentry(d);
6973 + spin_unlock(&inode->i_lock);
6976 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6978 + struct dentry *wh = NULL;
6980 + struct au_iinfo *iinfo;
6982 + if (!dentry || IS_ERR(dentry)) {
6983 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6986 + /* do not call dget_parent() here */
6987 + /* note: access d_xxx without d_lock */
6988 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6989 + bindex, dentry, dentry,
6990 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6991 + au_dcount(dentry), dentry->d_flags,
6992 + d_unhashed(dentry) ? "un" : "");
6995 + && d_is_positive(dentry)
6996 + && au_test_aufs(dentry->d_sb)) {
6997 + iinfo = au_ii(d_inode(dentry));
6999 + hn = !!au_hn(iinfo->ii_hinode + bindex);
7000 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
7003 + do_pri_inode(bindex, d_inode(dentry), hn, wh);
7007 +void au_dpri_dentry(struct dentry *dentry)
7009 + struct au_dinfo *dinfo;
7010 + aufs_bindex_t bindex;
7012 + struct au_hdentry *hdp;
7014 + err = do_pri_dentry(-1, dentry);
7015 + if (err || !au_test_aufs(dentry->d_sb))
7018 + dinfo = au_di(dentry);
7021 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7022 + dinfo->di_bstart, dinfo->di_bend,
7023 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7024 + dinfo->di_tmpfile);
7025 + if (dinfo->di_bstart < 0)
7027 + hdp = dinfo->di_hdentry;
7028 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
7029 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
7032 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7036 + if (!file || IS_ERR(file)) {
7037 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7042 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7043 + && au_test_aufs(file->f_path.dentry->d_sb)
7045 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7046 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7047 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7048 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7049 + file->f_version, file->f_pos, a);
7050 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7051 + do_pri_dentry(bindex, file->f_path.dentry);
7055 +void au_dpri_file(struct file *file)
7057 + struct au_finfo *finfo;
7058 + struct au_fidir *fidir;
7059 + struct au_hfile *hfile;
7060 + aufs_bindex_t bindex;
7063 + err = do_pri_file(-1, file);
7065 + || IS_ERR_OR_NULL(file->f_path.dentry)
7066 + || !au_test_aufs(file->f_path.dentry->d_sb))
7069 + finfo = au_fi(file);
7072 + if (finfo->fi_btop < 0)
7074 + fidir = finfo->fi_hdir;
7076 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7078 + for (bindex = finfo->fi_btop;
7079 + bindex >= 0 && bindex <= fidir->fd_bbot;
7081 + hfile = fidir->fd_hfile + bindex;
7082 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7086 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7088 + struct vfsmount *mnt;
7089 + struct super_block *sb;
7091 + if (!br || IS_ERR(br))
7093 + mnt = au_br_mnt(br);
7094 + if (!mnt || IS_ERR(mnt))
7097 + if (!sb || IS_ERR(sb))
7100 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
7101 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7103 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
7104 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7105 + sb->s_flags, sb->s_count,
7106 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7110 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7114 +void au_dpri_sb(struct super_block *sb)
7116 + struct au_sbinfo *sbinfo;
7117 + aufs_bindex_t bindex;
7119 + /* to reuduce stack size */
7121 + struct vfsmount mnt;
7122 + struct au_branch fake;
7125 + /* this function can be called from magic sysrq */
7126 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7127 + if (unlikely(!a)) {
7128 + dpri("no memory\n");
7132 + a->mnt.mnt_sb = sb;
7133 + a->fake.br_perm = 0;
7134 + a->fake.br_path.mnt = &a->mnt;
7135 + a->fake.br_xino.xi_file = NULL;
7136 + atomic_set(&a->fake.br_count, 0);
7137 + smp_mb(); /* atomic_set */
7138 + err = do_pri_br(-1, &a->fake);
7140 + dpri("dev 0x%x\n", sb->s_dev);
7141 + if (err || !au_test_aufs(sb))
7144 + sbinfo = au_sbi(sb);
7147 + dpri("nw %d, gen %u, kobj %d\n",
7148 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7149 + atomic_read(&sbinfo->si_kobj.kref.refcount));
7150 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
7151 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7154 +/* ---------------------------------------------------------------------- */
7156 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7158 + struct inode *h_inode, *inode = d_inode(dentry);
7159 + struct dentry *h_dentry;
7160 + aufs_bindex_t bindex, bend, bi;
7162 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7165 + bend = au_dbend(dentry);
7166 + bi = au_ibend(inode);
7169 + bindex = au_dbstart(dentry);
7170 + bi = au_ibstart(inode);
7174 + for (; bindex <= bend; bindex++) {
7175 + h_dentry = au_h_dptr(dentry, bindex);
7178 + h_inode = au_h_iptr(inode, bindex);
7179 + if (unlikely(h_inode != d_inode(h_dentry))) {
7181 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7182 + AuDbgDentry(dentry);
7183 + AuDbgInode(inode);
7190 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7193 + struct au_dcsub_pages dpages;
7194 + struct au_dpage *dpage;
7195 + struct dentry **dentries;
7197 + err = au_dpages_init(&dpages, GFP_NOFS);
7199 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7201 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7202 + dpage = dpages.dpages + i;
7203 + dentries = dpage->dentries;
7204 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7205 + AuDebugOn(au_digen_test(dentries[j], sigen));
7207 + au_dpages_free(&dpages);
7210 +void au_dbg_verify_kthread(void)
7212 + if (au_wkq_test()) {
7215 + * It may be recursive, but udba=notify between two aufs mounts,
7216 + * where a single ro branch is shared, is not a problem.
7222 +/* ---------------------------------------------------------------------- */
7224 +int __init au_debug_init(void)
7226 + aufs_bindex_t bindex;
7227 + struct au_vdir_destr destr;
7230 + AuDebugOn(bindex >= 0);
7233 + AuDebugOn(destr.len < NAME_MAX);
7235 +#ifdef CONFIG_4KSTACKS
7236 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7241 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7242 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7243 +++ linux/fs/aufs/debug.h 2015-06-28 17:35:44.348050491 +0200
7246 + * Copyright (C) 2005-2015 Junjiro R. Okajima
7248 + * This program, aufs is free software; you can redistribute it and/or modify
7249 + * it under the terms of the GNU General Public License as published by
7250 + * the Free Software Foundation; either version 2 of the License, or
7251 + * (at your option) any later version.
7253 + * This program is distributed in the hope that it will be useful,
7254 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7255 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7256 + * GNU General Public License for more details.
7258 + * You should have received a copy of the GNU General Public License
7259 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7263 + * debug print functions
7266 +#ifndef __AUFS_DEBUG_H__
7267 +#define __AUFS_DEBUG_H__
7271 +#include <linux/atomic.h>
7272 +#include <linux/module.h>
7273 +#include <linux/kallsyms.h>
7274 +#include <linux/sysrq.h>
7276 +#ifdef CONFIG_AUFS_DEBUG
7277 +#define AuDebugOn(a) BUG_ON(a)
7279 +/* module parameter */
7280 +extern atomic_t aufs_debug;
7281 +static inline void au_debug_on(void)
7283 + atomic_inc(&aufs_debug);
7285 +static inline void au_debug_off(void)
7287 + atomic_dec_if_positive(&aufs_debug);
7290 +static inline int au_debug_test(void)
7292 + return atomic_read(&aufs_debug) > 0;
7295 +#define AuDebugOn(a) do {} while (0)
7296 +AuStubVoid(au_debug_on, void)
7297 +AuStubVoid(au_debug_off, void)
7298 +AuStubInt0(au_debug_test, void)
7299 +#endif /* CONFIG_AUFS_DEBUG */
7301 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7303 +/* ---------------------------------------------------------------------- */
7307 +#define AuDbg(fmt, ...) do { \
7308 + if (au_debug_test()) \
7309 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7311 +#define AuLabel(l) AuDbg(#l "\n")
7312 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7313 +#define AuWarn1(fmt, ...) do { \
7314 + static unsigned char _c; \
7316 + pr_warn(fmt, ##__VA_ARGS__); \
7319 +#define AuErr1(fmt, ...) do { \
7320 + static unsigned char _c; \
7322 + pr_err(fmt, ##__VA_ARGS__); \
7325 +#define AuIOErr1(fmt, ...) do { \
7326 + static unsigned char _c; \
7328 + AuIOErr(fmt, ##__VA_ARGS__); \
7331 +#define AuUnsupportMsg "This operation is not supported." \
7332 + " Please report this application to aufs-users ML."
7333 +#define AuUnsupport(fmt, ...) do { \
7334 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7338 +#define AuTraceErr(e) do { \
7339 + if (unlikely((e) < 0)) \
7340 + AuDbg("err %d\n", (int)(e)); \
7343 +#define AuTraceErrPtr(p) do { \
7345 + AuDbg("err %ld\n", PTR_ERR(p)); \
7348 +/* dirty macros for debug print, use with "%.*s" and caution */
7349 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7351 +/* ---------------------------------------------------------------------- */
7354 +#ifdef CONFIG_AUFS_DEBUG
7355 +extern struct mutex au_dbg_mtx;
7356 +extern char *au_plevel;
7358 +void au_dpri_whlist(struct au_nhash *whlist);
7360 +void au_dpri_vdir(struct au_vdir *vdir);
7362 +void au_dpri_inode(struct inode *inode);
7363 +void au_dpri_dalias(struct inode *inode);
7364 +void au_dpri_dentry(struct dentry *dentry);
7366 +void au_dpri_file(struct file *filp);
7367 +struct super_block;
7368 +void au_dpri_sb(struct super_block *sb);
7370 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7371 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7372 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7373 +void au_dbg_verify_kthread(void);
7375 +int __init au_debug_init(void);
7377 +#define AuDbgWhlist(w) do { \
7378 + mutex_lock(&au_dbg_mtx); \
7380 + au_dpri_whlist(w); \
7381 + mutex_unlock(&au_dbg_mtx); \
7384 +#define AuDbgVdir(v) do { \
7385 + mutex_lock(&au_dbg_mtx); \
7387 + au_dpri_vdir(v); \
7388 + mutex_unlock(&au_dbg_mtx); \
7391 +#define AuDbgInode(i) do { \
7392 + mutex_lock(&au_dbg_mtx); \
7394 + au_dpri_inode(i); \
7395 + mutex_unlock(&au_dbg_mtx); \
7398 +#define AuDbgDAlias(i) do { \
7399 + mutex_lock(&au_dbg_mtx); \
7401 + au_dpri_dalias(i); \
7402 + mutex_unlock(&au_dbg_mtx); \
7405 +#define AuDbgDentry(d) do { \
7406 + mutex_lock(&au_dbg_mtx); \
7408 + au_dpri_dentry(d); \
7409 + mutex_unlock(&au_dbg_mtx); \
7412 +#define AuDbgFile(f) do { \
7413 + mutex_lock(&au_dbg_mtx); \
7415 + au_dpri_file(f); \
7416 + mutex_unlock(&au_dbg_mtx); \
7419 +#define AuDbgSb(sb) do { \
7420 + mutex_lock(&au_dbg_mtx); \
7421 + AuDbg(#sb "\n"); \
7423 + mutex_unlock(&au_dbg_mtx); \
7426 +#define AuDbgSym(addr) do { \
7427 + char sym[KSYM_SYMBOL_LEN]; \
7428 + sprint_symbol(sym, (unsigned long)addr); \
7429 + AuDbg("%s\n", sym); \
7432 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7433 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7434 +AuStubVoid(au_dbg_verify_kthread, void)
7435 +AuStubInt0(__init au_debug_init, void)
7437 +#define AuDbgWhlist(w) do {} while (0)
7438 +#define AuDbgVdir(v) do {} while (0)
7439 +#define AuDbgInode(i) do {} while (0)
7440 +#define AuDbgDAlias(i) do {} while (0)
7441 +#define AuDbgDentry(d) do {} while (0)
7442 +#define AuDbgFile(f) do {} while (0)
7443 +#define AuDbgSb(sb) do {} while (0)
7444 +#define AuDbgSym(addr) do {} while (0)
7445 +#endif /* CONFIG_AUFS_DEBUG */
7447 +/* ---------------------------------------------------------------------- */
7449 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7450 +int __init au_sysrq_init(void);
7451 +void au_sysrq_fin(void);
7453 +#ifdef CONFIG_HW_CONSOLE
7454 +#define au_dbg_blocked() do { \
7456 + handle_sysrq('w'); \
7459 +AuStubVoid(au_dbg_blocked, void)
7463 +AuStubInt0(__init au_sysrq_init, void)
7464 +AuStubVoid(au_sysrq_fin, void)
7465 +AuStubVoid(au_dbg_blocked, void)
7466 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7468 +#endif /* __KERNEL__ */
7469 +#endif /* __AUFS_DEBUG_H__ */
7470 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7471 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7472 +++ linux/fs/aufs/dentry.c 2015-06-28 17:36:09.025073697 +0200
7475 + * Copyright (C) 2005-2015 Junjiro R. Okajima
7477 + * This program, aufs is free software; you can redistribute it and/or modify
7478 + * it under the terms of the GNU General Public License as published by
7479 + * the Free Software Foundation; either version 2 of the License, or
7480 + * (at your option) any later version.
7482 + * This program is distributed in the hope that it will be useful,
7483 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7484 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7485 + * GNU General Public License for more details.
7487 + * You should have received a copy of the GNU General Public License
7488 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7492 + * lookup and dentry operations
7495 +#include <linux/namei.h>
7498 +#define AuLkup_ALLOW_NEG 1
7499 +#define AuLkup_IGNORE_PERM (1 << 1)
7500 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7501 +#define au_fset_lkup(flags, name) \
7502 + do { (flags) |= AuLkup_##name; } while (0)
7503 +#define au_fclr_lkup(flags, name) \
7504 + do { (flags) &= ~AuLkup_##name; } while (0)
7506 +struct au_do_lookup_args {
7507 + unsigned int flags;
7512 + * returns positive/negative dentry, NULL or an error.
7513 + * NULL means whiteout-ed or not-found.
7515 +static struct dentry*
7516 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7517 + aufs_bindex_t bindex, struct qstr *wh_name,
7518 + struct au_do_lookup_args *args)
7520 + struct dentry *h_dentry;
7521 + struct inode *h_inode;
7522 + struct au_branch *br;
7523 + int wh_found, opq;
7524 + unsigned char wh_able;
7525 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7526 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7530 + br = au_sbr(dentry->d_sb, bindex);
7531 + wh_able = !!au_br_whable(br->br_perm);
7533 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7534 + h_dentry = ERR_PTR(wh_found);
7537 + if (unlikely(wh_found < 0))
7540 + /* We found a whiteout */
7541 + /* au_set_dbend(dentry, bindex); */
7542 + au_set_dbwh(dentry, bindex);
7544 + return NULL; /* success */
7548 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7550 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7551 + if (IS_ERR(h_dentry)) {
7552 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7558 + h_inode = d_inode(h_dentry);
7559 + if (d_is_negative(h_dentry)) {
7562 + } else if (wh_found
7563 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7566 + if (au_dbend(dentry) <= bindex)
7567 + au_set_dbend(dentry, bindex);
7568 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7569 + au_set_dbstart(dentry, bindex);
7570 + au_set_h_dptr(dentry, bindex, h_dentry);
7572 + if (!d_is_dir(h_dentry)
7574 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7575 + goto out; /* success */
7577 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7578 + opq = au_diropq_test(h_dentry);
7579 + mutex_unlock(&h_inode->i_mutex);
7581 + au_set_dbdiropq(dentry, bindex);
7582 + else if (unlikely(opq < 0)) {
7583 + au_set_h_dptr(dentry, bindex, NULL);
7584 + h_dentry = ERR_PTR(opq);
7595 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7597 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7598 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7604 + * returns the number of lower positive dentries,
7605 + * otherwise an error.
7606 + * can be called at unlinking with @type is zero.
7608 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7610 + int npositive, err;
7611 + aufs_bindex_t bindex, btail, bdiropq;
7612 + unsigned char isdir, dirperm1;
7613 + struct qstr whname;
7614 + struct au_do_lookup_args args = {
7618 + const struct qstr *name = &dentry->d_name;
7619 + struct dentry *parent;
7620 + struct super_block *sb;
7622 + sb = dentry->d_sb;
7623 + err = au_test_shwh(sb, name);
7624 + if (unlikely(err))
7627 + err = au_wh_name_alloc(&whname, name);
7628 + if (unlikely(err))
7631 + isdir = !!d_is_dir(dentry);
7633 + au_fset_lkup(args.flags, ALLOW_NEG);
7634 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7637 + parent = dget_parent(dentry);
7638 + btail = au_dbtaildir(parent);
7639 + for (bindex = bstart; bindex <= btail; bindex++) {
7640 + struct dentry *h_parent, *h_dentry;
7641 + struct inode *h_inode, *h_dir;
7643 + h_dentry = au_h_dptr(dentry, bindex);
7645 + if (d_is_positive(h_dentry))
7647 + if (type != S_IFDIR)
7651 + h_parent = au_h_dptr(parent, bindex);
7652 + if (!h_parent || !d_is_dir(h_parent))
7655 + h_dir = d_inode(h_parent);
7656 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7657 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7659 + mutex_unlock(&h_dir->i_mutex);
7660 + err = PTR_ERR(h_dentry);
7661 + if (IS_ERR(h_dentry))
7664 + au_fclr_lkup(args.flags, ALLOW_NEG);
7666 + au_fset_lkup(args.flags, IGNORE_PERM);
7668 + if (au_dbwh(dentry) >= 0)
7672 + if (d_is_negative(h_dentry))
7674 + h_inode = d_inode(h_dentry);
7677 + args.type = h_inode->i_mode & S_IFMT;
7678 + if (args.type != S_IFDIR)
7681 + /* the type of lower may be different */
7682 + bdiropq = au_dbdiropq(dentry);
7683 + if (bdiropq >= 0 && bdiropq <= bindex)
7689 + AuLabel(positive);
7690 + au_update_dbstart(dentry);
7693 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7694 + && au_dbstart(dentry) < 0)) {
7696 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7702 + kfree(whname.name);
7707 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7709 + struct dentry *dentry;
7712 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7713 + dentry = vfsub_lkup_one(name, parent);
7715 + struct vfsub_lkup_one_args args = {
7721 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7722 + if (unlikely(wkq_err))
7723 + dentry = ERR_PTR(wkq_err);
7730 + * lookup @dentry on @bindex which should be negative.
7732 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7735 + struct dentry *parent, *h_parent, *h_dentry;
7736 + struct au_branch *br;
7738 + parent = dget_parent(dentry);
7739 + h_parent = au_h_dptr(parent, bindex);
7740 + br = au_sbr(dentry->d_sb, bindex);
7742 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7744 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7745 + err = PTR_ERR(h_dentry);
7746 + if (IS_ERR(h_dentry))
7748 + if (unlikely(d_is_positive(h_dentry))) {
7750 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7756 + if (bindex < au_dbstart(dentry))
7757 + au_set_dbstart(dentry, bindex);
7758 + if (au_dbend(dentry) < bindex)
7759 + au_set_dbend(dentry, bindex);
7760 + au_set_h_dptr(dentry, bindex, h_dentry);
7767 +/* ---------------------------------------------------------------------- */
7769 +/* subset of struct inode */
7771 + unsigned long i_ino;
7772 + /* unsigned int i_nlink; */
7778 + blkcnt_t i_blocks;
7783 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7785 + ia->i_ino = h_inode->i_ino;
7786 + /* ia->i_nlink = h_inode->i_nlink; */
7787 + ia->i_uid = h_inode->i_uid;
7788 + ia->i_gid = h_inode->i_gid;
7789 + ia->i_version = h_inode->i_version;
7791 + ia->i_size = h_inode->i_size;
7792 + ia->i_blocks = h_inode->i_blocks;
7794 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7797 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7799 + return ia->i_ino != h_inode->i_ino
7800 + /* || ia->i_nlink != h_inode->i_nlink */
7801 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7802 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7803 + || ia->i_version != h_inode->i_version
7805 + || ia->i_size != h_inode->i_size
7806 + || ia->i_blocks != h_inode->i_blocks
7808 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7811 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7812 + struct au_branch *br)
7815 + struct au_iattr ia;
7816 + struct inode *h_inode;
7817 + struct dentry *h_d;
7818 + struct super_block *h_sb;
7821 + memset(&ia, -1, sizeof(ia));
7822 + h_sb = h_dentry->d_sb;
7824 + if (d_is_positive(h_dentry)) {
7825 + h_inode = d_inode(h_dentry);
7826 + au_iattr_save(&ia, h_inode);
7827 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7828 + /* nfs d_revalidate may return 0 for negative dentry */
7829 + /* fuse d_revalidate always return 0 for negative dentry */
7832 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7833 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7834 + err = PTR_ERR(h_d);
7839 + if (unlikely(h_d != h_dentry
7840 + || d_inode(h_d) != h_inode
7841 + || (h_inode && au_iattr_test(&ia, h_inode))))
7842 + err = au_busy_or_stale();
7850 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7851 + struct dentry *h_parent, struct au_branch *br)
7856 + if (udba == AuOpt_UDBA_REVAL
7857 + && !au_test_fs_remote(h_dentry->d_sb)) {
7859 + err = (d_inode(h_dentry->d_parent) != h_dir);
7860 + } else if (udba != AuOpt_UDBA_NONE)
7861 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7866 +/* ---------------------------------------------------------------------- */
7868 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7871 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7872 + struct au_hdentry tmp, *p, *q;
7873 + struct au_dinfo *dinfo;
7874 + struct super_block *sb;
7876 + DiMustWriteLock(dentry);
7878 + sb = dentry->d_sb;
7879 + dinfo = au_di(dentry);
7880 + bend = dinfo->di_bend;
7881 + bwh = dinfo->di_bwh;
7882 + bdiropq = dinfo->di_bdiropq;
7883 + p = dinfo->di_hdentry + dinfo->di_bstart;
7884 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7885 + if (!p->hd_dentry)
7888 + new_bindex = au_br_index(sb, p->hd_id);
7889 + if (new_bindex == bindex)
7892 + if (dinfo->di_bwh == bindex)
7894 + if (dinfo->di_bdiropq == bindex)
7895 + bdiropq = new_bindex;
7896 + if (new_bindex < 0) {
7898 + p->hd_dentry = NULL;
7902 + /* swap two lower dentries, and loop again */
7903 + q = dinfo->di_hdentry + new_bindex;
7907 + if (tmp.hd_dentry) {
7913 + dinfo->di_bwh = -1;
7914 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7915 + dinfo->di_bwh = bwh;
7917 + dinfo->di_bdiropq = -1;
7919 + && bdiropq <= au_sbend(sb)
7920 + && au_sbr_whable(sb, bdiropq))
7921 + dinfo->di_bdiropq = bdiropq;
7924 + dinfo->di_bstart = -1;
7925 + dinfo->di_bend = -1;
7926 + bend = au_dbend(parent);
7927 + p = dinfo->di_hdentry;
7928 + for (bindex = 0; bindex <= bend; bindex++, p++)
7929 + if (p->hd_dentry) {
7930 + dinfo->di_bstart = bindex;
7934 + if (dinfo->di_bstart >= 0) {
7935 + p = dinfo->di_hdentry + bend;
7936 + for (bindex = bend; bindex >= 0; bindex--, p--)
7937 + if (p->hd_dentry) {
7938 + dinfo->di_bend = bindex;
7947 +static void au_do_hide(struct dentry *dentry)
7949 + struct inode *inode;
7951 + if (d_really_is_positive(dentry)) {
7952 + inode = d_inode(dentry);
7953 + if (!d_is_dir(dentry)) {
7954 + if (inode->i_nlink && !d_unhashed(dentry))
7955 + drop_nlink(inode);
7957 + clear_nlink(inode);
7958 + /* stop next lookup */
7959 + inode->i_flags |= S_DEAD;
7961 + smp_mb(); /* necessary? */
7966 +static int au_hide_children(struct dentry *parent)
7968 + int err, i, j, ndentry;
7969 + struct au_dcsub_pages dpages;
7970 + struct au_dpage *dpage;
7971 + struct dentry *dentry;
7973 + err = au_dpages_init(&dpages, GFP_NOFS);
7974 + if (unlikely(err))
7976 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7977 + if (unlikely(err))
7980 + /* in reverse order */
7981 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7982 + dpage = dpages.dpages + i;
7983 + ndentry = dpage->ndentry;
7984 + for (j = ndentry - 1; j >= 0; j--) {
7985 + dentry = dpage->dentries[j];
7986 + if (dentry != parent)
7987 + au_do_hide(dentry);
7992 + au_dpages_free(&dpages);
7997 +static void au_hide(struct dentry *dentry)
8001 + AuDbgDentry(dentry);
8002 + if (d_is_dir(dentry)) {
8003 + /* shrink_dcache_parent(dentry); */
8004 + err = au_hide_children(dentry);
8005 + if (unlikely(err))
8006 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8009 + au_do_hide(dentry);
8013 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8015 + * a dirty branch is added
8016 + * - on the top of layers
8017 + * - in the middle of layers
8018 + * - to the bottom of layers
8020 + * on the added branch there exists
8023 + * - a same named entry
8025 + * * negative --> positive
8026 + * * positive --> positive
8027 + * - type is unchanged
8028 + * - type is changed
8030 + * * negative --> negative
8031 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8034 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8035 + struct au_dinfo *tmp)
8038 + aufs_bindex_t bindex, bend;
8040 + struct dentry *dentry;
8041 + struct inode *inode;
8044 + struct au_hdentry *hd;
8045 + struct inode *inode, *h_inode;
8046 + struct dentry *h_dentry;
8049 + AuDebugOn(dinfo->di_bstart < 0);
8051 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
8052 + orig_h.inode = NULL;
8053 + if (d_is_positive(orig_h.dentry)) {
8054 + orig_h.inode = d_inode(orig_h.dentry);
8055 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8057 + memset(&tmp_h, 0, sizeof(tmp_h));
8058 + if (tmp->di_bstart >= 0) {
8059 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
8060 + tmp_h.inode = NULL;
8061 + if (d_is_positive(tmp_h.dentry)) {
8062 + tmp_h.inode = d_inode(tmp_h.dentry);
8063 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8068 + if (d_really_is_positive(dentry))
8069 + inode = d_inode(dentry);
8070 + if (!orig_h.inode) {
8071 + AuDbg("nagative originally\n");
8077 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8078 + AuDebugOn(dinfo->di_bdiropq != -1);
8080 + if (!tmp_h.inode) {
8081 + AuDbg("negative --> negative\n");
8082 + /* should have only one negative lower */
8083 + if (tmp->di_bstart >= 0
8084 + && tmp->di_bstart < dinfo->di_bstart) {
8085 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
8086 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8087 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
8088 + au_di_cp(dinfo, tmp);
8089 + hd = tmp->di_hdentry + tmp->di_bstart;
8090 + au_set_h_dptr(dentry, tmp->di_bstart,
8091 + dget(hd->hd_dentry));
8093 + au_dbg_verify_dinode(dentry);
8095 + AuDbg("negative --> positive\n");
8097 + * similar to the behaviour of creating with bypassing
8099 + * unhash it in order to force an error in the
8100 + * succeeding create operation.
8101 + * we should not set S_DEAD here.
8104 + /* au_di_swap(tmp, dinfo); */
8105 + au_dbg_verify_dinode(dentry);
8108 + AuDbg("positive originally\n");
8109 + /* inode may be NULL */
8110 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8111 + if (!tmp_h.inode) {
8112 + AuDbg("positive --> negative\n");
8113 + /* or bypassing aufs */
8115 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
8116 + dinfo->di_bwh = tmp->di_bwh;
8118 + err = au_refresh_hinode_self(inode);
8119 + au_dbg_verify_dinode(dentry);
8120 + } else if (orig_h.mode == tmp_h.mode) {
8121 + AuDbg("positive --> positive, same type\n");
8122 + if (!S_ISDIR(orig_h.mode)
8123 + && dinfo->di_bstart > tmp->di_bstart) {
8125 + * similar to the behaviour of removing and
8130 + err = au_refresh_hinode_self(inode);
8131 + au_dbg_verify_dinode(dentry);
8133 + /* fill empty slots */
8134 + if (dinfo->di_bstart > tmp->di_bstart)
8135 + dinfo->di_bstart = tmp->di_bstart;
8136 + if (dinfo->di_bend < tmp->di_bend)
8137 + dinfo->di_bend = tmp->di_bend;
8138 + dinfo->di_bwh = tmp->di_bwh;
8139 + dinfo->di_bdiropq = tmp->di_bdiropq;
8140 + hd = tmp->di_hdentry;
8141 + bend = dinfo->di_bend;
8142 + for (bindex = tmp->di_bstart; bindex <= bend;
8144 + if (au_h_dptr(dentry, bindex))
8146 + h_dentry = hd[bindex].hd_dentry;
8149 + AuDebugOn(d_is_negative(h_dentry));
8150 + h_inode = d_inode(h_dentry);
8151 + AuDebugOn(orig_h.mode
8152 + != (h_inode->i_mode
8154 + au_set_h_dptr(dentry, bindex,
8157 + err = au_refresh_hinode(inode, dentry);
8158 + au_dbg_verify_dinode(dentry);
8161 + AuDbg("positive --> positive, different type\n");
8162 + /* similar to the behaviour of removing and creating */
8165 + err = au_refresh_hinode_self(inode);
8166 + au_dbg_verify_dinode(dentry);
8174 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8177 + unsigned int sigen;
8178 + struct au_dinfo *dinfo, *tmp;
8179 + struct super_block *sb;
8180 + struct inode *inode;
8182 + DiMustWriteLock(dentry);
8183 + AuDebugOn(IS_ROOT(dentry));
8184 + AuDebugOn(d_really_is_negative(parent));
8186 + sb = dentry->d_sb;
8187 + sigen = au_sigen(sb);
8188 + err = au_digen_test(parent, sigen);
8189 + if (unlikely(err))
8192 + dinfo = au_di(dentry);
8193 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
8194 + if (unlikely(err))
8196 + ebrange = au_dbrange_test(dentry);
8198 + ebrange = au_do_refresh_hdentry(dentry, parent);
8200 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8201 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
8202 + if (d_really_is_positive(dentry)) {
8203 + inode = d_inode(dentry);
8204 + err = au_refresh_hinode_self(inode);
8206 + au_dbg_verify_dinode(dentry);
8208 + goto out_dgen; /* success */
8212 + /* temporary dinfo */
8213 + AuDbgDentry(dentry);
8215 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8216 + if (unlikely(!tmp))
8218 + au_di_swap(tmp, dinfo);
8219 + /* returns the number of positive dentries */
8221 + * if current working dir is removed, it returns an error.
8222 + * but the dentry is legal.
8224 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
8225 + AuDbgDentry(dentry);
8226 + au_di_swap(tmp, dinfo);
8227 + if (err == -ENOENT)
8230 + /* compare/refresh by dinfo */
8231 + AuDbgDentry(dentry);
8232 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8233 + au_dbg_verify_dinode(dentry);
8236 + au_rw_write_unlock(&tmp->di_rwsem);
8238 + if (unlikely(err))
8242 + au_update_digen(dentry);
8244 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8245 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8246 + AuDbgDentry(dentry);
8252 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8253 + struct dentry *dentry, aufs_bindex_t bindex)
8258 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8261 + AuDbg("b%d\n", bindex);
8263 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8264 + * due to whiteout and branch permission.
8266 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8267 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8268 + /* it may return tri-state */
8269 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8271 + if (unlikely(valid < 0))
8281 +/* todo: remove this */
8282 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8283 + unsigned int flags, int do_udba)
8286 + umode_t mode, h_mode;
8287 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
8288 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8289 + struct inode *h_inode, *h_cached_inode;
8290 + struct dentry *h_dentry;
8291 + struct qstr *name, *h_name;
8298 + unhashed = !!d_unhashed(dentry);
8299 + is_root = !!IS_ROOT(dentry);
8300 + name = &dentry->d_name;
8301 + tmpfile = au_di(dentry)->di_tmpfile;
8304 + * Theoretically, REVAL test should be unnecessary in case of
8306 + * But {fs,i}notify doesn't fire some necessary events,
8307 + * IN_ATTRIB for atime/nlink/pageio
8308 + * Let's do REVAL test too.
8310 + if (do_udba && inode) {
8311 + mode = (inode->i_mode & S_IFMT);
8312 + plus = (inode->i_nlink > 0);
8313 + ibs = au_ibstart(inode);
8314 + ibe = au_ibend(inode);
8317 + bstart = au_dbstart(dentry);
8319 + if (inode && S_ISDIR(inode->i_mode))
8320 + btail = au_dbtaildir(dentry);
8321 + for (bindex = bstart; bindex <= btail; bindex++) {
8322 + h_dentry = au_h_dptr(dentry, bindex);
8326 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8327 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8328 + spin_lock(&h_dentry->d_lock);
8329 + h_name = &h_dentry->d_name;
8330 + if (unlikely(do_udba
8333 + && (unhashed != !!d_unhashed(h_dentry)
8335 + && !au_qstreq(name, h_name))
8338 + && !(flags & LOOKUP_OPEN)
8339 + && (h_dentry->d_flags
8340 + & DCACHE_NFSFS_RENAMED)))
8344 + h_unhashed = d_unhashed(h_dentry);
8345 + spin_unlock(&h_dentry->d_lock);
8346 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8347 + unhashed, h_unhashed, dentry, h_dentry);
8350 + spin_unlock(&h_dentry->d_lock);
8352 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8353 + if (unlikely(err))
8354 + /* do not goto err, to keep the errno */
8357 + /* todo: plink too? */
8362 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8366 + if (d_is_positive(h_dentry))
8367 + h_inode = d_inode(h_dentry);
8370 + h_cached_inode = h_inode;
8372 + h_mode = (h_inode->i_mode & S_IFMT);
8373 + h_plus = (h_inode->i_nlink > 0);
8375 + if (inode && ibs <= bindex && bindex <= ibe)
8376 + h_cached_inode = au_h_iptr(inode, bindex);
8379 + if (unlikely(plus != h_plus && !tmpfile))
8382 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8384 + && !IS_ROOT(h_dentry)
8385 + && unhashed != d_unhashed(h_dentry)))
8388 + if (unlikely(mode != h_mode
8389 + || h_cached_inode != h_inode))
8402 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8403 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8406 + struct dentry *parent;
8408 + if (!au_digen_test(dentry, sigen))
8411 + parent = dget_parent(dentry);
8412 + di_read_lock_parent(parent, AuLock_IR);
8413 + AuDebugOn(au_digen_test(parent, sigen));
8414 + au_dbg_verify_gen(parent, sigen);
8415 + err = au_refresh_dentry(dentry, parent);
8416 + di_read_unlock(parent, AuLock_IR);
8422 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8425 + struct dentry *d, *parent;
8427 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8428 + return simple_reval_dpath(dentry, sigen);
8430 + /* slow loop, keep it simple and stupid */
8431 + /* cf: au_cpup_dirs() */
8434 + while (au_digen_test(dentry, sigen)) {
8438 + parent = dget_parent(d);
8439 + if (!au_digen_test(parent, sigen))
8445 + di_write_lock_child2(d);
8447 + /* someone might update our dentry while we were sleeping */
8448 + if (au_digen_test(d, sigen)) {
8450 + * todo: consolidate with simple_reval_dpath(),
8451 + * do_refresh() and au_reval_for_attr().
8453 + di_read_lock_parent(parent, AuLock_IR);
8454 + err = au_refresh_dentry(d, parent);
8455 + di_read_unlock(parent, AuLock_IR);
8459 + di_write_unlock(d);
8461 + if (unlikely(err))
8469 + * if valid returns 1, otherwise 0.
8471 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8474 + unsigned int sigen;
8475 + unsigned char do_udba;
8476 + struct super_block *sb;
8477 + struct inode *inode;
8479 + /* todo: support rcu-walk? */
8480 + if (flags & LOOKUP_RCU)
8484 + if (unlikely(!au_di(dentry)))
8488 + sb = dentry->d_sb;
8491 + * i_mutex of parent dir may be held,
8492 + * but we should not return 'invalid' due to busy.
8494 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8495 + if (unlikely(err)) {
8501 + if (d_really_is_positive(dentry))
8502 + inode = d_inode(dentry);
8503 + if (unlikely(inode && is_bad_inode(inode))) {
8508 + if (unlikely(au_dbrange_test(dentry))) {
8514 + sigen = au_sigen(sb);
8515 + if (au_digen_test(dentry, sigen)) {
8516 + AuDebugOn(IS_ROOT(dentry));
8517 + err = au_reval_dpath(dentry, sigen);
8518 + if (unlikely(err)) {
8523 + di_downgrade_lock(dentry, AuLock_IR);
8526 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8528 + && !(inode->i_state && I_LINKABLE)
8529 + && (IS_DEADDIR(inode) || !inode->i_nlink))
8532 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8533 + if (do_udba && inode) {
8534 + aufs_bindex_t bstart = au_ibstart(inode);
8535 + struct inode *h_inode;
8537 + if (bstart >= 0) {
8538 + h_inode = au_h_iptr(inode, bstart);
8539 + if (h_inode && au_test_higen(inode, h_inode))
8544 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8545 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8547 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8553 + di_downgrade_lock(dentry, AuLock_IR);
8555 + aufs_read_unlock(dentry, AuLock_IR);
8560 + AuDbg("%pd invalid, %d\n", dentry, valid);
8566 +static void aufs_d_release(struct dentry *dentry)
8568 + if (au_di(dentry)) {
8569 + au_di_fin(dentry);
8570 + au_hn_di_reinit(dentry);
8574 +const struct dentry_operations aufs_dop = {
8575 + .d_revalidate = aufs_d_revalidate,
8576 + .d_weak_revalidate = aufs_d_revalidate,
8577 + .d_release = aufs_d_release
8579 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8580 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8581 +++ linux/fs/aufs/dentry.h 2015-06-28 17:35:44.348050491 +0200
8584 + * Copyright (C) 2005-2015 Junjiro R. Okajima
8586 + * This program, aufs is free software; you can redistribute it and/or modify
8587 + * it under the terms of the GNU General Public License as published by
8588 + * the Free Software Foundation; either version 2 of the License, or
8589 + * (at your option) any later version.
8591 + * This program is distributed in the hope that it will be useful,
8592 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8593 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8594 + * GNU General Public License for more details.
8596 + * You should have received a copy of the GNU General Public License
8597 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8601 + * lookup and dentry operations
8604 +#ifndef __AUFS_DENTRY_H__
8605 +#define __AUFS_DENTRY_H__
8609 +#include <linux/dcache.h>
8612 +struct au_hdentry {
8613 + struct dentry *hd_dentry;
8614 + aufs_bindex_t hd_id;
8618 + atomic_t di_generation;
8620 + struct au_rwsem di_rwsem;
8621 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8622 + unsigned char di_tmpfile; /* to allow the different name */
8623 + struct au_hdentry *di_hdentry;
8624 +} ____cacheline_aligned_in_smp;
8626 +/* ---------------------------------------------------------------------- */
8629 +extern const struct dentry_operations aufs_dop;
8631 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8632 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8633 + struct dentry *h_parent, struct au_branch *br);
8635 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8636 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8637 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8638 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8641 +void au_di_init_once(void *_di);
8642 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8643 +void au_di_free(struct au_dinfo *dinfo);
8644 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8645 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8646 +int au_di_init(struct dentry *dentry);
8647 +void au_di_fin(struct dentry *dentry);
8648 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8650 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8651 +void di_read_unlock(struct dentry *d, int flags);
8652 +void di_downgrade_lock(struct dentry *d, int flags);
8653 +void di_write_lock(struct dentry *d, unsigned int lsc);
8654 +void di_write_unlock(struct dentry *d);
8655 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8656 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8657 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8659 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8660 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8661 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8662 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8664 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8665 + struct dentry *h_dentry);
8666 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8667 +int au_dbrange_test(struct dentry *dentry);
8668 +void au_update_digen(struct dentry *dentry);
8669 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8670 +void au_update_dbstart(struct dentry *dentry);
8671 +void au_update_dbend(struct dentry *dentry);
8672 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8674 +/* ---------------------------------------------------------------------- */
8676 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8678 + return dentry->d_fsdata;
8681 +/* ---------------------------------------------------------------------- */
8683 +/* lock subclass for dinfo */
8685 + AuLsc_DI_CHILD, /* child first */
8686 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8687 + AuLsc_DI_CHILD3, /* copyup dirs */
8691 + AuLsc_DI_TMP /* temp for replacing dinfo */
8695 + * di_read_lock_child, di_write_lock_child,
8696 + * di_read_lock_child2, di_write_lock_child2,
8697 + * di_read_lock_child3, di_write_lock_child3,
8698 + * di_read_lock_parent, di_write_lock_parent,
8699 + * di_read_lock_parent2, di_write_lock_parent2,
8700 + * di_read_lock_parent3, di_write_lock_parent3,
8702 +#define AuReadLockFunc(name, lsc) \
8703 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8704 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8706 +#define AuWriteLockFunc(name, lsc) \
8707 +static inline void di_write_lock_##name(struct dentry *d) \
8708 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8710 +#define AuRWLockFuncs(name, lsc) \
8711 + AuReadLockFunc(name, lsc) \
8712 + AuWriteLockFunc(name, lsc)
8714 +AuRWLockFuncs(child, CHILD);
8715 +AuRWLockFuncs(child2, CHILD2);
8716 +AuRWLockFuncs(child3, CHILD3);
8717 +AuRWLockFuncs(parent, PARENT);
8718 +AuRWLockFuncs(parent2, PARENT2);
8719 +AuRWLockFuncs(parent3, PARENT3);
8721 +#undef AuReadLockFunc
8722 +#undef AuWriteLockFunc
8723 +#undef AuRWLockFuncs
8725 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8726 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8727 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8729 +/* ---------------------------------------------------------------------- */
8731 +/* todo: memory barrier? */
8732 +static inline unsigned int au_digen(struct dentry *d)
8734 + return atomic_read(&au_di(d)->di_generation);
8737 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8739 + hdentry->hd_dentry = NULL;
8742 +static inline void au_hdput(struct au_hdentry *hd)
8745 + dput(hd->hd_dentry);
8748 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8750 + DiMustAnyLock(dentry);
8751 + return au_di(dentry)->di_bstart;
8754 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8756 + DiMustAnyLock(dentry);
8757 + return au_di(dentry)->di_bend;
8760 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8762 + DiMustAnyLock(dentry);
8763 + return au_di(dentry)->di_bwh;
8766 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8768 + DiMustAnyLock(dentry);
8769 + return au_di(dentry)->di_bdiropq;
8772 +/* todo: hard/soft set? */
8773 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8775 + DiMustWriteLock(dentry);
8776 + au_di(dentry)->di_bstart = bindex;
8779 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8781 + DiMustWriteLock(dentry);
8782 + au_di(dentry)->di_bend = bindex;
8785 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8787 + DiMustWriteLock(dentry);
8788 + /* dbwh can be outside of bstart - bend range */
8789 + au_di(dentry)->di_bwh = bindex;
8792 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8794 + DiMustWriteLock(dentry);
8795 + au_di(dentry)->di_bdiropq = bindex;
8798 +/* ---------------------------------------------------------------------- */
8800 +#ifdef CONFIG_AUFS_HNOTIFY
8801 +static inline void au_digen_dec(struct dentry *d)
8803 + atomic_dec(&au_di(d)->di_generation);
8806 +static inline void au_hn_di_reinit(struct dentry *dentry)
8808 + dentry->d_fsdata = NULL;
8811 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8812 +#endif /* CONFIG_AUFS_HNOTIFY */
8814 +#endif /* __KERNEL__ */
8815 +#endif /* __AUFS_DENTRY_H__ */
8816 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8817 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8818 +++ linux/fs/aufs/dinfo.c 2015-06-28 17:36:09.025073697 +0200
8821 + * Copyright (C) 2005-2015 Junjiro R. Okajima
8823 + * This program, aufs is free software; you can redistribute it and/or modify
8824 + * it under the terms of the GNU General Public License as published by
8825 + * the Free Software Foundation; either version 2 of the License, or
8826 + * (at your option) any later version.
8828 + * This program is distributed in the hope that it will be useful,
8829 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8830 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8831 + * GNU General Public License for more details.
8833 + * You should have received a copy of the GNU General Public License
8834 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8838 + * dentry private data
8843 +void au_di_init_once(void *_dinfo)
8845 + struct au_dinfo *dinfo = _dinfo;
8846 + static struct lock_class_key aufs_di;
8848 + au_rw_init(&dinfo->di_rwsem);
8849 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8852 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8854 + struct au_dinfo *dinfo;
8857 + dinfo = au_cache_alloc_dinfo();
8858 + if (unlikely(!dinfo))
8861 + nbr = au_sbend(sb) + 1;
8864 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8865 + if (dinfo->di_hdentry) {
8866 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8867 + dinfo->di_bstart = -1;
8868 + dinfo->di_bend = -1;
8869 + dinfo->di_bwh = -1;
8870 + dinfo->di_bdiropq = -1;
8871 + dinfo->di_tmpfile = 0;
8872 + for (i = 0; i < nbr; i++)
8873 + dinfo->di_hdentry[i].hd_id = -1;
8877 + au_cache_free_dinfo(dinfo);
8884 +void au_di_free(struct au_dinfo *dinfo)
8886 + struct au_hdentry *p;
8887 + aufs_bindex_t bend, bindex;
8889 + /* dentry may not be revalidated */
8890 + bindex = dinfo->di_bstart;
8891 + if (bindex >= 0) {
8892 + bend = dinfo->di_bend;
8893 + p = dinfo->di_hdentry + bindex;
8894 + while (bindex++ <= bend)
8897 + kfree(dinfo->di_hdentry);
8898 + au_cache_free_dinfo(dinfo);
8901 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8903 + struct au_hdentry *p;
8906 + AuRwMustWriteLock(&a->di_rwsem);
8907 + AuRwMustWriteLock(&b->di_rwsem);
8909 +#define DiSwap(v, name) \
8911 + v = a->di_##name; \
8912 + a->di_##name = b->di_##name; \
8913 + b->di_##name = v; \
8916 + DiSwap(p, hdentry);
8917 + DiSwap(bi, bstart);
8920 + DiSwap(bi, bdiropq);
8926 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8928 + AuRwMustWriteLock(&dst->di_rwsem);
8929 + AuRwMustWriteLock(&src->di_rwsem);
8931 + dst->di_bstart = src->di_bstart;
8932 + dst->di_bend = src->di_bend;
8933 + dst->di_bwh = src->di_bwh;
8934 + dst->di_bdiropq = src->di_bdiropq;
8938 +int au_di_init(struct dentry *dentry)
8941 + struct super_block *sb;
8942 + struct au_dinfo *dinfo;
8945 + sb = dentry->d_sb;
8946 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8948 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8949 + /* smp_mb(); */ /* atomic_set */
8950 + dentry->d_fsdata = dinfo;
8957 +void au_di_fin(struct dentry *dentry)
8959 + struct au_dinfo *dinfo;
8961 + dinfo = au_di(dentry);
8962 + AuRwDestroy(&dinfo->di_rwsem);
8963 + au_di_free(dinfo);
8966 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8969 + struct au_hdentry *hdp;
8971 + AuRwMustWriteLock(&dinfo->di_rwsem);
8974 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8976 + sz = sizeof(*hdp);
8977 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8979 + dinfo->di_hdentry = hdp;
8986 +/* ---------------------------------------------------------------------- */
8988 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8991 + case AuLsc_DI_CHILD:
8992 + ii_write_lock_child(inode);
8994 + case AuLsc_DI_CHILD2:
8995 + ii_write_lock_child2(inode);
8997 + case AuLsc_DI_CHILD3:
8998 + ii_write_lock_child3(inode);
9000 + case AuLsc_DI_PARENT:
9001 + ii_write_lock_parent(inode);
9003 + case AuLsc_DI_PARENT2:
9004 + ii_write_lock_parent2(inode);
9006 + case AuLsc_DI_PARENT3:
9007 + ii_write_lock_parent3(inode);
9014 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9017 + case AuLsc_DI_CHILD:
9018 + ii_read_lock_child(inode);
9020 + case AuLsc_DI_CHILD2:
9021 + ii_read_lock_child2(inode);
9023 + case AuLsc_DI_CHILD3:
9024 + ii_read_lock_child3(inode);
9026 + case AuLsc_DI_PARENT:
9027 + ii_read_lock_parent(inode);
9029 + case AuLsc_DI_PARENT2:
9030 + ii_read_lock_parent2(inode);
9032 + case AuLsc_DI_PARENT3:
9033 + ii_read_lock_parent3(inode);
9040 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9042 + struct inode *inode;
9044 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9045 + if (d_really_is_positive(d)) {
9046 + inode = d_inode(d);
9047 + if (au_ftest_lock(flags, IW))
9048 + do_ii_write_lock(inode, lsc);
9049 + else if (au_ftest_lock(flags, IR))
9050 + do_ii_read_lock(inode, lsc);
9054 +void di_read_unlock(struct dentry *d, int flags)
9056 + struct inode *inode;
9058 + if (d_really_is_positive(d)) {
9059 + inode = d_inode(d);
9060 + if (au_ftest_lock(flags, IW)) {
9061 + au_dbg_verify_dinode(d);
9062 + ii_write_unlock(inode);
9063 + } else if (au_ftest_lock(flags, IR)) {
9064 + au_dbg_verify_dinode(d);
9065 + ii_read_unlock(inode);
9068 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9071 +void di_downgrade_lock(struct dentry *d, int flags)
9073 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9074 + ii_downgrade_lock(d_inode(d));
9075 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9078 +void di_write_lock(struct dentry *d, unsigned int lsc)
9080 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9081 + if (d_really_is_positive(d))
9082 + do_ii_write_lock(d_inode(d), lsc);
9085 +void di_write_unlock(struct dentry *d)
9087 + au_dbg_verify_dinode(d);
9088 + if (d_really_is_positive(d))
9089 + ii_write_unlock(d_inode(d));
9090 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9093 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9095 + AuDebugOn(d1 == d2
9096 + || d_inode(d1) == d_inode(d2)
9097 + || d1->d_sb != d2->d_sb);
9099 + if (isdir && au_test_subdir(d1, d2)) {
9100 + di_write_lock_child(d1);
9101 + di_write_lock_child2(d2);
9103 + /* there should be no races */
9104 + di_write_lock_child(d2);
9105 + di_write_lock_child2(d1);
9109 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9111 + AuDebugOn(d1 == d2
9112 + || d_inode(d1) == d_inode(d2)
9113 + || d1->d_sb != d2->d_sb);
9115 + if (isdir && au_test_subdir(d1, d2)) {
9116 + di_write_lock_parent(d1);
9117 + di_write_lock_parent2(d2);
9119 + /* there should be no races */
9120 + di_write_lock_parent(d2);
9121 + di_write_lock_parent2(d1);
9125 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9127 + di_write_unlock(d1);
9128 + if (d_inode(d1) == d_inode(d2))
9129 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9131 + di_write_unlock(d2);
9134 +/* ---------------------------------------------------------------------- */
9136 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9140 + DiMustAnyLock(dentry);
9142 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
9144 + AuDebugOn(bindex < 0);
9145 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
9146 + AuDebugOn(d && au_dcount(d) <= 0);
9151 + * extended version of au_h_dptr().
9152 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9155 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9157 + struct dentry *h_dentry;
9158 + struct inode *inode, *h_inode;
9160 + AuDebugOn(d_really_is_negative(dentry));
9163 + if (au_dbstart(dentry) <= bindex
9164 + && bindex <= au_dbend(dentry))
9165 + h_dentry = au_h_dptr(dentry, bindex);
9166 + if (h_dentry && !au_d_linkable(h_dentry)) {
9168 + goto out; /* success */
9171 + inode = d_inode(dentry);
9172 + AuDebugOn(bindex < au_ibstart(inode));
9173 + AuDebugOn(au_ibend(inode) < bindex);
9174 + h_inode = au_h_iptr(inode, bindex);
9175 + h_dentry = d_find_alias(h_inode);
9177 + if (!IS_ERR(h_dentry)) {
9178 + if (!au_d_linkable(h_dentry))
9179 + goto out; /* success */
9185 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9186 + h_dentry = au_plink_lkup(inode, bindex);
9187 + AuDebugOn(!h_dentry);
9188 + if (!IS_ERR(h_dentry)) {
9189 + if (!au_d_hashed_positive(h_dentry))
9190 + goto out; /* success */
9197 + AuDbgDentry(h_dentry);
9201 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9203 + aufs_bindex_t bend, bwh;
9205 + bend = au_dbend(dentry);
9207 + bwh = au_dbwh(dentry);
9210 + if (0 < bwh && bwh < bend)
9216 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9218 + aufs_bindex_t bend, bopq;
9220 + bend = au_dbtail(dentry);
9222 + bopq = au_dbdiropq(dentry);
9223 + if (0 <= bopq && bopq < bend)
9229 +/* ---------------------------------------------------------------------- */
9231 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9232 + struct dentry *h_dentry)
9234 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
9235 + struct au_branch *br;
9237 + DiMustWriteLock(dentry);
9240 + hd->hd_dentry = h_dentry;
9242 + br = au_sbr(dentry->d_sb, bindex);
9243 + hd->hd_id = br->br_id;
9247 +int au_dbrange_test(struct dentry *dentry)
9250 + aufs_bindex_t bstart, bend;
9253 + bstart = au_dbstart(dentry);
9254 + bend = au_dbend(dentry);
9256 + AuDebugOn(bend < 0 && bstart > bend);
9259 + AuDebugOn(bend >= 0);
9265 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9270 + if (unlikely(au_digen(dentry) != sigen
9271 + || au_iigen_test(d_inode(dentry), sigen)))
9277 +void au_update_digen(struct dentry *dentry)
9279 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9280 + /* smp_mb(); */ /* atomic_set */
9283 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9285 + struct au_dinfo *dinfo;
9286 + struct dentry *h_d;
9287 + struct au_hdentry *hdp;
9289 + DiMustWriteLock(dentry);
9291 + dinfo = au_di(dentry);
9292 + if (!dinfo || dinfo->di_bstart < 0)
9295 + hdp = dinfo->di_hdentry;
9296 + if (do_put_zero) {
9297 + aufs_bindex_t bindex, bend;
9299 + bend = dinfo->di_bend;
9300 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
9301 + h_d = hdp[0 + bindex].hd_dentry;
9302 + if (h_d && d_is_negative(h_d))
9303 + au_set_h_dptr(dentry, bindex, NULL);
9307 + dinfo->di_bstart = -1;
9308 + while (++dinfo->di_bstart <= dinfo->di_bend)
9309 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
9311 + if (dinfo->di_bstart > dinfo->di_bend) {
9312 + dinfo->di_bstart = -1;
9313 + dinfo->di_bend = -1;
9318 + while (0 <= --dinfo->di_bend)
9319 + if (hdp[0 + dinfo->di_bend].hd_dentry)
9321 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
9324 +void au_update_dbstart(struct dentry *dentry)
9326 + aufs_bindex_t bindex, bend;
9327 + struct dentry *h_dentry;
9329 + bend = au_dbend(dentry);
9330 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
9331 + h_dentry = au_h_dptr(dentry, bindex);
9334 + if (d_is_positive(h_dentry)) {
9335 + au_set_dbstart(dentry, bindex);
9338 + au_set_h_dptr(dentry, bindex, NULL);
9342 +void au_update_dbend(struct dentry *dentry)
9344 + aufs_bindex_t bindex, bstart;
9345 + struct dentry *h_dentry;
9347 + bstart = au_dbstart(dentry);
9348 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
9349 + h_dentry = au_h_dptr(dentry, bindex);
9352 + if (d_is_positive(h_dentry)) {
9353 + au_set_dbend(dentry, bindex);
9356 + au_set_h_dptr(dentry, bindex, NULL);
9360 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9362 + aufs_bindex_t bindex, bend;
9364 + bend = au_dbend(dentry);
9365 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
9366 + if (au_h_dptr(dentry, bindex) == h_dentry)
9370 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9371 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9372 +++ linux/fs/aufs/dir.c 2015-06-28 17:36:09.025073697 +0200
9375 + * Copyright (C) 2005-2015 Junjiro R. Okajima
9377 + * This program, aufs is free software; you can redistribute it and/or modify
9378 + * it under the terms of the GNU General Public License as published by
9379 + * the Free Software Foundation; either version 2 of the License, or
9380 + * (at your option) any later version.
9382 + * This program is distributed in the hope that it will be useful,
9383 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9384 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9385 + * GNU General Public License for more details.
9387 + * You should have received a copy of the GNU General Public License
9388 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9392 + * directory operations
9395 +#include <linux/fs_stack.h>
9398 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9400 + unsigned int nlink;
9402 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9404 + nlink = dir->i_nlink;
9405 + nlink += h_dir->i_nlink - 2;
9406 + if (h_dir->i_nlink < 2)
9408 + smp_mb(); /* for i_nlink */
9409 + /* 0 can happen in revaliding */
9410 + set_nlink(dir, nlink);
9413 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9415 + unsigned int nlink;
9417 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9419 + nlink = dir->i_nlink;
9420 + nlink -= h_dir->i_nlink - 2;
9421 + if (h_dir->i_nlink < 2)
9423 + smp_mb(); /* for i_nlink */
9424 + /* nlink == 0 means the branch-fs is broken */
9425 + set_nlink(dir, nlink);
9428 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9431 + aufs_bindex_t bindex, bend;
9432 + struct file *h_file;
9433 + struct dentry *h_dentry;
9437 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9439 + bend = au_fbend_dir(file);
9440 + for (bindex = au_fbstart(file);
9441 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9443 + h_file = au_hf_dir(file, bindex);
9444 + if (h_file && file_inode(h_file))
9445 + sz += vfsub_f_size_read(h_file);
9448 + AuDebugOn(!dentry);
9449 + AuDebugOn(!d_is_dir(dentry));
9451 + bend = au_dbtaildir(dentry);
9452 + for (bindex = au_dbstart(dentry);
9453 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9455 + h_dentry = au_h_dptr(dentry, bindex);
9456 + if (h_dentry && d_is_positive(h_dentry))
9457 + sz += i_size_read(d_inode(h_dentry));
9460 + if (sz < KMALLOC_MAX_SIZE)
9461 + sz = roundup_pow_of_two(sz);
9462 + if (sz > KMALLOC_MAX_SIZE)
9463 + sz = KMALLOC_MAX_SIZE;
9464 + else if (sz < NAME_MAX) {
9465 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9466 + sz = AUFS_RDBLK_DEF;
9471 +struct au_dir_ts_arg {
9472 + struct dentry *dentry;
9473 + aufs_bindex_t brid;
9476 +static void au_do_dir_ts(void *arg)
9478 + struct au_dir_ts_arg *a = arg;
9479 + struct au_dtime dt;
9480 + struct path h_path;
9481 + struct inode *dir, *h_dir;
9482 + struct super_block *sb;
9483 + struct au_branch *br;
9484 + struct au_hinode *hdir;
9486 + aufs_bindex_t bstart, bindex;
9488 + sb = a->dentry->d_sb;
9489 + if (d_really_is_negative(a->dentry))
9491 + aufs_read_lock(a->dentry, AuLock_DW | AuLock_DIR); /* noflush */
9493 + /* no dir->i_mutex lock */
9494 + dir = d_inode(a->dentry);
9495 + bstart = au_ibstart(dir);
9496 + bindex = au_br_index(sb, a->brid);
9497 + if (bindex < bstart)
9500 + br = au_sbr(sb, bindex);
9501 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9502 + if (!h_path.dentry)
9504 + h_path.mnt = au_br_mnt(br);
9505 + au_dtime_store(&dt, a->dentry, &h_path);
9507 + br = au_sbr(sb, bstart);
9508 + if (!au_br_writable(br->br_perm))
9510 + h_path.dentry = au_h_dptr(a->dentry, bstart);
9511 + h_path.mnt = au_br_mnt(br);
9512 + err = vfsub_mnt_want_write(h_path.mnt);
9515 + hdir = au_hi(dir, bstart);
9516 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
9517 + h_dir = au_h_iptr(dir, bstart);
9518 + if (h_dir->i_nlink
9519 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9520 + dt.dt_h_path = h_path;
9521 + au_dtime_revert(&dt);
9523 + au_hn_imtx_unlock(hdir);
9524 + vfsub_mnt_drop_write(h_path.mnt);
9525 + au_cpup_attr_timesizes(dir);
9528 + aufs_read_unlock(a->dentry, AuLock_DW);
9531 + au_nwt_done(&au_sbi(sb)->si_nowait);
9535 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9537 + int perm, wkq_err;
9538 + aufs_bindex_t bstart;
9539 + struct au_dir_ts_arg *arg;
9540 + struct dentry *dentry;
9541 + struct super_block *sb;
9545 + dentry = d_find_any_alias(dir);
9546 + AuDebugOn(!dentry);
9547 + sb = dentry->d_sb;
9548 + bstart = au_ibstart(dir);
9549 + if (bstart == bindex) {
9550 + au_cpup_attr_timesizes(dir);
9554 + perm = au_sbr_perm(sb, bstart);
9555 + if (!au_br_writable(perm))
9558 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9562 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9563 + arg->brid = au_sbr_id(sb, bindex);
9564 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9565 + if (unlikely(wkq_err)) {
9566 + pr_err("wkq %d\n", wkq_err);
9575 +/* ---------------------------------------------------------------------- */
9577 +static int reopen_dir(struct file *file)
9580 + unsigned int flags;
9581 + aufs_bindex_t bindex, btail, bstart;
9582 + struct dentry *dentry, *h_dentry;
9583 + struct file *h_file;
9585 + /* open all lower dirs */
9586 + dentry = file->f_path.dentry;
9587 + bstart = au_dbstart(dentry);
9588 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9589 + au_set_h_fptr(file, bindex, NULL);
9590 + au_set_fbstart(file, bstart);
9592 + btail = au_dbtaildir(dentry);
9593 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9594 + au_set_h_fptr(file, bindex, NULL);
9595 + au_set_fbend_dir(file, btail);
9597 + flags = vfsub_file_flags(file);
9598 + for (bindex = bstart; bindex <= btail; bindex++) {
9599 + h_dentry = au_h_dptr(dentry, bindex);
9602 + h_file = au_hf_dir(file, bindex);
9606 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9607 + err = PTR_ERR(h_file);
9608 + if (IS_ERR(h_file))
9609 + goto out; /* close all? */
9610 + au_set_h_fptr(file, bindex, h_file);
9612 + au_update_figen(file);
9613 + /* todo: necessary? */
9614 + /* file->f_ra = h_file->f_ra; */
9621 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9624 + aufs_bindex_t bindex, btail;
9625 + struct dentry *dentry, *h_dentry;
9627 + FiMustWriteLock(file);
9628 + AuDebugOn(h_file);
9631 + dentry = file->f_path.dentry;
9632 + file->f_version = d_inode(dentry)->i_version;
9633 + bindex = au_dbstart(dentry);
9634 + au_set_fbstart(file, bindex);
9635 + btail = au_dbtaildir(dentry);
9636 + au_set_fbend_dir(file, btail);
9637 + for (; !err && bindex <= btail; bindex++) {
9638 + h_dentry = au_h_dptr(dentry, bindex);
9642 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9643 + if (IS_ERR(h_file)) {
9644 + err = PTR_ERR(h_file);
9647 + au_set_h_fptr(file, bindex, h_file);
9649 + au_update_figen(file);
9650 + /* todo: necessary? */
9651 + /* file->f_ra = h_file->f_ra; */
9653 + return 0; /* success */
9656 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9657 + au_set_h_fptr(file, bindex, NULL);
9658 + au_set_fbstart(file, -1);
9659 + au_set_fbend_dir(file, -1);
9664 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9665 + struct file *file)
9668 + struct super_block *sb;
9669 + struct au_fidir *fidir;
9672 + sb = file->f_path.dentry->d_sb;
9673 + si_read_lock(sb, AuLock_FLUSH);
9674 + fidir = au_fidir_alloc(sb);
9676 + struct au_do_open_args args = {
9677 + .open = do_open_dir,
9680 + err = au_do_open(file, &args);
9681 + if (unlikely(err))
9684 + si_read_unlock(sb);
9688 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9689 + struct file *file)
9691 + struct au_vdir *vdir_cache;
9692 + struct au_finfo *finfo;
9693 + struct au_fidir *fidir;
9694 + aufs_bindex_t bindex, bend;
9696 + finfo = au_fi(file);
9697 + fidir = finfo->fi_hdir;
9699 + au_sphl_del(&finfo->fi_hlist,
9700 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9701 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9703 + au_vdir_free(vdir_cache);
9705 + bindex = finfo->fi_btop;
9706 + if (bindex >= 0) {
9708 + * calls fput() instead of filp_close(),
9709 + * since no dnotify or lock for the lower file.
9711 + bend = fidir->fd_bbot;
9712 + for (; bindex <= bend; bindex++)
9713 + au_set_h_fptr(file, bindex, NULL);
9716 + finfo->fi_hdir = NULL;
9718 + au_finfo_fin(file);
9722 +/* ---------------------------------------------------------------------- */
9724 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9727 + aufs_bindex_t bindex, bend;
9728 + struct file *h_file;
9731 + bend = au_fbend_dir(file);
9732 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9733 + h_file = au_hf_dir(file, bindex);
9735 + err = vfsub_flush(h_file, id);
9740 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9742 + return au_do_flush(file, id, au_do_flush_dir);
9745 +/* ---------------------------------------------------------------------- */
9747 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9750 + aufs_bindex_t bend, bindex;
9751 + struct inode *inode;
9752 + struct super_block *sb;
9755 + sb = dentry->d_sb;
9756 + inode = d_inode(dentry);
9758 + bend = au_dbend(dentry);
9759 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9760 + struct path h_path;
9762 + if (au_test_ro(sb, bindex, inode))
9764 + h_path.dentry = au_h_dptr(dentry, bindex);
9765 + if (!h_path.dentry)
9768 + h_path.mnt = au_sbr_mnt(sb, bindex);
9769 + err = vfsub_fsync(NULL, &h_path, datasync);
9775 +static int au_do_fsync_dir(struct file *file, int datasync)
9778 + aufs_bindex_t bend, bindex;
9779 + struct file *h_file;
9780 + struct super_block *sb;
9781 + struct inode *inode;
9783 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9784 + if (unlikely(err))
9787 + inode = file_inode(file);
9789 + bend = au_fbend_dir(file);
9790 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9791 + h_file = au_hf_dir(file, bindex);
9792 + if (!h_file || au_test_ro(sb, bindex, inode))
9795 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9803 + * @file may be NULL
9805 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9809 + struct dentry *dentry;
9810 + struct inode *inode;
9811 + struct super_block *sb;
9812 + struct mutex *mtx;
9815 + dentry = file->f_path.dentry;
9816 + inode = d_inode(dentry);
9817 + mtx = &inode->i_mutex;
9819 + sb = dentry->d_sb;
9820 + si_noflush_read_lock(sb);
9822 + err = au_do_fsync_dir(file, datasync);
9824 + di_write_lock_child(dentry);
9825 + err = au_do_fsync_dir_no_file(dentry, datasync);
9827 + au_cpup_attr_timesizes(inode);
9828 + di_write_unlock(dentry);
9830 + fi_write_unlock(file);
9832 + si_read_unlock(sb);
9833 + mutex_unlock(mtx);
9837 +/* ---------------------------------------------------------------------- */
9839 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9842 + struct dentry *dentry;
9843 + struct inode *inode, *h_inode;
9844 + struct super_block *sb;
9846 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9848 + dentry = file->f_path.dentry;
9849 + inode = d_inode(dentry);
9852 + sb = dentry->d_sb;
9853 + si_read_lock(sb, AuLock_FLUSH);
9854 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9855 + if (unlikely(err))
9857 + err = au_alive_dir(dentry);
9859 + err = au_vdir_init(file);
9860 + di_downgrade_lock(dentry, AuLock_IR);
9861 + if (unlikely(err))
9864 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9865 + if (!au_test_nfsd()) {
9866 + err = au_vdir_fill_de(file, ctx);
9867 + fsstack_copy_attr_atime(inode, h_inode);
9870 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9871 + * encode_fh() and others.
9873 + atomic_inc(&h_inode->i_count);
9874 + di_read_unlock(dentry, AuLock_IR);
9875 + si_read_unlock(sb);
9876 + err = au_vdir_fill_de(file, ctx);
9877 + fsstack_copy_attr_atime(inode, h_inode);
9878 + fi_write_unlock(file);
9886 + di_read_unlock(dentry, AuLock_IR);
9887 + fi_write_unlock(file);
9889 + si_read_unlock(sb);
9893 +/* ---------------------------------------------------------------------- */
9895 +#define AuTestEmpty_WHONLY 1
9896 +#define AuTestEmpty_CALLED (1 << 1)
9897 +#define AuTestEmpty_SHWH (1 << 2)
9898 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9899 +#define au_fset_testempty(flags, name) \
9900 + do { (flags) |= AuTestEmpty_##name; } while (0)
9901 +#define au_fclr_testempty(flags, name) \
9902 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9904 +#ifndef CONFIG_AUFS_SHWH
9905 +#undef AuTestEmpty_SHWH
9906 +#define AuTestEmpty_SHWH 0
9909 +struct test_empty_arg {
9910 + struct dir_context ctx;
9911 + struct au_nhash *whlist;
9912 + unsigned int flags;
9914 + aufs_bindex_t bindex;
9917 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9918 + int namelen, loff_t offset __maybe_unused, u64 ino,
9919 + unsigned int d_type)
9921 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9923 + char *name = (void *)__name;
9926 + au_fset_testempty(arg->flags, CALLED);
9928 + if (name[0] == '.'
9929 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9930 + goto out; /* success */
9932 + if (namelen <= AUFS_WH_PFX_LEN
9933 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9934 + if (au_ftest_testempty(arg->flags, WHONLY)
9935 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9936 + arg->err = -ENOTEMPTY;
9940 + name += AUFS_WH_PFX_LEN;
9941 + namelen -= AUFS_WH_PFX_LEN;
9942 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9943 + arg->err = au_nhash_append_wh
9944 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9945 + au_ftest_testempty(arg->flags, SHWH));
9949 + AuTraceErr(arg->err);
9953 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9956 + struct file *h_file;
9958 + h_file = au_h_open(dentry, arg->bindex,
9959 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9960 + /*file*/NULL, /*force_wr*/0);
9961 + err = PTR_ERR(h_file);
9962 + if (IS_ERR(h_file))
9966 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9967 + && !file_inode(h_file)->i_nlink)
9972 + au_fclr_testempty(arg->flags, CALLED);
9974 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9977 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9981 + au_sbr_put(dentry->d_sb, arg->bindex);
9986 +struct do_test_empty_args {
9988 + struct dentry *dentry;
9989 + struct test_empty_arg *arg;
9992 +static void call_do_test_empty(void *args)
9994 + struct do_test_empty_args *a = args;
9995 + *a->errp = do_test_empty(a->dentry, a->arg);
9998 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10000 + int err, wkq_err;
10001 + struct dentry *h_dentry;
10002 + struct inode *h_inode;
10004 + h_dentry = au_h_dptr(dentry, arg->bindex);
10005 + h_inode = d_inode(h_dentry);
10006 + /* todo: i_mode changes anytime? */
10007 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
10008 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10009 + mutex_unlock(&h_inode->i_mutex);
10011 + err = do_test_empty(dentry, arg);
10013 + struct do_test_empty_args args = {
10015 + .dentry = dentry,
10018 + unsigned int flags = arg->flags;
10020 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10021 + if (unlikely(wkq_err))
10023 + arg->flags = flags;
10029 +int au_test_empty_lower(struct dentry *dentry)
10032 + unsigned int rdhash;
10033 + aufs_bindex_t bindex, bstart, btail;
10034 + struct au_nhash whlist;
10035 + struct test_empty_arg arg = {
10037 + .actor = test_empty_cb
10040 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10042 + SiMustAnyLock(dentry->d_sb);
10044 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10046 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10047 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10048 + if (unlikely(err))
10052 + arg.whlist = &whlist;
10053 + bstart = au_dbstart(dentry);
10054 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10055 + au_fset_testempty(arg.flags, SHWH);
10056 + test_empty = do_test_empty;
10057 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10058 + test_empty = sio_test_empty;
10059 + arg.bindex = bstart;
10060 + err = test_empty(dentry, &arg);
10061 + if (unlikely(err))
10064 + au_fset_testempty(arg.flags, WHONLY);
10065 + btail = au_dbtaildir(dentry);
10066 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
10067 + struct dentry *h_dentry;
10069 + h_dentry = au_h_dptr(dentry, bindex);
10070 + if (h_dentry && d_is_positive(h_dentry)) {
10071 + arg.bindex = bindex;
10072 + err = test_empty(dentry, &arg);
10077 + au_nhash_wh_free(&whlist);
10082 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10085 + struct test_empty_arg arg = {
10087 + .actor = test_empty_cb
10090 + aufs_bindex_t bindex, btail;
10093 + arg.whlist = whlist;
10094 + arg.flags = AuTestEmpty_WHONLY;
10095 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10096 + au_fset_testempty(arg.flags, SHWH);
10097 + btail = au_dbtaildir(dentry);
10098 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
10099 + struct dentry *h_dentry;
10101 + h_dentry = au_h_dptr(dentry, bindex);
10102 + if (h_dentry && d_is_positive(h_dentry)) {
10103 + arg.bindex = bindex;
10104 + err = sio_test_empty(dentry, &arg);
10111 +/* ---------------------------------------------------------------------- */
10113 +const struct file_operations aufs_dir_fop = {
10114 + .owner = THIS_MODULE,
10115 + .llseek = default_llseek,
10116 + .read = generic_read_dir,
10117 + .iterate = aufs_iterate,
10118 + .unlocked_ioctl = aufs_ioctl_dir,
10119 +#ifdef CONFIG_COMPAT
10120 + .compat_ioctl = aufs_compat_ioctl_dir,
10122 + .open = aufs_open_dir,
10123 + .release = aufs_release_dir,
10124 + .flush = aufs_flush_dir,
10125 + .fsync = aufs_fsync_dir
10127 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10128 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10129 +++ linux/fs/aufs/dir.h 2015-06-28 17:35:44.348050491 +0200
10132 + * Copyright (C) 2005-2015 Junjiro R. Okajima
10134 + * This program, aufs is free software; you can redistribute it and/or modify
10135 + * it under the terms of the GNU General Public License as published by
10136 + * the Free Software Foundation; either version 2 of the License, or
10137 + * (at your option) any later version.
10139 + * This program is distributed in the hope that it will be useful,
10140 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10141 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10142 + * GNU General Public License for more details.
10144 + * You should have received a copy of the GNU General Public License
10145 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10149 + * directory operations
10152 +#ifndef __AUFS_DIR_H__
10153 +#define __AUFS_DIR_H__
10157 +#include <linux/fs.h>
10159 +/* ---------------------------------------------------------------------- */
10161 +/* need to be faster and smaller */
10164 + unsigned int nh_num;
10165 + struct hlist_head *nh_head;
10168 +struct au_vdir_destr {
10169 + unsigned char len;
10170 + unsigned char name[0];
10173 +struct au_vdir_dehstr {
10174 + struct hlist_node hash;
10175 + struct au_vdir_destr *str;
10176 +} ____cacheline_aligned_in_smp;
10178 +struct au_vdir_de {
10180 + unsigned char de_type;
10181 + /* caution: packed */
10182 + struct au_vdir_destr de_str;
10185 +struct au_vdir_wh {
10186 + struct hlist_node wh_hash;
10187 +#ifdef CONFIG_AUFS_SHWH
10189 + aufs_bindex_t wh_bindex;
10190 + unsigned char wh_type;
10192 + aufs_bindex_t wh_bindex;
10194 + /* caution: packed */
10195 + struct au_vdir_destr wh_str;
10198 +union au_vdir_deblk_p {
10199 + unsigned char *deblk;
10200 + struct au_vdir_de *de;
10204 + unsigned char **vd_deblk;
10205 + unsigned long vd_nblk;
10207 + unsigned long ul;
10208 + union au_vdir_deblk_p p;
10211 + unsigned long vd_version;
10212 + unsigned int vd_deblk_sz;
10213 + unsigned long vd_jiffy;
10214 +} ____cacheline_aligned_in_smp;
10216 +/* ---------------------------------------------------------------------- */
10219 +extern const struct file_operations aufs_dir_fop;
10220 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10221 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10222 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10223 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10224 +int au_test_empty_lower(struct dentry *dentry);
10225 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10228 +unsigned int au_rdhash_est(loff_t sz);
10229 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10230 +void au_nhash_wh_free(struct au_nhash *whlist);
10231 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10233 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10234 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10235 + unsigned int d_type, aufs_bindex_t bindex,
10236 + unsigned char shwh);
10237 +void au_vdir_free(struct au_vdir *vdir);
10238 +int au_vdir_init(struct file *file);
10239 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10242 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10244 +#ifdef CONFIG_AUFS_RDU
10246 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10247 +#ifdef CONFIG_COMPAT
10248 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10249 + unsigned long arg);
10252 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10253 + unsigned int cmd, unsigned long arg)
10254 +#ifdef CONFIG_COMPAT
10255 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10256 + unsigned int cmd, unsigned long arg)
10260 +#endif /* __KERNEL__ */
10261 +#endif /* __AUFS_DIR_H__ */
10262 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10263 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10264 +++ linux/fs/aufs/dynop.c 2015-06-28 17:35:44.348050491 +0200
10267 + * Copyright (C) 2010-2015 Junjiro R. Okajima
10269 + * This program, aufs is free software; you can redistribute it and/or modify
10270 + * it under the terms of the GNU General Public License as published by
10271 + * the Free Software Foundation; either version 2 of the License, or
10272 + * (at your option) any later version.
10274 + * This program is distributed in the hope that it will be useful,
10275 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10276 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10277 + * GNU General Public License for more details.
10279 + * You should have received a copy of the GNU General Public License
10280 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10284 + * dynamically customizable operations for regular files
10289 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10292 + * How large will these lists be?
10293 + * Usually just a few elements, 20-30 at most for each, I guess.
10295 +static struct au_splhead dynop[AuDyLast];
10297 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
10299 + struct au_dykey *key, *tmp;
10300 + struct list_head *head;
10303 + head = &spl->head;
10305 + list_for_each_entry_rcu(tmp, head, dk_list)
10306 + if (tmp->dk_op.dy_hop == h_op) {
10308 + kref_get(&key->dk_kref);
10311 + rcu_read_unlock();
10316 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10318 + struct au_dykey **k, *found;
10319 + const void *h_op = key->dk_op.dy_hop;
10323 + k = br->br_dykey;
10324 + for (i = 0; i < AuBrDynOp; i++)
10326 + if (k[i]->dk_op.dy_hop == h_op) {
10333 + spin_lock(&br->br_dykey_lock);
10334 + for (; i < AuBrDynOp; i++)
10336 + if (k[i]->dk_op.dy_hop == h_op) {
10344 + spin_unlock(&br->br_dykey_lock);
10345 + BUG_ON(i == AuBrDynOp); /* expand the array */
10351 +/* kref_get() if @key is already added */
10352 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
10354 + struct au_dykey *tmp, *found;
10355 + struct list_head *head;
10356 + const void *h_op = key->dk_op.dy_hop;
10359 + head = &spl->head;
10360 + spin_lock(&spl->spin);
10361 + list_for_each_entry(tmp, head, dk_list)
10362 + if (tmp->dk_op.dy_hop == h_op) {
10363 + kref_get(&tmp->dk_kref);
10368 + list_add_rcu(&key->dk_list, head);
10369 + spin_unlock(&spl->spin);
10376 +static void dy_free_rcu(struct rcu_head *rcu)
10378 + struct au_dykey *key;
10380 + key = container_of(rcu, struct au_dykey, dk_rcu);
10385 +static void dy_free(struct kref *kref)
10387 + struct au_dykey *key;
10388 + struct au_splhead *spl;
10390 + key = container_of(kref, struct au_dykey, dk_kref);
10391 + spl = dynop + key->dk_op.dy_type;
10392 + au_spl_del_rcu(&key->dk_list, spl);
10393 + call_rcu(&key->dk_rcu, dy_free_rcu);
10396 +void au_dy_put(struct au_dykey *key)
10398 + kref_put(&key->dk_kref, dy_free);
10401 +/* ---------------------------------------------------------------------- */
10403 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10405 +#ifdef CONFIG_AUFS_DEBUG
10406 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10407 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10409 +#define DyDbgDeclare(cnt) do {} while (0)
10410 +#define DyDbgInc(cnt) do {} while (0)
10413 +#define DySet(func, dst, src, h_op, h_sb) do { \
10415 + if (h_op->func) { \
10417 + dst.func = src.func; \
10419 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10423 +#define DySetForce(func, dst, src) do { \
10424 + AuDebugOn(!src.func); \
10426 + dst.func = src.func; \
10429 +#define DySetAop(func) \
10430 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10431 +#define DySetAopForce(func) \
10432 + DySetForce(func, dyaop->da_op, aufs_aop)
10434 +static void dy_aop(struct au_dykey *key, const void *h_op,
10435 + struct super_block *h_sb __maybe_unused)
10437 + struct au_dyaop *dyaop = (void *)key;
10438 + const struct address_space_operations *h_aop = h_op;
10439 + DyDbgDeclare(cnt);
10441 + AuDbg("%s\n", au_sbtype(h_sb));
10443 + DySetAop(writepage);
10444 + DySetAopForce(readpage); /* force */
10445 + DySetAop(writepages);
10446 + DySetAop(set_page_dirty);
10447 + DySetAop(readpages);
10448 + DySetAop(write_begin);
10449 + DySetAop(write_end);
10451 + DySetAop(invalidatepage);
10452 + DySetAop(releasepage);
10453 + DySetAop(freepage);
10454 + /* this one will be changed according to an aufs mount option */
10455 + DySetAop(direct_IO);
10456 + DySetAop(migratepage);
10457 + DySetAop(launder_page);
10458 + DySetAop(is_partially_uptodate);
10459 + DySetAop(is_dirty_writeback);
10460 + DySetAop(error_remove_page);
10461 + DySetAop(swap_activate);
10462 + DySetAop(swap_deactivate);
10464 + DyDbgSize(cnt, *h_aop);
10467 +/* ---------------------------------------------------------------------- */
10469 +static void dy_bug(struct kref *kref)
10474 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10476 + struct au_dykey *key, *old;
10477 + struct au_splhead *spl;
10480 + void (*set)(struct au_dykey *key, const void *h_op,
10481 + struct super_block *h_sb __maybe_unused);
10483 + static const struct op a[] = {
10485 + .sz = sizeof(struct au_dyaop),
10489 + const struct op *p;
10491 + spl = dynop + op->dy_type;
10492 + key = dy_gfind_get(spl, op->dy_hop);
10494 + goto out_add; /* success */
10496 + p = a + op->dy_type;
10497 + key = kzalloc(p->sz, GFP_NOFS);
10498 + if (unlikely(!key)) {
10499 + key = ERR_PTR(-ENOMEM);
10503 + key->dk_op.dy_hop = op->dy_hop;
10504 + kref_init(&key->dk_kref);
10505 + p->set(key, op->dy_hop, au_br_sb(br));
10506 + old = dy_gadd(spl, key);
10513 + old = dy_bradd(br, key);
10515 + /* its ref-count should never be zero here */
10516 + kref_put(&key->dk_kref, dy_bug);
10521 +/* ---------------------------------------------------------------------- */
10523 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10524 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10525 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10526 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10527 + * See the aufs manual in detail.
10529 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10532 + dyaop->da_op.direct_IO = NULL;
10534 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10537 +static struct au_dyaop *dy_aget(struct au_branch *br,
10538 + const struct address_space_operations *h_aop,
10541 + struct au_dyaop *dyaop;
10542 + struct au_dynop op;
10544 + op.dy_type = AuDy_AOP;
10545 + op.dy_haop = h_aop;
10546 + dyaop = (void *)dy_get(&op, br);
10547 + if (IS_ERR(dyaop))
10549 + dy_adx(dyaop, do_dx);
10555 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10556 + struct inode *h_inode)
10559 + struct super_block *sb;
10560 + struct au_branch *br;
10561 + struct au_dyaop *dyaop;
10563 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10564 + IiMustWriteLock(inode);
10566 + sb = inode->i_sb;
10567 + br = au_sbr(sb, bindex);
10568 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10569 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10570 + err = PTR_ERR(dyaop);
10571 + if (IS_ERR(dyaop))
10572 + /* unnecessary to call dy_fput() */
10576 + inode->i_mapping->a_ops = &dyaop->da_op;
10583 + * Is it safe to replace a_ops during the inode/file is in operation?
10584 + * Yes, I hope so.
10586 +int au_dy_irefresh(struct inode *inode)
10589 + aufs_bindex_t bstart;
10590 + struct inode *h_inode;
10593 + if (S_ISREG(inode->i_mode)) {
10594 + bstart = au_ibstart(inode);
10595 + h_inode = au_h_iptr(inode, bstart);
10596 + err = au_dy_iaop(inode, bstart, h_inode);
10601 +void au_dy_arefresh(int do_dx)
10603 + struct au_splhead *spl;
10604 + struct list_head *head;
10605 + struct au_dykey *key;
10607 + spl = dynop + AuDy_AOP;
10608 + head = &spl->head;
10609 + spin_lock(&spl->spin);
10610 + list_for_each_entry(key, head, dk_list)
10611 + dy_adx((void *)key, do_dx);
10612 + spin_unlock(&spl->spin);
10615 +/* ---------------------------------------------------------------------- */
10617 +void __init au_dy_init(void)
10621 + /* make sure that 'struct au_dykey *' can be any type */
10622 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10624 + for (i = 0; i < AuDyLast; i++)
10625 + au_spl_init(dynop + i);
10628 +void au_dy_fin(void)
10632 + for (i = 0; i < AuDyLast; i++)
10633 + WARN_ON(!list_empty(&dynop[i].head));
10635 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10636 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10637 +++ linux/fs/aufs/dynop.h 2015-06-28 17:35:44.348050491 +0200
10640 + * Copyright (C) 2010-2015 Junjiro R. Okajima
10642 + * This program, aufs is free software; you can redistribute it and/or modify
10643 + * it under the terms of the GNU General Public License as published by
10644 + * the Free Software Foundation; either version 2 of the License, or
10645 + * (at your option) any later version.
10647 + * This program is distributed in the hope that it will be useful,
10648 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10649 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10650 + * GNU General Public License for more details.
10652 + * You should have received a copy of the GNU General Public License
10653 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10657 + * dynamically customizable operations (for regular files only)
10660 +#ifndef __AUFS_DYNOP_H__
10661 +#define __AUFS_DYNOP_H__
10665 +#include <linux/fs.h>
10666 +#include <linux/kref.h>
10668 +enum {AuDy_AOP, AuDyLast};
10673 + const void *dy_hop;
10674 + const struct address_space_operations *dy_haop;
10680 + struct list_head dk_list;
10681 + struct rcu_head dk_rcu;
10683 + struct au_dynop dk_op;
10686 + * during I am in the branch local array, kref is gotten. when the
10687 + * branch is removed, kref is put.
10689 + struct kref dk_kref;
10692 +/* stop unioning since their sizes are very different from each other */
10694 + struct au_dykey da_key;
10695 + struct address_space_operations da_op; /* not const */
10698 +/* ---------------------------------------------------------------------- */
10702 +void au_dy_put(struct au_dykey *key);
10703 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10704 + struct inode *h_inode);
10705 +int au_dy_irefresh(struct inode *inode);
10706 +void au_dy_arefresh(int do_dio);
10708 +void __init au_dy_init(void);
10709 +void au_dy_fin(void);
10711 +#endif /* __KERNEL__ */
10712 +#endif /* __AUFS_DYNOP_H__ */
10713 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10714 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10715 +++ linux/fs/aufs/export.c 2015-06-28 17:36:09.025073697 +0200
10718 + * Copyright (C) 2005-2015 Junjiro R. Okajima
10720 + * This program, aufs is free software; you can redistribute it and/or modify
10721 + * it under the terms of the GNU General Public License as published by
10722 + * the Free Software Foundation; either version 2 of the License, or
10723 + * (at your option) any later version.
10725 + * This program is distributed in the hope that it will be useful,
10726 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10727 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10728 + * GNU General Public License for more details.
10730 + * You should have received a copy of the GNU General Public License
10731 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10738 +#include <linux/exportfs.h>
10739 +#include <linux/fs_struct.h>
10740 +#include <linux/namei.h>
10741 +#include <linux/nsproxy.h>
10742 +#include <linux/random.h>
10743 +#include <linux/writeback.h>
10744 +#include "../fs/mount.h"
10748 +#ifdef CONFIG_AUFS_INO_T_64
10756 +static ino_t decode_ino(__u32 *a)
10760 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10762 +#ifdef CONFIG_AUFS_INO_T_64
10768 +static void encode_ino(__u32 *a, ino_t ino)
10774 +#ifdef CONFIG_AUFS_INO_T_64
10779 +/* NFS file handle */
10783 +#ifdef CONFIG_AUFS_INO_T_64
10784 + /* support 64bit inode number */
10797 + Fh_ino = Fh_ino1,
10798 + Fh_dir_ino = Fh_dir_ino1
10801 +static int au_test_anon(struct dentry *dentry)
10803 + /* note: read d_flags without d_lock */
10804 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10807 +int au_test_nfsd(void)
10810 + struct task_struct *tsk = current;
10811 + char comm[sizeof(tsk->comm)];
10814 + if (tsk->flags & PF_KTHREAD) {
10815 + get_task_comm(comm, tsk);
10816 + ret = !strcmp(comm, "nfsd");
10822 +/* ---------------------------------------------------------------------- */
10823 +/* inode generation external table */
10825 +void au_xigen_inc(struct inode *inode)
10830 + struct super_block *sb;
10831 + struct au_sbinfo *sbinfo;
10833 + sb = inode->i_sb;
10834 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10836 + sbinfo = au_sbi(sb);
10837 + pos = inode->i_ino;
10838 + pos *= sizeof(igen);
10839 + igen = inode->i_generation + 1;
10840 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10841 + sizeof(igen), &pos);
10842 + if (sz == sizeof(igen))
10843 + return; /* success */
10845 + if (unlikely(sz >= 0))
10846 + AuIOErr("xigen error (%zd)\n", sz);
10849 +int au_xigen_new(struct inode *inode)
10854 + struct super_block *sb;
10855 + struct au_sbinfo *sbinfo;
10856 + struct file *file;
10859 + /* todo: dirty, at mount time */
10860 + if (inode->i_ino == AUFS_ROOT_INO)
10862 + sb = inode->i_sb;
10863 + SiMustAnyLock(sb);
10864 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10868 + pos = inode->i_ino;
10869 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10870 + AuIOErr1("too large i%lld\n", pos);
10873 + pos *= sizeof(inode->i_generation);
10876 + sbinfo = au_sbi(sb);
10877 + file = sbinfo->si_xigen;
10880 + if (vfsub_f_size_read(file)
10881 + < pos + sizeof(inode->i_generation)) {
10882 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10883 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10884 + sizeof(inode->i_generation), &pos);
10886 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10887 + sizeof(inode->i_generation), &pos);
10888 + if (sz == sizeof(inode->i_generation))
10889 + goto out; /* success */
10892 + if (unlikely(sz >= 0)) {
10894 + AuIOErr("xigen error (%zd)\n", sz);
10901 +int au_xigen_set(struct super_block *sb, struct file *base)
10904 + struct au_sbinfo *sbinfo;
10905 + struct file *file;
10907 + SiMustWriteLock(sb);
10909 + sbinfo = au_sbi(sb);
10910 + file = au_xino_create2(base, sbinfo->si_xigen);
10911 + err = PTR_ERR(file);
10912 + if (IS_ERR(file))
10915 + if (sbinfo->si_xigen)
10916 + fput(sbinfo->si_xigen);
10917 + sbinfo->si_xigen = file;
10923 +void au_xigen_clr(struct super_block *sb)
10925 + struct au_sbinfo *sbinfo;
10927 + SiMustWriteLock(sb);
10929 + sbinfo = au_sbi(sb);
10930 + if (sbinfo->si_xigen) {
10931 + fput(sbinfo->si_xigen);
10932 + sbinfo->si_xigen = NULL;
10936 +/* ---------------------------------------------------------------------- */
10938 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10941 + struct dentry *dentry, *d;
10942 + struct inode *inode;
10943 + unsigned int sigen;
10946 + inode = ilookup(sb, ino);
10950 + dentry = ERR_PTR(-ESTALE);
10951 + sigen = au_sigen(sb);
10952 + if (unlikely(is_bad_inode(inode)
10953 + || IS_DEADDIR(inode)
10954 + || sigen != au_iigen(inode, NULL)))
10958 + if (!dir_ino || S_ISDIR(inode->i_mode))
10959 + dentry = d_find_alias(inode);
10961 + spin_lock(&inode->i_lock);
10962 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
10963 + spin_lock(&d->d_lock);
10964 + if (!au_test_anon(d)
10965 + && d_inode(d->d_parent)->i_ino == dir_ino) {
10966 + dentry = dget_dlock(d);
10967 + spin_unlock(&d->d_lock);
10970 + spin_unlock(&d->d_lock);
10972 + spin_unlock(&inode->i_lock);
10974 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10975 + /* need to refresh */
10983 + AuTraceErrPtr(dentry);
10987 +/* ---------------------------------------------------------------------- */
10989 +/* todo: dirty? */
10990 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10992 +struct au_compare_mnt_args {
10994 + struct super_block *sb;
10997 + struct vfsmount *mnt;
11000 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
11002 + struct au_compare_mnt_args *a = arg;
11004 + if (mnt->mnt_sb != a->sb)
11006 + a->mnt = mntget(mnt);
11010 +static struct vfsmount *au_mnt_get(struct super_block *sb)
11013 + struct path root;
11014 + struct au_compare_mnt_args args = {
11018 + get_fs_root(current->fs, &root);
11020 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
11021 + rcu_read_unlock();
11024 + AuDebugOn(!args.mnt);
11028 +struct au_nfsd_si_lock {
11029 + unsigned int sigen;
11030 + aufs_bindex_t bindex, br_id;
11031 + unsigned char force_lock;
11034 +static int si_nfsd_read_lock(struct super_block *sb,
11035 + struct au_nfsd_si_lock *nsi_lock)
11038 + aufs_bindex_t bindex;
11040 + si_read_lock(sb, AuLock_FLUSH);
11042 + /* branch id may be wrapped around */
11044 + bindex = au_br_index(sb, nsi_lock->br_id);
11045 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11046 + goto out; /* success */
11050 + if (!nsi_lock->force_lock)
11051 + si_read_unlock(sb);
11054 + nsi_lock->bindex = bindex;
11058 +struct find_name_by_ino {
11059 + struct dir_context ctx;
11060 + int called, found;
11067 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11068 + loff_t offset, u64 ino, unsigned int d_type)
11070 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11074 + if (a->ino != ino)
11077 + memcpy(a->name, name, namelen);
11078 + a->namelen = namelen;
11083 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11084 + struct au_nfsd_si_lock *nsi_lock)
11086 + struct dentry *dentry, *parent;
11087 + struct file *file;
11088 + struct inode *dir;
11089 + struct find_name_by_ino arg = {
11091 + .actor = find_name_by_ino
11096 + parent = path->dentry;
11098 + si_read_unlock(parent->d_sb);
11099 + file = vfsub_dentry_open(path, au_dir_roflags);
11100 + dentry = (void *)file;
11101 + if (IS_ERR(file))
11104 + dentry = ERR_PTR(-ENOMEM);
11105 + arg.name = (void *)__get_free_page(GFP_NOFS);
11106 + if (unlikely(!arg.name))
11113 + err = vfsub_iterate_dir(file, &arg.ctx);
11114 + } while (!err && !arg.found && arg.called);
11115 + dentry = ERR_PTR(err);
11116 + if (unlikely(err))
11118 + /* instead of ENOENT */
11119 + dentry = ERR_PTR(-ESTALE);
11123 + /* do not call vfsub_lkup_one() */
11124 + dir = d_inode(parent);
11125 + mutex_lock(&dir->i_mutex);
11126 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
11127 + mutex_unlock(&dir->i_mutex);
11128 + AuTraceErrPtr(dentry);
11129 + if (IS_ERR(dentry))
11131 + AuDebugOn(au_test_anon(dentry));
11132 + if (unlikely(d_really_is_negative(dentry))) {
11134 + dentry = ERR_PTR(-ENOENT);
11138 + free_page((unsigned long)arg.name);
11142 + if (unlikely(nsi_lock
11143 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11144 + if (!IS_ERR(dentry)) {
11146 + dentry = ERR_PTR(-ESTALE);
11148 + AuTraceErrPtr(dentry);
11152 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11154 + struct au_nfsd_si_lock *nsi_lock)
11156 + struct dentry *dentry;
11157 + struct path path;
11159 + if (dir_ino != AUFS_ROOT_INO) {
11160 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11161 + dentry = path.dentry;
11162 + if (!path.dentry || IS_ERR(path.dentry))
11164 + AuDebugOn(au_test_anon(path.dentry));
11166 + path.dentry = dget(sb->s_root);
11168 + path.mnt = au_mnt_get(sb);
11169 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11173 + AuTraceErrPtr(dentry);
11177 +/* ---------------------------------------------------------------------- */
11179 +static int h_acceptable(void *expv, struct dentry *dentry)
11184 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11185 + char *buf, int len, struct super_block *sb)
11189 + struct path path;
11191 + p = d_path(h_rootpath, buf, len);
11196 + path.mnt = h_rootpath->mnt;
11197 + path.dentry = h_parent;
11198 + p = d_path(&path, buf, len);
11204 + path.mnt = au_mnt_get(sb);
11205 + path.dentry = sb->s_root;
11206 + p = d_path(&path, buf, len - strlen(p));
11207 + mntput(path.mnt);
11211 + p[strlen(p)] = '/';
11214 + AuTraceErrPtr(p);
11219 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11220 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11222 + struct dentry *dentry, *h_parent, *root;
11223 + struct super_block *h_sb;
11224 + char *pathname, *p;
11225 + struct vfsmount *h_mnt;
11226 + struct au_branch *br;
11228 + struct path path;
11230 + br = au_sbr(sb, nsi_lock->bindex);
11231 + h_mnt = au_br_mnt(br);
11232 + h_sb = h_mnt->mnt_sb;
11233 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11234 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11235 + fh_len - Fh_tail, fh[Fh_h_type],
11236 + h_acceptable, /*context*/NULL);
11237 + dentry = h_parent;
11238 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11239 + AuWarn1("%s decode_fh failed, %ld\n",
11240 + au_sbtype(h_sb), PTR_ERR(h_parent));
11244 + if (unlikely(au_test_anon(h_parent))) {
11245 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11246 + au_sbtype(h_sb));
11247 + goto out_h_parent;
11250 + dentry = ERR_PTR(-ENOMEM);
11251 + pathname = (void *)__get_free_page(GFP_NOFS);
11252 + if (unlikely(!pathname))
11253 + goto out_h_parent;
11255 + root = sb->s_root;
11256 + path.mnt = h_mnt;
11257 + di_read_lock_parent(root, !AuLock_IR);
11258 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11259 + di_read_unlock(root, !AuLock_IR);
11260 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11261 + dentry = (void *)p;
11263 + goto out_pathname;
11265 + si_read_unlock(sb);
11266 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11267 + dentry = ERR_PTR(err);
11268 + if (unlikely(err))
11271 + dentry = ERR_PTR(-ENOENT);
11272 + AuDebugOn(au_test_anon(path.dentry));
11273 + if (unlikely(d_really_is_negative(path.dentry)))
11276 + if (ino != d_inode(path.dentry)->i_ino)
11277 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11279 + dentry = dget(path.dentry);
11284 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11285 + if (!IS_ERR(dentry)) {
11287 + dentry = ERR_PTR(-ESTALE);
11290 + free_page((unsigned long)pathname);
11294 + AuTraceErrPtr(dentry);
11298 +/* ---------------------------------------------------------------------- */
11300 +static struct dentry *
11301 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11304 + struct dentry *dentry;
11305 + __u32 *fh = fid->raw;
11306 + struct au_branch *br;
11307 + ino_t ino, dir_ino;
11308 + struct au_nfsd_si_lock nsi_lock = {
11312 + dentry = ERR_PTR(-ESTALE);
11313 + /* it should never happen, but the file handle is unreliable */
11314 + if (unlikely(fh_len < Fh_tail))
11316 + nsi_lock.sigen = fh[Fh_sigen];
11317 + nsi_lock.br_id = fh[Fh_br_id];
11319 + /* branch id may be wrapped around */
11321 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11323 + nsi_lock.force_lock = 1;
11325 + /* is this inode still cached? */
11326 + ino = decode_ino(fh + Fh_ino);
11327 + /* it should never happen */
11328 + if (unlikely(ino == AUFS_ROOT_INO))
11331 + dir_ino = decode_ino(fh + Fh_dir_ino);
11332 + dentry = decode_by_ino(sb, ino, dir_ino);
11333 + if (IS_ERR(dentry))
11338 + /* is the parent dir cached? */
11339 + br = au_sbr(sb, nsi_lock.bindex);
11340 + atomic_inc(&br->br_count);
11341 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11342 + if (IS_ERR(dentry))
11347 + /* lookup path */
11348 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11349 + if (IS_ERR(dentry))
11351 + if (unlikely(!dentry))
11352 + /* todo?: make it ESTALE */
11356 + if (!au_digen_test(dentry, au_sigen(sb))
11357 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11358 + goto out_unlock; /* success */
11361 + dentry = ERR_PTR(-ESTALE);
11364 + atomic_dec(&br->br_count);
11365 + si_read_unlock(sb);
11367 + AuTraceErrPtr(dentry);
11371 +#if 0 /* reserved for future use */
11372 +/* support subtreecheck option */
11373 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11374 + int fh_len, int fh_type)
11376 + struct dentry *parent;
11377 + __u32 *fh = fid->raw;
11380 + dir_ino = decode_ino(fh + Fh_dir_ino);
11381 + parent = decode_by_ino(sb, dir_ino, 0);
11382 + if (IS_ERR(parent))
11385 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11386 + dir_ino, fh, fh_len);
11389 + AuTraceErrPtr(parent);
11394 +/* ---------------------------------------------------------------------- */
11396 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11397 + struct inode *dir)
11400 + aufs_bindex_t bindex;
11401 + struct super_block *sb, *h_sb;
11402 + struct dentry *dentry, *parent, *h_parent;
11403 + struct inode *h_dir;
11404 + struct au_branch *br;
11407 + if (unlikely(*max_len <= Fh_tail)) {
11408 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11412 + err = FILEID_ROOT;
11413 + if (inode->i_ino == AUFS_ROOT_INO) {
11414 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11419 + sb = inode->i_sb;
11420 + err = si_read_lock(sb, AuLock_FLUSH);
11421 + if (unlikely(err))
11424 +#ifdef CONFIG_AUFS_DEBUG
11425 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11426 + AuWarn1("NFS-exporting requires xino\n");
11430 + ii_read_lock_child(inode);
11431 + bindex = au_ibstart(inode);
11433 + dentry = d_find_any_alias(inode);
11434 + if (unlikely(!dentry))
11436 + AuDebugOn(au_test_anon(dentry));
11437 + parent = dget_parent(dentry);
11439 + if (unlikely(!parent))
11441 + if (d_really_is_positive(parent))
11442 + dir = d_inode(parent);
11445 + ii_read_lock_parent(dir);
11446 + h_dir = au_h_iptr(dir, bindex);
11447 + ii_read_unlock(dir);
11448 + if (unlikely(!h_dir))
11450 + h_parent = d_find_any_alias(h_dir);
11451 + if (unlikely(!h_parent))
11452 + goto out_hparent;
11455 + br = au_sbr(sb, bindex);
11456 + h_sb = au_br_sb(br);
11457 + if (unlikely(!h_sb->s_export_op)) {
11458 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11459 + goto out_hparent;
11462 + fh[Fh_br_id] = br->br_id;
11463 + fh[Fh_sigen] = au_sigen(sb);
11464 + encode_ino(fh + Fh_ino, inode->i_ino);
11465 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11466 + fh[Fh_igen] = inode->i_generation;
11468 + *max_len -= Fh_tail;
11469 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11471 + /*connectable or subtreecheck*/0);
11472 + err = fh[Fh_h_type];
11473 + *max_len += Fh_tail;
11474 + /* todo: macros? */
11475 + if (err != FILEID_INVALID)
11478 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11485 + ii_read_unlock(inode);
11486 + si_read_unlock(sb);
11488 + if (unlikely(err < 0))
11489 + err = FILEID_INVALID;
11493 +/* ---------------------------------------------------------------------- */
11495 +static int aufs_commit_metadata(struct inode *inode)
11498 + aufs_bindex_t bindex;
11499 + struct super_block *sb;
11500 + struct inode *h_inode;
11501 + int (*f)(struct inode *inode);
11503 + sb = inode->i_sb;
11504 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11505 + ii_write_lock_child(inode);
11506 + bindex = au_ibstart(inode);
11507 + AuDebugOn(bindex < 0);
11508 + h_inode = au_h_iptr(inode, bindex);
11510 + f = h_inode->i_sb->s_export_op->commit_metadata;
11512 + err = f(h_inode);
11514 + struct writeback_control wbc = {
11515 + .sync_mode = WB_SYNC_ALL,
11516 + .nr_to_write = 0 /* metadata only */
11519 + err = sync_inode(h_inode, &wbc);
11522 + au_cpup_attr_timesizes(inode);
11523 + ii_write_unlock(inode);
11524 + si_read_unlock(sb);
11528 +/* ---------------------------------------------------------------------- */
11530 +static struct export_operations aufs_export_op = {
11531 + .fh_to_dentry = aufs_fh_to_dentry,
11532 + /* .fh_to_parent = aufs_fh_to_parent, */
11533 + .encode_fh = aufs_encode_fh,
11534 + .commit_metadata = aufs_commit_metadata
11537 +void au_export_init(struct super_block *sb)
11539 + struct au_sbinfo *sbinfo;
11542 + sb->s_export_op = &aufs_export_op;
11543 + sbinfo = au_sbi(sb);
11544 + sbinfo->si_xigen = NULL;
11545 + get_random_bytes(&u, sizeof(u));
11546 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11547 + atomic_set(&sbinfo->si_xigen_next, u);
11549 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11550 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11551 +++ linux/fs/aufs/fhsm.c 2015-06-28 17:35:44.348050491 +0200
11554 + * Copyright (C) 2011-2015 Junjiro R. Okajima
11556 + * This program, aufs is free software; you can redistribute it and/or modify
11557 + * it under the terms of the GNU General Public License as published by
11558 + * the Free Software Foundation; either version 2 of the License, or
11559 + * (at your option) any later version.
11561 + * This program is distributed in the hope that it will be useful,
11562 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11564 + * GNU General Public License for more details.
11566 + * You should have received a copy of the GNU General Public License
11567 + * along with this program; if not, write to the Free Software
11568 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11572 + * File-based Hierarchy Storage Management
11575 +#include <linux/anon_inodes.h>
11576 +#include <linux/poll.h>
11577 +#include <linux/seq_file.h>
11578 +#include <linux/statfs.h>
11581 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11583 + struct au_sbinfo *sbinfo;
11584 + struct au_fhsm *fhsm;
11586 + SiMustAnyLock(sb);
11588 + sbinfo = au_sbi(sb);
11589 + fhsm = &sbinfo->si_fhsm;
11590 + AuDebugOn(!fhsm);
11591 + return fhsm->fhsm_bottom;
11594 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11596 + struct au_sbinfo *sbinfo;
11597 + struct au_fhsm *fhsm;
11599 + SiMustWriteLock(sb);
11601 + sbinfo = au_sbi(sb);
11602 + fhsm = &sbinfo->si_fhsm;
11603 + AuDebugOn(!fhsm);
11604 + fhsm->fhsm_bottom = bindex;
11607 +/* ---------------------------------------------------------------------- */
11609 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11611 + struct au_br_fhsm *bf;
11613 + bf = br->br_fhsm;
11614 + MtxMustLock(&bf->bf_lock);
11616 + return !bf->bf_readable
11617 + || time_after(jiffies,
11618 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11621 +/* ---------------------------------------------------------------------- */
11623 +static void au_fhsm_notify(struct super_block *sb, int val)
11625 + struct au_sbinfo *sbinfo;
11626 + struct au_fhsm *fhsm;
11628 + SiMustAnyLock(sb);
11630 + sbinfo = au_sbi(sb);
11631 + fhsm = &sbinfo->si_fhsm;
11632 + if (au_fhsm_pid(fhsm)
11633 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11634 + atomic_set(&fhsm->fhsm_readable, val);
11636 + wake_up(&fhsm->fhsm_wqh);
11640 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11641 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11644 + struct au_branch *br;
11645 + struct au_br_fhsm *bf;
11647 + br = au_sbr(sb, bindex);
11648 + AuDebugOn(au_br_rdonly(br));
11649 + bf = br->br_fhsm;
11653 + mutex_lock(&bf->bf_lock);
11655 + MtxMustLock(&bf->bf_lock);
11657 + /* sb->s_root for NFS is unreliable */
11658 + err = au_br_stfs(br, &bf->bf_stfs);
11659 + if (unlikely(err)) {
11660 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11664 + bf->bf_jiffy = jiffies;
11665 + bf->bf_readable = 1;
11667 + au_fhsm_notify(sb, /*val*/1);
11669 + *rstfs = bf->bf_stfs;
11673 + mutex_unlock(&bf->bf_lock);
11674 + au_fhsm_notify(sb, /*val*/1);
11679 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11682 + struct au_sbinfo *sbinfo;
11683 + struct au_fhsm *fhsm;
11684 + struct au_branch *br;
11685 + struct au_br_fhsm *bf;
11687 + AuDbg("b%d, force %d\n", bindex, force);
11688 + SiMustAnyLock(sb);
11690 + sbinfo = au_sbi(sb);
11691 + fhsm = &sbinfo->si_fhsm;
11692 + if (!au_ftest_si(sbinfo, FHSM)
11693 + || fhsm->fhsm_bottom == bindex)
11696 + br = au_sbr(sb, bindex);
11697 + bf = br->br_fhsm;
11699 + mutex_lock(&bf->bf_lock);
11701 + || au_fhsm_pid(fhsm)
11702 + || au_fhsm_test_jiffy(sbinfo, br))
11703 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11705 + mutex_unlock(&bf->bf_lock);
11708 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11710 + aufs_bindex_t bindex, bend;
11711 + struct au_branch *br;
11713 + /* exclude the bottom */
11714 + bend = au_fhsm_bottom(sb);
11715 + for (bindex = 0; bindex < bend; bindex++) {
11716 + br = au_sbr(sb, bindex);
11717 + if (au_br_fhsm(br->br_perm))
11718 + au_fhsm_wrote(sb, bindex, force);
11722 +/* ---------------------------------------------------------------------- */
11724 +static unsigned int au_fhsm_poll(struct file *file,
11725 + struct poll_table_struct *wait)
11727 + unsigned int mask;
11728 + struct au_sbinfo *sbinfo;
11729 + struct au_fhsm *fhsm;
11732 + sbinfo = file->private_data;
11733 + fhsm = &sbinfo->si_fhsm;
11734 + poll_wait(file, &fhsm->fhsm_wqh, wait);
11735 + if (atomic_read(&fhsm->fhsm_readable))
11736 + mask = POLLIN /* | POLLRDNORM */;
11738 + AuTraceErr((int)mask);
11742 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
11743 + struct aufs_stfs *stfs, __s16 brid)
11747 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
11749 + err = __put_user(brid, &stbr->brid);
11750 + if (unlikely(err))
11756 +static ssize_t au_fhsm_do_read(struct super_block *sb,
11757 + struct aufs_stbr __user *stbr, size_t count)
11761 + aufs_bindex_t bindex, bend;
11762 + struct au_branch *br;
11763 + struct au_br_fhsm *bf;
11765 + /* except the bottom branch */
11768 + bend = au_fhsm_bottom(sb);
11769 + for (bindex = 0; !err && bindex < bend; bindex++) {
11770 + br = au_sbr(sb, bindex);
11771 + if (!au_br_fhsm(br->br_perm))
11774 + bf = br->br_fhsm;
11775 + mutex_lock(&bf->bf_lock);
11776 + if (bf->bf_readable) {
11778 + if (count >= sizeof(*stbr))
11779 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
11782 + bf->bf_readable = 0;
11783 + count -= sizeof(*stbr);
11787 + mutex_unlock(&bf->bf_lock);
11790 + err = sizeof(*stbr) * nstbr;
11795 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
11800 + aufs_bindex_t nfhsm, bindex, bend;
11801 + struct au_sbinfo *sbinfo;
11802 + struct au_fhsm *fhsm;
11803 + struct au_branch *br;
11804 + struct super_block *sb;
11807 + sbinfo = file->private_data;
11808 + fhsm = &sbinfo->si_fhsm;
11810 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
11811 + if (!atomic_read(&fhsm->fhsm_readable)) {
11812 + if (vfsub_file_flags(file) & O_NONBLOCK)
11815 + err = wait_event_interruptible_locked_irq
11817 + atomic_read(&fhsm->fhsm_readable));
11819 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
11820 + if (unlikely(err))
11823 + /* sb may already be dead */
11824 + au_rw_read_lock(&sbinfo->si_rwsem);
11825 + readable = atomic_read(&fhsm->fhsm_readable);
11826 + if (readable > 0) {
11827 + sb = sbinfo->si_sb;
11829 + /* exclude the bottom branch */
11831 + bend = au_fhsm_bottom(sb);
11832 + for (bindex = 0; bindex < bend; bindex++) {
11833 + br = au_sbr(sb, bindex);
11834 + if (au_br_fhsm(br->br_perm))
11838 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
11839 + atomic_set(&fhsm->fhsm_readable, 0);
11840 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
11844 + au_rw_read_unlock(&sbinfo->si_rwsem);
11852 +static int au_fhsm_release(struct inode *inode, struct file *file)
11854 + struct au_sbinfo *sbinfo;
11855 + struct au_fhsm *fhsm;
11857 + /* sb may already be dead */
11858 + sbinfo = file->private_data;
11859 + fhsm = &sbinfo->si_fhsm;
11860 + spin_lock(&fhsm->fhsm_spin);
11861 + fhsm->fhsm_pid = 0;
11862 + spin_unlock(&fhsm->fhsm_spin);
11863 + kobject_put(&sbinfo->si_kobj);
11868 +static const struct file_operations au_fhsm_fops = {
11869 + .owner = THIS_MODULE,
11870 + .llseek = noop_llseek,
11871 + .read = au_fhsm_read,
11872 + .poll = au_fhsm_poll,
11873 + .release = au_fhsm_release
11876 +int au_fhsm_fd(struct super_block *sb, int oflags)
11879 + struct au_sbinfo *sbinfo;
11880 + struct au_fhsm *fhsm;
11883 + if (unlikely(!capable(CAP_SYS_ADMIN)))
11887 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
11891 + sbinfo = au_sbi(sb);
11892 + fhsm = &sbinfo->si_fhsm;
11893 + spin_lock(&fhsm->fhsm_spin);
11894 + if (!fhsm->fhsm_pid)
11895 + fhsm->fhsm_pid = current->pid;
11898 + spin_unlock(&fhsm->fhsm_spin);
11899 + if (unlikely(err))
11902 + oflags |= O_RDONLY;
11903 + /* oflags |= FMODE_NONOTIFY; */
11904 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
11906 + if (unlikely(fd < 0))
11909 + /* succeed reglardless 'fhsm' status */
11910 + kobject_get(&sbinfo->si_kobj);
11911 + si_noflush_read_lock(sb);
11912 + if (au_ftest_si(sbinfo, FHSM))
11913 + au_fhsm_wrote_all(sb, /*force*/0);
11914 + si_read_unlock(sb);
11915 + goto out; /* success */
11918 + spin_lock(&fhsm->fhsm_spin);
11919 + fhsm->fhsm_pid = 0;
11920 + spin_unlock(&fhsm->fhsm_spin);
11926 +/* ---------------------------------------------------------------------- */
11928 +int au_fhsm_br_alloc(struct au_branch *br)
11933 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
11935 + au_br_fhsm_init(br->br_fhsm);
11942 +/* ---------------------------------------------------------------------- */
11944 +void au_fhsm_fin(struct super_block *sb)
11946 + au_fhsm_notify(sb, /*val*/-1);
11949 +void au_fhsm_init(struct au_sbinfo *sbinfo)
11951 + struct au_fhsm *fhsm;
11953 + fhsm = &sbinfo->si_fhsm;
11954 + spin_lock_init(&fhsm->fhsm_spin);
11955 + init_waitqueue_head(&fhsm->fhsm_wqh);
11956 + atomic_set(&fhsm->fhsm_readable, 0);
11957 + fhsm->fhsm_expire
11958 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
11959 + fhsm->fhsm_bottom = -1;
11962 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
11964 + sbinfo->si_fhsm.fhsm_expire
11965 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
11968 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
11972 + if (!au_ftest_si(sbinfo, FHSM))
11975 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
11976 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
11977 + seq_printf(seq, ",fhsm_sec=%u", u);
11979 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
11980 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
11981 +++ linux/fs/aufs/file.c 2015-06-28 17:36:09.025073697 +0200
11984 + * Copyright (C) 2005-2015 Junjiro R. Okajima
11986 + * This program, aufs is free software; you can redistribute it and/or modify
11987 + * it under the terms of the GNU General Public License as published by
11988 + * the Free Software Foundation; either version 2 of the License, or
11989 + * (at your option) any later version.
11991 + * This program is distributed in the hope that it will be useful,
11992 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11993 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11994 + * GNU General Public License for more details.
11996 + * You should have received a copy of the GNU General Public License
11997 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12001 + * handling file/dir, and address_space operation
12004 +#ifdef CONFIG_AUFS_DEBUG
12005 +#include <linux/migrate.h>
12007 +#include <linux/pagemap.h>
12010 +/* drop flags for writing */
12011 +unsigned int au_file_roflags(unsigned int flags)
12013 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12014 + flags |= O_RDONLY | O_NOATIME;
12018 +/* common functions to regular file and dir */
12019 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12020 + struct file *file, int force_wr)
12022 + struct file *h_file;
12023 + struct dentry *h_dentry;
12024 + struct inode *h_inode;
12025 + struct super_block *sb;
12026 + struct au_branch *br;
12027 + struct path h_path;
12030 + /* a race condition can happen between open and unlink/rmdir */
12031 + h_file = ERR_PTR(-ENOENT);
12032 + h_dentry = au_h_dptr(dentry, bindex);
12033 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12035 + h_inode = d_inode(h_dentry);
12036 + spin_lock(&h_dentry->d_lock);
12037 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12038 + /* || !d_inode(dentry)->i_nlink */
12040 + spin_unlock(&h_dentry->d_lock);
12041 + if (unlikely(err))
12044 + sb = dentry->d_sb;
12045 + br = au_sbr(sb, bindex);
12046 + err = au_br_test_oflag(flags, br);
12047 + h_file = ERR_PTR(err);
12048 + if (unlikely(err))
12051 + /* drop flags for writing */
12052 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12053 + if (force_wr && !(flags & O_WRONLY))
12055 + flags = au_file_roflags(flags);
12057 + h_file = ERR_PTR(-EROFS);
12058 + flags = au_file_roflags(flags);
12059 + if (unlikely(vfsub_native_ro(h_inode)
12060 + || IS_APPEND(h_inode)))
12062 + flags &= ~O_ACCMODE;
12063 + flags |= O_WRONLY;
12066 + flags &= ~O_CREAT;
12067 + atomic_inc(&br->br_count);
12068 + h_path.dentry = h_dentry;
12069 + h_path.mnt = au_br_mnt(br);
12070 + h_file = vfsub_dentry_open(&h_path, flags);
12071 + if (IS_ERR(h_file))
12074 + if (flags & __FMODE_EXEC) {
12075 + err = deny_write_access(h_file);
12076 + if (unlikely(err)) {
12078 + h_file = ERR_PTR(err);
12082 + fsnotify_open(h_file);
12083 + goto out; /* success */
12086 + atomic_dec(&br->br_count);
12091 +static int au_cmoo(struct dentry *dentry)
12094 + unsigned int udba;
12095 + struct path h_path;
12096 + struct au_pin pin;
12097 + struct au_cp_generic cpg = {
12098 + .dentry = dentry,
12103 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12105 + struct inode *delegated;
12106 + struct super_block *sb;
12107 + struct au_sbinfo *sbinfo;
12108 + struct au_fhsm *fhsm;
12110 + struct au_branch *br;
12111 + struct dentry *parent;
12112 + struct au_hinode *hdir;
12114 + DiMustWriteLock(dentry);
12115 + IiMustWriteLock(d_inode(dentry));
12118 + if (IS_ROOT(dentry))
12120 + cpg.bsrc = au_dbstart(dentry);
12124 + sb = dentry->d_sb;
12125 + sbinfo = au_sbi(sb);
12126 + fhsm = &sbinfo->si_fhsm;
12127 + pid = au_fhsm_pid(fhsm);
12129 + && (current->pid == pid
12130 + || current->real_parent->pid == pid))
12133 + br = au_sbr(sb, cpg.bsrc);
12134 + cmoo = au_br_cmoo(br->br_perm);
12137 + if (!d_is_reg(dentry))
12138 + cmoo &= AuBrAttr_COO_ALL;
12142 + parent = dget_parent(dentry);
12143 + di_write_lock_parent(parent);
12144 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12146 + if (unlikely(err < 0)) {
12147 + err = 0; /* there is no upper writable branch */
12150 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12152 + /* do not respect the coo attrib for the target branch */
12153 + err = au_cpup_dirs(dentry, cpg.bdst);
12154 + if (unlikely(err))
12157 + di_downgrade_lock(parent, AuLock_IR);
12158 + udba = au_opt_udba(sb);
12159 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12160 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12161 + if (unlikely(err))
12164 + err = au_sio_cpup_simple(&cpg);
12166 + if (unlikely(err))
12168 + if (!(cmoo & AuBrWAttr_MOO))
12169 + goto out_parent; /* success */
12171 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12172 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12173 + if (unlikely(err))
12176 + h_path.mnt = au_br_mnt(br);
12177 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12178 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12179 + delegated = NULL;
12180 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12182 + /* todo: keep h_dentry or not? */
12183 + if (unlikely(err == -EWOULDBLOCK)) {
12184 + pr_warn("cannot retry for NFSv4 delegation"
12185 + " for an internal unlink\n");
12188 + if (unlikely(err)) {
12189 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12193 + goto out_parent; /* success */
12196 + di_downgrade_lock(parent, AuLock_IR);
12198 + di_read_unlock(parent, AuLock_IR);
12205 +int au_do_open(struct file *file, struct au_do_open_args *args)
12207 + int err, no_lock = args->no_lock;
12208 + struct dentry *dentry;
12209 + struct au_finfo *finfo;
12212 + err = au_finfo_init(file, args->fidir);
12215 + err = au_finfo_init(file, args->fidir);
12218 + if (unlikely(err))
12221 + dentry = file->f_path.dentry;
12222 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12224 + di_write_lock_child(dentry);
12225 + err = au_cmoo(dentry);
12226 + di_downgrade_lock(dentry, AuLock_IR);
12228 + err = args->open(file, vfsub_file_flags(file), NULL);
12229 + di_read_unlock(dentry, AuLock_IR);
12231 + err = au_cmoo(dentry);
12233 + err = args->open(file, vfsub_file_flags(file),
12235 + if (!err && au_fbstart(file) != au_dbstart(dentry))
12237 + * cmoo happens after h_file was opened.
12238 + * need to refresh file later.
12240 + atomic_dec(&au_fi(file)->fi_generation);
12243 + finfo = au_fi(file);
12245 + finfo->fi_file = file;
12246 + au_sphl_add(&finfo->fi_hlist,
12247 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12250 + fi_write_unlock(file);
12253 + fi_write_unlock(file);
12256 + if (unlikely(err)) {
12257 + finfo->fi_hdir = NULL;
12258 + au_finfo_fin(file);
12265 +int au_reopen_nondir(struct file *file)
12268 + aufs_bindex_t bstart;
12269 + struct dentry *dentry;
12270 + struct file *h_file, *h_file_tmp;
12272 + dentry = file->f_path.dentry;
12273 + bstart = au_dbstart(dentry);
12274 + h_file_tmp = NULL;
12275 + if (au_fbstart(file) == bstart) {
12276 + h_file = au_hf_top(file);
12277 + if (file->f_mode == h_file->f_mode)
12278 + return 0; /* success */
12279 + h_file_tmp = h_file;
12280 + get_file(h_file_tmp);
12281 + au_set_h_fptr(file, bstart, NULL);
12283 + AuDebugOn(au_fi(file)->fi_hdir);
12286 + * file exists on both of rw and ro
12287 + * open --> dbstart and fbstart are both 0
12288 + * prepend a branch as rw, "rw" become ro
12290 + * delete the top branch, "rw" becomes rw again
12291 + * --> dbstart is 1, fbstart is still 0
12292 + * write --> fbstart is 0 but dbstart is 1
12294 + /* AuDebugOn(au_fbstart(file) < bstart); */
12296 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
12297 + file, /*force_wr*/0);
12298 + err = PTR_ERR(h_file);
12299 + if (IS_ERR(h_file)) {
12300 + if (h_file_tmp) {
12301 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
12302 + au_set_h_fptr(file, bstart, h_file_tmp);
12303 + h_file_tmp = NULL;
12305 + goto out; /* todo: close all? */
12309 + au_set_fbstart(file, bstart);
12310 + au_set_h_fptr(file, bstart, h_file);
12311 + au_update_figen(file);
12312 + /* todo: necessary? */
12313 + /* file->f_ra = h_file->f_ra; */
12317 + fput(h_file_tmp);
12321 +/* ---------------------------------------------------------------------- */
12323 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12324 + struct dentry *hi_wh)
12327 + aufs_bindex_t bstart;
12328 + struct au_dinfo *dinfo;
12329 + struct dentry *h_dentry;
12330 + struct au_hdentry *hdp;
12332 + dinfo = au_di(file->f_path.dentry);
12333 + AuRwMustWriteLock(&dinfo->di_rwsem);
12335 + bstart = dinfo->di_bstart;
12336 + dinfo->di_bstart = btgt;
12337 + hdp = dinfo->di_hdentry;
12338 + h_dentry = hdp[0 + btgt].hd_dentry;
12339 + hdp[0 + btgt].hd_dentry = hi_wh;
12340 + err = au_reopen_nondir(file);
12341 + hdp[0 + btgt].hd_dentry = h_dentry;
12342 + dinfo->di_bstart = bstart;
12347 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12348 + aufs_bindex_t bcpup, struct au_pin *pin)
12351 + struct inode *inode, *h_inode;
12352 + struct dentry *h_dentry, *hi_wh;
12353 + struct au_cp_generic cpg = {
12354 + .dentry = file->f_path.dentry,
12361 + au_update_dbstart(cpg.dentry);
12362 + inode = d_inode(cpg.dentry);
12364 + if (au_dbstart(cpg.dentry) <= bcpup
12365 + && au_dbend(cpg.dentry) >= bcpup) {
12366 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12367 + if (h_dentry && d_is_positive(h_dentry))
12368 + h_inode = d_inode(h_dentry);
12370 + hi_wh = au_hi_wh(inode, bcpup);
12371 + if (!hi_wh && !h_inode)
12372 + err = au_sio_cpup_wh(&cpg, file);
12374 + /* already copied-up after unlink */
12375 + err = au_reopen_wh(file, bcpup, hi_wh);
12378 + && (inode->i_nlink > 1
12379 + || (inode->i_state & I_LINKABLE))
12380 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12381 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12387 + * prepare the @file for writing.
12389 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12392 + aufs_bindex_t dbstart;
12393 + struct dentry *parent;
12394 + struct inode *inode;
12395 + struct super_block *sb;
12396 + struct file *h_file;
12397 + struct au_cp_generic cpg = {
12398 + .dentry = file->f_path.dentry,
12403 + .flags = AuCpup_DTIME
12406 + sb = cpg.dentry->d_sb;
12407 + inode = d_inode(cpg.dentry);
12408 + cpg.bsrc = au_fbstart(file);
12409 + err = au_test_ro(sb, cpg.bsrc, inode);
12410 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12411 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12416 + /* need to cpup or reopen */
12417 + parent = dget_parent(cpg.dentry);
12418 + di_write_lock_parent(parent);
12419 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12421 + if (unlikely(err < 0))
12425 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12426 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12427 + if (unlikely(err))
12431 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12432 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12433 + if (unlikely(err))
12436 + dbstart = au_dbstart(cpg.dentry);
12437 + if (dbstart <= cpg.bdst)
12438 + cpg.bsrc = cpg.bdst;
12440 + if (dbstart <= cpg.bdst /* just reopen */
12441 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12443 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12444 + if (IS_ERR(h_file))
12445 + err = PTR_ERR(h_file);
12447 + di_downgrade_lock(parent, AuLock_IR);
12448 + if (dbstart > cpg.bdst)
12449 + err = au_sio_cpup_simple(&cpg);
12451 + err = au_reopen_nondir(file);
12452 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12454 + } else { /* copyup as wh and reopen */
12456 + * since writable hfsplus branch is not supported,
12457 + * h_open_pre/post() are unnecessary.
12459 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12460 + di_downgrade_lock(parent, AuLock_IR);
12464 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12465 + goto out_dput; /* success */
12471 + di_downgrade_lock(parent, AuLock_IR);
12473 + di_read_unlock(parent, AuLock_IR);
12480 +/* ---------------------------------------------------------------------- */
12482 +int au_do_flush(struct file *file, fl_owner_t id,
12483 + int (*flush)(struct file *file, fl_owner_t id))
12486 + struct super_block *sb;
12487 + struct inode *inode;
12489 + inode = file_inode(file);
12490 + sb = inode->i_sb;
12491 + si_noflush_read_lock(sb);
12492 + fi_read_lock(file);
12493 + ii_read_lock_child(inode);
12495 + err = flush(file, id);
12496 + au_cpup_attr_timesizes(inode);
12498 + ii_read_unlock(inode);
12499 + fi_read_unlock(file);
12500 + si_read_unlock(sb);
12504 +/* ---------------------------------------------------------------------- */
12506 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12509 + struct au_pin pin;
12510 + struct au_finfo *finfo;
12511 + struct dentry *parent, *hi_wh;
12512 + struct inode *inode;
12513 + struct super_block *sb;
12514 + struct au_cp_generic cpg = {
12515 + .dentry = file->f_path.dentry,
12520 + .flags = AuCpup_DTIME
12523 + FiMustWriteLock(file);
12526 + finfo = au_fi(file);
12527 + sb = cpg.dentry->d_sb;
12528 + inode = d_inode(cpg.dentry);
12529 + cpg.bdst = au_ibstart(inode);
12530 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12533 + parent = dget_parent(cpg.dentry);
12534 + if (au_test_ro(sb, cpg.bdst, inode)) {
12535 + di_read_lock_parent(parent, !AuLock_IR);
12536 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12538 + di_read_unlock(parent, !AuLock_IR);
12539 + if (unlikely(err < 0))
12544 + di_read_lock_parent(parent, AuLock_IR);
12545 + hi_wh = au_hi_wh(inode, cpg.bdst);
12546 + if (!S_ISDIR(inode->i_mode)
12547 + && au_opt_test(au_mntflags(sb), PLINK)
12548 + && au_plink_test(inode)
12549 + && !d_unhashed(cpg.dentry)
12550 + && cpg.bdst < au_dbstart(cpg.dentry)) {
12551 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12552 + if (unlikely(err))
12555 + /* always superio. */
12556 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12557 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12559 + err = au_sio_cpup_simple(&cpg);
12562 + } else if (hi_wh) {
12563 + /* already copied-up after unlink */
12564 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12565 + *need_reopen = 0;
12569 + di_read_unlock(parent, AuLock_IR);
12576 +static void au_do_refresh_dir(struct file *file)
12578 + aufs_bindex_t bindex, bend, new_bindex, brid;
12579 + struct au_hfile *p, tmp, *q;
12580 + struct au_finfo *finfo;
12581 + struct super_block *sb;
12582 + struct au_fidir *fidir;
12584 + FiMustWriteLock(file);
12586 + sb = file->f_path.dentry->d_sb;
12587 + finfo = au_fi(file);
12588 + fidir = finfo->fi_hdir;
12589 + AuDebugOn(!fidir);
12590 + p = fidir->fd_hfile + finfo->fi_btop;
12591 + brid = p->hf_br->br_id;
12592 + bend = fidir->fd_bbot;
12593 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
12597 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12598 + if (new_bindex == bindex)
12600 + if (new_bindex < 0) {
12601 + au_set_h_fptr(file, bindex, NULL);
12605 + /* swap two lower inode, and loop again */
12606 + q = fidir->fd_hfile + new_bindex;
12610 + if (tmp.hf_file) {
12616 + p = fidir->fd_hfile;
12617 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12618 + bend = au_sbend(sb);
12619 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
12620 + finfo->fi_btop++, p++)
12621 + if (p->hf_file) {
12622 + if (file_inode(p->hf_file))
12624 + au_hfput(p, file);
12627 + bend = au_br_index(sb, brid);
12628 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
12629 + finfo->fi_btop++, p++)
12631 + au_hfput(p, file);
12632 + bend = au_sbend(sb);
12635 + p = fidir->fd_hfile + bend;
12636 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
12637 + fidir->fd_bbot--, p--)
12638 + if (p->hf_file) {
12639 + if (file_inode(p->hf_file))
12641 + au_hfput(p, file);
12643 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12647 + * after branch manipulating, refresh the file.
12649 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12651 + int err, need_reopen;
12652 + aufs_bindex_t bend, bindex;
12653 + struct dentry *dentry;
12654 + struct au_finfo *finfo;
12655 + struct au_hfile *hfile;
12657 + dentry = file->f_path.dentry;
12658 + finfo = au_fi(file);
12659 + if (!finfo->fi_hdir) {
12660 + hfile = &finfo->fi_htop;
12661 + AuDebugOn(!hfile->hf_file);
12662 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
12663 + AuDebugOn(bindex < 0);
12664 + if (bindex != finfo->fi_btop)
12665 + au_set_fbstart(file, bindex);
12667 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
12668 + if (unlikely(err))
12670 + au_do_refresh_dir(file);
12675 + if (!au_test_mmapped(file))
12676 + err = au_file_refresh_by_inode(file, &need_reopen);
12677 + if (!err && need_reopen && !d_unlinked(dentry))
12678 + err = reopen(file);
12680 + au_update_figen(file);
12681 + goto out; /* success */
12684 + /* error, close all lower files */
12685 + if (finfo->fi_hdir) {
12686 + bend = au_fbend_dir(file);
12687 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
12688 + au_set_h_fptr(file, bindex, NULL);
12695 +/* common function to regular file and dir */
12696 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12700 + unsigned int sigen, figen;
12701 + aufs_bindex_t bstart;
12702 + unsigned char pseudo_link;
12703 + struct dentry *dentry;
12704 + struct inode *inode;
12707 + dentry = file->f_path.dentry;
12708 + inode = d_inode(dentry);
12709 + sigen = au_sigen(dentry->d_sb);
12710 + fi_write_lock(file);
12711 + figen = au_figen(file);
12712 + di_write_lock_child(dentry);
12713 + bstart = au_dbstart(dentry);
12714 + pseudo_link = (bstart != au_ibstart(inode));
12715 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
12717 + di_downgrade_lock(dentry, AuLock_IR);
12718 + fi_downgrade_lock(file);
12720 + goto out; /* success */
12723 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12724 + if (au_digen_test(dentry, sigen)) {
12725 + err = au_reval_dpath(dentry, sigen);
12726 + AuDebugOn(!err && au_digen_test(dentry, sigen));
12730 + err = refresh_file(file, reopen);
12733 + di_downgrade_lock(dentry, AuLock_IR);
12734 + fi_downgrade_lock(file);
12737 + di_write_unlock(dentry);
12738 + fi_write_unlock(file);
12745 +/* ---------------------------------------------------------------------- */
12747 +/* cf. aufs_nopage() */
12748 +/* for madvise(2) */
12749 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
12751 + unlock_page(page);
12755 +/* it will never be called, but necessary to support O_DIRECT */
12756 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
12758 +{ BUG(); return 0; }
12760 +/* they will never be called. */
12761 +#ifdef CONFIG_AUFS_DEBUG
12762 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
12763 + loff_t pos, unsigned len, unsigned flags,
12764 + struct page **pagep, void **fsdata)
12765 +{ AuUnsupport(); return 0; }
12766 +static int aufs_write_end(struct file *file, struct address_space *mapping,
12767 + loff_t pos, unsigned len, unsigned copied,
12768 + struct page *page, void *fsdata)
12769 +{ AuUnsupport(); return 0; }
12770 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
12771 +{ AuUnsupport(); return 0; }
12773 +static int aufs_set_page_dirty(struct page *page)
12774 +{ AuUnsupport(); return 0; }
12775 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
12776 + unsigned int length)
12777 +{ AuUnsupport(); }
12778 +static int aufs_releasepage(struct page *page, gfp_t gfp)
12779 +{ AuUnsupport(); return 0; }
12780 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
12781 + struct page *page, enum migrate_mode mode)
12782 +{ AuUnsupport(); return 0; }
12783 +static int aufs_launder_page(struct page *page)
12784 +{ AuUnsupport(); return 0; }
12785 +static int aufs_is_partially_uptodate(struct page *page,
12786 + unsigned long from,
12787 + unsigned long count)
12788 +{ AuUnsupport(); return 0; }
12789 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
12791 +{ AuUnsupport(); }
12792 +static int aufs_error_remove_page(struct address_space *mapping,
12793 + struct page *page)
12794 +{ AuUnsupport(); return 0; }
12795 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
12797 +{ AuUnsupport(); return 0; }
12798 +static void aufs_swap_deactivate(struct file *file)
12799 +{ AuUnsupport(); }
12800 +#endif /* CONFIG_AUFS_DEBUG */
12802 +const struct address_space_operations aufs_aop = {
12803 + .readpage = aufs_readpage,
12804 + .direct_IO = aufs_direct_IO,
12805 +#ifdef CONFIG_AUFS_DEBUG
12806 + .writepage = aufs_writepage,
12807 + /* no writepages, because of writepage */
12808 + .set_page_dirty = aufs_set_page_dirty,
12809 + /* no readpages, because of readpage */
12810 + .write_begin = aufs_write_begin,
12811 + .write_end = aufs_write_end,
12812 + /* no bmap, no block device */
12813 + .invalidatepage = aufs_invalidatepage,
12814 + .releasepage = aufs_releasepage,
12815 + .migratepage = aufs_migratepage,
12816 + .launder_page = aufs_launder_page,
12817 + .is_partially_uptodate = aufs_is_partially_uptodate,
12818 + .is_dirty_writeback = aufs_is_dirty_writeback,
12819 + .error_remove_page = aufs_error_remove_page,
12820 + .swap_activate = aufs_swap_activate,
12821 + .swap_deactivate = aufs_swap_deactivate
12822 +#endif /* CONFIG_AUFS_DEBUG */
12824 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
12825 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
12826 +++ linux/fs/aufs/file.h 2015-06-28 17:35:44.348050491 +0200
12829 + * Copyright (C) 2005-2015 Junjiro R. Okajima
12831 + * This program, aufs is free software; you can redistribute it and/or modify
12832 + * it under the terms of the GNU General Public License as published by
12833 + * the Free Software Foundation; either version 2 of the License, or
12834 + * (at your option) any later version.
12836 + * This program is distributed in the hope that it will be useful,
12837 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12838 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12839 + * GNU General Public License for more details.
12841 + * You should have received a copy of the GNU General Public License
12842 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12846 + * file operations
12849 +#ifndef __AUFS_FILE_H__
12850 +#define __AUFS_FILE_H__
12854 +#include <linux/file.h>
12855 +#include <linux/fs.h>
12856 +#include <linux/poll.h>
12857 +#include "rwsem.h"
12861 + struct file *hf_file;
12862 + struct au_branch *hf_br;
12867 + aufs_bindex_t fd_bbot;
12868 + aufs_bindex_t fd_nent;
12869 + struct au_vdir *fd_vdir_cache;
12870 + struct au_hfile fd_hfile[];
12873 +static inline int au_fidir_sz(int nent)
12875 + AuDebugOn(nent < 0);
12876 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
12880 + atomic_t fi_generation;
12882 + struct au_rwsem fi_rwsem;
12883 + aufs_bindex_t fi_btop;
12885 + /* do not union them */
12886 + struct { /* for non-dir */
12887 + struct au_hfile fi_htop;
12888 + atomic_t fi_mmapped;
12890 + struct au_fidir *fi_hdir; /* for dir only */
12892 + struct hlist_node fi_hlist;
12893 + struct file *fi_file; /* very ugly */
12894 +} ____cacheline_aligned_in_smp;
12896 +/* ---------------------------------------------------------------------- */
12899 +extern const struct address_space_operations aufs_aop;
12900 +unsigned int au_file_roflags(unsigned int flags);
12901 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12902 + struct file *file, int force_wr);
12903 +struct au_do_open_args {
12905 + int (*open)(struct file *file, int flags,
12906 + struct file *h_file);
12907 + struct au_fidir *fidir;
12908 + struct file *h_file;
12910 +int au_do_open(struct file *file, struct au_do_open_args *args);
12911 +int au_reopen_nondir(struct file *file);
12913 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
12914 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12916 +int au_do_flush(struct file *file, fl_owner_t id,
12917 + int (*flush)(struct file *file, fl_owner_t id));
12920 +#ifdef CONFIG_AUFS_POLL
12921 +unsigned int aufs_poll(struct file *file, poll_table *wait);
12924 +#ifdef CONFIG_AUFS_BR_HFSPLUS
12926 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
12928 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
12929 + struct file *h_file);
12931 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
12932 + aufs_bindex_t bindex, int force_wr)
12933 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
12934 + struct file *h_file);
12938 +extern const struct file_operations aufs_file_fop;
12939 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
12940 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
12941 +struct file *au_read_pre(struct file *file, int keep_fi);
12944 +void au_hfput(struct au_hfile *hf, struct file *file);
12945 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
12946 + struct file *h_file);
12948 +void au_update_figen(struct file *file);
12949 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
12950 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
12952 +void au_fi_init_once(void *_fi);
12953 +void au_finfo_fin(struct file *file);
12954 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
12957 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
12958 +#ifdef CONFIG_COMPAT
12959 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
12960 + unsigned long arg);
12961 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
12962 + unsigned long arg);
12965 +/* ---------------------------------------------------------------------- */
12967 +static inline struct au_finfo *au_fi(struct file *file)
12969 + return file->private_data;
12972 +/* ---------------------------------------------------------------------- */
12975 + * fi_read_lock, fi_write_lock,
12976 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
12978 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
12980 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
12981 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
12982 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
12984 +/* ---------------------------------------------------------------------- */
12986 +/* todo: hard/soft set? */
12987 +static inline aufs_bindex_t au_fbstart(struct file *file)
12989 + FiMustAnyLock(file);
12990 + return au_fi(file)->fi_btop;
12993 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
12995 + FiMustAnyLock(file);
12996 + AuDebugOn(!au_fi(file)->fi_hdir);
12997 + return au_fi(file)->fi_hdir->fd_bbot;
13000 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13002 + FiMustAnyLock(file);
13003 + AuDebugOn(!au_fi(file)->fi_hdir);
13004 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13007 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
13009 + FiMustWriteLock(file);
13010 + au_fi(file)->fi_btop = bindex;
13013 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
13015 + FiMustWriteLock(file);
13016 + AuDebugOn(!au_fi(file)->fi_hdir);
13017 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13020 +static inline void au_set_fvdir_cache(struct file *file,
13021 + struct au_vdir *vdir_cache)
13023 + FiMustWriteLock(file);
13024 + AuDebugOn(!au_fi(file)->fi_hdir);
13025 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13028 +static inline struct file *au_hf_top(struct file *file)
13030 + FiMustAnyLock(file);
13031 + AuDebugOn(au_fi(file)->fi_hdir);
13032 + return au_fi(file)->fi_htop.hf_file;
13035 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13037 + FiMustAnyLock(file);
13038 + AuDebugOn(!au_fi(file)->fi_hdir);
13039 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13042 +/* todo: memory barrier? */
13043 +static inline unsigned int au_figen(struct file *f)
13045 + return atomic_read(&au_fi(f)->fi_generation);
13048 +static inline void au_set_mmapped(struct file *f)
13050 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13052 + pr_warn("fi_mmapped wrapped around\n");
13053 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13057 +static inline void au_unset_mmapped(struct file *f)
13059 + atomic_dec(&au_fi(f)->fi_mmapped);
13062 +static inline int au_test_mmapped(struct file *f)
13064 + return atomic_read(&au_fi(f)->fi_mmapped);
13067 +/* customize vma->vm_file */
13069 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13070 + struct file *file)
13074 + f = vma->vm_file;
13076 + vma->vm_file = file;
13081 +#define AuDbgVmRegion(file, vma) do {} while (0)
13083 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13084 + struct file *file)
13086 + au_do_vm_file_reset(vma, file);
13089 +#define AuDbgVmRegion(file, vma) \
13090 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13092 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13093 + struct file *file)
13097 + au_do_vm_file_reset(vma, file);
13098 + f = vma->vm_region->vm_file;
13100 + vma->vm_region->vm_file = file;
13103 +#endif /* CONFIG_MMU */
13105 +/* handle vma->vm_prfile */
13106 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13107 + struct file *file)
13110 + vma->vm_prfile = file;
13111 +#ifndef CONFIG_MMU
13113 + vma->vm_region->vm_prfile = file;
13117 +#endif /* __KERNEL__ */
13118 +#endif /* __AUFS_FILE_H__ */
13119 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13120 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13121 +++ linux/fs/aufs/finfo.c 2015-06-28 17:35:44.348050491 +0200
13124 + * Copyright (C) 2005-2015 Junjiro R. Okajima
13126 + * This program, aufs is free software; you can redistribute it and/or modify
13127 + * it under the terms of the GNU General Public License as published by
13128 + * the Free Software Foundation; either version 2 of the License, or
13129 + * (at your option) any later version.
13131 + * This program is distributed in the hope that it will be useful,
13132 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13133 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13134 + * GNU General Public License for more details.
13136 + * You should have received a copy of the GNU General Public License
13137 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13141 + * file private data
13146 +void au_hfput(struct au_hfile *hf, struct file *file)
13148 + /* todo: direct access f_flags */
13149 + if (vfsub_file_flags(file) & __FMODE_EXEC)
13150 + allow_write_access(hf->hf_file);
13151 + fput(hf->hf_file);
13152 + hf->hf_file = NULL;
13153 + atomic_dec(&hf->hf_br->br_count);
13154 + hf->hf_br = NULL;
13157 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13159 + struct au_finfo *finfo = au_fi(file);
13160 + struct au_hfile *hf;
13161 + struct au_fidir *fidir;
13163 + fidir = finfo->fi_hdir;
13165 + AuDebugOn(finfo->fi_btop != bindex);
13166 + hf = &finfo->fi_htop;
13168 + hf = fidir->fd_hfile + bindex;
13170 + if (hf && hf->hf_file)
13171 + au_hfput(hf, file);
13173 + FiMustWriteLock(file);
13174 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13175 + hf->hf_file = val;
13176 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13180 +void au_update_figen(struct file *file)
13182 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13183 + /* smp_mb(); */ /* atomic_set */
13186 +/* ---------------------------------------------------------------------- */
13188 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13190 + struct au_fidir *fidir;
13193 + nbr = au_sbend(sb) + 1;
13195 + nbr = 2; /* initial allocate for 2 branches */
13196 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13198 + fidir->fd_bbot = -1;
13199 + fidir->fd_nent = nbr;
13200 + fidir->fd_vdir_cache = NULL;
13206 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
13209 + struct au_fidir *fidir, *p;
13211 + AuRwMustWriteLock(&finfo->fi_rwsem);
13212 + fidir = finfo->fi_hdir;
13213 + AuDebugOn(!fidir);
13216 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13219 + p->fd_nent = nbr;
13220 + finfo->fi_hdir = p;
13227 +/* ---------------------------------------------------------------------- */
13229 +void au_finfo_fin(struct file *file)
13231 + struct au_finfo *finfo;
13233 + au_nfiles_dec(file->f_path.dentry->d_sb);
13235 + finfo = au_fi(file);
13236 + AuDebugOn(finfo->fi_hdir);
13237 + AuRwDestroy(&finfo->fi_rwsem);
13238 + au_cache_free_finfo(finfo);
13241 +void au_fi_init_once(void *_finfo)
13243 + struct au_finfo *finfo = _finfo;
13244 + static struct lock_class_key aufs_fi;
13246 + au_rw_init(&finfo->fi_rwsem);
13247 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
13250 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13253 + struct au_finfo *finfo;
13254 + struct dentry *dentry;
13257 + dentry = file->f_path.dentry;
13258 + finfo = au_cache_alloc_finfo();
13259 + if (unlikely(!finfo))
13263 + au_nfiles_inc(dentry->d_sb);
13264 + /* verbose coding for lock class name */
13266 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
13268 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
13269 + au_rw_write_lock(&finfo->fi_rwsem);
13270 + finfo->fi_btop = -1;
13271 + finfo->fi_hdir = fidir;
13272 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13273 + /* smp_mb(); */ /* atomic_set */
13275 + file->private_data = finfo;
13280 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13281 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13282 +++ linux/fs/aufs/f_op.c 2015-06-28 17:36:09.025073697 +0200
13285 + * Copyright (C) 2005-2015 Junjiro R. Okajima
13287 + * This program, aufs is free software; you can redistribute it and/or modify
13288 + * it under the terms of the GNU General Public License as published by
13289 + * the Free Software Foundation; either version 2 of the License, or
13290 + * (at your option) any later version.
13292 + * This program is distributed in the hope that it will be useful,
13293 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13294 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13295 + * GNU General Public License for more details.
13297 + * You should have received a copy of the GNU General Public License
13298 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13302 + * file and vm operations
13305 +#include <linux/aio.h>
13306 +#include <linux/fs_stack.h>
13307 +#include <linux/mman.h>
13308 +#include <linux/security.h>
13311 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13314 + aufs_bindex_t bindex;
13315 + struct dentry *dentry;
13316 + struct au_finfo *finfo;
13317 + struct inode *h_inode;
13319 + FiMustWriteLock(file);
13322 + dentry = file->f_path.dentry;
13323 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13324 + finfo = au_fi(file);
13325 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13326 + atomic_set(&finfo->fi_mmapped, 0);
13327 + bindex = au_dbstart(dentry);
13329 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13331 + get_file(h_file);
13332 + if (IS_ERR(h_file))
13333 + err = PTR_ERR(h_file);
13335 + if ((flags & __O_TMPFILE)
13336 + && !(flags & O_EXCL)) {
13337 + h_inode = file_inode(h_file);
13338 + spin_lock(&h_inode->i_lock);
13339 + h_inode->i_state |= I_LINKABLE;
13340 + spin_unlock(&h_inode->i_lock);
13342 + au_set_fbstart(file, bindex);
13343 + au_set_h_fptr(file, bindex, h_file);
13344 + au_update_figen(file);
13345 + /* todo: necessary? */
13346 + /* file->f_ra = h_file->f_ra; */
13352 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13353 + struct file *file)
13356 + struct super_block *sb;
13357 + struct au_do_open_args args = {
13358 + .open = au_do_open_nondir
13361 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13362 + file, vfsub_file_flags(file), file->f_mode);
13364 + sb = file->f_path.dentry->d_sb;
13365 + si_read_lock(sb, AuLock_FLUSH);
13366 + err = au_do_open(file, &args);
13367 + si_read_unlock(sb);
13371 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13373 + struct au_finfo *finfo;
13374 + aufs_bindex_t bindex;
13376 + finfo = au_fi(file);
13377 + au_sphl_del(&finfo->fi_hlist,
13378 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13379 + bindex = finfo->fi_btop;
13381 + au_set_h_fptr(file, bindex, NULL);
13383 + au_finfo_fin(file);
13387 +/* ---------------------------------------------------------------------- */
13389 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13392 + struct file *h_file;
13395 + h_file = au_hf_top(file);
13397 + err = vfsub_flush(h_file, id);
13401 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13403 + return au_do_flush(file, id, au_do_flush_nondir);
13406 +/* ---------------------------------------------------------------------- */
13408 + * read and write functions acquire [fdi]_rwsem once, but release before
13409 + * mmap_sem. This is because to stop a race condition between mmap(2).
13410 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13411 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13412 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13415 +/* Callers should call au_read_post() or fput() in the end */
13416 +struct file *au_read_pre(struct file *file, int keep_fi)
13418 + struct file *h_file;
13421 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13423 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13424 + h_file = au_hf_top(file);
13425 + get_file(h_file);
13427 + fi_read_unlock(file);
13429 + h_file = ERR_PTR(err);
13434 +static void au_read_post(struct inode *inode, struct file *h_file)
13436 + /* update without lock, I don't think it a problem */
13437 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13441 +struct au_write_pre {
13443 + aufs_bindex_t bstart;
13447 + * return with iinfo is write-locked
13448 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13451 +static struct file *au_write_pre(struct file *file, int do_ready,
13452 + struct au_write_pre *wpre)
13454 + struct file *h_file;
13455 + struct dentry *dentry;
13457 + struct au_pin pin;
13459 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13460 + h_file = ERR_PTR(err);
13461 + if (unlikely(err))
13464 + dentry = file->f_path.dentry;
13466 + err = au_ready_to_write(file, -1, &pin);
13467 + if (unlikely(err)) {
13468 + h_file = ERR_PTR(err);
13469 + di_write_unlock(dentry);
13474 + di_downgrade_lock(dentry, /*flags*/0);
13476 + wpre->bstart = au_fbstart(file);
13477 + h_file = au_hf_top(file);
13478 + get_file(h_file);
13480 + wpre->blks = file_inode(h_file)->i_blocks;
13483 + di_read_unlock(dentry, /*flags*/0);
13486 + fi_write_unlock(file);
13491 +static void au_write_post(struct inode *inode, struct file *h_file,
13492 + struct au_write_pre *wpre, ssize_t written)
13494 + struct inode *h_inode;
13496 + au_cpup_attr_timesizes(inode);
13497 + AuDebugOn(au_ibstart(inode) != wpre->bstart);
13498 + h_inode = file_inode(h_file);
13499 + inode->i_mode = h_inode->i_mode;
13500 + ii_write_unlock(inode);
13503 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13505 + au_fhsm_wrote(inode->i_sb, wpre->bstart,
13506 + /*force*/h_inode->i_blocks > wpre->blks);
13509 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13513 + struct inode *inode;
13514 + struct file *h_file;
13515 + struct super_block *sb;
13517 + inode = file_inode(file);
13518 + sb = inode->i_sb;
13519 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13521 + h_file = au_read_pre(file, /*keep_fi*/0);
13522 + err = PTR_ERR(h_file);
13523 + if (IS_ERR(h_file))
13526 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13527 + err = vfsub_read_u(h_file, buf, count, ppos);
13528 + /* todo: necessary? */
13529 + /* file->f_ra = h_file->f_ra; */
13530 + au_read_post(inode, h_file);
13533 + si_read_unlock(sb);
13538 + * todo: very ugly
13539 + * it locks both of i_mutex and si_rwsem for read in safe.
13540 + * if the plink maintenance mode continues forever (that is the problem),
13541 + * may loop forever.
13543 +static void au_mtx_and_read_lock(struct inode *inode)
13546 + struct super_block *sb = inode->i_sb;
13549 + mutex_lock(&inode->i_mutex);
13550 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13553 + mutex_unlock(&inode->i_mutex);
13554 + si_read_lock(sb, AuLock_NOPLMW);
13555 + si_read_unlock(sb);
13559 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13560 + size_t count, loff_t *ppos)
13563 + struct au_write_pre wpre;
13564 + struct inode *inode;
13565 + struct file *h_file;
13566 + char __user *buf = (char __user *)ubuf;
13568 + inode = file_inode(file);
13569 + au_mtx_and_read_lock(inode);
13571 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13572 + err = PTR_ERR(h_file);
13573 + if (IS_ERR(h_file))
13576 + err = vfsub_write_u(h_file, buf, count, ppos);
13577 + au_write_post(inode, h_file, &wpre, err);
13580 + si_read_unlock(inode->i_sb);
13581 + mutex_unlock(&inode->i_mutex);
13585 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13586 + struct iov_iter *iov_iter)
13589 + struct file *file;
13590 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13592 + err = security_file_permission(h_file, rw);
13593 + if (unlikely(err))
13598 + if (rw == MAY_READ)
13599 + iter = h_file->f_op->read_iter;
13600 + else if (rw == MAY_WRITE)
13601 + iter = h_file->f_op->write_iter;
13603 + file = kio->ki_filp;
13604 + kio->ki_filp = h_file;
13607 + err = iter(kio, iov_iter);
13610 + /* currently there is no such fs */
13612 + kio->ki_filp = file;
13618 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13621 + struct file *file, *h_file;
13622 + struct inode *inode;
13623 + struct super_block *sb;
13625 + file = kio->ki_filp;
13626 + inode = file_inode(file);
13627 + sb = inode->i_sb;
13628 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13630 + h_file = au_read_pre(file, /*keep_fi*/0);
13631 + err = PTR_ERR(h_file);
13632 + if (IS_ERR(h_file))
13635 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13636 + /* todo: necessary? */
13637 + /* file->f_ra = h_file->f_ra; */
13638 + au_read_post(inode, h_file);
13641 + si_read_unlock(sb);
13645 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13648 + struct au_write_pre wpre;
13649 + struct inode *inode;
13650 + struct file *file, *h_file;
13652 + file = kio->ki_filp;
13653 + inode = file_inode(file);
13654 + au_mtx_and_read_lock(inode);
13656 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13657 + err = PTR_ERR(h_file);
13658 + if (IS_ERR(h_file))
13661 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13662 + au_write_post(inode, h_file, &wpre, err);
13665 + si_read_unlock(inode->i_sb);
13666 + mutex_unlock(&inode->i_mutex);
13670 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13671 + struct pipe_inode_info *pipe, size_t len,
13672 + unsigned int flags)
13675 + struct file *h_file;
13676 + struct inode *inode;
13677 + struct super_block *sb;
13679 + inode = file_inode(file);
13680 + sb = inode->i_sb;
13681 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13683 + h_file = au_read_pre(file, /*keep_fi*/1);
13684 + err = PTR_ERR(h_file);
13685 + if (IS_ERR(h_file))
13688 + if (au_test_loopback_kthread()) {
13689 + au_warn_loopback(h_file->f_path.dentry->d_sb);
13690 + if (file->f_mapping != h_file->f_mapping) {
13691 + file->f_mapping = h_file->f_mapping;
13692 + smp_mb(); /* unnecessary? */
13695 + fi_read_unlock(file);
13697 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13698 + /* todo: necessasry? */
13699 + /* file->f_ra = h_file->f_ra; */
13700 + au_read_post(inode, h_file);
13703 + si_read_unlock(sb);
13708 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
13709 + size_t len, unsigned int flags)
13712 + struct au_write_pre wpre;
13713 + struct inode *inode;
13714 + struct file *h_file;
13716 + inode = file_inode(file);
13717 + au_mtx_and_read_lock(inode);
13719 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13720 + err = PTR_ERR(h_file);
13721 + if (IS_ERR(h_file))
13724 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
13725 + au_write_post(inode, h_file, &wpre, err);
13728 + si_read_unlock(inode->i_sb);
13729 + mutex_unlock(&inode->i_mutex);
13733 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
13737 + struct au_write_pre wpre;
13738 + struct inode *inode;
13739 + struct file *h_file;
13741 + inode = file_inode(file);
13742 + au_mtx_and_read_lock(inode);
13744 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13745 + err = PTR_ERR(h_file);
13746 + if (IS_ERR(h_file))
13750 + err = vfs_fallocate(h_file, mode, offset, len);
13752 + au_write_post(inode, h_file, &wpre, /*written*/1);
13755 + si_read_unlock(inode->i_sb);
13756 + mutex_unlock(&inode->i_mutex);
13760 +/* ---------------------------------------------------------------------- */
13763 + * The locking order around current->mmap_sem.
13764 + * - in most and regular cases
13765 + * file I/O syscall -- aufs_read() or something
13766 + * -- si_rwsem for read -- mmap_sem
13767 + * (Note that [fdi]i_rwsem are released before mmap_sem).
13769 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
13770 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
13771 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
13772 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
13773 + * It means that when aufs acquires si_rwsem for write, the process should never
13774 + * acquire mmap_sem.
13776 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
13777 + * problem either since any directory is not able to be mmap-ed.
13778 + * The similar scenario is applied to aufs_readlink() too.
13781 +#if 0 /* stop calling security_file_mmap() */
13782 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
13783 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
13785 +static unsigned long au_arch_prot_conv(unsigned long flags)
13787 + /* currently ppc64 only */
13788 +#ifdef CONFIG_PPC64
13789 + /* cf. linux/arch/powerpc/include/asm/mman.h */
13790 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
13791 + return AuConv_VM_PROT(flags, SAO);
13793 + AuDebugOn(arch_calc_vm_prot_bits(-1));
13798 +static unsigned long au_prot_conv(unsigned long flags)
13800 + return AuConv_VM_PROT(flags, READ)
13801 + | AuConv_VM_PROT(flags, WRITE)
13802 + | AuConv_VM_PROT(flags, EXEC)
13803 + | au_arch_prot_conv(flags);
13806 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
13807 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
13809 +static unsigned long au_flag_conv(unsigned long flags)
13811 + return AuConv_VM_MAP(flags, GROWSDOWN)
13812 + | AuConv_VM_MAP(flags, DENYWRITE)
13813 + | AuConv_VM_MAP(flags, LOCKED);
13817 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
13820 + const unsigned char wlock
13821 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
13822 + struct super_block *sb;
13823 + struct file *h_file;
13824 + struct inode *inode;
13826 + AuDbgVmRegion(file, vma);
13828 + inode = file_inode(file);
13829 + sb = inode->i_sb;
13831 + si_read_lock(sb, AuLock_NOPLMW);
13833 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
13835 + err = PTR_ERR(h_file);
13836 + if (IS_ERR(h_file))
13840 + au_set_mmapped(file);
13841 + au_vm_file_reset(vma, h_file);
13843 + * we cannot call security_mmap_file() here since it may acquire
13844 + * mmap_sem or i_mutex.
13846 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
13847 + * au_flag_conv(vma->vm_flags));
13850 + err = h_file->f_op->mmap(h_file, vma);
13852 + au_vm_prfile_set(vma, file);
13853 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13854 + goto out_fput; /* success */
13856 + au_unset_mmapped(file);
13857 + au_vm_file_reset(vma, file);
13861 + ii_write_unlock(inode);
13866 + si_read_unlock(sb);
13872 +/* ---------------------------------------------------------------------- */
13874 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
13878 + struct au_write_pre wpre;
13879 + struct inode *inode;
13880 + struct file *h_file;
13882 + err = 0; /* -EBADF; */ /* posix? */
13883 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13886 + inode = file_inode(file);
13887 + au_mtx_and_read_lock(inode);
13889 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13890 + err = PTR_ERR(h_file);
13891 + if (IS_ERR(h_file))
13894 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
13895 + au_write_post(inode, h_file, &wpre, /*written*/0);
13898 + si_read_unlock(inode->i_sb);
13899 + mutex_unlock(&inode->i_mutex);
13904 +/* no one supports this operation, currently */
13906 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
13909 + struct au_write_pre wpre;
13910 + struct inode *inode;
13911 + struct file *file, *h_file;
13913 + err = 0; /* -EBADF; */ /* posix? */
13914 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13917 + file = kio->ki_filp;
13918 + inode = file_inode(file);
13919 + au_mtx_and_read_lock(inode);
13921 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13922 + err = PTR_ERR(h_file);
13923 + if (IS_ERR(h_file))
13927 + h_file = au_hf_top(file);
13928 + if (h_file->f_op->aio_fsync) {
13929 + struct mutex *h_mtx;
13931 + h_mtx = &file_inode(h_file)->i_mutex;
13932 + if (!is_sync_kiocb(kio)) {
13933 + get_file(h_file);
13936 + kio->ki_filp = h_file;
13937 + err = h_file->f_op->aio_fsync(kio, datasync);
13938 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13940 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
13942 + mutex_unlock(h_mtx);
13944 + au_write_post(inode, h_file, &wpre, /*written*/0);
13947 + si_read_unlock(inode->sb);
13948 + mutex_unlock(&inode->i_mutex);
13954 +static int aufs_fasync(int fd, struct file *file, int flag)
13957 + struct file *h_file;
13958 + struct super_block *sb;
13960 + sb = file->f_path.dentry->d_sb;
13961 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13963 + h_file = au_read_pre(file, /*keep_fi*/0);
13964 + err = PTR_ERR(h_file);
13965 + if (IS_ERR(h_file))
13968 + if (h_file->f_op->fasync)
13969 + err = h_file->f_op->fasync(fd, h_file, flag);
13970 + fput(h_file); /* instead of au_read_post() */
13973 + si_read_unlock(sb);
13977 +/* ---------------------------------------------------------------------- */
13979 +/* no one supports this operation, currently */
13981 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
13982 + size_t len, loff_t *pos, int more)
13987 +/* ---------------------------------------------------------------------- */
13989 +const struct file_operations aufs_file_fop = {
13990 + .owner = THIS_MODULE,
13992 + .llseek = default_llseek,
13994 + .read = aufs_read,
13995 + .write = aufs_write,
13996 + .read_iter = aufs_read_iter,
13997 + .write_iter = aufs_write_iter,
13999 +#ifdef CONFIG_AUFS_POLL
14000 + .poll = aufs_poll,
14002 + .unlocked_ioctl = aufs_ioctl_nondir,
14003 +#ifdef CONFIG_COMPAT
14004 + .compat_ioctl = aufs_compat_ioctl_nondir,
14006 + .mmap = aufs_mmap,
14007 + .open = aufs_open_nondir,
14008 + .flush = aufs_flush_nondir,
14009 + .release = aufs_release_nondir,
14010 + .fsync = aufs_fsync_nondir,
14011 + /* .aio_fsync = aufs_aio_fsync_nondir, */
14012 + .fasync = aufs_fasync,
14013 + /* .sendpage = aufs_sendpage, */
14014 + .splice_write = aufs_splice_write,
14015 + .splice_read = aufs_splice_read,
14017 + .aio_splice_write = aufs_aio_splice_write,
14018 + .aio_splice_read = aufs_aio_splice_read,
14020 + .fallocate = aufs_fallocate
14022 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14023 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14024 +++ linux/fs/aufs/fstype.h 2015-06-28 17:35:44.348050491 +0200
14027 + * Copyright (C) 2005-2015 Junjiro R. Okajima
14029 + * This program, aufs is free software; you can redistribute it and/or modify
14030 + * it under the terms of the GNU General Public License as published by
14031 + * the Free Software Foundation; either version 2 of the License, or
14032 + * (at your option) any later version.
14034 + * This program is distributed in the hope that it will be useful,
14035 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14036 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14037 + * GNU General Public License for more details.
14039 + * You should have received a copy of the GNU General Public License
14040 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14044 + * judging filesystem type
14047 +#ifndef __AUFS_FSTYPE_H__
14048 +#define __AUFS_FSTYPE_H__
14052 +#include <linux/fs.h>
14053 +#include <linux/magic.h>
14054 +#include <linux/romfs_fs.h>
14055 +#include <linux/nfs_fs.h>
14057 +static inline int au_test_aufs(struct super_block *sb)
14059 + return sb->s_magic == AUFS_SUPER_MAGIC;
14062 +static inline const char *au_sbtype(struct super_block *sb)
14064 + return sb->s_type->name;
14067 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14069 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
14070 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14076 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14078 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
14079 + return sb->s_magic == ROMFS_MAGIC;
14085 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14087 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
14088 + return sb->s_magic == CRAMFS_MAGIC;
14093 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14095 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
14096 + return sb->s_magic == NFS_SUPER_MAGIC;
14102 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14104 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
14105 + return sb->s_magic == FUSE_SUPER_MAGIC;
14111 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14113 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
14114 + return sb->s_magic == XFS_SB_MAGIC;
14120 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14122 +#ifdef CONFIG_TMPFS
14123 + return sb->s_magic == TMPFS_MAGIC;
14129 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14131 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
14132 + return !strcmp(au_sbtype(sb), "ecryptfs");
14138 +static inline int au_test_ramfs(struct super_block *sb)
14140 + return sb->s_magic == RAMFS_MAGIC;
14143 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14145 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
14146 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14152 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14154 +#ifdef CONFIG_PROC_FS
14155 + return sb->s_magic == PROC_SUPER_MAGIC;
14161 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14163 +#ifdef CONFIG_SYSFS
14164 + return sb->s_magic == SYSFS_MAGIC;
14170 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14172 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
14173 + return sb->s_magic == CONFIGFS_MAGIC;
14179 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14181 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
14182 + return sb->s_magic == MINIX3_SUPER_MAGIC
14183 + || sb->s_magic == MINIX2_SUPER_MAGIC
14184 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14185 + || sb->s_magic == MINIX_SUPER_MAGIC
14186 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14192 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14194 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
14195 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14201 +static inline int au_test_msdos(struct super_block *sb)
14203 + return au_test_fat(sb);
14206 +static inline int au_test_vfat(struct super_block *sb)
14208 + return au_test_fat(sb);
14211 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14213 +#ifdef CONFIG_SECURITYFS
14214 + return sb->s_magic == SECURITYFS_MAGIC;
14220 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14222 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
14223 + return sb->s_magic == SQUASHFS_MAGIC;
14229 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14231 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
14232 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14238 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14240 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
14241 + return sb->s_magic == XENFS_SUPER_MAGIC;
14247 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14249 +#ifdef CONFIG_DEBUG_FS
14250 + return sb->s_magic == DEBUGFS_MAGIC;
14256 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14258 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
14259 + return sb->s_magic == NILFS_SUPER_MAGIC;
14265 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14267 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
14268 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14274 +/* ---------------------------------------------------------------------- */
14276 + * they can't be an aufs branch.
14278 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14281 +#ifndef CONFIG_AUFS_BR_RAMFS
14282 + au_test_ramfs(sb) ||
14284 + au_test_procfs(sb)
14285 + || au_test_sysfs(sb)
14286 + || au_test_configfs(sb)
14287 + || au_test_debugfs(sb)
14288 + || au_test_securityfs(sb)
14289 + || au_test_xenfs(sb)
14290 + || au_test_ecryptfs(sb)
14291 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14292 + || au_test_aufs(sb); /* will be supported in next version */
14295 +static inline int au_test_fs_remote(struct super_block *sb)
14297 + return !au_test_tmpfs(sb)
14298 +#ifdef CONFIG_AUFS_BR_RAMFS
14299 + && !au_test_ramfs(sb)
14301 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14304 +/* ---------------------------------------------------------------------- */
14307 + * Note: these functions (below) are created after reading ->getattr() in all
14308 + * filesystems under linux/fs. it means we have to do so in every update...
14312 + * some filesystems require getattr to refresh the inode attributes before
14314 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14315 + * and leave the work for d_revalidate()
14317 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14319 + return au_test_nfs(sb)
14320 + || au_test_fuse(sb)
14321 + /* || au_test_btrfs(sb) */ /* untested */
14326 + * filesystems which don't maintain i_size or i_blocks.
14328 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14330 + return au_test_xfs(sb)
14331 + || au_test_btrfs(sb)
14332 + || au_test_ubifs(sb)
14333 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14334 + /* || au_test_minix(sb) */ /* untested */
14339 + * filesystems which don't store the correct value in some of their inode
14342 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14344 + return au_test_fs_bad_iattr_size(sb)
14345 + || au_test_fat(sb)
14346 + || au_test_msdos(sb)
14347 + || au_test_vfat(sb);
14350 +/* they don't check i_nlink in link(2) */
14351 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14353 + return au_test_tmpfs(sb)
14354 +#ifdef CONFIG_AUFS_BR_RAMFS
14355 + || au_test_ramfs(sb)
14357 + || au_test_ubifs(sb)
14358 + || au_test_hfsplus(sb);
14362 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14364 +static inline int au_test_fs_notime(struct super_block *sb)
14366 + return au_test_nfs(sb)
14367 + || au_test_fuse(sb)
14368 + || au_test_ubifs(sb)
14372 +/* temporary support for i#1 in cramfs */
14373 +static inline int au_test_fs_unique_ino(struct inode *inode)
14375 + if (au_test_cramfs(inode->i_sb))
14376 + return inode->i_ino != 1;
14380 +/* ---------------------------------------------------------------------- */
14383 + * the filesystem where the xino files placed must support i/o after unlink and
14384 + * maintain i_size and i_blocks.
14386 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14388 + return au_test_fs_remote(sb)
14389 + || au_test_fs_bad_iattr_size(sb)
14390 + /* don't want unnecessary work for xino */
14391 + || au_test_aufs(sb)
14392 + || au_test_ecryptfs(sb)
14393 + || au_test_nilfs(sb);
14396 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14398 + return au_test_tmpfs(sb)
14399 + || au_test_ramfs(sb);
14403 + * test if the @sb is real-readonly.
14405 +static inline int au_test_fs_rr(struct super_block *sb)
14407 + return au_test_squashfs(sb)
14408 + || au_test_iso9660(sb)
14409 + || au_test_cramfs(sb)
14410 + || au_test_romfs(sb);
14414 + * test if the @inode is nfs with 'noacl' option
14415 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14417 +static inline int au_test_nfs_noacl(struct inode *inode)
14419 + return au_test_nfs(inode->i_sb)
14420 + /* && IS_POSIXACL(inode) */
14421 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14424 +#endif /* __KERNEL__ */
14425 +#endif /* __AUFS_FSTYPE_H__ */
14426 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14427 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14428 +++ linux/fs/aufs/hfsnotify.c 2015-06-28 17:35:44.348050491 +0200
14431 + * Copyright (C) 2005-2015 Junjiro R. Okajima
14433 + * This program, aufs is free software; you can redistribute it and/or modify
14434 + * it under the terms of the GNU General Public License as published by
14435 + * the Free Software Foundation; either version 2 of the License, or
14436 + * (at your option) any later version.
14438 + * This program is distributed in the hope that it will be useful,
14439 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14440 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14441 + * GNU General Public License for more details.
14443 + * You should have received a copy of the GNU General Public License
14444 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14448 + * fsnotify for the lower directories
14453 +/* FS_IN_IGNORED is unnecessary */
14454 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14455 + | FS_CREATE | FS_EVENT_ON_CHILD);
14456 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14457 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14459 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14461 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14464 + au_cache_free_hnotify(hn);
14465 + smp_mb__before_atomic();
14466 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14467 + wake_up(&au_hfsn_wq);
14470 +static int au_hfsn_alloc(struct au_hinode *hinode)
14473 + struct au_hnotify *hn;
14474 + struct super_block *sb;
14475 + struct au_branch *br;
14476 + struct fsnotify_mark *mark;
14477 + aufs_bindex_t bindex;
14479 + hn = hinode->hi_notify;
14480 + sb = hn->hn_aufs_inode->i_sb;
14481 + bindex = au_br_index(sb, hinode->hi_id);
14482 + br = au_sbr(sb, bindex);
14483 + AuDebugOn(!br->br_hfsn);
14485 + mark = &hn->hn_mark;
14486 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14487 + mark->mask = AuHfsnMask;
14489 + * by udba rename or rmdir, aufs assign a new inode to the known
14490 + * h_inode, so specify 1 to allow dups.
14493 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14494 + /*mnt*/NULL, /*allow_dups*/1);
14495 + /* even if err */
14496 + fsnotify_put_mark(mark);
14502 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14504 + struct fsnotify_mark *mark;
14505 + unsigned long long ull;
14506 + struct fsnotify_group *group;
14508 + ull = atomic64_inc_return(&au_hfsn_ifree);
14511 + mark = &hn->hn_mark;
14512 + spin_lock(&mark->lock);
14513 + group = mark->group;
14514 + fsnotify_get_group(group);
14515 + spin_unlock(&mark->lock);
14517 + fsnotify_destroy_mark(mark, group);
14518 + fsnotify_put_group(group);
14521 + /* free hn by myself */
14525 +/* ---------------------------------------------------------------------- */
14527 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14529 + struct fsnotify_mark *mark;
14531 + mark = &hinode->hi_notify->hn_mark;
14532 + spin_lock(&mark->lock);
14534 + AuDebugOn(mark->mask & AuHfsnMask);
14535 + mark->mask |= AuHfsnMask;
14537 + AuDebugOn(!(mark->mask & AuHfsnMask));
14538 + mark->mask &= ~AuHfsnMask;
14540 + spin_unlock(&mark->lock);
14541 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14544 +/* ---------------------------------------------------------------------- */
14546 +/* #define AuDbgHnotify */
14547 +#ifdef AuDbgHnotify
14548 +static char *au_hfsn_name(u32 mask)
14550 +#ifdef CONFIG_AUFS_DEBUG
14551 +#define test_ret(flag) \
14553 + if (mask & flag) \
14556 + test_ret(FS_ACCESS);
14557 + test_ret(FS_MODIFY);
14558 + test_ret(FS_ATTRIB);
14559 + test_ret(FS_CLOSE_WRITE);
14560 + test_ret(FS_CLOSE_NOWRITE);
14561 + test_ret(FS_OPEN);
14562 + test_ret(FS_MOVED_FROM);
14563 + test_ret(FS_MOVED_TO);
14564 + test_ret(FS_CREATE);
14565 + test_ret(FS_DELETE);
14566 + test_ret(FS_DELETE_SELF);
14567 + test_ret(FS_MOVE_SELF);
14568 + test_ret(FS_UNMOUNT);
14569 + test_ret(FS_Q_OVERFLOW);
14570 + test_ret(FS_IN_IGNORED);
14571 + test_ret(FS_ISDIR);
14572 + test_ret(FS_IN_ONESHOT);
14573 + test_ret(FS_EVENT_ON_CHILD);
14582 +/* ---------------------------------------------------------------------- */
14584 +static void au_hfsn_free_group(struct fsnotify_group *group)
14586 + struct au_br_hfsnotify *hfsn = group->private;
14592 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14593 + struct inode *inode,
14594 + struct fsnotify_mark *inode_mark,
14595 + struct fsnotify_mark *vfsmount_mark,
14596 + u32 mask, void *data, int data_type,
14597 + const unsigned char *file_name, u32 cookie)
14600 + struct au_hnotify *hnotify;
14601 + struct inode *h_dir, *h_inode;
14602 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14604 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14607 + /* if FS_UNMOUNT happens, there must be another bug */
14608 + AuDebugOn(mask & FS_UNMOUNT);
14609 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14614 +#ifdef AuDbgHnotify
14616 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14617 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14618 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14619 + h_dir->i_ino, mask, au_hfsn_name(mask),
14620 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14621 + /* WARN_ON(1); */
14626 + AuDebugOn(!inode_mark);
14627 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14628 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14634 +static struct fsnotify_ops au_hfsn_ops = {
14635 + .handle_event = au_hfsn_handle_event,
14636 + .free_group_priv = au_hfsn_free_group
14639 +/* ---------------------------------------------------------------------- */
14641 +static void au_hfsn_fin_br(struct au_branch *br)
14643 + struct au_br_hfsnotify *hfsn;
14645 + hfsn = br->br_hfsn;
14648 + fsnotify_put_group(hfsn->hfsn_group);
14653 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14656 + struct fsnotify_group *group;
14657 + struct au_br_hfsnotify *hfsn;
14660 + br->br_hfsn = NULL;
14661 + if (!au_br_hnotifyable(perm))
14665 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14666 + if (unlikely(!hfsn))
14670 + group = fsnotify_alloc_group(&au_hfsn_ops);
14671 + if (IS_ERR(group)) {
14672 + err = PTR_ERR(group);
14673 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14677 + group->private = hfsn;
14678 + hfsn->hfsn_group = group;
14679 + br->br_hfsn = hfsn;
14680 + goto out; /* success */
14688 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14693 + if (!br->br_hfsn)
14694 + err = au_hfsn_init_br(br, perm);
14699 +/* ---------------------------------------------------------------------- */
14701 +static void au_hfsn_fin(void)
14703 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14704 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14707 +const struct au_hnotify_op au_hnotify_op = {
14708 + .ctl = au_hfsn_ctl,
14709 + .alloc = au_hfsn_alloc,
14710 + .free = au_hfsn_free,
14712 + .fin = au_hfsn_fin,
14714 + .reset_br = au_hfsn_reset_br,
14715 + .fin_br = au_hfsn_fin_br,
14716 + .init_br = au_hfsn_init_br
14718 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14719 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14720 +++ linux/fs/aufs/hfsplus.c 2015-06-28 17:36:09.025073697 +0200
14723 + * Copyright (C) 2010-2015 Junjiro R. Okajima
14725 + * This program, aufs is free software; you can redistribute it and/or modify
14726 + * it under the terms of the GNU General Public License as published by
14727 + * the Free Software Foundation; either version 2 of the License, or
14728 + * (at your option) any later version.
14730 + * This program is distributed in the hope that it will be useful,
14731 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14732 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14733 + * GNU General Public License for more details.
14735 + * You should have received a copy of the GNU General Public License
14736 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14740 + * special support for filesystems which aqucires an inode mutex
14741 + * at final closing a file, eg, hfsplus.
14743 + * This trick is very simple and stupid, just to open the file before really
14744 + * neceeary open to tell hfsplus that this is not the final closing.
14745 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14746 + * and au_h_open_post() after releasing it.
14751 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14754 + struct file *h_file;
14755 + struct dentry *h_dentry;
14757 + h_dentry = au_h_dptr(dentry, bindex);
14758 + AuDebugOn(!h_dentry);
14759 + AuDebugOn(d_is_negative(h_dentry));
14762 + if (au_test_hfsplus(h_dentry->d_sb)
14763 + && d_is_reg(h_dentry))
14764 + h_file = au_h_open(dentry, bindex,
14765 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14766 + /*file*/NULL, force_wr);
14770 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14771 + struct file *h_file)
14775 + au_sbr_put(dentry->d_sb, bindex);
14778 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
14779 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14780 +++ linux/fs/aufs/hnotify.c 2015-06-28 17:36:09.025073697 +0200
14783 + * Copyright (C) 2005-2015 Junjiro R. Okajima
14785 + * This program, aufs is free software; you can redistribute it and/or modify
14786 + * it under the terms of the GNU General Public License as published by
14787 + * the Free Software Foundation; either version 2 of the License, or
14788 + * (at your option) any later version.
14790 + * This program is distributed in the hope that it will be useful,
14791 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14792 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14793 + * GNU General Public License for more details.
14795 + * You should have received a copy of the GNU General Public License
14796 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14800 + * abstraction to notify the direct changes on lower directories
14805 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14808 + struct au_hnotify *hn;
14811 + hn = au_cache_alloc_hnotify();
14813 + hn->hn_aufs_inode = inode;
14814 + hinode->hi_notify = hn;
14815 + err = au_hnotify_op.alloc(hinode);
14817 + if (unlikely(err)) {
14818 + hinode->hi_notify = NULL;
14819 + au_cache_free_hnotify(hn);
14821 + * The upper dir was removed by udba, but the same named
14822 + * dir left. In this case, aufs assignes a new inode
14823 + * number and set the monitor again.
14824 + * For the lower dir, the old monitnor is still left.
14826 + if (err == -EEXIST)
14835 +void au_hn_free(struct au_hinode *hinode)
14837 + struct au_hnotify *hn;
14839 + hn = hinode->hi_notify;
14841 + hinode->hi_notify = NULL;
14842 + if (au_hnotify_op.free(hinode, hn))
14843 + au_cache_free_hnotify(hn);
14847 +/* ---------------------------------------------------------------------- */
14849 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
14851 + if (hinode->hi_notify)
14852 + au_hnotify_op.ctl(hinode, do_set);
14855 +void au_hn_reset(struct inode *inode, unsigned int flags)
14857 + aufs_bindex_t bindex, bend;
14858 + struct inode *hi;
14859 + struct dentry *iwhdentry;
14861 + bend = au_ibend(inode);
14862 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14863 + hi = au_h_iptr(inode, bindex);
14867 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
14868 + iwhdentry = au_hi_wh(inode, bindex);
14872 + au_set_h_iptr(inode, bindex, NULL, 0);
14873 + au_set_h_iptr(inode, bindex, au_igrab(hi),
14874 + flags & ~AuHi_XINO);
14877 + /* mutex_unlock(&hi->i_mutex); */
14881 +/* ---------------------------------------------------------------------- */
14883 +static int hn_xino(struct inode *inode, struct inode *h_inode)
14886 + aufs_bindex_t bindex, bend, bfound, bstart;
14887 + struct inode *h_i;
14890 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14891 + pr_warn("branch root dir was changed\n");
14896 + bend = au_ibend(inode);
14897 + bstart = au_ibstart(inode);
14898 +#if 0 /* reserved for future use */
14899 + if (bindex == bend) {
14900 + /* keep this ino in rename case */
14904 + for (bindex = bstart; bindex <= bend; bindex++)
14905 + if (au_h_iptr(inode, bindex) == h_inode) {
14912 + for (bindex = bstart; bindex <= bend; bindex++) {
14913 + h_i = au_h_iptr(inode, bindex);
14917 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
14918 + /* ignore this error */
14919 + /* bad action? */
14922 + /* children inode number will be broken */
14929 +static int hn_gen_tree(struct dentry *dentry)
14931 + int err, i, j, ndentry;
14932 + struct au_dcsub_pages dpages;
14933 + struct au_dpage *dpage;
14934 + struct dentry **dentries;
14936 + err = au_dpages_init(&dpages, GFP_NOFS);
14937 + if (unlikely(err))
14939 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
14940 + if (unlikely(err))
14943 + for (i = 0; i < dpages.ndpage; i++) {
14944 + dpage = dpages.dpages + i;
14945 + dentries = dpage->dentries;
14946 + ndentry = dpage->ndentry;
14947 + for (j = 0; j < ndentry; j++) {
14948 + struct dentry *d;
14955 + if (d_really_is_positive(d))
14956 + /* todo: reset children xino?
14957 + cached children only? */
14958 + au_iigen_dec(d_inode(d));
14963 + au_dpages_free(&dpages);
14966 + /* discard children */
14967 + dentry_unhash(dentry);
14975 + * return 0 if processed.
14977 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
14978 + const unsigned int isdir)
14981 + struct dentry *d;
14982 + struct qstr *dname;
14985 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14986 + pr_warn("branch root dir was changed\n");
14992 + AuDebugOn(!name);
14993 + au_iigen_dec(inode);
14994 + spin_lock(&inode->i_lock);
14995 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
14996 + spin_lock(&d->d_lock);
14997 + dname = &d->d_name;
14998 + if (dname->len != nlen
14999 + && memcmp(dname->name, name, nlen)) {
15000 + spin_unlock(&d->d_lock);
15005 + spin_unlock(&d->d_lock);
15008 + spin_unlock(&inode->i_lock);
15010 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15011 + d = d_find_any_alias(inode);
15013 + au_iigen_dec(inode);
15017 + spin_lock(&d->d_lock);
15018 + dname = &d->d_name;
15019 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15020 + spin_unlock(&d->d_lock);
15021 + err = hn_gen_tree(d);
15022 + spin_lock(&d->d_lock);
15024 + spin_unlock(&d->d_lock);
15033 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15037 + if (IS_ROOT(dentry)) {
15038 + pr_warn("branch root dir was changed\n");
15044 + au_digen_dec(dentry);
15045 + if (d_really_is_positive(dentry))
15046 + au_iigen_dec(d_inode(dentry));
15048 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15049 + if (d_really_is_positive(dentry))
15050 + err = hn_gen_tree(dentry);
15057 +/* ---------------------------------------------------------------------- */
15059 +/* hnotify job flags */
15060 +#define AuHnJob_XINO0 1
15061 +#define AuHnJob_GEN (1 << 1)
15062 +#define AuHnJob_DIRENT (1 << 2)
15063 +#define AuHnJob_ISDIR (1 << 3)
15064 +#define AuHnJob_TRYXINO0 (1 << 4)
15065 +#define AuHnJob_MNTPNT (1 << 5)
15066 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15067 +#define au_fset_hnjob(flags, name) \
15068 + do { (flags) |= AuHnJob_##name; } while (0)
15069 +#define au_fclr_hnjob(flags, name) \
15070 + do { (flags) &= ~AuHnJob_##name; } while (0)
15078 +struct au_hnotify_args {
15079 + struct inode *h_dir, *dir, *h_child_inode;
15081 + unsigned int flags[AuHnLast];
15082 + unsigned int h_child_nlen;
15083 + char h_child_name[];
15086 +struct hn_job_args {
15087 + unsigned int flags;
15088 + struct inode *inode, *h_inode, *dir, *h_dir;
15089 + struct dentry *dentry;
15094 +static int hn_job(struct hn_job_args *a)
15096 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15100 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15101 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15103 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15106 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
15107 + if (!a->h_inode->i_nlink
15108 + && !(a->h_inode->i_state & I_LINKABLE))
15109 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15110 + mutex_unlock(&a->h_inode->i_mutex);
15113 + /* make the generation obsolete */
15114 + if (au_ftest_hnjob(a->flags, GEN)) {
15117 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15119 + if (e && a->dentry)
15120 + hn_gen_by_name(a->dentry, isdir);
15121 + /* ignore this error */
15124 + /* make dir entries obsolete */
15125 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15126 + struct au_vdir *vdir;
15128 + vdir = au_ivdir(a->inode);
15130 + vdir->vd_jiffy = 0;
15131 + /* IMustLock(a->inode); */
15132 + /* a->inode->i_version++; */
15135 + /* can do nothing but warn */
15136 + if (au_ftest_hnjob(a->flags, MNTPNT)
15138 + && d_mountpoint(a->dentry))
15139 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15144 +/* ---------------------------------------------------------------------- */
15146 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15147 + struct inode *dir)
15149 + struct dentry *dentry, *d, *parent;
15150 + struct qstr *dname;
15152 + parent = d_find_any_alias(dir);
15157 + spin_lock(&parent->d_lock);
15158 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15159 + /* AuDbg("%pd\n", d); */
15160 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15161 + dname = &d->d_name;
15162 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15163 + goto cont_unlock;
15167 + goto cont_unlock;
15168 + if (au_dcount(d) > 0) {
15169 + dentry = dget_dlock(d);
15170 + spin_unlock(&d->d_lock);
15175 + spin_unlock(&d->d_lock);
15177 + spin_unlock(&parent->d_lock);
15181 + di_write_lock_child(dentry);
15186 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15187 + aufs_bindex_t bindex, ino_t h_ino)
15189 + struct inode *inode;
15194 + err = au_xino_read(sb, bindex, h_ino, &ino);
15196 + inode = ilookup(sb, ino);
15200 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15201 + pr_warn("wrong root branch\n");
15207 + ii_write_lock_child(inode);
15213 +static void au_hn_bh(void *_args)
15215 + struct au_hnotify_args *a = _args;
15216 + struct super_block *sb;
15217 + aufs_bindex_t bindex, bend, bfound;
15218 + unsigned char xino, try_iput;
15220 + struct inode *inode;
15222 + struct hn_job_args args;
15223 + struct dentry *dentry;
15224 + struct au_sbinfo *sbinfo;
15226 + AuDebugOn(!_args);
15227 + AuDebugOn(!a->h_dir);
15228 + AuDebugOn(!a->dir);
15229 + AuDebugOn(!a->mask);
15230 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15231 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15232 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15237 + * do not lock a->dir->i_mutex here
15238 + * because of d_revalidate() may cause a deadlock.
15240 + sb = a->dir->i_sb;
15242 + sbinfo = au_sbi(sb);
15243 + AuDebugOn(!sbinfo);
15244 + si_write_lock(sb, AuLock_NOPLMW);
15246 + ii_read_lock_parent(a->dir);
15248 + bend = au_ibend(a->dir);
15249 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
15250 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15254 + ii_read_unlock(a->dir);
15255 + if (unlikely(bfound < 0))
15258 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15260 + if (a->h_child_inode)
15261 + h_ino = a->h_child_inode->i_ino;
15263 + if (a->h_child_nlen
15264 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15265 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15266 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15269 + if (dentry && d_really_is_positive(dentry))
15270 + inode = d_inode(dentry);
15271 + if (xino && !inode && h_ino
15272 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15273 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15274 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15275 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15279 + args.flags = a->flags[AuHn_CHILD];
15280 + args.dentry = dentry;
15281 + args.inode = inode;
15282 + args.h_inode = a->h_child_inode;
15283 + args.dir = a->dir;
15284 + args.h_dir = a->h_dir;
15285 + args.h_name = a->h_child_name;
15286 + args.h_nlen = a->h_child_nlen;
15287 + err = hn_job(&args);
15289 + if (au_di(dentry))
15290 + di_write_unlock(dentry);
15293 + if (inode && try_iput) {
15294 + ii_write_unlock(inode);
15298 + ii_write_lock_parent(a->dir);
15299 + args.flags = a->flags[AuHn_PARENT];
15300 + args.dentry = NULL;
15301 + args.inode = a->dir;
15302 + args.h_inode = a->h_dir;
15304 + args.h_dir = NULL;
15305 + args.h_name = NULL;
15307 + err = hn_job(&args);
15308 + ii_write_unlock(a->dir);
15311 + iput(a->h_child_inode);
15314 + si_write_unlock(sb);
15315 + au_nwt_done(&sbinfo->si_nowait);
15319 +/* ---------------------------------------------------------------------- */
15321 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15322 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15325 + unsigned int flags[AuHnLast], f;
15326 + unsigned char isdir, isroot, wh;
15327 + struct inode *dir;
15328 + struct au_hnotify_args *args;
15329 + char *p, *h_child_name;
15332 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15333 + dir = igrab(hnotify->hn_aufs_inode);
15337 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15339 + h_child_name = (void *)h_child_qstr->name;
15340 + len = h_child_qstr->len;
15341 + if (h_child_name) {
15342 + if (len > AUFS_WH_PFX_LEN
15343 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15344 + h_child_name += AUFS_WH_PFX_LEN;
15345 + len -= AUFS_WH_PFX_LEN;
15351 + if (h_child_inode)
15352 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15353 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15354 + flags[AuHn_CHILD] = 0;
15356 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15357 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15358 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15359 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15360 + case FS_MOVED_FROM:
15361 + case FS_MOVED_TO:
15362 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15363 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15366 + AuDebugOn(!h_child_name);
15371 + * aufs never be able to get this child inode.
15372 + * revalidation should be in d_revalidate()
15373 + * by checking i_nlink, i_generation or d_unhashed().
15375 + AuDebugOn(!h_child_name);
15376 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15377 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15385 + h_child_inode = NULL;
15388 + /* iput() and kfree() will be called in au_hnotify() */
15389 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15390 + if (unlikely(!args)) {
15391 + AuErr1("no memory\n");
15395 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15396 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15397 + args->mask = mask;
15399 + args->h_dir = igrab(h_dir);
15400 + if (h_child_inode)
15401 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15402 + args->h_child_inode = h_child_inode;
15403 + args->h_child_nlen = len;
15405 + p = (void *)args;
15406 + p += sizeof(*args);
15407 + memcpy(p, h_child_name, len);
15411 + /* NFS fires the event for silly-renamed one from kworker */
15413 + if (!dir->i_nlink
15414 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15416 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15417 + if (unlikely(err)) {
15418 + pr_err("wkq %d\n", err);
15419 + iput(args->h_child_inode);
15420 + iput(args->h_dir);
15429 +/* ---------------------------------------------------------------------- */
15431 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15435 + AuDebugOn(!(udba & AuOptMask_UDBA));
15438 + if (au_hnotify_op.reset_br)
15439 + err = au_hnotify_op.reset_br(udba, br, perm);
15444 +int au_hnotify_init_br(struct au_branch *br, int perm)
15449 + if (au_hnotify_op.init_br)
15450 + err = au_hnotify_op.init_br(br, perm);
15455 +void au_hnotify_fin_br(struct au_branch *br)
15457 + if (au_hnotify_op.fin_br)
15458 + au_hnotify_op.fin_br(br);
15461 +static void au_hn_destroy_cache(void)
15463 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15464 + au_cachep[AuCache_HNOTIFY] = NULL;
15467 +int __init au_hnotify_init(void)
15472 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15473 + if (au_cachep[AuCache_HNOTIFY]) {
15475 + if (au_hnotify_op.init)
15476 + err = au_hnotify_op.init();
15477 + if (unlikely(err))
15478 + au_hn_destroy_cache();
15484 +void au_hnotify_fin(void)
15486 + if (au_hnotify_op.fin)
15487 + au_hnotify_op.fin();
15488 + /* cf. au_cache_fin() */
15489 + if (au_cachep[AuCache_HNOTIFY])
15490 + au_hn_destroy_cache();
15492 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15493 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15494 +++ linux/fs/aufs/iinfo.c 2015-06-28 17:35:44.348050491 +0200
15497 + * Copyright (C) 2005-2015 Junjiro R. Okajima
15499 + * This program, aufs is free software; you can redistribute it and/or modify
15500 + * it under the terms of the GNU General Public License as published by
15501 + * the Free Software Foundation; either version 2 of the License, or
15502 + * (at your option) any later version.
15504 + * This program is distributed in the hope that it will be useful,
15505 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15506 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15507 + * GNU General Public License for more details.
15509 + * You should have received a copy of the GNU General Public License
15510 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15514 + * inode private data
15519 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15521 + struct inode *h_inode;
15523 + IiMustAnyLock(inode);
15525 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
15526 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15530 +/* todo: hard/soft set? */
15531 +void au_hiput(struct au_hinode *hinode)
15533 + au_hn_free(hinode);
15534 + dput(hinode->hi_whdentry);
15535 + iput(hinode->hi_inode);
15538 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15540 + unsigned int flags;
15541 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15544 + if (au_opt_test(mnt_flags, XINO))
15545 + au_fset_hi(flags, XINO);
15546 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15547 + au_fset_hi(flags, HNOTIFY);
15551 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15552 + struct inode *h_inode, unsigned int flags)
15554 + struct au_hinode *hinode;
15555 + struct inode *hi;
15556 + struct au_iinfo *iinfo = au_ii(inode);
15558 + IiMustWriteLock(inode);
15560 + hinode = iinfo->ii_hinode + bindex;
15561 + hi = hinode->hi_inode;
15562 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15565 + au_hiput(hinode);
15566 + hinode->hi_inode = h_inode;
15569 + struct super_block *sb = inode->i_sb;
15570 + struct au_branch *br;
15572 + AuDebugOn(inode->i_mode
15573 + && (h_inode->i_mode & S_IFMT)
15574 + != (inode->i_mode & S_IFMT));
15575 + if (bindex == iinfo->ii_bstart)
15576 + au_cpup_igen(inode, h_inode);
15577 + br = au_sbr(sb, bindex);
15578 + hinode->hi_id = br->br_id;
15579 + if (au_ftest_hi(flags, XINO)) {
15580 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15582 + if (unlikely(err))
15583 + AuIOErr1("failed au_xino_write() %d\n", err);
15586 + if (au_ftest_hi(flags, HNOTIFY)
15587 + && au_br_hnotifyable(br->br_perm)) {
15588 + err = au_hn_alloc(hinode, inode);
15589 + if (unlikely(err))
15590 + AuIOErr1("au_hn_alloc() %d\n", err);
15595 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15596 + struct dentry *h_wh)
15598 + struct au_hinode *hinode;
15600 + IiMustWriteLock(inode);
15602 + hinode = au_ii(inode)->ii_hinode + bindex;
15603 + AuDebugOn(hinode->hi_whdentry);
15604 + hinode->hi_whdentry = h_wh;
15607 +void au_update_iigen(struct inode *inode, int half)
15609 + struct au_iinfo *iinfo;
15610 + struct au_iigen *iigen;
15611 + unsigned int sigen;
15613 + sigen = au_sigen(inode->i_sb);
15614 + iinfo = au_ii(inode);
15615 + iigen = &iinfo->ii_generation;
15616 + spin_lock(&iinfo->ii_genspin);
15617 + iigen->ig_generation = sigen;
15619 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15621 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15622 + spin_unlock(&iinfo->ii_genspin);
15625 +/* it may be called at remount time, too */
15626 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15628 + struct au_iinfo *iinfo;
15629 + aufs_bindex_t bindex, bend;
15631 + iinfo = au_ii(inode);
15635 + IiMustWriteLock(inode);
15637 + if (do_put_zero && iinfo->ii_bstart >= 0) {
15638 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15640 + struct inode *h_i;
15642 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
15645 + && !(h_i->i_state & I_LINKABLE))
15646 + au_set_h_iptr(inode, bindex, NULL, 0);
15650 + iinfo->ii_bstart = -1;
15651 + iinfo->ii_bend = -1;
15652 + bend = au_sbend(inode->i_sb);
15653 + for (bindex = 0; bindex <= bend; bindex++)
15654 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15655 + iinfo->ii_bstart = bindex;
15658 + if (iinfo->ii_bstart >= 0)
15659 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
15660 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15661 + iinfo->ii_bend = bindex;
15664 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
15667 +/* ---------------------------------------------------------------------- */
15669 +void au_icntnr_init_once(void *_c)
15671 + struct au_icntnr *c = _c;
15672 + struct au_iinfo *iinfo = &c->iinfo;
15673 + static struct lock_class_key aufs_ii;
15675 + spin_lock_init(&iinfo->ii_genspin);
15676 + au_rw_init(&iinfo->ii_rwsem);
15677 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
15678 + inode_init_once(&c->vfs_inode);
15681 +int au_iinfo_init(struct inode *inode)
15683 + struct au_iinfo *iinfo;
15684 + struct super_block *sb;
15687 + sb = inode->i_sb;
15688 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15689 + nbr = au_sbend(sb) + 1;
15690 + if (unlikely(nbr <= 0))
15692 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15693 + if (iinfo->ii_hinode) {
15694 + au_ninodes_inc(sb);
15695 + for (i = 0; i < nbr; i++)
15696 + iinfo->ii_hinode[i].hi_id = -1;
15698 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15699 + iinfo->ii_bstart = -1;
15700 + iinfo->ii_bend = -1;
15701 + iinfo->ii_vdir = NULL;
15707 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
15710 + struct au_hinode *hip;
15712 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15715 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
15717 + sz = sizeof(*hip);
15718 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
15720 + iinfo->ii_hinode = hip;
15727 +void au_iinfo_fin(struct inode *inode)
15729 + struct au_iinfo *iinfo;
15730 + struct au_hinode *hi;
15731 + struct super_block *sb;
15732 + aufs_bindex_t bindex, bend;
15733 + const unsigned char unlinked = !inode->i_nlink;
15735 + iinfo = au_ii(inode);
15736 + /* bad_inode case */
15740 + sb = inode->i_sb;
15741 + au_ninodes_dec(sb);
15742 + if (si_pid_test(sb))
15743 + au_xino_delete_inode(inode, unlinked);
15746 + * it is safe to hide the dependency between sbinfo and
15750 + si_noflush_read_lock(sb);
15751 + au_xino_delete_inode(inode, unlinked);
15752 + si_read_unlock(sb);
15756 + if (iinfo->ii_vdir)
15757 + au_vdir_free(iinfo->ii_vdir);
15759 + bindex = iinfo->ii_bstart;
15760 + if (bindex >= 0) {
15761 + hi = iinfo->ii_hinode + bindex;
15762 + bend = iinfo->ii_bend;
15763 + while (bindex++ <= bend) {
15764 + if (hi->hi_inode)
15769 + kfree(iinfo->ii_hinode);
15770 + iinfo->ii_hinode = NULL;
15771 + AuRwDestroy(&iinfo->ii_rwsem);
15773 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
15774 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
15775 +++ linux/fs/aufs/inode.c 2015-06-28 17:36:09.025073697 +0200
15778 + * Copyright (C) 2005-2015 Junjiro R. Okajima
15780 + * This program, aufs is free software; you can redistribute it and/or modify
15781 + * it under the terms of the GNU General Public License as published by
15782 + * the Free Software Foundation; either version 2 of the License, or
15783 + * (at your option) any later version.
15785 + * This program is distributed in the hope that it will be useful,
15786 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15787 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15788 + * GNU General Public License for more details.
15790 + * You should have received a copy of the GNU General Public License
15791 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15795 + * inode functions
15800 +struct inode *au_igrab(struct inode *inode)
15803 + AuDebugOn(!atomic_read(&inode->i_count));
15809 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
15811 + au_cpup_attr_all(inode, /*force*/0);
15812 + au_update_iigen(inode, /*half*/1);
15814 + inode->i_version++;
15817 +static int au_ii_refresh(struct inode *inode, int *update)
15821 + aufs_bindex_t bindex, new_bindex;
15822 + struct super_block *sb;
15823 + struct au_iinfo *iinfo;
15824 + struct au_hinode *p, *q, tmp;
15826 + IiMustWriteLock(inode);
15829 + sb = inode->i_sb;
15830 + type = inode->i_mode & S_IFMT;
15831 + iinfo = au_ii(inode);
15832 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
15833 + if (unlikely(err))
15836 + AuDebugOn(iinfo->ii_bstart < 0);
15837 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15838 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15840 + if (!p->hi_inode)
15843 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
15844 + new_bindex = au_br_index(sb, p->hi_id);
15845 + if (new_bindex == bindex)
15848 + if (new_bindex < 0) {
15851 + p->hi_inode = NULL;
15855 + if (new_bindex < iinfo->ii_bstart)
15856 + iinfo->ii_bstart = new_bindex;
15857 + if (iinfo->ii_bend < new_bindex)
15858 + iinfo->ii_bend = new_bindex;
15859 + /* swap two lower inode, and loop again */
15860 + q = iinfo->ii_hinode + new_bindex;
15864 + if (tmp.hi_inode) {
15869 + au_update_ibrange(inode, /*do_put_zero*/0);
15870 + e = au_dy_irefresh(inode);
15871 + if (unlikely(e && !err))
15879 +int au_refresh_hinode_self(struct inode *inode)
15883 + err = au_ii_refresh(inode, &update);
15885 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
15891 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
15893 + int err, e, update;
15894 + unsigned int flags;
15896 + aufs_bindex_t bindex, bend;
15897 + unsigned char isdir;
15898 + struct au_hinode *p;
15899 + struct au_iinfo *iinfo;
15901 + err = au_ii_refresh(inode, &update);
15902 + if (unlikely(err))
15906 + iinfo = au_ii(inode);
15907 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15908 + mode = (inode->i_mode & S_IFMT);
15909 + isdir = S_ISDIR(mode);
15910 + flags = au_hi_flags(inode, isdir);
15911 + bend = au_dbend(dentry);
15912 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
15913 + struct inode *h_i, *h_inode;
15914 + struct dentry *h_d;
15916 + h_d = au_h_dptr(dentry, bindex);
15917 + if (!h_d || d_is_negative(h_d))
15920 + h_inode = d_inode(h_d);
15921 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
15922 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
15923 + h_i = au_h_iptr(inode, bindex);
15925 + if (h_i == h_inode)
15931 + if (bindex < iinfo->ii_bstart)
15932 + iinfo->ii_bstart = bindex;
15933 + if (iinfo->ii_bend < bindex)
15934 + iinfo->ii_bend = bindex;
15935 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
15938 + au_update_ibrange(inode, /*do_put_zero*/0);
15939 + e = au_dy_irefresh(inode);
15940 + if (unlikely(e && !err))
15943 + au_refresh_hinode_attr(inode, update && isdir);
15950 +static int set_inode(struct inode *inode, struct dentry *dentry)
15953 + unsigned int flags;
15955 + aufs_bindex_t bindex, bstart, btail;
15956 + unsigned char isdir;
15957 + struct dentry *h_dentry;
15958 + struct inode *h_inode;
15959 + struct au_iinfo *iinfo;
15961 + IiMustWriteLock(inode);
15965 + bstart = au_dbstart(dentry);
15966 + h_dentry = au_h_dptr(dentry, bstart);
15967 + h_inode = d_inode(h_dentry);
15968 + mode = h_inode->i_mode;
15969 + switch (mode & S_IFMT) {
15971 + btail = au_dbtail(dentry);
15972 + inode->i_op = &aufs_iop;
15973 + inode->i_fop = &aufs_file_fop;
15974 + err = au_dy_iaop(inode, bstart, h_inode);
15975 + if (unlikely(err))
15980 + btail = au_dbtaildir(dentry);
15981 + inode->i_op = &aufs_dir_iop;
15982 + inode->i_fop = &aufs_dir_fop;
15985 + btail = au_dbtail(dentry);
15986 + inode->i_op = &aufs_symlink_iop;
15992 + btail = au_dbtail(dentry);
15993 + inode->i_op = &aufs_iop;
15994 + init_special_inode(inode, mode, h_inode->i_rdev);
15997 + AuIOErr("Unknown file type 0%o\n", mode);
16002 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
16003 + flags = au_hi_flags(inode, isdir);
16004 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
16005 + && au_ftest_hi(flags, HNOTIFY)
16006 + && dentry->d_name.len > AUFS_WH_PFX_LEN
16007 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
16008 + au_fclr_hi(flags, HNOTIFY);
16009 + iinfo = au_ii(inode);
16010 + iinfo->ii_bstart = bstart;
16011 + iinfo->ii_bend = btail;
16012 + for (bindex = bstart; bindex <= btail; bindex++) {
16013 + h_dentry = au_h_dptr(dentry, bindex);
16015 + au_set_h_iptr(inode, bindex,
16016 + au_igrab(d_inode(h_dentry)), flags);
16018 + au_cpup_attr_all(inode, /*force*/1);
16020 + * to force calling aufs_get_acl() every time,
16021 + * do not call cache_no_acl() for aufs inode.
16029 + * successful returns with iinfo write_locked
16031 + * zero: success, matched
16032 + * plus: no error, but unmatched
16034 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16037 + unsigned int gen;
16038 + struct au_iigen iigen;
16039 + aufs_bindex_t bindex, bend;
16040 + struct inode *h_inode, *h_dinode;
16041 + struct dentry *h_dentry;
16044 + * before this function, if aufs got any iinfo lock, it must be only
16045 + * one, the parent dir.
16046 + * it can happen by UDBA and the obsoleted inode number.
16049 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16053 + ii_write_lock_new_child(inode);
16054 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
16055 + h_dinode = d_inode(h_dentry);
16056 + bend = au_ibend(inode);
16057 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
16058 + h_inode = au_h_iptr(inode, bindex);
16059 + if (!h_inode || h_inode != h_dinode)
16063 + gen = au_iigen(inode, &iigen);
16064 + if (gen == au_digen(dentry)
16065 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
16068 + /* fully refresh inode using dentry */
16069 + err = au_refresh_hinode(inode, dentry);
16071 + au_update_iigen(inode, /*half*/0);
16075 + if (unlikely(err))
16076 + ii_write_unlock(inode);
16081 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16082 + unsigned int d_type, ino_t *ino)
16085 + struct mutex *mtx;
16087 + /* prevent hardlinked inode number from race condition */
16089 + if (d_type != DT_DIR) {
16090 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16093 + err = au_xino_read(sb, bindex, h_ino, ino);
16094 + if (unlikely(err))
16099 + *ino = au_xino_new_ino(sb);
16100 + if (unlikely(!*ino))
16102 + err = au_xino_write(sb, bindex, h_ino, *ino);
16103 + if (unlikely(err))
16109 + mutex_unlock(mtx);
16113 +/* successful returns with iinfo write_locked */
16114 +/* todo: return with unlocked? */
16115 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16117 + struct inode *inode, *h_inode;
16118 + struct dentry *h_dentry;
16119 + struct super_block *sb;
16120 + struct mutex *mtx;
16121 + ino_t h_ino, ino;
16123 + aufs_bindex_t bstart;
16125 + sb = dentry->d_sb;
16126 + bstart = au_dbstart(dentry);
16127 + h_dentry = au_h_dptr(dentry, bstart);
16128 + h_inode = d_inode(h_dentry);
16129 + h_ino = h_inode->i_ino;
16132 + * stop 'race'-ing between hardlinks under different
16136 + if (!d_is_dir(h_dentry))
16137 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
16142 + err = au_xino_read(sb, bstart, h_ino, &ino);
16143 + inode = ERR_PTR(err);
16144 + if (unlikely(err))
16148 + ino = au_xino_new_ino(sb);
16149 + if (unlikely(!ino)) {
16150 + inode = ERR_PTR(-EIO);
16155 + AuDbg("i%lu\n", (unsigned long)ino);
16156 + inode = au_iget_locked(sb, ino);
16157 + err = PTR_ERR(inode);
16158 + if (IS_ERR(inode))
16161 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16162 + if (inode->i_state & I_NEW) {
16163 + /* verbose coding for lock class name */
16164 + if (unlikely(d_is_symlink(h_dentry)))
16165 + au_rw_class(&au_ii(inode)->ii_rwsem,
16166 + au_lc_key + AuLcSymlink_IIINFO);
16167 + else if (unlikely(d_is_dir(h_dentry)))
16168 + au_rw_class(&au_ii(inode)->ii_rwsem,
16169 + au_lc_key + AuLcDir_IIINFO);
16170 + else /* likely */
16171 + au_rw_class(&au_ii(inode)->ii_rwsem,
16172 + au_lc_key + AuLcNonDir_IIINFO);
16174 + ii_write_lock_new_child(inode);
16175 + err = set_inode(inode, dentry);
16177 + unlock_new_inode(inode);
16178 + goto out; /* success */
16182 + * iget_failed() calls iput(), but we need to call
16183 + * ii_write_unlock() after iget_failed(). so dirty hack for
16186 + atomic_inc(&inode->i_count);
16187 + iget_failed(inode);
16188 + ii_write_unlock(inode);
16189 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
16190 + /* ignore this error */
16192 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16194 + * horrible race condition between lookup, readdir and copyup
16195 + * (or something).
16198 + mutex_unlock(mtx);
16199 + err = reval_inode(inode, dentry);
16200 + if (unlikely(err < 0)) {
16207 + goto out; /* success */
16212 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16213 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16214 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16215 + bstart, au_sbtype(h_dentry->d_sb), dentry,
16216 + (unsigned long)h_ino, (unsigned long)ino);
16218 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
16222 + mutex_unlock(mtx);
16228 + inode = ERR_PTR(err);
16231 + mutex_unlock(mtx);
16235 +/* ---------------------------------------------------------------------- */
16237 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16238 + struct inode *inode)
16241 + struct inode *hi;
16243 + err = au_br_rdonly(au_sbr(sb, bindex));
16245 + /* pseudo-link after flushed may happen out of bounds */
16248 + && au_ibstart(inode) <= bindex
16249 + && bindex <= au_ibend(inode)) {
16251 + * permission check is unnecessary since vfsub routine
16252 + * will be called later
16254 + hi = au_h_iptr(inode, bindex);
16256 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16262 +int au_test_h_perm(struct inode *h_inode, int mask)
16264 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16266 + return inode_permission(h_inode, mask);
16269 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16271 + if (au_test_nfs(h_inode->i_sb)
16272 + && (mask & MAY_WRITE)
16273 + && S_ISDIR(h_inode->i_mode))
16274 + mask |= MAY_READ; /* force permission check */
16275 + return au_test_h_perm(h_inode, mask);
16277 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16278 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16279 +++ linux/fs/aufs/inode.h 2015-06-28 17:35:44.348050491 +0200
16282 + * Copyright (C) 2005-2015 Junjiro R. Okajima
16284 + * This program, aufs is free software; you can redistribute it and/or modify
16285 + * it under the terms of the GNU General Public License as published by
16286 + * the Free Software Foundation; either version 2 of the License, or
16287 + * (at your option) any later version.
16289 + * This program is distributed in the hope that it will be useful,
16290 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16291 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16292 + * GNU General Public License for more details.
16294 + * You should have received a copy of the GNU General Public License
16295 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16299 + * inode operations
16302 +#ifndef __AUFS_INODE_H__
16303 +#define __AUFS_INODE_H__
16307 +#include <linux/fsnotify.h>
16308 +#include "rwsem.h"
16312 +struct au_hnotify {
16313 +#ifdef CONFIG_AUFS_HNOTIFY
16314 +#ifdef CONFIG_AUFS_HFSNOTIFY
16315 + /* never use fsnotify_add_vfsmount_mark() */
16316 + struct fsnotify_mark hn_mark;
16318 + struct inode *hn_aufs_inode; /* no get/put */
16320 +} ____cacheline_aligned_in_smp;
16322 +struct au_hinode {
16323 + struct inode *hi_inode;
16324 + aufs_bindex_t hi_id;
16325 +#ifdef CONFIG_AUFS_HNOTIFY
16326 + struct au_hnotify *hi_notify;
16329 + /* reference to the copied-up whiteout with get/put */
16330 + struct dentry *hi_whdentry;
16334 +#define AuIG_HALF_REFRESHED 1
16335 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16336 +#define au_ig_fset(flags, name) \
16337 + do { (flags) |= AuIG_##name; } while (0)
16338 +#define au_ig_fclr(flags, name) \
16339 + do { (flags) &= ~AuIG_##name; } while (0)
16342 + __u32 ig_generation, ig_flags;
16347 + spinlock_t ii_genspin;
16348 + struct au_iigen ii_generation;
16349 + struct super_block *ii_hsb1; /* no get/put */
16351 + struct au_rwsem ii_rwsem;
16352 + aufs_bindex_t ii_bstart, ii_bend;
16354 + struct au_hinode *ii_hinode;
16355 + struct au_vdir *ii_vdir;
16358 +struct au_icntnr {
16359 + struct au_iinfo iinfo;
16360 + struct inode vfs_inode;
16361 +} ____cacheline_aligned_in_smp;
16363 +/* au_pin flags */
16364 +#define AuPin_DI_LOCKED 1
16365 +#define AuPin_MNT_WRITE (1 << 1)
16366 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16367 +#define au_fset_pin(flags, name) \
16368 + do { (flags) |= AuPin_##name; } while (0)
16369 +#define au_fclr_pin(flags, name) \
16370 + do { (flags) &= ~AuPin_##name; } while (0)
16374 + struct dentry *dentry;
16375 + unsigned int udba;
16376 + unsigned char lsc_di, lsc_hi, flags;
16377 + aufs_bindex_t bindex;
16380 + struct dentry *parent;
16381 + struct au_hinode *hdir;
16382 + struct vfsmount *h_mnt;
16384 + /* temporary unlock/relock for copyup */
16385 + struct dentry *h_dentry, *h_parent;
16386 + struct au_branch *br;
16387 + struct task_struct *task;
16390 +void au_pin_hdir_unlock(struct au_pin *p);
16391 +int au_pin_hdir_lock(struct au_pin *p);
16392 +int au_pin_hdir_relock(struct au_pin *p);
16393 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
16394 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16395 +void au_pin_hdir_release(struct au_pin *p);
16397 +/* ---------------------------------------------------------------------- */
16399 +static inline struct au_iinfo *au_ii(struct inode *inode)
16401 + struct au_iinfo *iinfo;
16403 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16404 + if (iinfo->ii_hinode)
16406 + return NULL; /* debugging bad_inode case */
16409 +/* ---------------------------------------------------------------------- */
16412 +struct inode *au_igrab(struct inode *inode);
16413 +int au_refresh_hinode_self(struct inode *inode);
16414 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16415 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16416 + unsigned int d_type, ino_t *ino);
16417 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16418 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16419 + struct inode *inode);
16420 +int au_test_h_perm(struct inode *h_inode, int mask);
16421 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16423 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16424 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16426 +#ifdef CONFIG_AUFS_SHWH
16427 + return au_ino(sb, bindex, h_ino, d_type, ino);
16434 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
16436 +/* au_wr_dir flags */
16437 +#define AuWrDir_ADD_ENTRY 1
16438 +#define AuWrDir_ISDIR (1 << 1)
16439 +#define AuWrDir_TMPFILE (1 << 2)
16440 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16441 +#define au_fset_wrdir(flags, name) \
16442 + do { (flags) |= AuWrDir_##name; } while (0)
16443 +#define au_fclr_wrdir(flags, name) \
16444 + do { (flags) &= ~AuWrDir_##name; } while (0)
16446 +struct au_wr_dir_args {
16447 + aufs_bindex_t force_btgt;
16448 + unsigned char flags;
16450 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16451 + struct au_wr_dir_args *args);
16453 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16454 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16455 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16456 + unsigned int udba, unsigned char flags);
16457 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16458 + unsigned int udba, unsigned char flags) __must_check;
16459 +int au_do_pin(struct au_pin *pin) __must_check;
16460 +void au_unpin(struct au_pin *pin);
16461 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16463 +#define AuIcpup_DID_CPUP 1
16464 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16465 +#define au_fset_icpup(flags, name) \
16466 + do { (flags) |= AuIcpup_##name; } while (0)
16467 +#define au_fclr_icpup(flags, name) \
16468 + do { (flags) &= ~AuIcpup_##name; } while (0)
16470 +struct au_icpup_args {
16471 + unsigned char flags;
16472 + unsigned char pin_flags;
16473 + aufs_bindex_t btgt;
16474 + unsigned int udba;
16475 + struct au_pin pin;
16476 + struct path h_path;
16477 + struct inode *h_inode;
16480 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16481 + struct au_icpup_args *a);
16483 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16486 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16487 + struct dentry *h_parent, int isdir);
16488 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16490 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16491 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16493 +struct vfsub_aopen_args;
16494 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
16495 + struct vfsub_aopen_args *args);
16496 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16497 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16498 + struct dentry *dentry);
16499 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16502 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16503 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16504 + struct dentry *h_parent, int isdir);
16505 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16506 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16509 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16510 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16511 + struct inode *dir, struct dentry *dentry);
16514 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16515 +void au_hiput(struct au_hinode *hinode);
16516 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16517 + struct dentry *h_wh);
16518 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16520 +/* hinode flags */
16521 +#define AuHi_XINO 1
16522 +#define AuHi_HNOTIFY (1 << 1)
16523 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16524 +#define au_fset_hi(flags, name) \
16525 + do { (flags) |= AuHi_##name; } while (0)
16526 +#define au_fclr_hi(flags, name) \
16527 + do { (flags) &= ~AuHi_##name; } while (0)
16529 +#ifndef CONFIG_AUFS_HNOTIFY
16530 +#undef AuHi_HNOTIFY
16531 +#define AuHi_HNOTIFY 0
16534 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16535 + struct inode *h_inode, unsigned int flags);
16537 +void au_update_iigen(struct inode *inode, int half);
16538 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16540 +void au_icntnr_init_once(void *_c);
16541 +int au_iinfo_init(struct inode *inode);
16542 +void au_iinfo_fin(struct inode *inode);
16543 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
16545 +#ifdef CONFIG_PROC_FS
16547 +int au_plink_maint(struct super_block *sb, int flags);
16549 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16550 +int au_plink_maint_enter(struct super_block *sb);
16551 +#ifdef CONFIG_AUFS_DEBUG
16552 +void au_plink_list(struct super_block *sb);
16554 +AuStubVoid(au_plink_list, struct super_block *sb)
16556 +int au_plink_test(struct inode *inode);
16557 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16558 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16559 + struct dentry *h_dentry);
16560 +void au_plink_put(struct super_block *sb, int verbose);
16561 +void au_plink_clean(struct super_block *sb, int verbose);
16562 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16564 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16565 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16566 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16567 +AuStubVoid(au_plink_list, struct super_block *sb);
16568 +AuStubInt0(au_plink_test, struct inode *inode);
16569 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16570 + struct inode *inode, aufs_bindex_t bindex);
16571 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16572 + struct dentry *h_dentry);
16573 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16574 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16575 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16576 +#endif /* CONFIG_PROC_FS */
16578 +#ifdef CONFIG_AUFS_XATTR
16580 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
16581 + unsigned int verbose);
16582 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16583 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
16585 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
16586 + size_t size, int flags);
16587 +int aufs_removexattr(struct dentry *dentry, const char *name);
16589 +/* void au_xattr_init(struct super_block *sb); */
16591 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16592 + int ignore_flags, unsigned int verbose);
16593 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
16596 +#ifdef CONFIG_FS_POSIX_ACL
16597 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16598 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16601 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16608 +struct au_srxattr {
16612 + const char *name;
16613 + const void *value;
16618 + const char *name;
16621 + struct posix_acl *acl;
16626 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg);
16629 +/* ---------------------------------------------------------------------- */
16631 +/* lock subclass for iinfo */
16633 + AuLsc_II_CHILD, /* child first */
16634 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16635 + AuLsc_II_CHILD3, /* copyup dirs */
16636 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16637 + AuLsc_II_PARENT2,
16638 + AuLsc_II_PARENT3, /* copyup dirs */
16639 + AuLsc_II_NEW_CHILD
16643 + * ii_read_lock_child, ii_write_lock_child,
16644 + * ii_read_lock_child2, ii_write_lock_child2,
16645 + * ii_read_lock_child3, ii_write_lock_child3,
16646 + * ii_read_lock_parent, ii_write_lock_parent,
16647 + * ii_read_lock_parent2, ii_write_lock_parent2,
16648 + * ii_read_lock_parent3, ii_write_lock_parent3,
16649 + * ii_read_lock_new_child, ii_write_lock_new_child,
16651 +#define AuReadLockFunc(name, lsc) \
16652 +static inline void ii_read_lock_##name(struct inode *i) \
16654 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16657 +#define AuWriteLockFunc(name, lsc) \
16658 +static inline void ii_write_lock_##name(struct inode *i) \
16660 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16663 +#define AuRWLockFuncs(name, lsc) \
16664 + AuReadLockFunc(name, lsc) \
16665 + AuWriteLockFunc(name, lsc)
16667 +AuRWLockFuncs(child, CHILD);
16668 +AuRWLockFuncs(child2, CHILD2);
16669 +AuRWLockFuncs(child3, CHILD3);
16670 +AuRWLockFuncs(parent, PARENT);
16671 +AuRWLockFuncs(parent2, PARENT2);
16672 +AuRWLockFuncs(parent3, PARENT3);
16673 +AuRWLockFuncs(new_child, NEW_CHILD);
16675 +#undef AuReadLockFunc
16676 +#undef AuWriteLockFunc
16677 +#undef AuRWLockFuncs
16680 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
16682 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
16684 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
16685 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
16686 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
16688 +/* ---------------------------------------------------------------------- */
16690 +static inline void au_icntnr_init(struct au_icntnr *c)
16692 +#ifdef CONFIG_AUFS_DEBUG
16693 + c->vfs_inode.i_mode = 0;
16697 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
16699 + unsigned int gen;
16700 + struct au_iinfo *iinfo;
16702 + iinfo = au_ii(inode);
16703 + spin_lock(&iinfo->ii_genspin);
16705 + *iigen = iinfo->ii_generation;
16706 + gen = iinfo->ii_generation.ig_generation;
16707 + spin_unlock(&iinfo->ii_genspin);
16712 +/* tiny test for inode number */
16713 +/* tmpfs generation is too rough */
16714 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
16716 + struct au_iinfo *iinfo;
16718 + iinfo = au_ii(inode);
16719 + AuRwMustAnyLock(&iinfo->ii_rwsem);
16720 + return !(iinfo->ii_hsb1 == h_inode->i_sb
16721 + && iinfo->ii_higen == h_inode->i_generation);
16724 +static inline void au_iigen_dec(struct inode *inode)
16726 + struct au_iinfo *iinfo;
16728 + iinfo = au_ii(inode);
16729 + spin_lock(&iinfo->ii_genspin);
16730 + iinfo->ii_generation.ig_generation--;
16731 + spin_unlock(&iinfo->ii_genspin);
16734 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
16739 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
16745 +/* ---------------------------------------------------------------------- */
16747 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
16748 + aufs_bindex_t bindex)
16750 + IiMustAnyLock(inode);
16751 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
16754 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
16756 + IiMustAnyLock(inode);
16757 + return au_ii(inode)->ii_bstart;
16760 +static inline aufs_bindex_t au_ibend(struct inode *inode)
16762 + IiMustAnyLock(inode);
16763 + return au_ii(inode)->ii_bend;
16766 +static inline struct au_vdir *au_ivdir(struct inode *inode)
16768 + IiMustAnyLock(inode);
16769 + return au_ii(inode)->ii_vdir;
16772 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
16774 + IiMustAnyLock(inode);
16775 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
16778 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
16780 + IiMustWriteLock(inode);
16781 + au_ii(inode)->ii_bstart = bindex;
16784 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
16786 + IiMustWriteLock(inode);
16787 + au_ii(inode)->ii_bend = bindex;
16790 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
16792 + IiMustWriteLock(inode);
16793 + au_ii(inode)->ii_vdir = vdir;
16796 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
16798 + IiMustAnyLock(inode);
16799 + return au_ii(inode)->ii_hinode + bindex;
16802 +/* ---------------------------------------------------------------------- */
16804 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
16807 + return pin->parent;
16811 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
16813 + if (pin && pin->hdir)
16814 + return pin->hdir->hi_inode;
16818 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
16821 + return pin->hdir;
16825 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
16828 + pin->dentry = dentry;
16831 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
16832 + unsigned char lflag)
16836 + au_fset_pin(pin->flags, DI_LOCKED);
16838 + au_fclr_pin(pin->flags, DI_LOCKED);
16842 +#if 0 /* reserved */
16843 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
16846 + dput(pin->parent);
16847 + pin->parent = dget(parent);
16852 +/* ---------------------------------------------------------------------- */
16855 +#ifdef CONFIG_AUFS_HNOTIFY
16856 +struct au_hnotify_op {
16857 + void (*ctl)(struct au_hinode *hinode, int do_set);
16858 + int (*alloc)(struct au_hinode *hinode);
16861 + * if it returns true, the the caller should free hinode->hi_notify,
16862 + * otherwise ->free() frees it.
16864 + int (*free)(struct au_hinode *hinode,
16865 + struct au_hnotify *hn) __must_check;
16867 + void (*fin)(void);
16868 + int (*init)(void);
16870 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
16871 + void (*fin_br)(struct au_branch *br);
16872 + int (*init_br)(struct au_branch *br, int perm);
16876 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
16877 +void au_hn_free(struct au_hinode *hinode);
16878 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
16879 +void au_hn_reset(struct inode *inode, unsigned int flags);
16880 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
16881 + struct qstr *h_child_qstr, struct inode *h_child_inode);
16882 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
16883 +int au_hnotify_init_br(struct au_branch *br, int perm);
16884 +void au_hnotify_fin_br(struct au_branch *br);
16885 +int __init au_hnotify_init(void);
16886 +void au_hnotify_fin(void);
16889 +extern const struct au_hnotify_op au_hnotify_op;
16892 +void au_hn_init(struct au_hinode *hinode)
16894 + hinode->hi_notify = NULL;
16897 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
16899 + return hinode->hi_notify;
16903 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
16904 + struct au_hinode *hinode __maybe_unused,
16905 + struct inode *inode __maybe_unused)
16906 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
16907 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
16908 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
16909 + int do_set __maybe_unused)
16910 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
16911 + unsigned int flags __maybe_unused)
16912 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
16913 + struct au_branch *br __maybe_unused,
16914 + int perm __maybe_unused)
16915 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
16916 + int perm __maybe_unused)
16917 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
16918 +AuStubInt0(__init au_hnotify_init, void)
16919 +AuStubVoid(au_hnotify_fin, void)
16920 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
16921 +#endif /* CONFIG_AUFS_HNOTIFY */
16923 +static inline void au_hn_suspend(struct au_hinode *hdir)
16925 + au_hn_ctl(hdir, /*do_set*/0);
16928 +static inline void au_hn_resume(struct au_hinode *hdir)
16930 + au_hn_ctl(hdir, /*do_set*/1);
16933 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
16935 + mutex_lock(&hdir->hi_inode->i_mutex);
16936 + au_hn_suspend(hdir);
16939 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
16940 + unsigned int sc __maybe_unused)
16942 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
16943 + au_hn_suspend(hdir);
16946 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
16948 + au_hn_resume(hdir);
16949 + mutex_unlock(&hdir->hi_inode->i_mutex);
16952 +#endif /* __KERNEL__ */
16953 +#endif /* __AUFS_INODE_H__ */
16954 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
16955 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
16956 +++ linux/fs/aufs/ioctl.c 2015-06-28 17:35:44.348050491 +0200
16959 + * Copyright (C) 2005-2015 Junjiro R. Okajima
16961 + * This program, aufs is free software; you can redistribute it and/or modify
16962 + * it under the terms of the GNU General Public License as published by
16963 + * the Free Software Foundation; either version 2 of the License, or
16964 + * (at your option) any later version.
16966 + * This program is distributed in the hope that it will be useful,
16967 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16968 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16969 + * GNU General Public License for more details.
16971 + * You should have received a copy of the GNU General Public License
16972 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16977 + * plink-management and readdir in userspace.
16978 + * assist the pathconf(3) wrapper library.
16980 + * File-based Hierarchical Storage Management.
16983 +#include <linux/compat.h>
16984 +#include <linux/file.h>
16987 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
16990 + aufs_bindex_t wbi, bindex, bend;
16991 + struct file *h_file;
16992 + struct super_block *sb;
16993 + struct dentry *root;
16994 + struct au_branch *br;
16995 + struct aufs_wbr_fd wbrfd = {
16996 + .oflags = au_dir_roflags,
16999 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17000 + | O_NOATIME | O_CLOEXEC;
17002 + AuDebugOn(wbrfd.oflags & ~valid);
17005 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17006 + if (unlikely(err)) {
17012 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17013 + wbrfd.oflags |= au_dir_roflags;
17014 + AuDbg("0%o\n", wbrfd.oflags);
17015 + if (unlikely(wbrfd.oflags & ~valid))
17019 + fd = get_unused_fd_flags(0);
17021 + if (unlikely(fd < 0))
17024 + h_file = ERR_PTR(-EINVAL);
17027 + sb = path->dentry->d_sb;
17028 + root = sb->s_root;
17029 + aufs_read_lock(root, AuLock_IR);
17030 + bend = au_sbend(sb);
17031 + if (wbrfd.brid >= 0) {
17032 + wbi = au_br_index(sb, wbrfd.brid);
17033 + if (unlikely(wbi < 0 || wbi > bend))
17037 + h_file = ERR_PTR(-ENOENT);
17038 + br = au_sbr(sb, wbi);
17039 + if (!au_br_writable(br->br_perm)) {
17043 + bindex = wbi + 1;
17045 + for (; bindex <= bend; bindex++) {
17046 + br = au_sbr(sb, bindex);
17047 + if (au_br_writable(br->br_perm)) {
17049 + br = au_sbr(sb, wbi);
17054 + AuDbg("wbi %d\n", wbi);
17056 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17060 + aufs_read_unlock(root, AuLock_IR);
17061 + err = PTR_ERR(h_file);
17062 + if (IS_ERR(h_file))
17065 + atomic_dec(&br->br_count); /* cf. au_h_open() */
17066 + fd_install(fd, h_file);
17068 + goto out; /* success */
17071 + put_unused_fd(fd);
17077 +/* ---------------------------------------------------------------------- */
17079 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17082 + struct dentry *dentry;
17085 + case AUFS_CTL_RDU:
17086 + case AUFS_CTL_RDU_INO:
17087 + err = au_rdu_ioctl(file, cmd, arg);
17090 + case AUFS_CTL_WBR_FD:
17091 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17094 + case AUFS_CTL_IBUSY:
17095 + err = au_ibusy_ioctl(file, arg);
17098 + case AUFS_CTL_BRINFO:
17099 + err = au_brinfo_ioctl(file, arg);
17102 + case AUFS_CTL_FHSM_FD:
17103 + dentry = file->f_path.dentry;
17104 + if (IS_ROOT(dentry))
17105 + err = au_fhsm_fd(dentry->d_sb, arg);
17111 + /* do not call the lower */
17112 + AuDbg("0x%x\n", cmd);
17120 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17125 + case AUFS_CTL_MVDOWN:
17126 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17129 + case AUFS_CTL_WBR_FD:
17130 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17134 + /* do not call the lower */
17135 + AuDbg("0x%x\n", cmd);
17143 +#ifdef CONFIG_COMPAT
17144 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17145 + unsigned long arg)
17150 + case AUFS_CTL_RDU:
17151 + case AUFS_CTL_RDU_INO:
17152 + err = au_rdu_compat_ioctl(file, cmd, arg);
17155 + case AUFS_CTL_IBUSY:
17156 + err = au_ibusy_compat_ioctl(file, arg);
17159 + case AUFS_CTL_BRINFO:
17160 + err = au_brinfo_compat_ioctl(file, arg);
17164 + err = aufs_ioctl_dir(file, cmd, arg);
17171 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17172 + unsigned long arg)
17174 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17177 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17178 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17179 +++ linux/fs/aufs/i_op_add.c 2015-06-28 17:36:09.025073697 +0200
17182 + * Copyright (C) 2005-2015 Junjiro R. Okajima
17184 + * This program, aufs is free software; you can redistribute it and/or modify
17185 + * it under the terms of the GNU General Public License as published by
17186 + * the Free Software Foundation; either version 2 of the License, or
17187 + * (at your option) any later version.
17189 + * This program is distributed in the hope that it will be useful,
17190 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17191 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17192 + * GNU General Public License for more details.
17194 + * You should have received a copy of the GNU General Public License
17195 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17199 + * inode operations (add entry)
17205 + * final procedure of adding a new entry, except link(2).
17206 + * remove whiteout, instantiate, copyup the parent dir's times and size
17207 + * and update version.
17208 + * if it failed, re-create the removed whiteout.
17210 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17211 + struct dentry *wh_dentry, struct dentry *dentry)
17214 + aufs_bindex_t bwh;
17215 + struct path h_path;
17216 + struct super_block *sb;
17217 + struct inode *inode, *h_dir;
17218 + struct dentry *wh;
17223 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17224 + IMustLock(h_dir);
17225 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17226 + bwh = au_dbwh(dentry);
17227 + h_path.dentry = wh_dentry;
17228 + h_path.mnt = au_sbr_mnt(sb, bindex);
17229 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17231 + if (unlikely(err))
17235 + inode = au_new_inode(dentry, /*must_new*/1);
17236 + if (!IS_ERR(inode)) {
17237 + d_instantiate(dentry, inode);
17238 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17240 + au_dir_ts(dir, bindex);
17241 + dir->i_version++;
17242 + au_fhsm_wrote(sb, bindex, /*force*/0);
17243 + return 0; /* success */
17246 + err = PTR_ERR(inode);
17251 + /* dir inode is locked */
17252 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17253 + rerr = PTR_ERR(wh);
17254 + if (IS_ERR(wh)) {
17255 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17256 + dentry, err, rerr);
17265 +static int au_d_may_add(struct dentry *dentry)
17270 + if (unlikely(d_unhashed(dentry)))
17272 + if (unlikely(d_really_is_positive(dentry)))
17278 + * simple tests for the adding inode operations.
17279 + * following the checks in vfs, plus the parent-child relationship.
17281 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17282 + struct dentry *h_parent, int isdir)
17286 + struct dentry *h_dentry;
17287 + struct inode *h_inode;
17289 + err = -ENAMETOOLONG;
17290 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17293 + h_dentry = au_h_dptr(dentry, bindex);
17294 + if (d_really_is_negative(dentry)) {
17296 + if (unlikely(d_is_positive(h_dentry)))
17299 + /* rename(2) case */
17301 + if (unlikely(d_is_negative(h_dentry)))
17303 + h_inode = d_inode(h_dentry);
17304 + if (unlikely(!h_inode->i_nlink))
17307 + h_mode = h_inode->i_mode;
17310 + if (unlikely(S_ISDIR(h_mode)))
17312 + } else if (unlikely(!S_ISDIR(h_mode))) {
17319 + /* expected parent dir is locked */
17320 + if (unlikely(h_parent != h_dentry->d_parent))
17329 + * initial procedure of adding a new entry.
17330 + * prepare writable branch and the parent dir, lock it,
17331 + * and lookup whiteout for the new entry.
17333 +static struct dentry*
17334 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17335 + struct dentry *src_dentry, struct au_pin *pin,
17336 + struct au_wr_dir_args *wr_dir_args)
17338 + struct dentry *wh_dentry, *h_parent;
17339 + struct super_block *sb;
17340 + struct au_branch *br;
17342 + unsigned int udba;
17343 + aufs_bindex_t bcpup;
17345 + AuDbg("%pd\n", dentry);
17347 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17349 + wh_dentry = ERR_PTR(err);
17350 + if (unlikely(err < 0))
17353 + sb = dentry->d_sb;
17354 + udba = au_opt_udba(sb);
17355 + err = au_pin(pin, dentry, bcpup, udba,
17356 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17357 + wh_dentry = ERR_PTR(err);
17358 + if (unlikely(err))
17361 + h_parent = au_pinned_h_parent(pin);
17362 + if (udba != AuOpt_UDBA_NONE
17363 + && au_dbstart(dentry) == bcpup)
17364 + err = au_may_add(dentry, bcpup, h_parent,
17365 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17366 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17367 + err = -ENAMETOOLONG;
17368 + wh_dentry = ERR_PTR(err);
17369 + if (unlikely(err))
17372 + br = au_sbr(sb, bcpup);
17374 + struct path tmp = {
17375 + .dentry = h_parent,
17376 + .mnt = au_br_mnt(br)
17378 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17381 + wh_dentry = NULL;
17382 + if (bcpup != au_dbwh(dentry))
17383 + goto out; /* success */
17386 + * ENAMETOOLONG here means that if we allowed create such name, then it
17387 + * would not be able to removed in the future. So we don't allow such
17388 + * name here and we don't handle ENAMETOOLONG differently here.
17390 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17393 + if (IS_ERR(wh_dentry))
17396 + return wh_dentry;
17399 +/* ---------------------------------------------------------------------- */
17401 +enum { Mknod, Symlink, Creat };
17402 +struct simple_arg {
17409 + struct vfsub_aopen_args *aopen;
17412 + const char *symname;
17421 +static int add_simple(struct inode *dir, struct dentry *dentry,
17422 + struct simple_arg *arg)
17425 + aufs_bindex_t bstart;
17426 + unsigned char created;
17427 + const unsigned char try_aopen
17428 + = (arg->type == Creat && arg->u.c.try_aopen);
17429 + struct dentry *wh_dentry, *parent;
17430 + struct inode *h_dir;
17431 + struct super_block *sb;
17432 + struct au_branch *br;
17433 + /* to reuduce stack size */
17435 + struct au_dtime dt;
17436 + struct au_pin pin;
17437 + struct path h_path;
17438 + struct au_wr_dir_args wr_dir_args;
17441 + AuDbg("%pd\n", dentry);
17445 + a = kmalloc(sizeof(*a), GFP_NOFS);
17446 + if (unlikely(!a))
17448 + a->wr_dir_args.force_btgt = -1;
17449 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17451 + parent = dentry->d_parent; /* dir inode is locked */
17452 + if (!try_aopen) {
17453 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17454 + if (unlikely(err))
17457 + err = au_d_may_add(dentry);
17458 + if (unlikely(err))
17461 + di_write_lock_parent(parent);
17462 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17463 + &a->pin, &a->wr_dir_args);
17464 + err = PTR_ERR(wh_dentry);
17465 + if (IS_ERR(wh_dentry))
17468 + bstart = au_dbstart(dentry);
17469 + sb = dentry->d_sb;
17470 + br = au_sbr(sb, bstart);
17471 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17472 + a->h_path.mnt = au_br_mnt(br);
17473 + h_dir = au_pinned_h_dir(&a->pin);
17474 + switch (arg->type) {
17477 + if (!try_aopen || !h_dir->i_op->atomic_open)
17478 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17479 + arg->u.c.want_excl);
17481 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
17482 + arg->u.c.aopen, br);
17485 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17488 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17496 + err = epilog(dir, bstart, wh_dentry, dentry);
17499 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
17500 + /* no delegation since it is just created */
17501 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17504 + AuIOErr("%pd revert failure(%d, %d)\n",
17505 + dentry, err, rerr);
17508 + au_dtime_revert(&a->dt);
17511 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
17512 + *arg->u.c.aopen->opened |= FILE_CREATED;
17514 + au_unpin(&a->pin);
17519 + di_write_unlock(parent);
17521 + if (unlikely(err)) {
17522 + au_update_dbstart(dentry);
17526 + aufs_read_unlock(dentry, AuLock_DW);
17533 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17536 + struct simple_arg arg = {
17543 + return add_simple(dir, dentry, &arg);
17546 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17548 + struct simple_arg arg = {
17550 + .u.s.symname = symname
17552 + return add_simple(dir, dentry, &arg);
17555 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17558 + struct simple_arg arg = {
17562 + .want_excl = want_excl
17565 + return add_simple(dir, dentry, &arg);
17568 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17569 + struct vfsub_aopen_args *aopen_args)
17571 + struct simple_arg arg = {
17574 + .mode = aopen_args->create_mode,
17575 + .want_excl = aopen_args->open_flag & O_EXCL,
17576 + .try_aopen = true,
17577 + .aopen = aopen_args
17580 + return add_simple(dir, dentry, &arg);
17583 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17586 + aufs_bindex_t bindex;
17587 + struct super_block *sb;
17588 + struct dentry *parent, *h_parent, *h_dentry;
17589 + struct inode *h_dir, *inode;
17590 + struct vfsmount *h_mnt;
17591 + struct au_wr_dir_args wr_dir_args = {
17592 + .force_btgt = -1,
17593 + .flags = AuWrDir_TMPFILE
17596 + /* copy-up may happen */
17597 + mutex_lock(&dir->i_mutex);
17600 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17601 + if (unlikely(err))
17604 + err = au_di_init(dentry);
17605 + if (unlikely(err))
17609 + parent = d_find_any_alias(dir);
17610 + AuDebugOn(!parent);
17611 + di_write_lock_parent(parent);
17612 + if (unlikely(d_inode(parent) != dir))
17615 + err = au_digen_test(parent, au_sigen(sb));
17616 + if (unlikely(err))
17619 + bindex = au_dbstart(parent);
17620 + au_set_dbstart(dentry, bindex);
17621 + au_set_dbend(dentry, bindex);
17622 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17624 + if (unlikely(err < 0))
17627 + err = -EOPNOTSUPP;
17628 + h_dir = au_h_iptr(dir, bindex);
17629 + if (unlikely(!h_dir->i_op->tmpfile))
17632 + h_mnt = au_sbr_mnt(sb, bindex);
17633 + err = vfsub_mnt_want_write(h_mnt);
17634 + if (unlikely(err))
17637 + h_parent = au_h_dptr(parent, bindex);
17638 + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC);
17639 + if (unlikely(err))
17643 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17644 + if (unlikely(!h_dentry))
17647 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17648 + if (unlikely(err))
17651 + au_set_dbstart(dentry, bindex);
17652 + au_set_dbend(dentry, bindex);
17653 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17654 + inode = au_new_inode(dentry, /*must_new*/1);
17655 + if (IS_ERR(inode)) {
17656 + err = PTR_ERR(inode);
17657 + au_set_h_dptr(dentry, bindex, NULL);
17658 + au_set_dbstart(dentry, -1);
17659 + au_set_dbend(dentry, -1);
17661 + if (!inode->i_nlink)
17662 + set_nlink(inode, 1);
17663 + d_tmpfile(dentry, inode);
17664 + au_di(dentry)->di_tmpfile = 1;
17666 + /* update without i_mutex */
17667 + if (au_ibstart(dir) == au_dbstart(dentry))
17668 + au_cpup_attr_timesizes(dir);
17674 + vfsub_mnt_drop_write(h_mnt);
17676 + di_write_unlock(parent);
17678 + di_write_unlock(dentry);
17681 + /* verbose coding for lock class name */
17682 + au_rw_class(&au_di(dentry)->di_rwsem,
17683 + au_lc_key + AuLcNonDir_DIINFO);
17688 + au_di_fin(dentry);
17689 + dentry->d_fsdata = NULL;
17692 + si_read_unlock(sb);
17694 + mutex_unlock(&dir->i_mutex);
17698 +/* ---------------------------------------------------------------------- */
17700 +struct au_link_args {
17701 + aufs_bindex_t bdst, bsrc;
17702 + struct au_pin pin;
17703 + struct path h_path;
17704 + struct dentry *src_parent, *parent;
17707 +static int au_cpup_before_link(struct dentry *src_dentry,
17708 + struct au_link_args *a)
17711 + struct dentry *h_src_dentry;
17712 + struct au_cp_generic cpg = {
17713 + .dentry = src_dentry,
17718 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
17721 + di_read_lock_parent(a->src_parent, AuLock_IR);
17722 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
17723 + if (unlikely(err))
17726 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
17727 + err = au_pin(&a->pin, src_dentry, a->bdst,
17728 + au_opt_udba(src_dentry->d_sb),
17729 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17730 + if (unlikely(err))
17733 + err = au_sio_cpup_simple(&cpg);
17734 + au_unpin(&a->pin);
17737 + di_read_unlock(a->src_parent, AuLock_IR);
17741 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
17742 + struct au_link_args *a)
17745 + unsigned char plink;
17746 + aufs_bindex_t bend;
17747 + struct dentry *h_src_dentry;
17748 + struct inode *h_inode, *inode, *delegated;
17749 + struct super_block *sb;
17750 + struct file *h_file;
17754 + sb = src_dentry->d_sb;
17755 + inode = d_inode(src_dentry);
17756 + if (au_ibstart(inode) <= a->bdst)
17757 + h_inode = au_h_iptr(inode, a->bdst);
17758 + if (!h_inode || !h_inode->i_nlink) {
17759 + /* copyup src_dentry as the name of dentry. */
17760 + bend = au_dbend(dentry);
17761 + if (bend < a->bsrc)
17762 + au_set_dbend(dentry, a->bsrc);
17763 + au_set_h_dptr(dentry, a->bsrc,
17764 + dget(au_h_dptr(src_dentry, a->bsrc)));
17765 + dget(a->h_path.dentry);
17766 + au_set_h_dptr(dentry, a->bdst, NULL);
17767 + AuDbg("temporary d_inode...\n");
17768 + spin_lock(&dentry->d_lock);
17769 + dentry->d_inode = d_inode(src_dentry); /* tmp */
17770 + spin_unlock(&dentry->d_lock);
17771 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
17772 + if (IS_ERR(h_file))
17773 + err = PTR_ERR(h_file);
17775 + struct au_cp_generic cpg = {
17776 + .dentry = dentry,
17781 + .flags = AuCpup_KEEPLINO
17783 + err = au_sio_cpup_simple(&cpg);
17784 + au_h_open_post(dentry, a->bsrc, h_file);
17786 + dput(a->h_path.dentry);
17787 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17789 + au_set_h_dptr(dentry, a->bdst,
17790 + a->h_path.dentry);
17792 + spin_lock(&dentry->d_lock);
17793 + dentry->d_inode = NULL; /* restore */
17794 + spin_unlock(&dentry->d_lock);
17795 + AuDbg("temporary d_inode...done\n");
17796 + au_set_h_dptr(dentry, a->bsrc, NULL);
17797 + au_set_dbend(dentry, bend);
17799 + /* the inode of src_dentry already exists on a.bdst branch */
17800 + h_src_dentry = d_find_alias(h_inode);
17801 + if (!h_src_dentry && au_plink_test(inode)) {
17803 + h_src_dentry = au_plink_lkup(inode, a->bdst);
17804 + err = PTR_ERR(h_src_dentry);
17805 + if (IS_ERR(h_src_dentry))
17808 + if (unlikely(d_is_negative(h_src_dentry))) {
17809 + dput(h_src_dentry);
17810 + h_src_dentry = NULL;
17814 + if (h_src_dentry) {
17815 + delegated = NULL;
17816 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17817 + &a->h_path, &delegated);
17818 + if (unlikely(err == -EWOULDBLOCK)) {
17819 + pr_warn("cannot retry for NFSv4 delegation"
17820 + " for an internal link\n");
17823 + dput(h_src_dentry);
17825 + AuIOErr("no dentry found for hi%lu on b%d\n",
17826 + h_inode->i_ino, a->bdst);
17831 + if (!err && !plink)
17832 + au_plink_append(inode, a->bdst, a->h_path.dentry);
17839 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17840 + struct dentry *dentry)
17843 + struct au_dtime dt;
17844 + struct au_link_args *a;
17845 + struct dentry *wh_dentry, *h_src_dentry;
17846 + struct inode *inode, *delegated;
17847 + struct super_block *sb;
17848 + struct au_wr_dir_args wr_dir_args = {
17849 + /* .force_btgt = -1, */
17850 + .flags = AuWrDir_ADD_ENTRY
17854 + inode = d_inode(src_dentry);
17855 + IMustLock(inode);
17858 + a = kzalloc(sizeof(*a), GFP_NOFS);
17859 + if (unlikely(!a))
17862 + a->parent = dentry->d_parent; /* dir inode is locked */
17863 + err = aufs_read_and_write_lock2(dentry, src_dentry,
17864 + AuLock_NOPLM | AuLock_GEN);
17865 + if (unlikely(err))
17867 + err = au_d_linkable(src_dentry);
17868 + if (unlikely(err))
17870 + err = au_d_may_add(dentry);
17871 + if (unlikely(err))
17874 + a->src_parent = dget_parent(src_dentry);
17875 + wr_dir_args.force_btgt = au_ibstart(inode);
17877 + di_write_lock_parent(a->parent);
17878 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
17879 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
17881 + err = PTR_ERR(wh_dentry);
17882 + if (IS_ERR(wh_dentry))
17886 + sb = dentry->d_sb;
17887 + a->bdst = au_dbstart(dentry);
17888 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17889 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
17890 + a->bsrc = au_ibstart(inode);
17891 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17892 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
17893 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
17894 + if (!h_src_dentry) {
17895 + a->bsrc = au_dbstart(src_dentry);
17896 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17897 + AuDebugOn(!h_src_dentry);
17898 + } else if (IS_ERR(h_src_dentry)) {
17899 + err = PTR_ERR(h_src_dentry);
17903 + if (au_opt_test(au_mntflags(sb), PLINK)) {
17904 + if (a->bdst < a->bsrc
17905 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
17906 + err = au_cpup_or_link(src_dentry, dentry, a);
17908 + delegated = NULL;
17909 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17910 + &a->h_path, &delegated);
17911 + if (unlikely(err == -EWOULDBLOCK)) {
17912 + pr_warn("cannot retry for NFSv4 delegation"
17913 + " for an internal link\n");
17917 + dput(h_src_dentry);
17920 + * copyup src_dentry to the branch we process,
17921 + * and then link(2) to it.
17923 + dput(h_src_dentry);
17924 + if (a->bdst < a->bsrc
17925 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
17926 + au_unpin(&a->pin);
17927 + di_write_unlock(a->parent);
17928 + err = au_cpup_before_link(src_dentry, a);
17929 + di_write_lock_parent(a->parent);
17931 + err = au_pin(&a->pin, dentry, a->bdst,
17933 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17934 + if (unlikely(err))
17938 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
17940 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
17941 + delegated = NULL;
17942 + err = vfsub_link(h_src_dentry,
17943 + au_pinned_h_dir(&a->pin),
17944 + &a->h_path, &delegated);
17945 + if (unlikely(err == -EWOULDBLOCK)) {
17946 + pr_warn("cannot retry"
17947 + " for NFSv4 delegation"
17948 + " for an internal link\n");
17954 + if (unlikely(err))
17958 + a->h_path.dentry = wh_dentry;
17959 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
17961 + if (unlikely(err))
17965 + au_dir_ts(dir, a->bdst);
17966 + dir->i_version++;
17967 + inc_nlink(inode);
17968 + inode->i_ctime = dir->i_ctime;
17969 + d_instantiate(dentry, au_igrab(inode));
17970 + if (d_unhashed(a->h_path.dentry))
17971 + /* some filesystem calls d_drop() */
17973 + /* some filesystems consume an inode even hardlink */
17974 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
17975 + goto out_unpin; /* success */
17978 + /* no delegation since it is just created */
17979 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
17980 + /*delegated*/NULL, /*force*/0);
17981 + if (unlikely(rerr)) {
17982 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
17985 + au_dtime_revert(&dt);
17987 + au_unpin(&a->pin);
17991 + di_write_unlock(a->parent);
17992 + dput(a->src_parent);
17994 + if (unlikely(err)) {
17995 + au_update_dbstart(dentry);
17998 + aufs_read_and_write_unlock2(dentry, src_dentry);
18006 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18009 + aufs_bindex_t bindex;
18010 + unsigned char diropq;
18011 + struct path h_path;
18012 + struct dentry *wh_dentry, *parent, *opq_dentry;
18013 + struct mutex *h_mtx;
18014 + struct super_block *sb;
18016 + struct au_pin pin;
18017 + struct au_dtime dt;
18018 + } *a; /* reduce the stack usage */
18019 + struct au_wr_dir_args wr_dir_args = {
18020 + .force_btgt = -1,
18021 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18027 + a = kmalloc(sizeof(*a), GFP_NOFS);
18028 + if (unlikely(!a))
18031 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18032 + if (unlikely(err))
18034 + err = au_d_may_add(dentry);
18035 + if (unlikely(err))
18038 + parent = dentry->d_parent; /* dir inode is locked */
18039 + di_write_lock_parent(parent);
18040 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18041 + &a->pin, &wr_dir_args);
18042 + err = PTR_ERR(wh_dentry);
18043 + if (IS_ERR(wh_dentry))
18046 + sb = dentry->d_sb;
18047 + bindex = au_dbstart(dentry);
18048 + h_path.dentry = au_h_dptr(dentry, bindex);
18049 + h_path.mnt = au_sbr_mnt(sb, bindex);
18050 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18051 + if (unlikely(err))
18054 + /* make the dir opaque */
18056 + h_mtx = &d_inode(h_path.dentry)->i_mutex;
18058 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18059 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18060 + opq_dentry = au_diropq_create(dentry, bindex);
18061 + mutex_unlock(h_mtx);
18062 + err = PTR_ERR(opq_dentry);
18063 + if (IS_ERR(opq_dentry))
18065 + dput(opq_dentry);
18069 + err = epilog(dir, bindex, wh_dentry, dentry);
18072 + goto out_unpin; /* success */
18077 + AuLabel(revert opq);
18078 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18079 + rerr = au_diropq_remove(dentry, bindex);
18080 + mutex_unlock(h_mtx);
18082 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18083 + dentry, err, rerr);
18089 + AuLabel(revert dir);
18090 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18092 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18093 + dentry, err, rerr);
18096 + au_dtime_revert(&a->dt);
18098 + au_unpin(&a->pin);
18101 + di_write_unlock(parent);
18103 + if (unlikely(err)) {
18104 + au_update_dbstart(dentry);
18107 + aufs_read_unlock(dentry, AuLock_DW);
18113 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18114 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18115 +++ linux/fs/aufs/i_op.c 2015-06-28 17:36:09.025073697 +0200
18118 + * Copyright (C) 2005-2015 Junjiro R. Okajima
18120 + * This program, aufs is free software; you can redistribute it and/or modify
18121 + * it under the terms of the GNU General Public License as published by
18122 + * the Free Software Foundation; either version 2 of the License, or
18123 + * (at your option) any later version.
18125 + * This program is distributed in the hope that it will be useful,
18126 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18127 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18128 + * GNU General Public License for more details.
18130 + * You should have received a copy of the GNU General Public License
18131 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18135 + * inode operations (except add/del/rename)
18138 +#include <linux/device_cgroup.h>
18139 +#include <linux/fs_stack.h>
18140 +#include <linux/mm.h>
18141 +#include <linux/namei.h>
18142 +#include <linux/security.h>
18145 +static int h_permission(struct inode *h_inode, int mask,
18146 + struct vfsmount *h_mnt, int brperm)
18149 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18152 + if ((write_mask && IS_IMMUTABLE(h_inode))
18153 + || ((mask & MAY_EXEC)
18154 + && S_ISREG(h_inode->i_mode)
18155 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
18156 + || !(h_inode->i_mode & S_IXUGO))))
18160 + * - skip the lower fs test in the case of write to ro branch.
18161 + * - nfs dir permission write check is optimized, but a policy for
18162 + * link/rename requires a real check.
18163 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18164 + * in this case, generic_permission() returns -EOPNOTSUPP.
18166 + if ((write_mask && !au_br_writable(brperm))
18167 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18168 + && write_mask && !(mask & MAY_READ))
18169 + || !h_inode->i_op->permission) {
18170 + /* AuLabel(generic_permission); */
18171 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18172 + err = generic_permission(h_inode, mask);
18173 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18174 + err = h_inode->i_op->permission(h_inode, mask);
18177 + /* AuLabel(h_inode->permission); */
18178 + err = h_inode->i_op->permission(h_inode, mask);
18183 + err = devcgroup_inode_permission(h_inode, mask);
18185 + err = security_inode_permission(h_inode, mask);
18189 + /* todo: do we need to call ima_path_check()? */
18190 + struct path h_path = {
18194 + err = ima_path_check(&h_path,
18195 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18196 + IMA_COUNT_LEAVE);
18204 +static int aufs_permission(struct inode *inode, int mask)
18207 + aufs_bindex_t bindex, bend;
18208 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18209 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18210 + struct inode *h_inode;
18211 + struct super_block *sb;
18212 + struct au_branch *br;
18214 + /* todo: support rcu-walk? */
18215 + if (mask & MAY_NOT_BLOCK)
18218 + sb = inode->i_sb;
18219 + si_read_lock(sb, AuLock_FLUSH);
18220 + ii_read_lock_child(inode);
18222 + err = au_iigen_test(inode, au_sigen(sb));
18223 + if (unlikely(err))
18229 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18230 + err = au_busy_or_stale();
18231 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18232 + if (unlikely(!h_inode
18233 + || (h_inode->i_mode & S_IFMT)
18234 + != (inode->i_mode & S_IFMT)))
18238 + bindex = au_ibstart(inode);
18239 + br = au_sbr(sb, bindex);
18240 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
18243 + && !special_file(h_inode->i_mode)) {
18244 + /* test whether the upper writable branch exists */
18246 + for (; bindex >= 0; bindex--)
18247 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18255 + /* non-write to dir */
18257 + bend = au_ibend(inode);
18258 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
18259 + h_inode = au_h_iptr(inode, bindex);
18261 + err = au_busy_or_stale();
18262 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18265 + br = au_sbr(sb, bindex);
18266 + err = h_permission(h_inode, mask, au_br_mnt(br),
18272 + ii_read_unlock(inode);
18273 + si_read_unlock(sb);
18277 +/* ---------------------------------------------------------------------- */
18279 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18280 + unsigned int flags)
18282 + struct dentry *ret, *parent;
18283 + struct inode *inode;
18284 + struct super_block *sb;
18285 + int err, npositive;
18289 + /* todo: support rcu-walk? */
18290 + ret = ERR_PTR(-ECHILD);
18291 + if (flags & LOOKUP_RCU)
18294 + ret = ERR_PTR(-ENAMETOOLONG);
18295 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18299 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18300 + ret = ERR_PTR(err);
18301 + if (unlikely(err))
18304 + err = au_di_init(dentry);
18305 + ret = ERR_PTR(err);
18306 + if (unlikely(err))
18310 + npositive = 0; /* suppress a warning */
18311 + parent = dentry->d_parent; /* dir inode is locked */
18312 + di_read_lock_parent(parent, AuLock_IR);
18313 + err = au_alive_dir(parent);
18315 + err = au_digen_test(parent, au_sigen(sb));
18317 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
18321 + di_read_unlock(parent, AuLock_IR);
18322 + ret = ERR_PTR(err);
18323 + if (unlikely(err < 0))
18327 + inode = au_new_inode(dentry, /*must_new*/0);
18328 + if (IS_ERR(inode)) {
18329 + ret = (void *)inode;
18336 + atomic_inc(&inode->i_count);
18337 + ret = d_splice_alias(inode, dentry);
18339 + if (unlikely(d_need_lookup(dentry))) {
18340 + spin_lock(&dentry->d_lock);
18341 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18342 + spin_unlock(&dentry->d_lock);
18346 + if (!IS_ERR(ret)) {
18348 + if (ret && ret != dentry)
18349 + ii_write_unlock(inode);
18351 + ii_write_unlock(inode);
18358 + di_write_unlock(dentry);
18360 + /* verbose coding for lock class name */
18361 + if (unlikely(S_ISLNK(inode->i_mode)))
18362 + au_rw_class(&au_di(dentry)->di_rwsem,
18363 + au_lc_key + AuLcSymlink_DIINFO);
18364 + else if (unlikely(S_ISDIR(inode->i_mode)))
18365 + au_rw_class(&au_di(dentry)->di_rwsem,
18366 + au_lc_key + AuLcDir_DIINFO);
18367 + else /* likely */
18368 + au_rw_class(&au_di(dentry)->di_rwsem,
18369 + au_lc_key + AuLcNonDir_DIINFO);
18372 + si_read_unlock(sb);
18377 +/* ---------------------------------------------------------------------- */
18379 +struct aopen_node {
18380 + struct hlist_node hlist;
18381 + struct file *file, *h_file;
18384 +static int au_do_aopen(struct inode *inode, struct file *file)
18386 + struct au_sphlhead *aopen;
18387 + struct aopen_node *node;
18388 + struct au_do_open_args args = {
18390 + .open = au_do_open_nondir
18393 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18394 + spin_lock(&aopen->spin);
18395 + hlist_for_each_entry(node, &aopen->head, hlist)
18396 + if (node->file == file) {
18397 + args.h_file = node->h_file;
18400 + spin_unlock(&aopen->spin);
18401 + /* AuDebugOn(!args.h_file); */
18403 + return au_do_open(file, &args);
18406 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18407 + struct file *file, unsigned int open_flag,
18408 + umode_t create_mode, int *opened)
18410 + int err, h_opened = *opened;
18411 + struct dentry *parent;
18412 + struct dentry *d;
18413 + struct au_sphlhead *aopen;
18414 + struct vfsub_aopen_args args = {
18415 + .open_flag = open_flag,
18416 + .create_mode = create_mode,
18417 + .opened = &h_opened
18419 + struct aopen_node aopen_node = {
18424 + AuDbg("open_flag 0x%x\n", open_flag);
18425 + AuDbgDentry(dentry);
18428 + if (!au_di(dentry)) {
18429 + d = aufs_lookup(dir, dentry, /*flags*/0);
18431 + err = PTR_ERR(d);
18435 + * obsoleted dentry found.
18436 + * another error will be returned later.
18442 + AuDbgDentry(dentry);
18445 + if (d_is_positive(dentry)
18446 + || d_unhashed(dentry)
18447 + || d_unlinked(dentry)
18448 + || !(open_flag & O_CREAT))
18449 + goto out_no_open;
18451 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18452 + if (unlikely(err))
18455 + parent = dentry->d_parent; /* dir is locked */
18456 + di_write_lock_parent(parent);
18457 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
18458 + if (unlikely(err))
18461 + AuDbgDentry(dentry);
18462 + if (d_is_positive(dentry))
18465 + args.file = get_empty_filp();
18466 + err = PTR_ERR(args.file);
18467 + if (IS_ERR(args.file))
18470 + args.file->f_flags = file->f_flags;
18471 + err = au_aopen_or_create(dir, dentry, &args);
18473 + AuDbgFile(args.file);
18474 + if (unlikely(err < 0)) {
18475 + if (h_opened & FILE_OPENED)
18478 + put_filp(args.file);
18482 + /* some filesystems don't set FILE_CREATED while succeeded? */
18483 + *opened |= FILE_CREATED;
18484 + if (h_opened & FILE_OPENED)
18485 + aopen_node.h_file = args.file;
18487 + put_filp(args.file);
18488 + args.file = NULL;
18490 + aopen = &au_sbi(dir->i_sb)->si_aopen;
18491 + au_sphl_add(&aopen_node.hlist, aopen);
18492 + err = finish_open(file, dentry, au_do_aopen, opened);
18493 + au_sphl_del(&aopen_node.hlist, aopen);
18496 + if (aopen_node.h_file)
18497 + fput(aopen_node.h_file);
18500 + di_write_unlock(parent);
18501 + aufs_read_unlock(dentry, AuLock_DW);
18502 + AuDbgDentry(dentry);
18503 + if (unlikely(err))
18506 + if (!err && !(*opened & FILE_CREATED)) {
18507 + AuLabel(out_no_open);
18509 + err = finish_no_open(file, dentry);
18512 + AuDbg("%pd%s%s\n", dentry,
18513 + (*opened & FILE_CREATED) ? " created" : "",
18514 + (*opened & FILE_OPENED) ? " opened" : "");
18520 +/* ---------------------------------------------------------------------- */
18522 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18523 + const unsigned char add_entry, aufs_bindex_t bcpup,
18524 + aufs_bindex_t bstart)
18527 + struct dentry *h_parent;
18528 + struct inode *h_dir;
18531 + IMustLock(d_inode(parent));
18533 + di_write_lock_parent(parent);
18536 + if (!au_h_dptr(parent, bcpup)) {
18537 + if (bstart > bcpup)
18538 + err = au_cpup_dirs(dentry, bcpup);
18539 + else if (bstart < bcpup)
18540 + err = au_cpdown_dirs(dentry, bcpup);
18544 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18545 + h_parent = au_h_dptr(parent, bcpup);
18546 + h_dir = d_inode(h_parent);
18547 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
18548 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
18549 + /* todo: no unlock here */
18550 + mutex_unlock(&h_dir->i_mutex);
18552 + AuDbg("bcpup %d\n", bcpup);
18554 + if (d_really_is_negative(dentry))
18555 + au_set_h_dptr(dentry, bstart, NULL);
18556 + au_update_dbrange(dentry, /*do_put_zero*/0);
18561 + di_write_unlock(parent);
18563 + err = bcpup; /* success */
18570 + * decide the branch and the parent dir where we will create a new entry.
18571 + * returns new bindex or an error.
18572 + * copyup the parent dir if needed.
18574 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18575 + struct au_wr_dir_args *args)
18578 + unsigned int flags;
18579 + aufs_bindex_t bcpup, bstart, src_bstart;
18580 + const unsigned char add_entry
18581 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18582 + | au_ftest_wrdir(args->flags, TMPFILE);
18583 + struct super_block *sb;
18584 + struct dentry *parent;
18585 + struct au_sbinfo *sbinfo;
18587 + sb = dentry->d_sb;
18588 + sbinfo = au_sbi(sb);
18589 + parent = dget_parent(dentry);
18590 + bstart = au_dbstart(dentry);
18592 + if (args->force_btgt < 0) {
18593 + if (src_dentry) {
18594 + src_bstart = au_dbstart(src_dentry);
18595 + if (src_bstart < bstart)
18596 + bcpup = src_bstart;
18597 + } else if (add_entry) {
18599 + if (au_ftest_wrdir(args->flags, ISDIR))
18600 + au_fset_wbr(flags, DIR);
18601 + err = AuWbrCreate(sbinfo, dentry, flags);
18605 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
18607 + err = AuWbrCopyup(sbinfo, dentry);
18609 + if (!IS_ROOT(dentry)) {
18610 + di_read_lock_parent(parent, !AuLock_IR);
18611 + err = AuWbrCopyup(sbinfo, dentry);
18612 + di_read_unlock(parent, !AuLock_IR);
18614 + err = AuWbrCopyup(sbinfo, dentry);
18617 + if (unlikely(err < 0))
18621 + bcpup = args->force_btgt;
18622 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
18625 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
18627 + if (bcpup == bstart)
18628 + goto out; /* success */
18630 + /* copyup the new parent into the branch we process */
18631 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
18633 + if (d_really_is_negative(dentry)) {
18634 + au_set_h_dptr(dentry, bstart, NULL);
18635 + au_set_dbstart(dentry, bcpup);
18636 + au_set_dbend(dentry, bcpup);
18638 + AuDebugOn(add_entry
18639 + && !au_ftest_wrdir(args->flags, TMPFILE)
18640 + && !au_h_dptr(dentry, bcpup));
18648 +/* ---------------------------------------------------------------------- */
18650 +void au_pin_hdir_unlock(struct au_pin *p)
18653 + au_hn_imtx_unlock(p->hdir);
18656 +int au_pin_hdir_lock(struct au_pin *p)
18664 + /* even if an error happens later, keep this lock */
18665 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
18668 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
18673 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18674 + p->h_parent, p->br);
18680 +int au_pin_hdir_relock(struct au_pin *p)
18683 + struct inode *h_i;
18684 + struct dentry *h_d[] = {
18689 + err = au_pin_hdir_lock(p);
18690 + if (unlikely(err))
18693 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
18696 + if (d_is_positive(h_d[i])) {
18697 + h_i = d_inode(h_d[i]);
18698 + err = !h_i->i_nlink;
18706 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
18708 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
18709 + p->hdir->hi_inode->i_mutex.owner = task;
18713 +void au_pin_hdir_acquire_nest(struct au_pin *p)
18716 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
18717 + p->lsc_hi, 0, NULL, _RET_IP_);
18718 + au_pin_hdir_set_owner(p, current);
18722 +void au_pin_hdir_release(struct au_pin *p)
18725 + au_pin_hdir_set_owner(p, p->task);
18726 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
18730 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
18732 + if (pin && pin->parent)
18733 + return au_h_dptr(pin->parent, pin->bindex);
18737 +void au_unpin(struct au_pin *p)
18740 + au_pin_hdir_unlock(p);
18741 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
18742 + vfsub_mnt_drop_write(p->h_mnt);
18746 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18747 + di_read_unlock(p->parent, AuLock_IR);
18748 + iput(p->hdir->hi_inode);
18750 + p->parent = NULL;
18753 + /* do not clear p->task */
18756 +int au_do_pin(struct au_pin *p)
18759 + struct super_block *sb;
18760 + struct inode *h_dir;
18763 + sb = p->dentry->d_sb;
18764 + p->br = au_sbr(sb, p->bindex);
18765 + if (IS_ROOT(p->dentry)) {
18766 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18767 + p->h_mnt = au_br_mnt(p->br);
18768 + err = vfsub_mnt_want_write(p->h_mnt);
18769 + if (unlikely(err)) {
18770 + au_fclr_pin(p->flags, MNT_WRITE);
18777 + p->h_dentry = NULL;
18778 + if (p->bindex <= au_dbend(p->dentry))
18779 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
18781 + p->parent = dget_parent(p->dentry);
18782 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18783 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
18786 + p->h_parent = au_h_dptr(p->parent, p->bindex);
18787 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
18789 + h_dir = p->hdir->hi_inode;
18793 + * if DI_LOCKED is not set, then p->parent may be different
18794 + * and h_parent can be NULL.
18796 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
18798 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18799 + di_read_unlock(p->parent, AuLock_IR);
18801 + p->parent = NULL;
18805 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18806 + p->h_mnt = au_br_mnt(p->br);
18807 + err = vfsub_mnt_want_write(p->h_mnt);
18808 + if (unlikely(err)) {
18809 + au_fclr_pin(p->flags, MNT_WRITE);
18810 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18811 + di_read_unlock(p->parent, AuLock_IR);
18813 + p->parent = NULL;
18819 + err = au_pin_hdir_lock(p);
18821 + goto out; /* success */
18826 + pr_err("err %d\n", err);
18827 + err = au_busy_or_stale();
18832 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
18833 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18834 + unsigned int udba, unsigned char flags)
18836 + p->dentry = dentry;
18838 + p->lsc_di = lsc_di;
18839 + p->lsc_hi = lsc_hi;
18840 + p->flags = flags;
18841 + p->bindex = bindex;
18843 + p->parent = NULL;
18847 + p->h_dentry = NULL;
18848 + p->h_parent = NULL;
18850 + p->task = current;
18853 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18854 + unsigned int udba, unsigned char flags)
18856 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
18858 + return au_do_pin(pin);
18861 +/* ---------------------------------------------------------------------- */
18864 + * ->setattr() and ->getattr() are called in various cases.
18865 + * chmod, stat: dentry is revalidated.
18866 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
18868 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
18870 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
18871 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
18874 + struct dentry *parent;
18877 + if (au_digen_test(dentry, sigen)) {
18878 + parent = dget_parent(dentry);
18879 + di_read_lock_parent(parent, AuLock_IR);
18880 + err = au_refresh_dentry(dentry, parent);
18881 + di_read_unlock(parent, AuLock_IR);
18889 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18890 + struct au_icpup_args *a)
18894 + aufs_bindex_t bstart, ibstart;
18895 + struct dentry *hi_wh, *parent;
18896 + struct inode *inode;
18897 + struct au_wr_dir_args wr_dir_args = {
18898 + .force_btgt = -1,
18902 + if (d_is_dir(dentry))
18903 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18904 + /* plink or hi_wh() case */
18905 + bstart = au_dbstart(dentry);
18906 + inode = d_inode(dentry);
18907 + ibstart = au_ibstart(inode);
18908 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
18909 + wr_dir_args.force_btgt = ibstart;
18910 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18911 + if (unlikely(err < 0))
18914 + if (err != bstart)
18915 + au_fset_icpup(a->flags, DID_CPUP);
18918 + a->pin_flags = AuPin_MNT_WRITE;
18920 + if (!IS_ROOT(dentry)) {
18921 + au_fset_pin(a->pin_flags, DI_LOCKED);
18922 + parent = dget_parent(dentry);
18923 + di_write_lock_parent(parent);
18926 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
18927 + if (unlikely(err))
18930 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18932 + a->h_inode = d_inode(a->h_path.dentry);
18933 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
18934 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18935 + if (ia->ia_size < i_size_read(a->h_inode))
18936 + sz = ia->ia_size;
18937 + mutex_unlock(&a->h_inode->i_mutex);
18941 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
18942 + hi_wh = au_hi_wh(inode, a->btgt);
18944 + struct au_cp_generic cpg = {
18945 + .dentry = dentry,
18951 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
18952 + if (unlikely(err))
18954 + hi_wh = au_hi_wh(inode, a->btgt);
18955 + /* todo: revalidate hi_wh? */
18960 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
18961 + di_downgrade_lock(parent, AuLock_IR);
18965 + if (!au_ftest_icpup(a->flags, DID_CPUP))
18966 + goto out; /* success */
18968 + if (!d_unhashed(dentry)) {
18969 + struct au_cp_generic cpg = {
18970 + .dentry = dentry,
18975 + .flags = AuCpup_DTIME | AuCpup_HOPEN
18977 + err = au_sio_cpup_simple(&cpg);
18979 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18980 + } else if (!hi_wh)
18981 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18983 + a->h_path.dentry = hi_wh; /* do not dget here */
18986 + a->h_inode = d_inode(a->h_path.dentry);
18988 + goto out; /* success */
18989 + au_unpin(&a->pin);
18992 + di_write_unlock(parent);
18997 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
19001 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19004 + struct inode *inode, *delegated;
19005 + struct super_block *sb;
19006 + struct file *file;
19007 + struct au_icpup_args *a;
19009 + inode = d_inode(dentry);
19010 + IMustLock(inode);
19013 + a = kzalloc(sizeof(*a), GFP_NOFS);
19014 + if (unlikely(!a))
19017 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19018 + ia->ia_valid &= ~ATTR_MODE;
19021 + sb = dentry->d_sb;
19022 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19023 + if (unlikely(err))
19026 + if (ia->ia_valid & ATTR_FILE) {
19027 + /* currently ftruncate(2) only */
19028 + AuDebugOn(!d_is_reg(dentry));
19029 + file = ia->ia_file;
19030 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
19031 + if (unlikely(err))
19033 + ia->ia_file = au_hf_top(file);
19034 + a->udba = AuOpt_UDBA_NONE;
19036 + /* fchmod() doesn't pass ia_file */
19037 + a->udba = au_opt_udba(sb);
19038 + di_write_lock_child(dentry);
19039 + /* no d_unlinked(), to set UDBA_NONE for root */
19040 + if (d_unhashed(dentry))
19041 + a->udba = AuOpt_UDBA_NONE;
19042 + if (a->udba != AuOpt_UDBA_NONE) {
19043 + AuDebugOn(IS_ROOT(dentry));
19044 + err = au_reval_for_attr(dentry, au_sigen(sb));
19045 + if (unlikely(err))
19050 + err = au_pin_and_icpup(dentry, ia, a);
19051 + if (unlikely(err < 0))
19053 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19054 + ia->ia_file = NULL;
19055 + ia->ia_valid &= ~ATTR_FILE;
19058 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19059 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19060 + == (ATTR_MODE | ATTR_CTIME)) {
19061 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19062 + if (unlikely(err))
19064 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19065 + && (ia->ia_valid & ATTR_CTIME)) {
19066 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19067 + if (unlikely(err))
19071 + if (ia->ia_valid & ATTR_SIZE) {
19074 + if (ia->ia_size < i_size_read(inode))
19076 + truncate_setsize(inode, ia->ia_size);
19079 + if (ia->ia_valid & ATTR_FILE)
19081 + mutex_unlock(&a->h_inode->i_mutex);
19082 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19083 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
19085 + delegated = NULL;
19087 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19089 + err = break_deleg_wait(&delegated);
19097 + au_cpup_attr_changeable(inode);
19100 + mutex_unlock(&a->h_inode->i_mutex);
19101 + au_unpin(&a->pin);
19102 + if (unlikely(err))
19103 + au_update_dbstart(dentry);
19105 + di_write_unlock(dentry);
19107 + fi_write_unlock(file);
19108 + ia->ia_file = file;
19109 + ia->ia_valid |= ATTR_FILE;
19112 + si_read_unlock(sb);
19120 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19121 +static int au_h_path_to_set_attr(struct dentry *dentry,
19122 + struct au_icpup_args *a, struct path *h_path)
19125 + struct super_block *sb;
19127 + sb = dentry->d_sb;
19128 + a->udba = au_opt_udba(sb);
19129 + /* no d_unlinked(), to set UDBA_NONE for root */
19130 + if (d_unhashed(dentry))
19131 + a->udba = AuOpt_UDBA_NONE;
19132 + if (a->udba != AuOpt_UDBA_NONE) {
19133 + AuDebugOn(IS_ROOT(dentry));
19134 + err = au_reval_for_attr(dentry, au_sigen(sb));
19135 + if (unlikely(err))
19138 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19139 + if (unlikely(err < 0))
19142 + h_path->dentry = a->h_path.dentry;
19143 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19149 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg)
19152 + struct path h_path;
19153 + struct super_block *sb;
19154 + struct au_icpup_args *a;
19155 + struct inode *inode, *h_inode;
19157 + inode = d_inode(dentry);
19158 + IMustLock(inode);
19161 + a = kzalloc(sizeof(*a), GFP_NOFS);
19162 + if (unlikely(!a))
19165 + sb = dentry->d_sb;
19166 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19167 + if (unlikely(err))
19170 + h_path.dentry = NULL; /* silence gcc */
19171 + di_write_lock_child(dentry);
19172 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19173 + if (unlikely(err))
19176 + mutex_unlock(&a->h_inode->i_mutex);
19177 + switch (arg->type) {
19178 + case AU_XATTR_SET:
19179 + err = vfsub_setxattr(h_path.dentry,
19180 + arg->u.set.name, arg->u.set.value,
19181 + arg->u.set.size, arg->u.set.flags);
19183 + case AU_XATTR_REMOVE:
19184 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
19187 + err = -EOPNOTSUPP;
19188 + h_inode = d_inode(h_path.dentry);
19189 + if (h_inode->i_op->set_acl)
19190 + err = h_inode->i_op->set_acl(h_inode,
19191 + arg->u.acl_set.acl,
19192 + arg->u.acl_set.type);
19196 + au_cpup_attr_timesizes(inode);
19198 + au_unpin(&a->pin);
19199 + if (unlikely(err))
19200 + au_update_dbstart(dentry);
19203 + di_write_unlock(dentry);
19204 + si_read_unlock(sb);
19213 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19214 + unsigned int nlink)
19218 + inode->i_mode = st->mode;
19219 + /* don't i_[ug]id_write() here */
19220 + inode->i_uid = st->uid;
19221 + inode->i_gid = st->gid;
19222 + inode->i_atime = st->atime;
19223 + inode->i_mtime = st->mtime;
19224 + inode->i_ctime = st->ctime;
19226 + au_cpup_attr_nlink(inode, /*force*/0);
19227 + if (S_ISDIR(inode->i_mode)) {
19228 + n = inode->i_nlink;
19231 + smp_mb(); /* for i_nlink */
19232 + /* 0 can happen */
19233 + set_nlink(inode, n);
19236 + spin_lock(&inode->i_lock);
19237 + inode->i_blocks = st->blocks;
19238 + i_size_write(inode, st->size);
19239 + spin_unlock(&inode->i_lock);
19243 + * common routine for aufs_getattr() and aufs_getxattr().
19244 + * returns zero or negative (an error).
19245 + * @dentry will be read-locked in success.
19247 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
19250 + unsigned int mnt_flags, sigen;
19251 + unsigned char udba_none;
19252 + aufs_bindex_t bindex;
19253 + struct super_block *sb, *h_sb;
19254 + struct inode *inode;
19256 + h_path->mnt = NULL;
19257 + h_path->dentry = NULL;
19260 + sb = dentry->d_sb;
19261 + mnt_flags = au_mntflags(sb);
19262 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19264 + /* support fstat(2) */
19265 + if (!d_unlinked(dentry) && !udba_none) {
19266 + sigen = au_sigen(sb);
19267 + err = au_digen_test(dentry, sigen);
19269 + di_read_lock_child(dentry, AuLock_IR);
19270 + err = au_dbrange_test(dentry);
19271 + if (unlikely(err)) {
19272 + di_read_unlock(dentry, AuLock_IR);
19276 + AuDebugOn(IS_ROOT(dentry));
19277 + di_write_lock_child(dentry);
19278 + err = au_dbrange_test(dentry);
19280 + err = au_reval_for_attr(dentry, sigen);
19282 + di_downgrade_lock(dentry, AuLock_IR);
19284 + di_write_unlock(dentry);
19289 + di_read_lock_child(dentry, AuLock_IR);
19291 + inode = d_inode(dentry);
19292 + bindex = au_ibstart(inode);
19293 + h_path->mnt = au_sbr_mnt(sb, bindex);
19294 + h_sb = h_path->mnt->mnt_sb;
19296 + && !au_test_fs_bad_iattr(h_sb)
19298 + goto out; /* success */
19300 + if (au_dbstart(dentry) == bindex)
19301 + h_path->dentry = au_h_dptr(dentry, bindex);
19302 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19303 + h_path->dentry = au_plink_lkup(inode, bindex);
19304 + if (IS_ERR(h_path->dentry))
19305 + /* pretending success */
19306 + h_path->dentry = NULL;
19308 + dput(h_path->dentry);
19315 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19316 + struct dentry *dentry, struct kstat *st)
19319 + unsigned char positive;
19320 + struct path h_path;
19321 + struct inode *inode;
19322 + struct super_block *sb;
19324 + inode = d_inode(dentry);
19325 + sb = dentry->d_sb;
19326 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19327 + if (unlikely(err))
19329 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
19330 + if (unlikely(err))
19332 + if (unlikely(!h_path.dentry))
19333 + /* illegally overlapped or something */
19334 + goto out_fill; /* pretending success */
19336 + positive = d_is_positive(h_path.dentry);
19338 + err = vfs_getattr(&h_path, st);
19341 + au_refresh_iattr(inode, st,
19342 + d_inode(h_path.dentry)->i_nlink);
19343 + goto out_fill; /* success */
19349 + generic_fillattr(inode, st);
19351 + di_read_unlock(dentry, AuLock_IR);
19353 + si_read_unlock(sb);
19359 +/* ---------------------------------------------------------------------- */
19361 +static int h_readlink(struct dentry *dentry, int bindex, char __user *buf,
19365 + struct super_block *sb;
19366 + struct dentry *h_dentry;
19367 + struct inode *inode, *h_inode;
19370 + h_dentry = au_h_dptr(dentry, bindex);
19371 + h_inode = d_inode(h_dentry);
19372 + if (unlikely(!h_inode->i_op->readlink))
19375 + err = security_inode_readlink(h_dentry);
19376 + if (unlikely(err))
19379 + sb = dentry->d_sb;
19380 + inode = d_inode(dentry);
19381 + if (!au_test_ro(sb, bindex, inode)) {
19382 + vfsub_touch_atime(au_sbr_mnt(sb, bindex), h_dentry);
19383 + fsstack_copy_attr_atime(inode, h_inode);
19385 + err = h_inode->i_op->readlink(h_dentry, buf, bufsiz);
19391 +static int aufs_readlink(struct dentry *dentry, char __user *buf, int bufsiz)
19395 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19396 + if (unlikely(err))
19398 + err = au_d_hashed_positive(dentry);
19400 + err = h_readlink(dentry, au_dbstart(dentry), buf, bufsiz);
19401 + aufs_read_unlock(dentry, AuLock_IR);
19407 +static void *aufs_follow_link(struct dentry *dentry, struct nameidata *nd)
19410 + mm_segment_t old_fs;
19417 + buf.k = (void *)__get_free_page(GFP_NOFS);
19418 + if (unlikely(!buf.k))
19421 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19422 + if (unlikely(err))
19425 + err = au_d_hashed_positive(dentry);
19427 + old_fs = get_fs();
19428 + set_fs(KERNEL_DS);
19429 + err = h_readlink(dentry, au_dbstart(dentry), buf.u, PATH_MAX);
19432 + aufs_read_unlock(dentry, AuLock_IR);
19436 + /* will be freed by put_link */
19437 + nd_set_link(nd, buf.k);
19438 + return NULL; /* success */
19442 + free_page((unsigned long)buf.k);
19445 + return ERR_PTR(err);
19448 +static void aufs_put_link(struct dentry *dentry __maybe_unused,
19449 + struct nameidata *nd, void *cookie __maybe_unused)
19453 + p = nd_get_link(nd);
19454 + if (!IS_ERR_OR_NULL(p))
19455 + free_page((unsigned long)p);
19458 +/* ---------------------------------------------------------------------- */
19460 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19463 + struct super_block *sb;
19464 + struct inode *h_inode;
19466 + sb = inode->i_sb;
19467 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19469 + si_read_lock(sb, AuLock_FLUSH);
19470 + ii_write_lock_child(inode);
19472 + h_inode = au_h_iptr(inode, au_ibstart(inode));
19473 + err = vfsub_update_time(h_inode, ts, flags);
19476 + au_cpup_attr_timesizes(inode);
19477 + ii_write_unlock(inode);
19478 + si_read_unlock(sb);
19481 + if (!err && (flags & S_VERSION))
19482 + inode_inc_iversion(inode);
19487 +/* ---------------------------------------------------------------------- */
19489 +struct inode_operations aufs_symlink_iop = {
19490 + .permission = aufs_permission,
19491 +#ifdef CONFIG_FS_POSIX_ACL
19492 + .get_acl = aufs_get_acl,
19493 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19496 + .setattr = aufs_setattr,
19497 + .getattr = aufs_getattr,
19499 +#ifdef CONFIG_AUFS_XATTR
19500 + .setxattr = aufs_setxattr,
19501 + .getxattr = aufs_getxattr,
19502 + .listxattr = aufs_listxattr,
19503 + .removexattr = aufs_removexattr,
19506 + .readlink = aufs_readlink,
19507 + .follow_link = aufs_follow_link,
19508 + .put_link = aufs_put_link,
19510 + /* .update_time = aufs_update_time */
19513 +struct inode_operations aufs_dir_iop = {
19514 + .create = aufs_create,
19515 + .lookup = aufs_lookup,
19516 + .link = aufs_link,
19517 + .unlink = aufs_unlink,
19518 + .symlink = aufs_symlink,
19519 + .mkdir = aufs_mkdir,
19520 + .rmdir = aufs_rmdir,
19521 + .mknod = aufs_mknod,
19522 + .rename = aufs_rename,
19524 + .permission = aufs_permission,
19525 +#ifdef CONFIG_FS_POSIX_ACL
19526 + .get_acl = aufs_get_acl,
19527 + .set_acl = aufs_set_acl,
19530 + .setattr = aufs_setattr,
19531 + .getattr = aufs_getattr,
19533 +#ifdef CONFIG_AUFS_XATTR
19534 + .setxattr = aufs_setxattr,
19535 + .getxattr = aufs_getxattr,
19536 + .listxattr = aufs_listxattr,
19537 + .removexattr = aufs_removexattr,
19540 + .update_time = aufs_update_time,
19541 + .atomic_open = aufs_atomic_open,
19542 + .tmpfile = aufs_tmpfile
19545 +struct inode_operations aufs_iop = {
19546 + .permission = aufs_permission,
19547 +#ifdef CONFIG_FS_POSIX_ACL
19548 + .get_acl = aufs_get_acl,
19549 + .set_acl = aufs_set_acl,
19552 + .setattr = aufs_setattr,
19553 + .getattr = aufs_getattr,
19555 +#ifdef CONFIG_AUFS_XATTR
19556 + .setxattr = aufs_setxattr,
19557 + .getxattr = aufs_getxattr,
19558 + .listxattr = aufs_listxattr,
19559 + .removexattr = aufs_removexattr,
19562 + .update_time = aufs_update_time
19564 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19565 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19566 +++ linux/fs/aufs/i_op_del.c 2015-06-28 17:36:09.025073697 +0200
19569 + * Copyright (C) 2005-2015 Junjiro R. Okajima
19571 + * This program, aufs is free software; you can redistribute it and/or modify
19572 + * it under the terms of the GNU General Public License as published by
19573 + * the Free Software Foundation; either version 2 of the License, or
19574 + * (at your option) any later version.
19576 + * This program is distributed in the hope that it will be useful,
19577 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19578 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19579 + * GNU General Public License for more details.
19581 + * You should have received a copy of the GNU General Public License
19582 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19586 + * inode operations (del entry)
19592 + * decide if a new whiteout for @dentry is necessary or not.
19593 + * when it is necessary, prepare the parent dir for the upper branch whose
19594 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19595 + * be done by caller.
19597 + * 0: wh is unnecessary
19598 + * plus: wh is necessary
19601 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19603 + int need_wh, err;
19604 + aufs_bindex_t bstart;
19605 + struct super_block *sb;
19607 + sb = dentry->d_sb;
19608 + bstart = au_dbstart(dentry);
19609 + if (*bcpup < 0) {
19611 + if (au_test_ro(sb, bstart, d_inode(dentry))) {
19612 + err = AuWbrCopyup(au_sbi(sb), dentry);
19614 + if (unlikely(err < 0))
19618 + AuDebugOn(bstart < *bcpup
19619 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
19620 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
19622 + if (*bcpup != bstart) {
19623 + err = au_cpup_dirs(dentry, *bcpup);
19624 + if (unlikely(err))
19628 + struct au_dinfo *dinfo, *tmp;
19630 + need_wh = -ENOMEM;
19631 + dinfo = au_di(dentry);
19632 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19634 + au_di_cp(tmp, dinfo);
19635 + au_di_swap(tmp, dinfo);
19636 + /* returns the number of positive dentries */
19637 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
19638 + au_di_swap(tmp, dinfo);
19639 + au_rw_write_unlock(&tmp->di_rwsem);
19643 + AuDbg("need_wh %d\n", need_wh);
19651 + * simple tests for the del-entry operations.
19652 + * following the checks in vfs, plus the parent-child relationship.
19654 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19655 + struct dentry *h_parent, int isdir)
19659 + struct dentry *h_dentry, *h_latest;
19660 + struct inode *h_inode;
19662 + h_dentry = au_h_dptr(dentry, bindex);
19663 + if (d_really_is_positive(dentry)) {
19665 + if (unlikely(d_is_negative(h_dentry)))
19667 + h_inode = d_inode(h_dentry);
19668 + if (unlikely(!h_inode->i_nlink))
19671 + h_mode = h_inode->i_mode;
19674 + if (unlikely(S_ISDIR(h_mode)))
19676 + } else if (unlikely(!S_ISDIR(h_mode))) {
19681 + /* rename(2) case */
19683 + if (unlikely(d_is_positive(h_dentry)))
19688 + /* expected parent dir is locked */
19689 + if (unlikely(h_parent != h_dentry->d_parent))
19694 + * rmdir a dir may break the consistency on some filesystem.
19695 + * let's try heavy test.
19698 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
19699 + && au_test_h_perm(d_inode(h_parent),
19700 + MAY_EXEC | MAY_WRITE)))
19703 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
19705 + if (IS_ERR(h_latest))
19707 + if (h_latest == h_dentry)
19716 + * decide the branch where we operate for @dentry. the branch index will be set
19717 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
19718 + * dir for reverting.
19719 + * when a new whiteout is necessary, create it.
19721 +static struct dentry*
19722 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
19723 + struct au_dtime *dt, struct au_pin *pin)
19725 + struct dentry *wh_dentry;
19726 + struct super_block *sb;
19727 + struct path h_path;
19728 + int err, need_wh;
19729 + unsigned int udba;
19730 + aufs_bindex_t bcpup;
19732 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
19733 + wh_dentry = ERR_PTR(need_wh);
19734 + if (unlikely(need_wh < 0))
19737 + sb = dentry->d_sb;
19738 + udba = au_opt_udba(sb);
19740 + err = au_pin(pin, dentry, bcpup, udba,
19741 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19742 + wh_dentry = ERR_PTR(err);
19743 + if (unlikely(err))
19746 + h_path.dentry = au_pinned_h_parent(pin);
19747 + if (udba != AuOpt_UDBA_NONE
19748 + && au_dbstart(dentry) == bcpup) {
19749 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
19750 + wh_dentry = ERR_PTR(err);
19751 + if (unlikely(err))
19755 + h_path.mnt = au_sbr_mnt(sb, bcpup);
19756 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
19757 + wh_dentry = NULL;
19759 + goto out; /* success, no need to create whiteout */
19761 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
19762 + if (IS_ERR(wh_dentry))
19765 + /* returns with the parent is locked and wh_dentry is dget-ed */
19766 + goto out; /* success */
19771 + return wh_dentry;
19775 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
19776 + * in order to be revertible and save time for removing many child whiteouts
19778 + * returns 1 when there are too many child whiteout and caller should remove
19779 + * them asynchronously. returns 0 when the number of children is enough small to
19780 + * remove now or the branch fs is a remote fs.
19781 + * otherwise return an error.
19783 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
19784 + struct au_nhash *whlist, struct inode *dir)
19786 + int rmdir_later, err, dirwh;
19787 + struct dentry *h_dentry;
19788 + struct super_block *sb;
19789 + struct inode *inode;
19791 + sb = dentry->d_sb;
19792 + SiMustAnyLock(sb);
19793 + h_dentry = au_h_dptr(dentry, bindex);
19794 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
19795 + if (unlikely(err))
19798 + /* stop monitoring */
19799 + inode = d_inode(dentry);
19800 + au_hn_free(au_hi(inode, bindex));
19802 + if (!au_test_fs_remote(h_dentry->d_sb)) {
19803 + dirwh = au_sbi(sb)->si_dirwh;
19804 + rmdir_later = (dirwh <= 1);
19805 + if (!rmdir_later)
19806 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
19809 + return rmdir_later;
19812 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
19813 + if (unlikely(err)) {
19814 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
19815 + h_dentry, bindex, err);
19825 + * final procedure for deleting a entry.
19826 + * maintain dentry and iattr.
19828 +static void epilog(struct inode *dir, struct dentry *dentry,
19829 + aufs_bindex_t bindex)
19831 + struct inode *inode;
19833 + inode = d_inode(dentry);
19835 + inode->i_ctime = dir->i_ctime;
19837 + au_dir_ts(dir, bindex);
19838 + dir->i_version++;
19842 + * when an error happened, remove the created whiteout and revert everything.
19844 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
19845 + aufs_bindex_t bwh, struct dentry *wh_dentry,
19846 + struct dentry *dentry, struct au_dtime *dt)
19849 + struct path h_path = {
19850 + .dentry = wh_dentry,
19851 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
19854 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
19856 + au_set_dbwh(dentry, bwh);
19857 + au_dtime_revert(dt);
19861 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
19865 +/* ---------------------------------------------------------------------- */
19867 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
19870 + aufs_bindex_t bwh, bindex, bstart;
19871 + struct inode *inode, *h_dir, *delegated;
19872 + struct dentry *parent, *wh_dentry;
19873 + /* to reuduce stack size */
19875 + struct au_dtime dt;
19876 + struct au_pin pin;
19877 + struct path h_path;
19883 + a = kmalloc(sizeof(*a), GFP_NOFS);
19884 + if (unlikely(!a))
19887 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19888 + if (unlikely(err))
19890 + err = au_d_hashed_positive(dentry);
19891 + if (unlikely(err))
19893 + inode = d_inode(dentry);
19894 + IMustLock(inode);
19896 + if (unlikely(d_is_dir(dentry)))
19897 + goto out_unlock; /* possible? */
19899 + bstart = au_dbstart(dentry);
19900 + bwh = au_dbwh(dentry);
19902 + parent = dentry->d_parent; /* dir inode is locked */
19903 + di_write_lock_parent(parent);
19904 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
19906 + err = PTR_ERR(wh_dentry);
19907 + if (IS_ERR(wh_dentry))
19910 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
19911 + a->h_path.dentry = au_h_dptr(dentry, bstart);
19912 + dget(a->h_path.dentry);
19913 + if (bindex == bstart) {
19914 + h_dir = au_pinned_h_dir(&a->pin);
19915 + delegated = NULL;
19916 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
19917 + if (unlikely(err == -EWOULDBLOCK)) {
19918 + pr_warn("cannot retry for NFSv4 delegation"
19919 + " for an internal unlink\n");
19923 + /* dir inode is locked */
19924 + h_dir = d_inode(wh_dentry->d_parent);
19925 + IMustLock(h_dir);
19930 + vfsub_drop_nlink(inode);
19931 + epilog(dir, dentry, bindex);
19933 + /* update target timestamps */
19934 + if (bindex == bstart) {
19935 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
19937 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
19939 + /* todo: this timestamp may be reverted later */
19940 + inode->i_ctime = h_dir->i_ctime;
19941 + goto out_unpin; /* success */
19948 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19955 + au_unpin(&a->pin);
19957 + dput(a->h_path.dentry);
19959 + di_write_unlock(parent);
19961 + aufs_read_unlock(dentry, AuLock_DW);
19968 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
19970 + int err, rmdir_later;
19971 + aufs_bindex_t bwh, bindex, bstart;
19972 + struct inode *inode;
19973 + struct dentry *parent, *wh_dentry, *h_dentry;
19974 + struct au_whtmp_rmdir *args;
19975 + /* to reuduce stack size */
19977 + struct au_dtime dt;
19978 + struct au_pin pin;
19984 + a = kmalloc(sizeof(*a), GFP_NOFS);
19985 + if (unlikely(!a))
19988 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
19989 + if (unlikely(err))
19991 + err = au_alive_dir(dentry);
19992 + if (unlikely(err))
19994 + inode = d_inode(dentry);
19995 + IMustLock(inode);
19997 + if (unlikely(!d_is_dir(dentry)))
19998 + goto out_unlock; /* possible? */
20001 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20002 + if (unlikely(!args))
20005 + parent = dentry->d_parent; /* dir inode is locked */
20006 + di_write_lock_parent(parent);
20007 + err = au_test_empty(dentry, &args->whlist);
20008 + if (unlikely(err))
20011 + bstart = au_dbstart(dentry);
20012 + bwh = au_dbwh(dentry);
20014 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20016 + err = PTR_ERR(wh_dentry);
20017 + if (IS_ERR(wh_dentry))
20020 + h_dentry = au_h_dptr(dentry, bstart);
20023 + if (bindex == bstart) {
20024 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
20026 + rmdir_later = err;
20030 + /* stop monitoring */
20031 + au_hn_free(au_hi(inode, bstart));
20033 + /* dir inode is locked */
20034 + IMustLock(d_inode(wh_dentry->d_parent));
20039 + vfsub_dead_dir(inode);
20040 + au_set_dbdiropq(dentry, -1);
20041 + epilog(dir, dentry, bindex);
20043 + if (rmdir_later) {
20044 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
20048 + goto out_unpin; /* success */
20056 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20063 + au_unpin(&a->pin);
20067 + di_write_unlock(parent);
20069 + au_whtmp_rmdir_free(args);
20071 + aufs_read_unlock(dentry, AuLock_DW);
20078 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20079 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20080 +++ linux/fs/aufs/i_op_ren.c 2015-06-28 17:36:09.025073697 +0200
20083 + * Copyright (C) 2005-2015 Junjiro R. Okajima
20085 + * This program, aufs is free software; you can redistribute it and/or modify
20086 + * it under the terms of the GNU General Public License as published by
20087 + * the Free Software Foundation; either version 2 of the License, or
20088 + * (at your option) any later version.
20090 + * This program is distributed in the hope that it will be useful,
20091 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20092 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20093 + * GNU General Public License for more details.
20095 + * You should have received a copy of the GNU General Public License
20096 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20100 + * inode operation (rename entry)
20101 + * todo: this is crazy monster
20106 +enum { AuSRC, AuDST, AuSrcDst };
20107 +enum { AuPARENT, AuCHILD, AuParentChild };
20109 +#define AuRen_ISDIR 1
20110 +#define AuRen_ISSAMEDIR (1 << 1)
20111 +#define AuRen_WHSRC (1 << 2)
20112 +#define AuRen_WHDST (1 << 3)
20113 +#define AuRen_MNT_WRITE (1 << 4)
20114 +#define AuRen_DT_DSTDIR (1 << 5)
20115 +#define AuRen_DIROPQ (1 << 6)
20116 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20117 +#define au_fset_ren(flags, name) \
20118 + do { (flags) |= AuRen_##name; } while (0)
20119 +#define au_fclr_ren(flags, name) \
20120 + do { (flags) &= ~AuRen_##name; } while (0)
20122 +struct au_ren_args {
20124 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20126 + struct inode *dir, *inode;
20127 + struct au_hinode *hdir;
20128 + struct au_dtime dt[AuParentChild];
20129 + aufs_bindex_t bstart;
20132 +#define src_dentry sd[AuSRC].dentry
20133 +#define src_dir sd[AuSRC].dir
20134 +#define src_inode sd[AuSRC].inode
20135 +#define src_h_dentry sd[AuSRC].h_dentry
20136 +#define src_parent sd[AuSRC].parent
20137 +#define src_h_parent sd[AuSRC].h_parent
20138 +#define src_wh_dentry sd[AuSRC].wh_dentry
20139 +#define src_hdir sd[AuSRC].hdir
20140 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20141 +#define src_dt sd[AuSRC].dt
20142 +#define src_bstart sd[AuSRC].bstart
20144 +#define dst_dentry sd[AuDST].dentry
20145 +#define dst_dir sd[AuDST].dir
20146 +#define dst_inode sd[AuDST].inode
20147 +#define dst_h_dentry sd[AuDST].h_dentry
20148 +#define dst_parent sd[AuDST].parent
20149 +#define dst_h_parent sd[AuDST].h_parent
20150 +#define dst_wh_dentry sd[AuDST].wh_dentry
20151 +#define dst_hdir sd[AuDST].hdir
20152 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20153 +#define dst_dt sd[AuDST].dt
20154 +#define dst_bstart sd[AuDST].bstart
20156 + struct dentry *h_trap;
20157 + struct au_branch *br;
20158 + struct au_hinode *src_hinode;
20159 + struct path h_path;
20160 + struct au_nhash whlist;
20161 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
20163 + unsigned int flags;
20165 + struct au_whtmp_rmdir *thargs;
20166 + struct dentry *h_dst;
20169 +/* ---------------------------------------------------------------------- */
20172 + * functions for reverting.
20173 + * when an error happened in a single rename systemcall, we should revert
20174 + * everything as if nothing happend.
20175 + * we don't need to revert the copied-up/down the parent dir since they are
20179 +#define RevertFailure(fmt, ...) do { \
20180 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20181 + ##__VA_ARGS__, err, rerr); \
20185 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20189 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20190 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
20191 + au_hn_imtx_unlock(a->src_hinode);
20192 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
20194 + RevertFailure("remove diropq %pd", a->src_dentry);
20197 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20200 + struct inode *delegated;
20202 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20203 + a->src_h_parent);
20204 + rerr = PTR_ERR(a->h_path.dentry);
20205 + if (IS_ERR(a->h_path.dentry)) {
20206 + RevertFailure("lkup one %pd", a->src_dentry);
20210 + delegated = NULL;
20211 + rerr = vfsub_rename(a->dst_h_dir,
20212 + au_h_dptr(a->src_dentry, a->btgt),
20213 + a->src_h_dir, &a->h_path, &delegated);
20214 + if (unlikely(rerr == -EWOULDBLOCK)) {
20215 + pr_warn("cannot retry for NFSv4 delegation"
20216 + " for an internal rename\n");
20219 + d_drop(a->h_path.dentry);
20220 + dput(a->h_path.dentry);
20221 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20223 + RevertFailure("rename %pd", a->src_dentry);
20226 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20229 + struct inode *delegated;
20231 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20232 + a->dst_h_parent);
20233 + rerr = PTR_ERR(a->h_path.dentry);
20234 + if (IS_ERR(a->h_path.dentry)) {
20235 + RevertFailure("lkup one %pd", a->dst_dentry);
20238 + if (d_is_positive(a->h_path.dentry)) {
20239 + d_drop(a->h_path.dentry);
20240 + dput(a->h_path.dentry);
20244 + delegated = NULL;
20245 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20247 + if (unlikely(rerr == -EWOULDBLOCK)) {
20248 + pr_warn("cannot retry for NFSv4 delegation"
20249 + " for an internal rename\n");
20252 + d_drop(a->h_path.dentry);
20253 + dput(a->h_path.dentry);
20255 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20257 + RevertFailure("rename %pd", a->h_dst);
20260 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20264 + a->h_path.dentry = a->src_wh_dentry;
20265 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20266 + au_set_dbwh(a->src_dentry, a->src_bwh);
20268 + RevertFailure("unlink %pd", a->src_wh_dentry);
20270 +#undef RevertFailure
20272 +/* ---------------------------------------------------------------------- */
20275 + * when we have to copyup the renaming entry, do it with the rename-target name
20276 + * in order to minimize the cost (the later actual rename is unnecessary).
20277 + * otherwise rename it on the target branch.
20279 +static int au_ren_or_cpup(struct au_ren_args *a)
20282 + struct dentry *d;
20283 + struct inode *delegated;
20285 + d = a->src_dentry;
20286 + if (au_dbstart(d) == a->btgt) {
20287 + a->h_path.dentry = a->dst_h_dentry;
20288 + if (au_ftest_ren(a->flags, DIROPQ)
20289 + && au_dbdiropq(d) == a->btgt)
20290 + au_fclr_ren(a->flags, DIROPQ);
20291 + AuDebugOn(au_dbstart(d) != a->btgt);
20292 + delegated = NULL;
20293 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20294 + a->dst_h_dir, &a->h_path, &delegated);
20295 + if (unlikely(err == -EWOULDBLOCK)) {
20296 + pr_warn("cannot retry for NFSv4 delegation"
20297 + " for an internal rename\n");
20303 + if (!err && a->h_dst)
20304 + /* it will be set to dinfo later */
20310 +/* cf. aufs_rmdir() */
20311 +static int au_ren_del_whtmp(struct au_ren_args *a)
20314 + struct inode *dir;
20316 + dir = a->dst_dir;
20317 + SiMustAnyLock(dir->i_sb);
20318 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20319 + au_sbi(dir->i_sb)->si_dirwh)
20320 + || au_test_fs_remote(a->h_dst->d_sb)) {
20321 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20322 + if (unlikely(err))
20323 + pr_warn("failed removing whtmp dir %pd (%d), "
20324 + "ignored.\n", a->h_dst, err);
20326 + au_nhash_wh_free(&a->thargs->whlist);
20327 + a->thargs->whlist = a->whlist;
20328 + a->whlist.nh_num = 0;
20329 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20331 + a->thargs = NULL;
20337 +/* make it 'opaque' dir. */
20338 +static int au_ren_diropq(struct au_ren_args *a)
20341 + struct dentry *diropq;
20344 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
20345 + a->src_hinode = au_hi(a->src_inode, a->btgt);
20346 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20347 + diropq = au_diropq_create(a->src_dentry, a->btgt);
20348 + au_hn_imtx_unlock(a->src_hinode);
20349 + if (IS_ERR(diropq))
20350 + err = PTR_ERR(diropq);
20357 +static int do_rename(struct au_ren_args *a)
20360 + struct dentry *d, *h_d;
20362 + /* prepare workqueue args for asynchronous rmdir */
20363 + h_d = a->dst_h_dentry;
20364 + if (au_ftest_ren(a->flags, ISDIR) && d_is_positive(h_d)) {
20366 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
20367 + if (unlikely(!a->thargs))
20369 + a->h_dst = dget(h_d);
20372 + /* create whiteout for src_dentry */
20373 + if (au_ftest_ren(a->flags, WHSRC)) {
20374 + a->src_bwh = au_dbwh(a->src_dentry);
20375 + AuDebugOn(a->src_bwh >= 0);
20377 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
20378 + err = PTR_ERR(a->src_wh_dentry);
20379 + if (IS_ERR(a->src_wh_dentry))
20383 + /* lookup whiteout for dentry */
20384 + if (au_ftest_ren(a->flags, WHDST)) {
20385 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
20387 + err = PTR_ERR(h_d);
20390 + if (d_is_negative(h_d))
20393 + a->dst_wh_dentry = h_d;
20396 + /* rename dentry to tmpwh */
20398 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20399 + if (unlikely(err))
20402 + d = a->dst_dentry;
20403 + au_set_h_dptr(d, a->btgt, NULL);
20404 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20405 + if (unlikely(err))
20407 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20410 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_bstart != a->btgt);
20412 + /* rename by vfs_rename or cpup */
20413 + d = a->dst_dentry;
20414 + if (au_ftest_ren(a->flags, ISDIR)
20415 + && (a->dst_wh_dentry
20416 + || au_dbdiropq(d) == a->btgt
20417 + /* hide the lower to keep xino */
20418 + || a->btgt < au_dbend(d)
20419 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
20420 + au_fset_ren(a->flags, DIROPQ);
20421 + err = au_ren_or_cpup(a);
20422 + if (unlikely(err))
20423 + /* leave the copied-up one */
20426 + /* make dir opaque */
20427 + if (au_ftest_ren(a->flags, DIROPQ)) {
20428 + err = au_ren_diropq(a);
20429 + if (unlikely(err))
20433 + /* update target timestamps */
20434 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
20435 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20436 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20437 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20439 + /* remove whiteout for dentry */
20440 + if (a->dst_wh_dentry) {
20441 + a->h_path.dentry = a->dst_wh_dentry;
20442 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20444 + if (unlikely(err))
20448 + /* remove whtmp */
20450 + au_ren_del_whtmp(a); /* ignore this error */
20452 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20454 + goto out_success;
20457 + if (au_ftest_ren(a->flags, DIROPQ))
20458 + au_ren_rev_diropq(err, a);
20460 + au_ren_rev_rename(err, a);
20464 + au_ren_rev_whtmp(err, a);
20466 + dput(a->dst_wh_dentry);
20467 + a->dst_wh_dentry = NULL;
20469 + if (a->src_wh_dentry)
20470 + au_ren_rev_whsrc(err, a);
20472 + dput(a->src_wh_dentry);
20473 + dput(a->dst_wh_dentry);
20477 + au_whtmp_rmdir_free(a->thargs);
20478 + a->thargs = NULL;
20484 +/* ---------------------------------------------------------------------- */
20487 + * test if @dentry dir can be rename destination or not.
20488 + * success means, it is a logically empty dir.
20490 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20492 + return au_test_empty(dentry, whlist);
20496 + * test if @dentry dir can be rename source or not.
20497 + * if it can, return 0 and @children is filled.
20499 + * - it is a logically empty dir.
20500 + * - or, it exists on writable branch and has no children including whiteouts
20501 + * on the lower branch.
20503 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20506 + unsigned int rdhash;
20507 + aufs_bindex_t bstart;
20509 + bstart = au_dbstart(dentry);
20510 + if (bstart != btgt) {
20511 + struct au_nhash whlist;
20513 + SiMustAnyLock(dentry->d_sb);
20514 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20516 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20518 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20519 + if (unlikely(err))
20521 + err = au_test_empty(dentry, &whlist);
20522 + au_nhash_wh_free(&whlist);
20526 + if (bstart == au_dbtaildir(dentry))
20527 + return 0; /* success */
20529 + err = au_test_empty_lower(dentry);
20532 + if (err == -ENOTEMPTY) {
20533 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20534 + " is not supported\n");
20540 +/* side effect: sets whlist and h_dentry */
20541 +static int au_ren_may_dir(struct au_ren_args *a)
20544 + unsigned int rdhash;
20545 + struct dentry *d;
20547 + d = a->dst_dentry;
20548 + SiMustAnyLock(d->d_sb);
20551 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
20552 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20554 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20555 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20556 + if (unlikely(err))
20559 + au_set_dbstart(d, a->dst_bstart);
20560 + err = may_rename_dstdir(d, &a->whlist);
20561 + au_set_dbstart(d, a->btgt);
20563 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
20564 + if (unlikely(err))
20567 + d = a->src_dentry;
20568 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
20569 + if (au_ftest_ren(a->flags, ISDIR)) {
20570 + err = may_rename_srcdir(d, a->btgt);
20571 + if (unlikely(err)) {
20572 + au_nhash_wh_free(&a->whlist);
20573 + a->whlist.nh_num = 0;
20580 +/* ---------------------------------------------------------------------- */
20583 + * simple tests for rename.
20584 + * following the checks in vfs, plus the parent-child relationship.
20586 +static int au_may_ren(struct au_ren_args *a)
20589 + struct inode *h_inode;
20591 + if (a->src_bstart == a->btgt) {
20592 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20593 + au_ftest_ren(a->flags, ISDIR));
20594 + if (unlikely(err))
20597 + if (unlikely(a->src_h_dentry == a->h_trap))
20602 + if (a->dst_bstart != a->btgt)
20605 + err = -ENOTEMPTY;
20606 + if (unlikely(a->dst_h_dentry == a->h_trap))
20610 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20611 + if (d_really_is_negative(a->dst_dentry)) {
20612 + if (d_is_negative(a->dst_h_dentry))
20613 + err = au_may_add(a->dst_dentry, a->btgt,
20614 + a->dst_h_parent, isdir);
20616 + if (unlikely(d_is_negative(a->dst_h_dentry)))
20618 + h_inode = d_inode(a->dst_h_dentry);
20619 + if (h_inode->i_nlink)
20620 + err = au_may_del(a->dst_dentry, a->btgt,
20621 + a->dst_h_parent, isdir);
20625 + if (unlikely(err == -ENOENT || err == -EEXIST))
20631 +/* ---------------------------------------------------------------------- */
20636 + * - src_dir and dir by lock_rename()
20637 + * - inode if exitsts
20640 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
20642 + * + di_write_lock2_child()
20643 + * + di_write_lock_child()
20644 + * + ii_write_lock_child()
20645 + * + di_write_lock_child2()
20646 + * + ii_write_lock_child2()
20647 + * + src_parent and parent
20648 + * + di_write_lock_parent()
20649 + * + ii_write_lock_parent()
20650 + * + di_write_lock_parent2()
20651 + * + ii_write_lock_parent2()
20652 + * + lower src_dir and dir by vfsub_lock_rename()
20653 + * + verify the every relationships between child and parent. if any
20654 + * of them failed, unlock all and return -EBUSY.
20656 +static void au_ren_unlock(struct au_ren_args *a)
20658 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
20659 + a->dst_h_parent, a->dst_hdir);
20660 + if (au_ftest_ren(a->flags, MNT_WRITE))
20661 + vfsub_mnt_drop_write(au_br_mnt(a->br));
20664 +static int au_ren_lock(struct au_ren_args *a)
20667 + unsigned int udba;
20670 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
20671 + a->src_hdir = au_hi(a->src_dir, a->btgt);
20672 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
20673 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
20675 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
20676 + if (unlikely(err))
20678 + au_fset_ren(a->flags, MNT_WRITE);
20679 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
20680 + a->dst_h_parent, a->dst_hdir);
20681 + udba = au_opt_udba(a->src_dentry->d_sb);
20682 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
20683 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
20684 + err = au_busy_or_stale();
20685 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
20686 + err = au_h_verify(a->src_h_dentry, udba,
20687 + d_inode(a->src_h_parent), a->src_h_parent,
20689 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
20690 + err = au_h_verify(a->dst_h_dentry, udba,
20691 + d_inode(a->dst_h_parent), a->dst_h_parent,
20694 + goto out; /* success */
20696 + err = au_busy_or_stale();
20697 + au_ren_unlock(a);
20703 +/* ---------------------------------------------------------------------- */
20705 +static void au_ren_refresh_dir(struct au_ren_args *a)
20707 + struct inode *dir;
20709 + dir = a->dst_dir;
20710 + dir->i_version++;
20711 + if (au_ftest_ren(a->flags, ISDIR)) {
20712 + /* is this updating defined in POSIX? */
20713 + au_cpup_attr_timesizes(a->src_inode);
20714 + au_cpup_attr_nlink(dir, /*force*/1);
20717 + au_dir_ts(dir, a->btgt);
20719 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20722 + dir = a->src_dir;
20723 + dir->i_version++;
20724 + if (au_ftest_ren(a->flags, ISDIR))
20725 + au_cpup_attr_nlink(dir, /*force*/1);
20726 + au_dir_ts(dir, a->btgt);
20729 +static void au_ren_refresh(struct au_ren_args *a)
20731 + aufs_bindex_t bend, bindex;
20732 + struct dentry *d, *h_d;
20733 + struct inode *i, *h_i;
20734 + struct super_block *sb;
20736 + d = a->dst_dentry;
20739 + /* already dget-ed by au_ren_or_cpup() */
20740 + au_set_h_dptr(d, a->btgt, a->h_dst);
20742 + i = a->dst_inode;
20744 + if (!au_ftest_ren(a->flags, ISDIR))
20745 + vfsub_drop_nlink(i);
20747 + vfsub_dead_dir(i);
20748 + au_cpup_attr_timesizes(i);
20750 + au_update_dbrange(d, /*do_put_zero*/1);
20753 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
20754 + au_set_h_dptr(d, bindex, NULL);
20755 + bend = au_dbend(d);
20756 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
20757 + au_set_h_dptr(d, bindex, NULL);
20758 + au_update_dbrange(d, /*do_put_zero*/0);
20761 + d = a->src_dentry;
20762 + au_set_dbwh(d, -1);
20763 + bend = au_dbend(d);
20764 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20765 + h_d = au_h_dptr(d, bindex);
20767 + au_set_h_dptr(d, bindex, NULL);
20769 + au_set_dbend(d, a->btgt);
20772 + i = a->src_inode;
20773 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
20774 + return; /* success */
20776 + bend = au_ibend(i);
20777 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20778 + h_i = au_h_iptr(i, bindex);
20780 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
20781 + /* ignore this error */
20782 + au_set_h_iptr(i, bindex, NULL, 0);
20785 + au_set_ibend(i, a->btgt);
20788 +/* ---------------------------------------------------------------------- */
20790 +/* mainly for link(2) and rename(2) */
20791 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
20793 + aufs_bindex_t bdiropq, bwh;
20794 + struct dentry *parent;
20795 + struct au_branch *br;
20797 + parent = dentry->d_parent;
20798 + IMustLock(d_inode(parent)); /* dir is locked */
20800 + bdiropq = au_dbdiropq(parent);
20801 + bwh = au_dbwh(dentry);
20802 + br = au_sbr(dentry->d_sb, btgt);
20803 + if (au_br_rdonly(br)
20804 + || (0 <= bdiropq && bdiropq < btgt)
20805 + || (0 <= bwh && bwh < btgt))
20808 + AuDbg("btgt %d\n", btgt);
20812 +/* sets src_bstart, dst_bstart and btgt */
20813 +static int au_ren_wbr(struct au_ren_args *a)
20816 + struct au_wr_dir_args wr_dir_args = {
20817 + /* .force_btgt = -1, */
20818 + .flags = AuWrDir_ADD_ENTRY
20821 + a->src_bstart = au_dbstart(a->src_dentry);
20822 + a->dst_bstart = au_dbstart(a->dst_dentry);
20823 + if (au_ftest_ren(a->flags, ISDIR))
20824 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
20825 + wr_dir_args.force_btgt = a->src_bstart;
20826 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
20827 + wr_dir_args.force_btgt = a->dst_bstart;
20828 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
20829 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
20835 +static void au_ren_dt(struct au_ren_args *a)
20837 + a->h_path.dentry = a->src_h_parent;
20838 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
20839 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
20840 + a->h_path.dentry = a->dst_h_parent;
20841 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
20844 + au_fclr_ren(a->flags, DT_DSTDIR);
20845 + if (!au_ftest_ren(a->flags, ISDIR))
20848 + a->h_path.dentry = a->src_h_dentry;
20849 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
20850 + if (d_is_positive(a->dst_h_dentry)) {
20851 + au_fset_ren(a->flags, DT_DSTDIR);
20852 + a->h_path.dentry = a->dst_h_dentry;
20853 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
20857 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
20859 + struct dentry *h_d;
20860 + struct mutex *h_mtx;
20862 + au_dtime_revert(a->src_dt + AuPARENT);
20863 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
20864 + au_dtime_revert(a->dst_dt + AuPARENT);
20866 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
20867 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
20868 + h_mtx = &d_inode(h_d)->i_mutex;
20869 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20870 + au_dtime_revert(a->src_dt + AuCHILD);
20871 + mutex_unlock(h_mtx);
20873 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
20874 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
20875 + h_mtx = &d_inode(h_d)->i_mutex;
20876 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20877 + au_dtime_revert(a->dst_dt + AuCHILD);
20878 + mutex_unlock(h_mtx);
20883 +/* ---------------------------------------------------------------------- */
20885 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
20886 + struct inode *_dst_dir, struct dentry *_dst_dentry)
20889 + /* reduce stack space */
20890 + struct au_ren_args *a;
20892 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
20893 + IMustLock(_src_dir);
20894 + IMustLock(_dst_dir);
20897 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
20898 + a = kzalloc(sizeof(*a), GFP_NOFS);
20899 + if (unlikely(!a))
20902 + a->src_dir = _src_dir;
20903 + a->src_dentry = _src_dentry;
20904 + a->src_inode = NULL;
20905 + if (d_really_is_positive(a->src_dentry))
20906 + a->src_inode = d_inode(a->src_dentry);
20907 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
20908 + a->dst_dir = _dst_dir;
20909 + a->dst_dentry = _dst_dentry;
20910 + a->dst_inode = NULL;
20911 + if (d_really_is_positive(a->dst_dentry))
20912 + a->dst_inode = d_inode(a->dst_dentry);
20913 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
20914 + if (a->dst_inode) {
20915 + IMustLock(a->dst_inode);
20916 + au_igrab(a->dst_inode);
20920 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
20921 + if (d_is_dir(a->src_dentry)) {
20922 + au_fset_ren(a->flags, ISDIR);
20923 + if (unlikely(d_really_is_positive(a->dst_dentry)
20924 + && !d_is_dir(a->dst_dentry)))
20926 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20927 + AuLock_DIR | flags);
20929 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20931 + if (unlikely(err))
20934 + err = au_d_hashed_positive(a->src_dentry);
20935 + if (unlikely(err))
20938 + if (a->dst_inode) {
20940 + * If it is a dir, VFS unhash dst_dentry before this
20941 + * function. It means we cannot rely upon d_unhashed().
20943 + if (unlikely(!a->dst_inode->i_nlink))
20945 + if (!S_ISDIR(a->dst_inode->i_mode)) {
20946 + err = au_d_hashed_positive(a->dst_dentry);
20947 + if (unlikely(err))
20949 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
20951 + } else if (unlikely(d_unhashed(a->dst_dentry)))
20955 + * is it possible?
20956 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
20957 + * there may exist a problem somewhere else.
20960 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
20963 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
20964 + di_write_lock_parent(a->dst_parent);
20966 + /* which branch we process */
20967 + err = au_ren_wbr(a);
20968 + if (unlikely(err < 0))
20970 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
20971 + a->h_path.mnt = au_br_mnt(a->br);
20973 + /* are they available to be renamed */
20974 + err = au_ren_may_dir(a);
20975 + if (unlikely(err))
20976 + goto out_children;
20978 + /* prepare the writable parent dir on the same branch */
20979 + if (a->dst_bstart == a->btgt) {
20980 + au_fset_ren(a->flags, WHDST);
20982 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
20983 + if (unlikely(err))
20984 + goto out_children;
20987 + if (a->src_dir != a->dst_dir) {
20989 + * this temporary unlock is safe,
20990 + * because both dir->i_mutex are locked.
20992 + di_write_unlock(a->dst_parent);
20993 + di_write_lock_parent(a->src_parent);
20994 + err = au_wr_dir_need_wh(a->src_dentry,
20995 + au_ftest_ren(a->flags, ISDIR),
20997 + di_write_unlock(a->src_parent);
20998 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
20999 + au_fclr_ren(a->flags, ISSAMEDIR);
21001 + err = au_wr_dir_need_wh(a->src_dentry,
21002 + au_ftest_ren(a->flags, ISDIR),
21004 + if (unlikely(err < 0))
21005 + goto out_children;
21007 + au_fset_ren(a->flags, WHSRC);
21010 + if (a->src_bstart != a->btgt) {
21011 + struct au_pin pin;
21013 + err = au_pin(&pin, a->src_dentry, a->btgt,
21014 + au_opt_udba(a->src_dentry->d_sb),
21015 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21017 + struct au_cp_generic cpg = {
21018 + .dentry = a->src_dentry,
21020 + .bsrc = a->src_bstart,
21023 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21025 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
21026 + err = au_sio_cpup_simple(&cpg);
21029 + if (unlikely(err))
21030 + goto out_children;
21031 + a->src_bstart = a->btgt;
21032 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21033 + au_fset_ren(a->flags, WHSRC);
21036 + /* lock them all */
21037 + err = au_ren_lock(a);
21038 + if (unlikely(err))
21039 + /* leave the copied-up one */
21040 + goto out_children;
21042 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21043 + err = au_may_ren(a);
21044 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21045 + err = -ENAMETOOLONG;
21046 + if (unlikely(err))
21049 + /* store timestamps to be revertible */
21053 + err = do_rename(a);
21054 + if (unlikely(err))
21057 + /* update dir attributes */
21058 + au_ren_refresh_dir(a);
21060 + /* dput/iput all lower dentries */
21061 + au_ren_refresh(a);
21063 + goto out_hdir; /* success */
21066 + au_ren_rev_dt(err, a);
21068 + au_ren_unlock(a);
21070 + au_nhash_wh_free(&a->whlist);
21071 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
21072 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
21073 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21074 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
21078 + d_move(a->src_dentry, a->dst_dentry);
21080 + au_update_dbstart(a->dst_dentry);
21081 + if (!a->dst_inode)
21082 + d_drop(a->dst_dentry);
21084 + if (au_ftest_ren(a->flags, ISSAMEDIR))
21085 + di_write_unlock(a->dst_parent);
21087 + di_write_unlock2(a->src_parent, a->dst_parent);
21089 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21091 + iput(a->dst_inode);
21093 + au_whtmp_rmdir_free(a->thargs);
21099 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21100 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21101 +++ linux/fs/aufs/Kconfig 2015-06-28 17:35:44.344717109 +0200
21104 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21106 + Aufs is a stackable unification filesystem such as Unionfs,
21107 + which unifies several directories and provides a merged single
21109 + In the early days, aufs was entirely re-designed and
21110 + re-implemented Unionfs Version 1.x series. Introducing many
21111 + original ideas, approaches and improvements, it becomes totally
21112 + different from Unionfs while keeping the basic features.
21116 + prompt "Maximum number of branches"
21117 + default AUFS_BRANCH_MAX_127
21119 + Specifies the maximum number of branches (or member directories)
21120 + in a single aufs. The larger value consumes more system
21121 + resources and has a minor impact to performance.
21122 +config AUFS_BRANCH_MAX_127
21125 + Specifies the maximum number of branches (or member directories)
21126 + in a single aufs. The larger value consumes more system
21127 + resources and has a minor impact to performance.
21128 +config AUFS_BRANCH_MAX_511
21131 + Specifies the maximum number of branches (or member directories)
21132 + in a single aufs. The larger value consumes more system
21133 + resources and has a minor impact to performance.
21134 +config AUFS_BRANCH_MAX_1023
21137 + Specifies the maximum number of branches (or member directories)
21138 + in a single aufs. The larger value consumes more system
21139 + resources and has a minor impact to performance.
21140 +config AUFS_BRANCH_MAX_32767
21143 + Specifies the maximum number of branches (or member directories)
21144 + in a single aufs. The larger value consumes more system
21145 + resources and has a minor impact to performance.
21148 +config AUFS_SBILIST
21150 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21153 + Automatic configuration for internal use.
21154 + When aufs supports Magic SysRq or /proc, enabled automatically.
21156 +config AUFS_HNOTIFY
21157 + bool "Detect direct branch access (bypassing aufs)"
21159 + If you want to modify files on branches directly, eg. bypassing aufs,
21160 + and want aufs to detect the changes of them fully, then enable this
21161 + option and use 'udba=notify' mount option.
21162 + Currently there is only one available configuration, "fsnotify".
21163 + It will have a negative impact to the performance.
21164 + See detail in aufs.5.
21167 + prompt "method" if AUFS_HNOTIFY
21168 + default AUFS_HFSNOTIFY
21169 +config AUFS_HFSNOTIFY
21174 +config AUFS_EXPORT
21175 + bool "NFS-exportable aufs"
21176 + depends on EXPORTFS
21178 + If you want to export your mounted aufs via NFS, then enable this
21179 + option. There are several requirements for this configuration.
21180 + See detail in aufs.5.
21182 +config AUFS_INO_T_64
21184 + depends on AUFS_EXPORT
21185 + depends on 64BIT && !(ALPHA || S390)
21188 + Automatic configuration for internal use.
21189 + /* typedef unsigned long/int __kernel_ino_t */
21190 + /* alpha and s390x are int */
21193 + bool "support for XATTR/EA (including Security Labels)"
21195 + If your branch fs supports XATTR/EA and you want to make them
21196 + available in aufs too, then enable this opsion and specify the
21197 + branch attributes for EA.
21198 + See detail in aufs.5.
21201 + bool "File-based Hierarchical Storage Management"
21203 + Hierarchical Storage Management (or HSM) is a well-known feature
21204 + in the storage world. Aufs provides this feature as file-based.
21205 + with multiple branches.
21206 + These multiple branches are prioritized, ie. the topmost one
21207 + should be the fastest drive and be used heavily.
21210 + bool "Readdir in userspace"
21212 + Aufs has two methods to provide a merged view for a directory,
21213 + by a user-space library and by kernel-space natively. The latter
21214 + is always enabled but sometimes large and slow.
21215 + If you enable this option, install the library in aufs2-util
21216 + package, and set some environment variables for your readdir(3),
21217 + then the work will be handled in user-space which generally
21218 + shows better performance in most cases.
21219 + See detail in aufs.5.
21222 + bool "Show whiteouts"
21224 + If you want to make the whiteouts in aufs visible, then enable
21225 + this option and specify 'shwh' mount option. Although it may
21226 + sounds like philosophy or something, but in technically it
21227 + simply shows the name of whiteout with keeping its behaviour.
21229 +config AUFS_BR_RAMFS
21230 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21232 + If you want to use ramfs as an aufs branch fs, then enable this
21233 + option. Generally tmpfs is recommended.
21234 + Aufs prohibited them to be a branch fs by default, because
21235 + initramfs becomes unusable after switch_root or something
21236 + generally. If you sets initramfs as an aufs branch and boot your
21237 + system by switch_root, you will meet a problem easily since the
21238 + files in initramfs may be inaccessible.
21239 + Unless you are going to use ramfs as an aufs branch fs without
21240 + switch_root or something, leave it N.
21242 +config AUFS_BR_FUSE
21243 + bool "Fuse fs as an aufs branch"
21244 + depends on FUSE_FS
21247 + If you want to use fuse-based userspace filesystem as an aufs
21248 + branch fs, then enable this option.
21249 + It implements the internal poll(2) operation which is
21250 + implemented by fuse only (curretnly).
21255 + Automatic configuration for internal use.
21257 +config AUFS_BR_HFSPLUS
21258 + bool "Hfsplus as an aufs branch"
21259 + depends on HFSPLUS_FS
21262 + If you want to use hfsplus fs as an aufs branch fs, then enable
21263 + this option. This option introduces a small overhead at
21264 + copying-up a file on hfsplus.
21266 +config AUFS_BDEV_LOOP
21268 + depends on BLK_DEV_LOOP
21271 + Automatic configuration for internal use.
21272 + Convert =[ym] into =y.
21275 + bool "Debug aufs"
21277 + Enable this to compile aufs internal debug code.
21278 + It will have a negative impact to the performance.
21280 +config AUFS_MAGIC_SYSRQ
21282 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21285 + Automatic configuration for internal use.
21286 + When aufs supports Magic SysRq, enabled automatically.
21288 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21289 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21290 +++ linux/fs/aufs/loop.c 2015-06-28 17:35:44.348050491 +0200
21293 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21295 + * This program, aufs is free software; you can redistribute it and/or modify
21296 + * it under the terms of the GNU General Public License as published by
21297 + * the Free Software Foundation; either version 2 of the License, or
21298 + * (at your option) any later version.
21300 + * This program is distributed in the hope that it will be useful,
21301 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21302 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21303 + * GNU General Public License for more details.
21305 + * You should have received a copy of the GNU General Public License
21306 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21310 + * support for loopback block device as a branch
21315 +/* added into drivers/block/loop.c */
21316 +static struct file *(*backing_file_func)(struct super_block *sb);
21319 + * test if two lower dentries have overlapping branches.
21321 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21323 + struct super_block *h_sb;
21324 + struct file *backing_file;
21326 + if (unlikely(!backing_file_func)) {
21327 + /* don't load "loop" module here */
21328 + backing_file_func = symbol_get(loop_backing_file);
21329 + if (unlikely(!backing_file_func))
21330 + /* "loop" module is not loaded */
21334 + h_sb = h_adding->d_sb;
21335 + backing_file = backing_file_func(h_sb);
21336 + if (!backing_file)
21339 + h_adding = backing_file->f_path.dentry;
21341 + * h_adding can be local NFS.
21342 + * in this case aufs cannot detect the loop.
21344 + if (unlikely(h_adding->d_sb == sb))
21346 + return !!au_test_subdir(h_adding, sb->s_root);
21349 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21350 +int au_test_loopback_kthread(void)
21353 + struct task_struct *tsk = current;
21354 + char c, comm[sizeof(tsk->comm)];
21357 + if (tsk->flags & PF_KTHREAD) {
21358 + get_task_comm(comm, tsk);
21360 + ret = ('0' <= c && c <= '9'
21361 + && !strncmp(comm, "loop", 4));
21367 +/* ---------------------------------------------------------------------- */
21369 +#define au_warn_loopback_step 16
21370 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21371 +static unsigned long *au_warn_loopback_array;
21373 +void au_warn_loopback(struct super_block *h_sb)
21375 + int i, new_nelem;
21376 + unsigned long *a, magic;
21377 + static DEFINE_SPINLOCK(spin);
21379 + magic = h_sb->s_magic;
21380 + spin_lock(&spin);
21381 + a = au_warn_loopback_array;
21382 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21383 + if (a[i] == magic) {
21384 + spin_unlock(&spin);
21388 + /* h_sb is new to us, print it */
21389 + if (i < au_warn_loopback_nelem) {
21394 + /* expand the array */
21395 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21396 + a = au_kzrealloc(au_warn_loopback_array,
21397 + au_warn_loopback_nelem * sizeof(unsigned long),
21398 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
21400 + au_warn_loopback_nelem = new_nelem;
21401 + au_warn_loopback_array = a;
21406 + spin_unlock(&spin);
21407 + AuWarn1("realloc failed, ignored\n");
21411 + spin_unlock(&spin);
21412 + pr_warn("you may want to try another patch for loopback file "
21413 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21416 +int au_loopback_init(void)
21419 + struct super_block *sb __maybe_unused;
21421 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
21424 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21425 + sizeof(unsigned long), GFP_NOFS);
21426 + if (unlikely(!au_warn_loopback_array))
21432 +void au_loopback_fin(void)
21434 + symbol_put(loop_backing_file);
21435 + kfree(au_warn_loopback_array);
21437 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21438 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21439 +++ linux/fs/aufs/loop.h 2015-06-28 17:35:44.348050491 +0200
21442 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21444 + * This program, aufs is free software; you can redistribute it and/or modify
21445 + * it under the terms of the GNU General Public License as published by
21446 + * the Free Software Foundation; either version 2 of the License, or
21447 + * (at your option) any later version.
21449 + * This program is distributed in the hope that it will be useful,
21450 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21451 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21452 + * GNU General Public License for more details.
21454 + * You should have received a copy of the GNU General Public License
21455 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21459 + * support for loopback mount as a branch
21462 +#ifndef __AUFS_LOOP_H__
21463 +#define __AUFS_LOOP_H__
21468 +struct super_block;
21470 +#ifdef CONFIG_AUFS_BDEV_LOOP
21471 +/* drivers/block/loop.c */
21472 +struct file *loop_backing_file(struct super_block *sb);
21475 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21476 +int au_test_loopback_kthread(void);
21477 +void au_warn_loopback(struct super_block *h_sb);
21479 +int au_loopback_init(void);
21480 +void au_loopback_fin(void);
21482 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21483 + struct dentry *h_adding)
21484 +AuStubInt0(au_test_loopback_kthread, void)
21485 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21487 +AuStubInt0(au_loopback_init, void)
21488 +AuStubVoid(au_loopback_fin, void)
21489 +#endif /* BLK_DEV_LOOP */
21491 +#endif /* __KERNEL__ */
21492 +#endif /* __AUFS_LOOP_H__ */
21493 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21494 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21495 +++ linux/fs/aufs/magic.mk 2015-06-28 17:35:44.348050491 +0200
21498 +# defined in ${srctree}/fs/fuse/inode.c
21500 +ifdef CONFIG_FUSE_FS
21501 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21504 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21506 +ifdef CONFIG_XFS_FS
21507 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21510 +# defined in ${srctree}/fs/configfs/mount.c
21512 +ifdef CONFIG_CONFIGFS_FS
21513 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21516 +# defined in ${srctree}/fs/ubifs/ubifs.h
21518 +ifdef CONFIG_UBIFS_FS
21519 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21522 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21524 +ifdef CONFIG_HFSPLUS_FS
21525 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21527 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
21528 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
21529 +++ linux/fs/aufs/Makefile 2015-06-28 17:35:44.344717109 +0200
21532 +include ${src}/magic.mk
21533 +ifeq (${CONFIG_AUFS_FS},m)
21534 +include ${src}/conf.mk
21536 +-include ${src}/priv_def.mk
21538 +# cf. include/linux/kernel.h
21540 +ccflags-y += -DDEBUG
21541 +# sparse requires the full pathname
21543 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
21545 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
21548 +obj-$(CONFIG_AUFS_FS) += aufs.o
21549 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
21550 + wkq.o vfsub.o dcsub.o \
21551 + cpup.o whout.o wbr_policy.o \
21552 + dinfo.o dentry.o \
21554 + finfo.o file.o f_op.o \
21556 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
21560 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
21561 +aufs-$(CONFIG_SYSFS) += sysfs.o
21562 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
21563 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
21564 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
21565 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
21566 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
21567 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
21568 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
21569 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
21570 +aufs-$(CONFIG_AUFS_POLL) += poll.o
21571 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
21572 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
21573 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
21574 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
21575 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
21576 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21577 +++ linux/fs/aufs/module.c 2015-06-28 17:35:44.348050491 +0200
21580 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21582 + * This program, aufs is free software; you can redistribute it and/or modify
21583 + * it under the terms of the GNU General Public License as published by
21584 + * the Free Software Foundation; either version 2 of the License, or
21585 + * (at your option) any later version.
21587 + * This program is distributed in the hope that it will be useful,
21588 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21589 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21590 + * GNU General Public License for more details.
21592 + * You should have received a copy of the GNU General Public License
21593 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21597 + * module global variables and operations
21600 +#include <linux/module.h>
21601 +#include <linux/seq_file.h>
21604 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21606 + if (new_sz <= nused)
21609 + p = krealloc(p, new_sz, gfp);
21611 + memset(p + nused, 0, new_sz - nused);
21615 +/* ---------------------------------------------------------------------- */
21620 +struct kmem_cache *au_cachep[AuCache_Last];
21621 +static int __init au_cache_init(void)
21623 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21624 + if (au_cachep[AuCache_DINFO])
21625 + /* SLAB_DESTROY_BY_RCU */
21626 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21627 + au_icntnr_init_once);
21628 + if (au_cachep[AuCache_ICNTNR])
21629 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21630 + au_fi_init_once);
21631 + if (au_cachep[AuCache_FINFO])
21632 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21633 + if (au_cachep[AuCache_VDIR])
21634 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21635 + if (au_cachep[AuCache_DEHSTR])
21641 +static void au_cache_fin(void)
21646 + * Make sure all delayed rcu free inodes are flushed before we
21651 + /* excluding AuCache_HNOTIFY */
21652 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21653 + for (i = 0; i < AuCache_HNOTIFY; i++)
21654 + if (au_cachep[i]) {
21655 + kmem_cache_destroy(au_cachep[i]);
21656 + au_cachep[i] = NULL;
21660 +/* ---------------------------------------------------------------------- */
21662 +int au_dir_roflags;
21664 +#ifdef CONFIG_AUFS_SBILIST
21666 + * iterate_supers_type() doesn't protect us from
21667 + * remounting (branch management)
21669 +struct au_splhead au_sbilist;
21672 +struct lock_class_key au_lc_key[AuLcKey_Last];
21675 + * functions for module interface.
21677 +MODULE_LICENSE("GPL");
21678 +/* MODULE_LICENSE("GPL v2"); */
21679 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21680 +MODULE_DESCRIPTION(AUFS_NAME
21681 + " -- Advanced multi layered unification filesystem");
21682 +MODULE_VERSION(AUFS_VERSION);
21683 +MODULE_ALIAS_FS(AUFS_NAME);
21685 +/* this module parameter has no meaning when SYSFS is disabled */
21686 +int sysaufs_brs = 1;
21687 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21688 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21690 +/* this module parameter has no meaning when USER_NS is disabled */
21691 +static bool au_userns;
21692 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21693 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21695 +/* ---------------------------------------------------------------------- */
21697 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21699 +int au_seq_path(struct seq_file *seq, struct path *path)
21701 + return seq_path(seq, path, au_esc_chars);
21704 +/* ---------------------------------------------------------------------- */
21706 +static int __init aufs_init(void)
21711 + p = au_esc_chars;
21712 + for (i = 1; i <= ' '; i++)
21718 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21720 + au_sbilist_init();
21721 + sysaufs_brs_init();
21724 + err = sysaufs_init();
21725 + if (unlikely(err))
21727 + err = au_procfs_init();
21728 + if (unlikely(err))
21729 + goto out_sysaufs;
21730 + err = au_wkq_init();
21731 + if (unlikely(err))
21733 + err = au_loopback_init();
21734 + if (unlikely(err))
21736 + err = au_hnotify_init();
21737 + if (unlikely(err))
21738 + goto out_loopback;
21739 + err = au_sysrq_init();
21740 + if (unlikely(err))
21742 + err = au_cache_init();
21743 + if (unlikely(err))
21746 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
21747 + err = register_filesystem(&aufs_fs_type);
21748 + if (unlikely(err))
21751 + /* since we define pr_fmt, call printk directly */
21752 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
21753 + goto out; /* success */
21760 + au_hnotify_fin();
21762 + au_loopback_fin();
21774 +static void __exit aufs_exit(void)
21776 + unregister_filesystem(&aufs_fs_type);
21779 + au_hnotify_fin();
21780 + au_loopback_fin();
21787 +module_init(aufs_init);
21788 +module_exit(aufs_exit);
21789 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
21790 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
21791 +++ linux/fs/aufs/module.h 2015-06-28 17:35:44.348050491 +0200
21794 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21796 + * This program, aufs is free software; you can redistribute it and/or modify
21797 + * it under the terms of the GNU General Public License as published by
21798 + * the Free Software Foundation; either version 2 of the License, or
21799 + * (at your option) any later version.
21801 + * This program is distributed in the hope that it will be useful,
21802 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21803 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21804 + * GNU General Public License for more details.
21806 + * You should have received a copy of the GNU General Public License
21807 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21811 + * module initialization and module-global
21814 +#ifndef __AUFS_MODULE_H__
21815 +#define __AUFS_MODULE_H__
21819 +#include <linux/slab.h>
21824 +/* module parameters */
21825 +extern int sysaufs_brs;
21827 +/* ---------------------------------------------------------------------- */
21829 +extern int au_dir_roflags;
21832 + AuLcNonDir_FIINFO,
21833 + AuLcNonDir_DIINFO,
21834 + AuLcNonDir_IIINFO,
21840 + AuLcSymlink_DIINFO,
21841 + AuLcSymlink_IIINFO,
21845 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
21847 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
21848 +int au_seq_path(struct seq_file *seq, struct path *path);
21850 +#ifdef CONFIG_PROC_FS
21852 +int __init au_procfs_init(void);
21853 +void au_procfs_fin(void);
21855 +AuStubInt0(au_procfs_init, void);
21856 +AuStubVoid(au_procfs_fin, void);
21859 +/* ---------------------------------------------------------------------- */
21868 + AuCache_HNOTIFY, /* must be last */
21872 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
21873 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
21874 +#define AuCacheCtor(type, ctor) \
21875 + kmem_cache_create(#type, sizeof(struct type), \
21876 + __alignof__(struct type), AuCacheFlags, ctor)
21878 +extern struct kmem_cache *au_cachep[];
21880 +#define AuCacheFuncs(name, index) \
21881 +static inline struct au_##name *au_cache_alloc_##name(void) \
21882 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
21883 +static inline void au_cache_free_##name(struct au_##name *p) \
21884 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
21886 +AuCacheFuncs(dinfo, DINFO);
21887 +AuCacheFuncs(icntnr, ICNTNR);
21888 +AuCacheFuncs(finfo, FINFO);
21889 +AuCacheFuncs(vdir, VDIR);
21890 +AuCacheFuncs(vdir_dehstr, DEHSTR);
21891 +#ifdef CONFIG_AUFS_HNOTIFY
21892 +AuCacheFuncs(hnotify, HNOTIFY);
21895 +#endif /* __KERNEL__ */
21896 +#endif /* __AUFS_MODULE_H__ */
21897 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
21898 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
21899 +++ linux/fs/aufs/mvdown.c 2015-06-28 17:36:09.025073697 +0200
21902 + * Copyright (C) 2011-2015 Junjiro R. Okajima
21904 + * This program, aufs is free software; you can redistribute it and/or modify
21905 + * it under the terms of the GNU General Public License as published by
21906 + * the Free Software Foundation; either version 2 of the License, or
21907 + * (at your option) any later version.
21909 + * This program is distributed in the hope that it will be useful,
21910 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21911 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21912 + * GNU General Public License for more details.
21914 + * You should have received a copy of the GNU General Public License
21915 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21919 + * move-down, opposite of copy-up
21924 +struct au_mvd_args {
21926 + struct super_block *h_sb;
21927 + struct dentry *h_parent;
21928 + struct au_hinode *hdir;
21929 + struct inode *h_dir, *h_inode;
21930 + struct au_pin pin;
21931 + } info[AUFS_MVDOWN_NARRAY];
21933 + struct aufs_mvdown mvdown;
21934 + struct dentry *dentry, *parent;
21935 + struct inode *inode, *dir;
21936 + struct super_block *sb;
21937 + aufs_bindex_t bopq, bwh, bfound;
21938 + unsigned char rename_lock;
21941 +#define mvd_errno mvdown.au_errno
21942 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
21943 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
21944 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
21945 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
21947 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
21948 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
21949 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
21950 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
21951 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
21952 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
21954 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
21955 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
21956 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
21957 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
21958 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
21959 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
21961 +#define AU_MVD_PR(flag, ...) do { \
21963 + pr_err(__VA_ARGS__); \
21966 +static int find_lower_writable(struct au_mvd_args *a)
21968 + struct super_block *sb;
21969 + aufs_bindex_t bindex, bend;
21970 + struct au_branch *br;
21973 + bindex = a->mvd_bsrc;
21974 + bend = au_sbend(sb);
21975 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
21976 + for (bindex++; bindex <= bend; bindex++) {
21977 + br = au_sbr(sb, bindex);
21978 + if (au_br_fhsm(br->br_perm)
21979 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
21982 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
21983 + for (bindex++; bindex <= bend; bindex++) {
21984 + br = au_sbr(sb, bindex);
21985 + if (!au_br_rdonly(br))
21989 + for (bindex++; bindex <= bend; bindex++) {
21990 + br = au_sbr(sb, bindex);
21991 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
21992 + if (au_br_rdonly(br))
21994 + |= AUFS_MVDOWN_ROLOWER_R;
22002 +/* make the parent dir on bdst */
22003 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22008 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22009 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22010 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22011 + a->mvd_h_dst_parent = NULL;
22012 + if (au_dbend(a->parent) >= a->mvd_bdst)
22013 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22014 + if (!a->mvd_h_dst_parent) {
22015 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22016 + if (unlikely(err)) {
22017 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22020 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22028 +/* lock them all */
22029 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22032 + struct dentry *h_trap;
22034 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22035 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22036 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22037 + au_opt_udba(a->sb),
22038 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22040 + if (unlikely(err)) {
22041 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22045 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22046 + a->rename_lock = 0;
22047 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22048 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22049 + au_opt_udba(a->sb),
22050 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22051 + err = au_do_pin(&a->mvd_pin_src);
22053 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22054 + if (unlikely(err)) {
22055 + AU_MVD_PR(dmsg, "pin_src failed\n");
22058 + goto out; /* success */
22061 + a->rename_lock = 1;
22062 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22063 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22064 + au_opt_udba(a->sb),
22065 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22067 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22068 + if (unlikely(err)) {
22069 + AU_MVD_PR(dmsg, "pin_src failed\n");
22070 + au_pin_hdir_lock(&a->mvd_pin_dst);
22073 + au_pin_hdir_unlock(&a->mvd_pin_src);
22074 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22075 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22077 + err = (h_trap != a->mvd_h_src_parent);
22079 + err = (h_trap != a->mvd_h_dst_parent);
22081 + BUG_ON(err); /* it should never happen */
22082 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22085 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22086 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22087 + au_pin_hdir_lock(&a->mvd_pin_src);
22088 + au_unpin(&a->mvd_pin_src);
22089 + au_pin_hdir_lock(&a->mvd_pin_dst);
22092 + goto out; /* success */
22095 + au_unpin(&a->mvd_pin_dst);
22101 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22103 + if (!a->rename_lock)
22104 + au_unpin(&a->mvd_pin_src);
22106 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22107 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22108 + au_pin_hdir_lock(&a->mvd_pin_src);
22109 + au_unpin(&a->mvd_pin_src);
22110 + au_pin_hdir_lock(&a->mvd_pin_dst);
22112 + au_unpin(&a->mvd_pin_dst);
22115 +/* copy-down the file */
22116 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22119 + struct au_cp_generic cpg = {
22120 + .dentry = a->dentry,
22121 + .bdst = a->mvd_bdst,
22122 + .bsrc = a->mvd_bsrc,
22124 + .pin = &a->mvd_pin_dst,
22125 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22128 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22129 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22130 + au_fset_cpup(cpg.flags, OVERWRITE);
22131 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22132 + au_fset_cpup(cpg.flags, RWDST);
22133 + err = au_sio_cpdown_simple(&cpg);
22134 + if (unlikely(err))
22135 + AU_MVD_PR(dmsg, "cpdown failed\n");
22142 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22145 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22148 + struct path h_path;
22149 + struct au_branch *br;
22150 + struct inode *delegated;
22152 + br = au_sbr(a->sb, a->mvd_bdst);
22153 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22154 + err = PTR_ERR(h_path.dentry);
22155 + if (IS_ERR(h_path.dentry)) {
22156 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22161 + if (d_is_positive(h_path.dentry)) {
22162 + h_path.mnt = au_br_mnt(br);
22163 + delegated = NULL;
22164 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22165 + &delegated, /*force*/0);
22166 + if (unlikely(err == -EWOULDBLOCK)) {
22167 + pr_warn("cannot retry for NFSv4 delegation"
22168 + " for an internal unlink\n");
22171 + if (unlikely(err))
22172 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22174 + dput(h_path.dentry);
22182 + * unlink the topmost h_dentry
22184 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22187 + struct path h_path;
22188 + struct inode *delegated;
22190 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22191 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22192 + delegated = NULL;
22193 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22194 + if (unlikely(err == -EWOULDBLOCK)) {
22195 + pr_warn("cannot retry for NFSv4 delegation"
22196 + " for an internal unlink\n");
22199 + if (unlikely(err))
22200 + AU_MVD_PR(dmsg, "unlink failed\n");
22206 +/* Since mvdown succeeded, we ignore an error of this function */
22207 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22210 + struct au_branch *br;
22212 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22213 + br = au_sbr(a->sb, a->mvd_bsrc);
22214 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22216 + br = au_sbr(a->sb, a->mvd_bdst);
22217 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22218 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22221 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22223 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22227 + * copy-down the file and unlink the bsrc file.
22228 + * - unlink the bdst whout if exist
22229 + * - copy-down the file (with whtmp name and rename)
22230 + * - unlink the bsrc file
22232 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22236 + err = au_do_mkdir(dmsg, a);
22238 + err = au_do_lock(dmsg, a);
22239 + if (unlikely(err))
22243 + * do not revert the activities we made on bdst since they should be
22244 + * harmless in aufs.
22247 + err = au_do_cpdown(dmsg, a);
22249 + err = au_do_unlink_wh(dmsg, a);
22250 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22251 + err = au_do_unlink(dmsg, a);
22252 + if (unlikely(err))
22255 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22256 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22257 + if (find_lower_writable(a) < 0)
22258 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22260 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22261 + au_do_stfs(dmsg, a);
22263 + /* maintain internal array */
22264 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22265 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22266 + au_set_dbstart(a->dentry, a->mvd_bdst);
22267 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22268 + au_set_ibstart(a->inode, a->mvd_bdst);
22270 + if (au_dbend(a->dentry) < a->mvd_bdst)
22271 + au_set_dbend(a->dentry, a->mvd_bdst);
22272 + if (au_ibend(a->inode) < a->mvd_bdst)
22273 + au_set_ibend(a->inode, a->mvd_bdst);
22276 + au_do_unlock(dmsg, a);
22282 +/* ---------------------------------------------------------------------- */
22284 +/* make sure the file is idle */
22285 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22287 + int err, plinked;
22290 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22291 + if (au_dbstart(a->dentry) == a->mvd_bsrc
22292 + && au_dcount(a->dentry) == 1
22293 + && atomic_read(&a->inode->i_count) == 1
22294 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22295 + && (!plinked || !au_plink_test(a->inode))
22296 + && a->inode->i_nlink == 1)
22301 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22302 + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry),
22303 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22304 + a->mvd_h_src_inode->i_nlink,
22305 + plinked, plinked ? au_plink_test(a->inode) : 0);
22312 +/* make sure the parent dir is fine */
22313 +static int au_mvd_args_parent(const unsigned char dmsg,
22314 + struct au_mvd_args *a)
22317 + aufs_bindex_t bindex;
22320 + if (unlikely(au_alive_dir(a->parent))) {
22322 + AU_MVD_PR(dmsg, "parent dir is dead\n");
22326 + a->bopq = au_dbdiropq(a->parent);
22327 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
22328 + AuDbg("b%d\n", bindex);
22329 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
22330 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
22332 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
22333 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
22334 + a->bopq, a->mvd_bdst);
22342 +static int au_mvd_args_intermediate(const unsigned char dmsg,
22343 + struct au_mvd_args *a)
22346 + struct au_dinfo *dinfo, *tmp;
22348 + /* lookup the next lower positive entry */
22350 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
22351 + if (unlikely(!tmp))
22356 + dinfo = au_di(a->dentry);
22357 + au_di_cp(tmp, dinfo);
22358 + au_di_swap(tmp, dinfo);
22360 + /* returns the number of positive dentries */
22361 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
22363 + a->bwh = au_dbwh(a->dentry);
22364 + else if (err > 0)
22365 + a->bfound = au_dbstart(a->dentry);
22367 + au_di_swap(tmp, dinfo);
22368 + au_rw_write_unlock(&tmp->di_rwsem);
22370 + if (unlikely(err < 0))
22371 + AU_MVD_PR(dmsg, "failed look-up lower\n");
22374 + * here, we have these cases.
22376 + * no positive dentry under bsrc. there are more sub-cases.
22378 + * there no whiteout, we can safely move-down.
22381 + * bsrc < bwh && bwh < bdst
22382 + * there is a whiteout on RO branch. cannot proceed.
22384 + * there is a whiteout on the RW target branch. it should
22387 + * there is a whiteout somewhere unrelated branch.
22388 + * -1 < bfound && bfound <= bsrc
22391 + * found, but it is on RO branch between bsrc and bdst. cannot
22394 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
22397 + * found, after we create the file on bdst, it will be hidden.
22400 + AuDebugOn(a->bfound == -1
22402 + && a->bwh <= a->mvd_bsrc);
22403 + AuDebugOn(-1 < a->bfound
22404 + && a->bfound <= a->mvd_bsrc);
22407 + if (a->bfound == -1
22408 + && a->mvd_bsrc < a->bwh
22410 + && a->bwh < a->mvd_bdst) {
22411 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
22412 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
22413 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
22415 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
22416 + a->mvd_errno = EAU_MVDOWN_UPPER;
22417 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
22418 + a->mvd_bdst, a->bfound);
22422 + err = 0; /* success */
22429 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
22434 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22435 + && a->bfound == a->mvd_bdst)
22441 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
22444 + struct au_branch *br;
22447 + if (unlikely(S_ISDIR(a->inode->i_mode)))
22451 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
22452 + a->mvd_bsrc = au_ibstart(a->inode);
22454 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
22455 + if (unlikely(a->mvd_bsrc < 0
22456 + || (a->mvd_bsrc < au_dbstart(a->dentry)
22457 + || au_dbend(a->dentry) < a->mvd_bsrc
22458 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
22459 + || (a->mvd_bsrc < au_ibstart(a->inode)
22460 + || au_ibend(a->inode) < a->mvd_bsrc
22461 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
22462 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
22463 + AU_MVD_PR(dmsg, "no upper\n");
22467 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
22468 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22469 + AU_MVD_PR(dmsg, "on the bottom\n");
22472 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
22473 + br = au_sbr(a->sb, a->mvd_bsrc);
22474 + err = au_br_rdonly(br);
22475 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
22476 + if (unlikely(err))
22478 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
22479 + || IS_APPEND(a->mvd_h_src_inode))) {
22481 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
22487 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
22488 + a->mvd_bdst = find_lower_writable(a);
22489 + if (unlikely(a->mvd_bdst < 0)) {
22490 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22491 + AU_MVD_PR(dmsg, "no writable lower branch\n");
22495 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
22496 + if (unlikely(a->mvd_bdst < 0
22497 + || au_sbend(a->sb) < a->mvd_bdst)) {
22498 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
22499 + AU_MVD_PR(dmsg, "no lower brid\n");
22504 + err = au_mvd_args_busy(dmsg, a);
22506 + err = au_mvd_args_parent(dmsg, a);
22508 + err = au_mvd_args_intermediate(dmsg, a);
22510 + err = au_mvd_args_exist(dmsg, a);
22512 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
22519 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
22522 + unsigned char dmsg;
22523 + struct au_mvd_args *args;
22526 + if (unlikely(!capable(CAP_SYS_ADMIN)))
22530 + args = kmalloc(sizeof(*args), GFP_NOFS);
22531 + if (unlikely(!args))
22534 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
22536 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
22537 + if (unlikely(err)) {
22542 + AuDbg("flags 0x%x\n", args->mvdown.flags);
22543 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
22544 + args->mvdown.au_errno = 0;
22545 + args->dentry = dentry;
22546 + args->inode = d_inode(dentry);
22547 + args->sb = dentry->d_sb;
22550 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
22551 + args->parent = dget_parent(dentry);
22552 + args->dir = d_inode(args->parent);
22553 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
22554 + dput(args->parent);
22555 + if (unlikely(args->parent != dentry->d_parent)) {
22556 + AU_MVD_PR(dmsg, "parent dir is moved\n");
22560 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
22561 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
22562 + if (unlikely(err))
22565 + di_write_lock_parent(args->parent);
22566 + err = au_mvd_args(dmsg, args);
22567 + if (unlikely(err))
22570 + err = au_do_mvdown(dmsg, args);
22571 + if (unlikely(err))
22574 + au_cpup_attr_timesizes(args->dir);
22575 + au_cpup_attr_timesizes(args->inode);
22576 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
22577 + /* au_digen_dec(dentry); */
22580 + di_write_unlock(args->parent);
22581 + aufs_read_unlock(dentry, AuLock_DW);
22583 + mutex_unlock(&args->inode->i_mutex);
22585 + mutex_unlock(&args->dir->i_mutex);
22587 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
22595 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
22596 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
22597 +++ linux/fs/aufs/opts.c 2015-06-28 17:36:09.028407078 +0200
22600 + * Copyright (C) 2005-2015 Junjiro R. Okajima
22602 + * This program, aufs is free software; you can redistribute it and/or modify
22603 + * it under the terms of the GNU General Public License as published by
22604 + * the Free Software Foundation; either version 2 of the License, or
22605 + * (at your option) any later version.
22607 + * This program is distributed in the hope that it will be useful,
22608 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22609 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22610 + * GNU General Public License for more details.
22612 + * You should have received a copy of the GNU General Public License
22613 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22617 + * mount options/flags
22620 +#include <linux/namei.h>
22621 +#include <linux/types.h> /* a distribution requires */
22622 +#include <linux/parser.h>
22625 +/* ---------------------------------------------------------------------- */
22629 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
22630 + Opt_idel, Opt_imod,
22631 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
22632 + Opt_rdblk_def, Opt_rdhash_def,
22633 + Opt_xino, Opt_noxino,
22634 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22635 + Opt_trunc_xino_path, Opt_itrunc_xino,
22636 + Opt_trunc_xib, Opt_notrunc_xib,
22637 + Opt_shwh, Opt_noshwh,
22638 + Opt_plink, Opt_noplink, Opt_list_plink,
22640 + Opt_dio, Opt_nodio,
22641 + Opt_diropq_a, Opt_diropq_w,
22642 + Opt_warn_perm, Opt_nowarn_perm,
22643 + Opt_wbr_copyup, Opt_wbr_create,
22645 + Opt_verbose, Opt_noverbose,
22646 + Opt_sum, Opt_nosum, Opt_wsum,
22647 + Opt_dirperm1, Opt_nodirperm1,
22648 + Opt_acl, Opt_noacl,
22649 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22652 +static match_table_t options = {
22653 + {Opt_br, "br=%s"},
22654 + {Opt_br, "br:%s"},
22656 + {Opt_add, "add=%d:%s"},
22657 + {Opt_add, "add:%d:%s"},
22658 + {Opt_add, "ins=%d:%s"},
22659 + {Opt_add, "ins:%d:%s"},
22660 + {Opt_append, "append=%s"},
22661 + {Opt_append, "append:%s"},
22662 + {Opt_prepend, "prepend=%s"},
22663 + {Opt_prepend, "prepend:%s"},
22665 + {Opt_del, "del=%s"},
22666 + {Opt_del, "del:%s"},
22667 + /* {Opt_idel, "idel:%d"}, */
22668 + {Opt_mod, "mod=%s"},
22669 + {Opt_mod, "mod:%s"},
22670 + /* {Opt_imod, "imod:%d:%s"}, */
22672 + {Opt_dirwh, "dirwh=%d"},
22674 + {Opt_xino, "xino=%s"},
22675 + {Opt_noxino, "noxino"},
22676 + {Opt_trunc_xino, "trunc_xino"},
22677 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22678 + {Opt_notrunc_xino, "notrunc_xino"},
22679 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22680 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22681 + /* {Opt_zxino, "zxino=%s"}, */
22682 + {Opt_trunc_xib, "trunc_xib"},
22683 + {Opt_notrunc_xib, "notrunc_xib"},
22685 +#ifdef CONFIG_PROC_FS
22686 + {Opt_plink, "plink"},
22688 + {Opt_ignore_silent, "plink"},
22691 + {Opt_noplink, "noplink"},
22693 +#ifdef CONFIG_AUFS_DEBUG
22694 + {Opt_list_plink, "list_plink"},
22697 + {Opt_udba, "udba=%s"},
22699 + {Opt_dio, "dio"},
22700 + {Opt_nodio, "nodio"},
22702 +#ifdef CONFIG_AUFS_FHSM
22703 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22705 + {Opt_ignore_silent, "fhsm_sec=%d"},
22708 + {Opt_diropq_a, "diropq=always"},
22709 + {Opt_diropq_a, "diropq=a"},
22710 + {Opt_diropq_w, "diropq=whiteouted"},
22711 + {Opt_diropq_w, "diropq=w"},
22713 + {Opt_warn_perm, "warn_perm"},
22714 + {Opt_nowarn_perm, "nowarn_perm"},
22716 + /* keep them temporary */
22717 + {Opt_ignore_silent, "nodlgt"},
22718 + {Opt_ignore_silent, "clean_plink"},
22720 +#ifdef CONFIG_AUFS_SHWH
22721 + {Opt_shwh, "shwh"},
22723 + {Opt_noshwh, "noshwh"},
22725 + {Opt_dirperm1, "dirperm1"},
22726 + {Opt_nodirperm1, "nodirperm1"},
22728 + {Opt_verbose, "verbose"},
22729 + {Opt_verbose, "v"},
22730 + {Opt_noverbose, "noverbose"},
22731 + {Opt_noverbose, "quiet"},
22732 + {Opt_noverbose, "q"},
22733 + {Opt_noverbose, "silent"},
22735 + {Opt_sum, "sum"},
22736 + {Opt_nosum, "nosum"},
22737 + {Opt_wsum, "wsum"},
22739 + {Opt_rdcache, "rdcache=%d"},
22740 + {Opt_rdblk, "rdblk=%d"},
22741 + {Opt_rdblk_def, "rdblk=def"},
22742 + {Opt_rdhash, "rdhash=%d"},
22743 + {Opt_rdhash_def, "rdhash=def"},
22745 + {Opt_wbr_create, "create=%s"},
22746 + {Opt_wbr_create, "create_policy=%s"},
22747 + {Opt_wbr_copyup, "cpup=%s"},
22748 + {Opt_wbr_copyup, "copyup=%s"},
22749 + {Opt_wbr_copyup, "copyup_policy=%s"},
22751 + /* generic VFS flag */
22752 +#ifdef CONFIG_FS_POSIX_ACL
22753 + {Opt_acl, "acl"},
22754 + {Opt_noacl, "noacl"},
22756 + {Opt_ignore_silent, "acl"},
22757 + {Opt_ignore_silent, "noacl"},
22760 + /* internal use for the scripts */
22761 + {Opt_ignore_silent, "si=%s"},
22763 + {Opt_br, "dirs=%s"},
22764 + {Opt_ignore, "debug=%d"},
22765 + {Opt_ignore, "delete=whiteout"},
22766 + {Opt_ignore, "delete=all"},
22767 + {Opt_ignore, "imap=%s"},
22769 + /* temporary workaround, due to old mount(8)? */
22770 + {Opt_ignore_silent, "relatime"},
22775 +/* ---------------------------------------------------------------------- */
22777 +static const char *au_parser_pattern(int val, match_table_t tbl)
22779 + struct match_token *p;
22782 + while (p->pattern) {
22783 + if (p->token == val)
22784 + return p->pattern;
22791 +static const char *au_optstr(int *val, match_table_t tbl)
22793 + struct match_token *p;
22800 + while (p->pattern) {
22802 + && (v & p->token) == p->token) {
22803 + *val &= ~p->token;
22804 + return p->pattern;
22813 +/* ---------------------------------------------------------------------- */
22815 +static match_table_t brperm = {
22816 + {AuBrPerm_RO, AUFS_BRPERM_RO},
22817 + {AuBrPerm_RR, AUFS_BRPERM_RR},
22818 + {AuBrPerm_RW, AUFS_BRPERM_RW},
22822 +static match_table_t brattr = {
22824 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
22825 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
22826 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
22827 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
22828 +#ifdef CONFIG_AUFS_FHSM
22829 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
22831 +#ifdef CONFIG_AUFS_XATTR
22832 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
22833 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
22834 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
22835 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
22836 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
22837 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
22840 + /* ro/rr branch */
22841 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
22844 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
22845 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
22850 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
22857 + p = strchr(str, '+');
22860 + v = match_token(str, table, args);
22862 + if (v & AuBrAttr_CMOO_Mask)
22863 + attr &= ~AuBrAttr_CMOO_Mask;
22868 + pr_warn("ignored branch attribute %s\n", str);
22878 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
22886 + p = au_optstr(&perm, brattr);
22889 + memcpy(q, p, sz + 1);
22895 + p = au_optstr(&perm, brattr);
22899 + memcpy(q, p, sz + 1);
22905 + return q - str->a;
22908 +static int noinline_for_stack br_perm_val(char *perm)
22910 + int val, bad, sz;
22912 + substring_t args[MAX_OPT_ARGS];
22913 + au_br_perm_str_t attr;
22915 + p = strchr(perm, '+');
22918 + val = match_token(perm, brperm, args);
22922 + pr_warn("ignored branch permission %s\n", perm);
22923 + val = AuBrPerm_RO;
22929 + val |= br_attr_val(p + 1, brattr, args);
22932 + switch (val & AuBrPerm_Mask) {
22933 + case AuBrPerm_RO:
22934 + case AuBrPerm_RR:
22935 + bad = val & AuBrWAttr_Mask;
22936 + val &= ~AuBrWAttr_Mask;
22938 + case AuBrPerm_RW:
22939 + bad = val & AuBrRAttr_Mask;
22940 + val &= ~AuBrRAttr_Mask;
22945 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
22946 + * does not treat it as an error, just warning.
22947 + * this is a tiny guard for the user operation.
22949 + if (val & AuBrAttr_UNPIN) {
22950 + bad |= AuBrAttr_UNPIN;
22951 + val &= ~AuBrAttr_UNPIN;
22954 + if (unlikely(bad)) {
22955 + sz = au_do_optstr_br_attr(&attr, bad);
22957 + pr_warn("ignored branch attribute %s\n", attr.a);
22964 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
22966 + au_br_perm_str_t attr;
22972 + p = au_optstr(&perm, brperm);
22973 + AuDebugOn(!p || !*p);
22975 + memcpy(q, p, sz + 1);
22978 + sz = au_do_optstr_br_attr(&attr, perm);
22981 + memcpy(q, attr.a, sz + 1);
22984 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
22987 +/* ---------------------------------------------------------------------- */
22989 +static match_table_t udbalevel = {
22990 + {AuOpt_UDBA_REVAL, "reval"},
22991 + {AuOpt_UDBA_NONE, "none"},
22992 +#ifdef CONFIG_AUFS_HNOTIFY
22993 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
22994 +#ifdef CONFIG_AUFS_HFSNOTIFY
22995 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23001 +static int noinline_for_stack udba_val(char *str)
23003 + substring_t args[MAX_OPT_ARGS];
23005 + return match_token(str, udbalevel, args);
23008 +const char *au_optstr_udba(int udba)
23010 + return au_parser_pattern(udba, udbalevel);
23013 +/* ---------------------------------------------------------------------- */
23015 +static match_table_t au_wbr_create_policy = {
23016 + {AuWbrCreate_TDP, "tdp"},
23017 + {AuWbrCreate_TDP, "top-down-parent"},
23018 + {AuWbrCreate_RR, "rr"},
23019 + {AuWbrCreate_RR, "round-robin"},
23020 + {AuWbrCreate_MFS, "mfs"},
23021 + {AuWbrCreate_MFS, "most-free-space"},
23022 + {AuWbrCreate_MFSV, "mfs:%d"},
23023 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23025 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23026 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23027 + {AuWbrCreate_PMFS, "pmfs"},
23028 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23029 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23030 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23036 + * cf. linux/lib/parser.c and cmdline.c
23037 + * gave up calling memparse() since it uses simple_strtoull() instead of
23040 +static int noinline_for_stack
23041 +au_match_ull(substring_t *s, unsigned long long *result)
23044 + unsigned int len;
23048 + len = s->to - s->from;
23049 + if (len + 1 <= sizeof(a)) {
23050 + memcpy(a, s->from, len);
23052 + err = kstrtoull(a, 0, result);
23057 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23058 + struct au_opt_wbr_create *create)
23061 + unsigned long long ull;
23064 + if (!au_match_ull(arg, &ull))
23065 + create->mfsrr_watermark = ull;
23067 + pr_err("bad integer in %s\n", str);
23074 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23075 + struct au_opt_wbr_create *create)
23080 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23081 + create->mfs_second = n;
23083 + pr_err("bad integer in %s\n", str);
23090 +static int noinline_for_stack
23091 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23094 + substring_t args[MAX_OPT_ARGS];
23096 + err = match_token(str, au_wbr_create_policy, args);
23097 + create->wbr_create = err;
23099 + case AuWbrCreate_MFSRRV:
23100 + case AuWbrCreate_PMFSRRV:
23101 + e = au_wbr_mfs_wmark(&args[0], str, create);
23103 + e = au_wbr_mfs_sec(&args[1], str, create);
23107 + case AuWbrCreate_MFSRR:
23108 + case AuWbrCreate_PMFSRR:
23109 + e = au_wbr_mfs_wmark(&args[0], str, create);
23110 + if (unlikely(e)) {
23115 + case AuWbrCreate_MFS:
23116 + case AuWbrCreate_PMFS:
23117 + create->mfs_second = AUFS_MFS_DEF_SEC;
23119 + case AuWbrCreate_MFSV:
23120 + case AuWbrCreate_PMFSV:
23121 + e = au_wbr_mfs_sec(&args[0], str, create);
23130 +const char *au_optstr_wbr_create(int wbr_create)
23132 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23135 +static match_table_t au_wbr_copyup_policy = {
23136 + {AuWbrCopyup_TDP, "tdp"},
23137 + {AuWbrCopyup_TDP, "top-down-parent"},
23138 + {AuWbrCopyup_BUP, "bup"},
23139 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23140 + {AuWbrCopyup_BU, "bu"},
23141 + {AuWbrCopyup_BU, "bottom-up"},
23145 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23147 + substring_t args[MAX_OPT_ARGS];
23149 + return match_token(str, au_wbr_copyup_policy, args);
23152 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23154 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23157 +/* ---------------------------------------------------------------------- */
23159 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23161 +static void dump_opts(struct au_opts *opts)
23163 +#ifdef CONFIG_AUFS_DEBUG
23164 + /* reduce stack space */
23166 + struct au_opt_add *add;
23167 + struct au_opt_del *del;
23168 + struct au_opt_mod *mod;
23169 + struct au_opt_xino *xino;
23170 + struct au_opt_xino_itrunc *xino_itrunc;
23171 + struct au_opt_wbr_create *create;
23173 + struct au_opt *opt;
23176 + while (opt->type != Opt_tail) {
23177 + switch (opt->type) {
23179 + u.add = &opt->add;
23180 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23181 + u.add->bindex, u.add->pathname, u.add->perm,
23182 + u.add->path.dentry);
23186 + u.del = &opt->del;
23187 + AuDbg("del {%s, %p}\n",
23188 + u.del->pathname, u.del->h_path.dentry);
23192 + u.mod = &opt->mod;
23193 + AuDbg("mod {%s, 0x%x, %p}\n",
23194 + u.mod->path, u.mod->perm, u.mod->h_root);
23197 + u.add = &opt->add;
23198 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23199 + u.add->bindex, u.add->pathname, u.add->perm,
23200 + u.add->path.dentry);
23202 + case Opt_prepend:
23203 + u.add = &opt->add;
23204 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23205 + u.add->bindex, u.add->pathname, u.add->perm,
23206 + u.add->path.dentry);
23209 + AuDbg("dirwh %d\n", opt->dirwh);
23211 + case Opt_rdcache:
23212 + AuDbg("rdcache %d\n", opt->rdcache);
23215 + AuDbg("rdblk %u\n", opt->rdblk);
23217 + case Opt_rdblk_def:
23218 + AuDbg("rdblk_def\n");
23221 + AuDbg("rdhash %u\n", opt->rdhash);
23223 + case Opt_rdhash_def:
23224 + AuDbg("rdhash_def\n");
23227 + u.xino = &opt->xino;
23228 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23230 + case Opt_trunc_xino:
23231 + AuLabel(trunc_xino);
23233 + case Opt_notrunc_xino:
23234 + AuLabel(notrunc_xino);
23236 + case Opt_trunc_xino_path:
23237 + case Opt_itrunc_xino:
23238 + u.xino_itrunc = &opt->xino_itrunc;
23239 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23244 + case Opt_trunc_xib:
23245 + AuLabel(trunc_xib);
23247 + case Opt_notrunc_xib:
23248 + AuLabel(notrunc_xib);
23256 + case Opt_dirperm1:
23257 + AuLabel(dirperm1);
23259 + case Opt_nodirperm1:
23260 + AuLabel(nodirperm1);
23265 + case Opt_noplink:
23266 + AuLabel(noplink);
23268 + case Opt_list_plink:
23269 + AuLabel(list_plink);
23272 + AuDbg("udba %d, %s\n",
23273 + opt->udba, au_optstr_udba(opt->udba));
23281 + case Opt_diropq_a:
23282 + AuLabel(diropq_a);
23284 + case Opt_diropq_w:
23285 + AuLabel(diropq_w);
23287 + case Opt_warn_perm:
23288 + AuLabel(warn_perm);
23290 + case Opt_nowarn_perm:
23291 + AuLabel(nowarn_perm);
23293 + case Opt_verbose:
23294 + AuLabel(verbose);
23296 + case Opt_noverbose:
23297 + AuLabel(noverbose);
23308 + case Opt_wbr_create:
23309 + u.create = &opt->wbr_create;
23310 + AuDbg("create %d, %s\n", u.create->wbr_create,
23311 + au_optstr_wbr_create(u.create->wbr_create));
23312 + switch (u.create->wbr_create) {
23313 + case AuWbrCreate_MFSV:
23314 + case AuWbrCreate_PMFSV:
23315 + AuDbg("%d sec\n", u.create->mfs_second);
23317 + case AuWbrCreate_MFSRR:
23318 + AuDbg("%llu watermark\n",
23319 + u.create->mfsrr_watermark);
23321 + case AuWbrCreate_MFSRRV:
23322 + case AuWbrCreate_PMFSRRV:
23323 + AuDbg("%llu watermark, %d sec\n",
23324 + u.create->mfsrr_watermark,
23325 + u.create->mfs_second);
23329 + case Opt_wbr_copyup:
23330 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
23331 + au_optstr_wbr_copyup(opt->wbr_copyup));
23333 + case Opt_fhsm_sec:
23334 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
23350 +void au_opts_free(struct au_opts *opts)
23352 + struct au_opt *opt;
23355 + while (opt->type != Opt_tail) {
23356 + switch (opt->type) {
23359 + case Opt_prepend:
23360 + path_put(&opt->add.path);
23364 + path_put(&opt->del.h_path);
23368 + dput(opt->mod.h_root);
23371 + fput(opt->xino.file);
23378 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
23379 + aufs_bindex_t bindex)
23382 + struct au_opt_add *add = &opt->add;
23385 + add->bindex = bindex;
23386 + add->perm = AuBrPerm_RO;
23387 + add->pathname = opt_str;
23388 + p = strchr(opt_str, '=');
23392 + add->perm = br_perm_val(p);
23395 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
23398 + add->perm = AuBrPerm_RO;
23399 + if (au_test_fs_rr(add->path.dentry->d_sb))
23400 + add->perm = AuBrPerm_RR;
23401 + else if (!bindex && !(sb_flags & MS_RDONLY))
23402 + add->perm = AuBrPerm_RW;
23404 + opt->type = Opt_add;
23407 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
23414 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
23418 + del->pathname = args[0].from;
23419 + AuDbg("del path %s\n", del->pathname);
23421 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
23422 + if (unlikely(err))
23423 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
23428 +#if 0 /* reserved for future use */
23429 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
23430 + struct au_opt_del *del, substring_t args[])
23433 + struct dentry *root;
23436 + root = sb->s_root;
23437 + aufs_read_lock(root, AuLock_FLUSH);
23438 + if (bindex < 0 || au_sbend(sb) < bindex) {
23439 + pr_err("out of bounds, %d\n", bindex);
23444 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
23445 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
23448 + aufs_read_unlock(root, !AuLock_IR);
23453 +static int noinline_for_stack
23454 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
23457 + struct path path;
23461 + mod->path = args[0].from;
23462 + p = strchr(mod->path, '=');
23463 + if (unlikely(!p)) {
23464 + pr_err("no permssion %s\n", args[0].from);
23469 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
23470 + if (unlikely(err)) {
23471 + pr_err("lookup failed %s (%d)\n", mod->path, err);
23475 + mod->perm = br_perm_val(p);
23476 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
23477 + mod->h_root = dget(path.dentry);
23484 +#if 0 /* reserved for future use */
23485 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
23486 + struct au_opt_mod *mod, substring_t args[])
23489 + struct dentry *root;
23492 + root = sb->s_root;
23493 + aufs_read_lock(root, AuLock_FLUSH);
23494 + if (bindex < 0 || au_sbend(sb) < bindex) {
23495 + pr_err("out of bounds, %d\n", bindex);
23500 + mod->perm = br_perm_val(args[1].from);
23501 + AuDbg("mod path %s, perm 0x%x, %s\n",
23502 + mod->path, mod->perm, args[1].from);
23503 + mod->h_root = dget(au_h_dptr(root, bindex));
23506 + aufs_read_unlock(root, !AuLock_IR);
23511 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
23512 + substring_t args[])
23515 + struct file *file;
23517 + file = au_xino_create(sb, args[0].from, /*silent*/0);
23518 + err = PTR_ERR(file);
23519 + if (IS_ERR(file))
23523 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
23525 + pr_err("%s must be outside\n", args[0].from);
23530 + xino->file = file;
23531 + xino->path = args[0].from;
23537 +static int noinline_for_stack
23538 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
23539 + struct au_opt_xino_itrunc *xino_itrunc,
23540 + substring_t args[])
23543 + aufs_bindex_t bend, bindex;
23544 + struct path path;
23545 + struct dentry *root;
23547 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
23548 + if (unlikely(err)) {
23549 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
23553 + xino_itrunc->bindex = -1;
23554 + root = sb->s_root;
23555 + aufs_read_lock(root, AuLock_FLUSH);
23556 + bend = au_sbend(sb);
23557 + for (bindex = 0; bindex <= bend; bindex++) {
23558 + if (au_h_dptr(root, bindex) == path.dentry) {
23559 + xino_itrunc->bindex = bindex;
23563 + aufs_read_unlock(root, !AuLock_IR);
23566 + if (unlikely(xino_itrunc->bindex < 0)) {
23567 + pr_err("no such branch %s\n", args[0].from);
23575 +/* called without aufs lock */
23576 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
23578 + int err, n, token;
23579 + aufs_bindex_t bindex;
23580 + unsigned char skipped;
23581 + struct dentry *root;
23582 + struct au_opt *opt, *opt_tail;
23584 + /* reduce the stack space */
23586 + struct au_opt_xino_itrunc *xino_itrunc;
23587 + struct au_opt_wbr_create *create;
23590 + substring_t args[MAX_OPT_ARGS];
23594 + a = kmalloc(sizeof(*a), GFP_NOFS);
23595 + if (unlikely(!a))
23598 + root = sb->s_root;
23602 + opt_tail = opt + opts->max_opt - 1;
23603 + opt->type = Opt_tail;
23604 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
23607 + token = match_token(opt_str, options, a->args);
23611 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
23613 + err = opt_add(opt, opt_str, opts->sb_flags,
23615 + if (unlikely(!err && ++opt > opt_tail)) {
23619 + opt->type = Opt_tail;
23624 + if (unlikely(match_int(&a->args[0], &n))) {
23625 + pr_err("bad integer in %s\n", opt_str);
23629 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
23632 + opt->type = token;
23635 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23636 + /*dummy bindex*/1);
23638 + opt->type = token;
23640 + case Opt_prepend:
23641 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23644 + opt->type = token;
23647 + err = au_opts_parse_del(&opt->del, a->args);
23649 + opt->type = token;
23651 +#if 0 /* reserved for future use */
23653 + del->pathname = "(indexed)";
23654 + if (unlikely(match_int(&args[0], &n))) {
23655 + pr_err("bad integer in %s\n", opt_str);
23658 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23660 + opt->type = token;
23664 + err = au_opts_parse_mod(&opt->mod, a->args);
23666 + opt->type = token;
23668 +#ifdef IMOD /* reserved for future use */
23670 + u.mod->path = "(indexed)";
23671 + if (unlikely(match_int(&a->args[0], &n))) {
23672 + pr_err("bad integer in %s\n", opt_str);
23675 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23677 + opt->type = token;
23681 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23683 + opt->type = token;
23686 + case Opt_trunc_xino_path:
23687 + err = au_opts_parse_xino_itrunc_path
23688 + (sb, &opt->xino_itrunc, a->args);
23690 + opt->type = token;
23693 + case Opt_itrunc_xino:
23694 + u.xino_itrunc = &opt->xino_itrunc;
23695 + if (unlikely(match_int(&a->args[0], &n))) {
23696 + pr_err("bad integer in %s\n", opt_str);
23699 + u.xino_itrunc->bindex = n;
23700 + aufs_read_lock(root, AuLock_FLUSH);
23701 + if (n < 0 || au_sbend(sb) < n) {
23702 + pr_err("out of bounds, %d\n", n);
23703 + aufs_read_unlock(root, !AuLock_IR);
23706 + aufs_read_unlock(root, !AuLock_IR);
23708 + opt->type = token;
23712 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23715 + opt->type = token;
23718 + case Opt_rdcache:
23719 + if (unlikely(match_int(&a->args[0], &n))) {
23720 + pr_err("bad integer in %s\n", opt_str);
23723 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23724 + pr_err("rdcache must be smaller than %d\n",
23725 + AUFS_RDCACHE_MAX);
23728 + opt->rdcache = n;
23730 + opt->type = token;
23733 + if (unlikely(match_int(&a->args[0], &n)
23735 + || n > KMALLOC_MAX_SIZE)) {
23736 + pr_err("bad integer in %s\n", opt_str);
23739 + if (unlikely(n && n < NAME_MAX)) {
23740 + pr_err("rdblk must be larger than %d\n",
23746 + opt->type = token;
23749 + if (unlikely(match_int(&a->args[0], &n)
23751 + || n * sizeof(struct hlist_head)
23752 + > KMALLOC_MAX_SIZE)) {
23753 + pr_err("bad integer in %s\n", opt_str);
23758 + opt->type = token;
23761 + case Opt_trunc_xino:
23762 + case Opt_notrunc_xino:
23764 + case Opt_trunc_xib:
23765 + case Opt_notrunc_xib:
23768 + case Opt_dirperm1:
23769 + case Opt_nodirperm1:
23771 + case Opt_noplink:
23772 + case Opt_list_plink:
23775 + case Opt_diropq_a:
23776 + case Opt_diropq_w:
23777 + case Opt_warn_perm:
23778 + case Opt_nowarn_perm:
23779 + case Opt_verbose:
23780 + case Opt_noverbose:
23784 + case Opt_rdblk_def:
23785 + case Opt_rdhash_def:
23789 + opt->type = token;
23793 + opt->udba = udba_val(a->args[0].from);
23794 + if (opt->udba >= 0) {
23796 + opt->type = token;
23798 + pr_err("wrong value, %s\n", opt_str);
23801 + case Opt_wbr_create:
23802 + u.create = &opt->wbr_create;
23803 + u.create->wbr_create
23804 + = au_wbr_create_val(a->args[0].from, u.create);
23805 + if (u.create->wbr_create >= 0) {
23807 + opt->type = token;
23809 + pr_err("wrong value, %s\n", opt_str);
23811 + case Opt_wbr_copyup:
23812 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
23813 + if (opt->wbr_copyup >= 0) {
23815 + opt->type = token;
23817 + pr_err("wrong value, %s\n", opt_str);
23820 + case Opt_fhsm_sec:
23821 + if (unlikely(match_int(&a->args[0], &n)
23823 + pr_err("bad integer in %s\n", opt_str);
23826 + if (sysaufs_brs) {
23827 + opt->fhsm_second = n;
23828 + opt->type = token;
23830 + pr_warn("ignored %s\n", opt_str);
23835 + pr_warn("ignored %s\n", opt_str);
23837 + case Opt_ignore_silent:
23842 + pr_err("unknown option %s\n", opt_str);
23846 + if (!err && !skipped) {
23847 + if (unlikely(++opt > opt_tail)) {
23850 + opt->type = Opt_tail;
23853 + opt->type = Opt_tail;
23859 + if (unlikely(err))
23860 + au_opts_free(opts);
23866 +static int au_opt_wbr_create(struct super_block *sb,
23867 + struct au_opt_wbr_create *create)
23870 + struct au_sbinfo *sbinfo;
23872 + SiMustWriteLock(sb);
23874 + err = 1; /* handled */
23875 + sbinfo = au_sbi(sb);
23876 + if (sbinfo->si_wbr_create_ops->fin) {
23877 + err = sbinfo->si_wbr_create_ops->fin(sb);
23882 + sbinfo->si_wbr_create = create->wbr_create;
23883 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
23884 + switch (create->wbr_create) {
23885 + case AuWbrCreate_MFSRRV:
23886 + case AuWbrCreate_MFSRR:
23887 + case AuWbrCreate_PMFSRR:
23888 + case AuWbrCreate_PMFSRRV:
23889 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
23891 + case AuWbrCreate_MFS:
23892 + case AuWbrCreate_MFSV:
23893 + case AuWbrCreate_PMFS:
23894 + case AuWbrCreate_PMFSV:
23895 + sbinfo->si_wbr_mfs.mfs_expire
23896 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
23900 + if (sbinfo->si_wbr_create_ops->init)
23901 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
23908 + * plus: processed without an error
23909 + * zero: unprocessed
23911 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
23912 + struct au_opts *opts)
23915 + struct au_sbinfo *sbinfo;
23917 + SiMustWriteLock(sb);
23919 + err = 1; /* handled */
23920 + sbinfo = au_sbi(sb);
23921 + switch (opt->type) {
23923 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23924 + sbinfo->si_mntflags |= opt->udba;
23925 + opts->given_udba |= opt->udba;
23929 + au_opt_set(sbinfo->si_mntflags, PLINK);
23931 + case Opt_noplink:
23932 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23933 + au_plink_put(sb, /*verbose*/1);
23934 + au_opt_clr(sbinfo->si_mntflags, PLINK);
23936 + case Opt_list_plink:
23937 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23938 + au_plink_list(sb);
23942 + au_opt_set(sbinfo->si_mntflags, DIO);
23943 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23946 + au_opt_clr(sbinfo->si_mntflags, DIO);
23947 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23950 + case Opt_fhsm_sec:
23951 + au_fhsm_set(sbinfo, opt->fhsm_second);
23954 + case Opt_diropq_a:
23955 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23957 + case Opt_diropq_w:
23958 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23961 + case Opt_warn_perm:
23962 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
23964 + case Opt_nowarn_perm:
23965 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
23968 + case Opt_verbose:
23969 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
23971 + case Opt_noverbose:
23972 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
23976 + au_opt_set(sbinfo->si_mntflags, SUM);
23979 + au_opt_clr(sbinfo->si_mntflags, SUM);
23980 + au_opt_set(sbinfo->si_mntflags, SUM_W);
23982 + au_opt_clr(sbinfo->si_mntflags, SUM);
23983 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
23986 + case Opt_wbr_create:
23987 + err = au_opt_wbr_create(sb, &opt->wbr_create);
23989 + case Opt_wbr_copyup:
23990 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
23991 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
23995 + sbinfo->si_dirwh = opt->dirwh;
23998 + case Opt_rdcache:
23999 + sbinfo->si_rdcache
24000 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24003 + sbinfo->si_rdblk = opt->rdblk;
24005 + case Opt_rdblk_def:
24006 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24009 + sbinfo->si_rdhash = opt->rdhash;
24011 + case Opt_rdhash_def:
24012 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24016 + au_opt_set(sbinfo->si_mntflags, SHWH);
24019 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24022 + case Opt_dirperm1:
24023 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24025 + case Opt_nodirperm1:
24026 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24029 + case Opt_trunc_xino:
24030 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24032 + case Opt_notrunc_xino:
24033 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24036 + case Opt_trunc_xino_path:
24037 + case Opt_itrunc_xino:
24038 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24043 + case Opt_trunc_xib:
24044 + au_fset_opts(opts->flags, TRUNC_XIB);
24046 + case Opt_notrunc_xib:
24047 + au_fclr_opts(opts->flags, TRUNC_XIB);
24051 + sb->s_flags |= MS_POSIXACL;
24054 + sb->s_flags &= ~MS_POSIXACL;
24066 + * returns tri-state.
24067 + * plus: processed without an error
24068 + * zero: unprocessed
24071 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24072 + struct au_opts *opts)
24074 + int err, do_refresh;
24077 + switch (opt->type) {
24079 + opt->add.bindex = au_sbend(sb) + 1;
24080 + if (opt->add.bindex < 0)
24081 + opt->add.bindex = 0;
24083 + case Opt_prepend:
24084 + opt->add.bindex = 0;
24085 + add: /* indented label */
24087 + err = au_br_add(sb, &opt->add,
24088 + au_ftest_opts(opts->flags, REMOUNT));
24091 + au_fset_opts(opts->flags, REFRESH);
24097 + err = au_br_del(sb, &opt->del,
24098 + au_ftest_opts(opts->flags, REMOUNT));
24101 + au_fset_opts(opts->flags, TRUNC_XIB);
24102 + au_fset_opts(opts->flags, REFRESH);
24108 + err = au_br_mod(sb, &opt->mod,
24109 + au_ftest_opts(opts->flags, REMOUNT),
24114 + au_fset_opts(opts->flags, REFRESH);
24122 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24123 + struct au_opt_xino **opt_xino,
24124 + struct au_opts *opts)
24127 + aufs_bindex_t bend, bindex;
24128 + struct dentry *root, *parent, *h_root;
24131 + switch (opt->type) {
24133 + err = au_xino_set(sb, &opt->xino,
24134 + !!au_ftest_opts(opts->flags, REMOUNT));
24135 + if (unlikely(err))
24138 + *opt_xino = &opt->xino;
24139 + au_xino_brid_set(sb, -1);
24141 + /* safe d_parent access */
24142 + parent = opt->xino.file->f_path.dentry->d_parent;
24143 + root = sb->s_root;
24144 + bend = au_sbend(sb);
24145 + for (bindex = 0; bindex <= bend; bindex++) {
24146 + h_root = au_h_dptr(root, bindex);
24147 + if (h_root == parent) {
24148 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24156 + au_xino_brid_set(sb, -1);
24157 + *opt_xino = (void *)-1;
24164 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24165 + unsigned int pending)
24168 + aufs_bindex_t bindex, bend;
24169 + unsigned char do_plink, skip, do_free;
24170 + struct au_branch *br;
24171 + struct au_wbr *wbr;
24172 + struct dentry *root;
24173 + struct inode *dir, *h_dir;
24174 + struct au_sbinfo *sbinfo;
24175 + struct au_hinode *hdir;
24177 + SiMustAnyLock(sb);
24179 + sbinfo = au_sbi(sb);
24180 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24182 + if (!(sb_flags & MS_RDONLY)) {
24183 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24184 + pr_warn("first branch should be rw\n");
24185 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24186 + pr_warn("shwh should be used with ro\n");
24189 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24190 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24191 + pr_warn("udba=*notify requires xino\n");
24193 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24194 + pr_warn("dirperm1 breaks the protection"
24195 + " by the permission bits on the lower branch\n");
24199 + root = sb->s_root;
24200 + dir = d_inode(root);
24201 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24202 + bend = au_sbend(sb);
24203 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24205 + h_dir = au_h_iptr(dir, bindex);
24206 + br = au_sbr(sb, bindex);
24208 + if ((br->br_perm & AuBrAttr_ICEX)
24209 + && !h_dir->i_op->listxattr)
24210 + br->br_perm &= ~AuBrAttr_ICEX;
24212 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24213 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24214 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24218 + wbr = br->br_wbr;
24220 + wbr_wh_read_lock(wbr);
24222 + if (!au_br_writable(br->br_perm)) {
24225 + || (!wbr->wbr_whbase
24226 + && !wbr->wbr_plink
24227 + && !wbr->wbr_orph));
24228 + } else if (!au_br_wh_linkable(br->br_perm)) {
24229 + /* skip = (!br->br_whbase && !br->br_orph); */
24230 + skip = (!wbr || !wbr->wbr_whbase);
24231 + if (skip && wbr) {
24233 + skip = !!wbr->wbr_plink;
24235 + skip = !wbr->wbr_plink;
24238 + /* skip = (br->br_whbase && br->br_ohph); */
24239 + skip = (wbr && wbr->wbr_whbase);
24242 + skip = !!wbr->wbr_plink;
24244 + skip = !wbr->wbr_plink;
24248 + wbr_wh_read_unlock(wbr);
24250 + if (au_br_fhsm(br->br_perm)) {
24252 + AuDebugOn(!br->br_fhsm);
24258 + hdir = au_hi(dir, bindex);
24259 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
24261 + wbr_wh_write_lock(wbr);
24262 + err = au_wh_init(br, sb);
24264 + wbr_wh_write_unlock(wbr);
24265 + au_hn_imtx_unlock(hdir);
24267 + if (!err && do_free) {
24269 + br->br_wbr = NULL;
24274 + au_fset_si(sbinfo, FHSM);
24275 + for (bindex = bend; bindex >= 0; bindex--) {
24276 + br = au_sbr(sb, bindex);
24277 + if (au_br_fhsm(br->br_perm)) {
24278 + au_fhsm_set_bottom(sb, bindex);
24283 + au_fclr_si(sbinfo, FHSM);
24284 + au_fhsm_set_bottom(sb, -1);
24290 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24293 + unsigned int tmp;
24294 + aufs_bindex_t bindex, bend;
24295 + struct au_opt *opt;
24296 + struct au_opt_xino *opt_xino, xino;
24297 + struct au_sbinfo *sbinfo;
24298 + struct au_branch *br;
24299 + struct inode *dir;
24301 + SiMustWriteLock(sb);
24306 + while (err >= 0 && opt->type != Opt_tail)
24307 + err = au_opt_simple(sb, opt++, opts);
24310 + else if (unlikely(err < 0))
24313 + /* disable xino and udba temporary */
24314 + sbinfo = au_sbi(sb);
24315 + tmp = sbinfo->si_mntflags;
24316 + au_opt_clr(sbinfo->si_mntflags, XINO);
24317 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
24320 + while (err >= 0 && opt->type != Opt_tail)
24321 + err = au_opt_br(sb, opt++, opts);
24324 + else if (unlikely(err < 0))
24327 + bend = au_sbend(sb);
24328 + if (unlikely(bend < 0)) {
24330 + pr_err("no branches\n");
24334 + if (au_opt_test(tmp, XINO))
24335 + au_opt_set(sbinfo->si_mntflags, XINO);
24337 + while (!err && opt->type != Opt_tail)
24338 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
24339 + if (unlikely(err))
24342 + err = au_opts_verify(sb, sb->s_flags, tmp);
24343 + if (unlikely(err))
24346 + /* restore xino */
24347 + if (au_opt_test(tmp, XINO) && !opt_xino) {
24348 + xino.file = au_xino_def(sb);
24349 + err = PTR_ERR(xino.file);
24350 + if (IS_ERR(xino.file))
24353 + err = au_xino_set(sb, &xino, /*remount*/0);
24355 + if (unlikely(err))
24359 + /* restore udba */
24360 + tmp &= AuOptMask_UDBA;
24361 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24362 + sbinfo->si_mntflags |= tmp;
24363 + bend = au_sbend(sb);
24364 + for (bindex = 0; bindex <= bend; bindex++) {
24365 + br = au_sbr(sb, bindex);
24366 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
24367 + if (unlikely(err))
24368 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24370 + /* go on even if err */
24372 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
24373 + dir = d_inode(sb->s_root);
24374 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
24381 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
24384 + struct inode *dir;
24385 + struct au_opt_xino *opt_xino;
24386 + struct au_opt *opt;
24387 + struct au_sbinfo *sbinfo;
24389 + SiMustWriteLock(sb);
24391 + dir = d_inode(sb->s_root);
24392 + sbinfo = au_sbi(sb);
24396 + while (err >= 0 && opt->type != Opt_tail) {
24397 + err = au_opt_simple(sb, opt, opts);
24399 + err = au_opt_br(sb, opt, opts);
24401 + err = au_opt_xino(sb, opt, &opt_xino, opts);
24407 + /* go on even err */
24409 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
24410 + if (unlikely(rerr && !err))
24413 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
24414 + rerr = au_xib_trunc(sb);
24415 + if (unlikely(rerr && !err))
24419 + /* will be handled by the caller */
24420 + if (!au_ftest_opts(opts->flags, REFRESH)
24421 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
24422 + au_fset_opts(opts->flags, REFRESH);
24424 + AuDbg("status 0x%x\n", opts->flags);
24428 +/* ---------------------------------------------------------------------- */
24430 +unsigned int au_opt_udba(struct super_block *sb)
24432 + return au_mntflags(sb) & AuOptMask_UDBA;
24434 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
24435 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
24436 +++ linux/fs/aufs/opts.h 2015-06-28 17:35:44.351383872 +0200
24439 + * Copyright (C) 2005-2015 Junjiro R. Okajima
24441 + * This program, aufs is free software; you can redistribute it and/or modify
24442 + * it under the terms of the GNU General Public License as published by
24443 + * the Free Software Foundation; either version 2 of the License, or
24444 + * (at your option) any later version.
24446 + * This program is distributed in the hope that it will be useful,
24447 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24448 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24449 + * GNU General Public License for more details.
24451 + * You should have received a copy of the GNU General Public License
24452 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24456 + * mount options/flags
24459 +#ifndef __AUFS_OPTS_H__
24460 +#define __AUFS_OPTS_H__
24464 +#include <linux/path.h>
24467 +struct super_block;
24469 +/* ---------------------------------------------------------------------- */
24472 +#define AuOpt_XINO 1 /* external inode number bitmap
24473 + and translation table */
24474 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
24475 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
24476 +#define AuOpt_UDBA_REVAL (1 << 3)
24477 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
24478 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
24479 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
24480 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
24482 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
24483 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
24484 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
24485 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
24486 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
24487 +#define AuOpt_DIO (1 << 14) /* direct io */
24489 +#ifndef CONFIG_AUFS_HNOTIFY
24490 +#undef AuOpt_UDBA_HNOTIFY
24491 +#define AuOpt_UDBA_HNOTIFY 0
24493 +#ifndef CONFIG_AUFS_SHWH
24495 +#define AuOpt_SHWH 0
24498 +#define AuOpt_Def (AuOpt_XINO \
24499 + | AuOpt_UDBA_REVAL \
24501 + /* | AuOpt_DIRPERM1 */ \
24502 + | AuOpt_WARN_PERM)
24503 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
24504 + | AuOpt_UDBA_REVAL \
24505 + | AuOpt_UDBA_HNOTIFY)
24507 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
24508 +#define au_opt_set(flags, name) do { \
24509 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
24510 + ((flags) |= AuOpt_##name); \
24512 +#define au_opt_set_udba(flags, name) do { \
24513 + (flags) &= ~AuOptMask_UDBA; \
24514 + ((flags) |= AuOpt_##name); \
24516 +#define au_opt_clr(flags, name) do { \
24517 + ((flags) &= ~AuOpt_##name); \
24520 +static inline unsigned int au_opts_plink(unsigned int mntflags)
24522 +#ifdef CONFIG_PROC_FS
24525 + return mntflags & ~AuOpt_PLINK;
24529 +/* ---------------------------------------------------------------------- */
24531 +/* policies to select one among multiple writable branches */
24533 + AuWbrCreate_TDP, /* top down parent */
24534 + AuWbrCreate_RR, /* round robin */
24535 + AuWbrCreate_MFS, /* most free space */
24536 + AuWbrCreate_MFSV, /* mfs with seconds */
24537 + AuWbrCreate_MFSRR, /* mfs then rr */
24538 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
24539 + AuWbrCreate_PMFS, /* parent and mfs */
24540 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
24541 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
24542 + AuWbrCreate_PMFSRRV, /* plus seconds */
24544 + AuWbrCreate_Def = AuWbrCreate_TDP
24548 + AuWbrCopyup_TDP, /* top down parent */
24549 + AuWbrCopyup_BUP, /* bottom up parent */
24550 + AuWbrCopyup_BU, /* bottom up */
24552 + AuWbrCopyup_Def = AuWbrCopyup_TDP
24555 +/* ---------------------------------------------------------------------- */
24557 +struct au_opt_add {
24558 + aufs_bindex_t bindex;
24561 + struct path path;
24564 +struct au_opt_del {
24566 + struct path h_path;
24569 +struct au_opt_mod {
24572 + struct dentry *h_root;
24575 +struct au_opt_xino {
24577 + struct file *file;
24580 +struct au_opt_xino_itrunc {
24581 + aufs_bindex_t bindex;
24584 +struct au_opt_wbr_create {
24587 + unsigned long long mfsrr_watermark;
24593 + struct au_opt_xino xino;
24594 + struct au_opt_xino_itrunc xino_itrunc;
24595 + struct au_opt_add add;
24596 + struct au_opt_del del;
24597 + struct au_opt_mod mod;
24600 + unsigned int rdblk;
24601 + unsigned int rdhash;
24603 + struct au_opt_wbr_create wbr_create;
24605 + unsigned int fhsm_second;
24610 +#define AuOpts_REMOUNT 1
24611 +#define AuOpts_REFRESH (1 << 1)
24612 +#define AuOpts_TRUNC_XIB (1 << 2)
24613 +#define AuOpts_REFRESH_DYAOP (1 << 3)
24614 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
24615 +#define au_fset_opts(flags, name) \
24616 + do { (flags) |= AuOpts_##name; } while (0)
24617 +#define au_fclr_opts(flags, name) \
24618 + do { (flags) &= ~AuOpts_##name; } while (0)
24621 + struct au_opt *opt;
24624 + unsigned int given_udba;
24625 + unsigned int flags;
24626 + unsigned long sb_flags;
24629 +/* ---------------------------------------------------------------------- */
24632 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
24633 +const char *au_optstr_udba(int udba);
24634 +const char *au_optstr_wbr_copyup(int wbr_copyup);
24635 +const char *au_optstr_wbr_create(int wbr_create);
24637 +void au_opts_free(struct au_opts *opts);
24638 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
24639 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24640 + unsigned int pending);
24641 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
24642 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
24644 +unsigned int au_opt_udba(struct super_block *sb);
24646 +#endif /* __KERNEL__ */
24647 +#endif /* __AUFS_OPTS_H__ */
24648 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
24649 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
24650 +++ linux/fs/aufs/plink.c 2015-06-28 17:36:09.028407078 +0200
24653 + * Copyright (C) 2005-2015 Junjiro R. Okajima
24655 + * This program, aufs is free software; you can redistribute it and/or modify
24656 + * it under the terms of the GNU General Public License as published by
24657 + * the Free Software Foundation; either version 2 of the License, or
24658 + * (at your option) any later version.
24660 + * This program is distributed in the hope that it will be useful,
24661 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24662 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24663 + * GNU General Public License for more details.
24665 + * You should have received a copy of the GNU General Public License
24666 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24676 + * the pseudo-link maintenance mode.
24677 + * during a user process maintains the pseudo-links,
24678 + * prohibit adding a new plink and branch manipulation.
24682 + * For entry functions which will handle plink, and i_mutex is already held
24684 + * They cannot wait and should return an error at once.
24685 + * Callers has to check the error.
24687 + * For entry functions which will handle plink, but i_mutex is not held
24689 + * They can wait the plink maintenance mode to finish.
24691 + * They behave like F_SETLK and F_SETLKW.
24692 + * If the caller never handle plink, then both flags are unnecessary.
24695 +int au_plink_maint(struct super_block *sb, int flags)
24699 + struct au_sbinfo *sbi;
24701 + SiMustAnyLock(sb);
24704 + if (!au_opt_test(au_mntflags(sb), PLINK))
24707 + sbi = au_sbi(sb);
24708 + pid = sbi->si_plink_maint_pid;
24709 + if (!pid || pid == current->pid)
24712 + /* todo: it highly depends upon /sbin/mount.aufs */
24714 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
24715 + rcu_read_unlock();
24719 + if (au_ftest_lock(flags, NOPLMW)) {
24720 + /* if there is no i_mutex lock in VFS, we don't need to wait */
24721 + /* AuDebugOn(!lockdep_depth(current)); */
24722 + while (sbi->si_plink_maint_pid) {
24723 + si_read_unlock(sb);
24724 + /* gave up wake_up_bit() */
24725 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
24727 + if (au_ftest_lock(flags, FLUSH))
24728 + au_nwt_flush(&sbi->si_nowait);
24729 + si_noflush_read_lock(sb);
24731 + } else if (au_ftest_lock(flags, NOPLM)) {
24732 + AuDbg("ppid %d, pid %d\n", ppid, pid);
24740 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
24742 + spin_lock(&sbinfo->si_plink_maint_lock);
24743 + sbinfo->si_plink_maint_pid = 0;
24744 + spin_unlock(&sbinfo->si_plink_maint_lock);
24745 + wake_up_all(&sbinfo->si_plink_wq);
24748 +int au_plink_maint_enter(struct super_block *sb)
24751 + struct au_sbinfo *sbinfo;
24754 + sbinfo = au_sbi(sb);
24755 + /* make sure i am the only one in this fs */
24756 + si_write_lock(sb, AuLock_FLUSH);
24757 + if (au_opt_test(au_mntflags(sb), PLINK)) {
24758 + spin_lock(&sbinfo->si_plink_maint_lock);
24759 + if (!sbinfo->si_plink_maint_pid)
24760 + sbinfo->si_plink_maint_pid = current->pid;
24763 + spin_unlock(&sbinfo->si_plink_maint_lock);
24765 + si_write_unlock(sb);
24770 +/* ---------------------------------------------------------------------- */
24772 +#ifdef CONFIG_AUFS_DEBUG
24773 +void au_plink_list(struct super_block *sb)
24776 + struct au_sbinfo *sbinfo;
24777 + struct hlist_head *plink_hlist;
24778 + struct pseudo_link *plink;
24780 + SiMustAnyLock(sb);
24782 + sbinfo = au_sbi(sb);
24783 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24784 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24786 + for (i = 0; i < AuPlink_NHASH; i++) {
24787 + plink_hlist = &sbinfo->si_plink[i].head;
24789 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24790 + AuDbg("%lu\n", plink->inode->i_ino);
24791 + rcu_read_unlock();
24796 +/* is the inode pseudo-linked? */
24797 +int au_plink_test(struct inode *inode)
24800 + struct au_sbinfo *sbinfo;
24801 + struct hlist_head *plink_hlist;
24802 + struct pseudo_link *plink;
24804 + sbinfo = au_sbi(inode->i_sb);
24805 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24806 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
24807 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24810 + i = au_plink_hash(inode->i_ino);
24811 + plink_hlist = &sbinfo->si_plink[i].head;
24813 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24814 + if (plink->inode == inode) {
24818 + rcu_read_unlock();
24822 +/* ---------------------------------------------------------------------- */
24825 + * generate a name for plink.
24826 + * the file will be stored under AUFS_WH_PLINKDIR.
24828 +/* 20 is max digits length of ulong 64 */
24829 +#define PLINK_NAME_LEN ((20 + 1) * 2)
24831 +static int plink_name(char *name, int len, struct inode *inode,
24832 + aufs_bindex_t bindex)
24835 + struct inode *h_inode;
24837 + h_inode = au_h_iptr(inode, bindex);
24838 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
24842 +struct au_do_plink_lkup_args {
24843 + struct dentry **errp;
24844 + struct qstr *tgtname;
24845 + struct dentry *h_parent;
24846 + struct au_branch *br;
24849 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
24850 + struct dentry *h_parent,
24851 + struct au_branch *br)
24853 + struct dentry *h_dentry;
24854 + struct mutex *h_mtx;
24856 + h_mtx = &d_inode(h_parent)->i_mutex;
24857 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
24858 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
24859 + mutex_unlock(h_mtx);
24863 +static void au_call_do_plink_lkup(void *args)
24865 + struct au_do_plink_lkup_args *a = args;
24866 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
24869 +/* lookup the plink-ed @inode under the branch at @bindex */
24870 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
24872 + struct dentry *h_dentry, *h_parent;
24873 + struct au_branch *br;
24875 + char a[PLINK_NAME_LEN];
24876 + struct qstr tgtname = QSTR_INIT(a, 0);
24878 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24880 + br = au_sbr(inode->i_sb, bindex);
24881 + h_parent = br->br_wbr->wbr_plink;
24882 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24884 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24885 + struct au_do_plink_lkup_args args = {
24886 + .errp = &h_dentry,
24887 + .tgtname = &tgtname,
24888 + .h_parent = h_parent,
24892 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
24893 + if (unlikely(wkq_err))
24894 + h_dentry = ERR_PTR(wkq_err);
24896 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
24901 +/* create a pseudo-link */
24902 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
24903 + struct dentry *h_dentry, struct au_branch *br)
24906 + struct path h_path = {
24907 + .mnt = au_br_mnt(br)
24909 + struct inode *h_dir, *delegated;
24911 + h_dir = d_inode(h_parent);
24912 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
24914 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
24915 + err = PTR_ERR(h_path.dentry);
24916 + if (IS_ERR(h_path.dentry))
24920 + /* wh.plink dir is not monitored */
24921 + /* todo: is it really safe? */
24922 + if (d_is_positive(h_path.dentry)
24923 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
24924 + delegated = NULL;
24925 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
24926 + if (unlikely(err == -EWOULDBLOCK)) {
24927 + pr_warn("cannot retry for NFSv4 delegation"
24928 + " for an internal unlink\n");
24931 + dput(h_path.dentry);
24932 + h_path.dentry = NULL;
24936 + if (!err && d_is_negative(h_path.dentry)) {
24937 + delegated = NULL;
24938 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
24939 + if (unlikely(err == -EWOULDBLOCK)) {
24940 + pr_warn("cannot retry for NFSv4 delegation"
24941 + " for an internal link\n");
24945 + dput(h_path.dentry);
24948 + mutex_unlock(&h_dir->i_mutex);
24952 +struct do_whplink_args {
24954 + struct qstr *tgt;
24955 + struct dentry *h_parent;
24956 + struct dentry *h_dentry;
24957 + struct au_branch *br;
24960 +static void call_do_whplink(void *args)
24962 + struct do_whplink_args *a = args;
24963 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
24966 +static int whplink(struct dentry *h_dentry, struct inode *inode,
24967 + aufs_bindex_t bindex, struct au_branch *br)
24969 + int err, wkq_err;
24970 + struct au_wbr *wbr;
24971 + struct dentry *h_parent;
24972 + char a[PLINK_NAME_LEN];
24973 + struct qstr tgtname = QSTR_INIT(a, 0);
24975 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
24976 + h_parent = wbr->wbr_plink;
24977 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24979 + /* always superio. */
24980 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24981 + struct do_whplink_args args = {
24984 + .h_parent = h_parent,
24985 + .h_dentry = h_dentry,
24988 + wkq_err = au_wkq_wait(call_do_whplink, &args);
24989 + if (unlikely(wkq_err))
24992 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
24997 +/* free a single plink */
24998 +static void do_put_plink(struct pseudo_link *plink, int do_del)
25001 + hlist_del(&plink->hlist);
25002 + iput(plink->inode);
25006 +static void do_put_plink_rcu(struct rcu_head *rcu)
25008 + struct pseudo_link *plink;
25010 + plink = container_of(rcu, struct pseudo_link, rcu);
25011 + iput(plink->inode);
25016 + * create a new pseudo-link for @h_dentry on @bindex.
25017 + * the linked inode is held in aufs @inode.
25019 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25020 + struct dentry *h_dentry)
25022 + struct super_block *sb;
25023 + struct au_sbinfo *sbinfo;
25024 + struct hlist_head *plink_hlist;
25025 + struct pseudo_link *plink, *tmp;
25026 + struct au_sphlhead *sphl;
25027 + int found, err, cnt, i;
25029 + sb = inode->i_sb;
25030 + sbinfo = au_sbi(sb);
25031 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25032 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25034 + found = au_plink_test(inode);
25038 + i = au_plink_hash(inode->i_ino);
25039 + sphl = sbinfo->si_plink + i;
25040 + plink_hlist = &sphl->head;
25041 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
25043 + tmp->inode = au_igrab(inode);
25049 + spin_lock(&sphl->spin);
25050 + hlist_for_each_entry(plink, plink_hlist, hlist) {
25051 + if (plink->inode == inode) {
25057 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
25058 + spin_unlock(&sphl->spin);
25060 + cnt = au_sphl_count(sphl);
25061 +#define msg "unexpectedly unblanced or too many pseudo-links"
25062 + if (cnt > AUFS_PLINK_WARN)
25063 + AuWarn1(msg ", %d\n", cnt);
25065 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25067 + do_put_plink(tmp, 0);
25072 + if (unlikely(err)) {
25073 + pr_warn("err %d, damaged pseudo link.\n", err);
25075 + au_sphl_del_rcu(&tmp->hlist, sphl);
25076 + call_rcu(&tmp->rcu, do_put_plink_rcu);
25081 +/* free all plinks */
25082 +void au_plink_put(struct super_block *sb, int verbose)
25085 + struct au_sbinfo *sbinfo;
25086 + struct hlist_head *plink_hlist;
25087 + struct hlist_node *tmp;
25088 + struct pseudo_link *plink;
25090 + SiMustWriteLock(sb);
25092 + sbinfo = au_sbi(sb);
25093 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25094 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25096 + /* no spin_lock since sbinfo is write-locked */
25098 + for (i = 0; i < AuPlink_NHASH; i++) {
25099 + plink_hlist = &sbinfo->si_plink[i].head;
25100 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25101 + pr_warn("pseudo-link is not flushed");
25104 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
25105 + do_put_plink(plink, 0);
25106 + INIT_HLIST_HEAD(plink_hlist);
25110 +void au_plink_clean(struct super_block *sb, int verbose)
25112 + struct dentry *root;
25114 + root = sb->s_root;
25115 + aufs_write_lock(root);
25116 + if (au_opt_test(au_mntflags(sb), PLINK))
25117 + au_plink_put(sb, verbose);
25118 + aufs_write_unlock(root);
25121 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25124 + aufs_bindex_t bstart, bend, bindex;
25127 + bstart = au_ibstart(inode);
25128 + bend = au_ibend(inode);
25129 + if (bstart >= 0) {
25130 + for (bindex = bstart; bindex <= bend; bindex++) {
25131 + if (!au_h_iptr(inode, bindex)
25132 + || au_ii_br_id(inode, bindex) != br_id)
25134 + au_set_h_iptr(inode, bindex, NULL, 0);
25139 + for (bindex = bstart; bindex <= bend; bindex++)
25140 + if (au_h_iptr(inode, bindex)) {
25150 +/* free the plinks on a branch specified by @br_id */
25151 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25153 + struct au_sbinfo *sbinfo;
25154 + struct hlist_head *plink_hlist;
25155 + struct hlist_node *tmp;
25156 + struct pseudo_link *plink;
25157 + struct inode *inode;
25160 + SiMustWriteLock(sb);
25162 + sbinfo = au_sbi(sb);
25163 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25164 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25166 + /* no spin_lock since sbinfo is write-locked */
25167 + for (i = 0; i < AuPlink_NHASH; i++) {
25168 + plink_hlist = &sbinfo->si_plink[i].head;
25169 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
25170 + inode = au_igrab(plink->inode);
25171 + ii_write_lock_child(inode);
25172 + do_put = au_plink_do_half_refresh(inode, br_id);
25174 + do_put_plink(plink, 1);
25175 + ii_write_unlock(inode);
25180 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25181 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25182 +++ linux/fs/aufs/poll.c 2015-06-28 17:35:44.351383872 +0200
25185 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25187 + * This program, aufs is free software; you can redistribute it and/or modify
25188 + * it under the terms of the GNU General Public License as published by
25189 + * the Free Software Foundation; either version 2 of the License, or
25190 + * (at your option) any later version.
25192 + * This program is distributed in the hope that it will be useful,
25193 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25194 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25195 + * GNU General Public License for more details.
25197 + * You should have received a copy of the GNU General Public License
25198 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25203 + * There is only one filesystem which implements ->poll operation, currently.
25208 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25210 + unsigned int mask;
25212 + struct file *h_file;
25213 + struct super_block *sb;
25215 + /* We should pretend an error happened. */
25216 + mask = POLLERR /* | POLLIN | POLLOUT */;
25217 + sb = file->f_path.dentry->d_sb;
25218 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25220 + h_file = au_read_pre(file, /*keep_fi*/0);
25221 + err = PTR_ERR(h_file);
25222 + if (IS_ERR(h_file))
25225 + /* it is not an error if h_file has no operation */
25226 + mask = DEFAULT_POLLMASK;
25227 + if (h_file->f_op->poll)
25228 + mask = h_file->f_op->poll(h_file, wait);
25229 + fput(h_file); /* instead of au_read_post() */
25232 + si_read_unlock(sb);
25233 + AuTraceErr((int)mask);
25236 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25237 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25238 +++ linux/fs/aufs/posix_acl.c 2015-06-28 17:35:44.351383872 +0200
25241 + * Copyright (C) 2014-2015 Junjiro R. Okajima
25243 + * This program, aufs is free software; you can redistribute it and/or modify
25244 + * it under the terms of the GNU General Public License as published by
25245 + * the Free Software Foundation; either version 2 of the License, or
25246 + * (at your option) any later version.
25248 + * This program is distributed in the hope that it will be useful,
25249 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25250 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25251 + * GNU General Public License for more details.
25253 + * You should have received a copy of the GNU General Public License
25254 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25258 + * posix acl operations
25261 +#include <linux/fs.h>
25262 +#include <linux/posix_acl.h>
25265 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25267 + struct posix_acl *acl;
25269 + aufs_bindex_t bindex;
25270 + struct inode *h_inode;
25271 + struct super_block *sb;
25274 + sb = inode->i_sb;
25275 + si_read_lock(sb, AuLock_FLUSH);
25276 + ii_read_lock_child(inode);
25277 + if (!(sb->s_flags & MS_POSIXACL))
25280 + bindex = au_ibstart(inode);
25281 + h_inode = au_h_iptr(inode, bindex);
25282 + if (unlikely(!h_inode
25283 + || ((h_inode->i_mode & S_IFMT)
25284 + != (inode->i_mode & S_IFMT)))) {
25285 + err = au_busy_or_stale();
25286 + acl = ERR_PTR(err);
25290 + /* always topmost only */
25291 + acl = get_acl(h_inode, type);
25294 + ii_read_unlock(inode);
25295 + si_read_unlock(sb);
25297 + AuTraceErrPtr(acl);
25301 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25305 + struct dentry *dentry;
25306 + struct au_srxattr arg = {
25307 + .type = AU_ACL_SET,
25314 + mutex_lock(&inode->i_mutex);
25315 + if (inode->i_ino == AUFS_ROOT_INO)
25316 + dentry = dget(inode->i_sb->s_root);
25318 + dentry = d_find_alias(inode);
25320 + dentry = d_find_any_alias(inode);
25322 + pr_warn("cannot handle this inode, "
25323 + "please report to aufs-users ML\n");
25329 + ssz = au_srxattr(dentry, &arg);
25336 + mutex_unlock(&inode->i_mutex);
25339 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
25340 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
25341 +++ linux/fs/aufs/procfs.c 2015-06-28 17:35:44.351383872 +0200
25344 + * Copyright (C) 2010-2015 Junjiro R. Okajima
25346 + * This program, aufs is free software; you can redistribute it and/or modify
25347 + * it under the terms of the GNU General Public License as published by
25348 + * the Free Software Foundation; either version 2 of the License, or
25349 + * (at your option) any later version.
25351 + * This program is distributed in the hope that it will be useful,
25352 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25353 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25354 + * GNU General Public License for more details.
25356 + * You should have received a copy of the GNU General Public License
25357 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25361 + * procfs interfaces
25364 +#include <linux/proc_fs.h>
25367 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
25369 + struct au_sbinfo *sbinfo;
25371 + sbinfo = file->private_data;
25373 + au_plink_maint_leave(sbinfo);
25374 + kobject_put(&sbinfo->si_kobj);
25380 +static void au_procfs_plm_write_clean(struct file *file)
25382 + struct au_sbinfo *sbinfo;
25384 + sbinfo = file->private_data;
25386 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
25389 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
25392 + struct super_block *sb;
25393 + struct au_sbinfo *sbinfo;
25396 + if (unlikely(file->private_data))
25400 + /* don't use au_sbilist_lock() here */
25401 + spin_lock(&au_sbilist.spin);
25402 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
25403 + if (id == sysaufs_si_id(sbinfo)) {
25404 + kobject_get(&sbinfo->si_kobj);
25405 + sb = sbinfo->si_sb;
25408 + spin_unlock(&au_sbilist.spin);
25411 + if (unlikely(!sb))
25414 + err = au_plink_maint_enter(sb);
25416 + /* keep kobject_get() */
25417 + file->private_data = sbinfo;
25419 + kobject_put(&sbinfo->si_kobj);
25425 + * Accept a valid "si=xxxx" only.
25426 + * Once it is accepted successfully, accept "clean" too.
25428 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
25429 + size_t count, loff_t *ppos)
25432 + unsigned long id;
25433 + /* last newline is allowed */
25434 + char buf[3 + sizeof(unsigned long) * 2 + 1];
25437 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25441 + if (unlikely(count > sizeof(buf)))
25444 + err = copy_from_user(buf, ubuf, count);
25445 + if (unlikely(err)) {
25452 + if (!strcmp("clean", buf)) {
25453 + au_procfs_plm_write_clean(file);
25454 + goto out_success;
25455 + } else if (unlikely(strncmp("si=", buf, 3)))
25458 + err = kstrtoul(buf + 3, 16, &id);
25459 + if (unlikely(err))
25462 + err = au_procfs_plm_write_si(file, id);
25463 + if (unlikely(err))
25467 + err = count; /* success */
25472 +static const struct file_operations au_procfs_plm_fop = {
25473 + .write = au_procfs_plm_write,
25474 + .release = au_procfs_plm_release,
25475 + .owner = THIS_MODULE
25478 +/* ---------------------------------------------------------------------- */
25480 +static struct proc_dir_entry *au_procfs_dir;
25482 +void au_procfs_fin(void)
25484 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
25485 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25488 +int __init au_procfs_init(void)
25491 + struct proc_dir_entry *entry;
25494 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
25495 + if (unlikely(!au_procfs_dir))
25498 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
25499 + au_procfs_dir, &au_procfs_plm_fop);
25500 + if (unlikely(!entry))
25504 + goto out; /* success */
25508 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25512 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
25513 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
25514 +++ linux/fs/aufs/rdu.c 2015-06-28 17:36:09.028407078 +0200
25517 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25519 + * This program, aufs is free software; you can redistribute it and/or modify
25520 + * it under the terms of the GNU General Public License as published by
25521 + * the Free Software Foundation; either version 2 of the License, or
25522 + * (at your option) any later version.
25524 + * This program is distributed in the hope that it will be useful,
25525 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25526 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25527 + * GNU General Public License for more details.
25529 + * You should have received a copy of the GNU General Public License
25530 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25534 + * readdir in userspace.
25537 +#include <linux/compat.h>
25538 +#include <linux/fs_stack.h>
25539 +#include <linux/security.h>
25542 +/* bits for struct aufs_rdu.flags */
25543 +#define AuRdu_CALLED 1
25544 +#define AuRdu_CONT (1 << 1)
25545 +#define AuRdu_FULL (1 << 2)
25546 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
25547 +#define au_fset_rdu(flags, name) \
25548 + do { (flags) |= AuRdu_##name; } while (0)
25549 +#define au_fclr_rdu(flags, name) \
25550 + do { (flags) &= ~AuRdu_##name; } while (0)
25552 +struct au_rdu_arg {
25553 + struct dir_context ctx;
25554 + struct aufs_rdu *rdu;
25555 + union au_rdu_ent_ul ent;
25556 + unsigned long end;
25558 + struct super_block *sb;
25562 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
25563 + loff_t offset, u64 h_ino, unsigned int d_type)
25566 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
25567 + struct aufs_rdu *rdu = arg->rdu;
25568 + struct au_rdu_ent ent;
25572 + au_fset_rdu(rdu->cookie.flags, CALLED);
25573 + len = au_rdu_len(nlen);
25574 + if (arg->ent.ul + len < arg->end) {
25576 + ent.bindex = rdu->cookie.bindex;
25577 + ent.type = d_type;
25579 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25580 + ent.type = DT_UNKNOWN;
25582 + /* unnecessary to support mmap_sem since this is a dir */
25584 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
25586 + if (copy_to_user(arg->ent.e->name, name, nlen))
25588 + /* the terminating NULL */
25589 + if (__put_user(0, arg->ent.e->name + nlen))
25592 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
25593 + arg->ent.ul += len;
25597 + au_fset_rdu(rdu->cookie.flags, FULL);
25599 + rdu->tail = arg->ent;
25603 + /* AuTraceErr(err); */
25607 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
25611 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
25613 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
25614 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
25616 + if (unlikely(offset != cookie->h_pos))
25622 + au_fclr_rdu(cookie->flags, CALLED);
25624 + err = vfsub_iterate_dir(h_file, &arg->ctx);
25628 + && au_ftest_rdu(cookie->flags, CALLED)
25629 + && !au_ftest_rdu(cookie->flags, FULL));
25630 + cookie->h_pos = h_file->f_pos;
25637 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
25640 + aufs_bindex_t bend;
25641 + struct au_rdu_arg arg = {
25643 + .actor = au_rdu_fill
25646 + struct dentry *dentry;
25647 + struct inode *inode;
25648 + struct file *h_file;
25649 + struct au_rdu_cookie *cookie = &rdu->cookie;
25651 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
25652 + if (unlikely(err)) {
25658 + rdu->tail = rdu->ent;
25661 + arg.ent = rdu->ent;
25662 + arg.end = arg.ent.ul;
25663 + arg.end += rdu->sz;
25666 + if (unlikely(!file->f_op->iterate))
25669 + err = security_file_permission(file, MAY_READ);
25671 + if (unlikely(err))
25674 + dentry = file->f_path.dentry;
25675 + inode = d_inode(dentry);
25677 + mutex_lock(&inode->i_mutex);
25679 + err = mutex_lock_killable(&inode->i_mutex);
25681 + if (unlikely(err))
25685 + arg.sb = inode->i_sb;
25686 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
25687 + if (unlikely(err))
25689 + err = au_alive_dir(dentry);
25690 + if (unlikely(err))
25692 + /* todo: reval? */
25693 + fi_read_lock(file);
25696 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
25697 + && cookie->generation != au_figen(file)))
25702 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
25704 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
25706 + bend = au_fbstart(file);
25707 + if (cookie->bindex < bend)
25708 + cookie->bindex = bend;
25709 + bend = au_fbend_dir(file);
25710 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
25711 + for (; !err && cookie->bindex <= bend;
25712 + cookie->bindex++, cookie->h_pos = 0) {
25713 + h_file = au_hf_dir(file, cookie->bindex);
25717 + au_fclr_rdu(cookie->flags, FULL);
25718 + err = au_rdu_do(h_file, &arg);
25720 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
25723 + AuDbg("rent %llu\n", rdu->rent);
25725 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
25726 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
25727 + au_fset_rdu(cookie->flags, CONT);
25728 + cookie->generation = au_figen(file);
25731 + ii_read_lock_child(inode);
25732 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
25733 + ii_read_unlock(inode);
25736 + fi_read_unlock(file);
25738 + si_read_unlock(arg.sb);
25740 + mutex_unlock(&inode->i_mutex);
25746 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
25750 + unsigned long long nent;
25751 + union au_rdu_ent_ul *u;
25752 + struct au_rdu_ent ent;
25753 + struct super_block *sb;
25756 + nent = rdu->nent;
25758 + sb = file->f_path.dentry->d_sb;
25759 + si_read_lock(sb, AuLock_FLUSH);
25760 + while (nent-- > 0) {
25761 + /* unnecessary to support mmap_sem since this is a dir */
25762 + err = copy_from_user(&ent, u->e, sizeof(ent));
25764 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
25765 + if (unlikely(err)) {
25771 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
25773 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
25775 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
25777 + if (unlikely(err)) {
25782 + err = __put_user(ino, &u->e->ino);
25783 + if (unlikely(err)) {
25788 + u->ul += au_rdu_len(ent.nlen);
25790 + si_read_unlock(sb);
25795 +/* ---------------------------------------------------------------------- */
25797 +static int au_rdu_verify(struct aufs_rdu *rdu)
25799 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
25800 + "%llu, b%d, 0x%x, g%u}\n",
25801 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
25803 + rdu->rent, rdu->shwh, rdu->full,
25804 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
25805 + rdu->cookie.generation);
25807 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
25811 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
25815 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25818 + struct aufs_rdu rdu;
25819 + void __user *p = (void __user *)arg;
25821 + err = copy_from_user(&rdu, p, sizeof(rdu));
25822 + if (unlikely(err)) {
25827 + err = au_rdu_verify(&rdu);
25828 + if (unlikely(err))
25832 + case AUFS_CTL_RDU:
25833 + err = au_rdu(file, &rdu);
25834 + if (unlikely(err))
25837 + e = copy_to_user(p, &rdu, sizeof(rdu));
25838 + if (unlikely(e)) {
25843 + case AUFS_CTL_RDU_INO:
25844 + err = au_rdu_ino(file, &rdu);
25848 + /* err = -ENOTTY; */
25857 +#ifdef CONFIG_COMPAT
25858 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25861 + struct aufs_rdu rdu;
25862 + void __user *p = compat_ptr(arg);
25864 + /* todo: get_user()? */
25865 + err = copy_from_user(&rdu, p, sizeof(rdu));
25866 + if (unlikely(err)) {
25871 + rdu.ent.e = compat_ptr(rdu.ent.ul);
25872 + err = au_rdu_verify(&rdu);
25873 + if (unlikely(err))
25877 + case AUFS_CTL_RDU:
25878 + err = au_rdu(file, &rdu);
25879 + if (unlikely(err))
25882 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
25883 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
25884 + e = copy_to_user(p, &rdu, sizeof(rdu));
25885 + if (unlikely(e)) {
25890 + case AUFS_CTL_RDU_INO:
25891 + err = au_rdu_ino(file, &rdu);
25895 + /* err = -ENOTTY; */
25904 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
25905 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
25906 +++ linux/fs/aufs/rwsem.h 2015-06-28 17:35:44.351383872 +0200
25909 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25911 + * This program, aufs is free software; you can redistribute it and/or modify
25912 + * it under the terms of the GNU General Public License as published by
25913 + * the Free Software Foundation; either version 2 of the License, or
25914 + * (at your option) any later version.
25916 + * This program is distributed in the hope that it will be useful,
25917 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25918 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25919 + * GNU General Public License for more details.
25921 + * You should have received a copy of the GNU General Public License
25922 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25926 + * simple read-write semaphore wrappers
25929 +#ifndef __AUFS_RWSEM_H__
25930 +#define __AUFS_RWSEM_H__
25934 +#include "debug.h"
25937 + struct rw_semaphore rwsem;
25938 +#ifdef CONFIG_AUFS_DEBUG
25939 + /* just for debugging, not almighty counter */
25940 + atomic_t rcnt, wcnt;
25944 +#ifdef CONFIG_AUFS_DEBUG
25945 +#define AuDbgCntInit(rw) do { \
25946 + atomic_set(&(rw)->rcnt, 0); \
25947 + atomic_set(&(rw)->wcnt, 0); \
25948 + smp_mb(); /* atomic set */ \
25951 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
25952 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
25953 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
25954 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
25956 +#define AuDbgCntInit(rw) do {} while (0)
25957 +#define AuDbgRcntInc(rw) do {} while (0)
25958 +#define AuDbgRcntDec(rw) do {} while (0)
25959 +#define AuDbgWcntInc(rw) do {} while (0)
25960 +#define AuDbgWcntDec(rw) do {} while (0)
25961 +#endif /* CONFIG_AUFS_DEBUG */
25963 +/* to debug easier, do not make them inlined functions */
25964 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
25965 +/* rwsem_is_locked() is unusable */
25966 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
25967 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
25968 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
25969 + && atomic_read(&(rw)->wcnt) <= 0)
25970 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
25971 + || atomic_read(&(rw)->wcnt))
25973 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
25975 +static inline void au_rw_init(struct au_rwsem *rw)
25977 + AuDbgCntInit(rw);
25978 + init_rwsem(&rw->rwsem);
25981 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
25984 + down_write(&rw->rwsem);
25985 + AuDbgWcntInc(rw);
25988 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
25989 + unsigned int lsc)
25992 + down_write_nested(&rw->rwsem, lsc);
25993 + AuDbgWcntInc(rw);
25996 +static inline void au_rw_read_lock(struct au_rwsem *rw)
25998 + down_read(&rw->rwsem);
25999 + AuDbgRcntInc(rw);
26002 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26004 + down_read_nested(&rw->rwsem, lsc);
26005 + AuDbgRcntInc(rw);
26008 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26010 + AuRwMustReadLock(rw);
26011 + AuDbgRcntDec(rw);
26012 + up_read(&rw->rwsem);
26015 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26017 + AuRwMustWriteLock(rw);
26018 + AuDbgRcntInc(rw);
26019 + AuDbgWcntDec(rw);
26020 + downgrade_write(&rw->rwsem);
26023 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26025 + down_write(&rw->rwsem);
26026 + AuDbgWcntInc(rw);
26029 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26030 + unsigned int lsc)
26032 + down_write_nested(&rw->rwsem, lsc);
26033 + AuDbgWcntInc(rw);
26036 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26038 + AuRwMustWriteLock(rw);
26039 + AuDbgWcntDec(rw);
26040 + up_write(&rw->rwsem);
26043 +/* why is not _nested version defined */
26044 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26048 + ret = down_read_trylock(&rw->rwsem);
26050 + AuDbgRcntInc(rw);
26054 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26058 + ret = down_write_trylock(&rw->rwsem);
26060 + AuDbgWcntInc(rw);
26064 +#undef AuDbgCntInit
26065 +#undef AuDbgRcntInc
26066 +#undef AuDbgRcntDec
26067 +#undef AuDbgWcntInc
26068 +#undef AuDbgWcntDec
26070 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26071 +static inline void prefix##_read_lock(param) \
26072 +{ au_rw_read_lock(rwsem); } \
26073 +static inline void prefix##_write_lock(param) \
26074 +{ au_rw_write_lock(rwsem); } \
26075 +static inline int prefix##_read_trylock(param) \
26076 +{ return au_rw_read_trylock(rwsem); } \
26077 +static inline int prefix##_write_trylock(param) \
26078 +{ return au_rw_write_trylock(rwsem); }
26079 +/* why is not _nested version defined */
26080 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26081 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26082 +static inline void prefix##_write_trylock_nestd(param, lsc)
26083 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26085 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26086 +static inline void prefix##_read_unlock(param) \
26087 +{ au_rw_read_unlock(rwsem); } \
26088 +static inline void prefix##_write_unlock(param) \
26089 +{ au_rw_write_unlock(rwsem); } \
26090 +static inline void prefix##_downgrade_lock(param) \
26091 +{ au_rw_dgrade_lock(rwsem); }
26093 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26094 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26095 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26097 +#endif /* __KERNEL__ */
26098 +#endif /* __AUFS_RWSEM_H__ */
26099 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26100 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26101 +++ linux/fs/aufs/sbinfo.c 2015-06-28 17:36:09.028407078 +0200
26104 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26106 + * This program, aufs is free software; you can redistribute it and/or modify
26107 + * it under the terms of the GNU General Public License as published by
26108 + * the Free Software Foundation; either version 2 of the License, or
26109 + * (at your option) any later version.
26111 + * This program is distributed in the hope that it will be useful,
26112 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26113 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26114 + * GNU General Public License for more details.
26116 + * You should have received a copy of the GNU General Public License
26117 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26121 + * superblock private data
26127 + * they are necessary regardless sysfs is disabled.
26129 +void au_si_free(struct kobject *kobj)
26132 + struct au_sbinfo *sbinfo;
26133 + char *locked __maybe_unused; /* debug only */
26135 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26136 + for (i = 0; i < AuPlink_NHASH; i++)
26137 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26138 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
26140 + au_rw_write_lock(&sbinfo->si_rwsem);
26141 + au_br_free(sbinfo);
26142 + au_rw_write_unlock(&sbinfo->si_rwsem);
26144 + AuDebugOn(radix_tree_gang_lookup
26145 + (&sbinfo->au_si_pid.tree, (void **)&locked,
26146 + /*first_index*/PID_MAX_DEFAULT - 1,
26147 + /*max_items*/sizeof(locked)/sizeof(*locked)));
26149 + kfree(sbinfo->si_branch);
26150 + kfree(sbinfo->au_si_pid.bitmap);
26151 + mutex_destroy(&sbinfo->si_xib_mtx);
26152 + AuRwDestroy(&sbinfo->si_rwsem);
26157 +int au_si_alloc(struct super_block *sb)
26160 + struct au_sbinfo *sbinfo;
26161 + static struct lock_class_key aufs_si;
26164 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26165 + if (unlikely(!sbinfo))
26168 + BUILD_BUG_ON(sizeof(unsigned long) !=
26169 + sizeof(*sbinfo->au_si_pid.bitmap));
26170 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
26171 + sizeof(*sbinfo->au_si_pid.bitmap),
26173 + if (unlikely(!sbinfo->au_si_pid.bitmap))
26176 + /* will be reallocated separately */
26177 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26178 + if (unlikely(!sbinfo->si_branch))
26181 + err = sysaufs_si_init(sbinfo);
26182 + if (unlikely(err))
26185 + au_nwt_init(&sbinfo->si_nowait);
26186 + au_rw_init_wlock(&sbinfo->si_rwsem);
26187 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
26188 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
26189 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
26191 + atomic_long_set(&sbinfo->si_ninodes, 0);
26192 + atomic_long_set(&sbinfo->si_nfiles, 0);
26194 + sbinfo->si_bend = -1;
26195 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26197 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26198 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26199 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26200 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26202 + au_fhsm_init(sbinfo);
26204 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26206 + sbinfo->si_xino_jiffy = jiffies;
26207 + sbinfo->si_xino_expire
26208 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26209 + mutex_init(&sbinfo->si_xib_mtx);
26210 + sbinfo->si_xino_brid = -1;
26211 + /* leave si_xib_last_pindex and si_xib_next_bit */
26213 + au_sphl_init(&sbinfo->si_aopen);
26215 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26216 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26217 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26218 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26220 + for (i = 0; i < AuPlink_NHASH; i++)
26221 + au_sphl_init(sbinfo->si_plink + i);
26222 + init_waitqueue_head(&sbinfo->si_plink_wq);
26223 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26225 + au_sphl_init(&sbinfo->si_files);
26227 + /* leave other members for sysaufs and si_mnt. */
26228 + sbinfo->si_sb = sb;
26229 + sb->s_fs_info = sbinfo;
26231 + return 0; /* success */
26234 + kfree(sbinfo->si_branch);
26236 + kfree(sbinfo->au_si_pid.bitmap);
26243 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
26246 + struct au_branch **brp;
26248 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26251 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
26252 + if (unlikely(!sz))
26253 + sz = sizeof(*brp);
26254 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
26256 + sbinfo->si_branch = brp;
26263 +/* ---------------------------------------------------------------------- */
26265 +unsigned int au_sigen_inc(struct super_block *sb)
26267 + unsigned int gen;
26268 + struct inode *inode;
26270 + SiMustWriteLock(sb);
26272 + gen = ++au_sbi(sb)->si_generation;
26273 + au_update_digen(sb->s_root);
26274 + inode = d_inode(sb->s_root);
26275 + au_update_iigen(inode, /*half*/0);
26276 + inode->i_version++;
26280 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26282 + aufs_bindex_t br_id;
26284 + struct au_sbinfo *sbinfo;
26286 + SiMustWriteLock(sb);
26288 + sbinfo = au_sbi(sb);
26289 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26290 + br_id = ++sbinfo->si_last_br_id;
26291 + AuDebugOn(br_id < 0);
26292 + if (br_id && au_br_index(sb, br_id) < 0)
26299 +/* ---------------------------------------------------------------------- */
26301 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26302 +int si_read_lock(struct super_block *sb, int flags)
26307 + if (au_ftest_lock(flags, FLUSH))
26308 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26310 + si_noflush_read_lock(sb);
26311 + err = au_plink_maint(sb, flags);
26312 + if (unlikely(err))
26313 + si_read_unlock(sb);
26318 +int si_write_lock(struct super_block *sb, int flags)
26322 + if (au_ftest_lock(flags, FLUSH))
26323 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26325 + si_noflush_write_lock(sb);
26326 + err = au_plink_maint(sb, flags);
26327 + if (unlikely(err))
26328 + si_write_unlock(sb);
26333 +/* dentry and super_block lock. call at entry point */
26334 +int aufs_read_lock(struct dentry *dentry, int flags)
26337 + struct super_block *sb;
26339 + sb = dentry->d_sb;
26340 + err = si_read_lock(sb, flags);
26341 + if (unlikely(err))
26344 + if (au_ftest_lock(flags, DW))
26345 + di_write_lock_child(dentry);
26347 + di_read_lock_child(dentry, flags);
26349 + if (au_ftest_lock(flags, GEN)) {
26350 + err = au_digen_test(dentry, au_sigen(sb));
26351 + AuDebugOn(!err && au_dbrange_test(dentry));
26352 + if (unlikely(err))
26353 + aufs_read_unlock(dentry, flags);
26360 +void aufs_read_unlock(struct dentry *dentry, int flags)
26362 + if (au_ftest_lock(flags, DW))
26363 + di_write_unlock(dentry);
26365 + di_read_unlock(dentry, flags);
26366 + si_read_unlock(dentry->d_sb);
26369 +void aufs_write_lock(struct dentry *dentry)
26371 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
26372 + di_write_lock_child(dentry);
26375 +void aufs_write_unlock(struct dentry *dentry)
26377 + di_write_unlock(dentry);
26378 + si_write_unlock(dentry->d_sb);
26381 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
26384 + unsigned int sigen;
26385 + struct super_block *sb;
26388 + err = si_read_lock(sb, flags);
26389 + if (unlikely(err))
26392 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
26394 + if (au_ftest_lock(flags, GEN)) {
26395 + sigen = au_sigen(sb);
26396 + err = au_digen_test(d1, sigen);
26397 + AuDebugOn(!err && au_dbrange_test(d1));
26399 + err = au_digen_test(d2, sigen);
26400 + AuDebugOn(!err && au_dbrange_test(d2));
26402 + if (unlikely(err))
26403 + aufs_read_and_write_unlock2(d1, d2);
26410 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
26412 + di_write_unlock2(d1, d2);
26413 + si_read_unlock(d1->d_sb);
26416 +/* ---------------------------------------------------------------------- */
26418 +int si_pid_test_slow(struct super_block *sb)
26423 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
26424 + rcu_read_unlock();
26426 + return (long)!!p;
26429 +void si_pid_set_slow(struct super_block *sb)
26432 + struct au_sbinfo *sbinfo;
26434 + AuDebugOn(si_pid_test_slow(sb));
26436 + sbinfo = au_sbi(sb);
26437 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
26439 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26440 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
26441 + /*any valid ptr*/sb);
26442 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26444 + radix_tree_preload_end();
26447 +void si_pid_clr_slow(struct super_block *sb)
26450 + struct au_sbinfo *sbinfo;
26452 + AuDebugOn(!si_pid_test_slow(sb));
26454 + sbinfo = au_sbi(sb);
26455 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26456 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
26457 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26459 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
26460 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
26461 +++ linux/fs/aufs/spl.h 2015-06-28 17:35:44.351383872 +0200
26464 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26466 + * This program, aufs is free software; you can redistribute it and/or modify
26467 + * it under the terms of the GNU General Public License as published by
26468 + * the Free Software Foundation; either version 2 of the License, or
26469 + * (at your option) any later version.
26471 + * This program is distributed in the hope that it will be useful,
26472 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26473 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26474 + * GNU General Public License for more details.
26476 + * You should have received a copy of the GNU General Public License
26477 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26481 + * simple list protected by a spinlock
26484 +#ifndef __AUFS_SPL_H__
26485 +#define __AUFS_SPL_H__
26489 +struct au_splhead {
26491 + struct list_head head;
26494 +static inline void au_spl_init(struct au_splhead *spl)
26496 + spin_lock_init(&spl->spin);
26497 + INIT_LIST_HEAD(&spl->head);
26500 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
26502 + spin_lock(&spl->spin);
26503 + list_add(list, &spl->head);
26504 + spin_unlock(&spl->spin);
26507 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
26509 + spin_lock(&spl->spin);
26511 + spin_unlock(&spl->spin);
26514 +static inline void au_spl_del_rcu(struct list_head *list,
26515 + struct au_splhead *spl)
26517 + spin_lock(&spl->spin);
26518 + list_del_rcu(list);
26519 + spin_unlock(&spl->spin);
26522 +/* ---------------------------------------------------------------------- */
26524 +struct au_sphlhead {
26526 + struct hlist_head head;
26529 +static inline void au_sphl_init(struct au_sphlhead *sphl)
26531 + spin_lock_init(&sphl->spin);
26532 + INIT_HLIST_HEAD(&sphl->head);
26535 +static inline void au_sphl_add(struct hlist_node *hlist,
26536 + struct au_sphlhead *sphl)
26538 + spin_lock(&sphl->spin);
26539 + hlist_add_head(hlist, &sphl->head);
26540 + spin_unlock(&sphl->spin);
26543 +static inline void au_sphl_del(struct hlist_node *hlist,
26544 + struct au_sphlhead *sphl)
26546 + spin_lock(&sphl->spin);
26547 + hlist_del(hlist);
26548 + spin_unlock(&sphl->spin);
26551 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
26552 + struct au_sphlhead *sphl)
26554 + spin_lock(&sphl->spin);
26555 + hlist_del_rcu(hlist);
26556 + spin_unlock(&sphl->spin);
26559 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
26561 + unsigned long cnt;
26562 + struct hlist_node *pos;
26565 + spin_lock(&sphl->spin);
26566 + hlist_for_each(pos, &sphl->head)
26568 + spin_unlock(&sphl->spin);
26572 +#endif /* __KERNEL__ */
26573 +#endif /* __AUFS_SPL_H__ */
26574 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
26575 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
26576 +++ linux/fs/aufs/super.c 2015-06-28 17:36:09.028407078 +0200
26579 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26581 + * This program, aufs is free software; you can redistribute it and/or modify
26582 + * it under the terms of the GNU General Public License as published by
26583 + * the Free Software Foundation; either version 2 of the License, or
26584 + * (at your option) any later version.
26586 + * This program is distributed in the hope that it will be useful,
26587 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26588 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26589 + * GNU General Public License for more details.
26591 + * You should have received a copy of the GNU General Public License
26592 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26596 + * mount and super_block operations
26599 +#include <linux/mm.h>
26600 +#include <linux/seq_file.h>
26601 +#include <linux/statfs.h>
26602 +#include <linux/vmalloc.h>
26606 + * super_operations
26608 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
26610 + struct au_icntnr *c;
26612 + c = au_cache_alloc_icntnr();
26614 + au_icntnr_init(c);
26615 + c->vfs_inode.i_version = 1; /* sigen(sb); */
26616 + c->iinfo.ii_hinode = NULL;
26617 + return &c->vfs_inode;
26622 +static void aufs_destroy_inode_cb(struct rcu_head *head)
26624 + struct inode *inode = container_of(head, struct inode, i_rcu);
26626 + INIT_HLIST_HEAD(&inode->i_dentry);
26627 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
26630 +static void aufs_destroy_inode(struct inode *inode)
26632 + au_iinfo_fin(inode);
26633 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
26636 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
26638 + struct inode *inode;
26641 + inode = iget_locked(sb, ino);
26642 + if (unlikely(!inode)) {
26643 + inode = ERR_PTR(-ENOMEM);
26646 + if (!(inode->i_state & I_NEW))
26649 + err = au_xigen_new(inode);
26651 + err = au_iinfo_init(inode);
26653 + inode->i_version++;
26655 + iget_failed(inode);
26656 + inode = ERR_PTR(err);
26660 + /* never return NULL */
26661 + AuDebugOn(!inode);
26662 + AuTraceErrPtr(inode);
26666 +/* lock free root dinfo */
26667 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
26670 + aufs_bindex_t bindex, bend;
26671 + struct path path;
26672 + struct au_hdentry *hdp;
26673 + struct au_branch *br;
26674 + au_br_perm_str_t perm;
26677 + bend = au_sbend(sb);
26678 + hdp = au_di(sb->s_root)->di_hdentry;
26679 + for (bindex = 0; !err && bindex <= bend; bindex++) {
26680 + br = au_sbr(sb, bindex);
26681 + path.mnt = au_br_mnt(br);
26682 + path.dentry = hdp[bindex].hd_dentry;
26683 + err = au_seq_path(seq, &path);
26685 + au_optstr_br_perm(&perm, br->br_perm);
26686 + err = seq_printf(seq, "=%s", perm.a);
26690 + if (!err && bindex != bend)
26691 + err = seq_putc(seq, ':');
26697 +static void au_show_wbr_create(struct seq_file *m, int v,
26698 + struct au_sbinfo *sbinfo)
26702 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26704 + seq_puts(m, ",create=");
26705 + pat = au_optstr_wbr_create(v);
26707 + case AuWbrCreate_TDP:
26708 + case AuWbrCreate_RR:
26709 + case AuWbrCreate_MFS:
26710 + case AuWbrCreate_PMFS:
26711 + seq_puts(m, pat);
26713 + case AuWbrCreate_MFSV:
26714 + seq_printf(m, /*pat*/"mfs:%lu",
26715 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26718 + case AuWbrCreate_PMFSV:
26719 + seq_printf(m, /*pat*/"pmfs:%lu",
26720 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26723 + case AuWbrCreate_MFSRR:
26724 + seq_printf(m, /*pat*/"mfsrr:%llu",
26725 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26727 + case AuWbrCreate_MFSRRV:
26728 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
26729 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26730 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26733 + case AuWbrCreate_PMFSRR:
26734 + seq_printf(m, /*pat*/"pmfsrr:%llu",
26735 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26737 + case AuWbrCreate_PMFSRRV:
26738 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
26739 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26740 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26746 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
26748 +#ifdef CONFIG_SYSFS
26752 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
26753 + aufs_bindex_t bindex, brid;
26754 + struct qstr *name;
26756 + struct dentry *d, *h_root;
26757 + struct au_hdentry *hdp;
26759 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26762 + f = au_sbi(sb)->si_xib;
26766 + /* stop printing the default xino path on the first writable branch */
26768 + brid = au_xino_brid(sb);
26770 + bindex = au_br_index(sb, brid);
26771 + hdp = au_di(sb->s_root)->di_hdentry;
26772 + h_root = hdp[0 + bindex].hd_dentry;
26774 + d = f->f_path.dentry;
26775 + name = &d->d_name;
26776 + /* safe ->d_parent because the file is unlinked */
26777 + if (d->d_parent == h_root
26778 + && name->len == len
26779 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
26782 + seq_puts(seq, ",xino=");
26783 + err = au_xino_path(seq, f);
26790 +/* seq_file will re-call me in case of too long string */
26791 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
26794 + unsigned int mnt_flags, v;
26795 + struct super_block *sb;
26796 + struct au_sbinfo *sbinfo;
26798 +#define AuBool(name, str) do { \
26799 + v = au_opt_test(mnt_flags, name); \
26800 + if (v != au_opt_test(AuOpt_Def, name)) \
26801 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
26804 +#define AuStr(name, str) do { \
26805 + v = mnt_flags & AuOptMask_##name; \
26806 + if (v != (AuOpt_Def & AuOptMask_##name)) \
26807 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
26810 +#define AuUInt(name, str, val) do { \
26811 + if (val != AUFS_##name##_DEF) \
26812 + seq_printf(m, "," #str "=%u", val); \
26815 + sb = dentry->d_sb;
26816 + if (sb->s_flags & MS_POSIXACL)
26817 + seq_puts(m, ",acl");
26819 + /* lock free root dinfo */
26820 + si_noflush_read_lock(sb);
26821 + sbinfo = au_sbi(sb);
26822 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
26824 + mnt_flags = au_mntflags(sb);
26825 + if (au_opt_test(mnt_flags, XINO)) {
26826 + err = au_show_xino(m, sb);
26827 + if (unlikely(err))
26830 + seq_puts(m, ",noxino");
26832 + AuBool(TRUNC_XINO, trunc_xino);
26833 + AuStr(UDBA, udba);
26834 + AuBool(SHWH, shwh);
26835 + AuBool(PLINK, plink);
26836 + AuBool(DIO, dio);
26837 + AuBool(DIRPERM1, dirperm1);
26839 + v = sbinfo->si_wbr_create;
26840 + if (v != AuWbrCreate_Def)
26841 + au_show_wbr_create(m, v, sbinfo);
26843 + v = sbinfo->si_wbr_copyup;
26844 + if (v != AuWbrCopyup_Def)
26845 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
26847 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
26848 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
26849 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
26851 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
26853 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
26854 + AuUInt(RDCACHE, rdcache, v);
26856 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
26857 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
26859 + au_fhsm_show(m, sbinfo);
26861 + AuBool(SUM, sum);
26862 + /* AuBool(SUM_W, wsum); */
26863 + AuBool(WARN_PERM, warn_perm);
26864 + AuBool(VERBOSE, verbose);
26867 + /* be sure to print "br:" last */
26868 + if (!sysaufs_brs) {
26869 + seq_puts(m, ",br:");
26870 + au_show_brs(m, sb);
26872 + si_read_unlock(sb);
26880 +/* ---------------------------------------------------------------------- */
26882 +/* sum mode which returns the summation for statfs(2) */
26884 +static u64 au_add_till_max(u64 a, u64 b)
26892 + return ULLONG_MAX;
26895 +static u64 au_mul_till_max(u64 a, long mul)
26903 + return ULLONG_MAX;
26906 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
26909 + long bsize, factor;
26910 + u64 blocks, bfree, bavail, files, ffree;
26911 + aufs_bindex_t bend, bindex, i;
26912 + unsigned char shared;
26913 + struct path h_path;
26914 + struct super_block *h_sb;
26917 + bsize = LONG_MAX;
26923 + bend = au_sbend(sb);
26924 + for (bindex = 0; bindex <= bend; bindex++) {
26925 + h_path.mnt = au_sbr_mnt(sb, bindex);
26926 + h_sb = h_path.mnt->mnt_sb;
26928 + for (i = 0; !shared && i < bindex; i++)
26929 + shared = (au_sbr_sb(sb, i) == h_sb);
26933 + /* sb->s_root for NFS is unreliable */
26934 + h_path.dentry = h_path.mnt->mnt_root;
26935 + err = vfs_statfs(&h_path, buf);
26936 + if (unlikely(err))
26939 + if (bsize > buf->f_bsize) {
26941 + * we will reduce bsize, so we have to expand blocks
26942 + * etc. to match them again
26944 + factor = (bsize / buf->f_bsize);
26945 + blocks = au_mul_till_max(blocks, factor);
26946 + bfree = au_mul_till_max(bfree, factor);
26947 + bavail = au_mul_till_max(bavail, factor);
26948 + bsize = buf->f_bsize;
26951 + factor = (buf->f_bsize / bsize);
26952 + blocks = au_add_till_max(blocks,
26953 + au_mul_till_max(buf->f_blocks, factor));
26954 + bfree = au_add_till_max(bfree,
26955 + au_mul_till_max(buf->f_bfree, factor));
26956 + bavail = au_add_till_max(bavail,
26957 + au_mul_till_max(buf->f_bavail, factor));
26958 + files = au_add_till_max(files, buf->f_files);
26959 + ffree = au_add_till_max(ffree, buf->f_ffree);
26962 + buf->f_bsize = bsize;
26963 + buf->f_blocks = blocks;
26964 + buf->f_bfree = bfree;
26965 + buf->f_bavail = bavail;
26966 + buf->f_files = files;
26967 + buf->f_ffree = ffree;
26968 + buf->f_frsize = 0;
26974 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
26977 + struct path h_path;
26978 + struct super_block *sb;
26980 + /* lock free root dinfo */
26981 + sb = dentry->d_sb;
26982 + si_noflush_read_lock(sb);
26983 + if (!au_opt_test(au_mntflags(sb), SUM)) {
26984 + /* sb->s_root for NFS is unreliable */
26985 + h_path.mnt = au_sbr_mnt(sb, 0);
26986 + h_path.dentry = h_path.mnt->mnt_root;
26987 + err = vfs_statfs(&h_path, buf);
26989 + err = au_statfs_sum(sb, buf);
26990 + si_read_unlock(sb);
26993 + buf->f_type = AUFS_SUPER_MAGIC;
26994 + buf->f_namelen = AUFS_MAX_NAMELEN;
26995 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
26997 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27002 +/* ---------------------------------------------------------------------- */
27004 +static int aufs_sync_fs(struct super_block *sb, int wait)
27007 + aufs_bindex_t bend, bindex;
27008 + struct au_branch *br;
27009 + struct super_block *h_sb;
27012 + si_noflush_read_lock(sb);
27013 + bend = au_sbend(sb);
27014 + for (bindex = 0; bindex <= bend; bindex++) {
27015 + br = au_sbr(sb, bindex);
27016 + if (!au_br_writable(br->br_perm))
27019 + h_sb = au_sbr_sb(sb, bindex);
27020 + if (h_sb->s_op->sync_fs) {
27021 + e = h_sb->s_op->sync_fs(h_sb, wait);
27022 + if (unlikely(e && !err))
27024 + /* go on even if an error happens */
27027 + si_read_unlock(sb);
27032 +/* ---------------------------------------------------------------------- */
27034 +/* final actions when unmounting a file system */
27035 +static void aufs_put_super(struct super_block *sb)
27037 + struct au_sbinfo *sbinfo;
27039 + sbinfo = au_sbi(sb);
27043 + dbgaufs_si_fin(sbinfo);
27044 + kobject_put(&sbinfo->si_kobj);
27047 +/* ---------------------------------------------------------------------- */
27049 +void au_array_free(void *array)
27052 + if (!is_vmalloc_addr(array))
27059 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
27062 + unsigned long long n, sz;
27069 + if (*hint > ULLONG_MAX / sizeof(array)) {
27070 + array = ERR_PTR(-EMFILE);
27071 + pr_err("hint %llu\n", *hint);
27075 + sz = sizeof(array) * *hint;
27076 + array = kzalloc(sz, GFP_NOFS);
27077 + if (unlikely(!array))
27078 + array = vzalloc(sz);
27079 + if (unlikely(!array)) {
27080 + array = ERR_PTR(-ENOMEM);
27084 + n = cb(array, *hint, arg);
27085 + AuDebugOn(n > *hint);
27092 +static unsigned long long au_iarray_cb(void *a,
27093 + unsigned long long max __maybe_unused,
27096 + unsigned long long n;
27097 + struct inode **p, *inode;
27098 + struct list_head *head;
27103 + spin_lock(&inode_sb_list_lock);
27104 + list_for_each_entry(inode, head, i_sb_list) {
27105 + if (!is_bad_inode(inode)
27106 + && au_ii(inode)->ii_bstart >= 0) {
27107 + spin_lock(&inode->i_lock);
27108 + if (atomic_read(&inode->i_count)) {
27112 + AuDebugOn(n > max);
27114 + spin_unlock(&inode->i_lock);
27117 + spin_unlock(&inode_sb_list_lock);
27122 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27124 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
27125 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
27128 +void au_iarray_free(struct inode **a, unsigned long long max)
27130 + unsigned long long ull;
27132 + for (ull = 0; ull < max; ull++)
27134 + au_array_free(a);
27137 +/* ---------------------------------------------------------------------- */
27140 + * refresh dentry and inode at remount time.
27142 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27143 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27144 + struct dentry *parent)
27148 + di_write_lock_child(dentry);
27149 + di_read_lock_parent(parent, AuLock_IR);
27150 + err = au_refresh_dentry(dentry, parent);
27151 + if (!err && dir_flags)
27152 + au_hn_reset(d_inode(dentry), dir_flags);
27153 + di_read_unlock(parent, AuLock_IR);
27154 + di_write_unlock(dentry);
27159 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27160 + struct au_sbinfo *sbinfo,
27161 + const unsigned int dir_flags)
27164 + struct dentry *parent;
27167 + parent = dget_parent(dentry);
27168 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27169 + if (d_really_is_positive(dentry)) {
27170 + if (!d_is_dir(dentry))
27171 + err = au_do_refresh(dentry, /*dir_flags*/0,
27174 + err = au_do_refresh(dentry, dir_flags, parent);
27175 + if (unlikely(err))
27176 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27179 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27180 + AuDbgDentry(dentry);
27188 +static int au_refresh_d(struct super_block *sb)
27190 + int err, i, j, ndentry, e;
27191 + unsigned int sigen;
27192 + struct au_dcsub_pages dpages;
27193 + struct au_dpage *dpage;
27194 + struct dentry **dentries, *d;
27195 + struct au_sbinfo *sbinfo;
27196 + struct dentry *root = sb->s_root;
27197 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
27199 + err = au_dpages_init(&dpages, GFP_NOFS);
27200 + if (unlikely(err))
27202 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27203 + if (unlikely(err))
27206 + sigen = au_sigen(sb);
27207 + sbinfo = au_sbi(sb);
27208 + for (i = 0; i < dpages.ndpage; i++) {
27209 + dpage = dpages.dpages + i;
27210 + dentries = dpage->dentries;
27211 + ndentry = dpage->ndentry;
27212 + for (j = 0; j < ndentry; j++) {
27214 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
27215 + if (unlikely(e && !err))
27217 + /* go on even err */
27222 + au_dpages_free(&dpages);
27227 +static int au_refresh_i(struct super_block *sb)
27230 + unsigned int sigen;
27231 + unsigned long long max, ull;
27232 + struct inode *inode, **array;
27234 + array = au_iarray_alloc(sb, &max);
27235 + err = PTR_ERR(array);
27236 + if (IS_ERR(array))
27240 + sigen = au_sigen(sb);
27241 + for (ull = 0; ull < max; ull++) {
27242 + inode = array[ull];
27243 + if (unlikely(!inode))
27245 + if (au_iigen(inode, NULL) != sigen) {
27246 + ii_write_lock_child(inode);
27247 + e = au_refresh_hinode_self(inode);
27248 + ii_write_unlock(inode);
27249 + if (unlikely(e)) {
27250 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27253 + /* go on even if err */
27258 + au_iarray_free(array, max);
27264 +static void au_remount_refresh(struct super_block *sb)
27267 + unsigned int udba;
27268 + aufs_bindex_t bindex, bend;
27269 + struct dentry *root;
27270 + struct inode *inode;
27271 + struct au_branch *br;
27273 + au_sigen_inc(sb);
27274 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
27276 + root = sb->s_root;
27277 + DiMustNoWaiters(root);
27278 + inode = d_inode(root);
27279 + IiMustNoWaiters(inode);
27281 + udba = au_opt_udba(sb);
27282 + bend = au_sbend(sb);
27283 + for (bindex = 0; bindex <= bend; bindex++) {
27284 + br = au_sbr(sb, bindex);
27285 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27286 + if (unlikely(err))
27287 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27289 + /* go on even if err */
27291 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27293 + di_write_unlock(root);
27294 + err = au_refresh_d(sb);
27295 + e = au_refresh_i(sb);
27296 + if (unlikely(e && !err))
27298 + /* aufs_write_lock() calls ..._child() */
27299 + di_write_lock_child(root);
27301 + au_cpup_attr_all(inode, /*force*/1);
27303 + if (unlikely(err))
27304 + AuIOErr("refresh failed, ignored, %d\n", err);
27307 +/* stop extra interpretation of errno in mount(8), and strange error messages */
27308 +static int cvt_err(int err)
27322 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
27325 + unsigned int mntflags;
27326 + struct au_opts opts;
27327 + struct dentry *root;
27328 + struct inode *inode;
27329 + struct au_sbinfo *sbinfo;
27332 + root = sb->s_root;
27333 + if (!data || !*data) {
27334 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27336 + di_write_lock_child(root);
27337 + err = au_opts_verify(sb, *flags, /*pending*/0);
27338 + aufs_write_unlock(root);
27344 + memset(&opts, 0, sizeof(opts));
27345 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27346 + if (unlikely(!opts.opt))
27348 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27349 + opts.flags = AuOpts_REMOUNT;
27350 + opts.sb_flags = *flags;
27352 + /* parse it before aufs lock */
27353 + err = au_opts_parse(sb, data, &opts);
27354 + if (unlikely(err))
27357 + sbinfo = au_sbi(sb);
27358 + inode = d_inode(root);
27359 + mutex_lock(&inode->i_mutex);
27360 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27361 + if (unlikely(err))
27363 + di_write_lock_child(root);
27365 + /* au_opts_remount() may return an error */
27366 + err = au_opts_remount(sb, &opts);
27367 + au_opts_free(&opts);
27369 + if (au_ftest_opts(opts.flags, REFRESH))
27370 + au_remount_refresh(sb);
27372 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
27373 + mntflags = au_mntflags(sb);
27374 + do_dx = !!au_opt_test(mntflags, DIO);
27375 + au_dy_arefresh(do_dx);
27378 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
27379 + aufs_write_unlock(root);
27382 + mutex_unlock(&inode->i_mutex);
27384 + free_page((unsigned long)opts.opt);
27386 + err = cvt_err(err);
27391 +static const struct super_operations aufs_sop = {
27392 + .alloc_inode = aufs_alloc_inode,
27393 + .destroy_inode = aufs_destroy_inode,
27394 + /* always deleting, no clearing */
27395 + .drop_inode = generic_delete_inode,
27396 + .show_options = aufs_show_options,
27397 + .statfs = aufs_statfs,
27398 + .put_super = aufs_put_super,
27399 + .sync_fs = aufs_sync_fs,
27400 + .remount_fs = aufs_remount_fs
27403 +/* ---------------------------------------------------------------------- */
27405 +static int alloc_root(struct super_block *sb)
27408 + struct inode *inode;
27409 + struct dentry *root;
27412 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
27413 + err = PTR_ERR(inode);
27414 + if (IS_ERR(inode))
27417 + inode->i_op = &aufs_dir_iop;
27418 + inode->i_fop = &aufs_dir_fop;
27419 + inode->i_mode = S_IFDIR;
27420 + set_nlink(inode, 2);
27421 + unlock_new_inode(inode);
27423 + root = d_make_root(inode);
27424 + if (unlikely(!root))
27426 + err = PTR_ERR(root);
27427 + if (IS_ERR(root))
27430 + err = au_di_init(root);
27432 + sb->s_root = root;
27433 + return 0; /* success */
27441 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
27442 + int silent __maybe_unused)
27445 + struct au_opts opts;
27446 + struct dentry *root;
27447 + struct inode *inode;
27448 + char *arg = raw_data;
27450 + if (unlikely(!arg || !*arg)) {
27452 + pr_err("no arg\n");
27457 + memset(&opts, 0, sizeof(opts));
27458 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27459 + if (unlikely(!opts.opt))
27461 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27462 + opts.sb_flags = sb->s_flags;
27464 + err = au_si_alloc(sb);
27465 + if (unlikely(err))
27468 + /* all timestamps always follow the ones on the branch */
27469 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
27470 + sb->s_op = &aufs_sop;
27471 + sb->s_d_op = &aufs_dop;
27472 + sb->s_magic = AUFS_SUPER_MAGIC;
27473 + sb->s_maxbytes = 0;
27474 + sb->s_stack_depth = 1;
27475 + au_export_init(sb);
27476 + /* au_xattr_init(sb); */
27478 + err = alloc_root(sb);
27479 + if (unlikely(err)) {
27480 + si_write_unlock(sb);
27483 + root = sb->s_root;
27484 + inode = d_inode(root);
27487 + * actually we can parse options regardless aufs lock here.
27488 + * but at remount time, parsing must be done before aufs lock.
27489 + * so we follow the same rule.
27491 + ii_write_lock_parent(inode);
27492 + aufs_write_unlock(root);
27493 + err = au_opts_parse(sb, arg, &opts);
27494 + if (unlikely(err))
27497 + /* lock vfs_inode first, then aufs. */
27498 + mutex_lock(&inode->i_mutex);
27499 + aufs_write_lock(root);
27500 + err = au_opts_mount(sb, &opts);
27501 + au_opts_free(&opts);
27502 + aufs_write_unlock(root);
27503 + mutex_unlock(&inode->i_mutex);
27505 + goto out_opts; /* success */
27509 + sb->s_root = NULL;
27511 + dbgaufs_si_fin(au_sbi(sb));
27512 + kobject_put(&au_sbi(sb)->si_kobj);
27513 + sb->s_fs_info = NULL;
27515 + free_page((unsigned long)opts.opt);
27518 + err = cvt_err(err);
27523 +/* ---------------------------------------------------------------------- */
27525 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
27526 + const char *dev_name __maybe_unused,
27529 + struct dentry *root;
27530 + struct super_block *sb;
27532 + /* all timestamps always follow the ones on the branch */
27533 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
27534 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
27535 + if (IS_ERR(root))
27539 + si_write_lock(sb, !AuLock_FLUSH);
27540 + sysaufs_brs_add(sb, 0);
27541 + si_write_unlock(sb);
27542 + au_sbilist_add(sb);
27548 +static void aufs_kill_sb(struct super_block *sb)
27550 + struct au_sbinfo *sbinfo;
27552 + sbinfo = au_sbi(sb);
27554 + au_sbilist_del(sb);
27555 + aufs_write_lock(sb->s_root);
27557 + if (sbinfo->si_wbr_create_ops->fin)
27558 + sbinfo->si_wbr_create_ops->fin(sb);
27559 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
27560 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
27561 + au_remount_refresh(sb);
27563 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27564 + au_plink_put(sb, /*verbose*/1);
27566 + sbinfo->si_sb = NULL;
27567 + aufs_write_unlock(sb->s_root);
27568 + au_nwt_flush(&sbinfo->si_nowait);
27570 + kill_anon_super(sb);
27573 +struct file_system_type aufs_fs_type = {
27574 + .name = AUFS_FSTYPE,
27575 + /* a race between rename and others */
27576 + .fs_flags = FS_RENAME_DOES_D_MOVE,
27577 + .mount = aufs_mount,
27578 + .kill_sb = aufs_kill_sb,
27579 + /* no need to __module_get() and module_put(). */
27580 + .owner = THIS_MODULE,
27582 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
27583 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
27584 +++ linux/fs/aufs/super.h 2015-06-28 17:36:09.028407078 +0200
27587 + * Copyright (C) 2005-2015 Junjiro R. Okajima
27589 + * This program, aufs is free software; you can redistribute it and/or modify
27590 + * it under the terms of the GNU General Public License as published by
27591 + * the Free Software Foundation; either version 2 of the License, or
27592 + * (at your option) any later version.
27594 + * This program is distributed in the hope that it will be useful,
27595 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27596 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27597 + * GNU General Public License for more details.
27599 + * You should have received a copy of the GNU General Public License
27600 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27604 + * super_block operations
27607 +#ifndef __AUFS_SUPER_H__
27608 +#define __AUFS_SUPER_H__
27612 +#include <linux/fs.h>
27613 +#include <linux/kobject.h>
27614 +#include "rwsem.h"
27618 +/* policies to select one among multiple writable branches */
27619 +struct au_wbr_copyup_operations {
27620 + int (*copyup)(struct dentry *dentry);
27623 +#define AuWbr_DIR 1 /* target is a dir */
27624 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
27626 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
27627 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
27628 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
27630 +struct au_wbr_create_operations {
27631 + int (*create)(struct dentry *dentry, unsigned int flags);
27632 + int (*init)(struct super_block *sb);
27633 + int (*fin)(struct super_block *sb);
27636 +struct au_wbr_mfs {
27637 + struct mutex mfs_lock; /* protect this structure */
27638 + unsigned long mfs_jiffy;
27639 + unsigned long mfs_expire;
27640 + aufs_bindex_t mfs_bindex;
27642 + unsigned long long mfsrr_bytes;
27643 + unsigned long long mfsrr_watermark;
27646 +struct pseudo_link {
27648 + struct hlist_node hlist;
27649 + struct rcu_head rcu;
27651 + struct inode *inode;
27654 +#define AuPlink_NHASH 100
27655 +static inline int au_plink_hash(ino_t ino)
27657 + return ino % AuPlink_NHASH;
27660 +/* File-based Hierarchical Storage Management */
27662 +#ifdef CONFIG_AUFS_FHSM
27663 + /* allow only one process who can receive the notification */
27664 + spinlock_t fhsm_spin;
27666 + wait_queue_head_t fhsm_wqh;
27667 + atomic_t fhsm_readable;
27669 + /* these are protected by si_rwsem */
27670 + unsigned long fhsm_expire;
27671 + aufs_bindex_t fhsm_bottom;
27676 +struct au_sbinfo {
27677 + /* nowait tasks in the system-wide workqueue */
27678 + struct au_nowait_tasks si_nowait;
27681 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
27682 + * rwsem for au_sbinfo is necessary.
27684 + struct au_rwsem si_rwsem;
27686 + /* prevent recursive locking in deleting inode */
27688 + unsigned long *bitmap;
27689 + spinlock_t tree_lock;
27690 + struct radix_tree_root tree;
27694 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
27697 + atomic_long_t si_ninodes, si_nfiles;
27699 + /* branch management */
27700 + unsigned int si_generation;
27702 + /* see AuSi_ flags */
27703 + unsigned char au_si_status;
27705 + aufs_bindex_t si_bend;
27707 + /* dirty trick to keep br_id plus */
27708 + unsigned int si_last_br_id :
27709 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
27710 + struct au_branch **si_branch;
27712 + /* policy to select a writable branch */
27713 + unsigned char si_wbr_copyup;
27714 + unsigned char si_wbr_create;
27715 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
27716 + struct au_wbr_create_operations *si_wbr_create_ops;
27718 + /* round robin */
27719 + atomic_t si_wbr_rr_next;
27721 + /* most free space */
27722 + struct au_wbr_mfs si_wbr_mfs;
27724 + /* File-based Hierarchical Storage Management */
27725 + struct au_fhsm si_fhsm;
27727 + /* mount flags */
27728 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
27729 + unsigned int si_mntflags;
27731 + /* external inode number (bitmap and translation table) */
27732 + vfs_readf_t si_xread;
27733 + vfs_writef_t si_xwrite;
27734 + struct file *si_xib;
27735 + struct mutex si_xib_mtx; /* protect xib members */
27736 + unsigned long *si_xib_buf;
27737 + unsigned long si_xib_last_pindex;
27738 + int si_xib_next_bit;
27739 + aufs_bindex_t si_xino_brid;
27740 + unsigned long si_xino_jiffy;
27741 + unsigned long si_xino_expire;
27742 + /* reserved for future use */
27743 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
27745 +#ifdef CONFIG_AUFS_EXPORT
27746 + /* i_generation */
27747 + struct file *si_xigen;
27748 + atomic_t si_xigen_next;
27751 + /* dirty trick to suppoer atomic_open */
27752 + struct au_sphlhead si_aopen;
27754 + /* vdir parameters */
27755 + unsigned long si_rdcache; /* max cache time in jiffies */
27756 + unsigned int si_rdblk; /* deblk size */
27757 + unsigned int si_rdhash; /* hash size */
27760 + * If the number of whiteouts are larger than si_dirwh, leave all of
27761 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
27762 + * future fsck.aufs or kernel thread will remove them later.
27763 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
27765 + unsigned int si_dirwh;
27767 + /* pseudo_link list */
27768 + struct au_sphlhead si_plink[AuPlink_NHASH];
27769 + wait_queue_head_t si_plink_wq;
27770 + spinlock_t si_plink_maint_lock;
27771 + pid_t si_plink_maint_pid;
27774 + struct au_sphlhead si_files;
27777 + * sysfs and lifetime management.
27778 + * this is not a small structure and it may be a waste of memory in case
27779 + * of sysfs is disabled, particulary when many aufs-es are mounted.
27780 + * but using sysfs is majority.
27782 + struct kobject si_kobj;
27783 +#ifdef CONFIG_DEBUG_FS
27784 + struct dentry *si_dbgaufs;
27785 + struct dentry *si_dbgaufs_plink;
27786 + struct dentry *si_dbgaufs_xib;
27787 +#ifdef CONFIG_AUFS_EXPORT
27788 + struct dentry *si_dbgaufs_xigen;
27792 +#ifdef CONFIG_AUFS_SBILIST
27793 + struct list_head si_list;
27796 + /* dirty, necessary for unmounting, sysfs and sysrq */
27797 + struct super_block *si_sb;
27800 +/* sbinfo status flags */
27802 + * set true when refresh_dirs() failed at remount time.
27803 + * then try refreshing dirs at access time again.
27804 + * if it is false, refreshing dirs at access time is unnecesary
27806 +#define AuSi_FAILED_REFRESH_DIR 1
27808 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
27810 +#ifndef CONFIG_AUFS_FHSM
27812 +#define AuSi_FHSM 0
27815 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
27816 + unsigned int flag)
27818 + AuRwMustAnyLock(&sbi->si_rwsem);
27819 + return sbi->au_si_status & flag;
27821 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
27822 +#define au_fset_si(sbinfo, name) do { \
27823 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27824 + (sbinfo)->au_si_status |= AuSi_##name; \
27826 +#define au_fclr_si(sbinfo, name) do { \
27827 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27828 + (sbinfo)->au_si_status &= ~AuSi_##name; \
27831 +/* ---------------------------------------------------------------------- */
27833 +/* policy to select one among writable branches */
27834 +#define AuWbrCopyup(sbinfo, ...) \
27835 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
27836 +#define AuWbrCreate(sbinfo, ...) \
27837 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
27839 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
27840 +#define AuLock_DW 1 /* write-lock dentry */
27841 +#define AuLock_IR (1 << 1) /* read-lock inode */
27842 +#define AuLock_IW (1 << 2) /* write-lock inode */
27843 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
27844 +#define AuLock_DIR (1 << 4) /* target is a dir */
27845 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
27846 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
27847 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
27848 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
27849 +#define au_fset_lock(flags, name) \
27850 + do { (flags) |= AuLock_##name; } while (0)
27851 +#define au_fclr_lock(flags, name) \
27852 + do { (flags) &= ~AuLock_##name; } while (0)
27854 +/* ---------------------------------------------------------------------- */
27857 +extern struct file_system_type aufs_fs_type;
27858 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
27859 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
27861 +void au_array_free(void *array);
27862 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
27863 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
27864 +void au_iarray_free(struct inode **a, unsigned long long max);
27867 +void au_si_free(struct kobject *kobj);
27868 +int au_si_alloc(struct super_block *sb);
27869 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
27871 +unsigned int au_sigen_inc(struct super_block *sb);
27872 +aufs_bindex_t au_new_br_id(struct super_block *sb);
27874 +int si_read_lock(struct super_block *sb, int flags);
27875 +int si_write_lock(struct super_block *sb, int flags);
27876 +int aufs_read_lock(struct dentry *dentry, int flags);
27877 +void aufs_read_unlock(struct dentry *dentry, int flags);
27878 +void aufs_write_lock(struct dentry *dentry);
27879 +void aufs_write_unlock(struct dentry *dentry);
27880 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
27881 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
27883 +int si_pid_test_slow(struct super_block *sb);
27884 +void si_pid_set_slow(struct super_block *sb);
27885 +void si_pid_clr_slow(struct super_block *sb);
27887 +/* wbr_policy.c */
27888 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
27889 +extern struct au_wbr_create_operations au_wbr_create_ops[];
27890 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
27891 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
27892 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
27895 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
27897 +#ifdef CONFIG_AUFS_FHSM
27900 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
27904 + spin_lock(&fhsm->fhsm_spin);
27905 + pid = fhsm->fhsm_pid;
27906 + spin_unlock(&fhsm->fhsm_spin);
27911 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
27912 +void au_fhsm_wrote_all(struct super_block *sb, int force);
27913 +int au_fhsm_fd(struct super_block *sb, int oflags);
27914 +int au_fhsm_br_alloc(struct au_branch *br);
27915 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
27916 +void au_fhsm_fin(struct super_block *sb);
27917 +void au_fhsm_init(struct au_sbinfo *sbinfo);
27918 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
27919 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
27921 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
27923 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
27924 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
27925 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
27926 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
27927 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
27928 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
27929 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
27930 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
27931 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
27934 +/* ---------------------------------------------------------------------- */
27936 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
27938 + return sb->s_fs_info;
27941 +/* ---------------------------------------------------------------------- */
27943 +#ifdef CONFIG_AUFS_EXPORT
27944 +int au_test_nfsd(void);
27945 +void au_export_init(struct super_block *sb);
27946 +void au_xigen_inc(struct inode *inode);
27947 +int au_xigen_new(struct inode *inode);
27948 +int au_xigen_set(struct super_block *sb, struct file *base);
27949 +void au_xigen_clr(struct super_block *sb);
27951 +static inline int au_busy_or_stale(void)
27953 + if (!au_test_nfsd())
27958 +AuStubInt0(au_test_nfsd, void)
27959 +AuStubVoid(au_export_init, struct super_block *sb)
27960 +AuStubVoid(au_xigen_inc, struct inode *inode)
27961 +AuStubInt0(au_xigen_new, struct inode *inode)
27962 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
27963 +AuStubVoid(au_xigen_clr, struct super_block *sb)
27964 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
27965 +#endif /* CONFIG_AUFS_EXPORT */
27967 +/* ---------------------------------------------------------------------- */
27969 +#ifdef CONFIG_AUFS_SBILIST
27971 +extern struct au_splhead au_sbilist;
27973 +static inline void au_sbilist_init(void)
27975 + au_spl_init(&au_sbilist);
27978 +static inline void au_sbilist_add(struct super_block *sb)
27980 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
27983 +static inline void au_sbilist_del(struct super_block *sb)
27985 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
27988 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
27989 +static inline void au_sbilist_lock(void)
27991 + spin_lock(&au_sbilist.spin);
27994 +static inline void au_sbilist_unlock(void)
27996 + spin_unlock(&au_sbilist.spin);
27998 +#define AuGFP_SBILIST GFP_ATOMIC
28000 +AuStubVoid(au_sbilist_lock, void)
28001 +AuStubVoid(au_sbilist_unlock, void)
28002 +#define AuGFP_SBILIST GFP_NOFS
28003 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28005 +AuStubVoid(au_sbilist_init, void)
28006 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28007 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28008 +AuStubVoid(au_sbilist_lock, void)
28009 +AuStubVoid(au_sbilist_unlock, void)
28010 +#define AuGFP_SBILIST GFP_NOFS
28013 +/* ---------------------------------------------------------------------- */
28015 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28018 + * This function is a dynamic '__init' function actually,
28019 + * so the tiny check for si_rwsem is unnecessary.
28021 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28022 +#ifdef CONFIG_DEBUG_FS
28023 + sbinfo->si_dbgaufs = NULL;
28024 + sbinfo->si_dbgaufs_plink = NULL;
28025 + sbinfo->si_dbgaufs_xib = NULL;
28026 +#ifdef CONFIG_AUFS_EXPORT
28027 + sbinfo->si_dbgaufs_xigen = NULL;
28032 +/* ---------------------------------------------------------------------- */
28034 +static inline pid_t si_pid_bit(void)
28036 + /* the origin of pid is 1, but the bitmap's is 0 */
28037 + return current->pid - 1;
28040 +static inline int si_pid_test(struct super_block *sb)
28044 + bit = si_pid_bit();
28045 + if (bit < PID_MAX_DEFAULT)
28046 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28047 + return si_pid_test_slow(sb);
28050 +static inline void si_pid_set(struct super_block *sb)
28054 + bit = si_pid_bit();
28055 + if (bit < PID_MAX_DEFAULT) {
28056 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
28057 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28060 + si_pid_set_slow(sb);
28063 +static inline void si_pid_clr(struct super_block *sb)
28067 + bit = si_pid_bit();
28068 + if (bit < PID_MAX_DEFAULT) {
28069 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
28070 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28073 + si_pid_clr_slow(sb);
28076 +/* ---------------------------------------------------------------------- */
28078 +/* lock superblock. mainly for entry point functions */
28080 + * __si_read_lock, __si_write_lock,
28081 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28083 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28085 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28086 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28087 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28089 +static inline void si_noflush_read_lock(struct super_block *sb)
28091 + __si_read_lock(sb);
28095 +static inline int si_noflush_read_trylock(struct super_block *sb)
28099 + locked = __si_read_trylock(sb);
28105 +static inline void si_noflush_write_lock(struct super_block *sb)
28107 + __si_write_lock(sb);
28111 +static inline int si_noflush_write_trylock(struct super_block *sb)
28115 + locked = __si_write_trylock(sb);
28121 +#if 0 /* reserved */
28122 +static inline int si_read_trylock(struct super_block *sb, int flags)
28124 + if (au_ftest_lock(flags, FLUSH))
28125 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28126 + return si_noflush_read_trylock(sb);
28130 +static inline void si_read_unlock(struct super_block *sb)
28133 + __si_read_unlock(sb);
28136 +#if 0 /* reserved */
28137 +static inline int si_write_trylock(struct super_block *sb, int flags)
28139 + if (au_ftest_lock(flags, FLUSH))
28140 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28141 + return si_noflush_write_trylock(sb);
28145 +static inline void si_write_unlock(struct super_block *sb)
28148 + __si_write_unlock(sb);
28151 +#if 0 /* reserved */
28152 +static inline void si_downgrade_lock(struct super_block *sb)
28154 + __si_downgrade_lock(sb);
28158 +/* ---------------------------------------------------------------------- */
28160 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
28162 + SiMustAnyLock(sb);
28163 + return au_sbi(sb)->si_bend;
28166 +static inline unsigned int au_mntflags(struct super_block *sb)
28168 + SiMustAnyLock(sb);
28169 + return au_sbi(sb)->si_mntflags;
28172 +static inline unsigned int au_sigen(struct super_block *sb)
28174 + SiMustAnyLock(sb);
28175 + return au_sbi(sb)->si_generation;
28178 +static inline void au_ninodes_inc(struct super_block *sb)
28180 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
28183 +static inline void au_ninodes_dec(struct super_block *sb)
28185 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
28186 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
28189 +static inline void au_nfiles_inc(struct super_block *sb)
28191 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
28194 +static inline void au_nfiles_dec(struct super_block *sb)
28196 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
28197 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
28200 +static inline struct au_branch *au_sbr(struct super_block *sb,
28201 + aufs_bindex_t bindex)
28203 + SiMustAnyLock(sb);
28204 + return au_sbi(sb)->si_branch[0 + bindex];
28207 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28209 + SiMustWriteLock(sb);
28210 + au_sbi(sb)->si_xino_brid = brid;
28213 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28215 + SiMustAnyLock(sb);
28216 + return au_sbi(sb)->si_xino_brid;
28219 +#endif /* __KERNEL__ */
28220 +#endif /* __AUFS_SUPER_H__ */
28221 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28222 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28223 +++ linux/fs/aufs/sysaufs.c 2015-06-28 17:35:44.351383872 +0200
28226 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28228 + * This program, aufs is free software; you can redistribute it and/or modify
28229 + * it under the terms of the GNU General Public License as published by
28230 + * the Free Software Foundation; either version 2 of the License, or
28231 + * (at your option) any later version.
28233 + * This program is distributed in the hope that it will be useful,
28234 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28235 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28236 + * GNU General Public License for more details.
28238 + * You should have received a copy of the GNU General Public License
28239 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28243 + * sysfs interface and lifetime management
28244 + * they are necessary regardless sysfs is disabled.
28247 +#include <linux/random.h>
28250 +unsigned long sysaufs_si_mask;
28251 +struct kset *sysaufs_kset;
28253 +#define AuSiAttr(_name) { \
28254 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28255 + .show = sysaufs_si_##_name, \
28258 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28259 +struct attribute *sysaufs_si_attrs[] = {
28260 + &sysaufs_si_attr_xi_path.attr,
28264 +static const struct sysfs_ops au_sbi_ops = {
28265 + .show = sysaufs_si_show
28268 +static struct kobj_type au_sbi_ktype = {
28269 + .release = au_si_free,
28270 + .sysfs_ops = &au_sbi_ops,
28271 + .default_attrs = sysaufs_si_attrs
28274 +/* ---------------------------------------------------------------------- */
28276 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28280 + sbinfo->si_kobj.kset = sysaufs_kset;
28281 + /* cf. sysaufs_name() */
28282 + err = kobject_init_and_add
28283 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28284 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28286 + dbgaufs_si_null(sbinfo);
28288 + err = dbgaufs_si_init(sbinfo);
28289 + if (unlikely(err))
28290 + kobject_put(&sbinfo->si_kobj);
28295 +void sysaufs_fin(void)
28298 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28299 + kset_unregister(sysaufs_kset);
28302 +int __init sysaufs_init(void)
28307 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
28308 + } while (!sysaufs_si_mask);
28311 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
28312 + if (unlikely(!sysaufs_kset))
28314 + err = PTR_ERR(sysaufs_kset);
28315 + if (IS_ERR(sysaufs_kset))
28317 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28318 + if (unlikely(err)) {
28319 + kset_unregister(sysaufs_kset);
28323 + err = dbgaufs_init();
28324 + if (unlikely(err))
28329 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
28330 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
28331 +++ linux/fs/aufs/sysaufs.h 2015-06-28 17:35:44.351383872 +0200
28334 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28336 + * This program, aufs is free software; you can redistribute it and/or modify
28337 + * it under the terms of the GNU General Public License as published by
28338 + * the Free Software Foundation; either version 2 of the License, or
28339 + * (at your option) any later version.
28341 + * This program is distributed in the hope that it will be useful,
28342 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28343 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28344 + * GNU General Public License for more details.
28346 + * You should have received a copy of the GNU General Public License
28347 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28351 + * sysfs interface and mount lifetime management
28354 +#ifndef __SYSAUFS_H__
28355 +#define __SYSAUFS_H__
28359 +#include <linux/sysfs.h>
28360 +#include "module.h"
28362 +struct super_block;
28365 +struct sysaufs_si_attr {
28366 + struct attribute attr;
28367 + int (*show)(struct seq_file *seq, struct super_block *sb);
28370 +/* ---------------------------------------------------------------------- */
28373 +extern unsigned long sysaufs_si_mask;
28374 +extern struct kset *sysaufs_kset;
28375 +extern struct attribute *sysaufs_si_attrs[];
28376 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
28377 +int __init sysaufs_init(void);
28378 +void sysaufs_fin(void);
28380 +/* ---------------------------------------------------------------------- */
28382 +/* some people doesn't like to show a pointer in kernel */
28383 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
28385 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
28388 +#define SysaufsSiNamePrefix "si_"
28389 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
28390 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
28392 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
28393 + sysaufs_si_id(sbinfo));
28397 +#ifdef CONFIG_SYSFS
28399 +extern struct attribute_group *sysaufs_attr_group;
28401 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
28402 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28404 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
28405 +#ifdef CONFIG_COMPAT
28406 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
28409 +void sysaufs_br_init(struct au_branch *br);
28410 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
28411 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
28413 +#define sysaufs_brs_init() do {} while (0)
28416 +#define sysaufs_attr_group NULL
28418 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
28419 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
28420 + struct attribute *attr, char *buf)
28421 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
28422 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
28423 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
28425 +static inline void sysaufs_brs_init(void)
28430 +#endif /* CONFIG_SYSFS */
28432 +#endif /* __KERNEL__ */
28433 +#endif /* __SYSAUFS_H__ */
28434 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
28435 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
28436 +++ linux/fs/aufs/sysfs.c 2015-06-28 17:35:44.351383872 +0200
28439 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28441 + * This program, aufs is free software; you can redistribute it and/or modify
28442 + * it under the terms of the GNU General Public License as published by
28443 + * the Free Software Foundation; either version 2 of the License, or
28444 + * (at your option) any later version.
28446 + * This program is distributed in the hope that it will be useful,
28447 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28448 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28449 + * GNU General Public License for more details.
28451 + * You should have received a copy of the GNU General Public License
28452 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28456 + * sysfs interface
28459 +#include <linux/compat.h>
28460 +#include <linux/seq_file.h>
28463 +#ifdef CONFIG_AUFS_FS_MODULE
28464 +/* this entry violates the "one line per file" policy of sysfs */
28465 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
28469 + static char *conf =
28470 +/* this file is generated at compiling */
28471 +#include "conf.str"
28474 + err = snprintf(buf, PAGE_SIZE, conf);
28475 + if (unlikely(err >= PAGE_SIZE))
28480 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
28483 +static struct attribute *au_attr[] = {
28484 +#ifdef CONFIG_AUFS_FS_MODULE
28485 + &au_config_attr.attr,
28487 + NULL, /* need to NULL terminate the list of attributes */
28490 +static struct attribute_group sysaufs_attr_group_body = {
28494 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
28496 +/* ---------------------------------------------------------------------- */
28498 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
28502 + SiMustAnyLock(sb);
28505 + if (au_opt_test(au_mntflags(sb), XINO)) {
28506 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
28507 + seq_putc(seq, '\n');
28513 + * the lifetime of branch is independent from the entry under sysfs.
28514 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
28517 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
28518 + aufs_bindex_t bindex, int idx)
28521 + struct path path;
28522 + struct dentry *root;
28523 + struct au_branch *br;
28524 + au_br_perm_str_t perm;
28526 + AuDbg("b%d\n", bindex);
28529 + root = sb->s_root;
28530 + di_read_lock_parent(root, !AuLock_IR);
28531 + br = au_sbr(sb, bindex);
28534 + case AuBrSysfs_BR:
28535 + path.mnt = au_br_mnt(br);
28536 + path.dentry = au_h_dptr(root, bindex);
28537 + au_seq_path(seq, &path);
28538 + au_optstr_br_perm(&perm, br->br_perm);
28539 + err = seq_printf(seq, "=%s\n", perm.a);
28541 + case AuBrSysfs_BRID:
28542 + err = seq_printf(seq, "%d\n", br->br_id);
28545 + di_read_unlock(root, !AuLock_IR);
28552 +/* ---------------------------------------------------------------------- */
28554 +static struct seq_file *au_seq(char *p, ssize_t len)
28556 + struct seq_file *seq;
28558 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
28560 + /* mutex_init(&seq.lock); */
28563 + return seq; /* success */
28566 + seq = ERR_PTR(-ENOMEM);
28570 +#define SysaufsBr_PREFIX "br"
28571 +#define SysaufsBrid_PREFIX "brid"
28573 +/* todo: file size may exceed PAGE_SIZE */
28574 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28580 + aufs_bindex_t bend;
28581 + struct au_sbinfo *sbinfo;
28582 + struct super_block *sb;
28583 + struct seq_file *seq;
28585 + struct attribute **cattr;
28587 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28588 + sb = sbinfo->si_sb;
28591 + * prevent a race condition between sysfs and aufs.
28592 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
28593 + * prohibits maintaining the sysfs entries.
28594 + * hew we acquire read lock after sysfs_get_active_two().
28595 + * on the other hand, the remount process may maintain the sysfs/aufs
28596 + * entries after acquiring write lock.
28597 + * it can cause a deadlock.
28598 + * simply we gave up processing read here.
28601 + if (unlikely(!si_noflush_read_trylock(sb)))
28604 + seq = au_seq(buf, PAGE_SIZE);
28605 + err = PTR_ERR(seq);
28609 + name = (void *)attr->name;
28610 + cattr = sysaufs_si_attrs;
28612 + if (!strcmp(name, (*cattr)->name)) {
28613 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
28620 + if (!strncmp(name, SysaufsBrid_PREFIX,
28621 + sizeof(SysaufsBrid_PREFIX) - 1)) {
28622 + idx = AuBrSysfs_BRID;
28623 + name += sizeof(SysaufsBrid_PREFIX) - 1;
28624 + } else if (!strncmp(name, SysaufsBr_PREFIX,
28625 + sizeof(SysaufsBr_PREFIX) - 1)) {
28626 + idx = AuBrSysfs_BR;
28627 + name += sizeof(SysaufsBr_PREFIX) - 1;
28631 + err = kstrtol(name, 10, &l);
28633 + bend = au_sbend(sb);
28635 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
28642 + err = seq->count;
28643 + /* sysfs limit */
28644 + if (unlikely(err == PAGE_SIZE))
28649 + si_read_unlock(sb);
28654 +/* ---------------------------------------------------------------------- */
28656 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
28660 + aufs_bindex_t bindex, bend;
28663 + struct seq_file *seq;
28664 + struct au_branch *br;
28666 + si_read_lock(sb, AuLock_FLUSH);
28667 + bend = au_sbend(sb);
28673 + buf = (void *)__get_free_page(GFP_NOFS);
28674 + if (unlikely(!buf))
28677 + seq = au_seq(buf, PAGE_SIZE);
28678 + err = PTR_ERR(seq);
28682 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
28683 + for (bindex = 0; bindex <= bend; bindex++, arg++) {
28684 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
28685 + if (unlikely(err))
28688 + br = au_sbr(sb, bindex);
28689 + brid = br->br_id;
28690 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
28691 + err = __put_user(brid, &arg->id);
28692 + if (unlikely(err))
28695 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
28696 + err = __put_user(br->br_perm, &arg->perm);
28697 + if (unlikely(err))
28700 + au_seq_path(seq, &br->br_path);
28701 + err = seq_putc(seq, '\0');
28702 + if (!err && seq->count <= sz) {
28703 + err = copy_to_user(arg->path, seq->buf, seq->count);
28705 + if (unlikely(err))
28712 + if (unlikely(err))
28718 + free_page((unsigned long)buf);
28720 + si_read_unlock(sb);
28724 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
28726 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
28729 +#ifdef CONFIG_COMPAT
28730 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
28732 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
28736 +/* ---------------------------------------------------------------------- */
28738 +void sysaufs_br_init(struct au_branch *br)
28741 + struct au_brsysfs *br_sysfs;
28742 + struct attribute *attr;
28744 + br_sysfs = br->br_sysfs;
28745 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28746 + attr = &br_sysfs->attr;
28747 + sysfs_attr_init(attr);
28748 + attr->name = br_sysfs->name;
28749 + attr->mode = S_IRUGO;
28754 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
28756 + struct au_branch *br;
28757 + struct kobject *kobj;
28758 + struct au_brsysfs *br_sysfs;
28760 + aufs_bindex_t bend;
28762 + dbgaufs_brs_del(sb, bindex);
28764 + if (!sysaufs_brs)
28767 + kobj = &au_sbi(sb)->si_kobj;
28768 + bend = au_sbend(sb);
28769 + for (; bindex <= bend; bindex++) {
28770 + br = au_sbr(sb, bindex);
28771 + br_sysfs = br->br_sysfs;
28772 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28773 + sysfs_remove_file(kobj, &br_sysfs->attr);
28779 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
28782 + aufs_bindex_t bend;
28783 + struct kobject *kobj;
28784 + struct au_branch *br;
28785 + struct au_brsysfs *br_sysfs;
28787 + dbgaufs_brs_add(sb, bindex);
28789 + if (!sysaufs_brs)
28792 + kobj = &au_sbi(sb)->si_kobj;
28793 + bend = au_sbend(sb);
28794 + for (; bindex <= bend; bindex++) {
28795 + br = au_sbr(sb, bindex);
28796 + br_sysfs = br->br_sysfs;
28797 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
28798 + SysaufsBr_PREFIX "%d", bindex);
28799 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
28800 + SysaufsBrid_PREFIX "%d", bindex);
28801 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28802 + err = sysfs_create_file(kobj, &br_sysfs->attr);
28803 + if (unlikely(err))
28804 + pr_warn("failed %s under sysfs(%d)\n",
28805 + br_sysfs->name, err);
28810 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
28811 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
28812 +++ linux/fs/aufs/sysrq.c 2015-06-28 17:36:09.028407078 +0200
28815 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28817 + * This program, aufs is free software; you can redistribute it and/or modify
28818 + * it under the terms of the GNU General Public License as published by
28819 + * the Free Software Foundation; either version 2 of the License, or
28820 + * (at your option) any later version.
28822 + * This program is distributed in the hope that it will be useful,
28823 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28824 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28825 + * GNU General Public License for more details.
28827 + * You should have received a copy of the GNU General Public License
28828 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28832 + * magic sysrq hanlder
28835 +/* #include <linux/sysrq.h> */
28836 +#include <linux/writeback.h>
28839 +/* ---------------------------------------------------------------------- */
28841 +static void sysrq_sb(struct super_block *sb)
28844 + struct au_sbinfo *sbinfo;
28845 + struct file *file;
28846 + struct au_sphlhead *files;
28847 + struct au_finfo *finfo;
28849 + plevel = au_plevel;
28850 + au_plevel = KERN_WARNING;
28852 + /* since we define pr_fmt, call printk directly */
28853 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
28855 + sbinfo = au_sbi(sb);
28856 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
28857 + pr("superblock\n");
28861 + pr("root dentry\n");
28862 + au_dpri_dentry(sb->s_root);
28863 + pr("root inode\n");
28864 + au_dpri_inode(d_inode(sb->s_root));
28869 + int err, i, j, ndentry;
28870 + struct au_dcsub_pages dpages;
28871 + struct au_dpage *dpage;
28873 + err = au_dpages_init(&dpages, GFP_ATOMIC);
28874 + if (unlikely(err))
28876 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
28878 + for (i = 0; i < dpages.ndpage; i++) {
28879 + dpage = dpages.dpages + i;
28880 + ndentry = dpage->ndentry;
28881 + for (j = 0; j < ndentry; j++)
28882 + au_dpri_dentry(dpage->dentries[j]);
28884 + au_dpages_free(&dpages);
28892 + pr("isolated inode\n");
28893 + spin_lock(&inode_sb_list_lock);
28894 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
28895 + spin_lock(&i->i_lock);
28896 + if (1 || hlist_empty(&i->i_dentry))
28897 + au_dpri_inode(i);
28898 + spin_unlock(&i->i_lock);
28900 + spin_unlock(&inode_sb_list_lock);
28904 + files = &au_sbi(sb)->si_files;
28905 + spin_lock(&files->spin);
28906 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
28909 + file = finfo->fi_file;
28910 + mode = file_inode(file)->i_mode;
28911 + if (!special_file(mode))
28912 + au_dpri_file(file);
28914 + spin_unlock(&files->spin);
28918 + au_plevel = plevel;
28921 +/* ---------------------------------------------------------------------- */
28923 +/* module parameter */
28924 +static char *aufs_sysrq_key = "a";
28925 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
28926 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
28928 +static void au_sysrq(int key __maybe_unused)
28930 + struct au_sbinfo *sbinfo;
28933 + au_sbilist_lock();
28934 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
28935 + sysrq_sb(sbinfo->si_sb);
28936 + au_sbilist_unlock();
28940 +static struct sysrq_key_op au_sysrq_op = {
28941 + .handler = au_sysrq,
28942 + .help_msg = "Aufs",
28943 + .action_msg = "Aufs",
28944 + .enable_mask = SYSRQ_ENABLE_DUMP
28947 +/* ---------------------------------------------------------------------- */
28949 +int __init au_sysrq_init(void)
28955 + key = *aufs_sysrq_key;
28956 + if ('a' <= key && key <= 'z')
28957 + err = register_sysrq_key(key, &au_sysrq_op);
28958 + if (unlikely(err))
28959 + pr_err("err %d, sysrq=%c\n", err, key);
28963 +void au_sysrq_fin(void)
28967 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
28968 + if (unlikely(err))
28969 + pr_err("err %d (ignored)\n", err);
28971 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
28972 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
28973 +++ linux/fs/aufs/vdir.c 2015-06-28 17:35:44.351383872 +0200
28976 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28978 + * This program, aufs is free software; you can redistribute it and/or modify
28979 + * it under the terms of the GNU General Public License as published by
28980 + * the Free Software Foundation; either version 2 of the License, or
28981 + * (at your option) any later version.
28983 + * This program is distributed in the hope that it will be useful,
28984 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28985 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28986 + * GNU General Public License for more details.
28988 + * You should have received a copy of the GNU General Public License
28989 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28993 + * virtual or vertical directory
28998 +static unsigned int calc_size(int nlen)
29000 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29003 +static int set_deblk_end(union au_vdir_deblk_p *p,
29004 + union au_vdir_deblk_p *deblk_end)
29006 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29007 + p->de->de_str.len = 0;
29011 + return -1; /* error */
29014 +/* returns true or false */
29015 +static int is_deblk_end(union au_vdir_deblk_p *p,
29016 + union au_vdir_deblk_p *deblk_end)
29018 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29019 + return !p->de->de_str.len;
29023 +static unsigned char *last_deblk(struct au_vdir *vdir)
29025 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29028 +/* ---------------------------------------------------------------------- */
29030 +/* estimate the apropriate size for name hash table */
29031 +unsigned int au_rdhash_est(loff_t sz)
29039 + if (sz < AUFS_RDHASH_DEF)
29040 + n = AUFS_RDHASH_DEF;
29041 + /* pr_info("n %u\n", n); */
29046 + * the allocated memory has to be freed by
29047 + * au_nhash_wh_free() or au_nhash_de_free().
29049 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29051 + struct hlist_head *head;
29055 + sz = sizeof(*nhash->nh_head) * num_hash;
29056 + head = kmalloc(sz, gfp);
29058 + nhash->nh_num = num_hash;
29059 + nhash->nh_head = head;
29060 + for (u = 0; u < num_hash; u++)
29061 + INIT_HLIST_HEAD(head++);
29062 + return 0; /* success */
29068 +static void nhash_count(struct hlist_head *head)
29072 + struct hlist_node *pos;
29075 + hlist_for_each(pos, head)
29077 + pr_info("%lu\n", n);
29081 +static void au_nhash_wh_do_free(struct hlist_head *head)
29083 + struct au_vdir_wh *pos;
29084 + struct hlist_node *node;
29086 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29090 +static void au_nhash_de_do_free(struct hlist_head *head)
29092 + struct au_vdir_dehstr *pos;
29093 + struct hlist_node *node;
29095 + hlist_for_each_entry_safe(pos, node, head, hash)
29096 + au_cache_free_vdir_dehstr(pos);
29099 +static void au_nhash_do_free(struct au_nhash *nhash,
29100 + void (*free)(struct hlist_head *head))
29103 + struct hlist_head *head;
29105 + n = nhash->nh_num;
29109 + head = nhash->nh_head;
29110 + while (n-- > 0) {
29111 + nhash_count(head);
29114 + kfree(nhash->nh_head);
29117 +void au_nhash_wh_free(struct au_nhash *whlist)
29119 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29122 +static void au_nhash_de_free(struct au_nhash *delist)
29124 + au_nhash_do_free(delist, au_nhash_de_do_free);
29127 +/* ---------------------------------------------------------------------- */
29129 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29133 + unsigned int u, n;
29134 + struct hlist_head *head;
29135 + struct au_vdir_wh *pos;
29138 + n = whlist->nh_num;
29139 + head = whlist->nh_head;
29140 + for (u = 0; u < n; u++, head++)
29141 + hlist_for_each_entry(pos, head, wh_hash)
29142 + if (pos->wh_bindex == btgt && ++num > limit)
29147 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29148 + unsigned char *name,
29149 + unsigned int len)
29152 + /* const unsigned int magic_bit = 12; */
29154 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29159 + /* v = hash_long(v, magic_bit); */
29160 + v %= nhash->nh_num;
29161 + return nhash->nh_head + v;
29164 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29167 + return str->len == nlen && !memcmp(str->name, name, nlen);
29170 +/* returns found or not */
29171 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29173 + struct hlist_head *head;
29174 + struct au_vdir_wh *pos;
29175 + struct au_vdir_destr *str;
29177 + head = au_name_hash(whlist, name, nlen);
29178 + hlist_for_each_entry(pos, head, wh_hash) {
29179 + str = &pos->wh_str;
29180 + AuDbg("%.*s\n", str->len, str->name);
29181 + if (au_nhash_test_name(str, name, nlen))
29187 +/* returns found(true) or not */
29188 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29190 + struct hlist_head *head;
29191 + struct au_vdir_dehstr *pos;
29192 + struct au_vdir_destr *str;
29194 + head = au_name_hash(delist, name, nlen);
29195 + hlist_for_each_entry(pos, head, hash) {
29197 + AuDbg("%.*s\n", str->len, str->name);
29198 + if (au_nhash_test_name(str, name, nlen))
29204 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29205 + unsigned char d_type)
29207 +#ifdef CONFIG_AUFS_SHWH
29208 + wh->wh_ino = ino;
29209 + wh->wh_type = d_type;
29213 +/* ---------------------------------------------------------------------- */
29215 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29216 + unsigned int d_type, aufs_bindex_t bindex,
29217 + unsigned char shwh)
29220 + struct au_vdir_destr *str;
29221 + struct au_vdir_wh *wh;
29223 + AuDbg("%.*s\n", nlen, name);
29224 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29227 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29228 + if (unlikely(!wh))
29232 + wh->wh_bindex = bindex;
29234 + au_shwh_init_wh(wh, ino, d_type);
29235 + str = &wh->wh_str;
29237 + memcpy(str->name, name, nlen);
29238 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29245 +static int append_deblk(struct au_vdir *vdir)
29248 + unsigned long ul;
29249 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29250 + union au_vdir_deblk_p p, deblk_end;
29251 + unsigned char **o;
29254 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29256 + if (unlikely(!o))
29259 + vdir->vd_deblk = o;
29260 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29262 + ul = vdir->vd_nblk++;
29263 + vdir->vd_deblk[ul] = p.deblk;
29264 + vdir->vd_last.ul = ul;
29265 + vdir->vd_last.p.deblk = p.deblk;
29266 + deblk_end.deblk = p.deblk + deblk_sz;
29267 + err = set_deblk_end(&p, &deblk_end);
29274 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29275 + unsigned int d_type, struct au_nhash *delist)
29279 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29280 + union au_vdir_deblk_p p, *room, deblk_end;
29281 + struct au_vdir_dehstr *dehstr;
29283 + p.deblk = last_deblk(vdir);
29284 + deblk_end.deblk = p.deblk + deblk_sz;
29285 + room = &vdir->vd_last.p;
29286 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29287 + || !is_deblk_end(room, &deblk_end));
29289 + sz = calc_size(nlen);
29290 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29291 + err = append_deblk(vdir);
29292 + if (unlikely(err))
29295 + p.deblk = last_deblk(vdir);
29296 + deblk_end.deblk = p.deblk + deblk_sz;
29298 + AuDebugOn(room->deblk != p.deblk);
29302 + dehstr = au_cache_alloc_vdir_dehstr();
29303 + if (unlikely(!dehstr))
29306 + dehstr->str = &room->de->de_str;
29307 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
29308 + room->de->de_ino = ino;
29309 + room->de->de_type = d_type;
29310 + room->de->de_str.len = nlen;
29311 + memcpy(room->de->de_str.name, name, nlen);
29314 + room->deblk += sz;
29315 + if (unlikely(set_deblk_end(room, &deblk_end)))
29316 + err = append_deblk(vdir);
29323 +/* ---------------------------------------------------------------------- */
29325 +void au_vdir_free(struct au_vdir *vdir)
29327 + unsigned char **deblk;
29329 + deblk = vdir->vd_deblk;
29330 + while (vdir->vd_nblk--)
29332 + kfree(vdir->vd_deblk);
29333 + au_cache_free_vdir(vdir);
29336 +static struct au_vdir *alloc_vdir(struct file *file)
29338 + struct au_vdir *vdir;
29339 + struct super_block *sb;
29342 + sb = file->f_path.dentry->d_sb;
29343 + SiMustAnyLock(sb);
29346 + vdir = au_cache_alloc_vdir();
29347 + if (unlikely(!vdir))
29350 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
29351 + if (unlikely(!vdir->vd_deblk))
29354 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
29355 + if (!vdir->vd_deblk_sz) {
29356 + /* estimate the apropriate size for deblk */
29357 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
29358 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
29360 + vdir->vd_nblk = 0;
29361 + vdir->vd_version = 0;
29362 + vdir->vd_jiffy = 0;
29363 + err = append_deblk(vdir);
29365 + return vdir; /* success */
29367 + kfree(vdir->vd_deblk);
29370 + au_cache_free_vdir(vdir);
29372 + vdir = ERR_PTR(err);
29376 +static int reinit_vdir(struct au_vdir *vdir)
29379 + union au_vdir_deblk_p p, deblk_end;
29381 + while (vdir->vd_nblk > 1) {
29382 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
29383 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
29386 + p.deblk = vdir->vd_deblk[0];
29387 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
29388 + err = set_deblk_end(&p, &deblk_end);
29389 + /* keep vd_dblk_sz */
29390 + vdir->vd_last.ul = 0;
29391 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29392 + vdir->vd_version = 0;
29393 + vdir->vd_jiffy = 0;
29398 +/* ---------------------------------------------------------------------- */
29400 +#define AuFillVdir_CALLED 1
29401 +#define AuFillVdir_WHABLE (1 << 1)
29402 +#define AuFillVdir_SHWH (1 << 2)
29403 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
29404 +#define au_fset_fillvdir(flags, name) \
29405 + do { (flags) |= AuFillVdir_##name; } while (0)
29406 +#define au_fclr_fillvdir(flags, name) \
29407 + do { (flags) &= ~AuFillVdir_##name; } while (0)
29409 +#ifndef CONFIG_AUFS_SHWH
29410 +#undef AuFillVdir_SHWH
29411 +#define AuFillVdir_SHWH 0
29414 +struct fillvdir_arg {
29415 + struct dir_context ctx;
29416 + struct file *file;
29417 + struct au_vdir *vdir;
29418 + struct au_nhash delist;
29419 + struct au_nhash whlist;
29420 + aufs_bindex_t bindex;
29421 + unsigned int flags;
29425 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
29426 + loff_t offset __maybe_unused, u64 h_ino,
29427 + unsigned int d_type)
29429 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
29430 + char *name = (void *)__name;
29431 + struct super_block *sb;
29433 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
29436 + sb = arg->file->f_path.dentry->d_sb;
29437 + au_fset_fillvdir(arg->flags, CALLED);
29439 + if (nlen <= AUFS_WH_PFX_LEN
29440 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
29441 + if (test_known(&arg->delist, name, nlen)
29442 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
29443 + goto out; /* already exists or whiteouted */
29445 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
29447 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29448 + d_type = DT_UNKNOWN;
29449 + arg->err = append_de(arg->vdir, name, nlen, ino,
29450 + d_type, &arg->delist);
29452 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
29453 + name += AUFS_WH_PFX_LEN;
29454 + nlen -= AUFS_WH_PFX_LEN;
29455 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
29456 + goto out; /* already whiteouted */
29459 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
29462 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
29463 + d_type = DT_UNKNOWN;
29464 + arg->err = au_nhash_append_wh
29465 + (&arg->whlist, name, nlen, ino, d_type,
29466 + arg->bindex, shwh);
29472 + arg->vdir->vd_jiffy = jiffies;
29474 + AuTraceErr(arg->err);
29478 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
29479 + struct au_nhash *whlist, struct au_nhash *delist)
29481 +#ifdef CONFIG_AUFS_SHWH
29483 + unsigned int nh, u;
29484 + struct hlist_head *head;
29485 + struct au_vdir_wh *pos;
29486 + struct hlist_node *n;
29488 + struct au_vdir_destr *destr;
29490 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
29493 + o = p = (void *)__get_free_page(GFP_NOFS);
29494 + if (unlikely(!p))
29498 + nh = whlist->nh_num;
29499 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29500 + p += AUFS_WH_PFX_LEN;
29501 + for (u = 0; u < nh; u++) {
29502 + head = whlist->nh_head + u;
29503 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
29504 + destr = &pos->wh_str;
29505 + memcpy(p, destr->name, destr->len);
29506 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
29507 + pos->wh_ino, pos->wh_type, delist);
29508 + if (unlikely(err))
29513 + free_page((unsigned long)o);
29523 +static int au_do_read_vdir(struct fillvdir_arg *arg)
29526 + unsigned int rdhash;
29528 + aufs_bindex_t bend, bindex, bstart;
29529 + unsigned char shwh;
29530 + struct file *hf, *file;
29531 + struct super_block *sb;
29533 + file = arg->file;
29534 + sb = file->f_path.dentry->d_sb;
29535 + SiMustAnyLock(sb);
29537 + rdhash = au_sbi(sb)->si_rdhash;
29539 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
29540 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
29541 + if (unlikely(err))
29543 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
29544 + if (unlikely(err))
29550 + if (au_opt_test(au_mntflags(sb), SHWH)) {
29552 + au_fset_fillvdir(arg->flags, SHWH);
29554 + bstart = au_fbstart(file);
29555 + bend = au_fbend_dir(file);
29556 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
29557 + hf = au_hf_dir(file, bindex);
29561 + offset = vfsub_llseek(hf, 0, SEEK_SET);
29563 + if (unlikely(offset))
29566 + arg->bindex = bindex;
29567 + au_fclr_fillvdir(arg->flags, WHABLE);
29569 + || (bindex != bend
29570 + && au_br_whable(au_sbr_perm(sb, bindex))))
29571 + au_fset_fillvdir(arg->flags, WHABLE);
29574 + au_fclr_fillvdir(arg->flags, CALLED);
29576 + err = vfsub_iterate_dir(hf, &arg->ctx);
29579 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
29582 + * dir_relax() may be good for concurrency, but aufs should not
29583 + * use it since it will cause a lockdep problem.
29587 + if (!err && shwh)
29588 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
29590 + au_nhash_wh_free(&arg->whlist);
29593 + au_nhash_de_free(&arg->delist);
29598 +static int read_vdir(struct file *file, int may_read)
29601 + unsigned long expire;
29602 + unsigned char do_read;
29603 + struct fillvdir_arg arg = {
29605 + .actor = fillvdir
29608 + struct inode *inode;
29609 + struct au_vdir *vdir, *allocated;
29612 + inode = file_inode(file);
29613 + IMustLock(inode);
29614 + SiMustAnyLock(inode->i_sb);
29616 + allocated = NULL;
29618 + expire = au_sbi(inode->i_sb)->si_rdcache;
29619 + vdir = au_ivdir(inode);
29622 + vdir = alloc_vdir(file);
29623 + err = PTR_ERR(vdir);
29624 + if (IS_ERR(vdir))
29627 + allocated = vdir;
29628 + } else if (may_read
29629 + && (inode->i_version != vdir->vd_version
29630 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
29632 + err = reinit_vdir(vdir);
29633 + if (unlikely(err))
29638 + return 0; /* success */
29642 + err = au_do_read_vdir(&arg);
29644 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
29645 + vdir->vd_version = inode->i_version;
29646 + vdir->vd_last.ul = 0;
29647 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29649 + au_set_ivdir(inode, allocated);
29650 + } else if (allocated)
29651 + au_vdir_free(allocated);
29657 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
29660 + unsigned long ul, n;
29661 + const unsigned int deblk_sz = src->vd_deblk_sz;
29663 + AuDebugOn(tgt->vd_nblk != 1);
29666 + if (tgt->vd_nblk < src->vd_nblk) {
29667 + unsigned char **p;
29669 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
29671 + if (unlikely(!p))
29673 + tgt->vd_deblk = p;
29676 + if (tgt->vd_deblk_sz != deblk_sz) {
29677 + unsigned char *p;
29679 + tgt->vd_deblk_sz = deblk_sz;
29680 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
29681 + if (unlikely(!p))
29683 + tgt->vd_deblk[0] = p;
29685 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
29686 + tgt->vd_version = src->vd_version;
29687 + tgt->vd_jiffy = src->vd_jiffy;
29689 + n = src->vd_nblk;
29690 + for (ul = 1; ul < n; ul++) {
29691 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
29693 + if (unlikely(!tgt->vd_deblk[ul]))
29697 + tgt->vd_nblk = n;
29698 + tgt->vd_last.ul = tgt->vd_last.ul;
29699 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
29700 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
29701 + - src->vd_deblk[src->vd_last.ul];
29703 + return 0; /* success */
29706 + rerr = reinit_vdir(tgt);
29711 +int au_vdir_init(struct file *file)
29714 + struct inode *inode;
29715 + struct au_vdir *vdir_cache, *allocated;
29717 + /* test file->f_pos here instead of ctx->pos */
29718 + err = read_vdir(file, !file->f_pos);
29719 + if (unlikely(err))
29722 + allocated = NULL;
29723 + vdir_cache = au_fvdir_cache(file);
29724 + if (!vdir_cache) {
29725 + vdir_cache = alloc_vdir(file);
29726 + err = PTR_ERR(vdir_cache);
29727 + if (IS_ERR(vdir_cache))
29729 + allocated = vdir_cache;
29730 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
29731 + /* test file->f_pos here instead of ctx->pos */
29732 + err = reinit_vdir(vdir_cache);
29733 + if (unlikely(err))
29736 + return 0; /* success */
29738 + inode = file_inode(file);
29739 + err = copy_vdir(vdir_cache, au_ivdir(inode));
29741 + file->f_version = inode->i_version;
29743 + au_set_fvdir_cache(file, allocated);
29744 + } else if (allocated)
29745 + au_vdir_free(allocated);
29751 +static loff_t calc_offset(struct au_vdir *vdir)
29754 + union au_vdir_deblk_p p;
29756 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
29757 + offset = vdir->vd_last.p.deblk - p.deblk;
29758 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
29762 +/* returns true or false */
29763 +static int seek_vdir(struct file *file, struct dir_context *ctx)
29766 + unsigned int deblk_sz;
29767 + unsigned long ul, n;
29769 + union au_vdir_deblk_p p, deblk_end;
29770 + struct au_vdir *vdir_cache;
29773 + vdir_cache = au_fvdir_cache(file);
29774 + offset = calc_offset(vdir_cache);
29775 + AuDbg("offset %lld\n", offset);
29776 + if (ctx->pos == offset)
29779 + vdir_cache->vd_last.ul = 0;
29780 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
29785 + deblk_sz = vdir_cache->vd_deblk_sz;
29786 + ul = div64_u64(ctx->pos, deblk_sz);
29787 + AuDbg("ul %lu\n", ul);
29788 + if (ul >= vdir_cache->vd_nblk)
29791 + n = vdir_cache->vd_nblk;
29792 + for (; ul < n; ul++) {
29793 + p.deblk = vdir_cache->vd_deblk[ul];
29794 + deblk_end.deblk = p.deblk + deblk_sz;
29796 + offset *= deblk_sz;
29797 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
29800 + l = calc_size(p.de->de_str.len);
29804 + if (!is_deblk_end(&p, &deblk_end)) {
29806 + vdir_cache->vd_last.ul = ul;
29807 + vdir_cache->vd_last.p = p;
29814 + AuTraceErr(!valid);
29818 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
29820 + unsigned int l, deblk_sz;
29821 + union au_vdir_deblk_p deblk_end;
29822 + struct au_vdir *vdir_cache;
29823 + struct au_vdir_de *de;
29825 + vdir_cache = au_fvdir_cache(file);
29826 + if (!seek_vdir(file, ctx))
29829 + deblk_sz = vdir_cache->vd_deblk_sz;
29831 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29832 + deblk_end.deblk += deblk_sz;
29833 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
29834 + de = vdir_cache->vd_last.p.de;
29835 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
29836 + de->de_str.len, de->de_str.name, ctx->pos,
29837 + (unsigned long)de->de_ino, de->de_type);
29838 + if (unlikely(!dir_emit(ctx, de->de_str.name,
29839 + de->de_str.len, de->de_ino,
29841 + /* todo: ignore the error caused by udba? */
29842 + /* return err; */
29846 + l = calc_size(de->de_str.len);
29847 + vdir_cache->vd_last.p.deblk += l;
29850 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
29851 + vdir_cache->vd_last.ul++;
29852 + vdir_cache->vd_last.p.deblk
29853 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29854 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
29863 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
29864 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
29865 +++ linux/fs/aufs/vfsub.c 2015-06-28 17:36:09.028407078 +0200
29868 + * Copyright (C) 2005-2015 Junjiro R. Okajima
29870 + * This program, aufs is free software; you can redistribute it and/or modify
29871 + * it under the terms of the GNU General Public License as published by
29872 + * the Free Software Foundation; either version 2 of the License, or
29873 + * (at your option) any later version.
29875 + * This program is distributed in the hope that it will be useful,
29876 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29877 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29878 + * GNU General Public License for more details.
29880 + * You should have received a copy of the GNU General Public License
29881 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29885 + * sub-routines for VFS
29888 +#include <linux/namei.h>
29889 +#include <linux/security.h>
29890 +#include <linux/splice.h>
29893 +int vfsub_update_h_iattr(struct path *h_path, int *did)
29897 + struct super_block *h_sb;
29899 + /* for remote fs, leave work for its getattr or d_revalidate */
29900 + /* for bad i_attr fs, handle them in aufs_getattr() */
29901 + /* still some fs may acquire i_mutex. we need to skip them */
29905 + h_sb = h_path->dentry->d_sb;
29906 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
29908 + err = vfs_getattr(h_path, &st);
29913 +/* ---------------------------------------------------------------------- */
29915 +struct file *vfsub_dentry_open(struct path *path, int flags)
29917 + struct file *file;
29919 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
29921 + if (!IS_ERR_OR_NULL(file)
29922 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
29923 + i_readcount_inc(d_inode(path->dentry));
29928 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
29930 + struct file *file;
29933 + file = filp_open(path,
29934 + oflags /* | __FMODE_NONOTIFY */,
29937 + if (IS_ERR(file))
29939 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29946 + * Ideally this function should call VFS:do_last() in order to keep all its
29947 + * checkings. But it is very hard for aufs to regenerate several VFS internal
29948 + * structure such as nameidata. This is a second (or third) best approach.
29949 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
29951 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
29952 + struct vfsub_aopen_args *args, struct au_branch *br)
29955 + struct file *file = args->file;
29956 + /* copied from linux/fs/namei.c:atomic_open() */
29957 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
29960 + AuDebugOn(!dir->i_op->atomic_open);
29962 + err = au_br_test_oflag(args->open_flag, br);
29963 + if (unlikely(err))
29966 + args->file->f_path.dentry = DENTRY_NOT_SET;
29967 + args->file->f_path.mnt = au_br_mnt(br);
29968 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
29969 + args->create_mode, args->opened);
29971 + /* some filesystems don't set FILE_CREATED while succeeded? */
29972 + if (*args->opened & FILE_CREATED)
29973 + fsnotify_create(dir, dentry);
29979 + /* todo: call VFS:may_open() here */
29980 + err = open_check_o_direct(file);
29981 + /* todo: ima_file_check() too? */
29982 + if (!err && (args->open_flag & __FMODE_EXEC))
29983 + err = deny_write_access(file);
29984 + if (unlikely(err))
29985 + /* note that the file is created and still opened */
29989 + atomic_inc(&br->br_count);
29990 + fsnotify_open(file);
29996 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30000 + err = kern_path(name, flags, path);
30001 + if (!err && d_is_positive(path->dentry))
30002 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30006 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30009 + struct path path = {
30013 + /* VFS checks it too, but by WARN_ON_ONCE() */
30014 + IMustLock(d_inode(parent));
30016 + path.dentry = lookup_one_len(name, parent, len);
30017 + if (IS_ERR(path.dentry))
30019 + if (d_is_positive(path.dentry))
30020 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30023 + AuTraceErrPtr(path.dentry);
30024 + return path.dentry;
30027 +void vfsub_call_lkup_one(void *args)
30029 + struct vfsub_lkup_one_args *a = args;
30030 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30033 +/* ---------------------------------------------------------------------- */
30035 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30036 + struct dentry *d2, struct au_hinode *hdir2)
30038 + struct dentry *d;
30041 + d = lock_rename(d1, d2);
30043 + au_hn_suspend(hdir1);
30044 + if (hdir1 != hdir2)
30045 + au_hn_suspend(hdir2);
30050 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30051 + struct dentry *d2, struct au_hinode *hdir2)
30053 + au_hn_resume(hdir1);
30054 + if (hdir1 != hdir2)
30055 + au_hn_resume(hdir2);
30057 + unlock_rename(d1, d2);
30061 +/* ---------------------------------------------------------------------- */
30063 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30066 + struct dentry *d;
30070 + d = path->dentry;
30071 + path->dentry = d->d_parent;
30072 + err = security_path_mknod(path, d, mode, 0);
30073 + path->dentry = d;
30074 + if (unlikely(err))
30078 + err = vfs_create(dir, path->dentry, mode, want_excl);
30081 + struct path tmp = *path;
30084 + vfsub_update_h_iattr(&tmp, &did);
30086 + tmp.dentry = path->dentry->d_parent;
30087 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30096 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30099 + struct dentry *d;
30103 + d = path->dentry;
30104 + path->dentry = d->d_parent;
30105 + err = security_path_symlink(path, d, symname);
30106 + path->dentry = d;
30107 + if (unlikely(err))
30111 + err = vfs_symlink(dir, path->dentry, symname);
30114 + struct path tmp = *path;
30117 + vfsub_update_h_iattr(&tmp, &did);
30119 + tmp.dentry = path->dentry->d_parent;
30120 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30129 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30132 + struct dentry *d;
30136 + d = path->dentry;
30137 + path->dentry = d->d_parent;
30138 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30139 + path->dentry = d;
30140 + if (unlikely(err))
30144 + err = vfs_mknod(dir, path->dentry, mode, dev);
30147 + struct path tmp = *path;
30150 + vfsub_update_h_iattr(&tmp, &did);
30152 + tmp.dentry = path->dentry->d_parent;
30153 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30162 +static int au_test_nlink(struct inode *inode)
30164 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30166 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30167 + || inode->i_nlink < link_max)
30172 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30173 + struct inode **delegated_inode)
30176 + struct dentry *d;
30180 + err = au_test_nlink(d_inode(src_dentry));
30181 + if (unlikely(err))
30184 + /* we don't call may_linkat() */
30185 + d = path->dentry;
30186 + path->dentry = d->d_parent;
30187 + err = security_path_link(src_dentry, path, d);
30188 + path->dentry = d;
30189 + if (unlikely(err))
30193 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30196 + struct path tmp = *path;
30199 + /* fuse has different memory inode for the same inumber */
30200 + vfsub_update_h_iattr(&tmp, &did);
30202 + tmp.dentry = path->dentry->d_parent;
30203 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30204 + tmp.dentry = src_dentry;
30205 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30214 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30215 + struct inode *dir, struct path *path,
30216 + struct inode **delegated_inode)
30219 + struct path tmp = {
30222 + struct dentry *d;
30225 + IMustLock(src_dir);
30227 + d = path->dentry;
30228 + path->dentry = d->d_parent;
30229 + tmp.dentry = src_dentry->d_parent;
30230 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30231 + path->dentry = d;
30232 + if (unlikely(err))
30236 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30237 + delegated_inode, /*flags*/0);
30242 + tmp.dentry = d->d_parent;
30243 + vfsub_update_h_iattr(&tmp, &did);
30245 + tmp.dentry = src_dentry;
30246 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30247 + tmp.dentry = src_dentry->d_parent;
30248 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30257 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
30260 + struct dentry *d;
30264 + d = path->dentry;
30265 + path->dentry = d->d_parent;
30266 + err = security_path_mkdir(path, d, mode);
30267 + path->dentry = d;
30268 + if (unlikely(err))
30272 + err = vfs_mkdir(dir, path->dentry, mode);
30275 + struct path tmp = *path;
30278 + vfsub_update_h_iattr(&tmp, &did);
30280 + tmp.dentry = path->dentry->d_parent;
30281 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30290 +int vfsub_rmdir(struct inode *dir, struct path *path)
30293 + struct dentry *d;
30297 + d = path->dentry;
30298 + path->dentry = d->d_parent;
30299 + err = security_path_rmdir(path, d);
30300 + path->dentry = d;
30301 + if (unlikely(err))
30305 + err = vfs_rmdir(dir, path->dentry);
30308 + struct path tmp = {
30309 + .dentry = path->dentry->d_parent,
30313 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30320 +/* ---------------------------------------------------------------------- */
30322 +/* todo: support mmap_sem? */
30323 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30329 + err = vfs_read(file, ubuf, count, ppos);
30332 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30336 +/* todo: kernel_read()? */
30337 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30341 + mm_segment_t oldfs;
30348 + oldfs = get_fs();
30349 + set_fs(KERNEL_DS);
30350 + err = vfsub_read_u(file, buf.u, count, ppos);
30355 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30361 + err = vfs_write(file, ubuf, count, ppos);
30364 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30368 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
30371 + mm_segment_t oldfs;
30374 + const char __user *u;
30378 + oldfs = get_fs();
30379 + set_fs(KERNEL_DS);
30380 + err = vfsub_write_u(file, buf.u, count, ppos);
30385 +int vfsub_flush(struct file *file, fl_owner_t id)
30390 + if (file->f_op->flush) {
30391 + if (!au_test_nfs(file->f_path.dentry->d_sb))
30392 + err = file->f_op->flush(file, id);
30395 + err = file->f_op->flush(file, id);
30399 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
30405 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
30409 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
30412 + err = iterate_dir(file, ctx);
30415 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30419 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30420 + struct pipe_inode_info *pipe, size_t len,
30421 + unsigned int flags)
30426 + err = do_splice_to(in, ppos, pipe, len, flags);
30428 + file_accessed(in);
30430 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
30434 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30435 + loff_t *ppos, size_t len, unsigned int flags)
30440 + err = do_splice_from(pipe, out, ppos, len, flags);
30443 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
30447 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
30451 + /* file can be NULL */
30453 + err = vfs_fsync(file, datasync);
30457 + AuDebugOn(!file);
30458 + path = &file->f_path;
30460 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30465 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
30466 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30467 + struct file *h_file)
30470 + struct inode *h_inode;
30471 + struct super_block *h_sb;
30474 + err = vfsub_truncate(h_path, length);
30478 + h_inode = d_inode(h_path->dentry);
30479 + h_sb = h_inode->i_sb;
30481 + sb_start_write(h_sb);
30483 + err = locks_verify_truncate(h_inode, h_file, length);
30485 + err = security_path_truncate(h_path);
30488 + err = do_truncate(h_path->dentry, length, attr, h_file);
30492 + sb_end_write(h_sb);
30499 +/* ---------------------------------------------------------------------- */
30501 +struct au_vfsub_mkdir_args {
30503 + struct inode *dir;
30504 + struct path *path;
30508 +static void au_call_vfsub_mkdir(void *args)
30510 + struct au_vfsub_mkdir_args *a = args;
30511 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
30514 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
30516 + int err, do_sio, wkq_err;
30518 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30521 + err = vfsub_mkdir(dir, path, mode);
30524 + struct au_vfsub_mkdir_args args = {
30530 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
30531 + if (unlikely(wkq_err))
30538 +struct au_vfsub_rmdir_args {
30540 + struct inode *dir;
30541 + struct path *path;
30544 +static void au_call_vfsub_rmdir(void *args)
30546 + struct au_vfsub_rmdir_args *a = args;
30547 + *a->errp = vfsub_rmdir(a->dir, a->path);
30550 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
30552 + int err, do_sio, wkq_err;
30554 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30557 + err = vfsub_rmdir(dir, path);
30560 + struct au_vfsub_rmdir_args args = {
30565 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
30566 + if (unlikely(wkq_err))
30573 +/* ---------------------------------------------------------------------- */
30575 +struct notify_change_args {
30577 + struct path *path;
30578 + struct iattr *ia;
30579 + struct inode **delegated_inode;
30582 +static void call_notify_change(void *args)
30584 + struct notify_change_args *a = args;
30585 + struct inode *h_inode;
30587 + h_inode = d_inode(a->path->dentry);
30588 + IMustLock(h_inode);
30590 + *a->errp = -EPERM;
30591 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
30593 + *a->errp = notify_change(a->path->dentry, a->ia,
30594 + a->delegated_inode);
30597 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
30599 + AuTraceErr(*a->errp);
30602 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30603 + struct inode **delegated_inode)
30606 + struct notify_change_args args = {
30610 + .delegated_inode = delegated_inode
30613 + call_notify_change(&args);
30618 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30619 + struct inode **delegated_inode)
30621 + int err, wkq_err;
30622 + struct notify_change_args args = {
30626 + .delegated_inode = delegated_inode
30629 + wkq_err = au_wkq_wait(call_notify_change, &args);
30630 + if (unlikely(wkq_err))
30636 +/* ---------------------------------------------------------------------- */
30638 +struct unlink_args {
30640 + struct inode *dir;
30641 + struct path *path;
30642 + struct inode **delegated_inode;
30645 +static void call_unlink(void *args)
30647 + struct unlink_args *a = args;
30648 + struct dentry *d = a->path->dentry;
30649 + struct inode *h_inode;
30650 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
30651 + && au_dcount(d) == 1);
30653 + IMustLock(a->dir);
30655 + a->path->dentry = d->d_parent;
30656 + *a->errp = security_path_unlink(a->path, d);
30657 + a->path->dentry = d;
30658 + if (unlikely(*a->errp))
30661 + if (!stop_sillyrename)
30664 + if (d_is_positive(d)) {
30665 + h_inode = d_inode(d);
30670 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
30673 + struct path tmp = {
30674 + .dentry = d->d_parent,
30675 + .mnt = a->path->mnt
30677 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30680 + if (!stop_sillyrename)
30685 + AuTraceErr(*a->errp);
30689 + * @dir: must be locked.
30690 + * @dentry: target dentry.
30692 +int vfsub_unlink(struct inode *dir, struct path *path,
30693 + struct inode **delegated_inode, int force)
30696 + struct unlink_args args = {
30700 + .delegated_inode = delegated_inode
30704 + call_unlink(&args);
30708 + wkq_err = au_wkq_wait(call_unlink, &args);
30709 + if (unlikely(wkq_err))
30715 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
30716 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
30717 +++ linux/fs/aufs/vfsub.h 2015-06-28 17:35:44.351383872 +0200
30720 + * Copyright (C) 2005-2015 Junjiro R. Okajima
30722 + * This program, aufs is free software; you can redistribute it and/or modify
30723 + * it under the terms of the GNU General Public License as published by
30724 + * the Free Software Foundation; either version 2 of the License, or
30725 + * (at your option) any later version.
30727 + * This program is distributed in the hope that it will be useful,
30728 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30729 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30730 + * GNU General Public License for more details.
30732 + * You should have received a copy of the GNU General Public License
30733 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30737 + * sub-routines for VFS
30740 +#ifndef __AUFS_VFSUB_H__
30741 +#define __AUFS_VFSUB_H__
30745 +#include <linux/fs.h>
30746 +#include <linux/mount.h>
30747 +#include <linux/xattr.h>
30748 +#include "debug.h"
30750 +/* copied from linux/fs/internal.h */
30751 +/* todo: BAD approach!! */
30752 +extern void __mnt_drop_write(struct vfsmount *);
30753 +extern spinlock_t inode_sb_list_lock;
30754 +extern int open_check_o_direct(struct file *f);
30756 +/* ---------------------------------------------------------------------- */
30758 +/* lock subclass for lower inode */
30759 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
30760 +/* reduce? gave up. */
30762 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
30763 + AuLsc_I_PARENT, /* lower inode, parent first */
30764 + AuLsc_I_PARENT2, /* copyup dirs */
30765 + AuLsc_I_PARENT3, /* copyup wh */
30771 +/* to debug easier, do not make them inlined functions */
30772 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
30773 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
30775 +/* ---------------------------------------------------------------------- */
30777 +static inline void vfsub_drop_nlink(struct inode *inode)
30779 + AuDebugOn(!inode->i_nlink);
30780 + drop_nlink(inode);
30783 +static inline void vfsub_dead_dir(struct inode *inode)
30785 + AuDebugOn(!S_ISDIR(inode->i_mode));
30786 + inode->i_flags |= S_DEAD;
30787 + clear_nlink(inode);
30790 +static inline int vfsub_native_ro(struct inode *inode)
30792 + return (inode->i_sb->s_flags & MS_RDONLY)
30793 + || IS_RDONLY(inode)
30794 + /* || IS_APPEND(inode) */
30795 + || IS_IMMUTABLE(inode);
30798 +/* ---------------------------------------------------------------------- */
30800 +int vfsub_update_h_iattr(struct path *h_path, int *did);
30801 +struct file *vfsub_dentry_open(struct path *path, int flags);
30802 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
30803 +struct vfsub_aopen_args {
30804 + struct file *file;
30805 + unsigned int open_flag;
30806 + umode_t create_mode;
30810 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30811 + struct vfsub_aopen_args *args, struct au_branch *br);
30812 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
30814 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30817 +struct vfsub_lkup_one_args {
30818 + struct dentry **errp;
30819 + struct qstr *name;
30820 + struct dentry *parent;
30823 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
30824 + struct dentry *parent)
30826 + return vfsub_lookup_one_len(name->name, parent, name->len);
30829 +void vfsub_call_lkup_one(void *args);
30831 +/* ---------------------------------------------------------------------- */
30833 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
30838 + err = mnt_want_write(mnt);
30843 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
30846 + mnt_drop_write(mnt);
30850 +#if 0 /* reserved */
30851 +static inline void vfsub_mnt_drop_write_file(struct file *file)
30854 + mnt_drop_write_file(file);
30859 +/* ---------------------------------------------------------------------- */
30862 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30863 + struct dentry *d2, struct au_hinode *hdir2);
30864 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30865 + struct dentry *d2, struct au_hinode *hdir2);
30867 +int vfsub_create(struct inode *dir, struct path *path, int mode,
30869 +int vfsub_symlink(struct inode *dir, struct path *path,
30870 + const char *symname);
30871 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
30872 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
30873 + struct path *path, struct inode **delegated_inode);
30874 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
30875 + struct inode *hdir, struct path *path,
30876 + struct inode **delegated_inode);
30877 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
30878 +int vfsub_rmdir(struct inode *dir, struct path *path);
30880 +/* ---------------------------------------------------------------------- */
30882 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30884 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30886 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30888 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
30890 +int vfsub_flush(struct file *file, fl_owner_t id);
30891 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
30893 +static inline loff_t vfsub_f_size_read(struct file *file)
30895 + return i_size_read(file_inode(file));
30898 +static inline unsigned int vfsub_file_flags(struct file *file)
30900 + unsigned int flags;
30902 + spin_lock(&file->f_lock);
30903 + flags = file->f_flags;
30904 + spin_unlock(&file->f_lock);
30909 +#if 0 /* reserved */
30910 +static inline void vfsub_file_accessed(struct file *h_file)
30912 + file_accessed(h_file);
30913 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
30917 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
30918 + struct dentry *h_dentry)
30920 + struct path h_path = {
30921 + .dentry = h_dentry,
30924 + touch_atime(&h_path);
30925 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
30928 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
30931 + return generic_update_time(h_inode, ts, flags);
30932 + /* no vfsub_update_h_iattr() since we don't have struct path */
30935 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30936 + struct pipe_inode_info *pipe, size_t len,
30937 + unsigned int flags);
30938 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30939 + loff_t *ppos, size_t len, unsigned int flags);
30941 +static inline long vfsub_truncate(struct path *path, loff_t length)
30946 + err = vfs_truncate(path, length);
30951 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30952 + struct file *h_file);
30953 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
30955 +/* ---------------------------------------------------------------------- */
30957 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
30962 + err = vfs_llseek(file, offset, origin);
30967 +/* ---------------------------------------------------------------------- */
30969 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
30970 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
30971 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30972 + struct inode **delegated_inode);
30973 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30974 + struct inode **delegated_inode);
30975 +int vfsub_unlink(struct inode *dir, struct path *path,
30976 + struct inode **delegated_inode, int force);
30978 +/* ---------------------------------------------------------------------- */
30980 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
30981 + const void *value, size_t size, int flags)
30986 + err = vfs_setxattr(dentry, name, value, size, flags);
30992 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
30997 + err = vfs_removexattr(dentry, name);
31003 +#endif /* __KERNEL__ */
31004 +#endif /* __AUFS_VFSUB_H__ */
31005 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31006 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31007 +++ linux/fs/aufs/wbr_policy.c 2015-06-28 17:36:09.028407078 +0200
31010 + * Copyright (C) 2005-2015 Junjiro R. Okajima
31012 + * This program, aufs is free software; you can redistribute it and/or modify
31013 + * it under the terms of the GNU General Public License as published by
31014 + * the Free Software Foundation; either version 2 of the License, or
31015 + * (at your option) any later version.
31017 + * This program is distributed in the hope that it will be useful,
31018 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31019 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31020 + * GNU General Public License for more details.
31022 + * You should have received a copy of the GNU General Public License
31023 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31027 + * policies for selecting one among multiple writable branches
31030 +#include <linux/statfs.h>
31033 +/* subset of cpup_attr() */
31034 +static noinline_for_stack
31035 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31039 + struct inode *h_isrc;
31041 + h_isrc = d_inode(h_src);
31042 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31043 + ia.ia_mode = h_isrc->i_mode;
31044 + ia.ia_uid = h_isrc->i_uid;
31045 + ia.ia_gid = h_isrc->i_gid;
31046 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31047 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31048 + /* no delegation since it is just created */
31049 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31051 + /* is this nfs only? */
31052 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31053 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31054 + ia.ia_mode = h_isrc->i_mode;
31055 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31061 +#define AuCpdown_PARENT_OPQ 1
31062 +#define AuCpdown_WHED (1 << 1)
31063 +#define AuCpdown_MADE_DIR (1 << 2)
31064 +#define AuCpdown_DIROPQ (1 << 3)
31065 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31066 +#define au_fset_cpdown(flags, name) \
31067 + do { (flags) |= AuCpdown_##name; } while (0)
31068 +#define au_fclr_cpdown(flags, name) \
31069 + do { (flags) &= ~AuCpdown_##name; } while (0)
31071 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31072 + unsigned int *flags)
31075 + struct dentry *opq_dentry;
31077 + opq_dentry = au_diropq_create(dentry, bdst);
31078 + err = PTR_ERR(opq_dentry);
31079 + if (IS_ERR(opq_dentry))
31081 + dput(opq_dentry);
31082 + au_fset_cpdown(*flags, DIROPQ);
31088 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31089 + struct inode *dir, aufs_bindex_t bdst)
31092 + struct path h_path;
31093 + struct au_branch *br;
31095 + br = au_sbr(dentry->d_sb, bdst);
31096 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31097 + err = PTR_ERR(h_path.dentry);
31098 + if (IS_ERR(h_path.dentry))
31102 + if (d_is_positive(h_path.dentry)) {
31103 + h_path.mnt = au_br_mnt(br);
31104 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31107 + dput(h_path.dentry);
31113 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31114 + struct au_pin *pin,
31115 + struct dentry *h_parent, void *arg)
31118 + aufs_bindex_t bopq, bstart;
31119 + struct path h_path;
31120 + struct dentry *parent;
31121 + struct inode *h_dir, *h_inode, *inode, *dir;
31122 + unsigned int *flags = arg;
31124 + bstart = au_dbstart(dentry);
31125 + /* dentry is di-locked */
31126 + parent = dget_parent(dentry);
31127 + dir = d_inode(parent);
31128 + h_dir = d_inode(h_parent);
31129 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31130 + IMustLock(h_dir);
31132 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31133 + if (unlikely(err < 0))
31135 + h_path.dentry = au_h_dptr(dentry, bdst);
31136 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31137 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31138 + S_IRWXU | S_IRUGO | S_IXUGO);
31139 + if (unlikely(err))
31141 + au_fset_cpdown(*flags, MADE_DIR);
31143 + bopq = au_dbdiropq(dentry);
31144 + au_fclr_cpdown(*flags, WHED);
31145 + au_fclr_cpdown(*flags, DIROPQ);
31146 + if (au_dbwh(dentry) == bdst)
31147 + au_fset_cpdown(*flags, WHED);
31148 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31149 + au_fset_cpdown(*flags, PARENT_OPQ);
31150 + h_inode = d_inode(h_path.dentry);
31151 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
31152 + if (au_ftest_cpdown(*flags, WHED)) {
31153 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31154 + if (unlikely(err)) {
31155 + mutex_unlock(&h_inode->i_mutex);
31160 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
31161 + mutex_unlock(&h_inode->i_mutex);
31162 + if (unlikely(err))
31165 + if (au_ftest_cpdown(*flags, WHED)) {
31166 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
31167 + if (unlikely(err))
31171 + inode = d_inode(dentry);
31172 + if (au_ibend(inode) < bdst)
31173 + au_set_ibend(inode, bdst);
31174 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
31175 + au_hi_flags(inode, /*isdir*/1));
31176 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
31177 + goto out; /* success */
31181 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31182 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
31183 + rerr = au_diropq_remove(dentry, bdst);
31184 + mutex_unlock(&h_inode->i_mutex);
31185 + if (unlikely(rerr)) {
31186 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
31187 + dentry, bdst, rerr);
31193 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
31194 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
31195 + if (unlikely(rerr)) {
31196 + AuIOErr("failed removing %pd b%d (%d)\n",
31197 + dentry, bdst, rerr);
31202 + au_set_h_dptr(dentry, bdst, NULL);
31203 + if (au_dbend(dentry) == bdst)
31204 + au_update_dbend(dentry);
31210 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
31213 + unsigned int flags;
31216 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
31221 +/* ---------------------------------------------------------------------- */
31223 +/* policies for create */
31225 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
31227 + int err, i, j, ndentry;
31228 + aufs_bindex_t bopq;
31229 + struct au_dcsub_pages dpages;
31230 + struct au_dpage *dpage;
31231 + struct dentry **dentries, *parent, *d;
31233 + err = au_dpages_init(&dpages, GFP_NOFS);
31234 + if (unlikely(err))
31236 + parent = dget_parent(dentry);
31237 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
31238 + if (unlikely(err))
31242 + for (i = 0; i < dpages.ndpage; i++) {
31243 + dpage = dpages.dpages + i;
31244 + dentries = dpage->dentries;
31245 + ndentry = dpage->ndentry;
31246 + for (j = 0; j < ndentry; j++) {
31248 + di_read_lock_parent2(d, !AuLock_IR);
31249 + bopq = au_dbdiropq(d);
31250 + di_read_unlock(d, !AuLock_IR);
31251 + if (bopq >= 0 && bopq < err)
31258 + au_dpages_free(&dpages);
31263 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
31265 + for (; bindex >= 0; bindex--)
31266 + if (!au_br_rdonly(au_sbr(sb, bindex)))
31271 +/* top down parent */
31272 +static int au_wbr_create_tdp(struct dentry *dentry,
31273 + unsigned int flags __maybe_unused)
31276 + aufs_bindex_t bstart, bindex;
31277 + struct super_block *sb;
31278 + struct dentry *parent, *h_parent;
31280 + sb = dentry->d_sb;
31281 + bstart = au_dbstart(dentry);
31283 + if (!au_br_rdonly(au_sbr(sb, bstart)))
31287 + parent = dget_parent(dentry);
31288 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
31289 + h_parent = au_h_dptr(parent, bindex);
31290 + if (!h_parent || d_is_negative(h_parent))
31293 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31300 + /* bottom up here */
31301 + if (unlikely(err < 0)) {
31302 + err = au_wbr_bu(sb, bstart - 1);
31304 + err = au_wbr_nonopq(dentry, err);
31308 + AuDbg("b%d\n", err);
31312 +/* ---------------------------------------------------------------------- */
31314 +/* an exception for the policy other than tdp */
31315 +static int au_wbr_create_exp(struct dentry *dentry)
31318 + aufs_bindex_t bwh, bdiropq;
31319 + struct dentry *parent;
31322 + bwh = au_dbwh(dentry);
31323 + parent = dget_parent(dentry);
31324 + bdiropq = au_dbdiropq(parent);
31326 + if (bdiropq >= 0)
31327 + err = min(bdiropq, bwh);
31330 + AuDbg("%d\n", err);
31331 + } else if (bdiropq >= 0) {
31333 + AuDbg("%d\n", err);
31338 + err = au_wbr_nonopq(dentry, err);
31340 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
31343 + AuDbg("%d\n", err);
31347 +/* ---------------------------------------------------------------------- */
31350 +static int au_wbr_create_init_rr(struct super_block *sb)
31354 + err = au_wbr_bu(sb, au_sbend(sb));
31355 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
31358 + AuDbg("b%d\n", err);
31362 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
31366 + aufs_bindex_t bindex, bend;
31367 + struct super_block *sb;
31370 + err = au_wbr_create_exp(dentry);
31374 + sb = dentry->d_sb;
31375 + next = &au_sbi(sb)->si_wbr_rr_next;
31376 + bend = au_sbend(sb);
31378 + for (bindex = 0; bindex <= bend; bindex++) {
31379 + if (!au_ftest_wbr(flags, DIR)) {
31380 + err = atomic_dec_return(next) + 1;
31381 + /* modulo for 0 is meaningless */
31382 + if (unlikely(!err))
31383 + err = atomic_dec_return(next) + 1;
31385 + err = atomic_read(next);
31386 + AuDbg("%d\n", err);
31389 + AuDbg("%d\n", err);
31390 + if (!au_br_rdonly(au_sbr(sb, err)))
31396 + err = au_wbr_nonopq(dentry, err);
31399 + AuDbg("%d\n", err);
31403 +/* ---------------------------------------------------------------------- */
31405 +/* most free space */
31406 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
31408 + struct super_block *sb;
31409 + struct au_branch *br;
31410 + struct au_wbr_mfs *mfs;
31411 + struct dentry *h_parent;
31412 + aufs_bindex_t bindex, bend;
31414 + unsigned long long b, bavail;
31415 + struct path h_path;
31416 + /* reduce the stack usage */
31417 + struct kstatfs *st;
31419 + st = kmalloc(sizeof(*st), GFP_NOFS);
31420 + if (unlikely(!st)) {
31421 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
31426 + sb = dentry->d_sb;
31427 + mfs = &au_sbi(sb)->si_wbr_mfs;
31428 + MtxMustLock(&mfs->mfs_lock);
31429 + mfs->mfs_bindex = -EROFS;
31430 + mfs->mfsrr_bytes = 0;
31433 + bend = au_sbend(sb);
31435 + bindex = au_dbstart(parent);
31436 + bend = au_dbtaildir(parent);
31439 + for (; bindex <= bend; bindex++) {
31441 + h_parent = au_h_dptr(parent, bindex);
31442 + if (!h_parent || d_is_negative(h_parent))
31445 + br = au_sbr(sb, bindex);
31446 + if (au_br_rdonly(br))
31449 + /* sb->s_root for NFS is unreliable */
31450 + h_path.mnt = au_br_mnt(br);
31451 + h_path.dentry = h_path.mnt->mnt_root;
31452 + err = vfs_statfs(&h_path, st);
31453 + if (unlikely(err)) {
31454 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
31458 + /* when the available size is equal, select the lower one */
31459 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
31460 + || sizeof(b) < sizeof(st->f_bsize));
31461 + b = st->f_bavail * st->f_bsize;
31462 + br->br_wbr->wbr_bytes = b;
31463 + if (b >= bavail) {
31465 + mfs->mfs_bindex = bindex;
31466 + mfs->mfs_jiffy = jiffies;
31470 + mfs->mfsrr_bytes = bavail;
31471 + AuDbg("b%d\n", mfs->mfs_bindex);
31475 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
31478 + struct dentry *parent;
31479 + struct super_block *sb;
31480 + struct au_wbr_mfs *mfs;
31482 + err = au_wbr_create_exp(dentry);
31486 + sb = dentry->d_sb;
31488 + if (au_ftest_wbr(flags, PARENT))
31489 + parent = dget_parent(dentry);
31490 + mfs = &au_sbi(sb)->si_wbr_mfs;
31491 + mutex_lock(&mfs->mfs_lock);
31492 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
31493 + || mfs->mfs_bindex < 0
31494 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
31495 + au_mfs(dentry, parent);
31496 + mutex_unlock(&mfs->mfs_lock);
31497 + err = mfs->mfs_bindex;
31501 + err = au_wbr_nonopq(dentry, err);
31504 + AuDbg("b%d\n", err);
31508 +static int au_wbr_create_init_mfs(struct super_block *sb)
31510 + struct au_wbr_mfs *mfs;
31512 + mfs = &au_sbi(sb)->si_wbr_mfs;
31513 + mutex_init(&mfs->mfs_lock);
31514 + mfs->mfs_jiffy = 0;
31515 + mfs->mfs_bindex = -EROFS;
31520 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
31522 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
31526 +/* ---------------------------------------------------------------------- */
31528 +/* most free space and then round robin */
31529 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
31532 + struct au_wbr_mfs *mfs;
31534 + err = au_wbr_create_mfs(dentry, flags);
31536 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
31537 + mutex_lock(&mfs->mfs_lock);
31538 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
31539 + err = au_wbr_create_rr(dentry, flags);
31540 + mutex_unlock(&mfs->mfs_lock);
31543 + AuDbg("b%d\n", err);
31547 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
31551 + au_wbr_create_init_mfs(sb); /* ignore */
31552 + err = au_wbr_create_init_rr(sb);
31557 +/* ---------------------------------------------------------------------- */
31559 +/* top down parent and most free space */
31560 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
31563 + unsigned long long b;
31564 + aufs_bindex_t bindex, bstart, bend;
31565 + struct super_block *sb;
31566 + struct dentry *parent, *h_parent;
31567 + struct au_branch *br;
31569 + err = au_wbr_create_tdp(dentry, flags);
31570 + if (unlikely(err < 0))
31572 + parent = dget_parent(dentry);
31573 + bstart = au_dbstart(parent);
31574 + bend = au_dbtaildir(parent);
31575 + if (bstart == bend)
31576 + goto out_parent; /* success */
31578 + e2 = au_wbr_create_mfs(dentry, flags);
31580 + goto out_parent; /* success */
31582 + /* when the available size is equal, select upper one */
31583 + sb = dentry->d_sb;
31584 + br = au_sbr(sb, err);
31585 + b = br->br_wbr->wbr_bytes;
31586 + AuDbg("b%d, %llu\n", err, b);
31588 + for (bindex = bstart; bindex <= bend; bindex++) {
31589 + h_parent = au_h_dptr(parent, bindex);
31590 + if (!h_parent || d_is_negative(h_parent))
31593 + br = au_sbr(sb, bindex);
31594 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
31595 + b = br->br_wbr->wbr_bytes;
31597 + AuDbg("b%d, %llu\n", err, b);
31602 + err = au_wbr_nonopq(dentry, err);
31607 + AuDbg("b%d\n", err);
31611 +/* ---------------------------------------------------------------------- */
31614 + * - top down parent
31615 + * - most free space with parent
31616 + * - most free space round-robin regardless parent
31618 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
31621 + unsigned long long watermark;
31622 + struct super_block *sb;
31623 + struct au_branch *br;
31624 + struct au_wbr_mfs *mfs;
31626 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
31627 + if (unlikely(err < 0))
31630 + sb = dentry->d_sb;
31631 + br = au_sbr(sb, err);
31632 + mfs = &au_sbi(sb)->si_wbr_mfs;
31633 + mutex_lock(&mfs->mfs_lock);
31634 + watermark = mfs->mfsrr_watermark;
31635 + mutex_unlock(&mfs->mfs_lock);
31636 + if (br->br_wbr->wbr_bytes < watermark)
31637 + /* regardless the parent dir */
31638 + err = au_wbr_create_mfsrr(dentry, flags);
31641 + AuDbg("b%d\n", err);
31645 +/* ---------------------------------------------------------------------- */
31647 +/* policies for copyup */
31649 +/* top down parent */
31650 +static int au_wbr_copyup_tdp(struct dentry *dentry)
31652 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
31655 +/* bottom up parent */
31656 +static int au_wbr_copyup_bup(struct dentry *dentry)
31659 + aufs_bindex_t bindex, bstart;
31660 + struct dentry *parent, *h_parent;
31661 + struct super_block *sb;
31664 + sb = dentry->d_sb;
31665 + parent = dget_parent(dentry);
31666 + bstart = au_dbstart(parent);
31667 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
31668 + h_parent = au_h_dptr(parent, bindex);
31669 + if (!h_parent || d_is_negative(h_parent))
31672 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31679 + /* bottom up here */
31680 + if (unlikely(err < 0))
31681 + err = au_wbr_bu(sb, bstart - 1);
31683 + AuDbg("b%d\n", err);
31688 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
31692 + err = au_wbr_bu(dentry->d_sb, bstart);
31693 + AuDbg("b%d\n", err);
31694 + if (err > bstart)
31695 + err = au_wbr_nonopq(dentry, err);
31697 + AuDbg("b%d\n", err);
31701 +static int au_wbr_copyup_bu(struct dentry *dentry)
31704 + aufs_bindex_t bstart;
31706 + bstart = au_dbstart(dentry);
31707 + err = au_wbr_do_copyup_bu(dentry, bstart);
31711 +/* ---------------------------------------------------------------------- */
31713 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
31714 + [AuWbrCopyup_TDP] = {
31715 + .copyup = au_wbr_copyup_tdp
31717 + [AuWbrCopyup_BUP] = {
31718 + .copyup = au_wbr_copyup_bup
31720 + [AuWbrCopyup_BU] = {
31721 + .copyup = au_wbr_copyup_bu
31725 +struct au_wbr_create_operations au_wbr_create_ops[] = {
31726 + [AuWbrCreate_TDP] = {
31727 + .create = au_wbr_create_tdp
31729 + [AuWbrCreate_RR] = {
31730 + .create = au_wbr_create_rr,
31731 + .init = au_wbr_create_init_rr
31733 + [AuWbrCreate_MFS] = {
31734 + .create = au_wbr_create_mfs,
31735 + .init = au_wbr_create_init_mfs,
31736 + .fin = au_wbr_create_fin_mfs
31738 + [AuWbrCreate_MFSV] = {
31739 + .create = au_wbr_create_mfs,
31740 + .init = au_wbr_create_init_mfs,
31741 + .fin = au_wbr_create_fin_mfs
31743 + [AuWbrCreate_MFSRR] = {
31744 + .create = au_wbr_create_mfsrr,
31745 + .init = au_wbr_create_init_mfsrr,
31746 + .fin = au_wbr_create_fin_mfs
31748 + [AuWbrCreate_MFSRRV] = {
31749 + .create = au_wbr_create_mfsrr,
31750 + .init = au_wbr_create_init_mfsrr,
31751 + .fin = au_wbr_create_fin_mfs
31753 + [AuWbrCreate_PMFS] = {
31754 + .create = au_wbr_create_pmfs,
31755 + .init = au_wbr_create_init_mfs,
31756 + .fin = au_wbr_create_fin_mfs
31758 + [AuWbrCreate_PMFSV] = {
31759 + .create = au_wbr_create_pmfs,
31760 + .init = au_wbr_create_init_mfs,
31761 + .fin = au_wbr_create_fin_mfs
31763 + [AuWbrCreate_PMFSRR] = {
31764 + .create = au_wbr_create_pmfsrr,
31765 + .init = au_wbr_create_init_mfsrr,
31766 + .fin = au_wbr_create_fin_mfs
31768 + [AuWbrCreate_PMFSRRV] = {
31769 + .create = au_wbr_create_pmfsrr,
31770 + .init = au_wbr_create_init_mfsrr,
31771 + .fin = au_wbr_create_fin_mfs
31774 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
31775 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
31776 +++ linux/fs/aufs/whout.c 2015-06-28 17:36:09.028407078 +0200
31779 + * Copyright (C) 2005-2015 Junjiro R. Okajima
31781 + * This program, aufs is free software; you can redistribute it and/or modify
31782 + * it under the terms of the GNU General Public License as published by
31783 + * the Free Software Foundation; either version 2 of the License, or
31784 + * (at your option) any later version.
31786 + * This program is distributed in the hope that it will be useful,
31787 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31788 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31789 + * GNU General Public License for more details.
31791 + * You should have received a copy of the GNU General Public License
31792 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31796 + * whiteout for logical deletion and opaque directory
31801 +#define WH_MASK S_IRUGO
31804 + * If a directory contains this file, then it is opaque. We start with the
31805 + * .wh. flag so that it is blocked by lookup.
31807 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
31808 + sizeof(AUFS_WH_DIROPQ) - 1);
31811 + * generate whiteout name, which is NOT terminated by NULL.
31812 + * @name: original d_name.name
31813 + * @len: original d_name.len
31814 + * @wh: whiteout qstr
31815 + * returns zero when succeeds, otherwise error.
31816 + * succeeded value as wh->name should be freed by kfree().
31818 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
31822 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
31823 + return -ENAMETOOLONG;
31825 + wh->len = name->len + AUFS_WH_PFX_LEN;
31826 + p = kmalloc(wh->len, GFP_NOFS);
31829 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
31830 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
31837 +/* ---------------------------------------------------------------------- */
31840 + * test if the @wh_name exists under @h_parent.
31841 + * @try_sio specifies the necessary of super-io.
31843 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
31846 + struct dentry *wh_dentry;
31849 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
31851 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
31852 + err = PTR_ERR(wh_dentry);
31853 + if (IS_ERR(wh_dentry)) {
31854 + if (err == -ENAMETOOLONG)
31860 + if (d_is_negative(wh_dentry))
31861 + goto out_wh; /* success */
31864 + if (d_is_reg(wh_dentry))
31865 + goto out_wh; /* success */
31868 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
31869 + wh_dentry, d_inode(wh_dentry)->i_mode);
31878 + * test if the @h_dentry sets opaque or not.
31880 +int au_diropq_test(struct dentry *h_dentry)
31883 + struct inode *h_dir;
31885 + h_dir = d_inode(h_dentry);
31886 + err = au_wh_test(h_dentry, &diropq_name,
31887 + au_test_h_perm_sio(h_dir, MAY_EXEC));
31892 + * returns a negative dentry whose name is unique and temporary.
31894 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
31895 + struct qstr *prefix)
31897 + struct dentry *dentry;
31899 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
31901 + /* strict atomic_t is unnecessary here */
31902 + static unsigned short cnt;
31905 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
31908 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
31909 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
31910 + dentry = ERR_PTR(-ENAMETOOLONG);
31911 + if (unlikely(qs.len > NAME_MAX))
31913 + dentry = ERR_PTR(-ENOMEM);
31914 + name = kmalloc(qs.len + 1, GFP_NOFS);
31915 + if (unlikely(!name))
31919 + /* doubly whiteout-ed */
31920 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
31921 + p = name + AUFS_WH_PFX_LEN * 2;
31922 + memcpy(p, prefix->name, prefix->len);
31923 + p += prefix->len;
31925 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
31928 + for (i = 0; i < 3; i++) {
31929 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
31930 + dentry = au_sio_lkup_one(&qs, h_parent);
31931 + if (IS_ERR(dentry) || d_is_negative(dentry))
31935 + /* pr_warn("could not get random name\n"); */
31936 + dentry = ERR_PTR(-EEXIST);
31937 + AuDbg("%.*s\n", AuLNPair(&qs));
31941 + if (name != defname)
31944 + AuTraceErrPtr(dentry);
31949 + * rename the @h_dentry on @br to the whiteouted temporary name.
31951 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
31954 + struct path h_path = {
31955 + .mnt = au_br_mnt(br)
31957 + struct inode *h_dir, *delegated;
31958 + struct dentry *h_parent;
31960 + h_parent = h_dentry->d_parent; /* dir inode is locked */
31961 + h_dir = d_inode(h_parent);
31962 + IMustLock(h_dir);
31964 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
31965 + err = PTR_ERR(h_path.dentry);
31966 + if (IS_ERR(h_path.dentry))
31969 + /* under the same dir, no need to lock_rename() */
31970 + delegated = NULL;
31971 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
31973 + if (unlikely(err == -EWOULDBLOCK)) {
31974 + pr_warn("cannot retry for NFSv4 delegation"
31975 + " for an internal rename\n");
31978 + dput(h_path.dentry);
31985 +/* ---------------------------------------------------------------------- */
31987 + * functions for removing a whiteout
31990 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
31993 + struct inode *delegated;
31996 + * forces superio when the dir has a sticky bit.
31997 + * this may be a violation of unix fs semantics.
31999 + force = (h_dir->i_mode & S_ISVTX)
32000 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32001 + delegated = NULL;
32002 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32003 + if (unlikely(err == -EWOULDBLOCK)) {
32004 + pr_warn("cannot retry for NFSv4 delegation"
32005 + " for an internal unlink\n");
32011 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32012 + struct dentry *dentry)
32016 + err = do_unlink_wh(h_dir, h_path);
32017 + if (!err && dentry)
32018 + au_set_dbwh(dentry, -1);
32023 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32024 + struct au_branch *br)
32027 + struct path h_path = {
32028 + .mnt = au_br_mnt(br)
32032 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32033 + if (IS_ERR(h_path.dentry))
32034 + err = PTR_ERR(h_path.dentry);
32036 + if (d_is_reg(h_path.dentry))
32037 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32038 + dput(h_path.dentry);
32044 +/* ---------------------------------------------------------------------- */
32046 + * initialize/clean whiteout for a branch
32049 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32053 + struct inode *delegated;
32055 + if (d_is_negative(whpath->dentry))
32059 + err = vfsub_rmdir(h_dir, whpath);
32061 + delegated = NULL;
32062 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32063 + if (unlikely(err == -EWOULDBLOCK)) {
32064 + pr_warn("cannot retry for NFSv4 delegation"
32065 + " for an internal unlink\n");
32069 + if (unlikely(err))
32070 + pr_warn("failed removing %pd (%d), ignored.\n",
32071 + whpath->dentry, err);
32074 +static int test_linkable(struct dentry *h_root)
32076 + struct inode *h_dir = d_inode(h_root);
32078 + if (h_dir->i_op->link)
32081 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32082 + h_root, au_sbtype(h_root->d_sb));
32086 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32087 +static int au_whdir(struct inode *h_dir, struct path *path)
32092 + if (d_is_negative(path->dentry)) {
32093 + int mode = S_IRWXU;
32095 + if (au_test_nfs(path->dentry->d_sb))
32097 + err = vfsub_mkdir(h_dir, path, mode);
32098 + } else if (d_is_dir(path->dentry))
32101 + pr_err("unknown %pd exists\n", path->dentry);
32106 +struct au_wh_base {
32107 + const struct qstr *name;
32108 + struct dentry *dentry;
32111 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
32112 + struct path *h_path)
32114 + h_path->dentry = base[AuBrWh_BASE].dentry;
32115 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32116 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32117 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32118 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32119 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32123 + * returns tri-state,
32124 + * minus: error, caller should print the message
32126 + * plus: error, caller should NOT print the message
32128 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
32129 + int do_plink, struct au_wh_base base[],
32130 + struct path *h_path)
32133 + struct inode *h_dir;
32135 + h_dir = d_inode(h_root);
32136 + h_path->dentry = base[AuBrWh_BASE].dentry;
32137 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32138 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32140 + err = test_linkable(h_root);
32141 + if (unlikely(err)) {
32146 + err = au_whdir(h_dir, h_path);
32147 + if (unlikely(err))
32149 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32151 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32152 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32153 + err = au_whdir(h_dir, h_path);
32154 + if (unlikely(err))
32156 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32163 + * for the moment, aufs supports the branch filesystem which does not support
32164 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
32165 + * copyup failed. finally, such filesystem will not be used as the writable
32168 + * returns tri-state, see above.
32170 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
32171 + int do_plink, struct au_wh_base base[],
32172 + struct path *h_path)
32175 + struct inode *h_dir;
32177 + WbrWhMustWriteLock(wbr);
32179 + err = test_linkable(h_root);
32180 + if (unlikely(err)) {
32186 + * todo: should this create be done in /sbin/mount.aufs helper?
32189 + h_dir = d_inode(h_root);
32190 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
32191 + h_path->dentry = base[AuBrWh_BASE].dentry;
32192 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
32193 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
32196 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
32197 + if (unlikely(err))
32200 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32202 + err = au_whdir(h_dir, h_path);
32203 + if (unlikely(err))
32205 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32207 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32208 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
32210 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32211 + err = au_whdir(h_dir, h_path);
32212 + if (unlikely(err))
32214 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32221 + * initialize the whiteout base file/dir for @br.
32223 +int au_wh_init(struct au_branch *br, struct super_block *sb)
32226 + const unsigned char do_plink
32227 + = !!au_opt_test(au_mntflags(sb), PLINK);
32228 + struct inode *h_dir;
32229 + struct path path = br->br_path;
32230 + struct dentry *h_root = path.dentry;
32231 + struct au_wbr *wbr = br->br_wbr;
32232 + static const struct qstr base_name[] = {
32233 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
32234 + sizeof(AUFS_BASE_NAME) - 1),
32235 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
32236 + sizeof(AUFS_PLINKDIR_NAME) - 1),
32237 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
32238 + sizeof(AUFS_ORPHDIR_NAME) - 1)
32240 + struct au_wh_base base[] = {
32241 + [AuBrWh_BASE] = {
32242 + .name = base_name + AuBrWh_BASE,
32245 + [AuBrWh_PLINK] = {
32246 + .name = base_name + AuBrWh_PLINK,
32249 + [AuBrWh_ORPH] = {
32250 + .name = base_name + AuBrWh_ORPH,
32256 + WbrWhMustWriteLock(wbr);
32258 + for (i = 0; i < AuBrWh_Last; i++) {
32259 + /* doubly whiteouted */
32260 + struct dentry *d;
32262 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
32263 + err = PTR_ERR(d);
32267 + base[i].dentry = d;
32269 + && wbr->wbr_wh[i]
32270 + && wbr->wbr_wh[i] != base[i].dentry);
32274 + for (i = 0; i < AuBrWh_Last; i++) {
32275 + dput(wbr->wbr_wh[i]);
32276 + wbr->wbr_wh[i] = NULL;
32280 + if (!au_br_writable(br->br_perm)) {
32281 + h_dir = d_inode(h_root);
32282 + au_wh_init_ro(h_dir, base, &path);
32283 + } else if (!au_br_wh_linkable(br->br_perm)) {
32284 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
32290 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
32296 + goto out; /* success */
32299 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
32300 + err, h_root, au_sbtype(h_root->d_sb));
32302 + for (i = 0; i < AuBrWh_Last; i++)
32303 + dput(base[i].dentry);
32307 +/* ---------------------------------------------------------------------- */
32309 + * whiteouts are all hard-linked usually.
32310 + * when its link count reaches a ceiling, we create a new whiteout base
32311 + * asynchronously.
32314 +struct reinit_br_wh {
32315 + struct super_block *sb;
32316 + struct au_branch *br;
32319 +static void reinit_br_wh(void *arg)
32322 + aufs_bindex_t bindex;
32323 + struct path h_path;
32324 + struct reinit_br_wh *a = arg;
32325 + struct au_wbr *wbr;
32326 + struct inode *dir, *delegated;
32327 + struct dentry *h_root;
32328 + struct au_hinode *hdir;
32331 + wbr = a->br->br_wbr;
32332 + /* big aufs lock */
32333 + si_noflush_write_lock(a->sb);
32334 + if (!au_br_writable(a->br->br_perm))
32336 + bindex = au_br_index(a->sb, a->br->br_id);
32337 + if (unlikely(bindex < 0))
32340 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
32341 + dir = d_inode(a->sb->s_root);
32342 + hdir = au_hi(dir, bindex);
32343 + h_root = au_h_dptr(a->sb->s_root, bindex);
32344 + AuDebugOn(h_root != au_br_dentry(a->br));
32346 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32347 + wbr_wh_write_lock(wbr);
32348 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
32351 + h_path.dentry = wbr->wbr_whbase;
32352 + h_path.mnt = au_br_mnt(a->br);
32353 + delegated = NULL;
32354 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
32356 + if (unlikely(err == -EWOULDBLOCK)) {
32357 + pr_warn("cannot retry for NFSv4 delegation"
32358 + " for an internal unlink\n");
32362 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
32365 + dput(wbr->wbr_whbase);
32366 + wbr->wbr_whbase = NULL;
32368 + err = au_wh_init(a->br, a->sb);
32369 + wbr_wh_write_unlock(wbr);
32370 + au_hn_imtx_unlock(hdir);
32371 + di_read_unlock(a->sb->s_root, AuLock_IR);
32373 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
32377 + atomic_dec(&wbr->wbr_wh_running);
32378 + atomic_dec(&a->br->br_count);
32379 + si_write_unlock(a->sb);
32380 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
32382 + if (unlikely(err))
32383 + AuIOErr("err %d\n", err);
32386 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
32388 + int do_dec, wkq_err;
32389 + struct reinit_br_wh *arg;
32392 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
32395 + /* ignore ENOMEM */
32396 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
32399 + * dec(wh_running), kfree(arg) and dec(br_count)
32400 + * in reinit function
32404 + atomic_inc(&br->br_count);
32405 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
32406 + if (unlikely(wkq_err)) {
32407 + atomic_dec(&br->br_wbr->wbr_wh_running);
32408 + atomic_dec(&br->br_count);
32416 + atomic_dec(&br->br_wbr->wbr_wh_running);
32419 +/* ---------------------------------------------------------------------- */
32422 + * create the whiteout @wh.
32424 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
32425 + struct dentry *wh)
32428 + struct path h_path = {
32431 + struct au_branch *br;
32432 + struct au_wbr *wbr;
32433 + struct dentry *h_parent;
32434 + struct inode *h_dir, *delegated;
32436 + h_parent = wh->d_parent; /* dir inode is locked */
32437 + h_dir = d_inode(h_parent);
32438 + IMustLock(h_dir);
32440 + br = au_sbr(sb, bindex);
32441 + h_path.mnt = au_br_mnt(br);
32442 + wbr = br->br_wbr;
32443 + wbr_wh_read_lock(wbr);
32444 + if (wbr->wbr_whbase) {
32445 + delegated = NULL;
32446 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
32447 + if (unlikely(err == -EWOULDBLOCK)) {
32448 + pr_warn("cannot retry for NFSv4 delegation"
32449 + " for an internal link\n");
32452 + if (!err || err != -EMLINK)
32455 + /* link count full. re-initialize br_whbase. */
32456 + kick_reinit_br_wh(sb, br);
32459 + /* return this error in this context */
32460 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
32462 + au_fhsm_wrote(sb, bindex, /*force*/0);
32465 + wbr_wh_read_unlock(wbr);
32469 +/* ---------------------------------------------------------------------- */
32472 + * create or remove the diropq.
32474 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
32475 + unsigned int flags)
32477 + struct dentry *opq_dentry, *h_dentry;
32478 + struct super_block *sb;
32479 + struct au_branch *br;
32482 + sb = dentry->d_sb;
32483 + br = au_sbr(sb, bindex);
32484 + h_dentry = au_h_dptr(dentry, bindex);
32485 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
32486 + if (IS_ERR(opq_dentry))
32489 + if (au_ftest_diropq(flags, CREATE)) {
32490 + err = link_or_create_wh(sb, bindex, opq_dentry);
32492 + au_set_dbdiropq(dentry, bindex);
32493 + goto out; /* success */
32496 + struct path tmp = {
32497 + .dentry = opq_dentry,
32498 + .mnt = au_br_mnt(br)
32500 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
32502 + au_set_dbdiropq(dentry, -1);
32504 + dput(opq_dentry);
32505 + opq_dentry = ERR_PTR(err);
32508 + return opq_dentry;
32511 +struct do_diropq_args {
32512 + struct dentry **errp;
32513 + struct dentry *dentry;
32514 + aufs_bindex_t bindex;
32515 + unsigned int flags;
32518 +static void call_do_diropq(void *args)
32520 + struct do_diropq_args *a = args;
32521 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
32524 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32525 + unsigned int flags)
32527 + struct dentry *diropq, *h_dentry;
32529 + h_dentry = au_h_dptr(dentry, bindex);
32530 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
32531 + diropq = do_diropq(dentry, bindex, flags);
32534 + struct do_diropq_args args = {
32536 + .dentry = dentry,
32537 + .bindex = bindex,
32541 + wkq_err = au_wkq_wait(call_do_diropq, &args);
32542 + if (unlikely(wkq_err))
32543 + diropq = ERR_PTR(wkq_err);
32549 +/* ---------------------------------------------------------------------- */
32552 + * lookup whiteout dentry.
32553 + * @h_parent: lower parent dentry which must exist and be locked
32554 + * @base_name: name of dentry which will be whiteouted
32555 + * returns dentry for whiteout.
32557 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32558 + struct au_branch *br)
32561 + struct qstr wh_name;
32562 + struct dentry *wh_dentry;
32564 + err = au_wh_name_alloc(&wh_name, base_name);
32565 + wh_dentry = ERR_PTR(err);
32567 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
32568 + kfree(wh_name.name);
32570 + return wh_dentry;
32574 + * link/create a whiteout for @dentry on @bindex.
32576 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32577 + struct dentry *h_parent)
32579 + struct dentry *wh_dentry;
32580 + struct super_block *sb;
32583 + sb = dentry->d_sb;
32584 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
32585 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
32586 + err = link_or_create_wh(sb, bindex, wh_dentry);
32588 + au_set_dbwh(dentry, bindex);
32589 + au_fhsm_wrote(sb, bindex, /*force*/0);
32592 + wh_dentry = ERR_PTR(err);
32596 + return wh_dentry;
32599 +/* ---------------------------------------------------------------------- */
32601 +/* Delete all whiteouts in this directory on branch bindex. */
32602 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
32603 + aufs_bindex_t bindex, struct au_branch *br)
32606 + unsigned long ul, n;
32607 + struct qstr wh_name;
32609 + struct hlist_head *head;
32610 + struct au_vdir_wh *pos;
32611 + struct au_vdir_destr *str;
32614 + p = (void *)__get_free_page(GFP_NOFS);
32615 + wh_name.name = p;
32616 + if (unlikely(!wh_name.name))
32620 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32621 + p += AUFS_WH_PFX_LEN;
32622 + n = whlist->nh_num;
32623 + head = whlist->nh_head;
32624 + for (ul = 0; !err && ul < n; ul++, head++) {
32625 + hlist_for_each_entry(pos, head, wh_hash) {
32626 + if (pos->wh_bindex != bindex)
32629 + str = &pos->wh_str;
32630 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
32631 + memcpy(p, str->name, str->len);
32632 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
32633 + err = unlink_wh_name(h_dentry, &wh_name, br);
32638 + AuIOErr("whiteout name too long %.*s\n",
32639 + str->len, str->name);
32644 + free_page((unsigned long)wh_name.name);
32650 +struct del_wh_children_args {
32652 + struct dentry *h_dentry;
32653 + struct au_nhash *whlist;
32654 + aufs_bindex_t bindex;
32655 + struct au_branch *br;
32658 +static void call_del_wh_children(void *args)
32660 + struct del_wh_children_args *a = args;
32661 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
32664 +/* ---------------------------------------------------------------------- */
32666 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
32668 + struct au_whtmp_rmdir *whtmp;
32670 + unsigned int rdhash;
32672 + SiMustAnyLock(sb);
32674 + whtmp = kmalloc(sizeof(*whtmp), gfp);
32675 + if (unlikely(!whtmp)) {
32676 + whtmp = ERR_PTR(-ENOMEM);
32680 + whtmp->dir = NULL;
32681 + whtmp->br = NULL;
32682 + whtmp->wh_dentry = NULL;
32683 + /* no estimation for dir size */
32684 + rdhash = au_sbi(sb)->si_rdhash;
32686 + rdhash = AUFS_RDHASH_DEF;
32687 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
32688 + if (unlikely(err)) {
32690 + whtmp = ERR_PTR(err);
32697 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
32700 + atomic_dec(&whtmp->br->br_count);
32701 + dput(whtmp->wh_dentry);
32702 + iput(whtmp->dir);
32703 + au_nhash_wh_free(&whtmp->whlist);
32708 + * rmdir the whiteouted temporary named dir @h_dentry.
32709 + * @whlist: whiteouted children.
32711 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32712 + struct dentry *wh_dentry, struct au_nhash *whlist)
32715 + unsigned int h_nlink;
32716 + struct path h_tmp;
32717 + struct inode *wh_inode, *h_dir;
32718 + struct au_branch *br;
32720 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
32721 + IMustLock(h_dir);
32723 + br = au_sbr(dir->i_sb, bindex);
32724 + wh_inode = d_inode(wh_dentry);
32725 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
32728 + * someone else might change some whiteouts while we were sleeping.
32729 + * it means this whlist may have an obsoleted entry.
32731 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
32732 + err = del_wh_children(wh_dentry, whlist, bindex, br);
32735 + struct del_wh_children_args args = {
32737 + .h_dentry = wh_dentry,
32738 + .whlist = whlist,
32739 + .bindex = bindex,
32743 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
32744 + if (unlikely(wkq_err))
32747 + mutex_unlock(&wh_inode->i_mutex);
32750 + h_tmp.dentry = wh_dentry;
32751 + h_tmp.mnt = au_br_mnt(br);
32752 + h_nlink = h_dir->i_nlink;
32753 + err = vfsub_rmdir(h_dir, &h_tmp);
32754 + /* some fs doesn't change the parent nlink in some cases */
32755 + h_nlink -= h_dir->i_nlink;
32759 + if (au_ibstart(dir) == bindex) {
32760 + /* todo: dir->i_mutex is necessary */
32761 + au_cpup_attr_timesizes(dir);
32763 + vfsub_drop_nlink(dir);
32765 + return 0; /* success */
32768 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
32772 +static void call_rmdir_whtmp(void *args)
32775 + aufs_bindex_t bindex;
32776 + struct au_whtmp_rmdir *a = args;
32777 + struct super_block *sb;
32778 + struct dentry *h_parent;
32779 + struct inode *h_dir;
32780 + struct au_hinode *hdir;
32782 + /* rmdir by nfsd may cause deadlock with this i_mutex */
32783 + /* mutex_lock(&a->dir->i_mutex); */
32785 + sb = a->dir->i_sb;
32786 + si_read_lock(sb, !AuLock_FLUSH);
32787 + if (!au_br_writable(a->br->br_perm))
32789 + bindex = au_br_index(sb, a->br->br_id);
32790 + if (unlikely(bindex < 0))
32794 + ii_write_lock_parent(a->dir);
32795 + h_parent = dget_parent(a->wh_dentry);
32796 + h_dir = d_inode(h_parent);
32797 + hdir = au_hi(a->dir, bindex);
32798 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
32799 + if (unlikely(err))
32801 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32802 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
32805 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
32806 + au_hn_imtx_unlock(hdir);
32807 + vfsub_mnt_drop_write(au_br_mnt(a->br));
32811 + ii_write_unlock(a->dir);
32813 + /* mutex_unlock(&a->dir->i_mutex); */
32814 + au_whtmp_rmdir_free(a);
32815 + si_read_unlock(sb);
32816 + au_nwt_done(&au_sbi(sb)->si_nowait);
32817 + if (unlikely(err))
32818 + AuIOErr("err %d\n", err);
32821 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32822 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
32825 + struct super_block *sb;
32829 + /* all post-process will be done in do_rmdir_whtmp(). */
32831 + args->dir = au_igrab(dir);
32832 + args->br = au_sbr(sb, bindex);
32833 + atomic_inc(&args->br->br_count);
32834 + args->wh_dentry = dget(wh_dentry);
32835 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
32836 + if (unlikely(wkq_err)) {
32837 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
32838 + au_whtmp_rmdir_free(args);
32841 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
32842 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
32843 +++ linux/fs/aufs/whout.h 2015-06-28 17:35:44.351383872 +0200
32846 + * Copyright (C) 2005-2015 Junjiro R. Okajima
32848 + * This program, aufs is free software; you can redistribute it and/or modify
32849 + * it under the terms of the GNU General Public License as published by
32850 + * the Free Software Foundation; either version 2 of the License, or
32851 + * (at your option) any later version.
32853 + * This program is distributed in the hope that it will be useful,
32854 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32855 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32856 + * GNU General Public License for more details.
32858 + * You should have received a copy of the GNU General Public License
32859 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32863 + * whiteout for logical deletion and opaque directory
32866 +#ifndef __AUFS_WHOUT_H__
32867 +#define __AUFS_WHOUT_H__
32874 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
32875 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
32876 +int au_diropq_test(struct dentry *h_dentry);
32878 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32879 + struct qstr *prefix);
32880 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
32881 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32882 + struct dentry *dentry);
32883 +int au_wh_init(struct au_branch *br, struct super_block *sb);
32885 +/* diropq flags */
32886 +#define AuDiropq_CREATE 1
32887 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
32888 +#define au_fset_diropq(flags, name) \
32889 + do { (flags) |= AuDiropq_##name; } while (0)
32890 +#define au_fclr_diropq(flags, name) \
32891 + do { (flags) &= ~AuDiropq_##name; } while (0)
32893 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32894 + unsigned int flags);
32895 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32896 + struct au_branch *br);
32897 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32898 + struct dentry *h_parent);
32900 +/* real rmdir for the whiteout-ed dir */
32901 +struct au_whtmp_rmdir {
32902 + struct inode *dir;
32903 + struct au_branch *br;
32904 + struct dentry *wh_dentry;
32905 + struct au_nhash whlist;
32908 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
32909 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
32910 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32911 + struct dentry *wh_dentry, struct au_nhash *whlist);
32912 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32913 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
32915 +/* ---------------------------------------------------------------------- */
32917 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
32918 + aufs_bindex_t bindex)
32920 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
32923 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
32925 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
32928 +#endif /* __KERNEL__ */
32929 +#endif /* __AUFS_WHOUT_H__ */
32930 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
32931 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
32932 +++ linux/fs/aufs/wkq.c 2015-06-28 17:35:44.351383872 +0200
32935 + * Copyright (C) 2005-2015 Junjiro R. Okajima
32937 + * This program, aufs is free software; you can redistribute it and/or modify
32938 + * it under the terms of the GNU General Public License as published by
32939 + * the Free Software Foundation; either version 2 of the License, or
32940 + * (at your option) any later version.
32942 + * This program is distributed in the hope that it will be useful,
32943 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32944 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32945 + * GNU General Public License for more details.
32947 + * You should have received a copy of the GNU General Public License
32948 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32952 + * workqueue for asynchronous/super-io operations
32953 + * todo: try new dredential scheme
32956 +#include <linux/module.h>
32959 +/* internal workqueue named AUFS_WKQ_NAME */
32961 +static struct workqueue_struct *au_wkq;
32963 +struct au_wkinfo {
32964 + struct work_struct wk;
32965 + struct kobject *kobj;
32967 + unsigned int flags; /* see wkq.h */
32969 + au_wkq_func_t func;
32972 + struct completion *comp;
32975 +/* ---------------------------------------------------------------------- */
32977 +static void wkq_func(struct work_struct *wk)
32979 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
32981 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
32982 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
32984 + wkinfo->func(wkinfo->args);
32985 + if (au_ftest_wkq(wkinfo->flags, WAIT))
32986 + complete(wkinfo->comp);
32988 + kobject_put(wkinfo->kobj);
32989 + module_put(THIS_MODULE); /* todo: ?? */
32995 + * Since struct completion is large, try allocating it dynamically.
32997 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
32998 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33000 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33002 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33004 + init_completion(*comp);
33005 + wkinfo->comp = *comp;
33011 +static void au_wkq_comp_free(struct completion *comp)
33019 +#define AuWkqCompDeclare(name) \
33020 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33021 + struct completion *comp = &_ ## name
33023 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33025 + wkinfo->comp = *comp;
33029 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33033 +#endif /* 4KSTACKS */
33035 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33037 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33038 + if (au_wkq_test()) {
33039 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33040 + " due to a dead dir by UDBA?\n");
33041 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33044 + au_dbg_verify_kthread();
33046 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33047 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33048 + queue_work(au_wkq, &wkinfo->wk);
33050 + INIT_WORK(&wkinfo->wk, wkq_func);
33051 + schedule_work(&wkinfo->wk);
33056 + * Be careful. It is easy to make deadlock happen.
33057 + * processA: lock, wkq and wait
33058 + * processB: wkq and wait, lock in wkq
33061 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33064 + AuWkqCompDeclare(comp);
33065 + struct au_wkinfo wkinfo = {
33071 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33073 + au_wkq_run(&wkinfo);
33074 + /* no timeout, no interrupt */
33075 + wait_for_completion(wkinfo.comp);
33076 + au_wkq_comp_free(comp);
33077 + destroy_work_on_stack(&wkinfo.wk);
33085 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33086 + * problem in a concurrent umounting.
33088 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33089 + unsigned int flags)
33092 + struct au_wkinfo *wkinfo;
33094 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
33097 + * wkq_func() must free this wkinfo.
33098 + * it highly depends upon the implementation of workqueue.
33101 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
33103 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
33104 + wkinfo->flags = flags & ~AuWkq_WAIT;
33105 + wkinfo->func = func;
33106 + wkinfo->args = args;
33107 + wkinfo->comp = NULL;
33108 + kobject_get(wkinfo->kobj);
33109 + __module_get(THIS_MODULE); /* todo: ?? */
33111 + au_wkq_run(wkinfo);
33114 + au_nwt_done(&au_sbi(sb)->si_nowait);
33120 +/* ---------------------------------------------------------------------- */
33122 +void au_nwt_init(struct au_nowait_tasks *nwt)
33124 + atomic_set(&nwt->nw_len, 0);
33125 + /* smp_mb(); */ /* atomic_set */
33126 + init_waitqueue_head(&nwt->nw_wq);
33129 +void au_wkq_fin(void)
33131 + destroy_workqueue(au_wkq);
33134 +int __init au_wkq_init(void)
33139 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
33140 + if (IS_ERR(au_wkq))
33141 + err = PTR_ERR(au_wkq);
33142 + else if (!au_wkq)
33147 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
33148 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
33149 +++ linux/fs/aufs/wkq.h 2015-06-28 17:35:44.351383872 +0200
33152 + * Copyright (C) 2005-2015 Junjiro R. Okajima
33154 + * This program, aufs is free software; you can redistribute it and/or modify
33155 + * it under the terms of the GNU General Public License as published by
33156 + * the Free Software Foundation; either version 2 of the License, or
33157 + * (at your option) any later version.
33159 + * This program is distributed in the hope that it will be useful,
33160 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33161 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33162 + * GNU General Public License for more details.
33164 + * You should have received a copy of the GNU General Public License
33165 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33169 + * workqueue for asynchronous/super-io operations
33170 + * todo: try new credentials management scheme
33173 +#ifndef __AUFS_WKQ_H__
33174 +#define __AUFS_WKQ_H__
33178 +struct super_block;
33180 +/* ---------------------------------------------------------------------- */
33183 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
33185 +struct au_nowait_tasks {
33187 + wait_queue_head_t nw_wq;
33190 +/* ---------------------------------------------------------------------- */
33192 +typedef void (*au_wkq_func_t)(void *args);
33195 +#define AuWkq_WAIT 1
33196 +#define AuWkq_NEST (1 << 1)
33197 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
33198 +#define au_fset_wkq(flags, name) \
33199 + do { (flags) |= AuWkq_##name; } while (0)
33200 +#define au_fclr_wkq(flags, name) \
33201 + do { (flags) &= ~AuWkq_##name; } while (0)
33203 +#ifndef CONFIG_AUFS_HNOTIFY
33205 +#define AuWkq_NEST 0
33209 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
33210 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33211 + unsigned int flags);
33212 +void au_nwt_init(struct au_nowait_tasks *nwt);
33213 +int __init au_wkq_init(void);
33214 +void au_wkq_fin(void);
33216 +/* ---------------------------------------------------------------------- */
33218 +static inline int au_wkq_test(void)
33220 + return current->flags & PF_WQ_WORKER;
33223 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
33225 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
33228 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
33230 + if (atomic_dec_and_test(&nwt->nw_len))
33231 + wake_up_all(&nwt->nw_wq);
33234 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
33236 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
33240 +#endif /* __KERNEL__ */
33241 +#endif /* __AUFS_WKQ_H__ */
33242 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
33243 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
33244 +++ linux/fs/aufs/xattr.c 2015-06-28 17:36:09.028407078 +0200
33247 + * Copyright (C) 2014-2015 Junjiro R. Okajima
33249 + * This program, aufs is free software; you can redistribute it and/or modify
33250 + * it under the terms of the GNU General Public License as published by
33251 + * the Free Software Foundation; either version 2 of the License, or
33252 + * (at your option) any later version.
33254 + * This program is distributed in the hope that it will be useful,
33255 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33256 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33257 + * GNU General Public License for more details.
33259 + * You should have received a copy of the GNU General Public License
33260 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33264 + * handling xattr functions
33267 +#include <linux/xattr.h>
33270 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
33272 + if (!ignore_flags)
33280 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
33285 +#define cmp(brattr, prefix) do { \
33286 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
33287 + XATTR_##prefix##_PREFIX_LEN)) { \
33288 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
33294 + cmp(SEC, SECURITY);
33295 + cmp(SYS, SYSTEM);
33296 + cmp(TR, TRUSTED);
33300 + if (ignore_flags & AuBrAttr_ICEX_OTH)
33307 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
33309 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
33310 + char *name, char **buf, unsigned int ignore_flags,
33311 + unsigned int verbose)
33315 + struct inode *h_idst;
33317 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
33319 + if (unlikely(err <= 0)) {
33320 + if (err == -ENODATA
33321 + || (err == -EOPNOTSUPP
33322 + && ((ignore_flags & au_xattr_out_of_list)
33323 + || (au_test_nfs_noacl(d_inode(h_src))
33324 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
33326 + XATTR_NAME_POSIX_ACL_DEFAULT))))
33329 + if (err && (verbose || au_debug_test()))
33330 + pr_err("%s, err %d\n", name, err);
33334 + /* unlock it temporary */
33335 + h_idst = d_inode(h_dst);
33336 + mutex_unlock(&h_idst->i_mutex);
33337 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
33338 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33339 + if (unlikely(err)) {
33340 + if (verbose || au_debug_test())
33341 + pr_err("%s, err %d\n", name, err);
33342 + err = au_xattr_ignore(err, name, ignore_flags);
33349 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
33350 + unsigned int verbose)
33352 + int err, unlocked, acl_access, acl_default;
33354 + struct inode *h_isrc, *h_idst;
33355 + char *value, *p, *o, *e;
33357 + /* try stopping to update the source inode while we are referencing */
33358 + /* there should not be the parent-child relationship between them */
33359 + h_isrc = d_inode(h_src);
33360 + h_idst = d_inode(h_dst);
33361 + mutex_unlock(&h_idst->i_mutex);
33362 + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD);
33363 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33366 + /* some filesystems don't list POSIX ACL, for example tmpfs */
33367 + ssz = vfs_listxattr(h_src, NULL, 0);
33369 + if (unlikely(err < 0)) {
33371 + if (err == -ENODATA
33372 + || err == -EOPNOTSUPP)
33373 + err = 0; /* ignore */
33382 + p = kmalloc(ssz, GFP_NOFS);
33384 + if (unlikely(!p))
33386 + err = vfs_listxattr(h_src, p, ssz);
33388 + mutex_unlock(&h_isrc->i_mutex);
33390 + AuDbg("err %d, ssz %zd\n", err, ssz);
33391 + if (unlikely(err < 0))
33399 + while (!err && p < e) {
33400 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
33401 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
33402 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
33403 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
33405 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
33407 + p += strlen(p) + 1;
33410 + ignore_flags |= au_xattr_out_of_list;
33411 + if (!err && !acl_access) {
33412 + err = au_do_cpup_xattr(h_dst, h_src,
33413 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
33414 + ignore_flags, verbose);
33417 + if (!err && !acl_default) {
33418 + err = au_do_cpup_xattr(h_dst, h_src,
33419 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
33420 + ignore_flags, verbose);
33430 + mutex_unlock(&h_isrc->i_mutex);
33435 +/* ---------------------------------------------------------------------- */
33442 +struct au_lgxattr {
33450 + const char *name;
33457 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
33460 + struct path h_path;
33461 + struct super_block *sb;
33463 + sb = dentry->d_sb;
33464 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
33465 + if (unlikely(err))
33467 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
33468 + if (unlikely(err))
33470 + if (unlikely(!h_path.dentry))
33471 + /* illegally overlapped or something */
33472 + goto out_di; /* pretending success */
33474 + /* always topmost entry only */
33475 + switch (arg->type) {
33476 + case AU_XATTR_LIST:
33477 + err = vfs_listxattr(h_path.dentry,
33478 + arg->u.list.list, arg->u.list.size);
33480 + case AU_XATTR_GET:
33481 + err = vfs_getxattr(h_path.dentry,
33482 + arg->u.get.name, arg->u.get.value,
33483 + arg->u.get.size);
33488 + di_read_unlock(dentry, AuLock_IR);
33490 + si_read_unlock(sb);
33496 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
33498 + struct au_lgxattr arg = {
33499 + .type = AU_XATTR_LIST,
33506 + return au_lgxattr(dentry, &arg);
33509 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
33512 + struct au_lgxattr arg = {
33513 + .type = AU_XATTR_GET,
33521 + return au_lgxattr(dentry, &arg);
33524 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
33525 + size_t size, int flags)
33527 + struct au_srxattr arg = {
33528 + .type = AU_XATTR_SET,
33537 + return au_srxattr(dentry, &arg);
33540 +int aufs_removexattr(struct dentry *dentry, const char *name)
33542 + struct au_srxattr arg = {
33543 + .type = AU_XATTR_REMOVE,
33549 + return au_srxattr(dentry, &arg);
33552 +/* ---------------------------------------------------------------------- */
33555 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
33556 + const char *name, size_t name_len, int type)
33558 + return aufs_listxattr(dentry, list, list_size);
33561 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
33562 + size_t size, int type)
33564 + return aufs_getxattr(dentry, name, buffer, size);
33567 +static int au_xattr_set(struct dentry *dentry, const char *name,
33568 + const void *value, size_t size, int flags, int type)
33570 + return aufs_setxattr(dentry, name, value, size, flags);
33573 +static const struct xattr_handler au_xattr_handler = {
33574 + /* no prefix, no flags */
33575 + .list = au_xattr_list,
33576 + .get = au_xattr_get,
33577 + .set = au_xattr_set
33578 + /* why no remove? */
33581 +static const struct xattr_handler *au_xattr_handlers[] = {
33582 + &au_xattr_handler
33585 +void au_xattr_init(struct super_block *sb)
33587 + /* sb->s_xattr = au_xattr_handlers; */
33590 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
33591 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
33592 +++ linux/fs/aufs/xino.c 2015-06-28 17:36:09.028407078 +0200
33595 + * Copyright (C) 2005-2015 Junjiro R. Okajima
33597 + * This program, aufs is free software; you can redistribute it and/or modify
33598 + * it under the terms of the GNU General Public License as published by
33599 + * the Free Software Foundation; either version 2 of the License, or
33600 + * (at your option) any later version.
33602 + * This program is distributed in the hope that it will be useful,
33603 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33604 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33605 + * GNU General Public License for more details.
33607 + * You should have received a copy of the GNU General Public License
33608 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33612 + * external inode number translation table and bitmap
33615 +#include <linux/seq_file.h>
33616 +#include <linux/statfs.h>
33619 +/* todo: unnecessary to support mmap_sem since kernel-space? */
33620 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
33624 + mm_segment_t oldfs;
33631 + oldfs = get_fs();
33632 + set_fs(KERNEL_DS);
33634 + /* todo: signal_pending? */
33635 + err = func(file, buf.u, size, pos);
33636 + } while (err == -EAGAIN || err == -EINTR);
33639 +#if 0 /* reserved for future use */
33641 + fsnotify_access(file->f_path.dentry);
33647 +/* ---------------------------------------------------------------------- */
33649 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
33650 + size_t size, loff_t *pos)
33653 + mm_segment_t oldfs;
33656 + const char __user *u;
33660 + oldfs = get_fs();
33661 + set_fs(KERNEL_DS);
33663 + /* todo: signal_pending? */
33664 + err = func(file, buf.u, size, pos);
33665 + } while (err == -EAGAIN || err == -EINTR);
33668 +#if 0 /* reserved for future use */
33670 + fsnotify_modify(file->f_path.dentry);
33676 +struct do_xino_fwrite_args {
33678 + vfs_writef_t func;
33679 + struct file *file;
33685 +static void call_do_xino_fwrite(void *args)
33687 + struct do_xino_fwrite_args *a = args;
33688 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
33691 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
33692 + size_t size, loff_t *pos)
33696 + /* todo: signal block and no wkq? */
33697 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
33699 + err = do_xino_fwrite(func, file, buf, size, pos);
33703 + * it breaks RLIMIT_FSIZE and normal user's limit,
33704 + * users should care about quota and real 'filesystem full.'
33707 + struct do_xino_fwrite_args args = {
33716 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
33717 + if (unlikely(wkq_err))
33724 +/* ---------------------------------------------------------------------- */
33727 + * create a new xinofile at the same place/path as @base_file.
33729 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
33731 + struct file *file;
33732 + struct dentry *base, *parent;
33733 + struct inode *dir, *delegated;
33734 + struct qstr *name;
33735 + struct path path;
33738 + base = base_file->f_path.dentry;
33739 + parent = base->d_parent; /* dir inode is locked */
33740 + dir = d_inode(parent);
33743 + file = ERR_PTR(-EINVAL);
33744 + name = &base->d_name;
33745 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
33746 + if (IS_ERR(path.dentry)) {
33747 + file = (void *)path.dentry;
33748 + pr_err("%pd lookup err %ld\n",
33749 + base, PTR_ERR(path.dentry));
33753 + /* no need to mnt_want_write() since we call dentry_open() later */
33754 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
33755 + if (unlikely(err)) {
33756 + file = ERR_PTR(err);
33757 + pr_err("%pd create err %d\n", base, err);
33761 + path.mnt = base_file->f_path.mnt;
33762 + file = vfsub_dentry_open(&path,
33763 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
33764 + /* | __FMODE_NONOTIFY */);
33765 + if (IS_ERR(file)) {
33766 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
33770 + delegated = NULL;
33771 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
33772 + if (unlikely(err == -EWOULDBLOCK)) {
33773 + pr_warn("cannot retry for NFSv4 delegation"
33774 + " for an internal unlink\n");
33777 + if (unlikely(err)) {
33778 + pr_err("%pd unlink err %d\n", base, err);
33783 + /* no one can touch copy_src xino */
33784 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
33785 + if (unlikely(err)) {
33786 + pr_err("%pd copy err %d\n", base, err);
33790 + goto out_dput; /* success */
33794 + file = ERR_PTR(err);
33796 + dput(path.dentry);
33801 +struct au_xino_lock_dir {
33802 + struct au_hinode *hdir;
33803 + struct dentry *parent;
33804 + struct mutex *mtx;
33807 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
33808 + struct au_xino_lock_dir *ldir)
33810 + aufs_bindex_t brid, bindex;
33812 + ldir->hdir = NULL;
33814 + brid = au_xino_brid(sb);
33816 + bindex = au_br_index(sb, brid);
33817 + if (bindex >= 0) {
33818 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
33819 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
33821 + ldir->parent = dget_parent(xino->f_path.dentry);
33822 + ldir->mtx = &d_inode(ldir->parent)->i_mutex;
33823 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
33827 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
33830 + au_hn_imtx_unlock(ldir->hdir);
33832 + mutex_unlock(ldir->mtx);
33833 + dput(ldir->parent);
33837 +/* ---------------------------------------------------------------------- */
33839 +/* trucate xino files asynchronously */
33841 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
33844 + unsigned long jiffy;
33846 + aufs_bindex_t bi, bend;
33847 + struct kstatfs *st;
33848 + struct au_branch *br;
33849 + struct file *new_xino, *file;
33850 + struct super_block *h_sb;
33851 + struct au_xino_lock_dir ldir;
33854 + st = kzalloc(sizeof(*st), GFP_NOFS);
33855 + if (unlikely(!st))
33859 + bend = au_sbend(sb);
33860 + if (unlikely(bindex < 0 || bend < bindex))
33862 + br = au_sbr(sb, bindex);
33863 + file = br->br_xino.xi_file;
33867 + err = vfs_statfs(&file->f_path, st);
33868 + if (unlikely(err))
33869 + AuErr1("statfs err %d, ignored\n", err);
33871 + blocks = file_inode(file)->i_blocks;
33872 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33873 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
33875 + au_xino_lock_dir(sb, file, &ldir);
33876 + /* mnt_want_write() is unnecessary here */
33877 + new_xino = au_xino_create2(file, file);
33878 + au_xino_unlock_dir(&ldir);
33879 + err = PTR_ERR(new_xino);
33880 + if (IS_ERR(new_xino)) {
33881 + pr_err("err %d, ignored\n", err);
33886 + br->br_xino.xi_file = new_xino;
33888 + h_sb = au_br_sb(br);
33889 + for (bi = 0; bi <= bend; bi++) {
33890 + if (unlikely(bi == bindex))
33892 + br = au_sbr(sb, bi);
33893 + if (au_br_sb(br) != h_sb)
33896 + fput(br->br_xino.xi_file);
33897 + br->br_xino.xi_file = new_xino;
33898 + get_file(new_xino);
33901 + err = vfs_statfs(&new_xino->f_path, st);
33903 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33904 + bindex, (u64)file_inode(new_xino)->i_blocks,
33905 + st->f_bfree, st->f_blocks);
33906 + if (file_inode(new_xino)->i_blocks < blocks)
33907 + au_sbi(sb)->si_xino_jiffy = jiffy;
33909 + AuErr1("statfs err %d, ignored\n", err);
33917 +struct xino_do_trunc_args {
33918 + struct super_block *sb;
33919 + struct au_branch *br;
33922 +static void xino_do_trunc(void *_args)
33924 + struct xino_do_trunc_args *args = _args;
33925 + struct super_block *sb;
33926 + struct au_branch *br;
33927 + struct inode *dir;
33929 + aufs_bindex_t bindex;
33933 + dir = d_inode(sb->s_root);
33936 + si_noflush_write_lock(sb);
33937 + ii_read_lock_parent(dir);
33938 + bindex = au_br_index(sb, br->br_id);
33939 + err = au_xino_trunc(sb, bindex);
33940 + ii_read_unlock(dir);
33941 + if (unlikely(err))
33942 + pr_warn("err b%d, (%d)\n", bindex, err);
33943 + atomic_dec(&br->br_xino_running);
33944 + atomic_dec(&br->br_count);
33945 + si_write_unlock(sb);
33946 + au_nwt_done(&au_sbi(sb)->si_nowait);
33950 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
33953 + struct kstatfs st;
33954 + struct au_sbinfo *sbinfo;
33956 + /* todo: si_xino_expire and the ratio should be customizable */
33957 + sbinfo = au_sbi(sb);
33958 + if (time_before(jiffies,
33959 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
33962 + /* truncation border */
33963 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
33964 + if (unlikely(err)) {
33965 + AuErr1("statfs err %d, ignored\n", err);
33968 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
33974 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
33976 + struct xino_do_trunc_args *args;
33979 + if (!xino_trunc_test(sb, br))
33982 + if (atomic_inc_return(&br->br_xino_running) > 1)
33985 + /* lock and kfree() will be called in trunc_xino() */
33986 + args = kmalloc(sizeof(*args), GFP_NOFS);
33987 + if (unlikely(!args)) {
33988 + AuErr1("no memory\n");
33992 + atomic_inc(&br->br_count);
33995 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
33997 + return; /* success */
33999 + pr_err("wkq %d\n", wkq_err);
34000 + atomic_dec(&br->br_count);
34005 + atomic_dec(&br->br_xino_running);
34008 +/* ---------------------------------------------------------------------- */
34010 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34011 + ino_t h_ino, ino_t ino)
34017 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34018 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34021 + pos *= sizeof(ino);
34022 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34023 + if (sz == sizeof(ino))
34024 + return 0; /* success */
34026 + AuIOErr("write failed (%zd)\n", sz);
34031 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34032 + * at the position of @h_ino.
34033 + * even if @ino is zero, it is written to the xinofile and means no entry.
34034 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34035 + * try truncating it.
34037 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34041 + unsigned int mnt_flags;
34042 + struct au_branch *br;
34044 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34045 + || ((loff_t)-1) > 0);
34046 + SiMustAnyLock(sb);
34048 + mnt_flags = au_mntflags(sb);
34049 + if (!au_opt_test(mnt_flags, XINO))
34052 + br = au_sbr(sb, bindex);
34053 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34056 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34057 + && au_test_fs_trunc_xino(au_br_sb(br)))
34058 + xino_try_trunc(sb, br);
34059 + return 0; /* success */
34062 + AuIOErr("write failed (%d)\n", err);
34066 +/* ---------------------------------------------------------------------- */
34068 +/* aufs inode number bitmap */
34070 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
34071 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
34075 + AuDebugOn(bit < 0 || page_bits <= bit);
34076 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
34080 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
34082 + AuDebugOn(ino < AUFS_FIRST_INO);
34083 + ino -= AUFS_FIRST_INO;
34084 + *pindex = ino / page_bits;
34085 + *bit = ino % page_bits;
34088 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
34093 + struct au_sbinfo *sbinfo;
34094 + struct file *xib;
34095 + unsigned long *p;
34097 + sbinfo = au_sbi(sb);
34098 + MtxMustLock(&sbinfo->si_xib_mtx);
34099 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
34100 + || !au_opt_test(sbinfo->si_mntflags, XINO));
34102 + if (pindex == sbinfo->si_xib_last_pindex)
34105 + xib = sbinfo->si_xib;
34106 + p = sbinfo->si_xib_buf;
34107 + pos = sbinfo->si_xib_last_pindex;
34108 + pos *= PAGE_SIZE;
34109 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34110 + if (unlikely(sz != PAGE_SIZE))
34114 + pos *= PAGE_SIZE;
34115 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
34116 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
34118 + memset(p, 0, PAGE_SIZE);
34119 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34121 + if (sz == PAGE_SIZE) {
34122 + sbinfo->si_xib_last_pindex = pindex;
34123 + return 0; /* success */
34127 + AuIOErr1("write failed (%zd)\n", sz);
34134 +/* ---------------------------------------------------------------------- */
34136 +static void au_xib_clear_bit(struct inode *inode)
34139 + unsigned long pindex;
34140 + struct super_block *sb;
34141 + struct au_sbinfo *sbinfo;
34143 + AuDebugOn(inode->i_nlink);
34145 + sb = inode->i_sb;
34146 + xib_calc_bit(inode->i_ino, &pindex, &bit);
34147 + AuDebugOn(page_bits <= bit);
34148 + sbinfo = au_sbi(sb);
34149 + mutex_lock(&sbinfo->si_xib_mtx);
34150 + err = xib_pindex(sb, pindex);
34152 + clear_bit(bit, sbinfo->si_xib_buf);
34153 + sbinfo->si_xib_next_bit = bit;
34155 + mutex_unlock(&sbinfo->si_xib_mtx);
34158 +/* for s_op->delete_inode() */
34159 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
34162 + unsigned int mnt_flags;
34163 + aufs_bindex_t bindex, bend, bi;
34164 + unsigned char try_trunc;
34165 + struct au_iinfo *iinfo;
34166 + struct super_block *sb;
34167 + struct au_hinode *hi;
34168 + struct inode *h_inode;
34169 + struct au_branch *br;
34170 + vfs_writef_t xwrite;
34172 + sb = inode->i_sb;
34173 + mnt_flags = au_mntflags(sb);
34174 + if (!au_opt_test(mnt_flags, XINO)
34175 + || inode->i_ino == AUFS_ROOT_INO)
34179 + au_xigen_inc(inode);
34180 + au_xib_clear_bit(inode);
34183 + iinfo = au_ii(inode);
34187 + bindex = iinfo->ii_bstart;
34191 + xwrite = au_sbi(sb)->si_xwrite;
34192 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
34193 + hi = iinfo->ii_hinode + bindex;
34194 + bend = iinfo->ii_bend;
34195 + for (; bindex <= bend; bindex++, hi++) {
34196 + h_inode = hi->hi_inode;
34198 + || (!unlinked && h_inode->i_nlink))
34201 + /* inode may not be revalidated */
34202 + bi = au_br_index(sb, hi->hi_id);
34206 + br = au_sbr(sb, bi);
34207 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
34208 + h_inode->i_ino, /*ino*/0);
34209 + if (!err && try_trunc
34210 + && au_test_fs_trunc_xino(au_br_sb(br)))
34211 + xino_try_trunc(sb, br);
34215 +/* get an unused inode number from bitmap */
34216 +ino_t au_xino_new_ino(struct super_block *sb)
34219 + unsigned long *p, pindex, ul, pend;
34220 + struct au_sbinfo *sbinfo;
34221 + struct file *file;
34222 + int free_bit, err;
34224 + if (!au_opt_test(au_mntflags(sb), XINO))
34225 + return iunique(sb, AUFS_FIRST_INO);
34227 + sbinfo = au_sbi(sb);
34228 + mutex_lock(&sbinfo->si_xib_mtx);
34229 + p = sbinfo->si_xib_buf;
34230 + free_bit = sbinfo->si_xib_next_bit;
34231 + if (free_bit < page_bits && !test_bit(free_bit, p))
34232 + goto out; /* success */
34233 + free_bit = find_first_zero_bit(p, page_bits);
34234 + if (free_bit < page_bits)
34235 + goto out; /* success */
34237 + pindex = sbinfo->si_xib_last_pindex;
34238 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
34239 + err = xib_pindex(sb, ul);
34240 + if (unlikely(err))
34242 + free_bit = find_first_zero_bit(p, page_bits);
34243 + if (free_bit < page_bits)
34244 + goto out; /* success */
34247 + file = sbinfo->si_xib;
34248 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
34249 + for (ul = pindex + 1; ul <= pend; ul++) {
34250 + err = xib_pindex(sb, ul);
34251 + if (unlikely(err))
34253 + free_bit = find_first_zero_bit(p, page_bits);
34254 + if (free_bit < page_bits)
34255 + goto out; /* success */
34260 + set_bit(free_bit, p);
34261 + sbinfo->si_xib_next_bit = free_bit + 1;
34262 + pindex = sbinfo->si_xib_last_pindex;
34263 + mutex_unlock(&sbinfo->si_xib_mtx);
34264 + ino = xib_calc_ino(pindex, free_bit);
34265 + AuDbg("i%lu\n", (unsigned long)ino);
34268 + mutex_unlock(&sbinfo->si_xib_mtx);
34274 + * read @ino from xinofile for the specified branch{@sb, @bindex}
34275 + * at the position of @h_ino.
34276 + * if @ino does not exist and @do_new is true, get new one.
34278 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34284 + struct file *file;
34285 + struct au_sbinfo *sbinfo;
34288 + if (!au_opt_test(au_mntflags(sb), XINO))
34289 + return 0; /* no xino */
34292 + sbinfo = au_sbi(sb);
34294 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
34295 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34298 + pos *= sizeof(*ino);
34300 + file = au_sbr(sb, bindex)->br_xino.xi_file;
34301 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
34302 + return 0; /* no ino */
34304 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
34305 + if (sz == sizeof(*ino))
34306 + return 0; /* success */
34309 + if (unlikely(sz >= 0)) {
34311 + AuIOErr("xino read error (%zd)\n", sz);
34317 +/* ---------------------------------------------------------------------- */
34319 +/* create and set a new xino file */
34321 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
34323 + struct file *file;
34324 + struct dentry *h_parent, *d;
34325 + struct inode *h_dir, *inode;
34329 + * at mount-time, and the xino file is the default path,
34330 + * hnotify is disabled so we have no notify events to ignore.
34331 + * when a user specified the xino, we cannot get au_hdir to be ignored.
34333 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34334 + /* | __FMODE_NONOTIFY */,
34335 + S_IRUGO | S_IWUGO);
34336 + if (IS_ERR(file)) {
34338 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
34342 + /* keep file count */
34344 + inode = file_inode(file);
34345 + h_parent = dget_parent(file->f_path.dentry);
34346 + h_dir = d_inode(h_parent);
34347 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
34348 + /* mnt_want_write() is unnecessary here */
34349 + /* no delegation since it is just created */
34350 + if (inode->i_nlink)
34351 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
34353 + mutex_unlock(&h_dir->i_mutex);
34355 + if (unlikely(err)) {
34357 + pr_err("unlink %s(%d)\n", fname, err);
34362 + d = file->f_path.dentry;
34363 + if (unlikely(sb == d->d_sb)) {
34365 + pr_err("%s must be outside\n", fname);
34368 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
34370 + pr_err("xino doesn't support %s(%s)\n",
34371 + fname, au_sbtype(d->d_sb));
34374 + return file; /* success */
34378 + file = ERR_PTR(err);
34383 + * find another branch who is on the same filesystem of the specified
34384 + * branch{@btgt}. search until @bend.
34386 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
34387 + aufs_bindex_t bend)
34389 + aufs_bindex_t bindex;
34390 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
34392 + for (bindex = 0; bindex < btgt; bindex++)
34393 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34395 + for (bindex++; bindex <= bend; bindex++)
34396 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34401 +/* ---------------------------------------------------------------------- */
34404 + * initialize the xinofile for the specified branch @br
34405 + * at the place/path where @base_file indicates.
34406 + * test whether another branch is on the same filesystem or not,
34407 + * if @do_test is true.
34409 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
34410 + struct file *base_file, int do_test)
34414 + aufs_bindex_t bend, bindex;
34415 + struct au_branch *shared_br, *b;
34416 + struct file *file;
34417 + struct super_block *tgt_sb;
34419 + shared_br = NULL;
34420 + bend = au_sbend(sb);
34422 + tgt_sb = au_br_sb(br);
34423 + for (bindex = 0; bindex <= bend; bindex++) {
34424 + b = au_sbr(sb, bindex);
34425 + if (tgt_sb == au_br_sb(b)) {
34432 + if (!shared_br || !shared_br->br_xino.xi_file) {
34433 + struct au_xino_lock_dir ldir;
34435 + au_xino_lock_dir(sb, base_file, &ldir);
34436 + /* mnt_want_write() is unnecessary here */
34437 + file = au_xino_create2(base_file, NULL);
34438 + au_xino_unlock_dir(&ldir);
34439 + err = PTR_ERR(file);
34440 + if (IS_ERR(file))
34442 + br->br_xino.xi_file = file;
34444 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
34445 + get_file(br->br_xino.xi_file);
34448 + ino = AUFS_ROOT_INO;
34449 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34451 + if (unlikely(err)) {
34452 + fput(br->br_xino.xi_file);
34453 + br->br_xino.xi_file = NULL;
34460 +/* ---------------------------------------------------------------------- */
34462 +/* trucate a xino bitmap file */
34465 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
34469 + unsigned long pindex;
34470 + loff_t pos, pend;
34471 + struct au_sbinfo *sbinfo;
34472 + vfs_readf_t func;
34474 + unsigned long *p;
34477 + sbinfo = au_sbi(sb);
34478 + MtxMustLock(&sbinfo->si_xib_mtx);
34479 + p = sbinfo->si_xib_buf;
34480 + func = sbinfo->si_xread;
34481 + pend = vfsub_f_size_read(file);
34483 + while (pos < pend) {
34484 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
34486 + if (unlikely(sz <= 0))
34490 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
34491 + if (unlikely(*ino < AUFS_FIRST_INO))
34494 + xib_calc_bit(*ino, &pindex, &bit);
34495 + AuDebugOn(page_bits <= bit);
34496 + err = xib_pindex(sb, pindex);
34508 +static int xib_restore(struct super_block *sb)
34511 + aufs_bindex_t bindex, bend;
34515 + page = (void *)__get_free_page(GFP_NOFS);
34516 + if (unlikely(!page))
34520 + bend = au_sbend(sb);
34521 + for (bindex = 0; !err && bindex <= bend; bindex++)
34522 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
34523 + err = do_xib_restore
34524 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
34526 + AuDbg("b%d\n", bindex);
34527 + free_page((unsigned long)page);
34533 +int au_xib_trunc(struct super_block *sb)
34538 + struct au_xino_lock_dir ldir;
34539 + struct au_sbinfo *sbinfo;
34540 + unsigned long *p;
34541 + struct file *file;
34543 + SiMustWriteLock(sb);
34546 + sbinfo = au_sbi(sb);
34547 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
34550 + file = sbinfo->si_xib;
34551 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
34554 + au_xino_lock_dir(sb, file, &ldir);
34555 + /* mnt_want_write() is unnecessary here */
34556 + file = au_xino_create2(sbinfo->si_xib, NULL);
34557 + au_xino_unlock_dir(&ldir);
34558 + err = PTR_ERR(file);
34559 + if (IS_ERR(file))
34561 + fput(sbinfo->si_xib);
34562 + sbinfo->si_xib = file;
34564 + p = sbinfo->si_xib_buf;
34565 + memset(p, 0, PAGE_SIZE);
34567 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
34568 + if (unlikely(sz != PAGE_SIZE)) {
34570 + AuIOErr("err %d\n", err);
34576 + mutex_lock(&sbinfo->si_xib_mtx);
34577 + /* mnt_want_write() is unnecessary here */
34578 + err = xib_restore(sb);
34579 + mutex_unlock(&sbinfo->si_xib_mtx);
34585 +/* ---------------------------------------------------------------------- */
34588 + * xino mount option handlers
34592 +static void xino_clear_xib(struct super_block *sb)
34594 + struct au_sbinfo *sbinfo;
34596 + SiMustWriteLock(sb);
34598 + sbinfo = au_sbi(sb);
34599 + sbinfo->si_xread = NULL;
34600 + sbinfo->si_xwrite = NULL;
34601 + if (sbinfo->si_xib)
34602 + fput(sbinfo->si_xib);
34603 + sbinfo->si_xib = NULL;
34604 + free_page((unsigned long)sbinfo->si_xib_buf);
34605 + sbinfo->si_xib_buf = NULL;
34608 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
34612 + struct au_sbinfo *sbinfo;
34613 + struct file *file;
34615 + SiMustWriteLock(sb);
34617 + sbinfo = au_sbi(sb);
34618 + file = au_xino_create2(base, sbinfo->si_xib);
34619 + err = PTR_ERR(file);
34620 + if (IS_ERR(file))
34622 + if (sbinfo->si_xib)
34623 + fput(sbinfo->si_xib);
34624 + sbinfo->si_xib = file;
34625 + sbinfo->si_xread = vfs_readf(file);
34626 + sbinfo->si_xwrite = vfs_writef(file);
34629 + if (!sbinfo->si_xib_buf)
34630 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
34631 + if (unlikely(!sbinfo->si_xib_buf))
34634 + sbinfo->si_xib_last_pindex = 0;
34635 + sbinfo->si_xib_next_bit = 0;
34636 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
34638 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
34639 + PAGE_SIZE, &pos);
34640 + if (unlikely(err != PAGE_SIZE))
34644 + goto out; /* success */
34647 + free_page((unsigned long)sbinfo->si_xib_buf);
34648 + sbinfo->si_xib_buf = NULL;
34652 + fput(sbinfo->si_xib);
34653 + sbinfo->si_xib = NULL;
34654 + sbinfo->si_xread = NULL;
34655 + sbinfo->si_xwrite = NULL;
34660 +/* xino for each branch */
34661 +static void xino_clear_br(struct super_block *sb)
34663 + aufs_bindex_t bindex, bend;
34664 + struct au_branch *br;
34666 + bend = au_sbend(sb);
34667 + for (bindex = 0; bindex <= bend; bindex++) {
34668 + br = au_sbr(sb, bindex);
34669 + if (!br || !br->br_xino.xi_file)
34672 + fput(br->br_xino.xi_file);
34673 + br->br_xino.xi_file = NULL;
34677 +static int au_xino_set_br(struct super_block *sb, struct file *base)
34681 + aufs_bindex_t bindex, bend, bshared;
34683 + struct file *old, *new;
34685 + struct au_branch *br;
34686 + struct inode *inode;
34687 + vfs_writef_t writef;
34689 + SiMustWriteLock(sb);
34692 + bend = au_sbend(sb);
34693 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
34694 + if (unlikely(!fpair))
34697 + inode = d_inode(sb->s_root);
34698 + ino = AUFS_ROOT_INO;
34699 + writef = au_sbi(sb)->si_xwrite;
34700 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34701 + br = au_sbr(sb, bindex);
34702 + bshared = is_sb_shared(sb, bindex, bindex - 1);
34703 + if (bshared >= 0) {
34704 + /* shared xino */
34705 + *p = fpair[bshared];
34706 + get_file(p->new);
34711 + p->old = br->br_xino.xi_file;
34712 + p->new = au_xino_create2(base, br->br_xino.xi_file);
34713 + err = PTR_ERR(p->new);
34714 + if (IS_ERR(p->new)) {
34720 + err = au_xino_do_write(writef, p->new,
34721 + au_h_iptr(inode, bindex)->i_ino, ino);
34722 + if (unlikely(err))
34726 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34727 + br = au_sbr(sb, bindex);
34728 + if (br->br_xino.xi_file)
34729 + fput(br->br_xino.xi_file);
34730 + get_file(p->new);
34731 + br->br_xino.xi_file = p->new;
34735 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
34745 +void au_xino_clr(struct super_block *sb)
34747 + struct au_sbinfo *sbinfo;
34749 + au_xigen_clr(sb);
34750 + xino_clear_xib(sb);
34751 + xino_clear_br(sb);
34752 + sbinfo = au_sbi(sb);
34753 + /* lvalue, do not call au_mntflags() */
34754 + au_opt_clr(sbinfo->si_mntflags, XINO);
34757 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
34760 + struct dentry *parent, *cur_parent;
34761 + struct qstr *dname, *cur_name;
34762 + struct file *cur_xino;
34763 + struct inode *dir;
34764 + struct au_sbinfo *sbinfo;
34766 + SiMustWriteLock(sb);
34769 + sbinfo = au_sbi(sb);
34770 + parent = dget_parent(xino->file->f_path.dentry);
34773 + dname = &xino->file->f_path.dentry->d_name;
34774 + cur_xino = sbinfo->si_xib;
34776 + cur_parent = dget_parent(cur_xino->f_path.dentry);
34777 + cur_name = &cur_xino->f_path.dentry->d_name;
34778 + skip = (cur_parent == parent
34779 + && au_qstreq(dname, cur_name));
34780 + dput(cur_parent);
34786 + au_opt_set(sbinfo->si_mntflags, XINO);
34787 + dir = d_inode(parent);
34788 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
34789 + /* mnt_want_write() is unnecessary here */
34790 + err = au_xino_set_xib(sb, xino->file);
34792 + err = au_xigen_set(sb, xino->file);
34794 + err = au_xino_set_br(sb, xino->file);
34795 + mutex_unlock(&dir->i_mutex);
34797 + goto out; /* success */
34800 + AuIOErr("failed creating xino(%d).\n", err);
34801 + au_xigen_clr(sb);
34802 + xino_clear_xib(sb);
34809 +/* ---------------------------------------------------------------------- */
34812 + * create a xinofile at the default place/path.
34814 +struct file *au_xino_def(struct super_block *sb)
34816 + struct file *file;
34818 + struct au_branch *br;
34819 + struct super_block *h_sb;
34820 + struct path path;
34821 + aufs_bindex_t bend, bindex, bwr;
34824 + bend = au_sbend(sb);
34826 + for (bindex = 0; bindex <= bend; bindex++) {
34827 + br = au_sbr(sb, bindex);
34828 + if (au_br_writable(br->br_perm)
34829 + && !au_test_fs_bad_xino(au_br_sb(br))) {
34836 + file = ERR_PTR(-ENOMEM);
34837 + page = (void *)__get_free_page(GFP_NOFS);
34838 + if (unlikely(!page))
34840 + path.mnt = au_br_mnt(br);
34841 + path.dentry = au_h_dptr(sb->s_root, bwr);
34842 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
34843 + file = (void *)p;
34844 + if (!IS_ERR(p)) {
34845 + strcat(p, "/" AUFS_XINO_FNAME);
34846 + AuDbg("%s\n", p);
34847 + file = au_xino_create(sb, p, /*silent*/0);
34848 + if (!IS_ERR(file))
34849 + au_xino_brid_set(sb, br->br_id);
34851 + free_page((unsigned long)page);
34853 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
34854 + if (IS_ERR(file))
34856 + h_sb = file->f_path.dentry->d_sb;
34857 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
34858 + pr_err("xino doesn't support %s(%s)\n",
34859 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
34861 + file = ERR_PTR(-EINVAL);
34863 + if (!IS_ERR(file))
34864 + au_xino_brid_set(sb, -1);
34871 +/* ---------------------------------------------------------------------- */
34873 +int au_xino_path(struct seq_file *seq, struct file *file)
34877 + err = au_seq_path(seq, &file->f_path);
34878 + if (unlikely(err < 0))
34882 +#define Deleted "\\040(deleted)"
34883 + seq->count -= sizeof(Deleted) - 1;
34884 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
34885 + sizeof(Deleted) - 1));
34891 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
34892 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
34893 +++ linux/include/uapi/linux/aufs_type.h 2015-06-28 17:36:09.028407078 +0200
34896 + * Copyright (C) 2005-2015 Junjiro R. Okajima
34898 + * This program, aufs is free software; you can redistribute it and/or modify
34899 + * it under the terms of the GNU General Public License as published by
34900 + * the Free Software Foundation; either version 2 of the License, or
34901 + * (at your option) any later version.
34903 + * This program is distributed in the hope that it will be useful,
34904 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34905 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34906 + * GNU General Public License for more details.
34908 + * You should have received a copy of the GNU General Public License
34909 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34912 +#ifndef __AUFS_TYPE_H__
34913 +#define __AUFS_TYPE_H__
34915 +#define AUFS_NAME "aufs"
34919 + * define it before including all other headers.
34920 + * sched.h may use pr_* macros before defining "current", so define the
34921 + * no-current version first, and re-define later.
34923 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
34924 +#include <linux/sched.h>
34926 +#define pr_fmt(fmt) \
34927 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
34928 + (int)sizeof(current->comm), current->comm, current->pid
34930 +#include <stdint.h>
34931 +#include <sys/types.h>
34932 +#endif /* __KERNEL__ */
34934 +#include <linux/limits.h>
34936 +#define AUFS_VERSION "4.x-rcN-20150622"
34938 +/* todo? move this to linux-2.6.19/include/magic.h */
34939 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
34941 +/* ---------------------------------------------------------------------- */
34943 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
34944 +typedef int8_t aufs_bindex_t;
34945 +#define AUFS_BRANCH_MAX 127
34947 +typedef int16_t aufs_bindex_t;
34948 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
34949 +#define AUFS_BRANCH_MAX 511
34950 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
34951 +#define AUFS_BRANCH_MAX 1023
34952 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
34953 +#define AUFS_BRANCH_MAX 32767
34958 +#ifndef AUFS_BRANCH_MAX
34959 +#error unknown CONFIG_AUFS_BRANCH_MAX value
34961 +#endif /* __KERNEL__ */
34963 +/* ---------------------------------------------------------------------- */
34965 +#define AUFS_FSTYPE AUFS_NAME
34967 +#define AUFS_ROOT_INO 2
34968 +#define AUFS_FIRST_INO 11
34970 +#define AUFS_WH_PFX ".wh."
34971 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
34972 +#define AUFS_WH_TMP_LEN 4
34973 +/* a limit for rmdir/rename a dir and copyup */
34974 +#define AUFS_MAX_NAMELEN (NAME_MAX \
34975 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
34977 + - AUFS_WH_TMP_LEN) /* hex */
34978 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
34979 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
34980 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
34981 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
34982 +#define AUFS_DIRWH_DEF 3
34983 +#define AUFS_RDCACHE_DEF 10 /* seconds */
34984 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
34985 +#define AUFS_RDBLK_DEF 512 /* bytes */
34986 +#define AUFS_RDHASH_DEF 32
34987 +#define AUFS_WKQ_NAME AUFS_NAME "d"
34988 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
34989 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
34990 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
34991 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
34993 +/* pseudo-link maintenace under /proc */
34994 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
34995 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
34996 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
34998 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
34999 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
35001 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
35002 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
35003 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
35005 +/* doubly whiteouted */
35006 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
35007 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
35008 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
35010 +/* branch permissions and attributes */
35011 +#define AUFS_BRPERM_RW "rw"
35012 +#define AUFS_BRPERM_RO "ro"
35013 +#define AUFS_BRPERM_RR "rr"
35014 +#define AUFS_BRATTR_COO_REG "coo_reg"
35015 +#define AUFS_BRATTR_COO_ALL "coo_all"
35016 +#define AUFS_BRATTR_FHSM "fhsm"
35017 +#define AUFS_BRATTR_UNPIN "unpin"
35018 +#define AUFS_BRATTR_ICEX "icex"
35019 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
35020 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
35021 +#define AUFS_BRATTR_ICEX_TR "icextr"
35022 +#define AUFS_BRATTR_ICEX_USR "icexusr"
35023 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
35024 +#define AUFS_BRRATTR_WH "wh"
35025 +#define AUFS_BRWATTR_NLWH "nolwh"
35026 +#define AUFS_BRWATTR_MOO "moo"
35028 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
35029 +#define AuBrPerm_RO (1 << 1) /* readonly */
35030 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
35031 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
35033 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
35034 +#define AuBrAttr_COO_ALL (1 << 4)
35035 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
35037 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
35038 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
35039 + branch. meaningless since
35040 + linux-3.18-rc1 */
35042 +/* ignore error in copying XATTR */
35043 +#define AuBrAttr_ICEX_SEC (1 << 7)
35044 +#define AuBrAttr_ICEX_SYS (1 << 8)
35045 +#define AuBrAttr_ICEX_TR (1 << 9)
35046 +#define AuBrAttr_ICEX_USR (1 << 10)
35047 +#define AuBrAttr_ICEX_OTH (1 << 11)
35048 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
35049 + | AuBrAttr_ICEX_SYS \
35050 + | AuBrAttr_ICEX_TR \
35051 + | AuBrAttr_ICEX_USR \
35052 + | AuBrAttr_ICEX_OTH)
35054 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
35055 +#define AuBrRAttr_Mask AuBrRAttr_WH
35057 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
35058 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
35059 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
35061 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
35063 +/* #warning test userspace */
35065 +#ifndef CONFIG_AUFS_FHSM
35066 +#undef AuBrAttr_FHSM
35067 +#define AuBrAttr_FHSM 0
35069 +#ifndef CONFIG_AUFS_XATTR
35070 +#undef AuBrAttr_ICEX
35071 +#define AuBrAttr_ICEX 0
35072 +#undef AuBrAttr_ICEX_SEC
35073 +#define AuBrAttr_ICEX_SEC 0
35074 +#undef AuBrAttr_ICEX_SYS
35075 +#define AuBrAttr_ICEX_SYS 0
35076 +#undef AuBrAttr_ICEX_TR
35077 +#define AuBrAttr_ICEX_TR 0
35078 +#undef AuBrAttr_ICEX_USR
35079 +#define AuBrAttr_ICEX_USR 0
35080 +#undef AuBrAttr_ICEX_OTH
35081 +#define AuBrAttr_ICEX_OTH 0
35085 +/* the longest combination */
35086 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
35087 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
35088 + "+" AUFS_BRATTR_COO_REG \
35089 + "+" AUFS_BRATTR_FHSM \
35090 + "+" AUFS_BRATTR_UNPIN \
35091 + "+" AUFS_BRATTR_ICEX_SEC \
35092 + "+" AUFS_BRATTR_ICEX_SYS \
35093 + "+" AUFS_BRATTR_ICEX_USR \
35094 + "+" AUFS_BRATTR_ICEX_OTH \
35095 + "+" AUFS_BRWATTR_NLWH)
35098 + char a[AuBrPermStrSz];
35099 +} au_br_perm_str_t;
35101 +static inline int au_br_writable(int brperm)
35103 + return brperm & AuBrPerm_RW;
35106 +static inline int au_br_whable(int brperm)
35108 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
35111 +static inline int au_br_wh_linkable(int brperm)
35113 + return !(brperm & AuBrWAttr_NoLinkWH);
35116 +static inline int au_br_cmoo(int brperm)
35118 + return brperm & AuBrAttr_CMOO_Mask;
35121 +static inline int au_br_fhsm(int brperm)
35123 + return brperm & AuBrAttr_FHSM;
35126 +/* ---------------------------------------------------------------------- */
35130 + /* readdir in userspace */
35134 + AuCtl_WBR_FD, /* pathconf wrapper */
35135 + AuCtl_IBUSY, /* busy inode */
35136 + AuCtl_MVDOWN, /* move-down */
35137 + AuCtl_BR, /* info about branches */
35138 + AuCtl_FHSM_FD /* connection for fhsm */
35141 +/* borrowed from linux/include/linux/kernel.h */
35143 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
35144 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
35147 +/* borrowed from linux/include/linux/compiler-gcc3.h */
35149 +#define __aligned(x) __attribute__((aligned(x)))
35154 +#define __packed __attribute__((packed))
35158 +struct au_rdu_cookie {
35163 + uint32_t generation;
35166 +struct au_rdu_ent {
35175 +static inline int au_rdu_len(int nlen)
35177 + /* include the terminating NULL */
35178 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
35179 + sizeof(uint64_t));
35182 +union au_rdu_ent_ul {
35183 + struct au_rdu_ent __user *e;
35195 + uint64_t sz; /* AuCtl_RDU */
35196 + uint64_t nent; /* AuCtl_RDU_INO */
35198 + union au_rdu_ent_ul ent;
35199 + uint16_t verify[AufsCtlRduV_End];
35201 + /* input/output */
35205 + union au_rdu_ent_ul tail;
35206 + /* number of entries which were added in a single call */
35211 + struct au_rdu_cookie cookie;
35214 +/* ---------------------------------------------------------------------- */
35216 +struct aufs_wbr_fd {
35221 +/* ---------------------------------------------------------------------- */
35223 +struct aufs_ibusy {
35224 + uint64_t ino, h_ino;
35228 +/* ---------------------------------------------------------------------- */
35230 +/* error code for move-down */
35231 +/* the actual message strings are implemented in aufs-util.git */
35233 + EAU_MVDOWN_OPAQUE = 1,
35234 + EAU_MVDOWN_WHITEOUT,
35235 + EAU_MVDOWN_UPPER,
35236 + EAU_MVDOWN_BOTTOM,
35237 + EAU_MVDOWN_NOUPPER,
35238 + EAU_MVDOWN_NOLOWERBR,
35242 +/* flags for move-down */
35243 +#define AUFS_MVDOWN_DMSG 1
35244 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
35245 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
35246 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
35247 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
35248 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
35249 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
35250 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
35251 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
35252 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
35253 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
35254 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
35255 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
35257 +/* index for move-down */
35259 + AUFS_MVDOWN_UPPER,
35260 + AUFS_MVDOWN_LOWER,
35261 + AUFS_MVDOWN_NARRAY
35265 + * additional info of move-down
35266 + * number of free blocks and inodes.
35267 + * subset of struct kstatfs, but smaller and always 64bit.
35269 +struct aufs_stfs {
35270 + uint64_t f_blocks;
35271 + uint64_t f_bavail;
35272 + uint64_t f_files;
35273 + uint64_t f_ffree;
35276 +struct aufs_stbr {
35277 + int16_t brid; /* optional input */
35278 + int16_t bindex; /* output */
35279 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
35282 +struct aufs_mvdown {
35283 + uint32_t flags; /* input/output */
35284 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
35285 + int8_t au_errno; /* output */
35288 +/* ---------------------------------------------------------------------- */
35290 +union aufs_brinfo {
35291 + /* PATH_MAX may differ between kernel-space and user-space */
35292 + char _spacer[4096];
35300 +/* ---------------------------------------------------------------------- */
35302 +#define AuCtlType 'A'
35303 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
35304 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
35305 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
35306 + struct aufs_wbr_fd)
35307 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
35308 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
35309 + struct aufs_mvdown)
35310 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
35311 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
35313 +#endif /* __AUFS_TYPE_H__ */
35314 aufs4.x-rcN loopback patch
35316 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
35317 index 0160952..866f8e2 100644
35318 --- a/drivers/block/loop.c
35319 +++ b/drivers/block/loop.c
35320 @@ -419,7 +419,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
35323 struct switch_request {
35324 - struct file *file;
35325 + struct file *file, *virt_file;
35326 struct completion wait;
35329 @@ -439,6 +439,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35330 mapping = file->f_mapping;
35331 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
35332 lo->lo_backing_file = file;
35333 + lo->lo_backing_virt_file = p->virt_file;
35334 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
35335 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
35336 lo->old_gfp_mask = mapping_gfp_mask(mapping);
35337 @@ -450,11 +451,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35338 * First it needs to flush existing IO, it does this by sending a magic
35339 * BIO down the pipe. The completion of this BIO does the actual switch.
35341 -static int loop_switch(struct loop_device *lo, struct file *file)
35342 +static int loop_switch(struct loop_device *lo, struct file *file,
35343 + struct file *virt_file)
35345 struct switch_request w;
35348 + w.virt_file = virt_file;
35350 /* freeze queue and wait for completion of scheduled requests */
35351 blk_mq_freeze_queue(lo->lo_queue);
35352 @@ -473,7 +476,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
35354 static int loop_flush(struct loop_device *lo)
35356 - return loop_switch(lo, NULL);
35357 + return loop_switch(lo, NULL, NULL);
35360 +static struct file *loop_real_file(struct file *file)
35362 + struct file *f = NULL;
35364 + if (file->f_path.dentry->d_sb->s_op->real_loop)
35365 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
35370 @@ -488,6 +500,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35373 struct file *file, *old_file;
35374 + struct file *f, *virt_file = NULL, *old_virt_file;
35375 struct inode *inode;
35378 @@ -504,9 +517,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35382 + f = loop_real_file(file);
35384 + virt_file = file;
35389 inode = file->f_mapping->host;
35390 old_file = lo->lo_backing_file;
35391 + old_virt_file = lo->lo_backing_virt_file;
35395 @@ -518,17 +538,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35398 /* and ... switch */
35399 - error = loop_switch(lo, file);
35400 + error = loop_switch(lo, file, virt_file);
35405 + if (old_virt_file)
35406 + fput(old_virt_file);
35407 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
35408 ioctl_by_bdev(bdev, BLKRRPART, 0);
35418 @@ -689,7 +713,7 @@ static void loop_config_discard(struct loop_device *lo)
35419 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35420 struct block_device *bdev, unsigned int arg)
35422 - struct file *file, *f;
35423 + struct file *file, *f, *virt_file = NULL;
35424 struct inode *inode;
35425 struct address_space *mapping;
35426 unsigned lo_blocksize;
35427 @@ -704,6 +728,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35431 + f = loop_real_file(file);
35433 + virt_file = file;
35439 if (lo->lo_state != Lo_unbound)
35440 @@ -752,6 +782,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35441 lo->lo_device = bdev;
35442 lo->lo_flags = lo_flags;
35443 lo->lo_backing_file = file;
35444 + lo->lo_backing_virt_file = virt_file;
35445 lo->transfer = NULL;
35447 lo->lo_sizelimit = 0;
35448 @@ -783,6 +814,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35455 /* This is safe: open() is still holding a reference. */
35456 module_put(THIS_MODULE);
35457 @@ -829,6 +862,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
35458 static int loop_clr_fd(struct loop_device *lo)
35460 struct file *filp = lo->lo_backing_file;
35461 + struct file *virt_filp = lo->lo_backing_virt_file;
35462 gfp_t gfp = lo->old_gfp_mask;
35463 struct block_device *bdev = lo->lo_device;
35465 @@ -857,6 +891,7 @@ static int loop_clr_fd(struct loop_device *lo)
35466 spin_lock_irq(&lo->lo_lock);
35467 lo->lo_state = Lo_rundown;
35468 lo->lo_backing_file = NULL;
35469 + lo->lo_backing_virt_file = NULL;
35470 spin_unlock_irq(&lo->lo_lock);
35472 loop_release_xfer(lo);
35473 @@ -898,6 +933,8 @@ static int loop_clr_fd(struct loop_device *lo)
35474 * bd_mutex which is usually taken before lo_ctl_mutex.
35482 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
35483 index 301c27f..df84aa0 100644
35484 --- a/drivers/block/loop.h
35485 +++ b/drivers/block/loop.h
35486 @@ -46,7 +46,7 @@ struct loop_device {
35487 int (*ioctl)(struct loop_device *, int cmd,
35488 unsigned long arg);
35490 - struct file * lo_backing_file;
35491 + struct file * lo_backing_file, *lo_backing_virt_file;
35492 struct block_device *lo_device;
35493 unsigned lo_blocksize;
35495 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
35496 index 91c2ce7..d4ee5a7 100644
35497 --- a/fs/aufs/f_op.c
35498 +++ b/fs/aufs/f_op.c
35499 @@ -389,7 +389,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
35500 if (IS_ERR(h_file))
35503 - if (au_test_loopback_kthread()) {
35504 + if (0 && au_test_loopback_kthread()) {
35505 au_warn_loopback(h_file->f_path.dentry->d_sb);
35506 if (file->f_mapping != h_file->f_mapping) {
35507 file->f_mapping = h_file->f_mapping;
35508 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
35509 index 69f7e96..7941063 100644
35510 --- a/fs/aufs/loop.c
35511 +++ b/fs/aufs/loop.c
35512 @@ -130,3 +130,19 @@ void au_loopback_fin(void)
35513 symbol_put(loop_backing_file);
35514 kfree(au_warn_loopback_array);
35517 +/* ---------------------------------------------------------------------- */
35519 +/* support the loopback block device insude aufs */
35521 +struct file *aufs_real_loop(struct file *file)
35525 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
35526 + fi_read_lock(file);
35527 + f = au_hf_top(file);
35528 + fi_read_unlock(file);
35532 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
35533 index 6d9864d..3322557 100644
35534 --- a/fs/aufs/loop.h
35535 +++ b/fs/aufs/loop.h
35536 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
35538 int au_loopback_init(void);
35539 void au_loopback_fin(void);
35541 +struct file *aufs_real_loop(struct file *file);
35543 +AuStub(struct file *, loop_backing_file, return NULL)
35545 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
35546 struct dentry *h_adding)
35547 AuStubInt0(au_test_loopback_kthread, void)
35548 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
35550 AuStubInt0(au_loopback_init, void)
35551 AuStubVoid(au_loopback_fin, void)
35553 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
35554 #endif /* BLK_DEV_LOOP */
35556 #endif /* __KERNEL__ */
35557 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
35558 index ee5780d..da35759 100644
35559 --- a/fs/aufs/super.c
35560 +++ b/fs/aufs/super.c
35561 @@ -807,7 +807,10 @@ static const struct super_operations aufs_sop = {
35562 .statfs = aufs_statfs,
35563 .put_super = aufs_put_super,
35564 .sync_fs = aufs_sync_fs,
35565 - .remount_fs = aufs_remount_fs
35566 + .remount_fs = aufs_remount_fs,
35567 +#ifdef CONFIG_AUFS_BDEV_LOOP
35568 + .real_loop = aufs_real_loop
35572 /* ---------------------------------------------------------------------- */
35573 diff --git a/include/linux/fs.h b/include/linux/fs.h
35574 index 3229f97..f63cc0d 100644
35575 --- a/include/linux/fs.h
35576 +++ b/include/linux/fs.h
35577 @@ -1696,6 +1696,10 @@ struct super_operations {
35578 struct shrink_control *);
35579 long (*free_cached_objects)(struct super_block *,
35580 struct shrink_control *);
35581 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
35583 + struct file *(*real_loop)(struct file *);