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 cb20e4b..dd81418 100644
19 @@ -126,3 +126,4 @@ obj-y += exofs/ # Multiple modules
20 obj-$(CONFIG_CEPH_FS) += ceph/
21 obj-$(CONFIG_PSTORE) += pstore/
22 obj-$(CONFIG_EFIVAR_FS) += efivarfs/
23 +obj-$(CONFIG_AUFS_FS) += aufs/
24 diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild
25 index 1ff9942..31efc0a 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 8133cef..04beb19 100644
42 @@ -1939,6 +1939,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 f7a4c9d..23103ad 100644
64 --- a/drivers/block/loop.c
65 +++ b/drivers/block/loop.c
66 @@ -560,6 +560,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 7a3f3e5..0b40298 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 5fc1e50..5f8385a 100644
141 @@ -1102,8 +1102,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 @@ -1119,9 +1119,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 a0653e5..86080ea 100644
179 --- a/include/linux/fs.h
180 +++ b/include/linux/fs.h
181 @@ -1661,6 +1661,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 1cf7a53..076aff86 100644
215 @@ -2473,7 +2473,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 87782e8..b287e64 100644
228 @@ -1934,7 +1934,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 f8595e8..cb8eda0 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 ca1e091..8940e47 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 e0d64c9..7aa92db 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 2e872f9..2494ed2 100644
296 --- a/include/linux/mm.h
297 +++ b/include/linux/mm.h
298 @@ -1173,6 +1173,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 0038ac7..409940d 100644
329 --- a/include/linux/mm_types.h
330 +++ b/include/linux/mm_types.h
331 @@ -259,6 +259,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 @@ -323,6 +324,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 1bfefc6..a86bd7f 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 1283fc8..128f18f 100644
377 @@ -2089,7 +2089,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/memory.c b/mm/memory.c
387 index a84fbb7..13973d2 100644
390 @@ -2034,7 +2034,7 @@ static inline int wp_page_reuse(struct mm_struct *mm,
394 - file_update_time(vma->vm_file);
395 + vma_file_update_time(vma);
398 return VM_FAULT_WRITE;
399 diff --git a/mm/mmap.c b/mm/mmap.c
400 index aa632ad..3ff75d3 100644
403 @@ -274,7 +274,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
404 if (vma->vm_ops && vma->vm_ops->close)
405 vma->vm_ops->close(vma);
407 - fput(vma->vm_file);
409 mpol_put(vma_policy(vma));
410 kmem_cache_free(vm_area_cachep, vma);
412 @@ -886,7 +886,7 @@ again: remove_next = 1 + (end > next->vm_end);
415 uprobe_munmap(next, next->vm_start, next->vm_end);
420 anon_vma_merge(vma, next);
421 @@ -1671,8 +1671,8 @@ out:
429 /* Undo any partial mapping done by a device driver. */
430 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
431 @@ -2473,7 +2473,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
435 - get_file(new->vm_file);
438 if (new->vm_ops && new->vm_ops->open)
439 new->vm_ops->open(new);
440 @@ -2492,7 +2492,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
441 if (new->vm_ops && new->vm_ops->close)
442 new->vm_ops->close(new);
444 - fput(new->vm_file);
446 unlink_anon_vmas(new);
448 mpol_put(vma_policy(new));
449 @@ -2635,7 +2635,6 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
450 struct vm_area_struct *vma;
451 unsigned long populate = 0;
452 unsigned long ret = -EINVAL;
455 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. "
456 "See Documentation/vm/remap_file_pages.txt.\n",
457 @@ -2679,10 +2678,10 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
458 munlock_vma_pages_range(vma, start, start + size);
461 - file = get_file(vma->vm_file);
463 ret = do_mmap_pgoff(vma->vm_file, start, size,
464 prot, flags, pgoff, &populate);
468 up_write(&mm->mmap_sem);
470 @@ -2949,7 +2948,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
471 if (anon_vma_clone(new_vma, vma))
472 goto out_free_mempol;
473 if (new_vma->vm_file)
474 - get_file(new_vma->vm_file);
475 + vma_get_file(new_vma);
476 if (new_vma->vm_ops && new_vma->vm_ops->open)
477 new_vma->vm_ops->open(new_vma);
478 vma_link(mm, new_vma, prev, rb_link, rb_parent);
479 diff --git a/mm/nommu.c b/mm/nommu.c
480 index 58ea364..f937b7e 100644
483 @@ -671,7 +671,7 @@ static void __put_nommu_region(struct vm_region *region)
484 up_write(&nommu_region_sem);
487 - fput(region->vm_file);
490 /* IO memory and memory shared directly out of the pagecache
491 * from ramfs/tmpfs mustn't be released here */
492 @@ -829,7 +829,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
493 if (vma->vm_ops && vma->vm_ops->close)
494 vma->vm_ops->close(vma);
496 - fput(vma->vm_file);
498 put_nommu_region(vma->vm_region);
499 kmem_cache_free(vm_area_cachep, vma);
501 @@ -1354,7 +1354,7 @@ unsigned long do_mmap_pgoff(struct file *file,
502 goto error_just_free;
505 - fput(region->vm_file);
507 kmem_cache_free(vm_region_jar, region);
510 @@ -1429,10 +1429,10 @@ error_just_free:
511 up_write(&nommu_region_sem);
514 - fput(region->vm_file);
516 kmem_cache_free(vm_region_jar, region);
518 - fput(vma->vm_file);
520 kmem_cache_free(vm_area_cachep, vma);
523 diff --git a/mm/prfile.c b/mm/prfile.c
525 index 0000000..b323b8a
530 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
531 + * in /proc/PID/maps.
532 + * Call these functions via macros defined in linux/mm.h.
534 + * See Documentation/filesystems/aufs/design/06mmap.txt
536 + * Copyright (c) 2014 Junjro R. Okajima
537 + * Copyright (c) 2014 Ian Campbell
540 +#include <linux/mm.h>
541 +#include <linux/file.h>
542 +#include <linux/fs.h>
544 +/* #define PRFILE_TRACE */
545 +static inline void prfile_trace(struct file *f, struct file *pr,
546 + const char func[], int line, const char func2[])
550 + pr_info("%s:%d: %s, %s\n", func, line, func2,
551 + f ? (char *)f->f_path.dentry->d_name.name : "(null)");
555 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
558 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
560 + prfile_trace(f, pr, func, line, __func__);
561 + file_update_time(f);
563 + file_update_time(pr);
566 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
569 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
571 + prfile_trace(f, pr, func, line, __func__);
572 + return (f && pr) ? pr : f;
575 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
577 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
579 + prfile_trace(f, pr, func, line, __func__);
585 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
587 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
589 + prfile_trace(f, pr, func, line, __func__);
596 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
599 + struct file *f = region->vm_file, *pr = region->vm_prfile;
601 + prfile_trace(f, pr, func, line, __func__);
602 + return (f && pr) ? pr : f;
605 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
607 + struct file *f = region->vm_file, *pr = region->vm_prfile;
609 + prfile_trace(f, pr, func, line, __func__);
614 +#endif /* !CONFIG_MMU */
615 aufs4.x-rcN standalone patch
617 diff --git a/fs/dcache.c b/fs/dcache.c
618 index 0b40298..4844e61 100644
621 @@ -1269,6 +1269,7 @@ rename_retry:
625 +EXPORT_SYMBOL(d_walk);
628 * Search for at least 1 mount point in the dentry's subdirs.
629 diff --git a/fs/file_table.c b/fs/file_table.c
630 index 7f9d407..8c9ec1d 100644
631 --- a/fs/file_table.c
632 +++ b/fs/file_table.c
633 @@ -146,6 +146,7 @@ over:
635 return ERR_PTR(-ENFILE);
637 +EXPORT_SYMBOL(get_empty_filp);
640 * alloc_file - allocate and initialize a 'struct file'
641 @@ -307,6 +308,7 @@ void put_filp(struct file *file)
645 +EXPORT_SYMBOL(put_filp);
647 void __init files_init(unsigned long mempages)
649 diff --git a/fs/inode.c b/fs/inode.c
650 index d30640f..1ecc715 100644
653 @@ -58,6 +58,7 @@ static struct hlist_head *inode_hashtable __read_mostly;
654 static __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_hash_lock);
656 __cacheline_aligned_in_smp DEFINE_SPINLOCK(inode_sb_list_lock);
657 +EXPORT_SYMBOL(inode_sb_list_lock);
660 * Empty aops. Can be used for the cases where the user does not
661 diff --git a/fs/namespace.c b/fs/namespace.c
662 index c7cb8a5..08723de 100644
665 @@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
666 mnt_dec_writers(real_mount(mnt));
669 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
672 * mnt_drop_write - give up write access to a mount
673 @@ -1779,6 +1780,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
677 +EXPORT_SYMBOL(iterate_mounts);
679 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
681 diff --git a/fs/notify/group.c b/fs/notify/group.c
682 index d16b62c..06ca6bc 100644
683 --- a/fs/notify/group.c
684 +++ b/fs/notify/group.c
686 #include <linux/srcu.h>
687 #include <linux/rculist.h>
688 #include <linux/wait.h>
689 +#include <linux/module.h>
691 #include <linux/fsnotify_backend.h>
692 #include "fsnotify.h"
693 @@ -72,6 +73,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
695 atomic_inc(&group->refcnt);
697 +EXPORT_SYMBOL(fsnotify_get_group);
700 * Drop a reference to a group. Free it if it's through.
701 @@ -81,6 +83,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
702 if (atomic_dec_and_test(&group->refcnt))
703 fsnotify_final_destroy_group(group);
705 +EXPORT_SYMBOL(fsnotify_put_group);
708 * Create a new fsnotify_group and hold a reference for the group returned.
709 @@ -109,6 +112,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
713 +EXPORT_SYMBOL(fsnotify_alloc_group);
715 int fsnotify_fasync(int fd, struct file *file, int on)
717 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
718 index 92e48c7..d2c4b68 100644
719 --- a/fs/notify/mark.c
720 +++ b/fs/notify/mark.c
721 @@ -109,6 +109,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
722 mark->free_mark(mark);
725 +EXPORT_SYMBOL(fsnotify_put_mark);
727 /* Calculate mask of events for a list of marks */
728 u32 fsnotify_recalc_mask(struct hlist_head *head)
729 @@ -202,6 +203,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
730 fsnotify_destroy_mark_locked(mark, group);
731 mutex_unlock(&group->mark_mutex);
733 +EXPORT_SYMBOL(fsnotify_destroy_mark);
736 * Destroy all marks in the given list. The marks must be already detached from
737 @@ -376,6 +378,7 @@ err:
741 +EXPORT_SYMBOL(fsnotify_add_mark);
743 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
744 struct inode *inode, struct vfsmount *mnt, int allow_dups)
745 @@ -455,6 +458,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
746 atomic_set(&mark->refcnt, 1);
747 mark->free_mark = free_mark;
749 +EXPORT_SYMBOL(fsnotify_init_mark);
751 static int fsnotify_mark_destroy(void *ignored)
753 diff --git a/fs/open.c b/fs/open.c
754 index e33dab2..b84b828 100644
757 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
758 mutex_unlock(&dentry->d_inode->i_mutex);
761 +EXPORT_SYMBOL(do_truncate);
763 long vfs_truncate(struct path *path, loff_t length)
765 @@ -678,6 +679,7 @@ int open_check_o_direct(struct file *f)
769 +EXPORT_SYMBOL(open_check_o_direct);
771 static int do_dentry_open(struct file *f,
773 diff --git a/fs/read_write.c b/fs/read_write.c
774 index fd0414e..8ace6ec 100644
775 --- a/fs/read_write.c
776 +++ b/fs/read_write.c
777 @@ -504,6 +504,7 @@ vfs_readf_t vfs_readf(struct file *file)
778 return new_sync_read;
779 return ERR_PTR(-ENOSYS);
781 +EXPORT_SYMBOL(vfs_readf);
783 vfs_writef_t vfs_writef(struct file *file)
785 @@ -515,6 +516,7 @@ vfs_writef_t vfs_writef(struct file *file)
786 return new_sync_write;
787 return ERR_PTR(-ENOSYS);
789 +EXPORT_SYMBOL(vfs_writef);
791 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
793 diff --git a/fs/splice.c b/fs/splice.c
794 index 5f8385a..f76067e 100644
797 @@ -1115,6 +1115,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
799 return splice_write(pipe, out, ppos, len, flags);
801 +EXPORT_SYMBOL(do_splice_from);
804 * Attempt to initiate a splice from a file to a pipe.
805 @@ -1141,6 +1142,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
807 return splice_read(in, ppos, pipe, len, flags);
809 +EXPORT_SYMBOL(do_splice_to);
812 * splice_direct_to_actor - splices data directly between two non-pipes
813 diff --git a/fs/xattr.c b/fs/xattr.c
814 index 072fee1..a7677af 100644
817 @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
818 *xattr_value = value;
821 +EXPORT_SYMBOL(vfs_getxattr_alloc);
823 /* Compare an extended attribute value with the given value */
824 int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
825 diff --git a/security/commoncap.c b/security/commoncap.c
826 index d103f5a4..393654e 100644
827 --- a/security/commoncap.c
828 +++ b/security/commoncap.c
829 @@ -970,12 +970,14 @@ int cap_mmap_addr(unsigned long addr)
833 +EXPORT_SYMBOL(cap_mmap_addr);
835 int cap_mmap_file(struct file *file, unsigned long reqprot,
836 unsigned long prot, unsigned long flags)
840 +EXPORT_SYMBOL(cap_mmap_file);
842 #ifdef CONFIG_SECURITY
844 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
845 index 188c1d2..426d9af 100644
846 --- a/security/device_cgroup.c
847 +++ b/security/device_cgroup.c
849 #include <linux/device_cgroup.h>
850 #include <linux/cgroup.h>
851 #include <linux/ctype.h>
852 +#include <linux/export.h>
853 #include <linux/list.h>
854 #include <linux/uaccess.h>
855 #include <linux/seq_file.h>
856 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
857 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
860 +EXPORT_SYMBOL(__devcgroup_inode_permission);
862 int devcgroup_inode_mknod(int mode, dev_t dev)
864 diff --git a/security/security.c b/security/security.c
865 index 595fffa..346bad6 100644
866 --- a/security/security.c
867 +++ b/security/security.c
868 @@ -438,6 +438,7 @@ int security_path_rmdir(struct path *dir, struct dentry *dentry)
870 return call_int_hook(path_rmdir, 0, dir, dentry);
872 +EXPORT_SYMBOL(security_path_rmdir);
874 int security_path_unlink(struct path *dir, struct dentry *dentry)
876 @@ -454,6 +455,7 @@ int security_path_symlink(struct path *dir, struct dentry *dentry,
878 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
880 +EXPORT_SYMBOL(security_path_symlink);
882 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
883 struct dentry *new_dentry)
884 @@ -462,6 +464,7 @@ int security_path_link(struct dentry *old_dentry, struct path *new_dir,
886 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
888 +EXPORT_SYMBOL(security_path_link);
890 int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
891 struct path *new_dir, struct dentry *new_dentry,
892 @@ -489,6 +492,7 @@ int security_path_truncate(struct path *path)
894 return call_int_hook(path_truncate, 0, path);
896 +EXPORT_SYMBOL(security_path_truncate);
898 int security_path_chmod(struct path *path, umode_t mode)
900 @@ -496,6 +500,7 @@ int security_path_chmod(struct path *path, umode_t mode)
902 return call_int_hook(path_chmod, 0, path, mode);
904 +EXPORT_SYMBOL(security_path_chmod);
906 int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
908 @@ -503,6 +508,7 @@ int security_path_chown(struct path *path, kuid_t uid, kgid_t gid)
910 return call_int_hook(path_chown, 0, path, uid, gid);
912 +EXPORT_SYMBOL(security_path_chown);
914 int security_path_chroot(struct path *path)
916 @@ -588,6 +594,7 @@ int security_inode_readlink(struct dentry *dentry)
918 return call_int_hook(inode_readlink, 0, dentry);
920 +EXPORT_SYMBOL(security_inode_readlink);
922 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
924 @@ -603,6 +610,7 @@ int security_inode_permission(struct inode *inode, int mask)
926 return call_int_hook(inode_permission, 0, inode, mask);
928 +EXPORT_SYMBOL(security_inode_permission);
930 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
932 @@ -741,6 +749,7 @@ int security_file_permission(struct file *file, int mask)
934 return fsnotify_perm(file, mask);
936 +EXPORT_SYMBOL(security_file_permission);
938 int security_file_alloc(struct file *file)
940 @@ -800,6 +809,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
942 return ima_file_mmap(file, prot);
944 +EXPORT_SYMBOL(security_mmap_file);
946 int security_mmap_addr(unsigned long addr)
948 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
949 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
950 +++ linux/Documentation/ABI/testing/debugfs-aufs 2015-09-24 10:47:58.244719488 +0200
952 +What: /debug/aufs/si_<id>/
954 +Contact: J. R. Okajima <hooanon05g@gmail.com>
956 + Under /debug/aufs, a directory named si_<id> is created
957 + per aufs mount, where <id> is a unique id generated
960 +What: /debug/aufs/si_<id>/plink
962 +Contact: J. R. Okajima <hooanon05g@gmail.com>
964 + It has three lines and shows the information about the
965 + pseudo-link. The first line is a single number
966 + representing a number of buckets. The second line is a
967 + number of pseudo-links per buckets (separated by a
968 + blank). The last line is a single number representing a
969 + total number of psedo-links.
970 + When the aufs mount option 'noplink' is specified, it
971 + will show "1\n0\n0\n".
973 +What: /debug/aufs/si_<id>/xib
975 +Contact: J. R. Okajima <hooanon05g@gmail.com>
977 + It shows the consumed blocks by xib (External Inode Number
978 + Bitmap), its block size and file size.
979 + When the aufs mount option 'noxino' is specified, it
980 + will be empty. About XINO files, see the aufs manual.
982 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
984 +Contact: J. R. Okajima <hooanon05g@gmail.com>
986 + It shows the consumed blocks by xino (External Inode Number
987 + Translation Table), its link count, block size and file
989 + When the aufs mount option 'noxino' is specified, it
990 + will be empty. About XINO files, see the aufs manual.
992 +What: /debug/aufs/si_<id>/xigen
994 +Contact: J. R. Okajima <hooanon05g@gmail.com>
996 + It shows the consumed blocks by xigen (External Inode
997 + Generation Table), its block size and file size.
998 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1000 + When the aufs mount option 'noxino' is specified, it
1001 + will be empty. About XINO files, see the aufs manual.
1002 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1003 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1004 +++ linux/Documentation/ABI/testing/sysfs-aufs 2015-09-24 10:47:58.244719488 +0200
1006 +What: /sys/fs/aufs/si_<id>/
1008 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1010 + Under /sys/fs/aufs, a directory named si_<id> is created
1011 + per aufs mount, where <id> is a unique id generated
1014 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1016 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1018 + It shows the abolute path of a member directory (which
1019 + is called branch) in aufs, and its permission.
1021 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1023 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1025 + It shows the id of a member directory (which is called
1028 +What: /sys/fs/aufs/si_<id>/xi_path
1030 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1032 + It shows the abolute path of XINO (External Inode Number
1033 + Bitmap, Translation Table and Generation Table) file
1034 + even if it is the default path.
1035 + When the aufs mount option 'noxino' is specified, it
1036 + will be empty. About XINO files, see the aufs manual.
1037 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1038 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1039 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2015-09-24 10:47:58.244719488 +0200
1042 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1044 +# This program is free software; you can redistribute it and/or modify
1045 +# it under the terms of the GNU General Public License as published by
1046 +# the Free Software Foundation; either version 2 of the License, or
1047 +# (at your option) any later version.
1049 +# This program is distributed in the hope that it will be useful,
1050 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1051 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1052 +# GNU General Public License for more details.
1054 +# You should have received a copy of the GNU General Public License
1055 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1058 +----------------------------------------
1060 +aufs [ei ju: ef es] | [a u f s]
1061 +1. abbrev. for "advanced multi-layered unification filesystem".
1062 +2. abbrev. for "another unionfs".
1063 +3. abbrev. for "auf das" in German which means "on the" in English.
1064 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1065 + But "Filesystem aufs Filesystem" is hard to understand.
1067 +AUFS is a filesystem with features:
1068 +- multi layered stackable unification filesystem, the member directory
1069 + is called as a branch.
1070 +- branch permission and attribute, 'readonly', 'real-readonly',
1071 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1073 +- internal "file copy-on-write".
1074 +- logical deletion, whiteout.
1075 +- dynamic branch manipulation, adding, deleting and changing permission.
1076 +- allow bypassing aufs, user's direct branch access.
1077 +- external inode number translation table and bitmap which maintains the
1078 + persistent aufs inode number.
1079 +- seekable directory, including NFS readdir.
1080 +- file mapping, mmap and sharing pages.
1081 +- pseudo-link, hardlink over branches.
1082 +- loopback mounted filesystem as a branch.
1083 +- several policies to select one among multiple writable branches.
1084 +- revert a single systemcall when an error occurs in aufs.
1088 +Multi Layered Stackable Unification Filesystem
1089 +----------------------------------------------------------------------
1090 +Most people already knows what it is.
1091 +It is a filesystem which unifies several directories and provides a
1092 +merged single directory. When users access a file, the access will be
1093 +passed/re-directed/converted (sorry, I am not sure which English word is
1094 +correct) to the real file on the member filesystem. The member
1095 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1096 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1097 +readonly branch is handled by creating 'whiteout' on the upper writable
1100 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1101 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1102 +different approaches to implement the merged-view.
1103 +The former tries putting it into VFS, and the latter implements as a
1104 +separate filesystem.
1105 +(If I misunderstand about these implementations, please let me know and
1106 +I shall correct it. Because it is a long time ago when I read their
1107 +source files last time).
1109 +UnionMount's approach will be able to small, but may be hard to share
1110 +branches between several UnionMount since the whiteout in it is
1111 +implemented in the inode on branch filesystem and always
1112 +shared. According to Bharata's post, readdir does not seems to be
1114 +There are several missing features known in this implementations such as
1115 +- for users, the inode number may change silently. eg. copy-up.
1116 +- link(2) may break by copy-up.
1117 +- read(2) may get an obsoleted filedata (fstat(2) too).
1118 +- fcntl(F_SETLK) may be broken by copy-up.
1119 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1122 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1123 +merged into mainline. This is another implementation of UnionMount as a
1124 +separated filesystem. All the limitations and known problems which
1125 +UnionMount are equally inherited to "overlay" filesystem.
1127 +Unionfs has a longer history. When I started implementing a stackable
1128 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1129 +inode, dentry and file objects and they have an array pointing lower
1130 +same kind objects. After contributing many patches for Unionfs, I
1131 +re-started my project AUFS (Jun 2006).
1133 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1134 +implemented my own ideas, approaches and enhancements and it became
1135 +totally different one.
1137 +Comparing DM snapshot and fs based implementation
1138 +- the number of bytes to be copied between devices is much smaller.
1139 +- the type of filesystem must be one and only.
1140 +- the fs must be writable, no readonly fs, even for the lower original
1141 + device. so the compression fs will not be usable. but if we use
1142 + loopback mount, we may address this issue.
1144 + mount /cdrom/squashfs.img /sq
1145 + losetup /sq/ext2.img
1146 + losetup /somewhere/cow
1147 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1148 +- it will be difficult (or needs more operations) to extract the
1149 + difference between the original device and COW.
1150 +- DM snapshot-merge may help a lot when users try merging. in the
1151 + fs-layer union, users will use rsync(1).
1153 +You may want to read my old paper "Filesystems in LiveCD"
1154 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1157 +Several characters/aspects/persona of aufs
1158 +----------------------------------------------------------------------
1160 +Aufs has several characters, aspects or persona.
1161 +1. a filesystem, callee of VFS helper
1162 +2. sub-VFS, caller of VFS helper for branches
1163 +3. a virtual filesystem which maintains persistent inode number
1164 +4. reader/writer of files on branches such like an application
1166 +1. Callee of VFS Helper
1167 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1168 +unlink(2) from an application reaches sys_unlink() kernel function and
1169 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1170 +calls filesystem specific unlink operation. Actually aufs implements the
1171 +unlink operation but it behaves like a redirector.
1173 +2. Caller of VFS Helper for Branches
1174 +aufs_unlink() passes the unlink request to the branch filesystem as if
1175 +it were called from VFS. So the called unlink operation of the branch
1176 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1177 +every necessary pre/post operation for the branch filesystem.
1178 +- acquire the lock for the parent dir on a branch
1179 +- lookup in a branch
1180 +- revalidate dentry on a branch
1181 +- mnt_want_write() for a branch
1182 +- vfs_unlink() for a branch
1183 +- mnt_drop_write() for a branch
1184 +- release the lock on a branch
1186 +3. Persistent Inode Number
1187 +One of the most important issue for a filesystem is to maintain inode
1188 +numbers. This is particularly important to support exporting a
1189 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1190 +backend block device for its own. But some storage is necessary to
1191 +keep and maintain the inode numbers. It may be a large space and may not
1192 +suit to keep in memory. Aufs rents some space from its first writable
1193 +branch filesystem (by default) and creates file(s) on it. These files
1194 +are created by aufs internally and removed soon (currently) keeping
1196 +Note: Because these files are removed, they are totally gone after
1197 + unmounting aufs. It means the inode numbers are not persistent
1198 + across unmount or reboot. I have a plan to make them really
1199 + persistent which will be important for aufs on NFS server.
1201 +4. Read/Write Files Internally (copy-on-write)
1202 +Because a branch can be readonly, when you write a file on it, aufs will
1203 +"copy-up" it to the upper writable branch internally. And then write the
1204 +originally requested thing to the file. Generally kernel doesn't
1205 +open/read/write file actively. In aufs, even a single write may cause a
1206 +internal "file copy". This behaviour is very similar to cp(1) command.
1208 +Some people may think it is better to pass such work to user space
1209 +helper, instead of doing in kernel space. Actually I am still thinking
1210 +about it. But currently I have implemented it in kernel space.
1211 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1212 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1213 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2015-09-24 10:47:58.244719488 +0200
1216 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1218 +# This program is free software; you can redistribute it and/or modify
1219 +# it under the terms of the GNU General Public License as published by
1220 +# the Free Software Foundation; either version 2 of the License, or
1221 +# (at your option) any later version.
1223 +# This program is distributed in the hope that it will be useful,
1224 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1225 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1226 +# GNU General Public License for more details.
1228 +# You should have received a copy of the GNU General Public License
1229 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1231 +Basic Aufs Internal Structure
1233 +Superblock/Inode/Dentry/File Objects
1234 +----------------------------------------------------------------------
1235 +As like an ordinary filesystem, aufs has its own
1236 +superblock/inode/dentry/file objects. All these objects have a
1237 +dynamically allocated array and store the same kind of pointers to the
1238 +lower filesystem, branch.
1239 +For example, when you build a union with one readwrite branch and one
1240 +readonly, mounted /au, /rw and /ro respectively.
1242 +- /ro/fileA exists but /rw/fileA
1244 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1245 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1246 +- [0] = NULL (because /rw/fileA doesn't exist)
1249 +This style of an array is essentially same to the aufs
1250 +superblock/inode/dentry/file objects.
1252 +Because aufs supports manipulating branches, ie. add/delete/change
1253 +branches dynamically, these objects has its own generation. When
1254 +branches are changed, the generation in aufs superblock is
1255 +incremented. And a generation in other object are compared when it is
1256 +accessed. When a generation in other objects are obsoleted, aufs
1257 +refreshes the internal array.
1261 +----------------------------------------------------------------------
1262 +Additionally aufs superblock has some data for policies to select one
1263 +among multiple writable branches, XIB files, pseudo-links and kobject.
1264 +See below in detail.
1265 +About the policies which supports copy-down a directory, see
1266 +wbr_policy.txt too.
1269 +Branch and XINO(External Inode Number Translation Table)
1270 +----------------------------------------------------------------------
1271 +Every branch has its own xino (external inode number translation table)
1272 +file. The xino file is created and unlinked by aufs internally. When two
1273 +members of a union exist on the same filesystem, they share the single
1275 +The struct of a xino file is simple, just a sequence of aufs inode
1276 +numbers which is indexed by the lower inode number.
1277 +In the above sample, assume the inode number of /ro/fileA is i111 and
1278 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1279 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1281 +When the inode numbers are not contiguous, the xino file will be sparse
1282 +which has a hole in it and doesn't consume as much disk space as it
1283 +might appear. If your branch filesystem consumes disk space for such
1284 +holes, then you should specify 'xino=' option at mounting aufs.
1286 +Aufs has a mount option to free the disk blocks for such holes in XINO
1287 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1288 +meet a problem of disk shortage due to XINO files, then you should try
1289 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1290 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1291 +the holes in XINO files.
1293 +Also a writable branch has three kinds of "whiteout bases". All these
1294 +are existed when the branch is joined to aufs, and their names are
1295 +whiteout-ed doubly, so that users will never see their names in aufs
1297 +1. a regular file which will be hardlinked to all whiteouts.
1298 +2. a directory to store a pseudo-link.
1299 +3. a directory to store an "orphan"-ed file temporary.
1302 + When you remove a file on a readonly branch, aufs handles it as a
1303 + logical deletion and creates a whiteout on the upper writable branch
1304 + as a hardlink of this file in order not to consume inode on the
1307 + See below, Pseudo-link.
1309 + When "fileC" exists on the lower readonly branch only and it is
1310 + opened and removed with its parent dir, and then user writes
1311 + something into it, then aufs copies-up fileC to this
1312 + directory. Because there is no other dir to store fileC. After
1313 + creating a file under this dir, the file is unlinked.
1315 +Because aufs supports manipulating branches, ie. add/delete/change
1316 +dynamically, a branch has its own id. When the branch order changes,
1317 +aufs finds the new index by searching the branch id.
1321 +----------------------------------------------------------------------
1322 +Assume "fileA" exists on the lower readonly branch only and it is
1323 +hardlinked to "fileB" on the branch. When you write something to fileA,
1324 +aufs copies-up it to the upper writable branch. Additionally aufs
1325 +creates a hardlink under the Pseudo-link Directory of the writable
1326 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1327 +simple list. If fileB is read after unlinking fileA, aufs returns
1328 +filedata from the pseudo-link instead of the lower readonly
1329 +branch. Because the pseudo-link is based upon the inode, to keep the
1330 +inode number by xino (see above) is essentially necessary.
1332 +All the hardlinks under the Pseudo-link Directory of the writable branch
1333 +should be restored in a proper location later. Aufs provides a utility
1334 +to do this. The userspace helpers executed at remounting and unmounting
1336 +During this utility is running, it puts aufs into the pseudo-link
1337 +maintenance mode. In this mode, only the process which began the
1338 +maintenance mode (and its child processes) is allowed to operate in
1339 +aufs. Some other processes which are not related to the pseudo-link will
1340 +be allowed to run too, but the rest have to return an error or wait
1341 +until the maintenance mode ends. If a process already acquires an inode
1342 +mutex (in VFS), it has to return an error.
1345 +XIB(external inode number bitmap)
1346 +----------------------------------------------------------------------
1347 +Addition to the xino file per a branch, aufs has an external inode number
1348 +bitmap in a superblock object. It is also an internal file such like a
1350 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1352 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1354 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1355 +reduce the number of consumed disk blocks for these files.
1358 +Virtual or Vertical Dir, and Readdir in Userspace
1359 +----------------------------------------------------------------------
1360 +In order to support multiple layers (branches), aufs readdir operation
1361 +constructs a virtual dir block on memory. For readdir, aufs calls
1362 +vfs_readdir() internally for each dir on branches, merges their entries
1363 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1364 +object. So the file object has its entry list until it is closed. The
1365 +entry list will be updated when the file position is zero and becomes
1366 +obsoleted. This decision is made in aufs automatically.
1368 +The dynamically allocated memory block for the name of entries has a
1369 +unit of 512 bytes (by default) and stores the names contiguously (no
1370 +padding). Another block for each entry is handled by kmem_cache too.
1371 +During building dir blocks, aufs creates hash list and judging whether
1372 +the entry is whiteouted by its upper branch or already listed.
1373 +The merged result is cached in the corresponding inode object and
1374 +maintained by a customizable life-time option.
1376 +Some people may call it can be a security hole or invite DoS attack
1377 +since the opened and once readdir-ed dir (file object) holds its entry
1378 +list and becomes a pressure for system memory. But I'd say it is similar
1379 +to files under /proc or /sys. The virtual files in them also holds a
1380 +memory page (generally) while they are opened. When an idea to reduce
1381 +memory for them is introduced, it will be applied to aufs too.
1382 +For those who really hate this situation, I've developed readdir(3)
1383 +library which operates this merging in userspace. You just need to set
1384 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1385 +kernel space for readdir(3).
1389 +----------------------------------------------------------------------
1390 +Aufs sometimes requires privilege access to a branch. For instance,
1391 +in copy-up/down operation. When a user process is going to make changes
1392 +to a file which exists in the lower readonly branch only, and the mode
1393 +of one of ancestor directories may not be writable by a user
1394 +process. Here aufs copy-up the file with its ancestors and they may
1395 +require privilege to set its owner/group/mode/etc.
1396 +This is a typical case of a application character of aufs (see
1399 +Aufs uses workqueue synchronously for this case. It creates its own
1400 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1401 +passes the request to call mkdir or write (for example), and wait for
1402 +its completion. This approach solves a problem of a signal handler
1404 +If aufs didn't adopt the workqueue and changed the privilege of the
1405 +process, then the process may receive the unexpected SIGXFSZ or other
1408 +Also aufs uses the system global workqueue ("events" kernel thread) too
1409 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1410 +whiteout base and etc. This is unrelated to a privilege.
1411 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1412 +superblock at the beginning, at the same time waits for the completion
1413 +of all queued asynchronous tasks.
1417 +----------------------------------------------------------------------
1418 +The whiteout in aufs is very similar to Unionfs's. That is represented
1419 +by its filename. UnionMount takes an approach of a file mode, but I am
1420 +afraid several utilities (find(1) or something) will have to support it.
1422 +Basically the whiteout represents "logical deletion" which stops aufs to
1423 +lookup further, but also it represents "dir is opaque" which also stop
1426 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1427 +In order to make several functions in a single systemcall to be
1428 +revertible, aufs adopts an approach to rename a directory to a temporary
1429 +unique whiteouted name.
1430 +For example, in rename(2) dir where the target dir already existed, aufs
1431 +renames the target dir to a temporary unique whiteouted name before the
1432 +actual rename on a branch, and then handles other actions (make it opaque,
1433 +update the attributes, etc). If an error happens in these actions, aufs
1434 +simply renames the whiteouted name back and returns an error. If all are
1435 +succeeded, aufs registers a function to remove the whiteouted unique
1436 +temporary name completely and asynchronously to the system global
1441 +----------------------------------------------------------------------
1442 +It is a well-known feature or concept.
1443 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1444 +internally and makes change to the new file on the upper writable branch.
1445 +When the trigger systemcall does not update the timestamps of the parent
1446 +dir, aufs reverts it after copy-up.
1449 +Move-down (aufs3.9 and later)
1450 +----------------------------------------------------------------------
1451 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1452 +the lower readonly branch to the upper writable branch when a user
1453 +changes something about the file.
1454 +"Move-down" is an opposite action of copy-up. Basically this action is
1455 +ran manually instead of automatically and internally.
1456 +For desgin and implementation, aufs has to consider these issues.
1457 +- whiteout for the file may exist on the lower branch.
1458 +- ancestor directories may not exist on the lower branch.
1459 +- diropq for the ancestor directories may exist on the upper branch.
1460 +- free space on the lower branch will reduce.
1461 +- another access to the file may happen during moving-down, including
1462 + UDBA (see "Revalidate Dentry and UDBA").
1463 +- the file should not be hard-linked nor pseudo-linked. they should be
1464 + handled by auplink utility later.
1466 +Sometimes users want to move-down a file from the upper writable branch
1467 +to the lower readonly or writable branch. For instance,
1468 +- the free space of the upper writable branch is going to run out.
1469 +- create a new intermediate branch between the upper and lower branch.
1472 +For this purpose, use "aumvdown" command in aufs-util.git.
1473 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1474 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1475 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2015-09-24 10:47:58.244719488 +0200
1478 +# Copyright (C) 2015 Junjiro R. Okajima
1480 +# This program is free software; you can redistribute it and/or modify
1481 +# it under the terms of the GNU General Public License as published by
1482 +# the Free Software Foundation; either version 2 of the License, or
1483 +# (at your option) any later version.
1485 +# This program is distributed in the hope that it will be useful,
1486 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1487 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1488 +# GNU General Public License for more details.
1490 +# You should have received a copy of the GNU General Public License
1491 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1493 +Support for a branch who has its ->atomic_open()
1494 +----------------------------------------------------------------------
1495 +The filesystems who implement its ->atomic_open() are not majority. For
1496 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1497 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1498 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1499 +sure whether all filesystems who have ->atomic_open() behave like this,
1500 +but NFSv4 surely returns the error.
1502 +In order to support ->atomic_open() for aufs, there are a few
1505 +A. Introduce aufs_atomic_open()
1506 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1508 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1509 + an aufs user Pip Cet's approach
1510 + - calls aufs_create(), VFS finish_open() and notify_change().
1511 + - pass fake-mode to finish_open(), and then correct the mode by
1513 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1514 + - no aufs_atomic_open().
1515 + - aufs_lookup() registers the TID to an aufs internal object.
1516 + - aufs_create() does nothing when the matching TID is registered, but
1517 + registers the mode.
1518 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1519 + TID is registered.
1520 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1522 + - no aufs_atomic_open().
1523 + - aufs_create() registers the TID to an internal object. this info
1524 + represents "this process created this file just now."
1525 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1526 + registered TID and re-try open() with superuser's credential.
1528 +Pros and cons for each approach.
1531 + - straightforward but highly depends upon VFS internal.
1532 + - the atomic behavaiour is kept.
1533 + - some of parameters such as nameidata are hard to reproduce for
1537 + - easy to implement.
1538 + - the atomic behavaiour is lost.
1540 + - the atomic behavaiour is kept.
1541 + - dirty and tricky.
1542 + - VFS checks whether the file is created correctly after calling
1543 + ->create(), which means this approach doesn't work.
1545 + - easy to implement.
1546 + - the atomic behavaiour is lost.
1547 + - to open a file with superuser's credential and give it to a user
1548 + process is a bad idea, since the file object keeps the credential
1549 + in it. It may affect LSM or something. This approach doesn't work
1552 +The approach A is ideal, but it hard to implement. So here is a
1553 +variation of A, which is to be implemented.
1555 +A-1. Introduce aufs_atomic_open()
1556 + - calls branch fs ->atomic_open() if exists. otherwise calls
1557 + vfs_create() and finish_open().
1558 + - the demerit is that the several checks after branch fs
1559 + ->atomic_open() are lost. in the ordinary case, the checks are
1560 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1561 + be implemented in aufs, but not all I am afraid.
1562 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1563 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1564 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2015-09-24 10:47:58.244719488 +0200
1567 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1569 +# This program is free software; you can redistribute it and/or modify
1570 +# it under the terms of the GNU General Public License as published by
1571 +# the Free Software Foundation; either version 2 of the License, or
1572 +# (at your option) any later version.
1574 +# This program is distributed in the hope that it will be useful,
1575 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1576 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1577 +# GNU General Public License for more details.
1579 +# You should have received a copy of the GNU General Public License
1580 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1583 +----------------------------------------------------------------------
1584 +Since aufs has a character of sub-VFS (see Introduction), it operates
1585 +lookup for branches as VFS does. It may be a heavy work. But almost all
1586 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1587 +directly connected to its parent. Digging down the directory hierarchy
1588 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1591 +When a branch is a remote filesystem, aufs basically relies upon its
1592 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1594 +For d_revalidate, aufs implements three levels of revalidate tests. See
1595 +"Revalidate Dentry and UDBA" in detail.
1598 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1599 +----------------------------------------------------------------------
1600 +Let's try case study.
1601 +- aufs has two branches, upper readwrite and lower readonly.
1603 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1604 +- user invoked "chmod a+rx /au/dirA"
1605 +- the internal copy-up is activated and "/rw/dirA" is created and its
1606 + permission bits are set to world readable.
1607 +- then "/au/dirA" becomes world readable?
1609 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1610 +or it may be a natively readonly filesystem. If aufs respects the lower
1611 +branch, it should not respond readdir request from other users. But user
1612 +allowed it by chmod. Should really aufs rejects showing the entries
1615 +To be honest, I don't have a good solution for this case. So aufs
1616 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1618 +When dirperm1 is specified, aufs checks only the highest one for the
1619 +directory permission, and shows the entries. Otherwise, as usual, checks
1620 +every dir existing on all branches and rejects the request.
1622 +As a side effect, dirperm1 option improves the performance of aufs
1623 +because the number of permission check is reduced when the number of
1627 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1628 +----------------------------------------------------------------------
1629 +Generally VFS helpers re-validate a dentry as a part of lookup.
1630 +0. digging down the directory hierarchy.
1631 +1. lock the parent dir by its i_mutex.
1632 +2. lookup the final (child) entry.
1634 +4. call the actual operation (create, unlink, etc.)
1635 +5. unlock the parent dir
1637 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1638 +called. Actually aufs implements it and checks the dentry on a branch is
1640 +But it is not enough. Because aufs has to release the lock for the
1641 +parent dir on a branch at the end of ->lookup() (step 2) and
1642 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1644 +If the file on a branch is changed directly, eg. bypassing aufs, after
1645 +aufs released the lock, then the subsequent operation may cause
1646 +something unpleasant result.
1648 +This situation is a result of VFS architecture, ->lookup() and
1649 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1650 +design from VFS's point of view. It is just not suitable for sub-VFS
1653 +Aufs supports such case by three level of revalidation which is
1654 +selectable by user.
1655 +1. Simple Revalidate
1656 + Addition to the native flow in VFS's, confirm the child-parent
1657 + relationship on the branch just after locking the parent dir on the
1658 + branch in the "actual operation" (step 4). When this validation
1659 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1660 + checks the validation of the dentry on branches.
1661 +2. Monitor Changes Internally by Inotify/Fsnotify
1662 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1663 + the dentry on the branch, and returns EBUSY if it finds different
1665 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1666 + during it is in cache. When the event is notified, aufs registers a
1667 + function to kernel 'events' thread by schedule_work(). And the
1668 + function sets some special status to the cached aufs dentry and inode
1669 + private data. If they are not cached, then aufs has nothing to
1670 + do. When the same file is accessed through aufs (step 0-3) later,
1671 + aufs will detect the status and refresh all necessary data.
1672 + In this mode, aufs has to ignore the event which is fired by aufs
1674 +3. No Extra Validation
1675 + This is the simplest test and doesn't add any additional revalidation
1676 + test, and skip the revalidation in step 4. It is useful and improves
1677 + aufs performance when system surely hide the aufs branches from user,
1678 + by over-mounting something (or another method).
1679 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1680 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1681 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2015-09-24 10:47:58.244719488 +0200
1684 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1686 +# This program is free software; you can redistribute it and/or modify
1687 +# it under the terms of the GNU General Public License as published by
1688 +# the Free Software Foundation; either version 2 of the License, or
1689 +# (at your option) any later version.
1691 +# This program is distributed in the hope that it will be useful,
1692 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1693 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1694 +# GNU General Public License for more details.
1696 +# You should have received a copy of the GNU General Public License
1697 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1699 +Branch Manipulation
1701 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1702 +and changing its permission/attribute, there are a lot of works to do.
1706 +----------------------------------------------------------------------
1707 +o Confirm the adding dir exists outside of aufs, including loopback
1708 + mount, and its various attributes.
1709 +o Initialize the xino file and whiteout bases if necessary.
1712 +o Check the owner/group/mode of the directory
1713 + When the owner/group/mode of the adding directory differs from the
1714 + existing branch, aufs issues a warning because it may impose a
1716 + For example, when a upper writable branch has a world writable empty
1717 + top directory, a malicious user can create any files on the writable
1718 + branch directly, like copy-up and modify manually. If something like
1719 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1720 + writable branch, and the writable branch is world-writable, then a
1721 + malicious guy may create /etc/passwd on the writable branch directly
1722 + and the infected file will be valid in aufs.
1723 + I am afraid it can be a security issue, but aufs can do nothing except
1724 + producing a warning.
1728 +----------------------------------------------------------------------
1729 +o Confirm the deleting branch is not busy
1730 + To be general, there is one merit to adopt "remount" interface to
1731 + manipulate branches. It is to discard caches. At deleting a branch,
1732 + aufs checks the still cached (and connected) dentries and inodes. If
1733 + there are any, then they are all in-use. An inode without its
1734 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1736 + For the cached one, aufs checks whether the same named entry exists on
1738 + If the cached one is a directory, because aufs provides a merged view
1739 + to users, as long as one dir is left on any branch aufs can show the
1740 + dir to users. In this case, the branch can be removed from aufs.
1741 + Otherwise aufs rejects deleting the branch.
1743 + If any file on the deleting branch is opened by aufs, then aufs
1747 +Modify the Permission of a Branch
1748 +----------------------------------------------------------------------
1749 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1752 +o rw --> ro: Confirm the modifying branch is not busy
1753 + Aufs rejects the request if any of these conditions are true.
1754 + - a file on the branch is mmap-ed.
1755 + - a regular file on the branch is opened for write and there is no
1756 + same named entry on the upper branch.
1757 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1758 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1759 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2015-09-24 10:47:58.244719488 +0200
1762 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1764 +# This program is free software; you can redistribute it and/or modify
1765 +# it under the terms of the GNU General Public License as published by
1766 +# the Free Software Foundation; either version 2 of the License, or
1767 +# (at your option) any later version.
1769 +# This program is distributed in the hope that it will be useful,
1770 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1771 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1772 +# GNU General Public License for more details.
1774 +# You should have received a copy of the GNU General Public License
1775 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1777 +Policies to Select One among Multiple Writable Branches
1778 +----------------------------------------------------------------------
1779 +When the number of writable branch is more than one, aufs has to decide
1780 +the target branch for file creation or copy-up. By default, the highest
1781 +writable branch which has the parent (or ancestor) dir of the target
1782 +file is chosen (top-down-parent policy).
1783 +By user's request, aufs implements some other policies to select the
1784 +writable branch, for file creation several policies, round-robin,
1785 +most-free-space, and other policies. For copy-up, top-down-parent,
1786 +bottom-up-parent, bottom-up and others.
1788 +As expected, the round-robin policy selects the branch in circular. When
1789 +you have two writable branches and creates 10 new files, 5 files will be
1790 +created for each branch. mkdir(2) systemcall is an exception. When you
1791 +create 10 new directories, all will be created on the same branch.
1792 +And the most-free-space policy selects the one which has most free
1793 +space among the writable branches. The amount of free space will be
1794 +checked by aufs internally, and users can specify its time interval.
1796 +The policies for copy-up is more simple,
1797 +top-down-parent is equivalent to the same named on in create policy,
1798 +bottom-up-parent selects the writable branch where the parent dir
1799 +exists and the nearest upper one from the copyup-source,
1800 +bottom-up selects the nearest upper writable branch from the
1801 +copyup-source, regardless the existence of the parent dir.
1803 +There are some rules or exceptions to apply these policies.
1804 +- If there is a readonly branch above the policy-selected branch and
1805 + the parent dir is marked as opaque (a variation of whiteout), or the
1806 + target (creating) file is whiteout-ed on the upper readonly branch,
1807 + then the result of the policy is ignored and the target file will be
1808 + created on the nearest upper writable branch than the readonly branch.
1809 +- If there is a writable branch above the policy-selected branch and
1810 + the parent dir is marked as opaque or the target file is whiteouted
1811 + on the branch, then the result of the policy is ignored and the target
1812 + file will be created on the highest one among the upper writable
1813 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1815 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1816 + They try selecting the branch where the source exists as possible
1817 + since copyup a large file will take long time. If it can't be,
1818 + ie. the branch where the source exists is readonly, then they will
1819 + follow the copyup policy.
1820 +- There is an exception for rename(2) when the target exists.
1821 + If the rename target exists, aufs compares the index of the branches
1822 + where the source and the target exists and selects the higher
1823 + one. If the selected branch is readonly, then aufs follows the
1825 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1826 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1827 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2015-09-24 10:47:58.244719488 +0200
1830 +# Copyright (C) 2011-2015 Junjiro R. Okajima
1832 +# This program is free software; you can redistribute it and/or modify
1833 +# it under the terms of the GNU General Public License as published by
1834 +# the Free Software Foundation; either version 2 of the License, or
1835 +# (at your option) any later version.
1837 +# This program is distributed in the hope that it will be useful,
1838 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1839 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1840 +# GNU General Public License for more details.
1842 +# You should have received a copy of the GNU General Public License
1843 +# along with this program; if not, write to the Free Software
1844 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1847 +File-based Hierarchical Storage Management (FHSM)
1848 +----------------------------------------------------------------------
1849 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1850 +storage world. Aufs provides this feature as file-based with multiple
1851 +writable branches, based upon the principle of "Colder, the Lower".
1852 +Here the word "colder" means that the less used files, and "lower" means
1853 +that the position in the order of the stacked branches vertically.
1854 +These multiple writable branches are prioritized, ie. the topmost one
1855 +should be the fastest drive and be used heavily.
1857 +o Characters in aufs FHSM story
1858 +- aufs itself and a new branch attribute.
1859 +- a new ioctl interface to move-down and to establish a connection with
1860 + the daemon ("move-down" is a converse of "copy-up").
1861 +- userspace tool and daemon.
1863 +The userspace daemon establishes a connection with aufs and waits for
1864 +the notification. The notified information is very similar to struct
1865 +statfs containing the number of consumed blocks and inodes.
1866 +When the consumed blocks/inodes of a branch exceeds the user-specified
1867 +upper watermark, the daemon activates its move-down process until the
1868 +consumed blocks/inodes reaches the user-specified lower watermark.
1870 +The actual move-down is done by aufs based upon the request from
1871 +user-space since we need to maintain the inode number and the internal
1872 +pointer arrays in aufs.
1874 +Currently aufs FHSM handles the regular files only. Additionally they
1875 +must not be hard-linked nor pseudo-linked.
1878 +o Cowork of aufs and the user-space daemon
1879 + During the userspace daemon established the connection, aufs sends a
1880 + small notification to it whenever aufs writes something into the
1881 + writable branch. But it may cost high since aufs issues statfs(2)
1882 + internally. So user can specify a new option to cache the
1883 + info. Actually the notification is controlled by these factors.
1884 + + the specified cache time.
1885 + + classified as "force" by aufs internally.
1886 + Until the specified time expires, aufs doesn't send the info
1887 + except the forced cases. When aufs decide forcing, the info is always
1888 + notified to userspace.
1889 + For example, the number of free inodes is generally large enough and
1890 + the shortage of it happens rarely. So aufs doesn't force the
1891 + notification when creating a new file, directory and others. This is
1892 + the typical case which aufs doesn't force.
1893 + When aufs writes the actual filedata and the files consumes any of new
1894 + blocks, the aufs forces notifying.
1897 +o Interfaces in aufs
1898 +- New branch attribute.
1900 + Specifies that the branch is managed by FHSM feature. In other word,
1901 + participant in the FHSM.
1902 + When nofhsm is set to the branch, it will not be the source/target
1903 + branch of the move-down operation. This attribute is set
1904 + independently from coo and moo attributes, and if you want full
1905 + FHSM, you should specify them as well.
1906 +- New mount option.
1908 + Specifies a second to suppress many less important info to be
1911 + + AUFS_CTL_FHSM_FD
1912 + create a new file descriptor which userspace can read the notification
1913 + (a subset of struct statfs) from aufs.
1914 +- Module parameter 'brs'
1915 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
1917 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
1918 + When there are two or more branches with fhsm attributes,
1919 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
1920 + terminates it. As a result of remounting and branch-manipulation, the
1921 + number of branches with fhsm attribute can be one. In this case,
1922 + /sbin/mount.aufs will terminate the user-space daemon.
1925 +Finally the operation is done as these steps in kernel-space.
1927 + + no one else is using the file.
1928 + + the file is not hard-linked.
1929 + + the file is not pseudo-linked.
1930 + + the file is a regular file.
1931 + + the parent dir is not opaqued.
1932 +- find the target writable branch.
1933 +- make sure the file is not whiteout-ed by the upper (than the target)
1935 +- make the parent dir on the target branch.
1936 +- mutex lock the inode on the branch.
1937 +- unlink the whiteout on the target branch (if exists).
1938 +- lookup and create the whiteout-ed temporary name on the target branch.
1939 +- copy the file as the whiteout-ed temporary name on the target branch.
1940 +- rename the whiteout-ed temporary name to the original name.
1941 +- unlink the file on the source branch.
1942 +- maintain the internal pointer array and the external inode number
1944 +- maintain the timestamps and other attributes of the parent dir and the
1947 +And of course, in every step, an error may happen. So the operation
1948 +should restore the original file state after an error happens.
1949 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
1950 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
1951 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2015-09-24 10:47:58.244719488 +0200
1954 +# Copyright (C) 2005-2015 Junjiro R. Okajima
1956 +# This program is free software; you can redistribute it and/or modify
1957 +# it under the terms of the GNU General Public License as published by
1958 +# the Free Software Foundation; either version 2 of the License, or
1959 +# (at your option) any later version.
1961 +# This program is distributed in the hope that it will be useful,
1962 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1963 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1964 +# GNU General Public License for more details.
1966 +# You should have received a copy of the GNU General Public License
1967 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1969 +mmap(2) -- File Memory Mapping
1970 +----------------------------------------------------------------------
1971 +In aufs, the file-mapped pages are handled by a branch fs directly, no
1972 +interaction with aufs. It means aufs_mmap() calls the branch fs's
1974 +This approach is simple and good, but there is one problem.
1975 +Under /proc, several entries show the mmapped files by its path (with
1976 +device and inode number), and the printed path will be the path on the
1977 +branch fs's instead of virtual aufs's.
1978 +This is not a problem in most cases, but some utilities lsof(1) (and its
1979 +user) may expect the path on aufs.
1981 +To address this issue, aufs adds a new member called vm_prfile in struct
1982 +vm_area_struct (and struct vm_region). The original vm_file points to
1983 +the file on the branch fs in order to handle everything correctly as
1984 +usual. The new vm_prfile points to a virtual file in aufs, and the
1985 +show-functions in procfs refers to vm_prfile if it is set.
1986 +Also we need to maintain several other places where touching vm_file
1988 +- fork()/clone() copies vma and the reference count of vm_file is
1990 +- merging vma maintains the ref count too.
1992 +This is not a good approach. It just fakes the printed path. But it
1993 +leaves all behaviour around f_mapping unchanged. This is surely an
1995 +Actually aufs had adopted another complicated approach which calls
1996 +generic_file_mmap() and handles struct vm_operations_struct. In this
1997 +approach, aufs met a hard problem and I could not solve it without
1998 +switching the approach.
2000 +There may be one more another approach which is
2001 +- bind-mount the branch-root onto the aufs-root internally
2002 +- grab the new vfsmount (ie. struct mount)
2003 +- lazy-umount the branch-root internally
2004 +- in open(2) the aufs-file, open the branch-file with the hidden
2005 + vfsmount (instead of the original branch's vfsmount)
2006 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2007 + but it may be possible from userspace by the mount helper.
2009 +Adding the internal hidden vfsmount and using it in opening a file, the
2010 +file path under /proc will be printed correctly. This approach looks
2011 +smarter, but is not possible I am afraid.
2012 +- aufs-root may be bind-mount later. when it happens, another hidden
2013 + vfsmount will be required.
2014 +- it is hard to get the chance to bind-mount and lazy-umount
2015 + + in kernel-space, FS can have vfsmount in open(2) via
2016 + file->f_path, and aufs can know its vfsmount. But several locks are
2017 + already acquired, and if aufs tries to bind-mount and lazy-umount
2018 + here, then it may cause a deadlock.
2019 + + in user-space, bind-mount doesn't invoke the mount helper.
2020 +- since /proc shows dev and ino, aufs has to give vma these info. it
2021 + means a new member vm_prinode will be necessary. this is essentially
2022 + equivalent to vm_prfile described above.
2024 +I have to give up this "looks-smater" approach.
2025 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2026 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2027 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2015-09-24 10:47:58.244719488 +0200
2030 +# Copyright (C) 2014-2015 Junjiro R. Okajima
2032 +# This program is free software; you can redistribute it and/or modify
2033 +# it under the terms of the GNU General Public License as published by
2034 +# the Free Software Foundation; either version 2 of the License, or
2035 +# (at your option) any later version.
2037 +# This program is distributed in the hope that it will be useful,
2038 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2039 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2040 +# GNU General Public License for more details.
2042 +# You should have received a copy of the GNU General Public License
2043 +# along with this program; if not, write to the Free Software
2044 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2047 +Listing XATTR/EA and getting the value
2048 +----------------------------------------------------------------------
2049 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2050 +shows the values from the topmost existing file. This behaviour is good
2051 +for the non-dir entries since the bahaviour exactly matches the shown
2052 +information. But for the directories, aufs considers all the same named
2053 +entries on the lower branches. Which means, if one of the lower entry
2054 +rejects readdir call, then aufs returns an error even if the topmost
2055 +entry allows it. This behaviour is necessary to respect the branch fs's
2056 +security, but can make users confused since the user-visible standard
2057 +attributes don't match the behaviour.
2058 +To address this issue, aufs has a mount option called dirperm1 which
2059 +checks the permission for the topmost entry only, and ignores the lower
2060 +entry's permission.
2062 +A similar issue can happen around XATTR.
2063 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2064 +always set. Otherwise these very unpleasant situation would happen.
2065 +- listxattr(2) may return the duplicated entries.
2066 +- users may not be able to remove or reset the XATTR forever,
2069 +XATTR/EA support in the internal (copy,move)-(up,down)
2070 +----------------------------------------------------------------------
2071 +Generally the extended attributes of inode are categorized as these.
2072 +- "security" for LSM and capability.
2073 +- "system" for posix ACL, 'acl' mount option is required for the branch
2075 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2076 +- "user" for userspace, 'user_xattr' mount option is required for the
2077 + branch fs generally.
2079 +Moreover there are some other categories. Aufs handles these rather
2080 +unpopular categories as the ordinary ones, ie. there is no special
2081 +condition nor exception.
2083 +In copy-up, the support for XATTR on the dst branch may differ from the
2084 +src branch. In this case, the copy-up operation will get an error and
2085 +the original user operation which triggered the copy-up will fail. It
2086 +can happen that even all copy-up will fail.
2087 +When both of src and dst branches support XATTR and if an error occurs
2088 +during copying XATTR, then the copy-up should fail obviously. That is a
2089 +good reason and aufs should return an error to userspace. But when only
2090 +the src branch support that XATTR, aufs should not return an error.
2091 +For example, the src branch supports ACL but the dst branch doesn't
2092 +because the dst branch may natively un-support it or temporary
2093 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2094 +may NOT return an error even if the XATTR is not supported. It is
2095 +totally up to the branch fs.
2097 +Anyway when the aufs internal copy-up gets an error from the dst branch
2098 +fs, then aufs tries removing the just copied entry and returns the error
2099 +to the userspace. The worst case of this situation will be all copy-up
2102 +For the copy-up operation, there two basic approaches.
2103 +- copy the specified XATTR only (by category above), and return the
2104 + error unconditionally if it happens.
2105 +- copy all XATTR, and ignore the error on the specified category only.
2107 +In order to support XATTR and to implement the correct behaviour, aufs
2108 +chooses the latter approach and introduces some new branch attributes,
2109 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2110 +They correspond to the XATTR namespaces (see above). Additionally, to be
2111 +convenient, "icex" is also provided which means all "icex*" attributes
2112 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2114 +The meaning of these attributes is to ignore the error from setting
2115 +XATTR on that branch.
2116 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2117 +error from the dst branch according to the specified attributes.
2119 +Some XATTR may have its default value. The default value may come from
2120 +the parent dir or the environment. If the default value is set at the
2121 +file creating-time, it will be overwritten by copy-up.
2122 +Some contradiction may happen I am afraid.
2123 +Do we need another attribute to stop copying XATTR? I am unsure. For
2124 +now, aufs implements the branch attributes to ignore the error.
2125 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2126 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2127 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2015-09-24 10:47:58.248052907 +0200
2130 +# Copyright (C) 2005-2015 Junjiro R. Okajima
2132 +# This program is free software; you can redistribute it and/or modify
2133 +# it under the terms of the GNU General Public License as published by
2134 +# the Free Software Foundation; either version 2 of the License, or
2135 +# (at your option) any later version.
2137 +# This program is distributed in the hope that it will be useful,
2138 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2139 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2140 +# GNU General Public License for more details.
2142 +# You should have received a copy of the GNU General Public License
2143 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2145 +Export Aufs via NFS
2146 +----------------------------------------------------------------------
2147 +Here is an approach.
2148 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2150 +- iget_locked(): initialize aufs inode generation for a new inode, and
2151 + store it in xigen file.
2152 +- destroy_inode(): increment aufs inode generation and store it in xigen
2153 + file. it is necessary even if it is not unlinked, because any data of
2154 + inode may be changed by UDBA.
2155 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2156 + build file handle by
2157 + + branch id (4 bytes)
2158 + + superblock generation (4 bytes)
2159 + + inode number (4 or 8 bytes)
2160 + + parent dir inode number (4 or 8 bytes)
2161 + + inode generation (4 bytes))
2162 + + return value of exportfs_encode_fh() for the parent on a branch (4
2164 + + file handle for a branch (by exportfs_encode_fh())
2166 + + find the index of a branch from its id in handle, and check it is
2167 + still exist in aufs.
2168 + + 1st level: get the inode number from handle and search it in cache.
2169 + + 2nd level: if not found in cache, get the parent inode number from
2170 + the handle and search it in cache. and then open the found parent
2171 + dir, find the matching inode number by vfs_readdir() and get its
2172 + name, and call lookup_one_len() for the target dentry.
2173 + + 3rd level: if the parent dir is not cached, call
2174 + exportfs_decode_fh() for a branch and get the parent on a branch,
2175 + build a pathname of it, convert it a pathname in aufs, call
2176 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2178 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2179 + for every branch, but not itself. to get this, (currently) aufs
2180 + searches in current->nsproxy->mnt_ns list. it may not be a good
2181 + idea, but I didn't get other approach.
2182 + + test the generation of the gotten inode.
2183 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2184 + convert it into ESTALE for NFSD.
2185 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2186 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2187 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2188 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2189 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2015-09-24 10:47:58.248052907 +0200
2192 +# Copyright (C) 2005-2015 Junjiro R. Okajima
2194 +# This program is free software; you can redistribute it and/or modify
2195 +# it under the terms of the GNU General Public License as published by
2196 +# the Free Software Foundation; either version 2 of the License, or
2197 +# (at your option) any later version.
2199 +# This program is distributed in the hope that it will be useful,
2200 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2201 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2202 +# GNU General Public License for more details.
2204 +# You should have received a copy of the GNU General Public License
2205 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2207 +Show Whiteout Mode (shwh)
2208 +----------------------------------------------------------------------
2209 +Generally aufs hides the name of whiteouts. But in some cases, to show
2210 +them is very useful for users. For instance, creating a new middle layer
2211 +(branch) by merging existing layers.
2213 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2214 +When you have three branches,
2215 +- Bottom: 'system', squashfs (underlying base system), read-only
2216 +- Middle: 'mods', squashfs, read-only
2217 +- Top: 'overlay', ram (tmpfs), read-write
2219 +The top layer is loaded at boot time and saved at shutdown, to preserve
2220 +the changes made to the system during the session.
2221 +When larger changes have been made, or smaller changes have accumulated,
2222 +the size of the saved top layer data grows. At this point, it would be
2223 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2224 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2225 +restoring save and load speed.
2227 +This merging is simplified by the use of another aufs mount, of just the
2228 +two overlay branches using the 'shwh' option.
2229 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2230 + aufs /livesys/merge_union
2232 +A merged view of these two branches is then available at
2233 +/livesys/merge_union, and the new feature is that the whiteouts are
2235 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2236 +writing to all branches. Also the default mode for all branches is 'ro'.
2237 +It is now possible to save the combined contents of the two overlay
2238 +branches to a new squashfs, e.g.:
2239 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2241 +This new squashfs archive can be stored on the boot device and the
2242 +initramfs will use it to replace the old one at the next boot.
2243 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2244 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2245 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2015-09-24 10:47:58.248052907 +0200
2248 +# Copyright (C) 2010-2015 Junjiro R. Okajima
2250 +# This program is free software; you can redistribute it and/or modify
2251 +# it under the terms of the GNU General Public License as published by
2252 +# the Free Software Foundation; either version 2 of the License, or
2253 +# (at your option) any later version.
2255 +# This program is distributed in the hope that it will be useful,
2256 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2257 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2258 +# GNU General Public License for more details.
2260 +# You should have received a copy of the GNU General Public License
2261 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2263 +Dynamically customizable FS operations
2264 +----------------------------------------------------------------------
2265 +Generally FS operations (struct inode_operations, struct
2266 +address_space_operations, struct file_operations, etc.) are defined as
2267 +"static const", but it never means that FS have only one set of
2268 +operation. Some FS have multiple sets of them. For instance, ext2 has
2269 +three sets, one for XIP, for NOBH, and for normal.
2270 +Since aufs overrides and redirects these operations, sometimes aufs has
2271 +to change its behaviour according to the branch FS type. More importantly
2272 +VFS acts differently if a function (member in the struct) is set or
2273 +not. It means aufs should have several sets of operations and select one
2274 +among them according to the branch FS definition.
2276 +In order to solve this problem and not to affect the behaviour of VFS,
2277 +aufs defines these operations dynamically. For instance, aufs defines
2278 +dummy direct_IO function for struct address_space_operations, but it may
2279 +not be set to the address_space_operations actually. When the branch FS
2280 +doesn't have it, aufs doesn't set it to its address_space_operations
2281 +while the function definition itself is still alive. So the behaviour
2282 +itself will not change, and it will return an error when direct_IO is
2285 +The lifetime of these dynamically generated operation object is
2286 +maintained by aufs branch object. When the branch is removed from aufs,
2287 +the reference counter of the object is decremented. When it reaches
2288 +zero, the dynamically generated operation object will be freed.
2290 +This approach is designed to support AIO (io_submit), Direct I/O and
2292 +Currently this approach is applied to address_space_operations for
2293 +regular files only.
2294 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2295 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2296 +++ linux/Documentation/filesystems/aufs/README 2015-09-24 10:47:58.244719488 +0200
2299 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2305 +----------------------------------------
2306 +In the early days, aufs was entirely re-designed and re-implemented
2307 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2308 +improvements and implementations, it becomes totally different from
2309 +Unionfs while keeping the basic features.
2310 +Recently, Unionfs Version 2.x series begin taking some of the same
2311 +approaches to aufs1's.
2312 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2313 +University and his team.
2315 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2316 +If you want older kernel version support, try aufs2-2.6.git or
2317 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2319 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2320 + According to Christoph Hellwig, linux rejects all union-type
2321 + filesystems but UnionMount.
2322 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2324 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2325 + UnionMount, and he pointed out an issue around a directory mutex
2326 + lock and aufs addressed it. But it is still unsure whether aufs will
2327 + be merged (or any other union solution).
2328 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2332 +----------------------------------------
2333 +- unite several directories into a single virtual filesystem. The member
2334 + directory is called as a branch.
2335 +- you can specify the permission flags to the branch, which are 'readonly',
2336 + 'readwrite' and 'whiteout-able.'
2337 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2338 + readonly branch are modifiable logically.
2339 +- dynamic branch manipulation, add, del.
2342 +Also there are many enhancements in aufs, such as:
2343 +- test only the highest one for the directory permission (dirperm1)
2344 +- copyup on open (coo=)
2345 +- 'move' policy for copy-up between two writable branches, after
2346 + checking free space.
2348 +- readdir(3) in userspace.
2349 +- keep inode number by external inode number table
2350 +- keep the timestamps of file/dir in internal copyup operation
2351 +- seekable directory, supporting NFS readdir.
2352 +- whiteout is hardlinked in order to reduce the consumption of inodes
2354 +- do not copyup, nor create a whiteout when it is unnecessary
2355 +- revert a single systemcall when an error occurs in aufs
2356 +- remount interface instead of ioctl
2357 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2358 +- loopback mounted filesystem as a branch
2359 +- kernel thread for removing the dir who has a plenty of whiteouts
2360 +- support copyup sparse file (a file which has a 'hole' in it)
2361 +- default permission flags for branches
2362 +- selectable permission flags for ro branch, whether whiteout can
2365 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2366 +- support multiple writable branches, some policies to select one
2367 + among multiple writable branches.
2368 +- a new semantics for link(2) and rename(2) to support multiple
2369 + writable branches.
2370 +- no glibc changes are required.
2371 +- pseudo hardlink (hardlink over branches)
2372 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2373 + including NFS or remote filesystem branch.
2374 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2377 +Currently these features are dropped temporary from aufs4.
2378 +See design/08plan.txt in detail.
2379 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2381 +- statistics of aufs thread (/sys/fs/aufs/stat)
2383 +Features or just an idea in the future (see also design/*.txt),
2384 +- reorder the branch index without del/re-add.
2385 +- permanent xino files for NFSD
2386 +- an option for refreshing the opened files after add/del branches
2387 +- light version, without branch manipulation. (unnecessary?)
2388 +- copyup in userspace
2389 +- inotify in userspace
2394 +----------------------------------------
2395 +There are three GIT trees for aufs4, aufs4-linux.git,
2396 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2398 +While the aufs-util is always necessary, you need either of aufs4-linux
2399 +or aufs4-standalone.
2401 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2402 +git://git.kernel.org/.../torvalds/linux.git.
2403 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2404 +build aufs4 as an external kernel module.
2405 +Several extra patches are not included in this tree. Only
2406 +aufs4-standalone tree contains them. They are describe in the later
2407 +section "Configuration and Compilation."
2409 +On the other hand, the aufs4-standalone tree has only aufs source files
2410 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2411 +But you need to apply all aufs patches manually.
2413 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2414 +represents the linux kernel version, "linux-4.x". For instance,
2415 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2416 +"aufs4.x-rcN" branch.
2419 +$ git clone --reference /your/linux/git/tree \
2420 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2421 +- if you don't have linux GIT tree, then remove "--reference ..."
2422 +$ cd aufs4-linux.git
2423 +$ git checkout origin/aufs4.0
2425 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2426 +leave the patch-work to GIT.
2427 +$ cd /your/linux/git/tree
2428 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2430 +$ git checkout -b my4.0 v4.0
2431 +$ (add your local change...)
2432 +$ git pull aufs4 aufs4.0
2433 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2434 +- you may need to solve some conflicts between your_changes and
2435 + aufs4.0. in this case, git-rerere is recommended so that you can
2436 + solve the similar conflicts automatically when you upgrade to 4.1 or
2437 + later in the future.
2439 +o aufs4-standalone tree
2440 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2441 +$ cd aufs4-standalone.git
2442 +$ git checkout origin/aufs4.0
2445 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2446 +- note that the public aufs-util.git is on SourceForge instead of
2449 +$ git checkout origin/aufs4.0
2451 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2452 +The minor version number, 'x' in '4.x', of aufs may not always
2453 +follow the minor version number of the kernel.
2454 +Because changes in the kernel that cause the use of a new
2455 +minor version number do not always require changes to aufs-util.
2457 +Since aufs-util has its own minor version number, you may not be
2458 +able to find a GIT branch in aufs-util for your kernel's
2459 +exact minor version number.
2460 +In this case, you should git-checkout the branch for the
2461 +nearest lower number.
2463 +For (an unreleased) example:
2464 +If you are using "linux-4.10" and the "aufs4.10" branch
2465 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2466 +or something numerically smaller is the branch for your kernel.
2468 +Also you can view all branches by
2472 +3. Configuration and Compilation
2473 +----------------------------------------
2474 +Make sure you have git-checkout'ed the correct branch.
2476 +For aufs4-linux tree,
2477 +- enable CONFIG_AUFS_FS.
2478 +- set other aufs configurations if necessary.
2480 +For aufs4-standalone tree,
2481 +There are several ways to build.
2484 +- apply ./aufs4-kbuild.patch to your kernel source files.
2485 +- apply ./aufs4-base.patch too.
2486 +- apply ./aufs4-mmap.patch too.
2487 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2488 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2489 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2490 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2491 +- enable CONFIG_AUFS_FS, you can select either
2493 +- and build your kernel as usual.
2494 +- install the built kernel.
2495 + Note: Since linux-3.9, every filesystem module requires an alias
2496 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2497 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2498 +- install the header files too by "make headers_install" to the
2499 + directory where you specify. By default, it is $PWD/usr.
2500 + "make help" shows a brief note for headers_install.
2501 +- and reboot your system.
2504 +- module only (CONFIG_AUFS_FS=m).
2505 +- apply ./aufs4-base.patch to your kernel source files.
2506 +- apply ./aufs4-mmap.patch too.
2507 +- apply ./aufs4-standalone.patch too.
2508 +- build your kernel, don't forget "make headers_install", and reboot.
2509 +- edit ./config.mk and set other aufs configurations if necessary.
2510 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2511 + every aufs configurations.
2512 +- build the module by simple "make".
2513 + Note: Since linux-3.9, every filesystem module requires an alias
2514 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2515 + modules.aliases file.
2516 +- you can specify ${KDIR} make variable which points to your kernel
2518 +- install the files
2519 + + run "make install" to install the aufs module, or copy the built
2520 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2521 + + run "make install_headers" (instead of headers_install) to install
2522 + the modified aufs header file (you can specify DESTDIR which is
2523 + available in aufs standalone version's Makefile only), or copy
2524 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2525 + you like manually. By default, the target directory is $PWD/usr.
2526 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2527 + kernel source tree.
2529 +Note: The header file aufs_type.h is necessary to build aufs-util
2530 + as well as "make headers_install" in the kernel source tree.
2531 + headers_install is subject to be forgotten, but it is essentially
2532 + necessary, not only for building aufs-util.
2533 + You may not meet problems without headers_install in some older
2537 +- read README in aufs-util, build and install it
2538 +- note that your distribution may contain an obsoleted version of
2539 + aufs_type.h in /usr/include/linux or something. When you build aufs
2540 + utilities, make sure that your compiler refers the correct aufs header
2541 + file which is built by "make headers_install."
2542 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2543 + then run "make install_ulib" too. And refer to the aufs manual in
2546 +There several other patches in aufs4-standalone.git. They are all
2547 +optional. When you meet some problems, they will help you.
2548 +- aufs4-loopback.patch
2549 + Supports a nested loopback mount in a branch-fs. This patch is
2550 + unnecessary until aufs produces a message like "you may want to try
2551 + another patch for loopback file".
2553 + Modifies a system global kernel internal function get_next_ino() in
2554 + order to stop assigning 0 for an inode-number. Not directly related to
2555 + aufs, but recommended generally.
2557 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2558 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2559 + duplication of inode number, which is important for backup tools and
2560 + other utilities. When you find aufs XINO files for tmpfs branch
2561 + growing too much, try this patch.
2565 +----------------------------------------
2566 +At first, make sure aufs-util are installed, and please read the aufs
2567 +manual, aufs.5 in aufs-util.git tree.
2571 +$ mkdir /tmp/rw /tmp/aufs
2572 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2574 +Here is another example. The result is equivalent.
2575 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2577 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2578 +# mount -o remount,append:${HOME} /tmp/aufs
2580 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2581 +you modify a file under /tmp/aufs, the one on your home directory is
2582 +not affected, instead the same named file will be newly created under
2583 +/tmp/rw. And all of your modification to a file will be applied to
2584 +the one under /tmp/rw. This is called the file based Copy on Write
2586 +Aufs mount options are described in aufs.5.
2587 +If you run chroot or something and make your aufs as a root directory,
2588 +then you need to customize the shutdown script. See the aufs manual in
2591 +Additionally, there are some sample usages of aufs which are a
2592 +diskless system with network booting, and LiveCD over NFS.
2593 +See sample dir in CVS tree on SourceForge.
2597 +----------------------------------------
2598 +When you have any problems or strange behaviour in aufs, please let me
2600 +- /proc/mounts (instead of the output of mount(8))
2601 +- /sys/module/aufs/*
2602 +- /sys/fs/aufs/* (if you have them)
2603 +- /debug/aufs/* (if you have them)
2604 +- linux kernel version
2605 + if your kernel is not plain, for example modified by distributor,
2606 + the url where i can download its source is necessary too.
2607 +- aufs version which was printed at loading the module or booting the
2608 + system, instead of the date you downloaded.
2609 +- configuration (define/undefine CONFIG_AUFS_xxx)
2610 +- kernel configuration or /proc/config.gz (if you have it)
2611 +- behaviour which you think to be incorrect
2612 +- actual operation, reproducible one is better
2613 +- mailto: aufs-users at lists.sourceforge.net
2615 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2616 +and Feature Requests) on SourceForge. Please join and write to
2620 +6. Acknowledgements
2621 +----------------------------------------
2622 +Thanks to everyone who have tried and are using aufs, whoever
2623 +have reported a bug or any feedback.
2625 +Especially donators:
2626 +Tomas Matejicek(slax.org) made a donation (much more than once).
2627 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2628 + scripts) is making "doubling" donations.
2629 + Unfortunately I cannot list all of the donators, but I really
2631 + It ends Aug 2010, but the ordinary donation URL is still available.
2632 + <http://sourceforge.net/donate/index.php?group_id=167503>
2633 +Dai Itasaka made a donation (2007/8).
2634 +Chuck Smith made a donation (2008/4, 10 and 12).
2635 +Henk Schoneveld made a donation (2008/9).
2636 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2637 +Francois Dupoux made a donation (2008/11).
2638 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2639 + aufs2 GIT tree (2009/2).
2640 +William Grant made a donation (2009/3).
2641 +Patrick Lane made a donation (2009/4).
2642 +The Mail Archive (mail-archive.com) made donations (2009/5).
2643 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2644 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2645 +Pavel Pronskiy made a donation (2011/2).
2646 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2647 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2648 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2650 +Sam Liddicott made a donation (2011/9).
2651 +Era Scarecrow made a donation (2013/4).
2652 +Bor Ratajc made a donation (2013/4).
2653 +Alessandro Gorreta made a donation (2013/4).
2654 +POIRETTE Marc made a donation (2013/4).
2655 +Alessandro Gorreta made a donation (2013/4).
2656 +lauri kasvandik made a donation (2013/5).
2657 +"pemasu from Finland" made a donation (2013/7).
2658 +The Parted Magic Project made a donation (2013/9 and 11).
2659 +Pavel Barta made a donation (2013/10).
2660 +Nikolay Pertsev made a donation (2014/5).
2661 +James B made a donation (2014/7 and 2015/7).
2662 +Stefano Di Biase made a donation (2014/8).
2663 +Daniel Epellei made a donation (2015/1).
2665 +Thank you very much.
2666 +Donations are always, including future donations, very important and
2667 +helpful for me to keep on developing aufs.
2671 +----------------------------------------
2672 +If you are an experienced user, no explanation is needed. Aufs is
2673 +just a linux filesystem.
2678 +# Local variables: ;
2681 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2682 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2683 +++ linux/fs/aufs/aufs.h 2015-09-24 10:47:58.248052907 +0200
2686 + * Copyright (C) 2005-2015 Junjiro R. Okajima
2688 + * This program, aufs is free software; you can redistribute it and/or modify
2689 + * it under the terms of the GNU General Public License as published by
2690 + * the Free Software Foundation; either version 2 of the License, or
2691 + * (at your option) any later version.
2693 + * This program is distributed in the hope that it will be useful,
2694 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2695 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2696 + * GNU General Public License for more details.
2698 + * You should have received a copy of the GNU General Public License
2699 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2703 + * all header files
2711 +#define AuStub(type, name, body, ...) \
2712 + static inline type name(__VA_ARGS__) { body; }
2714 +#define AuStubVoid(name, ...) \
2715 + AuStub(void, name, , __VA_ARGS__)
2716 +#define AuStubInt0(name, ...) \
2717 + AuStub(int, name, return 0, __VA_ARGS__)
2721 +#include "branch.h"
2724 +#include "dbgaufs.h"
2725 +#include "dentry.h"
2729 +#include "fstype.h"
2732 +#include "module.h"
2737 +#include "sysaufs.h"
2742 +#endif /* __KERNEL__ */
2743 +#endif /* __AUFS_H__ */
2744 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2745 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2746 +++ linux/fs/aufs/branch.c 2015-09-24 10:47:58.248052907 +0200
2749 + * Copyright (C) 2005-2015 Junjiro R. Okajima
2751 + * This program, aufs is free software; you can redistribute it and/or modify
2752 + * it under the terms of the GNU General Public License as published by
2753 + * the Free Software Foundation; either version 2 of the License, or
2754 + * (at your option) any later version.
2756 + * This program is distributed in the hope that it will be useful,
2757 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2758 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2759 + * GNU General Public License for more details.
2761 + * You should have received a copy of the GNU General Public License
2762 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2766 + * branch management
2769 +#include <linux/compat.h>
2770 +#include <linux/statfs.h>
2774 + * free a single branch
2776 +static void au_br_do_free(struct au_branch *br)
2779 + struct au_wbr *wbr;
2780 + struct au_dykey **key;
2782 + au_hnotify_fin_br(br);
2784 + if (br->br_xino.xi_file)
2785 + fput(br->br_xino.xi_file);
2786 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2788 + AuDebugOn(atomic_read(&br->br_count));
2792 + for (i = 0; i < AuBrWh_Last; i++)
2793 + dput(wbr->wbr_wh[i]);
2794 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2795 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2798 + if (br->br_fhsm) {
2799 + au_br_fhsm_fin(br->br_fhsm);
2800 + kfree(br->br_fhsm);
2803 + key = br->br_dykey;
2804 + for (i = 0; i < AuBrDynOp; i++, key++)
2810 + /* recursive lock, s_umount of branch's */
2812 + path_put(&br->br_path);
2819 + * frees all branches
2821 +void au_br_free(struct au_sbinfo *sbinfo)
2823 + aufs_bindex_t bmax;
2824 + struct au_branch **br;
2826 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2828 + bmax = sbinfo->si_bend + 1;
2829 + br = sbinfo->si_branch;
2831 + au_br_do_free(*br++);
2835 + * find the index of a branch which is specified by @br_id.
2837 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2839 + aufs_bindex_t bindex, bend;
2841 + bend = au_sbend(sb);
2842 + for (bindex = 0; bindex <= bend; bindex++)
2843 + if (au_sbr_id(sb, bindex) == br_id)
2848 +/* ---------------------------------------------------------------------- */
2854 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2855 + struct dentry *h_root)
2857 + if (unlikely(h_adding == h_root
2858 + || au_test_loopback_overlap(sb, h_adding)))
2860 + if (h_adding->d_sb != h_root->d_sb)
2862 + return au_test_subdir(h_adding, h_root)
2863 + || au_test_subdir(h_root, h_adding);
2867 + * returns a newly allocated branch. @new_nbranch is a number of branches
2868 + * after adding a branch.
2870 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2873 + struct au_branch *add_branch;
2874 + struct dentry *root;
2875 + struct inode *inode;
2879 + root = sb->s_root;
2880 + add_branch = kmalloc(sizeof(*add_branch), GFP_NOFS);
2881 + if (unlikely(!add_branch))
2884 + err = au_hnotify_init_br(add_branch, perm);
2885 + if (unlikely(err))
2888 + add_branch->br_wbr = NULL;
2889 + if (au_br_writable(perm)) {
2890 + /* may be freed separately at changing the branch permission */
2891 + add_branch->br_wbr = kmalloc(sizeof(*add_branch->br_wbr),
2893 + if (unlikely(!add_branch->br_wbr))
2897 + add_branch->br_fhsm = NULL;
2898 + if (au_br_fhsm(perm)) {
2899 + err = au_fhsm_br_alloc(add_branch);
2900 + if (unlikely(err))
2904 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
2906 + err = au_di_realloc(au_di(root), new_nbranch);
2908 + inode = d_inode(root);
2909 + err = au_ii_realloc(au_ii(inode), new_nbranch);
2912 + return add_branch; /* success */
2915 + kfree(add_branch->br_wbr);
2917 + au_hnotify_fin_br(add_branch);
2919 + kfree(add_branch);
2921 + return ERR_PTR(err);
2925 + * test if the branch permission is legal or not.
2927 +static int test_br(struct inode *inode, int brperm, char *path)
2931 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
2936 + pr_err("write permission for readonly mount or inode, %s\n", path);
2944 + * 0: success, the caller will add it
2945 + * plus: success, it is already unified, the caller should ignore it
2948 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
2951 + aufs_bindex_t bend, bindex;
2952 + struct dentry *root, *h_dentry;
2953 + struct inode *inode, *h_inode;
2955 + root = sb->s_root;
2956 + bend = au_sbend(sb);
2957 + if (unlikely(bend >= 0
2958 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
2962 + pr_err("%s duplicated\n", add->pathname);
2967 + err = -ENOSPC; /* -E2BIG; */
2968 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
2969 + || AUFS_BRANCH_MAX - 1 <= bend)) {
2970 + pr_err("number of branches exceeded %s\n", add->pathname);
2975 + if (unlikely(add->bindex < 0 || bend + 1 < add->bindex)) {
2976 + pr_err("bad index %d\n", add->bindex);
2980 + inode = d_inode(add->path.dentry);
2982 + if (unlikely(!inode->i_nlink)) {
2983 + pr_err("no existence %s\n", add->pathname);
2988 + if (unlikely(inode->i_sb == sb)) {
2989 + pr_err("%s must be outside\n", add->pathname);
2993 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
2994 + pr_err("unsupported filesystem, %s (%s)\n",
2995 + add->pathname, au_sbtype(inode->i_sb));
2999 + if (unlikely(inode->i_sb->s_stack_depth)) {
3000 + pr_err("already stacked, %s (%s)\n",
3001 + add->pathname, au_sbtype(inode->i_sb));
3005 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3006 + if (unlikely(err))
3010 + return 0; /* success */
3013 + for (bindex = 0; bindex <= bend; bindex++)
3014 + if (unlikely(test_overlap(sb, add->path.dentry,
3015 + au_h_dptr(root, bindex)))) {
3016 + pr_err("%s is overlapped\n", add->pathname);
3021 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3022 + h_dentry = au_h_dptr(root, 0);
3023 + h_inode = d_inode(h_dentry);
3024 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3025 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3026 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3027 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3029 + i_uid_read(inode), i_gid_read(inode),
3030 + (inode->i_mode & S_IALLUGO),
3031 + i_uid_read(h_inode), i_gid_read(h_inode),
3032 + (h_inode->i_mode & S_IALLUGO));
3040 + * initialize or clean the whiteouts for an adding branch
3042 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3045 + int err, old_perm;
3046 + aufs_bindex_t bindex;
3047 + struct mutex *h_mtx;
3048 + struct au_wbr *wbr;
3049 + struct au_hinode *hdir;
3050 + struct dentry *h_dentry;
3052 + err = vfsub_mnt_want_write(au_br_mnt(br));
3053 + if (unlikely(err))
3057 + old_perm = br->br_perm;
3058 + br->br_perm = new_perm;
3061 + bindex = au_br_index(sb, br->br_id);
3062 + if (0 <= bindex) {
3063 + hdir = au_hi(d_inode(sb->s_root), bindex);
3064 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
3066 + h_dentry = au_br_dentry(br);
3067 + h_mtx = &d_inode(h_dentry)->i_mutex;
3068 + mutex_lock_nested(h_mtx, AuLsc_I_PARENT);
3071 + err = au_wh_init(br, sb);
3073 + wbr_wh_write_lock(wbr);
3074 + err = au_wh_init(br, sb);
3075 + wbr_wh_write_unlock(wbr);
3078 + au_hn_imtx_unlock(hdir);
3080 + mutex_unlock(h_mtx);
3081 + vfsub_mnt_drop_write(au_br_mnt(br));
3082 + br->br_perm = old_perm;
3084 + if (!err && wbr && !au_br_writable(new_perm)) {
3086 + br->br_wbr = NULL;
3093 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3097 + struct kstatfs kst;
3098 + struct au_wbr *wbr;
3101 + au_rw_init(&wbr->wbr_wh_rwsem);
3102 + memset(wbr->wbr_wh, 0, sizeof(wbr->wbr_wh));
3103 + atomic_set(&wbr->wbr_wh_running, 0);
3104 + wbr->wbr_bytes = 0;
3107 + * a limit for rmdir/rename a dir
3108 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3110 + err = vfs_statfs(&br->br_path, &kst);
3111 + if (unlikely(err))
3114 + if (kst.f_namelen >= NAME_MAX)
3115 + err = au_br_init_wh(sb, br, perm);
3117 + pr_err("%pd(%s), unsupported namelen %ld\n",
3119 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3125 +/* initialize a new branch */
3126 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3127 + struct au_opt_add *add)
3130 + struct inode *h_inode;
3133 + memset(&br->br_xino, 0, sizeof(br->br_xino));
3134 + mutex_init(&br->br_xino.xi_nondir_mtx);
3135 + br->br_perm = add->perm;
3136 + br->br_path = add->path; /* set first, path_get() later */
3137 + spin_lock_init(&br->br_dykey_lock);
3138 + memset(br->br_dykey, 0, sizeof(br->br_dykey));
3139 + atomic_set(&br->br_count, 0);
3140 + atomic_set(&br->br_xino_running, 0);
3141 + br->br_id = au_new_br_id(sb);
3142 + AuDebugOn(br->br_id < 0);
3144 + if (au_br_writable(add->perm)) {
3145 + err = au_wbr_init(br, sb, add->perm);
3146 + if (unlikely(err))
3150 + if (au_opt_test(au_mntflags(sb), XINO)) {
3151 + h_inode = d_inode(add->path.dentry);
3152 + err = au_xino_br(sb, br, h_inode->i_ino,
3153 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3154 + if (unlikely(err)) {
3155 + AuDebugOn(br->br_xino.xi_file);
3160 + sysaufs_br_init(br);
3161 + path_get(&br->br_path);
3162 + goto out; /* success */
3165 + memset(&br->br_path, 0, sizeof(br->br_path));
3170 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3171 + struct au_branch *br, aufs_bindex_t bend,
3172 + aufs_bindex_t amount)
3174 + struct au_branch **brp;
3176 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3178 + brp = sbinfo->si_branch + bindex;
3179 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3181 + sbinfo->si_bend++;
3182 + if (unlikely(bend < 0))
3183 + sbinfo->si_bend = 0;
3186 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3187 + aufs_bindex_t bend, aufs_bindex_t amount)
3189 + struct au_hdentry *hdp;
3191 + AuRwMustWriteLock(&dinfo->di_rwsem);
3193 + hdp = dinfo->di_hdentry + bindex;
3194 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3195 + au_h_dentry_init(hdp);
3197 + if (unlikely(bend < 0))
3198 + dinfo->di_bstart = 0;
3201 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3202 + aufs_bindex_t bend, aufs_bindex_t amount)
3204 + struct au_hinode *hip;
3206 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3208 + hip = iinfo->ii_hinode + bindex;
3209 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3210 + hip->hi_inode = NULL;
3213 + if (unlikely(bend < 0))
3214 + iinfo->ii_bstart = 0;
3217 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3218 + aufs_bindex_t bindex)
3220 + struct dentry *root, *h_dentry;
3221 + struct inode *root_inode, *h_inode;
3222 + aufs_bindex_t bend, amount;
3224 + root = sb->s_root;
3225 + root_inode = d_inode(root);
3226 + bend = au_sbend(sb);
3227 + amount = bend + 1 - bindex;
3228 + h_dentry = au_br_dentry(br);
3229 + au_sbilist_lock();
3230 + au_br_do_add_brp(au_sbi(sb), bindex, br, bend, amount);
3231 + au_br_do_add_hdp(au_di(root), bindex, bend, amount);
3232 + au_br_do_add_hip(au_ii(root_inode), bindex, bend, amount);
3233 + au_set_h_dptr(root, bindex, dget(h_dentry));
3234 + h_inode = d_inode(h_dentry);
3235 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3236 + au_sbilist_unlock();
3239 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3242 + aufs_bindex_t bend, add_bindex;
3243 + struct dentry *root, *h_dentry;
3244 + struct inode *root_inode;
3245 + struct au_branch *add_branch;
3247 + root = sb->s_root;
3248 + root_inode = d_inode(root);
3249 + IMustLock(root_inode);
3250 + err = test_add(sb, add, remount);
3251 + if (unlikely(err < 0))
3255 + goto out; /* success */
3258 + bend = au_sbend(sb);
3259 + add_branch = au_br_alloc(sb, bend + 2, add->perm);
3260 + err = PTR_ERR(add_branch);
3261 + if (IS_ERR(add_branch))
3264 + err = au_br_init(add_branch, sb, add);
3265 + if (unlikely(err)) {
3266 + au_br_do_free(add_branch);
3270 + add_bindex = add->bindex;
3272 + au_br_do_add(sb, add_branch, add_bindex);
3274 + sysaufs_brs_del(sb, add_bindex);
3275 + au_br_do_add(sb, add_branch, add_bindex);
3276 + sysaufs_brs_add(sb, add_bindex);
3279 + h_dentry = add->path.dentry;
3280 + if (!add_bindex) {
3281 + au_cpup_attr_all(root_inode, /*force*/1);
3282 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3284 + au_add_nlink(root_inode, d_inode(h_dentry));
3287 + * this test/set prevents aufs from handling unnecesary notify events
3288 + * of xino files, in case of re-adding a writable branch which was
3289 + * once detached from aufs.
3291 + if (au_xino_brid(sb) < 0
3292 + && au_br_writable(add_branch->br_perm)
3293 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3294 + && add_branch->br_xino.xi_file
3295 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3296 + au_xino_brid_set(sb, add_branch->br_id);
3302 +/* ---------------------------------------------------------------------- */
3304 +static unsigned long long au_farray_cb(void *a,
3305 + unsigned long long max __maybe_unused,
3308 + unsigned long long n;
3309 + struct file **p, *f;
3310 + struct au_sphlhead *files;
3311 + struct au_finfo *finfo;
3312 + struct super_block *sb = arg;
3316 + files = &au_sbi(sb)->si_files;
3317 + spin_lock(&files->spin);
3318 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3319 + f = finfo->fi_file;
3321 + && !special_file(file_inode(f)->i_mode)) {
3325 + AuDebugOn(n > max);
3328 + spin_unlock(&files->spin);
3333 +static struct file **au_farray_alloc(struct super_block *sb,
3334 + unsigned long long *max)
3336 + *max = atomic_long_read(&au_sbi(sb)->si_nfiles);
3337 + return au_array_alloc(max, au_farray_cb, sb);
3340 +static void au_farray_free(struct file **a, unsigned long long max)
3342 + unsigned long long ull;
3344 + for (ull = 0; ull < max; ull++)
3350 +/* ---------------------------------------------------------------------- */
3356 +/* to show the line number, do not make it inlined function */
3357 +#define AuVerbose(do_info, fmt, ...) do { \
3359 + pr_info(fmt, ##__VA_ARGS__); \
3362 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t bstart,
3363 + aufs_bindex_t bend)
3365 + return (inode && !S_ISDIR(inode->i_mode)) || bstart == bend;
3368 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t bstart,
3369 + aufs_bindex_t bend)
3371 + return au_test_ibusy(d_inode(dentry), bstart, bend);
3375 + * test if the branch is deletable or not.
3377 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3378 + unsigned int sigen, const unsigned int verbose)
3380 + int err, i, j, ndentry;
3381 + aufs_bindex_t bstart, bend;
3382 + struct au_dcsub_pages dpages;
3383 + struct au_dpage *dpage;
3386 + err = au_dpages_init(&dpages, GFP_NOFS);
3387 + if (unlikely(err))
3389 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3390 + if (unlikely(err))
3393 + for (i = 0; !err && i < dpages.ndpage; i++) {
3394 + dpage = dpages.dpages + i;
3395 + ndentry = dpage->ndentry;
3396 + for (j = 0; !err && j < ndentry; j++) {
3397 + d = dpage->dentries[j];
3398 + AuDebugOn(au_dcount(d) <= 0);
3399 + if (!au_digen_test(d, sigen)) {
3400 + di_read_lock_child(d, AuLock_IR);
3401 + if (unlikely(au_dbrange_test(d))) {
3402 + di_read_unlock(d, AuLock_IR);
3406 + di_write_lock_child(d);
3407 + if (unlikely(au_dbrange_test(d))) {
3408 + di_write_unlock(d);
3411 + err = au_reval_dpath(d, sigen);
3413 + di_downgrade_lock(d, AuLock_IR);
3415 + di_write_unlock(d);
3420 + /* AuDbgDentry(d); */
3421 + bstart = au_dbstart(d);
3422 + bend = au_dbend(d);
3423 + if (bstart <= bindex
3425 + && au_h_dptr(d, bindex)
3426 + && au_test_dbusy(d, bstart, bend)) {
3428 + AuVerbose(verbose, "busy %pd\n", d);
3431 + di_read_unlock(d, AuLock_IR);
3436 + au_dpages_free(&dpages);
3441 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3442 + unsigned int sigen, const unsigned int verbose)
3445 + unsigned long long max, ull;
3446 + struct inode *i, **array;
3447 + aufs_bindex_t bstart, bend;
3449 + array = au_iarray_alloc(sb, &max);
3450 + err = PTR_ERR(array);
3451 + if (IS_ERR(array))
3455 + AuDbg("b%d\n", bindex);
3456 + for (ull = 0; !err && ull < max; ull++) {
3460 + if (i->i_ino == AUFS_ROOT_INO)
3463 + /* AuDbgInode(i); */
3464 + if (au_iigen(i, NULL) == sigen)
3465 + ii_read_lock_child(i);
3467 + ii_write_lock_child(i);
3468 + err = au_refresh_hinode_self(i);
3471 + ii_downgrade_lock(i);
3473 + ii_write_unlock(i);
3478 + bstart = au_ibstart(i);
3479 + bend = au_ibend(i);
3480 + if (bstart <= bindex
3482 + && au_h_iptr(i, bindex)
3483 + && au_test_ibusy(i, bstart, bend)) {
3485 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3488 + ii_read_unlock(i);
3490 + au_iarray_free(array, max);
3496 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3497 + const unsigned int verbose)
3500 + unsigned int sigen;
3502 + sigen = au_sigen(root->d_sb);
3503 + DiMustNoWaiters(root);
3504 + IiMustNoWaiters(d_inode(root));
3505 + di_write_unlock(root);
3506 + err = test_dentry_busy(root, bindex, sigen, verbose);
3508 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3509 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3514 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3515 + struct file **to_free, int *idx)
3518 + unsigned char matched, root;
3519 + aufs_bindex_t bindex, bend;
3520 + struct au_fidir *fidir;
3521 + struct au_hfile *hfile;
3524 + root = IS_ROOT(file->f_path.dentry);
3527 + to_free[*idx] = file;
3533 + fidir = au_fi(file)->fi_hdir;
3534 + AuDebugOn(!fidir);
3535 + bend = au_fbend_dir(file);
3536 + for (bindex = au_fbstart(file); bindex <= bend; bindex++) {
3537 + hfile = fidir->fd_hfile + bindex;
3538 + if (!hfile->hf_file)
3541 + if (hfile->hf_br->br_id == br_id) {
3553 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3554 + struct file **to_free, int opened)
3557 + unsigned long long ull, max;
3558 + aufs_bindex_t bstart;
3559 + struct file *file, **array;
3560 + struct dentry *root;
3561 + struct au_hfile *hfile;
3563 + array = au_farray_alloc(sb, &max);
3564 + err = PTR_ERR(array);
3565 + if (IS_ERR(array))
3570 + root = sb->s_root;
3571 + di_write_unlock(root);
3572 + for (ull = 0; ull < max; ull++) {
3573 + file = array[ull];
3574 + if (unlikely(!file))
3577 + /* AuDbg("%pD\n", file); */
3578 + fi_read_lock(file);
3579 + bstart = au_fbstart(file);
3580 + if (!d_is_dir(file->f_path.dentry)) {
3581 + hfile = &au_fi(file)->fi_htop;
3582 + if (hfile->hf_br->br_id == br_id)
3585 + err = test_dir_busy(file, br_id, to_free, &idx);
3586 + fi_read_unlock(file);
3587 + if (unlikely(err))
3590 + di_write_lock_child(root);
3591 + au_farray_free(array, max);
3592 + AuDebugOn(idx > opened);
3598 +static void br_del_file(struct file **to_free, unsigned long long opened,
3599 + aufs_bindex_t br_id)
3601 + unsigned long long ull;
3602 + aufs_bindex_t bindex, bstart, bend, bfound;
3603 + struct file *file;
3604 + struct au_fidir *fidir;
3605 + struct au_hfile *hfile;
3607 + for (ull = 0; ull < opened; ull++) {
3608 + file = to_free[ull];
3609 + if (unlikely(!file))
3612 + /* AuDbg("%pD\n", file); */
3613 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3615 + fidir = au_fi(file)->fi_hdir;
3616 + AuDebugOn(!fidir);
3617 + fi_write_lock(file);
3618 + bstart = au_fbstart(file);
3619 + bend = au_fbend_dir(file);
3620 + for (bindex = bstart; bindex <= bend; bindex++) {
3621 + hfile = fidir->fd_hfile + bindex;
3622 + if (!hfile->hf_file)
3625 + if (hfile->hf_br->br_id == br_id) {
3630 + AuDebugOn(bfound < 0);
3631 + au_set_h_fptr(file, bfound, NULL);
3632 + if (bfound == bstart) {
3633 + for (bstart++; bstart <= bend; bstart++)
3634 + if (au_hf_dir(file, bstart)) {
3635 + au_set_fbstart(file, bstart);
3639 + fi_write_unlock(file);
3643 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3644 + const aufs_bindex_t bindex,
3645 + const aufs_bindex_t bend)
3647 + struct au_branch **brp, **p;
3649 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3651 + brp = sbinfo->si_branch + bindex;
3652 + if (bindex < bend)
3653 + memmove(brp, brp + 1, sizeof(*brp) * (bend - bindex));
3654 + sbinfo->si_branch[0 + bend] = NULL;
3655 + sbinfo->si_bend--;
3657 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bend, AuGFP_SBILIST);
3659 + sbinfo->si_branch = p;
3660 + /* harmless error */
3663 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3664 + const aufs_bindex_t bend)
3666 + struct au_hdentry *hdp, *p;
3668 + AuRwMustWriteLock(&dinfo->di_rwsem);
3670 + hdp = dinfo->di_hdentry;
3671 + if (bindex < bend)
3672 + memmove(hdp + bindex, hdp + bindex + 1,
3673 + sizeof(*hdp) * (bend - bindex));
3674 + hdp[0 + bend].hd_dentry = NULL;
3677 + p = krealloc(hdp, sizeof(*p) * bend, AuGFP_SBILIST);
3679 + dinfo->di_hdentry = p;
3680 + /* harmless error */
3683 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3684 + const aufs_bindex_t bend)
3686 + struct au_hinode *hip, *p;
3688 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3690 + hip = iinfo->ii_hinode + bindex;
3691 + if (bindex < bend)
3692 + memmove(hip, hip + 1, sizeof(*hip) * (bend - bindex));
3693 + iinfo->ii_hinode[0 + bend].hi_inode = NULL;
3694 + au_hn_init(iinfo->ii_hinode + bend);
3697 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bend, AuGFP_SBILIST);
3699 + iinfo->ii_hinode = p;
3700 + /* harmless error */
3703 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3704 + struct au_branch *br)
3706 + aufs_bindex_t bend;
3707 + struct au_sbinfo *sbinfo;
3708 + struct dentry *root, *h_root;
3709 + struct inode *inode, *h_inode;
3710 + struct au_hinode *hinode;
3712 + SiMustWriteLock(sb);
3714 + root = sb->s_root;
3715 + inode = d_inode(root);
3716 + sbinfo = au_sbi(sb);
3717 + bend = sbinfo->si_bend;
3719 + h_root = au_h_dptr(root, bindex);
3720 + hinode = au_hi(inode, bindex);
3721 + h_inode = au_igrab(hinode->hi_inode);
3724 + au_sbilist_lock();
3725 + au_br_do_del_brp(sbinfo, bindex, bend);
3726 + au_br_do_del_hdp(au_di(root), bindex, bend);
3727 + au_br_do_del_hip(au_ii(inode), bindex, bend);
3728 + au_sbilist_unlock();
3732 + au_br_do_free(br);
3735 +static unsigned long long empty_cb(void *array, unsigned long long max,
3741 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3744 + unsigned long long opened;
3745 + unsigned int mnt_flags;
3746 + aufs_bindex_t bindex, bend, br_id;
3747 + unsigned char do_wh, verbose;
3748 + struct au_branch *br;
3749 + struct au_wbr *wbr;
3750 + struct dentry *root;
3751 + struct file **to_free;
3756 + root = sb->s_root;
3757 + bindex = au_find_dbindex(root, del->h_path.dentry);
3760 + goto out; /* success */
3762 + pr_err("%s no such branch\n", del->pathname);
3765 + AuDbg("bindex b%d\n", bindex);
3768 + mnt_flags = au_mntflags(sb);
3769 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3770 + bend = au_sbend(sb);
3771 + if (unlikely(!bend)) {
3772 + AuVerbose(verbose, "no more branches left\n");
3775 + br = au_sbr(sb, bindex);
3776 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3778 + br_id = br->br_id;
3779 + opened = atomic_read(&br->br_count);
3780 + if (unlikely(opened)) {
3781 + to_free = au_array_alloc(&opened, empty_cb, NULL);
3782 + err = PTR_ERR(to_free);
3783 + if (IS_ERR(to_free))
3786 + err = test_file_busy(sb, br_id, to_free, opened);
3787 + if (unlikely(err)) {
3788 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3794 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3796 + /* instead of WbrWhMustWriteLock(wbr) */
3797 + SiMustWriteLock(sb);
3798 + for (i = 0; i < AuBrWh_Last; i++) {
3799 + dput(wbr->wbr_wh[i]);
3800 + wbr->wbr_wh[i] = NULL;
3804 + err = test_children_busy(root, bindex, verbose);
3805 + if (unlikely(err)) {
3814 + * now we confirmed the branch is deletable.
3815 + * let's free the remaining opened dirs on the branch.
3817 + di_write_unlock(root);
3818 + br_del_file(to_free, opened, br_id);
3819 + di_write_lock_child(root);
3823 + au_br_do_del(sb, bindex, br);
3825 + sysaufs_brs_del(sb, bindex);
3826 + au_br_do_del(sb, bindex, br);
3827 + sysaufs_brs_add(sb, bindex);
3831 + au_cpup_attr_all(d_inode(root), /*force*/1);
3832 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3834 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3835 + if (au_opt_test(mnt_flags, PLINK))
3836 + au_plink_half_refresh(sb, br_id);
3838 + if (au_xino_brid(sb) == br_id)
3839 + au_xino_brid_set(sb, -1);
3840 + goto out; /* success */
3844 + rerr = au_br_init_wh(sb, br, br->br_perm);
3846 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3847 + del->pathname, rerr);
3850 + au_farray_free(to_free, opened);
3854 +/* ---------------------------------------------------------------------- */
3856 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3859 + aufs_bindex_t bstart, bend;
3860 + struct aufs_ibusy ibusy;
3861 + struct inode *inode, *h_inode;
3864 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3867 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3869 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3870 + if (unlikely(err)) {
3877 + si_read_lock(sb, AuLock_FLUSH);
3878 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbend(sb)))
3882 + ibusy.h_ino = 0; /* invalid */
3883 + inode = ilookup(sb, ibusy.ino);
3885 + || inode->i_ino == AUFS_ROOT_INO
3886 + || is_bad_inode(inode))
3889 + ii_read_lock_child(inode);
3890 + bstart = au_ibstart(inode);
3891 + bend = au_ibend(inode);
3892 + if (bstart <= ibusy.bindex && ibusy.bindex <= bend) {
3893 + h_inode = au_h_iptr(inode, ibusy.bindex);
3894 + if (h_inode && au_test_ibusy(inode, bstart, bend))
3895 + ibusy.h_ino = h_inode->i_ino;
3897 + ii_read_unlock(inode);
3901 + si_read_unlock(sb);
3903 + err = __put_user(ibusy.h_ino, &arg->h_ino);
3904 + if (unlikely(err)) {
3913 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
3915 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
3918 +#ifdef CONFIG_COMPAT
3919 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
3921 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
3925 +/* ---------------------------------------------------------------------- */
3928 + * change a branch permission
3931 +static void au_warn_ima(void)
3934 + /* since it doesn't support mark_files_ro() */
3935 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
3939 +static int do_need_sigen_inc(int a, int b)
3941 + return au_br_whable(a) && !au_br_whable(b);
3944 +static int need_sigen_inc(int old, int new)
3946 + return do_need_sigen_inc(old, new)
3947 + || do_need_sigen_inc(new, old);
3950 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
3953 + unsigned int mnt_flags;
3954 + unsigned long long ull, max;
3955 + aufs_bindex_t br_id;
3956 + unsigned char verbose, writer;
3957 + struct file *file, *hf, **array;
3958 + struct au_hfile *hfile;
3960 + mnt_flags = au_mntflags(sb);
3961 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3963 + array = au_farray_alloc(sb, &max);
3964 + err = PTR_ERR(array);
3965 + if (IS_ERR(array))
3969 + br_id = au_sbr_id(sb, bindex);
3970 + for (ull = 0; ull < max; ull++) {
3971 + file = array[ull];
3972 + if (unlikely(!file))
3975 + /* AuDbg("%pD\n", file); */
3976 + fi_read_lock(file);
3977 + if (unlikely(au_test_mmapped(file))) {
3979 + AuVerbose(verbose, "mmapped %pD\n", file);
3981 + FiMustNoWaiters(file);
3982 + fi_read_unlock(file);
3986 + hfile = &au_fi(file)->fi_htop;
3987 + hf = hfile->hf_file;
3988 + if (!d_is_reg(file->f_path.dentry)
3989 + || !(file->f_mode & FMODE_WRITE)
3990 + || hfile->hf_br->br_id != br_id
3991 + || !(hf->f_mode & FMODE_WRITE))
3992 + array[ull] = NULL;
3998 + FiMustNoWaiters(file);
3999 + fi_read_unlock(file);
4007 + for (ull = 0; ull < max; ull++) {
4008 + file = array[ull];
4012 + /* todo: already flushed? */
4014 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4015 + * approach which resets f_mode and calls mnt_drop_write() and
4016 + * file_release_write() for each file, because the branch
4017 + * attribute in aufs world is totally different from the native
4020 + /* fi_read_lock(file); */
4021 + hfile = &au_fi(file)->fi_htop;
4022 + hf = hfile->hf_file;
4023 + /* fi_read_unlock(file); */
4024 + spin_lock(&hf->f_lock);
4025 + writer = !!(hf->f_mode & FMODE_WRITER);
4026 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4027 + spin_unlock(&hf->f_lock);
4029 + put_write_access(file_inode(hf));
4030 + __mnt_drop_write(hf->f_path.mnt);
4035 + au_farray_free(array, max);
4041 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4045 + aufs_bindex_t bindex;
4046 + struct dentry *root;
4047 + struct au_branch *br;
4048 + struct au_br_fhsm *bf;
4050 + root = sb->s_root;
4051 + bindex = au_find_dbindex(root, mod->h_root);
4054 + return 0; /* success */
4056 + pr_err("%s no such branch\n", mod->path);
4059 + AuDbg("bindex b%d\n", bindex);
4061 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4062 + if (unlikely(err))
4065 + br = au_sbr(sb, bindex);
4066 + AuDebugOn(mod->h_root != au_br_dentry(br));
4067 + if (br->br_perm == mod->perm)
4068 + return 0; /* success */
4070 + /* pre-allocate for non-fhsm --> fhsm */
4072 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4073 + err = au_fhsm_br_alloc(br);
4074 + if (unlikely(err))
4077 + br->br_fhsm = NULL;
4080 + if (au_br_writable(br->br_perm)) {
4081 + /* remove whiteout base */
4082 + err = au_br_init_wh(sb, br, mod->perm);
4083 + if (unlikely(err))
4086 + if (!au_br_writable(mod->perm)) {
4087 + /* rw --> ro, file might be mmapped */
4088 + DiMustNoWaiters(root);
4089 + IiMustNoWaiters(d_inode(root));
4090 + di_write_unlock(root);
4091 + err = au_br_mod_files_ro(sb, bindex);
4092 + /* aufs_write_lock() calls ..._child() */
4093 + di_write_lock_child(root);
4095 + if (unlikely(err)) {
4097 + br->br_wbr = kmalloc(sizeof(*br->br_wbr),
4100 + rerr = au_wbr_init(br, sb, br->br_perm);
4101 + if (unlikely(rerr)) {
4102 + AuIOErr("nested error %d (%d)\n",
4104 + br->br_perm = mod->perm;
4108 + } else if (au_br_writable(mod->perm)) {
4111 + br->br_wbr = kmalloc(sizeof(*br->br_wbr), GFP_NOFS);
4113 + err = au_wbr_init(br, sb, mod->perm);
4114 + if (unlikely(err)) {
4115 + kfree(br->br_wbr);
4116 + br->br_wbr = NULL;
4120 + if (unlikely(err))
4123 + if (au_br_fhsm(br->br_perm)) {
4124 + if (!au_br_fhsm(mod->perm)) {
4125 + /* fhsm --> non-fhsm */
4126 + au_br_fhsm_fin(br->br_fhsm);
4127 + kfree(br->br_fhsm);
4128 + br->br_fhsm = NULL;
4130 + } else if (au_br_fhsm(mod->perm))
4131 + /* non-fhsm --> fhsm */
4134 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4135 + br->br_perm = mod->perm;
4136 + goto out; /* success */
4145 +/* ---------------------------------------------------------------------- */
4147 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4150 + struct kstatfs kstfs;
4152 + err = vfs_statfs(&br->br_path, &kstfs);
4154 + stfs->f_blocks = kstfs.f_blocks;
4155 + stfs->f_bavail = kstfs.f_bavail;
4156 + stfs->f_files = kstfs.f_files;
4157 + stfs->f_ffree = kstfs.f_ffree;
4162 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4163 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4164 +++ linux/fs/aufs/branch.h 2015-09-24 10:47:58.248052907 +0200
4167 + * Copyright (C) 2005-2015 Junjiro R. Okajima
4169 + * This program, aufs is free software; you can redistribute it and/or modify
4170 + * it under the terms of the GNU General Public License as published by
4171 + * the Free Software Foundation; either version 2 of the License, or
4172 + * (at your option) any later version.
4174 + * This program is distributed in the hope that it will be useful,
4175 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4176 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4177 + * GNU General Public License for more details.
4179 + * You should have received a copy of the GNU General Public License
4180 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4184 + * branch filesystems and xino for them
4187 +#ifndef __AUFS_BRANCH_H__
4188 +#define __AUFS_BRANCH_H__
4192 +#include <linux/mount.h>
4197 +/* ---------------------------------------------------------------------- */
4200 +struct au_xino_file {
4201 + struct file *xi_file;
4202 + struct mutex xi_nondir_mtx;
4204 + /* todo: make xino files an array to support huge inode number */
4206 +#ifdef CONFIG_DEBUG_FS
4207 + struct dentry *xi_dbgaufs;
4211 +/* File-based Hierarchical Storage Management */
4212 +struct au_br_fhsm {
4213 +#ifdef CONFIG_AUFS_FHSM
4214 + struct mutex bf_lock;
4215 + unsigned long bf_jiffy;
4216 + struct aufs_stfs bf_stfs;
4221 +/* members for writable branch only */
4222 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4224 + struct au_rwsem wbr_wh_rwsem;
4225 + struct dentry *wbr_wh[AuBrWh_Last];
4226 + atomic_t wbr_wh_running;
4227 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4228 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4229 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4232 + unsigned long long wbr_bytes;
4235 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4236 +#define AuBrDynOp (AuDyLast * 4)
4238 +#ifdef CONFIG_AUFS_HFSNOTIFY
4239 +/* support for asynchronous destruction */
4240 +struct au_br_hfsnotify {
4241 + struct fsnotify_group *hfsn_group;
4245 +/* sysfs entries */
4246 +struct au_brsysfs {
4248 + struct attribute attr;
4257 +/* protected by superblock rwsem */
4259 + struct au_xino_file br_xino;
4261 + aufs_bindex_t br_id;
4264 + struct path br_path;
4265 + spinlock_t br_dykey_lock;
4266 + struct au_dykey *br_dykey[AuBrDynOp];
4267 + atomic_t br_count;
4269 + struct au_wbr *br_wbr;
4270 + struct au_br_fhsm *br_fhsm;
4272 + /* xino truncation */
4273 + atomic_t br_xino_running;
4275 +#ifdef CONFIG_AUFS_HFSNOTIFY
4276 + struct au_br_hfsnotify *br_hfsn;
4279 +#ifdef CONFIG_SYSFS
4280 + /* entries under sysfs per mount-point */
4281 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4285 +/* ---------------------------------------------------------------------- */
4287 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4289 + return br->br_path.mnt;
4292 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4294 + return br->br_path.dentry;
4297 +static inline struct super_block *au_br_sb(struct au_branch *br)
4299 + return au_br_mnt(br)->mnt_sb;
4302 +static inline int au_br_rdonly(struct au_branch *br)
4304 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4305 + || !au_br_writable(br->br_perm))
4309 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4311 +#ifdef CONFIG_AUFS_HNOTIFY
4312 + return !(brperm & AuBrPerm_RR);
4318 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4320 + int err, exec_flag;
4323 + exec_flag = oflag & __FMODE_EXEC;
4324 + if (unlikely(exec_flag && (au_br_mnt(br)->mnt_flags & MNT_NOEXEC)))
4330 +/* ---------------------------------------------------------------------- */
4334 +void au_br_free(struct au_sbinfo *sinfo);
4335 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4337 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4339 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4340 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4341 +#ifdef CONFIG_COMPAT
4342 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4345 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4348 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4351 +static const loff_t au_loff_max = LLONG_MAX;
4353 +int au_xib_trunc(struct super_block *sb);
4354 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4356 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4357 + size_t size, loff_t *pos);
4358 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4359 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4360 +ino_t au_xino_new_ino(struct super_block *sb);
4361 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4362 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4364 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4366 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4367 + struct file *base_file, int do_test);
4368 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4370 +struct au_opt_xino;
4371 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4372 +void au_xino_clr(struct super_block *sb);
4373 +struct file *au_xino_def(struct super_block *sb);
4374 +int au_xino_path(struct seq_file *seq, struct file *file);
4376 +/* ---------------------------------------------------------------------- */
4378 +/* Superblock to branch */
4380 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4382 + return au_sbr(sb, bindex)->br_id;
4386 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4388 + return au_br_mnt(au_sbr(sb, bindex));
4392 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4394 + return au_br_sb(au_sbr(sb, bindex));
4397 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4399 + atomic_dec(&au_sbr(sb, bindex)->br_count);
4402 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4404 + return au_sbr(sb, bindex)->br_perm;
4407 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4409 + return au_br_whable(au_sbr_perm(sb, bindex));
4412 +/* ---------------------------------------------------------------------- */
4415 + * wbr_wh_read_lock, wbr_wh_write_lock
4416 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4418 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4420 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4421 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4422 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4424 +/* ---------------------------------------------------------------------- */
4426 +#ifdef CONFIG_AUFS_FHSM
4427 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4429 + mutex_init(&brfhsm->bf_lock);
4430 + brfhsm->bf_jiffy = 0;
4431 + brfhsm->bf_readable = 0;
4434 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4436 + mutex_destroy(&brfhsm->bf_lock);
4439 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4440 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4443 +#endif /* __KERNEL__ */
4444 +#endif /* __AUFS_BRANCH_H__ */
4445 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4446 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4447 +++ linux/fs/aufs/conf.mk 2015-09-24 10:47:58.248052907 +0200
4450 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4454 +AuConfStr += ${1}=${${1}}
4458 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4460 + HNOTIFY HFSNOTIFY \
4471 +$(foreach i, ${AuConfAll}, \
4472 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4474 +AuConfName = ${obj}/conf.str
4475 +${AuConfName}.tmp: FORCE
4476 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4477 +${AuConfName}: ${AuConfName}.tmp
4478 + @diff -q $< $@ > /dev/null 2>&1 || { \
4479 + echo ' GEN ' $@; \
4483 +clean-files += ${AuConfName} ${AuConfName}.tmp
4484 +${obj}/sysfs.o: ${AuConfName}
4486 +-include ${srctree}/${src}/conf_priv.mk
4487 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4488 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4489 +++ linux/fs/aufs/cpup.c 2015-09-24 10:47:58.248052907 +0200
4492 + * Copyright (C) 2005-2015 Junjiro R. Okajima
4494 + * This program, aufs is free software; you can redistribute it and/or modify
4495 + * it under the terms of the GNU General Public License as published by
4496 + * the Free Software Foundation; either version 2 of the License, or
4497 + * (at your option) any later version.
4499 + * This program is distributed in the hope that it will be useful,
4500 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4501 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4502 + * GNU General Public License for more details.
4504 + * You should have received a copy of the GNU General Public License
4505 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4509 + * copy-up functions, see wbr_policy.c for copy-down
4512 +#include <linux/fs_stack.h>
4513 +#include <linux/mm.h>
4516 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4518 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4519 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4521 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4523 + dst->i_flags |= iflags & ~mask;
4524 + if (au_test_fs_notime(dst->i_sb))
4525 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4528 +void au_cpup_attr_timesizes(struct inode *inode)
4530 + struct inode *h_inode;
4532 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4533 + fsstack_copy_attr_times(inode, h_inode);
4534 + fsstack_copy_inode_size(inode, h_inode);
4537 +void au_cpup_attr_nlink(struct inode *inode, int force)
4539 + struct inode *h_inode;
4540 + struct super_block *sb;
4541 + aufs_bindex_t bindex, bend;
4544 + bindex = au_ibstart(inode);
4545 + h_inode = au_h_iptr(inode, bindex);
4547 + && !S_ISDIR(h_inode->i_mode)
4548 + && au_opt_test(au_mntflags(sb), PLINK)
4549 + && au_plink_test(inode))
4553 + * 0 can happen in revalidating.
4554 + * h_inode->i_mutex may not be held here, but it is harmless since once
4555 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4557 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4558 + * the incorrect link count.
4560 + set_nlink(inode, h_inode->i_nlink);
4563 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4564 + * it may includes whplink directory.
4566 + if (S_ISDIR(h_inode->i_mode)) {
4567 + bend = au_ibend(inode);
4568 + for (bindex++; bindex <= bend; bindex++) {
4569 + h_inode = au_h_iptr(inode, bindex);
4571 + au_add_nlink(inode, h_inode);
4576 +void au_cpup_attr_changeable(struct inode *inode)
4578 + struct inode *h_inode;
4580 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4581 + inode->i_mode = h_inode->i_mode;
4582 + inode->i_uid = h_inode->i_uid;
4583 + inode->i_gid = h_inode->i_gid;
4584 + au_cpup_attr_timesizes(inode);
4585 + au_cpup_attr_flags(inode, h_inode->i_flags);
4588 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4590 + struct au_iinfo *iinfo = au_ii(inode);
4592 + IiMustWriteLock(inode);
4594 + iinfo->ii_higen = h_inode->i_generation;
4595 + iinfo->ii_hsb1 = h_inode->i_sb;
4598 +void au_cpup_attr_all(struct inode *inode, int force)
4600 + struct inode *h_inode;
4602 + h_inode = au_h_iptr(inode, au_ibstart(inode));
4603 + au_cpup_attr_changeable(inode);
4604 + if (inode->i_nlink > 0)
4605 + au_cpup_attr_nlink(inode, force);
4606 + inode->i_rdev = h_inode->i_rdev;
4607 + inode->i_blkbits = h_inode->i_blkbits;
4608 + au_cpup_igen(inode, h_inode);
4611 +/* ---------------------------------------------------------------------- */
4613 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4615 +/* keep the timestamps of the parent dir when cpup */
4616 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4617 + struct path *h_path)
4619 + struct inode *h_inode;
4621 + dt->dt_dentry = dentry;
4622 + dt->dt_h_path = *h_path;
4623 + h_inode = d_inode(h_path->dentry);
4624 + dt->dt_atime = h_inode->i_atime;
4625 + dt->dt_mtime = h_inode->i_mtime;
4629 +void au_dtime_revert(struct au_dtime *dt)
4631 + struct iattr attr;
4634 + attr.ia_atime = dt->dt_atime;
4635 + attr.ia_mtime = dt->dt_mtime;
4636 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4637 + | ATTR_ATIME | ATTR_ATIME_SET;
4639 + /* no delegation since this is a directory */
4640 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4641 + if (unlikely(err))
4642 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4645 +/* ---------------------------------------------------------------------- */
4647 +/* internal use only */
4648 +struct au_cpup_reg_attr {
4651 + unsigned int iflags; /* inode->i_flags */
4654 +static noinline_for_stack
4655 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4656 + struct au_cpup_reg_attr *h_src_attr)
4658 + int err, sbits, icex;
4659 + unsigned int mnt_flags;
4660 + unsigned char verbose;
4662 + struct path h_path;
4663 + struct inode *h_isrc, *h_idst;
4664 + struct kstat *h_st;
4665 + struct au_branch *br;
4667 + h_path.dentry = au_h_dptr(dst, bindex);
4668 + h_idst = d_inode(h_path.dentry);
4669 + br = au_sbr(dst->d_sb, bindex);
4670 + h_path.mnt = au_br_mnt(br);
4671 + h_isrc = d_inode(h_src);
4672 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4673 + | ATTR_ATIME | ATTR_MTIME
4674 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4675 + if (h_src_attr && h_src_attr->valid) {
4676 + h_st = &h_src_attr->st;
4677 + ia.ia_uid = h_st->uid;
4678 + ia.ia_gid = h_st->gid;
4679 + ia.ia_atime = h_st->atime;
4680 + ia.ia_mtime = h_st->mtime;
4681 + if (h_idst->i_mode != h_st->mode
4682 + && !S_ISLNK(h_idst->i_mode)) {
4683 + ia.ia_valid |= ATTR_MODE;
4684 + ia.ia_mode = h_st->mode;
4686 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4687 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4689 + ia.ia_uid = h_isrc->i_uid;
4690 + ia.ia_gid = h_isrc->i_gid;
4691 + ia.ia_atime = h_isrc->i_atime;
4692 + ia.ia_mtime = h_isrc->i_mtime;
4693 + if (h_idst->i_mode != h_isrc->i_mode
4694 + && !S_ISLNK(h_idst->i_mode)) {
4695 + ia.ia_valid |= ATTR_MODE;
4696 + ia.ia_mode = h_isrc->i_mode;
4698 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4699 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4701 + /* no delegation since it is just created */
4702 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4704 + /* is this nfs only? */
4705 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4706 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4707 + ia.ia_mode = h_isrc->i_mode;
4708 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4711 + icex = br->br_perm & AuBrAttr_ICEX;
4713 + mnt_flags = au_mntflags(dst->d_sb);
4714 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4715 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4721 +/* ---------------------------------------------------------------------- */
4723 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4724 + char *buf, unsigned long blksize)
4727 + size_t sz, rbytes, wbytes;
4728 + unsigned char all_zero;
4730 + struct mutex *h_mtx;
4731 + /* reduce stack usage */
4734 + zp = page_address(ZERO_PAGE(0));
4735 + if (unlikely(!zp))
4736 + return -ENOMEM; /* possible? */
4741 + AuDbg("len %lld\n", len);
4743 + if (len < blksize)
4747 + /* todo: signal_pending? */
4748 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4749 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4752 + if (unlikely(err < 0))
4756 + if (len >= rbytes && rbytes == blksize)
4757 + all_zero = !memcmp(buf, zp, rbytes);
4764 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4766 + /* todo: signal_pending? */
4767 + if (unlikely(err == -EAGAIN || err == -EINTR))
4769 + if (unlikely(err < 0))
4774 + if (unlikely(err < 0))
4780 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4782 + if (unlikely(res < 0))
4789 + /* the last block may be a hole */
4790 + if (!err && all_zero) {
4791 + AuLabel(last hole);
4794 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4795 + /* nfs requires this step to make last hole */
4796 + /* is this only nfs? */
4798 + /* todo: signal_pending? */
4799 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4800 + } while (err == -EAGAIN || err == -EINTR);
4807 + ia->ia_size = dst->f_pos;
4808 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4809 + ia->ia_file = dst;
4810 + h_mtx = &file_inode(dst)->i_mutex;
4811 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
4812 + /* no delegation since it is just created */
4813 + err = vfsub_notify_change(&dst->f_path, ia,
4814 + /*delegated*/NULL);
4815 + mutex_unlock(h_mtx);
4822 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4825 + unsigned long blksize;
4826 + unsigned char do_kfree;
4830 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
4831 + if (!blksize || PAGE_SIZE < blksize)
4832 + blksize = PAGE_SIZE;
4833 + AuDbg("blksize %lu\n", blksize);
4834 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4836 + buf = kmalloc(blksize, GFP_NOFS);
4838 + buf = (void *)__get_free_page(GFP_NOFS);
4839 + if (unlikely(!buf))
4842 + if (len > (1 << 22))
4843 + AuDbg("copying a large file %lld\n", (long long)len);
4847 + err = au_do_copy_file(dst, src, len, buf, blksize);
4851 + free_page((unsigned long)buf);
4858 + * to support a sparse file which is opened with O_APPEND,
4859 + * we need to close the file.
4861 +static int au_cp_regular(struct au_cp_generic *cpg)
4864 + enum { SRC, DST };
4866 + aufs_bindex_t bindex;
4867 + unsigned int flags;
4868 + struct dentry *dentry;
4870 + struct file *file;
4874 + .bindex = cpg->bsrc,
4875 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
4879 + .bindex = cpg->bdst,
4880 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
4881 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
4882 + .label = &&out_src
4885 + struct super_block *sb;
4887 + /* bsrc branch can be ro/rw. */
4888 + sb = cpg->dentry->d_sb;
4890 + for (i = 0; i < 2; i++, f++) {
4891 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
4892 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
4893 + /*file*/NULL, f->force_wr);
4894 + err = PTR_ERR(f->file);
4895 + if (IS_ERR(f->file))
4899 + /* try stopping to update while we copyup */
4900 + IMustLock(d_inode(file[SRC].dentry));
4901 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
4903 + fput(file[DST].file);
4904 + au_sbr_put(sb, file[DST].bindex);
4907 + fput(file[SRC].file);
4908 + au_sbr_put(sb, file[SRC].bindex);
4913 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
4914 + struct au_cpup_reg_attr *h_src_attr)
4918 + struct path h_path;
4919 + struct inode *h_src_inode, *h_dst_inode;
4922 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
4923 + l = i_size_read(h_src_inode);
4924 + if (cpg->len == -1 || l < cpg->len)
4927 + /* try stopping to update while we are referencing */
4928 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4929 + au_pin_hdir_unlock(cpg->pin);
4931 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
4932 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
4933 + h_src_attr->iflags = h_src_inode->i_flags;
4934 + if (!au_test_nfs(h_src_inode->i_sb))
4935 + err = vfs_getattr(&h_path, &h_src_attr->st);
4937 + mutex_unlock(&h_src_inode->i_mutex);
4938 + err = vfs_getattr(&h_path, &h_src_attr->st);
4939 + mutex_lock_nested(&h_src_inode->i_mutex, AuLsc_I_CHILD);
4941 + if (unlikely(err)) {
4942 + mutex_unlock(&h_src_inode->i_mutex);
4945 + h_src_attr->valid = 1;
4946 + err = au_cp_regular(cpg);
4947 + mutex_unlock(&h_src_inode->i_mutex);
4948 + rerr = au_pin_hdir_relock(cpg->pin);
4952 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
4953 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
4954 + h_dst_inode = d_inode(h_path.dentry);
4955 + spin_lock(&h_dst_inode->i_lock);
4956 + h_dst_inode->i_state |= I_LINKABLE;
4957 + spin_unlock(&h_dst_inode->i_lock);
4964 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
4965 + struct inode *h_dir)
4968 + mm_segment_t old_fs;
4973 + struct inode *h_inode = d_inode(h_src);
4974 + const struct inode_operations *h_iop = h_inode->i_op;
4977 + if (unlikely(!h_iop->readlink))
4981 + sym.k = (void *)__get_free_page(GFP_NOFS);
4982 + if (unlikely(!sym.k))
4985 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
4986 + old_fs = get_fs();
4987 + set_fs(KERNEL_DS);
4988 + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX);
4993 + sym.k[symlen] = 0;
4994 + err = vfsub_symlink(h_dir, h_path, sym.k);
4996 + free_page((unsigned long)sym.k);
5002 +static noinline_for_stack
5003 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5004 + struct au_cpup_reg_attr *h_src_attr)
5008 + unsigned int mnt_flags;
5009 + unsigned char isdir, isreg, force;
5010 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5011 + struct au_dtime dt;
5012 + struct path h_path;
5013 + struct dentry *h_src, *h_dst, *h_parent;
5014 + struct inode *h_inode, *h_dir, *dir, *inode;
5015 + struct super_block *sb;
5017 + /* bsrc branch can be ro/rw. */
5018 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5019 + h_inode = d_inode(h_src);
5020 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5022 + /* try stopping to be referenced while we are creating */
5023 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5024 + if (au_ftest_cpup(cpg->flags, RENAME))
5025 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5026 + AUFS_WH_PFX_LEN));
5027 + h_parent = h_dst->d_parent; /* dir inode is locked */
5028 + h_dir = d_inode(h_parent);
5030 + AuDebugOn(h_parent != h_dst->d_parent);
5032 + sb = cpg->dentry->d_sb;
5033 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5035 + h_path.dentry = h_parent;
5036 + au_dtime_store(&dt, dst_parent, &h_path);
5038 + h_path.dentry = h_dst;
5042 + mode = h_inode->i_mode;
5043 + switch (mode & S_IFMT) {
5046 + err = vfsub_create(h_dir, &h_path, mode | S_IWUSR,
5047 + /*want_excl*/true);
5049 + err = au_do_cpup_regular(cpg, h_src_attr);
5053 + err = vfsub_mkdir(h_dir, &h_path, mode);
5056 + * strange behaviour from the users view,
5057 + * particularry setattr case
5059 + dir = d_inode(dst_parent);
5060 + if (au_ibstart(dir) == cpg->bdst)
5061 + au_cpup_attr_nlink(dir, /*force*/1);
5062 + inode = d_inode(cpg->dentry);
5063 + au_cpup_attr_nlink(inode, /*force*/1);
5067 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5071 + AuDebugOn(!capable(CAP_MKNOD));
5075 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5078 + AuIOErr("Unknown inode type 0%o\n", mode);
5082 + mnt_flags = au_mntflags(sb);
5083 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5085 + && au_opt_test(mnt_flags, XINO)
5086 + && (h_inode->i_nlink == 1
5087 + || (h_inode->i_state & I_LINKABLE))
5088 + /* todo: unnecessary? */
5089 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5090 + && cpg->bdst < cpg->bsrc
5091 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5092 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5093 + /* ignore this error */
5098 + force = !!cpg->len;
5099 + if (cpg->len == -1)
5100 + force = !!i_size_read(h_inode);
5102 + au_fhsm_wrote(sb, cpg->bdst, force);
5106 + au_dtime_revert(&dt);
5110 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5113 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5114 + struct inode *h_dir;
5115 + aufs_bindex_t bdst;
5117 + dentry = cpg->dentry;
5119 + h_dentry = au_h_dptr(dentry, bdst);
5120 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5122 + au_set_h_dptr(dentry, bdst, NULL);
5123 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5125 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5126 + au_set_h_dptr(dentry, bdst, h_dentry);
5129 + parent = dget_parent(dentry);
5130 + h_parent = au_h_dptr(parent, bdst);
5132 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5133 + if (IS_ERR(h_path->dentry))
5134 + err = PTR_ERR(h_path->dentry);
5136 + if (unlikely(err))
5139 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5140 + h_dir = d_inode(h_parent);
5142 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5143 + /* no delegation since it is just created */
5144 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
5145 + dput(h_path->dentry);
5152 + * copyup the @dentry from @bsrc to @bdst.
5153 + * the caller must set the both of lower dentries.
5154 + * @len is for truncating when it is -1 copyup the entire file.
5155 + * in link/rename cases, @dst_parent may be different from the real one.
5156 + * basic->bsrc can be larger than basic->bdst.
5158 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5161 + aufs_bindex_t old_ibstart;
5162 + unsigned char isdir, plink;
5163 + struct dentry *h_src, *h_dst, *h_parent;
5164 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5165 + struct super_block *sb;
5166 + struct au_branch *br;
5167 + /* to reuduce stack size */
5169 + struct au_dtime dt;
5170 + struct path h_path;
5171 + struct au_cpup_reg_attr h_src_attr;
5175 + a = kmalloc(sizeof(*a), GFP_NOFS);
5178 + a->h_src_attr.valid = 0;
5180 + sb = cpg->dentry->d_sb;
5181 + br = au_sbr(sb, cpg->bdst);
5182 + a->h_path.mnt = au_br_mnt(br);
5183 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5184 + h_parent = h_dst->d_parent; /* dir inode is locked */
5185 + h_dir = d_inode(h_parent);
5188 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5189 + inode = d_inode(cpg->dentry);
5192 + dst_parent = dget_parent(cpg->dentry);
5196 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5197 + dst_inode = au_h_iptr(inode, cpg->bdst);
5199 + if (unlikely(!plink)) {
5201 + AuIOErr("hi%lu(i%lu) exists on b%d "
5202 + "but plink is disabled\n",
5203 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5207 + if (dst_inode->i_nlink) {
5208 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5210 + h_src = au_plink_lkup(inode, cpg->bdst);
5211 + err = PTR_ERR(h_src);
5212 + if (IS_ERR(h_src))
5214 + if (unlikely(d_is_negative(h_src))) {
5216 + AuIOErr("i%lu exists on a upper branch "
5217 + "but not pseudo-linked\n",
5224 + a->h_path.dentry = h_parent;
5225 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5228 + a->h_path.dentry = h_dst;
5230 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5231 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5232 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5234 + au_dtime_revert(&a->dt);
5235 + if (unlikely(err == -EWOULDBLOCK)) {
5236 + pr_warn("cannot retry for NFSv4 delegation"
5237 + " for an internal link\n");
5243 + /* todo: cpup_wh_file? */
5245 + au_update_ibrange(inode, /*do_put_zero*/1);
5248 + isdir = S_ISDIR(inode->i_mode);
5249 + old_ibstart = au_ibstart(inode);
5250 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5251 + if (unlikely(err))
5253 + dst_inode = d_inode(h_dst);
5254 + mutex_lock_nested(&dst_inode->i_mutex, AuLsc_I_CHILD2);
5255 + /* todo: necessary? */
5256 + /* au_pin_hdir_unlock(cpg->pin); */
5258 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5259 + if (unlikely(err)) {
5260 + /* todo: necessary? */
5261 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5262 + mutex_unlock(&dst_inode->i_mutex);
5266 + if (cpg->bdst < old_ibstart) {
5267 + if (S_ISREG(inode->i_mode)) {
5268 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5269 + if (unlikely(err)) {
5270 + /* ignore an error */
5271 + /* au_pin_hdir_relock(cpg->pin); */
5272 + mutex_unlock(&dst_inode->i_mutex);
5276 + au_set_ibstart(inode, cpg->bdst);
5278 + au_set_ibend(inode, cpg->bdst);
5279 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5280 + au_hi_flags(inode, isdir));
5282 + /* todo: necessary? */
5283 + /* err = au_pin_hdir_relock(cpg->pin); */
5284 + mutex_unlock(&dst_inode->i_mutex);
5285 + if (unlikely(err))
5288 + src_inode = d_inode(h_src);
5290 + && (src_inode->i_nlink > 1
5291 + || src_inode->i_state & I_LINKABLE)
5293 + au_plink_append(inode, cpg->bdst, h_dst);
5295 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5296 + a->h_path.dentry = h_dst;
5297 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5300 + goto out_parent; /* success */
5304 + a->h_path.dentry = h_parent;
5305 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5306 + a->h_path.dentry = h_dst;
5308 + if (d_is_positive(h_dst)) {
5310 + /* no delegation since it is just created */
5311 + rerr = vfsub_unlink(h_dir, &a->h_path,
5312 + /*delegated*/NULL, /*force*/0);
5314 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5316 + au_dtime_revert(&a->dt);
5318 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5328 +#if 0 /* reserved */
5329 +struct au_cpup_single_args {
5331 + struct au_cp_generic *cpg;
5332 + struct dentry *dst_parent;
5335 +static void au_call_cpup_single(void *args)
5337 + struct au_cpup_single_args *a = args;
5339 + au_pin_hdir_acquire_nest(a->cpg->pin);
5340 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5341 + au_pin_hdir_release(a->cpg->pin);
5346 + * prevent SIGXFSZ in copy-up.
5347 + * testing CAP_MKNOD is for generic fs,
5348 + * but CAP_FSETID is for xfs only, currently.
5350 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5353 + struct super_block *sb;
5354 + struct inode *h_dir;
5357 + sb = au_pinned_parent(pin)->d_sb;
5358 + if (!au_wkq_test()
5359 + && (!au_sbi(sb)->si_plink_maint_pid
5360 + || au_plink_maint(sb, AuLock_NOPLM))) {
5361 + switch (mode & S_IFMT) {
5363 + /* no condition about RLIMIT_FSIZE and the file size */
5368 + do_sio = !capable(CAP_MKNOD);
5372 + do_sio = ((mode & (S_ISUID | S_ISGID))
5373 + && !capable(CAP_FSETID));
5374 + /* this workaround may be removed in the future */
5376 + h_dir = au_pinned_h_dir(pin);
5377 + do_sio = h_dir->i_mode & S_ISVTX;
5384 +#if 0 /* reserved */
5385 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5388 + struct dentry *h_dentry;
5390 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5391 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5392 + err = au_cpup_single(cpg, dst_parent);
5394 + struct au_cpup_single_args args = {
5397 + .dst_parent = dst_parent
5399 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5400 + if (unlikely(wkq_err))
5409 + * copyup the @dentry from the first active lower branch to @bdst,
5410 + * using au_cpup_single().
5412 +static int au_cpup_simple(struct au_cp_generic *cpg)
5415 + unsigned int flags_orig;
5416 + struct dentry *dentry;
5418 + AuDebugOn(cpg->bsrc < 0);
5420 + dentry = cpg->dentry;
5421 + DiMustWriteLock(dentry);
5423 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5425 + flags_orig = cpg->flags;
5426 + au_fset_cpup(cpg->flags, RENAME);
5427 + err = au_cpup_single(cpg, NULL);
5428 + cpg->flags = flags_orig;
5430 + return 0; /* success */
5433 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5434 + au_set_dbstart(dentry, cpg->bsrc);
5440 +struct au_cpup_simple_args {
5442 + struct au_cp_generic *cpg;
5445 +static void au_call_cpup_simple(void *args)
5447 + struct au_cpup_simple_args *a = args;
5449 + au_pin_hdir_acquire_nest(a->cpg->pin);
5450 + *a->errp = au_cpup_simple(a->cpg);
5451 + au_pin_hdir_release(a->cpg->pin);
5454 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5457 + struct dentry *dentry, *parent;
5458 + struct file *h_file;
5459 + struct inode *h_dir;
5461 + dentry = cpg->dentry;
5463 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5464 + AuDebugOn(cpg->bsrc < 0);
5465 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5466 + err = PTR_ERR(h_file);
5467 + if (IS_ERR(h_file))
5471 + parent = dget_parent(dentry);
5472 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5473 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5474 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5475 + err = au_cpup_simple(cpg);
5477 + struct au_cpup_simple_args args = {
5481 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5482 + if (unlikely(wkq_err))
5488 + au_h_open_post(dentry, cpg->bsrc, h_file);
5494 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5496 + aufs_bindex_t bsrc, bend;
5497 + struct dentry *dentry, *h_dentry;
5499 + if (cpg->bsrc < 0) {
5500 + dentry = cpg->dentry;
5501 + bend = au_dbend(dentry);
5502 + for (bsrc = cpg->bdst + 1; bsrc <= bend; bsrc++) {
5503 + h_dentry = au_h_dptr(dentry, bsrc);
5505 + AuDebugOn(d_is_negative(h_dentry));
5509 + AuDebugOn(bsrc > bend);
5512 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5513 + return au_do_sio_cpup_simple(cpg);
5516 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5518 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5519 + return au_do_sio_cpup_simple(cpg);
5522 +/* ---------------------------------------------------------------------- */
5525 + * copyup the deleted file for writing.
5527 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5528 + struct file *file)
5531 + unsigned int flags_orig;
5532 + aufs_bindex_t bsrc_orig;
5533 + struct dentry *h_d_dst, *h_d_start;
5534 + struct au_dinfo *dinfo;
5535 + struct au_hdentry *hdp;
5537 + dinfo = au_di(cpg->dentry);
5538 + AuRwMustWriteLock(&dinfo->di_rwsem);
5540 + bsrc_orig = cpg->bsrc;
5541 + cpg->bsrc = dinfo->di_bstart;
5542 + hdp = dinfo->di_hdentry;
5543 + h_d_dst = hdp[0 + cpg->bdst].hd_dentry;
5544 + dinfo->di_bstart = cpg->bdst;
5545 + hdp[0 + cpg->bdst].hd_dentry = wh_dentry;
5548 + h_d_start = hdp[0 + cpg->bsrc].hd_dentry;
5549 + hdp[0 + cpg->bsrc].hd_dentry = au_hf_top(file)->f_path.dentry;
5551 + flags_orig = cpg->flags;
5552 + cpg->flags = !AuCpup_DTIME;
5553 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5554 + cpg->flags = flags_orig;
5557 + err = au_reopen_nondir(file);
5558 + hdp[0 + cpg->bsrc].hd_dentry = h_d_start;
5560 + hdp[0 + cpg->bdst].hd_dentry = h_d_dst;
5561 + dinfo->di_bstart = cpg->bsrc;
5562 + cpg->bsrc = bsrc_orig;
5567 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5570 + aufs_bindex_t bdst;
5571 + struct au_dtime dt;
5572 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5573 + struct au_branch *br;
5574 + struct path h_path;
5576 + dentry = cpg->dentry;
5578 + br = au_sbr(dentry->d_sb, bdst);
5579 + parent = dget_parent(dentry);
5580 + h_parent = au_h_dptr(parent, bdst);
5581 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5582 + err = PTR_ERR(wh_dentry);
5583 + if (IS_ERR(wh_dentry))
5586 + h_path.dentry = h_parent;
5587 + h_path.mnt = au_br_mnt(br);
5588 + au_dtime_store(&dt, parent, &h_path);
5589 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5590 + if (unlikely(err))
5594 + h_path.dentry = wh_dentry;
5595 + if (!d_is_dir(wh_dentry)) {
5596 + /* no delegation since it is just created */
5597 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5598 + /*delegated*/NULL, /*force*/0);
5600 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5601 + if (unlikely(err)) {
5602 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5606 + au_dtime_revert(&dt);
5607 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5616 +struct au_cpup_wh_args {
5618 + struct au_cp_generic *cpg;
5619 + struct file *file;
5622 +static void au_call_cpup_wh(void *args)
5624 + struct au_cpup_wh_args *a = args;
5626 + au_pin_hdir_acquire_nest(a->cpg->pin);
5627 + *a->errp = au_cpup_wh(a->cpg, a->file);
5628 + au_pin_hdir_release(a->cpg->pin);
5631 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5634 + aufs_bindex_t bdst;
5635 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5636 + struct inode *dir, *h_dir, *h_tmpdir;
5637 + struct au_wbr *wbr;
5638 + struct au_pin wh_pin, *pin_orig;
5640 + dentry = cpg->dentry;
5642 + parent = dget_parent(dentry);
5643 + dir = d_inode(parent);
5646 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5649 + if (!h_dir->i_nlink) {
5650 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5651 + h_orph = wbr->wbr_orph;
5653 + h_parent = dget(au_h_dptr(parent, bdst));
5654 + au_set_h_dptr(parent, bdst, dget(h_orph));
5655 + h_tmpdir = d_inode(h_orph);
5656 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5658 + mutex_lock_nested(&h_tmpdir->i_mutex, AuLsc_I_PARENT3);
5659 + /* todo: au_h_open_pre()? */
5661 + pin_orig = cpg->pin;
5662 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5663 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5664 + cpg->pin = &wh_pin;
5667 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5668 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5669 + err = au_cpup_wh(cpg, file);
5671 + struct au_cpup_wh_args args = {
5676 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5677 + if (unlikely(wkq_err))
5682 + mutex_unlock(&h_tmpdir->i_mutex);
5683 + /* todo: au_h_open_post()? */
5684 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5685 + au_set_h_dptr(parent, bdst, h_parent);
5686 + AuDebugOn(!pin_orig);
5687 + cpg->pin = pin_orig;
5695 +/* ---------------------------------------------------------------------- */
5698 + * generic routine for both of copy-up and copy-down.
5700 +/* cf. revalidate function in file.c */
5701 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5702 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5703 + struct au_pin *pin,
5704 + struct dentry *h_parent, void *arg),
5708 + struct au_pin pin;
5709 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
5712 + parent = dget_parent(dentry);
5713 + if (IS_ROOT(parent))
5716 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5717 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5719 + /* do not use au_dpage */
5720 + real_parent = parent;
5723 + parent = dget_parent(dentry);
5724 + h_parent = au_h_dptr(parent, bdst);
5726 + goto out; /* success */
5728 + /* find top dir which is necessary to cpup */
5732 + parent = dget_parent(d);
5733 + di_read_lock_parent3(parent, !AuLock_IR);
5734 + h_parent = au_h_dptr(parent, bdst);
5735 + di_read_unlock(parent, !AuLock_IR);
5736 + } while (!h_parent);
5738 + if (d != real_parent)
5739 + di_write_lock_child3(d);
5741 + /* somebody else might create while we were sleeping */
5742 + h_dentry = au_h_dptr(d, bdst);
5743 + if (!h_dentry || d_is_negative(h_dentry)) {
5745 + au_update_dbstart(d);
5747 + au_pin_set_dentry(&pin, d);
5748 + err = au_do_pin(&pin);
5750 + err = cp(d, bdst, &pin, h_parent, arg);
5755 + if (d != real_parent)
5756 + di_write_unlock(d);
5757 + if (unlikely(err))
5766 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5767 + struct au_pin *pin,
5768 + struct dentry *h_parent __maybe_unused,
5769 + void *arg __maybe_unused)
5771 + struct au_cp_generic cpg = {
5777 + .flags = AuCpup_DTIME
5779 + return au_sio_cpup_simple(&cpg);
5782 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5784 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5787 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5790 + struct dentry *parent;
5791 + struct inode *dir;
5793 + parent = dget_parent(dentry);
5794 + dir = d_inode(parent);
5796 + if (au_h_iptr(dir, bdst))
5799 + di_read_unlock(parent, AuLock_IR);
5800 + di_write_lock_parent(parent);
5801 + /* someone else might change our inode while we were sleeping */
5802 + if (!au_h_iptr(dir, bdst))
5803 + err = au_cpup_dirs(dentry, bdst);
5804 + di_downgrade_lock(parent, AuLock_IR);
5810 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
5811 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
5812 +++ linux/fs/aufs/cpup.h 2015-09-24 10:47:58.248052907 +0200
5815 + * Copyright (C) 2005-2015 Junjiro R. Okajima
5817 + * This program, aufs is free software; you can redistribute it and/or modify
5818 + * it under the terms of the GNU General Public License as published by
5819 + * the Free Software Foundation; either version 2 of the License, or
5820 + * (at your option) any later version.
5822 + * This program is distributed in the hope that it will be useful,
5823 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5824 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5825 + * GNU General Public License for more details.
5827 + * You should have received a copy of the GNU General Public License
5828 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5832 + * copy-up/down functions
5835 +#ifndef __AUFS_CPUP_H__
5836 +#define __AUFS_CPUP_H__
5840 +#include <linux/path.h>
5846 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
5847 +void au_cpup_attr_timesizes(struct inode *inode);
5848 +void au_cpup_attr_nlink(struct inode *inode, int force);
5849 +void au_cpup_attr_changeable(struct inode *inode);
5850 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
5851 +void au_cpup_attr_all(struct inode *inode, int force);
5853 +/* ---------------------------------------------------------------------- */
5855 +struct au_cp_generic {
5856 + struct dentry *dentry;
5857 + aufs_bindex_t bdst, bsrc;
5859 + struct au_pin *pin;
5860 + unsigned int flags;
5864 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
5865 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
5867 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
5868 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
5870 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
5872 +#define AuCpup_RWDST (1 << 5) /* force write target even if
5873 + the branch is marked as RO */
5875 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
5876 +#define au_fset_cpup(flags, name) \
5877 + do { (flags) |= AuCpup_##name; } while (0)
5878 +#define au_fclr_cpup(flags, name) \
5879 + do { (flags) &= ~AuCpup_##name; } while (0)
5881 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
5882 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
5883 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
5884 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
5886 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5887 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5888 + struct au_pin *pin,
5889 + struct dentry *h_parent, void *arg),
5891 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5892 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
5894 +/* ---------------------------------------------------------------------- */
5896 +/* keep timestamps when copyup */
5898 + struct dentry *dt_dentry;
5899 + struct path dt_h_path;
5900 + struct timespec dt_atime, dt_mtime;
5902 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
5903 + struct path *h_path);
5904 +void au_dtime_revert(struct au_dtime *dt);
5906 +#endif /* __KERNEL__ */
5907 +#endif /* __AUFS_CPUP_H__ */
5908 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
5909 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
5910 +++ linux/fs/aufs/dbgaufs.c 2015-09-24 10:47:58.248052907 +0200
5913 + * Copyright (C) 2005-2015 Junjiro R. Okajima
5915 + * This program, aufs is free software; you can redistribute it and/or modify
5916 + * it under the terms of the GNU General Public License as published by
5917 + * the Free Software Foundation; either version 2 of the License, or
5918 + * (at your option) any later version.
5920 + * This program is distributed in the hope that it will be useful,
5921 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
5922 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5923 + * GNU General Public License for more details.
5925 + * You should have received a copy of the GNU General Public License
5926 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
5930 + * debugfs interface
5933 +#include <linux/debugfs.h>
5936 +#ifndef CONFIG_SYSFS
5937 +#error DEBUG_FS depends upon SYSFS
5940 +static struct dentry *dbgaufs;
5941 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
5943 +/* 20 is max digits length of ulong 64 */
5944 +struct dbgaufs_arg {
5950 + * common function for all XINO files
5952 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
5953 + struct file *file)
5955 + kfree(file->private_data);
5959 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
5963 + struct dbgaufs_arg *p;
5966 + p = kmalloc(sizeof(*p), GFP_NOFS);
5972 + file->private_data = p;
5976 + err = vfs_getattr(&xf->f_path, &st);
5980 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
5981 + (long)file_count(xf), st.blocks, st.blksize,
5982 + (long long)st.size);
5984 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
5985 + st.blocks, st.blksize,
5986 + (long long)st.size);
5987 + AuDebugOn(p->n >= sizeof(p->a));
5989 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
5998 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
5999 + size_t count, loff_t *ppos)
6001 + struct dbgaufs_arg *p;
6003 + p = file->private_data;
6004 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6007 +/* ---------------------------------------------------------------------- */
6009 +struct dbgaufs_plink_arg {
6014 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6015 + struct file *file)
6017 + free_page((unsigned long)file->private_data);
6021 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6023 + int err, i, limit;
6024 + unsigned long n, sum;
6025 + struct dbgaufs_plink_arg *p;
6026 + struct au_sbinfo *sbinfo;
6027 + struct super_block *sb;
6028 + struct au_sphlhead *sphl;
6031 + p = (void *)get_zeroed_page(GFP_NOFS);
6036 + sbinfo = inode->i_private;
6037 + sb = sbinfo->si_sb;
6038 + si_noflush_read_lock(sb);
6039 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6040 + limit = PAGE_SIZE - sizeof(p->n);
6042 + /* the number of buckets */
6043 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6048 + for (i = 0, sphl = sbinfo->si_plink;
6049 + i < AuPlink_NHASH;
6051 + n = au_sphl_count(sphl);
6054 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6057 + if (unlikely(limit <= 0))
6060 + p->a[p->n - 1] = '\n';
6062 + /* the sum of plinks */
6063 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6066 + if (unlikely(limit <= 0))
6069 +#define str "1\n0\n0\n"
6070 + p->n = sizeof(str) - 1;
6071 + strcpy(p->a, str);
6074 + si_read_unlock(sb);
6077 + file->private_data = p;
6078 + goto out; /* success */
6081 + free_page((unsigned long)p);
6086 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6087 + size_t count, loff_t *ppos)
6089 + struct dbgaufs_plink_arg *p;
6091 + p = file->private_data;
6092 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6095 +static const struct file_operations dbgaufs_plink_fop = {
6096 + .owner = THIS_MODULE,
6097 + .open = dbgaufs_plink_open,
6098 + .release = dbgaufs_plink_release,
6099 + .read = dbgaufs_plink_read
6102 +/* ---------------------------------------------------------------------- */
6104 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6107 + struct au_sbinfo *sbinfo;
6108 + struct super_block *sb;
6110 + sbinfo = inode->i_private;
6111 + sb = sbinfo->si_sb;
6112 + si_noflush_read_lock(sb);
6113 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6114 + si_read_unlock(sb);
6118 +static const struct file_operations dbgaufs_xib_fop = {
6119 + .owner = THIS_MODULE,
6120 + .open = dbgaufs_xib_open,
6121 + .release = dbgaufs_xi_release,
6122 + .read = dbgaufs_xi_read
6125 +/* ---------------------------------------------------------------------- */
6127 +#define DbgaufsXi_PREFIX "xi"
6129 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6133 + struct au_sbinfo *sbinfo;
6134 + struct super_block *sb;
6136 + struct qstr *name;
6140 + name = &file->f_path.dentry->d_name;
6141 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6142 + || memcmp(name->name, DbgaufsXi_PREFIX,
6143 + sizeof(DbgaufsXi_PREFIX) - 1)))
6145 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6146 + if (unlikely(err))
6149 + sbinfo = inode->i_private;
6150 + sb = sbinfo->si_sb;
6151 + si_noflush_read_lock(sb);
6152 + if (l <= au_sbend(sb)) {
6153 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6154 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6157 + si_read_unlock(sb);
6163 +static const struct file_operations dbgaufs_xino_fop = {
6164 + .owner = THIS_MODULE,
6165 + .open = dbgaufs_xino_open,
6166 + .release = dbgaufs_xi_release,
6167 + .read = dbgaufs_xi_read
6170 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6172 + aufs_bindex_t bend;
6173 + struct au_branch *br;
6174 + struct au_xino_file *xi;
6176 + if (!au_sbi(sb)->si_dbgaufs)
6179 + bend = au_sbend(sb);
6180 + for (; bindex <= bend; bindex++) {
6181 + br = au_sbr(sb, bindex);
6182 + xi = &br->br_xino;
6183 + debugfs_remove(xi->xi_dbgaufs);
6184 + xi->xi_dbgaufs = NULL;
6188 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6190 + struct au_sbinfo *sbinfo;
6191 + struct dentry *parent;
6192 + struct au_branch *br;
6193 + struct au_xino_file *xi;
6194 + aufs_bindex_t bend;
6195 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6197 + sbinfo = au_sbi(sb);
6198 + parent = sbinfo->si_dbgaufs;
6202 + bend = au_sbend(sb);
6203 + for (; bindex <= bend; bindex++) {
6204 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6205 + br = au_sbr(sb, bindex);
6206 + xi = &br->br_xino;
6207 + AuDebugOn(xi->xi_dbgaufs);
6208 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6209 + sbinfo, &dbgaufs_xino_fop);
6210 + /* ignore an error */
6211 + if (unlikely(!xi->xi_dbgaufs))
6212 + AuWarn1("failed %s under debugfs\n", name);
6216 +/* ---------------------------------------------------------------------- */
6218 +#ifdef CONFIG_AUFS_EXPORT
6219 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6222 + struct au_sbinfo *sbinfo;
6223 + struct super_block *sb;
6225 + sbinfo = inode->i_private;
6226 + sb = sbinfo->si_sb;
6227 + si_noflush_read_lock(sb);
6228 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6229 + si_read_unlock(sb);
6233 +static const struct file_operations dbgaufs_xigen_fop = {
6234 + .owner = THIS_MODULE,
6235 + .open = dbgaufs_xigen_open,
6236 + .release = dbgaufs_xi_release,
6237 + .read = dbgaufs_xi_read
6240 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6245 + * This function is a dynamic '__init' function actually,
6246 + * so the tiny check for si_rwsem is unnecessary.
6248 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6251 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6252 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6253 + &dbgaufs_xigen_fop);
6254 + if (sbinfo->si_dbgaufs_xigen)
6260 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6264 +#endif /* CONFIG_AUFS_EXPORT */
6266 +/* ---------------------------------------------------------------------- */
6268 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6271 + * This function is a dynamic '__fin' function actually,
6272 + * so the tiny check for si_rwsem is unnecessary.
6274 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6276 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6277 + sbinfo->si_dbgaufs = NULL;
6278 + kobject_put(&sbinfo->si_kobj);
6281 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6284 + char name[SysaufsSiNameLen];
6287 + * This function is a dynamic '__init' function actually,
6288 + * so the tiny check for si_rwsem is unnecessary.
6290 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6294 + AuErr1("/debug/aufs is uninitialized\n");
6299 + sysaufs_name(sbinfo, name);
6300 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6301 + if (unlikely(!sbinfo->si_dbgaufs))
6303 + kobject_get(&sbinfo->si_kobj);
6305 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6306 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6307 + &dbgaufs_xib_fop);
6308 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6311 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6312 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6313 + &dbgaufs_plink_fop);
6314 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6317 + err = dbgaufs_xigen_init(sbinfo);
6319 + goto out; /* success */
6322 + dbgaufs_si_fin(sbinfo);
6327 +/* ---------------------------------------------------------------------- */
6329 +void dbgaufs_fin(void)
6331 + debugfs_remove(dbgaufs);
6334 +int __init dbgaufs_init(void)
6339 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6344 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6345 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6346 +++ linux/fs/aufs/dbgaufs.h 2015-09-24 10:47:58.248052907 +0200
6349 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6351 + * This program, aufs is free software; you can redistribute it and/or modify
6352 + * it under the terms of the GNU General Public License as published by
6353 + * the Free Software Foundation; either version 2 of the License, or
6354 + * (at your option) any later version.
6356 + * This program is distributed in the hope that it will be useful,
6357 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6358 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6359 + * GNU General Public License for more details.
6361 + * You should have received a copy of the GNU General Public License
6362 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6366 + * debugfs interface
6369 +#ifndef __DBGAUFS_H__
6370 +#define __DBGAUFS_H__
6374 +struct super_block;
6377 +#ifdef CONFIG_DEBUG_FS
6379 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6380 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6381 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6382 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6383 +void dbgaufs_fin(void);
6384 +int __init dbgaufs_init(void);
6386 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6387 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6388 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6389 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6390 +AuStubVoid(dbgaufs_fin, void)
6391 +AuStubInt0(__init dbgaufs_init, void)
6392 +#endif /* CONFIG_DEBUG_FS */
6394 +#endif /* __KERNEL__ */
6395 +#endif /* __DBGAUFS_H__ */
6396 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6397 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6398 +++ linux/fs/aufs/dcsub.c 2015-09-24 10:47:58.248052907 +0200
6401 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6403 + * This program, aufs is free software; you can redistribute it and/or modify
6404 + * it under the terms of the GNU General Public License as published by
6405 + * the Free Software Foundation; either version 2 of the License, or
6406 + * (at your option) any later version.
6408 + * This program is distributed in the hope that it will be useful,
6409 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6410 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6411 + * GNU General Public License for more details.
6413 + * You should have received a copy of the GNU General Public License
6414 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6418 + * sub-routines for dentry cache
6423 +static void au_dpage_free(struct au_dpage *dpage)
6426 + struct dentry **p;
6428 + p = dpage->dentries;
6429 + for (i = 0; i < dpage->ndentry; i++)
6431 + free_page((unsigned long)dpage->dentries);
6434 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6440 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6441 + if (unlikely(!dpages->dpages))
6444 + p = (void *)__get_free_page(gfp);
6448 + dpages->dpages[0].ndentry = 0;
6449 + dpages->dpages[0].dentries = p;
6450 + dpages->ndpage = 1;
6451 + return 0; /* success */
6454 + kfree(dpages->dpages);
6459 +void au_dpages_free(struct au_dcsub_pages *dpages)
6462 + struct au_dpage *p;
6464 + p = dpages->dpages;
6465 + for (i = 0; i < dpages->ndpage; i++)
6466 + au_dpage_free(p++);
6467 + kfree(dpages->dpages);
6470 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6471 + struct dentry *dentry, gfp_t gfp)
6474 + struct au_dpage *dpage;
6477 + dpage = dpages->dpages + dpages->ndpage - 1;
6478 + sz = PAGE_SIZE / sizeof(dentry);
6479 + if (unlikely(dpage->ndentry >= sz)) {
6480 + AuLabel(new dpage);
6482 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6483 + p = au_kzrealloc(dpages->dpages, sz,
6484 + sz + sizeof(*dpages->dpages), gfp);
6488 + dpages->dpages = p;
6489 + dpage = dpages->dpages + dpages->ndpage;
6490 + p = (void *)__get_free_page(gfp);
6494 + dpage->ndentry = 0;
6495 + dpage->dentries = p;
6499 + AuDebugOn(au_dcount(dentry) <= 0);
6500 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6501 + return 0; /* success */
6507 +/* todo: BAD approach */
6508 +/* copied from linux/fs/dcache.c */
6516 +extern void d_walk(struct dentry *parent, void *data,
6517 + enum d_walk_ret (*enter)(void *, struct dentry *),
6518 + void (*finish)(void *));
6520 +struct ac_dpages_arg {
6522 + struct au_dcsub_pages *dpages;
6523 + struct super_block *sb;
6524 + au_dpages_test test;
6528 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6530 + enum d_walk_ret ret;
6531 + struct ac_dpages_arg *arg = _arg;
6533 + ret = D_WALK_CONTINUE;
6534 + if (dentry->d_sb == arg->sb
6535 + && !IS_ROOT(dentry)
6536 + && au_dcount(dentry) > 0
6538 + && (!arg->test || arg->test(dentry, arg->arg))) {
6539 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6540 + if (unlikely(arg->err))
6541 + ret = D_WALK_QUIT;
6547 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6548 + au_dpages_test test, void *arg)
6550 + struct ac_dpages_arg args = {
6558 + d_walk(root, &args, au_call_dpages_append, NULL);
6563 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6564 + int do_include, au_dpages_test test, void *arg)
6569 + write_seqlock(&rename_lock);
6570 + spin_lock(&dentry->d_lock);
6572 + && au_dcount(dentry) > 0
6573 + && (!test || test(dentry, arg)))
6574 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6575 + spin_unlock(&dentry->d_lock);
6576 + if (unlikely(err))
6580 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6583 + while (!IS_ROOT(dentry)) {
6584 + dentry = dentry->d_parent; /* rename_lock is locked */
6585 + spin_lock(&dentry->d_lock);
6586 + if (au_dcount(dentry) > 0
6587 + && (!test || test(dentry, arg)))
6588 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6589 + spin_unlock(&dentry->d_lock);
6590 + if (unlikely(err))
6595 + write_sequnlock(&rename_lock);
6599 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6601 + return au_di(dentry) && dentry->d_sb == arg;
6604 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6605 + struct dentry *dentry, int do_include)
6607 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6608 + au_dcsub_dpages_aufs, dentry->d_sb);
6611 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6613 + struct path path[2] = {
6622 + return path_is_under(path + 0, path + 1);
6624 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6625 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6626 +++ linux/fs/aufs/dcsub.h 2015-09-24 10:47:58.251386326 +0200
6629 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6631 + * This program, aufs is free software; you can redistribute it and/or modify
6632 + * it under the terms of the GNU General Public License as published by
6633 + * the Free Software Foundation; either version 2 of the License, or
6634 + * (at your option) any later version.
6636 + * This program is distributed in the hope that it will be useful,
6637 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6638 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6639 + * GNU General Public License for more details.
6641 + * You should have received a copy of the GNU General Public License
6642 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6646 + * sub-routines for dentry cache
6649 +#ifndef __AUFS_DCSUB_H__
6650 +#define __AUFS_DCSUB_H__
6654 +#include <linux/dcache.h>
6655 +#include <linux/fs.h>
6659 + struct dentry **dentries;
6662 +struct au_dcsub_pages {
6664 + struct au_dpage *dpages;
6667 +/* ---------------------------------------------------------------------- */
6670 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6671 +void au_dpages_free(struct au_dcsub_pages *dpages);
6672 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6673 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6674 + au_dpages_test test, void *arg);
6675 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6676 + int do_include, au_dpages_test test, void *arg);
6677 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6678 + struct dentry *dentry, int do_include);
6679 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6681 +/* ---------------------------------------------------------------------- */
6684 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6685 + * include/linux/dcache.h. Try them (in the future).
6688 +static inline int au_d_hashed_positive(struct dentry *d)
6691 + struct inode *inode = d_inode(d);
6694 + if (unlikely(d_unhashed(d)
6695 + || d_is_negative(d)
6696 + || !inode->i_nlink))
6701 +static inline int au_d_linkable(struct dentry *d)
6704 + struct inode *inode = d_inode(d);
6706 + err = au_d_hashed_positive(d);
6708 + && d_is_positive(d)
6709 + && (inode->i_state & I_LINKABLE))
6714 +static inline int au_d_alive(struct dentry *d)
6717 + struct inode *inode;
6721 + err = au_d_hashed_positive(d);
6723 + inode = d_inode(d);
6724 + if (unlikely(d_unlinked(d)
6725 + || d_is_negative(d)
6726 + || !inode->i_nlink))
6732 +static inline int au_alive_dir(struct dentry *d)
6736 + err = au_d_alive(d);
6737 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
6742 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6744 + return a->len == b->len
6745 + && !memcmp(a->name, b->name, a->len);
6750 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
6752 + * the type of d_lockref.count became int, but the inlined function d_count()
6753 + * still returns unsigned int.
6754 + * I don't know why. Maybe it is for every d_count() users?
6755 + * Anyway au_dcount() lives on.
6757 +static inline int au_dcount(struct dentry *d)
6759 + return (int)d_count(d);
6762 +#endif /* __KERNEL__ */
6763 +#endif /* __AUFS_DCSUB_H__ */
6764 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6765 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6766 +++ linux/fs/aufs/debug.c 2015-09-24 10:47:58.251386326 +0200
6769 + * Copyright (C) 2005-2015 Junjiro R. Okajima
6771 + * This program, aufs is free software; you can redistribute it and/or modify
6772 + * it under the terms of the GNU General Public License as published by
6773 + * the Free Software Foundation; either version 2 of the License, or
6774 + * (at your option) any later version.
6776 + * This program is distributed in the hope that it will be useful,
6777 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6778 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6779 + * GNU General Public License for more details.
6781 + * You should have received a copy of the GNU General Public License
6782 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6786 + * debug print functions
6791 +/* Returns 0, or -errno. arg is in kp->arg. */
6792 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
6796 + err = kstrtoint(val, 0, &n);
6806 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
6807 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
6812 + return sprintf(buffer, "%d", atomic_read(a));
6815 +static struct kernel_param_ops param_ops_atomic_t = {
6816 + .set = param_atomic_t_set,
6817 + .get = param_atomic_t_get
6818 + /* void (*free)(void *arg) */
6821 +atomic_t aufs_debug = ATOMIC_INIT(0);
6822 +MODULE_PARM_DESC(debug, "debug print");
6823 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
6825 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
6826 +char *au_plevel = KERN_DEBUG;
6827 +#define dpri(fmt, ...) do { \
6829 + && strcmp(au_plevel, KERN_DEBUG)) \
6830 + || au_debug_test()) \
6831 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
6834 +/* ---------------------------------------------------------------------- */
6836 +void au_dpri_whlist(struct au_nhash *whlist)
6838 + unsigned long ul, n;
6839 + struct hlist_head *head;
6840 + struct au_vdir_wh *pos;
6842 + n = whlist->nh_num;
6843 + head = whlist->nh_head;
6844 + for (ul = 0; ul < n; ul++) {
6845 + hlist_for_each_entry(pos, head, wh_hash)
6846 + dpri("b%d, %.*s, %d\n",
6848 + pos->wh_str.len, pos->wh_str.name,
6854 +void au_dpri_vdir(struct au_vdir *vdir)
6857 + union au_vdir_deblk_p p;
6860 + if (!vdir || IS_ERR(vdir)) {
6861 + dpri("err %ld\n", PTR_ERR(vdir));
6865 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
6866 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
6867 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
6868 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
6869 + p.deblk = vdir->vd_deblk[ul];
6871 + dpri("[%lu]: %p\n", ul, o);
6875 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
6876 + struct dentry *wh)
6881 + if (!inode || IS_ERR(inode)) {
6882 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
6886 + /* the type of i_blocks depends upon CONFIG_LBDAF */
6887 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
6888 + && sizeof(inode->i_blocks) != sizeof(u64));
6890 + n = (void *)wh->d_name.name;
6891 + l = wh->d_name.len;
6894 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
6895 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
6897 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
6898 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
6899 + i_size_read(inode), (unsigned long long)inode->i_blocks,
6900 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
6901 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
6902 + inode->i_state, inode->i_flags, inode->i_version,
6903 + inode->i_generation,
6904 + l ? ", wh " : "", l, n);
6908 +void au_dpri_inode(struct inode *inode)
6910 + struct au_iinfo *iinfo;
6911 + aufs_bindex_t bindex;
6914 + err = do_pri_inode(-1, inode, -1, NULL);
6915 + if (err || !au_test_aufs(inode->i_sb))
6918 + iinfo = au_ii(inode);
6921 + dpri("i-1: bstart %d, bend %d, gen %d\n",
6922 + iinfo->ii_bstart, iinfo->ii_bend, au_iigen(inode, NULL));
6923 + if (iinfo->ii_bstart < 0)
6926 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend; bindex++) {
6927 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6928 + do_pri_inode(bindex, iinfo->ii_hinode[0 + bindex].hi_inode, hn,
6929 + iinfo->ii_hinode[0 + bindex].hi_whdentry);
6933 +void au_dpri_dalias(struct inode *inode)
6937 + spin_lock(&inode->i_lock);
6938 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
6939 + au_dpri_dentry(d);
6940 + spin_unlock(&inode->i_lock);
6943 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
6945 + struct dentry *wh = NULL;
6947 + struct au_iinfo *iinfo;
6949 + if (!dentry || IS_ERR(dentry)) {
6950 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
6953 + /* do not call dget_parent() here */
6954 + /* note: access d_xxx without d_lock */
6955 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
6956 + bindex, dentry, dentry,
6957 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
6958 + au_dcount(dentry), dentry->d_flags,
6959 + d_unhashed(dentry) ? "un" : "");
6962 + && d_is_positive(dentry)
6963 + && au_test_aufs(dentry->d_sb)) {
6964 + iinfo = au_ii(d_inode(dentry));
6966 + hn = !!au_hn(iinfo->ii_hinode + bindex);
6967 + wh = iinfo->ii_hinode[0 + bindex].hi_whdentry;
6970 + do_pri_inode(bindex, d_inode(dentry), hn, wh);
6974 +void au_dpri_dentry(struct dentry *dentry)
6976 + struct au_dinfo *dinfo;
6977 + aufs_bindex_t bindex;
6979 + struct au_hdentry *hdp;
6981 + err = do_pri_dentry(-1, dentry);
6982 + if (err || !au_test_aufs(dentry->d_sb))
6985 + dinfo = au_di(dentry);
6988 + dpri("d-1: bstart %d, bend %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
6989 + dinfo->di_bstart, dinfo->di_bend,
6990 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
6991 + dinfo->di_tmpfile);
6992 + if (dinfo->di_bstart < 0)
6994 + hdp = dinfo->di_hdentry;
6995 + for (bindex = dinfo->di_bstart; bindex <= dinfo->di_bend; bindex++)
6996 + do_pri_dentry(bindex, hdp[0 + bindex].hd_dentry);
6999 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7003 + if (!file || IS_ERR(file)) {
7004 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7009 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7010 + && au_test_aufs(file->f_path.dentry->d_sb)
7012 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7013 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7014 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7015 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7016 + file->f_version, file->f_pos, a);
7017 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7018 + do_pri_dentry(bindex, file->f_path.dentry);
7022 +void au_dpri_file(struct file *file)
7024 + struct au_finfo *finfo;
7025 + struct au_fidir *fidir;
7026 + struct au_hfile *hfile;
7027 + aufs_bindex_t bindex;
7030 + err = do_pri_file(-1, file);
7032 + || IS_ERR_OR_NULL(file->f_path.dentry)
7033 + || !au_test_aufs(file->f_path.dentry->d_sb))
7036 + finfo = au_fi(file);
7039 + if (finfo->fi_btop < 0)
7041 + fidir = finfo->fi_hdir;
7043 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7045 + for (bindex = finfo->fi_btop;
7046 + bindex >= 0 && bindex <= fidir->fd_bbot;
7048 + hfile = fidir->fd_hfile + bindex;
7049 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7053 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7055 + struct vfsmount *mnt;
7056 + struct super_block *sb;
7058 + if (!br || IS_ERR(br))
7060 + mnt = au_br_mnt(br);
7061 + if (!mnt || IS_ERR(mnt))
7064 + if (!sb || IS_ERR(sb))
7067 + dpri("s%d: {perm 0x%x, id %d, cnt %d, wbr %p}, "
7068 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7070 + bindex, br->br_perm, br->br_id, atomic_read(&br->br_count),
7071 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7072 + sb->s_flags, sb->s_count,
7073 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7077 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7081 +void au_dpri_sb(struct super_block *sb)
7083 + struct au_sbinfo *sbinfo;
7084 + aufs_bindex_t bindex;
7086 + /* to reuduce stack size */
7088 + struct vfsmount mnt;
7089 + struct au_branch fake;
7092 + /* this function can be called from magic sysrq */
7093 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7094 + if (unlikely(!a)) {
7095 + dpri("no memory\n");
7099 + a->mnt.mnt_sb = sb;
7100 + a->fake.br_perm = 0;
7101 + a->fake.br_path.mnt = &a->mnt;
7102 + a->fake.br_xino.xi_file = NULL;
7103 + atomic_set(&a->fake.br_count, 0);
7104 + smp_mb(); /* atomic_set */
7105 + err = do_pri_br(-1, &a->fake);
7107 + dpri("dev 0x%x\n", sb->s_dev);
7108 + if (err || !au_test_aufs(sb))
7111 + sbinfo = au_sbi(sb);
7114 + dpri("nw %d, gen %u, kobj %d\n",
7115 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7116 + atomic_read(&sbinfo->si_kobj.kref.refcount));
7117 + for (bindex = 0; bindex <= sbinfo->si_bend; bindex++)
7118 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7121 +/* ---------------------------------------------------------------------- */
7123 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7125 + struct inode *h_inode, *inode = d_inode(dentry);
7126 + struct dentry *h_dentry;
7127 + aufs_bindex_t bindex, bend, bi;
7129 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7132 + bend = au_dbend(dentry);
7133 + bi = au_ibend(inode);
7136 + bindex = au_dbstart(dentry);
7137 + bi = au_ibstart(inode);
7141 + for (; bindex <= bend; bindex++) {
7142 + h_dentry = au_h_dptr(dentry, bindex);
7145 + h_inode = au_h_iptr(inode, bindex);
7146 + if (unlikely(h_inode != d_inode(h_dentry))) {
7148 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7149 + AuDbgDentry(dentry);
7150 + AuDbgInode(inode);
7157 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7160 + struct au_dcsub_pages dpages;
7161 + struct au_dpage *dpage;
7162 + struct dentry **dentries;
7164 + err = au_dpages_init(&dpages, GFP_NOFS);
7166 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7168 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7169 + dpage = dpages.dpages + i;
7170 + dentries = dpage->dentries;
7171 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7172 + AuDebugOn(au_digen_test(dentries[j], sigen));
7174 + au_dpages_free(&dpages);
7177 +void au_dbg_verify_kthread(void)
7179 + if (au_wkq_test()) {
7182 + * It may be recursive, but udba=notify between two aufs mounts,
7183 + * where a single ro branch is shared, is not a problem.
7189 +/* ---------------------------------------------------------------------- */
7191 +int __init au_debug_init(void)
7193 + aufs_bindex_t bindex;
7194 + struct au_vdir_destr destr;
7197 + AuDebugOn(bindex >= 0);
7200 + AuDebugOn(destr.len < NAME_MAX);
7202 +#ifdef CONFIG_4KSTACKS
7203 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7208 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7209 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7210 +++ linux/fs/aufs/debug.h 2015-09-24 10:47:58.251386326 +0200
7213 + * Copyright (C) 2005-2015 Junjiro R. Okajima
7215 + * This program, aufs is free software; you can redistribute it and/or modify
7216 + * it under the terms of the GNU General Public License as published by
7217 + * the Free Software Foundation; either version 2 of the License, or
7218 + * (at your option) any later version.
7220 + * This program is distributed in the hope that it will be useful,
7221 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7222 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7223 + * GNU General Public License for more details.
7225 + * You should have received a copy of the GNU General Public License
7226 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7230 + * debug print functions
7233 +#ifndef __AUFS_DEBUG_H__
7234 +#define __AUFS_DEBUG_H__
7238 +#include <linux/atomic.h>
7239 +#include <linux/module.h>
7240 +#include <linux/kallsyms.h>
7241 +#include <linux/sysrq.h>
7243 +#ifdef CONFIG_AUFS_DEBUG
7244 +#define AuDebugOn(a) BUG_ON(a)
7246 +/* module parameter */
7247 +extern atomic_t aufs_debug;
7248 +static inline void au_debug_on(void)
7250 + atomic_inc(&aufs_debug);
7252 +static inline void au_debug_off(void)
7254 + atomic_dec_if_positive(&aufs_debug);
7257 +static inline int au_debug_test(void)
7259 + return atomic_read(&aufs_debug) > 0;
7262 +#define AuDebugOn(a) do {} while (0)
7263 +AuStubVoid(au_debug_on, void)
7264 +AuStubVoid(au_debug_off, void)
7265 +AuStubInt0(au_debug_test, void)
7266 +#endif /* CONFIG_AUFS_DEBUG */
7268 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7270 +/* ---------------------------------------------------------------------- */
7274 +#define AuDbg(fmt, ...) do { \
7275 + if (au_debug_test()) \
7276 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7278 +#define AuLabel(l) AuDbg(#l "\n")
7279 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7280 +#define AuWarn1(fmt, ...) do { \
7281 + static unsigned char _c; \
7283 + pr_warn(fmt, ##__VA_ARGS__); \
7286 +#define AuErr1(fmt, ...) do { \
7287 + static unsigned char _c; \
7289 + pr_err(fmt, ##__VA_ARGS__); \
7292 +#define AuIOErr1(fmt, ...) do { \
7293 + static unsigned char _c; \
7295 + AuIOErr(fmt, ##__VA_ARGS__); \
7298 +#define AuUnsupportMsg "This operation is not supported." \
7299 + " Please report this application to aufs-users ML."
7300 +#define AuUnsupport(fmt, ...) do { \
7301 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7305 +#define AuTraceErr(e) do { \
7306 + if (unlikely((e) < 0)) \
7307 + AuDbg("err %d\n", (int)(e)); \
7310 +#define AuTraceErrPtr(p) do { \
7312 + AuDbg("err %ld\n", PTR_ERR(p)); \
7315 +/* dirty macros for debug print, use with "%.*s" and caution */
7316 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7318 +/* ---------------------------------------------------------------------- */
7321 +#ifdef CONFIG_AUFS_DEBUG
7322 +extern struct mutex au_dbg_mtx;
7323 +extern char *au_plevel;
7325 +void au_dpri_whlist(struct au_nhash *whlist);
7327 +void au_dpri_vdir(struct au_vdir *vdir);
7329 +void au_dpri_inode(struct inode *inode);
7330 +void au_dpri_dalias(struct inode *inode);
7331 +void au_dpri_dentry(struct dentry *dentry);
7333 +void au_dpri_file(struct file *filp);
7334 +struct super_block;
7335 +void au_dpri_sb(struct super_block *sb);
7337 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7338 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7339 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7340 +void au_dbg_verify_kthread(void);
7342 +int __init au_debug_init(void);
7344 +#define AuDbgWhlist(w) do { \
7345 + mutex_lock(&au_dbg_mtx); \
7347 + au_dpri_whlist(w); \
7348 + mutex_unlock(&au_dbg_mtx); \
7351 +#define AuDbgVdir(v) do { \
7352 + mutex_lock(&au_dbg_mtx); \
7354 + au_dpri_vdir(v); \
7355 + mutex_unlock(&au_dbg_mtx); \
7358 +#define AuDbgInode(i) do { \
7359 + mutex_lock(&au_dbg_mtx); \
7361 + au_dpri_inode(i); \
7362 + mutex_unlock(&au_dbg_mtx); \
7365 +#define AuDbgDAlias(i) do { \
7366 + mutex_lock(&au_dbg_mtx); \
7368 + au_dpri_dalias(i); \
7369 + mutex_unlock(&au_dbg_mtx); \
7372 +#define AuDbgDentry(d) do { \
7373 + mutex_lock(&au_dbg_mtx); \
7375 + au_dpri_dentry(d); \
7376 + mutex_unlock(&au_dbg_mtx); \
7379 +#define AuDbgFile(f) do { \
7380 + mutex_lock(&au_dbg_mtx); \
7382 + au_dpri_file(f); \
7383 + mutex_unlock(&au_dbg_mtx); \
7386 +#define AuDbgSb(sb) do { \
7387 + mutex_lock(&au_dbg_mtx); \
7388 + AuDbg(#sb "\n"); \
7390 + mutex_unlock(&au_dbg_mtx); \
7393 +#define AuDbgSym(addr) do { \
7394 + char sym[KSYM_SYMBOL_LEN]; \
7395 + sprint_symbol(sym, (unsigned long)addr); \
7396 + AuDbg("%s\n", sym); \
7399 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7400 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7401 +AuStubVoid(au_dbg_verify_kthread, void)
7402 +AuStubInt0(__init au_debug_init, void)
7404 +#define AuDbgWhlist(w) do {} while (0)
7405 +#define AuDbgVdir(v) do {} while (0)
7406 +#define AuDbgInode(i) do {} while (0)
7407 +#define AuDbgDAlias(i) do {} while (0)
7408 +#define AuDbgDentry(d) do {} while (0)
7409 +#define AuDbgFile(f) do {} while (0)
7410 +#define AuDbgSb(sb) do {} while (0)
7411 +#define AuDbgSym(addr) do {} while (0)
7412 +#endif /* CONFIG_AUFS_DEBUG */
7414 +/* ---------------------------------------------------------------------- */
7416 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7417 +int __init au_sysrq_init(void);
7418 +void au_sysrq_fin(void);
7420 +#ifdef CONFIG_HW_CONSOLE
7421 +#define au_dbg_blocked() do { \
7423 + handle_sysrq('w'); \
7426 +AuStubVoid(au_dbg_blocked, void)
7430 +AuStubInt0(__init au_sysrq_init, void)
7431 +AuStubVoid(au_sysrq_fin, void)
7432 +AuStubVoid(au_dbg_blocked, void)
7433 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7435 +#endif /* __KERNEL__ */
7436 +#endif /* __AUFS_DEBUG_H__ */
7437 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7438 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7439 +++ linux/fs/aufs/dentry.c 2015-09-24 10:47:58.251386326 +0200
7442 + * Copyright (C) 2005-2015 Junjiro R. Okajima
7444 + * This program, aufs is free software; you can redistribute it and/or modify
7445 + * it under the terms of the GNU General Public License as published by
7446 + * the Free Software Foundation; either version 2 of the License, or
7447 + * (at your option) any later version.
7449 + * This program is distributed in the hope that it will be useful,
7450 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7451 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7452 + * GNU General Public License for more details.
7454 + * You should have received a copy of the GNU General Public License
7455 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7459 + * lookup and dentry operations
7462 +#include <linux/namei.h>
7465 +#define AuLkup_ALLOW_NEG 1
7466 +#define AuLkup_IGNORE_PERM (1 << 1)
7467 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
7468 +#define au_fset_lkup(flags, name) \
7469 + do { (flags) |= AuLkup_##name; } while (0)
7470 +#define au_fclr_lkup(flags, name) \
7471 + do { (flags) &= ~AuLkup_##name; } while (0)
7473 +struct au_do_lookup_args {
7474 + unsigned int flags;
7479 + * returns positive/negative dentry, NULL or an error.
7480 + * NULL means whiteout-ed or not-found.
7482 +static struct dentry*
7483 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7484 + aufs_bindex_t bindex, struct qstr *wh_name,
7485 + struct au_do_lookup_args *args)
7487 + struct dentry *h_dentry;
7488 + struct inode *h_inode;
7489 + struct au_branch *br;
7490 + int wh_found, opq;
7491 + unsigned char wh_able;
7492 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7493 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7497 + br = au_sbr(dentry->d_sb, bindex);
7498 + wh_able = !!au_br_whable(br->br_perm);
7500 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7501 + h_dentry = ERR_PTR(wh_found);
7504 + if (unlikely(wh_found < 0))
7507 + /* We found a whiteout */
7508 + /* au_set_dbend(dentry, bindex); */
7509 + au_set_dbwh(dentry, bindex);
7511 + return NULL; /* success */
7515 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7517 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7518 + if (IS_ERR(h_dentry)) {
7519 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7525 + h_inode = d_inode(h_dentry);
7526 + if (d_is_negative(h_dentry)) {
7529 + } else if (wh_found
7530 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7533 + if (au_dbend(dentry) <= bindex)
7534 + au_set_dbend(dentry, bindex);
7535 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
7536 + au_set_dbstart(dentry, bindex);
7537 + au_set_h_dptr(dentry, bindex, h_dentry);
7539 + if (!d_is_dir(h_dentry)
7541 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7542 + goto out; /* success */
7544 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
7545 + opq = au_diropq_test(h_dentry);
7546 + mutex_unlock(&h_inode->i_mutex);
7548 + au_set_dbdiropq(dentry, bindex);
7549 + else if (unlikely(opq < 0)) {
7550 + au_set_h_dptr(dentry, bindex, NULL);
7551 + h_dentry = ERR_PTR(opq);
7562 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7564 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7565 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7571 + * returns the number of lower positive dentries,
7572 + * otherwise an error.
7573 + * can be called at unlinking with @type is zero.
7575 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type)
7577 + int npositive, err;
7578 + aufs_bindex_t bindex, btail, bdiropq;
7579 + unsigned char isdir, dirperm1;
7580 + struct qstr whname;
7581 + struct au_do_lookup_args args = {
7585 + const struct qstr *name = &dentry->d_name;
7586 + struct dentry *parent;
7587 + struct super_block *sb;
7589 + sb = dentry->d_sb;
7590 + err = au_test_shwh(sb, name);
7591 + if (unlikely(err))
7594 + err = au_wh_name_alloc(&whname, name);
7595 + if (unlikely(err))
7598 + isdir = !!d_is_dir(dentry);
7600 + au_fset_lkup(args.flags, ALLOW_NEG);
7601 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7604 + parent = dget_parent(dentry);
7605 + btail = au_dbtaildir(parent);
7606 + for (bindex = bstart; bindex <= btail; bindex++) {
7607 + struct dentry *h_parent, *h_dentry;
7608 + struct inode *h_inode, *h_dir;
7610 + h_dentry = au_h_dptr(dentry, bindex);
7612 + if (d_is_positive(h_dentry))
7614 + if (type != S_IFDIR)
7618 + h_parent = au_h_dptr(parent, bindex);
7619 + if (!h_parent || !d_is_dir(h_parent))
7622 + h_dir = d_inode(h_parent);
7623 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
7624 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7626 + mutex_unlock(&h_dir->i_mutex);
7627 + err = PTR_ERR(h_dentry);
7628 + if (IS_ERR(h_dentry))
7631 + au_fclr_lkup(args.flags, ALLOW_NEG);
7633 + au_fset_lkup(args.flags, IGNORE_PERM);
7635 + if (au_dbwh(dentry) >= 0)
7639 + if (d_is_negative(h_dentry))
7641 + h_inode = d_inode(h_dentry);
7644 + args.type = h_inode->i_mode & S_IFMT;
7645 + if (args.type != S_IFDIR)
7648 + /* the type of lower may be different */
7649 + bdiropq = au_dbdiropq(dentry);
7650 + if (bdiropq >= 0 && bdiropq <= bindex)
7656 + AuLabel(positive);
7657 + au_update_dbstart(dentry);
7660 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7661 + && au_dbstart(dentry) < 0)) {
7663 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7669 + kfree(whname.name);
7674 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7676 + struct dentry *dentry;
7679 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7680 + dentry = vfsub_lkup_one(name, parent);
7682 + struct vfsub_lkup_one_args args = {
7688 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7689 + if (unlikely(wkq_err))
7690 + dentry = ERR_PTR(wkq_err);
7697 + * lookup @dentry on @bindex which should be negative.
7699 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7702 + struct dentry *parent, *h_parent, *h_dentry;
7703 + struct au_branch *br;
7705 + parent = dget_parent(dentry);
7706 + h_parent = au_h_dptr(parent, bindex);
7707 + br = au_sbr(dentry->d_sb, bindex);
7709 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7711 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7712 + err = PTR_ERR(h_dentry);
7713 + if (IS_ERR(h_dentry))
7715 + if (unlikely(d_is_positive(h_dentry))) {
7717 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7723 + if (bindex < au_dbstart(dentry))
7724 + au_set_dbstart(dentry, bindex);
7725 + if (au_dbend(dentry) < bindex)
7726 + au_set_dbend(dentry, bindex);
7727 + au_set_h_dptr(dentry, bindex, h_dentry);
7734 +/* ---------------------------------------------------------------------- */
7736 +/* subset of struct inode */
7738 + unsigned long i_ino;
7739 + /* unsigned int i_nlink; */
7745 + blkcnt_t i_blocks;
7750 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7752 + ia->i_ino = h_inode->i_ino;
7753 + /* ia->i_nlink = h_inode->i_nlink; */
7754 + ia->i_uid = h_inode->i_uid;
7755 + ia->i_gid = h_inode->i_gid;
7756 + ia->i_version = h_inode->i_version;
7758 + ia->i_size = h_inode->i_size;
7759 + ia->i_blocks = h_inode->i_blocks;
7761 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7764 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7766 + return ia->i_ino != h_inode->i_ino
7767 + /* || ia->i_nlink != h_inode->i_nlink */
7768 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7769 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7770 + || ia->i_version != h_inode->i_version
7772 + || ia->i_size != h_inode->i_size
7773 + || ia->i_blocks != h_inode->i_blocks
7775 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7778 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7779 + struct au_branch *br)
7782 + struct au_iattr ia;
7783 + struct inode *h_inode;
7784 + struct dentry *h_d;
7785 + struct super_block *h_sb;
7788 + memset(&ia, -1, sizeof(ia));
7789 + h_sb = h_dentry->d_sb;
7791 + if (d_is_positive(h_dentry)) {
7792 + h_inode = d_inode(h_dentry);
7793 + au_iattr_save(&ia, h_inode);
7794 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7795 + /* nfs d_revalidate may return 0 for negative dentry */
7796 + /* fuse d_revalidate always return 0 for negative dentry */
7799 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7800 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7801 + err = PTR_ERR(h_d);
7806 + if (unlikely(h_d != h_dentry
7807 + || d_inode(h_d) != h_inode
7808 + || (h_inode && au_iattr_test(&ia, h_inode))))
7809 + err = au_busy_or_stale();
7817 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
7818 + struct dentry *h_parent, struct au_branch *br)
7823 + if (udba == AuOpt_UDBA_REVAL
7824 + && !au_test_fs_remote(h_dentry->d_sb)) {
7826 + err = (d_inode(h_dentry->d_parent) != h_dir);
7827 + } else if (udba != AuOpt_UDBA_NONE)
7828 + err = au_h_verify_dentry(h_dentry, h_parent, br);
7833 +/* ---------------------------------------------------------------------- */
7835 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
7838 + aufs_bindex_t new_bindex, bindex, bend, bwh, bdiropq;
7839 + struct au_hdentry tmp, *p, *q;
7840 + struct au_dinfo *dinfo;
7841 + struct super_block *sb;
7843 + DiMustWriteLock(dentry);
7845 + sb = dentry->d_sb;
7846 + dinfo = au_di(dentry);
7847 + bend = dinfo->di_bend;
7848 + bwh = dinfo->di_bwh;
7849 + bdiropq = dinfo->di_bdiropq;
7850 + p = dinfo->di_hdentry + dinfo->di_bstart;
7851 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++, p++) {
7852 + if (!p->hd_dentry)
7855 + new_bindex = au_br_index(sb, p->hd_id);
7856 + if (new_bindex == bindex)
7859 + if (dinfo->di_bwh == bindex)
7861 + if (dinfo->di_bdiropq == bindex)
7862 + bdiropq = new_bindex;
7863 + if (new_bindex < 0) {
7865 + p->hd_dentry = NULL;
7869 + /* swap two lower dentries, and loop again */
7870 + q = dinfo->di_hdentry + new_bindex;
7874 + if (tmp.hd_dentry) {
7880 + dinfo->di_bwh = -1;
7881 + if (bwh >= 0 && bwh <= au_sbend(sb) && au_sbr_whable(sb, bwh))
7882 + dinfo->di_bwh = bwh;
7884 + dinfo->di_bdiropq = -1;
7886 + && bdiropq <= au_sbend(sb)
7887 + && au_sbr_whable(sb, bdiropq))
7888 + dinfo->di_bdiropq = bdiropq;
7891 + dinfo->di_bstart = -1;
7892 + dinfo->di_bend = -1;
7893 + bend = au_dbend(parent);
7894 + p = dinfo->di_hdentry;
7895 + for (bindex = 0; bindex <= bend; bindex++, p++)
7896 + if (p->hd_dentry) {
7897 + dinfo->di_bstart = bindex;
7901 + if (dinfo->di_bstart >= 0) {
7902 + p = dinfo->di_hdentry + bend;
7903 + for (bindex = bend; bindex >= 0; bindex--, p--)
7904 + if (p->hd_dentry) {
7905 + dinfo->di_bend = bindex;
7914 +static void au_do_hide(struct dentry *dentry)
7916 + struct inode *inode;
7918 + if (d_really_is_positive(dentry)) {
7919 + inode = d_inode(dentry);
7920 + if (!d_is_dir(dentry)) {
7921 + if (inode->i_nlink && !d_unhashed(dentry))
7922 + drop_nlink(inode);
7924 + clear_nlink(inode);
7925 + /* stop next lookup */
7926 + inode->i_flags |= S_DEAD;
7928 + smp_mb(); /* necessary? */
7933 +static int au_hide_children(struct dentry *parent)
7935 + int err, i, j, ndentry;
7936 + struct au_dcsub_pages dpages;
7937 + struct au_dpage *dpage;
7938 + struct dentry *dentry;
7940 + err = au_dpages_init(&dpages, GFP_NOFS);
7941 + if (unlikely(err))
7943 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
7944 + if (unlikely(err))
7947 + /* in reverse order */
7948 + for (i = dpages.ndpage - 1; i >= 0; i--) {
7949 + dpage = dpages.dpages + i;
7950 + ndentry = dpage->ndentry;
7951 + for (j = ndentry - 1; j >= 0; j--) {
7952 + dentry = dpage->dentries[j];
7953 + if (dentry != parent)
7954 + au_do_hide(dentry);
7959 + au_dpages_free(&dpages);
7964 +static void au_hide(struct dentry *dentry)
7968 + AuDbgDentry(dentry);
7969 + if (d_is_dir(dentry)) {
7970 + /* shrink_dcache_parent(dentry); */
7971 + err = au_hide_children(dentry);
7972 + if (unlikely(err))
7973 + AuIOErr("%pd, failed hiding children, ignored %d\n",
7976 + au_do_hide(dentry);
7980 + * By adding a dirty branch, a cached dentry may be affected in various ways.
7982 + * a dirty branch is added
7983 + * - on the top of layers
7984 + * - in the middle of layers
7985 + * - to the bottom of layers
7987 + * on the added branch there exists
7990 + * - a same named entry
7992 + * * negative --> positive
7993 + * * positive --> positive
7994 + * - type is unchanged
7995 + * - type is changed
7997 + * * negative --> negative
7998 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8001 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8002 + struct au_dinfo *tmp)
8005 + aufs_bindex_t bindex, bend;
8007 + struct dentry *dentry;
8008 + struct inode *inode;
8011 + struct au_hdentry *hd;
8012 + struct inode *inode, *h_inode;
8013 + struct dentry *h_dentry;
8016 + AuDebugOn(dinfo->di_bstart < 0);
8018 + orig_h.dentry = dinfo->di_hdentry[dinfo->di_bstart].hd_dentry;
8019 + orig_h.inode = NULL;
8020 + if (d_is_positive(orig_h.dentry)) {
8021 + orig_h.inode = d_inode(orig_h.dentry);
8022 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8024 + memset(&tmp_h, 0, sizeof(tmp_h));
8025 + if (tmp->di_bstart >= 0) {
8026 + tmp_h.dentry = tmp->di_hdentry[tmp->di_bstart].hd_dentry;
8027 + tmp_h.inode = NULL;
8028 + if (d_is_positive(tmp_h.dentry)) {
8029 + tmp_h.inode = d_inode(tmp_h.dentry);
8030 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8035 + if (d_really_is_positive(dentry))
8036 + inode = d_inode(dentry);
8037 + if (!orig_h.inode) {
8038 + AuDbg("nagative originally\n");
8044 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8045 + AuDebugOn(dinfo->di_bdiropq != -1);
8047 + if (!tmp_h.inode) {
8048 + AuDbg("negative --> negative\n");
8049 + /* should have only one negative lower */
8050 + if (tmp->di_bstart >= 0
8051 + && tmp->di_bstart < dinfo->di_bstart) {
8052 + AuDebugOn(tmp->di_bstart != tmp->di_bend);
8053 + AuDebugOn(dinfo->di_bstart != dinfo->di_bend);
8054 + au_set_h_dptr(dentry, dinfo->di_bstart, NULL);
8055 + au_di_cp(dinfo, tmp);
8056 + hd = tmp->di_hdentry + tmp->di_bstart;
8057 + au_set_h_dptr(dentry, tmp->di_bstart,
8058 + dget(hd->hd_dentry));
8060 + au_dbg_verify_dinode(dentry);
8062 + AuDbg("negative --> positive\n");
8064 + * similar to the behaviour of creating with bypassing
8066 + * unhash it in order to force an error in the
8067 + * succeeding create operation.
8068 + * we should not set S_DEAD here.
8071 + /* au_di_swap(tmp, dinfo); */
8072 + au_dbg_verify_dinode(dentry);
8075 + AuDbg("positive originally\n");
8076 + /* inode may be NULL */
8077 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8078 + if (!tmp_h.inode) {
8079 + AuDbg("positive --> negative\n");
8080 + /* or bypassing aufs */
8082 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_bstart)
8083 + dinfo->di_bwh = tmp->di_bwh;
8085 + err = au_refresh_hinode_self(inode);
8086 + au_dbg_verify_dinode(dentry);
8087 + } else if (orig_h.mode == tmp_h.mode) {
8088 + AuDbg("positive --> positive, same type\n");
8089 + if (!S_ISDIR(orig_h.mode)
8090 + && dinfo->di_bstart > tmp->di_bstart) {
8092 + * similar to the behaviour of removing and
8097 + err = au_refresh_hinode_self(inode);
8098 + au_dbg_verify_dinode(dentry);
8100 + /* fill empty slots */
8101 + if (dinfo->di_bstart > tmp->di_bstart)
8102 + dinfo->di_bstart = tmp->di_bstart;
8103 + if (dinfo->di_bend < tmp->di_bend)
8104 + dinfo->di_bend = tmp->di_bend;
8105 + dinfo->di_bwh = tmp->di_bwh;
8106 + dinfo->di_bdiropq = tmp->di_bdiropq;
8107 + hd = tmp->di_hdentry;
8108 + bend = dinfo->di_bend;
8109 + for (bindex = tmp->di_bstart; bindex <= bend;
8111 + if (au_h_dptr(dentry, bindex))
8113 + h_dentry = hd[bindex].hd_dentry;
8116 + AuDebugOn(d_is_negative(h_dentry));
8117 + h_inode = d_inode(h_dentry);
8118 + AuDebugOn(orig_h.mode
8119 + != (h_inode->i_mode
8121 + au_set_h_dptr(dentry, bindex,
8124 + err = au_refresh_hinode(inode, dentry);
8125 + au_dbg_verify_dinode(dentry);
8128 + AuDbg("positive --> positive, different type\n");
8129 + /* similar to the behaviour of removing and creating */
8132 + err = au_refresh_hinode_self(inode);
8133 + au_dbg_verify_dinode(dentry);
8141 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8144 + unsigned int sigen;
8145 + struct au_dinfo *dinfo, *tmp;
8146 + struct super_block *sb;
8147 + struct inode *inode;
8149 + DiMustWriteLock(dentry);
8150 + AuDebugOn(IS_ROOT(dentry));
8151 + AuDebugOn(d_really_is_negative(parent));
8153 + sb = dentry->d_sb;
8154 + sigen = au_sigen(sb);
8155 + err = au_digen_test(parent, sigen);
8156 + if (unlikely(err))
8159 + dinfo = au_di(dentry);
8160 + err = au_di_realloc(dinfo, au_sbend(sb) + 1);
8161 + if (unlikely(err))
8163 + ebrange = au_dbrange_test(dentry);
8165 + ebrange = au_do_refresh_hdentry(dentry, parent);
8167 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8168 + AuDebugOn(au_dbstart(dentry) < 0 && au_dbend(dentry) >= 0);
8169 + if (d_really_is_positive(dentry)) {
8170 + inode = d_inode(dentry);
8171 + err = au_refresh_hinode_self(inode);
8173 + au_dbg_verify_dinode(dentry);
8175 + goto out_dgen; /* success */
8179 + /* temporary dinfo */
8180 + AuDbgDentry(dentry);
8182 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8183 + if (unlikely(!tmp))
8185 + au_di_swap(tmp, dinfo);
8186 + /* returns the number of positive dentries */
8188 + * if current working dir is removed, it returns an error.
8189 + * but the dentry is legal.
8191 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
8192 + AuDbgDentry(dentry);
8193 + au_di_swap(tmp, dinfo);
8194 + if (err == -ENOENT)
8197 + /* compare/refresh by dinfo */
8198 + AuDbgDentry(dentry);
8199 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8200 + au_dbg_verify_dinode(dentry);
8203 + au_rw_write_unlock(&tmp->di_rwsem);
8205 + if (unlikely(err))
8209 + au_update_digen(dentry);
8211 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8212 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8213 + AuDbgDentry(dentry);
8219 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8220 + struct dentry *dentry, aufs_bindex_t bindex)
8225 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8228 + AuDbg("b%d\n", bindex);
8230 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8231 + * due to whiteout and branch permission.
8233 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8234 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8235 + /* it may return tri-state */
8236 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8238 + if (unlikely(valid < 0))
8248 +/* todo: remove this */
8249 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8250 + unsigned int flags, int do_udba)
8253 + umode_t mode, h_mode;
8254 + aufs_bindex_t bindex, btail, bstart, ibs, ibe;
8255 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8256 + struct inode *h_inode, *h_cached_inode;
8257 + struct dentry *h_dentry;
8258 + struct qstr *name, *h_name;
8265 + unhashed = !!d_unhashed(dentry);
8266 + is_root = !!IS_ROOT(dentry);
8267 + name = &dentry->d_name;
8268 + tmpfile = au_di(dentry)->di_tmpfile;
8271 + * Theoretically, REVAL test should be unnecessary in case of
8273 + * But {fs,i}notify doesn't fire some necessary events,
8274 + * IN_ATTRIB for atime/nlink/pageio
8275 + * Let's do REVAL test too.
8277 + if (do_udba && inode) {
8278 + mode = (inode->i_mode & S_IFMT);
8279 + plus = (inode->i_nlink > 0);
8280 + ibs = au_ibstart(inode);
8281 + ibe = au_ibend(inode);
8284 + bstart = au_dbstart(dentry);
8286 + if (inode && S_ISDIR(inode->i_mode))
8287 + btail = au_dbtaildir(dentry);
8288 + for (bindex = bstart; bindex <= btail; bindex++) {
8289 + h_dentry = au_h_dptr(dentry, bindex);
8293 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8294 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8295 + spin_lock(&h_dentry->d_lock);
8296 + h_name = &h_dentry->d_name;
8297 + if (unlikely(do_udba
8300 + && (unhashed != !!d_unhashed(h_dentry)
8302 + && !au_qstreq(name, h_name))
8305 + && !(flags & LOOKUP_OPEN)
8306 + && (h_dentry->d_flags
8307 + & DCACHE_NFSFS_RENAMED)))
8311 + h_unhashed = d_unhashed(h_dentry);
8312 + spin_unlock(&h_dentry->d_lock);
8313 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8314 + unhashed, h_unhashed, dentry, h_dentry);
8317 + spin_unlock(&h_dentry->d_lock);
8319 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8320 + if (unlikely(err))
8321 + /* do not goto err, to keep the errno */
8324 + /* todo: plink too? */
8329 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8333 + if (d_is_positive(h_dentry))
8334 + h_inode = d_inode(h_dentry);
8337 + h_cached_inode = h_inode;
8339 + h_mode = (h_inode->i_mode & S_IFMT);
8340 + h_plus = (h_inode->i_nlink > 0);
8342 + if (inode && ibs <= bindex && bindex <= ibe)
8343 + h_cached_inode = au_h_iptr(inode, bindex);
8346 + if (unlikely(plus != h_plus && !tmpfile))
8349 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8351 + && !IS_ROOT(h_dentry)
8352 + && unhashed != d_unhashed(h_dentry)))
8355 + if (unlikely(mode != h_mode
8356 + || h_cached_inode != h_inode))
8369 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8370 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8373 + struct dentry *parent;
8375 + if (!au_digen_test(dentry, sigen))
8378 + parent = dget_parent(dentry);
8379 + di_read_lock_parent(parent, AuLock_IR);
8380 + AuDebugOn(au_digen_test(parent, sigen));
8381 + au_dbg_verify_gen(parent, sigen);
8382 + err = au_refresh_dentry(dentry, parent);
8383 + di_read_unlock(parent, AuLock_IR);
8389 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8392 + struct dentry *d, *parent;
8394 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8395 + return simple_reval_dpath(dentry, sigen);
8397 + /* slow loop, keep it simple and stupid */
8398 + /* cf: au_cpup_dirs() */
8401 + while (au_digen_test(dentry, sigen)) {
8405 + parent = dget_parent(d);
8406 + if (!au_digen_test(parent, sigen))
8412 + di_write_lock_child2(d);
8414 + /* someone might update our dentry while we were sleeping */
8415 + if (au_digen_test(d, sigen)) {
8417 + * todo: consolidate with simple_reval_dpath(),
8418 + * do_refresh() and au_reval_for_attr().
8420 + di_read_lock_parent(parent, AuLock_IR);
8421 + err = au_refresh_dentry(d, parent);
8422 + di_read_unlock(parent, AuLock_IR);
8426 + di_write_unlock(d);
8428 + if (unlikely(err))
8436 + * if valid returns 1, otherwise 0.
8438 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8441 + unsigned int sigen;
8442 + unsigned char do_udba;
8443 + struct super_block *sb;
8444 + struct inode *inode;
8446 + /* todo: support rcu-walk? */
8447 + if (flags & LOOKUP_RCU)
8451 + if (unlikely(!au_di(dentry)))
8455 + sb = dentry->d_sb;
8458 + * i_mutex of parent dir may be held,
8459 + * but we should not return 'invalid' due to busy.
8461 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8462 + if (unlikely(err)) {
8468 + if (d_really_is_positive(dentry))
8469 + inode = d_inode(dentry);
8470 + if (unlikely(inode && is_bad_inode(inode))) {
8475 + if (unlikely(au_dbrange_test(dentry))) {
8481 + sigen = au_sigen(sb);
8482 + if (au_digen_test(dentry, sigen)) {
8483 + AuDebugOn(IS_ROOT(dentry));
8484 + err = au_reval_dpath(dentry, sigen);
8485 + if (unlikely(err)) {
8490 + di_downgrade_lock(dentry, AuLock_IR);
8493 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8495 + && !(inode->i_state && I_LINKABLE)
8496 + && (IS_DEADDIR(inode) || !inode->i_nlink))
8499 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8500 + if (do_udba && inode) {
8501 + aufs_bindex_t bstart = au_ibstart(inode);
8502 + struct inode *h_inode;
8504 + if (bstart >= 0) {
8505 + h_inode = au_h_iptr(inode, bstart);
8506 + if (h_inode && au_test_higen(inode, h_inode))
8511 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8512 + if (unlikely(!err && do_udba && au_dbstart(dentry) < 0)) {
8514 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8520 + di_downgrade_lock(dentry, AuLock_IR);
8522 + aufs_read_unlock(dentry, AuLock_IR);
8527 + AuDbg("%pd invalid, %d\n", dentry, valid);
8533 +static void aufs_d_release(struct dentry *dentry)
8535 + if (au_di(dentry)) {
8536 + au_di_fin(dentry);
8537 + au_hn_di_reinit(dentry);
8541 +const struct dentry_operations aufs_dop = {
8542 + .d_revalidate = aufs_d_revalidate,
8543 + .d_weak_revalidate = aufs_d_revalidate,
8544 + .d_release = aufs_d_release
8546 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8547 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8548 +++ linux/fs/aufs/dentry.h 2015-09-24 10:47:58.251386326 +0200
8551 + * Copyright (C) 2005-2015 Junjiro R. Okajima
8553 + * This program, aufs is free software; you can redistribute it and/or modify
8554 + * it under the terms of the GNU General Public License as published by
8555 + * the Free Software Foundation; either version 2 of the License, or
8556 + * (at your option) any later version.
8558 + * This program is distributed in the hope that it will be useful,
8559 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8560 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8561 + * GNU General Public License for more details.
8563 + * You should have received a copy of the GNU General Public License
8564 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8568 + * lookup and dentry operations
8571 +#ifndef __AUFS_DENTRY_H__
8572 +#define __AUFS_DENTRY_H__
8576 +#include <linux/dcache.h>
8579 +struct au_hdentry {
8580 + struct dentry *hd_dentry;
8581 + aufs_bindex_t hd_id;
8585 + atomic_t di_generation;
8587 + struct au_rwsem di_rwsem;
8588 + aufs_bindex_t di_bstart, di_bend, di_bwh, di_bdiropq;
8589 + unsigned char di_tmpfile; /* to allow the different name */
8590 + struct au_hdentry *di_hdentry;
8591 +} ____cacheline_aligned_in_smp;
8593 +/* ---------------------------------------------------------------------- */
8596 +extern const struct dentry_operations aufs_dop;
8598 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8599 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8600 + struct dentry *h_parent, struct au_branch *br);
8602 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t bstart, mode_t type);
8603 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8604 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8605 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8608 +void au_di_init_once(void *_di);
8609 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8610 +void au_di_free(struct au_dinfo *dinfo);
8611 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8612 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8613 +int au_di_init(struct dentry *dentry);
8614 +void au_di_fin(struct dentry *dentry);
8615 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8617 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8618 +void di_read_unlock(struct dentry *d, int flags);
8619 +void di_downgrade_lock(struct dentry *d, int flags);
8620 +void di_write_lock(struct dentry *d, unsigned int lsc);
8621 +void di_write_unlock(struct dentry *d);
8622 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8623 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8624 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8626 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8627 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8628 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8629 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8631 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8632 + struct dentry *h_dentry);
8633 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8634 +int au_dbrange_test(struct dentry *dentry);
8635 +void au_update_digen(struct dentry *dentry);
8636 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8637 +void au_update_dbstart(struct dentry *dentry);
8638 +void au_update_dbend(struct dentry *dentry);
8639 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8641 +/* ---------------------------------------------------------------------- */
8643 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8645 + return dentry->d_fsdata;
8648 +/* ---------------------------------------------------------------------- */
8650 +/* lock subclass for dinfo */
8652 + AuLsc_DI_CHILD, /* child first */
8653 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8654 + AuLsc_DI_CHILD3, /* copyup dirs */
8658 + AuLsc_DI_TMP /* temp for replacing dinfo */
8662 + * di_read_lock_child, di_write_lock_child,
8663 + * di_read_lock_child2, di_write_lock_child2,
8664 + * di_read_lock_child3, di_write_lock_child3,
8665 + * di_read_lock_parent, di_write_lock_parent,
8666 + * di_read_lock_parent2, di_write_lock_parent2,
8667 + * di_read_lock_parent3, di_write_lock_parent3,
8669 +#define AuReadLockFunc(name, lsc) \
8670 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8671 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8673 +#define AuWriteLockFunc(name, lsc) \
8674 +static inline void di_write_lock_##name(struct dentry *d) \
8675 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8677 +#define AuRWLockFuncs(name, lsc) \
8678 + AuReadLockFunc(name, lsc) \
8679 + AuWriteLockFunc(name, lsc)
8681 +AuRWLockFuncs(child, CHILD);
8682 +AuRWLockFuncs(child2, CHILD2);
8683 +AuRWLockFuncs(child3, CHILD3);
8684 +AuRWLockFuncs(parent, PARENT);
8685 +AuRWLockFuncs(parent2, PARENT2);
8686 +AuRWLockFuncs(parent3, PARENT3);
8688 +#undef AuReadLockFunc
8689 +#undef AuWriteLockFunc
8690 +#undef AuRWLockFuncs
8692 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8693 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8694 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8696 +/* ---------------------------------------------------------------------- */
8698 +/* todo: memory barrier? */
8699 +static inline unsigned int au_digen(struct dentry *d)
8701 + return atomic_read(&au_di(d)->di_generation);
8704 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8706 + hdentry->hd_dentry = NULL;
8709 +static inline void au_hdput(struct au_hdentry *hd)
8712 + dput(hd->hd_dentry);
8715 +static inline aufs_bindex_t au_dbstart(struct dentry *dentry)
8717 + DiMustAnyLock(dentry);
8718 + return au_di(dentry)->di_bstart;
8721 +static inline aufs_bindex_t au_dbend(struct dentry *dentry)
8723 + DiMustAnyLock(dentry);
8724 + return au_di(dentry)->di_bend;
8727 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8729 + DiMustAnyLock(dentry);
8730 + return au_di(dentry)->di_bwh;
8733 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8735 + DiMustAnyLock(dentry);
8736 + return au_di(dentry)->di_bdiropq;
8739 +/* todo: hard/soft set? */
8740 +static inline void au_set_dbstart(struct dentry *dentry, aufs_bindex_t bindex)
8742 + DiMustWriteLock(dentry);
8743 + au_di(dentry)->di_bstart = bindex;
8746 +static inline void au_set_dbend(struct dentry *dentry, aufs_bindex_t bindex)
8748 + DiMustWriteLock(dentry);
8749 + au_di(dentry)->di_bend = bindex;
8752 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
8754 + DiMustWriteLock(dentry);
8755 + /* dbwh can be outside of bstart - bend range */
8756 + au_di(dentry)->di_bwh = bindex;
8759 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
8761 + DiMustWriteLock(dentry);
8762 + au_di(dentry)->di_bdiropq = bindex;
8765 +/* ---------------------------------------------------------------------- */
8767 +#ifdef CONFIG_AUFS_HNOTIFY
8768 +static inline void au_digen_dec(struct dentry *d)
8770 + atomic_dec(&au_di(d)->di_generation);
8773 +static inline void au_hn_di_reinit(struct dentry *dentry)
8775 + dentry->d_fsdata = NULL;
8778 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
8779 +#endif /* CONFIG_AUFS_HNOTIFY */
8781 +#endif /* __KERNEL__ */
8782 +#endif /* __AUFS_DENTRY_H__ */
8783 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
8784 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
8785 +++ linux/fs/aufs/dinfo.c 2015-09-24 10:47:58.251386326 +0200
8788 + * Copyright (C) 2005-2015 Junjiro R. Okajima
8790 + * This program, aufs is free software; you can redistribute it and/or modify
8791 + * it under the terms of the GNU General Public License as published by
8792 + * the Free Software Foundation; either version 2 of the License, or
8793 + * (at your option) any later version.
8795 + * This program is distributed in the hope that it will be useful,
8796 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8797 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8798 + * GNU General Public License for more details.
8800 + * You should have received a copy of the GNU General Public License
8801 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8805 + * dentry private data
8810 +void au_di_init_once(void *_dinfo)
8812 + struct au_dinfo *dinfo = _dinfo;
8813 + static struct lock_class_key aufs_di;
8815 + au_rw_init(&dinfo->di_rwsem);
8816 + au_rw_class(&dinfo->di_rwsem, &aufs_di);
8819 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
8821 + struct au_dinfo *dinfo;
8824 + dinfo = au_cache_alloc_dinfo();
8825 + if (unlikely(!dinfo))
8828 + nbr = au_sbend(sb) + 1;
8831 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
8832 + if (dinfo->di_hdentry) {
8833 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
8834 + dinfo->di_bstart = -1;
8835 + dinfo->di_bend = -1;
8836 + dinfo->di_bwh = -1;
8837 + dinfo->di_bdiropq = -1;
8838 + dinfo->di_tmpfile = 0;
8839 + for (i = 0; i < nbr; i++)
8840 + dinfo->di_hdentry[i].hd_id = -1;
8844 + au_cache_free_dinfo(dinfo);
8851 +void au_di_free(struct au_dinfo *dinfo)
8853 + struct au_hdentry *p;
8854 + aufs_bindex_t bend, bindex;
8856 + /* dentry may not be revalidated */
8857 + bindex = dinfo->di_bstart;
8858 + if (bindex >= 0) {
8859 + bend = dinfo->di_bend;
8860 + p = dinfo->di_hdentry + bindex;
8861 + while (bindex++ <= bend)
8864 + kfree(dinfo->di_hdentry);
8865 + au_cache_free_dinfo(dinfo);
8868 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
8870 + struct au_hdentry *p;
8873 + AuRwMustWriteLock(&a->di_rwsem);
8874 + AuRwMustWriteLock(&b->di_rwsem);
8876 +#define DiSwap(v, name) \
8878 + v = a->di_##name; \
8879 + a->di_##name = b->di_##name; \
8880 + b->di_##name = v; \
8883 + DiSwap(p, hdentry);
8884 + DiSwap(bi, bstart);
8887 + DiSwap(bi, bdiropq);
8893 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
8895 + AuRwMustWriteLock(&dst->di_rwsem);
8896 + AuRwMustWriteLock(&src->di_rwsem);
8898 + dst->di_bstart = src->di_bstart;
8899 + dst->di_bend = src->di_bend;
8900 + dst->di_bwh = src->di_bwh;
8901 + dst->di_bdiropq = src->di_bdiropq;
8905 +int au_di_init(struct dentry *dentry)
8908 + struct super_block *sb;
8909 + struct au_dinfo *dinfo;
8912 + sb = dentry->d_sb;
8913 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
8915 + atomic_set(&dinfo->di_generation, au_sigen(sb));
8916 + /* smp_mb(); */ /* atomic_set */
8917 + dentry->d_fsdata = dinfo;
8924 +void au_di_fin(struct dentry *dentry)
8926 + struct au_dinfo *dinfo;
8928 + dinfo = au_di(dentry);
8929 + AuRwDestroy(&dinfo->di_rwsem);
8930 + au_di_free(dinfo);
8933 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
8936 + struct au_hdentry *hdp;
8938 + AuRwMustWriteLock(&dinfo->di_rwsem);
8941 + sz = sizeof(*hdp) * (dinfo->di_bend + 1);
8943 + sz = sizeof(*hdp);
8944 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
8946 + dinfo->di_hdentry = hdp;
8953 +/* ---------------------------------------------------------------------- */
8955 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
8958 + case AuLsc_DI_CHILD:
8959 + ii_write_lock_child(inode);
8961 + case AuLsc_DI_CHILD2:
8962 + ii_write_lock_child2(inode);
8964 + case AuLsc_DI_CHILD3:
8965 + ii_write_lock_child3(inode);
8967 + case AuLsc_DI_PARENT:
8968 + ii_write_lock_parent(inode);
8970 + case AuLsc_DI_PARENT2:
8971 + ii_write_lock_parent2(inode);
8973 + case AuLsc_DI_PARENT3:
8974 + ii_write_lock_parent3(inode);
8981 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
8984 + case AuLsc_DI_CHILD:
8985 + ii_read_lock_child(inode);
8987 + case AuLsc_DI_CHILD2:
8988 + ii_read_lock_child2(inode);
8990 + case AuLsc_DI_CHILD3:
8991 + ii_read_lock_child3(inode);
8993 + case AuLsc_DI_PARENT:
8994 + ii_read_lock_parent(inode);
8996 + case AuLsc_DI_PARENT2:
8997 + ii_read_lock_parent2(inode);
8999 + case AuLsc_DI_PARENT3:
9000 + ii_read_lock_parent3(inode);
9007 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9009 + struct inode *inode;
9011 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9012 + if (d_really_is_positive(d)) {
9013 + inode = d_inode(d);
9014 + if (au_ftest_lock(flags, IW))
9015 + do_ii_write_lock(inode, lsc);
9016 + else if (au_ftest_lock(flags, IR))
9017 + do_ii_read_lock(inode, lsc);
9021 +void di_read_unlock(struct dentry *d, int flags)
9023 + struct inode *inode;
9025 + if (d_really_is_positive(d)) {
9026 + inode = d_inode(d);
9027 + if (au_ftest_lock(flags, IW)) {
9028 + au_dbg_verify_dinode(d);
9029 + ii_write_unlock(inode);
9030 + } else if (au_ftest_lock(flags, IR)) {
9031 + au_dbg_verify_dinode(d);
9032 + ii_read_unlock(inode);
9035 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9038 +void di_downgrade_lock(struct dentry *d, int flags)
9040 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9041 + ii_downgrade_lock(d_inode(d));
9042 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9045 +void di_write_lock(struct dentry *d, unsigned int lsc)
9047 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9048 + if (d_really_is_positive(d))
9049 + do_ii_write_lock(d_inode(d), lsc);
9052 +void di_write_unlock(struct dentry *d)
9054 + au_dbg_verify_dinode(d);
9055 + if (d_really_is_positive(d))
9056 + ii_write_unlock(d_inode(d));
9057 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9060 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9062 + AuDebugOn(d1 == d2
9063 + || d_inode(d1) == d_inode(d2)
9064 + || d1->d_sb != d2->d_sb);
9066 + if (isdir && au_test_subdir(d1, d2)) {
9067 + di_write_lock_child(d1);
9068 + di_write_lock_child2(d2);
9070 + /* there should be no races */
9071 + di_write_lock_child(d2);
9072 + di_write_lock_child2(d1);
9076 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9078 + AuDebugOn(d1 == d2
9079 + || d_inode(d1) == d_inode(d2)
9080 + || d1->d_sb != d2->d_sb);
9082 + if (isdir && au_test_subdir(d1, d2)) {
9083 + di_write_lock_parent(d1);
9084 + di_write_lock_parent2(d2);
9086 + /* there should be no races */
9087 + di_write_lock_parent(d2);
9088 + di_write_lock_parent2(d1);
9092 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9094 + di_write_unlock(d1);
9095 + if (d_inode(d1) == d_inode(d2))
9096 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9098 + di_write_unlock(d2);
9101 +/* ---------------------------------------------------------------------- */
9103 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9107 + DiMustAnyLock(dentry);
9109 + if (au_dbstart(dentry) < 0 || bindex < au_dbstart(dentry))
9111 + AuDebugOn(bindex < 0);
9112 + d = au_di(dentry)->di_hdentry[0 + bindex].hd_dentry;
9113 + AuDebugOn(d && au_dcount(d) <= 0);
9118 + * extended version of au_h_dptr().
9119 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9122 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9124 + struct dentry *h_dentry;
9125 + struct inode *inode, *h_inode;
9127 + AuDebugOn(d_really_is_negative(dentry));
9130 + if (au_dbstart(dentry) <= bindex
9131 + && bindex <= au_dbend(dentry))
9132 + h_dentry = au_h_dptr(dentry, bindex);
9133 + if (h_dentry && !au_d_linkable(h_dentry)) {
9135 + goto out; /* success */
9138 + inode = d_inode(dentry);
9139 + AuDebugOn(bindex < au_ibstart(inode));
9140 + AuDebugOn(au_ibend(inode) < bindex);
9141 + h_inode = au_h_iptr(inode, bindex);
9142 + h_dentry = d_find_alias(h_inode);
9144 + if (!IS_ERR(h_dentry)) {
9145 + if (!au_d_linkable(h_dentry))
9146 + goto out; /* success */
9152 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9153 + h_dentry = au_plink_lkup(inode, bindex);
9154 + AuDebugOn(!h_dentry);
9155 + if (!IS_ERR(h_dentry)) {
9156 + if (!au_d_hashed_positive(h_dentry))
9157 + goto out; /* success */
9164 + AuDbgDentry(h_dentry);
9168 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9170 + aufs_bindex_t bend, bwh;
9172 + bend = au_dbend(dentry);
9174 + bwh = au_dbwh(dentry);
9177 + if (0 < bwh && bwh < bend)
9183 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9185 + aufs_bindex_t bend, bopq;
9187 + bend = au_dbtail(dentry);
9189 + bopq = au_dbdiropq(dentry);
9190 + if (0 <= bopq && bopq < bend)
9196 +/* ---------------------------------------------------------------------- */
9198 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9199 + struct dentry *h_dentry)
9201 + struct au_hdentry *hd = au_di(dentry)->di_hdentry + bindex;
9202 + struct au_branch *br;
9204 + DiMustWriteLock(dentry);
9207 + hd->hd_dentry = h_dentry;
9209 + br = au_sbr(dentry->d_sb, bindex);
9210 + hd->hd_id = br->br_id;
9214 +int au_dbrange_test(struct dentry *dentry)
9217 + aufs_bindex_t bstart, bend;
9220 + bstart = au_dbstart(dentry);
9221 + bend = au_dbend(dentry);
9223 + AuDebugOn(bend < 0 && bstart > bend);
9226 + AuDebugOn(bend >= 0);
9232 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9237 + if (unlikely(au_digen(dentry) != sigen
9238 + || au_iigen_test(d_inode(dentry), sigen)))
9244 +void au_update_digen(struct dentry *dentry)
9246 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9247 + /* smp_mb(); */ /* atomic_set */
9250 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9252 + struct au_dinfo *dinfo;
9253 + struct dentry *h_d;
9254 + struct au_hdentry *hdp;
9256 + DiMustWriteLock(dentry);
9258 + dinfo = au_di(dentry);
9259 + if (!dinfo || dinfo->di_bstart < 0)
9262 + hdp = dinfo->di_hdentry;
9263 + if (do_put_zero) {
9264 + aufs_bindex_t bindex, bend;
9266 + bend = dinfo->di_bend;
9267 + for (bindex = dinfo->di_bstart; bindex <= bend; bindex++) {
9268 + h_d = hdp[0 + bindex].hd_dentry;
9269 + if (h_d && d_is_negative(h_d))
9270 + au_set_h_dptr(dentry, bindex, NULL);
9274 + dinfo->di_bstart = -1;
9275 + while (++dinfo->di_bstart <= dinfo->di_bend)
9276 + if (hdp[0 + dinfo->di_bstart].hd_dentry)
9278 + if (dinfo->di_bstart > dinfo->di_bend) {
9279 + dinfo->di_bstart = -1;
9280 + dinfo->di_bend = -1;
9285 + while (0 <= --dinfo->di_bend)
9286 + if (hdp[0 + dinfo->di_bend].hd_dentry)
9288 + AuDebugOn(dinfo->di_bstart > dinfo->di_bend || dinfo->di_bend < 0);
9291 +void au_update_dbstart(struct dentry *dentry)
9293 + aufs_bindex_t bindex, bend;
9294 + struct dentry *h_dentry;
9296 + bend = au_dbend(dentry);
9297 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
9298 + h_dentry = au_h_dptr(dentry, bindex);
9301 + if (d_is_positive(h_dentry)) {
9302 + au_set_dbstart(dentry, bindex);
9305 + au_set_h_dptr(dentry, bindex, NULL);
9309 +void au_update_dbend(struct dentry *dentry)
9311 + aufs_bindex_t bindex, bstart;
9312 + struct dentry *h_dentry;
9314 + bstart = au_dbstart(dentry);
9315 + for (bindex = au_dbend(dentry); bindex >= bstart; bindex--) {
9316 + h_dentry = au_h_dptr(dentry, bindex);
9319 + if (d_is_positive(h_dentry)) {
9320 + au_set_dbend(dentry, bindex);
9323 + au_set_h_dptr(dentry, bindex, NULL);
9327 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9329 + aufs_bindex_t bindex, bend;
9331 + bend = au_dbend(dentry);
9332 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++)
9333 + if (au_h_dptr(dentry, bindex) == h_dentry)
9337 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9338 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9339 +++ linux/fs/aufs/dir.c 2015-09-24 10:47:58.251386326 +0200
9342 + * Copyright (C) 2005-2015 Junjiro R. Okajima
9344 + * This program, aufs is free software; you can redistribute it and/or modify
9345 + * it under the terms of the GNU General Public License as published by
9346 + * the Free Software Foundation; either version 2 of the License, or
9347 + * (at your option) any later version.
9349 + * This program is distributed in the hope that it will be useful,
9350 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9351 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9352 + * GNU General Public License for more details.
9354 + * You should have received a copy of the GNU General Public License
9355 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9359 + * directory operations
9362 +#include <linux/fs_stack.h>
9365 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9367 + unsigned int nlink;
9369 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9371 + nlink = dir->i_nlink;
9372 + nlink += h_dir->i_nlink - 2;
9373 + if (h_dir->i_nlink < 2)
9375 + smp_mb(); /* for i_nlink */
9376 + /* 0 can happen in revaliding */
9377 + set_nlink(dir, nlink);
9380 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9382 + unsigned int nlink;
9384 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9386 + nlink = dir->i_nlink;
9387 + nlink -= h_dir->i_nlink - 2;
9388 + if (h_dir->i_nlink < 2)
9390 + smp_mb(); /* for i_nlink */
9391 + /* nlink == 0 means the branch-fs is broken */
9392 + set_nlink(dir, nlink);
9395 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9398 + aufs_bindex_t bindex, bend;
9399 + struct file *h_file;
9400 + struct dentry *h_dentry;
9404 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9406 + bend = au_fbend_dir(file);
9407 + for (bindex = au_fbstart(file);
9408 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9410 + h_file = au_hf_dir(file, bindex);
9411 + if (h_file && file_inode(h_file))
9412 + sz += vfsub_f_size_read(h_file);
9415 + AuDebugOn(!dentry);
9416 + AuDebugOn(!d_is_dir(dentry));
9418 + bend = au_dbtaildir(dentry);
9419 + for (bindex = au_dbstart(dentry);
9420 + bindex <= bend && sz < KMALLOC_MAX_SIZE;
9422 + h_dentry = au_h_dptr(dentry, bindex);
9423 + if (h_dentry && d_is_positive(h_dentry))
9424 + sz += i_size_read(d_inode(h_dentry));
9427 + if (sz < KMALLOC_MAX_SIZE)
9428 + sz = roundup_pow_of_two(sz);
9429 + if (sz > KMALLOC_MAX_SIZE)
9430 + sz = KMALLOC_MAX_SIZE;
9431 + else if (sz < NAME_MAX) {
9432 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9433 + sz = AUFS_RDBLK_DEF;
9438 +struct au_dir_ts_arg {
9439 + struct dentry *dentry;
9440 + aufs_bindex_t brid;
9443 +static void au_do_dir_ts(void *arg)
9445 + struct au_dir_ts_arg *a = arg;
9446 + struct au_dtime dt;
9447 + struct path h_path;
9448 + struct inode *dir, *h_dir;
9449 + struct super_block *sb;
9450 + struct au_branch *br;
9451 + struct au_hinode *hdir;
9453 + aufs_bindex_t bstart, bindex;
9455 + sb = a->dentry->d_sb;
9456 + if (d_really_is_negative(a->dentry))
9458 + aufs_read_lock(a->dentry, AuLock_DW | AuLock_DIR); /* noflush */
9460 + /* no dir->i_mutex lock */
9461 + dir = d_inode(a->dentry);
9462 + bstart = au_ibstart(dir);
9463 + bindex = au_br_index(sb, a->brid);
9464 + if (bindex < bstart)
9467 + br = au_sbr(sb, bindex);
9468 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9469 + if (!h_path.dentry)
9471 + h_path.mnt = au_br_mnt(br);
9472 + au_dtime_store(&dt, a->dentry, &h_path);
9474 + br = au_sbr(sb, bstart);
9475 + if (!au_br_writable(br->br_perm))
9477 + h_path.dentry = au_h_dptr(a->dentry, bstart);
9478 + h_path.mnt = au_br_mnt(br);
9479 + err = vfsub_mnt_want_write(h_path.mnt);
9482 + hdir = au_hi(dir, bstart);
9483 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
9484 + h_dir = au_h_iptr(dir, bstart);
9485 + if (h_dir->i_nlink
9486 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9487 + dt.dt_h_path = h_path;
9488 + au_dtime_revert(&dt);
9490 + au_hn_imtx_unlock(hdir);
9491 + vfsub_mnt_drop_write(h_path.mnt);
9492 + au_cpup_attr_timesizes(dir);
9495 + aufs_read_unlock(a->dentry, AuLock_DW);
9498 + au_nwt_done(&au_sbi(sb)->si_nowait);
9502 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9504 + int perm, wkq_err;
9505 + aufs_bindex_t bstart;
9506 + struct au_dir_ts_arg *arg;
9507 + struct dentry *dentry;
9508 + struct super_block *sb;
9512 + dentry = d_find_any_alias(dir);
9513 + AuDebugOn(!dentry);
9514 + sb = dentry->d_sb;
9515 + bstart = au_ibstart(dir);
9516 + if (bstart == bindex) {
9517 + au_cpup_attr_timesizes(dir);
9521 + perm = au_sbr_perm(sb, bstart);
9522 + if (!au_br_writable(perm))
9525 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9529 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9530 + arg->brid = au_sbr_id(sb, bindex);
9531 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9532 + if (unlikely(wkq_err)) {
9533 + pr_err("wkq %d\n", wkq_err);
9542 +/* ---------------------------------------------------------------------- */
9544 +static int reopen_dir(struct file *file)
9547 + unsigned int flags;
9548 + aufs_bindex_t bindex, btail, bstart;
9549 + struct dentry *dentry, *h_dentry;
9550 + struct file *h_file;
9552 + /* open all lower dirs */
9553 + dentry = file->f_path.dentry;
9554 + bstart = au_dbstart(dentry);
9555 + for (bindex = au_fbstart(file); bindex < bstart; bindex++)
9556 + au_set_h_fptr(file, bindex, NULL);
9557 + au_set_fbstart(file, bstart);
9559 + btail = au_dbtaildir(dentry);
9560 + for (bindex = au_fbend_dir(file); btail < bindex; bindex--)
9561 + au_set_h_fptr(file, bindex, NULL);
9562 + au_set_fbend_dir(file, btail);
9564 + flags = vfsub_file_flags(file);
9565 + for (bindex = bstart; bindex <= btail; bindex++) {
9566 + h_dentry = au_h_dptr(dentry, bindex);
9569 + h_file = au_hf_dir(file, bindex);
9573 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9574 + err = PTR_ERR(h_file);
9575 + if (IS_ERR(h_file))
9576 + goto out; /* close all? */
9577 + au_set_h_fptr(file, bindex, h_file);
9579 + au_update_figen(file);
9580 + /* todo: necessary? */
9581 + /* file->f_ra = h_file->f_ra; */
9588 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9591 + aufs_bindex_t bindex, btail;
9592 + struct dentry *dentry, *h_dentry;
9594 + FiMustWriteLock(file);
9595 + AuDebugOn(h_file);
9598 + dentry = file->f_path.dentry;
9599 + file->f_version = d_inode(dentry)->i_version;
9600 + bindex = au_dbstart(dentry);
9601 + au_set_fbstart(file, bindex);
9602 + btail = au_dbtaildir(dentry);
9603 + au_set_fbend_dir(file, btail);
9604 + for (; !err && bindex <= btail; bindex++) {
9605 + h_dentry = au_h_dptr(dentry, bindex);
9609 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9610 + if (IS_ERR(h_file)) {
9611 + err = PTR_ERR(h_file);
9614 + au_set_h_fptr(file, bindex, h_file);
9616 + au_update_figen(file);
9617 + /* todo: necessary? */
9618 + /* file->f_ra = h_file->f_ra; */
9620 + return 0; /* success */
9623 + for (bindex = au_fbstart(file); bindex <= btail; bindex++)
9624 + au_set_h_fptr(file, bindex, NULL);
9625 + au_set_fbstart(file, -1);
9626 + au_set_fbend_dir(file, -1);
9631 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9632 + struct file *file)
9635 + struct super_block *sb;
9636 + struct au_fidir *fidir;
9639 + sb = file->f_path.dentry->d_sb;
9640 + si_read_lock(sb, AuLock_FLUSH);
9641 + fidir = au_fidir_alloc(sb);
9643 + struct au_do_open_args args = {
9644 + .open = do_open_dir,
9647 + err = au_do_open(file, &args);
9648 + if (unlikely(err))
9651 + si_read_unlock(sb);
9655 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9656 + struct file *file)
9658 + struct au_vdir *vdir_cache;
9659 + struct au_finfo *finfo;
9660 + struct au_fidir *fidir;
9661 + aufs_bindex_t bindex, bend;
9663 + finfo = au_fi(file);
9664 + fidir = finfo->fi_hdir;
9666 + au_sphl_del(&finfo->fi_hlist,
9667 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9668 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9670 + au_vdir_free(vdir_cache);
9672 + bindex = finfo->fi_btop;
9673 + if (bindex >= 0) {
9675 + * calls fput() instead of filp_close(),
9676 + * since no dnotify or lock for the lower file.
9678 + bend = fidir->fd_bbot;
9679 + for (; bindex <= bend; bindex++)
9680 + au_set_h_fptr(file, bindex, NULL);
9683 + finfo->fi_hdir = NULL;
9685 + au_finfo_fin(file);
9689 +/* ---------------------------------------------------------------------- */
9691 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9694 + aufs_bindex_t bindex, bend;
9695 + struct file *h_file;
9698 + bend = au_fbend_dir(file);
9699 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9700 + h_file = au_hf_dir(file, bindex);
9702 + err = vfsub_flush(h_file, id);
9707 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9709 + return au_do_flush(file, id, au_do_flush_dir);
9712 +/* ---------------------------------------------------------------------- */
9714 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9717 + aufs_bindex_t bend, bindex;
9718 + struct inode *inode;
9719 + struct super_block *sb;
9722 + sb = dentry->d_sb;
9723 + inode = d_inode(dentry);
9725 + bend = au_dbend(dentry);
9726 + for (bindex = au_dbstart(dentry); !err && bindex <= bend; bindex++) {
9727 + struct path h_path;
9729 + if (au_test_ro(sb, bindex, inode))
9731 + h_path.dentry = au_h_dptr(dentry, bindex);
9732 + if (!h_path.dentry)
9735 + h_path.mnt = au_sbr_mnt(sb, bindex);
9736 + err = vfsub_fsync(NULL, &h_path, datasync);
9742 +static int au_do_fsync_dir(struct file *file, int datasync)
9745 + aufs_bindex_t bend, bindex;
9746 + struct file *h_file;
9747 + struct super_block *sb;
9748 + struct inode *inode;
9750 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9751 + if (unlikely(err))
9754 + inode = file_inode(file);
9756 + bend = au_fbend_dir(file);
9757 + for (bindex = au_fbstart(file); !err && bindex <= bend; bindex++) {
9758 + h_file = au_hf_dir(file, bindex);
9759 + if (!h_file || au_test_ro(sb, bindex, inode))
9762 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
9770 + * @file may be NULL
9772 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
9776 + struct dentry *dentry;
9777 + struct inode *inode;
9778 + struct super_block *sb;
9779 + struct mutex *mtx;
9782 + dentry = file->f_path.dentry;
9783 + inode = d_inode(dentry);
9784 + mtx = &inode->i_mutex;
9786 + sb = dentry->d_sb;
9787 + si_noflush_read_lock(sb);
9789 + err = au_do_fsync_dir(file, datasync);
9791 + di_write_lock_child(dentry);
9792 + err = au_do_fsync_dir_no_file(dentry, datasync);
9794 + au_cpup_attr_timesizes(inode);
9795 + di_write_unlock(dentry);
9797 + fi_write_unlock(file);
9799 + si_read_unlock(sb);
9800 + mutex_unlock(mtx);
9804 +/* ---------------------------------------------------------------------- */
9806 +static int aufs_iterate(struct file *file, struct dir_context *ctx)
9809 + struct dentry *dentry;
9810 + struct inode *inode, *h_inode;
9811 + struct super_block *sb;
9813 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
9815 + dentry = file->f_path.dentry;
9816 + inode = d_inode(dentry);
9819 + sb = dentry->d_sb;
9820 + si_read_lock(sb, AuLock_FLUSH);
9821 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
9822 + if (unlikely(err))
9824 + err = au_alive_dir(dentry);
9826 + err = au_vdir_init(file);
9827 + di_downgrade_lock(dentry, AuLock_IR);
9828 + if (unlikely(err))
9831 + h_inode = au_h_iptr(inode, au_ibstart(inode));
9832 + if (!au_test_nfsd()) {
9833 + err = au_vdir_fill_de(file, ctx);
9834 + fsstack_copy_attr_atime(inode, h_inode);
9837 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
9838 + * encode_fh() and others.
9840 + atomic_inc(&h_inode->i_count);
9841 + di_read_unlock(dentry, AuLock_IR);
9842 + si_read_unlock(sb);
9843 + err = au_vdir_fill_de(file, ctx);
9844 + fsstack_copy_attr_atime(inode, h_inode);
9845 + fi_write_unlock(file);
9853 + di_read_unlock(dentry, AuLock_IR);
9854 + fi_write_unlock(file);
9856 + si_read_unlock(sb);
9860 +/* ---------------------------------------------------------------------- */
9862 +#define AuTestEmpty_WHONLY 1
9863 +#define AuTestEmpty_CALLED (1 << 1)
9864 +#define AuTestEmpty_SHWH (1 << 2)
9865 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
9866 +#define au_fset_testempty(flags, name) \
9867 + do { (flags) |= AuTestEmpty_##name; } while (0)
9868 +#define au_fclr_testempty(flags, name) \
9869 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
9871 +#ifndef CONFIG_AUFS_SHWH
9872 +#undef AuTestEmpty_SHWH
9873 +#define AuTestEmpty_SHWH 0
9876 +struct test_empty_arg {
9877 + struct dir_context ctx;
9878 + struct au_nhash *whlist;
9879 + unsigned int flags;
9881 + aufs_bindex_t bindex;
9884 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
9885 + int namelen, loff_t offset __maybe_unused, u64 ino,
9886 + unsigned int d_type)
9888 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
9890 + char *name = (void *)__name;
9893 + au_fset_testempty(arg->flags, CALLED);
9895 + if (name[0] == '.'
9896 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
9897 + goto out; /* success */
9899 + if (namelen <= AUFS_WH_PFX_LEN
9900 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
9901 + if (au_ftest_testempty(arg->flags, WHONLY)
9902 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
9903 + arg->err = -ENOTEMPTY;
9907 + name += AUFS_WH_PFX_LEN;
9908 + namelen -= AUFS_WH_PFX_LEN;
9909 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
9910 + arg->err = au_nhash_append_wh
9911 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
9912 + au_ftest_testempty(arg->flags, SHWH));
9916 + AuTraceErr(arg->err);
9920 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9923 + struct file *h_file;
9925 + h_file = au_h_open(dentry, arg->bindex,
9926 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
9927 + /*file*/NULL, /*force_wr*/0);
9928 + err = PTR_ERR(h_file);
9929 + if (IS_ERR(h_file))
9933 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
9934 + && !file_inode(h_file)->i_nlink)
9939 + au_fclr_testempty(arg->flags, CALLED);
9941 + err = vfsub_iterate_dir(h_file, &arg->ctx);
9944 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
9948 + au_sbr_put(dentry->d_sb, arg->bindex);
9953 +struct do_test_empty_args {
9955 + struct dentry *dentry;
9956 + struct test_empty_arg *arg;
9959 +static void call_do_test_empty(void *args)
9961 + struct do_test_empty_args *a = args;
9962 + *a->errp = do_test_empty(a->dentry, a->arg);
9965 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
9968 + struct dentry *h_dentry;
9969 + struct inode *h_inode;
9971 + h_dentry = au_h_dptr(dentry, arg->bindex);
9972 + h_inode = d_inode(h_dentry);
9973 + /* todo: i_mode changes anytime? */
9974 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
9975 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
9976 + mutex_unlock(&h_inode->i_mutex);
9978 + err = do_test_empty(dentry, arg);
9980 + struct do_test_empty_args args = {
9985 + unsigned int flags = arg->flags;
9987 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
9988 + if (unlikely(wkq_err))
9990 + arg->flags = flags;
9996 +int au_test_empty_lower(struct dentry *dentry)
9999 + unsigned int rdhash;
10000 + aufs_bindex_t bindex, bstart, btail;
10001 + struct au_nhash whlist;
10002 + struct test_empty_arg arg = {
10004 + .actor = test_empty_cb
10007 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10009 + SiMustAnyLock(dentry->d_sb);
10011 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10013 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10014 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10015 + if (unlikely(err))
10019 + arg.whlist = &whlist;
10020 + bstart = au_dbstart(dentry);
10021 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10022 + au_fset_testempty(arg.flags, SHWH);
10023 + test_empty = do_test_empty;
10024 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10025 + test_empty = sio_test_empty;
10026 + arg.bindex = bstart;
10027 + err = test_empty(dentry, &arg);
10028 + if (unlikely(err))
10031 + au_fset_testempty(arg.flags, WHONLY);
10032 + btail = au_dbtaildir(dentry);
10033 + for (bindex = bstart + 1; !err && bindex <= btail; bindex++) {
10034 + struct dentry *h_dentry;
10036 + h_dentry = au_h_dptr(dentry, bindex);
10037 + if (h_dentry && d_is_positive(h_dentry)) {
10038 + arg.bindex = bindex;
10039 + err = test_empty(dentry, &arg);
10044 + au_nhash_wh_free(&whlist);
10049 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10052 + struct test_empty_arg arg = {
10054 + .actor = test_empty_cb
10057 + aufs_bindex_t bindex, btail;
10060 + arg.whlist = whlist;
10061 + arg.flags = AuTestEmpty_WHONLY;
10062 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10063 + au_fset_testempty(arg.flags, SHWH);
10064 + btail = au_dbtaildir(dentry);
10065 + for (bindex = au_dbstart(dentry); !err && bindex <= btail; bindex++) {
10066 + struct dentry *h_dentry;
10068 + h_dentry = au_h_dptr(dentry, bindex);
10069 + if (h_dentry && d_is_positive(h_dentry)) {
10070 + arg.bindex = bindex;
10071 + err = sio_test_empty(dentry, &arg);
10078 +/* ---------------------------------------------------------------------- */
10080 +const struct file_operations aufs_dir_fop = {
10081 + .owner = THIS_MODULE,
10082 + .llseek = default_llseek,
10083 + .read = generic_read_dir,
10084 + .iterate = aufs_iterate,
10085 + .unlocked_ioctl = aufs_ioctl_dir,
10086 +#ifdef CONFIG_COMPAT
10087 + .compat_ioctl = aufs_compat_ioctl_dir,
10089 + .open = aufs_open_dir,
10090 + .release = aufs_release_dir,
10091 + .flush = aufs_flush_dir,
10092 + .fsync = aufs_fsync_dir
10094 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10095 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10096 +++ linux/fs/aufs/dir.h 2015-09-24 10:47:58.251386326 +0200
10099 + * Copyright (C) 2005-2015 Junjiro R. Okajima
10101 + * This program, aufs is free software; you can redistribute it and/or modify
10102 + * it under the terms of the GNU General Public License as published by
10103 + * the Free Software Foundation; either version 2 of the License, or
10104 + * (at your option) any later version.
10106 + * This program is distributed in the hope that it will be useful,
10107 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10108 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10109 + * GNU General Public License for more details.
10111 + * You should have received a copy of the GNU General Public License
10112 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10116 + * directory operations
10119 +#ifndef __AUFS_DIR_H__
10120 +#define __AUFS_DIR_H__
10124 +#include <linux/fs.h>
10126 +/* ---------------------------------------------------------------------- */
10128 +/* need to be faster and smaller */
10131 + unsigned int nh_num;
10132 + struct hlist_head *nh_head;
10135 +struct au_vdir_destr {
10136 + unsigned char len;
10137 + unsigned char name[0];
10140 +struct au_vdir_dehstr {
10141 + struct hlist_node hash;
10142 + struct au_vdir_destr *str;
10143 +} ____cacheline_aligned_in_smp;
10145 +struct au_vdir_de {
10147 + unsigned char de_type;
10148 + /* caution: packed */
10149 + struct au_vdir_destr de_str;
10152 +struct au_vdir_wh {
10153 + struct hlist_node wh_hash;
10154 +#ifdef CONFIG_AUFS_SHWH
10156 + aufs_bindex_t wh_bindex;
10157 + unsigned char wh_type;
10159 + aufs_bindex_t wh_bindex;
10161 + /* caution: packed */
10162 + struct au_vdir_destr wh_str;
10165 +union au_vdir_deblk_p {
10166 + unsigned char *deblk;
10167 + struct au_vdir_de *de;
10171 + unsigned char **vd_deblk;
10172 + unsigned long vd_nblk;
10174 + unsigned long ul;
10175 + union au_vdir_deblk_p p;
10178 + unsigned long vd_version;
10179 + unsigned int vd_deblk_sz;
10180 + unsigned long vd_jiffy;
10181 +} ____cacheline_aligned_in_smp;
10183 +/* ---------------------------------------------------------------------- */
10186 +extern const struct file_operations aufs_dir_fop;
10187 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10188 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10189 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10190 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10191 +int au_test_empty_lower(struct dentry *dentry);
10192 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10195 +unsigned int au_rdhash_est(loff_t sz);
10196 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10197 +void au_nhash_wh_free(struct au_nhash *whlist);
10198 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10200 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10201 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10202 + unsigned int d_type, aufs_bindex_t bindex,
10203 + unsigned char shwh);
10204 +void au_vdir_free(struct au_vdir *vdir);
10205 +int au_vdir_init(struct file *file);
10206 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10209 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10211 +#ifdef CONFIG_AUFS_RDU
10213 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10214 +#ifdef CONFIG_COMPAT
10215 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10216 + unsigned long arg);
10219 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10220 + unsigned int cmd, unsigned long arg)
10221 +#ifdef CONFIG_COMPAT
10222 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10223 + unsigned int cmd, unsigned long arg)
10227 +#endif /* __KERNEL__ */
10228 +#endif /* __AUFS_DIR_H__ */
10229 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10230 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10231 +++ linux/fs/aufs/dynop.c 2015-09-24 10:47:58.251386326 +0200
10234 + * Copyright (C) 2010-2015 Junjiro R. Okajima
10236 + * This program, aufs is free software; you can redistribute it and/or modify
10237 + * it under the terms of the GNU General Public License as published by
10238 + * the Free Software Foundation; either version 2 of the License, or
10239 + * (at your option) any later version.
10241 + * This program is distributed in the hope that it will be useful,
10242 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10243 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10244 + * GNU General Public License for more details.
10246 + * You should have received a copy of the GNU General Public License
10247 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10251 + * dynamically customizable operations for regular files
10256 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10259 + * How large will these lists be?
10260 + * Usually just a few elements, 20-30 at most for each, I guess.
10262 +static struct au_splhead dynop[AuDyLast];
10264 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
10266 + struct au_dykey *key, *tmp;
10267 + struct list_head *head;
10270 + head = &spl->head;
10272 + list_for_each_entry_rcu(tmp, head, dk_list)
10273 + if (tmp->dk_op.dy_hop == h_op) {
10275 + kref_get(&key->dk_kref);
10278 + rcu_read_unlock();
10283 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10285 + struct au_dykey **k, *found;
10286 + const void *h_op = key->dk_op.dy_hop;
10290 + k = br->br_dykey;
10291 + for (i = 0; i < AuBrDynOp; i++)
10293 + if (k[i]->dk_op.dy_hop == h_op) {
10300 + spin_lock(&br->br_dykey_lock);
10301 + for (; i < AuBrDynOp; i++)
10303 + if (k[i]->dk_op.dy_hop == h_op) {
10311 + spin_unlock(&br->br_dykey_lock);
10312 + BUG_ON(i == AuBrDynOp); /* expand the array */
10318 +/* kref_get() if @key is already added */
10319 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
10321 + struct au_dykey *tmp, *found;
10322 + struct list_head *head;
10323 + const void *h_op = key->dk_op.dy_hop;
10326 + head = &spl->head;
10327 + spin_lock(&spl->spin);
10328 + list_for_each_entry(tmp, head, dk_list)
10329 + if (tmp->dk_op.dy_hop == h_op) {
10330 + kref_get(&tmp->dk_kref);
10335 + list_add_rcu(&key->dk_list, head);
10336 + spin_unlock(&spl->spin);
10343 +static void dy_free_rcu(struct rcu_head *rcu)
10345 + struct au_dykey *key;
10347 + key = container_of(rcu, struct au_dykey, dk_rcu);
10352 +static void dy_free(struct kref *kref)
10354 + struct au_dykey *key;
10355 + struct au_splhead *spl;
10357 + key = container_of(kref, struct au_dykey, dk_kref);
10358 + spl = dynop + key->dk_op.dy_type;
10359 + au_spl_del_rcu(&key->dk_list, spl);
10360 + call_rcu(&key->dk_rcu, dy_free_rcu);
10363 +void au_dy_put(struct au_dykey *key)
10365 + kref_put(&key->dk_kref, dy_free);
10368 +/* ---------------------------------------------------------------------- */
10370 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10372 +#ifdef CONFIG_AUFS_DEBUG
10373 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10374 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10376 +#define DyDbgDeclare(cnt) do {} while (0)
10377 +#define DyDbgInc(cnt) do {} while (0)
10380 +#define DySet(func, dst, src, h_op, h_sb) do { \
10382 + if (h_op->func) { \
10384 + dst.func = src.func; \
10386 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10390 +#define DySetForce(func, dst, src) do { \
10391 + AuDebugOn(!src.func); \
10393 + dst.func = src.func; \
10396 +#define DySetAop(func) \
10397 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10398 +#define DySetAopForce(func) \
10399 + DySetForce(func, dyaop->da_op, aufs_aop)
10401 +static void dy_aop(struct au_dykey *key, const void *h_op,
10402 + struct super_block *h_sb __maybe_unused)
10404 + struct au_dyaop *dyaop = (void *)key;
10405 + const struct address_space_operations *h_aop = h_op;
10406 + DyDbgDeclare(cnt);
10408 + AuDbg("%s\n", au_sbtype(h_sb));
10410 + DySetAop(writepage);
10411 + DySetAopForce(readpage); /* force */
10412 + DySetAop(writepages);
10413 + DySetAop(set_page_dirty);
10414 + DySetAop(readpages);
10415 + DySetAop(write_begin);
10416 + DySetAop(write_end);
10418 + DySetAop(invalidatepage);
10419 + DySetAop(releasepage);
10420 + DySetAop(freepage);
10421 + /* this one will be changed according to an aufs mount option */
10422 + DySetAop(direct_IO);
10423 + DySetAop(migratepage);
10424 + DySetAop(launder_page);
10425 + DySetAop(is_partially_uptodate);
10426 + DySetAop(is_dirty_writeback);
10427 + DySetAop(error_remove_page);
10428 + DySetAop(swap_activate);
10429 + DySetAop(swap_deactivate);
10431 + DyDbgSize(cnt, *h_aop);
10434 +/* ---------------------------------------------------------------------- */
10436 +static void dy_bug(struct kref *kref)
10441 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10443 + struct au_dykey *key, *old;
10444 + struct au_splhead *spl;
10447 + void (*set)(struct au_dykey *key, const void *h_op,
10448 + struct super_block *h_sb __maybe_unused);
10450 + static const struct op a[] = {
10452 + .sz = sizeof(struct au_dyaop),
10456 + const struct op *p;
10458 + spl = dynop + op->dy_type;
10459 + key = dy_gfind_get(spl, op->dy_hop);
10461 + goto out_add; /* success */
10463 + p = a + op->dy_type;
10464 + key = kzalloc(p->sz, GFP_NOFS);
10465 + if (unlikely(!key)) {
10466 + key = ERR_PTR(-ENOMEM);
10470 + key->dk_op.dy_hop = op->dy_hop;
10471 + kref_init(&key->dk_kref);
10472 + p->set(key, op->dy_hop, au_br_sb(br));
10473 + old = dy_gadd(spl, key);
10480 + old = dy_bradd(br, key);
10482 + /* its ref-count should never be zero here */
10483 + kref_put(&key->dk_kref, dy_bug);
10488 +/* ---------------------------------------------------------------------- */
10490 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10491 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10492 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10493 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10494 + * See the aufs manual in detail.
10496 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10499 + dyaop->da_op.direct_IO = NULL;
10501 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10504 +static struct au_dyaop *dy_aget(struct au_branch *br,
10505 + const struct address_space_operations *h_aop,
10508 + struct au_dyaop *dyaop;
10509 + struct au_dynop op;
10511 + op.dy_type = AuDy_AOP;
10512 + op.dy_haop = h_aop;
10513 + dyaop = (void *)dy_get(&op, br);
10514 + if (IS_ERR(dyaop))
10516 + dy_adx(dyaop, do_dx);
10522 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10523 + struct inode *h_inode)
10526 + struct super_block *sb;
10527 + struct au_branch *br;
10528 + struct au_dyaop *dyaop;
10530 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10531 + IiMustWriteLock(inode);
10533 + sb = inode->i_sb;
10534 + br = au_sbr(sb, bindex);
10535 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10536 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10537 + err = PTR_ERR(dyaop);
10538 + if (IS_ERR(dyaop))
10539 + /* unnecessary to call dy_fput() */
10543 + inode->i_mapping->a_ops = &dyaop->da_op;
10550 + * Is it safe to replace a_ops during the inode/file is in operation?
10551 + * Yes, I hope so.
10553 +int au_dy_irefresh(struct inode *inode)
10556 + aufs_bindex_t bstart;
10557 + struct inode *h_inode;
10560 + if (S_ISREG(inode->i_mode)) {
10561 + bstart = au_ibstart(inode);
10562 + h_inode = au_h_iptr(inode, bstart);
10563 + err = au_dy_iaop(inode, bstart, h_inode);
10568 +void au_dy_arefresh(int do_dx)
10570 + struct au_splhead *spl;
10571 + struct list_head *head;
10572 + struct au_dykey *key;
10574 + spl = dynop + AuDy_AOP;
10575 + head = &spl->head;
10576 + spin_lock(&spl->spin);
10577 + list_for_each_entry(key, head, dk_list)
10578 + dy_adx((void *)key, do_dx);
10579 + spin_unlock(&spl->spin);
10582 +/* ---------------------------------------------------------------------- */
10584 +void __init au_dy_init(void)
10588 + /* make sure that 'struct au_dykey *' can be any type */
10589 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10591 + for (i = 0; i < AuDyLast; i++)
10592 + au_spl_init(dynop + i);
10595 +void au_dy_fin(void)
10599 + for (i = 0; i < AuDyLast; i++)
10600 + WARN_ON(!list_empty(&dynop[i].head));
10602 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10603 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10604 +++ linux/fs/aufs/dynop.h 2015-09-24 10:47:58.251386326 +0200
10607 + * Copyright (C) 2010-2015 Junjiro R. Okajima
10609 + * This program, aufs is free software; you can redistribute it and/or modify
10610 + * it under the terms of the GNU General Public License as published by
10611 + * the Free Software Foundation; either version 2 of the License, or
10612 + * (at your option) any later version.
10614 + * This program is distributed in the hope that it will be useful,
10615 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10616 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10617 + * GNU General Public License for more details.
10619 + * You should have received a copy of the GNU General Public License
10620 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10624 + * dynamically customizable operations (for regular files only)
10627 +#ifndef __AUFS_DYNOP_H__
10628 +#define __AUFS_DYNOP_H__
10632 +#include <linux/fs.h>
10633 +#include <linux/kref.h>
10635 +enum {AuDy_AOP, AuDyLast};
10640 + const void *dy_hop;
10641 + const struct address_space_operations *dy_haop;
10647 + struct list_head dk_list;
10648 + struct rcu_head dk_rcu;
10650 + struct au_dynop dk_op;
10653 + * during I am in the branch local array, kref is gotten. when the
10654 + * branch is removed, kref is put.
10656 + struct kref dk_kref;
10659 +/* stop unioning since their sizes are very different from each other */
10661 + struct au_dykey da_key;
10662 + struct address_space_operations da_op; /* not const */
10665 +/* ---------------------------------------------------------------------- */
10669 +void au_dy_put(struct au_dykey *key);
10670 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10671 + struct inode *h_inode);
10672 +int au_dy_irefresh(struct inode *inode);
10673 +void au_dy_arefresh(int do_dio);
10675 +void __init au_dy_init(void);
10676 +void au_dy_fin(void);
10678 +#endif /* __KERNEL__ */
10679 +#endif /* __AUFS_DYNOP_H__ */
10680 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10681 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10682 +++ linux/fs/aufs/export.c 2015-09-24 10:47:58.251386326 +0200
10685 + * Copyright (C) 2005-2015 Junjiro R. Okajima
10687 + * This program, aufs is free software; you can redistribute it and/or modify
10688 + * it under the terms of the GNU General Public License as published by
10689 + * the Free Software Foundation; either version 2 of the License, or
10690 + * (at your option) any later version.
10692 + * This program is distributed in the hope that it will be useful,
10693 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10694 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10695 + * GNU General Public License for more details.
10697 + * You should have received a copy of the GNU General Public License
10698 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10705 +#include <linux/exportfs.h>
10706 +#include <linux/fs_struct.h>
10707 +#include <linux/namei.h>
10708 +#include <linux/nsproxy.h>
10709 +#include <linux/random.h>
10710 +#include <linux/writeback.h>
10711 +#include "../fs/mount.h"
10715 +#ifdef CONFIG_AUFS_INO_T_64
10723 +static ino_t decode_ino(__u32 *a)
10727 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10729 +#ifdef CONFIG_AUFS_INO_T_64
10735 +static void encode_ino(__u32 *a, ino_t ino)
10741 +#ifdef CONFIG_AUFS_INO_T_64
10746 +/* NFS file handle */
10750 +#ifdef CONFIG_AUFS_INO_T_64
10751 + /* support 64bit inode number */
10764 + Fh_ino = Fh_ino1,
10765 + Fh_dir_ino = Fh_dir_ino1
10768 +static int au_test_anon(struct dentry *dentry)
10770 + /* note: read d_flags without d_lock */
10771 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
10774 +int au_test_nfsd(void)
10777 + struct task_struct *tsk = current;
10778 + char comm[sizeof(tsk->comm)];
10781 + if (tsk->flags & PF_KTHREAD) {
10782 + get_task_comm(comm, tsk);
10783 + ret = !strcmp(comm, "nfsd");
10789 +/* ---------------------------------------------------------------------- */
10790 +/* inode generation external table */
10792 +void au_xigen_inc(struct inode *inode)
10797 + struct super_block *sb;
10798 + struct au_sbinfo *sbinfo;
10800 + sb = inode->i_sb;
10801 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
10803 + sbinfo = au_sbi(sb);
10804 + pos = inode->i_ino;
10805 + pos *= sizeof(igen);
10806 + igen = inode->i_generation + 1;
10807 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
10808 + sizeof(igen), &pos);
10809 + if (sz == sizeof(igen))
10810 + return; /* success */
10812 + if (unlikely(sz >= 0))
10813 + AuIOErr("xigen error (%zd)\n", sz);
10816 +int au_xigen_new(struct inode *inode)
10821 + struct super_block *sb;
10822 + struct au_sbinfo *sbinfo;
10823 + struct file *file;
10826 + /* todo: dirty, at mount time */
10827 + if (inode->i_ino == AUFS_ROOT_INO)
10829 + sb = inode->i_sb;
10830 + SiMustAnyLock(sb);
10831 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
10835 + pos = inode->i_ino;
10836 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
10837 + AuIOErr1("too large i%lld\n", pos);
10840 + pos *= sizeof(inode->i_generation);
10843 + sbinfo = au_sbi(sb);
10844 + file = sbinfo->si_xigen;
10847 + if (vfsub_f_size_read(file)
10848 + < pos + sizeof(inode->i_generation)) {
10849 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
10850 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
10851 + sizeof(inode->i_generation), &pos);
10853 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
10854 + sizeof(inode->i_generation), &pos);
10855 + if (sz == sizeof(inode->i_generation))
10856 + goto out; /* success */
10859 + if (unlikely(sz >= 0)) {
10861 + AuIOErr("xigen error (%zd)\n", sz);
10868 +int au_xigen_set(struct super_block *sb, struct file *base)
10871 + struct au_sbinfo *sbinfo;
10872 + struct file *file;
10874 + SiMustWriteLock(sb);
10876 + sbinfo = au_sbi(sb);
10877 + file = au_xino_create2(base, sbinfo->si_xigen);
10878 + err = PTR_ERR(file);
10879 + if (IS_ERR(file))
10882 + if (sbinfo->si_xigen)
10883 + fput(sbinfo->si_xigen);
10884 + sbinfo->si_xigen = file;
10890 +void au_xigen_clr(struct super_block *sb)
10892 + struct au_sbinfo *sbinfo;
10894 + SiMustWriteLock(sb);
10896 + sbinfo = au_sbi(sb);
10897 + if (sbinfo->si_xigen) {
10898 + fput(sbinfo->si_xigen);
10899 + sbinfo->si_xigen = NULL;
10903 +/* ---------------------------------------------------------------------- */
10905 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
10908 + struct dentry *dentry, *d;
10909 + struct inode *inode;
10910 + unsigned int sigen;
10913 + inode = ilookup(sb, ino);
10917 + dentry = ERR_PTR(-ESTALE);
10918 + sigen = au_sigen(sb);
10919 + if (unlikely(is_bad_inode(inode)
10920 + || IS_DEADDIR(inode)
10921 + || sigen != au_iigen(inode, NULL)))
10925 + if (!dir_ino || S_ISDIR(inode->i_mode))
10926 + dentry = d_find_alias(inode);
10928 + spin_lock(&inode->i_lock);
10929 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
10930 + spin_lock(&d->d_lock);
10931 + if (!au_test_anon(d)
10932 + && d_inode(d->d_parent)->i_ino == dir_ino) {
10933 + dentry = dget_dlock(d);
10934 + spin_unlock(&d->d_lock);
10937 + spin_unlock(&d->d_lock);
10939 + spin_unlock(&inode->i_lock);
10941 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
10942 + /* need to refresh */
10950 + AuTraceErrPtr(dentry);
10954 +/* ---------------------------------------------------------------------- */
10956 +/* todo: dirty? */
10957 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
10959 +struct au_compare_mnt_args {
10961 + struct super_block *sb;
10964 + struct vfsmount *mnt;
10967 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
10969 + struct au_compare_mnt_args *a = arg;
10971 + if (mnt->mnt_sb != a->sb)
10973 + a->mnt = mntget(mnt);
10977 +static struct vfsmount *au_mnt_get(struct super_block *sb)
10980 + struct path root;
10981 + struct au_compare_mnt_args args = {
10985 + get_fs_root(current->fs, &root);
10987 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
10988 + rcu_read_unlock();
10991 + AuDebugOn(!args.mnt);
10995 +struct au_nfsd_si_lock {
10996 + unsigned int sigen;
10997 + aufs_bindex_t bindex, br_id;
10998 + unsigned char force_lock;
11001 +static int si_nfsd_read_lock(struct super_block *sb,
11002 + struct au_nfsd_si_lock *nsi_lock)
11005 + aufs_bindex_t bindex;
11007 + si_read_lock(sb, AuLock_FLUSH);
11009 + /* branch id may be wrapped around */
11011 + bindex = au_br_index(sb, nsi_lock->br_id);
11012 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11013 + goto out; /* success */
11017 + if (!nsi_lock->force_lock)
11018 + si_read_unlock(sb);
11021 + nsi_lock->bindex = bindex;
11025 +struct find_name_by_ino {
11026 + struct dir_context ctx;
11027 + int called, found;
11034 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11035 + loff_t offset, u64 ino, unsigned int d_type)
11037 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11041 + if (a->ino != ino)
11044 + memcpy(a->name, name, namelen);
11045 + a->namelen = namelen;
11050 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11051 + struct au_nfsd_si_lock *nsi_lock)
11053 + struct dentry *dentry, *parent;
11054 + struct file *file;
11055 + struct inode *dir;
11056 + struct find_name_by_ino arg = {
11058 + .actor = find_name_by_ino
11063 + parent = path->dentry;
11065 + si_read_unlock(parent->d_sb);
11066 + file = vfsub_dentry_open(path, au_dir_roflags);
11067 + dentry = (void *)file;
11068 + if (IS_ERR(file))
11071 + dentry = ERR_PTR(-ENOMEM);
11072 + arg.name = (void *)__get_free_page(GFP_NOFS);
11073 + if (unlikely(!arg.name))
11080 + err = vfsub_iterate_dir(file, &arg.ctx);
11081 + } while (!err && !arg.found && arg.called);
11082 + dentry = ERR_PTR(err);
11083 + if (unlikely(err))
11085 + /* instead of ENOENT */
11086 + dentry = ERR_PTR(-ESTALE);
11090 + /* do not call vfsub_lkup_one() */
11091 + dir = d_inode(parent);
11092 + mutex_lock(&dir->i_mutex);
11093 + dentry = vfsub_lookup_one_len(arg.name, parent, arg.namelen);
11094 + mutex_unlock(&dir->i_mutex);
11095 + AuTraceErrPtr(dentry);
11096 + if (IS_ERR(dentry))
11098 + AuDebugOn(au_test_anon(dentry));
11099 + if (unlikely(d_really_is_negative(dentry))) {
11101 + dentry = ERR_PTR(-ENOENT);
11105 + free_page((unsigned long)arg.name);
11109 + if (unlikely(nsi_lock
11110 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11111 + if (!IS_ERR(dentry)) {
11113 + dentry = ERR_PTR(-ESTALE);
11115 + AuTraceErrPtr(dentry);
11119 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11121 + struct au_nfsd_si_lock *nsi_lock)
11123 + struct dentry *dentry;
11124 + struct path path;
11126 + if (dir_ino != AUFS_ROOT_INO) {
11127 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11128 + dentry = path.dentry;
11129 + if (!path.dentry || IS_ERR(path.dentry))
11131 + AuDebugOn(au_test_anon(path.dentry));
11133 + path.dentry = dget(sb->s_root);
11135 + path.mnt = au_mnt_get(sb);
11136 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11140 + AuTraceErrPtr(dentry);
11144 +/* ---------------------------------------------------------------------- */
11146 +static int h_acceptable(void *expv, struct dentry *dentry)
11151 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11152 + char *buf, int len, struct super_block *sb)
11156 + struct path path;
11158 + p = d_path(h_rootpath, buf, len);
11163 + path.mnt = h_rootpath->mnt;
11164 + path.dentry = h_parent;
11165 + p = d_path(&path, buf, len);
11171 + path.mnt = au_mnt_get(sb);
11172 + path.dentry = sb->s_root;
11173 + p = d_path(&path, buf, len - strlen(p));
11174 + mntput(path.mnt);
11178 + p[strlen(p)] = '/';
11181 + AuTraceErrPtr(p);
11186 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11187 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11189 + struct dentry *dentry, *h_parent, *root;
11190 + struct super_block *h_sb;
11191 + char *pathname, *p;
11192 + struct vfsmount *h_mnt;
11193 + struct au_branch *br;
11195 + struct path path;
11197 + br = au_sbr(sb, nsi_lock->bindex);
11198 + h_mnt = au_br_mnt(br);
11199 + h_sb = h_mnt->mnt_sb;
11200 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11201 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11202 + fh_len - Fh_tail, fh[Fh_h_type],
11203 + h_acceptable, /*context*/NULL);
11204 + dentry = h_parent;
11205 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11206 + AuWarn1("%s decode_fh failed, %ld\n",
11207 + au_sbtype(h_sb), PTR_ERR(h_parent));
11211 + if (unlikely(au_test_anon(h_parent))) {
11212 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11213 + au_sbtype(h_sb));
11214 + goto out_h_parent;
11217 + dentry = ERR_PTR(-ENOMEM);
11218 + pathname = (void *)__get_free_page(GFP_NOFS);
11219 + if (unlikely(!pathname))
11220 + goto out_h_parent;
11222 + root = sb->s_root;
11223 + path.mnt = h_mnt;
11224 + di_read_lock_parent(root, !AuLock_IR);
11225 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11226 + di_read_unlock(root, !AuLock_IR);
11227 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11228 + dentry = (void *)p;
11230 + goto out_pathname;
11232 + si_read_unlock(sb);
11233 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11234 + dentry = ERR_PTR(err);
11235 + if (unlikely(err))
11238 + dentry = ERR_PTR(-ENOENT);
11239 + AuDebugOn(au_test_anon(path.dentry));
11240 + if (unlikely(d_really_is_negative(path.dentry)))
11243 + if (ino != d_inode(path.dentry)->i_ino)
11244 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11246 + dentry = dget(path.dentry);
11251 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11252 + if (!IS_ERR(dentry)) {
11254 + dentry = ERR_PTR(-ESTALE);
11257 + free_page((unsigned long)pathname);
11261 + AuTraceErrPtr(dentry);
11265 +/* ---------------------------------------------------------------------- */
11267 +static struct dentry *
11268 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11271 + struct dentry *dentry;
11272 + __u32 *fh = fid->raw;
11273 + struct au_branch *br;
11274 + ino_t ino, dir_ino;
11275 + struct au_nfsd_si_lock nsi_lock = {
11279 + dentry = ERR_PTR(-ESTALE);
11280 + /* it should never happen, but the file handle is unreliable */
11281 + if (unlikely(fh_len < Fh_tail))
11283 + nsi_lock.sigen = fh[Fh_sigen];
11284 + nsi_lock.br_id = fh[Fh_br_id];
11286 + /* branch id may be wrapped around */
11288 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11290 + nsi_lock.force_lock = 1;
11292 + /* is this inode still cached? */
11293 + ino = decode_ino(fh + Fh_ino);
11294 + /* it should never happen */
11295 + if (unlikely(ino == AUFS_ROOT_INO))
11298 + dir_ino = decode_ino(fh + Fh_dir_ino);
11299 + dentry = decode_by_ino(sb, ino, dir_ino);
11300 + if (IS_ERR(dentry))
11305 + /* is the parent dir cached? */
11306 + br = au_sbr(sb, nsi_lock.bindex);
11307 + atomic_inc(&br->br_count);
11308 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11309 + if (IS_ERR(dentry))
11314 + /* lookup path */
11315 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11316 + if (IS_ERR(dentry))
11318 + if (unlikely(!dentry))
11319 + /* todo?: make it ESTALE */
11323 + if (!au_digen_test(dentry, au_sigen(sb))
11324 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11325 + goto out_unlock; /* success */
11328 + dentry = ERR_PTR(-ESTALE);
11331 + atomic_dec(&br->br_count);
11332 + si_read_unlock(sb);
11334 + AuTraceErrPtr(dentry);
11338 +#if 0 /* reserved for future use */
11339 +/* support subtreecheck option */
11340 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11341 + int fh_len, int fh_type)
11343 + struct dentry *parent;
11344 + __u32 *fh = fid->raw;
11347 + dir_ino = decode_ino(fh + Fh_dir_ino);
11348 + parent = decode_by_ino(sb, dir_ino, 0);
11349 + if (IS_ERR(parent))
11352 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11353 + dir_ino, fh, fh_len);
11356 + AuTraceErrPtr(parent);
11361 +/* ---------------------------------------------------------------------- */
11363 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11364 + struct inode *dir)
11367 + aufs_bindex_t bindex;
11368 + struct super_block *sb, *h_sb;
11369 + struct dentry *dentry, *parent, *h_parent;
11370 + struct inode *h_dir;
11371 + struct au_branch *br;
11374 + if (unlikely(*max_len <= Fh_tail)) {
11375 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11379 + err = FILEID_ROOT;
11380 + if (inode->i_ino == AUFS_ROOT_INO) {
11381 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11386 + sb = inode->i_sb;
11387 + err = si_read_lock(sb, AuLock_FLUSH);
11388 + if (unlikely(err))
11391 +#ifdef CONFIG_AUFS_DEBUG
11392 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11393 + AuWarn1("NFS-exporting requires xino\n");
11397 + ii_read_lock_child(inode);
11398 + bindex = au_ibstart(inode);
11400 + dentry = d_find_any_alias(inode);
11401 + if (unlikely(!dentry))
11403 + AuDebugOn(au_test_anon(dentry));
11404 + parent = dget_parent(dentry);
11406 + if (unlikely(!parent))
11408 + if (d_really_is_positive(parent))
11409 + dir = d_inode(parent);
11412 + ii_read_lock_parent(dir);
11413 + h_dir = au_h_iptr(dir, bindex);
11414 + ii_read_unlock(dir);
11415 + if (unlikely(!h_dir))
11417 + h_parent = d_find_any_alias(h_dir);
11418 + if (unlikely(!h_parent))
11419 + goto out_hparent;
11422 + br = au_sbr(sb, bindex);
11423 + h_sb = au_br_sb(br);
11424 + if (unlikely(!h_sb->s_export_op)) {
11425 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11426 + goto out_hparent;
11429 + fh[Fh_br_id] = br->br_id;
11430 + fh[Fh_sigen] = au_sigen(sb);
11431 + encode_ino(fh + Fh_ino, inode->i_ino);
11432 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11433 + fh[Fh_igen] = inode->i_generation;
11435 + *max_len -= Fh_tail;
11436 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11438 + /*connectable or subtreecheck*/0);
11439 + err = fh[Fh_h_type];
11440 + *max_len += Fh_tail;
11441 + /* todo: macros? */
11442 + if (err != FILEID_INVALID)
11445 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11452 + ii_read_unlock(inode);
11453 + si_read_unlock(sb);
11455 + if (unlikely(err < 0))
11456 + err = FILEID_INVALID;
11460 +/* ---------------------------------------------------------------------- */
11462 +static int aufs_commit_metadata(struct inode *inode)
11465 + aufs_bindex_t bindex;
11466 + struct super_block *sb;
11467 + struct inode *h_inode;
11468 + int (*f)(struct inode *inode);
11470 + sb = inode->i_sb;
11471 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11472 + ii_write_lock_child(inode);
11473 + bindex = au_ibstart(inode);
11474 + AuDebugOn(bindex < 0);
11475 + h_inode = au_h_iptr(inode, bindex);
11477 + f = h_inode->i_sb->s_export_op->commit_metadata;
11479 + err = f(h_inode);
11481 + struct writeback_control wbc = {
11482 + .sync_mode = WB_SYNC_ALL,
11483 + .nr_to_write = 0 /* metadata only */
11486 + err = sync_inode(h_inode, &wbc);
11489 + au_cpup_attr_timesizes(inode);
11490 + ii_write_unlock(inode);
11491 + si_read_unlock(sb);
11495 +/* ---------------------------------------------------------------------- */
11497 +static struct export_operations aufs_export_op = {
11498 + .fh_to_dentry = aufs_fh_to_dentry,
11499 + /* .fh_to_parent = aufs_fh_to_parent, */
11500 + .encode_fh = aufs_encode_fh,
11501 + .commit_metadata = aufs_commit_metadata
11504 +void au_export_init(struct super_block *sb)
11506 + struct au_sbinfo *sbinfo;
11509 + sb->s_export_op = &aufs_export_op;
11510 + sbinfo = au_sbi(sb);
11511 + sbinfo->si_xigen = NULL;
11512 + get_random_bytes(&u, sizeof(u));
11513 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11514 + atomic_set(&sbinfo->si_xigen_next, u);
11516 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11517 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11518 +++ linux/fs/aufs/fhsm.c 2015-09-24 10:47:58.251386326 +0200
11521 + * Copyright (C) 2011-2015 Junjiro R. Okajima
11523 + * This program, aufs is free software; you can redistribute it and/or modify
11524 + * it under the terms of the GNU General Public License as published by
11525 + * the Free Software Foundation; either version 2 of the License, or
11526 + * (at your option) any later version.
11528 + * This program is distributed in the hope that it will be useful,
11529 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11530 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11531 + * GNU General Public License for more details.
11533 + * You should have received a copy of the GNU General Public License
11534 + * along with this program; if not, write to the Free Software
11535 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11539 + * File-based Hierarchy Storage Management
11542 +#include <linux/anon_inodes.h>
11543 +#include <linux/poll.h>
11544 +#include <linux/seq_file.h>
11545 +#include <linux/statfs.h>
11548 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11550 + struct au_sbinfo *sbinfo;
11551 + struct au_fhsm *fhsm;
11553 + SiMustAnyLock(sb);
11555 + sbinfo = au_sbi(sb);
11556 + fhsm = &sbinfo->si_fhsm;
11557 + AuDebugOn(!fhsm);
11558 + return fhsm->fhsm_bottom;
11561 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11563 + struct au_sbinfo *sbinfo;
11564 + struct au_fhsm *fhsm;
11566 + SiMustWriteLock(sb);
11568 + sbinfo = au_sbi(sb);
11569 + fhsm = &sbinfo->si_fhsm;
11570 + AuDebugOn(!fhsm);
11571 + fhsm->fhsm_bottom = bindex;
11574 +/* ---------------------------------------------------------------------- */
11576 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11578 + struct au_br_fhsm *bf;
11580 + bf = br->br_fhsm;
11581 + MtxMustLock(&bf->bf_lock);
11583 + return !bf->bf_readable
11584 + || time_after(jiffies,
11585 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11588 +/* ---------------------------------------------------------------------- */
11590 +static void au_fhsm_notify(struct super_block *sb, int val)
11592 + struct au_sbinfo *sbinfo;
11593 + struct au_fhsm *fhsm;
11595 + SiMustAnyLock(sb);
11597 + sbinfo = au_sbi(sb);
11598 + fhsm = &sbinfo->si_fhsm;
11599 + if (au_fhsm_pid(fhsm)
11600 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11601 + atomic_set(&fhsm->fhsm_readable, val);
11603 + wake_up(&fhsm->fhsm_wqh);
11607 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11608 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11611 + struct au_branch *br;
11612 + struct au_br_fhsm *bf;
11614 + br = au_sbr(sb, bindex);
11615 + AuDebugOn(au_br_rdonly(br));
11616 + bf = br->br_fhsm;
11620 + mutex_lock(&bf->bf_lock);
11622 + MtxMustLock(&bf->bf_lock);
11624 + /* sb->s_root for NFS is unreliable */
11625 + err = au_br_stfs(br, &bf->bf_stfs);
11626 + if (unlikely(err)) {
11627 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11631 + bf->bf_jiffy = jiffies;
11632 + bf->bf_readable = 1;
11634 + au_fhsm_notify(sb, /*val*/1);
11636 + *rstfs = bf->bf_stfs;
11640 + mutex_unlock(&bf->bf_lock);
11641 + au_fhsm_notify(sb, /*val*/1);
11646 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11649 + struct au_sbinfo *sbinfo;
11650 + struct au_fhsm *fhsm;
11651 + struct au_branch *br;
11652 + struct au_br_fhsm *bf;
11654 + AuDbg("b%d, force %d\n", bindex, force);
11655 + SiMustAnyLock(sb);
11657 + sbinfo = au_sbi(sb);
11658 + fhsm = &sbinfo->si_fhsm;
11659 + if (!au_ftest_si(sbinfo, FHSM)
11660 + || fhsm->fhsm_bottom == bindex)
11663 + br = au_sbr(sb, bindex);
11664 + bf = br->br_fhsm;
11666 + mutex_lock(&bf->bf_lock);
11668 + || au_fhsm_pid(fhsm)
11669 + || au_fhsm_test_jiffy(sbinfo, br))
11670 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11672 + mutex_unlock(&bf->bf_lock);
11675 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11677 + aufs_bindex_t bindex, bend;
11678 + struct au_branch *br;
11680 + /* exclude the bottom */
11681 + bend = au_fhsm_bottom(sb);
11682 + for (bindex = 0; bindex < bend; bindex++) {
11683 + br = au_sbr(sb, bindex);
11684 + if (au_br_fhsm(br->br_perm))
11685 + au_fhsm_wrote(sb, bindex, force);
11689 +/* ---------------------------------------------------------------------- */
11691 +static unsigned int au_fhsm_poll(struct file *file,
11692 + struct poll_table_struct *wait)
11694 + unsigned int mask;
11695 + struct au_sbinfo *sbinfo;
11696 + struct au_fhsm *fhsm;
11699 + sbinfo = file->private_data;
11700 + fhsm = &sbinfo->si_fhsm;
11701 + poll_wait(file, &fhsm->fhsm_wqh, wait);
11702 + if (atomic_read(&fhsm->fhsm_readable))
11703 + mask = POLLIN /* | POLLRDNORM */;
11705 + AuTraceErr((int)mask);
11709 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
11710 + struct aufs_stfs *stfs, __s16 brid)
11714 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
11716 + err = __put_user(brid, &stbr->brid);
11717 + if (unlikely(err))
11723 +static ssize_t au_fhsm_do_read(struct super_block *sb,
11724 + struct aufs_stbr __user *stbr, size_t count)
11728 + aufs_bindex_t bindex, bend;
11729 + struct au_branch *br;
11730 + struct au_br_fhsm *bf;
11732 + /* except the bottom branch */
11735 + bend = au_fhsm_bottom(sb);
11736 + for (bindex = 0; !err && bindex < bend; bindex++) {
11737 + br = au_sbr(sb, bindex);
11738 + if (!au_br_fhsm(br->br_perm))
11741 + bf = br->br_fhsm;
11742 + mutex_lock(&bf->bf_lock);
11743 + if (bf->bf_readable) {
11745 + if (count >= sizeof(*stbr))
11746 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
11749 + bf->bf_readable = 0;
11750 + count -= sizeof(*stbr);
11754 + mutex_unlock(&bf->bf_lock);
11757 + err = sizeof(*stbr) * nstbr;
11762 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
11767 + aufs_bindex_t nfhsm, bindex, bend;
11768 + struct au_sbinfo *sbinfo;
11769 + struct au_fhsm *fhsm;
11770 + struct au_branch *br;
11771 + struct super_block *sb;
11774 + sbinfo = file->private_data;
11775 + fhsm = &sbinfo->si_fhsm;
11777 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
11778 + if (!atomic_read(&fhsm->fhsm_readable)) {
11779 + if (vfsub_file_flags(file) & O_NONBLOCK)
11782 + err = wait_event_interruptible_locked_irq
11784 + atomic_read(&fhsm->fhsm_readable));
11786 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
11787 + if (unlikely(err))
11790 + /* sb may already be dead */
11791 + au_rw_read_lock(&sbinfo->si_rwsem);
11792 + readable = atomic_read(&fhsm->fhsm_readable);
11793 + if (readable > 0) {
11794 + sb = sbinfo->si_sb;
11796 + /* exclude the bottom branch */
11798 + bend = au_fhsm_bottom(sb);
11799 + for (bindex = 0; bindex < bend; bindex++) {
11800 + br = au_sbr(sb, bindex);
11801 + if (au_br_fhsm(br->br_perm))
11805 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
11806 + atomic_set(&fhsm->fhsm_readable, 0);
11807 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
11811 + au_rw_read_unlock(&sbinfo->si_rwsem);
11819 +static int au_fhsm_release(struct inode *inode, struct file *file)
11821 + struct au_sbinfo *sbinfo;
11822 + struct au_fhsm *fhsm;
11824 + /* sb may already be dead */
11825 + sbinfo = file->private_data;
11826 + fhsm = &sbinfo->si_fhsm;
11827 + spin_lock(&fhsm->fhsm_spin);
11828 + fhsm->fhsm_pid = 0;
11829 + spin_unlock(&fhsm->fhsm_spin);
11830 + kobject_put(&sbinfo->si_kobj);
11835 +static const struct file_operations au_fhsm_fops = {
11836 + .owner = THIS_MODULE,
11837 + .llseek = noop_llseek,
11838 + .read = au_fhsm_read,
11839 + .poll = au_fhsm_poll,
11840 + .release = au_fhsm_release
11843 +int au_fhsm_fd(struct super_block *sb, int oflags)
11846 + struct au_sbinfo *sbinfo;
11847 + struct au_fhsm *fhsm;
11850 + if (unlikely(!capable(CAP_SYS_ADMIN)))
11854 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
11858 + sbinfo = au_sbi(sb);
11859 + fhsm = &sbinfo->si_fhsm;
11860 + spin_lock(&fhsm->fhsm_spin);
11861 + if (!fhsm->fhsm_pid)
11862 + fhsm->fhsm_pid = current->pid;
11865 + spin_unlock(&fhsm->fhsm_spin);
11866 + if (unlikely(err))
11869 + oflags |= O_RDONLY;
11870 + /* oflags |= FMODE_NONOTIFY; */
11871 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
11873 + if (unlikely(fd < 0))
11876 + /* succeed reglardless 'fhsm' status */
11877 + kobject_get(&sbinfo->si_kobj);
11878 + si_noflush_read_lock(sb);
11879 + if (au_ftest_si(sbinfo, FHSM))
11880 + au_fhsm_wrote_all(sb, /*force*/0);
11881 + si_read_unlock(sb);
11882 + goto out; /* success */
11885 + spin_lock(&fhsm->fhsm_spin);
11886 + fhsm->fhsm_pid = 0;
11887 + spin_unlock(&fhsm->fhsm_spin);
11893 +/* ---------------------------------------------------------------------- */
11895 +int au_fhsm_br_alloc(struct au_branch *br)
11900 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
11902 + au_br_fhsm_init(br->br_fhsm);
11909 +/* ---------------------------------------------------------------------- */
11911 +void au_fhsm_fin(struct super_block *sb)
11913 + au_fhsm_notify(sb, /*val*/-1);
11916 +void au_fhsm_init(struct au_sbinfo *sbinfo)
11918 + struct au_fhsm *fhsm;
11920 + fhsm = &sbinfo->si_fhsm;
11921 + spin_lock_init(&fhsm->fhsm_spin);
11922 + init_waitqueue_head(&fhsm->fhsm_wqh);
11923 + atomic_set(&fhsm->fhsm_readable, 0);
11924 + fhsm->fhsm_expire
11925 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
11926 + fhsm->fhsm_bottom = -1;
11929 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
11931 + sbinfo->si_fhsm.fhsm_expire
11932 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
11935 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
11939 + if (!au_ftest_si(sbinfo, FHSM))
11942 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
11943 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
11944 + seq_printf(seq, ",fhsm_sec=%u", u);
11946 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
11947 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
11948 +++ linux/fs/aufs/file.c 2015-09-24 10:47:58.251386326 +0200
11951 + * Copyright (C) 2005-2015 Junjiro R. Okajima
11953 + * This program, aufs is free software; you can redistribute it and/or modify
11954 + * it under the terms of the GNU General Public License as published by
11955 + * the Free Software Foundation; either version 2 of the License, or
11956 + * (at your option) any later version.
11958 + * This program is distributed in the hope that it will be useful,
11959 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11960 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11961 + * GNU General Public License for more details.
11963 + * You should have received a copy of the GNU General Public License
11964 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11968 + * handling file/dir, and address_space operation
11971 +#ifdef CONFIG_AUFS_DEBUG
11972 +#include <linux/migrate.h>
11974 +#include <linux/pagemap.h>
11977 +/* drop flags for writing */
11978 +unsigned int au_file_roflags(unsigned int flags)
11980 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
11981 + flags |= O_RDONLY | O_NOATIME;
11985 +/* common functions to regular file and dir */
11986 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
11987 + struct file *file, int force_wr)
11989 + struct file *h_file;
11990 + struct dentry *h_dentry;
11991 + struct inode *h_inode;
11992 + struct super_block *sb;
11993 + struct au_branch *br;
11994 + struct path h_path;
11997 + /* a race condition can happen between open and unlink/rmdir */
11998 + h_file = ERR_PTR(-ENOENT);
11999 + h_dentry = au_h_dptr(dentry, bindex);
12000 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12002 + h_inode = d_inode(h_dentry);
12003 + spin_lock(&h_dentry->d_lock);
12004 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12005 + /* || !d_inode(dentry)->i_nlink */
12007 + spin_unlock(&h_dentry->d_lock);
12008 + if (unlikely(err))
12011 + sb = dentry->d_sb;
12012 + br = au_sbr(sb, bindex);
12013 + err = au_br_test_oflag(flags, br);
12014 + h_file = ERR_PTR(err);
12015 + if (unlikely(err))
12018 + /* drop flags for writing */
12019 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12020 + if (force_wr && !(flags & O_WRONLY))
12022 + flags = au_file_roflags(flags);
12024 + h_file = ERR_PTR(-EROFS);
12025 + flags = au_file_roflags(flags);
12026 + if (unlikely(vfsub_native_ro(h_inode)
12027 + || IS_APPEND(h_inode)))
12029 + flags &= ~O_ACCMODE;
12030 + flags |= O_WRONLY;
12033 + flags &= ~O_CREAT;
12034 + atomic_inc(&br->br_count);
12035 + h_path.dentry = h_dentry;
12036 + h_path.mnt = au_br_mnt(br);
12037 + h_file = vfsub_dentry_open(&h_path, flags);
12038 + if (IS_ERR(h_file))
12041 + if (flags & __FMODE_EXEC) {
12042 + err = deny_write_access(h_file);
12043 + if (unlikely(err)) {
12045 + h_file = ERR_PTR(err);
12049 + fsnotify_open(h_file);
12050 + goto out; /* success */
12053 + atomic_dec(&br->br_count);
12058 +static int au_cmoo(struct dentry *dentry)
12061 + unsigned int udba;
12062 + struct path h_path;
12063 + struct au_pin pin;
12064 + struct au_cp_generic cpg = {
12065 + .dentry = dentry,
12070 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12072 + struct inode *delegated;
12073 + struct super_block *sb;
12074 + struct au_sbinfo *sbinfo;
12075 + struct au_fhsm *fhsm;
12077 + struct au_branch *br;
12078 + struct dentry *parent;
12079 + struct au_hinode *hdir;
12081 + DiMustWriteLock(dentry);
12082 + IiMustWriteLock(d_inode(dentry));
12085 + if (IS_ROOT(dentry))
12087 + cpg.bsrc = au_dbstart(dentry);
12091 + sb = dentry->d_sb;
12092 + sbinfo = au_sbi(sb);
12093 + fhsm = &sbinfo->si_fhsm;
12094 + pid = au_fhsm_pid(fhsm);
12096 + && (current->pid == pid
12097 + || current->real_parent->pid == pid))
12100 + br = au_sbr(sb, cpg.bsrc);
12101 + cmoo = au_br_cmoo(br->br_perm);
12104 + if (!d_is_reg(dentry))
12105 + cmoo &= AuBrAttr_COO_ALL;
12109 + parent = dget_parent(dentry);
12110 + di_write_lock_parent(parent);
12111 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12113 + if (unlikely(err < 0)) {
12114 + err = 0; /* there is no upper writable branch */
12117 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12119 + /* do not respect the coo attrib for the target branch */
12120 + err = au_cpup_dirs(dentry, cpg.bdst);
12121 + if (unlikely(err))
12124 + di_downgrade_lock(parent, AuLock_IR);
12125 + udba = au_opt_udba(sb);
12126 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12127 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12128 + if (unlikely(err))
12131 + err = au_sio_cpup_simple(&cpg);
12133 + if (unlikely(err))
12135 + if (!(cmoo & AuBrWAttr_MOO))
12136 + goto out_parent; /* success */
12138 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12139 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12140 + if (unlikely(err))
12143 + h_path.mnt = au_br_mnt(br);
12144 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12145 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12146 + delegated = NULL;
12147 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12149 + /* todo: keep h_dentry or not? */
12150 + if (unlikely(err == -EWOULDBLOCK)) {
12151 + pr_warn("cannot retry for NFSv4 delegation"
12152 + " for an internal unlink\n");
12155 + if (unlikely(err)) {
12156 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12160 + goto out_parent; /* success */
12163 + di_downgrade_lock(parent, AuLock_IR);
12165 + di_read_unlock(parent, AuLock_IR);
12172 +int au_do_open(struct file *file, struct au_do_open_args *args)
12174 + int err, no_lock = args->no_lock;
12175 + struct dentry *dentry;
12176 + struct au_finfo *finfo;
12179 + err = au_finfo_init(file, args->fidir);
12182 + err = au_finfo_init(file, args->fidir);
12185 + if (unlikely(err))
12188 + dentry = file->f_path.dentry;
12189 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12191 + di_write_lock_child(dentry);
12192 + err = au_cmoo(dentry);
12193 + di_downgrade_lock(dentry, AuLock_IR);
12195 + err = args->open(file, vfsub_file_flags(file), NULL);
12196 + di_read_unlock(dentry, AuLock_IR);
12198 + err = au_cmoo(dentry);
12200 + err = args->open(file, vfsub_file_flags(file),
12202 + if (!err && au_fbstart(file) != au_dbstart(dentry))
12204 + * cmoo happens after h_file was opened.
12205 + * need to refresh file later.
12207 + atomic_dec(&au_fi(file)->fi_generation);
12210 + finfo = au_fi(file);
12212 + finfo->fi_file = file;
12213 + au_sphl_add(&finfo->fi_hlist,
12214 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12217 + fi_write_unlock(file);
12220 + fi_write_unlock(file);
12223 + if (unlikely(err)) {
12224 + finfo->fi_hdir = NULL;
12225 + au_finfo_fin(file);
12232 +int au_reopen_nondir(struct file *file)
12235 + aufs_bindex_t bstart;
12236 + struct dentry *dentry;
12237 + struct file *h_file, *h_file_tmp;
12239 + dentry = file->f_path.dentry;
12240 + bstart = au_dbstart(dentry);
12241 + h_file_tmp = NULL;
12242 + if (au_fbstart(file) == bstart) {
12243 + h_file = au_hf_top(file);
12244 + if (file->f_mode == h_file->f_mode)
12245 + return 0; /* success */
12246 + h_file_tmp = h_file;
12247 + get_file(h_file_tmp);
12248 + au_set_h_fptr(file, bstart, NULL);
12250 + AuDebugOn(au_fi(file)->fi_hdir);
12253 + * file exists on both of rw and ro
12254 + * open --> dbstart and fbstart are both 0
12255 + * prepend a branch as rw, "rw" become ro
12257 + * delete the top branch, "rw" becomes rw again
12258 + * --> dbstart is 1, fbstart is still 0
12259 + * write --> fbstart is 0 but dbstart is 1
12261 + /* AuDebugOn(au_fbstart(file) < bstart); */
12263 + h_file = au_h_open(dentry, bstart, vfsub_file_flags(file) & ~O_TRUNC,
12264 + file, /*force_wr*/0);
12265 + err = PTR_ERR(h_file);
12266 + if (IS_ERR(h_file)) {
12267 + if (h_file_tmp) {
12268 + atomic_inc(&au_sbr(dentry->d_sb, bstart)->br_count);
12269 + au_set_h_fptr(file, bstart, h_file_tmp);
12270 + h_file_tmp = NULL;
12272 + goto out; /* todo: close all? */
12276 + au_set_fbstart(file, bstart);
12277 + au_set_h_fptr(file, bstart, h_file);
12278 + au_update_figen(file);
12279 + /* todo: necessary? */
12280 + /* file->f_ra = h_file->f_ra; */
12284 + fput(h_file_tmp);
12288 +/* ---------------------------------------------------------------------- */
12290 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12291 + struct dentry *hi_wh)
12294 + aufs_bindex_t bstart;
12295 + struct au_dinfo *dinfo;
12296 + struct dentry *h_dentry;
12297 + struct au_hdentry *hdp;
12299 + dinfo = au_di(file->f_path.dentry);
12300 + AuRwMustWriteLock(&dinfo->di_rwsem);
12302 + bstart = dinfo->di_bstart;
12303 + dinfo->di_bstart = btgt;
12304 + hdp = dinfo->di_hdentry;
12305 + h_dentry = hdp[0 + btgt].hd_dentry;
12306 + hdp[0 + btgt].hd_dentry = hi_wh;
12307 + err = au_reopen_nondir(file);
12308 + hdp[0 + btgt].hd_dentry = h_dentry;
12309 + dinfo->di_bstart = bstart;
12314 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12315 + aufs_bindex_t bcpup, struct au_pin *pin)
12318 + struct inode *inode, *h_inode;
12319 + struct dentry *h_dentry, *hi_wh;
12320 + struct au_cp_generic cpg = {
12321 + .dentry = file->f_path.dentry,
12328 + au_update_dbstart(cpg.dentry);
12329 + inode = d_inode(cpg.dentry);
12331 + if (au_dbstart(cpg.dentry) <= bcpup
12332 + && au_dbend(cpg.dentry) >= bcpup) {
12333 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12334 + if (h_dentry && d_is_positive(h_dentry))
12335 + h_inode = d_inode(h_dentry);
12337 + hi_wh = au_hi_wh(inode, bcpup);
12338 + if (!hi_wh && !h_inode)
12339 + err = au_sio_cpup_wh(&cpg, file);
12341 + /* already copied-up after unlink */
12342 + err = au_reopen_wh(file, bcpup, hi_wh);
12345 + && (inode->i_nlink > 1
12346 + || (inode->i_state & I_LINKABLE))
12347 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12348 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12354 + * prepare the @file for writing.
12356 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12359 + aufs_bindex_t dbstart;
12360 + struct dentry *parent;
12361 + struct inode *inode;
12362 + struct super_block *sb;
12363 + struct file *h_file;
12364 + struct au_cp_generic cpg = {
12365 + .dentry = file->f_path.dentry,
12370 + .flags = AuCpup_DTIME
12373 + sb = cpg.dentry->d_sb;
12374 + inode = d_inode(cpg.dentry);
12375 + cpg.bsrc = au_fbstart(file);
12376 + err = au_test_ro(sb, cpg.bsrc, inode);
12377 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12378 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12383 + /* need to cpup or reopen */
12384 + parent = dget_parent(cpg.dentry);
12385 + di_write_lock_parent(parent);
12386 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12388 + if (unlikely(err < 0))
12392 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12393 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12394 + if (unlikely(err))
12398 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12399 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12400 + if (unlikely(err))
12403 + dbstart = au_dbstart(cpg.dentry);
12404 + if (dbstart <= cpg.bdst)
12405 + cpg.bsrc = cpg.bdst;
12407 + if (dbstart <= cpg.bdst /* just reopen */
12408 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12410 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12411 + if (IS_ERR(h_file))
12412 + err = PTR_ERR(h_file);
12414 + di_downgrade_lock(parent, AuLock_IR);
12415 + if (dbstart > cpg.bdst)
12416 + err = au_sio_cpup_simple(&cpg);
12418 + err = au_reopen_nondir(file);
12419 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12421 + } else { /* copyup as wh and reopen */
12423 + * since writable hfsplus branch is not supported,
12424 + * h_open_pre/post() are unnecessary.
12426 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12427 + di_downgrade_lock(parent, AuLock_IR);
12431 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12432 + goto out_dput; /* success */
12438 + di_downgrade_lock(parent, AuLock_IR);
12440 + di_read_unlock(parent, AuLock_IR);
12447 +/* ---------------------------------------------------------------------- */
12449 +int au_do_flush(struct file *file, fl_owner_t id,
12450 + int (*flush)(struct file *file, fl_owner_t id))
12453 + struct super_block *sb;
12454 + struct inode *inode;
12456 + inode = file_inode(file);
12457 + sb = inode->i_sb;
12458 + si_noflush_read_lock(sb);
12459 + fi_read_lock(file);
12460 + ii_read_lock_child(inode);
12462 + err = flush(file, id);
12463 + au_cpup_attr_timesizes(inode);
12465 + ii_read_unlock(inode);
12466 + fi_read_unlock(file);
12467 + si_read_unlock(sb);
12471 +/* ---------------------------------------------------------------------- */
12473 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12476 + struct au_pin pin;
12477 + struct au_finfo *finfo;
12478 + struct dentry *parent, *hi_wh;
12479 + struct inode *inode;
12480 + struct super_block *sb;
12481 + struct au_cp_generic cpg = {
12482 + .dentry = file->f_path.dentry,
12487 + .flags = AuCpup_DTIME
12490 + FiMustWriteLock(file);
12493 + finfo = au_fi(file);
12494 + sb = cpg.dentry->d_sb;
12495 + inode = d_inode(cpg.dentry);
12496 + cpg.bdst = au_ibstart(inode);
12497 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12500 + parent = dget_parent(cpg.dentry);
12501 + if (au_test_ro(sb, cpg.bdst, inode)) {
12502 + di_read_lock_parent(parent, !AuLock_IR);
12503 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12505 + di_read_unlock(parent, !AuLock_IR);
12506 + if (unlikely(err < 0))
12511 + di_read_lock_parent(parent, AuLock_IR);
12512 + hi_wh = au_hi_wh(inode, cpg.bdst);
12513 + if (!S_ISDIR(inode->i_mode)
12514 + && au_opt_test(au_mntflags(sb), PLINK)
12515 + && au_plink_test(inode)
12516 + && !d_unhashed(cpg.dentry)
12517 + && cpg.bdst < au_dbstart(cpg.dentry)) {
12518 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12519 + if (unlikely(err))
12522 + /* always superio. */
12523 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12524 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12526 + err = au_sio_cpup_simple(&cpg);
12529 + } else if (hi_wh) {
12530 + /* already copied-up after unlink */
12531 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12532 + *need_reopen = 0;
12536 + di_read_unlock(parent, AuLock_IR);
12543 +static void au_do_refresh_dir(struct file *file)
12545 + aufs_bindex_t bindex, bend, new_bindex, brid;
12546 + struct au_hfile *p, tmp, *q;
12547 + struct au_finfo *finfo;
12548 + struct super_block *sb;
12549 + struct au_fidir *fidir;
12551 + FiMustWriteLock(file);
12553 + sb = file->f_path.dentry->d_sb;
12554 + finfo = au_fi(file);
12555 + fidir = finfo->fi_hdir;
12556 + AuDebugOn(!fidir);
12557 + p = fidir->fd_hfile + finfo->fi_btop;
12558 + brid = p->hf_br->br_id;
12559 + bend = fidir->fd_bbot;
12560 + for (bindex = finfo->fi_btop; bindex <= bend; bindex++, p++) {
12564 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12565 + if (new_bindex == bindex)
12567 + if (new_bindex < 0) {
12568 + au_set_h_fptr(file, bindex, NULL);
12572 + /* swap two lower inode, and loop again */
12573 + q = fidir->fd_hfile + new_bindex;
12577 + if (tmp.hf_file) {
12583 + p = fidir->fd_hfile;
12584 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12585 + bend = au_sbend(sb);
12586 + for (finfo->fi_btop = 0; finfo->fi_btop <= bend;
12587 + finfo->fi_btop++, p++)
12588 + if (p->hf_file) {
12589 + if (file_inode(p->hf_file))
12591 + au_hfput(p, file);
12594 + bend = au_br_index(sb, brid);
12595 + for (finfo->fi_btop = 0; finfo->fi_btop < bend;
12596 + finfo->fi_btop++, p++)
12598 + au_hfput(p, file);
12599 + bend = au_sbend(sb);
12602 + p = fidir->fd_hfile + bend;
12603 + for (fidir->fd_bbot = bend; fidir->fd_bbot >= finfo->fi_btop;
12604 + fidir->fd_bbot--, p--)
12605 + if (p->hf_file) {
12606 + if (file_inode(p->hf_file))
12608 + au_hfput(p, file);
12610 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12614 + * after branch manipulating, refresh the file.
12616 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12618 + int err, need_reopen;
12619 + aufs_bindex_t bend, bindex;
12620 + struct dentry *dentry;
12621 + struct au_finfo *finfo;
12622 + struct au_hfile *hfile;
12624 + dentry = file->f_path.dentry;
12625 + finfo = au_fi(file);
12626 + if (!finfo->fi_hdir) {
12627 + hfile = &finfo->fi_htop;
12628 + AuDebugOn(!hfile->hf_file);
12629 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
12630 + AuDebugOn(bindex < 0);
12631 + if (bindex != finfo->fi_btop)
12632 + au_set_fbstart(file, bindex);
12634 + err = au_fidir_realloc(finfo, au_sbend(dentry->d_sb) + 1);
12635 + if (unlikely(err))
12637 + au_do_refresh_dir(file);
12642 + if (!au_test_mmapped(file))
12643 + err = au_file_refresh_by_inode(file, &need_reopen);
12644 + if (!err && need_reopen && !d_unlinked(dentry))
12645 + err = reopen(file);
12647 + au_update_figen(file);
12648 + goto out; /* success */
12651 + /* error, close all lower files */
12652 + if (finfo->fi_hdir) {
12653 + bend = au_fbend_dir(file);
12654 + for (bindex = au_fbstart(file); bindex <= bend; bindex++)
12655 + au_set_h_fptr(file, bindex, NULL);
12662 +/* common function to regular file and dir */
12663 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12667 + unsigned int sigen, figen;
12668 + aufs_bindex_t bstart;
12669 + unsigned char pseudo_link;
12670 + struct dentry *dentry;
12671 + struct inode *inode;
12674 + dentry = file->f_path.dentry;
12675 + inode = d_inode(dentry);
12676 + sigen = au_sigen(dentry->d_sb);
12677 + fi_write_lock(file);
12678 + figen = au_figen(file);
12679 + di_write_lock_child(dentry);
12680 + bstart = au_dbstart(dentry);
12681 + pseudo_link = (bstart != au_ibstart(inode));
12682 + if (sigen == figen && !pseudo_link && au_fbstart(file) == bstart) {
12684 + di_downgrade_lock(dentry, AuLock_IR);
12685 + fi_downgrade_lock(file);
12687 + goto out; /* success */
12690 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12691 + if (au_digen_test(dentry, sigen)) {
12692 + err = au_reval_dpath(dentry, sigen);
12693 + AuDebugOn(!err && au_digen_test(dentry, sigen));
12697 + err = refresh_file(file, reopen);
12700 + di_downgrade_lock(dentry, AuLock_IR);
12701 + fi_downgrade_lock(file);
12704 + di_write_unlock(dentry);
12705 + fi_write_unlock(file);
12712 +/* ---------------------------------------------------------------------- */
12714 +/* cf. aufs_nopage() */
12715 +/* for madvise(2) */
12716 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
12718 + unlock_page(page);
12722 +/* it will never be called, but necessary to support O_DIRECT */
12723 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
12725 +{ BUG(); return 0; }
12727 +/* they will never be called. */
12728 +#ifdef CONFIG_AUFS_DEBUG
12729 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
12730 + loff_t pos, unsigned len, unsigned flags,
12731 + struct page **pagep, void **fsdata)
12732 +{ AuUnsupport(); return 0; }
12733 +static int aufs_write_end(struct file *file, struct address_space *mapping,
12734 + loff_t pos, unsigned len, unsigned copied,
12735 + struct page *page, void *fsdata)
12736 +{ AuUnsupport(); return 0; }
12737 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
12738 +{ AuUnsupport(); return 0; }
12740 +static int aufs_set_page_dirty(struct page *page)
12741 +{ AuUnsupport(); return 0; }
12742 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
12743 + unsigned int length)
12744 +{ AuUnsupport(); }
12745 +static int aufs_releasepage(struct page *page, gfp_t gfp)
12746 +{ AuUnsupport(); return 0; }
12747 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
12748 + struct page *page, enum migrate_mode mode)
12749 +{ AuUnsupport(); return 0; }
12750 +static int aufs_launder_page(struct page *page)
12751 +{ AuUnsupport(); return 0; }
12752 +static int aufs_is_partially_uptodate(struct page *page,
12753 + unsigned long from,
12754 + unsigned long count)
12755 +{ AuUnsupport(); return 0; }
12756 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
12758 +{ AuUnsupport(); }
12759 +static int aufs_error_remove_page(struct address_space *mapping,
12760 + struct page *page)
12761 +{ AuUnsupport(); return 0; }
12762 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
12764 +{ AuUnsupport(); return 0; }
12765 +static void aufs_swap_deactivate(struct file *file)
12766 +{ AuUnsupport(); }
12767 +#endif /* CONFIG_AUFS_DEBUG */
12769 +const struct address_space_operations aufs_aop = {
12770 + .readpage = aufs_readpage,
12771 + .direct_IO = aufs_direct_IO,
12772 +#ifdef CONFIG_AUFS_DEBUG
12773 + .writepage = aufs_writepage,
12774 + /* no writepages, because of writepage */
12775 + .set_page_dirty = aufs_set_page_dirty,
12776 + /* no readpages, because of readpage */
12777 + .write_begin = aufs_write_begin,
12778 + .write_end = aufs_write_end,
12779 + /* no bmap, no block device */
12780 + .invalidatepage = aufs_invalidatepage,
12781 + .releasepage = aufs_releasepage,
12782 + .migratepage = aufs_migratepage,
12783 + .launder_page = aufs_launder_page,
12784 + .is_partially_uptodate = aufs_is_partially_uptodate,
12785 + .is_dirty_writeback = aufs_is_dirty_writeback,
12786 + .error_remove_page = aufs_error_remove_page,
12787 + .swap_activate = aufs_swap_activate,
12788 + .swap_deactivate = aufs_swap_deactivate
12789 +#endif /* CONFIG_AUFS_DEBUG */
12791 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
12792 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
12793 +++ linux/fs/aufs/file.h 2015-09-24 10:47:58.251386326 +0200
12796 + * Copyright (C) 2005-2015 Junjiro R. Okajima
12798 + * This program, aufs is free software; you can redistribute it and/or modify
12799 + * it under the terms of the GNU General Public License as published by
12800 + * the Free Software Foundation; either version 2 of the License, or
12801 + * (at your option) any later version.
12803 + * This program is distributed in the hope that it will be useful,
12804 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12805 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12806 + * GNU General Public License for more details.
12808 + * You should have received a copy of the GNU General Public License
12809 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12813 + * file operations
12816 +#ifndef __AUFS_FILE_H__
12817 +#define __AUFS_FILE_H__
12821 +#include <linux/file.h>
12822 +#include <linux/fs.h>
12823 +#include <linux/poll.h>
12824 +#include "rwsem.h"
12828 + struct file *hf_file;
12829 + struct au_branch *hf_br;
12834 + aufs_bindex_t fd_bbot;
12835 + aufs_bindex_t fd_nent;
12836 + struct au_vdir *fd_vdir_cache;
12837 + struct au_hfile fd_hfile[];
12840 +static inline int au_fidir_sz(int nent)
12842 + AuDebugOn(nent < 0);
12843 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
12847 + atomic_t fi_generation;
12849 + struct au_rwsem fi_rwsem;
12850 + aufs_bindex_t fi_btop;
12852 + /* do not union them */
12853 + struct { /* for non-dir */
12854 + struct au_hfile fi_htop;
12855 + atomic_t fi_mmapped;
12857 + struct au_fidir *fi_hdir; /* for dir only */
12859 + struct hlist_node fi_hlist;
12860 + struct file *fi_file; /* very ugly */
12861 +} ____cacheline_aligned_in_smp;
12863 +/* ---------------------------------------------------------------------- */
12866 +extern const struct address_space_operations aufs_aop;
12867 +unsigned int au_file_roflags(unsigned int flags);
12868 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12869 + struct file *file, int force_wr);
12870 +struct au_do_open_args {
12872 + int (*open)(struct file *file, int flags,
12873 + struct file *h_file);
12874 + struct au_fidir *fidir;
12875 + struct file *h_file;
12877 +int au_do_open(struct file *file, struct au_do_open_args *args);
12878 +int au_reopen_nondir(struct file *file);
12880 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
12881 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12883 +int au_do_flush(struct file *file, fl_owner_t id,
12884 + int (*flush)(struct file *file, fl_owner_t id));
12887 +#ifdef CONFIG_AUFS_POLL
12888 +unsigned int aufs_poll(struct file *file, poll_table *wait);
12891 +#ifdef CONFIG_AUFS_BR_HFSPLUS
12893 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
12895 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
12896 + struct file *h_file);
12898 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
12899 + aufs_bindex_t bindex, int force_wr)
12900 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
12901 + struct file *h_file);
12905 +extern const struct file_operations aufs_file_fop;
12906 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
12907 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
12908 +struct file *au_read_pre(struct file *file, int keep_fi);
12911 +void au_hfput(struct au_hfile *hf, struct file *file);
12912 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
12913 + struct file *h_file);
12915 +void au_update_figen(struct file *file);
12916 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
12917 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
12919 +void au_fi_init_once(void *_fi);
12920 +void au_finfo_fin(struct file *file);
12921 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
12924 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
12925 +#ifdef CONFIG_COMPAT
12926 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
12927 + unsigned long arg);
12928 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
12929 + unsigned long arg);
12932 +/* ---------------------------------------------------------------------- */
12934 +static inline struct au_finfo *au_fi(struct file *file)
12936 + return file->private_data;
12939 +/* ---------------------------------------------------------------------- */
12942 + * fi_read_lock, fi_write_lock,
12943 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
12945 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
12947 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
12948 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
12949 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
12951 +/* ---------------------------------------------------------------------- */
12953 +/* todo: hard/soft set? */
12954 +static inline aufs_bindex_t au_fbstart(struct file *file)
12956 + FiMustAnyLock(file);
12957 + return au_fi(file)->fi_btop;
12960 +static inline aufs_bindex_t au_fbend_dir(struct file *file)
12962 + FiMustAnyLock(file);
12963 + AuDebugOn(!au_fi(file)->fi_hdir);
12964 + return au_fi(file)->fi_hdir->fd_bbot;
12967 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
12969 + FiMustAnyLock(file);
12970 + AuDebugOn(!au_fi(file)->fi_hdir);
12971 + return au_fi(file)->fi_hdir->fd_vdir_cache;
12974 +static inline void au_set_fbstart(struct file *file, aufs_bindex_t bindex)
12976 + FiMustWriteLock(file);
12977 + au_fi(file)->fi_btop = bindex;
12980 +static inline void au_set_fbend_dir(struct file *file, aufs_bindex_t bindex)
12982 + FiMustWriteLock(file);
12983 + AuDebugOn(!au_fi(file)->fi_hdir);
12984 + au_fi(file)->fi_hdir->fd_bbot = bindex;
12987 +static inline void au_set_fvdir_cache(struct file *file,
12988 + struct au_vdir *vdir_cache)
12990 + FiMustWriteLock(file);
12991 + AuDebugOn(!au_fi(file)->fi_hdir);
12992 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
12995 +static inline struct file *au_hf_top(struct file *file)
12997 + FiMustAnyLock(file);
12998 + AuDebugOn(au_fi(file)->fi_hdir);
12999 + return au_fi(file)->fi_htop.hf_file;
13002 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13004 + FiMustAnyLock(file);
13005 + AuDebugOn(!au_fi(file)->fi_hdir);
13006 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13009 +/* todo: memory barrier? */
13010 +static inline unsigned int au_figen(struct file *f)
13012 + return atomic_read(&au_fi(f)->fi_generation);
13015 +static inline void au_set_mmapped(struct file *f)
13017 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13019 + pr_warn("fi_mmapped wrapped around\n");
13020 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13024 +static inline void au_unset_mmapped(struct file *f)
13026 + atomic_dec(&au_fi(f)->fi_mmapped);
13029 +static inline int au_test_mmapped(struct file *f)
13031 + return atomic_read(&au_fi(f)->fi_mmapped);
13034 +/* customize vma->vm_file */
13036 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13037 + struct file *file)
13041 + f = vma->vm_file;
13043 + vma->vm_file = file;
13048 +#define AuDbgVmRegion(file, vma) do {} while (0)
13050 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13051 + struct file *file)
13053 + au_do_vm_file_reset(vma, file);
13056 +#define AuDbgVmRegion(file, vma) \
13057 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13059 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13060 + struct file *file)
13064 + au_do_vm_file_reset(vma, file);
13065 + f = vma->vm_region->vm_file;
13067 + vma->vm_region->vm_file = file;
13070 +#endif /* CONFIG_MMU */
13072 +/* handle vma->vm_prfile */
13073 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13074 + struct file *file)
13077 + vma->vm_prfile = file;
13078 +#ifndef CONFIG_MMU
13080 + vma->vm_region->vm_prfile = file;
13084 +#endif /* __KERNEL__ */
13085 +#endif /* __AUFS_FILE_H__ */
13086 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13087 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13088 +++ linux/fs/aufs/finfo.c 2015-09-24 10:47:58.251386326 +0200
13091 + * Copyright (C) 2005-2015 Junjiro R. Okajima
13093 + * This program, aufs is free software; you can redistribute it and/or modify
13094 + * it under the terms of the GNU General Public License as published by
13095 + * the Free Software Foundation; either version 2 of the License, or
13096 + * (at your option) any later version.
13098 + * This program is distributed in the hope that it will be useful,
13099 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13100 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13101 + * GNU General Public License for more details.
13103 + * You should have received a copy of the GNU General Public License
13104 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13108 + * file private data
13113 +void au_hfput(struct au_hfile *hf, struct file *file)
13115 + /* todo: direct access f_flags */
13116 + if (vfsub_file_flags(file) & __FMODE_EXEC)
13117 + allow_write_access(hf->hf_file);
13118 + fput(hf->hf_file);
13119 + hf->hf_file = NULL;
13120 + atomic_dec(&hf->hf_br->br_count);
13121 + hf->hf_br = NULL;
13124 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13126 + struct au_finfo *finfo = au_fi(file);
13127 + struct au_hfile *hf;
13128 + struct au_fidir *fidir;
13130 + fidir = finfo->fi_hdir;
13132 + AuDebugOn(finfo->fi_btop != bindex);
13133 + hf = &finfo->fi_htop;
13135 + hf = fidir->fd_hfile + bindex;
13137 + if (hf && hf->hf_file)
13138 + au_hfput(hf, file);
13140 + FiMustWriteLock(file);
13141 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13142 + hf->hf_file = val;
13143 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13147 +void au_update_figen(struct file *file)
13149 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13150 + /* smp_mb(); */ /* atomic_set */
13153 +/* ---------------------------------------------------------------------- */
13155 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13157 + struct au_fidir *fidir;
13160 + nbr = au_sbend(sb) + 1;
13162 + nbr = 2; /* initial allocate for 2 branches */
13163 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13165 + fidir->fd_bbot = -1;
13166 + fidir->fd_nent = nbr;
13167 + fidir->fd_vdir_cache = NULL;
13173 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
13176 + struct au_fidir *fidir, *p;
13178 + AuRwMustWriteLock(&finfo->fi_rwsem);
13179 + fidir = finfo->fi_hdir;
13180 + AuDebugOn(!fidir);
13183 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13186 + p->fd_nent = nbr;
13187 + finfo->fi_hdir = p;
13194 +/* ---------------------------------------------------------------------- */
13196 +void au_finfo_fin(struct file *file)
13198 + struct au_finfo *finfo;
13200 + au_nfiles_dec(file->f_path.dentry->d_sb);
13202 + finfo = au_fi(file);
13203 + AuDebugOn(finfo->fi_hdir);
13204 + AuRwDestroy(&finfo->fi_rwsem);
13205 + au_cache_free_finfo(finfo);
13208 +void au_fi_init_once(void *_finfo)
13210 + struct au_finfo *finfo = _finfo;
13211 + static struct lock_class_key aufs_fi;
13213 + au_rw_init(&finfo->fi_rwsem);
13214 + au_rw_class(&finfo->fi_rwsem, &aufs_fi);
13217 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13220 + struct au_finfo *finfo;
13221 + struct dentry *dentry;
13224 + dentry = file->f_path.dentry;
13225 + finfo = au_cache_alloc_finfo();
13226 + if (unlikely(!finfo))
13230 + au_nfiles_inc(dentry->d_sb);
13231 + /* verbose coding for lock class name */
13233 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcNonDir_FIINFO);
13235 + au_rw_class(&finfo->fi_rwsem, au_lc_key + AuLcDir_FIINFO);
13236 + au_rw_write_lock(&finfo->fi_rwsem);
13237 + finfo->fi_btop = -1;
13238 + finfo->fi_hdir = fidir;
13239 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13240 + /* smp_mb(); */ /* atomic_set */
13242 + file->private_data = finfo;
13247 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13248 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13249 +++ linux/fs/aufs/f_op.c 2015-09-24 10:47:58.251386326 +0200
13252 + * Copyright (C) 2005-2015 Junjiro R. Okajima
13254 + * This program, aufs is free software; you can redistribute it and/or modify
13255 + * it under the terms of the GNU General Public License as published by
13256 + * the Free Software Foundation; either version 2 of the License, or
13257 + * (at your option) any later version.
13259 + * This program is distributed in the hope that it will be useful,
13260 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13261 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13262 + * GNU General Public License for more details.
13264 + * You should have received a copy of the GNU General Public License
13265 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13269 + * file and vm operations
13272 +#include <linux/aio.h>
13273 +#include <linux/fs_stack.h>
13274 +#include <linux/mman.h>
13275 +#include <linux/security.h>
13278 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13281 + aufs_bindex_t bindex;
13282 + struct dentry *dentry;
13283 + struct au_finfo *finfo;
13284 + struct inode *h_inode;
13286 + FiMustWriteLock(file);
13289 + dentry = file->f_path.dentry;
13290 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13291 + finfo = au_fi(file);
13292 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13293 + atomic_set(&finfo->fi_mmapped, 0);
13294 + bindex = au_dbstart(dentry);
13296 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13298 + get_file(h_file);
13299 + if (IS_ERR(h_file))
13300 + err = PTR_ERR(h_file);
13302 + if ((flags & __O_TMPFILE)
13303 + && !(flags & O_EXCL)) {
13304 + h_inode = file_inode(h_file);
13305 + spin_lock(&h_inode->i_lock);
13306 + h_inode->i_state |= I_LINKABLE;
13307 + spin_unlock(&h_inode->i_lock);
13309 + au_set_fbstart(file, bindex);
13310 + au_set_h_fptr(file, bindex, h_file);
13311 + au_update_figen(file);
13312 + /* todo: necessary? */
13313 + /* file->f_ra = h_file->f_ra; */
13319 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13320 + struct file *file)
13323 + struct super_block *sb;
13324 + struct au_do_open_args args = {
13325 + .open = au_do_open_nondir
13328 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13329 + file, vfsub_file_flags(file), file->f_mode);
13331 + sb = file->f_path.dentry->d_sb;
13332 + si_read_lock(sb, AuLock_FLUSH);
13333 + err = au_do_open(file, &args);
13334 + si_read_unlock(sb);
13338 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13340 + struct au_finfo *finfo;
13341 + aufs_bindex_t bindex;
13343 + finfo = au_fi(file);
13344 + au_sphl_del(&finfo->fi_hlist,
13345 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13346 + bindex = finfo->fi_btop;
13348 + au_set_h_fptr(file, bindex, NULL);
13350 + au_finfo_fin(file);
13354 +/* ---------------------------------------------------------------------- */
13356 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13359 + struct file *h_file;
13362 + h_file = au_hf_top(file);
13364 + err = vfsub_flush(h_file, id);
13368 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13370 + return au_do_flush(file, id, au_do_flush_nondir);
13373 +/* ---------------------------------------------------------------------- */
13375 + * read and write functions acquire [fdi]_rwsem once, but release before
13376 + * mmap_sem. This is because to stop a race condition between mmap(2).
13377 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13378 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13379 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13382 +/* Callers should call au_read_post() or fput() in the end */
13383 +struct file *au_read_pre(struct file *file, int keep_fi)
13385 + struct file *h_file;
13388 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13390 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13391 + h_file = au_hf_top(file);
13392 + get_file(h_file);
13394 + fi_read_unlock(file);
13396 + h_file = ERR_PTR(err);
13401 +static void au_read_post(struct inode *inode, struct file *h_file)
13403 + /* update without lock, I don't think it a problem */
13404 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13408 +struct au_write_pre {
13410 + aufs_bindex_t bstart;
13414 + * return with iinfo is write-locked
13415 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13418 +static struct file *au_write_pre(struct file *file, int do_ready,
13419 + struct au_write_pre *wpre)
13421 + struct file *h_file;
13422 + struct dentry *dentry;
13424 + struct au_pin pin;
13426 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13427 + h_file = ERR_PTR(err);
13428 + if (unlikely(err))
13431 + dentry = file->f_path.dentry;
13433 + err = au_ready_to_write(file, -1, &pin);
13434 + if (unlikely(err)) {
13435 + h_file = ERR_PTR(err);
13436 + di_write_unlock(dentry);
13441 + di_downgrade_lock(dentry, /*flags*/0);
13443 + wpre->bstart = au_fbstart(file);
13444 + h_file = au_hf_top(file);
13445 + get_file(h_file);
13447 + wpre->blks = file_inode(h_file)->i_blocks;
13450 + di_read_unlock(dentry, /*flags*/0);
13453 + fi_write_unlock(file);
13458 +static void au_write_post(struct inode *inode, struct file *h_file,
13459 + struct au_write_pre *wpre, ssize_t written)
13461 + struct inode *h_inode;
13463 + au_cpup_attr_timesizes(inode);
13464 + AuDebugOn(au_ibstart(inode) != wpre->bstart);
13465 + h_inode = file_inode(h_file);
13466 + inode->i_mode = h_inode->i_mode;
13467 + ii_write_unlock(inode);
13470 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13472 + au_fhsm_wrote(inode->i_sb, wpre->bstart,
13473 + /*force*/h_inode->i_blocks > wpre->blks);
13476 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13480 + struct inode *inode;
13481 + struct file *h_file;
13482 + struct super_block *sb;
13484 + inode = file_inode(file);
13485 + sb = inode->i_sb;
13486 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13488 + h_file = au_read_pre(file, /*keep_fi*/0);
13489 + err = PTR_ERR(h_file);
13490 + if (IS_ERR(h_file))
13493 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13494 + err = vfsub_read_u(h_file, buf, count, ppos);
13495 + /* todo: necessary? */
13496 + /* file->f_ra = h_file->f_ra; */
13497 + au_read_post(inode, h_file);
13500 + si_read_unlock(sb);
13505 + * todo: very ugly
13506 + * it locks both of i_mutex and si_rwsem for read in safe.
13507 + * if the plink maintenance mode continues forever (that is the problem),
13508 + * may loop forever.
13510 +static void au_mtx_and_read_lock(struct inode *inode)
13513 + struct super_block *sb = inode->i_sb;
13516 + mutex_lock(&inode->i_mutex);
13517 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13520 + mutex_unlock(&inode->i_mutex);
13521 + si_read_lock(sb, AuLock_NOPLMW);
13522 + si_read_unlock(sb);
13526 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13527 + size_t count, loff_t *ppos)
13530 + struct au_write_pre wpre;
13531 + struct inode *inode;
13532 + struct file *h_file;
13533 + char __user *buf = (char __user *)ubuf;
13535 + inode = file_inode(file);
13536 + au_mtx_and_read_lock(inode);
13538 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13539 + err = PTR_ERR(h_file);
13540 + if (IS_ERR(h_file))
13543 + err = vfsub_write_u(h_file, buf, count, ppos);
13544 + au_write_post(inode, h_file, &wpre, err);
13547 + si_read_unlock(inode->i_sb);
13548 + mutex_unlock(&inode->i_mutex);
13552 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13553 + struct iov_iter *iov_iter)
13556 + struct file *file;
13557 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13559 + err = security_file_permission(h_file, rw);
13560 + if (unlikely(err))
13565 + if (rw == MAY_READ)
13566 + iter = h_file->f_op->read_iter;
13567 + else if (rw == MAY_WRITE)
13568 + iter = h_file->f_op->write_iter;
13570 + file = kio->ki_filp;
13571 + kio->ki_filp = h_file;
13574 + err = iter(kio, iov_iter);
13577 + /* currently there is no such fs */
13579 + kio->ki_filp = file;
13585 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13588 + struct file *file, *h_file;
13589 + struct inode *inode;
13590 + struct super_block *sb;
13592 + file = kio->ki_filp;
13593 + inode = file_inode(file);
13594 + sb = inode->i_sb;
13595 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13597 + h_file = au_read_pre(file, /*keep_fi*/0);
13598 + err = PTR_ERR(h_file);
13599 + if (IS_ERR(h_file))
13602 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13603 + /* todo: necessary? */
13604 + /* file->f_ra = h_file->f_ra; */
13605 + au_read_post(inode, h_file);
13608 + si_read_unlock(sb);
13612 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13615 + struct au_write_pre wpre;
13616 + struct inode *inode;
13617 + struct file *file, *h_file;
13619 + file = kio->ki_filp;
13620 + inode = file_inode(file);
13621 + au_mtx_and_read_lock(inode);
13623 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13624 + err = PTR_ERR(h_file);
13625 + if (IS_ERR(h_file))
13628 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13629 + au_write_post(inode, h_file, &wpre, err);
13632 + si_read_unlock(inode->i_sb);
13633 + mutex_unlock(&inode->i_mutex);
13637 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13638 + struct pipe_inode_info *pipe, size_t len,
13639 + unsigned int flags)
13642 + struct file *h_file;
13643 + struct inode *inode;
13644 + struct super_block *sb;
13646 + inode = file_inode(file);
13647 + sb = inode->i_sb;
13648 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13650 + h_file = au_read_pre(file, /*keep_fi*/1);
13651 + err = PTR_ERR(h_file);
13652 + if (IS_ERR(h_file))
13655 + if (au_test_loopback_kthread()) {
13656 + au_warn_loopback(h_file->f_path.dentry->d_sb);
13657 + if (file->f_mapping != h_file->f_mapping) {
13658 + file->f_mapping = h_file->f_mapping;
13659 + smp_mb(); /* unnecessary? */
13662 + fi_read_unlock(file);
13664 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13665 + /* todo: necessasry? */
13666 + /* file->f_ra = h_file->f_ra; */
13667 + au_read_post(inode, h_file);
13670 + si_read_unlock(sb);
13675 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
13676 + size_t len, unsigned int flags)
13679 + struct au_write_pre wpre;
13680 + struct inode *inode;
13681 + struct file *h_file;
13683 + inode = file_inode(file);
13684 + au_mtx_and_read_lock(inode);
13686 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13687 + err = PTR_ERR(h_file);
13688 + if (IS_ERR(h_file))
13691 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
13692 + au_write_post(inode, h_file, &wpre, err);
13695 + si_read_unlock(inode->i_sb);
13696 + mutex_unlock(&inode->i_mutex);
13700 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
13704 + struct au_write_pre wpre;
13705 + struct inode *inode;
13706 + struct file *h_file;
13708 + inode = file_inode(file);
13709 + au_mtx_and_read_lock(inode);
13711 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13712 + err = PTR_ERR(h_file);
13713 + if (IS_ERR(h_file))
13717 + err = vfs_fallocate(h_file, mode, offset, len);
13719 + au_write_post(inode, h_file, &wpre, /*written*/1);
13722 + si_read_unlock(inode->i_sb);
13723 + mutex_unlock(&inode->i_mutex);
13727 +/* ---------------------------------------------------------------------- */
13730 + * The locking order around current->mmap_sem.
13731 + * - in most and regular cases
13732 + * file I/O syscall -- aufs_read() or something
13733 + * -- si_rwsem for read -- mmap_sem
13734 + * (Note that [fdi]i_rwsem are released before mmap_sem).
13736 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
13737 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
13738 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
13739 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
13740 + * It means that when aufs acquires si_rwsem for write, the process should never
13741 + * acquire mmap_sem.
13743 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
13744 + * problem either since any directory is not able to be mmap-ed.
13745 + * The similar scenario is applied to aufs_readlink() too.
13748 +#if 0 /* stop calling security_file_mmap() */
13749 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
13750 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
13752 +static unsigned long au_arch_prot_conv(unsigned long flags)
13754 + /* currently ppc64 only */
13755 +#ifdef CONFIG_PPC64
13756 + /* cf. linux/arch/powerpc/include/asm/mman.h */
13757 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
13758 + return AuConv_VM_PROT(flags, SAO);
13760 + AuDebugOn(arch_calc_vm_prot_bits(-1));
13765 +static unsigned long au_prot_conv(unsigned long flags)
13767 + return AuConv_VM_PROT(flags, READ)
13768 + | AuConv_VM_PROT(flags, WRITE)
13769 + | AuConv_VM_PROT(flags, EXEC)
13770 + | au_arch_prot_conv(flags);
13773 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
13774 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
13776 +static unsigned long au_flag_conv(unsigned long flags)
13778 + return AuConv_VM_MAP(flags, GROWSDOWN)
13779 + | AuConv_VM_MAP(flags, DENYWRITE)
13780 + | AuConv_VM_MAP(flags, LOCKED);
13784 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
13787 + const unsigned char wlock
13788 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
13789 + struct super_block *sb;
13790 + struct file *h_file;
13791 + struct inode *inode;
13793 + AuDbgVmRegion(file, vma);
13795 + inode = file_inode(file);
13796 + sb = inode->i_sb;
13798 + si_read_lock(sb, AuLock_NOPLMW);
13800 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
13802 + err = PTR_ERR(h_file);
13803 + if (IS_ERR(h_file))
13807 + au_set_mmapped(file);
13808 + au_vm_file_reset(vma, h_file);
13810 + * we cannot call security_mmap_file() here since it may acquire
13811 + * mmap_sem or i_mutex.
13813 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
13814 + * au_flag_conv(vma->vm_flags));
13817 + err = h_file->f_op->mmap(h_file, vma);
13819 + au_vm_prfile_set(vma, file);
13820 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13821 + goto out_fput; /* success */
13823 + au_unset_mmapped(file);
13824 + au_vm_file_reset(vma, file);
13828 + ii_write_unlock(inode);
13833 + si_read_unlock(sb);
13839 +/* ---------------------------------------------------------------------- */
13841 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
13845 + struct au_write_pre wpre;
13846 + struct inode *inode;
13847 + struct file *h_file;
13849 + err = 0; /* -EBADF; */ /* posix? */
13850 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13853 + inode = file_inode(file);
13854 + au_mtx_and_read_lock(inode);
13856 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13857 + err = PTR_ERR(h_file);
13858 + if (IS_ERR(h_file))
13861 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
13862 + au_write_post(inode, h_file, &wpre, /*written*/0);
13865 + si_read_unlock(inode->i_sb);
13866 + mutex_unlock(&inode->i_mutex);
13871 +/* no one supports this operation, currently */
13873 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
13876 + struct au_write_pre wpre;
13877 + struct inode *inode;
13878 + struct file *file, *h_file;
13880 + err = 0; /* -EBADF; */ /* posix? */
13881 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
13884 + file = kio->ki_filp;
13885 + inode = file_inode(file);
13886 + au_mtx_and_read_lock(inode);
13888 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13889 + err = PTR_ERR(h_file);
13890 + if (IS_ERR(h_file))
13894 + h_file = au_hf_top(file);
13895 + if (h_file->f_op->aio_fsync) {
13896 + struct mutex *h_mtx;
13898 + h_mtx = &file_inode(h_file)->i_mutex;
13899 + if (!is_sync_kiocb(kio)) {
13900 + get_file(h_file);
13903 + kio->ki_filp = h_file;
13904 + err = h_file->f_op->aio_fsync(kio, datasync);
13905 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
13907 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
13909 + mutex_unlock(h_mtx);
13911 + au_write_post(inode, h_file, &wpre, /*written*/0);
13914 + si_read_unlock(inode->sb);
13915 + mutex_unlock(&inode->i_mutex);
13921 +static int aufs_fasync(int fd, struct file *file, int flag)
13924 + struct file *h_file;
13925 + struct super_block *sb;
13927 + sb = file->f_path.dentry->d_sb;
13928 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13930 + h_file = au_read_pre(file, /*keep_fi*/0);
13931 + err = PTR_ERR(h_file);
13932 + if (IS_ERR(h_file))
13935 + if (h_file->f_op->fasync)
13936 + err = h_file->f_op->fasync(fd, h_file, flag);
13937 + fput(h_file); /* instead of au_read_post() */
13940 + si_read_unlock(sb);
13944 +/* ---------------------------------------------------------------------- */
13946 +/* no one supports this operation, currently */
13948 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
13949 + size_t len, loff_t *pos, int more)
13954 +/* ---------------------------------------------------------------------- */
13956 +const struct file_operations aufs_file_fop = {
13957 + .owner = THIS_MODULE,
13959 + .llseek = default_llseek,
13961 + .read = aufs_read,
13962 + .write = aufs_write,
13963 + .read_iter = aufs_read_iter,
13964 + .write_iter = aufs_write_iter,
13966 +#ifdef CONFIG_AUFS_POLL
13967 + .poll = aufs_poll,
13969 + .unlocked_ioctl = aufs_ioctl_nondir,
13970 +#ifdef CONFIG_COMPAT
13971 + .compat_ioctl = aufs_compat_ioctl_nondir,
13973 + .mmap = aufs_mmap,
13974 + .open = aufs_open_nondir,
13975 + .flush = aufs_flush_nondir,
13976 + .release = aufs_release_nondir,
13977 + .fsync = aufs_fsync_nondir,
13978 + /* .aio_fsync = aufs_aio_fsync_nondir, */
13979 + .fasync = aufs_fasync,
13980 + /* .sendpage = aufs_sendpage, */
13981 + .splice_write = aufs_splice_write,
13982 + .splice_read = aufs_splice_read,
13984 + .aio_splice_write = aufs_aio_splice_write,
13985 + .aio_splice_read = aufs_aio_splice_read,
13987 + .fallocate = aufs_fallocate
13989 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
13990 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
13991 +++ linux/fs/aufs/fstype.h 2015-09-24 10:47:58.254719746 +0200
13994 + * Copyright (C) 2005-2015 Junjiro R. Okajima
13996 + * This program, aufs is free software; you can redistribute it and/or modify
13997 + * it under the terms of the GNU General Public License as published by
13998 + * the Free Software Foundation; either version 2 of the License, or
13999 + * (at your option) any later version.
14001 + * This program is distributed in the hope that it will be useful,
14002 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14003 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14004 + * GNU General Public License for more details.
14006 + * You should have received a copy of the GNU General Public License
14007 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14011 + * judging filesystem type
14014 +#ifndef __AUFS_FSTYPE_H__
14015 +#define __AUFS_FSTYPE_H__
14019 +#include <linux/fs.h>
14020 +#include <linux/magic.h>
14021 +#include <linux/romfs_fs.h>
14022 +#include <linux/nfs_fs.h>
14024 +static inline int au_test_aufs(struct super_block *sb)
14026 + return sb->s_magic == AUFS_SUPER_MAGIC;
14029 +static inline const char *au_sbtype(struct super_block *sb)
14031 + return sb->s_type->name;
14034 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14036 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
14037 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14043 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14045 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
14046 + return sb->s_magic == ROMFS_MAGIC;
14052 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14054 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
14055 + return sb->s_magic == CRAMFS_MAGIC;
14060 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14062 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
14063 + return sb->s_magic == NFS_SUPER_MAGIC;
14069 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14071 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
14072 + return sb->s_magic == FUSE_SUPER_MAGIC;
14078 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14080 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
14081 + return sb->s_magic == XFS_SB_MAGIC;
14087 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14089 +#ifdef CONFIG_TMPFS
14090 + return sb->s_magic == TMPFS_MAGIC;
14096 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14098 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
14099 + return !strcmp(au_sbtype(sb), "ecryptfs");
14105 +static inline int au_test_ramfs(struct super_block *sb)
14107 + return sb->s_magic == RAMFS_MAGIC;
14110 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14112 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
14113 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14119 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14121 +#ifdef CONFIG_PROC_FS
14122 + return sb->s_magic == PROC_SUPER_MAGIC;
14128 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14130 +#ifdef CONFIG_SYSFS
14131 + return sb->s_magic == SYSFS_MAGIC;
14137 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14139 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
14140 + return sb->s_magic == CONFIGFS_MAGIC;
14146 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14148 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
14149 + return sb->s_magic == MINIX3_SUPER_MAGIC
14150 + || sb->s_magic == MINIX2_SUPER_MAGIC
14151 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14152 + || sb->s_magic == MINIX_SUPER_MAGIC
14153 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14159 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14161 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
14162 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14168 +static inline int au_test_msdos(struct super_block *sb)
14170 + return au_test_fat(sb);
14173 +static inline int au_test_vfat(struct super_block *sb)
14175 + return au_test_fat(sb);
14178 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14180 +#ifdef CONFIG_SECURITYFS
14181 + return sb->s_magic == SECURITYFS_MAGIC;
14187 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14189 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
14190 + return sb->s_magic == SQUASHFS_MAGIC;
14196 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14198 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
14199 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14205 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14207 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
14208 + return sb->s_magic == XENFS_SUPER_MAGIC;
14214 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14216 +#ifdef CONFIG_DEBUG_FS
14217 + return sb->s_magic == DEBUGFS_MAGIC;
14223 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14225 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
14226 + return sb->s_magic == NILFS_SUPER_MAGIC;
14232 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14234 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
14235 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14241 +/* ---------------------------------------------------------------------- */
14243 + * they can't be an aufs branch.
14245 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14248 +#ifndef CONFIG_AUFS_BR_RAMFS
14249 + au_test_ramfs(sb) ||
14251 + au_test_procfs(sb)
14252 + || au_test_sysfs(sb)
14253 + || au_test_configfs(sb)
14254 + || au_test_debugfs(sb)
14255 + || au_test_securityfs(sb)
14256 + || au_test_xenfs(sb)
14257 + || au_test_ecryptfs(sb)
14258 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14259 + || au_test_aufs(sb); /* will be supported in next version */
14262 +static inline int au_test_fs_remote(struct super_block *sb)
14264 + return !au_test_tmpfs(sb)
14265 +#ifdef CONFIG_AUFS_BR_RAMFS
14266 + && !au_test_ramfs(sb)
14268 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14271 +/* ---------------------------------------------------------------------- */
14274 + * Note: these functions (below) are created after reading ->getattr() in all
14275 + * filesystems under linux/fs. it means we have to do so in every update...
14279 + * some filesystems require getattr to refresh the inode attributes before
14281 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14282 + * and leave the work for d_revalidate()
14284 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14286 + return au_test_nfs(sb)
14287 + || au_test_fuse(sb)
14288 + /* || au_test_btrfs(sb) */ /* untested */
14293 + * filesystems which don't maintain i_size or i_blocks.
14295 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14297 + return au_test_xfs(sb)
14298 + || au_test_btrfs(sb)
14299 + || au_test_ubifs(sb)
14300 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14301 + /* || au_test_minix(sb) */ /* untested */
14306 + * filesystems which don't store the correct value in some of their inode
14309 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14311 + return au_test_fs_bad_iattr_size(sb)
14312 + || au_test_fat(sb)
14313 + || au_test_msdos(sb)
14314 + || au_test_vfat(sb);
14317 +/* they don't check i_nlink in link(2) */
14318 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14320 + return au_test_tmpfs(sb)
14321 +#ifdef CONFIG_AUFS_BR_RAMFS
14322 + || au_test_ramfs(sb)
14324 + || au_test_ubifs(sb)
14325 + || au_test_hfsplus(sb);
14329 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14331 +static inline int au_test_fs_notime(struct super_block *sb)
14333 + return au_test_nfs(sb)
14334 + || au_test_fuse(sb)
14335 + || au_test_ubifs(sb)
14339 +/* temporary support for i#1 in cramfs */
14340 +static inline int au_test_fs_unique_ino(struct inode *inode)
14342 + if (au_test_cramfs(inode->i_sb))
14343 + return inode->i_ino != 1;
14347 +/* ---------------------------------------------------------------------- */
14350 + * the filesystem where the xino files placed must support i/o after unlink and
14351 + * maintain i_size and i_blocks.
14353 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14355 + return au_test_fs_remote(sb)
14356 + || au_test_fs_bad_iattr_size(sb)
14357 + /* don't want unnecessary work for xino */
14358 + || au_test_aufs(sb)
14359 + || au_test_ecryptfs(sb)
14360 + || au_test_nilfs(sb);
14363 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14365 + return au_test_tmpfs(sb)
14366 + || au_test_ramfs(sb);
14370 + * test if the @sb is real-readonly.
14372 +static inline int au_test_fs_rr(struct super_block *sb)
14374 + return au_test_squashfs(sb)
14375 + || au_test_iso9660(sb)
14376 + || au_test_cramfs(sb)
14377 + || au_test_romfs(sb);
14381 + * test if the @inode is nfs with 'noacl' option
14382 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14384 +static inline int au_test_nfs_noacl(struct inode *inode)
14386 + return au_test_nfs(inode->i_sb)
14387 + /* && IS_POSIXACL(inode) */
14388 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14391 +#endif /* __KERNEL__ */
14392 +#endif /* __AUFS_FSTYPE_H__ */
14393 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14394 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14395 +++ linux/fs/aufs/hfsnotify.c 2015-09-24 10:47:58.254719746 +0200
14398 + * Copyright (C) 2005-2015 Junjiro R. Okajima
14400 + * This program, aufs is free software; you can redistribute it and/or modify
14401 + * it under the terms of the GNU General Public License as published by
14402 + * the Free Software Foundation; either version 2 of the License, or
14403 + * (at your option) any later version.
14405 + * This program is distributed in the hope that it will be useful,
14406 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14407 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14408 + * GNU General Public License for more details.
14410 + * You should have received a copy of the GNU General Public License
14411 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14415 + * fsnotify for the lower directories
14420 +/* FS_IN_IGNORED is unnecessary */
14421 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14422 + | FS_CREATE | FS_EVENT_ON_CHILD);
14423 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14424 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14426 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14428 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14431 + au_cache_free_hnotify(hn);
14432 + smp_mb__before_atomic();
14433 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14434 + wake_up(&au_hfsn_wq);
14437 +static int au_hfsn_alloc(struct au_hinode *hinode)
14440 + struct au_hnotify *hn;
14441 + struct super_block *sb;
14442 + struct au_branch *br;
14443 + struct fsnotify_mark *mark;
14444 + aufs_bindex_t bindex;
14446 + hn = hinode->hi_notify;
14447 + sb = hn->hn_aufs_inode->i_sb;
14448 + bindex = au_br_index(sb, hinode->hi_id);
14449 + br = au_sbr(sb, bindex);
14450 + AuDebugOn(!br->br_hfsn);
14452 + mark = &hn->hn_mark;
14453 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14454 + mark->mask = AuHfsnMask;
14456 + * by udba rename or rmdir, aufs assign a new inode to the known
14457 + * h_inode, so specify 1 to allow dups.
14460 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14461 + /*mnt*/NULL, /*allow_dups*/1);
14462 + /* even if err */
14463 + fsnotify_put_mark(mark);
14469 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14471 + struct fsnotify_mark *mark;
14472 + unsigned long long ull;
14473 + struct fsnotify_group *group;
14475 + ull = atomic64_inc_return(&au_hfsn_ifree);
14478 + mark = &hn->hn_mark;
14479 + spin_lock(&mark->lock);
14480 + group = mark->group;
14481 + fsnotify_get_group(group);
14482 + spin_unlock(&mark->lock);
14484 + fsnotify_destroy_mark(mark, group);
14485 + fsnotify_put_group(group);
14488 + /* free hn by myself */
14492 +/* ---------------------------------------------------------------------- */
14494 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14496 + struct fsnotify_mark *mark;
14498 + mark = &hinode->hi_notify->hn_mark;
14499 + spin_lock(&mark->lock);
14501 + AuDebugOn(mark->mask & AuHfsnMask);
14502 + mark->mask |= AuHfsnMask;
14504 + AuDebugOn(!(mark->mask & AuHfsnMask));
14505 + mark->mask &= ~AuHfsnMask;
14507 + spin_unlock(&mark->lock);
14508 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14511 +/* ---------------------------------------------------------------------- */
14513 +/* #define AuDbgHnotify */
14514 +#ifdef AuDbgHnotify
14515 +static char *au_hfsn_name(u32 mask)
14517 +#ifdef CONFIG_AUFS_DEBUG
14518 +#define test_ret(flag) \
14520 + if (mask & flag) \
14523 + test_ret(FS_ACCESS);
14524 + test_ret(FS_MODIFY);
14525 + test_ret(FS_ATTRIB);
14526 + test_ret(FS_CLOSE_WRITE);
14527 + test_ret(FS_CLOSE_NOWRITE);
14528 + test_ret(FS_OPEN);
14529 + test_ret(FS_MOVED_FROM);
14530 + test_ret(FS_MOVED_TO);
14531 + test_ret(FS_CREATE);
14532 + test_ret(FS_DELETE);
14533 + test_ret(FS_DELETE_SELF);
14534 + test_ret(FS_MOVE_SELF);
14535 + test_ret(FS_UNMOUNT);
14536 + test_ret(FS_Q_OVERFLOW);
14537 + test_ret(FS_IN_IGNORED);
14538 + test_ret(FS_ISDIR);
14539 + test_ret(FS_IN_ONESHOT);
14540 + test_ret(FS_EVENT_ON_CHILD);
14549 +/* ---------------------------------------------------------------------- */
14551 +static void au_hfsn_free_group(struct fsnotify_group *group)
14553 + struct au_br_hfsnotify *hfsn = group->private;
14559 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14560 + struct inode *inode,
14561 + struct fsnotify_mark *inode_mark,
14562 + struct fsnotify_mark *vfsmount_mark,
14563 + u32 mask, void *data, int data_type,
14564 + const unsigned char *file_name, u32 cookie)
14567 + struct au_hnotify *hnotify;
14568 + struct inode *h_dir, *h_inode;
14569 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14571 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14574 + /* if FS_UNMOUNT happens, there must be another bug */
14575 + AuDebugOn(mask & FS_UNMOUNT);
14576 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14581 +#ifdef AuDbgHnotify
14583 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14584 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14585 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14586 + h_dir->i_ino, mask, au_hfsn_name(mask),
14587 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14588 + /* WARN_ON(1); */
14593 + AuDebugOn(!inode_mark);
14594 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14595 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14601 +static struct fsnotify_ops au_hfsn_ops = {
14602 + .handle_event = au_hfsn_handle_event,
14603 + .free_group_priv = au_hfsn_free_group
14606 +/* ---------------------------------------------------------------------- */
14608 +static void au_hfsn_fin_br(struct au_branch *br)
14610 + struct au_br_hfsnotify *hfsn;
14612 + hfsn = br->br_hfsn;
14615 + fsnotify_put_group(hfsn->hfsn_group);
14620 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14623 + struct fsnotify_group *group;
14624 + struct au_br_hfsnotify *hfsn;
14627 + br->br_hfsn = NULL;
14628 + if (!au_br_hnotifyable(perm))
14632 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14633 + if (unlikely(!hfsn))
14637 + group = fsnotify_alloc_group(&au_hfsn_ops);
14638 + if (IS_ERR(group)) {
14639 + err = PTR_ERR(group);
14640 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14644 + group->private = hfsn;
14645 + hfsn->hfsn_group = group;
14646 + br->br_hfsn = hfsn;
14647 + goto out; /* success */
14655 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14660 + if (!br->br_hfsn)
14661 + err = au_hfsn_init_br(br, perm);
14666 +/* ---------------------------------------------------------------------- */
14668 +static void au_hfsn_fin(void)
14670 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14671 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14674 +const struct au_hnotify_op au_hnotify_op = {
14675 + .ctl = au_hfsn_ctl,
14676 + .alloc = au_hfsn_alloc,
14677 + .free = au_hfsn_free,
14679 + .fin = au_hfsn_fin,
14681 + .reset_br = au_hfsn_reset_br,
14682 + .fin_br = au_hfsn_fin_br,
14683 + .init_br = au_hfsn_init_br
14685 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14686 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14687 +++ linux/fs/aufs/hfsplus.c 2015-09-24 10:47:58.254719746 +0200
14690 + * Copyright (C) 2010-2015 Junjiro R. Okajima
14692 + * This program, aufs is free software; you can redistribute it and/or modify
14693 + * it under the terms of the GNU General Public License as published by
14694 + * the Free Software Foundation; either version 2 of the License, or
14695 + * (at your option) any later version.
14697 + * This program is distributed in the hope that it will be useful,
14698 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14699 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14700 + * GNU General Public License for more details.
14702 + * You should have received a copy of the GNU General Public License
14703 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14707 + * special support for filesystems which aqucires an inode mutex
14708 + * at final closing a file, eg, hfsplus.
14710 + * This trick is very simple and stupid, just to open the file before really
14711 + * neceeary open to tell hfsplus that this is not the final closing.
14712 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14713 + * and au_h_open_post() after releasing it.
14718 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
14721 + struct file *h_file;
14722 + struct dentry *h_dentry;
14724 + h_dentry = au_h_dptr(dentry, bindex);
14725 + AuDebugOn(!h_dentry);
14726 + AuDebugOn(d_is_negative(h_dentry));
14729 + if (au_test_hfsplus(h_dentry->d_sb)
14730 + && d_is_reg(h_dentry))
14731 + h_file = au_h_open(dentry, bindex,
14732 + O_RDONLY | O_NOATIME | O_LARGEFILE,
14733 + /*file*/NULL, force_wr);
14737 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
14738 + struct file *h_file)
14742 + au_sbr_put(dentry->d_sb, bindex);
14745 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
14746 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
14747 +++ linux/fs/aufs/hnotify.c 2015-09-24 10:47:58.254719746 +0200
14750 + * Copyright (C) 2005-2015 Junjiro R. Okajima
14752 + * This program, aufs is free software; you can redistribute it and/or modify
14753 + * it under the terms of the GNU General Public License as published by
14754 + * the Free Software Foundation; either version 2 of the License, or
14755 + * (at your option) any later version.
14757 + * This program is distributed in the hope that it will be useful,
14758 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14759 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14760 + * GNU General Public License for more details.
14762 + * You should have received a copy of the GNU General Public License
14763 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14767 + * abstraction to notify the direct changes on lower directories
14772 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
14775 + struct au_hnotify *hn;
14778 + hn = au_cache_alloc_hnotify();
14780 + hn->hn_aufs_inode = inode;
14781 + hinode->hi_notify = hn;
14782 + err = au_hnotify_op.alloc(hinode);
14784 + if (unlikely(err)) {
14785 + hinode->hi_notify = NULL;
14786 + au_cache_free_hnotify(hn);
14788 + * The upper dir was removed by udba, but the same named
14789 + * dir left. In this case, aufs assignes a new inode
14790 + * number and set the monitor again.
14791 + * For the lower dir, the old monitnor is still left.
14793 + if (err == -EEXIST)
14802 +void au_hn_free(struct au_hinode *hinode)
14804 + struct au_hnotify *hn;
14806 + hn = hinode->hi_notify;
14808 + hinode->hi_notify = NULL;
14809 + if (au_hnotify_op.free(hinode, hn))
14810 + au_cache_free_hnotify(hn);
14814 +/* ---------------------------------------------------------------------- */
14816 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
14818 + if (hinode->hi_notify)
14819 + au_hnotify_op.ctl(hinode, do_set);
14822 +void au_hn_reset(struct inode *inode, unsigned int flags)
14824 + aufs_bindex_t bindex, bend;
14825 + struct inode *hi;
14826 + struct dentry *iwhdentry;
14828 + bend = au_ibend(inode);
14829 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
14830 + hi = au_h_iptr(inode, bindex);
14834 + /* mutex_lock_nested(&hi->i_mutex, AuLsc_I_CHILD); */
14835 + iwhdentry = au_hi_wh(inode, bindex);
14839 + au_set_h_iptr(inode, bindex, NULL, 0);
14840 + au_set_h_iptr(inode, bindex, au_igrab(hi),
14841 + flags & ~AuHi_XINO);
14844 + /* mutex_unlock(&hi->i_mutex); */
14848 +/* ---------------------------------------------------------------------- */
14850 +static int hn_xino(struct inode *inode, struct inode *h_inode)
14853 + aufs_bindex_t bindex, bend, bfound, bstart;
14854 + struct inode *h_i;
14857 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14858 + pr_warn("branch root dir was changed\n");
14863 + bend = au_ibend(inode);
14864 + bstart = au_ibstart(inode);
14865 +#if 0 /* reserved for future use */
14866 + if (bindex == bend) {
14867 + /* keep this ino in rename case */
14871 + for (bindex = bstart; bindex <= bend; bindex++)
14872 + if (au_h_iptr(inode, bindex) == h_inode) {
14879 + for (bindex = bstart; bindex <= bend; bindex++) {
14880 + h_i = au_h_iptr(inode, bindex);
14884 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
14885 + /* ignore this error */
14886 + /* bad action? */
14889 + /* children inode number will be broken */
14896 +static int hn_gen_tree(struct dentry *dentry)
14898 + int err, i, j, ndentry;
14899 + struct au_dcsub_pages dpages;
14900 + struct au_dpage *dpage;
14901 + struct dentry **dentries;
14903 + err = au_dpages_init(&dpages, GFP_NOFS);
14904 + if (unlikely(err))
14906 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
14907 + if (unlikely(err))
14910 + for (i = 0; i < dpages.ndpage; i++) {
14911 + dpage = dpages.dpages + i;
14912 + dentries = dpage->dentries;
14913 + ndentry = dpage->ndentry;
14914 + for (j = 0; j < ndentry; j++) {
14915 + struct dentry *d;
14922 + if (d_really_is_positive(d))
14923 + /* todo: reset children xino?
14924 + cached children only? */
14925 + au_iigen_dec(d_inode(d));
14930 + au_dpages_free(&dpages);
14933 + /* discard children */
14934 + dentry_unhash(dentry);
14942 + * return 0 if processed.
14944 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
14945 + const unsigned int isdir)
14948 + struct dentry *d;
14949 + struct qstr *dname;
14952 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
14953 + pr_warn("branch root dir was changed\n");
14959 + AuDebugOn(!name);
14960 + au_iigen_dec(inode);
14961 + spin_lock(&inode->i_lock);
14962 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
14963 + spin_lock(&d->d_lock);
14964 + dname = &d->d_name;
14965 + if (dname->len != nlen
14966 + && memcmp(dname->name, name, nlen)) {
14967 + spin_unlock(&d->d_lock);
14972 + spin_unlock(&d->d_lock);
14975 + spin_unlock(&inode->i_lock);
14977 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
14978 + d = d_find_any_alias(inode);
14980 + au_iigen_dec(inode);
14984 + spin_lock(&d->d_lock);
14985 + dname = &d->d_name;
14986 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
14987 + spin_unlock(&d->d_lock);
14988 + err = hn_gen_tree(d);
14989 + spin_lock(&d->d_lock);
14991 + spin_unlock(&d->d_lock);
15000 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15004 + if (IS_ROOT(dentry)) {
15005 + pr_warn("branch root dir was changed\n");
15011 + au_digen_dec(dentry);
15012 + if (d_really_is_positive(dentry))
15013 + au_iigen_dec(d_inode(dentry));
15015 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15016 + if (d_really_is_positive(dentry))
15017 + err = hn_gen_tree(dentry);
15024 +/* ---------------------------------------------------------------------- */
15026 +/* hnotify job flags */
15027 +#define AuHnJob_XINO0 1
15028 +#define AuHnJob_GEN (1 << 1)
15029 +#define AuHnJob_DIRENT (1 << 2)
15030 +#define AuHnJob_ISDIR (1 << 3)
15031 +#define AuHnJob_TRYXINO0 (1 << 4)
15032 +#define AuHnJob_MNTPNT (1 << 5)
15033 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15034 +#define au_fset_hnjob(flags, name) \
15035 + do { (flags) |= AuHnJob_##name; } while (0)
15036 +#define au_fclr_hnjob(flags, name) \
15037 + do { (flags) &= ~AuHnJob_##name; } while (0)
15045 +struct au_hnotify_args {
15046 + struct inode *h_dir, *dir, *h_child_inode;
15048 + unsigned int flags[AuHnLast];
15049 + unsigned int h_child_nlen;
15050 + char h_child_name[];
15053 +struct hn_job_args {
15054 + unsigned int flags;
15055 + struct inode *inode, *h_inode, *dir, *h_dir;
15056 + struct dentry *dentry;
15061 +static int hn_job(struct hn_job_args *a)
15063 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15067 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15068 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15070 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15073 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
15074 + if (!a->h_inode->i_nlink
15075 + && !(a->h_inode->i_state & I_LINKABLE))
15076 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15077 + mutex_unlock(&a->h_inode->i_mutex);
15080 + /* make the generation obsolete */
15081 + if (au_ftest_hnjob(a->flags, GEN)) {
15084 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15086 + if (e && a->dentry)
15087 + hn_gen_by_name(a->dentry, isdir);
15088 + /* ignore this error */
15091 + /* make dir entries obsolete */
15092 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15093 + struct au_vdir *vdir;
15095 + vdir = au_ivdir(a->inode);
15097 + vdir->vd_jiffy = 0;
15098 + /* IMustLock(a->inode); */
15099 + /* a->inode->i_version++; */
15102 + /* can do nothing but warn */
15103 + if (au_ftest_hnjob(a->flags, MNTPNT)
15105 + && d_mountpoint(a->dentry))
15106 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15111 +/* ---------------------------------------------------------------------- */
15113 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15114 + struct inode *dir)
15116 + struct dentry *dentry, *d, *parent;
15117 + struct qstr *dname;
15119 + parent = d_find_any_alias(dir);
15124 + spin_lock(&parent->d_lock);
15125 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15126 + /* AuDbg("%pd\n", d); */
15127 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15128 + dname = &d->d_name;
15129 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15130 + goto cont_unlock;
15134 + goto cont_unlock;
15135 + if (au_dcount(d) > 0) {
15136 + dentry = dget_dlock(d);
15137 + spin_unlock(&d->d_lock);
15142 + spin_unlock(&d->d_lock);
15144 + spin_unlock(&parent->d_lock);
15148 + di_write_lock_child(dentry);
15153 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15154 + aufs_bindex_t bindex, ino_t h_ino)
15156 + struct inode *inode;
15161 + err = au_xino_read(sb, bindex, h_ino, &ino);
15163 + inode = ilookup(sb, ino);
15167 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15168 + pr_warn("wrong root branch\n");
15174 + ii_write_lock_child(inode);
15180 +static void au_hn_bh(void *_args)
15182 + struct au_hnotify_args *a = _args;
15183 + struct super_block *sb;
15184 + aufs_bindex_t bindex, bend, bfound;
15185 + unsigned char xino, try_iput;
15187 + struct inode *inode;
15189 + struct hn_job_args args;
15190 + struct dentry *dentry;
15191 + struct au_sbinfo *sbinfo;
15193 + AuDebugOn(!_args);
15194 + AuDebugOn(!a->h_dir);
15195 + AuDebugOn(!a->dir);
15196 + AuDebugOn(!a->mask);
15197 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15198 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15199 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15204 + * do not lock a->dir->i_mutex here
15205 + * because of d_revalidate() may cause a deadlock.
15207 + sb = a->dir->i_sb;
15209 + sbinfo = au_sbi(sb);
15210 + AuDebugOn(!sbinfo);
15211 + si_write_lock(sb, AuLock_NOPLMW);
15213 + ii_read_lock_parent(a->dir);
15215 + bend = au_ibend(a->dir);
15216 + for (bindex = au_ibstart(a->dir); bindex <= bend; bindex++)
15217 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15221 + ii_read_unlock(a->dir);
15222 + if (unlikely(bfound < 0))
15225 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15227 + if (a->h_child_inode)
15228 + h_ino = a->h_child_inode->i_ino;
15230 + if (a->h_child_nlen
15231 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15232 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15233 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15236 + if (dentry && d_really_is_positive(dentry))
15237 + inode = d_inode(dentry);
15238 + if (xino && !inode && h_ino
15239 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15240 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15241 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15242 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15246 + args.flags = a->flags[AuHn_CHILD];
15247 + args.dentry = dentry;
15248 + args.inode = inode;
15249 + args.h_inode = a->h_child_inode;
15250 + args.dir = a->dir;
15251 + args.h_dir = a->h_dir;
15252 + args.h_name = a->h_child_name;
15253 + args.h_nlen = a->h_child_nlen;
15254 + err = hn_job(&args);
15256 + if (au_di(dentry))
15257 + di_write_unlock(dentry);
15260 + if (inode && try_iput) {
15261 + ii_write_unlock(inode);
15265 + ii_write_lock_parent(a->dir);
15266 + args.flags = a->flags[AuHn_PARENT];
15267 + args.dentry = NULL;
15268 + args.inode = a->dir;
15269 + args.h_inode = a->h_dir;
15271 + args.h_dir = NULL;
15272 + args.h_name = NULL;
15274 + err = hn_job(&args);
15275 + ii_write_unlock(a->dir);
15278 + iput(a->h_child_inode);
15281 + si_write_unlock(sb);
15282 + au_nwt_done(&sbinfo->si_nowait);
15286 +/* ---------------------------------------------------------------------- */
15288 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15289 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15292 + unsigned int flags[AuHnLast], f;
15293 + unsigned char isdir, isroot, wh;
15294 + struct inode *dir;
15295 + struct au_hnotify_args *args;
15296 + char *p, *h_child_name;
15299 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15300 + dir = igrab(hnotify->hn_aufs_inode);
15304 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15306 + h_child_name = (void *)h_child_qstr->name;
15307 + len = h_child_qstr->len;
15308 + if (h_child_name) {
15309 + if (len > AUFS_WH_PFX_LEN
15310 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15311 + h_child_name += AUFS_WH_PFX_LEN;
15312 + len -= AUFS_WH_PFX_LEN;
15318 + if (h_child_inode)
15319 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15320 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15321 + flags[AuHn_CHILD] = 0;
15323 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15324 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15325 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15326 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15327 + case FS_MOVED_FROM:
15328 + case FS_MOVED_TO:
15329 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15330 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15333 + AuDebugOn(!h_child_name);
15338 + * aufs never be able to get this child inode.
15339 + * revalidation should be in d_revalidate()
15340 + * by checking i_nlink, i_generation or d_unhashed().
15342 + AuDebugOn(!h_child_name);
15343 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15344 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15352 + h_child_inode = NULL;
15355 + /* iput() and kfree() will be called in au_hnotify() */
15356 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15357 + if (unlikely(!args)) {
15358 + AuErr1("no memory\n");
15362 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15363 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15364 + args->mask = mask;
15366 + args->h_dir = igrab(h_dir);
15367 + if (h_child_inode)
15368 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15369 + args->h_child_inode = h_child_inode;
15370 + args->h_child_nlen = len;
15372 + p = (void *)args;
15373 + p += sizeof(*args);
15374 + memcpy(p, h_child_name, len);
15378 + /* NFS fires the event for silly-renamed one from kworker */
15380 + if (!dir->i_nlink
15381 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15383 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15384 + if (unlikely(err)) {
15385 + pr_err("wkq %d\n", err);
15386 + iput(args->h_child_inode);
15387 + iput(args->h_dir);
15396 +/* ---------------------------------------------------------------------- */
15398 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15402 + AuDebugOn(!(udba & AuOptMask_UDBA));
15405 + if (au_hnotify_op.reset_br)
15406 + err = au_hnotify_op.reset_br(udba, br, perm);
15411 +int au_hnotify_init_br(struct au_branch *br, int perm)
15416 + if (au_hnotify_op.init_br)
15417 + err = au_hnotify_op.init_br(br, perm);
15422 +void au_hnotify_fin_br(struct au_branch *br)
15424 + if (au_hnotify_op.fin_br)
15425 + au_hnotify_op.fin_br(br);
15428 +static void au_hn_destroy_cache(void)
15430 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15431 + au_cachep[AuCache_HNOTIFY] = NULL;
15434 +int __init au_hnotify_init(void)
15439 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15440 + if (au_cachep[AuCache_HNOTIFY]) {
15442 + if (au_hnotify_op.init)
15443 + err = au_hnotify_op.init();
15444 + if (unlikely(err))
15445 + au_hn_destroy_cache();
15451 +void au_hnotify_fin(void)
15453 + if (au_hnotify_op.fin)
15454 + au_hnotify_op.fin();
15455 + /* cf. au_cache_fin() */
15456 + if (au_cachep[AuCache_HNOTIFY])
15457 + au_hn_destroy_cache();
15459 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15460 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15461 +++ linux/fs/aufs/iinfo.c 2015-09-24 10:47:58.254719746 +0200
15464 + * Copyright (C) 2005-2015 Junjiro R. Okajima
15466 + * This program, aufs is free software; you can redistribute it and/or modify
15467 + * it under the terms of the GNU General Public License as published by
15468 + * the Free Software Foundation; either version 2 of the License, or
15469 + * (at your option) any later version.
15471 + * This program is distributed in the hope that it will be useful,
15472 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15473 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15474 + * GNU General Public License for more details.
15476 + * You should have received a copy of the GNU General Public License
15477 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15481 + * inode private data
15486 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15488 + struct inode *h_inode;
15490 + IiMustAnyLock(inode);
15492 + h_inode = au_ii(inode)->ii_hinode[0 + bindex].hi_inode;
15493 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15497 +/* todo: hard/soft set? */
15498 +void au_hiput(struct au_hinode *hinode)
15500 + au_hn_free(hinode);
15501 + dput(hinode->hi_whdentry);
15502 + iput(hinode->hi_inode);
15505 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15507 + unsigned int flags;
15508 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15511 + if (au_opt_test(mnt_flags, XINO))
15512 + au_fset_hi(flags, XINO);
15513 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15514 + au_fset_hi(flags, HNOTIFY);
15518 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15519 + struct inode *h_inode, unsigned int flags)
15521 + struct au_hinode *hinode;
15522 + struct inode *hi;
15523 + struct au_iinfo *iinfo = au_ii(inode);
15525 + IiMustWriteLock(inode);
15527 + hinode = iinfo->ii_hinode + bindex;
15528 + hi = hinode->hi_inode;
15529 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15532 + au_hiput(hinode);
15533 + hinode->hi_inode = h_inode;
15536 + struct super_block *sb = inode->i_sb;
15537 + struct au_branch *br;
15539 + AuDebugOn(inode->i_mode
15540 + && (h_inode->i_mode & S_IFMT)
15541 + != (inode->i_mode & S_IFMT));
15542 + if (bindex == iinfo->ii_bstart)
15543 + au_cpup_igen(inode, h_inode);
15544 + br = au_sbr(sb, bindex);
15545 + hinode->hi_id = br->br_id;
15546 + if (au_ftest_hi(flags, XINO)) {
15547 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15549 + if (unlikely(err))
15550 + AuIOErr1("failed au_xino_write() %d\n", err);
15553 + if (au_ftest_hi(flags, HNOTIFY)
15554 + && au_br_hnotifyable(br->br_perm)) {
15555 + err = au_hn_alloc(hinode, inode);
15556 + if (unlikely(err))
15557 + AuIOErr1("au_hn_alloc() %d\n", err);
15562 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15563 + struct dentry *h_wh)
15565 + struct au_hinode *hinode;
15567 + IiMustWriteLock(inode);
15569 + hinode = au_ii(inode)->ii_hinode + bindex;
15570 + AuDebugOn(hinode->hi_whdentry);
15571 + hinode->hi_whdentry = h_wh;
15574 +void au_update_iigen(struct inode *inode, int half)
15576 + struct au_iinfo *iinfo;
15577 + struct au_iigen *iigen;
15578 + unsigned int sigen;
15580 + sigen = au_sigen(inode->i_sb);
15581 + iinfo = au_ii(inode);
15582 + iigen = &iinfo->ii_generation;
15583 + spin_lock(&iinfo->ii_genspin);
15584 + iigen->ig_generation = sigen;
15586 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15588 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15589 + spin_unlock(&iinfo->ii_genspin);
15592 +/* it may be called at remount time, too */
15593 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15595 + struct au_iinfo *iinfo;
15596 + aufs_bindex_t bindex, bend;
15598 + iinfo = au_ii(inode);
15602 + IiMustWriteLock(inode);
15604 + if (do_put_zero && iinfo->ii_bstart >= 0) {
15605 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15607 + struct inode *h_i;
15609 + h_i = iinfo->ii_hinode[0 + bindex].hi_inode;
15612 + && !(h_i->i_state & I_LINKABLE))
15613 + au_set_h_iptr(inode, bindex, NULL, 0);
15617 + iinfo->ii_bstart = -1;
15618 + iinfo->ii_bend = -1;
15619 + bend = au_sbend(inode->i_sb);
15620 + for (bindex = 0; bindex <= bend; bindex++)
15621 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15622 + iinfo->ii_bstart = bindex;
15625 + if (iinfo->ii_bstart >= 0)
15626 + for (bindex = bend; bindex >= iinfo->ii_bstart; bindex--)
15627 + if (iinfo->ii_hinode[0 + bindex].hi_inode) {
15628 + iinfo->ii_bend = bindex;
15631 + AuDebugOn(iinfo->ii_bstart > iinfo->ii_bend);
15634 +/* ---------------------------------------------------------------------- */
15636 +void au_icntnr_init_once(void *_c)
15638 + struct au_icntnr *c = _c;
15639 + struct au_iinfo *iinfo = &c->iinfo;
15640 + static struct lock_class_key aufs_ii;
15642 + spin_lock_init(&iinfo->ii_genspin);
15643 + au_rw_init(&iinfo->ii_rwsem);
15644 + au_rw_class(&iinfo->ii_rwsem, &aufs_ii);
15645 + inode_init_once(&c->vfs_inode);
15648 +int au_iinfo_init(struct inode *inode)
15650 + struct au_iinfo *iinfo;
15651 + struct super_block *sb;
15654 + sb = inode->i_sb;
15655 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15656 + nbr = au_sbend(sb) + 1;
15657 + if (unlikely(nbr <= 0))
15659 + iinfo->ii_hinode = kcalloc(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15660 + if (iinfo->ii_hinode) {
15661 + au_ninodes_inc(sb);
15662 + for (i = 0; i < nbr; i++)
15663 + iinfo->ii_hinode[i].hi_id = -1;
15665 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15666 + iinfo->ii_bstart = -1;
15667 + iinfo->ii_bend = -1;
15668 + iinfo->ii_vdir = NULL;
15674 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr)
15677 + struct au_hinode *hip;
15679 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15682 + sz = sizeof(*hip) * (iinfo->ii_bend + 1);
15684 + sz = sizeof(*hip);
15685 + hip = au_kzrealloc(iinfo->ii_hinode, sz, sizeof(*hip) * nbr, GFP_NOFS);
15687 + iinfo->ii_hinode = hip;
15694 +void au_iinfo_fin(struct inode *inode)
15696 + struct au_iinfo *iinfo;
15697 + struct au_hinode *hi;
15698 + struct super_block *sb;
15699 + aufs_bindex_t bindex, bend;
15700 + const unsigned char unlinked = !inode->i_nlink;
15702 + iinfo = au_ii(inode);
15703 + /* bad_inode case */
15707 + sb = inode->i_sb;
15708 + au_ninodes_dec(sb);
15709 + if (si_pid_test(sb))
15710 + au_xino_delete_inode(inode, unlinked);
15713 + * it is safe to hide the dependency between sbinfo and
15717 + si_noflush_read_lock(sb);
15718 + au_xino_delete_inode(inode, unlinked);
15719 + si_read_unlock(sb);
15723 + if (iinfo->ii_vdir)
15724 + au_vdir_free(iinfo->ii_vdir);
15726 + bindex = iinfo->ii_bstart;
15727 + if (bindex >= 0) {
15728 + hi = iinfo->ii_hinode + bindex;
15729 + bend = iinfo->ii_bend;
15730 + while (bindex++ <= bend) {
15731 + if (hi->hi_inode)
15736 + kfree(iinfo->ii_hinode);
15737 + iinfo->ii_hinode = NULL;
15738 + AuRwDestroy(&iinfo->ii_rwsem);
15740 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
15741 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
15742 +++ linux/fs/aufs/inode.c 2015-09-24 10:47:58.254719746 +0200
15745 + * Copyright (C) 2005-2015 Junjiro R. Okajima
15747 + * This program, aufs is free software; you can redistribute it and/or modify
15748 + * it under the terms of the GNU General Public License as published by
15749 + * the Free Software Foundation; either version 2 of the License, or
15750 + * (at your option) any later version.
15752 + * This program is distributed in the hope that it will be useful,
15753 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15754 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15755 + * GNU General Public License for more details.
15757 + * You should have received a copy of the GNU General Public License
15758 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15762 + * inode functions
15767 +struct inode *au_igrab(struct inode *inode)
15770 + AuDebugOn(!atomic_read(&inode->i_count));
15776 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
15778 + au_cpup_attr_all(inode, /*force*/0);
15779 + au_update_iigen(inode, /*half*/1);
15781 + inode->i_version++;
15784 +static int au_ii_refresh(struct inode *inode, int *update)
15788 + aufs_bindex_t bindex, new_bindex;
15789 + struct super_block *sb;
15790 + struct au_iinfo *iinfo;
15791 + struct au_hinode *p, *q, tmp;
15793 + IiMustWriteLock(inode);
15796 + sb = inode->i_sb;
15797 + type = inode->i_mode & S_IFMT;
15798 + iinfo = au_ii(inode);
15799 + err = au_ii_realloc(iinfo, au_sbend(sb) + 1);
15800 + if (unlikely(err))
15803 + AuDebugOn(iinfo->ii_bstart < 0);
15804 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15805 + for (bindex = iinfo->ii_bstart; bindex <= iinfo->ii_bend;
15807 + if (!p->hi_inode)
15810 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
15811 + new_bindex = au_br_index(sb, p->hi_id);
15812 + if (new_bindex == bindex)
15815 + if (new_bindex < 0) {
15818 + p->hi_inode = NULL;
15822 + if (new_bindex < iinfo->ii_bstart)
15823 + iinfo->ii_bstart = new_bindex;
15824 + if (iinfo->ii_bend < new_bindex)
15825 + iinfo->ii_bend = new_bindex;
15826 + /* swap two lower inode, and loop again */
15827 + q = iinfo->ii_hinode + new_bindex;
15831 + if (tmp.hi_inode) {
15836 + au_update_ibrange(inode, /*do_put_zero*/0);
15837 + e = au_dy_irefresh(inode);
15838 + if (unlikely(e && !err))
15846 +int au_refresh_hinode_self(struct inode *inode)
15850 + err = au_ii_refresh(inode, &update);
15852 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
15858 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
15860 + int err, e, update;
15861 + unsigned int flags;
15863 + aufs_bindex_t bindex, bend;
15864 + unsigned char isdir;
15865 + struct au_hinode *p;
15866 + struct au_iinfo *iinfo;
15868 + err = au_ii_refresh(inode, &update);
15869 + if (unlikely(err))
15873 + iinfo = au_ii(inode);
15874 + p = iinfo->ii_hinode + iinfo->ii_bstart;
15875 + mode = (inode->i_mode & S_IFMT);
15876 + isdir = S_ISDIR(mode);
15877 + flags = au_hi_flags(inode, isdir);
15878 + bend = au_dbend(dentry);
15879 + for (bindex = au_dbstart(dentry); bindex <= bend; bindex++) {
15880 + struct inode *h_i, *h_inode;
15881 + struct dentry *h_d;
15883 + h_d = au_h_dptr(dentry, bindex);
15884 + if (!h_d || d_is_negative(h_d))
15887 + h_inode = d_inode(h_d);
15888 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
15889 + if (iinfo->ii_bstart <= bindex && bindex <= iinfo->ii_bend) {
15890 + h_i = au_h_iptr(inode, bindex);
15892 + if (h_i == h_inode)
15898 + if (bindex < iinfo->ii_bstart)
15899 + iinfo->ii_bstart = bindex;
15900 + if (iinfo->ii_bend < bindex)
15901 + iinfo->ii_bend = bindex;
15902 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
15905 + au_update_ibrange(inode, /*do_put_zero*/0);
15906 + e = au_dy_irefresh(inode);
15907 + if (unlikely(e && !err))
15910 + au_refresh_hinode_attr(inode, update && isdir);
15917 +static int set_inode(struct inode *inode, struct dentry *dentry)
15920 + unsigned int flags;
15922 + aufs_bindex_t bindex, bstart, btail;
15923 + unsigned char isdir;
15924 + struct dentry *h_dentry;
15925 + struct inode *h_inode;
15926 + struct au_iinfo *iinfo;
15928 + IiMustWriteLock(inode);
15932 + bstart = au_dbstart(dentry);
15933 + h_dentry = au_h_dptr(dentry, bstart);
15934 + h_inode = d_inode(h_dentry);
15935 + mode = h_inode->i_mode;
15936 + switch (mode & S_IFMT) {
15938 + btail = au_dbtail(dentry);
15939 + inode->i_op = &aufs_iop;
15940 + inode->i_fop = &aufs_file_fop;
15941 + err = au_dy_iaop(inode, bstart, h_inode);
15942 + if (unlikely(err))
15947 + btail = au_dbtaildir(dentry);
15948 + inode->i_op = &aufs_dir_iop;
15949 + inode->i_fop = &aufs_dir_fop;
15952 + btail = au_dbtail(dentry);
15953 + inode->i_op = &aufs_symlink_iop;
15959 + btail = au_dbtail(dentry);
15960 + inode->i_op = &aufs_iop;
15961 + init_special_inode(inode, mode, h_inode->i_rdev);
15964 + AuIOErr("Unknown file type 0%o\n", mode);
15969 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
15970 + flags = au_hi_flags(inode, isdir);
15971 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
15972 + && au_ftest_hi(flags, HNOTIFY)
15973 + && dentry->d_name.len > AUFS_WH_PFX_LEN
15974 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
15975 + au_fclr_hi(flags, HNOTIFY);
15976 + iinfo = au_ii(inode);
15977 + iinfo->ii_bstart = bstart;
15978 + iinfo->ii_bend = btail;
15979 + for (bindex = bstart; bindex <= btail; bindex++) {
15980 + h_dentry = au_h_dptr(dentry, bindex);
15982 + au_set_h_iptr(inode, bindex,
15983 + au_igrab(d_inode(h_dentry)), flags);
15985 + au_cpup_attr_all(inode, /*force*/1);
15987 + * to force calling aufs_get_acl() every time,
15988 + * do not call cache_no_acl() for aufs inode.
15996 + * successful returns with iinfo write_locked
15998 + * zero: success, matched
15999 + * plus: no error, but unmatched
16001 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16004 + unsigned int gen;
16005 + struct au_iigen iigen;
16006 + aufs_bindex_t bindex, bend;
16007 + struct inode *h_inode, *h_dinode;
16008 + struct dentry *h_dentry;
16011 + * before this function, if aufs got any iinfo lock, it must be only
16012 + * one, the parent dir.
16013 + * it can happen by UDBA and the obsoleted inode number.
16016 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16020 + ii_write_lock_new_child(inode);
16021 + h_dentry = au_h_dptr(dentry, au_dbstart(dentry));
16022 + h_dinode = d_inode(h_dentry);
16023 + bend = au_ibend(inode);
16024 + for (bindex = au_ibstart(inode); bindex <= bend; bindex++) {
16025 + h_inode = au_h_iptr(inode, bindex);
16026 + if (!h_inode || h_inode != h_dinode)
16030 + gen = au_iigen(inode, &iigen);
16031 + if (gen == au_digen(dentry)
16032 + && !au_ig_ftest(iigen.ig_flags, HALF_REFRESHED))
16035 + /* fully refresh inode using dentry */
16036 + err = au_refresh_hinode(inode, dentry);
16038 + au_update_iigen(inode, /*half*/0);
16042 + if (unlikely(err))
16043 + ii_write_unlock(inode);
16048 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16049 + unsigned int d_type, ino_t *ino)
16052 + struct mutex *mtx;
16054 + /* prevent hardlinked inode number from race condition */
16056 + if (d_type != DT_DIR) {
16057 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16060 + err = au_xino_read(sb, bindex, h_ino, ino);
16061 + if (unlikely(err))
16066 + *ino = au_xino_new_ino(sb);
16067 + if (unlikely(!*ino))
16069 + err = au_xino_write(sb, bindex, h_ino, *ino);
16070 + if (unlikely(err))
16076 + mutex_unlock(mtx);
16080 +/* successful returns with iinfo write_locked */
16081 +/* todo: return with unlocked? */
16082 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16084 + struct inode *inode, *h_inode;
16085 + struct dentry *h_dentry;
16086 + struct super_block *sb;
16087 + struct mutex *mtx;
16088 + ino_t h_ino, ino;
16090 + aufs_bindex_t bstart;
16092 + sb = dentry->d_sb;
16093 + bstart = au_dbstart(dentry);
16094 + h_dentry = au_h_dptr(dentry, bstart);
16095 + h_inode = d_inode(h_dentry);
16096 + h_ino = h_inode->i_ino;
16099 + * stop 'race'-ing between hardlinks under different
16103 + if (!d_is_dir(h_dentry))
16104 + mtx = &au_sbr(sb, bstart)->br_xino.xi_nondir_mtx;
16109 + err = au_xino_read(sb, bstart, h_ino, &ino);
16110 + inode = ERR_PTR(err);
16111 + if (unlikely(err))
16115 + ino = au_xino_new_ino(sb);
16116 + if (unlikely(!ino)) {
16117 + inode = ERR_PTR(-EIO);
16122 + AuDbg("i%lu\n", (unsigned long)ino);
16123 + inode = au_iget_locked(sb, ino);
16124 + err = PTR_ERR(inode);
16125 + if (IS_ERR(inode))
16128 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16129 + if (inode->i_state & I_NEW) {
16130 + /* verbose coding for lock class name */
16131 + if (unlikely(d_is_symlink(h_dentry)))
16132 + au_rw_class(&au_ii(inode)->ii_rwsem,
16133 + au_lc_key + AuLcSymlink_IIINFO);
16134 + else if (unlikely(d_is_dir(h_dentry)))
16135 + au_rw_class(&au_ii(inode)->ii_rwsem,
16136 + au_lc_key + AuLcDir_IIINFO);
16137 + else /* likely */
16138 + au_rw_class(&au_ii(inode)->ii_rwsem,
16139 + au_lc_key + AuLcNonDir_IIINFO);
16141 + ii_write_lock_new_child(inode);
16142 + err = set_inode(inode, dentry);
16144 + unlock_new_inode(inode);
16145 + goto out; /* success */
16149 + * iget_failed() calls iput(), but we need to call
16150 + * ii_write_unlock() after iget_failed(). so dirty hack for
16153 + atomic_inc(&inode->i_count);
16154 + iget_failed(inode);
16155 + ii_write_unlock(inode);
16156 + au_xino_write(sb, bstart, h_ino, /*ino*/0);
16157 + /* ignore this error */
16159 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16161 + * horrible race condition between lookup, readdir and copyup
16162 + * (or something).
16165 + mutex_unlock(mtx);
16166 + err = reval_inode(inode, dentry);
16167 + if (unlikely(err < 0)) {
16174 + goto out; /* success */
16179 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16180 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16181 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16182 + bstart, au_sbtype(h_dentry->d_sb), dentry,
16183 + (unsigned long)h_ino, (unsigned long)ino);
16185 + err = au_xino_write(sb, bstart, h_ino, /*ino*/0);
16189 + mutex_unlock(mtx);
16195 + inode = ERR_PTR(err);
16198 + mutex_unlock(mtx);
16202 +/* ---------------------------------------------------------------------- */
16204 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16205 + struct inode *inode)
16208 + struct inode *hi;
16210 + err = au_br_rdonly(au_sbr(sb, bindex));
16212 + /* pseudo-link after flushed may happen out of bounds */
16215 + && au_ibstart(inode) <= bindex
16216 + && bindex <= au_ibend(inode)) {
16218 + * permission check is unnecessary since vfsub routine
16219 + * will be called later
16221 + hi = au_h_iptr(inode, bindex);
16223 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16229 +int au_test_h_perm(struct inode *h_inode, int mask)
16231 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16233 + return inode_permission(h_inode, mask);
16236 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16238 + if (au_test_nfs(h_inode->i_sb)
16239 + && (mask & MAY_WRITE)
16240 + && S_ISDIR(h_inode->i_mode))
16241 + mask |= MAY_READ; /* force permission check */
16242 + return au_test_h_perm(h_inode, mask);
16244 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16245 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16246 +++ linux/fs/aufs/inode.h 2015-09-24 10:47:58.254719746 +0200
16249 + * Copyright (C) 2005-2015 Junjiro R. Okajima
16251 + * This program, aufs is free software; you can redistribute it and/or modify
16252 + * it under the terms of the GNU General Public License as published by
16253 + * the Free Software Foundation; either version 2 of the License, or
16254 + * (at your option) any later version.
16256 + * This program is distributed in the hope that it will be useful,
16257 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16258 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16259 + * GNU General Public License for more details.
16261 + * You should have received a copy of the GNU General Public License
16262 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16266 + * inode operations
16269 +#ifndef __AUFS_INODE_H__
16270 +#define __AUFS_INODE_H__
16274 +#include <linux/fsnotify.h>
16275 +#include "rwsem.h"
16279 +struct au_hnotify {
16280 +#ifdef CONFIG_AUFS_HNOTIFY
16281 +#ifdef CONFIG_AUFS_HFSNOTIFY
16282 + /* never use fsnotify_add_vfsmount_mark() */
16283 + struct fsnotify_mark hn_mark;
16285 + struct inode *hn_aufs_inode; /* no get/put */
16287 +} ____cacheline_aligned_in_smp;
16289 +struct au_hinode {
16290 + struct inode *hi_inode;
16291 + aufs_bindex_t hi_id;
16292 +#ifdef CONFIG_AUFS_HNOTIFY
16293 + struct au_hnotify *hi_notify;
16296 + /* reference to the copied-up whiteout with get/put */
16297 + struct dentry *hi_whdentry;
16301 +#define AuIG_HALF_REFRESHED 1
16302 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16303 +#define au_ig_fset(flags, name) \
16304 + do { (flags) |= AuIG_##name; } while (0)
16305 +#define au_ig_fclr(flags, name) \
16306 + do { (flags) &= ~AuIG_##name; } while (0)
16309 + __u32 ig_generation, ig_flags;
16314 + spinlock_t ii_genspin;
16315 + struct au_iigen ii_generation;
16316 + struct super_block *ii_hsb1; /* no get/put */
16318 + struct au_rwsem ii_rwsem;
16319 + aufs_bindex_t ii_bstart, ii_bend;
16321 + struct au_hinode *ii_hinode;
16322 + struct au_vdir *ii_vdir;
16325 +struct au_icntnr {
16326 + struct au_iinfo iinfo;
16327 + struct inode vfs_inode;
16328 +} ____cacheline_aligned_in_smp;
16330 +/* au_pin flags */
16331 +#define AuPin_DI_LOCKED 1
16332 +#define AuPin_MNT_WRITE (1 << 1)
16333 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16334 +#define au_fset_pin(flags, name) \
16335 + do { (flags) |= AuPin_##name; } while (0)
16336 +#define au_fclr_pin(flags, name) \
16337 + do { (flags) &= ~AuPin_##name; } while (0)
16341 + struct dentry *dentry;
16342 + unsigned int udba;
16343 + unsigned char lsc_di, lsc_hi, flags;
16344 + aufs_bindex_t bindex;
16347 + struct dentry *parent;
16348 + struct au_hinode *hdir;
16349 + struct vfsmount *h_mnt;
16351 + /* temporary unlock/relock for copyup */
16352 + struct dentry *h_dentry, *h_parent;
16353 + struct au_branch *br;
16354 + struct task_struct *task;
16357 +void au_pin_hdir_unlock(struct au_pin *p);
16358 +int au_pin_hdir_lock(struct au_pin *p);
16359 +int au_pin_hdir_relock(struct au_pin *p);
16360 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task);
16361 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16362 +void au_pin_hdir_release(struct au_pin *p);
16364 +/* ---------------------------------------------------------------------- */
16366 +static inline struct au_iinfo *au_ii(struct inode *inode)
16368 + struct au_iinfo *iinfo;
16370 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16371 + if (iinfo->ii_hinode)
16373 + return NULL; /* debugging bad_inode case */
16376 +/* ---------------------------------------------------------------------- */
16379 +struct inode *au_igrab(struct inode *inode);
16380 +int au_refresh_hinode_self(struct inode *inode);
16381 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16382 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16383 + unsigned int d_type, ino_t *ino);
16384 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16385 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16386 + struct inode *inode);
16387 +int au_test_h_perm(struct inode *h_inode, int mask);
16388 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16390 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16391 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16393 +#ifdef CONFIG_AUFS_SHWH
16394 + return au_ino(sb, bindex, h_ino, d_type, ino);
16401 +extern struct inode_operations aufs_iop, aufs_symlink_iop, aufs_dir_iop;
16403 +/* au_wr_dir flags */
16404 +#define AuWrDir_ADD_ENTRY 1
16405 +#define AuWrDir_ISDIR (1 << 1)
16406 +#define AuWrDir_TMPFILE (1 << 2)
16407 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16408 +#define au_fset_wrdir(flags, name) \
16409 + do { (flags) |= AuWrDir_##name; } while (0)
16410 +#define au_fclr_wrdir(flags, name) \
16411 + do { (flags) &= ~AuWrDir_##name; } while (0)
16413 +struct au_wr_dir_args {
16414 + aufs_bindex_t force_btgt;
16415 + unsigned char flags;
16417 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16418 + struct au_wr_dir_args *args);
16420 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16421 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16422 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16423 + unsigned int udba, unsigned char flags);
16424 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16425 + unsigned int udba, unsigned char flags) __must_check;
16426 +int au_do_pin(struct au_pin *pin) __must_check;
16427 +void au_unpin(struct au_pin *pin);
16428 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16430 +#define AuIcpup_DID_CPUP 1
16431 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16432 +#define au_fset_icpup(flags, name) \
16433 + do { (flags) |= AuIcpup_##name; } while (0)
16434 +#define au_fclr_icpup(flags, name) \
16435 + do { (flags) &= ~AuIcpup_##name; } while (0)
16437 +struct au_icpup_args {
16438 + unsigned char flags;
16439 + unsigned char pin_flags;
16440 + aufs_bindex_t btgt;
16441 + unsigned int udba;
16442 + struct au_pin pin;
16443 + struct path h_path;
16444 + struct inode *h_inode;
16447 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16448 + struct au_icpup_args *a);
16450 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16453 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16454 + struct dentry *h_parent, int isdir);
16455 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16457 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16458 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16460 +struct vfsub_aopen_args;
16461 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
16462 + struct vfsub_aopen_args *args);
16463 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16464 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16465 + struct dentry *dentry);
16466 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16469 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16470 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16471 + struct dentry *h_parent, int isdir);
16472 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16473 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16476 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16477 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16478 + struct inode *dir, struct dentry *dentry);
16481 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16482 +void au_hiput(struct au_hinode *hinode);
16483 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16484 + struct dentry *h_wh);
16485 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16487 +/* hinode flags */
16488 +#define AuHi_XINO 1
16489 +#define AuHi_HNOTIFY (1 << 1)
16490 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16491 +#define au_fset_hi(flags, name) \
16492 + do { (flags) |= AuHi_##name; } while (0)
16493 +#define au_fclr_hi(flags, name) \
16494 + do { (flags) &= ~AuHi_##name; } while (0)
16496 +#ifndef CONFIG_AUFS_HNOTIFY
16497 +#undef AuHi_HNOTIFY
16498 +#define AuHi_HNOTIFY 0
16501 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16502 + struct inode *h_inode, unsigned int flags);
16504 +void au_update_iigen(struct inode *inode, int half);
16505 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16507 +void au_icntnr_init_once(void *_c);
16508 +int au_iinfo_init(struct inode *inode);
16509 +void au_iinfo_fin(struct inode *inode);
16510 +int au_ii_realloc(struct au_iinfo *iinfo, int nbr);
16512 +#ifdef CONFIG_PROC_FS
16514 +int au_plink_maint(struct super_block *sb, int flags);
16516 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16517 +int au_plink_maint_enter(struct super_block *sb);
16518 +#ifdef CONFIG_AUFS_DEBUG
16519 +void au_plink_list(struct super_block *sb);
16521 +AuStubVoid(au_plink_list, struct super_block *sb)
16523 +int au_plink_test(struct inode *inode);
16524 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16525 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16526 + struct dentry *h_dentry);
16527 +void au_plink_put(struct super_block *sb, int verbose);
16528 +void au_plink_clean(struct super_block *sb, int verbose);
16529 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16531 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16532 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16533 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16534 +AuStubVoid(au_plink_list, struct super_block *sb);
16535 +AuStubInt0(au_plink_test, struct inode *inode);
16536 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16537 + struct inode *inode, aufs_bindex_t bindex);
16538 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16539 + struct dentry *h_dentry);
16540 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16541 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16542 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16543 +#endif /* CONFIG_PROC_FS */
16545 +#ifdef CONFIG_AUFS_XATTR
16547 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
16548 + unsigned int verbose);
16549 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16550 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
16552 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
16553 + size_t size, int flags);
16554 +int aufs_removexattr(struct dentry *dentry, const char *name);
16556 +/* void au_xattr_init(struct super_block *sb); */
16558 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16559 + int ignore_flags, unsigned int verbose);
16560 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
16563 +#ifdef CONFIG_FS_POSIX_ACL
16564 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16565 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16568 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16575 +struct au_srxattr {
16579 + const char *name;
16580 + const void *value;
16585 + const char *name;
16588 + struct posix_acl *acl;
16593 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg);
16596 +/* ---------------------------------------------------------------------- */
16598 +/* lock subclass for iinfo */
16600 + AuLsc_II_CHILD, /* child first */
16601 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16602 + AuLsc_II_CHILD3, /* copyup dirs */
16603 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16604 + AuLsc_II_PARENT2,
16605 + AuLsc_II_PARENT3, /* copyup dirs */
16606 + AuLsc_II_NEW_CHILD
16610 + * ii_read_lock_child, ii_write_lock_child,
16611 + * ii_read_lock_child2, ii_write_lock_child2,
16612 + * ii_read_lock_child3, ii_write_lock_child3,
16613 + * ii_read_lock_parent, ii_write_lock_parent,
16614 + * ii_read_lock_parent2, ii_write_lock_parent2,
16615 + * ii_read_lock_parent3, ii_write_lock_parent3,
16616 + * ii_read_lock_new_child, ii_write_lock_new_child,
16618 +#define AuReadLockFunc(name, lsc) \
16619 +static inline void ii_read_lock_##name(struct inode *i) \
16621 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16624 +#define AuWriteLockFunc(name, lsc) \
16625 +static inline void ii_write_lock_##name(struct inode *i) \
16627 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16630 +#define AuRWLockFuncs(name, lsc) \
16631 + AuReadLockFunc(name, lsc) \
16632 + AuWriteLockFunc(name, lsc)
16634 +AuRWLockFuncs(child, CHILD);
16635 +AuRWLockFuncs(child2, CHILD2);
16636 +AuRWLockFuncs(child3, CHILD3);
16637 +AuRWLockFuncs(parent, PARENT);
16638 +AuRWLockFuncs(parent2, PARENT2);
16639 +AuRWLockFuncs(parent3, PARENT3);
16640 +AuRWLockFuncs(new_child, NEW_CHILD);
16642 +#undef AuReadLockFunc
16643 +#undef AuWriteLockFunc
16644 +#undef AuRWLockFuncs
16647 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
16649 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
16651 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
16652 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
16653 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
16655 +/* ---------------------------------------------------------------------- */
16657 +static inline void au_icntnr_init(struct au_icntnr *c)
16659 +#ifdef CONFIG_AUFS_DEBUG
16660 + c->vfs_inode.i_mode = 0;
16664 +static inline unsigned int au_iigen(struct inode *inode, struct au_iigen *iigen)
16666 + unsigned int gen;
16667 + struct au_iinfo *iinfo;
16669 + iinfo = au_ii(inode);
16670 + spin_lock(&iinfo->ii_genspin);
16672 + *iigen = iinfo->ii_generation;
16673 + gen = iinfo->ii_generation.ig_generation;
16674 + spin_unlock(&iinfo->ii_genspin);
16679 +/* tiny test for inode number */
16680 +/* tmpfs generation is too rough */
16681 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
16683 + struct au_iinfo *iinfo;
16685 + iinfo = au_ii(inode);
16686 + AuRwMustAnyLock(&iinfo->ii_rwsem);
16687 + return !(iinfo->ii_hsb1 == h_inode->i_sb
16688 + && iinfo->ii_higen == h_inode->i_generation);
16691 +static inline void au_iigen_dec(struct inode *inode)
16693 + struct au_iinfo *iinfo;
16695 + iinfo = au_ii(inode);
16696 + spin_lock(&iinfo->ii_genspin);
16697 + iinfo->ii_generation.ig_generation--;
16698 + spin_unlock(&iinfo->ii_genspin);
16701 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
16706 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
16712 +/* ---------------------------------------------------------------------- */
16714 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
16715 + aufs_bindex_t bindex)
16717 + IiMustAnyLock(inode);
16718 + return au_ii(inode)->ii_hinode[0 + bindex].hi_id;
16721 +static inline aufs_bindex_t au_ibstart(struct inode *inode)
16723 + IiMustAnyLock(inode);
16724 + return au_ii(inode)->ii_bstart;
16727 +static inline aufs_bindex_t au_ibend(struct inode *inode)
16729 + IiMustAnyLock(inode);
16730 + return au_ii(inode)->ii_bend;
16733 +static inline struct au_vdir *au_ivdir(struct inode *inode)
16735 + IiMustAnyLock(inode);
16736 + return au_ii(inode)->ii_vdir;
16739 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
16741 + IiMustAnyLock(inode);
16742 + return au_ii(inode)->ii_hinode[0 + bindex].hi_whdentry;
16745 +static inline void au_set_ibstart(struct inode *inode, aufs_bindex_t bindex)
16747 + IiMustWriteLock(inode);
16748 + au_ii(inode)->ii_bstart = bindex;
16751 +static inline void au_set_ibend(struct inode *inode, aufs_bindex_t bindex)
16753 + IiMustWriteLock(inode);
16754 + au_ii(inode)->ii_bend = bindex;
16757 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
16759 + IiMustWriteLock(inode);
16760 + au_ii(inode)->ii_vdir = vdir;
16763 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
16765 + IiMustAnyLock(inode);
16766 + return au_ii(inode)->ii_hinode + bindex;
16769 +/* ---------------------------------------------------------------------- */
16771 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
16774 + return pin->parent;
16778 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
16780 + if (pin && pin->hdir)
16781 + return pin->hdir->hi_inode;
16785 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
16788 + return pin->hdir;
16792 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
16795 + pin->dentry = dentry;
16798 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
16799 + unsigned char lflag)
16803 + au_fset_pin(pin->flags, DI_LOCKED);
16805 + au_fclr_pin(pin->flags, DI_LOCKED);
16809 +#if 0 /* reserved */
16810 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
16813 + dput(pin->parent);
16814 + pin->parent = dget(parent);
16819 +/* ---------------------------------------------------------------------- */
16822 +#ifdef CONFIG_AUFS_HNOTIFY
16823 +struct au_hnotify_op {
16824 + void (*ctl)(struct au_hinode *hinode, int do_set);
16825 + int (*alloc)(struct au_hinode *hinode);
16828 + * if it returns true, the the caller should free hinode->hi_notify,
16829 + * otherwise ->free() frees it.
16831 + int (*free)(struct au_hinode *hinode,
16832 + struct au_hnotify *hn) __must_check;
16834 + void (*fin)(void);
16835 + int (*init)(void);
16837 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
16838 + void (*fin_br)(struct au_branch *br);
16839 + int (*init_br)(struct au_branch *br, int perm);
16843 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
16844 +void au_hn_free(struct au_hinode *hinode);
16845 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
16846 +void au_hn_reset(struct inode *inode, unsigned int flags);
16847 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
16848 + struct qstr *h_child_qstr, struct inode *h_child_inode);
16849 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
16850 +int au_hnotify_init_br(struct au_branch *br, int perm);
16851 +void au_hnotify_fin_br(struct au_branch *br);
16852 +int __init au_hnotify_init(void);
16853 +void au_hnotify_fin(void);
16856 +extern const struct au_hnotify_op au_hnotify_op;
16859 +void au_hn_init(struct au_hinode *hinode)
16861 + hinode->hi_notify = NULL;
16864 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
16866 + return hinode->hi_notify;
16870 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
16871 + struct au_hinode *hinode __maybe_unused,
16872 + struct inode *inode __maybe_unused)
16873 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
16874 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
16875 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
16876 + int do_set __maybe_unused)
16877 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
16878 + unsigned int flags __maybe_unused)
16879 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
16880 + struct au_branch *br __maybe_unused,
16881 + int perm __maybe_unused)
16882 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
16883 + int perm __maybe_unused)
16884 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
16885 +AuStubInt0(__init au_hnotify_init, void)
16886 +AuStubVoid(au_hnotify_fin, void)
16887 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
16888 +#endif /* CONFIG_AUFS_HNOTIFY */
16890 +static inline void au_hn_suspend(struct au_hinode *hdir)
16892 + au_hn_ctl(hdir, /*do_set*/0);
16895 +static inline void au_hn_resume(struct au_hinode *hdir)
16897 + au_hn_ctl(hdir, /*do_set*/1);
16900 +static inline void au_hn_imtx_lock(struct au_hinode *hdir)
16902 + mutex_lock(&hdir->hi_inode->i_mutex);
16903 + au_hn_suspend(hdir);
16906 +static inline void au_hn_imtx_lock_nested(struct au_hinode *hdir,
16907 + unsigned int sc __maybe_unused)
16909 + mutex_lock_nested(&hdir->hi_inode->i_mutex, sc);
16910 + au_hn_suspend(hdir);
16913 +static inline void au_hn_imtx_unlock(struct au_hinode *hdir)
16915 + au_hn_resume(hdir);
16916 + mutex_unlock(&hdir->hi_inode->i_mutex);
16919 +#endif /* __KERNEL__ */
16920 +#endif /* __AUFS_INODE_H__ */
16921 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
16922 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
16923 +++ linux/fs/aufs/ioctl.c 2015-09-24 10:47:58.254719746 +0200
16926 + * Copyright (C) 2005-2015 Junjiro R. Okajima
16928 + * This program, aufs is free software; you can redistribute it and/or modify
16929 + * it under the terms of the GNU General Public License as published by
16930 + * the Free Software Foundation; either version 2 of the License, or
16931 + * (at your option) any later version.
16933 + * This program is distributed in the hope that it will be useful,
16934 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16935 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16936 + * GNU General Public License for more details.
16938 + * You should have received a copy of the GNU General Public License
16939 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16944 + * plink-management and readdir in userspace.
16945 + * assist the pathconf(3) wrapper library.
16947 + * File-based Hierarchical Storage Management.
16950 +#include <linux/compat.h>
16951 +#include <linux/file.h>
16954 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
16957 + aufs_bindex_t wbi, bindex, bend;
16958 + struct file *h_file;
16959 + struct super_block *sb;
16960 + struct dentry *root;
16961 + struct au_branch *br;
16962 + struct aufs_wbr_fd wbrfd = {
16963 + .oflags = au_dir_roflags,
16966 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
16967 + | O_NOATIME | O_CLOEXEC;
16969 + AuDebugOn(wbrfd.oflags & ~valid);
16972 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
16973 + if (unlikely(err)) {
16979 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
16980 + wbrfd.oflags |= au_dir_roflags;
16981 + AuDbg("0%o\n", wbrfd.oflags);
16982 + if (unlikely(wbrfd.oflags & ~valid))
16986 + fd = get_unused_fd_flags(0);
16988 + if (unlikely(fd < 0))
16991 + h_file = ERR_PTR(-EINVAL);
16994 + sb = path->dentry->d_sb;
16995 + root = sb->s_root;
16996 + aufs_read_lock(root, AuLock_IR);
16997 + bend = au_sbend(sb);
16998 + if (wbrfd.brid >= 0) {
16999 + wbi = au_br_index(sb, wbrfd.brid);
17000 + if (unlikely(wbi < 0 || wbi > bend))
17004 + h_file = ERR_PTR(-ENOENT);
17005 + br = au_sbr(sb, wbi);
17006 + if (!au_br_writable(br->br_perm)) {
17010 + bindex = wbi + 1;
17012 + for (; bindex <= bend; bindex++) {
17013 + br = au_sbr(sb, bindex);
17014 + if (au_br_writable(br->br_perm)) {
17016 + br = au_sbr(sb, wbi);
17021 + AuDbg("wbi %d\n", wbi);
17023 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17027 + aufs_read_unlock(root, AuLock_IR);
17028 + err = PTR_ERR(h_file);
17029 + if (IS_ERR(h_file))
17032 + atomic_dec(&br->br_count); /* cf. au_h_open() */
17033 + fd_install(fd, h_file);
17035 + goto out; /* success */
17038 + put_unused_fd(fd);
17044 +/* ---------------------------------------------------------------------- */
17046 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17049 + struct dentry *dentry;
17052 + case AUFS_CTL_RDU:
17053 + case AUFS_CTL_RDU_INO:
17054 + err = au_rdu_ioctl(file, cmd, arg);
17057 + case AUFS_CTL_WBR_FD:
17058 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17061 + case AUFS_CTL_IBUSY:
17062 + err = au_ibusy_ioctl(file, arg);
17065 + case AUFS_CTL_BRINFO:
17066 + err = au_brinfo_ioctl(file, arg);
17069 + case AUFS_CTL_FHSM_FD:
17070 + dentry = file->f_path.dentry;
17071 + if (IS_ROOT(dentry))
17072 + err = au_fhsm_fd(dentry->d_sb, arg);
17078 + /* do not call the lower */
17079 + AuDbg("0x%x\n", cmd);
17087 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17092 + case AUFS_CTL_MVDOWN:
17093 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17096 + case AUFS_CTL_WBR_FD:
17097 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17101 + /* do not call the lower */
17102 + AuDbg("0x%x\n", cmd);
17110 +#ifdef CONFIG_COMPAT
17111 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17112 + unsigned long arg)
17117 + case AUFS_CTL_RDU:
17118 + case AUFS_CTL_RDU_INO:
17119 + err = au_rdu_compat_ioctl(file, cmd, arg);
17122 + case AUFS_CTL_IBUSY:
17123 + err = au_ibusy_compat_ioctl(file, arg);
17126 + case AUFS_CTL_BRINFO:
17127 + err = au_brinfo_compat_ioctl(file, arg);
17131 + err = aufs_ioctl_dir(file, cmd, arg);
17138 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17139 + unsigned long arg)
17141 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17144 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17145 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17146 +++ linux/fs/aufs/i_op_add.c 2015-09-24 10:47:58.254719746 +0200
17149 + * Copyright (C) 2005-2015 Junjiro R. Okajima
17151 + * This program, aufs is free software; you can redistribute it and/or modify
17152 + * it under the terms of the GNU General Public License as published by
17153 + * the Free Software Foundation; either version 2 of the License, or
17154 + * (at your option) any later version.
17156 + * This program is distributed in the hope that it will be useful,
17157 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17158 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17159 + * GNU General Public License for more details.
17161 + * You should have received a copy of the GNU General Public License
17162 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17166 + * inode operations (add entry)
17172 + * final procedure of adding a new entry, except link(2).
17173 + * remove whiteout, instantiate, copyup the parent dir's times and size
17174 + * and update version.
17175 + * if it failed, re-create the removed whiteout.
17177 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17178 + struct dentry *wh_dentry, struct dentry *dentry)
17181 + aufs_bindex_t bwh;
17182 + struct path h_path;
17183 + struct super_block *sb;
17184 + struct inode *inode, *h_dir;
17185 + struct dentry *wh;
17190 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17191 + IMustLock(h_dir);
17192 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17193 + bwh = au_dbwh(dentry);
17194 + h_path.dentry = wh_dentry;
17195 + h_path.mnt = au_sbr_mnt(sb, bindex);
17196 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17198 + if (unlikely(err))
17202 + inode = au_new_inode(dentry, /*must_new*/1);
17203 + if (!IS_ERR(inode)) {
17204 + d_instantiate(dentry, inode);
17205 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17207 + au_dir_ts(dir, bindex);
17208 + dir->i_version++;
17209 + au_fhsm_wrote(sb, bindex, /*force*/0);
17210 + return 0; /* success */
17213 + err = PTR_ERR(inode);
17218 + /* dir inode is locked */
17219 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17220 + rerr = PTR_ERR(wh);
17221 + if (IS_ERR(wh)) {
17222 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17223 + dentry, err, rerr);
17232 +static int au_d_may_add(struct dentry *dentry)
17237 + if (unlikely(d_unhashed(dentry)))
17239 + if (unlikely(d_really_is_positive(dentry)))
17245 + * simple tests for the adding inode operations.
17246 + * following the checks in vfs, plus the parent-child relationship.
17248 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17249 + struct dentry *h_parent, int isdir)
17253 + struct dentry *h_dentry;
17254 + struct inode *h_inode;
17256 + err = -ENAMETOOLONG;
17257 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17260 + h_dentry = au_h_dptr(dentry, bindex);
17261 + if (d_really_is_negative(dentry)) {
17263 + if (unlikely(d_is_positive(h_dentry)))
17266 + /* rename(2) case */
17268 + if (unlikely(d_is_negative(h_dentry)))
17270 + h_inode = d_inode(h_dentry);
17271 + if (unlikely(!h_inode->i_nlink))
17274 + h_mode = h_inode->i_mode;
17277 + if (unlikely(S_ISDIR(h_mode)))
17279 + } else if (unlikely(!S_ISDIR(h_mode))) {
17286 + /* expected parent dir is locked */
17287 + if (unlikely(h_parent != h_dentry->d_parent))
17296 + * initial procedure of adding a new entry.
17297 + * prepare writable branch and the parent dir, lock it,
17298 + * and lookup whiteout for the new entry.
17300 +static struct dentry*
17301 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17302 + struct dentry *src_dentry, struct au_pin *pin,
17303 + struct au_wr_dir_args *wr_dir_args)
17305 + struct dentry *wh_dentry, *h_parent;
17306 + struct super_block *sb;
17307 + struct au_branch *br;
17309 + unsigned int udba;
17310 + aufs_bindex_t bcpup;
17312 + AuDbg("%pd\n", dentry);
17314 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17316 + wh_dentry = ERR_PTR(err);
17317 + if (unlikely(err < 0))
17320 + sb = dentry->d_sb;
17321 + udba = au_opt_udba(sb);
17322 + err = au_pin(pin, dentry, bcpup, udba,
17323 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17324 + wh_dentry = ERR_PTR(err);
17325 + if (unlikely(err))
17328 + h_parent = au_pinned_h_parent(pin);
17329 + if (udba != AuOpt_UDBA_NONE
17330 + && au_dbstart(dentry) == bcpup)
17331 + err = au_may_add(dentry, bcpup, h_parent,
17332 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17333 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17334 + err = -ENAMETOOLONG;
17335 + wh_dentry = ERR_PTR(err);
17336 + if (unlikely(err))
17339 + br = au_sbr(sb, bcpup);
17341 + struct path tmp = {
17342 + .dentry = h_parent,
17343 + .mnt = au_br_mnt(br)
17345 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17348 + wh_dentry = NULL;
17349 + if (bcpup != au_dbwh(dentry))
17350 + goto out; /* success */
17353 + * ENAMETOOLONG here means that if we allowed create such name, then it
17354 + * would not be able to removed in the future. So we don't allow such
17355 + * name here and we don't handle ENAMETOOLONG differently here.
17357 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17360 + if (IS_ERR(wh_dentry))
17363 + return wh_dentry;
17366 +/* ---------------------------------------------------------------------- */
17368 +enum { Mknod, Symlink, Creat };
17369 +struct simple_arg {
17376 + struct vfsub_aopen_args *aopen;
17379 + const char *symname;
17388 +static int add_simple(struct inode *dir, struct dentry *dentry,
17389 + struct simple_arg *arg)
17392 + aufs_bindex_t bstart;
17393 + unsigned char created;
17394 + const unsigned char try_aopen
17395 + = (arg->type == Creat && arg->u.c.try_aopen);
17396 + struct dentry *wh_dentry, *parent;
17397 + struct inode *h_dir;
17398 + struct super_block *sb;
17399 + struct au_branch *br;
17400 + /* to reuduce stack size */
17402 + struct au_dtime dt;
17403 + struct au_pin pin;
17404 + struct path h_path;
17405 + struct au_wr_dir_args wr_dir_args;
17408 + AuDbg("%pd\n", dentry);
17412 + a = kmalloc(sizeof(*a), GFP_NOFS);
17413 + if (unlikely(!a))
17415 + a->wr_dir_args.force_btgt = -1;
17416 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17418 + parent = dentry->d_parent; /* dir inode is locked */
17419 + if (!try_aopen) {
17420 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17421 + if (unlikely(err))
17424 + err = au_d_may_add(dentry);
17425 + if (unlikely(err))
17428 + di_write_lock_parent(parent);
17429 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17430 + &a->pin, &a->wr_dir_args);
17431 + err = PTR_ERR(wh_dentry);
17432 + if (IS_ERR(wh_dentry))
17435 + bstart = au_dbstart(dentry);
17436 + sb = dentry->d_sb;
17437 + br = au_sbr(sb, bstart);
17438 + a->h_path.dentry = au_h_dptr(dentry, bstart);
17439 + a->h_path.mnt = au_br_mnt(br);
17440 + h_dir = au_pinned_h_dir(&a->pin);
17441 + switch (arg->type) {
17444 + if (!try_aopen || !h_dir->i_op->atomic_open)
17445 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17446 + arg->u.c.want_excl);
17448 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
17449 + arg->u.c.aopen, br);
17452 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17455 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17463 + err = epilog(dir, bstart, wh_dentry, dentry);
17466 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
17467 + /* no delegation since it is just created */
17468 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17471 + AuIOErr("%pd revert failure(%d, %d)\n",
17472 + dentry, err, rerr);
17475 + au_dtime_revert(&a->dt);
17478 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
17479 + *arg->u.c.aopen->opened |= FILE_CREATED;
17481 + au_unpin(&a->pin);
17486 + di_write_unlock(parent);
17488 + if (unlikely(err)) {
17489 + au_update_dbstart(dentry);
17493 + aufs_read_unlock(dentry, AuLock_DW);
17500 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17503 + struct simple_arg arg = {
17510 + return add_simple(dir, dentry, &arg);
17513 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17515 + struct simple_arg arg = {
17517 + .u.s.symname = symname
17519 + return add_simple(dir, dentry, &arg);
17522 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17525 + struct simple_arg arg = {
17529 + .want_excl = want_excl
17532 + return add_simple(dir, dentry, &arg);
17535 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17536 + struct vfsub_aopen_args *aopen_args)
17538 + struct simple_arg arg = {
17541 + .mode = aopen_args->create_mode,
17542 + .want_excl = aopen_args->open_flag & O_EXCL,
17543 + .try_aopen = true,
17544 + .aopen = aopen_args
17547 + return add_simple(dir, dentry, &arg);
17550 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17553 + aufs_bindex_t bindex;
17554 + struct super_block *sb;
17555 + struct dentry *parent, *h_parent, *h_dentry;
17556 + struct inode *h_dir, *inode;
17557 + struct vfsmount *h_mnt;
17558 + struct au_wr_dir_args wr_dir_args = {
17559 + .force_btgt = -1,
17560 + .flags = AuWrDir_TMPFILE
17563 + /* copy-up may happen */
17564 + mutex_lock(&dir->i_mutex);
17567 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17568 + if (unlikely(err))
17571 + err = au_di_init(dentry);
17572 + if (unlikely(err))
17576 + parent = d_find_any_alias(dir);
17577 + AuDebugOn(!parent);
17578 + di_write_lock_parent(parent);
17579 + if (unlikely(d_inode(parent) != dir))
17582 + err = au_digen_test(parent, au_sigen(sb));
17583 + if (unlikely(err))
17586 + bindex = au_dbstart(parent);
17587 + au_set_dbstart(dentry, bindex);
17588 + au_set_dbend(dentry, bindex);
17589 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17591 + if (unlikely(err < 0))
17594 + err = -EOPNOTSUPP;
17595 + h_dir = au_h_iptr(dir, bindex);
17596 + if (unlikely(!h_dir->i_op->tmpfile))
17599 + h_mnt = au_sbr_mnt(sb, bindex);
17600 + err = vfsub_mnt_want_write(h_mnt);
17601 + if (unlikely(err))
17604 + h_parent = au_h_dptr(parent, bindex);
17605 + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC);
17606 + if (unlikely(err))
17610 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17611 + if (unlikely(!h_dentry))
17614 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17615 + if (unlikely(err))
17618 + au_set_dbstart(dentry, bindex);
17619 + au_set_dbend(dentry, bindex);
17620 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17621 + inode = au_new_inode(dentry, /*must_new*/1);
17622 + if (IS_ERR(inode)) {
17623 + err = PTR_ERR(inode);
17624 + au_set_h_dptr(dentry, bindex, NULL);
17625 + au_set_dbstart(dentry, -1);
17626 + au_set_dbend(dentry, -1);
17628 + if (!inode->i_nlink)
17629 + set_nlink(inode, 1);
17630 + d_tmpfile(dentry, inode);
17631 + au_di(dentry)->di_tmpfile = 1;
17633 + /* update without i_mutex */
17634 + if (au_ibstart(dir) == au_dbstart(dentry))
17635 + au_cpup_attr_timesizes(dir);
17641 + vfsub_mnt_drop_write(h_mnt);
17643 + di_write_unlock(parent);
17645 + di_write_unlock(dentry);
17648 + /* verbose coding for lock class name */
17649 + au_rw_class(&au_di(dentry)->di_rwsem,
17650 + au_lc_key + AuLcNonDir_DIINFO);
17655 + au_di_fin(dentry);
17656 + dentry->d_fsdata = NULL;
17659 + si_read_unlock(sb);
17661 + mutex_unlock(&dir->i_mutex);
17665 +/* ---------------------------------------------------------------------- */
17667 +struct au_link_args {
17668 + aufs_bindex_t bdst, bsrc;
17669 + struct au_pin pin;
17670 + struct path h_path;
17671 + struct dentry *src_parent, *parent;
17674 +static int au_cpup_before_link(struct dentry *src_dentry,
17675 + struct au_link_args *a)
17678 + struct dentry *h_src_dentry;
17679 + struct au_cp_generic cpg = {
17680 + .dentry = src_dentry,
17685 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
17688 + di_read_lock_parent(a->src_parent, AuLock_IR);
17689 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
17690 + if (unlikely(err))
17693 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
17694 + err = au_pin(&a->pin, src_dentry, a->bdst,
17695 + au_opt_udba(src_dentry->d_sb),
17696 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17697 + if (unlikely(err))
17700 + err = au_sio_cpup_simple(&cpg);
17701 + au_unpin(&a->pin);
17704 + di_read_unlock(a->src_parent, AuLock_IR);
17708 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
17709 + struct au_link_args *a)
17712 + unsigned char plink;
17713 + aufs_bindex_t bend;
17714 + struct dentry *h_src_dentry;
17715 + struct inode *h_inode, *inode, *delegated;
17716 + struct super_block *sb;
17717 + struct file *h_file;
17721 + sb = src_dentry->d_sb;
17722 + inode = d_inode(src_dentry);
17723 + if (au_ibstart(inode) <= a->bdst)
17724 + h_inode = au_h_iptr(inode, a->bdst);
17725 + if (!h_inode || !h_inode->i_nlink) {
17726 + /* copyup src_dentry as the name of dentry. */
17727 + bend = au_dbend(dentry);
17728 + if (bend < a->bsrc)
17729 + au_set_dbend(dentry, a->bsrc);
17730 + au_set_h_dptr(dentry, a->bsrc,
17731 + dget(au_h_dptr(src_dentry, a->bsrc)));
17732 + dget(a->h_path.dentry);
17733 + au_set_h_dptr(dentry, a->bdst, NULL);
17734 + AuDbg("temporary d_inode...\n");
17735 + spin_lock(&dentry->d_lock);
17736 + dentry->d_inode = d_inode(src_dentry); /* tmp */
17737 + spin_unlock(&dentry->d_lock);
17738 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
17739 + if (IS_ERR(h_file))
17740 + err = PTR_ERR(h_file);
17742 + struct au_cp_generic cpg = {
17743 + .dentry = dentry,
17748 + .flags = AuCpup_KEEPLINO
17750 + err = au_sio_cpup_simple(&cpg);
17751 + au_h_open_post(dentry, a->bsrc, h_file);
17753 + dput(a->h_path.dentry);
17754 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17756 + au_set_h_dptr(dentry, a->bdst,
17757 + a->h_path.dentry);
17759 + spin_lock(&dentry->d_lock);
17760 + dentry->d_inode = NULL; /* restore */
17761 + spin_unlock(&dentry->d_lock);
17762 + AuDbg("temporary d_inode...done\n");
17763 + au_set_h_dptr(dentry, a->bsrc, NULL);
17764 + au_set_dbend(dentry, bend);
17766 + /* the inode of src_dentry already exists on a.bdst branch */
17767 + h_src_dentry = d_find_alias(h_inode);
17768 + if (!h_src_dentry && au_plink_test(inode)) {
17770 + h_src_dentry = au_plink_lkup(inode, a->bdst);
17771 + err = PTR_ERR(h_src_dentry);
17772 + if (IS_ERR(h_src_dentry))
17775 + if (unlikely(d_is_negative(h_src_dentry))) {
17776 + dput(h_src_dentry);
17777 + h_src_dentry = NULL;
17781 + if (h_src_dentry) {
17782 + delegated = NULL;
17783 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17784 + &a->h_path, &delegated);
17785 + if (unlikely(err == -EWOULDBLOCK)) {
17786 + pr_warn("cannot retry for NFSv4 delegation"
17787 + " for an internal link\n");
17790 + dput(h_src_dentry);
17792 + AuIOErr("no dentry found for hi%lu on b%d\n",
17793 + h_inode->i_ino, a->bdst);
17798 + if (!err && !plink)
17799 + au_plink_append(inode, a->bdst, a->h_path.dentry);
17806 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
17807 + struct dentry *dentry)
17810 + struct au_dtime dt;
17811 + struct au_link_args *a;
17812 + struct dentry *wh_dentry, *h_src_dentry;
17813 + struct inode *inode, *delegated;
17814 + struct super_block *sb;
17815 + struct au_wr_dir_args wr_dir_args = {
17816 + /* .force_btgt = -1, */
17817 + .flags = AuWrDir_ADD_ENTRY
17821 + inode = d_inode(src_dentry);
17822 + IMustLock(inode);
17825 + a = kzalloc(sizeof(*a), GFP_NOFS);
17826 + if (unlikely(!a))
17829 + a->parent = dentry->d_parent; /* dir inode is locked */
17830 + err = aufs_read_and_write_lock2(dentry, src_dentry,
17831 + AuLock_NOPLM | AuLock_GEN);
17832 + if (unlikely(err))
17834 + err = au_d_linkable(src_dentry);
17835 + if (unlikely(err))
17837 + err = au_d_may_add(dentry);
17838 + if (unlikely(err))
17841 + a->src_parent = dget_parent(src_dentry);
17842 + wr_dir_args.force_btgt = au_ibstart(inode);
17844 + di_write_lock_parent(a->parent);
17845 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
17846 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
17848 + err = PTR_ERR(wh_dentry);
17849 + if (IS_ERR(wh_dentry))
17853 + sb = dentry->d_sb;
17854 + a->bdst = au_dbstart(dentry);
17855 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
17856 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
17857 + a->bsrc = au_ibstart(inode);
17858 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17859 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
17860 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
17861 + if (!h_src_dentry) {
17862 + a->bsrc = au_dbstart(src_dentry);
17863 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
17864 + AuDebugOn(!h_src_dentry);
17865 + } else if (IS_ERR(h_src_dentry)) {
17866 + err = PTR_ERR(h_src_dentry);
17870 + if (au_opt_test(au_mntflags(sb), PLINK)) {
17871 + if (a->bdst < a->bsrc
17872 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
17873 + err = au_cpup_or_link(src_dentry, dentry, a);
17875 + delegated = NULL;
17876 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
17877 + &a->h_path, &delegated);
17878 + if (unlikely(err == -EWOULDBLOCK)) {
17879 + pr_warn("cannot retry for NFSv4 delegation"
17880 + " for an internal link\n");
17884 + dput(h_src_dentry);
17887 + * copyup src_dentry to the branch we process,
17888 + * and then link(2) to it.
17890 + dput(h_src_dentry);
17891 + if (a->bdst < a->bsrc
17892 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
17893 + au_unpin(&a->pin);
17894 + di_write_unlock(a->parent);
17895 + err = au_cpup_before_link(src_dentry, a);
17896 + di_write_lock_parent(a->parent);
17898 + err = au_pin(&a->pin, dentry, a->bdst,
17900 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17901 + if (unlikely(err))
17905 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
17907 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
17908 + delegated = NULL;
17909 + err = vfsub_link(h_src_dentry,
17910 + au_pinned_h_dir(&a->pin),
17911 + &a->h_path, &delegated);
17912 + if (unlikely(err == -EWOULDBLOCK)) {
17913 + pr_warn("cannot retry"
17914 + " for NFSv4 delegation"
17915 + " for an internal link\n");
17921 + if (unlikely(err))
17925 + a->h_path.dentry = wh_dentry;
17926 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
17928 + if (unlikely(err))
17932 + au_dir_ts(dir, a->bdst);
17933 + dir->i_version++;
17934 + inc_nlink(inode);
17935 + inode->i_ctime = dir->i_ctime;
17936 + d_instantiate(dentry, au_igrab(inode));
17937 + if (d_unhashed(a->h_path.dentry))
17938 + /* some filesystem calls d_drop() */
17940 + /* some filesystems consume an inode even hardlink */
17941 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
17942 + goto out_unpin; /* success */
17945 + /* no delegation since it is just created */
17946 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
17947 + /*delegated*/NULL, /*force*/0);
17948 + if (unlikely(rerr)) {
17949 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
17952 + au_dtime_revert(&dt);
17954 + au_unpin(&a->pin);
17958 + di_write_unlock(a->parent);
17959 + dput(a->src_parent);
17961 + if (unlikely(err)) {
17962 + au_update_dbstart(dentry);
17965 + aufs_read_and_write_unlock2(dentry, src_dentry);
17973 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
17976 + aufs_bindex_t bindex;
17977 + unsigned char diropq;
17978 + struct path h_path;
17979 + struct dentry *wh_dentry, *parent, *opq_dentry;
17980 + struct mutex *h_mtx;
17981 + struct super_block *sb;
17983 + struct au_pin pin;
17984 + struct au_dtime dt;
17985 + } *a; /* reduce the stack usage */
17986 + struct au_wr_dir_args wr_dir_args = {
17987 + .force_btgt = -1,
17988 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
17994 + a = kmalloc(sizeof(*a), GFP_NOFS);
17995 + if (unlikely(!a))
17998 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17999 + if (unlikely(err))
18001 + err = au_d_may_add(dentry);
18002 + if (unlikely(err))
18005 + parent = dentry->d_parent; /* dir inode is locked */
18006 + di_write_lock_parent(parent);
18007 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18008 + &a->pin, &wr_dir_args);
18009 + err = PTR_ERR(wh_dentry);
18010 + if (IS_ERR(wh_dentry))
18013 + sb = dentry->d_sb;
18014 + bindex = au_dbstart(dentry);
18015 + h_path.dentry = au_h_dptr(dentry, bindex);
18016 + h_path.mnt = au_sbr_mnt(sb, bindex);
18017 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18018 + if (unlikely(err))
18021 + /* make the dir opaque */
18023 + h_mtx = &d_inode(h_path.dentry)->i_mutex;
18025 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18026 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18027 + opq_dentry = au_diropq_create(dentry, bindex);
18028 + mutex_unlock(h_mtx);
18029 + err = PTR_ERR(opq_dentry);
18030 + if (IS_ERR(opq_dentry))
18032 + dput(opq_dentry);
18036 + err = epilog(dir, bindex, wh_dentry, dentry);
18039 + goto out_unpin; /* success */
18044 + AuLabel(revert opq);
18045 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
18046 + rerr = au_diropq_remove(dentry, bindex);
18047 + mutex_unlock(h_mtx);
18049 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18050 + dentry, err, rerr);
18056 + AuLabel(revert dir);
18057 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18059 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18060 + dentry, err, rerr);
18063 + au_dtime_revert(&a->dt);
18065 + au_unpin(&a->pin);
18068 + di_write_unlock(parent);
18070 + if (unlikely(err)) {
18071 + au_update_dbstart(dentry);
18074 + aufs_read_unlock(dentry, AuLock_DW);
18080 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18081 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18082 +++ linux/fs/aufs/i_op.c 2015-09-24 10:47:58.254719746 +0200
18085 + * Copyright (C) 2005-2015 Junjiro R. Okajima
18087 + * This program, aufs is free software; you can redistribute it and/or modify
18088 + * it under the terms of the GNU General Public License as published by
18089 + * the Free Software Foundation; either version 2 of the License, or
18090 + * (at your option) any later version.
18092 + * This program is distributed in the hope that it will be useful,
18093 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18094 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18095 + * GNU General Public License for more details.
18097 + * You should have received a copy of the GNU General Public License
18098 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18102 + * inode operations (except add/del/rename)
18105 +#include <linux/device_cgroup.h>
18106 +#include <linux/fs_stack.h>
18107 +#include <linux/mm.h>
18108 +#include <linux/namei.h>
18109 +#include <linux/security.h>
18112 +static int h_permission(struct inode *h_inode, int mask,
18113 + struct vfsmount *h_mnt, int brperm)
18116 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18119 + if ((write_mask && IS_IMMUTABLE(h_inode))
18120 + || ((mask & MAY_EXEC)
18121 + && S_ISREG(h_inode->i_mode)
18122 + && ((h_mnt->mnt_flags & MNT_NOEXEC)
18123 + || !(h_inode->i_mode & S_IXUGO))))
18127 + * - skip the lower fs test in the case of write to ro branch.
18128 + * - nfs dir permission write check is optimized, but a policy for
18129 + * link/rename requires a real check.
18130 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18131 + * in this case, generic_permission() returns -EOPNOTSUPP.
18133 + if ((write_mask && !au_br_writable(brperm))
18134 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18135 + && write_mask && !(mask & MAY_READ))
18136 + || !h_inode->i_op->permission) {
18137 + /* AuLabel(generic_permission); */
18138 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18139 + err = generic_permission(h_inode, mask);
18140 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18141 + err = h_inode->i_op->permission(h_inode, mask);
18144 + /* AuLabel(h_inode->permission); */
18145 + err = h_inode->i_op->permission(h_inode, mask);
18150 + err = devcgroup_inode_permission(h_inode, mask);
18152 + err = security_inode_permission(h_inode, mask);
18156 + /* todo: do we need to call ima_path_check()? */
18157 + struct path h_path = {
18161 + err = ima_path_check(&h_path,
18162 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18163 + IMA_COUNT_LEAVE);
18171 +static int aufs_permission(struct inode *inode, int mask)
18174 + aufs_bindex_t bindex, bend;
18175 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18176 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18177 + struct inode *h_inode;
18178 + struct super_block *sb;
18179 + struct au_branch *br;
18181 + /* todo: support rcu-walk? */
18182 + if (mask & MAY_NOT_BLOCK)
18185 + sb = inode->i_sb;
18186 + si_read_lock(sb, AuLock_FLUSH);
18187 + ii_read_lock_child(inode);
18189 + err = au_iigen_test(inode, au_sigen(sb));
18190 + if (unlikely(err))
18196 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18197 + err = au_busy_or_stale();
18198 + h_inode = au_h_iptr(inode, au_ibstart(inode));
18199 + if (unlikely(!h_inode
18200 + || (h_inode->i_mode & S_IFMT)
18201 + != (inode->i_mode & S_IFMT)))
18205 + bindex = au_ibstart(inode);
18206 + br = au_sbr(sb, bindex);
18207 + err = h_permission(h_inode, mask, au_br_mnt(br), br->br_perm);
18210 + && !special_file(h_inode->i_mode)) {
18211 + /* test whether the upper writable branch exists */
18213 + for (; bindex >= 0; bindex--)
18214 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18222 + /* non-write to dir */
18224 + bend = au_ibend(inode);
18225 + for (bindex = au_ibstart(inode); !err && bindex <= bend; bindex++) {
18226 + h_inode = au_h_iptr(inode, bindex);
18228 + err = au_busy_or_stale();
18229 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18232 + br = au_sbr(sb, bindex);
18233 + err = h_permission(h_inode, mask, au_br_mnt(br),
18239 + ii_read_unlock(inode);
18240 + si_read_unlock(sb);
18244 +/* ---------------------------------------------------------------------- */
18246 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18247 + unsigned int flags)
18249 + struct dentry *ret, *parent;
18250 + struct inode *inode;
18251 + struct super_block *sb;
18252 + int err, npositive;
18256 + /* todo: support rcu-walk? */
18257 + ret = ERR_PTR(-ECHILD);
18258 + if (flags & LOOKUP_RCU)
18261 + ret = ERR_PTR(-ENAMETOOLONG);
18262 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18266 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18267 + ret = ERR_PTR(err);
18268 + if (unlikely(err))
18271 + err = au_di_init(dentry);
18272 + ret = ERR_PTR(err);
18273 + if (unlikely(err))
18277 + npositive = 0; /* suppress a warning */
18278 + parent = dentry->d_parent; /* dir inode is locked */
18279 + di_read_lock_parent(parent, AuLock_IR);
18280 + err = au_alive_dir(parent);
18282 + err = au_digen_test(parent, au_sigen(sb));
18284 + npositive = au_lkup_dentry(dentry, au_dbstart(parent),
18288 + di_read_unlock(parent, AuLock_IR);
18289 + ret = ERR_PTR(err);
18290 + if (unlikely(err < 0))
18294 + inode = au_new_inode(dentry, /*must_new*/0);
18295 + if (IS_ERR(inode)) {
18296 + ret = (void *)inode;
18303 + atomic_inc(&inode->i_count);
18304 + ret = d_splice_alias(inode, dentry);
18306 + if (unlikely(d_need_lookup(dentry))) {
18307 + spin_lock(&dentry->d_lock);
18308 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18309 + spin_unlock(&dentry->d_lock);
18313 + if (!IS_ERR(ret)) {
18315 + if (ret && ret != dentry)
18316 + ii_write_unlock(inode);
18318 + ii_write_unlock(inode);
18325 + di_write_unlock(dentry);
18327 + /* verbose coding for lock class name */
18328 + if (unlikely(S_ISLNK(inode->i_mode)))
18329 + au_rw_class(&au_di(dentry)->di_rwsem,
18330 + au_lc_key + AuLcSymlink_DIINFO);
18331 + else if (unlikely(S_ISDIR(inode->i_mode)))
18332 + au_rw_class(&au_di(dentry)->di_rwsem,
18333 + au_lc_key + AuLcDir_DIINFO);
18334 + else /* likely */
18335 + au_rw_class(&au_di(dentry)->di_rwsem,
18336 + au_lc_key + AuLcNonDir_DIINFO);
18339 + si_read_unlock(sb);
18344 +/* ---------------------------------------------------------------------- */
18346 +struct aopen_node {
18347 + struct hlist_node hlist;
18348 + struct file *file, *h_file;
18351 +static int au_do_aopen(struct inode *inode, struct file *file)
18353 + struct au_sphlhead *aopen;
18354 + struct aopen_node *node;
18355 + struct au_do_open_args args = {
18357 + .open = au_do_open_nondir
18360 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18361 + spin_lock(&aopen->spin);
18362 + hlist_for_each_entry(node, &aopen->head, hlist)
18363 + if (node->file == file) {
18364 + args.h_file = node->h_file;
18367 + spin_unlock(&aopen->spin);
18368 + /* AuDebugOn(!args.h_file); */
18370 + return au_do_open(file, &args);
18373 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18374 + struct file *file, unsigned int open_flag,
18375 + umode_t create_mode, int *opened)
18377 + int err, h_opened = *opened;
18378 + struct dentry *parent;
18379 + struct dentry *d;
18380 + struct au_sphlhead *aopen;
18381 + struct vfsub_aopen_args args = {
18382 + .open_flag = open_flag,
18383 + .create_mode = create_mode,
18384 + .opened = &h_opened
18386 + struct aopen_node aopen_node = {
18391 + AuDbg("open_flag 0x%x\n", open_flag);
18392 + AuDbgDentry(dentry);
18395 + if (!au_di(dentry)) {
18396 + d = aufs_lookup(dir, dentry, /*flags*/0);
18398 + err = PTR_ERR(d);
18402 + * obsoleted dentry found.
18403 + * another error will be returned later.
18409 + AuDbgDentry(dentry);
18412 + if (d_is_positive(dentry)
18413 + || d_unhashed(dentry)
18414 + || d_unlinked(dentry)
18415 + || !(open_flag & O_CREAT))
18416 + goto out_no_open;
18418 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18419 + if (unlikely(err))
18422 + parent = dentry->d_parent; /* dir is locked */
18423 + di_write_lock_parent(parent);
18424 + err = au_lkup_dentry(dentry, /*bstart*/0, /*type*/0);
18425 + if (unlikely(err))
18428 + AuDbgDentry(dentry);
18429 + if (d_is_positive(dentry))
18432 + args.file = get_empty_filp();
18433 + err = PTR_ERR(args.file);
18434 + if (IS_ERR(args.file))
18437 + args.file->f_flags = file->f_flags;
18438 + err = au_aopen_or_create(dir, dentry, &args);
18440 + AuDbgFile(args.file);
18441 + if (unlikely(err < 0)) {
18442 + if (h_opened & FILE_OPENED)
18445 + put_filp(args.file);
18449 + /* some filesystems don't set FILE_CREATED while succeeded? */
18450 + *opened |= FILE_CREATED;
18451 + if (h_opened & FILE_OPENED)
18452 + aopen_node.h_file = args.file;
18454 + put_filp(args.file);
18455 + args.file = NULL;
18457 + aopen = &au_sbi(dir->i_sb)->si_aopen;
18458 + au_sphl_add(&aopen_node.hlist, aopen);
18459 + err = finish_open(file, dentry, au_do_aopen, opened);
18460 + au_sphl_del(&aopen_node.hlist, aopen);
18463 + if (aopen_node.h_file)
18464 + fput(aopen_node.h_file);
18467 + di_write_unlock(parent);
18468 + aufs_read_unlock(dentry, AuLock_DW);
18469 + AuDbgDentry(dentry);
18470 + if (unlikely(err))
18473 + if (!err && !(*opened & FILE_CREATED)) {
18474 + AuLabel(out_no_open);
18476 + err = finish_no_open(file, dentry);
18479 + AuDbg("%pd%s%s\n", dentry,
18480 + (*opened & FILE_CREATED) ? " created" : "",
18481 + (*opened & FILE_OPENED) ? " opened" : "");
18487 +/* ---------------------------------------------------------------------- */
18489 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18490 + const unsigned char add_entry, aufs_bindex_t bcpup,
18491 + aufs_bindex_t bstart)
18494 + struct dentry *h_parent;
18495 + struct inode *h_dir;
18498 + IMustLock(d_inode(parent));
18500 + di_write_lock_parent(parent);
18503 + if (!au_h_dptr(parent, bcpup)) {
18504 + if (bstart > bcpup)
18505 + err = au_cpup_dirs(dentry, bcpup);
18506 + else if (bstart < bcpup)
18507 + err = au_cpdown_dirs(dentry, bcpup);
18511 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18512 + h_parent = au_h_dptr(parent, bcpup);
18513 + h_dir = d_inode(h_parent);
18514 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
18515 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
18516 + /* todo: no unlock here */
18517 + mutex_unlock(&h_dir->i_mutex);
18519 + AuDbg("bcpup %d\n", bcpup);
18521 + if (d_really_is_negative(dentry))
18522 + au_set_h_dptr(dentry, bstart, NULL);
18523 + au_update_dbrange(dentry, /*do_put_zero*/0);
18528 + di_write_unlock(parent);
18530 + err = bcpup; /* success */
18537 + * decide the branch and the parent dir where we will create a new entry.
18538 + * returns new bindex or an error.
18539 + * copyup the parent dir if needed.
18541 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18542 + struct au_wr_dir_args *args)
18545 + unsigned int flags;
18546 + aufs_bindex_t bcpup, bstart, src_bstart;
18547 + const unsigned char add_entry
18548 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18549 + | au_ftest_wrdir(args->flags, TMPFILE);
18550 + struct super_block *sb;
18551 + struct dentry *parent;
18552 + struct au_sbinfo *sbinfo;
18554 + sb = dentry->d_sb;
18555 + sbinfo = au_sbi(sb);
18556 + parent = dget_parent(dentry);
18557 + bstart = au_dbstart(dentry);
18559 + if (args->force_btgt < 0) {
18560 + if (src_dentry) {
18561 + src_bstart = au_dbstart(src_dentry);
18562 + if (src_bstart < bstart)
18563 + bcpup = src_bstart;
18564 + } else if (add_entry) {
18566 + if (au_ftest_wrdir(args->flags, ISDIR))
18567 + au_fset_wbr(flags, DIR);
18568 + err = AuWbrCreate(sbinfo, dentry, flags);
18572 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
18574 + err = AuWbrCopyup(sbinfo, dentry);
18576 + if (!IS_ROOT(dentry)) {
18577 + di_read_lock_parent(parent, !AuLock_IR);
18578 + err = AuWbrCopyup(sbinfo, dentry);
18579 + di_read_unlock(parent, !AuLock_IR);
18581 + err = AuWbrCopyup(sbinfo, dentry);
18584 + if (unlikely(err < 0))
18588 + bcpup = args->force_btgt;
18589 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
18592 + AuDbg("bstart %d, bcpup %d\n", bstart, bcpup);
18594 + if (bcpup == bstart)
18595 + goto out; /* success */
18597 + /* copyup the new parent into the branch we process */
18598 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, bstart);
18600 + if (d_really_is_negative(dentry)) {
18601 + au_set_h_dptr(dentry, bstart, NULL);
18602 + au_set_dbstart(dentry, bcpup);
18603 + au_set_dbend(dentry, bcpup);
18605 + AuDebugOn(add_entry
18606 + && !au_ftest_wrdir(args->flags, TMPFILE)
18607 + && !au_h_dptr(dentry, bcpup));
18615 +/* ---------------------------------------------------------------------- */
18617 +void au_pin_hdir_unlock(struct au_pin *p)
18620 + au_hn_imtx_unlock(p->hdir);
18623 +int au_pin_hdir_lock(struct au_pin *p)
18631 + /* even if an error happens later, keep this lock */
18632 + au_hn_imtx_lock_nested(p->hdir, p->lsc_hi);
18635 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
18640 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18641 + p->h_parent, p->br);
18647 +int au_pin_hdir_relock(struct au_pin *p)
18650 + struct inode *h_i;
18651 + struct dentry *h_d[] = {
18656 + err = au_pin_hdir_lock(p);
18657 + if (unlikely(err))
18660 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
18663 + if (d_is_positive(h_d[i])) {
18664 + h_i = d_inode(h_d[i]);
18665 + err = !h_i->i_nlink;
18673 +void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
18675 +#if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
18676 + p->hdir->hi_inode->i_mutex.owner = task;
18680 +void au_pin_hdir_acquire_nest(struct au_pin *p)
18683 + mutex_acquire_nest(&p->hdir->hi_inode->i_mutex.dep_map,
18684 + p->lsc_hi, 0, NULL, _RET_IP_);
18685 + au_pin_hdir_set_owner(p, current);
18689 +void au_pin_hdir_release(struct au_pin *p)
18692 + au_pin_hdir_set_owner(p, p->task);
18693 + mutex_release(&p->hdir->hi_inode->i_mutex.dep_map, 1, _RET_IP_);
18697 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
18699 + if (pin && pin->parent)
18700 + return au_h_dptr(pin->parent, pin->bindex);
18704 +void au_unpin(struct au_pin *p)
18707 + au_pin_hdir_unlock(p);
18708 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
18709 + vfsub_mnt_drop_write(p->h_mnt);
18713 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18714 + di_read_unlock(p->parent, AuLock_IR);
18715 + iput(p->hdir->hi_inode);
18717 + p->parent = NULL;
18720 + /* do not clear p->task */
18723 +int au_do_pin(struct au_pin *p)
18726 + struct super_block *sb;
18727 + struct inode *h_dir;
18730 + sb = p->dentry->d_sb;
18731 + p->br = au_sbr(sb, p->bindex);
18732 + if (IS_ROOT(p->dentry)) {
18733 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18734 + p->h_mnt = au_br_mnt(p->br);
18735 + err = vfsub_mnt_want_write(p->h_mnt);
18736 + if (unlikely(err)) {
18737 + au_fclr_pin(p->flags, MNT_WRITE);
18744 + p->h_dentry = NULL;
18745 + if (p->bindex <= au_dbend(p->dentry))
18746 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
18748 + p->parent = dget_parent(p->dentry);
18749 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18750 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
18753 + p->h_parent = au_h_dptr(p->parent, p->bindex);
18754 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
18756 + h_dir = p->hdir->hi_inode;
18760 + * if DI_LOCKED is not set, then p->parent may be different
18761 + * and h_parent can be NULL.
18763 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
18765 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18766 + di_read_unlock(p->parent, AuLock_IR);
18768 + p->parent = NULL;
18772 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
18773 + p->h_mnt = au_br_mnt(p->br);
18774 + err = vfsub_mnt_want_write(p->h_mnt);
18775 + if (unlikely(err)) {
18776 + au_fclr_pin(p->flags, MNT_WRITE);
18777 + if (!au_ftest_pin(p->flags, DI_LOCKED))
18778 + di_read_unlock(p->parent, AuLock_IR);
18780 + p->parent = NULL;
18786 + err = au_pin_hdir_lock(p);
18788 + goto out; /* success */
18793 + pr_err("err %d\n", err);
18794 + err = au_busy_or_stale();
18799 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
18800 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
18801 + unsigned int udba, unsigned char flags)
18803 + p->dentry = dentry;
18805 + p->lsc_di = lsc_di;
18806 + p->lsc_hi = lsc_hi;
18807 + p->flags = flags;
18808 + p->bindex = bindex;
18810 + p->parent = NULL;
18814 + p->h_dentry = NULL;
18815 + p->h_parent = NULL;
18817 + p->task = current;
18820 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
18821 + unsigned int udba, unsigned char flags)
18823 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
18825 + return au_do_pin(pin);
18828 +/* ---------------------------------------------------------------------- */
18831 + * ->setattr() and ->getattr() are called in various cases.
18832 + * chmod, stat: dentry is revalidated.
18833 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
18835 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
18837 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
18838 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
18841 + struct dentry *parent;
18844 + if (au_digen_test(dentry, sigen)) {
18845 + parent = dget_parent(dentry);
18846 + di_read_lock_parent(parent, AuLock_IR);
18847 + err = au_refresh_dentry(dentry, parent);
18848 + di_read_unlock(parent, AuLock_IR);
18856 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
18857 + struct au_icpup_args *a)
18861 + aufs_bindex_t bstart, ibstart;
18862 + struct dentry *hi_wh, *parent;
18863 + struct inode *inode;
18864 + struct au_wr_dir_args wr_dir_args = {
18865 + .force_btgt = -1,
18869 + if (d_is_dir(dentry))
18870 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
18871 + /* plink or hi_wh() case */
18872 + bstart = au_dbstart(dentry);
18873 + inode = d_inode(dentry);
18874 + ibstart = au_ibstart(inode);
18875 + if (bstart != ibstart && !au_test_ro(inode->i_sb, ibstart, inode))
18876 + wr_dir_args.force_btgt = ibstart;
18877 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18878 + if (unlikely(err < 0))
18881 + if (err != bstart)
18882 + au_fset_icpup(a->flags, DID_CPUP);
18885 + a->pin_flags = AuPin_MNT_WRITE;
18887 + if (!IS_ROOT(dentry)) {
18888 + au_fset_pin(a->pin_flags, DI_LOCKED);
18889 + parent = dget_parent(dentry);
18890 + di_write_lock_parent(parent);
18893 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
18894 + if (unlikely(err))
18897 + a->h_path.dentry = au_h_dptr(dentry, bstart);
18899 + a->h_inode = d_inode(a->h_path.dentry);
18900 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
18901 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18902 + if (ia->ia_size < i_size_read(a->h_inode))
18903 + sz = ia->ia_size;
18904 + mutex_unlock(&a->h_inode->i_mutex);
18908 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
18909 + hi_wh = au_hi_wh(inode, a->btgt);
18911 + struct au_cp_generic cpg = {
18912 + .dentry = dentry,
18918 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
18919 + if (unlikely(err))
18921 + hi_wh = au_hi_wh(inode, a->btgt);
18922 + /* todo: revalidate hi_wh? */
18927 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
18928 + di_downgrade_lock(parent, AuLock_IR);
18932 + if (!au_ftest_icpup(a->flags, DID_CPUP))
18933 + goto out; /* success */
18935 + if (!d_unhashed(dentry)) {
18936 + struct au_cp_generic cpg = {
18937 + .dentry = dentry,
18942 + .flags = AuCpup_DTIME | AuCpup_HOPEN
18944 + err = au_sio_cpup_simple(&cpg);
18946 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18947 + } else if (!hi_wh)
18948 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
18950 + a->h_path.dentry = hi_wh; /* do not dget here */
18953 + a->h_inode = d_inode(a->h_path.dentry);
18955 + goto out; /* success */
18956 + au_unpin(&a->pin);
18959 + di_write_unlock(parent);
18964 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
18968 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
18971 + struct inode *inode, *delegated;
18972 + struct super_block *sb;
18973 + struct file *file;
18974 + struct au_icpup_args *a;
18976 + inode = d_inode(dentry);
18977 + IMustLock(inode);
18980 + a = kzalloc(sizeof(*a), GFP_NOFS);
18981 + if (unlikely(!a))
18984 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
18985 + ia->ia_valid &= ~ATTR_MODE;
18988 + sb = dentry->d_sb;
18989 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18990 + if (unlikely(err))
18993 + if (ia->ia_valid & ATTR_FILE) {
18994 + /* currently ftruncate(2) only */
18995 + AuDebugOn(!d_is_reg(dentry));
18996 + file = ia->ia_file;
18997 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
18998 + if (unlikely(err))
19000 + ia->ia_file = au_hf_top(file);
19001 + a->udba = AuOpt_UDBA_NONE;
19003 + /* fchmod() doesn't pass ia_file */
19004 + a->udba = au_opt_udba(sb);
19005 + di_write_lock_child(dentry);
19006 + /* no d_unlinked(), to set UDBA_NONE for root */
19007 + if (d_unhashed(dentry))
19008 + a->udba = AuOpt_UDBA_NONE;
19009 + if (a->udba != AuOpt_UDBA_NONE) {
19010 + AuDebugOn(IS_ROOT(dentry));
19011 + err = au_reval_for_attr(dentry, au_sigen(sb));
19012 + if (unlikely(err))
19017 + err = au_pin_and_icpup(dentry, ia, a);
19018 + if (unlikely(err < 0))
19020 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19021 + ia->ia_file = NULL;
19022 + ia->ia_valid &= ~ATTR_FILE;
19025 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19026 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19027 + == (ATTR_MODE | ATTR_CTIME)) {
19028 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19029 + if (unlikely(err))
19031 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19032 + && (ia->ia_valid & ATTR_CTIME)) {
19033 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19034 + if (unlikely(err))
19038 + if (ia->ia_valid & ATTR_SIZE) {
19041 + if (ia->ia_size < i_size_read(inode))
19043 + truncate_setsize(inode, ia->ia_size);
19046 + if (ia->ia_valid & ATTR_FILE)
19048 + mutex_unlock(&a->h_inode->i_mutex);
19049 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19050 + mutex_lock_nested(&a->h_inode->i_mutex, AuLsc_I_CHILD);
19052 + delegated = NULL;
19054 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19056 + err = break_deleg_wait(&delegated);
19064 + au_cpup_attr_changeable(inode);
19067 + mutex_unlock(&a->h_inode->i_mutex);
19068 + au_unpin(&a->pin);
19069 + if (unlikely(err))
19070 + au_update_dbstart(dentry);
19072 + di_write_unlock(dentry);
19074 + fi_write_unlock(file);
19075 + ia->ia_file = file;
19076 + ia->ia_valid |= ATTR_FILE;
19079 + si_read_unlock(sb);
19087 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19088 +static int au_h_path_to_set_attr(struct dentry *dentry,
19089 + struct au_icpup_args *a, struct path *h_path)
19092 + struct super_block *sb;
19094 + sb = dentry->d_sb;
19095 + a->udba = au_opt_udba(sb);
19096 + /* no d_unlinked(), to set UDBA_NONE for root */
19097 + if (d_unhashed(dentry))
19098 + a->udba = AuOpt_UDBA_NONE;
19099 + if (a->udba != AuOpt_UDBA_NONE) {
19100 + AuDebugOn(IS_ROOT(dentry));
19101 + err = au_reval_for_attr(dentry, au_sigen(sb));
19102 + if (unlikely(err))
19105 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19106 + if (unlikely(err < 0))
19109 + h_path->dentry = a->h_path.dentry;
19110 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19116 +ssize_t au_srxattr(struct dentry *dentry, struct au_srxattr *arg)
19119 + struct path h_path;
19120 + struct super_block *sb;
19121 + struct au_icpup_args *a;
19122 + struct inode *inode, *h_inode;
19124 + inode = d_inode(dentry);
19125 + IMustLock(inode);
19128 + a = kzalloc(sizeof(*a), GFP_NOFS);
19129 + if (unlikely(!a))
19132 + sb = dentry->d_sb;
19133 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19134 + if (unlikely(err))
19137 + h_path.dentry = NULL; /* silence gcc */
19138 + di_write_lock_child(dentry);
19139 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19140 + if (unlikely(err))
19143 + mutex_unlock(&a->h_inode->i_mutex);
19144 + switch (arg->type) {
19145 + case AU_XATTR_SET:
19146 + err = vfsub_setxattr(h_path.dentry,
19147 + arg->u.set.name, arg->u.set.value,
19148 + arg->u.set.size, arg->u.set.flags);
19150 + case AU_XATTR_REMOVE:
19151 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
19154 + err = -EOPNOTSUPP;
19155 + h_inode = d_inode(h_path.dentry);
19156 + if (h_inode->i_op->set_acl)
19157 + err = h_inode->i_op->set_acl(h_inode,
19158 + arg->u.acl_set.acl,
19159 + arg->u.acl_set.type);
19163 + au_cpup_attr_timesizes(inode);
19165 + au_unpin(&a->pin);
19166 + if (unlikely(err))
19167 + au_update_dbstart(dentry);
19170 + di_write_unlock(dentry);
19171 + si_read_unlock(sb);
19180 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19181 + unsigned int nlink)
19185 + inode->i_mode = st->mode;
19186 + /* don't i_[ug]id_write() here */
19187 + inode->i_uid = st->uid;
19188 + inode->i_gid = st->gid;
19189 + inode->i_atime = st->atime;
19190 + inode->i_mtime = st->mtime;
19191 + inode->i_ctime = st->ctime;
19193 + au_cpup_attr_nlink(inode, /*force*/0);
19194 + if (S_ISDIR(inode->i_mode)) {
19195 + n = inode->i_nlink;
19198 + smp_mb(); /* for i_nlink */
19199 + /* 0 can happen */
19200 + set_nlink(inode, n);
19203 + spin_lock(&inode->i_lock);
19204 + inode->i_blocks = st->blocks;
19205 + i_size_write(inode, st->size);
19206 + spin_unlock(&inode->i_lock);
19210 + * common routine for aufs_getattr() and aufs_getxattr().
19211 + * returns zero or negative (an error).
19212 + * @dentry will be read-locked in success.
19214 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
19217 + unsigned int mnt_flags, sigen;
19218 + unsigned char udba_none;
19219 + aufs_bindex_t bindex;
19220 + struct super_block *sb, *h_sb;
19221 + struct inode *inode;
19223 + h_path->mnt = NULL;
19224 + h_path->dentry = NULL;
19227 + sb = dentry->d_sb;
19228 + mnt_flags = au_mntflags(sb);
19229 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19231 + /* support fstat(2) */
19232 + if (!d_unlinked(dentry) && !udba_none) {
19233 + sigen = au_sigen(sb);
19234 + err = au_digen_test(dentry, sigen);
19236 + di_read_lock_child(dentry, AuLock_IR);
19237 + err = au_dbrange_test(dentry);
19238 + if (unlikely(err)) {
19239 + di_read_unlock(dentry, AuLock_IR);
19243 + AuDebugOn(IS_ROOT(dentry));
19244 + di_write_lock_child(dentry);
19245 + err = au_dbrange_test(dentry);
19247 + err = au_reval_for_attr(dentry, sigen);
19249 + di_downgrade_lock(dentry, AuLock_IR);
19251 + di_write_unlock(dentry);
19256 + di_read_lock_child(dentry, AuLock_IR);
19258 + inode = d_inode(dentry);
19259 + bindex = au_ibstart(inode);
19260 + h_path->mnt = au_sbr_mnt(sb, bindex);
19261 + h_sb = h_path->mnt->mnt_sb;
19263 + && !au_test_fs_bad_iattr(h_sb)
19265 + goto out; /* success */
19267 + if (au_dbstart(dentry) == bindex)
19268 + h_path->dentry = au_h_dptr(dentry, bindex);
19269 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19270 + h_path->dentry = au_plink_lkup(inode, bindex);
19271 + if (IS_ERR(h_path->dentry))
19272 + /* pretending success */
19273 + h_path->dentry = NULL;
19275 + dput(h_path->dentry);
19282 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19283 + struct dentry *dentry, struct kstat *st)
19286 + unsigned char positive;
19287 + struct path h_path;
19288 + struct inode *inode;
19289 + struct super_block *sb;
19291 + inode = d_inode(dentry);
19292 + sb = dentry->d_sb;
19293 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19294 + if (unlikely(err))
19296 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
19297 + if (unlikely(err))
19299 + if (unlikely(!h_path.dentry))
19300 + /* illegally overlapped or something */
19301 + goto out_fill; /* pretending success */
19303 + positive = d_is_positive(h_path.dentry);
19305 + err = vfs_getattr(&h_path, st);
19308 + au_refresh_iattr(inode, st,
19309 + d_inode(h_path.dentry)->i_nlink);
19310 + goto out_fill; /* success */
19316 + generic_fillattr(inode, st);
19318 + di_read_unlock(dentry, AuLock_IR);
19320 + si_read_unlock(sb);
19326 +/* ---------------------------------------------------------------------- */
19330 + * - the number of symlinks is not so many.
19333 + * - sbinfo (instead of iinfo) contains an hlist of struct au_symlink.
19334 + * If iinfo contained the hlist, then it would be rather large waste of memory
19336 + * - struct au_symlink contains the necessary info for h_inode follow_link() and
19340 +struct au_symlink {
19342 + struct hlist_node hlist;
19343 + struct rcu_head rcu;
19346 + struct inode *h_inode;
19350 +static void au_symlink_add(struct super_block *sb, struct au_symlink *slink,
19351 + struct inode *h_inode, void *cookie)
19353 + struct au_sbinfo *sbinfo;
19356 + slink->h_inode = h_inode;
19357 + slink->h_cookie = cookie;
19358 + sbinfo = au_sbi(sb);
19359 + au_sphl_add(&slink->hlist, &sbinfo->si_symlink);
19362 +static void au_symlink_del(struct super_block *sb, struct au_symlink *slink)
19364 + struct au_sbinfo *sbinfo;
19366 + /* do not iput() within rcu */
19367 + iput(slink->h_inode);
19368 + slink->h_inode = NULL;
19369 + sbinfo = au_sbi(sb);
19370 + au_sphl_del_rcu(&slink->hlist, &sbinfo->si_symlink);
19371 + kfree_rcu(slink, rcu);
19374 +static const char *aufs_follow_link(struct dentry *dentry, void **cookie)
19377 + struct inode *inode, *h_inode;
19378 + struct dentry *h_dentry;
19379 + struct au_symlink *slink;
19381 + aufs_bindex_t bindex;
19383 + ret = NULL; /* supress a warning */
19384 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19385 + if (unlikely(err))
19388 + err = au_d_hashed_positive(dentry);
19389 + if (unlikely(err))
19393 + inode = d_inode(dentry);
19394 + bindex = au_ibstart(inode);
19395 + h_inode = au_h_iptr(inode, bindex);
19396 + if (unlikely(!h_inode->i_op->follow_link))
19400 + slink = kmalloc(sizeof(*slink), GFP_NOFS);
19401 + if (unlikely(!slink))
19406 + if (au_dbstart(dentry) <= bindex) {
19407 + h_dentry = au_h_dptr(dentry, bindex);
19412 + h_dentry = d_find_any_alias(h_inode);
19413 + if (IS_ERR(h_dentry)) {
19414 + err = PTR_ERR(h_dentry);
19418 + if (unlikely(!h_dentry))
19422 + AuDbg("%pf\n", h_inode->i_op->follow_link);
19423 + AuDbgDentry(h_dentry);
19424 + ret = h_inode->i_op->follow_link(h_dentry, cookie);
19427 + if (!IS_ERR_OR_NULL(ret)) {
19428 + au_symlink_add(inode->i_sb, slink, h_inode, *cookie);
19430 + AuDbg("slink %p\n", slink);
19431 + goto out_unlock; /* success */
19435 + slink->h_inode = NULL;
19436 + kfree_rcu(slink, rcu);
19438 + aufs_read_unlock(dentry, AuLock_IR);
19440 + if (unlikely(err))
19441 + ret = ERR_PTR(err);
19442 + AuTraceErrPtr(ret);
19446 +static void aufs_put_link(struct inode *inode, void *cookie)
19448 + struct au_symlink *slink;
19449 + struct inode *h_inode;
19452 + AuDbg("slink %p\n", slink);
19453 + h_inode = slink->h_inode;
19454 + AuDbg("%pf\n", h_inode->i_op->put_link);
19455 + AuDbgInode(h_inode);
19456 + if (h_inode->i_op->put_link)
19457 + h_inode->i_op->put_link(h_inode, slink->h_cookie);
19458 + au_symlink_del(inode->i_sb, slink);
19461 +/* ---------------------------------------------------------------------- */
19463 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19466 + struct super_block *sb;
19467 + struct inode *h_inode;
19469 + sb = inode->i_sb;
19470 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19472 + si_read_lock(sb, AuLock_FLUSH);
19473 + ii_write_lock_child(inode);
19475 + h_inode = au_h_iptr(inode, au_ibstart(inode));
19476 + err = vfsub_update_time(h_inode, ts, flags);
19479 + au_cpup_attr_timesizes(inode);
19480 + ii_write_unlock(inode);
19481 + si_read_unlock(sb);
19484 + if (!err && (flags & S_VERSION))
19485 + inode_inc_iversion(inode);
19490 +/* ---------------------------------------------------------------------- */
19492 +struct inode_operations aufs_symlink_iop = {
19493 + .permission = aufs_permission,
19494 +#ifdef CONFIG_FS_POSIX_ACL
19495 + .get_acl = aufs_get_acl,
19496 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19499 + .setattr = aufs_setattr,
19500 + .getattr = aufs_getattr,
19502 +#ifdef CONFIG_AUFS_XATTR
19503 + .setxattr = aufs_setxattr,
19504 + .getxattr = aufs_getxattr,
19505 + .listxattr = aufs_listxattr,
19506 + .removexattr = aufs_removexattr,
19509 + .readlink = generic_readlink,
19510 + .follow_link = aufs_follow_link,
19511 + .put_link = aufs_put_link,
19513 + /* .update_time = aufs_update_time */
19516 +struct inode_operations aufs_dir_iop = {
19517 + .create = aufs_create,
19518 + .lookup = aufs_lookup,
19519 + .link = aufs_link,
19520 + .unlink = aufs_unlink,
19521 + .symlink = aufs_symlink,
19522 + .mkdir = aufs_mkdir,
19523 + .rmdir = aufs_rmdir,
19524 + .mknod = aufs_mknod,
19525 + .rename = aufs_rename,
19527 + .permission = aufs_permission,
19528 +#ifdef CONFIG_FS_POSIX_ACL
19529 + .get_acl = aufs_get_acl,
19530 + .set_acl = aufs_set_acl,
19533 + .setattr = aufs_setattr,
19534 + .getattr = aufs_getattr,
19536 +#ifdef CONFIG_AUFS_XATTR
19537 + .setxattr = aufs_setxattr,
19538 + .getxattr = aufs_getxattr,
19539 + .listxattr = aufs_listxattr,
19540 + .removexattr = aufs_removexattr,
19543 + .update_time = aufs_update_time,
19544 + .atomic_open = aufs_atomic_open,
19545 + .tmpfile = aufs_tmpfile
19548 +struct inode_operations aufs_iop = {
19549 + .permission = aufs_permission,
19550 +#ifdef CONFIG_FS_POSIX_ACL
19551 + .get_acl = aufs_get_acl,
19552 + .set_acl = aufs_set_acl,
19555 + .setattr = aufs_setattr,
19556 + .getattr = aufs_getattr,
19558 +#ifdef CONFIG_AUFS_XATTR
19559 + .setxattr = aufs_setxattr,
19560 + .getxattr = aufs_getxattr,
19561 + .listxattr = aufs_listxattr,
19562 + .removexattr = aufs_removexattr,
19565 + .update_time = aufs_update_time
19567 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19568 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19569 +++ linux/fs/aufs/i_op_del.c 2015-09-24 10:47:58.254719746 +0200
19572 + * Copyright (C) 2005-2015 Junjiro R. Okajima
19574 + * This program, aufs is free software; you can redistribute it and/or modify
19575 + * it under the terms of the GNU General Public License as published by
19576 + * the Free Software Foundation; either version 2 of the License, or
19577 + * (at your option) any later version.
19579 + * This program is distributed in the hope that it will be useful,
19580 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19581 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19582 + * GNU General Public License for more details.
19584 + * You should have received a copy of the GNU General Public License
19585 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19589 + * inode operations (del entry)
19595 + * decide if a new whiteout for @dentry is necessary or not.
19596 + * when it is necessary, prepare the parent dir for the upper branch whose
19597 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19598 + * be done by caller.
19600 + * 0: wh is unnecessary
19601 + * plus: wh is necessary
19604 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19606 + int need_wh, err;
19607 + aufs_bindex_t bstart;
19608 + struct super_block *sb;
19610 + sb = dentry->d_sb;
19611 + bstart = au_dbstart(dentry);
19612 + if (*bcpup < 0) {
19614 + if (au_test_ro(sb, bstart, d_inode(dentry))) {
19615 + err = AuWbrCopyup(au_sbi(sb), dentry);
19617 + if (unlikely(err < 0))
19621 + AuDebugOn(bstart < *bcpup
19622 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
19623 + AuDbg("bcpup %d, bstart %d\n", *bcpup, bstart);
19625 + if (*bcpup != bstart) {
19626 + err = au_cpup_dirs(dentry, *bcpup);
19627 + if (unlikely(err))
19631 + struct au_dinfo *dinfo, *tmp;
19633 + need_wh = -ENOMEM;
19634 + dinfo = au_di(dentry);
19635 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19637 + au_di_cp(tmp, dinfo);
19638 + au_di_swap(tmp, dinfo);
19639 + /* returns the number of positive dentries */
19640 + need_wh = au_lkup_dentry(dentry, bstart + 1, /*type*/0);
19641 + au_di_swap(tmp, dinfo);
19642 + au_rw_write_unlock(&tmp->di_rwsem);
19646 + AuDbg("need_wh %d\n", need_wh);
19654 + * simple tests for the del-entry operations.
19655 + * following the checks in vfs, plus the parent-child relationship.
19657 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19658 + struct dentry *h_parent, int isdir)
19662 + struct dentry *h_dentry, *h_latest;
19663 + struct inode *h_inode;
19665 + h_dentry = au_h_dptr(dentry, bindex);
19666 + if (d_really_is_positive(dentry)) {
19668 + if (unlikely(d_is_negative(h_dentry)))
19670 + h_inode = d_inode(h_dentry);
19671 + if (unlikely(!h_inode->i_nlink))
19674 + h_mode = h_inode->i_mode;
19677 + if (unlikely(S_ISDIR(h_mode)))
19679 + } else if (unlikely(!S_ISDIR(h_mode))) {
19684 + /* rename(2) case */
19686 + if (unlikely(d_is_positive(h_dentry)))
19691 + /* expected parent dir is locked */
19692 + if (unlikely(h_parent != h_dentry->d_parent))
19697 + * rmdir a dir may break the consistency on some filesystem.
19698 + * let's try heavy test.
19701 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
19702 + && au_test_h_perm(d_inode(h_parent),
19703 + MAY_EXEC | MAY_WRITE)))
19706 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
19708 + if (IS_ERR(h_latest))
19710 + if (h_latest == h_dentry)
19719 + * decide the branch where we operate for @dentry. the branch index will be set
19720 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
19721 + * dir for reverting.
19722 + * when a new whiteout is necessary, create it.
19724 +static struct dentry*
19725 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
19726 + struct au_dtime *dt, struct au_pin *pin)
19728 + struct dentry *wh_dentry;
19729 + struct super_block *sb;
19730 + struct path h_path;
19731 + int err, need_wh;
19732 + unsigned int udba;
19733 + aufs_bindex_t bcpup;
19735 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
19736 + wh_dentry = ERR_PTR(need_wh);
19737 + if (unlikely(need_wh < 0))
19740 + sb = dentry->d_sb;
19741 + udba = au_opt_udba(sb);
19743 + err = au_pin(pin, dentry, bcpup, udba,
19744 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19745 + wh_dentry = ERR_PTR(err);
19746 + if (unlikely(err))
19749 + h_path.dentry = au_pinned_h_parent(pin);
19750 + if (udba != AuOpt_UDBA_NONE
19751 + && au_dbstart(dentry) == bcpup) {
19752 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
19753 + wh_dentry = ERR_PTR(err);
19754 + if (unlikely(err))
19758 + h_path.mnt = au_sbr_mnt(sb, bcpup);
19759 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
19760 + wh_dentry = NULL;
19762 + goto out; /* success, no need to create whiteout */
19764 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
19765 + if (IS_ERR(wh_dentry))
19768 + /* returns with the parent is locked and wh_dentry is dget-ed */
19769 + goto out; /* success */
19774 + return wh_dentry;
19778 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
19779 + * in order to be revertible and save time for removing many child whiteouts
19781 + * returns 1 when there are too many child whiteout and caller should remove
19782 + * them asynchronously. returns 0 when the number of children is enough small to
19783 + * remove now or the branch fs is a remote fs.
19784 + * otherwise return an error.
19786 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
19787 + struct au_nhash *whlist, struct inode *dir)
19789 + int rmdir_later, err, dirwh;
19790 + struct dentry *h_dentry;
19791 + struct super_block *sb;
19792 + struct inode *inode;
19794 + sb = dentry->d_sb;
19795 + SiMustAnyLock(sb);
19796 + h_dentry = au_h_dptr(dentry, bindex);
19797 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
19798 + if (unlikely(err))
19801 + /* stop monitoring */
19802 + inode = d_inode(dentry);
19803 + au_hn_free(au_hi(inode, bindex));
19805 + if (!au_test_fs_remote(h_dentry->d_sb)) {
19806 + dirwh = au_sbi(sb)->si_dirwh;
19807 + rmdir_later = (dirwh <= 1);
19808 + if (!rmdir_later)
19809 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
19812 + return rmdir_later;
19815 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
19816 + if (unlikely(err)) {
19817 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
19818 + h_dentry, bindex, err);
19828 + * final procedure for deleting a entry.
19829 + * maintain dentry and iattr.
19831 +static void epilog(struct inode *dir, struct dentry *dentry,
19832 + aufs_bindex_t bindex)
19834 + struct inode *inode;
19836 + inode = d_inode(dentry);
19838 + inode->i_ctime = dir->i_ctime;
19840 + au_dir_ts(dir, bindex);
19841 + dir->i_version++;
19845 + * when an error happened, remove the created whiteout and revert everything.
19847 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
19848 + aufs_bindex_t bwh, struct dentry *wh_dentry,
19849 + struct dentry *dentry, struct au_dtime *dt)
19852 + struct path h_path = {
19853 + .dentry = wh_dentry,
19854 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
19857 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
19859 + au_set_dbwh(dentry, bwh);
19860 + au_dtime_revert(dt);
19864 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
19868 +/* ---------------------------------------------------------------------- */
19870 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
19873 + aufs_bindex_t bwh, bindex, bstart;
19874 + struct inode *inode, *h_dir, *delegated;
19875 + struct dentry *parent, *wh_dentry;
19876 + /* to reuduce stack size */
19878 + struct au_dtime dt;
19879 + struct au_pin pin;
19880 + struct path h_path;
19886 + a = kmalloc(sizeof(*a), GFP_NOFS);
19887 + if (unlikely(!a))
19890 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
19891 + if (unlikely(err))
19893 + err = au_d_hashed_positive(dentry);
19894 + if (unlikely(err))
19896 + inode = d_inode(dentry);
19897 + IMustLock(inode);
19899 + if (unlikely(d_is_dir(dentry)))
19900 + goto out_unlock; /* possible? */
19902 + bstart = au_dbstart(dentry);
19903 + bwh = au_dbwh(dentry);
19905 + parent = dentry->d_parent; /* dir inode is locked */
19906 + di_write_lock_parent(parent);
19907 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
19909 + err = PTR_ERR(wh_dentry);
19910 + if (IS_ERR(wh_dentry))
19913 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, bstart);
19914 + a->h_path.dentry = au_h_dptr(dentry, bstart);
19915 + dget(a->h_path.dentry);
19916 + if (bindex == bstart) {
19917 + h_dir = au_pinned_h_dir(&a->pin);
19918 + delegated = NULL;
19919 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
19920 + if (unlikely(err == -EWOULDBLOCK)) {
19921 + pr_warn("cannot retry for NFSv4 delegation"
19922 + " for an internal unlink\n");
19926 + /* dir inode is locked */
19927 + h_dir = d_inode(wh_dentry->d_parent);
19928 + IMustLock(h_dir);
19933 + vfsub_drop_nlink(inode);
19934 + epilog(dir, dentry, bindex);
19936 + /* update target timestamps */
19937 + if (bindex == bstart) {
19938 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
19940 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
19942 + /* todo: this timestamp may be reverted later */
19943 + inode->i_ctime = h_dir->i_ctime;
19944 + goto out_unpin; /* success */
19951 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
19958 + au_unpin(&a->pin);
19960 + dput(a->h_path.dentry);
19962 + di_write_unlock(parent);
19964 + aufs_read_unlock(dentry, AuLock_DW);
19971 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
19973 + int err, rmdir_later;
19974 + aufs_bindex_t bwh, bindex, bstart;
19975 + struct inode *inode;
19976 + struct dentry *parent, *wh_dentry, *h_dentry;
19977 + struct au_whtmp_rmdir *args;
19978 + /* to reuduce stack size */
19980 + struct au_dtime dt;
19981 + struct au_pin pin;
19987 + a = kmalloc(sizeof(*a), GFP_NOFS);
19988 + if (unlikely(!a))
19991 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
19992 + if (unlikely(err))
19994 + err = au_alive_dir(dentry);
19995 + if (unlikely(err))
19997 + inode = d_inode(dentry);
19998 + IMustLock(inode);
20000 + if (unlikely(!d_is_dir(dentry)))
20001 + goto out_unlock; /* possible? */
20004 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20005 + if (unlikely(!args))
20008 + parent = dentry->d_parent; /* dir inode is locked */
20009 + di_write_lock_parent(parent);
20010 + err = au_test_empty(dentry, &args->whlist);
20011 + if (unlikely(err))
20014 + bstart = au_dbstart(dentry);
20015 + bwh = au_dbwh(dentry);
20017 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20019 + err = PTR_ERR(wh_dentry);
20020 + if (IS_ERR(wh_dentry))
20023 + h_dentry = au_h_dptr(dentry, bstart);
20026 + if (bindex == bstart) {
20027 + err = renwh_and_rmdir(dentry, bstart, &args->whlist, dir);
20029 + rmdir_later = err;
20033 + /* stop monitoring */
20034 + au_hn_free(au_hi(inode, bstart));
20036 + /* dir inode is locked */
20037 + IMustLock(d_inode(wh_dentry->d_parent));
20042 + vfsub_dead_dir(inode);
20043 + au_set_dbdiropq(dentry, -1);
20044 + epilog(dir, dentry, bindex);
20046 + if (rmdir_later) {
20047 + au_whtmp_kick_rmdir(dir, bstart, h_dentry, args);
20051 + goto out_unpin; /* success */
20059 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20066 + au_unpin(&a->pin);
20070 + di_write_unlock(parent);
20072 + au_whtmp_rmdir_free(args);
20074 + aufs_read_unlock(dentry, AuLock_DW);
20081 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20082 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20083 +++ linux/fs/aufs/i_op_ren.c 2015-09-24 10:47:58.254719746 +0200
20086 + * Copyright (C) 2005-2015 Junjiro R. Okajima
20088 + * This program, aufs is free software; you can redistribute it and/or modify
20089 + * it under the terms of the GNU General Public License as published by
20090 + * the Free Software Foundation; either version 2 of the License, or
20091 + * (at your option) any later version.
20093 + * This program is distributed in the hope that it will be useful,
20094 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20095 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20096 + * GNU General Public License for more details.
20098 + * You should have received a copy of the GNU General Public License
20099 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20103 + * inode operation (rename entry)
20104 + * todo: this is crazy monster
20109 +enum { AuSRC, AuDST, AuSrcDst };
20110 +enum { AuPARENT, AuCHILD, AuParentChild };
20112 +#define AuRen_ISDIR 1
20113 +#define AuRen_ISSAMEDIR (1 << 1)
20114 +#define AuRen_WHSRC (1 << 2)
20115 +#define AuRen_WHDST (1 << 3)
20116 +#define AuRen_MNT_WRITE (1 << 4)
20117 +#define AuRen_DT_DSTDIR (1 << 5)
20118 +#define AuRen_DIROPQ (1 << 6)
20119 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20120 +#define au_fset_ren(flags, name) \
20121 + do { (flags) |= AuRen_##name; } while (0)
20122 +#define au_fclr_ren(flags, name) \
20123 + do { (flags) &= ~AuRen_##name; } while (0)
20125 +struct au_ren_args {
20127 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20129 + struct inode *dir, *inode;
20130 + struct au_hinode *hdir;
20131 + struct au_dtime dt[AuParentChild];
20132 + aufs_bindex_t bstart;
20135 +#define src_dentry sd[AuSRC].dentry
20136 +#define src_dir sd[AuSRC].dir
20137 +#define src_inode sd[AuSRC].inode
20138 +#define src_h_dentry sd[AuSRC].h_dentry
20139 +#define src_parent sd[AuSRC].parent
20140 +#define src_h_parent sd[AuSRC].h_parent
20141 +#define src_wh_dentry sd[AuSRC].wh_dentry
20142 +#define src_hdir sd[AuSRC].hdir
20143 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20144 +#define src_dt sd[AuSRC].dt
20145 +#define src_bstart sd[AuSRC].bstart
20147 +#define dst_dentry sd[AuDST].dentry
20148 +#define dst_dir sd[AuDST].dir
20149 +#define dst_inode sd[AuDST].inode
20150 +#define dst_h_dentry sd[AuDST].h_dentry
20151 +#define dst_parent sd[AuDST].parent
20152 +#define dst_h_parent sd[AuDST].h_parent
20153 +#define dst_wh_dentry sd[AuDST].wh_dentry
20154 +#define dst_hdir sd[AuDST].hdir
20155 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20156 +#define dst_dt sd[AuDST].dt
20157 +#define dst_bstart sd[AuDST].bstart
20159 + struct dentry *h_trap;
20160 + struct au_branch *br;
20161 + struct au_hinode *src_hinode;
20162 + struct path h_path;
20163 + struct au_nhash whlist;
20164 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
20166 + unsigned int flags;
20168 + struct au_whtmp_rmdir *thargs;
20169 + struct dentry *h_dst;
20172 +/* ---------------------------------------------------------------------- */
20175 + * functions for reverting.
20176 + * when an error happened in a single rename systemcall, we should revert
20177 + * everything as if nothing happend.
20178 + * we don't need to revert the copied-up/down the parent dir since they are
20182 +#define RevertFailure(fmt, ...) do { \
20183 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20184 + ##__VA_ARGS__, err, rerr); \
20188 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20192 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20193 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
20194 + au_hn_imtx_unlock(a->src_hinode);
20195 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
20197 + RevertFailure("remove diropq %pd", a->src_dentry);
20200 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20203 + struct inode *delegated;
20205 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20206 + a->src_h_parent);
20207 + rerr = PTR_ERR(a->h_path.dentry);
20208 + if (IS_ERR(a->h_path.dentry)) {
20209 + RevertFailure("lkup one %pd", a->src_dentry);
20213 + delegated = NULL;
20214 + rerr = vfsub_rename(a->dst_h_dir,
20215 + au_h_dptr(a->src_dentry, a->btgt),
20216 + a->src_h_dir, &a->h_path, &delegated);
20217 + if (unlikely(rerr == -EWOULDBLOCK)) {
20218 + pr_warn("cannot retry for NFSv4 delegation"
20219 + " for an internal rename\n");
20222 + d_drop(a->h_path.dentry);
20223 + dput(a->h_path.dentry);
20224 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20226 + RevertFailure("rename %pd", a->src_dentry);
20229 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20232 + struct inode *delegated;
20234 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20235 + a->dst_h_parent);
20236 + rerr = PTR_ERR(a->h_path.dentry);
20237 + if (IS_ERR(a->h_path.dentry)) {
20238 + RevertFailure("lkup one %pd", a->dst_dentry);
20241 + if (d_is_positive(a->h_path.dentry)) {
20242 + d_drop(a->h_path.dentry);
20243 + dput(a->h_path.dentry);
20247 + delegated = NULL;
20248 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20250 + if (unlikely(rerr == -EWOULDBLOCK)) {
20251 + pr_warn("cannot retry for NFSv4 delegation"
20252 + " for an internal rename\n");
20255 + d_drop(a->h_path.dentry);
20256 + dput(a->h_path.dentry);
20258 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20260 + RevertFailure("rename %pd", a->h_dst);
20263 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20267 + a->h_path.dentry = a->src_wh_dentry;
20268 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20269 + au_set_dbwh(a->src_dentry, a->src_bwh);
20271 + RevertFailure("unlink %pd", a->src_wh_dentry);
20273 +#undef RevertFailure
20275 +/* ---------------------------------------------------------------------- */
20278 + * when we have to copyup the renaming entry, do it with the rename-target name
20279 + * in order to minimize the cost (the later actual rename is unnecessary).
20280 + * otherwise rename it on the target branch.
20282 +static int au_ren_or_cpup(struct au_ren_args *a)
20285 + struct dentry *d;
20286 + struct inode *delegated;
20288 + d = a->src_dentry;
20289 + if (au_dbstart(d) == a->btgt) {
20290 + a->h_path.dentry = a->dst_h_dentry;
20291 + if (au_ftest_ren(a->flags, DIROPQ)
20292 + && au_dbdiropq(d) == a->btgt)
20293 + au_fclr_ren(a->flags, DIROPQ);
20294 + AuDebugOn(au_dbstart(d) != a->btgt);
20295 + delegated = NULL;
20296 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20297 + a->dst_h_dir, &a->h_path, &delegated);
20298 + if (unlikely(err == -EWOULDBLOCK)) {
20299 + pr_warn("cannot retry for NFSv4 delegation"
20300 + " for an internal rename\n");
20306 + if (!err && a->h_dst)
20307 + /* it will be set to dinfo later */
20313 +/* cf. aufs_rmdir() */
20314 +static int au_ren_del_whtmp(struct au_ren_args *a)
20317 + struct inode *dir;
20319 + dir = a->dst_dir;
20320 + SiMustAnyLock(dir->i_sb);
20321 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20322 + au_sbi(dir->i_sb)->si_dirwh)
20323 + || au_test_fs_remote(a->h_dst->d_sb)) {
20324 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20325 + if (unlikely(err))
20326 + pr_warn("failed removing whtmp dir %pd (%d), "
20327 + "ignored.\n", a->h_dst, err);
20329 + au_nhash_wh_free(&a->thargs->whlist);
20330 + a->thargs->whlist = a->whlist;
20331 + a->whlist.nh_num = 0;
20332 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20334 + a->thargs = NULL;
20340 +/* make it 'opaque' dir. */
20341 +static int au_ren_diropq(struct au_ren_args *a)
20344 + struct dentry *diropq;
20347 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
20348 + a->src_hinode = au_hi(a->src_inode, a->btgt);
20349 + au_hn_imtx_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20350 + diropq = au_diropq_create(a->src_dentry, a->btgt);
20351 + au_hn_imtx_unlock(a->src_hinode);
20352 + if (IS_ERR(diropq))
20353 + err = PTR_ERR(diropq);
20360 +static int do_rename(struct au_ren_args *a)
20363 + struct dentry *d, *h_d;
20365 + /* prepare workqueue args for asynchronous rmdir */
20366 + h_d = a->dst_h_dentry;
20367 + if (au_ftest_ren(a->flags, ISDIR) && d_is_positive(h_d)) {
20369 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
20370 + if (unlikely(!a->thargs))
20372 + a->h_dst = dget(h_d);
20375 + /* create whiteout for src_dentry */
20376 + if (au_ftest_ren(a->flags, WHSRC)) {
20377 + a->src_bwh = au_dbwh(a->src_dentry);
20378 + AuDebugOn(a->src_bwh >= 0);
20380 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
20381 + err = PTR_ERR(a->src_wh_dentry);
20382 + if (IS_ERR(a->src_wh_dentry))
20386 + /* lookup whiteout for dentry */
20387 + if (au_ftest_ren(a->flags, WHDST)) {
20388 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
20390 + err = PTR_ERR(h_d);
20393 + if (d_is_negative(h_d))
20396 + a->dst_wh_dentry = h_d;
20399 + /* rename dentry to tmpwh */
20401 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20402 + if (unlikely(err))
20405 + d = a->dst_dentry;
20406 + au_set_h_dptr(d, a->btgt, NULL);
20407 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20408 + if (unlikely(err))
20410 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20413 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_bstart != a->btgt);
20415 + /* rename by vfs_rename or cpup */
20416 + d = a->dst_dentry;
20417 + if (au_ftest_ren(a->flags, ISDIR)
20418 + && (a->dst_wh_dentry
20419 + || au_dbdiropq(d) == a->btgt
20420 + /* hide the lower to keep xino */
20421 + || a->btgt < au_dbend(d)
20422 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
20423 + au_fset_ren(a->flags, DIROPQ);
20424 + err = au_ren_or_cpup(a);
20425 + if (unlikely(err))
20426 + /* leave the copied-up one */
20429 + /* make dir opaque */
20430 + if (au_ftest_ren(a->flags, DIROPQ)) {
20431 + err = au_ren_diropq(a);
20432 + if (unlikely(err))
20436 + /* update target timestamps */
20437 + AuDebugOn(au_dbstart(a->src_dentry) != a->btgt);
20438 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20439 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20440 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20442 + /* remove whiteout for dentry */
20443 + if (a->dst_wh_dentry) {
20444 + a->h_path.dentry = a->dst_wh_dentry;
20445 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20447 + if (unlikely(err))
20451 + /* remove whtmp */
20453 + au_ren_del_whtmp(a); /* ignore this error */
20455 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20457 + goto out_success;
20460 + if (au_ftest_ren(a->flags, DIROPQ))
20461 + au_ren_rev_diropq(err, a);
20463 + au_ren_rev_rename(err, a);
20467 + au_ren_rev_whtmp(err, a);
20469 + dput(a->dst_wh_dentry);
20470 + a->dst_wh_dentry = NULL;
20472 + if (a->src_wh_dentry)
20473 + au_ren_rev_whsrc(err, a);
20475 + dput(a->src_wh_dentry);
20476 + dput(a->dst_wh_dentry);
20480 + au_whtmp_rmdir_free(a->thargs);
20481 + a->thargs = NULL;
20487 +/* ---------------------------------------------------------------------- */
20490 + * test if @dentry dir can be rename destination or not.
20491 + * success means, it is a logically empty dir.
20493 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20495 + return au_test_empty(dentry, whlist);
20499 + * test if @dentry dir can be rename source or not.
20500 + * if it can, return 0 and @children is filled.
20502 + * - it is a logically empty dir.
20503 + * - or, it exists on writable branch and has no children including whiteouts
20504 + * on the lower branch.
20506 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20509 + unsigned int rdhash;
20510 + aufs_bindex_t bstart;
20512 + bstart = au_dbstart(dentry);
20513 + if (bstart != btgt) {
20514 + struct au_nhash whlist;
20516 + SiMustAnyLock(dentry->d_sb);
20517 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20519 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20521 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20522 + if (unlikely(err))
20524 + err = au_test_empty(dentry, &whlist);
20525 + au_nhash_wh_free(&whlist);
20529 + if (bstart == au_dbtaildir(dentry))
20530 + return 0; /* success */
20532 + err = au_test_empty_lower(dentry);
20535 + if (err == -ENOTEMPTY) {
20536 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20537 + " is not supported\n");
20543 +/* side effect: sets whlist and h_dentry */
20544 +static int au_ren_may_dir(struct au_ren_args *a)
20547 + unsigned int rdhash;
20548 + struct dentry *d;
20550 + d = a->dst_dentry;
20551 + SiMustAnyLock(d->d_sb);
20554 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
20555 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20557 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20558 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20559 + if (unlikely(err))
20562 + au_set_dbstart(d, a->dst_bstart);
20563 + err = may_rename_dstdir(d, &a->whlist);
20564 + au_set_dbstart(d, a->btgt);
20566 + a->dst_h_dentry = au_h_dptr(d, au_dbstart(d));
20567 + if (unlikely(err))
20570 + d = a->src_dentry;
20571 + a->src_h_dentry = au_h_dptr(d, au_dbstart(d));
20572 + if (au_ftest_ren(a->flags, ISDIR)) {
20573 + err = may_rename_srcdir(d, a->btgt);
20574 + if (unlikely(err)) {
20575 + au_nhash_wh_free(&a->whlist);
20576 + a->whlist.nh_num = 0;
20583 +/* ---------------------------------------------------------------------- */
20586 + * simple tests for rename.
20587 + * following the checks in vfs, plus the parent-child relationship.
20589 +static int au_may_ren(struct au_ren_args *a)
20592 + struct inode *h_inode;
20594 + if (a->src_bstart == a->btgt) {
20595 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20596 + au_ftest_ren(a->flags, ISDIR));
20597 + if (unlikely(err))
20600 + if (unlikely(a->src_h_dentry == a->h_trap))
20605 + if (a->dst_bstart != a->btgt)
20608 + err = -ENOTEMPTY;
20609 + if (unlikely(a->dst_h_dentry == a->h_trap))
20613 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20614 + if (d_really_is_negative(a->dst_dentry)) {
20615 + if (d_is_negative(a->dst_h_dentry))
20616 + err = au_may_add(a->dst_dentry, a->btgt,
20617 + a->dst_h_parent, isdir);
20619 + if (unlikely(d_is_negative(a->dst_h_dentry)))
20621 + h_inode = d_inode(a->dst_h_dentry);
20622 + if (h_inode->i_nlink)
20623 + err = au_may_del(a->dst_dentry, a->btgt,
20624 + a->dst_h_parent, isdir);
20628 + if (unlikely(err == -ENOENT || err == -EEXIST))
20634 +/* ---------------------------------------------------------------------- */
20639 + * - src_dir and dir by lock_rename()
20640 + * - inode if exitsts
20643 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
20645 + * + di_write_lock2_child()
20646 + * + di_write_lock_child()
20647 + * + ii_write_lock_child()
20648 + * + di_write_lock_child2()
20649 + * + ii_write_lock_child2()
20650 + * + src_parent and parent
20651 + * + di_write_lock_parent()
20652 + * + ii_write_lock_parent()
20653 + * + di_write_lock_parent2()
20654 + * + ii_write_lock_parent2()
20655 + * + lower src_dir and dir by vfsub_lock_rename()
20656 + * + verify the every relationships between child and parent. if any
20657 + * of them failed, unlock all and return -EBUSY.
20659 +static void au_ren_unlock(struct au_ren_args *a)
20661 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
20662 + a->dst_h_parent, a->dst_hdir);
20663 + if (au_ftest_ren(a->flags, MNT_WRITE))
20664 + vfsub_mnt_drop_write(au_br_mnt(a->br));
20667 +static int au_ren_lock(struct au_ren_args *a)
20670 + unsigned int udba;
20673 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
20674 + a->src_hdir = au_hi(a->src_dir, a->btgt);
20675 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
20676 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
20678 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
20679 + if (unlikely(err))
20681 + au_fset_ren(a->flags, MNT_WRITE);
20682 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
20683 + a->dst_h_parent, a->dst_hdir);
20684 + udba = au_opt_udba(a->src_dentry->d_sb);
20685 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
20686 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
20687 + err = au_busy_or_stale();
20688 + if (!err && au_dbstart(a->src_dentry) == a->btgt)
20689 + err = au_h_verify(a->src_h_dentry, udba,
20690 + d_inode(a->src_h_parent), a->src_h_parent,
20692 + if (!err && au_dbstart(a->dst_dentry) == a->btgt)
20693 + err = au_h_verify(a->dst_h_dentry, udba,
20694 + d_inode(a->dst_h_parent), a->dst_h_parent,
20697 + goto out; /* success */
20699 + err = au_busy_or_stale();
20700 + au_ren_unlock(a);
20706 +/* ---------------------------------------------------------------------- */
20708 +static void au_ren_refresh_dir(struct au_ren_args *a)
20710 + struct inode *dir;
20712 + dir = a->dst_dir;
20713 + dir->i_version++;
20714 + if (au_ftest_ren(a->flags, ISDIR)) {
20715 + /* is this updating defined in POSIX? */
20716 + au_cpup_attr_timesizes(a->src_inode);
20717 + au_cpup_attr_nlink(dir, /*force*/1);
20720 + au_dir_ts(dir, a->btgt);
20722 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20725 + dir = a->src_dir;
20726 + dir->i_version++;
20727 + if (au_ftest_ren(a->flags, ISDIR))
20728 + au_cpup_attr_nlink(dir, /*force*/1);
20729 + au_dir_ts(dir, a->btgt);
20732 +static void au_ren_refresh(struct au_ren_args *a)
20734 + aufs_bindex_t bend, bindex;
20735 + struct dentry *d, *h_d;
20736 + struct inode *i, *h_i;
20737 + struct super_block *sb;
20739 + d = a->dst_dentry;
20742 + /* already dget-ed by au_ren_or_cpup() */
20743 + au_set_h_dptr(d, a->btgt, a->h_dst);
20745 + i = a->dst_inode;
20747 + if (!au_ftest_ren(a->flags, ISDIR))
20748 + vfsub_drop_nlink(i);
20750 + vfsub_dead_dir(i);
20751 + au_cpup_attr_timesizes(i);
20753 + au_update_dbrange(d, /*do_put_zero*/1);
20756 + for (bindex = au_dbstart(d); bindex < bend; bindex++)
20757 + au_set_h_dptr(d, bindex, NULL);
20758 + bend = au_dbend(d);
20759 + for (bindex = a->btgt + 1; bindex <= bend; bindex++)
20760 + au_set_h_dptr(d, bindex, NULL);
20761 + au_update_dbrange(d, /*do_put_zero*/0);
20764 + d = a->src_dentry;
20765 + au_set_dbwh(d, -1);
20766 + bend = au_dbend(d);
20767 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20768 + h_d = au_h_dptr(d, bindex);
20770 + au_set_h_dptr(d, bindex, NULL);
20772 + au_set_dbend(d, a->btgt);
20775 + i = a->src_inode;
20776 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
20777 + return; /* success */
20779 + bend = au_ibend(i);
20780 + for (bindex = a->btgt + 1; bindex <= bend; bindex++) {
20781 + h_i = au_h_iptr(i, bindex);
20783 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
20784 + /* ignore this error */
20785 + au_set_h_iptr(i, bindex, NULL, 0);
20788 + au_set_ibend(i, a->btgt);
20791 +/* ---------------------------------------------------------------------- */
20793 +/* mainly for link(2) and rename(2) */
20794 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
20796 + aufs_bindex_t bdiropq, bwh;
20797 + struct dentry *parent;
20798 + struct au_branch *br;
20800 + parent = dentry->d_parent;
20801 + IMustLock(d_inode(parent)); /* dir is locked */
20803 + bdiropq = au_dbdiropq(parent);
20804 + bwh = au_dbwh(dentry);
20805 + br = au_sbr(dentry->d_sb, btgt);
20806 + if (au_br_rdonly(br)
20807 + || (0 <= bdiropq && bdiropq < btgt)
20808 + || (0 <= bwh && bwh < btgt))
20811 + AuDbg("btgt %d\n", btgt);
20815 +/* sets src_bstart, dst_bstart and btgt */
20816 +static int au_ren_wbr(struct au_ren_args *a)
20819 + struct au_wr_dir_args wr_dir_args = {
20820 + /* .force_btgt = -1, */
20821 + .flags = AuWrDir_ADD_ENTRY
20824 + a->src_bstart = au_dbstart(a->src_dentry);
20825 + a->dst_bstart = au_dbstart(a->dst_dentry);
20826 + if (au_ftest_ren(a->flags, ISDIR))
20827 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
20828 + wr_dir_args.force_btgt = a->src_bstart;
20829 + if (a->dst_inode && a->dst_bstart < a->src_bstart)
20830 + wr_dir_args.force_btgt = a->dst_bstart;
20831 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
20832 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
20838 +static void au_ren_dt(struct au_ren_args *a)
20840 + a->h_path.dentry = a->src_h_parent;
20841 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
20842 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
20843 + a->h_path.dentry = a->dst_h_parent;
20844 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
20847 + au_fclr_ren(a->flags, DT_DSTDIR);
20848 + if (!au_ftest_ren(a->flags, ISDIR))
20851 + a->h_path.dentry = a->src_h_dentry;
20852 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
20853 + if (d_is_positive(a->dst_h_dentry)) {
20854 + au_fset_ren(a->flags, DT_DSTDIR);
20855 + a->h_path.dentry = a->dst_h_dentry;
20856 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
20860 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
20862 + struct dentry *h_d;
20863 + struct mutex *h_mtx;
20865 + au_dtime_revert(a->src_dt + AuPARENT);
20866 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
20867 + au_dtime_revert(a->dst_dt + AuPARENT);
20869 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
20870 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
20871 + h_mtx = &d_inode(h_d)->i_mutex;
20872 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20873 + au_dtime_revert(a->src_dt + AuCHILD);
20874 + mutex_unlock(h_mtx);
20876 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
20877 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
20878 + h_mtx = &d_inode(h_d)->i_mutex;
20879 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD);
20880 + au_dtime_revert(a->dst_dt + AuCHILD);
20881 + mutex_unlock(h_mtx);
20886 +/* ---------------------------------------------------------------------- */
20888 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
20889 + struct inode *_dst_dir, struct dentry *_dst_dentry)
20892 + /* reduce stack space */
20893 + struct au_ren_args *a;
20895 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
20896 + IMustLock(_src_dir);
20897 + IMustLock(_dst_dir);
20900 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
20901 + a = kzalloc(sizeof(*a), GFP_NOFS);
20902 + if (unlikely(!a))
20905 + a->src_dir = _src_dir;
20906 + a->src_dentry = _src_dentry;
20907 + a->src_inode = NULL;
20908 + if (d_really_is_positive(a->src_dentry))
20909 + a->src_inode = d_inode(a->src_dentry);
20910 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
20911 + a->dst_dir = _dst_dir;
20912 + a->dst_dentry = _dst_dentry;
20913 + a->dst_inode = NULL;
20914 + if (d_really_is_positive(a->dst_dentry))
20915 + a->dst_inode = d_inode(a->dst_dentry);
20916 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
20917 + if (a->dst_inode) {
20918 + IMustLock(a->dst_inode);
20919 + au_igrab(a->dst_inode);
20923 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
20924 + if (d_is_dir(a->src_dentry)) {
20925 + au_fset_ren(a->flags, ISDIR);
20926 + if (unlikely(d_really_is_positive(a->dst_dentry)
20927 + && !d_is_dir(a->dst_dentry)))
20929 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20930 + AuLock_DIR | flags);
20932 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry,
20934 + if (unlikely(err))
20937 + err = au_d_hashed_positive(a->src_dentry);
20938 + if (unlikely(err))
20941 + if (a->dst_inode) {
20943 + * If it is a dir, VFS unhash dst_dentry before this
20944 + * function. It means we cannot rely upon d_unhashed().
20946 + if (unlikely(!a->dst_inode->i_nlink))
20948 + if (!S_ISDIR(a->dst_inode->i_mode)) {
20949 + err = au_d_hashed_positive(a->dst_dentry);
20950 + if (unlikely(err))
20952 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
20954 + } else if (unlikely(d_unhashed(a->dst_dentry)))
20958 + * is it possible?
20959 + * yes, it happend (in linux-3.3-rcN) but I don't know why.
20960 + * there may exist a problem somewhere else.
20963 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
20966 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
20967 + di_write_lock_parent(a->dst_parent);
20969 + /* which branch we process */
20970 + err = au_ren_wbr(a);
20971 + if (unlikely(err < 0))
20973 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
20974 + a->h_path.mnt = au_br_mnt(a->br);
20976 + /* are they available to be renamed */
20977 + err = au_ren_may_dir(a);
20978 + if (unlikely(err))
20979 + goto out_children;
20981 + /* prepare the writable parent dir on the same branch */
20982 + if (a->dst_bstart == a->btgt) {
20983 + au_fset_ren(a->flags, WHDST);
20985 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
20986 + if (unlikely(err))
20987 + goto out_children;
20990 + if (a->src_dir != a->dst_dir) {
20992 + * this temporary unlock is safe,
20993 + * because both dir->i_mutex are locked.
20995 + di_write_unlock(a->dst_parent);
20996 + di_write_lock_parent(a->src_parent);
20997 + err = au_wr_dir_need_wh(a->src_dentry,
20998 + au_ftest_ren(a->flags, ISDIR),
21000 + di_write_unlock(a->src_parent);
21001 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
21002 + au_fclr_ren(a->flags, ISSAMEDIR);
21004 + err = au_wr_dir_need_wh(a->src_dentry,
21005 + au_ftest_ren(a->flags, ISDIR),
21007 + if (unlikely(err < 0))
21008 + goto out_children;
21010 + au_fset_ren(a->flags, WHSRC);
21013 + if (a->src_bstart != a->btgt) {
21014 + struct au_pin pin;
21016 + err = au_pin(&pin, a->src_dentry, a->btgt,
21017 + au_opt_udba(a->src_dentry->d_sb),
21018 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21020 + struct au_cp_generic cpg = {
21021 + .dentry = a->src_dentry,
21023 + .bsrc = a->src_bstart,
21026 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21028 + AuDebugOn(au_dbstart(a->src_dentry) != a->src_bstart);
21029 + err = au_sio_cpup_simple(&cpg);
21032 + if (unlikely(err))
21033 + goto out_children;
21034 + a->src_bstart = a->btgt;
21035 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21036 + au_fset_ren(a->flags, WHSRC);
21039 + /* lock them all */
21040 + err = au_ren_lock(a);
21041 + if (unlikely(err))
21042 + /* leave the copied-up one */
21043 + goto out_children;
21045 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21046 + err = au_may_ren(a);
21047 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21048 + err = -ENAMETOOLONG;
21049 + if (unlikely(err))
21052 + /* store timestamps to be revertible */
21056 + err = do_rename(a);
21057 + if (unlikely(err))
21060 + /* update dir attributes */
21061 + au_ren_refresh_dir(a);
21063 + /* dput/iput all lower dentries */
21064 + au_ren_refresh(a);
21066 + goto out_hdir; /* success */
21069 + au_ren_rev_dt(err, a);
21071 + au_ren_unlock(a);
21073 + au_nhash_wh_free(&a->whlist);
21074 + if (err && a->dst_inode && a->dst_bstart != a->btgt) {
21075 + AuDbg("bstart %d, btgt %d\n", a->dst_bstart, a->btgt);
21076 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21077 + au_set_dbstart(a->dst_dentry, a->dst_bstart);
21081 + d_move(a->src_dentry, a->dst_dentry);
21083 + au_update_dbstart(a->dst_dentry);
21084 + if (!a->dst_inode)
21085 + d_drop(a->dst_dentry);
21087 + if (au_ftest_ren(a->flags, ISSAMEDIR))
21088 + di_write_unlock(a->dst_parent);
21090 + di_write_unlock2(a->src_parent, a->dst_parent);
21092 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21094 + iput(a->dst_inode);
21096 + au_whtmp_rmdir_free(a->thargs);
21102 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21103 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21104 +++ linux/fs/aufs/Kconfig 2015-09-24 10:47:58.248052907 +0200
21107 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21109 + Aufs is a stackable unification filesystem such as Unionfs,
21110 + which unifies several directories and provides a merged single
21112 + In the early days, aufs was entirely re-designed and
21113 + re-implemented Unionfs Version 1.x series. Introducing many
21114 + original ideas, approaches and improvements, it becomes totally
21115 + different from Unionfs while keeping the basic features.
21119 + prompt "Maximum number of branches"
21120 + default AUFS_BRANCH_MAX_127
21122 + Specifies the maximum number of branches (or member directories)
21123 + in a single aufs. The larger value consumes more system
21124 + resources and has a minor impact to performance.
21125 +config AUFS_BRANCH_MAX_127
21128 + Specifies the maximum number of branches (or member directories)
21129 + in a single aufs. The larger value consumes more system
21130 + resources and has a minor impact to performance.
21131 +config AUFS_BRANCH_MAX_511
21134 + Specifies the maximum number of branches (or member directories)
21135 + in a single aufs. The larger value consumes more system
21136 + resources and has a minor impact to performance.
21137 +config AUFS_BRANCH_MAX_1023
21140 + Specifies the maximum number of branches (or member directories)
21141 + in a single aufs. The larger value consumes more system
21142 + resources and has a minor impact to performance.
21143 +config AUFS_BRANCH_MAX_32767
21146 + Specifies the maximum number of branches (or member directories)
21147 + in a single aufs. The larger value consumes more system
21148 + resources and has a minor impact to performance.
21151 +config AUFS_SBILIST
21153 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21156 + Automatic configuration for internal use.
21157 + When aufs supports Magic SysRq or /proc, enabled automatically.
21159 +config AUFS_HNOTIFY
21160 + bool "Detect direct branch access (bypassing aufs)"
21162 + If you want to modify files on branches directly, eg. bypassing aufs,
21163 + and want aufs to detect the changes of them fully, then enable this
21164 + option and use 'udba=notify' mount option.
21165 + Currently there is only one available configuration, "fsnotify".
21166 + It will have a negative impact to the performance.
21167 + See detail in aufs.5.
21170 + prompt "method" if AUFS_HNOTIFY
21171 + default AUFS_HFSNOTIFY
21172 +config AUFS_HFSNOTIFY
21177 +config AUFS_EXPORT
21178 + bool "NFS-exportable aufs"
21179 + depends on EXPORTFS
21181 + If you want to export your mounted aufs via NFS, then enable this
21182 + option. There are several requirements for this configuration.
21183 + See detail in aufs.5.
21185 +config AUFS_INO_T_64
21187 + depends on AUFS_EXPORT
21188 + depends on 64BIT && !(ALPHA || S390)
21191 + Automatic configuration for internal use.
21192 + /* typedef unsigned long/int __kernel_ino_t */
21193 + /* alpha and s390x are int */
21196 + bool "support for XATTR/EA (including Security Labels)"
21198 + If your branch fs supports XATTR/EA and you want to make them
21199 + available in aufs too, then enable this opsion and specify the
21200 + branch attributes for EA.
21201 + See detail in aufs.5.
21204 + bool "File-based Hierarchical Storage Management"
21206 + Hierarchical Storage Management (or HSM) is a well-known feature
21207 + in the storage world. Aufs provides this feature as file-based.
21208 + with multiple branches.
21209 + These multiple branches are prioritized, ie. the topmost one
21210 + should be the fastest drive and be used heavily.
21213 + bool "Readdir in userspace"
21215 + Aufs has two methods to provide a merged view for a directory,
21216 + by a user-space library and by kernel-space natively. The latter
21217 + is always enabled but sometimes large and slow.
21218 + If you enable this option, install the library in aufs2-util
21219 + package, and set some environment variables for your readdir(3),
21220 + then the work will be handled in user-space which generally
21221 + shows better performance in most cases.
21222 + See detail in aufs.5.
21225 + bool "Show whiteouts"
21227 + If you want to make the whiteouts in aufs visible, then enable
21228 + this option and specify 'shwh' mount option. Although it may
21229 + sounds like philosophy or something, but in technically it
21230 + simply shows the name of whiteout with keeping its behaviour.
21232 +config AUFS_BR_RAMFS
21233 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21235 + If you want to use ramfs as an aufs branch fs, then enable this
21236 + option. Generally tmpfs is recommended.
21237 + Aufs prohibited them to be a branch fs by default, because
21238 + initramfs becomes unusable after switch_root or something
21239 + generally. If you sets initramfs as an aufs branch and boot your
21240 + system by switch_root, you will meet a problem easily since the
21241 + files in initramfs may be inaccessible.
21242 + Unless you are going to use ramfs as an aufs branch fs without
21243 + switch_root or something, leave it N.
21245 +config AUFS_BR_FUSE
21246 + bool "Fuse fs as an aufs branch"
21247 + depends on FUSE_FS
21250 + If you want to use fuse-based userspace filesystem as an aufs
21251 + branch fs, then enable this option.
21252 + It implements the internal poll(2) operation which is
21253 + implemented by fuse only (curretnly).
21258 + Automatic configuration for internal use.
21260 +config AUFS_BR_HFSPLUS
21261 + bool "Hfsplus as an aufs branch"
21262 + depends on HFSPLUS_FS
21265 + If you want to use hfsplus fs as an aufs branch fs, then enable
21266 + this option. This option introduces a small overhead at
21267 + copying-up a file on hfsplus.
21269 +config AUFS_BDEV_LOOP
21271 + depends on BLK_DEV_LOOP
21274 + Automatic configuration for internal use.
21275 + Convert =[ym] into =y.
21278 + bool "Debug aufs"
21280 + Enable this to compile aufs internal debug code.
21281 + It will have a negative impact to the performance.
21283 +config AUFS_MAGIC_SYSRQ
21285 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21288 + Automatic configuration for internal use.
21289 + When aufs supports Magic SysRq, enabled automatically.
21291 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21292 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21293 +++ linux/fs/aufs/loop.c 2015-09-24 10:47:58.254719746 +0200
21296 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21298 + * This program, aufs is free software; you can redistribute it and/or modify
21299 + * it under the terms of the GNU General Public License as published by
21300 + * the Free Software Foundation; either version 2 of the License, or
21301 + * (at your option) any later version.
21303 + * This program is distributed in the hope that it will be useful,
21304 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21305 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21306 + * GNU General Public License for more details.
21308 + * You should have received a copy of the GNU General Public License
21309 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21313 + * support for loopback block device as a branch
21318 +/* added into drivers/block/loop.c */
21319 +static struct file *(*backing_file_func)(struct super_block *sb);
21322 + * test if two lower dentries have overlapping branches.
21324 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21326 + struct super_block *h_sb;
21327 + struct file *backing_file;
21329 + if (unlikely(!backing_file_func)) {
21330 + /* don't load "loop" module here */
21331 + backing_file_func = symbol_get(loop_backing_file);
21332 + if (unlikely(!backing_file_func))
21333 + /* "loop" module is not loaded */
21337 + h_sb = h_adding->d_sb;
21338 + backing_file = backing_file_func(h_sb);
21339 + if (!backing_file)
21342 + h_adding = backing_file->f_path.dentry;
21344 + * h_adding can be local NFS.
21345 + * in this case aufs cannot detect the loop.
21347 + if (unlikely(h_adding->d_sb == sb))
21349 + return !!au_test_subdir(h_adding, sb->s_root);
21352 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21353 +int au_test_loopback_kthread(void)
21356 + struct task_struct *tsk = current;
21357 + char c, comm[sizeof(tsk->comm)];
21360 + if (tsk->flags & PF_KTHREAD) {
21361 + get_task_comm(comm, tsk);
21363 + ret = ('0' <= c && c <= '9'
21364 + && !strncmp(comm, "loop", 4));
21370 +/* ---------------------------------------------------------------------- */
21372 +#define au_warn_loopback_step 16
21373 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21374 +static unsigned long *au_warn_loopback_array;
21376 +void au_warn_loopback(struct super_block *h_sb)
21378 + int i, new_nelem;
21379 + unsigned long *a, magic;
21380 + static DEFINE_SPINLOCK(spin);
21382 + magic = h_sb->s_magic;
21383 + spin_lock(&spin);
21384 + a = au_warn_loopback_array;
21385 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21386 + if (a[i] == magic) {
21387 + spin_unlock(&spin);
21391 + /* h_sb is new to us, print it */
21392 + if (i < au_warn_loopback_nelem) {
21397 + /* expand the array */
21398 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21399 + a = au_kzrealloc(au_warn_loopback_array,
21400 + au_warn_loopback_nelem * sizeof(unsigned long),
21401 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
21403 + au_warn_loopback_nelem = new_nelem;
21404 + au_warn_loopback_array = a;
21409 + spin_unlock(&spin);
21410 + AuWarn1("realloc failed, ignored\n");
21414 + spin_unlock(&spin);
21415 + pr_warn("you may want to try another patch for loopback file "
21416 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21419 +int au_loopback_init(void)
21422 + struct super_block *sb __maybe_unused;
21424 + AuDebugOn(sizeof(sb->s_magic) != sizeof(unsigned long));
21427 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21428 + sizeof(unsigned long), GFP_NOFS);
21429 + if (unlikely(!au_warn_loopback_array))
21435 +void au_loopback_fin(void)
21437 + symbol_put(loop_backing_file);
21438 + kfree(au_warn_loopback_array);
21440 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21441 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21442 +++ linux/fs/aufs/loop.h 2015-09-24 10:47:58.254719746 +0200
21445 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21447 + * This program, aufs is free software; you can redistribute it and/or modify
21448 + * it under the terms of the GNU General Public License as published by
21449 + * the Free Software Foundation; either version 2 of the License, or
21450 + * (at your option) any later version.
21452 + * This program is distributed in the hope that it will be useful,
21453 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21454 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21455 + * GNU General Public License for more details.
21457 + * You should have received a copy of the GNU General Public License
21458 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21462 + * support for loopback mount as a branch
21465 +#ifndef __AUFS_LOOP_H__
21466 +#define __AUFS_LOOP_H__
21471 +struct super_block;
21473 +#ifdef CONFIG_AUFS_BDEV_LOOP
21474 +/* drivers/block/loop.c */
21475 +struct file *loop_backing_file(struct super_block *sb);
21478 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21479 +int au_test_loopback_kthread(void);
21480 +void au_warn_loopback(struct super_block *h_sb);
21482 +int au_loopback_init(void);
21483 +void au_loopback_fin(void);
21485 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21486 + struct dentry *h_adding)
21487 +AuStubInt0(au_test_loopback_kthread, void)
21488 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21490 +AuStubInt0(au_loopback_init, void)
21491 +AuStubVoid(au_loopback_fin, void)
21492 +#endif /* BLK_DEV_LOOP */
21494 +#endif /* __KERNEL__ */
21495 +#endif /* __AUFS_LOOP_H__ */
21496 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21497 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21498 +++ linux/fs/aufs/magic.mk 2015-09-24 10:47:58.254719746 +0200
21501 +# defined in ${srctree}/fs/fuse/inode.c
21503 +ifdef CONFIG_FUSE_FS
21504 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21507 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21509 +ifdef CONFIG_XFS_FS
21510 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21513 +# defined in ${srctree}/fs/configfs/mount.c
21515 +ifdef CONFIG_CONFIGFS_FS
21516 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21519 +# defined in ${srctree}/fs/ubifs/ubifs.h
21521 +ifdef CONFIG_UBIFS_FS
21522 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21525 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21527 +ifdef CONFIG_HFSPLUS_FS
21528 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21530 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
21531 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
21532 +++ linux/fs/aufs/Makefile 2015-09-24 10:47:58.248052907 +0200
21535 +include ${src}/magic.mk
21536 +ifeq (${CONFIG_AUFS_FS},m)
21537 +include ${src}/conf.mk
21539 +-include ${src}/priv_def.mk
21541 +# cf. include/linux/kernel.h
21543 +ccflags-y += -DDEBUG
21544 +# sparse requires the full pathname
21546 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
21548 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
21551 +obj-$(CONFIG_AUFS_FS) += aufs.o
21552 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
21553 + wkq.o vfsub.o dcsub.o \
21554 + cpup.o whout.o wbr_policy.o \
21555 + dinfo.o dentry.o \
21557 + finfo.o file.o f_op.o \
21559 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
21563 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
21564 +aufs-$(CONFIG_SYSFS) += sysfs.o
21565 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
21566 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
21567 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
21568 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
21569 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
21570 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
21571 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
21572 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
21573 +aufs-$(CONFIG_AUFS_POLL) += poll.o
21574 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
21575 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
21576 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
21577 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
21578 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
21579 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21580 +++ linux/fs/aufs/module.c 2015-09-24 10:47:58.254719746 +0200
21583 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21585 + * This program, aufs is free software; you can redistribute it and/or modify
21586 + * it under the terms of the GNU General Public License as published by
21587 + * the Free Software Foundation; either version 2 of the License, or
21588 + * (at your option) any later version.
21590 + * This program is distributed in the hope that it will be useful,
21591 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21592 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21593 + * GNU General Public License for more details.
21595 + * You should have received a copy of the GNU General Public License
21596 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21600 + * module global variables and operations
21603 +#include <linux/module.h>
21604 +#include <linux/seq_file.h>
21607 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21609 + if (new_sz <= nused)
21612 + p = krealloc(p, new_sz, gfp);
21614 + memset(p + nused, 0, new_sz - nused);
21618 +/* ---------------------------------------------------------------------- */
21623 +struct kmem_cache *au_cachep[AuCache_Last];
21624 +static int __init au_cache_init(void)
21626 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21627 + if (au_cachep[AuCache_DINFO])
21628 + /* SLAB_DESTROY_BY_RCU */
21629 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21630 + au_icntnr_init_once);
21631 + if (au_cachep[AuCache_ICNTNR])
21632 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21633 + au_fi_init_once);
21634 + if (au_cachep[AuCache_FINFO])
21635 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21636 + if (au_cachep[AuCache_VDIR])
21637 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21638 + if (au_cachep[AuCache_DEHSTR])
21644 +static void au_cache_fin(void)
21649 + * Make sure all delayed rcu free inodes are flushed before we
21654 + /* excluding AuCache_HNOTIFY */
21655 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21656 + for (i = 0; i < AuCache_HNOTIFY; i++)
21657 + if (au_cachep[i]) {
21658 + kmem_cache_destroy(au_cachep[i]);
21659 + au_cachep[i] = NULL;
21663 +/* ---------------------------------------------------------------------- */
21665 +int au_dir_roflags;
21667 +#ifdef CONFIG_AUFS_SBILIST
21669 + * iterate_supers_type() doesn't protect us from
21670 + * remounting (branch management)
21672 +struct au_splhead au_sbilist;
21675 +struct lock_class_key au_lc_key[AuLcKey_Last];
21678 + * functions for module interface.
21680 +MODULE_LICENSE("GPL");
21681 +/* MODULE_LICENSE("GPL v2"); */
21682 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21683 +MODULE_DESCRIPTION(AUFS_NAME
21684 + " -- Advanced multi layered unification filesystem");
21685 +MODULE_VERSION(AUFS_VERSION);
21686 +MODULE_ALIAS_FS(AUFS_NAME);
21688 +/* this module parameter has no meaning when SYSFS is disabled */
21689 +int sysaufs_brs = 1;
21690 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21691 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21693 +/* this module parameter has no meaning when USER_NS is disabled */
21694 +static bool au_userns;
21695 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21696 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21698 +/* ---------------------------------------------------------------------- */
21700 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21702 +int au_seq_path(struct seq_file *seq, struct path *path)
21704 + return seq_path(seq, path, au_esc_chars);
21707 +/* ---------------------------------------------------------------------- */
21709 +static int __init aufs_init(void)
21714 + p = au_esc_chars;
21715 + for (i = 1; i <= ' '; i++)
21721 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21723 + au_sbilist_init();
21724 + sysaufs_brs_init();
21727 + err = sysaufs_init();
21728 + if (unlikely(err))
21730 + err = au_procfs_init();
21731 + if (unlikely(err))
21732 + goto out_sysaufs;
21733 + err = au_wkq_init();
21734 + if (unlikely(err))
21736 + err = au_loopback_init();
21737 + if (unlikely(err))
21739 + err = au_hnotify_init();
21740 + if (unlikely(err))
21741 + goto out_loopback;
21742 + err = au_sysrq_init();
21743 + if (unlikely(err))
21745 + err = au_cache_init();
21746 + if (unlikely(err))
21749 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
21750 + err = register_filesystem(&aufs_fs_type);
21751 + if (unlikely(err))
21754 + /* since we define pr_fmt, call printk directly */
21755 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
21756 + goto out; /* success */
21763 + au_hnotify_fin();
21765 + au_loopback_fin();
21777 +static void __exit aufs_exit(void)
21779 + unregister_filesystem(&aufs_fs_type);
21782 + au_hnotify_fin();
21783 + au_loopback_fin();
21790 +module_init(aufs_init);
21791 +module_exit(aufs_exit);
21792 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
21793 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
21794 +++ linux/fs/aufs/module.h 2015-09-24 10:47:58.254719746 +0200
21797 + * Copyright (C) 2005-2015 Junjiro R. Okajima
21799 + * This program, aufs is free software; you can redistribute it and/or modify
21800 + * it under the terms of the GNU General Public License as published by
21801 + * the Free Software Foundation; either version 2 of the License, or
21802 + * (at your option) any later version.
21804 + * This program is distributed in the hope that it will be useful,
21805 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21806 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21807 + * GNU General Public License for more details.
21809 + * You should have received a copy of the GNU General Public License
21810 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21814 + * module initialization and module-global
21817 +#ifndef __AUFS_MODULE_H__
21818 +#define __AUFS_MODULE_H__
21822 +#include <linux/slab.h>
21827 +/* module parameters */
21828 +extern int sysaufs_brs;
21830 +/* ---------------------------------------------------------------------- */
21832 +extern int au_dir_roflags;
21835 + AuLcNonDir_FIINFO,
21836 + AuLcNonDir_DIINFO,
21837 + AuLcNonDir_IIINFO,
21843 + AuLcSymlink_DIINFO,
21844 + AuLcSymlink_IIINFO,
21848 +extern struct lock_class_key au_lc_key[AuLcKey_Last];
21850 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
21851 +int au_seq_path(struct seq_file *seq, struct path *path);
21853 +#ifdef CONFIG_PROC_FS
21855 +int __init au_procfs_init(void);
21856 +void au_procfs_fin(void);
21858 +AuStubInt0(au_procfs_init, void);
21859 +AuStubVoid(au_procfs_fin, void);
21862 +/* ---------------------------------------------------------------------- */
21871 + AuCache_HNOTIFY, /* must be last */
21875 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
21876 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
21877 +#define AuCacheCtor(type, ctor) \
21878 + kmem_cache_create(#type, sizeof(struct type), \
21879 + __alignof__(struct type), AuCacheFlags, ctor)
21881 +extern struct kmem_cache *au_cachep[];
21883 +#define AuCacheFuncs(name, index) \
21884 +static inline struct au_##name *au_cache_alloc_##name(void) \
21885 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
21886 +static inline void au_cache_free_##name(struct au_##name *p) \
21887 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
21889 +AuCacheFuncs(dinfo, DINFO);
21890 +AuCacheFuncs(icntnr, ICNTNR);
21891 +AuCacheFuncs(finfo, FINFO);
21892 +AuCacheFuncs(vdir, VDIR);
21893 +AuCacheFuncs(vdir_dehstr, DEHSTR);
21894 +#ifdef CONFIG_AUFS_HNOTIFY
21895 +AuCacheFuncs(hnotify, HNOTIFY);
21898 +#endif /* __KERNEL__ */
21899 +#endif /* __AUFS_MODULE_H__ */
21900 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
21901 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
21902 +++ linux/fs/aufs/mvdown.c 2015-09-24 10:47:58.254719746 +0200
21905 + * Copyright (C) 2011-2015 Junjiro R. Okajima
21907 + * This program, aufs is free software; you can redistribute it and/or modify
21908 + * it under the terms of the GNU General Public License as published by
21909 + * the Free Software Foundation; either version 2 of the License, or
21910 + * (at your option) any later version.
21912 + * This program is distributed in the hope that it will be useful,
21913 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21914 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21915 + * GNU General Public License for more details.
21917 + * You should have received a copy of the GNU General Public License
21918 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21922 + * move-down, opposite of copy-up
21927 +struct au_mvd_args {
21929 + struct super_block *h_sb;
21930 + struct dentry *h_parent;
21931 + struct au_hinode *hdir;
21932 + struct inode *h_dir, *h_inode;
21933 + struct au_pin pin;
21934 + } info[AUFS_MVDOWN_NARRAY];
21936 + struct aufs_mvdown mvdown;
21937 + struct dentry *dentry, *parent;
21938 + struct inode *inode, *dir;
21939 + struct super_block *sb;
21940 + aufs_bindex_t bopq, bwh, bfound;
21941 + unsigned char rename_lock;
21944 +#define mvd_errno mvdown.au_errno
21945 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
21946 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
21947 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
21948 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
21950 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
21951 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
21952 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
21953 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
21954 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
21955 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
21957 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
21958 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
21959 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
21960 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
21961 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
21962 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
21964 +#define AU_MVD_PR(flag, ...) do { \
21966 + pr_err(__VA_ARGS__); \
21969 +static int find_lower_writable(struct au_mvd_args *a)
21971 + struct super_block *sb;
21972 + aufs_bindex_t bindex, bend;
21973 + struct au_branch *br;
21976 + bindex = a->mvd_bsrc;
21977 + bend = au_sbend(sb);
21978 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
21979 + for (bindex++; bindex <= bend; bindex++) {
21980 + br = au_sbr(sb, bindex);
21981 + if (au_br_fhsm(br->br_perm)
21982 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
21985 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
21986 + for (bindex++; bindex <= bend; bindex++) {
21987 + br = au_sbr(sb, bindex);
21988 + if (!au_br_rdonly(br))
21992 + for (bindex++; bindex <= bend; bindex++) {
21993 + br = au_sbr(sb, bindex);
21994 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
21995 + if (au_br_rdonly(br))
21997 + |= AUFS_MVDOWN_ROLOWER_R;
22005 +/* make the parent dir on bdst */
22006 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22011 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22012 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22013 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22014 + a->mvd_h_dst_parent = NULL;
22015 + if (au_dbend(a->parent) >= a->mvd_bdst)
22016 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22017 + if (!a->mvd_h_dst_parent) {
22018 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22019 + if (unlikely(err)) {
22020 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22023 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22031 +/* lock them all */
22032 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22035 + struct dentry *h_trap;
22037 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22038 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22039 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22040 + au_opt_udba(a->sb),
22041 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22043 + if (unlikely(err)) {
22044 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22048 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22049 + a->rename_lock = 0;
22050 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22051 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22052 + au_opt_udba(a->sb),
22053 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22054 + err = au_do_pin(&a->mvd_pin_src);
22056 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22057 + if (unlikely(err)) {
22058 + AU_MVD_PR(dmsg, "pin_src failed\n");
22061 + goto out; /* success */
22064 + a->rename_lock = 1;
22065 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22066 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22067 + au_opt_udba(a->sb),
22068 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22070 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22071 + if (unlikely(err)) {
22072 + AU_MVD_PR(dmsg, "pin_src failed\n");
22073 + au_pin_hdir_lock(&a->mvd_pin_dst);
22076 + au_pin_hdir_unlock(&a->mvd_pin_src);
22077 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22078 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22080 + err = (h_trap != a->mvd_h_src_parent);
22082 + err = (h_trap != a->mvd_h_dst_parent);
22084 + BUG_ON(err); /* it should never happen */
22085 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22088 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22089 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22090 + au_pin_hdir_lock(&a->mvd_pin_src);
22091 + au_unpin(&a->mvd_pin_src);
22092 + au_pin_hdir_lock(&a->mvd_pin_dst);
22095 + goto out; /* success */
22098 + au_unpin(&a->mvd_pin_dst);
22104 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22106 + if (!a->rename_lock)
22107 + au_unpin(&a->mvd_pin_src);
22109 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22110 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22111 + au_pin_hdir_lock(&a->mvd_pin_src);
22112 + au_unpin(&a->mvd_pin_src);
22113 + au_pin_hdir_lock(&a->mvd_pin_dst);
22115 + au_unpin(&a->mvd_pin_dst);
22118 +/* copy-down the file */
22119 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22122 + struct au_cp_generic cpg = {
22123 + .dentry = a->dentry,
22124 + .bdst = a->mvd_bdst,
22125 + .bsrc = a->mvd_bsrc,
22127 + .pin = &a->mvd_pin_dst,
22128 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22131 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22132 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22133 + au_fset_cpup(cpg.flags, OVERWRITE);
22134 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22135 + au_fset_cpup(cpg.flags, RWDST);
22136 + err = au_sio_cpdown_simple(&cpg);
22137 + if (unlikely(err))
22138 + AU_MVD_PR(dmsg, "cpdown failed\n");
22145 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22148 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22151 + struct path h_path;
22152 + struct au_branch *br;
22153 + struct inode *delegated;
22155 + br = au_sbr(a->sb, a->mvd_bdst);
22156 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22157 + err = PTR_ERR(h_path.dentry);
22158 + if (IS_ERR(h_path.dentry)) {
22159 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22164 + if (d_is_positive(h_path.dentry)) {
22165 + h_path.mnt = au_br_mnt(br);
22166 + delegated = NULL;
22167 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22168 + &delegated, /*force*/0);
22169 + if (unlikely(err == -EWOULDBLOCK)) {
22170 + pr_warn("cannot retry for NFSv4 delegation"
22171 + " for an internal unlink\n");
22174 + if (unlikely(err))
22175 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22177 + dput(h_path.dentry);
22185 + * unlink the topmost h_dentry
22187 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22190 + struct path h_path;
22191 + struct inode *delegated;
22193 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22194 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22195 + delegated = NULL;
22196 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22197 + if (unlikely(err == -EWOULDBLOCK)) {
22198 + pr_warn("cannot retry for NFSv4 delegation"
22199 + " for an internal unlink\n");
22202 + if (unlikely(err))
22203 + AU_MVD_PR(dmsg, "unlink failed\n");
22209 +/* Since mvdown succeeded, we ignore an error of this function */
22210 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22213 + struct au_branch *br;
22215 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22216 + br = au_sbr(a->sb, a->mvd_bsrc);
22217 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22219 + br = au_sbr(a->sb, a->mvd_bdst);
22220 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22221 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22224 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22226 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22230 + * copy-down the file and unlink the bsrc file.
22231 + * - unlink the bdst whout if exist
22232 + * - copy-down the file (with whtmp name and rename)
22233 + * - unlink the bsrc file
22235 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22239 + err = au_do_mkdir(dmsg, a);
22241 + err = au_do_lock(dmsg, a);
22242 + if (unlikely(err))
22246 + * do not revert the activities we made on bdst since they should be
22247 + * harmless in aufs.
22250 + err = au_do_cpdown(dmsg, a);
22252 + err = au_do_unlink_wh(dmsg, a);
22253 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22254 + err = au_do_unlink(dmsg, a);
22255 + if (unlikely(err))
22258 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22259 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22260 + if (find_lower_writable(a) < 0)
22261 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22263 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22264 + au_do_stfs(dmsg, a);
22266 + /* maintain internal array */
22267 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22268 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22269 + au_set_dbstart(a->dentry, a->mvd_bdst);
22270 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22271 + au_set_ibstart(a->inode, a->mvd_bdst);
22273 + if (au_dbend(a->dentry) < a->mvd_bdst)
22274 + au_set_dbend(a->dentry, a->mvd_bdst);
22275 + if (au_ibend(a->inode) < a->mvd_bdst)
22276 + au_set_ibend(a->inode, a->mvd_bdst);
22279 + au_do_unlock(dmsg, a);
22285 +/* ---------------------------------------------------------------------- */
22287 +/* make sure the file is idle */
22288 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22290 + int err, plinked;
22293 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22294 + if (au_dbstart(a->dentry) == a->mvd_bsrc
22295 + && au_dcount(a->dentry) == 1
22296 + && atomic_read(&a->inode->i_count) == 1
22297 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22298 + && (!plinked || !au_plink_test(a->inode))
22299 + && a->inode->i_nlink == 1)
22304 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22305 + a->mvd_bsrc, au_dbstart(a->dentry), au_dcount(a->dentry),
22306 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22307 + a->mvd_h_src_inode->i_nlink,
22308 + plinked, plinked ? au_plink_test(a->inode) : 0);
22315 +/* make sure the parent dir is fine */
22316 +static int au_mvd_args_parent(const unsigned char dmsg,
22317 + struct au_mvd_args *a)
22320 + aufs_bindex_t bindex;
22323 + if (unlikely(au_alive_dir(a->parent))) {
22325 + AU_MVD_PR(dmsg, "parent dir is dead\n");
22329 + a->bopq = au_dbdiropq(a->parent);
22330 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
22331 + AuDbg("b%d\n", bindex);
22332 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
22333 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
22335 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
22336 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
22337 + a->bopq, a->mvd_bdst);
22345 +static int au_mvd_args_intermediate(const unsigned char dmsg,
22346 + struct au_mvd_args *a)
22349 + struct au_dinfo *dinfo, *tmp;
22351 + /* lookup the next lower positive entry */
22353 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
22354 + if (unlikely(!tmp))
22359 + dinfo = au_di(a->dentry);
22360 + au_di_cp(tmp, dinfo);
22361 + au_di_swap(tmp, dinfo);
22363 + /* returns the number of positive dentries */
22364 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, /*type*/0);
22366 + a->bwh = au_dbwh(a->dentry);
22367 + else if (err > 0)
22368 + a->bfound = au_dbstart(a->dentry);
22370 + au_di_swap(tmp, dinfo);
22371 + au_rw_write_unlock(&tmp->di_rwsem);
22373 + if (unlikely(err < 0))
22374 + AU_MVD_PR(dmsg, "failed look-up lower\n");
22377 + * here, we have these cases.
22379 + * no positive dentry under bsrc. there are more sub-cases.
22381 + * there no whiteout, we can safely move-down.
22384 + * bsrc < bwh && bwh < bdst
22385 + * there is a whiteout on RO branch. cannot proceed.
22387 + * there is a whiteout on the RW target branch. it should
22390 + * there is a whiteout somewhere unrelated branch.
22391 + * -1 < bfound && bfound <= bsrc
22394 + * found, but it is on RO branch between bsrc and bdst. cannot
22397 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
22400 + * found, after we create the file on bdst, it will be hidden.
22403 + AuDebugOn(a->bfound == -1
22405 + && a->bwh <= a->mvd_bsrc);
22406 + AuDebugOn(-1 < a->bfound
22407 + && a->bfound <= a->mvd_bsrc);
22410 + if (a->bfound == -1
22411 + && a->mvd_bsrc < a->bwh
22413 + && a->bwh < a->mvd_bdst) {
22414 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
22415 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
22416 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
22418 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
22419 + a->mvd_errno = EAU_MVDOWN_UPPER;
22420 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
22421 + a->mvd_bdst, a->bfound);
22425 + err = 0; /* success */
22432 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
22437 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22438 + && a->bfound == a->mvd_bdst)
22444 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
22447 + struct au_branch *br;
22450 + if (unlikely(S_ISDIR(a->inode->i_mode)))
22454 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
22455 + a->mvd_bsrc = au_ibstart(a->inode);
22457 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
22458 + if (unlikely(a->mvd_bsrc < 0
22459 + || (a->mvd_bsrc < au_dbstart(a->dentry)
22460 + || au_dbend(a->dentry) < a->mvd_bsrc
22461 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
22462 + || (a->mvd_bsrc < au_ibstart(a->inode)
22463 + || au_ibend(a->inode) < a->mvd_bsrc
22464 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
22465 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
22466 + AU_MVD_PR(dmsg, "no upper\n");
22470 + if (unlikely(a->mvd_bsrc == au_sbend(a->sb))) {
22471 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22472 + AU_MVD_PR(dmsg, "on the bottom\n");
22475 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
22476 + br = au_sbr(a->sb, a->mvd_bsrc);
22477 + err = au_br_rdonly(br);
22478 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
22479 + if (unlikely(err))
22481 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
22482 + || IS_APPEND(a->mvd_h_src_inode))) {
22484 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
22490 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
22491 + a->mvd_bdst = find_lower_writable(a);
22492 + if (unlikely(a->mvd_bdst < 0)) {
22493 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22494 + AU_MVD_PR(dmsg, "no writable lower branch\n");
22498 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
22499 + if (unlikely(a->mvd_bdst < 0
22500 + || au_sbend(a->sb) < a->mvd_bdst)) {
22501 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
22502 + AU_MVD_PR(dmsg, "no lower brid\n");
22507 + err = au_mvd_args_busy(dmsg, a);
22509 + err = au_mvd_args_parent(dmsg, a);
22511 + err = au_mvd_args_intermediate(dmsg, a);
22513 + err = au_mvd_args_exist(dmsg, a);
22515 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
22522 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
22525 + unsigned char dmsg;
22526 + struct au_mvd_args *args;
22529 + if (unlikely(!capable(CAP_SYS_ADMIN)))
22533 + args = kmalloc(sizeof(*args), GFP_NOFS);
22534 + if (unlikely(!args))
22537 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
22539 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
22540 + if (unlikely(err)) {
22545 + AuDbg("flags 0x%x\n", args->mvdown.flags);
22546 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
22547 + args->mvdown.au_errno = 0;
22548 + args->dentry = dentry;
22549 + args->inode = d_inode(dentry);
22550 + args->sb = dentry->d_sb;
22553 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
22554 + args->parent = dget_parent(dentry);
22555 + args->dir = d_inode(args->parent);
22556 + mutex_lock_nested(&args->dir->i_mutex, I_MUTEX_PARENT);
22557 + dput(args->parent);
22558 + if (unlikely(args->parent != dentry->d_parent)) {
22559 + AU_MVD_PR(dmsg, "parent dir is moved\n");
22563 + mutex_lock_nested(&args->inode->i_mutex, I_MUTEX_CHILD);
22564 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH);
22565 + if (unlikely(err))
22568 + di_write_lock_parent(args->parent);
22569 + err = au_mvd_args(dmsg, args);
22570 + if (unlikely(err))
22573 + err = au_do_mvdown(dmsg, args);
22574 + if (unlikely(err))
22577 + au_cpup_attr_timesizes(args->dir);
22578 + au_cpup_attr_timesizes(args->inode);
22579 + au_cpup_igen(args->inode, au_h_iptr(args->inode, args->mvd_bdst));
22580 + /* au_digen_dec(dentry); */
22583 + di_write_unlock(args->parent);
22584 + aufs_read_unlock(dentry, AuLock_DW);
22586 + mutex_unlock(&args->inode->i_mutex);
22588 + mutex_unlock(&args->dir->i_mutex);
22590 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
22598 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
22599 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
22600 +++ linux/fs/aufs/opts.c 2015-09-24 10:47:58.254719746 +0200
22603 + * Copyright (C) 2005-2015 Junjiro R. Okajima
22605 + * This program, aufs is free software; you can redistribute it and/or modify
22606 + * it under the terms of the GNU General Public License as published by
22607 + * the Free Software Foundation; either version 2 of the License, or
22608 + * (at your option) any later version.
22610 + * This program is distributed in the hope that it will be useful,
22611 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22612 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22613 + * GNU General Public License for more details.
22615 + * You should have received a copy of the GNU General Public License
22616 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22620 + * mount options/flags
22623 +#include <linux/namei.h>
22624 +#include <linux/types.h> /* a distribution requires */
22625 +#include <linux/parser.h>
22628 +/* ---------------------------------------------------------------------- */
22632 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
22633 + Opt_idel, Opt_imod,
22634 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
22635 + Opt_rdblk_def, Opt_rdhash_def,
22636 + Opt_xino, Opt_noxino,
22637 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22638 + Opt_trunc_xino_path, Opt_itrunc_xino,
22639 + Opt_trunc_xib, Opt_notrunc_xib,
22640 + Opt_shwh, Opt_noshwh,
22641 + Opt_plink, Opt_noplink, Opt_list_plink,
22643 + Opt_dio, Opt_nodio,
22644 + Opt_diropq_a, Opt_diropq_w,
22645 + Opt_warn_perm, Opt_nowarn_perm,
22646 + Opt_wbr_copyup, Opt_wbr_create,
22648 + Opt_verbose, Opt_noverbose,
22649 + Opt_sum, Opt_nosum, Opt_wsum,
22650 + Opt_dirperm1, Opt_nodirperm1,
22651 + Opt_acl, Opt_noacl,
22652 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22655 +static match_table_t options = {
22656 + {Opt_br, "br=%s"},
22657 + {Opt_br, "br:%s"},
22659 + {Opt_add, "add=%d:%s"},
22660 + {Opt_add, "add:%d:%s"},
22661 + {Opt_add, "ins=%d:%s"},
22662 + {Opt_add, "ins:%d:%s"},
22663 + {Opt_append, "append=%s"},
22664 + {Opt_append, "append:%s"},
22665 + {Opt_prepend, "prepend=%s"},
22666 + {Opt_prepend, "prepend:%s"},
22668 + {Opt_del, "del=%s"},
22669 + {Opt_del, "del:%s"},
22670 + /* {Opt_idel, "idel:%d"}, */
22671 + {Opt_mod, "mod=%s"},
22672 + {Opt_mod, "mod:%s"},
22673 + /* {Opt_imod, "imod:%d:%s"}, */
22675 + {Opt_dirwh, "dirwh=%d"},
22677 + {Opt_xino, "xino=%s"},
22678 + {Opt_noxino, "noxino"},
22679 + {Opt_trunc_xino, "trunc_xino"},
22680 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22681 + {Opt_notrunc_xino, "notrunc_xino"},
22682 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22683 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22684 + /* {Opt_zxino, "zxino=%s"}, */
22685 + {Opt_trunc_xib, "trunc_xib"},
22686 + {Opt_notrunc_xib, "notrunc_xib"},
22688 +#ifdef CONFIG_PROC_FS
22689 + {Opt_plink, "plink"},
22691 + {Opt_ignore_silent, "plink"},
22694 + {Opt_noplink, "noplink"},
22696 +#ifdef CONFIG_AUFS_DEBUG
22697 + {Opt_list_plink, "list_plink"},
22700 + {Opt_udba, "udba=%s"},
22702 + {Opt_dio, "dio"},
22703 + {Opt_nodio, "nodio"},
22705 +#ifdef CONFIG_AUFS_FHSM
22706 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22708 + {Opt_ignore_silent, "fhsm_sec=%d"},
22711 + {Opt_diropq_a, "diropq=always"},
22712 + {Opt_diropq_a, "diropq=a"},
22713 + {Opt_diropq_w, "diropq=whiteouted"},
22714 + {Opt_diropq_w, "diropq=w"},
22716 + {Opt_warn_perm, "warn_perm"},
22717 + {Opt_nowarn_perm, "nowarn_perm"},
22719 + /* keep them temporary */
22720 + {Opt_ignore_silent, "nodlgt"},
22721 + {Opt_ignore_silent, "clean_plink"},
22723 +#ifdef CONFIG_AUFS_SHWH
22724 + {Opt_shwh, "shwh"},
22726 + {Opt_noshwh, "noshwh"},
22728 + {Opt_dirperm1, "dirperm1"},
22729 + {Opt_nodirperm1, "nodirperm1"},
22731 + {Opt_verbose, "verbose"},
22732 + {Opt_verbose, "v"},
22733 + {Opt_noverbose, "noverbose"},
22734 + {Opt_noverbose, "quiet"},
22735 + {Opt_noverbose, "q"},
22736 + {Opt_noverbose, "silent"},
22738 + {Opt_sum, "sum"},
22739 + {Opt_nosum, "nosum"},
22740 + {Opt_wsum, "wsum"},
22742 + {Opt_rdcache, "rdcache=%d"},
22743 + {Opt_rdblk, "rdblk=%d"},
22744 + {Opt_rdblk_def, "rdblk=def"},
22745 + {Opt_rdhash, "rdhash=%d"},
22746 + {Opt_rdhash_def, "rdhash=def"},
22748 + {Opt_wbr_create, "create=%s"},
22749 + {Opt_wbr_create, "create_policy=%s"},
22750 + {Opt_wbr_copyup, "cpup=%s"},
22751 + {Opt_wbr_copyup, "copyup=%s"},
22752 + {Opt_wbr_copyup, "copyup_policy=%s"},
22754 + /* generic VFS flag */
22755 +#ifdef CONFIG_FS_POSIX_ACL
22756 + {Opt_acl, "acl"},
22757 + {Opt_noacl, "noacl"},
22759 + {Opt_ignore_silent, "acl"},
22760 + {Opt_ignore_silent, "noacl"},
22763 + /* internal use for the scripts */
22764 + {Opt_ignore_silent, "si=%s"},
22766 + {Opt_br, "dirs=%s"},
22767 + {Opt_ignore, "debug=%d"},
22768 + {Opt_ignore, "delete=whiteout"},
22769 + {Opt_ignore, "delete=all"},
22770 + {Opt_ignore, "imap=%s"},
22772 + /* temporary workaround, due to old mount(8)? */
22773 + {Opt_ignore_silent, "relatime"},
22778 +/* ---------------------------------------------------------------------- */
22780 +static const char *au_parser_pattern(int val, match_table_t tbl)
22782 + struct match_token *p;
22785 + while (p->pattern) {
22786 + if (p->token == val)
22787 + return p->pattern;
22794 +static const char *au_optstr(int *val, match_table_t tbl)
22796 + struct match_token *p;
22803 + while (p->pattern) {
22805 + && (v & p->token) == p->token) {
22806 + *val &= ~p->token;
22807 + return p->pattern;
22816 +/* ---------------------------------------------------------------------- */
22818 +static match_table_t brperm = {
22819 + {AuBrPerm_RO, AUFS_BRPERM_RO},
22820 + {AuBrPerm_RR, AUFS_BRPERM_RR},
22821 + {AuBrPerm_RW, AUFS_BRPERM_RW},
22825 +static match_table_t brattr = {
22827 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
22828 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
22829 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
22830 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
22831 +#ifdef CONFIG_AUFS_FHSM
22832 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
22834 +#ifdef CONFIG_AUFS_XATTR
22835 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
22836 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
22837 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
22838 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
22839 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
22840 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
22843 + /* ro/rr branch */
22844 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
22847 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
22848 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
22853 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
22860 + p = strchr(str, '+');
22863 + v = match_token(str, table, args);
22865 + if (v & AuBrAttr_CMOO_Mask)
22866 + attr &= ~AuBrAttr_CMOO_Mask;
22871 + pr_warn("ignored branch attribute %s\n", str);
22881 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
22889 + p = au_optstr(&perm, brattr);
22892 + memcpy(q, p, sz + 1);
22898 + p = au_optstr(&perm, brattr);
22902 + memcpy(q, p, sz + 1);
22908 + return q - str->a;
22911 +static int noinline_for_stack br_perm_val(char *perm)
22913 + int val, bad, sz;
22915 + substring_t args[MAX_OPT_ARGS];
22916 + au_br_perm_str_t attr;
22918 + p = strchr(perm, '+');
22921 + val = match_token(perm, brperm, args);
22925 + pr_warn("ignored branch permission %s\n", perm);
22926 + val = AuBrPerm_RO;
22932 + val |= br_attr_val(p + 1, brattr, args);
22935 + switch (val & AuBrPerm_Mask) {
22936 + case AuBrPerm_RO:
22937 + case AuBrPerm_RR:
22938 + bad = val & AuBrWAttr_Mask;
22939 + val &= ~AuBrWAttr_Mask;
22941 + case AuBrPerm_RW:
22942 + bad = val & AuBrRAttr_Mask;
22943 + val &= ~AuBrRAttr_Mask;
22948 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
22949 + * does not treat it as an error, just warning.
22950 + * this is a tiny guard for the user operation.
22952 + if (val & AuBrAttr_UNPIN) {
22953 + bad |= AuBrAttr_UNPIN;
22954 + val &= ~AuBrAttr_UNPIN;
22957 + if (unlikely(bad)) {
22958 + sz = au_do_optstr_br_attr(&attr, bad);
22960 + pr_warn("ignored branch attribute %s\n", attr.a);
22967 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
22969 + au_br_perm_str_t attr;
22975 + p = au_optstr(&perm, brperm);
22976 + AuDebugOn(!p || !*p);
22978 + memcpy(q, p, sz + 1);
22981 + sz = au_do_optstr_br_attr(&attr, perm);
22984 + memcpy(q, attr.a, sz + 1);
22987 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
22990 +/* ---------------------------------------------------------------------- */
22992 +static match_table_t udbalevel = {
22993 + {AuOpt_UDBA_REVAL, "reval"},
22994 + {AuOpt_UDBA_NONE, "none"},
22995 +#ifdef CONFIG_AUFS_HNOTIFY
22996 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
22997 +#ifdef CONFIG_AUFS_HFSNOTIFY
22998 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23004 +static int noinline_for_stack udba_val(char *str)
23006 + substring_t args[MAX_OPT_ARGS];
23008 + return match_token(str, udbalevel, args);
23011 +const char *au_optstr_udba(int udba)
23013 + return au_parser_pattern(udba, udbalevel);
23016 +/* ---------------------------------------------------------------------- */
23018 +static match_table_t au_wbr_create_policy = {
23019 + {AuWbrCreate_TDP, "tdp"},
23020 + {AuWbrCreate_TDP, "top-down-parent"},
23021 + {AuWbrCreate_RR, "rr"},
23022 + {AuWbrCreate_RR, "round-robin"},
23023 + {AuWbrCreate_MFS, "mfs"},
23024 + {AuWbrCreate_MFS, "most-free-space"},
23025 + {AuWbrCreate_MFSV, "mfs:%d"},
23026 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23028 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23029 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23030 + {AuWbrCreate_PMFS, "pmfs"},
23031 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23032 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23033 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23039 + * cf. linux/lib/parser.c and cmdline.c
23040 + * gave up calling memparse() since it uses simple_strtoull() instead of
23043 +static int noinline_for_stack
23044 +au_match_ull(substring_t *s, unsigned long long *result)
23047 + unsigned int len;
23051 + len = s->to - s->from;
23052 + if (len + 1 <= sizeof(a)) {
23053 + memcpy(a, s->from, len);
23055 + err = kstrtoull(a, 0, result);
23060 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23061 + struct au_opt_wbr_create *create)
23064 + unsigned long long ull;
23067 + if (!au_match_ull(arg, &ull))
23068 + create->mfsrr_watermark = ull;
23070 + pr_err("bad integer in %s\n", str);
23077 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23078 + struct au_opt_wbr_create *create)
23083 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23084 + create->mfs_second = n;
23086 + pr_err("bad integer in %s\n", str);
23093 +static int noinline_for_stack
23094 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23097 + substring_t args[MAX_OPT_ARGS];
23099 + err = match_token(str, au_wbr_create_policy, args);
23100 + create->wbr_create = err;
23102 + case AuWbrCreate_MFSRRV:
23103 + case AuWbrCreate_PMFSRRV:
23104 + e = au_wbr_mfs_wmark(&args[0], str, create);
23106 + e = au_wbr_mfs_sec(&args[1], str, create);
23110 + case AuWbrCreate_MFSRR:
23111 + case AuWbrCreate_PMFSRR:
23112 + e = au_wbr_mfs_wmark(&args[0], str, create);
23113 + if (unlikely(e)) {
23118 + case AuWbrCreate_MFS:
23119 + case AuWbrCreate_PMFS:
23120 + create->mfs_second = AUFS_MFS_DEF_SEC;
23122 + case AuWbrCreate_MFSV:
23123 + case AuWbrCreate_PMFSV:
23124 + e = au_wbr_mfs_sec(&args[0], str, create);
23133 +const char *au_optstr_wbr_create(int wbr_create)
23135 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23138 +static match_table_t au_wbr_copyup_policy = {
23139 + {AuWbrCopyup_TDP, "tdp"},
23140 + {AuWbrCopyup_TDP, "top-down-parent"},
23141 + {AuWbrCopyup_BUP, "bup"},
23142 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23143 + {AuWbrCopyup_BU, "bu"},
23144 + {AuWbrCopyup_BU, "bottom-up"},
23148 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23150 + substring_t args[MAX_OPT_ARGS];
23152 + return match_token(str, au_wbr_copyup_policy, args);
23155 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23157 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23160 +/* ---------------------------------------------------------------------- */
23162 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23164 +static void dump_opts(struct au_opts *opts)
23166 +#ifdef CONFIG_AUFS_DEBUG
23167 + /* reduce stack space */
23169 + struct au_opt_add *add;
23170 + struct au_opt_del *del;
23171 + struct au_opt_mod *mod;
23172 + struct au_opt_xino *xino;
23173 + struct au_opt_xino_itrunc *xino_itrunc;
23174 + struct au_opt_wbr_create *create;
23176 + struct au_opt *opt;
23179 + while (opt->type != Opt_tail) {
23180 + switch (opt->type) {
23182 + u.add = &opt->add;
23183 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23184 + u.add->bindex, u.add->pathname, u.add->perm,
23185 + u.add->path.dentry);
23189 + u.del = &opt->del;
23190 + AuDbg("del {%s, %p}\n",
23191 + u.del->pathname, u.del->h_path.dentry);
23195 + u.mod = &opt->mod;
23196 + AuDbg("mod {%s, 0x%x, %p}\n",
23197 + u.mod->path, u.mod->perm, u.mod->h_root);
23200 + u.add = &opt->add;
23201 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23202 + u.add->bindex, u.add->pathname, u.add->perm,
23203 + u.add->path.dentry);
23205 + case Opt_prepend:
23206 + u.add = &opt->add;
23207 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23208 + u.add->bindex, u.add->pathname, u.add->perm,
23209 + u.add->path.dentry);
23212 + AuDbg("dirwh %d\n", opt->dirwh);
23214 + case Opt_rdcache:
23215 + AuDbg("rdcache %d\n", opt->rdcache);
23218 + AuDbg("rdblk %u\n", opt->rdblk);
23220 + case Opt_rdblk_def:
23221 + AuDbg("rdblk_def\n");
23224 + AuDbg("rdhash %u\n", opt->rdhash);
23226 + case Opt_rdhash_def:
23227 + AuDbg("rdhash_def\n");
23230 + u.xino = &opt->xino;
23231 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23233 + case Opt_trunc_xino:
23234 + AuLabel(trunc_xino);
23236 + case Opt_notrunc_xino:
23237 + AuLabel(notrunc_xino);
23239 + case Opt_trunc_xino_path:
23240 + case Opt_itrunc_xino:
23241 + u.xino_itrunc = &opt->xino_itrunc;
23242 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23247 + case Opt_trunc_xib:
23248 + AuLabel(trunc_xib);
23250 + case Opt_notrunc_xib:
23251 + AuLabel(notrunc_xib);
23259 + case Opt_dirperm1:
23260 + AuLabel(dirperm1);
23262 + case Opt_nodirperm1:
23263 + AuLabel(nodirperm1);
23268 + case Opt_noplink:
23269 + AuLabel(noplink);
23271 + case Opt_list_plink:
23272 + AuLabel(list_plink);
23275 + AuDbg("udba %d, %s\n",
23276 + opt->udba, au_optstr_udba(opt->udba));
23284 + case Opt_diropq_a:
23285 + AuLabel(diropq_a);
23287 + case Opt_diropq_w:
23288 + AuLabel(diropq_w);
23290 + case Opt_warn_perm:
23291 + AuLabel(warn_perm);
23293 + case Opt_nowarn_perm:
23294 + AuLabel(nowarn_perm);
23296 + case Opt_verbose:
23297 + AuLabel(verbose);
23299 + case Opt_noverbose:
23300 + AuLabel(noverbose);
23311 + case Opt_wbr_create:
23312 + u.create = &opt->wbr_create;
23313 + AuDbg("create %d, %s\n", u.create->wbr_create,
23314 + au_optstr_wbr_create(u.create->wbr_create));
23315 + switch (u.create->wbr_create) {
23316 + case AuWbrCreate_MFSV:
23317 + case AuWbrCreate_PMFSV:
23318 + AuDbg("%d sec\n", u.create->mfs_second);
23320 + case AuWbrCreate_MFSRR:
23321 + AuDbg("%llu watermark\n",
23322 + u.create->mfsrr_watermark);
23324 + case AuWbrCreate_MFSRRV:
23325 + case AuWbrCreate_PMFSRRV:
23326 + AuDbg("%llu watermark, %d sec\n",
23327 + u.create->mfsrr_watermark,
23328 + u.create->mfs_second);
23332 + case Opt_wbr_copyup:
23333 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
23334 + au_optstr_wbr_copyup(opt->wbr_copyup));
23336 + case Opt_fhsm_sec:
23337 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
23353 +void au_opts_free(struct au_opts *opts)
23355 + struct au_opt *opt;
23358 + while (opt->type != Opt_tail) {
23359 + switch (opt->type) {
23362 + case Opt_prepend:
23363 + path_put(&opt->add.path);
23367 + path_put(&opt->del.h_path);
23371 + dput(opt->mod.h_root);
23374 + fput(opt->xino.file);
23381 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
23382 + aufs_bindex_t bindex)
23385 + struct au_opt_add *add = &opt->add;
23388 + add->bindex = bindex;
23389 + add->perm = AuBrPerm_RO;
23390 + add->pathname = opt_str;
23391 + p = strchr(opt_str, '=');
23395 + add->perm = br_perm_val(p);
23398 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
23401 + add->perm = AuBrPerm_RO;
23402 + if (au_test_fs_rr(add->path.dentry->d_sb))
23403 + add->perm = AuBrPerm_RR;
23404 + else if (!bindex && !(sb_flags & MS_RDONLY))
23405 + add->perm = AuBrPerm_RW;
23407 + opt->type = Opt_add;
23410 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
23417 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
23421 + del->pathname = args[0].from;
23422 + AuDbg("del path %s\n", del->pathname);
23424 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
23425 + if (unlikely(err))
23426 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
23431 +#if 0 /* reserved for future use */
23432 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
23433 + struct au_opt_del *del, substring_t args[])
23436 + struct dentry *root;
23439 + root = sb->s_root;
23440 + aufs_read_lock(root, AuLock_FLUSH);
23441 + if (bindex < 0 || au_sbend(sb) < bindex) {
23442 + pr_err("out of bounds, %d\n", bindex);
23447 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
23448 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
23451 + aufs_read_unlock(root, !AuLock_IR);
23456 +static int noinline_for_stack
23457 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
23460 + struct path path;
23464 + mod->path = args[0].from;
23465 + p = strchr(mod->path, '=');
23466 + if (unlikely(!p)) {
23467 + pr_err("no permssion %s\n", args[0].from);
23472 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
23473 + if (unlikely(err)) {
23474 + pr_err("lookup failed %s (%d)\n", mod->path, err);
23478 + mod->perm = br_perm_val(p);
23479 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
23480 + mod->h_root = dget(path.dentry);
23487 +#if 0 /* reserved for future use */
23488 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
23489 + struct au_opt_mod *mod, substring_t args[])
23492 + struct dentry *root;
23495 + root = sb->s_root;
23496 + aufs_read_lock(root, AuLock_FLUSH);
23497 + if (bindex < 0 || au_sbend(sb) < bindex) {
23498 + pr_err("out of bounds, %d\n", bindex);
23503 + mod->perm = br_perm_val(args[1].from);
23504 + AuDbg("mod path %s, perm 0x%x, %s\n",
23505 + mod->path, mod->perm, args[1].from);
23506 + mod->h_root = dget(au_h_dptr(root, bindex));
23509 + aufs_read_unlock(root, !AuLock_IR);
23514 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
23515 + substring_t args[])
23518 + struct file *file;
23520 + file = au_xino_create(sb, args[0].from, /*silent*/0);
23521 + err = PTR_ERR(file);
23522 + if (IS_ERR(file))
23526 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
23528 + pr_err("%s must be outside\n", args[0].from);
23533 + xino->file = file;
23534 + xino->path = args[0].from;
23540 +static int noinline_for_stack
23541 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
23542 + struct au_opt_xino_itrunc *xino_itrunc,
23543 + substring_t args[])
23546 + aufs_bindex_t bend, bindex;
23547 + struct path path;
23548 + struct dentry *root;
23550 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
23551 + if (unlikely(err)) {
23552 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
23556 + xino_itrunc->bindex = -1;
23557 + root = sb->s_root;
23558 + aufs_read_lock(root, AuLock_FLUSH);
23559 + bend = au_sbend(sb);
23560 + for (bindex = 0; bindex <= bend; bindex++) {
23561 + if (au_h_dptr(root, bindex) == path.dentry) {
23562 + xino_itrunc->bindex = bindex;
23566 + aufs_read_unlock(root, !AuLock_IR);
23569 + if (unlikely(xino_itrunc->bindex < 0)) {
23570 + pr_err("no such branch %s\n", args[0].from);
23578 +/* called without aufs lock */
23579 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
23581 + int err, n, token;
23582 + aufs_bindex_t bindex;
23583 + unsigned char skipped;
23584 + struct dentry *root;
23585 + struct au_opt *opt, *opt_tail;
23587 + /* reduce the stack space */
23589 + struct au_opt_xino_itrunc *xino_itrunc;
23590 + struct au_opt_wbr_create *create;
23593 + substring_t args[MAX_OPT_ARGS];
23597 + a = kmalloc(sizeof(*a), GFP_NOFS);
23598 + if (unlikely(!a))
23601 + root = sb->s_root;
23605 + opt_tail = opt + opts->max_opt - 1;
23606 + opt->type = Opt_tail;
23607 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
23610 + token = match_token(opt_str, options, a->args);
23614 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
23616 + err = opt_add(opt, opt_str, opts->sb_flags,
23618 + if (unlikely(!err && ++opt > opt_tail)) {
23622 + opt->type = Opt_tail;
23627 + if (unlikely(match_int(&a->args[0], &n))) {
23628 + pr_err("bad integer in %s\n", opt_str);
23632 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
23635 + opt->type = token;
23638 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23639 + /*dummy bindex*/1);
23641 + opt->type = token;
23643 + case Opt_prepend:
23644 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23647 + opt->type = token;
23650 + err = au_opts_parse_del(&opt->del, a->args);
23652 + opt->type = token;
23654 +#if 0 /* reserved for future use */
23656 + del->pathname = "(indexed)";
23657 + if (unlikely(match_int(&args[0], &n))) {
23658 + pr_err("bad integer in %s\n", opt_str);
23661 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23663 + opt->type = token;
23667 + err = au_opts_parse_mod(&opt->mod, a->args);
23669 + opt->type = token;
23671 +#ifdef IMOD /* reserved for future use */
23673 + u.mod->path = "(indexed)";
23674 + if (unlikely(match_int(&a->args[0], &n))) {
23675 + pr_err("bad integer in %s\n", opt_str);
23678 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23680 + opt->type = token;
23684 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23686 + opt->type = token;
23689 + case Opt_trunc_xino_path:
23690 + err = au_opts_parse_xino_itrunc_path
23691 + (sb, &opt->xino_itrunc, a->args);
23693 + opt->type = token;
23696 + case Opt_itrunc_xino:
23697 + u.xino_itrunc = &opt->xino_itrunc;
23698 + if (unlikely(match_int(&a->args[0], &n))) {
23699 + pr_err("bad integer in %s\n", opt_str);
23702 + u.xino_itrunc->bindex = n;
23703 + aufs_read_lock(root, AuLock_FLUSH);
23704 + if (n < 0 || au_sbend(sb) < n) {
23705 + pr_err("out of bounds, %d\n", n);
23706 + aufs_read_unlock(root, !AuLock_IR);
23709 + aufs_read_unlock(root, !AuLock_IR);
23711 + opt->type = token;
23715 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23718 + opt->type = token;
23721 + case Opt_rdcache:
23722 + if (unlikely(match_int(&a->args[0], &n))) {
23723 + pr_err("bad integer in %s\n", opt_str);
23726 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23727 + pr_err("rdcache must be smaller than %d\n",
23728 + AUFS_RDCACHE_MAX);
23731 + opt->rdcache = n;
23733 + opt->type = token;
23736 + if (unlikely(match_int(&a->args[0], &n)
23738 + || n > KMALLOC_MAX_SIZE)) {
23739 + pr_err("bad integer in %s\n", opt_str);
23742 + if (unlikely(n && n < NAME_MAX)) {
23743 + pr_err("rdblk must be larger than %d\n",
23749 + opt->type = token;
23752 + if (unlikely(match_int(&a->args[0], &n)
23754 + || n * sizeof(struct hlist_head)
23755 + > KMALLOC_MAX_SIZE)) {
23756 + pr_err("bad integer in %s\n", opt_str);
23761 + opt->type = token;
23764 + case Opt_trunc_xino:
23765 + case Opt_notrunc_xino:
23767 + case Opt_trunc_xib:
23768 + case Opt_notrunc_xib:
23771 + case Opt_dirperm1:
23772 + case Opt_nodirperm1:
23774 + case Opt_noplink:
23775 + case Opt_list_plink:
23778 + case Opt_diropq_a:
23779 + case Opt_diropq_w:
23780 + case Opt_warn_perm:
23781 + case Opt_nowarn_perm:
23782 + case Opt_verbose:
23783 + case Opt_noverbose:
23787 + case Opt_rdblk_def:
23788 + case Opt_rdhash_def:
23792 + opt->type = token;
23796 + opt->udba = udba_val(a->args[0].from);
23797 + if (opt->udba >= 0) {
23799 + opt->type = token;
23801 + pr_err("wrong value, %s\n", opt_str);
23804 + case Opt_wbr_create:
23805 + u.create = &opt->wbr_create;
23806 + u.create->wbr_create
23807 + = au_wbr_create_val(a->args[0].from, u.create);
23808 + if (u.create->wbr_create >= 0) {
23810 + opt->type = token;
23812 + pr_err("wrong value, %s\n", opt_str);
23814 + case Opt_wbr_copyup:
23815 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
23816 + if (opt->wbr_copyup >= 0) {
23818 + opt->type = token;
23820 + pr_err("wrong value, %s\n", opt_str);
23823 + case Opt_fhsm_sec:
23824 + if (unlikely(match_int(&a->args[0], &n)
23826 + pr_err("bad integer in %s\n", opt_str);
23829 + if (sysaufs_brs) {
23830 + opt->fhsm_second = n;
23831 + opt->type = token;
23833 + pr_warn("ignored %s\n", opt_str);
23838 + pr_warn("ignored %s\n", opt_str);
23840 + case Opt_ignore_silent:
23845 + pr_err("unknown option %s\n", opt_str);
23849 + if (!err && !skipped) {
23850 + if (unlikely(++opt > opt_tail)) {
23853 + opt->type = Opt_tail;
23856 + opt->type = Opt_tail;
23862 + if (unlikely(err))
23863 + au_opts_free(opts);
23869 +static int au_opt_wbr_create(struct super_block *sb,
23870 + struct au_opt_wbr_create *create)
23873 + struct au_sbinfo *sbinfo;
23875 + SiMustWriteLock(sb);
23877 + err = 1; /* handled */
23878 + sbinfo = au_sbi(sb);
23879 + if (sbinfo->si_wbr_create_ops->fin) {
23880 + err = sbinfo->si_wbr_create_ops->fin(sb);
23885 + sbinfo->si_wbr_create = create->wbr_create;
23886 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
23887 + switch (create->wbr_create) {
23888 + case AuWbrCreate_MFSRRV:
23889 + case AuWbrCreate_MFSRR:
23890 + case AuWbrCreate_PMFSRR:
23891 + case AuWbrCreate_PMFSRRV:
23892 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
23894 + case AuWbrCreate_MFS:
23895 + case AuWbrCreate_MFSV:
23896 + case AuWbrCreate_PMFS:
23897 + case AuWbrCreate_PMFSV:
23898 + sbinfo->si_wbr_mfs.mfs_expire
23899 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
23903 + if (sbinfo->si_wbr_create_ops->init)
23904 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
23911 + * plus: processed without an error
23912 + * zero: unprocessed
23914 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
23915 + struct au_opts *opts)
23918 + struct au_sbinfo *sbinfo;
23920 + SiMustWriteLock(sb);
23922 + err = 1; /* handled */
23923 + sbinfo = au_sbi(sb);
23924 + switch (opt->type) {
23926 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
23927 + sbinfo->si_mntflags |= opt->udba;
23928 + opts->given_udba |= opt->udba;
23932 + au_opt_set(sbinfo->si_mntflags, PLINK);
23934 + case Opt_noplink:
23935 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23936 + au_plink_put(sb, /*verbose*/1);
23937 + au_opt_clr(sbinfo->si_mntflags, PLINK);
23939 + case Opt_list_plink:
23940 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
23941 + au_plink_list(sb);
23945 + au_opt_set(sbinfo->si_mntflags, DIO);
23946 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23949 + au_opt_clr(sbinfo->si_mntflags, DIO);
23950 + au_fset_opts(opts->flags, REFRESH_DYAOP);
23953 + case Opt_fhsm_sec:
23954 + au_fhsm_set(sbinfo, opt->fhsm_second);
23957 + case Opt_diropq_a:
23958 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23960 + case Opt_diropq_w:
23961 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
23964 + case Opt_warn_perm:
23965 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
23967 + case Opt_nowarn_perm:
23968 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
23971 + case Opt_verbose:
23972 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
23974 + case Opt_noverbose:
23975 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
23979 + au_opt_set(sbinfo->si_mntflags, SUM);
23982 + au_opt_clr(sbinfo->si_mntflags, SUM);
23983 + au_opt_set(sbinfo->si_mntflags, SUM_W);
23985 + au_opt_clr(sbinfo->si_mntflags, SUM);
23986 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
23989 + case Opt_wbr_create:
23990 + err = au_opt_wbr_create(sb, &opt->wbr_create);
23992 + case Opt_wbr_copyup:
23993 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
23994 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
23998 + sbinfo->si_dirwh = opt->dirwh;
24001 + case Opt_rdcache:
24002 + sbinfo->si_rdcache
24003 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24006 + sbinfo->si_rdblk = opt->rdblk;
24008 + case Opt_rdblk_def:
24009 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24012 + sbinfo->si_rdhash = opt->rdhash;
24014 + case Opt_rdhash_def:
24015 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24019 + au_opt_set(sbinfo->si_mntflags, SHWH);
24022 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24025 + case Opt_dirperm1:
24026 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24028 + case Opt_nodirperm1:
24029 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24032 + case Opt_trunc_xino:
24033 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24035 + case Opt_notrunc_xino:
24036 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24039 + case Opt_trunc_xino_path:
24040 + case Opt_itrunc_xino:
24041 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24046 + case Opt_trunc_xib:
24047 + au_fset_opts(opts->flags, TRUNC_XIB);
24049 + case Opt_notrunc_xib:
24050 + au_fclr_opts(opts->flags, TRUNC_XIB);
24054 + sb->s_flags |= MS_POSIXACL;
24057 + sb->s_flags &= ~MS_POSIXACL;
24069 + * returns tri-state.
24070 + * plus: processed without an error
24071 + * zero: unprocessed
24074 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24075 + struct au_opts *opts)
24077 + int err, do_refresh;
24080 + switch (opt->type) {
24082 + opt->add.bindex = au_sbend(sb) + 1;
24083 + if (opt->add.bindex < 0)
24084 + opt->add.bindex = 0;
24086 + case Opt_prepend:
24087 + opt->add.bindex = 0;
24088 + add: /* indented label */
24090 + err = au_br_add(sb, &opt->add,
24091 + au_ftest_opts(opts->flags, REMOUNT));
24094 + au_fset_opts(opts->flags, REFRESH);
24100 + err = au_br_del(sb, &opt->del,
24101 + au_ftest_opts(opts->flags, REMOUNT));
24104 + au_fset_opts(opts->flags, TRUNC_XIB);
24105 + au_fset_opts(opts->flags, REFRESH);
24111 + err = au_br_mod(sb, &opt->mod,
24112 + au_ftest_opts(opts->flags, REMOUNT),
24117 + au_fset_opts(opts->flags, REFRESH);
24125 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24126 + struct au_opt_xino **opt_xino,
24127 + struct au_opts *opts)
24130 + aufs_bindex_t bend, bindex;
24131 + struct dentry *root, *parent, *h_root;
24134 + switch (opt->type) {
24136 + err = au_xino_set(sb, &opt->xino,
24137 + !!au_ftest_opts(opts->flags, REMOUNT));
24138 + if (unlikely(err))
24141 + *opt_xino = &opt->xino;
24142 + au_xino_brid_set(sb, -1);
24144 + /* safe d_parent access */
24145 + parent = opt->xino.file->f_path.dentry->d_parent;
24146 + root = sb->s_root;
24147 + bend = au_sbend(sb);
24148 + for (bindex = 0; bindex <= bend; bindex++) {
24149 + h_root = au_h_dptr(root, bindex);
24150 + if (h_root == parent) {
24151 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24159 + au_xino_brid_set(sb, -1);
24160 + *opt_xino = (void *)-1;
24167 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24168 + unsigned int pending)
24171 + aufs_bindex_t bindex, bend;
24172 + unsigned char do_plink, skip, do_free;
24173 + struct au_branch *br;
24174 + struct au_wbr *wbr;
24175 + struct dentry *root;
24176 + struct inode *dir, *h_dir;
24177 + struct au_sbinfo *sbinfo;
24178 + struct au_hinode *hdir;
24180 + SiMustAnyLock(sb);
24182 + sbinfo = au_sbi(sb);
24183 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24185 + if (!(sb_flags & MS_RDONLY)) {
24186 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24187 + pr_warn("first branch should be rw\n");
24188 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24189 + pr_warn("shwh should be used with ro\n");
24192 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24193 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24194 + pr_warn("udba=*notify requires xino\n");
24196 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24197 + pr_warn("dirperm1 breaks the protection"
24198 + " by the permission bits on the lower branch\n");
24202 + root = sb->s_root;
24203 + dir = d_inode(root);
24204 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24205 + bend = au_sbend(sb);
24206 + for (bindex = 0; !err && bindex <= bend; bindex++) {
24208 + h_dir = au_h_iptr(dir, bindex);
24209 + br = au_sbr(sb, bindex);
24211 + if ((br->br_perm & AuBrAttr_ICEX)
24212 + && !h_dir->i_op->listxattr)
24213 + br->br_perm &= ~AuBrAttr_ICEX;
24215 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24216 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24217 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24221 + wbr = br->br_wbr;
24223 + wbr_wh_read_lock(wbr);
24225 + if (!au_br_writable(br->br_perm)) {
24228 + || (!wbr->wbr_whbase
24229 + && !wbr->wbr_plink
24230 + && !wbr->wbr_orph));
24231 + } else if (!au_br_wh_linkable(br->br_perm)) {
24232 + /* skip = (!br->br_whbase && !br->br_orph); */
24233 + skip = (!wbr || !wbr->wbr_whbase);
24234 + if (skip && wbr) {
24236 + skip = !!wbr->wbr_plink;
24238 + skip = !wbr->wbr_plink;
24241 + /* skip = (br->br_whbase && br->br_ohph); */
24242 + skip = (wbr && wbr->wbr_whbase);
24245 + skip = !!wbr->wbr_plink;
24247 + skip = !wbr->wbr_plink;
24251 + wbr_wh_read_unlock(wbr);
24253 + if (au_br_fhsm(br->br_perm)) {
24255 + AuDebugOn(!br->br_fhsm);
24261 + hdir = au_hi(dir, bindex);
24262 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
24264 + wbr_wh_write_lock(wbr);
24265 + err = au_wh_init(br, sb);
24267 + wbr_wh_write_unlock(wbr);
24268 + au_hn_imtx_unlock(hdir);
24270 + if (!err && do_free) {
24272 + br->br_wbr = NULL;
24277 + au_fset_si(sbinfo, FHSM);
24278 + for (bindex = bend; bindex >= 0; bindex--) {
24279 + br = au_sbr(sb, bindex);
24280 + if (au_br_fhsm(br->br_perm)) {
24281 + au_fhsm_set_bottom(sb, bindex);
24286 + au_fclr_si(sbinfo, FHSM);
24287 + au_fhsm_set_bottom(sb, -1);
24293 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24296 + unsigned int tmp;
24297 + aufs_bindex_t bindex, bend;
24298 + struct au_opt *opt;
24299 + struct au_opt_xino *opt_xino, xino;
24300 + struct au_sbinfo *sbinfo;
24301 + struct au_branch *br;
24302 + struct inode *dir;
24304 + SiMustWriteLock(sb);
24309 + while (err >= 0 && opt->type != Opt_tail)
24310 + err = au_opt_simple(sb, opt++, opts);
24313 + else if (unlikely(err < 0))
24316 + /* disable xino and udba temporary */
24317 + sbinfo = au_sbi(sb);
24318 + tmp = sbinfo->si_mntflags;
24319 + au_opt_clr(sbinfo->si_mntflags, XINO);
24320 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
24323 + while (err >= 0 && opt->type != Opt_tail)
24324 + err = au_opt_br(sb, opt++, opts);
24327 + else if (unlikely(err < 0))
24330 + bend = au_sbend(sb);
24331 + if (unlikely(bend < 0)) {
24333 + pr_err("no branches\n");
24337 + if (au_opt_test(tmp, XINO))
24338 + au_opt_set(sbinfo->si_mntflags, XINO);
24340 + while (!err && opt->type != Opt_tail)
24341 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
24342 + if (unlikely(err))
24345 + err = au_opts_verify(sb, sb->s_flags, tmp);
24346 + if (unlikely(err))
24349 + /* restore xino */
24350 + if (au_opt_test(tmp, XINO) && !opt_xino) {
24351 + xino.file = au_xino_def(sb);
24352 + err = PTR_ERR(xino.file);
24353 + if (IS_ERR(xino.file))
24356 + err = au_xino_set(sb, &xino, /*remount*/0);
24358 + if (unlikely(err))
24362 + /* restore udba */
24363 + tmp &= AuOptMask_UDBA;
24364 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24365 + sbinfo->si_mntflags |= tmp;
24366 + bend = au_sbend(sb);
24367 + for (bindex = 0; bindex <= bend; bindex++) {
24368 + br = au_sbr(sb, bindex);
24369 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
24370 + if (unlikely(err))
24371 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24373 + /* go on even if err */
24375 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
24376 + dir = d_inode(sb->s_root);
24377 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
24384 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
24387 + struct inode *dir;
24388 + struct au_opt_xino *opt_xino;
24389 + struct au_opt *opt;
24390 + struct au_sbinfo *sbinfo;
24392 + SiMustWriteLock(sb);
24394 + dir = d_inode(sb->s_root);
24395 + sbinfo = au_sbi(sb);
24399 + while (err >= 0 && opt->type != Opt_tail) {
24400 + err = au_opt_simple(sb, opt, opts);
24402 + err = au_opt_br(sb, opt, opts);
24404 + err = au_opt_xino(sb, opt, &opt_xino, opts);
24410 + /* go on even err */
24412 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
24413 + if (unlikely(rerr && !err))
24416 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
24417 + rerr = au_xib_trunc(sb);
24418 + if (unlikely(rerr && !err))
24422 + /* will be handled by the caller */
24423 + if (!au_ftest_opts(opts->flags, REFRESH)
24424 + && (opts->given_udba || au_opt_test(sbinfo->si_mntflags, XINO)))
24425 + au_fset_opts(opts->flags, REFRESH);
24427 + AuDbg("status 0x%x\n", opts->flags);
24431 +/* ---------------------------------------------------------------------- */
24433 +unsigned int au_opt_udba(struct super_block *sb)
24435 + return au_mntflags(sb) & AuOptMask_UDBA;
24437 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
24438 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
24439 +++ linux/fs/aufs/opts.h 2015-09-24 10:47:58.254719746 +0200
24442 + * Copyright (C) 2005-2015 Junjiro R. Okajima
24444 + * This program, aufs is free software; you can redistribute it and/or modify
24445 + * it under the terms of the GNU General Public License as published by
24446 + * the Free Software Foundation; either version 2 of the License, or
24447 + * (at your option) any later version.
24449 + * This program is distributed in the hope that it will be useful,
24450 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24451 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24452 + * GNU General Public License for more details.
24454 + * You should have received a copy of the GNU General Public License
24455 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24459 + * mount options/flags
24462 +#ifndef __AUFS_OPTS_H__
24463 +#define __AUFS_OPTS_H__
24467 +#include <linux/path.h>
24470 +struct super_block;
24472 +/* ---------------------------------------------------------------------- */
24475 +#define AuOpt_XINO 1 /* external inode number bitmap
24476 + and translation table */
24477 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
24478 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
24479 +#define AuOpt_UDBA_REVAL (1 << 3)
24480 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
24481 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
24482 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
24483 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
24485 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
24486 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
24487 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
24488 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
24489 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
24490 +#define AuOpt_DIO (1 << 14) /* direct io */
24492 +#ifndef CONFIG_AUFS_HNOTIFY
24493 +#undef AuOpt_UDBA_HNOTIFY
24494 +#define AuOpt_UDBA_HNOTIFY 0
24496 +#ifndef CONFIG_AUFS_SHWH
24498 +#define AuOpt_SHWH 0
24501 +#define AuOpt_Def (AuOpt_XINO \
24502 + | AuOpt_UDBA_REVAL \
24504 + /* | AuOpt_DIRPERM1 */ \
24505 + | AuOpt_WARN_PERM)
24506 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
24507 + | AuOpt_UDBA_REVAL \
24508 + | AuOpt_UDBA_HNOTIFY)
24510 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
24511 +#define au_opt_set(flags, name) do { \
24512 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
24513 + ((flags) |= AuOpt_##name); \
24515 +#define au_opt_set_udba(flags, name) do { \
24516 + (flags) &= ~AuOptMask_UDBA; \
24517 + ((flags) |= AuOpt_##name); \
24519 +#define au_opt_clr(flags, name) do { \
24520 + ((flags) &= ~AuOpt_##name); \
24523 +static inline unsigned int au_opts_plink(unsigned int mntflags)
24525 +#ifdef CONFIG_PROC_FS
24528 + return mntflags & ~AuOpt_PLINK;
24532 +/* ---------------------------------------------------------------------- */
24534 +/* policies to select one among multiple writable branches */
24536 + AuWbrCreate_TDP, /* top down parent */
24537 + AuWbrCreate_RR, /* round robin */
24538 + AuWbrCreate_MFS, /* most free space */
24539 + AuWbrCreate_MFSV, /* mfs with seconds */
24540 + AuWbrCreate_MFSRR, /* mfs then rr */
24541 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
24542 + AuWbrCreate_PMFS, /* parent and mfs */
24543 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
24544 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
24545 + AuWbrCreate_PMFSRRV, /* plus seconds */
24547 + AuWbrCreate_Def = AuWbrCreate_TDP
24551 + AuWbrCopyup_TDP, /* top down parent */
24552 + AuWbrCopyup_BUP, /* bottom up parent */
24553 + AuWbrCopyup_BU, /* bottom up */
24555 + AuWbrCopyup_Def = AuWbrCopyup_TDP
24558 +/* ---------------------------------------------------------------------- */
24560 +struct au_opt_add {
24561 + aufs_bindex_t bindex;
24564 + struct path path;
24567 +struct au_opt_del {
24569 + struct path h_path;
24572 +struct au_opt_mod {
24575 + struct dentry *h_root;
24578 +struct au_opt_xino {
24580 + struct file *file;
24583 +struct au_opt_xino_itrunc {
24584 + aufs_bindex_t bindex;
24587 +struct au_opt_wbr_create {
24590 + unsigned long long mfsrr_watermark;
24596 + struct au_opt_xino xino;
24597 + struct au_opt_xino_itrunc xino_itrunc;
24598 + struct au_opt_add add;
24599 + struct au_opt_del del;
24600 + struct au_opt_mod mod;
24603 + unsigned int rdblk;
24604 + unsigned int rdhash;
24606 + struct au_opt_wbr_create wbr_create;
24608 + unsigned int fhsm_second;
24613 +#define AuOpts_REMOUNT 1
24614 +#define AuOpts_REFRESH (1 << 1)
24615 +#define AuOpts_TRUNC_XIB (1 << 2)
24616 +#define AuOpts_REFRESH_DYAOP (1 << 3)
24617 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
24618 +#define au_fset_opts(flags, name) \
24619 + do { (flags) |= AuOpts_##name; } while (0)
24620 +#define au_fclr_opts(flags, name) \
24621 + do { (flags) &= ~AuOpts_##name; } while (0)
24624 + struct au_opt *opt;
24627 + unsigned int given_udba;
24628 + unsigned int flags;
24629 + unsigned long sb_flags;
24632 +/* ---------------------------------------------------------------------- */
24635 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
24636 +const char *au_optstr_udba(int udba);
24637 +const char *au_optstr_wbr_copyup(int wbr_copyup);
24638 +const char *au_optstr_wbr_create(int wbr_create);
24640 +void au_opts_free(struct au_opts *opts);
24641 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
24642 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24643 + unsigned int pending);
24644 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
24645 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
24647 +unsigned int au_opt_udba(struct super_block *sb);
24649 +#endif /* __KERNEL__ */
24650 +#endif /* __AUFS_OPTS_H__ */
24651 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
24652 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
24653 +++ linux/fs/aufs/plink.c 2015-09-24 10:47:58.254719746 +0200
24656 + * Copyright (C) 2005-2015 Junjiro R. Okajima
24658 + * This program, aufs is free software; you can redistribute it and/or modify
24659 + * it under the terms of the GNU General Public License as published by
24660 + * the Free Software Foundation; either version 2 of the License, or
24661 + * (at your option) any later version.
24663 + * This program is distributed in the hope that it will be useful,
24664 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24665 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24666 + * GNU General Public License for more details.
24668 + * You should have received a copy of the GNU General Public License
24669 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24679 + * the pseudo-link maintenance mode.
24680 + * during a user process maintains the pseudo-links,
24681 + * prohibit adding a new plink and branch manipulation.
24685 + * For entry functions which will handle plink, and i_mutex is already held
24687 + * They cannot wait and should return an error at once.
24688 + * Callers has to check the error.
24690 + * For entry functions which will handle plink, but i_mutex is not held
24692 + * They can wait the plink maintenance mode to finish.
24694 + * They behave like F_SETLK and F_SETLKW.
24695 + * If the caller never handle plink, then both flags are unnecessary.
24698 +int au_plink_maint(struct super_block *sb, int flags)
24702 + struct au_sbinfo *sbi;
24704 + SiMustAnyLock(sb);
24707 + if (!au_opt_test(au_mntflags(sb), PLINK))
24710 + sbi = au_sbi(sb);
24711 + pid = sbi->si_plink_maint_pid;
24712 + if (!pid || pid == current->pid)
24715 + /* todo: it highly depends upon /sbin/mount.aufs */
24717 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
24718 + rcu_read_unlock();
24722 + if (au_ftest_lock(flags, NOPLMW)) {
24723 + /* if there is no i_mutex lock in VFS, we don't need to wait */
24724 + /* AuDebugOn(!lockdep_depth(current)); */
24725 + while (sbi->si_plink_maint_pid) {
24726 + si_read_unlock(sb);
24727 + /* gave up wake_up_bit() */
24728 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
24730 + if (au_ftest_lock(flags, FLUSH))
24731 + au_nwt_flush(&sbi->si_nowait);
24732 + si_noflush_read_lock(sb);
24734 + } else if (au_ftest_lock(flags, NOPLM)) {
24735 + AuDbg("ppid %d, pid %d\n", ppid, pid);
24743 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
24745 + spin_lock(&sbinfo->si_plink_maint_lock);
24746 + sbinfo->si_plink_maint_pid = 0;
24747 + spin_unlock(&sbinfo->si_plink_maint_lock);
24748 + wake_up_all(&sbinfo->si_plink_wq);
24751 +int au_plink_maint_enter(struct super_block *sb)
24754 + struct au_sbinfo *sbinfo;
24757 + sbinfo = au_sbi(sb);
24758 + /* make sure i am the only one in this fs */
24759 + si_write_lock(sb, AuLock_FLUSH);
24760 + if (au_opt_test(au_mntflags(sb), PLINK)) {
24761 + spin_lock(&sbinfo->si_plink_maint_lock);
24762 + if (!sbinfo->si_plink_maint_pid)
24763 + sbinfo->si_plink_maint_pid = current->pid;
24766 + spin_unlock(&sbinfo->si_plink_maint_lock);
24768 + si_write_unlock(sb);
24773 +/* ---------------------------------------------------------------------- */
24775 +#ifdef CONFIG_AUFS_DEBUG
24776 +void au_plink_list(struct super_block *sb)
24779 + struct au_sbinfo *sbinfo;
24780 + struct hlist_head *plink_hlist;
24781 + struct pseudo_link *plink;
24783 + SiMustAnyLock(sb);
24785 + sbinfo = au_sbi(sb);
24786 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
24787 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
24789 + for (i = 0; i < AuPlink_NHASH; i++) {
24790 + plink_hlist = &sbinfo->si_plink[i].head;
24792 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24793 + AuDbg("%lu\n", plink->inode->i_ino);
24794 + rcu_read_unlock();
24799 +/* is the inode pseudo-linked? */
24800 +int au_plink_test(struct inode *inode)
24803 + struct au_sbinfo *sbinfo;
24804 + struct hlist_head *plink_hlist;
24805 + struct pseudo_link *plink;
24807 + sbinfo = au_sbi(inode->i_sb);
24808 + AuRwMustAnyLock(&sbinfo->si_rwsem);
24809 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
24810 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24813 + i = au_plink_hash(inode->i_ino);
24814 + plink_hlist = &sbinfo->si_plink[i].head;
24816 + hlist_for_each_entry_rcu(plink, plink_hlist, hlist)
24817 + if (plink->inode == inode) {
24821 + rcu_read_unlock();
24825 +/* ---------------------------------------------------------------------- */
24828 + * generate a name for plink.
24829 + * the file will be stored under AUFS_WH_PLINKDIR.
24831 +/* 20 is max digits length of ulong 64 */
24832 +#define PLINK_NAME_LEN ((20 + 1) * 2)
24834 +static int plink_name(char *name, int len, struct inode *inode,
24835 + aufs_bindex_t bindex)
24838 + struct inode *h_inode;
24840 + h_inode = au_h_iptr(inode, bindex);
24841 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
24845 +struct au_do_plink_lkup_args {
24846 + struct dentry **errp;
24847 + struct qstr *tgtname;
24848 + struct dentry *h_parent;
24849 + struct au_branch *br;
24852 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
24853 + struct dentry *h_parent,
24854 + struct au_branch *br)
24856 + struct dentry *h_dentry;
24857 + struct mutex *h_mtx;
24859 + h_mtx = &d_inode(h_parent)->i_mutex;
24860 + mutex_lock_nested(h_mtx, AuLsc_I_CHILD2);
24861 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
24862 + mutex_unlock(h_mtx);
24866 +static void au_call_do_plink_lkup(void *args)
24868 + struct au_do_plink_lkup_args *a = args;
24869 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
24872 +/* lookup the plink-ed @inode under the branch at @bindex */
24873 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
24875 + struct dentry *h_dentry, *h_parent;
24876 + struct au_branch *br;
24878 + char a[PLINK_NAME_LEN];
24879 + struct qstr tgtname = QSTR_INIT(a, 0);
24881 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
24883 + br = au_sbr(inode->i_sb, bindex);
24884 + h_parent = br->br_wbr->wbr_plink;
24885 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24887 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24888 + struct au_do_plink_lkup_args args = {
24889 + .errp = &h_dentry,
24890 + .tgtname = &tgtname,
24891 + .h_parent = h_parent,
24895 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
24896 + if (unlikely(wkq_err))
24897 + h_dentry = ERR_PTR(wkq_err);
24899 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
24904 +/* create a pseudo-link */
24905 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
24906 + struct dentry *h_dentry, struct au_branch *br)
24909 + struct path h_path = {
24910 + .mnt = au_br_mnt(br)
24912 + struct inode *h_dir, *delegated;
24914 + h_dir = d_inode(h_parent);
24915 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_CHILD2);
24917 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
24918 + err = PTR_ERR(h_path.dentry);
24919 + if (IS_ERR(h_path.dentry))
24923 + /* wh.plink dir is not monitored */
24924 + /* todo: is it really safe? */
24925 + if (d_is_positive(h_path.dentry)
24926 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
24927 + delegated = NULL;
24928 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
24929 + if (unlikely(err == -EWOULDBLOCK)) {
24930 + pr_warn("cannot retry for NFSv4 delegation"
24931 + " for an internal unlink\n");
24934 + dput(h_path.dentry);
24935 + h_path.dentry = NULL;
24939 + if (!err && d_is_negative(h_path.dentry)) {
24940 + delegated = NULL;
24941 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
24942 + if (unlikely(err == -EWOULDBLOCK)) {
24943 + pr_warn("cannot retry for NFSv4 delegation"
24944 + " for an internal link\n");
24948 + dput(h_path.dentry);
24951 + mutex_unlock(&h_dir->i_mutex);
24955 +struct do_whplink_args {
24957 + struct qstr *tgt;
24958 + struct dentry *h_parent;
24959 + struct dentry *h_dentry;
24960 + struct au_branch *br;
24963 +static void call_do_whplink(void *args)
24965 + struct do_whplink_args *a = args;
24966 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
24969 +static int whplink(struct dentry *h_dentry, struct inode *inode,
24970 + aufs_bindex_t bindex, struct au_branch *br)
24972 + int err, wkq_err;
24973 + struct au_wbr *wbr;
24974 + struct dentry *h_parent;
24975 + char a[PLINK_NAME_LEN];
24976 + struct qstr tgtname = QSTR_INIT(a, 0);
24978 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
24979 + h_parent = wbr->wbr_plink;
24980 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
24982 + /* always superio. */
24983 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
24984 + struct do_whplink_args args = {
24987 + .h_parent = h_parent,
24988 + .h_dentry = h_dentry,
24991 + wkq_err = au_wkq_wait(call_do_whplink, &args);
24992 + if (unlikely(wkq_err))
24995 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
25000 +/* free a single plink */
25001 +static void do_put_plink(struct pseudo_link *plink, int do_del)
25004 + hlist_del(&plink->hlist);
25005 + iput(plink->inode);
25009 +static void do_put_plink_rcu(struct rcu_head *rcu)
25011 + struct pseudo_link *plink;
25013 + plink = container_of(rcu, struct pseudo_link, rcu);
25014 + iput(plink->inode);
25019 + * create a new pseudo-link for @h_dentry on @bindex.
25020 + * the linked inode is held in aufs @inode.
25022 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25023 + struct dentry *h_dentry)
25025 + struct super_block *sb;
25026 + struct au_sbinfo *sbinfo;
25027 + struct hlist_head *plink_hlist;
25028 + struct pseudo_link *plink, *tmp;
25029 + struct au_sphlhead *sphl;
25030 + int found, err, cnt, i;
25032 + sb = inode->i_sb;
25033 + sbinfo = au_sbi(sb);
25034 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25035 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25037 + found = au_plink_test(inode);
25041 + i = au_plink_hash(inode->i_ino);
25042 + sphl = sbinfo->si_plink + i;
25043 + plink_hlist = &sphl->head;
25044 + tmp = kmalloc(sizeof(*plink), GFP_NOFS);
25046 + tmp->inode = au_igrab(inode);
25052 + spin_lock(&sphl->spin);
25053 + hlist_for_each_entry(plink, plink_hlist, hlist) {
25054 + if (plink->inode == inode) {
25060 + hlist_add_head_rcu(&tmp->hlist, plink_hlist);
25061 + spin_unlock(&sphl->spin);
25063 + cnt = au_sphl_count(sphl);
25064 +#define msg "unexpectedly unblanced or too many pseudo-links"
25065 + if (cnt > AUFS_PLINK_WARN)
25066 + AuWarn1(msg ", %d\n", cnt);
25068 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25070 + do_put_plink(tmp, 0);
25075 + if (unlikely(err)) {
25076 + pr_warn("err %d, damaged pseudo link.\n", err);
25078 + au_sphl_del_rcu(&tmp->hlist, sphl);
25079 + call_rcu(&tmp->rcu, do_put_plink_rcu);
25084 +/* free all plinks */
25085 +void au_plink_put(struct super_block *sb, int verbose)
25088 + struct au_sbinfo *sbinfo;
25089 + struct hlist_head *plink_hlist;
25090 + struct hlist_node *tmp;
25091 + struct pseudo_link *plink;
25093 + SiMustWriteLock(sb);
25095 + sbinfo = au_sbi(sb);
25096 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25097 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25099 + /* no spin_lock since sbinfo is write-locked */
25101 + for (i = 0; i < AuPlink_NHASH; i++) {
25102 + plink_hlist = &sbinfo->si_plink[i].head;
25103 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25104 + pr_warn("pseudo-link is not flushed");
25107 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist)
25108 + do_put_plink(plink, 0);
25109 + INIT_HLIST_HEAD(plink_hlist);
25113 +void au_plink_clean(struct super_block *sb, int verbose)
25115 + struct dentry *root;
25117 + root = sb->s_root;
25118 + aufs_write_lock(root);
25119 + if (au_opt_test(au_mntflags(sb), PLINK))
25120 + au_plink_put(sb, verbose);
25121 + aufs_write_unlock(root);
25124 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25127 + aufs_bindex_t bstart, bend, bindex;
25130 + bstart = au_ibstart(inode);
25131 + bend = au_ibend(inode);
25132 + if (bstart >= 0) {
25133 + for (bindex = bstart; bindex <= bend; bindex++) {
25134 + if (!au_h_iptr(inode, bindex)
25135 + || au_ii_br_id(inode, bindex) != br_id)
25137 + au_set_h_iptr(inode, bindex, NULL, 0);
25142 + for (bindex = bstart; bindex <= bend; bindex++)
25143 + if (au_h_iptr(inode, bindex)) {
25153 +/* free the plinks on a branch specified by @br_id */
25154 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25156 + struct au_sbinfo *sbinfo;
25157 + struct hlist_head *plink_hlist;
25158 + struct hlist_node *tmp;
25159 + struct pseudo_link *plink;
25160 + struct inode *inode;
25163 + SiMustWriteLock(sb);
25165 + sbinfo = au_sbi(sb);
25166 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25167 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25169 + /* no spin_lock since sbinfo is write-locked */
25170 + for (i = 0; i < AuPlink_NHASH; i++) {
25171 + plink_hlist = &sbinfo->si_plink[i].head;
25172 + hlist_for_each_entry_safe(plink, tmp, plink_hlist, hlist) {
25173 + inode = au_igrab(plink->inode);
25174 + ii_write_lock_child(inode);
25175 + do_put = au_plink_do_half_refresh(inode, br_id);
25177 + do_put_plink(plink, 1);
25178 + ii_write_unlock(inode);
25183 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25184 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25185 +++ linux/fs/aufs/poll.c 2015-09-24 10:47:58.254719746 +0200
25188 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25190 + * This program, aufs is free software; you can redistribute it and/or modify
25191 + * it under the terms of the GNU General Public License as published by
25192 + * the Free Software Foundation; either version 2 of the License, or
25193 + * (at your option) any later version.
25195 + * This program is distributed in the hope that it will be useful,
25196 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25197 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25198 + * GNU General Public License for more details.
25200 + * You should have received a copy of the GNU General Public License
25201 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25206 + * There is only one filesystem which implements ->poll operation, currently.
25211 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25213 + unsigned int mask;
25215 + struct file *h_file;
25216 + struct super_block *sb;
25218 + /* We should pretend an error happened. */
25219 + mask = POLLERR /* | POLLIN | POLLOUT */;
25220 + sb = file->f_path.dentry->d_sb;
25221 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25223 + h_file = au_read_pre(file, /*keep_fi*/0);
25224 + err = PTR_ERR(h_file);
25225 + if (IS_ERR(h_file))
25228 + /* it is not an error if h_file has no operation */
25229 + mask = DEFAULT_POLLMASK;
25230 + if (h_file->f_op->poll)
25231 + mask = h_file->f_op->poll(h_file, wait);
25232 + fput(h_file); /* instead of au_read_post() */
25235 + si_read_unlock(sb);
25236 + AuTraceErr((int)mask);
25239 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25240 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25241 +++ linux/fs/aufs/posix_acl.c 2015-09-24 10:47:58.254719746 +0200
25244 + * Copyright (C) 2014-2015 Junjiro R. Okajima
25246 + * This program, aufs is free software; you can redistribute it and/or modify
25247 + * it under the terms of the GNU General Public License as published by
25248 + * the Free Software Foundation; either version 2 of the License, or
25249 + * (at your option) any later version.
25251 + * This program is distributed in the hope that it will be useful,
25252 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25253 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25254 + * GNU General Public License for more details.
25256 + * You should have received a copy of the GNU General Public License
25257 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25261 + * posix acl operations
25264 +#include <linux/fs.h>
25265 +#include <linux/posix_acl.h>
25268 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25270 + struct posix_acl *acl;
25272 + aufs_bindex_t bindex;
25273 + struct inode *h_inode;
25274 + struct super_block *sb;
25277 + sb = inode->i_sb;
25278 + si_read_lock(sb, AuLock_FLUSH);
25279 + ii_read_lock_child(inode);
25280 + if (!(sb->s_flags & MS_POSIXACL))
25283 + bindex = au_ibstart(inode);
25284 + h_inode = au_h_iptr(inode, bindex);
25285 + if (unlikely(!h_inode
25286 + || ((h_inode->i_mode & S_IFMT)
25287 + != (inode->i_mode & S_IFMT)))) {
25288 + err = au_busy_or_stale();
25289 + acl = ERR_PTR(err);
25293 + /* always topmost only */
25294 + acl = get_acl(h_inode, type);
25297 + ii_read_unlock(inode);
25298 + si_read_unlock(sb);
25300 + AuTraceErrPtr(acl);
25304 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25308 + struct dentry *dentry;
25309 + struct au_srxattr arg = {
25310 + .type = AU_ACL_SET,
25317 + mutex_lock(&inode->i_mutex);
25318 + if (inode->i_ino == AUFS_ROOT_INO)
25319 + dentry = dget(inode->i_sb->s_root);
25321 + dentry = d_find_alias(inode);
25323 + dentry = d_find_any_alias(inode);
25325 + pr_warn("cannot handle this inode, "
25326 + "please report to aufs-users ML\n");
25332 + ssz = au_srxattr(dentry, &arg);
25339 + mutex_unlock(&inode->i_mutex);
25342 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
25343 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
25344 +++ linux/fs/aufs/procfs.c 2015-09-24 10:47:58.254719746 +0200
25347 + * Copyright (C) 2010-2015 Junjiro R. Okajima
25349 + * This program, aufs is free software; you can redistribute it and/or modify
25350 + * it under the terms of the GNU General Public License as published by
25351 + * the Free Software Foundation; either version 2 of the License, or
25352 + * (at your option) any later version.
25354 + * This program is distributed in the hope that it will be useful,
25355 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25356 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25357 + * GNU General Public License for more details.
25359 + * You should have received a copy of the GNU General Public License
25360 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25364 + * procfs interfaces
25367 +#include <linux/proc_fs.h>
25370 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
25372 + struct au_sbinfo *sbinfo;
25374 + sbinfo = file->private_data;
25376 + au_plink_maint_leave(sbinfo);
25377 + kobject_put(&sbinfo->si_kobj);
25383 +static void au_procfs_plm_write_clean(struct file *file)
25385 + struct au_sbinfo *sbinfo;
25387 + sbinfo = file->private_data;
25389 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
25392 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
25395 + struct super_block *sb;
25396 + struct au_sbinfo *sbinfo;
25399 + if (unlikely(file->private_data))
25403 + /* don't use au_sbilist_lock() here */
25404 + spin_lock(&au_sbilist.spin);
25405 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
25406 + if (id == sysaufs_si_id(sbinfo)) {
25407 + kobject_get(&sbinfo->si_kobj);
25408 + sb = sbinfo->si_sb;
25411 + spin_unlock(&au_sbilist.spin);
25414 + if (unlikely(!sb))
25417 + err = au_plink_maint_enter(sb);
25419 + /* keep kobject_get() */
25420 + file->private_data = sbinfo;
25422 + kobject_put(&sbinfo->si_kobj);
25428 + * Accept a valid "si=xxxx" only.
25429 + * Once it is accepted successfully, accept "clean" too.
25431 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
25432 + size_t count, loff_t *ppos)
25435 + unsigned long id;
25436 + /* last newline is allowed */
25437 + char buf[3 + sizeof(unsigned long) * 2 + 1];
25440 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25444 + if (unlikely(count > sizeof(buf)))
25447 + err = copy_from_user(buf, ubuf, count);
25448 + if (unlikely(err)) {
25455 + if (!strcmp("clean", buf)) {
25456 + au_procfs_plm_write_clean(file);
25457 + goto out_success;
25458 + } else if (unlikely(strncmp("si=", buf, 3)))
25461 + err = kstrtoul(buf + 3, 16, &id);
25462 + if (unlikely(err))
25465 + err = au_procfs_plm_write_si(file, id);
25466 + if (unlikely(err))
25470 + err = count; /* success */
25475 +static const struct file_operations au_procfs_plm_fop = {
25476 + .write = au_procfs_plm_write,
25477 + .release = au_procfs_plm_release,
25478 + .owner = THIS_MODULE
25481 +/* ---------------------------------------------------------------------- */
25483 +static struct proc_dir_entry *au_procfs_dir;
25485 +void au_procfs_fin(void)
25487 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
25488 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25491 +int __init au_procfs_init(void)
25494 + struct proc_dir_entry *entry;
25497 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
25498 + if (unlikely(!au_procfs_dir))
25501 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
25502 + au_procfs_dir, &au_procfs_plm_fop);
25503 + if (unlikely(!entry))
25507 + goto out; /* success */
25511 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25515 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
25516 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
25517 +++ linux/fs/aufs/rdu.c 2015-09-24 10:47:58.254719746 +0200
25520 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25522 + * This program, aufs is free software; you can redistribute it and/or modify
25523 + * it under the terms of the GNU General Public License as published by
25524 + * the Free Software Foundation; either version 2 of the License, or
25525 + * (at your option) any later version.
25527 + * This program is distributed in the hope that it will be useful,
25528 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25529 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25530 + * GNU General Public License for more details.
25532 + * You should have received a copy of the GNU General Public License
25533 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25537 + * readdir in userspace.
25540 +#include <linux/compat.h>
25541 +#include <linux/fs_stack.h>
25542 +#include <linux/security.h>
25545 +/* bits for struct aufs_rdu.flags */
25546 +#define AuRdu_CALLED 1
25547 +#define AuRdu_CONT (1 << 1)
25548 +#define AuRdu_FULL (1 << 2)
25549 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
25550 +#define au_fset_rdu(flags, name) \
25551 + do { (flags) |= AuRdu_##name; } while (0)
25552 +#define au_fclr_rdu(flags, name) \
25553 + do { (flags) &= ~AuRdu_##name; } while (0)
25555 +struct au_rdu_arg {
25556 + struct dir_context ctx;
25557 + struct aufs_rdu *rdu;
25558 + union au_rdu_ent_ul ent;
25559 + unsigned long end;
25561 + struct super_block *sb;
25565 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
25566 + loff_t offset, u64 h_ino, unsigned int d_type)
25569 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
25570 + struct aufs_rdu *rdu = arg->rdu;
25571 + struct au_rdu_ent ent;
25575 + au_fset_rdu(rdu->cookie.flags, CALLED);
25576 + len = au_rdu_len(nlen);
25577 + if (arg->ent.ul + len < arg->end) {
25579 + ent.bindex = rdu->cookie.bindex;
25580 + ent.type = d_type;
25582 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25583 + ent.type = DT_UNKNOWN;
25585 + /* unnecessary to support mmap_sem since this is a dir */
25587 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
25589 + if (copy_to_user(arg->ent.e->name, name, nlen))
25591 + /* the terminating NULL */
25592 + if (__put_user(0, arg->ent.e->name + nlen))
25595 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
25596 + arg->ent.ul += len;
25600 + au_fset_rdu(rdu->cookie.flags, FULL);
25602 + rdu->tail = arg->ent;
25606 + /* AuTraceErr(err); */
25610 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
25614 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
25616 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
25617 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
25619 + if (unlikely(offset != cookie->h_pos))
25625 + au_fclr_rdu(cookie->flags, CALLED);
25627 + err = vfsub_iterate_dir(h_file, &arg->ctx);
25631 + && au_ftest_rdu(cookie->flags, CALLED)
25632 + && !au_ftest_rdu(cookie->flags, FULL));
25633 + cookie->h_pos = h_file->f_pos;
25640 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
25643 + aufs_bindex_t bend;
25644 + struct au_rdu_arg arg = {
25646 + .actor = au_rdu_fill
25649 + struct dentry *dentry;
25650 + struct inode *inode;
25651 + struct file *h_file;
25652 + struct au_rdu_cookie *cookie = &rdu->cookie;
25654 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
25655 + if (unlikely(err)) {
25661 + rdu->tail = rdu->ent;
25664 + arg.ent = rdu->ent;
25665 + arg.end = arg.ent.ul;
25666 + arg.end += rdu->sz;
25669 + if (unlikely(!file->f_op->iterate))
25672 + err = security_file_permission(file, MAY_READ);
25674 + if (unlikely(err))
25677 + dentry = file->f_path.dentry;
25678 + inode = d_inode(dentry);
25680 + mutex_lock(&inode->i_mutex);
25682 + err = mutex_lock_killable(&inode->i_mutex);
25684 + if (unlikely(err))
25688 + arg.sb = inode->i_sb;
25689 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
25690 + if (unlikely(err))
25692 + err = au_alive_dir(dentry);
25693 + if (unlikely(err))
25695 + /* todo: reval? */
25696 + fi_read_lock(file);
25699 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
25700 + && cookie->generation != au_figen(file)))
25705 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
25707 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
25709 + bend = au_fbstart(file);
25710 + if (cookie->bindex < bend)
25711 + cookie->bindex = bend;
25712 + bend = au_fbend_dir(file);
25713 + /* AuDbg("b%d, b%d\n", cookie->bindex, bend); */
25714 + for (; !err && cookie->bindex <= bend;
25715 + cookie->bindex++, cookie->h_pos = 0) {
25716 + h_file = au_hf_dir(file, cookie->bindex);
25720 + au_fclr_rdu(cookie->flags, FULL);
25721 + err = au_rdu_do(h_file, &arg);
25723 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
25726 + AuDbg("rent %llu\n", rdu->rent);
25728 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
25729 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
25730 + au_fset_rdu(cookie->flags, CONT);
25731 + cookie->generation = au_figen(file);
25734 + ii_read_lock_child(inode);
25735 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibstart(inode)));
25736 + ii_read_unlock(inode);
25739 + fi_read_unlock(file);
25741 + si_read_unlock(arg.sb);
25743 + mutex_unlock(&inode->i_mutex);
25749 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
25753 + unsigned long long nent;
25754 + union au_rdu_ent_ul *u;
25755 + struct au_rdu_ent ent;
25756 + struct super_block *sb;
25759 + nent = rdu->nent;
25761 + sb = file->f_path.dentry->d_sb;
25762 + si_read_lock(sb, AuLock_FLUSH);
25763 + while (nent-- > 0) {
25764 + /* unnecessary to support mmap_sem since this is a dir */
25765 + err = copy_from_user(&ent, u->e, sizeof(ent));
25767 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
25768 + if (unlikely(err)) {
25774 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
25776 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
25778 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
25780 + if (unlikely(err)) {
25785 + err = __put_user(ino, &u->e->ino);
25786 + if (unlikely(err)) {
25791 + u->ul += au_rdu_len(ent.nlen);
25793 + si_read_unlock(sb);
25798 +/* ---------------------------------------------------------------------- */
25800 +static int au_rdu_verify(struct aufs_rdu *rdu)
25802 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
25803 + "%llu, b%d, 0x%x, g%u}\n",
25804 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
25806 + rdu->rent, rdu->shwh, rdu->full,
25807 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
25808 + rdu->cookie.generation);
25810 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
25814 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
25818 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25821 + struct aufs_rdu rdu;
25822 + void __user *p = (void __user *)arg;
25824 + err = copy_from_user(&rdu, p, sizeof(rdu));
25825 + if (unlikely(err)) {
25830 + err = au_rdu_verify(&rdu);
25831 + if (unlikely(err))
25835 + case AUFS_CTL_RDU:
25836 + err = au_rdu(file, &rdu);
25837 + if (unlikely(err))
25840 + e = copy_to_user(p, &rdu, sizeof(rdu));
25841 + if (unlikely(e)) {
25846 + case AUFS_CTL_RDU_INO:
25847 + err = au_rdu_ino(file, &rdu);
25851 + /* err = -ENOTTY; */
25860 +#ifdef CONFIG_COMPAT
25861 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
25864 + struct aufs_rdu rdu;
25865 + void __user *p = compat_ptr(arg);
25867 + /* todo: get_user()? */
25868 + err = copy_from_user(&rdu, p, sizeof(rdu));
25869 + if (unlikely(err)) {
25874 + rdu.ent.e = compat_ptr(rdu.ent.ul);
25875 + err = au_rdu_verify(&rdu);
25876 + if (unlikely(err))
25880 + case AUFS_CTL_RDU:
25881 + err = au_rdu(file, &rdu);
25882 + if (unlikely(err))
25885 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
25886 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
25887 + e = copy_to_user(p, &rdu, sizeof(rdu));
25888 + if (unlikely(e)) {
25893 + case AUFS_CTL_RDU_INO:
25894 + err = au_rdu_ino(file, &rdu);
25898 + /* err = -ENOTTY; */
25907 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
25908 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
25909 +++ linux/fs/aufs/rwsem.h 2015-09-24 10:47:58.254719746 +0200
25912 + * Copyright (C) 2005-2015 Junjiro R. Okajima
25914 + * This program, aufs is free software; you can redistribute it and/or modify
25915 + * it under the terms of the GNU General Public License as published by
25916 + * the Free Software Foundation; either version 2 of the License, or
25917 + * (at your option) any later version.
25919 + * This program is distributed in the hope that it will be useful,
25920 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25921 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25922 + * GNU General Public License for more details.
25924 + * You should have received a copy of the GNU General Public License
25925 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25929 + * simple read-write semaphore wrappers
25932 +#ifndef __AUFS_RWSEM_H__
25933 +#define __AUFS_RWSEM_H__
25937 +#include "debug.h"
25940 + struct rw_semaphore rwsem;
25941 +#ifdef CONFIG_AUFS_DEBUG
25942 + /* just for debugging, not almighty counter */
25943 + atomic_t rcnt, wcnt;
25947 +#ifdef CONFIG_AUFS_DEBUG
25948 +#define AuDbgCntInit(rw) do { \
25949 + atomic_set(&(rw)->rcnt, 0); \
25950 + atomic_set(&(rw)->wcnt, 0); \
25951 + smp_mb(); /* atomic set */ \
25954 +#define AuDbgRcntInc(rw) atomic_inc(&(rw)->rcnt)
25955 +#define AuDbgRcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->rcnt) < 0)
25956 +#define AuDbgWcntInc(rw) atomic_inc(&(rw)->wcnt)
25957 +#define AuDbgWcntDec(rw) WARN_ON(atomic_dec_return(&(rw)->wcnt) < 0)
25959 +#define AuDbgCntInit(rw) do {} while (0)
25960 +#define AuDbgRcntInc(rw) do {} while (0)
25961 +#define AuDbgRcntDec(rw) do {} while (0)
25962 +#define AuDbgWcntInc(rw) do {} while (0)
25963 +#define AuDbgWcntDec(rw) do {} while (0)
25964 +#endif /* CONFIG_AUFS_DEBUG */
25966 +/* to debug easier, do not make them inlined functions */
25967 +#define AuRwMustNoWaiters(rw) AuDebugOn(!list_empty(&(rw)->rwsem.wait_list))
25968 +/* rwsem_is_locked() is unusable */
25969 +#define AuRwMustReadLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0)
25970 +#define AuRwMustWriteLock(rw) AuDebugOn(atomic_read(&(rw)->wcnt) <= 0)
25971 +#define AuRwMustAnyLock(rw) AuDebugOn(atomic_read(&(rw)->rcnt) <= 0 \
25972 + && atomic_read(&(rw)->wcnt) <= 0)
25973 +#define AuRwDestroy(rw) AuDebugOn(atomic_read(&(rw)->rcnt) \
25974 + || atomic_read(&(rw)->wcnt))
25976 +#define au_rw_class(rw, key) lockdep_set_class(&(rw)->rwsem, key)
25978 +static inline void au_rw_init(struct au_rwsem *rw)
25980 + AuDbgCntInit(rw);
25981 + init_rwsem(&rw->rwsem);
25984 +static inline void au_rw_init_wlock(struct au_rwsem *rw)
25987 + down_write(&rw->rwsem);
25988 + AuDbgWcntInc(rw);
25991 +static inline void au_rw_init_wlock_nested(struct au_rwsem *rw,
25992 + unsigned int lsc)
25995 + down_write_nested(&rw->rwsem, lsc);
25996 + AuDbgWcntInc(rw);
25999 +static inline void au_rw_read_lock(struct au_rwsem *rw)
26001 + down_read(&rw->rwsem);
26002 + AuDbgRcntInc(rw);
26005 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26007 + down_read_nested(&rw->rwsem, lsc);
26008 + AuDbgRcntInc(rw);
26011 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26013 + AuRwMustReadLock(rw);
26014 + AuDbgRcntDec(rw);
26015 + up_read(&rw->rwsem);
26018 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26020 + AuRwMustWriteLock(rw);
26021 + AuDbgRcntInc(rw);
26022 + AuDbgWcntDec(rw);
26023 + downgrade_write(&rw->rwsem);
26026 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26028 + down_write(&rw->rwsem);
26029 + AuDbgWcntInc(rw);
26032 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26033 + unsigned int lsc)
26035 + down_write_nested(&rw->rwsem, lsc);
26036 + AuDbgWcntInc(rw);
26039 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26041 + AuRwMustWriteLock(rw);
26042 + AuDbgWcntDec(rw);
26043 + up_write(&rw->rwsem);
26046 +/* why is not _nested version defined */
26047 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26051 + ret = down_read_trylock(&rw->rwsem);
26053 + AuDbgRcntInc(rw);
26057 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26061 + ret = down_write_trylock(&rw->rwsem);
26063 + AuDbgWcntInc(rw);
26067 +#undef AuDbgCntInit
26068 +#undef AuDbgRcntInc
26069 +#undef AuDbgRcntDec
26070 +#undef AuDbgWcntInc
26071 +#undef AuDbgWcntDec
26073 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26074 +static inline void prefix##_read_lock(param) \
26075 +{ au_rw_read_lock(rwsem); } \
26076 +static inline void prefix##_write_lock(param) \
26077 +{ au_rw_write_lock(rwsem); } \
26078 +static inline int prefix##_read_trylock(param) \
26079 +{ return au_rw_read_trylock(rwsem); } \
26080 +static inline int prefix##_write_trylock(param) \
26081 +{ return au_rw_write_trylock(rwsem); }
26082 +/* why is not _nested version defined */
26083 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26084 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26085 +static inline void prefix##_write_trylock_nestd(param, lsc)
26086 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26088 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26089 +static inline void prefix##_read_unlock(param) \
26090 +{ au_rw_read_unlock(rwsem); } \
26091 +static inline void prefix##_write_unlock(param) \
26092 +{ au_rw_write_unlock(rwsem); } \
26093 +static inline void prefix##_downgrade_lock(param) \
26094 +{ au_rw_dgrade_lock(rwsem); }
26096 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26097 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26098 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26100 +#endif /* __KERNEL__ */
26101 +#endif /* __AUFS_RWSEM_H__ */
26102 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26103 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26104 +++ linux/fs/aufs/sbinfo.c 2015-09-24 10:47:58.254719746 +0200
26107 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26109 + * This program, aufs is free software; you can redistribute it and/or modify
26110 + * it under the terms of the GNU General Public License as published by
26111 + * the Free Software Foundation; either version 2 of the License, or
26112 + * (at your option) any later version.
26114 + * This program is distributed in the hope that it will be useful,
26115 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26116 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26117 + * GNU General Public License for more details.
26119 + * You should have received a copy of the GNU General Public License
26120 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26124 + * superblock private data
26130 + * they are necessary regardless sysfs is disabled.
26132 +void au_si_free(struct kobject *kobj)
26135 + struct au_sbinfo *sbinfo;
26136 + char *locked __maybe_unused; /* debug only */
26138 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26139 + for (i = 0; i < AuPlink_NHASH; i++)
26140 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26141 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
26143 + AuDebugOn(!hlist_empty(&sbinfo->si_symlink.head));
26145 + au_rw_write_lock(&sbinfo->si_rwsem);
26146 + au_br_free(sbinfo);
26147 + au_rw_write_unlock(&sbinfo->si_rwsem);
26149 + AuDebugOn(radix_tree_gang_lookup
26150 + (&sbinfo->au_si_pid.tree, (void **)&locked,
26151 + /*first_index*/PID_MAX_DEFAULT - 1,
26152 + /*max_items*/sizeof(locked)/sizeof(*locked)));
26154 + kfree(sbinfo->si_branch);
26155 + kfree(sbinfo->au_si_pid.bitmap);
26156 + mutex_destroy(&sbinfo->si_xib_mtx);
26157 + AuRwDestroy(&sbinfo->si_rwsem);
26162 +int au_si_alloc(struct super_block *sb)
26165 + struct au_sbinfo *sbinfo;
26166 + static struct lock_class_key aufs_si;
26169 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26170 + if (unlikely(!sbinfo))
26173 + BUILD_BUG_ON(sizeof(unsigned long) !=
26174 + sizeof(*sbinfo->au_si_pid.bitmap));
26175 + sbinfo->au_si_pid.bitmap = kcalloc(BITS_TO_LONGS(PID_MAX_DEFAULT),
26176 + sizeof(*sbinfo->au_si_pid.bitmap),
26178 + if (unlikely(!sbinfo->au_si_pid.bitmap))
26181 + /* will be reallocated separately */
26182 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26183 + if (unlikely(!sbinfo->si_branch))
26186 + err = sysaufs_si_init(sbinfo);
26187 + if (unlikely(err))
26190 + au_nwt_init(&sbinfo->si_nowait);
26191 + au_rw_init_wlock(&sbinfo->si_rwsem);
26192 + au_rw_class(&sbinfo->si_rwsem, &aufs_si);
26193 + spin_lock_init(&sbinfo->au_si_pid.tree_lock);
26194 + INIT_RADIX_TREE(&sbinfo->au_si_pid.tree, GFP_ATOMIC | __GFP_NOFAIL);
26196 + atomic_long_set(&sbinfo->si_ninodes, 0);
26197 + atomic_long_set(&sbinfo->si_nfiles, 0);
26199 + sbinfo->si_bend = -1;
26200 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26202 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26203 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26204 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26205 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26207 + au_fhsm_init(sbinfo);
26209 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26211 + au_sphl_init(&sbinfo->si_symlink);
26213 + sbinfo->si_xino_jiffy = jiffies;
26214 + sbinfo->si_xino_expire
26215 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26216 + mutex_init(&sbinfo->si_xib_mtx);
26217 + sbinfo->si_xino_brid = -1;
26218 + /* leave si_xib_last_pindex and si_xib_next_bit */
26220 + au_sphl_init(&sbinfo->si_aopen);
26222 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26223 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26224 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26225 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26227 + for (i = 0; i < AuPlink_NHASH; i++)
26228 + au_sphl_init(sbinfo->si_plink + i);
26229 + init_waitqueue_head(&sbinfo->si_plink_wq);
26230 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26232 + au_sphl_init(&sbinfo->si_files);
26234 + /* leave other members for sysaufs and si_mnt. */
26235 + sbinfo->si_sb = sb;
26236 + sb->s_fs_info = sbinfo;
26238 + return 0; /* success */
26241 + kfree(sbinfo->si_branch);
26243 + kfree(sbinfo->au_si_pid.bitmap);
26250 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
26253 + struct au_branch **brp;
26255 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26258 + sz = sizeof(*brp) * (sbinfo->si_bend + 1);
26259 + if (unlikely(!sz))
26260 + sz = sizeof(*brp);
26261 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
26263 + sbinfo->si_branch = brp;
26270 +/* ---------------------------------------------------------------------- */
26272 +unsigned int au_sigen_inc(struct super_block *sb)
26274 + unsigned int gen;
26275 + struct inode *inode;
26277 + SiMustWriteLock(sb);
26279 + gen = ++au_sbi(sb)->si_generation;
26280 + au_update_digen(sb->s_root);
26281 + inode = d_inode(sb->s_root);
26282 + au_update_iigen(inode, /*half*/0);
26283 + inode->i_version++;
26287 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26289 + aufs_bindex_t br_id;
26291 + struct au_sbinfo *sbinfo;
26293 + SiMustWriteLock(sb);
26295 + sbinfo = au_sbi(sb);
26296 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26297 + br_id = ++sbinfo->si_last_br_id;
26298 + AuDebugOn(br_id < 0);
26299 + if (br_id && au_br_index(sb, br_id) < 0)
26306 +/* ---------------------------------------------------------------------- */
26308 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26309 +int si_read_lock(struct super_block *sb, int flags)
26314 + if (au_ftest_lock(flags, FLUSH))
26315 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26317 + si_noflush_read_lock(sb);
26318 + err = au_plink_maint(sb, flags);
26319 + if (unlikely(err))
26320 + si_read_unlock(sb);
26325 +int si_write_lock(struct super_block *sb, int flags)
26329 + if (au_ftest_lock(flags, FLUSH))
26330 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26332 + si_noflush_write_lock(sb);
26333 + err = au_plink_maint(sb, flags);
26334 + if (unlikely(err))
26335 + si_write_unlock(sb);
26340 +/* dentry and super_block lock. call at entry point */
26341 +int aufs_read_lock(struct dentry *dentry, int flags)
26344 + struct super_block *sb;
26346 + sb = dentry->d_sb;
26347 + err = si_read_lock(sb, flags);
26348 + if (unlikely(err))
26351 + if (au_ftest_lock(flags, DW))
26352 + di_write_lock_child(dentry);
26354 + di_read_lock_child(dentry, flags);
26356 + if (au_ftest_lock(flags, GEN)) {
26357 + err = au_digen_test(dentry, au_sigen(sb));
26358 + AuDebugOn(!err && au_dbrange_test(dentry));
26359 + if (unlikely(err))
26360 + aufs_read_unlock(dentry, flags);
26367 +void aufs_read_unlock(struct dentry *dentry, int flags)
26369 + if (au_ftest_lock(flags, DW))
26370 + di_write_unlock(dentry);
26372 + di_read_unlock(dentry, flags);
26373 + si_read_unlock(dentry->d_sb);
26376 +void aufs_write_lock(struct dentry *dentry)
26378 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
26379 + di_write_lock_child(dentry);
26382 +void aufs_write_unlock(struct dentry *dentry)
26384 + di_write_unlock(dentry);
26385 + si_write_unlock(dentry->d_sb);
26388 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
26391 + unsigned int sigen;
26392 + struct super_block *sb;
26395 + err = si_read_lock(sb, flags);
26396 + if (unlikely(err))
26399 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIR));
26401 + if (au_ftest_lock(flags, GEN)) {
26402 + sigen = au_sigen(sb);
26403 + err = au_digen_test(d1, sigen);
26404 + AuDebugOn(!err && au_dbrange_test(d1));
26406 + err = au_digen_test(d2, sigen);
26407 + AuDebugOn(!err && au_dbrange_test(d2));
26409 + if (unlikely(err))
26410 + aufs_read_and_write_unlock2(d1, d2);
26417 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
26419 + di_write_unlock2(d1, d2);
26420 + si_read_unlock(d1->d_sb);
26423 +/* ---------------------------------------------------------------------- */
26425 +int si_pid_test_slow(struct super_block *sb)
26430 + p = radix_tree_lookup(&au_sbi(sb)->au_si_pid.tree, current->pid);
26431 + rcu_read_unlock();
26433 + return (long)!!p;
26436 +void si_pid_set_slow(struct super_block *sb)
26439 + struct au_sbinfo *sbinfo;
26441 + AuDebugOn(si_pid_test_slow(sb));
26443 + sbinfo = au_sbi(sb);
26444 + err = radix_tree_preload(GFP_NOFS | __GFP_NOFAIL);
26446 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26447 + err = radix_tree_insert(&sbinfo->au_si_pid.tree, current->pid,
26448 + /*any valid ptr*/sb);
26449 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26451 + radix_tree_preload_end();
26454 +void si_pid_clr_slow(struct super_block *sb)
26457 + struct au_sbinfo *sbinfo;
26459 + AuDebugOn(!si_pid_test_slow(sb));
26461 + sbinfo = au_sbi(sb);
26462 + spin_lock(&sbinfo->au_si_pid.tree_lock);
26463 + p = radix_tree_delete(&sbinfo->au_si_pid.tree, current->pid);
26464 + spin_unlock(&sbinfo->au_si_pid.tree_lock);
26466 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
26467 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
26468 +++ linux/fs/aufs/spl.h 2015-09-24 10:47:58.254719746 +0200
26471 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26473 + * This program, aufs is free software; you can redistribute it and/or modify
26474 + * it under the terms of the GNU General Public License as published by
26475 + * the Free Software Foundation; either version 2 of the License, or
26476 + * (at your option) any later version.
26478 + * This program is distributed in the hope that it will be useful,
26479 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26480 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26481 + * GNU General Public License for more details.
26483 + * You should have received a copy of the GNU General Public License
26484 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26488 + * simple list protected by a spinlock
26491 +#ifndef __AUFS_SPL_H__
26492 +#define __AUFS_SPL_H__
26496 +struct au_splhead {
26498 + struct list_head head;
26501 +static inline void au_spl_init(struct au_splhead *spl)
26503 + spin_lock_init(&spl->spin);
26504 + INIT_LIST_HEAD(&spl->head);
26507 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
26509 + spin_lock(&spl->spin);
26510 + list_add(list, &spl->head);
26511 + spin_unlock(&spl->spin);
26514 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
26516 + spin_lock(&spl->spin);
26518 + spin_unlock(&spl->spin);
26521 +static inline void au_spl_del_rcu(struct list_head *list,
26522 + struct au_splhead *spl)
26524 + spin_lock(&spl->spin);
26525 + list_del_rcu(list);
26526 + spin_unlock(&spl->spin);
26529 +/* ---------------------------------------------------------------------- */
26531 +struct au_sphlhead {
26533 + struct hlist_head head;
26536 +static inline void au_sphl_init(struct au_sphlhead *sphl)
26538 + spin_lock_init(&sphl->spin);
26539 + INIT_HLIST_HEAD(&sphl->head);
26542 +static inline void au_sphl_add(struct hlist_node *hlist,
26543 + struct au_sphlhead *sphl)
26545 + spin_lock(&sphl->spin);
26546 + hlist_add_head(hlist, &sphl->head);
26547 + spin_unlock(&sphl->spin);
26550 +static inline void au_sphl_del(struct hlist_node *hlist,
26551 + struct au_sphlhead *sphl)
26553 + spin_lock(&sphl->spin);
26554 + hlist_del(hlist);
26555 + spin_unlock(&sphl->spin);
26558 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
26559 + struct au_sphlhead *sphl)
26561 + spin_lock(&sphl->spin);
26562 + hlist_del_rcu(hlist);
26563 + spin_unlock(&sphl->spin);
26566 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
26568 + unsigned long cnt;
26569 + struct hlist_node *pos;
26572 + spin_lock(&sphl->spin);
26573 + hlist_for_each(pos, &sphl->head)
26575 + spin_unlock(&sphl->spin);
26579 +#endif /* __KERNEL__ */
26580 +#endif /* __AUFS_SPL_H__ */
26581 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
26582 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
26583 +++ linux/fs/aufs/super.c 2015-09-24 10:47:58.254719746 +0200
26586 + * Copyright (C) 2005-2015 Junjiro R. Okajima
26588 + * This program, aufs is free software; you can redistribute it and/or modify
26589 + * it under the terms of the GNU General Public License as published by
26590 + * the Free Software Foundation; either version 2 of the License, or
26591 + * (at your option) any later version.
26593 + * This program is distributed in the hope that it will be useful,
26594 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26595 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26596 + * GNU General Public License for more details.
26598 + * You should have received a copy of the GNU General Public License
26599 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26603 + * mount and super_block operations
26606 +#include <linux/mm.h>
26607 +#include <linux/seq_file.h>
26608 +#include <linux/statfs.h>
26609 +#include <linux/vmalloc.h>
26613 + * super_operations
26615 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
26617 + struct au_icntnr *c;
26619 + c = au_cache_alloc_icntnr();
26621 + au_icntnr_init(c);
26622 + c->vfs_inode.i_version = 1; /* sigen(sb); */
26623 + c->iinfo.ii_hinode = NULL;
26624 + return &c->vfs_inode;
26629 +static void aufs_destroy_inode_cb(struct rcu_head *head)
26631 + struct inode *inode = container_of(head, struct inode, i_rcu);
26633 + INIT_HLIST_HEAD(&inode->i_dentry);
26634 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
26637 +static void aufs_destroy_inode(struct inode *inode)
26639 + au_iinfo_fin(inode);
26640 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
26643 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
26645 + struct inode *inode;
26648 + inode = iget_locked(sb, ino);
26649 + if (unlikely(!inode)) {
26650 + inode = ERR_PTR(-ENOMEM);
26653 + if (!(inode->i_state & I_NEW))
26656 + err = au_xigen_new(inode);
26658 + err = au_iinfo_init(inode);
26660 + inode->i_version++;
26662 + iget_failed(inode);
26663 + inode = ERR_PTR(err);
26667 + /* never return NULL */
26668 + AuDebugOn(!inode);
26669 + AuTraceErrPtr(inode);
26673 +/* lock free root dinfo */
26674 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
26677 + aufs_bindex_t bindex, bend;
26678 + struct path path;
26679 + struct au_hdentry *hdp;
26680 + struct au_branch *br;
26681 + au_br_perm_str_t perm;
26684 + bend = au_sbend(sb);
26685 + hdp = au_di(sb->s_root)->di_hdentry;
26686 + for (bindex = 0; !err && bindex <= bend; bindex++) {
26687 + br = au_sbr(sb, bindex);
26688 + path.mnt = au_br_mnt(br);
26689 + path.dentry = hdp[bindex].hd_dentry;
26690 + err = au_seq_path(seq, &path);
26692 + au_optstr_br_perm(&perm, br->br_perm);
26693 + err = seq_printf(seq, "=%s", perm.a);
26697 + if (!err && bindex != bend)
26698 + err = seq_putc(seq, ':');
26704 +static void au_show_wbr_create(struct seq_file *m, int v,
26705 + struct au_sbinfo *sbinfo)
26709 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26711 + seq_puts(m, ",create=");
26712 + pat = au_optstr_wbr_create(v);
26714 + case AuWbrCreate_TDP:
26715 + case AuWbrCreate_RR:
26716 + case AuWbrCreate_MFS:
26717 + case AuWbrCreate_PMFS:
26718 + seq_puts(m, pat);
26720 + case AuWbrCreate_MFSV:
26721 + seq_printf(m, /*pat*/"mfs:%lu",
26722 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26725 + case AuWbrCreate_PMFSV:
26726 + seq_printf(m, /*pat*/"pmfs:%lu",
26727 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26730 + case AuWbrCreate_MFSRR:
26731 + seq_printf(m, /*pat*/"mfsrr:%llu",
26732 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26734 + case AuWbrCreate_MFSRRV:
26735 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
26736 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26737 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26740 + case AuWbrCreate_PMFSRR:
26741 + seq_printf(m, /*pat*/"pmfsrr:%llu",
26742 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26744 + case AuWbrCreate_PMFSRRV:
26745 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
26746 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26747 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26753 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
26755 +#ifdef CONFIG_SYSFS
26759 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
26760 + aufs_bindex_t bindex, brid;
26761 + struct qstr *name;
26763 + struct dentry *d, *h_root;
26764 + struct au_hdentry *hdp;
26766 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26769 + f = au_sbi(sb)->si_xib;
26773 + /* stop printing the default xino path on the first writable branch */
26775 + brid = au_xino_brid(sb);
26777 + bindex = au_br_index(sb, brid);
26778 + hdp = au_di(sb->s_root)->di_hdentry;
26779 + h_root = hdp[0 + bindex].hd_dentry;
26781 + d = f->f_path.dentry;
26782 + name = &d->d_name;
26783 + /* safe ->d_parent because the file is unlinked */
26784 + if (d->d_parent == h_root
26785 + && name->len == len
26786 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
26789 + seq_puts(seq, ",xino=");
26790 + err = au_xino_path(seq, f);
26797 +/* seq_file will re-call me in case of too long string */
26798 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
26801 + unsigned int mnt_flags, v;
26802 + struct super_block *sb;
26803 + struct au_sbinfo *sbinfo;
26805 +#define AuBool(name, str) do { \
26806 + v = au_opt_test(mnt_flags, name); \
26807 + if (v != au_opt_test(AuOpt_Def, name)) \
26808 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
26811 +#define AuStr(name, str) do { \
26812 + v = mnt_flags & AuOptMask_##name; \
26813 + if (v != (AuOpt_Def & AuOptMask_##name)) \
26814 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
26817 +#define AuUInt(name, str, val) do { \
26818 + if (val != AUFS_##name##_DEF) \
26819 + seq_printf(m, "," #str "=%u", val); \
26822 + sb = dentry->d_sb;
26823 + if (sb->s_flags & MS_POSIXACL)
26824 + seq_puts(m, ",acl");
26826 + /* lock free root dinfo */
26827 + si_noflush_read_lock(sb);
26828 + sbinfo = au_sbi(sb);
26829 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
26831 + mnt_flags = au_mntflags(sb);
26832 + if (au_opt_test(mnt_flags, XINO)) {
26833 + err = au_show_xino(m, sb);
26834 + if (unlikely(err))
26837 + seq_puts(m, ",noxino");
26839 + AuBool(TRUNC_XINO, trunc_xino);
26840 + AuStr(UDBA, udba);
26841 + AuBool(SHWH, shwh);
26842 + AuBool(PLINK, plink);
26843 + AuBool(DIO, dio);
26844 + AuBool(DIRPERM1, dirperm1);
26846 + v = sbinfo->si_wbr_create;
26847 + if (v != AuWbrCreate_Def)
26848 + au_show_wbr_create(m, v, sbinfo);
26850 + v = sbinfo->si_wbr_copyup;
26851 + if (v != AuWbrCopyup_Def)
26852 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
26854 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
26855 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
26856 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
26858 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
26860 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
26861 + AuUInt(RDCACHE, rdcache, v);
26863 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
26864 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
26866 + au_fhsm_show(m, sbinfo);
26868 + AuBool(SUM, sum);
26869 + /* AuBool(SUM_W, wsum); */
26870 + AuBool(WARN_PERM, warn_perm);
26871 + AuBool(VERBOSE, verbose);
26874 + /* be sure to print "br:" last */
26875 + if (!sysaufs_brs) {
26876 + seq_puts(m, ",br:");
26877 + au_show_brs(m, sb);
26879 + si_read_unlock(sb);
26887 +/* ---------------------------------------------------------------------- */
26889 +/* sum mode which returns the summation for statfs(2) */
26891 +static u64 au_add_till_max(u64 a, u64 b)
26899 + return ULLONG_MAX;
26902 +static u64 au_mul_till_max(u64 a, long mul)
26910 + return ULLONG_MAX;
26913 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
26916 + long bsize, factor;
26917 + u64 blocks, bfree, bavail, files, ffree;
26918 + aufs_bindex_t bend, bindex, i;
26919 + unsigned char shared;
26920 + struct path h_path;
26921 + struct super_block *h_sb;
26924 + bsize = LONG_MAX;
26930 + bend = au_sbend(sb);
26931 + for (bindex = 0; bindex <= bend; bindex++) {
26932 + h_path.mnt = au_sbr_mnt(sb, bindex);
26933 + h_sb = h_path.mnt->mnt_sb;
26935 + for (i = 0; !shared && i < bindex; i++)
26936 + shared = (au_sbr_sb(sb, i) == h_sb);
26940 + /* sb->s_root for NFS is unreliable */
26941 + h_path.dentry = h_path.mnt->mnt_root;
26942 + err = vfs_statfs(&h_path, buf);
26943 + if (unlikely(err))
26946 + if (bsize > buf->f_bsize) {
26948 + * we will reduce bsize, so we have to expand blocks
26949 + * etc. to match them again
26951 + factor = (bsize / buf->f_bsize);
26952 + blocks = au_mul_till_max(blocks, factor);
26953 + bfree = au_mul_till_max(bfree, factor);
26954 + bavail = au_mul_till_max(bavail, factor);
26955 + bsize = buf->f_bsize;
26958 + factor = (buf->f_bsize / bsize);
26959 + blocks = au_add_till_max(blocks,
26960 + au_mul_till_max(buf->f_blocks, factor));
26961 + bfree = au_add_till_max(bfree,
26962 + au_mul_till_max(buf->f_bfree, factor));
26963 + bavail = au_add_till_max(bavail,
26964 + au_mul_till_max(buf->f_bavail, factor));
26965 + files = au_add_till_max(files, buf->f_files);
26966 + ffree = au_add_till_max(ffree, buf->f_ffree);
26969 + buf->f_bsize = bsize;
26970 + buf->f_blocks = blocks;
26971 + buf->f_bfree = bfree;
26972 + buf->f_bavail = bavail;
26973 + buf->f_files = files;
26974 + buf->f_ffree = ffree;
26975 + buf->f_frsize = 0;
26981 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
26984 + struct path h_path;
26985 + struct super_block *sb;
26987 + /* lock free root dinfo */
26988 + sb = dentry->d_sb;
26989 + si_noflush_read_lock(sb);
26990 + if (!au_opt_test(au_mntflags(sb), SUM)) {
26991 + /* sb->s_root for NFS is unreliable */
26992 + h_path.mnt = au_sbr_mnt(sb, 0);
26993 + h_path.dentry = h_path.mnt->mnt_root;
26994 + err = vfs_statfs(&h_path, buf);
26996 + err = au_statfs_sum(sb, buf);
26997 + si_read_unlock(sb);
27000 + buf->f_type = AUFS_SUPER_MAGIC;
27001 + buf->f_namelen = AUFS_MAX_NAMELEN;
27002 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
27004 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27009 +/* ---------------------------------------------------------------------- */
27011 +static int aufs_sync_fs(struct super_block *sb, int wait)
27014 + aufs_bindex_t bend, bindex;
27015 + struct au_branch *br;
27016 + struct super_block *h_sb;
27019 + si_noflush_read_lock(sb);
27020 + bend = au_sbend(sb);
27021 + for (bindex = 0; bindex <= bend; bindex++) {
27022 + br = au_sbr(sb, bindex);
27023 + if (!au_br_writable(br->br_perm))
27026 + h_sb = au_sbr_sb(sb, bindex);
27027 + if (h_sb->s_op->sync_fs) {
27028 + e = h_sb->s_op->sync_fs(h_sb, wait);
27029 + if (unlikely(e && !err))
27031 + /* go on even if an error happens */
27034 + si_read_unlock(sb);
27039 +/* ---------------------------------------------------------------------- */
27041 +/* final actions when unmounting a file system */
27042 +static void aufs_put_super(struct super_block *sb)
27044 + struct au_sbinfo *sbinfo;
27046 + sbinfo = au_sbi(sb);
27050 + dbgaufs_si_fin(sbinfo);
27051 + kobject_put(&sbinfo->si_kobj);
27054 +/* ---------------------------------------------------------------------- */
27056 +void au_array_free(void *array)
27059 + if (!is_vmalloc_addr(array))
27066 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg)
27069 + unsigned long long n, sz;
27076 + if (*hint > ULLONG_MAX / sizeof(array)) {
27077 + array = ERR_PTR(-EMFILE);
27078 + pr_err("hint %llu\n", *hint);
27082 + sz = sizeof(array) * *hint;
27083 + array = kzalloc(sz, GFP_NOFS);
27084 + if (unlikely(!array))
27085 + array = vzalloc(sz);
27086 + if (unlikely(!array)) {
27087 + array = ERR_PTR(-ENOMEM);
27091 + n = cb(array, *hint, arg);
27092 + AuDebugOn(n > *hint);
27099 +static unsigned long long au_iarray_cb(void *a,
27100 + unsigned long long max __maybe_unused,
27103 + unsigned long long n;
27104 + struct inode **p, *inode;
27105 + struct list_head *head;
27110 + spin_lock(&inode_sb_list_lock);
27111 + list_for_each_entry(inode, head, i_sb_list) {
27112 + if (!is_bad_inode(inode)
27113 + && au_ii(inode)->ii_bstart >= 0) {
27114 + spin_lock(&inode->i_lock);
27115 + if (atomic_read(&inode->i_count)) {
27119 + AuDebugOn(n > max);
27121 + spin_unlock(&inode->i_lock);
27124 + spin_unlock(&inode_sb_list_lock);
27129 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27131 + *max = atomic_long_read(&au_sbi(sb)->si_ninodes);
27132 + return au_array_alloc(max, au_iarray_cb, &sb->s_inodes);
27135 +void au_iarray_free(struct inode **a, unsigned long long max)
27137 + unsigned long long ull;
27139 + for (ull = 0; ull < max; ull++)
27141 + au_array_free(a);
27144 +/* ---------------------------------------------------------------------- */
27147 + * refresh dentry and inode at remount time.
27149 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27150 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27151 + struct dentry *parent)
27155 + di_write_lock_child(dentry);
27156 + di_read_lock_parent(parent, AuLock_IR);
27157 + err = au_refresh_dentry(dentry, parent);
27158 + if (!err && dir_flags)
27159 + au_hn_reset(d_inode(dentry), dir_flags);
27160 + di_read_unlock(parent, AuLock_IR);
27161 + di_write_unlock(dentry);
27166 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27167 + struct au_sbinfo *sbinfo,
27168 + const unsigned int dir_flags)
27171 + struct dentry *parent;
27174 + parent = dget_parent(dentry);
27175 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27176 + if (d_really_is_positive(dentry)) {
27177 + if (!d_is_dir(dentry))
27178 + err = au_do_refresh(dentry, /*dir_flags*/0,
27181 + err = au_do_refresh(dentry, dir_flags, parent);
27182 + if (unlikely(err))
27183 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27186 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27187 + AuDbgDentry(dentry);
27195 +static int au_refresh_d(struct super_block *sb)
27197 + int err, i, j, ndentry, e;
27198 + unsigned int sigen;
27199 + struct au_dcsub_pages dpages;
27200 + struct au_dpage *dpage;
27201 + struct dentry **dentries, *d;
27202 + struct au_sbinfo *sbinfo;
27203 + struct dentry *root = sb->s_root;
27204 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
27206 + err = au_dpages_init(&dpages, GFP_NOFS);
27207 + if (unlikely(err))
27209 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27210 + if (unlikely(err))
27213 + sigen = au_sigen(sb);
27214 + sbinfo = au_sbi(sb);
27215 + for (i = 0; i < dpages.ndpage; i++) {
27216 + dpage = dpages.dpages + i;
27217 + dentries = dpage->dentries;
27218 + ndentry = dpage->ndentry;
27219 + for (j = 0; j < ndentry; j++) {
27221 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags);
27222 + if (unlikely(e && !err))
27224 + /* go on even err */
27229 + au_dpages_free(&dpages);
27234 +static int au_refresh_i(struct super_block *sb)
27237 + unsigned int sigen;
27238 + unsigned long long max, ull;
27239 + struct inode *inode, **array;
27241 + array = au_iarray_alloc(sb, &max);
27242 + err = PTR_ERR(array);
27243 + if (IS_ERR(array))
27247 + sigen = au_sigen(sb);
27248 + for (ull = 0; ull < max; ull++) {
27249 + inode = array[ull];
27250 + if (unlikely(!inode))
27252 + if (au_iigen(inode, NULL) != sigen) {
27253 + ii_write_lock_child(inode);
27254 + e = au_refresh_hinode_self(inode);
27255 + ii_write_unlock(inode);
27256 + if (unlikely(e)) {
27257 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27260 + /* go on even if err */
27265 + au_iarray_free(array, max);
27271 +static void au_remount_refresh(struct super_block *sb)
27274 + unsigned int udba;
27275 + aufs_bindex_t bindex, bend;
27276 + struct dentry *root;
27277 + struct inode *inode;
27278 + struct au_branch *br;
27280 + au_sigen_inc(sb);
27281 + au_fclr_si(au_sbi(sb), FAILED_REFRESH_DIR);
27283 + root = sb->s_root;
27284 + DiMustNoWaiters(root);
27285 + inode = d_inode(root);
27286 + IiMustNoWaiters(inode);
27288 + udba = au_opt_udba(sb);
27289 + bend = au_sbend(sb);
27290 + for (bindex = 0; bindex <= bend; bindex++) {
27291 + br = au_sbr(sb, bindex);
27292 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27293 + if (unlikely(err))
27294 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27296 + /* go on even if err */
27298 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27300 + di_write_unlock(root);
27301 + err = au_refresh_d(sb);
27302 + e = au_refresh_i(sb);
27303 + if (unlikely(e && !err))
27305 + /* aufs_write_lock() calls ..._child() */
27306 + di_write_lock_child(root);
27308 + au_cpup_attr_all(inode, /*force*/1);
27310 + if (unlikely(err))
27311 + AuIOErr("refresh failed, ignored, %d\n", err);
27314 +/* stop extra interpretation of errno in mount(8), and strange error messages */
27315 +static int cvt_err(int err)
27329 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
27332 + unsigned int mntflags;
27333 + struct au_opts opts;
27334 + struct dentry *root;
27335 + struct inode *inode;
27336 + struct au_sbinfo *sbinfo;
27339 + root = sb->s_root;
27340 + if (!data || !*data) {
27341 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27343 + di_write_lock_child(root);
27344 + err = au_opts_verify(sb, *flags, /*pending*/0);
27345 + aufs_write_unlock(root);
27351 + memset(&opts, 0, sizeof(opts));
27352 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27353 + if (unlikely(!opts.opt))
27355 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27356 + opts.flags = AuOpts_REMOUNT;
27357 + opts.sb_flags = *flags;
27359 + /* parse it before aufs lock */
27360 + err = au_opts_parse(sb, data, &opts);
27361 + if (unlikely(err))
27364 + sbinfo = au_sbi(sb);
27365 + inode = d_inode(root);
27366 + mutex_lock(&inode->i_mutex);
27367 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27368 + if (unlikely(err))
27370 + di_write_lock_child(root);
27372 + /* au_opts_remount() may return an error */
27373 + err = au_opts_remount(sb, &opts);
27374 + au_opts_free(&opts);
27376 + if (au_ftest_opts(opts.flags, REFRESH))
27377 + au_remount_refresh(sb);
27379 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
27380 + mntflags = au_mntflags(sb);
27381 + do_dx = !!au_opt_test(mntflags, DIO);
27382 + au_dy_arefresh(do_dx);
27385 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
27386 + aufs_write_unlock(root);
27389 + mutex_unlock(&inode->i_mutex);
27391 + free_page((unsigned long)opts.opt);
27393 + err = cvt_err(err);
27398 +static const struct super_operations aufs_sop = {
27399 + .alloc_inode = aufs_alloc_inode,
27400 + .destroy_inode = aufs_destroy_inode,
27401 + /* always deleting, no clearing */
27402 + .drop_inode = generic_delete_inode,
27403 + .show_options = aufs_show_options,
27404 + .statfs = aufs_statfs,
27405 + .put_super = aufs_put_super,
27406 + .sync_fs = aufs_sync_fs,
27407 + .remount_fs = aufs_remount_fs
27410 +/* ---------------------------------------------------------------------- */
27412 +static int alloc_root(struct super_block *sb)
27415 + struct inode *inode;
27416 + struct dentry *root;
27419 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
27420 + err = PTR_ERR(inode);
27421 + if (IS_ERR(inode))
27424 + inode->i_op = &aufs_dir_iop;
27425 + inode->i_fop = &aufs_dir_fop;
27426 + inode->i_mode = S_IFDIR;
27427 + set_nlink(inode, 2);
27428 + unlock_new_inode(inode);
27430 + root = d_make_root(inode);
27431 + if (unlikely(!root))
27433 + err = PTR_ERR(root);
27434 + if (IS_ERR(root))
27437 + err = au_di_init(root);
27439 + sb->s_root = root;
27440 + return 0; /* success */
27448 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
27449 + int silent __maybe_unused)
27452 + struct au_opts opts;
27453 + struct dentry *root;
27454 + struct inode *inode;
27455 + char *arg = raw_data;
27457 + if (unlikely(!arg || !*arg)) {
27459 + pr_err("no arg\n");
27464 + memset(&opts, 0, sizeof(opts));
27465 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27466 + if (unlikely(!opts.opt))
27468 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27469 + opts.sb_flags = sb->s_flags;
27471 + err = au_si_alloc(sb);
27472 + if (unlikely(err))
27475 + /* all timestamps always follow the ones on the branch */
27476 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
27477 + sb->s_op = &aufs_sop;
27478 + sb->s_d_op = &aufs_dop;
27479 + sb->s_magic = AUFS_SUPER_MAGIC;
27480 + sb->s_maxbytes = 0;
27481 + sb->s_stack_depth = 1;
27482 + au_export_init(sb);
27483 + /* au_xattr_init(sb); */
27485 + err = alloc_root(sb);
27486 + if (unlikely(err)) {
27487 + si_write_unlock(sb);
27490 + root = sb->s_root;
27491 + inode = d_inode(root);
27494 + * actually we can parse options regardless aufs lock here.
27495 + * but at remount time, parsing must be done before aufs lock.
27496 + * so we follow the same rule.
27498 + ii_write_lock_parent(inode);
27499 + aufs_write_unlock(root);
27500 + err = au_opts_parse(sb, arg, &opts);
27501 + if (unlikely(err))
27504 + /* lock vfs_inode first, then aufs. */
27505 + mutex_lock(&inode->i_mutex);
27506 + aufs_write_lock(root);
27507 + err = au_opts_mount(sb, &opts);
27508 + au_opts_free(&opts);
27509 + aufs_write_unlock(root);
27510 + mutex_unlock(&inode->i_mutex);
27512 + goto out_opts; /* success */
27516 + sb->s_root = NULL;
27518 + dbgaufs_si_fin(au_sbi(sb));
27519 + kobject_put(&au_sbi(sb)->si_kobj);
27520 + sb->s_fs_info = NULL;
27522 + free_page((unsigned long)opts.opt);
27525 + err = cvt_err(err);
27530 +/* ---------------------------------------------------------------------- */
27532 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
27533 + const char *dev_name __maybe_unused,
27536 + struct dentry *root;
27537 + struct super_block *sb;
27539 + /* all timestamps always follow the ones on the branch */
27540 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
27541 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
27542 + if (IS_ERR(root))
27546 + si_write_lock(sb, !AuLock_FLUSH);
27547 + sysaufs_brs_add(sb, 0);
27548 + si_write_unlock(sb);
27549 + au_sbilist_add(sb);
27555 +static void aufs_kill_sb(struct super_block *sb)
27557 + struct au_sbinfo *sbinfo;
27559 + sbinfo = au_sbi(sb);
27561 + au_sbilist_del(sb);
27562 + aufs_write_lock(sb->s_root);
27564 + if (sbinfo->si_wbr_create_ops->fin)
27565 + sbinfo->si_wbr_create_ops->fin(sb);
27566 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
27567 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
27568 + au_remount_refresh(sb);
27570 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27571 + au_plink_put(sb, /*verbose*/1);
27573 + sbinfo->si_sb = NULL;
27574 + aufs_write_unlock(sb->s_root);
27575 + au_nwt_flush(&sbinfo->si_nowait);
27577 + kill_anon_super(sb);
27580 +struct file_system_type aufs_fs_type = {
27581 + .name = AUFS_FSTYPE,
27582 + /* a race between rename and others */
27583 + .fs_flags = FS_RENAME_DOES_D_MOVE,
27584 + .mount = aufs_mount,
27585 + .kill_sb = aufs_kill_sb,
27586 + /* no need to __module_get() and module_put(). */
27587 + .owner = THIS_MODULE,
27589 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
27590 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
27591 +++ linux/fs/aufs/super.h 2015-09-24 10:47:58.254719746 +0200
27594 + * Copyright (C) 2005-2015 Junjiro R. Okajima
27596 + * This program, aufs is free software; you can redistribute it and/or modify
27597 + * it under the terms of the GNU General Public License as published by
27598 + * the Free Software Foundation; either version 2 of the License, or
27599 + * (at your option) any later version.
27601 + * This program is distributed in the hope that it will be useful,
27602 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27603 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27604 + * GNU General Public License for more details.
27606 + * You should have received a copy of the GNU General Public License
27607 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27611 + * super_block operations
27614 +#ifndef __AUFS_SUPER_H__
27615 +#define __AUFS_SUPER_H__
27619 +#include <linux/fs.h>
27620 +#include <linux/kobject.h>
27621 +#include "rwsem.h"
27625 +/* policies to select one among multiple writable branches */
27626 +struct au_wbr_copyup_operations {
27627 + int (*copyup)(struct dentry *dentry);
27630 +#define AuWbr_DIR 1 /* target is a dir */
27631 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
27633 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
27634 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
27635 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
27637 +struct au_wbr_create_operations {
27638 + int (*create)(struct dentry *dentry, unsigned int flags);
27639 + int (*init)(struct super_block *sb);
27640 + int (*fin)(struct super_block *sb);
27643 +struct au_wbr_mfs {
27644 + struct mutex mfs_lock; /* protect this structure */
27645 + unsigned long mfs_jiffy;
27646 + unsigned long mfs_expire;
27647 + aufs_bindex_t mfs_bindex;
27649 + unsigned long long mfsrr_bytes;
27650 + unsigned long long mfsrr_watermark;
27653 +struct pseudo_link {
27655 + struct hlist_node hlist;
27656 + struct rcu_head rcu;
27658 + struct inode *inode;
27661 +#define AuPlink_NHASH 100
27662 +static inline int au_plink_hash(ino_t ino)
27664 + return ino % AuPlink_NHASH;
27667 +/* File-based Hierarchical Storage Management */
27669 +#ifdef CONFIG_AUFS_FHSM
27670 + /* allow only one process who can receive the notification */
27671 + spinlock_t fhsm_spin;
27673 + wait_queue_head_t fhsm_wqh;
27674 + atomic_t fhsm_readable;
27676 + /* these are protected by si_rwsem */
27677 + unsigned long fhsm_expire;
27678 + aufs_bindex_t fhsm_bottom;
27683 +struct au_sbinfo {
27684 + /* nowait tasks in the system-wide workqueue */
27685 + struct au_nowait_tasks si_nowait;
27688 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
27689 + * rwsem for au_sbinfo is necessary.
27691 + struct au_rwsem si_rwsem;
27693 + /* prevent recursive locking in deleting inode */
27695 + unsigned long *bitmap;
27696 + spinlock_t tree_lock;
27697 + struct radix_tree_root tree;
27701 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
27704 + atomic_long_t si_ninodes, si_nfiles;
27706 + /* branch management */
27707 + unsigned int si_generation;
27709 + /* see AuSi_ flags */
27710 + unsigned char au_si_status;
27712 + aufs_bindex_t si_bend;
27714 + /* dirty trick to keep br_id plus */
27715 + unsigned int si_last_br_id :
27716 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
27717 + struct au_branch **si_branch;
27719 + /* policy to select a writable branch */
27720 + unsigned char si_wbr_copyup;
27721 + unsigned char si_wbr_create;
27722 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
27723 + struct au_wbr_create_operations *si_wbr_create_ops;
27725 + /* round robin */
27726 + atomic_t si_wbr_rr_next;
27728 + /* most free space */
27729 + struct au_wbr_mfs si_wbr_mfs;
27731 + /* File-based Hierarchical Storage Management */
27732 + struct au_fhsm si_fhsm;
27734 + /* mount flags */
27735 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
27736 + unsigned int si_mntflags;
27738 + /* symlink to follow_link() and put_link() */
27739 + struct au_sphlhead si_symlink;
27741 + /* external inode number (bitmap and translation table) */
27742 + vfs_readf_t si_xread;
27743 + vfs_writef_t si_xwrite;
27744 + struct file *si_xib;
27745 + struct mutex si_xib_mtx; /* protect xib members */
27746 + unsigned long *si_xib_buf;
27747 + unsigned long si_xib_last_pindex;
27748 + int si_xib_next_bit;
27749 + aufs_bindex_t si_xino_brid;
27750 + unsigned long si_xino_jiffy;
27751 + unsigned long si_xino_expire;
27752 + /* reserved for future use */
27753 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
27755 +#ifdef CONFIG_AUFS_EXPORT
27756 + /* i_generation */
27757 + struct file *si_xigen;
27758 + atomic_t si_xigen_next;
27761 + /* dirty trick to suppoer atomic_open */
27762 + struct au_sphlhead si_aopen;
27764 + /* vdir parameters */
27765 + unsigned long si_rdcache; /* max cache time in jiffies */
27766 + unsigned int si_rdblk; /* deblk size */
27767 + unsigned int si_rdhash; /* hash size */
27770 + * If the number of whiteouts are larger than si_dirwh, leave all of
27771 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
27772 + * future fsck.aufs or kernel thread will remove them later.
27773 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
27775 + unsigned int si_dirwh;
27777 + /* pseudo_link list */
27778 + struct au_sphlhead si_plink[AuPlink_NHASH];
27779 + wait_queue_head_t si_plink_wq;
27780 + spinlock_t si_plink_maint_lock;
27781 + pid_t si_plink_maint_pid;
27784 + struct au_sphlhead si_files;
27787 + * sysfs and lifetime management.
27788 + * this is not a small structure and it may be a waste of memory in case
27789 + * of sysfs is disabled, particulary when many aufs-es are mounted.
27790 + * but using sysfs is majority.
27792 + struct kobject si_kobj;
27793 +#ifdef CONFIG_DEBUG_FS
27794 + struct dentry *si_dbgaufs;
27795 + struct dentry *si_dbgaufs_plink;
27796 + struct dentry *si_dbgaufs_xib;
27797 +#ifdef CONFIG_AUFS_EXPORT
27798 + struct dentry *si_dbgaufs_xigen;
27802 +#ifdef CONFIG_AUFS_SBILIST
27803 + struct list_head si_list;
27806 + /* dirty, necessary for unmounting, sysfs and sysrq */
27807 + struct super_block *si_sb;
27810 +/* sbinfo status flags */
27812 + * set true when refresh_dirs() failed at remount time.
27813 + * then try refreshing dirs at access time again.
27814 + * if it is false, refreshing dirs at access time is unnecesary
27816 +#define AuSi_FAILED_REFRESH_DIR 1
27818 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
27820 +#ifndef CONFIG_AUFS_FHSM
27822 +#define AuSi_FHSM 0
27825 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
27826 + unsigned int flag)
27828 + AuRwMustAnyLock(&sbi->si_rwsem);
27829 + return sbi->au_si_status & flag;
27831 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
27832 +#define au_fset_si(sbinfo, name) do { \
27833 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27834 + (sbinfo)->au_si_status |= AuSi_##name; \
27836 +#define au_fclr_si(sbinfo, name) do { \
27837 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
27838 + (sbinfo)->au_si_status &= ~AuSi_##name; \
27841 +/* ---------------------------------------------------------------------- */
27843 +/* policy to select one among writable branches */
27844 +#define AuWbrCopyup(sbinfo, ...) \
27845 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
27846 +#define AuWbrCreate(sbinfo, ...) \
27847 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
27849 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
27850 +#define AuLock_DW 1 /* write-lock dentry */
27851 +#define AuLock_IR (1 << 1) /* read-lock inode */
27852 +#define AuLock_IW (1 << 2) /* write-lock inode */
27853 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
27854 +#define AuLock_DIR (1 << 4) /* target is a dir */
27855 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
27856 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
27857 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
27858 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
27859 +#define au_fset_lock(flags, name) \
27860 + do { (flags) |= AuLock_##name; } while (0)
27861 +#define au_fclr_lock(flags, name) \
27862 + do { (flags) &= ~AuLock_##name; } while (0)
27864 +/* ---------------------------------------------------------------------- */
27867 +extern struct file_system_type aufs_fs_type;
27868 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
27869 +typedef unsigned long long (*au_arraycb_t)(void *array, unsigned long long max,
27871 +void au_array_free(void *array);
27872 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, void *arg);
27873 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
27874 +void au_iarray_free(struct inode **a, unsigned long long max);
27877 +void au_si_free(struct kobject *kobj);
27878 +int au_si_alloc(struct super_block *sb);
27879 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
27881 +unsigned int au_sigen_inc(struct super_block *sb);
27882 +aufs_bindex_t au_new_br_id(struct super_block *sb);
27884 +int si_read_lock(struct super_block *sb, int flags);
27885 +int si_write_lock(struct super_block *sb, int flags);
27886 +int aufs_read_lock(struct dentry *dentry, int flags);
27887 +void aufs_read_unlock(struct dentry *dentry, int flags);
27888 +void aufs_write_lock(struct dentry *dentry);
27889 +void aufs_write_unlock(struct dentry *dentry);
27890 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
27891 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
27893 +int si_pid_test_slow(struct super_block *sb);
27894 +void si_pid_set_slow(struct super_block *sb);
27895 +void si_pid_clr_slow(struct super_block *sb);
27897 +/* wbr_policy.c */
27898 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
27899 +extern struct au_wbr_create_operations au_wbr_create_ops[];
27900 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
27901 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
27902 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart);
27905 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
27907 +#ifdef CONFIG_AUFS_FHSM
27910 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
27914 + spin_lock(&fhsm->fhsm_spin);
27915 + pid = fhsm->fhsm_pid;
27916 + spin_unlock(&fhsm->fhsm_spin);
27921 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
27922 +void au_fhsm_wrote_all(struct super_block *sb, int force);
27923 +int au_fhsm_fd(struct super_block *sb, int oflags);
27924 +int au_fhsm_br_alloc(struct au_branch *br);
27925 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
27926 +void au_fhsm_fin(struct super_block *sb);
27927 +void au_fhsm_init(struct au_sbinfo *sbinfo);
27928 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
27929 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
27931 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
27933 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
27934 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
27935 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
27936 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
27937 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
27938 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
27939 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
27940 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
27941 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
27944 +/* ---------------------------------------------------------------------- */
27946 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
27948 + return sb->s_fs_info;
27951 +/* ---------------------------------------------------------------------- */
27953 +#ifdef CONFIG_AUFS_EXPORT
27954 +int au_test_nfsd(void);
27955 +void au_export_init(struct super_block *sb);
27956 +void au_xigen_inc(struct inode *inode);
27957 +int au_xigen_new(struct inode *inode);
27958 +int au_xigen_set(struct super_block *sb, struct file *base);
27959 +void au_xigen_clr(struct super_block *sb);
27961 +static inline int au_busy_or_stale(void)
27963 + if (!au_test_nfsd())
27968 +AuStubInt0(au_test_nfsd, void)
27969 +AuStubVoid(au_export_init, struct super_block *sb)
27970 +AuStubVoid(au_xigen_inc, struct inode *inode)
27971 +AuStubInt0(au_xigen_new, struct inode *inode)
27972 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
27973 +AuStubVoid(au_xigen_clr, struct super_block *sb)
27974 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
27975 +#endif /* CONFIG_AUFS_EXPORT */
27977 +/* ---------------------------------------------------------------------- */
27979 +#ifdef CONFIG_AUFS_SBILIST
27981 +extern struct au_splhead au_sbilist;
27983 +static inline void au_sbilist_init(void)
27985 + au_spl_init(&au_sbilist);
27988 +static inline void au_sbilist_add(struct super_block *sb)
27990 + au_spl_add(&au_sbi(sb)->si_list, &au_sbilist);
27993 +static inline void au_sbilist_del(struct super_block *sb)
27995 + au_spl_del(&au_sbi(sb)->si_list, &au_sbilist);
27998 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
27999 +static inline void au_sbilist_lock(void)
28001 + spin_lock(&au_sbilist.spin);
28004 +static inline void au_sbilist_unlock(void)
28006 + spin_unlock(&au_sbilist.spin);
28008 +#define AuGFP_SBILIST GFP_ATOMIC
28010 +AuStubVoid(au_sbilist_lock, void)
28011 +AuStubVoid(au_sbilist_unlock, void)
28012 +#define AuGFP_SBILIST GFP_NOFS
28013 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28015 +AuStubVoid(au_sbilist_init, void)
28016 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28017 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28018 +AuStubVoid(au_sbilist_lock, void)
28019 +AuStubVoid(au_sbilist_unlock, void)
28020 +#define AuGFP_SBILIST GFP_NOFS
28023 +/* ---------------------------------------------------------------------- */
28025 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28028 + * This function is a dynamic '__init' function actually,
28029 + * so the tiny check for si_rwsem is unnecessary.
28031 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28032 +#ifdef CONFIG_DEBUG_FS
28033 + sbinfo->si_dbgaufs = NULL;
28034 + sbinfo->si_dbgaufs_plink = NULL;
28035 + sbinfo->si_dbgaufs_xib = NULL;
28036 +#ifdef CONFIG_AUFS_EXPORT
28037 + sbinfo->si_dbgaufs_xigen = NULL;
28042 +/* ---------------------------------------------------------------------- */
28044 +static inline pid_t si_pid_bit(void)
28046 + /* the origin of pid is 1, but the bitmap's is 0 */
28047 + return current->pid - 1;
28050 +static inline int si_pid_test(struct super_block *sb)
28054 + bit = si_pid_bit();
28055 + if (bit < PID_MAX_DEFAULT)
28056 + return test_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28057 + return si_pid_test_slow(sb);
28060 +static inline void si_pid_set(struct super_block *sb)
28064 + bit = si_pid_bit();
28065 + if (bit < PID_MAX_DEFAULT) {
28066 + AuDebugOn(test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
28067 + set_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28070 + si_pid_set_slow(sb);
28073 +static inline void si_pid_clr(struct super_block *sb)
28077 + bit = si_pid_bit();
28078 + if (bit < PID_MAX_DEFAULT) {
28079 + AuDebugOn(!test_bit(bit, au_sbi(sb)->au_si_pid.bitmap));
28080 + clear_bit(bit, au_sbi(sb)->au_si_pid.bitmap);
28083 + si_pid_clr_slow(sb);
28086 +/* ---------------------------------------------------------------------- */
28088 +/* lock superblock. mainly for entry point functions */
28090 + * __si_read_lock, __si_write_lock,
28091 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28093 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28095 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28096 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28097 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28099 +static inline void si_noflush_read_lock(struct super_block *sb)
28101 + __si_read_lock(sb);
28105 +static inline int si_noflush_read_trylock(struct super_block *sb)
28109 + locked = __si_read_trylock(sb);
28115 +static inline void si_noflush_write_lock(struct super_block *sb)
28117 + __si_write_lock(sb);
28121 +static inline int si_noflush_write_trylock(struct super_block *sb)
28125 + locked = __si_write_trylock(sb);
28131 +#if 0 /* reserved */
28132 +static inline int si_read_trylock(struct super_block *sb, int flags)
28134 + if (au_ftest_lock(flags, FLUSH))
28135 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28136 + return si_noflush_read_trylock(sb);
28140 +static inline void si_read_unlock(struct super_block *sb)
28143 + __si_read_unlock(sb);
28146 +#if 0 /* reserved */
28147 +static inline int si_write_trylock(struct super_block *sb, int flags)
28149 + if (au_ftest_lock(flags, FLUSH))
28150 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28151 + return si_noflush_write_trylock(sb);
28155 +static inline void si_write_unlock(struct super_block *sb)
28158 + __si_write_unlock(sb);
28161 +#if 0 /* reserved */
28162 +static inline void si_downgrade_lock(struct super_block *sb)
28164 + __si_downgrade_lock(sb);
28168 +/* ---------------------------------------------------------------------- */
28170 +static inline aufs_bindex_t au_sbend(struct super_block *sb)
28172 + SiMustAnyLock(sb);
28173 + return au_sbi(sb)->si_bend;
28176 +static inline unsigned int au_mntflags(struct super_block *sb)
28178 + SiMustAnyLock(sb);
28179 + return au_sbi(sb)->si_mntflags;
28182 +static inline unsigned int au_sigen(struct super_block *sb)
28184 + SiMustAnyLock(sb);
28185 + return au_sbi(sb)->si_generation;
28188 +static inline void au_ninodes_inc(struct super_block *sb)
28190 + atomic_long_inc(&au_sbi(sb)->si_ninodes);
28193 +static inline void au_ninodes_dec(struct super_block *sb)
28195 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_ninodes));
28196 + atomic_long_dec(&au_sbi(sb)->si_ninodes);
28199 +static inline void au_nfiles_inc(struct super_block *sb)
28201 + atomic_long_inc(&au_sbi(sb)->si_nfiles);
28204 +static inline void au_nfiles_dec(struct super_block *sb)
28206 + AuDebugOn(!atomic_long_read(&au_sbi(sb)->si_nfiles));
28207 + atomic_long_dec(&au_sbi(sb)->si_nfiles);
28210 +static inline struct au_branch *au_sbr(struct super_block *sb,
28211 + aufs_bindex_t bindex)
28213 + SiMustAnyLock(sb);
28214 + return au_sbi(sb)->si_branch[0 + bindex];
28217 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28219 + SiMustWriteLock(sb);
28220 + au_sbi(sb)->si_xino_brid = brid;
28223 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28225 + SiMustAnyLock(sb);
28226 + return au_sbi(sb)->si_xino_brid;
28229 +#endif /* __KERNEL__ */
28230 +#endif /* __AUFS_SUPER_H__ */
28231 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28232 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28233 +++ linux/fs/aufs/sysaufs.c 2015-09-24 10:47:58.254719746 +0200
28236 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28238 + * This program, aufs is free software; you can redistribute it and/or modify
28239 + * it under the terms of the GNU General Public License as published by
28240 + * the Free Software Foundation; either version 2 of the License, or
28241 + * (at your option) any later version.
28243 + * This program is distributed in the hope that it will be useful,
28244 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28245 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28246 + * GNU General Public License for more details.
28248 + * You should have received a copy of the GNU General Public License
28249 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28253 + * sysfs interface and lifetime management
28254 + * they are necessary regardless sysfs is disabled.
28257 +#include <linux/random.h>
28260 +unsigned long sysaufs_si_mask;
28261 +struct kset *sysaufs_kset;
28263 +#define AuSiAttr(_name) { \
28264 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28265 + .show = sysaufs_si_##_name, \
28268 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28269 +struct attribute *sysaufs_si_attrs[] = {
28270 + &sysaufs_si_attr_xi_path.attr,
28274 +static const struct sysfs_ops au_sbi_ops = {
28275 + .show = sysaufs_si_show
28278 +static struct kobj_type au_sbi_ktype = {
28279 + .release = au_si_free,
28280 + .sysfs_ops = &au_sbi_ops,
28281 + .default_attrs = sysaufs_si_attrs
28284 +/* ---------------------------------------------------------------------- */
28286 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28290 + sbinfo->si_kobj.kset = sysaufs_kset;
28291 + /* cf. sysaufs_name() */
28292 + err = kobject_init_and_add
28293 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28294 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28296 + dbgaufs_si_null(sbinfo);
28298 + err = dbgaufs_si_init(sbinfo);
28299 + if (unlikely(err))
28300 + kobject_put(&sbinfo->si_kobj);
28305 +void sysaufs_fin(void)
28308 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28309 + kset_unregister(sysaufs_kset);
28312 +int __init sysaufs_init(void)
28317 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
28318 + } while (!sysaufs_si_mask);
28321 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
28322 + if (unlikely(!sysaufs_kset))
28324 + err = PTR_ERR(sysaufs_kset);
28325 + if (IS_ERR(sysaufs_kset))
28327 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28328 + if (unlikely(err)) {
28329 + kset_unregister(sysaufs_kset);
28333 + err = dbgaufs_init();
28334 + if (unlikely(err))
28339 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
28340 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
28341 +++ linux/fs/aufs/sysaufs.h 2015-09-24 10:47:58.254719746 +0200
28344 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28346 + * This program, aufs is free software; you can redistribute it and/or modify
28347 + * it under the terms of the GNU General Public License as published by
28348 + * the Free Software Foundation; either version 2 of the License, or
28349 + * (at your option) any later version.
28351 + * This program is distributed in the hope that it will be useful,
28352 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28353 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28354 + * GNU General Public License for more details.
28356 + * You should have received a copy of the GNU General Public License
28357 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28361 + * sysfs interface and mount lifetime management
28364 +#ifndef __SYSAUFS_H__
28365 +#define __SYSAUFS_H__
28369 +#include <linux/sysfs.h>
28370 +#include "module.h"
28372 +struct super_block;
28375 +struct sysaufs_si_attr {
28376 + struct attribute attr;
28377 + int (*show)(struct seq_file *seq, struct super_block *sb);
28380 +/* ---------------------------------------------------------------------- */
28383 +extern unsigned long sysaufs_si_mask;
28384 +extern struct kset *sysaufs_kset;
28385 +extern struct attribute *sysaufs_si_attrs[];
28386 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
28387 +int __init sysaufs_init(void);
28388 +void sysaufs_fin(void);
28390 +/* ---------------------------------------------------------------------- */
28392 +/* some people doesn't like to show a pointer in kernel */
28393 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
28395 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
28398 +#define SysaufsSiNamePrefix "si_"
28399 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
28400 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
28402 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
28403 + sysaufs_si_id(sbinfo));
28407 +#ifdef CONFIG_SYSFS
28409 +extern struct attribute_group *sysaufs_attr_group;
28411 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
28412 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28414 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
28415 +#ifdef CONFIG_COMPAT
28416 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
28419 +void sysaufs_br_init(struct au_branch *br);
28420 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
28421 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
28423 +#define sysaufs_brs_init() do {} while (0)
28426 +#define sysaufs_attr_group NULL
28428 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
28429 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
28430 + struct attribute *attr, char *buf)
28431 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
28432 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
28433 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
28435 +static inline void sysaufs_brs_init(void)
28440 +#endif /* CONFIG_SYSFS */
28442 +#endif /* __KERNEL__ */
28443 +#endif /* __SYSAUFS_H__ */
28444 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
28445 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
28446 +++ linux/fs/aufs/sysfs.c 2015-09-24 10:47:58.254719746 +0200
28449 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28451 + * This program, aufs is free software; you can redistribute it and/or modify
28452 + * it under the terms of the GNU General Public License as published by
28453 + * the Free Software Foundation; either version 2 of the License, or
28454 + * (at your option) any later version.
28456 + * This program is distributed in the hope that it will be useful,
28457 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28458 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28459 + * GNU General Public License for more details.
28461 + * You should have received a copy of the GNU General Public License
28462 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28466 + * sysfs interface
28469 +#include <linux/compat.h>
28470 +#include <linux/seq_file.h>
28473 +#ifdef CONFIG_AUFS_FS_MODULE
28474 +/* this entry violates the "one line per file" policy of sysfs */
28475 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
28479 + static char *conf =
28480 +/* this file is generated at compiling */
28481 +#include "conf.str"
28484 + err = snprintf(buf, PAGE_SIZE, conf);
28485 + if (unlikely(err >= PAGE_SIZE))
28490 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
28493 +static struct attribute *au_attr[] = {
28494 +#ifdef CONFIG_AUFS_FS_MODULE
28495 + &au_config_attr.attr,
28497 + NULL, /* need to NULL terminate the list of attributes */
28500 +static struct attribute_group sysaufs_attr_group_body = {
28504 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
28506 +/* ---------------------------------------------------------------------- */
28508 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
28512 + SiMustAnyLock(sb);
28515 + if (au_opt_test(au_mntflags(sb), XINO)) {
28516 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
28517 + seq_putc(seq, '\n');
28523 + * the lifetime of branch is independent from the entry under sysfs.
28524 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
28527 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
28528 + aufs_bindex_t bindex, int idx)
28531 + struct path path;
28532 + struct dentry *root;
28533 + struct au_branch *br;
28534 + au_br_perm_str_t perm;
28536 + AuDbg("b%d\n", bindex);
28539 + root = sb->s_root;
28540 + di_read_lock_parent(root, !AuLock_IR);
28541 + br = au_sbr(sb, bindex);
28544 + case AuBrSysfs_BR:
28545 + path.mnt = au_br_mnt(br);
28546 + path.dentry = au_h_dptr(root, bindex);
28547 + au_seq_path(seq, &path);
28548 + au_optstr_br_perm(&perm, br->br_perm);
28549 + err = seq_printf(seq, "=%s\n", perm.a);
28551 + case AuBrSysfs_BRID:
28552 + err = seq_printf(seq, "%d\n", br->br_id);
28555 + di_read_unlock(root, !AuLock_IR);
28562 +/* ---------------------------------------------------------------------- */
28564 +static struct seq_file *au_seq(char *p, ssize_t len)
28566 + struct seq_file *seq;
28568 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
28570 + /* mutex_init(&seq.lock); */
28573 + return seq; /* success */
28576 + seq = ERR_PTR(-ENOMEM);
28580 +#define SysaufsBr_PREFIX "br"
28581 +#define SysaufsBrid_PREFIX "brid"
28583 +/* todo: file size may exceed PAGE_SIZE */
28584 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28590 + aufs_bindex_t bend;
28591 + struct au_sbinfo *sbinfo;
28592 + struct super_block *sb;
28593 + struct seq_file *seq;
28595 + struct attribute **cattr;
28597 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28598 + sb = sbinfo->si_sb;
28601 + * prevent a race condition between sysfs and aufs.
28602 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
28603 + * prohibits maintaining the sysfs entries.
28604 + * hew we acquire read lock after sysfs_get_active_two().
28605 + * on the other hand, the remount process may maintain the sysfs/aufs
28606 + * entries after acquiring write lock.
28607 + * it can cause a deadlock.
28608 + * simply we gave up processing read here.
28611 + if (unlikely(!si_noflush_read_trylock(sb)))
28614 + seq = au_seq(buf, PAGE_SIZE);
28615 + err = PTR_ERR(seq);
28619 + name = (void *)attr->name;
28620 + cattr = sysaufs_si_attrs;
28622 + if (!strcmp(name, (*cattr)->name)) {
28623 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
28630 + if (!strncmp(name, SysaufsBrid_PREFIX,
28631 + sizeof(SysaufsBrid_PREFIX) - 1)) {
28632 + idx = AuBrSysfs_BRID;
28633 + name += sizeof(SysaufsBrid_PREFIX) - 1;
28634 + } else if (!strncmp(name, SysaufsBr_PREFIX,
28635 + sizeof(SysaufsBr_PREFIX) - 1)) {
28636 + idx = AuBrSysfs_BR;
28637 + name += sizeof(SysaufsBr_PREFIX) - 1;
28641 + err = kstrtol(name, 10, &l);
28643 + bend = au_sbend(sb);
28645 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
28652 + err = seq->count;
28653 + /* sysfs limit */
28654 + if (unlikely(err == PAGE_SIZE))
28659 + si_read_unlock(sb);
28664 +/* ---------------------------------------------------------------------- */
28666 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
28670 + aufs_bindex_t bindex, bend;
28673 + struct seq_file *seq;
28674 + struct au_branch *br;
28676 + si_read_lock(sb, AuLock_FLUSH);
28677 + bend = au_sbend(sb);
28683 + buf = (void *)__get_free_page(GFP_NOFS);
28684 + if (unlikely(!buf))
28687 + seq = au_seq(buf, PAGE_SIZE);
28688 + err = PTR_ERR(seq);
28692 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
28693 + for (bindex = 0; bindex <= bend; bindex++, arg++) {
28694 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
28695 + if (unlikely(err))
28698 + br = au_sbr(sb, bindex);
28699 + brid = br->br_id;
28700 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
28701 + err = __put_user(brid, &arg->id);
28702 + if (unlikely(err))
28705 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
28706 + err = __put_user(br->br_perm, &arg->perm);
28707 + if (unlikely(err))
28710 + au_seq_path(seq, &br->br_path);
28711 + err = seq_putc(seq, '\0');
28712 + if (!err && seq->count <= sz) {
28713 + err = copy_to_user(arg->path, seq->buf, seq->count);
28715 + if (unlikely(err))
28722 + if (unlikely(err))
28728 + free_page((unsigned long)buf);
28730 + si_read_unlock(sb);
28734 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
28736 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
28739 +#ifdef CONFIG_COMPAT
28740 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
28742 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
28746 +/* ---------------------------------------------------------------------- */
28748 +void sysaufs_br_init(struct au_branch *br)
28751 + struct au_brsysfs *br_sysfs;
28752 + struct attribute *attr;
28754 + br_sysfs = br->br_sysfs;
28755 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28756 + attr = &br_sysfs->attr;
28757 + sysfs_attr_init(attr);
28758 + attr->name = br_sysfs->name;
28759 + attr->mode = S_IRUGO;
28764 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
28766 + struct au_branch *br;
28767 + struct kobject *kobj;
28768 + struct au_brsysfs *br_sysfs;
28770 + aufs_bindex_t bend;
28772 + dbgaufs_brs_del(sb, bindex);
28774 + if (!sysaufs_brs)
28777 + kobj = &au_sbi(sb)->si_kobj;
28778 + bend = au_sbend(sb);
28779 + for (; bindex <= bend; bindex++) {
28780 + br = au_sbr(sb, bindex);
28781 + br_sysfs = br->br_sysfs;
28782 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28783 + sysfs_remove_file(kobj, &br_sysfs->attr);
28789 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
28792 + aufs_bindex_t bend;
28793 + struct kobject *kobj;
28794 + struct au_branch *br;
28795 + struct au_brsysfs *br_sysfs;
28797 + dbgaufs_brs_add(sb, bindex);
28799 + if (!sysaufs_brs)
28802 + kobj = &au_sbi(sb)->si_kobj;
28803 + bend = au_sbend(sb);
28804 + for (; bindex <= bend; bindex++) {
28805 + br = au_sbr(sb, bindex);
28806 + br_sysfs = br->br_sysfs;
28807 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
28808 + SysaufsBr_PREFIX "%d", bindex);
28809 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
28810 + SysaufsBrid_PREFIX "%d", bindex);
28811 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
28812 + err = sysfs_create_file(kobj, &br_sysfs->attr);
28813 + if (unlikely(err))
28814 + pr_warn("failed %s under sysfs(%d)\n",
28815 + br_sysfs->name, err);
28820 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
28821 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
28822 +++ linux/fs/aufs/sysrq.c 2015-09-24 10:47:58.254719746 +0200
28825 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28827 + * This program, aufs is free software; you can redistribute it and/or modify
28828 + * it under the terms of the GNU General Public License as published by
28829 + * the Free Software Foundation; either version 2 of the License, or
28830 + * (at your option) any later version.
28832 + * This program is distributed in the hope that it will be useful,
28833 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28834 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28835 + * GNU General Public License for more details.
28837 + * You should have received a copy of the GNU General Public License
28838 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28842 + * magic sysrq hanlder
28845 +/* #include <linux/sysrq.h> */
28846 +#include <linux/writeback.h>
28849 +/* ---------------------------------------------------------------------- */
28851 +static void sysrq_sb(struct super_block *sb)
28854 + struct au_sbinfo *sbinfo;
28855 + struct file *file;
28856 + struct au_sphlhead *files;
28857 + struct au_finfo *finfo;
28859 + plevel = au_plevel;
28860 + au_plevel = KERN_WARNING;
28862 + /* since we define pr_fmt, call printk directly */
28863 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
28865 + sbinfo = au_sbi(sb);
28866 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
28867 + pr("superblock\n");
28871 + pr("root dentry\n");
28872 + au_dpri_dentry(sb->s_root);
28873 + pr("root inode\n");
28874 + au_dpri_inode(d_inode(sb->s_root));
28879 + int err, i, j, ndentry;
28880 + struct au_dcsub_pages dpages;
28881 + struct au_dpage *dpage;
28883 + err = au_dpages_init(&dpages, GFP_ATOMIC);
28884 + if (unlikely(err))
28886 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
28888 + for (i = 0; i < dpages.ndpage; i++) {
28889 + dpage = dpages.dpages + i;
28890 + ndentry = dpage->ndentry;
28891 + for (j = 0; j < ndentry; j++)
28892 + au_dpri_dentry(dpage->dentries[j]);
28894 + au_dpages_free(&dpages);
28902 + pr("isolated inode\n");
28903 + spin_lock(&inode_sb_list_lock);
28904 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
28905 + spin_lock(&i->i_lock);
28906 + if (1 || hlist_empty(&i->i_dentry))
28907 + au_dpri_inode(i);
28908 + spin_unlock(&i->i_lock);
28910 + spin_unlock(&inode_sb_list_lock);
28914 + files = &au_sbi(sb)->si_files;
28915 + spin_lock(&files->spin);
28916 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
28919 + file = finfo->fi_file;
28920 + mode = file_inode(file)->i_mode;
28921 + if (!special_file(mode))
28922 + au_dpri_file(file);
28924 + spin_unlock(&files->spin);
28928 + au_plevel = plevel;
28931 +/* ---------------------------------------------------------------------- */
28933 +/* module parameter */
28934 +static char *aufs_sysrq_key = "a";
28935 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
28936 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
28938 +static void au_sysrq(int key __maybe_unused)
28940 + struct au_sbinfo *sbinfo;
28943 + au_sbilist_lock();
28944 + list_for_each_entry(sbinfo, &au_sbilist.head, si_list)
28945 + sysrq_sb(sbinfo->si_sb);
28946 + au_sbilist_unlock();
28950 +static struct sysrq_key_op au_sysrq_op = {
28951 + .handler = au_sysrq,
28952 + .help_msg = "Aufs",
28953 + .action_msg = "Aufs",
28954 + .enable_mask = SYSRQ_ENABLE_DUMP
28957 +/* ---------------------------------------------------------------------- */
28959 +int __init au_sysrq_init(void)
28965 + key = *aufs_sysrq_key;
28966 + if ('a' <= key && key <= 'z')
28967 + err = register_sysrq_key(key, &au_sysrq_op);
28968 + if (unlikely(err))
28969 + pr_err("err %d, sysrq=%c\n", err, key);
28973 +void au_sysrq_fin(void)
28977 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
28978 + if (unlikely(err))
28979 + pr_err("err %d (ignored)\n", err);
28981 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
28982 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
28983 +++ linux/fs/aufs/vdir.c 2015-09-24 10:47:58.258053165 +0200
28986 + * Copyright (C) 2005-2015 Junjiro R. Okajima
28988 + * This program, aufs is free software; you can redistribute it and/or modify
28989 + * it under the terms of the GNU General Public License as published by
28990 + * the Free Software Foundation; either version 2 of the License, or
28991 + * (at your option) any later version.
28993 + * This program is distributed in the hope that it will be useful,
28994 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28995 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28996 + * GNU General Public License for more details.
28998 + * You should have received a copy of the GNU General Public License
28999 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29003 + * virtual or vertical directory
29008 +static unsigned int calc_size(int nlen)
29010 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29013 +static int set_deblk_end(union au_vdir_deblk_p *p,
29014 + union au_vdir_deblk_p *deblk_end)
29016 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29017 + p->de->de_str.len = 0;
29021 + return -1; /* error */
29024 +/* returns true or false */
29025 +static int is_deblk_end(union au_vdir_deblk_p *p,
29026 + union au_vdir_deblk_p *deblk_end)
29028 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29029 + return !p->de->de_str.len;
29033 +static unsigned char *last_deblk(struct au_vdir *vdir)
29035 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29038 +/* ---------------------------------------------------------------------- */
29040 +/* estimate the apropriate size for name hash table */
29041 +unsigned int au_rdhash_est(loff_t sz)
29049 + if (sz < AUFS_RDHASH_DEF)
29050 + n = AUFS_RDHASH_DEF;
29051 + /* pr_info("n %u\n", n); */
29056 + * the allocated memory has to be freed by
29057 + * au_nhash_wh_free() or au_nhash_de_free().
29059 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29061 + struct hlist_head *head;
29065 + sz = sizeof(*nhash->nh_head) * num_hash;
29066 + head = kmalloc(sz, gfp);
29068 + nhash->nh_num = num_hash;
29069 + nhash->nh_head = head;
29070 + for (u = 0; u < num_hash; u++)
29071 + INIT_HLIST_HEAD(head++);
29072 + return 0; /* success */
29078 +static void nhash_count(struct hlist_head *head)
29082 + struct hlist_node *pos;
29085 + hlist_for_each(pos, head)
29087 + pr_info("%lu\n", n);
29091 +static void au_nhash_wh_do_free(struct hlist_head *head)
29093 + struct au_vdir_wh *pos;
29094 + struct hlist_node *node;
29096 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29100 +static void au_nhash_de_do_free(struct hlist_head *head)
29102 + struct au_vdir_dehstr *pos;
29103 + struct hlist_node *node;
29105 + hlist_for_each_entry_safe(pos, node, head, hash)
29106 + au_cache_free_vdir_dehstr(pos);
29109 +static void au_nhash_do_free(struct au_nhash *nhash,
29110 + void (*free)(struct hlist_head *head))
29113 + struct hlist_head *head;
29115 + n = nhash->nh_num;
29119 + head = nhash->nh_head;
29120 + while (n-- > 0) {
29121 + nhash_count(head);
29124 + kfree(nhash->nh_head);
29127 +void au_nhash_wh_free(struct au_nhash *whlist)
29129 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29132 +static void au_nhash_de_free(struct au_nhash *delist)
29134 + au_nhash_do_free(delist, au_nhash_de_do_free);
29137 +/* ---------------------------------------------------------------------- */
29139 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29143 + unsigned int u, n;
29144 + struct hlist_head *head;
29145 + struct au_vdir_wh *pos;
29148 + n = whlist->nh_num;
29149 + head = whlist->nh_head;
29150 + for (u = 0; u < n; u++, head++)
29151 + hlist_for_each_entry(pos, head, wh_hash)
29152 + if (pos->wh_bindex == btgt && ++num > limit)
29157 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29158 + unsigned char *name,
29159 + unsigned int len)
29162 + /* const unsigned int magic_bit = 12; */
29164 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29169 + /* v = hash_long(v, magic_bit); */
29170 + v %= nhash->nh_num;
29171 + return nhash->nh_head + v;
29174 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29177 + return str->len == nlen && !memcmp(str->name, name, nlen);
29180 +/* returns found or not */
29181 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29183 + struct hlist_head *head;
29184 + struct au_vdir_wh *pos;
29185 + struct au_vdir_destr *str;
29187 + head = au_name_hash(whlist, name, nlen);
29188 + hlist_for_each_entry(pos, head, wh_hash) {
29189 + str = &pos->wh_str;
29190 + AuDbg("%.*s\n", str->len, str->name);
29191 + if (au_nhash_test_name(str, name, nlen))
29197 +/* returns found(true) or not */
29198 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29200 + struct hlist_head *head;
29201 + struct au_vdir_dehstr *pos;
29202 + struct au_vdir_destr *str;
29204 + head = au_name_hash(delist, name, nlen);
29205 + hlist_for_each_entry(pos, head, hash) {
29207 + AuDbg("%.*s\n", str->len, str->name);
29208 + if (au_nhash_test_name(str, name, nlen))
29214 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29215 + unsigned char d_type)
29217 +#ifdef CONFIG_AUFS_SHWH
29218 + wh->wh_ino = ino;
29219 + wh->wh_type = d_type;
29223 +/* ---------------------------------------------------------------------- */
29225 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29226 + unsigned int d_type, aufs_bindex_t bindex,
29227 + unsigned char shwh)
29230 + struct au_vdir_destr *str;
29231 + struct au_vdir_wh *wh;
29233 + AuDbg("%.*s\n", nlen, name);
29234 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29237 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29238 + if (unlikely(!wh))
29242 + wh->wh_bindex = bindex;
29244 + au_shwh_init_wh(wh, ino, d_type);
29245 + str = &wh->wh_str;
29247 + memcpy(str->name, name, nlen);
29248 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29255 +static int append_deblk(struct au_vdir *vdir)
29258 + unsigned long ul;
29259 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29260 + union au_vdir_deblk_p p, deblk_end;
29261 + unsigned char **o;
29264 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29266 + if (unlikely(!o))
29269 + vdir->vd_deblk = o;
29270 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29272 + ul = vdir->vd_nblk++;
29273 + vdir->vd_deblk[ul] = p.deblk;
29274 + vdir->vd_last.ul = ul;
29275 + vdir->vd_last.p.deblk = p.deblk;
29276 + deblk_end.deblk = p.deblk + deblk_sz;
29277 + err = set_deblk_end(&p, &deblk_end);
29284 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29285 + unsigned int d_type, struct au_nhash *delist)
29289 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29290 + union au_vdir_deblk_p p, *room, deblk_end;
29291 + struct au_vdir_dehstr *dehstr;
29293 + p.deblk = last_deblk(vdir);
29294 + deblk_end.deblk = p.deblk + deblk_sz;
29295 + room = &vdir->vd_last.p;
29296 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29297 + || !is_deblk_end(room, &deblk_end));
29299 + sz = calc_size(nlen);
29300 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29301 + err = append_deblk(vdir);
29302 + if (unlikely(err))
29305 + p.deblk = last_deblk(vdir);
29306 + deblk_end.deblk = p.deblk + deblk_sz;
29308 + AuDebugOn(room->deblk != p.deblk);
29312 + dehstr = au_cache_alloc_vdir_dehstr();
29313 + if (unlikely(!dehstr))
29316 + dehstr->str = &room->de->de_str;
29317 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
29318 + room->de->de_ino = ino;
29319 + room->de->de_type = d_type;
29320 + room->de->de_str.len = nlen;
29321 + memcpy(room->de->de_str.name, name, nlen);
29324 + room->deblk += sz;
29325 + if (unlikely(set_deblk_end(room, &deblk_end)))
29326 + err = append_deblk(vdir);
29333 +/* ---------------------------------------------------------------------- */
29335 +void au_vdir_free(struct au_vdir *vdir)
29337 + unsigned char **deblk;
29339 + deblk = vdir->vd_deblk;
29340 + while (vdir->vd_nblk--)
29342 + kfree(vdir->vd_deblk);
29343 + au_cache_free_vdir(vdir);
29346 +static struct au_vdir *alloc_vdir(struct file *file)
29348 + struct au_vdir *vdir;
29349 + struct super_block *sb;
29352 + sb = file->f_path.dentry->d_sb;
29353 + SiMustAnyLock(sb);
29356 + vdir = au_cache_alloc_vdir();
29357 + if (unlikely(!vdir))
29360 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
29361 + if (unlikely(!vdir->vd_deblk))
29364 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
29365 + if (!vdir->vd_deblk_sz) {
29366 + /* estimate the apropriate size for deblk */
29367 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
29368 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
29370 + vdir->vd_nblk = 0;
29371 + vdir->vd_version = 0;
29372 + vdir->vd_jiffy = 0;
29373 + err = append_deblk(vdir);
29375 + return vdir; /* success */
29377 + kfree(vdir->vd_deblk);
29380 + au_cache_free_vdir(vdir);
29382 + vdir = ERR_PTR(err);
29386 +static int reinit_vdir(struct au_vdir *vdir)
29389 + union au_vdir_deblk_p p, deblk_end;
29391 + while (vdir->vd_nblk > 1) {
29392 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
29393 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
29396 + p.deblk = vdir->vd_deblk[0];
29397 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
29398 + err = set_deblk_end(&p, &deblk_end);
29399 + /* keep vd_dblk_sz */
29400 + vdir->vd_last.ul = 0;
29401 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29402 + vdir->vd_version = 0;
29403 + vdir->vd_jiffy = 0;
29408 +/* ---------------------------------------------------------------------- */
29410 +#define AuFillVdir_CALLED 1
29411 +#define AuFillVdir_WHABLE (1 << 1)
29412 +#define AuFillVdir_SHWH (1 << 2)
29413 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
29414 +#define au_fset_fillvdir(flags, name) \
29415 + do { (flags) |= AuFillVdir_##name; } while (0)
29416 +#define au_fclr_fillvdir(flags, name) \
29417 + do { (flags) &= ~AuFillVdir_##name; } while (0)
29419 +#ifndef CONFIG_AUFS_SHWH
29420 +#undef AuFillVdir_SHWH
29421 +#define AuFillVdir_SHWH 0
29424 +struct fillvdir_arg {
29425 + struct dir_context ctx;
29426 + struct file *file;
29427 + struct au_vdir *vdir;
29428 + struct au_nhash delist;
29429 + struct au_nhash whlist;
29430 + aufs_bindex_t bindex;
29431 + unsigned int flags;
29435 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
29436 + loff_t offset __maybe_unused, u64 h_ino,
29437 + unsigned int d_type)
29439 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
29440 + char *name = (void *)__name;
29441 + struct super_block *sb;
29443 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
29446 + sb = arg->file->f_path.dentry->d_sb;
29447 + au_fset_fillvdir(arg->flags, CALLED);
29449 + if (nlen <= AUFS_WH_PFX_LEN
29450 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
29451 + if (test_known(&arg->delist, name, nlen)
29452 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
29453 + goto out; /* already exists or whiteouted */
29455 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
29457 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29458 + d_type = DT_UNKNOWN;
29459 + arg->err = append_de(arg->vdir, name, nlen, ino,
29460 + d_type, &arg->delist);
29462 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
29463 + name += AUFS_WH_PFX_LEN;
29464 + nlen -= AUFS_WH_PFX_LEN;
29465 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
29466 + goto out; /* already whiteouted */
29469 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
29472 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
29473 + d_type = DT_UNKNOWN;
29474 + arg->err = au_nhash_append_wh
29475 + (&arg->whlist, name, nlen, ino, d_type,
29476 + arg->bindex, shwh);
29482 + arg->vdir->vd_jiffy = jiffies;
29484 + AuTraceErr(arg->err);
29488 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
29489 + struct au_nhash *whlist, struct au_nhash *delist)
29491 +#ifdef CONFIG_AUFS_SHWH
29493 + unsigned int nh, u;
29494 + struct hlist_head *head;
29495 + struct au_vdir_wh *pos;
29496 + struct hlist_node *n;
29498 + struct au_vdir_destr *destr;
29500 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
29503 + o = p = (void *)__get_free_page(GFP_NOFS);
29504 + if (unlikely(!p))
29508 + nh = whlist->nh_num;
29509 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29510 + p += AUFS_WH_PFX_LEN;
29511 + for (u = 0; u < nh; u++) {
29512 + head = whlist->nh_head + u;
29513 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
29514 + destr = &pos->wh_str;
29515 + memcpy(p, destr->name, destr->len);
29516 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
29517 + pos->wh_ino, pos->wh_type, delist);
29518 + if (unlikely(err))
29523 + free_page((unsigned long)o);
29533 +static int au_do_read_vdir(struct fillvdir_arg *arg)
29536 + unsigned int rdhash;
29538 + aufs_bindex_t bend, bindex, bstart;
29539 + unsigned char shwh;
29540 + struct file *hf, *file;
29541 + struct super_block *sb;
29543 + file = arg->file;
29544 + sb = file->f_path.dentry->d_sb;
29545 + SiMustAnyLock(sb);
29547 + rdhash = au_sbi(sb)->si_rdhash;
29549 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
29550 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
29551 + if (unlikely(err))
29553 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
29554 + if (unlikely(err))
29560 + if (au_opt_test(au_mntflags(sb), SHWH)) {
29562 + au_fset_fillvdir(arg->flags, SHWH);
29564 + bstart = au_fbstart(file);
29565 + bend = au_fbend_dir(file);
29566 + for (bindex = bstart; !err && bindex <= bend; bindex++) {
29567 + hf = au_hf_dir(file, bindex);
29571 + offset = vfsub_llseek(hf, 0, SEEK_SET);
29573 + if (unlikely(offset))
29576 + arg->bindex = bindex;
29577 + au_fclr_fillvdir(arg->flags, WHABLE);
29579 + || (bindex != bend
29580 + && au_br_whable(au_sbr_perm(sb, bindex))))
29581 + au_fset_fillvdir(arg->flags, WHABLE);
29584 + au_fclr_fillvdir(arg->flags, CALLED);
29586 + err = vfsub_iterate_dir(hf, &arg->ctx);
29589 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
29592 + * dir_relax() may be good for concurrency, but aufs should not
29593 + * use it since it will cause a lockdep problem.
29597 + if (!err && shwh)
29598 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
29600 + au_nhash_wh_free(&arg->whlist);
29603 + au_nhash_de_free(&arg->delist);
29608 +static int read_vdir(struct file *file, int may_read)
29611 + unsigned long expire;
29612 + unsigned char do_read;
29613 + struct fillvdir_arg arg = {
29615 + .actor = fillvdir
29618 + struct inode *inode;
29619 + struct au_vdir *vdir, *allocated;
29622 + inode = file_inode(file);
29623 + IMustLock(inode);
29624 + SiMustAnyLock(inode->i_sb);
29626 + allocated = NULL;
29628 + expire = au_sbi(inode->i_sb)->si_rdcache;
29629 + vdir = au_ivdir(inode);
29632 + vdir = alloc_vdir(file);
29633 + err = PTR_ERR(vdir);
29634 + if (IS_ERR(vdir))
29637 + allocated = vdir;
29638 + } else if (may_read
29639 + && (inode->i_version != vdir->vd_version
29640 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
29642 + err = reinit_vdir(vdir);
29643 + if (unlikely(err))
29648 + return 0; /* success */
29652 + err = au_do_read_vdir(&arg);
29654 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
29655 + vdir->vd_version = inode->i_version;
29656 + vdir->vd_last.ul = 0;
29657 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29659 + au_set_ivdir(inode, allocated);
29660 + } else if (allocated)
29661 + au_vdir_free(allocated);
29667 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
29670 + unsigned long ul, n;
29671 + const unsigned int deblk_sz = src->vd_deblk_sz;
29673 + AuDebugOn(tgt->vd_nblk != 1);
29676 + if (tgt->vd_nblk < src->vd_nblk) {
29677 + unsigned char **p;
29679 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
29681 + if (unlikely(!p))
29683 + tgt->vd_deblk = p;
29686 + if (tgt->vd_deblk_sz != deblk_sz) {
29687 + unsigned char *p;
29689 + tgt->vd_deblk_sz = deblk_sz;
29690 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
29691 + if (unlikely(!p))
29693 + tgt->vd_deblk[0] = p;
29695 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
29696 + tgt->vd_version = src->vd_version;
29697 + tgt->vd_jiffy = src->vd_jiffy;
29699 + n = src->vd_nblk;
29700 + for (ul = 1; ul < n; ul++) {
29701 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
29703 + if (unlikely(!tgt->vd_deblk[ul]))
29707 + tgt->vd_nblk = n;
29708 + tgt->vd_last.ul = tgt->vd_last.ul;
29709 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
29710 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
29711 + - src->vd_deblk[src->vd_last.ul];
29713 + return 0; /* success */
29716 + rerr = reinit_vdir(tgt);
29721 +int au_vdir_init(struct file *file)
29724 + struct inode *inode;
29725 + struct au_vdir *vdir_cache, *allocated;
29727 + /* test file->f_pos here instead of ctx->pos */
29728 + err = read_vdir(file, !file->f_pos);
29729 + if (unlikely(err))
29732 + allocated = NULL;
29733 + vdir_cache = au_fvdir_cache(file);
29734 + if (!vdir_cache) {
29735 + vdir_cache = alloc_vdir(file);
29736 + err = PTR_ERR(vdir_cache);
29737 + if (IS_ERR(vdir_cache))
29739 + allocated = vdir_cache;
29740 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
29741 + /* test file->f_pos here instead of ctx->pos */
29742 + err = reinit_vdir(vdir_cache);
29743 + if (unlikely(err))
29746 + return 0; /* success */
29748 + inode = file_inode(file);
29749 + err = copy_vdir(vdir_cache, au_ivdir(inode));
29751 + file->f_version = inode->i_version;
29753 + au_set_fvdir_cache(file, allocated);
29754 + } else if (allocated)
29755 + au_vdir_free(allocated);
29761 +static loff_t calc_offset(struct au_vdir *vdir)
29764 + union au_vdir_deblk_p p;
29766 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
29767 + offset = vdir->vd_last.p.deblk - p.deblk;
29768 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
29772 +/* returns true or false */
29773 +static int seek_vdir(struct file *file, struct dir_context *ctx)
29776 + unsigned int deblk_sz;
29777 + unsigned long ul, n;
29779 + union au_vdir_deblk_p p, deblk_end;
29780 + struct au_vdir *vdir_cache;
29783 + vdir_cache = au_fvdir_cache(file);
29784 + offset = calc_offset(vdir_cache);
29785 + AuDbg("offset %lld\n", offset);
29786 + if (ctx->pos == offset)
29789 + vdir_cache->vd_last.ul = 0;
29790 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
29795 + deblk_sz = vdir_cache->vd_deblk_sz;
29796 + ul = div64_u64(ctx->pos, deblk_sz);
29797 + AuDbg("ul %lu\n", ul);
29798 + if (ul >= vdir_cache->vd_nblk)
29801 + n = vdir_cache->vd_nblk;
29802 + for (; ul < n; ul++) {
29803 + p.deblk = vdir_cache->vd_deblk[ul];
29804 + deblk_end.deblk = p.deblk + deblk_sz;
29806 + offset *= deblk_sz;
29807 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
29810 + l = calc_size(p.de->de_str.len);
29814 + if (!is_deblk_end(&p, &deblk_end)) {
29816 + vdir_cache->vd_last.ul = ul;
29817 + vdir_cache->vd_last.p = p;
29824 + AuTraceErr(!valid);
29828 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
29830 + unsigned int l, deblk_sz;
29831 + union au_vdir_deblk_p deblk_end;
29832 + struct au_vdir *vdir_cache;
29833 + struct au_vdir_de *de;
29835 + vdir_cache = au_fvdir_cache(file);
29836 + if (!seek_vdir(file, ctx))
29839 + deblk_sz = vdir_cache->vd_deblk_sz;
29841 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29842 + deblk_end.deblk += deblk_sz;
29843 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
29844 + de = vdir_cache->vd_last.p.de;
29845 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
29846 + de->de_str.len, de->de_str.name, ctx->pos,
29847 + (unsigned long)de->de_ino, de->de_type);
29848 + if (unlikely(!dir_emit(ctx, de->de_str.name,
29849 + de->de_str.len, de->de_ino,
29851 + /* todo: ignore the error caused by udba? */
29852 + /* return err; */
29856 + l = calc_size(de->de_str.len);
29857 + vdir_cache->vd_last.p.deblk += l;
29860 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
29861 + vdir_cache->vd_last.ul++;
29862 + vdir_cache->vd_last.p.deblk
29863 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
29864 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
29873 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
29874 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
29875 +++ linux/fs/aufs/vfsub.c 2015-09-24 10:47:58.258053165 +0200
29878 + * Copyright (C) 2005-2015 Junjiro R. Okajima
29880 + * This program, aufs is free software; you can redistribute it and/or modify
29881 + * it under the terms of the GNU General Public License as published by
29882 + * the Free Software Foundation; either version 2 of the License, or
29883 + * (at your option) any later version.
29885 + * This program is distributed in the hope that it will be useful,
29886 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29887 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29888 + * GNU General Public License for more details.
29890 + * You should have received a copy of the GNU General Public License
29891 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29895 + * sub-routines for VFS
29898 +#include <linux/namei.h>
29899 +#include <linux/security.h>
29900 +#include <linux/splice.h>
29903 +int vfsub_update_h_iattr(struct path *h_path, int *did)
29907 + struct super_block *h_sb;
29909 + /* for remote fs, leave work for its getattr or d_revalidate */
29910 + /* for bad i_attr fs, handle them in aufs_getattr() */
29911 + /* still some fs may acquire i_mutex. we need to skip them */
29915 + h_sb = h_path->dentry->d_sb;
29916 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
29918 + err = vfs_getattr(h_path, &st);
29923 +/* ---------------------------------------------------------------------- */
29925 +struct file *vfsub_dentry_open(struct path *path, int flags)
29927 + struct file *file;
29929 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
29931 + if (!IS_ERR_OR_NULL(file)
29932 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
29933 + i_readcount_inc(d_inode(path->dentry));
29938 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
29940 + struct file *file;
29943 + file = filp_open(path,
29944 + oflags /* | __FMODE_NONOTIFY */,
29947 + if (IS_ERR(file))
29949 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
29956 + * Ideally this function should call VFS:do_last() in order to keep all its
29957 + * checkings. But it is very hard for aufs to regenerate several VFS internal
29958 + * structure such as nameidata. This is a second (or third) best approach.
29959 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
29961 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
29962 + struct vfsub_aopen_args *args, struct au_branch *br)
29965 + struct file *file = args->file;
29966 + /* copied from linux/fs/namei.c:atomic_open() */
29967 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
29970 + AuDebugOn(!dir->i_op->atomic_open);
29972 + err = au_br_test_oflag(args->open_flag, br);
29973 + if (unlikely(err))
29976 + args->file->f_path.dentry = DENTRY_NOT_SET;
29977 + args->file->f_path.mnt = au_br_mnt(br);
29978 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
29979 + args->create_mode, args->opened);
29981 + /* some filesystems don't set FILE_CREATED while succeeded? */
29982 + if (*args->opened & FILE_CREATED)
29983 + fsnotify_create(dir, dentry);
29989 + /* todo: call VFS:may_open() here */
29990 + err = open_check_o_direct(file);
29991 + /* todo: ima_file_check() too? */
29992 + if (!err && (args->open_flag & __FMODE_EXEC))
29993 + err = deny_write_access(file);
29994 + if (unlikely(err))
29995 + /* note that the file is created and still opened */
29999 + atomic_inc(&br->br_count);
30000 + fsnotify_open(file);
30006 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30010 + err = kern_path(name, flags, path);
30011 + if (!err && d_is_positive(path->dentry))
30012 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30016 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30019 + struct path path = {
30023 + /* VFS checks it too, but by WARN_ON_ONCE() */
30024 + IMustLock(d_inode(parent));
30026 + path.dentry = lookup_one_len(name, parent, len);
30027 + if (IS_ERR(path.dentry))
30029 + if (d_is_positive(path.dentry))
30030 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30033 + AuTraceErrPtr(path.dentry);
30034 + return path.dentry;
30037 +void vfsub_call_lkup_one(void *args)
30039 + struct vfsub_lkup_one_args *a = args;
30040 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30043 +/* ---------------------------------------------------------------------- */
30045 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30046 + struct dentry *d2, struct au_hinode *hdir2)
30048 + struct dentry *d;
30051 + d = lock_rename(d1, d2);
30053 + au_hn_suspend(hdir1);
30054 + if (hdir1 != hdir2)
30055 + au_hn_suspend(hdir2);
30060 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30061 + struct dentry *d2, struct au_hinode *hdir2)
30063 + au_hn_resume(hdir1);
30064 + if (hdir1 != hdir2)
30065 + au_hn_resume(hdir2);
30067 + unlock_rename(d1, d2);
30071 +/* ---------------------------------------------------------------------- */
30073 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30076 + struct dentry *d;
30080 + d = path->dentry;
30081 + path->dentry = d->d_parent;
30082 + err = security_path_mknod(path, d, mode, 0);
30083 + path->dentry = d;
30084 + if (unlikely(err))
30088 + err = vfs_create(dir, path->dentry, mode, want_excl);
30091 + struct path tmp = *path;
30094 + vfsub_update_h_iattr(&tmp, &did);
30096 + tmp.dentry = path->dentry->d_parent;
30097 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30106 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30109 + struct dentry *d;
30113 + d = path->dentry;
30114 + path->dentry = d->d_parent;
30115 + err = security_path_symlink(path, d, symname);
30116 + path->dentry = d;
30117 + if (unlikely(err))
30121 + err = vfs_symlink(dir, path->dentry, symname);
30124 + struct path tmp = *path;
30127 + vfsub_update_h_iattr(&tmp, &did);
30129 + tmp.dentry = path->dentry->d_parent;
30130 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30139 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30142 + struct dentry *d;
30146 + d = path->dentry;
30147 + path->dentry = d->d_parent;
30148 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30149 + path->dentry = d;
30150 + if (unlikely(err))
30154 + err = vfs_mknod(dir, path->dentry, mode, dev);
30157 + struct path tmp = *path;
30160 + vfsub_update_h_iattr(&tmp, &did);
30162 + tmp.dentry = path->dentry->d_parent;
30163 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30172 +static int au_test_nlink(struct inode *inode)
30174 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30176 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30177 + || inode->i_nlink < link_max)
30182 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30183 + struct inode **delegated_inode)
30186 + struct dentry *d;
30190 + err = au_test_nlink(d_inode(src_dentry));
30191 + if (unlikely(err))
30194 + /* we don't call may_linkat() */
30195 + d = path->dentry;
30196 + path->dentry = d->d_parent;
30197 + err = security_path_link(src_dentry, path, d);
30198 + path->dentry = d;
30199 + if (unlikely(err))
30203 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30206 + struct path tmp = *path;
30209 + /* fuse has different memory inode for the same inumber */
30210 + vfsub_update_h_iattr(&tmp, &did);
30212 + tmp.dentry = path->dentry->d_parent;
30213 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30214 + tmp.dentry = src_dentry;
30215 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30224 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30225 + struct inode *dir, struct path *path,
30226 + struct inode **delegated_inode)
30229 + struct path tmp = {
30232 + struct dentry *d;
30235 + IMustLock(src_dir);
30237 + d = path->dentry;
30238 + path->dentry = d->d_parent;
30239 + tmp.dentry = src_dentry->d_parent;
30240 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30241 + path->dentry = d;
30242 + if (unlikely(err))
30246 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30247 + delegated_inode, /*flags*/0);
30252 + tmp.dentry = d->d_parent;
30253 + vfsub_update_h_iattr(&tmp, &did);
30255 + tmp.dentry = src_dentry;
30256 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30257 + tmp.dentry = src_dentry->d_parent;
30258 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30267 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
30270 + struct dentry *d;
30274 + d = path->dentry;
30275 + path->dentry = d->d_parent;
30276 + err = security_path_mkdir(path, d, mode);
30277 + path->dentry = d;
30278 + if (unlikely(err))
30282 + err = vfs_mkdir(dir, path->dentry, mode);
30285 + struct path tmp = *path;
30288 + vfsub_update_h_iattr(&tmp, &did);
30290 + tmp.dentry = path->dentry->d_parent;
30291 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30300 +int vfsub_rmdir(struct inode *dir, struct path *path)
30303 + struct dentry *d;
30307 + d = path->dentry;
30308 + path->dentry = d->d_parent;
30309 + err = security_path_rmdir(path, d);
30310 + path->dentry = d;
30311 + if (unlikely(err))
30315 + err = vfs_rmdir(dir, path->dentry);
30318 + struct path tmp = {
30319 + .dentry = path->dentry->d_parent,
30323 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30330 +/* ---------------------------------------------------------------------- */
30332 +/* todo: support mmap_sem? */
30333 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30339 + err = vfs_read(file, ubuf, count, ppos);
30342 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30346 +/* todo: kernel_read()? */
30347 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30351 + mm_segment_t oldfs;
30358 + oldfs = get_fs();
30359 + set_fs(KERNEL_DS);
30360 + err = vfsub_read_u(file, buf.u, count, ppos);
30365 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30371 + err = vfs_write(file, ubuf, count, ppos);
30374 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30378 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
30381 + mm_segment_t oldfs;
30384 + const char __user *u;
30388 + oldfs = get_fs();
30389 + set_fs(KERNEL_DS);
30390 + err = vfsub_write_u(file, buf.u, count, ppos);
30395 +int vfsub_flush(struct file *file, fl_owner_t id)
30400 + if (file->f_op->flush) {
30401 + if (!au_test_nfs(file->f_path.dentry->d_sb))
30402 + err = file->f_op->flush(file, id);
30405 + err = file->f_op->flush(file, id);
30409 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
30415 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
30419 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
30422 + err = iterate_dir(file, ctx);
30425 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30429 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30430 + struct pipe_inode_info *pipe, size_t len,
30431 + unsigned int flags)
30436 + err = do_splice_to(in, ppos, pipe, len, flags);
30438 + file_accessed(in);
30440 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
30444 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30445 + loff_t *ppos, size_t len, unsigned int flags)
30450 + err = do_splice_from(pipe, out, ppos, len, flags);
30453 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
30457 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
30461 + /* file can be NULL */
30463 + err = vfs_fsync(file, datasync);
30467 + AuDebugOn(!file);
30468 + path = &file->f_path;
30470 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30475 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
30476 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30477 + struct file *h_file)
30480 + struct inode *h_inode;
30481 + struct super_block *h_sb;
30484 + err = vfsub_truncate(h_path, length);
30488 + h_inode = d_inode(h_path->dentry);
30489 + h_sb = h_inode->i_sb;
30491 + sb_start_write(h_sb);
30493 + err = locks_verify_truncate(h_inode, h_file, length);
30495 + err = security_path_truncate(h_path);
30498 + err = do_truncate(h_path->dentry, length, attr, h_file);
30502 + sb_end_write(h_sb);
30509 +/* ---------------------------------------------------------------------- */
30511 +struct au_vfsub_mkdir_args {
30513 + struct inode *dir;
30514 + struct path *path;
30518 +static void au_call_vfsub_mkdir(void *args)
30520 + struct au_vfsub_mkdir_args *a = args;
30521 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
30524 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
30526 + int err, do_sio, wkq_err;
30528 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30531 + err = vfsub_mkdir(dir, path, mode);
30534 + struct au_vfsub_mkdir_args args = {
30540 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
30541 + if (unlikely(wkq_err))
30548 +struct au_vfsub_rmdir_args {
30550 + struct inode *dir;
30551 + struct path *path;
30554 +static void au_call_vfsub_rmdir(void *args)
30556 + struct au_vfsub_rmdir_args *a = args;
30557 + *a->errp = vfsub_rmdir(a->dir, a->path);
30560 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
30562 + int err, do_sio, wkq_err;
30564 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30567 + err = vfsub_rmdir(dir, path);
30570 + struct au_vfsub_rmdir_args args = {
30575 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
30576 + if (unlikely(wkq_err))
30583 +/* ---------------------------------------------------------------------- */
30585 +struct notify_change_args {
30587 + struct path *path;
30588 + struct iattr *ia;
30589 + struct inode **delegated_inode;
30592 +static void call_notify_change(void *args)
30594 + struct notify_change_args *a = args;
30595 + struct inode *h_inode;
30597 + h_inode = d_inode(a->path->dentry);
30598 + IMustLock(h_inode);
30600 + *a->errp = -EPERM;
30601 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
30603 + *a->errp = notify_change(a->path->dentry, a->ia,
30604 + a->delegated_inode);
30607 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
30609 + AuTraceErr(*a->errp);
30612 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30613 + struct inode **delegated_inode)
30616 + struct notify_change_args args = {
30620 + .delegated_inode = delegated_inode
30623 + call_notify_change(&args);
30628 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30629 + struct inode **delegated_inode)
30631 + int err, wkq_err;
30632 + struct notify_change_args args = {
30636 + .delegated_inode = delegated_inode
30639 + wkq_err = au_wkq_wait(call_notify_change, &args);
30640 + if (unlikely(wkq_err))
30646 +/* ---------------------------------------------------------------------- */
30648 +struct unlink_args {
30650 + struct inode *dir;
30651 + struct path *path;
30652 + struct inode **delegated_inode;
30655 +static void call_unlink(void *args)
30657 + struct unlink_args *a = args;
30658 + struct dentry *d = a->path->dentry;
30659 + struct inode *h_inode;
30660 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
30661 + && au_dcount(d) == 1);
30663 + IMustLock(a->dir);
30665 + a->path->dentry = d->d_parent;
30666 + *a->errp = security_path_unlink(a->path, d);
30667 + a->path->dentry = d;
30668 + if (unlikely(*a->errp))
30671 + if (!stop_sillyrename)
30674 + if (d_is_positive(d)) {
30675 + h_inode = d_inode(d);
30680 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
30683 + struct path tmp = {
30684 + .dentry = d->d_parent,
30685 + .mnt = a->path->mnt
30687 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30690 + if (!stop_sillyrename)
30695 + AuTraceErr(*a->errp);
30699 + * @dir: must be locked.
30700 + * @dentry: target dentry.
30702 +int vfsub_unlink(struct inode *dir, struct path *path,
30703 + struct inode **delegated_inode, int force)
30706 + struct unlink_args args = {
30710 + .delegated_inode = delegated_inode
30714 + call_unlink(&args);
30718 + wkq_err = au_wkq_wait(call_unlink, &args);
30719 + if (unlikely(wkq_err))
30725 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
30726 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
30727 +++ linux/fs/aufs/vfsub.h 2015-09-24 10:47:58.258053165 +0200
30730 + * Copyright (C) 2005-2015 Junjiro R. Okajima
30732 + * This program, aufs is free software; you can redistribute it and/or modify
30733 + * it under the terms of the GNU General Public License as published by
30734 + * the Free Software Foundation; either version 2 of the License, or
30735 + * (at your option) any later version.
30737 + * This program is distributed in the hope that it will be useful,
30738 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30739 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30740 + * GNU General Public License for more details.
30742 + * You should have received a copy of the GNU General Public License
30743 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30747 + * sub-routines for VFS
30750 +#ifndef __AUFS_VFSUB_H__
30751 +#define __AUFS_VFSUB_H__
30755 +#include <linux/fs.h>
30756 +#include <linux/mount.h>
30757 +#include <linux/xattr.h>
30758 +#include "debug.h"
30760 +/* copied from linux/fs/internal.h */
30761 +/* todo: BAD approach!! */
30762 +extern void __mnt_drop_write(struct vfsmount *);
30763 +extern spinlock_t inode_sb_list_lock;
30764 +extern int open_check_o_direct(struct file *f);
30766 +/* ---------------------------------------------------------------------- */
30768 +/* lock subclass for lower inode */
30769 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
30770 +/* reduce? gave up. */
30772 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
30773 + AuLsc_I_PARENT, /* lower inode, parent first */
30774 + AuLsc_I_PARENT2, /* copyup dirs */
30775 + AuLsc_I_PARENT3, /* copyup wh */
30781 +/* to debug easier, do not make them inlined functions */
30782 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
30783 +#define IMustLock(i) MtxMustLock(&(i)->i_mutex)
30785 +/* ---------------------------------------------------------------------- */
30787 +static inline void vfsub_drop_nlink(struct inode *inode)
30789 + AuDebugOn(!inode->i_nlink);
30790 + drop_nlink(inode);
30793 +static inline void vfsub_dead_dir(struct inode *inode)
30795 + AuDebugOn(!S_ISDIR(inode->i_mode));
30796 + inode->i_flags |= S_DEAD;
30797 + clear_nlink(inode);
30800 +static inline int vfsub_native_ro(struct inode *inode)
30802 + return (inode->i_sb->s_flags & MS_RDONLY)
30803 + || IS_RDONLY(inode)
30804 + /* || IS_APPEND(inode) */
30805 + || IS_IMMUTABLE(inode);
30808 +/* ---------------------------------------------------------------------- */
30810 +int vfsub_update_h_iattr(struct path *h_path, int *did);
30811 +struct file *vfsub_dentry_open(struct path *path, int flags);
30812 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
30813 +struct vfsub_aopen_args {
30814 + struct file *file;
30815 + unsigned int open_flag;
30816 + umode_t create_mode;
30820 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30821 + struct vfsub_aopen_args *args, struct au_branch *br);
30822 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
30824 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30827 +struct vfsub_lkup_one_args {
30828 + struct dentry **errp;
30829 + struct qstr *name;
30830 + struct dentry *parent;
30833 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
30834 + struct dentry *parent)
30836 + return vfsub_lookup_one_len(name->name, parent, name->len);
30839 +void vfsub_call_lkup_one(void *args);
30841 +/* ---------------------------------------------------------------------- */
30843 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
30848 + err = mnt_want_write(mnt);
30853 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
30856 + mnt_drop_write(mnt);
30860 +#if 0 /* reserved */
30861 +static inline void vfsub_mnt_drop_write_file(struct file *file)
30864 + mnt_drop_write_file(file);
30869 +/* ---------------------------------------------------------------------- */
30872 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30873 + struct dentry *d2, struct au_hinode *hdir2);
30874 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30875 + struct dentry *d2, struct au_hinode *hdir2);
30877 +int vfsub_create(struct inode *dir, struct path *path, int mode,
30879 +int vfsub_symlink(struct inode *dir, struct path *path,
30880 + const char *symname);
30881 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
30882 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
30883 + struct path *path, struct inode **delegated_inode);
30884 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
30885 + struct inode *hdir, struct path *path,
30886 + struct inode **delegated_inode);
30887 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
30888 +int vfsub_rmdir(struct inode *dir, struct path *path);
30890 +/* ---------------------------------------------------------------------- */
30892 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30894 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30896 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30898 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
30900 +int vfsub_flush(struct file *file, fl_owner_t id);
30901 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
30903 +static inline loff_t vfsub_f_size_read(struct file *file)
30905 + return i_size_read(file_inode(file));
30908 +static inline unsigned int vfsub_file_flags(struct file *file)
30910 + unsigned int flags;
30912 + spin_lock(&file->f_lock);
30913 + flags = file->f_flags;
30914 + spin_unlock(&file->f_lock);
30919 +#if 0 /* reserved */
30920 +static inline void vfsub_file_accessed(struct file *h_file)
30922 + file_accessed(h_file);
30923 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
30927 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
30928 + struct dentry *h_dentry)
30930 + struct path h_path = {
30931 + .dentry = h_dentry,
30934 + touch_atime(&h_path);
30935 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
30938 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
30941 + return generic_update_time(h_inode, ts, flags);
30942 + /* no vfsub_update_h_iattr() since we don't have struct path */
30945 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30946 + struct pipe_inode_info *pipe, size_t len,
30947 + unsigned int flags);
30948 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30949 + loff_t *ppos, size_t len, unsigned int flags);
30951 +static inline long vfsub_truncate(struct path *path, loff_t length)
30956 + err = vfs_truncate(path, length);
30961 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30962 + struct file *h_file);
30963 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
30965 +/* ---------------------------------------------------------------------- */
30967 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
30972 + err = vfs_llseek(file, offset, origin);
30977 +/* ---------------------------------------------------------------------- */
30979 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
30980 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
30981 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30982 + struct inode **delegated_inode);
30983 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30984 + struct inode **delegated_inode);
30985 +int vfsub_unlink(struct inode *dir, struct path *path,
30986 + struct inode **delegated_inode, int force);
30988 +/* ---------------------------------------------------------------------- */
30990 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
30991 + const void *value, size_t size, int flags)
30996 + err = vfs_setxattr(dentry, name, value, size, flags);
31002 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31007 + err = vfs_removexattr(dentry, name);
31013 +#endif /* __KERNEL__ */
31014 +#endif /* __AUFS_VFSUB_H__ */
31015 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31016 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31017 +++ linux/fs/aufs/wbr_policy.c 2015-09-24 10:47:58.258053165 +0200
31020 + * Copyright (C) 2005-2015 Junjiro R. Okajima
31022 + * This program, aufs is free software; you can redistribute it and/or modify
31023 + * it under the terms of the GNU General Public License as published by
31024 + * the Free Software Foundation; either version 2 of the License, or
31025 + * (at your option) any later version.
31027 + * This program is distributed in the hope that it will be useful,
31028 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31029 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31030 + * GNU General Public License for more details.
31032 + * You should have received a copy of the GNU General Public License
31033 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31037 + * policies for selecting one among multiple writable branches
31040 +#include <linux/statfs.h>
31043 +/* subset of cpup_attr() */
31044 +static noinline_for_stack
31045 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31049 + struct inode *h_isrc;
31051 + h_isrc = d_inode(h_src);
31052 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31053 + ia.ia_mode = h_isrc->i_mode;
31054 + ia.ia_uid = h_isrc->i_uid;
31055 + ia.ia_gid = h_isrc->i_gid;
31056 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31057 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31058 + /* no delegation since it is just created */
31059 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31061 + /* is this nfs only? */
31062 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31063 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31064 + ia.ia_mode = h_isrc->i_mode;
31065 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31071 +#define AuCpdown_PARENT_OPQ 1
31072 +#define AuCpdown_WHED (1 << 1)
31073 +#define AuCpdown_MADE_DIR (1 << 2)
31074 +#define AuCpdown_DIROPQ (1 << 3)
31075 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31076 +#define au_fset_cpdown(flags, name) \
31077 + do { (flags) |= AuCpdown_##name; } while (0)
31078 +#define au_fclr_cpdown(flags, name) \
31079 + do { (flags) &= ~AuCpdown_##name; } while (0)
31081 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31082 + unsigned int *flags)
31085 + struct dentry *opq_dentry;
31087 + opq_dentry = au_diropq_create(dentry, bdst);
31088 + err = PTR_ERR(opq_dentry);
31089 + if (IS_ERR(opq_dentry))
31091 + dput(opq_dentry);
31092 + au_fset_cpdown(*flags, DIROPQ);
31098 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31099 + struct inode *dir, aufs_bindex_t bdst)
31102 + struct path h_path;
31103 + struct au_branch *br;
31105 + br = au_sbr(dentry->d_sb, bdst);
31106 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31107 + err = PTR_ERR(h_path.dentry);
31108 + if (IS_ERR(h_path.dentry))
31112 + if (d_is_positive(h_path.dentry)) {
31113 + h_path.mnt = au_br_mnt(br);
31114 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31117 + dput(h_path.dentry);
31123 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31124 + struct au_pin *pin,
31125 + struct dentry *h_parent, void *arg)
31128 + aufs_bindex_t bopq, bstart;
31129 + struct path h_path;
31130 + struct dentry *parent;
31131 + struct inode *h_dir, *h_inode, *inode, *dir;
31132 + unsigned int *flags = arg;
31134 + bstart = au_dbstart(dentry);
31135 + /* dentry is di-locked */
31136 + parent = dget_parent(dentry);
31137 + dir = d_inode(parent);
31138 + h_dir = d_inode(h_parent);
31139 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31140 + IMustLock(h_dir);
31142 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31143 + if (unlikely(err < 0))
31145 + h_path.dentry = au_h_dptr(dentry, bdst);
31146 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31147 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31148 + S_IRWXU | S_IRUGO | S_IXUGO);
31149 + if (unlikely(err))
31151 + au_fset_cpdown(*flags, MADE_DIR);
31153 + bopq = au_dbdiropq(dentry);
31154 + au_fclr_cpdown(*flags, WHED);
31155 + au_fclr_cpdown(*flags, DIROPQ);
31156 + if (au_dbwh(dentry) == bdst)
31157 + au_fset_cpdown(*flags, WHED);
31158 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31159 + au_fset_cpdown(*flags, PARENT_OPQ);
31160 + h_inode = d_inode(h_path.dentry);
31161 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
31162 + if (au_ftest_cpdown(*flags, WHED)) {
31163 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31164 + if (unlikely(err)) {
31165 + mutex_unlock(&h_inode->i_mutex);
31170 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, bstart));
31171 + mutex_unlock(&h_inode->i_mutex);
31172 + if (unlikely(err))
31175 + if (au_ftest_cpdown(*flags, WHED)) {
31176 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
31177 + if (unlikely(err))
31181 + inode = d_inode(dentry);
31182 + if (au_ibend(inode) < bdst)
31183 + au_set_ibend(inode, bdst);
31184 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
31185 + au_hi_flags(inode, /*isdir*/1));
31186 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
31187 + goto out; /* success */
31191 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31192 + mutex_lock_nested(&h_inode->i_mutex, AuLsc_I_CHILD);
31193 + rerr = au_diropq_remove(dentry, bdst);
31194 + mutex_unlock(&h_inode->i_mutex);
31195 + if (unlikely(rerr)) {
31196 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
31197 + dentry, bdst, rerr);
31203 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
31204 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
31205 + if (unlikely(rerr)) {
31206 + AuIOErr("failed removing %pd b%d (%d)\n",
31207 + dentry, bdst, rerr);
31212 + au_set_h_dptr(dentry, bdst, NULL);
31213 + if (au_dbend(dentry) == bdst)
31214 + au_update_dbend(dentry);
31220 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
31223 + unsigned int flags;
31226 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
31231 +/* ---------------------------------------------------------------------- */
31233 +/* policies for create */
31235 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
31237 + int err, i, j, ndentry;
31238 + aufs_bindex_t bopq;
31239 + struct au_dcsub_pages dpages;
31240 + struct au_dpage *dpage;
31241 + struct dentry **dentries, *parent, *d;
31243 + err = au_dpages_init(&dpages, GFP_NOFS);
31244 + if (unlikely(err))
31246 + parent = dget_parent(dentry);
31247 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
31248 + if (unlikely(err))
31252 + for (i = 0; i < dpages.ndpage; i++) {
31253 + dpage = dpages.dpages + i;
31254 + dentries = dpage->dentries;
31255 + ndentry = dpage->ndentry;
31256 + for (j = 0; j < ndentry; j++) {
31258 + di_read_lock_parent2(d, !AuLock_IR);
31259 + bopq = au_dbdiropq(d);
31260 + di_read_unlock(d, !AuLock_IR);
31261 + if (bopq >= 0 && bopq < err)
31268 + au_dpages_free(&dpages);
31273 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
31275 + for (; bindex >= 0; bindex--)
31276 + if (!au_br_rdonly(au_sbr(sb, bindex)))
31281 +/* top down parent */
31282 +static int au_wbr_create_tdp(struct dentry *dentry,
31283 + unsigned int flags __maybe_unused)
31286 + aufs_bindex_t bstart, bindex;
31287 + struct super_block *sb;
31288 + struct dentry *parent, *h_parent;
31290 + sb = dentry->d_sb;
31291 + bstart = au_dbstart(dentry);
31293 + if (!au_br_rdonly(au_sbr(sb, bstart)))
31297 + parent = dget_parent(dentry);
31298 + for (bindex = au_dbstart(parent); bindex < bstart; bindex++) {
31299 + h_parent = au_h_dptr(parent, bindex);
31300 + if (!h_parent || d_is_negative(h_parent))
31303 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31310 + /* bottom up here */
31311 + if (unlikely(err < 0)) {
31312 + err = au_wbr_bu(sb, bstart - 1);
31314 + err = au_wbr_nonopq(dentry, err);
31318 + AuDbg("b%d\n", err);
31322 +/* ---------------------------------------------------------------------- */
31324 +/* an exception for the policy other than tdp */
31325 +static int au_wbr_create_exp(struct dentry *dentry)
31328 + aufs_bindex_t bwh, bdiropq;
31329 + struct dentry *parent;
31332 + bwh = au_dbwh(dentry);
31333 + parent = dget_parent(dentry);
31334 + bdiropq = au_dbdiropq(parent);
31336 + if (bdiropq >= 0)
31337 + err = min(bdiropq, bwh);
31340 + AuDbg("%d\n", err);
31341 + } else if (bdiropq >= 0) {
31343 + AuDbg("%d\n", err);
31348 + err = au_wbr_nonopq(dentry, err);
31350 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
31353 + AuDbg("%d\n", err);
31357 +/* ---------------------------------------------------------------------- */
31360 +static int au_wbr_create_init_rr(struct super_block *sb)
31364 + err = au_wbr_bu(sb, au_sbend(sb));
31365 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
31368 + AuDbg("b%d\n", err);
31372 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
31376 + aufs_bindex_t bindex, bend;
31377 + struct super_block *sb;
31380 + err = au_wbr_create_exp(dentry);
31384 + sb = dentry->d_sb;
31385 + next = &au_sbi(sb)->si_wbr_rr_next;
31386 + bend = au_sbend(sb);
31388 + for (bindex = 0; bindex <= bend; bindex++) {
31389 + if (!au_ftest_wbr(flags, DIR)) {
31390 + err = atomic_dec_return(next) + 1;
31391 + /* modulo for 0 is meaningless */
31392 + if (unlikely(!err))
31393 + err = atomic_dec_return(next) + 1;
31395 + err = atomic_read(next);
31396 + AuDbg("%d\n", err);
31399 + AuDbg("%d\n", err);
31400 + if (!au_br_rdonly(au_sbr(sb, err)))
31406 + err = au_wbr_nonopq(dentry, err);
31409 + AuDbg("%d\n", err);
31413 +/* ---------------------------------------------------------------------- */
31415 +/* most free space */
31416 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
31418 + struct super_block *sb;
31419 + struct au_branch *br;
31420 + struct au_wbr_mfs *mfs;
31421 + struct dentry *h_parent;
31422 + aufs_bindex_t bindex, bend;
31424 + unsigned long long b, bavail;
31425 + struct path h_path;
31426 + /* reduce the stack usage */
31427 + struct kstatfs *st;
31429 + st = kmalloc(sizeof(*st), GFP_NOFS);
31430 + if (unlikely(!st)) {
31431 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
31436 + sb = dentry->d_sb;
31437 + mfs = &au_sbi(sb)->si_wbr_mfs;
31438 + MtxMustLock(&mfs->mfs_lock);
31439 + mfs->mfs_bindex = -EROFS;
31440 + mfs->mfsrr_bytes = 0;
31443 + bend = au_sbend(sb);
31445 + bindex = au_dbstart(parent);
31446 + bend = au_dbtaildir(parent);
31449 + for (; bindex <= bend; bindex++) {
31451 + h_parent = au_h_dptr(parent, bindex);
31452 + if (!h_parent || d_is_negative(h_parent))
31455 + br = au_sbr(sb, bindex);
31456 + if (au_br_rdonly(br))
31459 + /* sb->s_root for NFS is unreliable */
31460 + h_path.mnt = au_br_mnt(br);
31461 + h_path.dentry = h_path.mnt->mnt_root;
31462 + err = vfs_statfs(&h_path, st);
31463 + if (unlikely(err)) {
31464 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
31468 + /* when the available size is equal, select the lower one */
31469 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
31470 + || sizeof(b) < sizeof(st->f_bsize));
31471 + b = st->f_bavail * st->f_bsize;
31472 + br->br_wbr->wbr_bytes = b;
31473 + if (b >= bavail) {
31475 + mfs->mfs_bindex = bindex;
31476 + mfs->mfs_jiffy = jiffies;
31480 + mfs->mfsrr_bytes = bavail;
31481 + AuDbg("b%d\n", mfs->mfs_bindex);
31485 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
31488 + struct dentry *parent;
31489 + struct super_block *sb;
31490 + struct au_wbr_mfs *mfs;
31492 + err = au_wbr_create_exp(dentry);
31496 + sb = dentry->d_sb;
31498 + if (au_ftest_wbr(flags, PARENT))
31499 + parent = dget_parent(dentry);
31500 + mfs = &au_sbi(sb)->si_wbr_mfs;
31501 + mutex_lock(&mfs->mfs_lock);
31502 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
31503 + || mfs->mfs_bindex < 0
31504 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
31505 + au_mfs(dentry, parent);
31506 + mutex_unlock(&mfs->mfs_lock);
31507 + err = mfs->mfs_bindex;
31511 + err = au_wbr_nonopq(dentry, err);
31514 + AuDbg("b%d\n", err);
31518 +static int au_wbr_create_init_mfs(struct super_block *sb)
31520 + struct au_wbr_mfs *mfs;
31522 + mfs = &au_sbi(sb)->si_wbr_mfs;
31523 + mutex_init(&mfs->mfs_lock);
31524 + mfs->mfs_jiffy = 0;
31525 + mfs->mfs_bindex = -EROFS;
31530 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
31532 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
31536 +/* ---------------------------------------------------------------------- */
31538 +/* most free space and then round robin */
31539 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
31542 + struct au_wbr_mfs *mfs;
31544 + err = au_wbr_create_mfs(dentry, flags);
31546 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
31547 + mutex_lock(&mfs->mfs_lock);
31548 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
31549 + err = au_wbr_create_rr(dentry, flags);
31550 + mutex_unlock(&mfs->mfs_lock);
31553 + AuDbg("b%d\n", err);
31557 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
31561 + au_wbr_create_init_mfs(sb); /* ignore */
31562 + err = au_wbr_create_init_rr(sb);
31567 +/* ---------------------------------------------------------------------- */
31569 +/* top down parent and most free space */
31570 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
31573 + unsigned long long b;
31574 + aufs_bindex_t bindex, bstart, bend;
31575 + struct super_block *sb;
31576 + struct dentry *parent, *h_parent;
31577 + struct au_branch *br;
31579 + err = au_wbr_create_tdp(dentry, flags);
31580 + if (unlikely(err < 0))
31582 + parent = dget_parent(dentry);
31583 + bstart = au_dbstart(parent);
31584 + bend = au_dbtaildir(parent);
31585 + if (bstart == bend)
31586 + goto out_parent; /* success */
31588 + e2 = au_wbr_create_mfs(dentry, flags);
31590 + goto out_parent; /* success */
31592 + /* when the available size is equal, select upper one */
31593 + sb = dentry->d_sb;
31594 + br = au_sbr(sb, err);
31595 + b = br->br_wbr->wbr_bytes;
31596 + AuDbg("b%d, %llu\n", err, b);
31598 + for (bindex = bstart; bindex <= bend; bindex++) {
31599 + h_parent = au_h_dptr(parent, bindex);
31600 + if (!h_parent || d_is_negative(h_parent))
31603 + br = au_sbr(sb, bindex);
31604 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
31605 + b = br->br_wbr->wbr_bytes;
31607 + AuDbg("b%d, %llu\n", err, b);
31612 + err = au_wbr_nonopq(dentry, err);
31617 + AuDbg("b%d\n", err);
31621 +/* ---------------------------------------------------------------------- */
31624 + * - top down parent
31625 + * - most free space with parent
31626 + * - most free space round-robin regardless parent
31628 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
31631 + unsigned long long watermark;
31632 + struct super_block *sb;
31633 + struct au_branch *br;
31634 + struct au_wbr_mfs *mfs;
31636 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
31637 + if (unlikely(err < 0))
31640 + sb = dentry->d_sb;
31641 + br = au_sbr(sb, err);
31642 + mfs = &au_sbi(sb)->si_wbr_mfs;
31643 + mutex_lock(&mfs->mfs_lock);
31644 + watermark = mfs->mfsrr_watermark;
31645 + mutex_unlock(&mfs->mfs_lock);
31646 + if (br->br_wbr->wbr_bytes < watermark)
31647 + /* regardless the parent dir */
31648 + err = au_wbr_create_mfsrr(dentry, flags);
31651 + AuDbg("b%d\n", err);
31655 +/* ---------------------------------------------------------------------- */
31657 +/* policies for copyup */
31659 +/* top down parent */
31660 +static int au_wbr_copyup_tdp(struct dentry *dentry)
31662 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
31665 +/* bottom up parent */
31666 +static int au_wbr_copyup_bup(struct dentry *dentry)
31669 + aufs_bindex_t bindex, bstart;
31670 + struct dentry *parent, *h_parent;
31671 + struct super_block *sb;
31674 + sb = dentry->d_sb;
31675 + parent = dget_parent(dentry);
31676 + bstart = au_dbstart(parent);
31677 + for (bindex = au_dbstart(dentry); bindex >= bstart; bindex--) {
31678 + h_parent = au_h_dptr(parent, bindex);
31679 + if (!h_parent || d_is_negative(h_parent))
31682 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31689 + /* bottom up here */
31690 + if (unlikely(err < 0))
31691 + err = au_wbr_bu(sb, bstart - 1);
31693 + AuDbg("b%d\n", err);
31698 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t bstart)
31702 + err = au_wbr_bu(dentry->d_sb, bstart);
31703 + AuDbg("b%d\n", err);
31704 + if (err > bstart)
31705 + err = au_wbr_nonopq(dentry, err);
31707 + AuDbg("b%d\n", err);
31711 +static int au_wbr_copyup_bu(struct dentry *dentry)
31714 + aufs_bindex_t bstart;
31716 + bstart = au_dbstart(dentry);
31717 + err = au_wbr_do_copyup_bu(dentry, bstart);
31721 +/* ---------------------------------------------------------------------- */
31723 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
31724 + [AuWbrCopyup_TDP] = {
31725 + .copyup = au_wbr_copyup_tdp
31727 + [AuWbrCopyup_BUP] = {
31728 + .copyup = au_wbr_copyup_bup
31730 + [AuWbrCopyup_BU] = {
31731 + .copyup = au_wbr_copyup_bu
31735 +struct au_wbr_create_operations au_wbr_create_ops[] = {
31736 + [AuWbrCreate_TDP] = {
31737 + .create = au_wbr_create_tdp
31739 + [AuWbrCreate_RR] = {
31740 + .create = au_wbr_create_rr,
31741 + .init = au_wbr_create_init_rr
31743 + [AuWbrCreate_MFS] = {
31744 + .create = au_wbr_create_mfs,
31745 + .init = au_wbr_create_init_mfs,
31746 + .fin = au_wbr_create_fin_mfs
31748 + [AuWbrCreate_MFSV] = {
31749 + .create = au_wbr_create_mfs,
31750 + .init = au_wbr_create_init_mfs,
31751 + .fin = au_wbr_create_fin_mfs
31753 + [AuWbrCreate_MFSRR] = {
31754 + .create = au_wbr_create_mfsrr,
31755 + .init = au_wbr_create_init_mfsrr,
31756 + .fin = au_wbr_create_fin_mfs
31758 + [AuWbrCreate_MFSRRV] = {
31759 + .create = au_wbr_create_mfsrr,
31760 + .init = au_wbr_create_init_mfsrr,
31761 + .fin = au_wbr_create_fin_mfs
31763 + [AuWbrCreate_PMFS] = {
31764 + .create = au_wbr_create_pmfs,
31765 + .init = au_wbr_create_init_mfs,
31766 + .fin = au_wbr_create_fin_mfs
31768 + [AuWbrCreate_PMFSV] = {
31769 + .create = au_wbr_create_pmfs,
31770 + .init = au_wbr_create_init_mfs,
31771 + .fin = au_wbr_create_fin_mfs
31773 + [AuWbrCreate_PMFSRR] = {
31774 + .create = au_wbr_create_pmfsrr,
31775 + .init = au_wbr_create_init_mfsrr,
31776 + .fin = au_wbr_create_fin_mfs
31778 + [AuWbrCreate_PMFSRRV] = {
31779 + .create = au_wbr_create_pmfsrr,
31780 + .init = au_wbr_create_init_mfsrr,
31781 + .fin = au_wbr_create_fin_mfs
31784 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
31785 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
31786 +++ linux/fs/aufs/whout.c 2015-09-24 10:47:58.258053165 +0200
31789 + * Copyright (C) 2005-2015 Junjiro R. Okajima
31791 + * This program, aufs is free software; you can redistribute it and/or modify
31792 + * it under the terms of the GNU General Public License as published by
31793 + * the Free Software Foundation; either version 2 of the License, or
31794 + * (at your option) any later version.
31796 + * This program is distributed in the hope that it will be useful,
31797 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31798 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31799 + * GNU General Public License for more details.
31801 + * You should have received a copy of the GNU General Public License
31802 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31806 + * whiteout for logical deletion and opaque directory
31811 +#define WH_MASK S_IRUGO
31814 + * If a directory contains this file, then it is opaque. We start with the
31815 + * .wh. flag so that it is blocked by lookup.
31817 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
31818 + sizeof(AUFS_WH_DIROPQ) - 1);
31821 + * generate whiteout name, which is NOT terminated by NULL.
31822 + * @name: original d_name.name
31823 + * @len: original d_name.len
31824 + * @wh: whiteout qstr
31825 + * returns zero when succeeds, otherwise error.
31826 + * succeeded value as wh->name should be freed by kfree().
31828 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
31832 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
31833 + return -ENAMETOOLONG;
31835 + wh->len = name->len + AUFS_WH_PFX_LEN;
31836 + p = kmalloc(wh->len, GFP_NOFS);
31839 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
31840 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
31847 +/* ---------------------------------------------------------------------- */
31850 + * test if the @wh_name exists under @h_parent.
31851 + * @try_sio specifies the necessary of super-io.
31853 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
31856 + struct dentry *wh_dentry;
31859 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
31861 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
31862 + err = PTR_ERR(wh_dentry);
31863 + if (IS_ERR(wh_dentry)) {
31864 + if (err == -ENAMETOOLONG)
31870 + if (d_is_negative(wh_dentry))
31871 + goto out_wh; /* success */
31874 + if (d_is_reg(wh_dentry))
31875 + goto out_wh; /* success */
31878 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
31879 + wh_dentry, d_inode(wh_dentry)->i_mode);
31888 + * test if the @h_dentry sets opaque or not.
31890 +int au_diropq_test(struct dentry *h_dentry)
31893 + struct inode *h_dir;
31895 + h_dir = d_inode(h_dentry);
31896 + err = au_wh_test(h_dentry, &diropq_name,
31897 + au_test_h_perm_sio(h_dir, MAY_EXEC));
31902 + * returns a negative dentry whose name is unique and temporary.
31904 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
31905 + struct qstr *prefix)
31907 + struct dentry *dentry;
31909 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
31911 + /* strict atomic_t is unnecessary here */
31912 + static unsigned short cnt;
31915 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
31918 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
31919 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
31920 + dentry = ERR_PTR(-ENAMETOOLONG);
31921 + if (unlikely(qs.len > NAME_MAX))
31923 + dentry = ERR_PTR(-ENOMEM);
31924 + name = kmalloc(qs.len + 1, GFP_NOFS);
31925 + if (unlikely(!name))
31929 + /* doubly whiteout-ed */
31930 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
31931 + p = name + AUFS_WH_PFX_LEN * 2;
31932 + memcpy(p, prefix->name, prefix->len);
31933 + p += prefix->len;
31935 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
31938 + for (i = 0; i < 3; i++) {
31939 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
31940 + dentry = au_sio_lkup_one(&qs, h_parent);
31941 + if (IS_ERR(dentry) || d_is_negative(dentry))
31945 + /* pr_warn("could not get random name\n"); */
31946 + dentry = ERR_PTR(-EEXIST);
31947 + AuDbg("%.*s\n", AuLNPair(&qs));
31951 + if (name != defname)
31954 + AuTraceErrPtr(dentry);
31959 + * rename the @h_dentry on @br to the whiteouted temporary name.
31961 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
31964 + struct path h_path = {
31965 + .mnt = au_br_mnt(br)
31967 + struct inode *h_dir, *delegated;
31968 + struct dentry *h_parent;
31970 + h_parent = h_dentry->d_parent; /* dir inode is locked */
31971 + h_dir = d_inode(h_parent);
31972 + IMustLock(h_dir);
31974 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
31975 + err = PTR_ERR(h_path.dentry);
31976 + if (IS_ERR(h_path.dentry))
31979 + /* under the same dir, no need to lock_rename() */
31980 + delegated = NULL;
31981 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
31983 + if (unlikely(err == -EWOULDBLOCK)) {
31984 + pr_warn("cannot retry for NFSv4 delegation"
31985 + " for an internal rename\n");
31988 + dput(h_path.dentry);
31995 +/* ---------------------------------------------------------------------- */
31997 + * functions for removing a whiteout
32000 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
32003 + struct inode *delegated;
32006 + * forces superio when the dir has a sticky bit.
32007 + * this may be a violation of unix fs semantics.
32009 + force = (h_dir->i_mode & S_ISVTX)
32010 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32011 + delegated = NULL;
32012 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32013 + if (unlikely(err == -EWOULDBLOCK)) {
32014 + pr_warn("cannot retry for NFSv4 delegation"
32015 + " for an internal unlink\n");
32021 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32022 + struct dentry *dentry)
32026 + err = do_unlink_wh(h_dir, h_path);
32027 + if (!err && dentry)
32028 + au_set_dbwh(dentry, -1);
32033 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32034 + struct au_branch *br)
32037 + struct path h_path = {
32038 + .mnt = au_br_mnt(br)
32042 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32043 + if (IS_ERR(h_path.dentry))
32044 + err = PTR_ERR(h_path.dentry);
32046 + if (d_is_reg(h_path.dentry))
32047 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32048 + dput(h_path.dentry);
32054 +/* ---------------------------------------------------------------------- */
32056 + * initialize/clean whiteout for a branch
32059 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32063 + struct inode *delegated;
32065 + if (d_is_negative(whpath->dentry))
32069 + err = vfsub_rmdir(h_dir, whpath);
32071 + delegated = NULL;
32072 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32073 + if (unlikely(err == -EWOULDBLOCK)) {
32074 + pr_warn("cannot retry for NFSv4 delegation"
32075 + " for an internal unlink\n");
32079 + if (unlikely(err))
32080 + pr_warn("failed removing %pd (%d), ignored.\n",
32081 + whpath->dentry, err);
32084 +static int test_linkable(struct dentry *h_root)
32086 + struct inode *h_dir = d_inode(h_root);
32088 + if (h_dir->i_op->link)
32091 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32092 + h_root, au_sbtype(h_root->d_sb));
32096 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32097 +static int au_whdir(struct inode *h_dir, struct path *path)
32102 + if (d_is_negative(path->dentry)) {
32103 + int mode = S_IRWXU;
32105 + if (au_test_nfs(path->dentry->d_sb))
32107 + err = vfsub_mkdir(h_dir, path, mode);
32108 + } else if (d_is_dir(path->dentry))
32111 + pr_err("unknown %pd exists\n", path->dentry);
32116 +struct au_wh_base {
32117 + const struct qstr *name;
32118 + struct dentry *dentry;
32121 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
32122 + struct path *h_path)
32124 + h_path->dentry = base[AuBrWh_BASE].dentry;
32125 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32126 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32127 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32128 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32129 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32133 + * returns tri-state,
32134 + * minus: error, caller should print the message
32136 + * plus: error, caller should NOT print the message
32138 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
32139 + int do_plink, struct au_wh_base base[],
32140 + struct path *h_path)
32143 + struct inode *h_dir;
32145 + h_dir = d_inode(h_root);
32146 + h_path->dentry = base[AuBrWh_BASE].dentry;
32147 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32148 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32150 + err = test_linkable(h_root);
32151 + if (unlikely(err)) {
32156 + err = au_whdir(h_dir, h_path);
32157 + if (unlikely(err))
32159 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32161 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32162 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32163 + err = au_whdir(h_dir, h_path);
32164 + if (unlikely(err))
32166 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32173 + * for the moment, aufs supports the branch filesystem which does not support
32174 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
32175 + * copyup failed. finally, such filesystem will not be used as the writable
32178 + * returns tri-state, see above.
32180 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
32181 + int do_plink, struct au_wh_base base[],
32182 + struct path *h_path)
32185 + struct inode *h_dir;
32187 + WbrWhMustWriteLock(wbr);
32189 + err = test_linkable(h_root);
32190 + if (unlikely(err)) {
32196 + * todo: should this create be done in /sbin/mount.aufs helper?
32199 + h_dir = d_inode(h_root);
32200 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
32201 + h_path->dentry = base[AuBrWh_BASE].dentry;
32202 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
32203 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
32206 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
32207 + if (unlikely(err))
32210 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32212 + err = au_whdir(h_dir, h_path);
32213 + if (unlikely(err))
32215 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32217 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32218 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
32220 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32221 + err = au_whdir(h_dir, h_path);
32222 + if (unlikely(err))
32224 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32231 + * initialize the whiteout base file/dir for @br.
32233 +int au_wh_init(struct au_branch *br, struct super_block *sb)
32236 + const unsigned char do_plink
32237 + = !!au_opt_test(au_mntflags(sb), PLINK);
32238 + struct inode *h_dir;
32239 + struct path path = br->br_path;
32240 + struct dentry *h_root = path.dentry;
32241 + struct au_wbr *wbr = br->br_wbr;
32242 + static const struct qstr base_name[] = {
32243 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
32244 + sizeof(AUFS_BASE_NAME) - 1),
32245 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
32246 + sizeof(AUFS_PLINKDIR_NAME) - 1),
32247 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
32248 + sizeof(AUFS_ORPHDIR_NAME) - 1)
32250 + struct au_wh_base base[] = {
32251 + [AuBrWh_BASE] = {
32252 + .name = base_name + AuBrWh_BASE,
32255 + [AuBrWh_PLINK] = {
32256 + .name = base_name + AuBrWh_PLINK,
32259 + [AuBrWh_ORPH] = {
32260 + .name = base_name + AuBrWh_ORPH,
32266 + WbrWhMustWriteLock(wbr);
32268 + for (i = 0; i < AuBrWh_Last; i++) {
32269 + /* doubly whiteouted */
32270 + struct dentry *d;
32272 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
32273 + err = PTR_ERR(d);
32277 + base[i].dentry = d;
32279 + && wbr->wbr_wh[i]
32280 + && wbr->wbr_wh[i] != base[i].dentry);
32284 + for (i = 0; i < AuBrWh_Last; i++) {
32285 + dput(wbr->wbr_wh[i]);
32286 + wbr->wbr_wh[i] = NULL;
32290 + if (!au_br_writable(br->br_perm)) {
32291 + h_dir = d_inode(h_root);
32292 + au_wh_init_ro(h_dir, base, &path);
32293 + } else if (!au_br_wh_linkable(br->br_perm)) {
32294 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
32300 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
32306 + goto out; /* success */
32309 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
32310 + err, h_root, au_sbtype(h_root->d_sb));
32312 + for (i = 0; i < AuBrWh_Last; i++)
32313 + dput(base[i].dentry);
32317 +/* ---------------------------------------------------------------------- */
32319 + * whiteouts are all hard-linked usually.
32320 + * when its link count reaches a ceiling, we create a new whiteout base
32321 + * asynchronously.
32324 +struct reinit_br_wh {
32325 + struct super_block *sb;
32326 + struct au_branch *br;
32329 +static void reinit_br_wh(void *arg)
32332 + aufs_bindex_t bindex;
32333 + struct path h_path;
32334 + struct reinit_br_wh *a = arg;
32335 + struct au_wbr *wbr;
32336 + struct inode *dir, *delegated;
32337 + struct dentry *h_root;
32338 + struct au_hinode *hdir;
32341 + wbr = a->br->br_wbr;
32342 + /* big aufs lock */
32343 + si_noflush_write_lock(a->sb);
32344 + if (!au_br_writable(a->br->br_perm))
32346 + bindex = au_br_index(a->sb, a->br->br_id);
32347 + if (unlikely(bindex < 0))
32350 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
32351 + dir = d_inode(a->sb->s_root);
32352 + hdir = au_hi(dir, bindex);
32353 + h_root = au_h_dptr(a->sb->s_root, bindex);
32354 + AuDebugOn(h_root != au_br_dentry(a->br));
32356 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32357 + wbr_wh_write_lock(wbr);
32358 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
32361 + h_path.dentry = wbr->wbr_whbase;
32362 + h_path.mnt = au_br_mnt(a->br);
32363 + delegated = NULL;
32364 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
32366 + if (unlikely(err == -EWOULDBLOCK)) {
32367 + pr_warn("cannot retry for NFSv4 delegation"
32368 + " for an internal unlink\n");
32372 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
32375 + dput(wbr->wbr_whbase);
32376 + wbr->wbr_whbase = NULL;
32378 + err = au_wh_init(a->br, a->sb);
32379 + wbr_wh_write_unlock(wbr);
32380 + au_hn_imtx_unlock(hdir);
32381 + di_read_unlock(a->sb->s_root, AuLock_IR);
32383 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
32387 + atomic_dec(&wbr->wbr_wh_running);
32388 + atomic_dec(&a->br->br_count);
32389 + si_write_unlock(a->sb);
32390 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
32392 + if (unlikely(err))
32393 + AuIOErr("err %d\n", err);
32396 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
32398 + int do_dec, wkq_err;
32399 + struct reinit_br_wh *arg;
32402 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
32405 + /* ignore ENOMEM */
32406 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
32409 + * dec(wh_running), kfree(arg) and dec(br_count)
32410 + * in reinit function
32414 + atomic_inc(&br->br_count);
32415 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
32416 + if (unlikely(wkq_err)) {
32417 + atomic_dec(&br->br_wbr->wbr_wh_running);
32418 + atomic_dec(&br->br_count);
32426 + atomic_dec(&br->br_wbr->wbr_wh_running);
32429 +/* ---------------------------------------------------------------------- */
32432 + * create the whiteout @wh.
32434 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
32435 + struct dentry *wh)
32438 + struct path h_path = {
32441 + struct au_branch *br;
32442 + struct au_wbr *wbr;
32443 + struct dentry *h_parent;
32444 + struct inode *h_dir, *delegated;
32446 + h_parent = wh->d_parent; /* dir inode is locked */
32447 + h_dir = d_inode(h_parent);
32448 + IMustLock(h_dir);
32450 + br = au_sbr(sb, bindex);
32451 + h_path.mnt = au_br_mnt(br);
32452 + wbr = br->br_wbr;
32453 + wbr_wh_read_lock(wbr);
32454 + if (wbr->wbr_whbase) {
32455 + delegated = NULL;
32456 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
32457 + if (unlikely(err == -EWOULDBLOCK)) {
32458 + pr_warn("cannot retry for NFSv4 delegation"
32459 + " for an internal link\n");
32462 + if (!err || err != -EMLINK)
32465 + /* link count full. re-initialize br_whbase. */
32466 + kick_reinit_br_wh(sb, br);
32469 + /* return this error in this context */
32470 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
32472 + au_fhsm_wrote(sb, bindex, /*force*/0);
32475 + wbr_wh_read_unlock(wbr);
32479 +/* ---------------------------------------------------------------------- */
32482 + * create or remove the diropq.
32484 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
32485 + unsigned int flags)
32487 + struct dentry *opq_dentry, *h_dentry;
32488 + struct super_block *sb;
32489 + struct au_branch *br;
32492 + sb = dentry->d_sb;
32493 + br = au_sbr(sb, bindex);
32494 + h_dentry = au_h_dptr(dentry, bindex);
32495 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
32496 + if (IS_ERR(opq_dentry))
32499 + if (au_ftest_diropq(flags, CREATE)) {
32500 + err = link_or_create_wh(sb, bindex, opq_dentry);
32502 + au_set_dbdiropq(dentry, bindex);
32503 + goto out; /* success */
32506 + struct path tmp = {
32507 + .dentry = opq_dentry,
32508 + .mnt = au_br_mnt(br)
32510 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
32512 + au_set_dbdiropq(dentry, -1);
32514 + dput(opq_dentry);
32515 + opq_dentry = ERR_PTR(err);
32518 + return opq_dentry;
32521 +struct do_diropq_args {
32522 + struct dentry **errp;
32523 + struct dentry *dentry;
32524 + aufs_bindex_t bindex;
32525 + unsigned int flags;
32528 +static void call_do_diropq(void *args)
32530 + struct do_diropq_args *a = args;
32531 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
32534 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32535 + unsigned int flags)
32537 + struct dentry *diropq, *h_dentry;
32539 + h_dentry = au_h_dptr(dentry, bindex);
32540 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
32541 + diropq = do_diropq(dentry, bindex, flags);
32544 + struct do_diropq_args args = {
32546 + .dentry = dentry,
32547 + .bindex = bindex,
32551 + wkq_err = au_wkq_wait(call_do_diropq, &args);
32552 + if (unlikely(wkq_err))
32553 + diropq = ERR_PTR(wkq_err);
32559 +/* ---------------------------------------------------------------------- */
32562 + * lookup whiteout dentry.
32563 + * @h_parent: lower parent dentry which must exist and be locked
32564 + * @base_name: name of dentry which will be whiteouted
32565 + * returns dentry for whiteout.
32567 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32568 + struct au_branch *br)
32571 + struct qstr wh_name;
32572 + struct dentry *wh_dentry;
32574 + err = au_wh_name_alloc(&wh_name, base_name);
32575 + wh_dentry = ERR_PTR(err);
32577 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
32578 + kfree(wh_name.name);
32580 + return wh_dentry;
32584 + * link/create a whiteout for @dentry on @bindex.
32586 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32587 + struct dentry *h_parent)
32589 + struct dentry *wh_dentry;
32590 + struct super_block *sb;
32593 + sb = dentry->d_sb;
32594 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
32595 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
32596 + err = link_or_create_wh(sb, bindex, wh_dentry);
32598 + au_set_dbwh(dentry, bindex);
32599 + au_fhsm_wrote(sb, bindex, /*force*/0);
32602 + wh_dentry = ERR_PTR(err);
32606 + return wh_dentry;
32609 +/* ---------------------------------------------------------------------- */
32611 +/* Delete all whiteouts in this directory on branch bindex. */
32612 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
32613 + aufs_bindex_t bindex, struct au_branch *br)
32616 + unsigned long ul, n;
32617 + struct qstr wh_name;
32619 + struct hlist_head *head;
32620 + struct au_vdir_wh *pos;
32621 + struct au_vdir_destr *str;
32624 + p = (void *)__get_free_page(GFP_NOFS);
32625 + wh_name.name = p;
32626 + if (unlikely(!wh_name.name))
32630 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32631 + p += AUFS_WH_PFX_LEN;
32632 + n = whlist->nh_num;
32633 + head = whlist->nh_head;
32634 + for (ul = 0; !err && ul < n; ul++, head++) {
32635 + hlist_for_each_entry(pos, head, wh_hash) {
32636 + if (pos->wh_bindex != bindex)
32639 + str = &pos->wh_str;
32640 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
32641 + memcpy(p, str->name, str->len);
32642 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
32643 + err = unlink_wh_name(h_dentry, &wh_name, br);
32648 + AuIOErr("whiteout name too long %.*s\n",
32649 + str->len, str->name);
32654 + free_page((unsigned long)wh_name.name);
32660 +struct del_wh_children_args {
32662 + struct dentry *h_dentry;
32663 + struct au_nhash *whlist;
32664 + aufs_bindex_t bindex;
32665 + struct au_branch *br;
32668 +static void call_del_wh_children(void *args)
32670 + struct del_wh_children_args *a = args;
32671 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
32674 +/* ---------------------------------------------------------------------- */
32676 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
32678 + struct au_whtmp_rmdir *whtmp;
32680 + unsigned int rdhash;
32682 + SiMustAnyLock(sb);
32684 + whtmp = kmalloc(sizeof(*whtmp), gfp);
32685 + if (unlikely(!whtmp)) {
32686 + whtmp = ERR_PTR(-ENOMEM);
32690 + whtmp->dir = NULL;
32691 + whtmp->br = NULL;
32692 + whtmp->wh_dentry = NULL;
32693 + /* no estimation for dir size */
32694 + rdhash = au_sbi(sb)->si_rdhash;
32696 + rdhash = AUFS_RDHASH_DEF;
32697 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
32698 + if (unlikely(err)) {
32700 + whtmp = ERR_PTR(err);
32707 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
32710 + atomic_dec(&whtmp->br->br_count);
32711 + dput(whtmp->wh_dentry);
32712 + iput(whtmp->dir);
32713 + au_nhash_wh_free(&whtmp->whlist);
32718 + * rmdir the whiteouted temporary named dir @h_dentry.
32719 + * @whlist: whiteouted children.
32721 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32722 + struct dentry *wh_dentry, struct au_nhash *whlist)
32725 + unsigned int h_nlink;
32726 + struct path h_tmp;
32727 + struct inode *wh_inode, *h_dir;
32728 + struct au_branch *br;
32730 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
32731 + IMustLock(h_dir);
32733 + br = au_sbr(dir->i_sb, bindex);
32734 + wh_inode = d_inode(wh_dentry);
32735 + mutex_lock_nested(&wh_inode->i_mutex, AuLsc_I_CHILD);
32738 + * someone else might change some whiteouts while we were sleeping.
32739 + * it means this whlist may have an obsoleted entry.
32741 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
32742 + err = del_wh_children(wh_dentry, whlist, bindex, br);
32745 + struct del_wh_children_args args = {
32747 + .h_dentry = wh_dentry,
32748 + .whlist = whlist,
32749 + .bindex = bindex,
32753 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
32754 + if (unlikely(wkq_err))
32757 + mutex_unlock(&wh_inode->i_mutex);
32760 + h_tmp.dentry = wh_dentry;
32761 + h_tmp.mnt = au_br_mnt(br);
32762 + h_nlink = h_dir->i_nlink;
32763 + err = vfsub_rmdir(h_dir, &h_tmp);
32764 + /* some fs doesn't change the parent nlink in some cases */
32765 + h_nlink -= h_dir->i_nlink;
32769 + if (au_ibstart(dir) == bindex) {
32770 + /* todo: dir->i_mutex is necessary */
32771 + au_cpup_attr_timesizes(dir);
32773 + vfsub_drop_nlink(dir);
32775 + return 0; /* success */
32778 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
32782 +static void call_rmdir_whtmp(void *args)
32785 + aufs_bindex_t bindex;
32786 + struct au_whtmp_rmdir *a = args;
32787 + struct super_block *sb;
32788 + struct dentry *h_parent;
32789 + struct inode *h_dir;
32790 + struct au_hinode *hdir;
32792 + /* rmdir by nfsd may cause deadlock with this i_mutex */
32793 + /* mutex_lock(&a->dir->i_mutex); */
32795 + sb = a->dir->i_sb;
32796 + si_read_lock(sb, !AuLock_FLUSH);
32797 + if (!au_br_writable(a->br->br_perm))
32799 + bindex = au_br_index(sb, a->br->br_id);
32800 + if (unlikely(bindex < 0))
32804 + ii_write_lock_parent(a->dir);
32805 + h_parent = dget_parent(a->wh_dentry);
32806 + h_dir = d_inode(h_parent);
32807 + hdir = au_hi(a->dir, bindex);
32808 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
32809 + if (unlikely(err))
32811 + au_hn_imtx_lock_nested(hdir, AuLsc_I_PARENT);
32812 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
32815 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
32816 + au_hn_imtx_unlock(hdir);
32817 + vfsub_mnt_drop_write(au_br_mnt(a->br));
32821 + ii_write_unlock(a->dir);
32823 + /* mutex_unlock(&a->dir->i_mutex); */
32824 + au_whtmp_rmdir_free(a);
32825 + si_read_unlock(sb);
32826 + au_nwt_done(&au_sbi(sb)->si_nowait);
32827 + if (unlikely(err))
32828 + AuIOErr("err %d\n", err);
32831 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32832 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
32835 + struct super_block *sb;
32839 + /* all post-process will be done in do_rmdir_whtmp(). */
32841 + args->dir = au_igrab(dir);
32842 + args->br = au_sbr(sb, bindex);
32843 + atomic_inc(&args->br->br_count);
32844 + args->wh_dentry = dget(wh_dentry);
32845 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
32846 + if (unlikely(wkq_err)) {
32847 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
32848 + au_whtmp_rmdir_free(args);
32851 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
32852 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
32853 +++ linux/fs/aufs/whout.h 2015-09-24 10:47:58.258053165 +0200
32856 + * Copyright (C) 2005-2015 Junjiro R. Okajima
32858 + * This program, aufs is free software; you can redistribute it and/or modify
32859 + * it under the terms of the GNU General Public License as published by
32860 + * the Free Software Foundation; either version 2 of the License, or
32861 + * (at your option) any later version.
32863 + * This program is distributed in the hope that it will be useful,
32864 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32865 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32866 + * GNU General Public License for more details.
32868 + * You should have received a copy of the GNU General Public License
32869 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32873 + * whiteout for logical deletion and opaque directory
32876 +#ifndef __AUFS_WHOUT_H__
32877 +#define __AUFS_WHOUT_H__
32884 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
32885 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
32886 +int au_diropq_test(struct dentry *h_dentry);
32888 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32889 + struct qstr *prefix);
32890 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
32891 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32892 + struct dentry *dentry);
32893 +int au_wh_init(struct au_branch *br, struct super_block *sb);
32895 +/* diropq flags */
32896 +#define AuDiropq_CREATE 1
32897 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
32898 +#define au_fset_diropq(flags, name) \
32899 + do { (flags) |= AuDiropq_##name; } while (0)
32900 +#define au_fclr_diropq(flags, name) \
32901 + do { (flags) &= ~AuDiropq_##name; } while (0)
32903 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32904 + unsigned int flags);
32905 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32906 + struct au_branch *br);
32907 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32908 + struct dentry *h_parent);
32910 +/* real rmdir for the whiteout-ed dir */
32911 +struct au_whtmp_rmdir {
32912 + struct inode *dir;
32913 + struct au_branch *br;
32914 + struct dentry *wh_dentry;
32915 + struct au_nhash whlist;
32918 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
32919 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
32920 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
32921 + struct dentry *wh_dentry, struct au_nhash *whlist);
32922 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
32923 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
32925 +/* ---------------------------------------------------------------------- */
32927 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
32928 + aufs_bindex_t bindex)
32930 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
32933 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
32935 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
32938 +#endif /* __KERNEL__ */
32939 +#endif /* __AUFS_WHOUT_H__ */
32940 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
32941 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
32942 +++ linux/fs/aufs/wkq.c 2015-09-24 10:47:58.258053165 +0200
32945 + * Copyright (C) 2005-2015 Junjiro R. Okajima
32947 + * This program, aufs is free software; you can redistribute it and/or modify
32948 + * it under the terms of the GNU General Public License as published by
32949 + * the Free Software Foundation; either version 2 of the License, or
32950 + * (at your option) any later version.
32952 + * This program is distributed in the hope that it will be useful,
32953 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32954 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32955 + * GNU General Public License for more details.
32957 + * You should have received a copy of the GNU General Public License
32958 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32962 + * workqueue for asynchronous/super-io operations
32963 + * todo: try new dredential scheme
32966 +#include <linux/module.h>
32969 +/* internal workqueue named AUFS_WKQ_NAME */
32971 +static struct workqueue_struct *au_wkq;
32973 +struct au_wkinfo {
32974 + struct work_struct wk;
32975 + struct kobject *kobj;
32977 + unsigned int flags; /* see wkq.h */
32979 + au_wkq_func_t func;
32982 + struct completion *comp;
32985 +/* ---------------------------------------------------------------------- */
32987 +static void wkq_func(struct work_struct *wk)
32989 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
32991 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
32992 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
32994 + wkinfo->func(wkinfo->args);
32995 + if (au_ftest_wkq(wkinfo->flags, WAIT))
32996 + complete(wkinfo->comp);
32998 + kobject_put(wkinfo->kobj);
32999 + module_put(THIS_MODULE); /* todo: ?? */
33005 + * Since struct completion is large, try allocating it dynamically.
33007 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
33008 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33010 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33012 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33014 + init_completion(*comp);
33015 + wkinfo->comp = *comp;
33021 +static void au_wkq_comp_free(struct completion *comp)
33029 +#define AuWkqCompDeclare(name) \
33030 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33031 + struct completion *comp = &_ ## name
33033 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33035 + wkinfo->comp = *comp;
33039 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33043 +#endif /* 4KSTACKS */
33045 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33047 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33048 + if (au_wkq_test()) {
33049 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33050 + " due to a dead dir by UDBA?\n");
33051 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33054 + au_dbg_verify_kthread();
33056 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33057 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33058 + queue_work(au_wkq, &wkinfo->wk);
33060 + INIT_WORK(&wkinfo->wk, wkq_func);
33061 + schedule_work(&wkinfo->wk);
33066 + * Be careful. It is easy to make deadlock happen.
33067 + * processA: lock, wkq and wait
33068 + * processB: wkq and wait, lock in wkq
33071 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33074 + AuWkqCompDeclare(comp);
33075 + struct au_wkinfo wkinfo = {
33081 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33083 + au_wkq_run(&wkinfo);
33084 + /* no timeout, no interrupt */
33085 + wait_for_completion(wkinfo.comp);
33086 + au_wkq_comp_free(comp);
33087 + destroy_work_on_stack(&wkinfo.wk);
33095 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33096 + * problem in a concurrent umounting.
33098 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33099 + unsigned int flags)
33102 + struct au_wkinfo *wkinfo;
33104 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
33107 + * wkq_func() must free this wkinfo.
33108 + * it highly depends upon the implementation of workqueue.
33111 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
33113 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
33114 + wkinfo->flags = flags & ~AuWkq_WAIT;
33115 + wkinfo->func = func;
33116 + wkinfo->args = args;
33117 + wkinfo->comp = NULL;
33118 + kobject_get(wkinfo->kobj);
33119 + __module_get(THIS_MODULE); /* todo: ?? */
33121 + au_wkq_run(wkinfo);
33124 + au_nwt_done(&au_sbi(sb)->si_nowait);
33130 +/* ---------------------------------------------------------------------- */
33132 +void au_nwt_init(struct au_nowait_tasks *nwt)
33134 + atomic_set(&nwt->nw_len, 0);
33135 + /* smp_mb(); */ /* atomic_set */
33136 + init_waitqueue_head(&nwt->nw_wq);
33139 +void au_wkq_fin(void)
33141 + destroy_workqueue(au_wkq);
33144 +int __init au_wkq_init(void)
33149 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
33150 + if (IS_ERR(au_wkq))
33151 + err = PTR_ERR(au_wkq);
33152 + else if (!au_wkq)
33157 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
33158 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
33159 +++ linux/fs/aufs/wkq.h 2015-09-24 10:47:58.258053165 +0200
33162 + * Copyright (C) 2005-2015 Junjiro R. Okajima
33164 + * This program, aufs is free software; you can redistribute it and/or modify
33165 + * it under the terms of the GNU General Public License as published by
33166 + * the Free Software Foundation; either version 2 of the License, or
33167 + * (at your option) any later version.
33169 + * This program is distributed in the hope that it will be useful,
33170 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33171 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33172 + * GNU General Public License for more details.
33174 + * You should have received a copy of the GNU General Public License
33175 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33179 + * workqueue for asynchronous/super-io operations
33180 + * todo: try new credentials management scheme
33183 +#ifndef __AUFS_WKQ_H__
33184 +#define __AUFS_WKQ_H__
33188 +struct super_block;
33190 +/* ---------------------------------------------------------------------- */
33193 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
33195 +struct au_nowait_tasks {
33197 + wait_queue_head_t nw_wq;
33200 +/* ---------------------------------------------------------------------- */
33202 +typedef void (*au_wkq_func_t)(void *args);
33205 +#define AuWkq_WAIT 1
33206 +#define AuWkq_NEST (1 << 1)
33207 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
33208 +#define au_fset_wkq(flags, name) \
33209 + do { (flags) |= AuWkq_##name; } while (0)
33210 +#define au_fclr_wkq(flags, name) \
33211 + do { (flags) &= ~AuWkq_##name; } while (0)
33213 +#ifndef CONFIG_AUFS_HNOTIFY
33215 +#define AuWkq_NEST 0
33219 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
33220 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33221 + unsigned int flags);
33222 +void au_nwt_init(struct au_nowait_tasks *nwt);
33223 +int __init au_wkq_init(void);
33224 +void au_wkq_fin(void);
33226 +/* ---------------------------------------------------------------------- */
33228 +static inline int au_wkq_test(void)
33230 + return current->flags & PF_WQ_WORKER;
33233 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
33235 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
33238 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
33240 + if (atomic_dec_and_test(&nwt->nw_len))
33241 + wake_up_all(&nwt->nw_wq);
33244 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
33246 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
33250 +#endif /* __KERNEL__ */
33251 +#endif /* __AUFS_WKQ_H__ */
33252 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
33253 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
33254 +++ linux/fs/aufs/xattr.c 2015-09-24 10:47:58.258053165 +0200
33257 + * Copyright (C) 2014-2015 Junjiro R. Okajima
33259 + * This program, aufs is free software; you can redistribute it and/or modify
33260 + * it under the terms of the GNU General Public License as published by
33261 + * the Free Software Foundation; either version 2 of the License, or
33262 + * (at your option) any later version.
33264 + * This program is distributed in the hope that it will be useful,
33265 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33266 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33267 + * GNU General Public License for more details.
33269 + * You should have received a copy of the GNU General Public License
33270 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33274 + * handling xattr functions
33277 +#include <linux/xattr.h>
33280 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
33282 + if (!ignore_flags)
33290 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
33295 +#define cmp(brattr, prefix) do { \
33296 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
33297 + XATTR_##prefix##_PREFIX_LEN)) { \
33298 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
33304 + cmp(SEC, SECURITY);
33305 + cmp(SYS, SYSTEM);
33306 + cmp(TR, TRUSTED);
33310 + if (ignore_flags & AuBrAttr_ICEX_OTH)
33317 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
33319 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
33320 + char *name, char **buf, unsigned int ignore_flags,
33321 + unsigned int verbose)
33325 + struct inode *h_idst;
33327 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
33329 + if (unlikely(err <= 0)) {
33330 + if (err == -ENODATA
33331 + || (err == -EOPNOTSUPP
33332 + && ((ignore_flags & au_xattr_out_of_list)
33333 + || (au_test_nfs_noacl(d_inode(h_src))
33334 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
33336 + XATTR_NAME_POSIX_ACL_DEFAULT))))
33339 + if (err && (verbose || au_debug_test()))
33340 + pr_err("%s, err %d\n", name, err);
33344 + /* unlock it temporary */
33345 + h_idst = d_inode(h_dst);
33346 + mutex_unlock(&h_idst->i_mutex);
33347 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
33348 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33349 + if (unlikely(err)) {
33350 + if (verbose || au_debug_test())
33351 + pr_err("%s, err %d\n", name, err);
33352 + err = au_xattr_ignore(err, name, ignore_flags);
33359 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
33360 + unsigned int verbose)
33362 + int err, unlocked, acl_access, acl_default;
33364 + struct inode *h_isrc, *h_idst;
33365 + char *value, *p, *o, *e;
33367 + /* try stopping to update the source inode while we are referencing */
33368 + /* there should not be the parent-child relationship between them */
33369 + h_isrc = d_inode(h_src);
33370 + h_idst = d_inode(h_dst);
33371 + mutex_unlock(&h_idst->i_mutex);
33372 + mutex_lock_nested(&h_isrc->i_mutex, AuLsc_I_CHILD);
33373 + mutex_lock_nested(&h_idst->i_mutex, AuLsc_I_CHILD2);
33376 + /* some filesystems don't list POSIX ACL, for example tmpfs */
33377 + ssz = vfs_listxattr(h_src, NULL, 0);
33379 + if (unlikely(err < 0)) {
33381 + if (err == -ENODATA
33382 + || err == -EOPNOTSUPP)
33383 + err = 0; /* ignore */
33392 + p = kmalloc(ssz, GFP_NOFS);
33394 + if (unlikely(!p))
33396 + err = vfs_listxattr(h_src, p, ssz);
33398 + mutex_unlock(&h_isrc->i_mutex);
33400 + AuDbg("err %d, ssz %zd\n", err, ssz);
33401 + if (unlikely(err < 0))
33409 + while (!err && p < e) {
33410 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
33411 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
33412 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
33413 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
33415 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
33417 + p += strlen(p) + 1;
33420 + ignore_flags |= au_xattr_out_of_list;
33421 + if (!err && !acl_access) {
33422 + err = au_do_cpup_xattr(h_dst, h_src,
33423 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
33424 + ignore_flags, verbose);
33427 + if (!err && !acl_default) {
33428 + err = au_do_cpup_xattr(h_dst, h_src,
33429 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
33430 + ignore_flags, verbose);
33440 + mutex_unlock(&h_isrc->i_mutex);
33445 +/* ---------------------------------------------------------------------- */
33452 +struct au_lgxattr {
33460 + const char *name;
33467 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
33470 + struct path h_path;
33471 + struct super_block *sb;
33473 + sb = dentry->d_sb;
33474 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
33475 + if (unlikely(err))
33477 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
33478 + if (unlikely(err))
33480 + if (unlikely(!h_path.dentry))
33481 + /* illegally overlapped or something */
33482 + goto out_di; /* pretending success */
33484 + /* always topmost entry only */
33485 + switch (arg->type) {
33486 + case AU_XATTR_LIST:
33487 + err = vfs_listxattr(h_path.dentry,
33488 + arg->u.list.list, arg->u.list.size);
33490 + case AU_XATTR_GET:
33491 + err = vfs_getxattr(h_path.dentry,
33492 + arg->u.get.name, arg->u.get.value,
33493 + arg->u.get.size);
33498 + di_read_unlock(dentry, AuLock_IR);
33500 + si_read_unlock(sb);
33506 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
33508 + struct au_lgxattr arg = {
33509 + .type = AU_XATTR_LIST,
33516 + return au_lgxattr(dentry, &arg);
33519 +ssize_t aufs_getxattr(struct dentry *dentry, const char *name, void *value,
33522 + struct au_lgxattr arg = {
33523 + .type = AU_XATTR_GET,
33531 + return au_lgxattr(dentry, &arg);
33534 +int aufs_setxattr(struct dentry *dentry, const char *name, const void *value,
33535 + size_t size, int flags)
33537 + struct au_srxattr arg = {
33538 + .type = AU_XATTR_SET,
33547 + return au_srxattr(dentry, &arg);
33550 +int aufs_removexattr(struct dentry *dentry, const char *name)
33552 + struct au_srxattr arg = {
33553 + .type = AU_XATTR_REMOVE,
33559 + return au_srxattr(dentry, &arg);
33562 +/* ---------------------------------------------------------------------- */
33565 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
33566 + const char *name, size_t name_len, int type)
33568 + return aufs_listxattr(dentry, list, list_size);
33571 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
33572 + size_t size, int type)
33574 + return aufs_getxattr(dentry, name, buffer, size);
33577 +static int au_xattr_set(struct dentry *dentry, const char *name,
33578 + const void *value, size_t size, int flags, int type)
33580 + return aufs_setxattr(dentry, name, value, size, flags);
33583 +static const struct xattr_handler au_xattr_handler = {
33584 + /* no prefix, no flags */
33585 + .list = au_xattr_list,
33586 + .get = au_xattr_get,
33587 + .set = au_xattr_set
33588 + /* why no remove? */
33591 +static const struct xattr_handler *au_xattr_handlers[] = {
33592 + &au_xattr_handler
33595 +void au_xattr_init(struct super_block *sb)
33597 + /* sb->s_xattr = au_xattr_handlers; */
33600 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
33601 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
33602 +++ linux/fs/aufs/xino.c 2015-09-24 10:47:58.258053165 +0200
33605 + * Copyright (C) 2005-2015 Junjiro R. Okajima
33607 + * This program, aufs is free software; you can redistribute it and/or modify
33608 + * it under the terms of the GNU General Public License as published by
33609 + * the Free Software Foundation; either version 2 of the License, or
33610 + * (at your option) any later version.
33612 + * This program is distributed in the hope that it will be useful,
33613 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33614 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33615 + * GNU General Public License for more details.
33617 + * You should have received a copy of the GNU General Public License
33618 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33622 + * external inode number translation table and bitmap
33625 +#include <linux/seq_file.h>
33626 +#include <linux/statfs.h>
33629 +/* todo: unnecessary to support mmap_sem since kernel-space? */
33630 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
33634 + mm_segment_t oldfs;
33641 + oldfs = get_fs();
33642 + set_fs(KERNEL_DS);
33644 + /* todo: signal_pending? */
33645 + err = func(file, buf.u, size, pos);
33646 + } while (err == -EAGAIN || err == -EINTR);
33649 +#if 0 /* reserved for future use */
33651 + fsnotify_access(file->f_path.dentry);
33657 +/* ---------------------------------------------------------------------- */
33659 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
33660 + size_t size, loff_t *pos)
33663 + mm_segment_t oldfs;
33666 + const char __user *u;
33670 + oldfs = get_fs();
33671 + set_fs(KERNEL_DS);
33673 + /* todo: signal_pending? */
33674 + err = func(file, buf.u, size, pos);
33675 + } while (err == -EAGAIN || err == -EINTR);
33678 +#if 0 /* reserved for future use */
33680 + fsnotify_modify(file->f_path.dentry);
33686 +struct do_xino_fwrite_args {
33688 + vfs_writef_t func;
33689 + struct file *file;
33695 +static void call_do_xino_fwrite(void *args)
33697 + struct do_xino_fwrite_args *a = args;
33698 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
33701 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
33702 + size_t size, loff_t *pos)
33706 + /* todo: signal block and no wkq? */
33707 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
33709 + err = do_xino_fwrite(func, file, buf, size, pos);
33713 + * it breaks RLIMIT_FSIZE and normal user's limit,
33714 + * users should care about quota and real 'filesystem full.'
33717 + struct do_xino_fwrite_args args = {
33726 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
33727 + if (unlikely(wkq_err))
33734 +/* ---------------------------------------------------------------------- */
33737 + * create a new xinofile at the same place/path as @base_file.
33739 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
33741 + struct file *file;
33742 + struct dentry *base, *parent;
33743 + struct inode *dir, *delegated;
33744 + struct qstr *name;
33745 + struct path path;
33748 + base = base_file->f_path.dentry;
33749 + parent = base->d_parent; /* dir inode is locked */
33750 + dir = d_inode(parent);
33753 + file = ERR_PTR(-EINVAL);
33754 + name = &base->d_name;
33755 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
33756 + if (IS_ERR(path.dentry)) {
33757 + file = (void *)path.dentry;
33758 + pr_err("%pd lookup err %ld\n",
33759 + base, PTR_ERR(path.dentry));
33763 + /* no need to mnt_want_write() since we call dentry_open() later */
33764 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
33765 + if (unlikely(err)) {
33766 + file = ERR_PTR(err);
33767 + pr_err("%pd create err %d\n", base, err);
33771 + path.mnt = base_file->f_path.mnt;
33772 + file = vfsub_dentry_open(&path,
33773 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
33774 + /* | __FMODE_NONOTIFY */);
33775 + if (IS_ERR(file)) {
33776 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
33780 + delegated = NULL;
33781 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
33782 + if (unlikely(err == -EWOULDBLOCK)) {
33783 + pr_warn("cannot retry for NFSv4 delegation"
33784 + " for an internal unlink\n");
33787 + if (unlikely(err)) {
33788 + pr_err("%pd unlink err %d\n", base, err);
33793 + /* no one can touch copy_src xino */
33794 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
33795 + if (unlikely(err)) {
33796 + pr_err("%pd copy err %d\n", base, err);
33800 + goto out_dput; /* success */
33804 + file = ERR_PTR(err);
33806 + dput(path.dentry);
33811 +struct au_xino_lock_dir {
33812 + struct au_hinode *hdir;
33813 + struct dentry *parent;
33814 + struct mutex *mtx;
33817 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
33818 + struct au_xino_lock_dir *ldir)
33820 + aufs_bindex_t brid, bindex;
33822 + ldir->hdir = NULL;
33824 + brid = au_xino_brid(sb);
33826 + bindex = au_br_index(sb, brid);
33827 + if (bindex >= 0) {
33828 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
33829 + au_hn_imtx_lock_nested(ldir->hdir, AuLsc_I_PARENT);
33831 + ldir->parent = dget_parent(xino->f_path.dentry);
33832 + ldir->mtx = &d_inode(ldir->parent)->i_mutex;
33833 + mutex_lock_nested(ldir->mtx, AuLsc_I_PARENT);
33837 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
33840 + au_hn_imtx_unlock(ldir->hdir);
33842 + mutex_unlock(ldir->mtx);
33843 + dput(ldir->parent);
33847 +/* ---------------------------------------------------------------------- */
33849 +/* trucate xino files asynchronously */
33851 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
33854 + unsigned long jiffy;
33856 + aufs_bindex_t bi, bend;
33857 + struct kstatfs *st;
33858 + struct au_branch *br;
33859 + struct file *new_xino, *file;
33860 + struct super_block *h_sb;
33861 + struct au_xino_lock_dir ldir;
33864 + st = kzalloc(sizeof(*st), GFP_NOFS);
33865 + if (unlikely(!st))
33869 + bend = au_sbend(sb);
33870 + if (unlikely(bindex < 0 || bend < bindex))
33872 + br = au_sbr(sb, bindex);
33873 + file = br->br_xino.xi_file;
33877 + err = vfs_statfs(&file->f_path, st);
33878 + if (unlikely(err))
33879 + AuErr1("statfs err %d, ignored\n", err);
33881 + blocks = file_inode(file)->i_blocks;
33882 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33883 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
33885 + au_xino_lock_dir(sb, file, &ldir);
33886 + /* mnt_want_write() is unnecessary here */
33887 + new_xino = au_xino_create2(file, file);
33888 + au_xino_unlock_dir(&ldir);
33889 + err = PTR_ERR(new_xino);
33890 + if (IS_ERR(new_xino)) {
33891 + pr_err("err %d, ignored\n", err);
33896 + br->br_xino.xi_file = new_xino;
33898 + h_sb = au_br_sb(br);
33899 + for (bi = 0; bi <= bend; bi++) {
33900 + if (unlikely(bi == bindex))
33902 + br = au_sbr(sb, bi);
33903 + if (au_br_sb(br) != h_sb)
33906 + fput(br->br_xino.xi_file);
33907 + br->br_xino.xi_file = new_xino;
33908 + get_file(new_xino);
33911 + err = vfs_statfs(&new_xino->f_path, st);
33913 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
33914 + bindex, (u64)file_inode(new_xino)->i_blocks,
33915 + st->f_bfree, st->f_blocks);
33916 + if (file_inode(new_xino)->i_blocks < blocks)
33917 + au_sbi(sb)->si_xino_jiffy = jiffy;
33919 + AuErr1("statfs err %d, ignored\n", err);
33927 +struct xino_do_trunc_args {
33928 + struct super_block *sb;
33929 + struct au_branch *br;
33932 +static void xino_do_trunc(void *_args)
33934 + struct xino_do_trunc_args *args = _args;
33935 + struct super_block *sb;
33936 + struct au_branch *br;
33937 + struct inode *dir;
33939 + aufs_bindex_t bindex;
33943 + dir = d_inode(sb->s_root);
33946 + si_noflush_write_lock(sb);
33947 + ii_read_lock_parent(dir);
33948 + bindex = au_br_index(sb, br->br_id);
33949 + err = au_xino_trunc(sb, bindex);
33950 + ii_read_unlock(dir);
33951 + if (unlikely(err))
33952 + pr_warn("err b%d, (%d)\n", bindex, err);
33953 + atomic_dec(&br->br_xino_running);
33954 + atomic_dec(&br->br_count);
33955 + si_write_unlock(sb);
33956 + au_nwt_done(&au_sbi(sb)->si_nowait);
33960 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
33963 + struct kstatfs st;
33964 + struct au_sbinfo *sbinfo;
33966 + /* todo: si_xino_expire and the ratio should be customizable */
33967 + sbinfo = au_sbi(sb);
33968 + if (time_before(jiffies,
33969 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
33972 + /* truncation border */
33973 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
33974 + if (unlikely(err)) {
33975 + AuErr1("statfs err %d, ignored\n", err);
33978 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
33984 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
33986 + struct xino_do_trunc_args *args;
33989 + if (!xino_trunc_test(sb, br))
33992 + if (atomic_inc_return(&br->br_xino_running) > 1)
33995 + /* lock and kfree() will be called in trunc_xino() */
33996 + args = kmalloc(sizeof(*args), GFP_NOFS);
33997 + if (unlikely(!args)) {
33998 + AuErr1("no memory\n");
34002 + atomic_inc(&br->br_count);
34005 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
34007 + return; /* success */
34009 + pr_err("wkq %d\n", wkq_err);
34010 + atomic_dec(&br->br_count);
34015 + atomic_dec(&br->br_xino_running);
34018 +/* ---------------------------------------------------------------------- */
34020 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34021 + ino_t h_ino, ino_t ino)
34027 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34028 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34031 + pos *= sizeof(ino);
34032 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34033 + if (sz == sizeof(ino))
34034 + return 0; /* success */
34036 + AuIOErr("write failed (%zd)\n", sz);
34041 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34042 + * at the position of @h_ino.
34043 + * even if @ino is zero, it is written to the xinofile and means no entry.
34044 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34045 + * try truncating it.
34047 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34051 + unsigned int mnt_flags;
34052 + struct au_branch *br;
34054 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34055 + || ((loff_t)-1) > 0);
34056 + SiMustAnyLock(sb);
34058 + mnt_flags = au_mntflags(sb);
34059 + if (!au_opt_test(mnt_flags, XINO))
34062 + br = au_sbr(sb, bindex);
34063 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34066 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34067 + && au_test_fs_trunc_xino(au_br_sb(br)))
34068 + xino_try_trunc(sb, br);
34069 + return 0; /* success */
34072 + AuIOErr("write failed (%d)\n", err);
34076 +/* ---------------------------------------------------------------------- */
34078 +/* aufs inode number bitmap */
34080 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
34081 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
34085 + AuDebugOn(bit < 0 || page_bits <= bit);
34086 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
34090 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
34092 + AuDebugOn(ino < AUFS_FIRST_INO);
34093 + ino -= AUFS_FIRST_INO;
34094 + *pindex = ino / page_bits;
34095 + *bit = ino % page_bits;
34098 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
34103 + struct au_sbinfo *sbinfo;
34104 + struct file *xib;
34105 + unsigned long *p;
34107 + sbinfo = au_sbi(sb);
34108 + MtxMustLock(&sbinfo->si_xib_mtx);
34109 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
34110 + || !au_opt_test(sbinfo->si_mntflags, XINO));
34112 + if (pindex == sbinfo->si_xib_last_pindex)
34115 + xib = sbinfo->si_xib;
34116 + p = sbinfo->si_xib_buf;
34117 + pos = sbinfo->si_xib_last_pindex;
34118 + pos *= PAGE_SIZE;
34119 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34120 + if (unlikely(sz != PAGE_SIZE))
34124 + pos *= PAGE_SIZE;
34125 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
34126 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
34128 + memset(p, 0, PAGE_SIZE);
34129 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34131 + if (sz == PAGE_SIZE) {
34132 + sbinfo->si_xib_last_pindex = pindex;
34133 + return 0; /* success */
34137 + AuIOErr1("write failed (%zd)\n", sz);
34144 +/* ---------------------------------------------------------------------- */
34146 +static void au_xib_clear_bit(struct inode *inode)
34149 + unsigned long pindex;
34150 + struct super_block *sb;
34151 + struct au_sbinfo *sbinfo;
34153 + AuDebugOn(inode->i_nlink);
34155 + sb = inode->i_sb;
34156 + xib_calc_bit(inode->i_ino, &pindex, &bit);
34157 + AuDebugOn(page_bits <= bit);
34158 + sbinfo = au_sbi(sb);
34159 + mutex_lock(&sbinfo->si_xib_mtx);
34160 + err = xib_pindex(sb, pindex);
34162 + clear_bit(bit, sbinfo->si_xib_buf);
34163 + sbinfo->si_xib_next_bit = bit;
34165 + mutex_unlock(&sbinfo->si_xib_mtx);
34168 +/* for s_op->delete_inode() */
34169 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
34172 + unsigned int mnt_flags;
34173 + aufs_bindex_t bindex, bend, bi;
34174 + unsigned char try_trunc;
34175 + struct au_iinfo *iinfo;
34176 + struct super_block *sb;
34177 + struct au_hinode *hi;
34178 + struct inode *h_inode;
34179 + struct au_branch *br;
34180 + vfs_writef_t xwrite;
34182 + sb = inode->i_sb;
34183 + mnt_flags = au_mntflags(sb);
34184 + if (!au_opt_test(mnt_flags, XINO)
34185 + || inode->i_ino == AUFS_ROOT_INO)
34189 + au_xigen_inc(inode);
34190 + au_xib_clear_bit(inode);
34193 + iinfo = au_ii(inode);
34197 + bindex = iinfo->ii_bstart;
34201 + xwrite = au_sbi(sb)->si_xwrite;
34202 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
34203 + hi = iinfo->ii_hinode + bindex;
34204 + bend = iinfo->ii_bend;
34205 + for (; bindex <= bend; bindex++, hi++) {
34206 + h_inode = hi->hi_inode;
34208 + || (!unlinked && h_inode->i_nlink))
34211 + /* inode may not be revalidated */
34212 + bi = au_br_index(sb, hi->hi_id);
34216 + br = au_sbr(sb, bi);
34217 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
34218 + h_inode->i_ino, /*ino*/0);
34219 + if (!err && try_trunc
34220 + && au_test_fs_trunc_xino(au_br_sb(br)))
34221 + xino_try_trunc(sb, br);
34225 +/* get an unused inode number from bitmap */
34226 +ino_t au_xino_new_ino(struct super_block *sb)
34229 + unsigned long *p, pindex, ul, pend;
34230 + struct au_sbinfo *sbinfo;
34231 + struct file *file;
34232 + int free_bit, err;
34234 + if (!au_opt_test(au_mntflags(sb), XINO))
34235 + return iunique(sb, AUFS_FIRST_INO);
34237 + sbinfo = au_sbi(sb);
34238 + mutex_lock(&sbinfo->si_xib_mtx);
34239 + p = sbinfo->si_xib_buf;
34240 + free_bit = sbinfo->si_xib_next_bit;
34241 + if (free_bit < page_bits && !test_bit(free_bit, p))
34242 + goto out; /* success */
34243 + free_bit = find_first_zero_bit(p, page_bits);
34244 + if (free_bit < page_bits)
34245 + goto out; /* success */
34247 + pindex = sbinfo->si_xib_last_pindex;
34248 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
34249 + err = xib_pindex(sb, ul);
34250 + if (unlikely(err))
34252 + free_bit = find_first_zero_bit(p, page_bits);
34253 + if (free_bit < page_bits)
34254 + goto out; /* success */
34257 + file = sbinfo->si_xib;
34258 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
34259 + for (ul = pindex + 1; ul <= pend; ul++) {
34260 + err = xib_pindex(sb, ul);
34261 + if (unlikely(err))
34263 + free_bit = find_first_zero_bit(p, page_bits);
34264 + if (free_bit < page_bits)
34265 + goto out; /* success */
34270 + set_bit(free_bit, p);
34271 + sbinfo->si_xib_next_bit = free_bit + 1;
34272 + pindex = sbinfo->si_xib_last_pindex;
34273 + mutex_unlock(&sbinfo->si_xib_mtx);
34274 + ino = xib_calc_ino(pindex, free_bit);
34275 + AuDbg("i%lu\n", (unsigned long)ino);
34278 + mutex_unlock(&sbinfo->si_xib_mtx);
34284 + * read @ino from xinofile for the specified branch{@sb, @bindex}
34285 + * at the position of @h_ino.
34286 + * if @ino does not exist and @do_new is true, get new one.
34288 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34294 + struct file *file;
34295 + struct au_sbinfo *sbinfo;
34298 + if (!au_opt_test(au_mntflags(sb), XINO))
34299 + return 0; /* no xino */
34302 + sbinfo = au_sbi(sb);
34304 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
34305 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34308 + pos *= sizeof(*ino);
34310 + file = au_sbr(sb, bindex)->br_xino.xi_file;
34311 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
34312 + return 0; /* no ino */
34314 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
34315 + if (sz == sizeof(*ino))
34316 + return 0; /* success */
34319 + if (unlikely(sz >= 0)) {
34321 + AuIOErr("xino read error (%zd)\n", sz);
34327 +/* ---------------------------------------------------------------------- */
34329 +/* create and set a new xino file */
34331 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
34333 + struct file *file;
34334 + struct dentry *h_parent, *d;
34335 + struct inode *h_dir, *inode;
34339 + * at mount-time, and the xino file is the default path,
34340 + * hnotify is disabled so we have no notify events to ignore.
34341 + * when a user specified the xino, we cannot get au_hdir to be ignored.
34343 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34344 + /* | __FMODE_NONOTIFY */,
34345 + S_IRUGO | S_IWUGO);
34346 + if (IS_ERR(file)) {
34348 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
34352 + /* keep file count */
34354 + inode = file_inode(file);
34355 + h_parent = dget_parent(file->f_path.dentry);
34356 + h_dir = d_inode(h_parent);
34357 + mutex_lock_nested(&h_dir->i_mutex, AuLsc_I_PARENT);
34358 + /* mnt_want_write() is unnecessary here */
34359 + /* no delegation since it is just created */
34360 + if (inode->i_nlink)
34361 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
34363 + mutex_unlock(&h_dir->i_mutex);
34365 + if (unlikely(err)) {
34367 + pr_err("unlink %s(%d)\n", fname, err);
34372 + d = file->f_path.dentry;
34373 + if (unlikely(sb == d->d_sb)) {
34375 + pr_err("%s must be outside\n", fname);
34378 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
34380 + pr_err("xino doesn't support %s(%s)\n",
34381 + fname, au_sbtype(d->d_sb));
34384 + return file; /* success */
34388 + file = ERR_PTR(err);
34393 + * find another branch who is on the same filesystem of the specified
34394 + * branch{@btgt}. search until @bend.
34396 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
34397 + aufs_bindex_t bend)
34399 + aufs_bindex_t bindex;
34400 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
34402 + for (bindex = 0; bindex < btgt; bindex++)
34403 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34405 + for (bindex++; bindex <= bend; bindex++)
34406 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34411 +/* ---------------------------------------------------------------------- */
34414 + * initialize the xinofile for the specified branch @br
34415 + * at the place/path where @base_file indicates.
34416 + * test whether another branch is on the same filesystem or not,
34417 + * if @do_test is true.
34419 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
34420 + struct file *base_file, int do_test)
34424 + aufs_bindex_t bend, bindex;
34425 + struct au_branch *shared_br, *b;
34426 + struct file *file;
34427 + struct super_block *tgt_sb;
34429 + shared_br = NULL;
34430 + bend = au_sbend(sb);
34432 + tgt_sb = au_br_sb(br);
34433 + for (bindex = 0; bindex <= bend; bindex++) {
34434 + b = au_sbr(sb, bindex);
34435 + if (tgt_sb == au_br_sb(b)) {
34442 + if (!shared_br || !shared_br->br_xino.xi_file) {
34443 + struct au_xino_lock_dir ldir;
34445 + au_xino_lock_dir(sb, base_file, &ldir);
34446 + /* mnt_want_write() is unnecessary here */
34447 + file = au_xino_create2(base_file, NULL);
34448 + au_xino_unlock_dir(&ldir);
34449 + err = PTR_ERR(file);
34450 + if (IS_ERR(file))
34452 + br->br_xino.xi_file = file;
34454 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
34455 + get_file(br->br_xino.xi_file);
34458 + ino = AUFS_ROOT_INO;
34459 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34461 + if (unlikely(err)) {
34462 + fput(br->br_xino.xi_file);
34463 + br->br_xino.xi_file = NULL;
34470 +/* ---------------------------------------------------------------------- */
34472 +/* trucate a xino bitmap file */
34475 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
34479 + unsigned long pindex;
34480 + loff_t pos, pend;
34481 + struct au_sbinfo *sbinfo;
34482 + vfs_readf_t func;
34484 + unsigned long *p;
34487 + sbinfo = au_sbi(sb);
34488 + MtxMustLock(&sbinfo->si_xib_mtx);
34489 + p = sbinfo->si_xib_buf;
34490 + func = sbinfo->si_xread;
34491 + pend = vfsub_f_size_read(file);
34493 + while (pos < pend) {
34494 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
34496 + if (unlikely(sz <= 0))
34500 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
34501 + if (unlikely(*ino < AUFS_FIRST_INO))
34504 + xib_calc_bit(*ino, &pindex, &bit);
34505 + AuDebugOn(page_bits <= bit);
34506 + err = xib_pindex(sb, pindex);
34518 +static int xib_restore(struct super_block *sb)
34521 + aufs_bindex_t bindex, bend;
34525 + page = (void *)__get_free_page(GFP_NOFS);
34526 + if (unlikely(!page))
34530 + bend = au_sbend(sb);
34531 + for (bindex = 0; !err && bindex <= bend; bindex++)
34532 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
34533 + err = do_xib_restore
34534 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
34536 + AuDbg("b%d\n", bindex);
34537 + free_page((unsigned long)page);
34543 +int au_xib_trunc(struct super_block *sb)
34548 + struct au_xino_lock_dir ldir;
34549 + struct au_sbinfo *sbinfo;
34550 + unsigned long *p;
34551 + struct file *file;
34553 + SiMustWriteLock(sb);
34556 + sbinfo = au_sbi(sb);
34557 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
34560 + file = sbinfo->si_xib;
34561 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
34564 + au_xino_lock_dir(sb, file, &ldir);
34565 + /* mnt_want_write() is unnecessary here */
34566 + file = au_xino_create2(sbinfo->si_xib, NULL);
34567 + au_xino_unlock_dir(&ldir);
34568 + err = PTR_ERR(file);
34569 + if (IS_ERR(file))
34571 + fput(sbinfo->si_xib);
34572 + sbinfo->si_xib = file;
34574 + p = sbinfo->si_xib_buf;
34575 + memset(p, 0, PAGE_SIZE);
34577 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
34578 + if (unlikely(sz != PAGE_SIZE)) {
34580 + AuIOErr("err %d\n", err);
34586 + mutex_lock(&sbinfo->si_xib_mtx);
34587 + /* mnt_want_write() is unnecessary here */
34588 + err = xib_restore(sb);
34589 + mutex_unlock(&sbinfo->si_xib_mtx);
34595 +/* ---------------------------------------------------------------------- */
34598 + * xino mount option handlers
34602 +static void xino_clear_xib(struct super_block *sb)
34604 + struct au_sbinfo *sbinfo;
34606 + SiMustWriteLock(sb);
34608 + sbinfo = au_sbi(sb);
34609 + sbinfo->si_xread = NULL;
34610 + sbinfo->si_xwrite = NULL;
34611 + if (sbinfo->si_xib)
34612 + fput(sbinfo->si_xib);
34613 + sbinfo->si_xib = NULL;
34614 + free_page((unsigned long)sbinfo->si_xib_buf);
34615 + sbinfo->si_xib_buf = NULL;
34618 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
34622 + struct au_sbinfo *sbinfo;
34623 + struct file *file;
34625 + SiMustWriteLock(sb);
34627 + sbinfo = au_sbi(sb);
34628 + file = au_xino_create2(base, sbinfo->si_xib);
34629 + err = PTR_ERR(file);
34630 + if (IS_ERR(file))
34632 + if (sbinfo->si_xib)
34633 + fput(sbinfo->si_xib);
34634 + sbinfo->si_xib = file;
34635 + sbinfo->si_xread = vfs_readf(file);
34636 + sbinfo->si_xwrite = vfs_writef(file);
34639 + if (!sbinfo->si_xib_buf)
34640 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
34641 + if (unlikely(!sbinfo->si_xib_buf))
34644 + sbinfo->si_xib_last_pindex = 0;
34645 + sbinfo->si_xib_next_bit = 0;
34646 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
34648 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
34649 + PAGE_SIZE, &pos);
34650 + if (unlikely(err != PAGE_SIZE))
34654 + goto out; /* success */
34657 + free_page((unsigned long)sbinfo->si_xib_buf);
34658 + sbinfo->si_xib_buf = NULL;
34662 + fput(sbinfo->si_xib);
34663 + sbinfo->si_xib = NULL;
34664 + sbinfo->si_xread = NULL;
34665 + sbinfo->si_xwrite = NULL;
34670 +/* xino for each branch */
34671 +static void xino_clear_br(struct super_block *sb)
34673 + aufs_bindex_t bindex, bend;
34674 + struct au_branch *br;
34676 + bend = au_sbend(sb);
34677 + for (bindex = 0; bindex <= bend; bindex++) {
34678 + br = au_sbr(sb, bindex);
34679 + if (!br || !br->br_xino.xi_file)
34682 + fput(br->br_xino.xi_file);
34683 + br->br_xino.xi_file = NULL;
34687 +static int au_xino_set_br(struct super_block *sb, struct file *base)
34691 + aufs_bindex_t bindex, bend, bshared;
34693 + struct file *old, *new;
34695 + struct au_branch *br;
34696 + struct inode *inode;
34697 + vfs_writef_t writef;
34699 + SiMustWriteLock(sb);
34702 + bend = au_sbend(sb);
34703 + fpair = kcalloc(bend + 1, sizeof(*fpair), GFP_NOFS);
34704 + if (unlikely(!fpair))
34707 + inode = d_inode(sb->s_root);
34708 + ino = AUFS_ROOT_INO;
34709 + writef = au_sbi(sb)->si_xwrite;
34710 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34711 + br = au_sbr(sb, bindex);
34712 + bshared = is_sb_shared(sb, bindex, bindex - 1);
34713 + if (bshared >= 0) {
34714 + /* shared xino */
34715 + *p = fpair[bshared];
34716 + get_file(p->new);
34721 + p->old = br->br_xino.xi_file;
34722 + p->new = au_xino_create2(base, br->br_xino.xi_file);
34723 + err = PTR_ERR(p->new);
34724 + if (IS_ERR(p->new)) {
34730 + err = au_xino_do_write(writef, p->new,
34731 + au_h_iptr(inode, bindex)->i_ino, ino);
34732 + if (unlikely(err))
34736 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++) {
34737 + br = au_sbr(sb, bindex);
34738 + if (br->br_xino.xi_file)
34739 + fput(br->br_xino.xi_file);
34740 + get_file(p->new);
34741 + br->br_xino.xi_file = p->new;
34745 + for (bindex = 0, p = fpair; bindex <= bend; bindex++, p++)
34755 +void au_xino_clr(struct super_block *sb)
34757 + struct au_sbinfo *sbinfo;
34759 + au_xigen_clr(sb);
34760 + xino_clear_xib(sb);
34761 + xino_clear_br(sb);
34762 + sbinfo = au_sbi(sb);
34763 + /* lvalue, do not call au_mntflags() */
34764 + au_opt_clr(sbinfo->si_mntflags, XINO);
34767 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
34770 + struct dentry *parent, *cur_parent;
34771 + struct qstr *dname, *cur_name;
34772 + struct file *cur_xino;
34773 + struct inode *dir;
34774 + struct au_sbinfo *sbinfo;
34776 + SiMustWriteLock(sb);
34779 + sbinfo = au_sbi(sb);
34780 + parent = dget_parent(xino->file->f_path.dentry);
34783 + dname = &xino->file->f_path.dentry->d_name;
34784 + cur_xino = sbinfo->si_xib;
34786 + cur_parent = dget_parent(cur_xino->f_path.dentry);
34787 + cur_name = &cur_xino->f_path.dentry->d_name;
34788 + skip = (cur_parent == parent
34789 + && au_qstreq(dname, cur_name));
34790 + dput(cur_parent);
34796 + au_opt_set(sbinfo->si_mntflags, XINO);
34797 + dir = d_inode(parent);
34798 + mutex_lock_nested(&dir->i_mutex, AuLsc_I_PARENT);
34799 + /* mnt_want_write() is unnecessary here */
34800 + err = au_xino_set_xib(sb, xino->file);
34802 + err = au_xigen_set(sb, xino->file);
34804 + err = au_xino_set_br(sb, xino->file);
34805 + mutex_unlock(&dir->i_mutex);
34807 + goto out; /* success */
34810 + AuIOErr("failed creating xino(%d).\n", err);
34811 + au_xigen_clr(sb);
34812 + xino_clear_xib(sb);
34819 +/* ---------------------------------------------------------------------- */
34822 + * create a xinofile at the default place/path.
34824 +struct file *au_xino_def(struct super_block *sb)
34826 + struct file *file;
34828 + struct au_branch *br;
34829 + struct super_block *h_sb;
34830 + struct path path;
34831 + aufs_bindex_t bend, bindex, bwr;
34834 + bend = au_sbend(sb);
34836 + for (bindex = 0; bindex <= bend; bindex++) {
34837 + br = au_sbr(sb, bindex);
34838 + if (au_br_writable(br->br_perm)
34839 + && !au_test_fs_bad_xino(au_br_sb(br))) {
34846 + file = ERR_PTR(-ENOMEM);
34847 + page = (void *)__get_free_page(GFP_NOFS);
34848 + if (unlikely(!page))
34850 + path.mnt = au_br_mnt(br);
34851 + path.dentry = au_h_dptr(sb->s_root, bwr);
34852 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
34853 + file = (void *)p;
34854 + if (!IS_ERR(p)) {
34855 + strcat(p, "/" AUFS_XINO_FNAME);
34856 + AuDbg("%s\n", p);
34857 + file = au_xino_create(sb, p, /*silent*/0);
34858 + if (!IS_ERR(file))
34859 + au_xino_brid_set(sb, br->br_id);
34861 + free_page((unsigned long)page);
34863 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
34864 + if (IS_ERR(file))
34866 + h_sb = file->f_path.dentry->d_sb;
34867 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
34868 + pr_err("xino doesn't support %s(%s)\n",
34869 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
34871 + file = ERR_PTR(-EINVAL);
34873 + if (!IS_ERR(file))
34874 + au_xino_brid_set(sb, -1);
34881 +/* ---------------------------------------------------------------------- */
34883 +int au_xino_path(struct seq_file *seq, struct file *file)
34887 + err = au_seq_path(seq, &file->f_path);
34888 + if (unlikely(err < 0))
34892 +#define Deleted "\\040(deleted)"
34893 + seq->count -= sizeof(Deleted) - 1;
34894 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
34895 + sizeof(Deleted) - 1));
34901 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
34902 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
34903 +++ linux/include/uapi/linux/aufs_type.h 2015-09-24 10:47:58.258053165 +0200
34906 + * Copyright (C) 2005-2015 Junjiro R. Okajima
34908 + * This program, aufs is free software; you can redistribute it and/or modify
34909 + * it under the terms of the GNU General Public License as published by
34910 + * the Free Software Foundation; either version 2 of the License, or
34911 + * (at your option) any later version.
34913 + * This program is distributed in the hope that it will be useful,
34914 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34915 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34916 + * GNU General Public License for more details.
34918 + * You should have received a copy of the GNU General Public License
34919 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34922 +#ifndef __AUFS_TYPE_H__
34923 +#define __AUFS_TYPE_H__
34925 +#define AUFS_NAME "aufs"
34929 + * define it before including all other headers.
34930 + * sched.h may use pr_* macros before defining "current", so define the
34931 + * no-current version first, and re-define later.
34933 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
34934 +#include <linux/sched.h>
34936 +#define pr_fmt(fmt) \
34937 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
34938 + (int)sizeof(current->comm), current->comm, current->pid
34940 +#include <stdint.h>
34941 +#include <sys/types.h>
34942 +#endif /* __KERNEL__ */
34944 +#include <linux/limits.h>
34946 +#define AUFS_VERSION "4.x-rcN-20150921"
34948 +/* todo? move this to linux-2.6.19/include/magic.h */
34949 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
34951 +/* ---------------------------------------------------------------------- */
34953 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
34954 +typedef int8_t aufs_bindex_t;
34955 +#define AUFS_BRANCH_MAX 127
34957 +typedef int16_t aufs_bindex_t;
34958 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
34959 +#define AUFS_BRANCH_MAX 511
34960 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
34961 +#define AUFS_BRANCH_MAX 1023
34962 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
34963 +#define AUFS_BRANCH_MAX 32767
34968 +#ifndef AUFS_BRANCH_MAX
34969 +#error unknown CONFIG_AUFS_BRANCH_MAX value
34971 +#endif /* __KERNEL__ */
34973 +/* ---------------------------------------------------------------------- */
34975 +#define AUFS_FSTYPE AUFS_NAME
34977 +#define AUFS_ROOT_INO 2
34978 +#define AUFS_FIRST_INO 11
34980 +#define AUFS_WH_PFX ".wh."
34981 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
34982 +#define AUFS_WH_TMP_LEN 4
34983 +/* a limit for rmdir/rename a dir and copyup */
34984 +#define AUFS_MAX_NAMELEN (NAME_MAX \
34985 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
34987 + - AUFS_WH_TMP_LEN) /* hex */
34988 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
34989 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
34990 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
34991 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
34992 +#define AUFS_DIRWH_DEF 3
34993 +#define AUFS_RDCACHE_DEF 10 /* seconds */
34994 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
34995 +#define AUFS_RDBLK_DEF 512 /* bytes */
34996 +#define AUFS_RDHASH_DEF 32
34997 +#define AUFS_WKQ_NAME AUFS_NAME "d"
34998 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
34999 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
35000 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
35001 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
35003 +/* pseudo-link maintenace under /proc */
35004 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
35005 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
35006 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
35008 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
35009 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
35011 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
35012 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
35013 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
35015 +/* doubly whiteouted */
35016 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
35017 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
35018 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
35020 +/* branch permissions and attributes */
35021 +#define AUFS_BRPERM_RW "rw"
35022 +#define AUFS_BRPERM_RO "ro"
35023 +#define AUFS_BRPERM_RR "rr"
35024 +#define AUFS_BRATTR_COO_REG "coo_reg"
35025 +#define AUFS_BRATTR_COO_ALL "coo_all"
35026 +#define AUFS_BRATTR_FHSM "fhsm"
35027 +#define AUFS_BRATTR_UNPIN "unpin"
35028 +#define AUFS_BRATTR_ICEX "icex"
35029 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
35030 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
35031 +#define AUFS_BRATTR_ICEX_TR "icextr"
35032 +#define AUFS_BRATTR_ICEX_USR "icexusr"
35033 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
35034 +#define AUFS_BRRATTR_WH "wh"
35035 +#define AUFS_BRWATTR_NLWH "nolwh"
35036 +#define AUFS_BRWATTR_MOO "moo"
35038 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
35039 +#define AuBrPerm_RO (1 << 1) /* readonly */
35040 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
35041 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
35043 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
35044 +#define AuBrAttr_COO_ALL (1 << 4)
35045 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
35047 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
35048 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
35049 + branch. meaningless since
35050 + linux-3.18-rc1 */
35052 +/* ignore error in copying XATTR */
35053 +#define AuBrAttr_ICEX_SEC (1 << 7)
35054 +#define AuBrAttr_ICEX_SYS (1 << 8)
35055 +#define AuBrAttr_ICEX_TR (1 << 9)
35056 +#define AuBrAttr_ICEX_USR (1 << 10)
35057 +#define AuBrAttr_ICEX_OTH (1 << 11)
35058 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
35059 + | AuBrAttr_ICEX_SYS \
35060 + | AuBrAttr_ICEX_TR \
35061 + | AuBrAttr_ICEX_USR \
35062 + | AuBrAttr_ICEX_OTH)
35064 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
35065 +#define AuBrRAttr_Mask AuBrRAttr_WH
35067 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
35068 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
35069 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
35071 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
35073 +/* #warning test userspace */
35075 +#ifndef CONFIG_AUFS_FHSM
35076 +#undef AuBrAttr_FHSM
35077 +#define AuBrAttr_FHSM 0
35079 +#ifndef CONFIG_AUFS_XATTR
35080 +#undef AuBrAttr_ICEX
35081 +#define AuBrAttr_ICEX 0
35082 +#undef AuBrAttr_ICEX_SEC
35083 +#define AuBrAttr_ICEX_SEC 0
35084 +#undef AuBrAttr_ICEX_SYS
35085 +#define AuBrAttr_ICEX_SYS 0
35086 +#undef AuBrAttr_ICEX_TR
35087 +#define AuBrAttr_ICEX_TR 0
35088 +#undef AuBrAttr_ICEX_USR
35089 +#define AuBrAttr_ICEX_USR 0
35090 +#undef AuBrAttr_ICEX_OTH
35091 +#define AuBrAttr_ICEX_OTH 0
35095 +/* the longest combination */
35096 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
35097 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
35098 + "+" AUFS_BRATTR_COO_REG \
35099 + "+" AUFS_BRATTR_FHSM \
35100 + "+" AUFS_BRATTR_UNPIN \
35101 + "+" AUFS_BRATTR_ICEX_SEC \
35102 + "+" AUFS_BRATTR_ICEX_SYS \
35103 + "+" AUFS_BRATTR_ICEX_USR \
35104 + "+" AUFS_BRATTR_ICEX_OTH \
35105 + "+" AUFS_BRWATTR_NLWH)
35108 + char a[AuBrPermStrSz];
35109 +} au_br_perm_str_t;
35111 +static inline int au_br_writable(int brperm)
35113 + return brperm & AuBrPerm_RW;
35116 +static inline int au_br_whable(int brperm)
35118 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
35121 +static inline int au_br_wh_linkable(int brperm)
35123 + return !(brperm & AuBrWAttr_NoLinkWH);
35126 +static inline int au_br_cmoo(int brperm)
35128 + return brperm & AuBrAttr_CMOO_Mask;
35131 +static inline int au_br_fhsm(int brperm)
35133 + return brperm & AuBrAttr_FHSM;
35136 +/* ---------------------------------------------------------------------- */
35140 + /* readdir in userspace */
35144 + AuCtl_WBR_FD, /* pathconf wrapper */
35145 + AuCtl_IBUSY, /* busy inode */
35146 + AuCtl_MVDOWN, /* move-down */
35147 + AuCtl_BR, /* info about branches */
35148 + AuCtl_FHSM_FD /* connection for fhsm */
35151 +/* borrowed from linux/include/linux/kernel.h */
35153 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
35154 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
35157 +/* borrowed from linux/include/linux/compiler-gcc3.h */
35159 +#define __aligned(x) __attribute__((aligned(x)))
35164 +#define __packed __attribute__((packed))
35168 +struct au_rdu_cookie {
35173 + uint32_t generation;
35176 +struct au_rdu_ent {
35185 +static inline int au_rdu_len(int nlen)
35187 + /* include the terminating NULL */
35188 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
35189 + sizeof(uint64_t));
35192 +union au_rdu_ent_ul {
35193 + struct au_rdu_ent __user *e;
35205 + uint64_t sz; /* AuCtl_RDU */
35206 + uint64_t nent; /* AuCtl_RDU_INO */
35208 + union au_rdu_ent_ul ent;
35209 + uint16_t verify[AufsCtlRduV_End];
35211 + /* input/output */
35215 + union au_rdu_ent_ul tail;
35216 + /* number of entries which were added in a single call */
35221 + struct au_rdu_cookie cookie;
35224 +/* ---------------------------------------------------------------------- */
35226 +struct aufs_wbr_fd {
35231 +/* ---------------------------------------------------------------------- */
35233 +struct aufs_ibusy {
35234 + uint64_t ino, h_ino;
35238 +/* ---------------------------------------------------------------------- */
35240 +/* error code for move-down */
35241 +/* the actual message strings are implemented in aufs-util.git */
35243 + EAU_MVDOWN_OPAQUE = 1,
35244 + EAU_MVDOWN_WHITEOUT,
35245 + EAU_MVDOWN_UPPER,
35246 + EAU_MVDOWN_BOTTOM,
35247 + EAU_MVDOWN_NOUPPER,
35248 + EAU_MVDOWN_NOLOWERBR,
35252 +/* flags for move-down */
35253 +#define AUFS_MVDOWN_DMSG 1
35254 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
35255 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
35256 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
35257 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
35258 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
35259 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
35260 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
35261 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
35262 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
35263 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
35264 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
35265 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
35267 +/* index for move-down */
35269 + AUFS_MVDOWN_UPPER,
35270 + AUFS_MVDOWN_LOWER,
35271 + AUFS_MVDOWN_NARRAY
35275 + * additional info of move-down
35276 + * number of free blocks and inodes.
35277 + * subset of struct kstatfs, but smaller and always 64bit.
35279 +struct aufs_stfs {
35280 + uint64_t f_blocks;
35281 + uint64_t f_bavail;
35282 + uint64_t f_files;
35283 + uint64_t f_ffree;
35286 +struct aufs_stbr {
35287 + int16_t brid; /* optional input */
35288 + int16_t bindex; /* output */
35289 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
35292 +struct aufs_mvdown {
35293 + uint32_t flags; /* input/output */
35294 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
35295 + int8_t au_errno; /* output */
35298 +/* ---------------------------------------------------------------------- */
35300 +union aufs_brinfo {
35301 + /* PATH_MAX may differ between kernel-space and user-space */
35302 + char _spacer[4096];
35310 +/* ---------------------------------------------------------------------- */
35312 +#define AuCtlType 'A'
35313 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
35314 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
35315 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
35316 + struct aufs_wbr_fd)
35317 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
35318 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
35319 + struct aufs_mvdown)
35320 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
35321 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
35323 +#endif /* __AUFS_TYPE_H__ */
35324 aufs4.x-rcN loopback patch
35326 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
35327 index 23103ad..5c3263f 100644
35328 --- a/drivers/block/loop.c
35329 +++ b/drivers/block/loop.c
35330 @@ -417,7 +417,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
35333 struct switch_request {
35334 - struct file *file;
35335 + struct file *file, *virt_file;
35336 struct completion wait;
35339 @@ -437,6 +437,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35340 mapping = file->f_mapping;
35341 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
35342 lo->lo_backing_file = file;
35343 + lo->lo_backing_virt_file = p->virt_file;
35344 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
35345 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
35346 lo->old_gfp_mask = mapping_gfp_mask(mapping);
35347 @@ -448,11 +449,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35348 * First it needs to flush existing IO, it does this by sending a magic
35349 * BIO down the pipe. The completion of this BIO does the actual switch.
35351 -static int loop_switch(struct loop_device *lo, struct file *file)
35352 +static int loop_switch(struct loop_device *lo, struct file *file,
35353 + struct file *virt_file)
35355 struct switch_request w;
35358 + w.virt_file = virt_file;
35360 /* freeze queue and wait for completion of scheduled requests */
35361 blk_mq_freeze_queue(lo->lo_queue);
35362 @@ -471,7 +474,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
35364 static int loop_flush(struct loop_device *lo)
35366 - return loop_switch(lo, NULL);
35367 + return loop_switch(lo, NULL, NULL);
35370 +static struct file *loop_real_file(struct file *file)
35372 + struct file *f = NULL;
35374 + if (file->f_path.dentry->d_sb->s_op->real_loop)
35375 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
35379 static void loop_reread_partitions(struct loop_device *lo,
35380 @@ -508,6 +520,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35383 struct file *file, *old_file;
35384 + struct file *f, *virt_file = NULL, *old_virt_file;
35385 struct inode *inode;
35388 @@ -524,9 +537,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35392 + f = loop_real_file(file);
35394 + virt_file = file;
35399 inode = file->f_mapping->host;
35400 old_file = lo->lo_backing_file;
35401 + old_virt_file = lo->lo_backing_virt_file;
35405 @@ -538,17 +558,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35408 /* and ... switch */
35409 - error = loop_switch(lo, file);
35410 + error = loop_switch(lo, file, virt_file);
35415 + if (old_virt_file)
35416 + fput(old_virt_file);
35417 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
35418 loop_reread_partitions(lo, bdev);
35428 @@ -709,7 +733,7 @@ static void loop_config_discard(struct loop_device *lo)
35429 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35430 struct block_device *bdev, unsigned int arg)
35432 - struct file *file, *f;
35433 + struct file *file, *f, *virt_file = NULL;
35434 struct inode *inode;
35435 struct address_space *mapping;
35436 unsigned lo_blocksize;
35437 @@ -724,6 +748,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35441 + f = loop_real_file(file);
35443 + virt_file = file;
35449 if (lo->lo_state != Lo_unbound)
35450 @@ -778,6 +808,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35451 lo->lo_device = bdev;
35452 lo->lo_flags = lo_flags;
35453 lo->lo_backing_file = file;
35454 + lo->lo_backing_virt_file = virt_file;
35455 lo->transfer = NULL;
35457 lo->lo_sizelimit = 0;
35458 @@ -809,6 +840,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35465 /* This is safe: open() is still holding a reference. */
35466 module_put(THIS_MODULE);
35467 @@ -855,6 +888,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
35468 static int loop_clr_fd(struct loop_device *lo)
35470 struct file *filp = lo->lo_backing_file;
35471 + struct file *virt_filp = lo->lo_backing_virt_file;
35472 gfp_t gfp = lo->old_gfp_mask;
35473 struct block_device *bdev = lo->lo_device;
35475 @@ -886,6 +920,7 @@ static int loop_clr_fd(struct loop_device *lo)
35476 spin_lock_irq(&lo->lo_lock);
35477 lo->lo_state = Lo_rundown;
35478 lo->lo_backing_file = NULL;
35479 + lo->lo_backing_virt_file = NULL;
35480 spin_unlock_irq(&lo->lo_lock);
35482 loop_release_xfer(lo);
35483 @@ -931,6 +966,8 @@ static int loop_clr_fd(struct loop_device *lo)
35484 * bd_mutex which is usually taken before lo_ctl_mutex.
35492 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
35493 index 25e8997..93b6fce 100644
35494 --- a/drivers/block/loop.h
35495 +++ b/drivers/block/loop.h
35496 @@ -46,7 +46,7 @@ struct loop_device {
35497 int (*ioctl)(struct loop_device *, int cmd,
35498 unsigned long arg);
35500 - struct file * lo_backing_file;
35501 + struct file * lo_backing_file, *lo_backing_virt_file;
35502 struct block_device *lo_device;
35503 unsigned lo_blocksize;
35505 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
35506 index 91c2ce7..d4ee5a7 100644
35507 --- a/fs/aufs/f_op.c
35508 +++ b/fs/aufs/f_op.c
35509 @@ -389,7 +389,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
35510 if (IS_ERR(h_file))
35513 - if (au_test_loopback_kthread()) {
35514 + if (0 && au_test_loopback_kthread()) {
35515 au_warn_loopback(h_file->f_path.dentry->d_sb);
35516 if (file->f_mapping != h_file->f_mapping) {
35517 file->f_mapping = h_file->f_mapping;
35518 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
35519 index 69f7e96..7941063 100644
35520 --- a/fs/aufs/loop.c
35521 +++ b/fs/aufs/loop.c
35522 @@ -130,3 +130,19 @@ void au_loopback_fin(void)
35523 symbol_put(loop_backing_file);
35524 kfree(au_warn_loopback_array);
35527 +/* ---------------------------------------------------------------------- */
35529 +/* support the loopback block device insude aufs */
35531 +struct file *aufs_real_loop(struct file *file)
35535 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
35536 + fi_read_lock(file);
35537 + f = au_hf_top(file);
35538 + fi_read_unlock(file);
35542 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
35543 index 6d9864d..3322557 100644
35544 --- a/fs/aufs/loop.h
35545 +++ b/fs/aufs/loop.h
35546 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
35548 int au_loopback_init(void);
35549 void au_loopback_fin(void);
35551 +struct file *aufs_real_loop(struct file *file);
35553 +AuStub(struct file *, loop_backing_file, return NULL)
35555 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
35556 struct dentry *h_adding)
35557 AuStubInt0(au_test_loopback_kthread, void)
35558 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
35560 AuStubInt0(au_loopback_init, void)
35561 AuStubVoid(au_loopback_fin, void)
35563 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
35564 #endif /* BLK_DEV_LOOP */
35566 #endif /* __KERNEL__ */
35567 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
35568 index ee5780d..da35759 100644
35569 --- a/fs/aufs/super.c
35570 +++ b/fs/aufs/super.c
35571 @@ -807,7 +807,10 @@ static const struct super_operations aufs_sop = {
35572 .statfs = aufs_statfs,
35573 .put_super = aufs_put_super,
35574 .sync_fs = aufs_sync_fs,
35575 - .remount_fs = aufs_remount_fs
35576 + .remount_fs = aufs_remount_fs,
35577 +#ifdef CONFIG_AUFS_BDEV_LOOP
35578 + .real_loop = aufs_real_loop
35582 /* ---------------------------------------------------------------------- */
35583 diff --git a/include/linux/fs.h b/include/linux/fs.h
35584 index 86080ea..5f8e0f2 100644
35585 --- a/include/linux/fs.h
35586 +++ b/include/linux/fs.h
35587 @@ -1708,6 +1708,10 @@ struct super_operations {
35588 struct shrink_control *);
35589 long (*free_cached_objects)(struct super_block *,
35590 struct shrink_control *);
35591 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
35593 + struct file *(*real_loop)(struct file *);