1 aufs4.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index b8fcb41..78adefb 100644
7 @@ -236,6 +236,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 85b6e13..e7bb164 100644
19 @@ -128,3 +128,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 8bdae34..65dbd5f 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 952fd2a..6a8f0f8 100644
42 @@ -2210,6 +2210,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 1fa8cc2..7339e65 100644
64 --- a/drivers/block/loop.c
65 +++ b/drivers/block/loop.c
66 @@ -712,6 +712,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_GPL(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 d6847d7..c3c0b6d 100644
95 @@ -1202,7 +1202,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/fcntl.c b/fs/fcntl.c
105 index 350a2c8..6f42279 100644
110 #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME)
112 -static int setfl(int fd, struct file * filp, unsigned long arg)
113 +int setfl(int fd, struct file * filp, unsigned long arg)
115 struct inode * inode = file_inode(filp);
117 @@ -60,6 +60,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg)
119 if (filp->f_op->check_flags)
120 error = filp->f_op->check_flags(arg);
121 + if (!error && filp->f_op->setfl)
122 + error = filp->f_op->setfl(filp, arg);
126 diff --git a/fs/inode.c b/fs/inode.c
127 index 4ccbc21..aa6d071 100644
130 @@ -1591,7 +1591,7 @@ EXPORT_SYMBOL(generic_update_time);
131 * This does the actual work of updating an inodes time or version. Must have
132 * had called mnt_want_write() before calling this.
134 -static int update_time(struct inode *inode, struct timespec *time, int flags)
135 +int update_time(struct inode *inode, struct timespec *time, int flags)
137 int (*update_time)(struct inode *, struct timespec *, int);
139 diff --git a/fs/read_write.c b/fs/read_write.c
140 index 933b53a..2d13282 100644
141 --- a/fs/read_write.c
142 +++ b/fs/read_write.c
143 @@ -515,6 +515,28 @@ ssize_t __vfs_write(struct file *file, const char __user *p, size_t count,
145 EXPORT_SYMBOL(__vfs_write);
147 +vfs_readf_t vfs_readf(struct file *file)
149 + const struct file_operations *fop = file->f_op;
153 + if (fop->read_iter)
154 + return new_sync_read;
155 + return ERR_PTR(-ENOSYS);
158 +vfs_writef_t vfs_writef(struct file *file)
160 + const struct file_operations *fop = file->f_op;
164 + if (fop->write_iter)
165 + return new_sync_write;
166 + return ERR_PTR(-ENOSYS);
169 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
172 diff --git a/fs/splice.c b/fs/splice.c
173 index dd9bf7e..9326c2a 100644
176 @@ -1111,8 +1111,8 @@ EXPORT_SYMBOL(generic_splice_sendpage);
178 * Attempt to initiate a splice from pipe to file.
180 -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
181 - loff_t *ppos, size_t len, unsigned int flags)
182 +long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
183 + loff_t *ppos, size_t len, unsigned int flags)
185 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *,
186 loff_t *, size_t, unsigned int);
187 @@ -1128,9 +1128,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
189 * Attempt to initiate a splice from a file to a pipe.
191 -static long do_splice_to(struct file *in, loff_t *ppos,
192 - struct pipe_inode_info *pipe, size_t len,
193 - unsigned int flags)
194 +long do_splice_to(struct file *in, loff_t *ppos,
195 + struct pipe_inode_info *pipe, size_t len,
196 + unsigned int flags)
198 ssize_t (*splice_read)(struct file *, loff_t *,
199 struct pipe_inode_info *, size_t, unsigned int);
200 diff --git a/include/linux/file.h b/include/linux/file.h
201 index 7444f5f..bdac0be 100644
202 --- a/include/linux/file.h
203 +++ b/include/linux/file.h
204 @@ -19,6 +19,7 @@ struct dentry;
206 extern struct file *alloc_file(struct path *, fmode_t mode,
207 const struct file_operations *fop);
208 +extern struct file *get_empty_filp(void);
210 static inline void fput_light(struct file *file, int fput_needed)
212 diff --git a/include/linux/fs.h b/include/linux/fs.h
213 index dd28814..b689a48 100644
214 --- a/include/linux/fs.h
215 +++ b/include/linux/fs.h
216 @@ -1306,6 +1306,7 @@ extern void fasync_free(struct fasync_struct *);
217 /* can be called from interrupts */
218 extern void kill_fasync(struct fasync_struct **, int, int);
220 +extern int setfl(int fd, struct file * filp, unsigned long arg);
221 extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force);
222 extern void f_setown(struct file *filp, unsigned long arg, int force);
223 extern void f_delown(struct file *filp);
224 @@ -1690,6 +1691,7 @@ struct file_operations {
225 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
226 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
227 int (*check_flags)(int);
228 + int (*setfl)(struct file *, unsigned long);
229 int (*flock) (struct file *, int, struct file_lock *);
230 ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
231 ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
232 @@ -1750,6 +1752,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
233 struct iovec *fast_pointer,
234 struct iovec **ret_pointer);
236 +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *);
237 +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t,
239 +vfs_readf_t vfs_readf(struct file *file);
240 +vfs_writef_t vfs_writef(struct file *file);
242 extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *);
243 extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
244 extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *);
245 @@ -2105,6 +2113,7 @@ extern int current_umask(void);
246 extern void ihold(struct inode * inode);
247 extern void iput(struct inode *);
248 extern int generic_update_time(struct inode *, struct timespec *, int);
249 +extern int update_time(struct inode *, struct timespec *, int);
252 extern struct kobject *fs_kobj;
253 diff --git a/include/linux/splice.h b/include/linux/splice.h
254 index da2751d..2e0fca6 100644
255 --- a/include/linux/splice.h
256 +++ b/include/linux/splice.h
257 @@ -83,4 +83,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *);
258 extern void spd_release_page(struct splice_pipe_desc *, unsigned int);
260 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
262 +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
263 + loff_t *ppos, size_t len, unsigned int flags);
264 +extern long do_splice_to(struct file *in, loff_t *ppos,
265 + struct pipe_inode_info *pipe, size_t len,
266 + unsigned int flags);
268 aufs4.x-rcN mmap patch
270 diff --git a/fs/proc/base.c b/fs/proc/base.c
271 index a11eb71..8f10865 100644
274 @@ -1939,7 +1939,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path)
275 down_read(&mm->mmap_sem);
276 vma = find_exact_vma(mm, vm_start, vm_end);
277 if (vma && vma->vm_file) {
278 - *path = vma->vm_file->f_path;
279 + *path = vma_pr_or_file(vma)->f_path;
283 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
284 index f8595e8..cb8eda0 100644
285 --- a/fs/proc/nommu.c
286 +++ b/fs/proc/nommu.c
287 @@ -45,7 +45,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
288 file = region->vm_file;
291 - struct inode *inode = file_inode(region->vm_file);
292 + struct inode *inode;
294 + file = vmr_pr_or_file(region);
295 + inode = file_inode(file);
296 dev = inode->i_sb->s_dev;
299 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
300 index 4648c7f..061cb85 100644
301 --- a/fs/proc/task_mmu.c
302 +++ b/fs/proc/task_mmu.c
303 @@ -298,7 +298,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
304 const char *name = NULL;
307 - struct inode *inode = file_inode(vma->vm_file);
308 + struct inode *inode;
310 + file = vma_pr_or_file(vma);
311 + inode = file_inode(file);
312 dev = inode->i_sb->s_dev;
314 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
315 @@ -1624,7 +1627,7 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
316 struct proc_maps_private *proc_priv = &numa_priv->proc_maps;
317 struct vm_area_struct *vma = v;
318 struct numa_maps *md = &numa_priv->md;
319 - struct file *file = vma->vm_file;
320 + struct file *file = vma_pr_or_file(vma);
321 struct mm_struct *mm = vma->vm_mm;
322 struct mm_walk walk = {
323 .hugetlb_entry = gather_hugetlb_stats,
324 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
325 index faacb0c..17b43be 100644
326 --- a/fs/proc/task_nommu.c
327 +++ b/fs/proc/task_nommu.c
328 @@ -163,7 +163,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
332 - struct inode *inode = file_inode(vma->vm_file);
333 + struct inode *inode;
335 + file = vma_pr_or_file(vma);
336 + inode = file_inode(file);
337 dev = inode->i_sb->s_dev;
339 pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
340 diff --git a/include/linux/mm.h b/include/linux/mm.h
341 index ece042d..1e24513 100644
342 --- a/include/linux/mm.h
343 +++ b/include/linux/mm.h
344 @@ -1239,6 +1239,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
348 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
349 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
351 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
352 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
354 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
356 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
358 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
359 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
362 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
363 +extern void vmr_do_fput(struct vm_region *, const char[], int);
365 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
367 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
368 +#endif /* !CONFIG_MMU */
370 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
371 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
372 void *buf, int len, int write);
373 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
374 index ca3e517..10bc491 100644
375 --- a/include/linux/mm_types.h
376 +++ b/include/linux/mm_types.h
377 @@ -274,6 +274,7 @@ struct vm_region {
378 unsigned long vm_top; /* region allocated to here */
379 unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
380 struct file *vm_file; /* the backing file or NULL */
381 + struct file *vm_prfile; /* the virtual backing file or NULL */
383 int vm_usage; /* region usage count (access under nommu_region_sem) */
384 bool vm_icache_flushed : 1; /* true if the icache has been flushed for
385 @@ -348,6 +349,7 @@ struct vm_area_struct {
386 unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
388 struct file * vm_file; /* File we map to (can be NULL). */
389 + struct file *vm_prfile; /* shadow of vm_file */
390 void * vm_private_data; /* was vm_pte (shared mem) */
393 diff --git a/kernel/fork.c b/kernel/fork.c
394 index 4a7ec0c..8c8f7ac 100644
397 @@ -479,7 +479,7 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
398 struct inode *inode = file_inode(file);
399 struct address_space *mapping = file->f_mapping;
403 if (tmp->vm_flags & VM_DENYWRITE)
404 atomic_dec(&inode->i_writecount);
405 i_mmap_lock_write(mapping);
406 diff --git a/mm/Makefile b/mm/Makefile
407 index 78c6f7d..aea4230 100644
410 @@ -37,7 +37,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
411 mm_init.o mmu_context.o percpu.o slab_common.o \
412 compaction.o vmacache.o \
413 interval_tree.o list_lru.o workingset.o \
415 + prfile.o debug.o $(mmu-y)
419 diff --git a/mm/filemap.c b/mm/filemap.c
420 index 20f3b1f..ee827ce 100644
423 @@ -2208,7 +2208,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
424 int ret = VM_FAULT_LOCKED;
426 sb_start_pagefault(inode->i_sb);
427 - file_update_time(vma->vm_file);
428 + vma_file_update_time(vma);
430 if (page->mapping != inode->i_mapping) {
432 diff --git a/mm/memory.c b/mm/memory.c
433 index cd1f29e..f0c204c 100644
436 @@ -2100,7 +2100,7 @@ static inline int wp_page_reuse(struct mm_struct *mm,
440 - file_update_time(vma->vm_file);
441 + vma_file_update_time(vma);
444 return VM_FAULT_WRITE;
445 diff --git a/mm/mmap.c b/mm/mmap.c
446 index de2c176..b7f391c 100644
449 @@ -162,7 +162,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
450 if (vma->vm_ops && vma->vm_ops->close)
451 vma->vm_ops->close(vma);
453 - fput(vma->vm_file);
455 mpol_put(vma_policy(vma));
456 kmem_cache_free(vm_area_cachep, vma);
458 @@ -782,7 +782,7 @@ again: remove_next = 1 + (end > next->vm_end);
461 uprobe_munmap(next, next->vm_start, next->vm_end);
466 anon_vma_merge(vma, next);
467 @@ -1563,8 +1563,8 @@ out:
475 /* Undo any partial mapping done by a device driver. */
476 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
477 @@ -2358,7 +2358,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
481 - get_file(new->vm_file);
484 if (new->vm_ops && new->vm_ops->open)
485 new->vm_ops->open(new);
486 @@ -2377,7 +2377,7 @@ static int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
487 if (new->vm_ops && new->vm_ops->close)
488 new->vm_ops->close(new);
490 - fput(new->vm_file);
492 unlink_anon_vmas(new);
494 mpol_put(vma_policy(new));
495 @@ -2528,7 +2528,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
496 struct vm_area_struct *vma;
497 unsigned long populate = 0;
498 unsigned long ret = -EINVAL;
500 + struct file *file, *prfile;
502 pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.txt.\n",
503 current->comm, current->pid);
504 @@ -2597,10 +2597,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
508 - file = get_file(vma->vm_file);
510 + file = vma->vm_file;
511 + prfile = vma->vm_prfile;
512 ret = do_mmap_pgoff(vma->vm_file, start, size,
513 prot, flags, pgoff, &populate);
514 + if (!IS_ERR_VALUE(ret) && file && prfile) {
515 + struct vm_area_struct *new_vma;
517 + new_vma = find_vma(mm, ret);
518 + if (!new_vma->vm_prfile)
519 + new_vma->vm_prfile = prfile;
520 + if (new_vma != vma)
524 + * two fput()s instead of vma_fput(vma),
525 + * coz vma may not be available anymore.
531 up_write(&mm->mmap_sem);
533 @@ -2873,7 +2890,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
534 if (anon_vma_clone(new_vma, vma))
535 goto out_free_mempol;
536 if (new_vma->vm_file)
537 - get_file(new_vma->vm_file);
538 + vma_get_file(new_vma);
539 if (new_vma->vm_ops && new_vma->vm_ops->open)
540 new_vma->vm_ops->open(new_vma);
541 vma_link(mm, new_vma, prev, rb_link, rb_parent);
542 diff --git a/mm/nommu.c b/mm/nommu.c
543 index c2e588802..c39edc4 100644
546 @@ -644,7 +644,7 @@ static void __put_nommu_region(struct vm_region *region)
547 up_write(&nommu_region_sem);
550 - fput(region->vm_file);
553 /* IO memory and memory shared directly out of the pagecache
554 * from ramfs/tmpfs mustn't be released here */
555 @@ -802,7 +802,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma)
556 if (vma->vm_ops && vma->vm_ops->close)
557 vma->vm_ops->close(vma);
559 - fput(vma->vm_file);
561 put_nommu_region(vma->vm_region);
562 kmem_cache_free(vm_area_cachep, vma);
564 @@ -1328,7 +1328,7 @@ unsigned long do_mmap(struct file *file,
565 goto error_just_free;
568 - fput(region->vm_file);
570 kmem_cache_free(vm_region_jar, region);
573 @@ -1403,10 +1403,10 @@ error_just_free:
574 up_write(&nommu_region_sem);
577 - fput(region->vm_file);
579 kmem_cache_free(vm_region_jar, region);
581 - fput(vma->vm_file);
583 kmem_cache_free(vm_area_cachep, vma);
586 diff --git a/mm/prfile.c b/mm/prfile.c
588 index 0000000..b323b8a
593 + * Mainly for aufs which mmap(2) diffrent file and wants to print different path
594 + * in /proc/PID/maps.
595 + * Call these functions via macros defined in linux/mm.h.
597 + * See Documentation/filesystems/aufs/design/06mmap.txt
599 + * Copyright (c) 2014 Junjro R. Okajima
600 + * Copyright (c) 2014 Ian Campbell
603 +#include <linux/mm.h>
604 +#include <linux/file.h>
605 +#include <linux/fs.h>
607 +/* #define PRFILE_TRACE */
608 +static inline void prfile_trace(struct file *f, struct file *pr,
609 + const char func[], int line, const char func2[])
613 + pr_info("%s:%d: %s, %s\n", func, line, func2,
614 + f ? (char *)f->f_path.dentry->d_name.name : "(null)");
618 +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[],
621 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
623 + prfile_trace(f, pr, func, line, __func__);
624 + file_update_time(f);
626 + file_update_time(pr);
629 +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[],
632 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
634 + prfile_trace(f, pr, func, line, __func__);
635 + return (f && pr) ? pr : f;
638 +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line)
640 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
642 + prfile_trace(f, pr, func, line, __func__);
648 +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line)
650 + struct file *f = vma->vm_file, *pr = vma->vm_prfile;
652 + prfile_trace(f, pr, func, line, __func__);
659 +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[],
662 + struct file *f = region->vm_file, *pr = region->vm_prfile;
664 + prfile_trace(f, pr, func, line, __func__);
665 + return (f && pr) ? pr : f;
668 +void vmr_do_fput(struct vm_region *region, const char func[], int line)
670 + struct file *f = region->vm_file, *pr = region->vm_prfile;
672 + prfile_trace(f, pr, func, line, __func__);
677 +#endif /* !CONFIG_MMU */
678 aufs4.x-rcN standalone patch
680 diff --git a/fs/dcache.c b/fs/dcache.c
681 index c3c0b6d..c99d2d2 100644
684 @@ -1310,6 +1310,7 @@ rename_retry:
688 +EXPORT_SYMBOL_GPL(d_walk);
691 * Search for at least 1 mount point in the dentry's subdirs.
692 diff --git a/fs/exec.c b/fs/exec.c
693 index 887c1c9..40e8767 100644
696 @@ -104,6 +104,7 @@ bool path_noexec(const struct path *path)
697 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
698 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
700 +EXPORT_SYMBOL_GPL(path_noexec);
704 diff --git a/fs/fcntl.c b/fs/fcntl.c
705 index 6f42279..04fd33c 100644
708 @@ -82,6 +82,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
712 +EXPORT_SYMBOL_GPL(setfl);
714 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
716 diff --git a/fs/file_table.c b/fs/file_table.c
717 index ad17e05..ae9f267 100644
718 --- a/fs/file_table.c
719 +++ b/fs/file_table.c
720 @@ -147,6 +147,7 @@ over:
722 return ERR_PTR(-ENFILE);
724 +EXPORT_SYMBOL_GPL(get_empty_filp);
727 * alloc_file - allocate and initialize a 'struct file'
728 @@ -258,6 +259,7 @@ void flush_delayed_fput(void)
732 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
734 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
736 @@ -300,6 +302,7 @@ void __fput_sync(struct file *file)
740 +EXPORT_SYMBOL_GPL(__fput_sync);
742 void put_filp(struct file *file)
744 @@ -308,6 +311,7 @@ void put_filp(struct file *file)
748 +EXPORT_SYMBOL_GPL(put_filp);
750 void __init files_init(void)
752 diff --git a/fs/inode.c b/fs/inode.c
753 index aa6d071..f336032 100644
756 @@ -1600,6 +1600,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
758 return update_time(inode, time, flags);
760 +EXPORT_SYMBOL_GPL(update_time);
763 * touch_atime - update the access time
764 diff --git a/fs/namespace.c b/fs/namespace.c
765 index 783004a..44abb2d 100644
768 @@ -463,6 +463,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
769 mnt_dec_writers(real_mount(mnt));
772 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
775 * mnt_drop_write - give up write access to a mount
776 @@ -1811,6 +1812,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
780 +EXPORT_SYMBOL_GPL(iterate_mounts);
782 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
784 diff --git a/fs/notify/group.c b/fs/notify/group.c
785 index 3e2dd85..b17cb4b 100644
786 --- a/fs/notify/group.c
787 +++ b/fs/notify/group.c
789 #include <linux/srcu.h>
790 #include <linux/rculist.h>
791 #include <linux/wait.h>
792 +#include <linux/module.h>
794 #include <linux/fsnotify_backend.h>
795 #include "fsnotify.h"
796 @@ -81,6 +82,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
798 atomic_inc(&group->refcnt);
800 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
803 * Drop a reference to a group. Free it if it's through.
804 @@ -90,6 +92,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
805 if (atomic_dec_and_test(&group->refcnt))
806 fsnotify_final_destroy_group(group);
808 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
811 * Create a new fsnotify_group and hold a reference for the group returned.
812 @@ -118,6 +121,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
816 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
818 int fsnotify_fasync(int fd, struct file *file, int on)
820 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
821 index d3fea0b..5fc06ad 100644
822 --- a/fs/notify/mark.c
823 +++ b/fs/notify/mark.c
824 @@ -113,6 +113,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
825 mark->free_mark(mark);
828 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
830 /* Calculate mask of events for a list of marks */
831 u32 fsnotify_recalc_mask(struct hlist_head *head)
832 @@ -230,6 +231,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
833 mutex_unlock(&group->mark_mutex);
834 fsnotify_free_mark(mark);
836 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
838 void fsnotify_destroy_marks(struct hlist_head *head, spinlock_t *lock)
840 @@ -415,6 +417,7 @@ err:
844 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
846 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
847 struct inode *inode, struct vfsmount *mnt, int allow_dups)
848 @@ -533,6 +536,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
849 atomic_set(&mark->refcnt, 1);
850 mark->free_mark = free_mark;
852 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
855 * Destroy all marks in destroy_list, waits for SRCU period to finish before
856 diff --git a/fs/open.c b/fs/open.c
857 index 93ae3cd..d25b9bd 100644
860 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
861 inode_unlock(dentry->d_inode);
864 +EXPORT_SYMBOL_GPL(do_truncate);
866 long vfs_truncate(const struct path *path, loff_t length)
868 @@ -678,6 +679,7 @@ int open_check_o_direct(struct file *f)
872 +EXPORT_SYMBOL_GPL(open_check_o_direct);
874 static int do_dentry_open(struct file *f,
876 diff --git a/fs/read_write.c b/fs/read_write.c
877 index 2d13282..260c4a4 100644
878 --- a/fs/read_write.c
879 +++ b/fs/read_write.c
880 @@ -525,6 +525,7 @@ vfs_readf_t vfs_readf(struct file *file)
881 return new_sync_read;
882 return ERR_PTR(-ENOSYS);
884 +EXPORT_SYMBOL_GPL(vfs_readf);
886 vfs_writef_t vfs_writef(struct file *file)
888 @@ -536,6 +537,7 @@ vfs_writef_t vfs_writef(struct file *file)
889 return new_sync_write;
890 return ERR_PTR(-ENOSYS);
892 +EXPORT_SYMBOL_GPL(vfs_writef);
894 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
896 diff --git a/fs/splice.c b/fs/splice.c
897 index 9326c2a..0606690 100644
900 @@ -1124,6 +1124,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
902 return splice_write(pipe, out, ppos, len, flags);
904 +EXPORT_SYMBOL_GPL(do_splice_from);
907 * Attempt to initiate a splice from a file to a pipe.
908 @@ -1153,6 +1154,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
910 return splice_read(in, ppos, pipe, len, flags);
912 +EXPORT_SYMBOL_GPL(do_splice_to);
915 * splice_direct_to_actor - splices data directly between two non-pipes
916 diff --git a/fs/xattr.c b/fs/xattr.c
917 index 4beafc4..e118715 100644
920 @@ -207,6 +207,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value,
921 *xattr_value = value;
924 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
927 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
928 diff --git a/kernel/task_work.c b/kernel/task_work.c
929 index 53fa971..bce3211 100644
930 --- a/kernel/task_work.c
931 +++ b/kernel/task_work.c
932 @@ -118,3 +118,4 @@ void task_work_run(void)
936 +EXPORT_SYMBOL_GPL(task_work_run);
937 diff --git a/security/commoncap.c b/security/commoncap.c
938 index e7fadde..6423e53 100644
939 --- a/security/commoncap.c
940 +++ b/security/commoncap.c
941 @@ -1058,12 +1058,14 @@ int cap_mmap_addr(unsigned long addr)
945 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
947 int cap_mmap_file(struct file *file, unsigned long reqprot,
948 unsigned long prot, unsigned long flags)
952 +EXPORT_SYMBOL_GPL(cap_mmap_file);
954 #ifdef CONFIG_SECURITY
956 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
957 index 03c1652..f88c84b 100644
958 --- a/security/device_cgroup.c
959 +++ b/security/device_cgroup.c
961 #include <linux/device_cgroup.h>
962 #include <linux/cgroup.h>
963 #include <linux/ctype.h>
964 +#include <linux/export.h>
965 #include <linux/list.h>
966 #include <linux/uaccess.h>
967 #include <linux/seq_file.h>
968 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
969 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
972 +EXPORT_SYMBOL_GPL(__devcgroup_inode_permission);
974 int devcgroup_inode_mknod(int mode, dev_t dev)
976 diff --git a/security/security.c b/security/security.c
977 index 7095693..da7fe2c 100644
978 --- a/security/security.c
979 +++ b/security/security.c
980 @@ -434,6 +434,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
982 return call_int_hook(path_rmdir, 0, dir, dentry);
984 +EXPORT_SYMBOL_GPL(security_path_rmdir);
986 int security_path_unlink(const struct path *dir, struct dentry *dentry)
988 @@ -450,6 +451,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
990 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
992 +EXPORT_SYMBOL_GPL(security_path_symlink);
994 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
995 struct dentry *new_dentry)
996 @@ -458,6 +460,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
998 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1000 +EXPORT_SYMBOL_GPL(security_path_link);
1002 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1003 const struct path *new_dir, struct dentry *new_dentry,
1004 @@ -485,6 +488,7 @@ int security_path_truncate(const struct path *path)
1006 return call_int_hook(path_truncate, 0, path);
1008 +EXPORT_SYMBOL_GPL(security_path_truncate);
1010 int security_path_chmod(const struct path *path, umode_t mode)
1012 @@ -492,6 +496,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1014 return call_int_hook(path_chmod, 0, path, mode);
1016 +EXPORT_SYMBOL_GPL(security_path_chmod);
1018 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1020 @@ -499,6 +504,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1022 return call_int_hook(path_chown, 0, path, uid, gid);
1024 +EXPORT_SYMBOL_GPL(security_path_chown);
1026 int security_path_chroot(const struct path *path)
1028 @@ -584,6 +590,7 @@ int security_inode_readlink(struct dentry *dentry)
1030 return call_int_hook(inode_readlink, 0, dentry);
1032 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1034 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1036 @@ -599,6 +606,7 @@ int security_inode_permission(struct inode *inode, int mask)
1038 return call_int_hook(inode_permission, 0, inode, mask);
1040 +EXPORT_SYMBOL_GPL(security_inode_permission);
1042 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1044 @@ -737,6 +745,7 @@ int security_file_permission(struct file *file, int mask)
1046 return fsnotify_perm(file, mask);
1048 +EXPORT_SYMBOL_GPL(security_file_permission);
1050 int security_file_alloc(struct file *file)
1052 @@ -796,6 +805,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1054 return ima_file_mmap(file, prot);
1056 +EXPORT_SYMBOL_GPL(security_mmap_file);
1058 int security_mmap_addr(unsigned long addr)
1060 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1061 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1062 +++ linux/Documentation/ABI/testing/debugfs-aufs 2015-09-24 10:47:58.244719488 +0200
1064 +What: /debug/aufs/si_<id>/
1066 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1068 + Under /debug/aufs, a directory named si_<id> is created
1069 + per aufs mount, where <id> is a unique id generated
1072 +What: /debug/aufs/si_<id>/plink
1074 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1076 + It has three lines and shows the information about the
1077 + pseudo-link. The first line is a single number
1078 + representing a number of buckets. The second line is a
1079 + number of pseudo-links per buckets (separated by a
1080 + blank). The last line is a single number representing a
1081 + total number of psedo-links.
1082 + When the aufs mount option 'noplink' is specified, it
1083 + will show "1\n0\n0\n".
1085 +What: /debug/aufs/si_<id>/xib
1087 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1089 + It shows the consumed blocks by xib (External Inode Number
1090 + Bitmap), its block size and file size.
1091 + When the aufs mount option 'noxino' is specified, it
1092 + will be empty. About XINO files, see the aufs manual.
1094 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1096 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1098 + It shows the consumed blocks by xino (External Inode Number
1099 + Translation Table), its link count, block size and file
1101 + When the aufs mount option 'noxino' is specified, it
1102 + will be empty. About XINO files, see the aufs manual.
1104 +What: /debug/aufs/si_<id>/xigen
1106 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1108 + It shows the consumed blocks by xigen (External Inode
1109 + Generation Table), its block size and file size.
1110 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1112 + When the aufs mount option 'noxino' is specified, it
1113 + will be empty. About XINO files, see the aufs manual.
1114 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1115 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1116 +++ linux/Documentation/ABI/testing/sysfs-aufs 2015-09-24 10:47:58.244719488 +0200
1118 +What: /sys/fs/aufs/si_<id>/
1120 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1122 + Under /sys/fs/aufs, a directory named si_<id> is created
1123 + per aufs mount, where <id> is a unique id generated
1126 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1128 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1130 + It shows the abolute path of a member directory (which
1131 + is called branch) in aufs, and its permission.
1133 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1135 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1137 + It shows the id of a member directory (which is called
1140 +What: /sys/fs/aufs/si_<id>/xi_path
1142 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1144 + It shows the abolute path of XINO (External Inode Number
1145 + Bitmap, Translation Table and Generation Table) file
1146 + even if it is the default path.
1147 + When the aufs mount option 'noxino' is specified, it
1148 + will be empty. About XINO files, see the aufs manual.
1149 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1150 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1151 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2016-07-25 19:05:34.807826401 +0200
1154 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1156 +# This program is free software; you can redistribute it and/or modify
1157 +# it under the terms of the GNU General Public License as published by
1158 +# the Free Software Foundation; either version 2 of the License, or
1159 +# (at your option) any later version.
1161 +# This program is distributed in the hope that it will be useful,
1162 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1163 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1164 +# GNU General Public License for more details.
1166 +# You should have received a copy of the GNU General Public License
1167 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1170 +----------------------------------------
1172 +aufs [ei ju: ef es] | [a u f s]
1173 +1. abbrev. for "advanced multi-layered unification filesystem".
1174 +2. abbrev. for "another unionfs".
1175 +3. abbrev. for "auf das" in German which means "on the" in English.
1176 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1177 + But "Filesystem aufs Filesystem" is hard to understand.
1179 +AUFS is a filesystem with features:
1180 +- multi layered stackable unification filesystem, the member directory
1181 + is called as a branch.
1182 +- branch permission and attribute, 'readonly', 'real-readonly',
1183 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1185 +- internal "file copy-on-write".
1186 +- logical deletion, whiteout.
1187 +- dynamic branch manipulation, adding, deleting and changing permission.
1188 +- allow bypassing aufs, user's direct branch access.
1189 +- external inode number translation table and bitmap which maintains the
1190 + persistent aufs inode number.
1191 +- seekable directory, including NFS readdir.
1192 +- file mapping, mmap and sharing pages.
1193 +- pseudo-link, hardlink over branches.
1194 +- loopback mounted filesystem as a branch.
1195 +- several policies to select one among multiple writable branches.
1196 +- revert a single systemcall when an error occurs in aufs.
1200 +Multi Layered Stackable Unification Filesystem
1201 +----------------------------------------------------------------------
1202 +Most people already knows what it is.
1203 +It is a filesystem which unifies several directories and provides a
1204 +merged single directory. When users access a file, the access will be
1205 +passed/re-directed/converted (sorry, I am not sure which English word is
1206 +correct) to the real file on the member filesystem. The member
1207 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1208 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1209 +readonly branch is handled by creating 'whiteout' on the upper writable
1212 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1213 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1214 +different approaches to implement the merged-view.
1215 +The former tries putting it into VFS, and the latter implements as a
1216 +separate filesystem.
1217 +(If I misunderstand about these implementations, please let me know and
1218 +I shall correct it. Because it is a long time ago when I read their
1219 +source files last time).
1221 +UnionMount's approach will be able to small, but may be hard to share
1222 +branches between several UnionMount since the whiteout in it is
1223 +implemented in the inode on branch filesystem and always
1224 +shared. According to Bharata's post, readdir does not seems to be
1226 +There are several missing features known in this implementations such as
1227 +- for users, the inode number may change silently. eg. copy-up.
1228 +- link(2) may break by copy-up.
1229 +- read(2) may get an obsoleted filedata (fstat(2) too).
1230 +- fcntl(F_SETLK) may be broken by copy-up.
1231 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1234 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1235 +merged into mainline. This is another implementation of UnionMount as a
1236 +separated filesystem. All the limitations and known problems which
1237 +UnionMount are equally inherited to "overlay" filesystem.
1239 +Unionfs has a longer history. When I started implementing a stackable
1240 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1241 +inode, dentry and file objects and they have an array pointing lower
1242 +same kind objects. After contributing many patches for Unionfs, I
1243 +re-started my project AUFS (Jun 2006).
1245 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1246 +implemented my own ideas, approaches and enhancements and it became
1247 +totally different one.
1249 +Comparing DM snapshot and fs based implementation
1250 +- the number of bytes to be copied between devices is much smaller.
1251 +- the type of filesystem must be one and only.
1252 +- the fs must be writable, no readonly fs, even for the lower original
1253 + device. so the compression fs will not be usable. but if we use
1254 + loopback mount, we may address this issue.
1256 + mount /cdrom/squashfs.img /sq
1257 + losetup /sq/ext2.img
1258 + losetup /somewhere/cow
1259 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1260 +- it will be difficult (or needs more operations) to extract the
1261 + difference between the original device and COW.
1262 +- DM snapshot-merge may help a lot when users try merging. in the
1263 + fs-layer union, users will use rsync(1).
1265 +You may want to read my old paper "Filesystems in LiveCD"
1266 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1269 +Several characters/aspects/persona of aufs
1270 +----------------------------------------------------------------------
1272 +Aufs has several characters, aspects or persona.
1273 +1. a filesystem, callee of VFS helper
1274 +2. sub-VFS, caller of VFS helper for branches
1275 +3. a virtual filesystem which maintains persistent inode number
1276 +4. reader/writer of files on branches such like an application
1278 +1. Callee of VFS Helper
1279 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1280 +unlink(2) from an application reaches sys_unlink() kernel function and
1281 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1282 +calls filesystem specific unlink operation. Actually aufs implements the
1283 +unlink operation but it behaves like a redirector.
1285 +2. Caller of VFS Helper for Branches
1286 +aufs_unlink() passes the unlink request to the branch filesystem as if
1287 +it were called from VFS. So the called unlink operation of the branch
1288 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1289 +every necessary pre/post operation for the branch filesystem.
1290 +- acquire the lock for the parent dir on a branch
1291 +- lookup in a branch
1292 +- revalidate dentry on a branch
1293 +- mnt_want_write() for a branch
1294 +- vfs_unlink() for a branch
1295 +- mnt_drop_write() for a branch
1296 +- release the lock on a branch
1298 +3. Persistent Inode Number
1299 +One of the most important issue for a filesystem is to maintain inode
1300 +numbers. This is particularly important to support exporting a
1301 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1302 +backend block device for its own. But some storage is necessary to
1303 +keep and maintain the inode numbers. It may be a large space and may not
1304 +suit to keep in memory. Aufs rents some space from its first writable
1305 +branch filesystem (by default) and creates file(s) on it. These files
1306 +are created by aufs internally and removed soon (currently) keeping
1308 +Note: Because these files are removed, they are totally gone after
1309 + unmounting aufs. It means the inode numbers are not persistent
1310 + across unmount or reboot. I have a plan to make them really
1311 + persistent which will be important for aufs on NFS server.
1313 +4. Read/Write Files Internally (copy-on-write)
1314 +Because a branch can be readonly, when you write a file on it, aufs will
1315 +"copy-up" it to the upper writable branch internally. And then write the
1316 +originally requested thing to the file. Generally kernel doesn't
1317 +open/read/write file actively. In aufs, even a single write may cause a
1318 +internal "file copy". This behaviour is very similar to cp(1) command.
1320 +Some people may think it is better to pass such work to user space
1321 +helper, instead of doing in kernel space. Actually I am still thinking
1322 +about it. But currently I have implemented it in kernel space.
1323 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1324 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1325 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2016-07-25 19:05:34.807826401 +0200
1328 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1330 +# This program is free software; you can redistribute it and/or modify
1331 +# it under the terms of the GNU General Public License as published by
1332 +# the Free Software Foundation; either version 2 of the License, or
1333 +# (at your option) any later version.
1335 +# This program is distributed in the hope that it will be useful,
1336 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1337 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1338 +# GNU General Public License for more details.
1340 +# You should have received a copy of the GNU General Public License
1341 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1343 +Basic Aufs Internal Structure
1345 +Superblock/Inode/Dentry/File Objects
1346 +----------------------------------------------------------------------
1347 +As like an ordinary filesystem, aufs has its own
1348 +superblock/inode/dentry/file objects. All these objects have a
1349 +dynamically allocated array and store the same kind of pointers to the
1350 +lower filesystem, branch.
1351 +For example, when you build a union with one readwrite branch and one
1352 +readonly, mounted /au, /rw and /ro respectively.
1354 +- /ro/fileA exists but /rw/fileA
1356 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1357 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1358 +- [0] = NULL (because /rw/fileA doesn't exist)
1361 +This style of an array is essentially same to the aufs
1362 +superblock/inode/dentry/file objects.
1364 +Because aufs supports manipulating branches, ie. add/delete/change
1365 +branches dynamically, these objects has its own generation. When
1366 +branches are changed, the generation in aufs superblock is
1367 +incremented. And a generation in other object are compared when it is
1368 +accessed. When a generation in other objects are obsoleted, aufs
1369 +refreshes the internal array.
1373 +----------------------------------------------------------------------
1374 +Additionally aufs superblock has some data for policies to select one
1375 +among multiple writable branches, XIB files, pseudo-links and kobject.
1376 +See below in detail.
1377 +About the policies which supports copy-down a directory, see
1378 +wbr_policy.txt too.
1381 +Branch and XINO(External Inode Number Translation Table)
1382 +----------------------------------------------------------------------
1383 +Every branch has its own xino (external inode number translation table)
1384 +file. The xino file is created and unlinked by aufs internally. When two
1385 +members of a union exist on the same filesystem, they share the single
1387 +The struct of a xino file is simple, just a sequence of aufs inode
1388 +numbers which is indexed by the lower inode number.
1389 +In the above sample, assume the inode number of /ro/fileA is i111 and
1390 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1391 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1393 +When the inode numbers are not contiguous, the xino file will be sparse
1394 +which has a hole in it and doesn't consume as much disk space as it
1395 +might appear. If your branch filesystem consumes disk space for such
1396 +holes, then you should specify 'xino=' option at mounting aufs.
1398 +Aufs has a mount option to free the disk blocks for such holes in XINO
1399 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1400 +meet a problem of disk shortage due to XINO files, then you should try
1401 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1402 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1403 +the holes in XINO files.
1405 +Also a writable branch has three kinds of "whiteout bases". All these
1406 +are existed when the branch is joined to aufs, and their names are
1407 +whiteout-ed doubly, so that users will never see their names in aufs
1409 +1. a regular file which will be hardlinked to all whiteouts.
1410 +2. a directory to store a pseudo-link.
1411 +3. a directory to store an "orphan"-ed file temporary.
1414 + When you remove a file on a readonly branch, aufs handles it as a
1415 + logical deletion and creates a whiteout on the upper writable branch
1416 + as a hardlink of this file in order not to consume inode on the
1419 + See below, Pseudo-link.
1421 + When "fileC" exists on the lower readonly branch only and it is
1422 + opened and removed with its parent dir, and then user writes
1423 + something into it, then aufs copies-up fileC to this
1424 + directory. Because there is no other dir to store fileC. After
1425 + creating a file under this dir, the file is unlinked.
1427 +Because aufs supports manipulating branches, ie. add/delete/change
1428 +dynamically, a branch has its own id. When the branch order changes,
1429 +aufs finds the new index by searching the branch id.
1433 +----------------------------------------------------------------------
1434 +Assume "fileA" exists on the lower readonly branch only and it is
1435 +hardlinked to "fileB" on the branch. When you write something to fileA,
1436 +aufs copies-up it to the upper writable branch. Additionally aufs
1437 +creates a hardlink under the Pseudo-link Directory of the writable
1438 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1439 +simple list. If fileB is read after unlinking fileA, aufs returns
1440 +filedata from the pseudo-link instead of the lower readonly
1441 +branch. Because the pseudo-link is based upon the inode, to keep the
1442 +inode number by xino (see above) is essentially necessary.
1444 +All the hardlinks under the Pseudo-link Directory of the writable branch
1445 +should be restored in a proper location later. Aufs provides a utility
1446 +to do this. The userspace helpers executed at remounting and unmounting
1448 +During this utility is running, it puts aufs into the pseudo-link
1449 +maintenance mode. In this mode, only the process which began the
1450 +maintenance mode (and its child processes) is allowed to operate in
1451 +aufs. Some other processes which are not related to the pseudo-link will
1452 +be allowed to run too, but the rest have to return an error or wait
1453 +until the maintenance mode ends. If a process already acquires an inode
1454 +mutex (in VFS), it has to return an error.
1457 +XIB(external inode number bitmap)
1458 +----------------------------------------------------------------------
1459 +Addition to the xino file per a branch, aufs has an external inode number
1460 +bitmap in a superblock object. It is also an internal file such like a
1462 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1464 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1466 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1467 +reduce the number of consumed disk blocks for these files.
1470 +Virtual or Vertical Dir, and Readdir in Userspace
1471 +----------------------------------------------------------------------
1472 +In order to support multiple layers (branches), aufs readdir operation
1473 +constructs a virtual dir block on memory. For readdir, aufs calls
1474 +vfs_readdir() internally for each dir on branches, merges their entries
1475 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1476 +object. So the file object has its entry list until it is closed. The
1477 +entry list will be updated when the file position is zero and becomes
1478 +obsoleted. This decision is made in aufs automatically.
1480 +The dynamically allocated memory block for the name of entries has a
1481 +unit of 512 bytes (by default) and stores the names contiguously (no
1482 +padding). Another block for each entry is handled by kmem_cache too.
1483 +During building dir blocks, aufs creates hash list and judging whether
1484 +the entry is whiteouted by its upper branch or already listed.
1485 +The merged result is cached in the corresponding inode object and
1486 +maintained by a customizable life-time option.
1488 +Some people may call it can be a security hole or invite DoS attack
1489 +since the opened and once readdir-ed dir (file object) holds its entry
1490 +list and becomes a pressure for system memory. But I'd say it is similar
1491 +to files under /proc or /sys. The virtual files in them also holds a
1492 +memory page (generally) while they are opened. When an idea to reduce
1493 +memory for them is introduced, it will be applied to aufs too.
1494 +For those who really hate this situation, I've developed readdir(3)
1495 +library which operates this merging in userspace. You just need to set
1496 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1497 +kernel space for readdir(3).
1501 +----------------------------------------------------------------------
1502 +Aufs sometimes requires privilege access to a branch. For instance,
1503 +in copy-up/down operation. When a user process is going to make changes
1504 +to a file which exists in the lower readonly branch only, and the mode
1505 +of one of ancestor directories may not be writable by a user
1506 +process. Here aufs copy-up the file with its ancestors and they may
1507 +require privilege to set its owner/group/mode/etc.
1508 +This is a typical case of a application character of aufs (see
1511 +Aufs uses workqueue synchronously for this case. It creates its own
1512 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1513 +passes the request to call mkdir or write (for example), and wait for
1514 +its completion. This approach solves a problem of a signal handler
1516 +If aufs didn't adopt the workqueue and changed the privilege of the
1517 +process, then the process may receive the unexpected SIGXFSZ or other
1520 +Also aufs uses the system global workqueue ("events" kernel thread) too
1521 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1522 +whiteout base and etc. This is unrelated to a privilege.
1523 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1524 +superblock at the beginning, at the same time waits for the completion
1525 +of all queued asynchronous tasks.
1529 +----------------------------------------------------------------------
1530 +The whiteout in aufs is very similar to Unionfs's. That is represented
1531 +by its filename. UnionMount takes an approach of a file mode, but I am
1532 +afraid several utilities (find(1) or something) will have to support it.
1534 +Basically the whiteout represents "logical deletion" which stops aufs to
1535 +lookup further, but also it represents "dir is opaque" which also stop
1538 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1539 +In order to make several functions in a single systemcall to be
1540 +revertible, aufs adopts an approach to rename a directory to a temporary
1541 +unique whiteouted name.
1542 +For example, in rename(2) dir where the target dir already existed, aufs
1543 +renames the target dir to a temporary unique whiteouted name before the
1544 +actual rename on a branch, and then handles other actions (make it opaque,
1545 +update the attributes, etc). If an error happens in these actions, aufs
1546 +simply renames the whiteouted name back and returns an error. If all are
1547 +succeeded, aufs registers a function to remove the whiteouted unique
1548 +temporary name completely and asynchronously to the system global
1553 +----------------------------------------------------------------------
1554 +It is a well-known feature or concept.
1555 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1556 +internally and makes change to the new file on the upper writable branch.
1557 +When the trigger systemcall does not update the timestamps of the parent
1558 +dir, aufs reverts it after copy-up.
1561 +Move-down (aufs3.9 and later)
1562 +----------------------------------------------------------------------
1563 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1564 +the lower readonly branch to the upper writable branch when a user
1565 +changes something about the file.
1566 +"Move-down" is an opposite action of copy-up. Basically this action is
1567 +ran manually instead of automatically and internally.
1568 +For desgin and implementation, aufs has to consider these issues.
1569 +- whiteout for the file may exist on the lower branch.
1570 +- ancestor directories may not exist on the lower branch.
1571 +- diropq for the ancestor directories may exist on the upper branch.
1572 +- free space on the lower branch will reduce.
1573 +- another access to the file may happen during moving-down, including
1574 + UDBA (see "Revalidate Dentry and UDBA").
1575 +- the file should not be hard-linked nor pseudo-linked. they should be
1576 + handled by auplink utility later.
1578 +Sometimes users want to move-down a file from the upper writable branch
1579 +to the lower readonly or writable branch. For instance,
1580 +- the free space of the upper writable branch is going to run out.
1581 +- create a new intermediate branch between the upper and lower branch.
1584 +For this purpose, use "aumvdown" command in aufs-util.git.
1585 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1586 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1587 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2016-07-25 19:05:34.807826401 +0200
1590 +# Copyright (C) 2015-2016 Junjiro R. Okajima
1592 +# This program is free software; you can redistribute it and/or modify
1593 +# it under the terms of the GNU General Public License as published by
1594 +# the Free Software Foundation; either version 2 of the License, or
1595 +# (at your option) any later version.
1597 +# This program is distributed in the hope that it will be useful,
1598 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1599 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1600 +# GNU General Public License for more details.
1602 +# You should have received a copy of the GNU General Public License
1603 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1605 +Support for a branch who has its ->atomic_open()
1606 +----------------------------------------------------------------------
1607 +The filesystems who implement its ->atomic_open() are not majority. For
1608 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1609 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1610 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1611 +sure whether all filesystems who have ->atomic_open() behave like this,
1612 +but NFSv4 surely returns the error.
1614 +In order to support ->atomic_open() for aufs, there are a few
1617 +A. Introduce aufs_atomic_open()
1618 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1620 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1621 + an aufs user Pip Cet's approach
1622 + - calls aufs_create(), VFS finish_open() and notify_change().
1623 + - pass fake-mode to finish_open(), and then correct the mode by
1625 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1626 + - no aufs_atomic_open().
1627 + - aufs_lookup() registers the TID to an aufs internal object.
1628 + - aufs_create() does nothing when the matching TID is registered, but
1629 + registers the mode.
1630 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1631 + TID is registered.
1632 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1634 + - no aufs_atomic_open().
1635 + - aufs_create() registers the TID to an internal object. this info
1636 + represents "this process created this file just now."
1637 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1638 + registered TID and re-try open() with superuser's credential.
1640 +Pros and cons for each approach.
1643 + - straightforward but highly depends upon VFS internal.
1644 + - the atomic behavaiour is kept.
1645 + - some of parameters such as nameidata are hard to reproduce for
1649 + - easy to implement.
1650 + - the atomic behavaiour is lost.
1652 + - the atomic behavaiour is kept.
1653 + - dirty and tricky.
1654 + - VFS checks whether the file is created correctly after calling
1655 + ->create(), which means this approach doesn't work.
1657 + - easy to implement.
1658 + - the atomic behavaiour is lost.
1659 + - to open a file with superuser's credential and give it to a user
1660 + process is a bad idea, since the file object keeps the credential
1661 + in it. It may affect LSM or something. This approach doesn't work
1664 +The approach A is ideal, but it hard to implement. So here is a
1665 +variation of A, which is to be implemented.
1667 +A-1. Introduce aufs_atomic_open()
1668 + - calls branch fs ->atomic_open() if exists. otherwise calls
1669 + vfs_create() and finish_open().
1670 + - the demerit is that the several checks after branch fs
1671 + ->atomic_open() are lost. in the ordinary case, the checks are
1672 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1673 + be implemented in aufs, but not all I am afraid.
1674 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1675 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1676 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2016-07-25 19:05:34.807826401 +0200
1679 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1681 +# This program is free software; you can redistribute it and/or modify
1682 +# it under the terms of the GNU General Public License as published by
1683 +# the Free Software Foundation; either version 2 of the License, or
1684 +# (at your option) any later version.
1686 +# This program is distributed in the hope that it will be useful,
1687 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1688 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1689 +# GNU General Public License for more details.
1691 +# You should have received a copy of the GNU General Public License
1692 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1695 +----------------------------------------------------------------------
1696 +Since aufs has a character of sub-VFS (see Introduction), it operates
1697 +lookup for branches as VFS does. It may be a heavy work. But almost all
1698 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1699 +directly connected to its parent. Digging down the directory hierarchy
1700 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1703 +When a branch is a remote filesystem, aufs basically relies upon its
1704 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1706 +For d_revalidate, aufs implements three levels of revalidate tests. See
1707 +"Revalidate Dentry and UDBA" in detail.
1710 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1711 +----------------------------------------------------------------------
1712 +Let's try case study.
1713 +- aufs has two branches, upper readwrite and lower readonly.
1715 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1716 +- user invoked "chmod a+rx /au/dirA"
1717 +- the internal copy-up is activated and "/rw/dirA" is created and its
1718 + permission bits are set to world readable.
1719 +- then "/au/dirA" becomes world readable?
1721 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1722 +or it may be a natively readonly filesystem. If aufs respects the lower
1723 +branch, it should not respond readdir request from other users. But user
1724 +allowed it by chmod. Should really aufs rejects showing the entries
1727 +To be honest, I don't have a good solution for this case. So aufs
1728 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1730 +When dirperm1 is specified, aufs checks only the highest one for the
1731 +directory permission, and shows the entries. Otherwise, as usual, checks
1732 +every dir existing on all branches and rejects the request.
1734 +As a side effect, dirperm1 option improves the performance of aufs
1735 +because the number of permission check is reduced when the number of
1739 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1740 +----------------------------------------------------------------------
1741 +Generally VFS helpers re-validate a dentry as a part of lookup.
1742 +0. digging down the directory hierarchy.
1743 +1. lock the parent dir by its i_mutex.
1744 +2. lookup the final (child) entry.
1746 +4. call the actual operation (create, unlink, etc.)
1747 +5. unlock the parent dir
1749 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1750 +called. Actually aufs implements it and checks the dentry on a branch is
1752 +But it is not enough. Because aufs has to release the lock for the
1753 +parent dir on a branch at the end of ->lookup() (step 2) and
1754 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1756 +If the file on a branch is changed directly, eg. bypassing aufs, after
1757 +aufs released the lock, then the subsequent operation may cause
1758 +something unpleasant result.
1760 +This situation is a result of VFS architecture, ->lookup() and
1761 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1762 +design from VFS's point of view. It is just not suitable for sub-VFS
1765 +Aufs supports such case by three level of revalidation which is
1766 +selectable by user.
1767 +1. Simple Revalidate
1768 + Addition to the native flow in VFS's, confirm the child-parent
1769 + relationship on the branch just after locking the parent dir on the
1770 + branch in the "actual operation" (step 4). When this validation
1771 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1772 + checks the validation of the dentry on branches.
1773 +2. Monitor Changes Internally by Inotify/Fsnotify
1774 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1775 + the dentry on the branch, and returns EBUSY if it finds different
1777 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1778 + during it is in cache. When the event is notified, aufs registers a
1779 + function to kernel 'events' thread by schedule_work(). And the
1780 + function sets some special status to the cached aufs dentry and inode
1781 + private data. If they are not cached, then aufs has nothing to
1782 + do. When the same file is accessed through aufs (step 0-3) later,
1783 + aufs will detect the status and refresh all necessary data.
1784 + In this mode, aufs has to ignore the event which is fired by aufs
1786 +3. No Extra Validation
1787 + This is the simplest test and doesn't add any additional revalidation
1788 + test, and skip the revalidation in step 4. It is useful and improves
1789 + aufs performance when system surely hide the aufs branches from user,
1790 + by over-mounting something (or another method).
1791 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1792 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1793 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2016-07-25 19:05:34.807826401 +0200
1796 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1798 +# This program is free software; you can redistribute it and/or modify
1799 +# it under the terms of the GNU General Public License as published by
1800 +# the Free Software Foundation; either version 2 of the License, or
1801 +# (at your option) any later version.
1803 +# This program is distributed in the hope that it will be useful,
1804 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1805 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1806 +# GNU General Public License for more details.
1808 +# You should have received a copy of the GNU General Public License
1809 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1811 +Branch Manipulation
1813 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1814 +and changing its permission/attribute, there are a lot of works to do.
1818 +----------------------------------------------------------------------
1819 +o Confirm the adding dir exists outside of aufs, including loopback
1820 + mount, and its various attributes.
1821 +o Initialize the xino file and whiteout bases if necessary.
1824 +o Check the owner/group/mode of the directory
1825 + When the owner/group/mode of the adding directory differs from the
1826 + existing branch, aufs issues a warning because it may impose a
1828 + For example, when a upper writable branch has a world writable empty
1829 + top directory, a malicious user can create any files on the writable
1830 + branch directly, like copy-up and modify manually. If something like
1831 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1832 + writable branch, and the writable branch is world-writable, then a
1833 + malicious guy may create /etc/passwd on the writable branch directly
1834 + and the infected file will be valid in aufs.
1835 + I am afraid it can be a security issue, but aufs can do nothing except
1836 + producing a warning.
1840 +----------------------------------------------------------------------
1841 +o Confirm the deleting branch is not busy
1842 + To be general, there is one merit to adopt "remount" interface to
1843 + manipulate branches. It is to discard caches. At deleting a branch,
1844 + aufs checks the still cached (and connected) dentries and inodes. If
1845 + there are any, then they are all in-use. An inode without its
1846 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1848 + For the cached one, aufs checks whether the same named entry exists on
1850 + If the cached one is a directory, because aufs provides a merged view
1851 + to users, as long as one dir is left on any branch aufs can show the
1852 + dir to users. In this case, the branch can be removed from aufs.
1853 + Otherwise aufs rejects deleting the branch.
1855 + If any file on the deleting branch is opened by aufs, then aufs
1859 +Modify the Permission of a Branch
1860 +----------------------------------------------------------------------
1861 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1864 +o rw --> ro: Confirm the modifying branch is not busy
1865 + Aufs rejects the request if any of these conditions are true.
1866 + - a file on the branch is mmap-ed.
1867 + - a regular file on the branch is opened for write and there is no
1868 + same named entry on the upper branch.
1869 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1870 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1871 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2016-07-25 19:05:34.807826401 +0200
1874 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1876 +# This program is free software; you can redistribute it and/or modify
1877 +# it under the terms of the GNU General Public License as published by
1878 +# the Free Software Foundation; either version 2 of the License, or
1879 +# (at your option) any later version.
1881 +# This program is distributed in the hope that it will be useful,
1882 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1883 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1884 +# GNU General Public License for more details.
1886 +# You should have received a copy of the GNU General Public License
1887 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1889 +Policies to Select One among Multiple Writable Branches
1890 +----------------------------------------------------------------------
1891 +When the number of writable branch is more than one, aufs has to decide
1892 +the target branch for file creation or copy-up. By default, the highest
1893 +writable branch which has the parent (or ancestor) dir of the target
1894 +file is chosen (top-down-parent policy).
1895 +By user's request, aufs implements some other policies to select the
1896 +writable branch, for file creation several policies, round-robin,
1897 +most-free-space, and other policies. For copy-up, top-down-parent,
1898 +bottom-up-parent, bottom-up and others.
1900 +As expected, the round-robin policy selects the branch in circular. When
1901 +you have two writable branches and creates 10 new files, 5 files will be
1902 +created for each branch. mkdir(2) systemcall is an exception. When you
1903 +create 10 new directories, all will be created on the same branch.
1904 +And the most-free-space policy selects the one which has most free
1905 +space among the writable branches. The amount of free space will be
1906 +checked by aufs internally, and users can specify its time interval.
1908 +The policies for copy-up is more simple,
1909 +top-down-parent is equivalent to the same named on in create policy,
1910 +bottom-up-parent selects the writable branch where the parent dir
1911 +exists and the nearest upper one from the copyup-source,
1912 +bottom-up selects the nearest upper writable branch from the
1913 +copyup-source, regardless the existence of the parent dir.
1915 +There are some rules or exceptions to apply these policies.
1916 +- If there is a readonly branch above the policy-selected branch and
1917 + the parent dir is marked as opaque (a variation of whiteout), or the
1918 + target (creating) file is whiteout-ed on the upper readonly branch,
1919 + then the result of the policy is ignored and the target file will be
1920 + created on the nearest upper writable branch than the readonly branch.
1921 +- If there is a writable branch above the policy-selected branch and
1922 + the parent dir is marked as opaque or the target file is whiteouted
1923 + on the branch, then the result of the policy is ignored and the target
1924 + file will be created on the highest one among the upper writable
1925 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1927 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1928 + They try selecting the branch where the source exists as possible
1929 + since copyup a large file will take long time. If it can't be,
1930 + ie. the branch where the source exists is readonly, then they will
1931 + follow the copyup policy.
1932 +- There is an exception for rename(2) when the target exists.
1933 + If the rename target exists, aufs compares the index of the branches
1934 + where the source and the target exists and selects the higher
1935 + one. If the selected branch is readonly, then aufs follows the
1937 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1938 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1939 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2016-07-25 19:05:34.807826401 +0200
1942 +# Copyright (C) 2011-2016 Junjiro R. Okajima
1944 +# This program is free software; you can redistribute it and/or modify
1945 +# it under the terms of the GNU General Public License as published by
1946 +# the Free Software Foundation; either version 2 of the License, or
1947 +# (at your option) any later version.
1949 +# This program is distributed in the hope that it will be useful,
1950 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1951 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1952 +# GNU General Public License for more details.
1954 +# You should have received a copy of the GNU General Public License
1955 +# along with this program; if not, write to the Free Software
1956 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1959 +File-based Hierarchical Storage Management (FHSM)
1960 +----------------------------------------------------------------------
1961 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1962 +storage world. Aufs provides this feature as file-based with multiple
1963 +writable branches, based upon the principle of "Colder, the Lower".
1964 +Here the word "colder" means that the less used files, and "lower" means
1965 +that the position in the order of the stacked branches vertically.
1966 +These multiple writable branches are prioritized, ie. the topmost one
1967 +should be the fastest drive and be used heavily.
1969 +o Characters in aufs FHSM story
1970 +- aufs itself and a new branch attribute.
1971 +- a new ioctl interface to move-down and to establish a connection with
1972 + the daemon ("move-down" is a converse of "copy-up").
1973 +- userspace tool and daemon.
1975 +The userspace daemon establishes a connection with aufs and waits for
1976 +the notification. The notified information is very similar to struct
1977 +statfs containing the number of consumed blocks and inodes.
1978 +When the consumed blocks/inodes of a branch exceeds the user-specified
1979 +upper watermark, the daemon activates its move-down process until the
1980 +consumed blocks/inodes reaches the user-specified lower watermark.
1982 +The actual move-down is done by aufs based upon the request from
1983 +user-space since we need to maintain the inode number and the internal
1984 +pointer arrays in aufs.
1986 +Currently aufs FHSM handles the regular files only. Additionally they
1987 +must not be hard-linked nor pseudo-linked.
1990 +o Cowork of aufs and the user-space daemon
1991 + During the userspace daemon established the connection, aufs sends a
1992 + small notification to it whenever aufs writes something into the
1993 + writable branch. But it may cost high since aufs issues statfs(2)
1994 + internally. So user can specify a new option to cache the
1995 + info. Actually the notification is controlled by these factors.
1996 + + the specified cache time.
1997 + + classified as "force" by aufs internally.
1998 + Until the specified time expires, aufs doesn't send the info
1999 + except the forced cases. When aufs decide forcing, the info is always
2000 + notified to userspace.
2001 + For example, the number of free inodes is generally large enough and
2002 + the shortage of it happens rarely. So aufs doesn't force the
2003 + notification when creating a new file, directory and others. This is
2004 + the typical case which aufs doesn't force.
2005 + When aufs writes the actual filedata and the files consumes any of new
2006 + blocks, the aufs forces notifying.
2009 +o Interfaces in aufs
2010 +- New branch attribute.
2012 + Specifies that the branch is managed by FHSM feature. In other word,
2013 + participant in the FHSM.
2014 + When nofhsm is set to the branch, it will not be the source/target
2015 + branch of the move-down operation. This attribute is set
2016 + independently from coo and moo attributes, and if you want full
2017 + FHSM, you should specify them as well.
2018 +- New mount option.
2020 + Specifies a second to suppress many less important info to be
2023 + + AUFS_CTL_FHSM_FD
2024 + create a new file descriptor which userspace can read the notification
2025 + (a subset of struct statfs) from aufs.
2026 +- Module parameter 'brs'
2027 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2029 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2030 + When there are two or more branches with fhsm attributes,
2031 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2032 + terminates it. As a result of remounting and branch-manipulation, the
2033 + number of branches with fhsm attribute can be one. In this case,
2034 + /sbin/mount.aufs will terminate the user-space daemon.
2037 +Finally the operation is done as these steps in kernel-space.
2039 + + no one else is using the file.
2040 + + the file is not hard-linked.
2041 + + the file is not pseudo-linked.
2042 + + the file is a regular file.
2043 + + the parent dir is not opaqued.
2044 +- find the target writable branch.
2045 +- make sure the file is not whiteout-ed by the upper (than the target)
2047 +- make the parent dir on the target branch.
2048 +- mutex lock the inode on the branch.
2049 +- unlink the whiteout on the target branch (if exists).
2050 +- lookup and create the whiteout-ed temporary name on the target branch.
2051 +- copy the file as the whiteout-ed temporary name on the target branch.
2052 +- rename the whiteout-ed temporary name to the original name.
2053 +- unlink the file on the source branch.
2054 +- maintain the internal pointer array and the external inode number
2056 +- maintain the timestamps and other attributes of the parent dir and the
2059 +And of course, in every step, an error may happen. So the operation
2060 +should restore the original file state after an error happens.
2061 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2062 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2063 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2016-07-25 19:05:34.807826401 +0200
2066 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2068 +# This program is free software; you can redistribute it and/or modify
2069 +# it under the terms of the GNU General Public License as published by
2070 +# the Free Software Foundation; either version 2 of the License, or
2071 +# (at your option) any later version.
2073 +# This program is distributed in the hope that it will be useful,
2074 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2075 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2076 +# GNU General Public License for more details.
2078 +# You should have received a copy of the GNU General Public License
2079 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2081 +mmap(2) -- File Memory Mapping
2082 +----------------------------------------------------------------------
2083 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2084 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2086 +This approach is simple and good, but there is one problem.
2087 +Under /proc, several entries show the mmapped files by its path (with
2088 +device and inode number), and the printed path will be the path on the
2089 +branch fs's instead of virtual aufs's.
2090 +This is not a problem in most cases, but some utilities lsof(1) (and its
2091 +user) may expect the path on aufs.
2093 +To address this issue, aufs adds a new member called vm_prfile in struct
2094 +vm_area_struct (and struct vm_region). The original vm_file points to
2095 +the file on the branch fs in order to handle everything correctly as
2096 +usual. The new vm_prfile points to a virtual file in aufs, and the
2097 +show-functions in procfs refers to vm_prfile if it is set.
2098 +Also we need to maintain several other places where touching vm_file
2100 +- fork()/clone() copies vma and the reference count of vm_file is
2102 +- merging vma maintains the ref count too.
2104 +This is not a good approach. It just fakes the printed path. But it
2105 +leaves all behaviour around f_mapping unchanged. This is surely an
2107 +Actually aufs had adopted another complicated approach which calls
2108 +generic_file_mmap() and handles struct vm_operations_struct. In this
2109 +approach, aufs met a hard problem and I could not solve it without
2110 +switching the approach.
2112 +There may be one more another approach which is
2113 +- bind-mount the branch-root onto the aufs-root internally
2114 +- grab the new vfsmount (ie. struct mount)
2115 +- lazy-umount the branch-root internally
2116 +- in open(2) the aufs-file, open the branch-file with the hidden
2117 + vfsmount (instead of the original branch's vfsmount)
2118 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2119 + but it may be possible from userspace by the mount helper.
2121 +Adding the internal hidden vfsmount and using it in opening a file, the
2122 +file path under /proc will be printed correctly. This approach looks
2123 +smarter, but is not possible I am afraid.
2124 +- aufs-root may be bind-mount later. when it happens, another hidden
2125 + vfsmount will be required.
2126 +- it is hard to get the chance to bind-mount and lazy-umount
2127 + + in kernel-space, FS can have vfsmount in open(2) via
2128 + file->f_path, and aufs can know its vfsmount. But several locks are
2129 + already acquired, and if aufs tries to bind-mount and lazy-umount
2130 + here, then it may cause a deadlock.
2131 + + in user-space, bind-mount doesn't invoke the mount helper.
2132 +- since /proc shows dev and ino, aufs has to give vma these info. it
2133 + means a new member vm_prinode will be necessary. this is essentially
2134 + equivalent to vm_prfile described above.
2136 +I have to give up this "looks-smater" approach.
2137 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2138 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2139 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2016-07-25 19:05:34.807826401 +0200
2142 +# Copyright (C) 2014-2016 Junjiro R. Okajima
2144 +# This program is free software; you can redistribute it and/or modify
2145 +# it under the terms of the GNU General Public License as published by
2146 +# the Free Software Foundation; either version 2 of the License, or
2147 +# (at your option) any later version.
2149 +# This program is distributed in the hope that it will be useful,
2150 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2151 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2152 +# GNU General Public License for more details.
2154 +# You should have received a copy of the GNU General Public License
2155 +# along with this program; if not, write to the Free Software
2156 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2159 +Listing XATTR/EA and getting the value
2160 +----------------------------------------------------------------------
2161 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2162 +shows the values from the topmost existing file. This behaviour is good
2163 +for the non-dir entries since the bahaviour exactly matches the shown
2164 +information. But for the directories, aufs considers all the same named
2165 +entries on the lower branches. Which means, if one of the lower entry
2166 +rejects readdir call, then aufs returns an error even if the topmost
2167 +entry allows it. This behaviour is necessary to respect the branch fs's
2168 +security, but can make users confused since the user-visible standard
2169 +attributes don't match the behaviour.
2170 +To address this issue, aufs has a mount option called dirperm1 which
2171 +checks the permission for the topmost entry only, and ignores the lower
2172 +entry's permission.
2174 +A similar issue can happen around XATTR.
2175 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2176 +always set. Otherwise these very unpleasant situation would happen.
2177 +- listxattr(2) may return the duplicated entries.
2178 +- users may not be able to remove or reset the XATTR forever,
2181 +XATTR/EA support in the internal (copy,move)-(up,down)
2182 +----------------------------------------------------------------------
2183 +Generally the extended attributes of inode are categorized as these.
2184 +- "security" for LSM and capability.
2185 +- "system" for posix ACL, 'acl' mount option is required for the branch
2187 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2188 +- "user" for userspace, 'user_xattr' mount option is required for the
2189 + branch fs generally.
2191 +Moreover there are some other categories. Aufs handles these rather
2192 +unpopular categories as the ordinary ones, ie. there is no special
2193 +condition nor exception.
2195 +In copy-up, the support for XATTR on the dst branch may differ from the
2196 +src branch. In this case, the copy-up operation will get an error and
2197 +the original user operation which triggered the copy-up will fail. It
2198 +can happen that even all copy-up will fail.
2199 +When both of src and dst branches support XATTR and if an error occurs
2200 +during copying XATTR, then the copy-up should fail obviously. That is a
2201 +good reason and aufs should return an error to userspace. But when only
2202 +the src branch support that XATTR, aufs should not return an error.
2203 +For example, the src branch supports ACL but the dst branch doesn't
2204 +because the dst branch may natively un-support it or temporary
2205 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2206 +may NOT return an error even if the XATTR is not supported. It is
2207 +totally up to the branch fs.
2209 +Anyway when the aufs internal copy-up gets an error from the dst branch
2210 +fs, then aufs tries removing the just copied entry and returns the error
2211 +to the userspace. The worst case of this situation will be all copy-up
2214 +For the copy-up operation, there two basic approaches.
2215 +- copy the specified XATTR only (by category above), and return the
2216 + error unconditionally if it happens.
2217 +- copy all XATTR, and ignore the error on the specified category only.
2219 +In order to support XATTR and to implement the correct behaviour, aufs
2220 +chooses the latter approach and introduces some new branch attributes,
2221 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2222 +They correspond to the XATTR namespaces (see above). Additionally, to be
2223 +convenient, "icex" is also provided which means all "icex*" attributes
2224 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2226 +The meaning of these attributes is to ignore the error from setting
2227 +XATTR on that branch.
2228 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2229 +error from the dst branch according to the specified attributes.
2231 +Some XATTR may have its default value. The default value may come from
2232 +the parent dir or the environment. If the default value is set at the
2233 +file creating-time, it will be overwritten by copy-up.
2234 +Some contradiction may happen I am afraid.
2235 +Do we need another attribute to stop copying XATTR? I am unsure. For
2236 +now, aufs implements the branch attributes to ignore the error.
2237 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2238 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2239 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2016-07-25 19:05:34.807826401 +0200
2242 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2244 +# This program is free software; you can redistribute it and/or modify
2245 +# it under the terms of the GNU General Public License as published by
2246 +# the Free Software Foundation; either version 2 of the License, or
2247 +# (at your option) any later version.
2249 +# This program is distributed in the hope that it will be useful,
2250 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2251 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2252 +# GNU General Public License for more details.
2254 +# You should have received a copy of the GNU General Public License
2255 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2257 +Export Aufs via NFS
2258 +----------------------------------------------------------------------
2259 +Here is an approach.
2260 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2262 +- iget_locked(): initialize aufs inode generation for a new inode, and
2263 + store it in xigen file.
2264 +- destroy_inode(): increment aufs inode generation and store it in xigen
2265 + file. it is necessary even if it is not unlinked, because any data of
2266 + inode may be changed by UDBA.
2267 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2268 + build file handle by
2269 + + branch id (4 bytes)
2270 + + superblock generation (4 bytes)
2271 + + inode number (4 or 8 bytes)
2272 + + parent dir inode number (4 or 8 bytes)
2273 + + inode generation (4 bytes))
2274 + + return value of exportfs_encode_fh() for the parent on a branch (4
2276 + + file handle for a branch (by exportfs_encode_fh())
2278 + + find the index of a branch from its id in handle, and check it is
2279 + still exist in aufs.
2280 + + 1st level: get the inode number from handle and search it in cache.
2281 + + 2nd level: if not found in cache, get the parent inode number from
2282 + the handle and search it in cache. and then open the found parent
2283 + dir, find the matching inode number by vfs_readdir() and get its
2284 + name, and call lookup_one_len() for the target dentry.
2285 + + 3rd level: if the parent dir is not cached, call
2286 + exportfs_decode_fh() for a branch and get the parent on a branch,
2287 + build a pathname of it, convert it a pathname in aufs, call
2288 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2290 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2291 + for every branch, but not itself. to get this, (currently) aufs
2292 + searches in current->nsproxy->mnt_ns list. it may not be a good
2293 + idea, but I didn't get other approach.
2294 + + test the generation of the gotten inode.
2295 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2296 + convert it into ESTALE for NFSD.
2297 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2298 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2299 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2300 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2301 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2016-07-25 19:05:34.807826401 +0200
2304 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2306 +# This program is free software; you can redistribute it and/or modify
2307 +# it under the terms of the GNU General Public License as published by
2308 +# the Free Software Foundation; either version 2 of the License, or
2309 +# (at your option) any later version.
2311 +# This program is distributed in the hope that it will be useful,
2312 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2313 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2314 +# GNU General Public License for more details.
2316 +# You should have received a copy of the GNU General Public License
2317 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2319 +Show Whiteout Mode (shwh)
2320 +----------------------------------------------------------------------
2321 +Generally aufs hides the name of whiteouts. But in some cases, to show
2322 +them is very useful for users. For instance, creating a new middle layer
2323 +(branch) by merging existing layers.
2325 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2326 +When you have three branches,
2327 +- Bottom: 'system', squashfs (underlying base system), read-only
2328 +- Middle: 'mods', squashfs, read-only
2329 +- Top: 'overlay', ram (tmpfs), read-write
2331 +The top layer is loaded at boot time and saved at shutdown, to preserve
2332 +the changes made to the system during the session.
2333 +When larger changes have been made, or smaller changes have accumulated,
2334 +the size of the saved top layer data grows. At this point, it would be
2335 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2336 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2337 +restoring save and load speed.
2339 +This merging is simplified by the use of another aufs mount, of just the
2340 +two overlay branches using the 'shwh' option.
2341 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2342 + aufs /livesys/merge_union
2344 +A merged view of these two branches is then available at
2345 +/livesys/merge_union, and the new feature is that the whiteouts are
2347 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2348 +writing to all branches. Also the default mode for all branches is 'ro'.
2349 +It is now possible to save the combined contents of the two overlay
2350 +branches to a new squashfs, e.g.:
2351 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2353 +This new squashfs archive can be stored on the boot device and the
2354 +initramfs will use it to replace the old one at the next boot.
2355 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2356 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2357 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2016-07-25 19:05:34.807826401 +0200
2360 +# Copyright (C) 2010-2016 Junjiro R. Okajima
2362 +# This program is free software; you can redistribute it and/or modify
2363 +# it under the terms of the GNU General Public License as published by
2364 +# the Free Software Foundation; either version 2 of the License, or
2365 +# (at your option) any later version.
2367 +# This program is distributed in the hope that it will be useful,
2368 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2369 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2370 +# GNU General Public License for more details.
2372 +# You should have received a copy of the GNU General Public License
2373 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2375 +Dynamically customizable FS operations
2376 +----------------------------------------------------------------------
2377 +Generally FS operations (struct inode_operations, struct
2378 +address_space_operations, struct file_operations, etc.) are defined as
2379 +"static const", but it never means that FS have only one set of
2380 +operation. Some FS have multiple sets of them. For instance, ext2 has
2381 +three sets, one for XIP, for NOBH, and for normal.
2382 +Since aufs overrides and redirects these operations, sometimes aufs has
2383 +to change its behaviour according to the branch FS type. More importantly
2384 +VFS acts differently if a function (member in the struct) is set or
2385 +not. It means aufs should have several sets of operations and select one
2386 +among them according to the branch FS definition.
2388 +In order to solve this problem and not to affect the behaviour of VFS,
2389 +aufs defines these operations dynamically. For instance, aufs defines
2390 +dummy direct_IO function for struct address_space_operations, but it may
2391 +not be set to the address_space_operations actually. When the branch FS
2392 +doesn't have it, aufs doesn't set it to its address_space_operations
2393 +while the function definition itself is still alive. So the behaviour
2394 +itself will not change, and it will return an error when direct_IO is
2397 +The lifetime of these dynamically generated operation object is
2398 +maintained by aufs branch object. When the branch is removed from aufs,
2399 +the reference counter of the object is decremented. When it reaches
2400 +zero, the dynamically generated operation object will be freed.
2402 +This approach is designed to support AIO (io_submit), Direct I/O and
2404 +Currently this approach is applied to address_space_operations for
2405 +regular files only.
2406 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2407 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2408 +++ linux/Documentation/filesystems/aufs/README 2016-07-25 19:05:34.807826401 +0200
2411 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2417 +----------------------------------------
2418 +In the early days, aufs was entirely re-designed and re-implemented
2419 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2420 +improvements and implementations, it becomes totally different from
2421 +Unionfs while keeping the basic features.
2422 +Recently, Unionfs Version 2.x series begin taking some of the same
2423 +approaches to aufs1's.
2424 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2425 +University and his team.
2427 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2428 +If you want older kernel version support, try aufs2-2.6.git or
2429 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2431 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2432 + According to Christoph Hellwig, linux rejects all union-type
2433 + filesystems but UnionMount.
2434 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2436 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2437 + UnionMount, and he pointed out an issue around a directory mutex
2438 + lock and aufs addressed it. But it is still unsure whether aufs will
2439 + be merged (or any other union solution).
2440 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2444 +----------------------------------------
2445 +- unite several directories into a single virtual filesystem. The member
2446 + directory is called as a branch.
2447 +- you can specify the permission flags to the branch, which are 'readonly',
2448 + 'readwrite' and 'whiteout-able.'
2449 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2450 + readonly branch are modifiable logically.
2451 +- dynamic branch manipulation, add, del.
2454 +Also there are many enhancements in aufs, such as:
2455 +- test only the highest one for the directory permission (dirperm1)
2456 +- copyup on open (coo=)
2457 +- 'move' policy for copy-up between two writable branches, after
2458 + checking free space.
2460 +- readdir(3) in userspace.
2461 +- keep inode number by external inode number table
2462 +- keep the timestamps of file/dir in internal copyup operation
2463 +- seekable directory, supporting NFS readdir.
2464 +- whiteout is hardlinked in order to reduce the consumption of inodes
2466 +- do not copyup, nor create a whiteout when it is unnecessary
2467 +- revert a single systemcall when an error occurs in aufs
2468 +- remount interface instead of ioctl
2469 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2470 +- loopback mounted filesystem as a branch
2471 +- kernel thread for removing the dir who has a plenty of whiteouts
2472 +- support copyup sparse file (a file which has a 'hole' in it)
2473 +- default permission flags for branches
2474 +- selectable permission flags for ro branch, whether whiteout can
2477 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2478 +- support multiple writable branches, some policies to select one
2479 + among multiple writable branches.
2480 +- a new semantics for link(2) and rename(2) to support multiple
2481 + writable branches.
2482 +- no glibc changes are required.
2483 +- pseudo hardlink (hardlink over branches)
2484 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2485 + including NFS or remote filesystem branch.
2486 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2489 +Currently these features are dropped temporary from aufs4.
2490 +See design/08plan.txt in detail.
2491 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2493 +- statistics of aufs thread (/sys/fs/aufs/stat)
2495 +Features or just an idea in the future (see also design/*.txt),
2496 +- reorder the branch index without del/re-add.
2497 +- permanent xino files for NFSD
2498 +- an option for refreshing the opened files after add/del branches
2499 +- light version, without branch manipulation. (unnecessary?)
2500 +- copyup in userspace
2501 +- inotify in userspace
2506 +----------------------------------------
2507 +There are three GIT trees for aufs4, aufs4-linux.git,
2508 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2510 +While the aufs-util is always necessary, you need either of aufs4-linux
2511 +or aufs4-standalone.
2513 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2514 +git://git.kernel.org/.../torvalds/linux.git.
2515 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2516 +build aufs4 as an external kernel module.
2517 +Several extra patches are not included in this tree. Only
2518 +aufs4-standalone tree contains them. They are described in the later
2519 +section "Configuration and Compilation."
2521 +On the other hand, the aufs4-standalone tree has only aufs source files
2522 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2523 +But you need to apply all aufs patches manually.
2525 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2526 +represents the linux kernel version, "linux-4.x". For instance,
2527 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2528 +"aufs4.x-rcN" branch.
2531 +$ git clone --reference /your/linux/git/tree \
2532 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2533 +- if you don't have linux GIT tree, then remove "--reference ..."
2534 +$ cd aufs4-linux.git
2535 +$ git checkout origin/aufs4.0
2537 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2538 +leave the patch-work to GIT.
2539 +$ cd /your/linux/git/tree
2540 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2542 +$ git checkout -b my4.0 v4.0
2543 +$ (add your local change...)
2544 +$ git pull aufs4 aufs4.0
2545 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2546 +- you may need to solve some conflicts between your_changes and
2547 + aufs4.0. in this case, git-rerere is recommended so that you can
2548 + solve the similar conflicts automatically when you upgrade to 4.1 or
2549 + later in the future.
2551 +o aufs4-standalone tree
2552 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2553 +$ cd aufs4-standalone.git
2554 +$ git checkout origin/aufs4.0
2557 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2558 +- note that the public aufs-util.git is on SourceForge instead of
2561 +$ git checkout origin/aufs4.0
2563 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2564 +The minor version number, 'x' in '4.x', of aufs may not always
2565 +follow the minor version number of the kernel.
2566 +Because changes in the kernel that cause the use of a new
2567 +minor version number do not always require changes to aufs-util.
2569 +Since aufs-util has its own minor version number, you may not be
2570 +able to find a GIT branch in aufs-util for your kernel's
2571 +exact minor version number.
2572 +In this case, you should git-checkout the branch for the
2573 +nearest lower number.
2575 +For (an unreleased) example:
2576 +If you are using "linux-4.10" and the "aufs4.10" branch
2577 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2578 +or something numerically smaller is the branch for your kernel.
2580 +Also you can view all branches by
2584 +3. Configuration and Compilation
2585 +----------------------------------------
2586 +Make sure you have git-checkout'ed the correct branch.
2588 +For aufs4-linux tree,
2589 +- enable CONFIG_AUFS_FS.
2590 +- set other aufs configurations if necessary.
2592 +For aufs4-standalone tree,
2593 +There are several ways to build.
2596 +- apply ./aufs4-kbuild.patch to your kernel source files.
2597 +- apply ./aufs4-base.patch too.
2598 +- apply ./aufs4-mmap.patch too.
2599 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2600 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2601 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2602 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2603 +- enable CONFIG_AUFS_FS, you can select either
2605 +- and build your kernel as usual.
2606 +- install the built kernel.
2607 + Note: Since linux-3.9, every filesystem module requires an alias
2608 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2609 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2610 +- install the header files too by "make headers_install" to the
2611 + directory where you specify. By default, it is $PWD/usr.
2612 + "make help" shows a brief note for headers_install.
2613 +- and reboot your system.
2616 +- module only (CONFIG_AUFS_FS=m).
2617 +- apply ./aufs4-base.patch to your kernel source files.
2618 +- apply ./aufs4-mmap.patch too.
2619 +- apply ./aufs4-standalone.patch too.
2620 +- build your kernel, don't forget "make headers_install", and reboot.
2621 +- edit ./config.mk and set other aufs configurations if necessary.
2622 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2623 + every aufs configurations.
2624 +- build the module by simple "make".
2625 + Note: Since linux-3.9, every filesystem module requires an alias
2626 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2627 + modules.aliases file.
2628 +- you can specify ${KDIR} make variable which points to your kernel
2630 +- install the files
2631 + + run "make install" to install the aufs module, or copy the built
2632 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2633 + + run "make install_headers" (instead of headers_install) to install
2634 + the modified aufs header file (you can specify DESTDIR which is
2635 + available in aufs standalone version's Makefile only), or copy
2636 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2637 + you like manually. By default, the target directory is $PWD/usr.
2638 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2639 + kernel source tree.
2641 +Note: The header file aufs_type.h is necessary to build aufs-util
2642 + as well as "make headers_install" in the kernel source tree.
2643 + headers_install is subject to be forgotten, but it is essentially
2644 + necessary, not only for building aufs-util.
2645 + You may not meet problems without headers_install in some older
2649 +- read README in aufs-util, build and install it
2650 +- note that your distribution may contain an obsoleted version of
2651 + aufs_type.h in /usr/include/linux or something. When you build aufs
2652 + utilities, make sure that your compiler refers the correct aufs header
2653 + file which is built by "make headers_install."
2654 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2655 + then run "make install_ulib" too. And refer to the aufs manual in
2658 +There several other patches in aufs4-standalone.git. They are all
2659 +optional. When you meet some problems, they will help you.
2660 +- aufs4-loopback.patch
2661 + Supports a nested loopback mount in a branch-fs. This patch is
2662 + unnecessary until aufs produces a message like "you may want to try
2663 + another patch for loopback file".
2665 + Modifies a system global kernel internal function get_next_ino() in
2666 + order to stop assigning 0 for an inode-number. Not directly related to
2667 + aufs, but recommended generally.
2669 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2670 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2671 + duplication of inode number, which is important for backup tools and
2672 + other utilities. When you find aufs XINO files for tmpfs branch
2673 + growing too much, try this patch.
2674 +- lockdep-debug.patch
2675 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2676 + also a caller of VFS functions for branch filesystems, subclassing of
2677 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2678 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2679 + need to apply this debug patch to expand several constant values.
2680 + If don't know what LOCKDEP, then you don't have apply this patch.
2684 +----------------------------------------
2685 +At first, make sure aufs-util are installed, and please read the aufs
2686 +manual, aufs.5 in aufs-util.git tree.
2690 +$ mkdir /tmp/rw /tmp/aufs
2691 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2693 +Here is another example. The result is equivalent.
2694 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2696 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2697 +# mount -o remount,append:${HOME} /tmp/aufs
2699 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2700 +you modify a file under /tmp/aufs, the one on your home directory is
2701 +not affected, instead the same named file will be newly created under
2702 +/tmp/rw. And all of your modification to a file will be applied to
2703 +the one under /tmp/rw. This is called the file based Copy on Write
2705 +Aufs mount options are described in aufs.5.
2706 +If you run chroot or something and make your aufs as a root directory,
2707 +then you need to customize the shutdown script. See the aufs manual in
2710 +Additionally, there are some sample usages of aufs which are a
2711 +diskless system with network booting, and LiveCD over NFS.
2712 +See sample dir in CVS tree on SourceForge.
2716 +----------------------------------------
2717 +When you have any problems or strange behaviour in aufs, please let me
2719 +- /proc/mounts (instead of the output of mount(8))
2720 +- /sys/module/aufs/*
2721 +- /sys/fs/aufs/* (if you have them)
2722 +- /debug/aufs/* (if you have them)
2723 +- linux kernel version
2724 + if your kernel is not plain, for example modified by distributor,
2725 + the url where i can download its source is necessary too.
2726 +- aufs version which was printed at loading the module or booting the
2727 + system, instead of the date you downloaded.
2728 +- configuration (define/undefine CONFIG_AUFS_xxx)
2729 +- kernel configuration or /proc/config.gz (if you have it)
2730 +- behaviour which you think to be incorrect
2731 +- actual operation, reproducible one is better
2732 +- mailto: aufs-users at lists.sourceforge.net
2734 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2735 +and Feature Requests) on SourceForge. Please join and write to
2739 +6. Acknowledgements
2740 +----------------------------------------
2741 +Thanks to everyone who have tried and are using aufs, whoever
2742 +have reported a bug or any feedback.
2744 +Especially donators:
2745 +Tomas Matejicek(slax.org) made a donation (much more than once).
2746 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2747 + scripts) is making "doubling" donations.
2748 + Unfortunately I cannot list all of the donators, but I really
2750 + It ends Aug 2010, but the ordinary donation URL is still available.
2751 + <http://sourceforge.net/donate/index.php?group_id=167503>
2752 +Dai Itasaka made a donation (2007/8).
2753 +Chuck Smith made a donation (2008/4, 10 and 12).
2754 +Henk Schoneveld made a donation (2008/9).
2755 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2756 +Francois Dupoux made a donation (2008/11).
2757 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2758 + aufs2 GIT tree (2009/2).
2759 +William Grant made a donation (2009/3).
2760 +Patrick Lane made a donation (2009/4).
2761 +The Mail Archive (mail-archive.com) made donations (2009/5).
2762 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2763 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2764 +Pavel Pronskiy made a donation (2011/2).
2765 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2766 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2767 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2769 +Sam Liddicott made a donation (2011/9).
2770 +Era Scarecrow made a donation (2013/4).
2771 +Bor Ratajc made a donation (2013/4).
2772 +Alessandro Gorreta made a donation (2013/4).
2773 +POIRETTE Marc made a donation (2013/4).
2774 +Alessandro Gorreta made a donation (2013/4).
2775 +lauri kasvandik made a donation (2013/5).
2776 +"pemasu from Finland" made a donation (2013/7).
2777 +The Parted Magic Project made a donation (2013/9 and 11).
2778 +Pavel Barta made a donation (2013/10).
2779 +Nikolay Pertsev made a donation (2014/5).
2780 +James B made a donation (2014/7 and 2015/7).
2781 +Stefano Di Biase made a donation (2014/8).
2782 +Daniel Epellei made a donation (2015/1).
2783 +OmegaPhil made a donation (2016/1).
2784 +Tomasz Szewczyk made a donation (2016/4).
2786 +Thank you very much.
2787 +Donations are always, including future donations, very important and
2788 +helpful for me to keep on developing aufs.
2792 +----------------------------------------
2793 +If you are an experienced user, no explanation is needed. Aufs is
2794 +just a linux filesystem.
2799 +# Local variables: ;
2802 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2803 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2804 +++ linux/fs/aufs/aufs.h 2016-07-25 19:05:34.811159821 +0200
2807 + * Copyright (C) 2005-2016 Junjiro R. Okajima
2809 + * This program, aufs is free software; you can redistribute it and/or modify
2810 + * it under the terms of the GNU General Public License as published by
2811 + * the Free Software Foundation; either version 2 of the License, or
2812 + * (at your option) any later version.
2814 + * This program is distributed in the hope that it will be useful,
2815 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2816 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2817 + * GNU General Public License for more details.
2819 + * You should have received a copy of the GNU General Public License
2820 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2824 + * all header files
2832 +#define AuStub(type, name, body, ...) \
2833 + static inline type name(__VA_ARGS__) { body; }
2835 +#define AuStubVoid(name, ...) \
2836 + AuStub(void, name, , __VA_ARGS__)
2837 +#define AuStubInt0(name, ...) \
2838 + AuStub(int, name, return 0, __VA_ARGS__)
2842 +#include "branch.h"
2845 +#include "dbgaufs.h"
2846 +#include "dentry.h"
2850 +#include "fstype.h"
2853 +#include "module.h"
2858 +#include "sysaufs.h"
2863 +#endif /* __KERNEL__ */
2864 +#endif /* __AUFS_H__ */
2865 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2866 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2867 +++ linux/fs/aufs/branch.c 2016-07-25 19:05:34.811159821 +0200
2870 + * Copyright (C) 2005-2016 Junjiro R. Okajima
2872 + * This program, aufs is free software; you can redistribute it and/or modify
2873 + * it under the terms of the GNU General Public License as published by
2874 + * the Free Software Foundation; either version 2 of the License, or
2875 + * (at your option) any later version.
2877 + * This program is distributed in the hope that it will be useful,
2878 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2879 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2880 + * GNU General Public License for more details.
2882 + * You should have received a copy of the GNU General Public License
2883 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2887 + * branch management
2890 +#include <linux/compat.h>
2891 +#include <linux/statfs.h>
2895 + * free a single branch
2897 +static void au_br_do_free(struct au_branch *br)
2900 + struct au_wbr *wbr;
2901 + struct au_dykey **key;
2903 + au_hnotify_fin_br(br);
2905 + if (br->br_xino.xi_file)
2906 + fput(br->br_xino.xi_file);
2907 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2909 + AuDebugOn(au_br_count(br));
2910 + au_br_count_fin(br);
2914 + for (i = 0; i < AuBrWh_Last; i++)
2915 + dput(wbr->wbr_wh[i]);
2916 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2917 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2920 + if (br->br_fhsm) {
2921 + au_br_fhsm_fin(br->br_fhsm);
2922 + kfree(br->br_fhsm);
2925 + key = br->br_dykey;
2926 + for (i = 0; i < AuBrDynOp; i++, key++)
2932 + /* recursive lock, s_umount of branch's */
2934 + path_put(&br->br_path);
2941 + * frees all branches
2943 +void au_br_free(struct au_sbinfo *sbinfo)
2945 + aufs_bindex_t bmax;
2946 + struct au_branch **br;
2948 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2950 + bmax = sbinfo->si_bbot + 1;
2951 + br = sbinfo->si_branch;
2953 + au_br_do_free(*br++);
2957 + * find the index of a branch which is specified by @br_id.
2959 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2961 + aufs_bindex_t bindex, bbot;
2963 + bbot = au_sbbot(sb);
2964 + for (bindex = 0; bindex <= bbot; bindex++)
2965 + if (au_sbr_id(sb, bindex) == br_id)
2970 +/* ---------------------------------------------------------------------- */
2976 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2977 + struct dentry *h_root)
2979 + if (unlikely(h_adding == h_root
2980 + || au_test_loopback_overlap(sb, h_adding)))
2982 + if (h_adding->d_sb != h_root->d_sb)
2984 + return au_test_subdir(h_adding, h_root)
2985 + || au_test_subdir(h_root, h_adding);
2989 + * returns a newly allocated branch. @new_nbranch is a number of branches
2990 + * after adding a branch.
2992 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2995 + struct au_branch *add_branch;
2996 + struct dentry *root;
2997 + struct inode *inode;
3001 + root = sb->s_root;
3002 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3003 + if (unlikely(!add_branch))
3006 + err = au_hnotify_init_br(add_branch, perm);
3007 + if (unlikely(err))
3010 + if (au_br_writable(perm)) {
3011 + /* may be freed separately at changing the branch permission */
3012 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3014 + if (unlikely(!add_branch->br_wbr))
3018 + if (au_br_fhsm(perm)) {
3019 + err = au_fhsm_br_alloc(add_branch);
3020 + if (unlikely(err))
3024 + err = au_sbr_realloc(au_sbi(sb), new_nbranch);
3026 + err = au_di_realloc(au_di(root), new_nbranch);
3028 + inode = d_inode(root);
3029 + err = au_hinode_realloc(au_ii(inode), new_nbranch);
3032 + return add_branch; /* success */
3035 + kfree(add_branch->br_wbr);
3037 + au_hnotify_fin_br(add_branch);
3039 + kfree(add_branch);
3041 + return ERR_PTR(err);
3045 + * test if the branch permission is legal or not.
3047 +static int test_br(struct inode *inode, int brperm, char *path)
3051 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3056 + pr_err("write permission for readonly mount or inode, %s\n", path);
3064 + * 0: success, the caller will add it
3065 + * plus: success, it is already unified, the caller should ignore it
3068 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3071 + aufs_bindex_t bbot, bindex;
3072 + struct dentry *root, *h_dentry;
3073 + struct inode *inode, *h_inode;
3075 + root = sb->s_root;
3076 + bbot = au_sbbot(sb);
3077 + if (unlikely(bbot >= 0
3078 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3082 + pr_err("%s duplicated\n", add->pathname);
3087 + err = -ENOSPC; /* -E2BIG; */
3088 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3089 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3090 + pr_err("number of branches exceeded %s\n", add->pathname);
3095 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3096 + pr_err("bad index %d\n", add->bindex);
3100 + inode = d_inode(add->path.dentry);
3102 + if (unlikely(!inode->i_nlink)) {
3103 + pr_err("no existence %s\n", add->pathname);
3108 + if (unlikely(inode->i_sb == sb)) {
3109 + pr_err("%s must be outside\n", add->pathname);
3113 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3114 + pr_err("unsupported filesystem, %s (%s)\n",
3115 + add->pathname, au_sbtype(inode->i_sb));
3119 + if (unlikely(inode->i_sb->s_stack_depth)) {
3120 + pr_err("already stacked, %s (%s)\n",
3121 + add->pathname, au_sbtype(inode->i_sb));
3125 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3126 + if (unlikely(err))
3130 + return 0; /* success */
3133 + for (bindex = 0; bindex <= bbot; bindex++)
3134 + if (unlikely(test_overlap(sb, add->path.dentry,
3135 + au_h_dptr(root, bindex)))) {
3136 + pr_err("%s is overlapped\n", add->pathname);
3141 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3142 + h_dentry = au_h_dptr(root, 0);
3143 + h_inode = d_inode(h_dentry);
3144 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3145 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3146 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3147 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3149 + i_uid_read(inode), i_gid_read(inode),
3150 + (inode->i_mode & S_IALLUGO),
3151 + i_uid_read(h_inode), i_gid_read(h_inode),
3152 + (h_inode->i_mode & S_IALLUGO));
3160 + * initialize or clean the whiteouts for an adding branch
3162 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3165 + int err, old_perm;
3166 + aufs_bindex_t bindex;
3167 + struct inode *h_inode;
3168 + struct au_wbr *wbr;
3169 + struct au_hinode *hdir;
3170 + struct dentry *h_dentry;
3172 + err = vfsub_mnt_want_write(au_br_mnt(br));
3173 + if (unlikely(err))
3177 + old_perm = br->br_perm;
3178 + br->br_perm = new_perm;
3181 + bindex = au_br_index(sb, br->br_id);
3182 + if (0 <= bindex) {
3183 + hdir = au_hi(d_inode(sb->s_root), bindex);
3184 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3186 + h_dentry = au_br_dentry(br);
3187 + h_inode = d_inode(h_dentry);
3188 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3191 + err = au_wh_init(br, sb);
3193 + wbr_wh_write_lock(wbr);
3194 + err = au_wh_init(br, sb);
3195 + wbr_wh_write_unlock(wbr);
3198 + au_hn_inode_unlock(hdir);
3200 + inode_unlock(h_inode);
3201 + vfsub_mnt_drop_write(au_br_mnt(br));
3202 + br->br_perm = old_perm;
3204 + if (!err && wbr && !au_br_writable(new_perm)) {
3206 + br->br_wbr = NULL;
3213 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3217 + struct kstatfs kst;
3218 + struct au_wbr *wbr;
3221 + au_rw_init(&wbr->wbr_wh_rwsem);
3222 + atomic_set(&wbr->wbr_wh_running, 0);
3225 + * a limit for rmdir/rename a dir
3226 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3228 + err = vfs_statfs(&br->br_path, &kst);
3229 + if (unlikely(err))
3232 + if (kst.f_namelen >= NAME_MAX)
3233 + err = au_br_init_wh(sb, br, perm);
3235 + pr_err("%pd(%s), unsupported namelen %ld\n",
3237 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3243 +/* initialize a new branch */
3244 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3245 + struct au_opt_add *add)
3248 + struct inode *h_inode;
3251 + mutex_init(&br->br_xino.xi_nondir_mtx);
3252 + br->br_perm = add->perm;
3253 + br->br_path = add->path; /* set first, path_get() later */
3254 + spin_lock_init(&br->br_dykey_lock);
3255 + au_br_count_init(br);
3256 + atomic_set(&br->br_xino_running, 0);
3257 + br->br_id = au_new_br_id(sb);
3258 + AuDebugOn(br->br_id < 0);
3260 + if (au_br_writable(add->perm)) {
3261 + err = au_wbr_init(br, sb, add->perm);
3262 + if (unlikely(err))
3266 + if (au_opt_test(au_mntflags(sb), XINO)) {
3267 + h_inode = d_inode(add->path.dentry);
3268 + err = au_xino_br(sb, br, h_inode->i_ino,
3269 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3270 + if (unlikely(err)) {
3271 + AuDebugOn(br->br_xino.xi_file);
3276 + sysaufs_br_init(br);
3277 + path_get(&br->br_path);
3278 + goto out; /* success */
3281 + memset(&br->br_path, 0, sizeof(br->br_path));
3286 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3287 + struct au_branch *br, aufs_bindex_t bbot,
3288 + aufs_bindex_t amount)
3290 + struct au_branch **brp;
3292 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3294 + brp = sbinfo->si_branch + bindex;
3295 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3297 + sbinfo->si_bbot++;
3298 + if (unlikely(bbot < 0))
3299 + sbinfo->si_bbot = 0;
3302 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3303 + aufs_bindex_t bbot, aufs_bindex_t amount)
3305 + struct au_hdentry *hdp;
3307 + AuRwMustWriteLock(&dinfo->di_rwsem);
3309 + hdp = au_hdentry(dinfo, bindex);
3310 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3311 + au_h_dentry_init(hdp);
3313 + if (unlikely(bbot < 0))
3314 + dinfo->di_btop = 0;
3317 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3318 + aufs_bindex_t bbot, aufs_bindex_t amount)
3320 + struct au_hinode *hip;
3322 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3324 + hip = au_hinode(iinfo, bindex);
3325 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3326 + au_hinode_init(hip);
3328 + if (unlikely(bbot < 0))
3329 + iinfo->ii_btop = 0;
3332 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3333 + aufs_bindex_t bindex)
3335 + struct dentry *root, *h_dentry;
3336 + struct inode *root_inode, *h_inode;
3337 + aufs_bindex_t bbot, amount;
3339 + root = sb->s_root;
3340 + root_inode = d_inode(root);
3341 + bbot = au_sbbot(sb);
3342 + amount = bbot + 1 - bindex;
3343 + h_dentry = au_br_dentry(br);
3344 + au_sbilist_lock();
3345 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3346 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3347 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3348 + au_set_h_dptr(root, bindex, dget(h_dentry));
3349 + h_inode = d_inode(h_dentry);
3350 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3351 + au_sbilist_unlock();
3354 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3357 + aufs_bindex_t bbot, add_bindex;
3358 + struct dentry *root, *h_dentry;
3359 + struct inode *root_inode;
3360 + struct au_branch *add_branch;
3362 + root = sb->s_root;
3363 + root_inode = d_inode(root);
3364 + IMustLock(root_inode);
3365 + IiMustWriteLock(root_inode);
3366 + err = test_add(sb, add, remount);
3367 + if (unlikely(err < 0))
3371 + goto out; /* success */
3374 + bbot = au_sbbot(sb);
3375 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3376 + err = PTR_ERR(add_branch);
3377 + if (IS_ERR(add_branch))
3380 + err = au_br_init(add_branch, sb, add);
3381 + if (unlikely(err)) {
3382 + au_br_do_free(add_branch);
3386 + add_bindex = add->bindex;
3388 + au_br_do_add(sb, add_branch, add_bindex);
3390 + sysaufs_brs_del(sb, add_bindex);
3391 + au_br_do_add(sb, add_branch, add_bindex);
3392 + sysaufs_brs_add(sb, add_bindex);
3395 + h_dentry = add->path.dentry;
3396 + if (!add_bindex) {
3397 + au_cpup_attr_all(root_inode, /*force*/1);
3398 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3400 + au_add_nlink(root_inode, d_inode(h_dentry));
3403 + * this test/set prevents aufs from handling unnecesary notify events
3404 + * of xino files, in case of re-adding a writable branch which was
3405 + * once detached from aufs.
3407 + if (au_xino_brid(sb) < 0
3408 + && au_br_writable(add_branch->br_perm)
3409 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3410 + && add_branch->br_xino.xi_file
3411 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3412 + au_xino_brid_set(sb, add_branch->br_id);
3418 +/* ---------------------------------------------------------------------- */
3420 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3421 + unsigned long long max __maybe_unused,
3424 + unsigned long long n;
3425 + struct file **p, *f;
3426 + struct au_sphlhead *files;
3427 + struct au_finfo *finfo;
3431 + files = &au_sbi(sb)->si_files;
3432 + spin_lock(&files->spin);
3433 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3434 + f = finfo->fi_file;
3436 + && !special_file(file_inode(f)->i_mode)) {
3440 + AuDebugOn(n > max);
3443 + spin_unlock(&files->spin);
3448 +static struct file **au_farray_alloc(struct super_block *sb,
3449 + unsigned long long *max)
3451 + *max = au_nfiles(sb);
3452 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3455 +static void au_farray_free(struct file **a, unsigned long long max)
3457 + unsigned long long ull;
3459 + for (ull = 0; ull < max; ull++)
3465 +/* ---------------------------------------------------------------------- */
3471 +/* to show the line number, do not make it inlined function */
3472 +#define AuVerbose(do_info, fmt, ...) do { \
3474 + pr_info(fmt, ##__VA_ARGS__); \
3477 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3478 + aufs_bindex_t bbot)
3480 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3483 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3484 + aufs_bindex_t bbot)
3486 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3490 + * test if the branch is deletable or not.
3492 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3493 + unsigned int sigen, const unsigned int verbose)
3495 + int err, i, j, ndentry;
3496 + aufs_bindex_t btop, bbot;
3497 + struct au_dcsub_pages dpages;
3498 + struct au_dpage *dpage;
3501 + err = au_dpages_init(&dpages, GFP_NOFS);
3502 + if (unlikely(err))
3504 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3505 + if (unlikely(err))
3508 + for (i = 0; !err && i < dpages.ndpage; i++) {
3509 + dpage = dpages.dpages + i;
3510 + ndentry = dpage->ndentry;
3511 + for (j = 0; !err && j < ndentry; j++) {
3512 + d = dpage->dentries[j];
3513 + AuDebugOn(au_dcount(d) <= 0);
3514 + if (!au_digen_test(d, sigen)) {
3515 + di_read_lock_child(d, AuLock_IR);
3516 + if (unlikely(au_dbrange_test(d))) {
3517 + di_read_unlock(d, AuLock_IR);
3521 + di_write_lock_child(d);
3522 + if (unlikely(au_dbrange_test(d))) {
3523 + di_write_unlock(d);
3526 + err = au_reval_dpath(d, sigen);
3528 + di_downgrade_lock(d, AuLock_IR);
3530 + di_write_unlock(d);
3535 + /* AuDbgDentry(d); */
3536 + btop = au_dbtop(d);
3537 + bbot = au_dbbot(d);
3538 + if (btop <= bindex
3540 + && au_h_dptr(d, bindex)
3541 + && au_test_dbusy(d, btop, bbot)) {
3543 + AuVerbose(verbose, "busy %pd\n", d);
3546 + di_read_unlock(d, AuLock_IR);
3551 + au_dpages_free(&dpages);
3556 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3557 + unsigned int sigen, const unsigned int verbose)
3560 + unsigned long long max, ull;
3561 + struct inode *i, **array;
3562 + aufs_bindex_t btop, bbot;
3564 + array = au_iarray_alloc(sb, &max);
3565 + err = PTR_ERR(array);
3566 + if (IS_ERR(array))
3570 + AuDbg("b%d\n", bindex);
3571 + for (ull = 0; !err && ull < max; ull++) {
3575 + if (i->i_ino == AUFS_ROOT_INO)
3578 + /* AuDbgInode(i); */
3579 + if (au_iigen(i, NULL) == sigen)
3580 + ii_read_lock_child(i);
3582 + ii_write_lock_child(i);
3583 + err = au_refresh_hinode_self(i);
3586 + ii_downgrade_lock(i);
3588 + ii_write_unlock(i);
3593 + btop = au_ibtop(i);
3594 + bbot = au_ibbot(i);
3595 + if (btop <= bindex
3597 + && au_h_iptr(i, bindex)
3598 + && au_test_ibusy(i, btop, bbot)) {
3600 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3603 + ii_read_unlock(i);
3605 + au_iarray_free(array, max);
3611 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3612 + const unsigned int verbose)
3615 + unsigned int sigen;
3617 + sigen = au_sigen(root->d_sb);
3618 + DiMustNoWaiters(root);
3619 + IiMustNoWaiters(d_inode(root));
3620 + di_write_unlock(root);
3621 + err = test_dentry_busy(root, bindex, sigen, verbose);
3623 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3624 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3629 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3630 + struct file **to_free, int *idx)
3633 + unsigned char matched, root;
3634 + aufs_bindex_t bindex, bbot;
3635 + struct au_fidir *fidir;
3636 + struct au_hfile *hfile;
3639 + root = IS_ROOT(file->f_path.dentry);
3642 + to_free[*idx] = file;
3648 + fidir = au_fi(file)->fi_hdir;
3649 + AuDebugOn(!fidir);
3650 + bbot = au_fbbot_dir(file);
3651 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3652 + hfile = fidir->fd_hfile + bindex;
3653 + if (!hfile->hf_file)
3656 + if (hfile->hf_br->br_id == br_id) {
3668 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3669 + struct file **to_free, int opened)
3672 + unsigned long long ull, max;
3673 + aufs_bindex_t btop;
3674 + struct file *file, **array;
3675 + struct dentry *root;
3676 + struct au_hfile *hfile;
3678 + array = au_farray_alloc(sb, &max);
3679 + err = PTR_ERR(array);
3680 + if (IS_ERR(array))
3685 + root = sb->s_root;
3686 + di_write_unlock(root);
3687 + for (ull = 0; ull < max; ull++) {
3688 + file = array[ull];
3689 + if (unlikely(!file))
3692 + /* AuDbg("%pD\n", file); */
3693 + fi_read_lock(file);
3694 + btop = au_fbtop(file);
3695 + if (!d_is_dir(file->f_path.dentry)) {
3696 + hfile = &au_fi(file)->fi_htop;
3697 + if (hfile->hf_br->br_id == br_id)
3700 + err = test_dir_busy(file, br_id, to_free, &idx);
3701 + fi_read_unlock(file);
3702 + if (unlikely(err))
3705 + di_write_lock_child(root);
3706 + au_farray_free(array, max);
3707 + AuDebugOn(idx > opened);
3713 +static void br_del_file(struct file **to_free, unsigned long long opened,
3714 + aufs_bindex_t br_id)
3716 + unsigned long long ull;
3717 + aufs_bindex_t bindex, btop, bbot, bfound;
3718 + struct file *file;
3719 + struct au_fidir *fidir;
3720 + struct au_hfile *hfile;
3722 + for (ull = 0; ull < opened; ull++) {
3723 + file = to_free[ull];
3724 + if (unlikely(!file))
3727 + /* AuDbg("%pD\n", file); */
3728 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3730 + fidir = au_fi(file)->fi_hdir;
3731 + AuDebugOn(!fidir);
3732 + fi_write_lock(file);
3733 + btop = au_fbtop(file);
3734 + bbot = au_fbbot_dir(file);
3735 + for (bindex = btop; bindex <= bbot; bindex++) {
3736 + hfile = fidir->fd_hfile + bindex;
3737 + if (!hfile->hf_file)
3740 + if (hfile->hf_br->br_id == br_id) {
3745 + AuDebugOn(bfound < 0);
3746 + au_set_h_fptr(file, bfound, NULL);
3747 + if (bfound == btop) {
3748 + for (btop++; btop <= bbot; btop++)
3749 + if (au_hf_dir(file, btop)) {
3750 + au_set_fbtop(file, btop);
3754 + fi_write_unlock(file);
3758 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3759 + const aufs_bindex_t bindex,
3760 + const aufs_bindex_t bbot)
3762 + struct au_branch **brp, **p;
3764 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3766 + brp = sbinfo->si_branch + bindex;
3767 + if (bindex < bbot)
3768 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3769 + sbinfo->si_branch[0 + bbot] = NULL;
3770 + sbinfo->si_bbot--;
3772 + p = krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST);
3774 + sbinfo->si_branch = p;
3775 + /* harmless error */
3778 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3779 + const aufs_bindex_t bbot)
3781 + struct au_hdentry *hdp, *p;
3783 + AuRwMustWriteLock(&dinfo->di_rwsem);
3785 + hdp = au_hdentry(dinfo, bindex);
3786 + if (bindex < bbot)
3787 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3788 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3791 + p = krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST);
3793 + dinfo->di_hdentry = p;
3794 + /* harmless error */
3797 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3798 + const aufs_bindex_t bbot)
3800 + struct au_hinode *hip, *p;
3802 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3804 + hip = au_hinode(iinfo, bindex);
3805 + if (bindex < bbot)
3806 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3807 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3810 + p = krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST);
3812 + iinfo->ii_hinode = p;
3813 + /* harmless error */
3816 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3817 + struct au_branch *br)
3819 + aufs_bindex_t bbot;
3820 + struct au_sbinfo *sbinfo;
3821 + struct dentry *root, *h_root;
3822 + struct inode *inode, *h_inode;
3823 + struct au_hinode *hinode;
3825 + SiMustWriteLock(sb);
3827 + root = sb->s_root;
3828 + inode = d_inode(root);
3829 + sbinfo = au_sbi(sb);
3830 + bbot = sbinfo->si_bbot;
3832 + h_root = au_h_dptr(root, bindex);
3833 + hinode = au_hi(inode, bindex);
3834 + h_inode = au_igrab(hinode->hi_inode);
3837 + au_sbilist_lock();
3838 + au_br_do_del_brp(sbinfo, bindex, bbot);
3839 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3840 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3841 + au_sbilist_unlock();
3845 + au_br_do_free(br);
3848 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3849 + unsigned long long max, void *arg)
3854 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3857 + unsigned long long opened;
3858 + unsigned int mnt_flags;
3859 + aufs_bindex_t bindex, bbot, br_id;
3860 + unsigned char do_wh, verbose;
3861 + struct au_branch *br;
3862 + struct au_wbr *wbr;
3863 + struct dentry *root;
3864 + struct file **to_free;
3869 + root = sb->s_root;
3870 + bindex = au_find_dbindex(root, del->h_path.dentry);
3873 + goto out; /* success */
3875 + pr_err("%s no such branch\n", del->pathname);
3878 + AuDbg("bindex b%d\n", bindex);
3881 + mnt_flags = au_mntflags(sb);
3882 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3883 + bbot = au_sbbot(sb);
3884 + if (unlikely(!bbot)) {
3885 + AuVerbose(verbose, "no more branches left\n");
3888 + br = au_sbr(sb, bindex);
3889 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3891 + br_id = br->br_id;
3892 + opened = au_br_count(br);
3893 + if (unlikely(opened)) {
3894 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3895 + err = PTR_ERR(to_free);
3896 + if (IS_ERR(to_free))
3899 + err = test_file_busy(sb, br_id, to_free, opened);
3900 + if (unlikely(err)) {
3901 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3907 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3909 + /* instead of WbrWhMustWriteLock(wbr) */
3910 + SiMustWriteLock(sb);
3911 + for (i = 0; i < AuBrWh_Last; i++) {
3912 + dput(wbr->wbr_wh[i]);
3913 + wbr->wbr_wh[i] = NULL;
3917 + err = test_children_busy(root, bindex, verbose);
3918 + if (unlikely(err)) {
3927 + * now we confirmed the branch is deletable.
3928 + * let's free the remaining opened dirs on the branch.
3930 + di_write_unlock(root);
3931 + br_del_file(to_free, opened, br_id);
3932 + di_write_lock_child(root);
3936 + au_br_do_del(sb, bindex, br);
3938 + sysaufs_brs_del(sb, bindex);
3939 + au_br_do_del(sb, bindex, br);
3940 + sysaufs_brs_add(sb, bindex);
3944 + au_cpup_attr_all(d_inode(root), /*force*/1);
3945 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3947 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3948 + if (au_opt_test(mnt_flags, PLINK))
3949 + au_plink_half_refresh(sb, br_id);
3951 + if (au_xino_brid(sb) == br_id)
3952 + au_xino_brid_set(sb, -1);
3953 + goto out; /* success */
3957 + rerr = au_br_init_wh(sb, br, br->br_perm);
3959 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3960 + del->pathname, rerr);
3963 + au_farray_free(to_free, opened);
3967 +/* ---------------------------------------------------------------------- */
3969 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3972 + aufs_bindex_t btop, bbot;
3973 + struct aufs_ibusy ibusy;
3974 + struct inode *inode, *h_inode;
3977 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3980 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3982 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3983 + if (unlikely(err)) {
3990 + si_read_lock(sb, AuLock_FLUSH);
3991 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
3995 + ibusy.h_ino = 0; /* invalid */
3996 + inode = ilookup(sb, ibusy.ino);
3998 + || inode->i_ino == AUFS_ROOT_INO
3999 + || au_is_bad_inode(inode))
4002 + ii_read_lock_child(inode);
4003 + btop = au_ibtop(inode);
4004 + bbot = au_ibbot(inode);
4005 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4006 + h_inode = au_h_iptr(inode, ibusy.bindex);
4007 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4008 + ibusy.h_ino = h_inode->i_ino;
4010 + ii_read_unlock(inode);
4014 + si_read_unlock(sb);
4016 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4017 + if (unlikely(err)) {
4026 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4028 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4031 +#ifdef CONFIG_COMPAT
4032 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4034 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4038 +/* ---------------------------------------------------------------------- */
4041 + * change a branch permission
4044 +static void au_warn_ima(void)
4047 + /* since it doesn't support mark_files_ro() */
4048 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4052 +static int do_need_sigen_inc(int a, int b)
4054 + return au_br_whable(a) && !au_br_whable(b);
4057 +static int need_sigen_inc(int old, int new)
4059 + return do_need_sigen_inc(old, new)
4060 + || do_need_sigen_inc(new, old);
4063 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4066 + unsigned int mnt_flags;
4067 + unsigned long long ull, max;
4068 + aufs_bindex_t br_id;
4069 + unsigned char verbose, writer;
4070 + struct file *file, *hf, **array;
4071 + struct au_hfile *hfile;
4073 + mnt_flags = au_mntflags(sb);
4074 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4076 + array = au_farray_alloc(sb, &max);
4077 + err = PTR_ERR(array);
4078 + if (IS_ERR(array))
4082 + br_id = au_sbr_id(sb, bindex);
4083 + for (ull = 0; ull < max; ull++) {
4084 + file = array[ull];
4085 + if (unlikely(!file))
4088 + /* AuDbg("%pD\n", file); */
4089 + fi_read_lock(file);
4090 + if (unlikely(au_test_mmapped(file))) {
4092 + AuVerbose(verbose, "mmapped %pD\n", file);
4094 + FiMustNoWaiters(file);
4095 + fi_read_unlock(file);
4099 + hfile = &au_fi(file)->fi_htop;
4100 + hf = hfile->hf_file;
4101 + if (!d_is_reg(file->f_path.dentry)
4102 + || !(file->f_mode & FMODE_WRITE)
4103 + || hfile->hf_br->br_id != br_id
4104 + || !(hf->f_mode & FMODE_WRITE))
4105 + array[ull] = NULL;
4111 + FiMustNoWaiters(file);
4112 + fi_read_unlock(file);
4120 + for (ull = 0; ull < max; ull++) {
4121 + file = array[ull];
4125 + /* todo: already flushed? */
4127 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4128 + * approach which resets f_mode and calls mnt_drop_write() and
4129 + * file_release_write() for each file, because the branch
4130 + * attribute in aufs world is totally different from the native
4133 + /* fi_read_lock(file); */
4134 + hfile = &au_fi(file)->fi_htop;
4135 + hf = hfile->hf_file;
4136 + /* fi_read_unlock(file); */
4137 + spin_lock(&hf->f_lock);
4138 + writer = !!(hf->f_mode & FMODE_WRITER);
4139 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4140 + spin_unlock(&hf->f_lock);
4142 + put_write_access(file_inode(hf));
4143 + __mnt_drop_write(hf->f_path.mnt);
4148 + au_farray_free(array, max);
4154 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4158 + aufs_bindex_t bindex;
4159 + struct dentry *root;
4160 + struct au_branch *br;
4161 + struct au_br_fhsm *bf;
4163 + root = sb->s_root;
4164 + bindex = au_find_dbindex(root, mod->h_root);
4167 + return 0; /* success */
4169 + pr_err("%s no such branch\n", mod->path);
4172 + AuDbg("bindex b%d\n", bindex);
4174 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4175 + if (unlikely(err))
4178 + br = au_sbr(sb, bindex);
4179 + AuDebugOn(mod->h_root != au_br_dentry(br));
4180 + if (br->br_perm == mod->perm)
4181 + return 0; /* success */
4183 + /* pre-allocate for non-fhsm --> fhsm */
4185 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4186 + err = au_fhsm_br_alloc(br);
4187 + if (unlikely(err))
4190 + br->br_fhsm = NULL;
4193 + if (au_br_writable(br->br_perm)) {
4194 + /* remove whiteout base */
4195 + err = au_br_init_wh(sb, br, mod->perm);
4196 + if (unlikely(err))
4199 + if (!au_br_writable(mod->perm)) {
4200 + /* rw --> ro, file might be mmapped */
4201 + DiMustNoWaiters(root);
4202 + IiMustNoWaiters(d_inode(root));
4203 + di_write_unlock(root);
4204 + err = au_br_mod_files_ro(sb, bindex);
4205 + /* aufs_write_lock() calls ..._child() */
4206 + di_write_lock_child(root);
4208 + if (unlikely(err)) {
4210 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4213 + rerr = au_wbr_init(br, sb, br->br_perm);
4214 + if (unlikely(rerr)) {
4215 + AuIOErr("nested error %d (%d)\n",
4217 + br->br_perm = mod->perm;
4221 + } else if (au_br_writable(mod->perm)) {
4224 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4226 + err = au_wbr_init(br, sb, mod->perm);
4227 + if (unlikely(err)) {
4228 + kfree(br->br_wbr);
4229 + br->br_wbr = NULL;
4233 + if (unlikely(err))
4236 + if (au_br_fhsm(br->br_perm)) {
4237 + if (!au_br_fhsm(mod->perm)) {
4238 + /* fhsm --> non-fhsm */
4239 + au_br_fhsm_fin(br->br_fhsm);
4240 + kfree(br->br_fhsm);
4241 + br->br_fhsm = NULL;
4243 + } else if (au_br_fhsm(mod->perm))
4244 + /* non-fhsm --> fhsm */
4247 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4248 + br->br_perm = mod->perm;
4249 + goto out; /* success */
4258 +/* ---------------------------------------------------------------------- */
4260 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4263 + struct kstatfs kstfs;
4265 + err = vfs_statfs(&br->br_path, &kstfs);
4267 + stfs->f_blocks = kstfs.f_blocks;
4268 + stfs->f_bavail = kstfs.f_bavail;
4269 + stfs->f_files = kstfs.f_files;
4270 + stfs->f_ffree = kstfs.f_ffree;
4275 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4276 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4277 +++ linux/fs/aufs/branch.h 2016-07-25 19:05:34.811159821 +0200
4280 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4282 + * This program, aufs is free software; you can redistribute it and/or modify
4283 + * it under the terms of the GNU General Public License as published by
4284 + * the Free Software Foundation; either version 2 of the License, or
4285 + * (at your option) any later version.
4287 + * This program is distributed in the hope that it will be useful,
4288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4290 + * GNU General Public License for more details.
4292 + * You should have received a copy of the GNU General Public License
4293 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4297 + * branch filesystems and xino for them
4300 +#ifndef __AUFS_BRANCH_H__
4301 +#define __AUFS_BRANCH_H__
4305 +#include <linux/mount.h>
4310 +/* ---------------------------------------------------------------------- */
4313 +struct au_xino_file {
4314 + struct file *xi_file;
4315 + struct mutex xi_nondir_mtx;
4317 + /* todo: make xino files an array to support huge inode number */
4319 +#ifdef CONFIG_DEBUG_FS
4320 + struct dentry *xi_dbgaufs;
4324 +/* File-based Hierarchical Storage Management */
4325 +struct au_br_fhsm {
4326 +#ifdef CONFIG_AUFS_FHSM
4327 + struct mutex bf_lock;
4328 + unsigned long bf_jiffy;
4329 + struct aufs_stfs bf_stfs;
4334 +/* members for writable branch only */
4335 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4337 + struct au_rwsem wbr_wh_rwsem;
4338 + struct dentry *wbr_wh[AuBrWh_Last];
4339 + atomic_t wbr_wh_running;
4340 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4341 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4342 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4345 + unsigned long long wbr_bytes;
4348 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4349 +#define AuBrDynOp (AuDyLast * 4)
4351 +#ifdef CONFIG_AUFS_HFSNOTIFY
4352 +/* support for asynchronous destruction */
4353 +struct au_br_hfsnotify {
4354 + struct fsnotify_group *hfsn_group;
4358 +/* sysfs entries */
4359 +struct au_brsysfs {
4361 + struct attribute attr;
4370 +/* protected by superblock rwsem */
4372 + struct au_xino_file br_xino;
4374 + aufs_bindex_t br_id;
4377 + struct path br_path;
4378 + spinlock_t br_dykey_lock;
4379 + struct au_dykey *br_dykey[AuBrDynOp];
4380 + struct percpu_counter br_count;
4382 + struct au_wbr *br_wbr;
4383 + struct au_br_fhsm *br_fhsm;
4385 + /* xino truncation */
4386 + atomic_t br_xino_running;
4388 +#ifdef CONFIG_AUFS_HFSNOTIFY
4389 + struct au_br_hfsnotify *br_hfsn;
4392 +#ifdef CONFIG_SYSFS
4393 + /* entries under sysfs per mount-point */
4394 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4398 +/* ---------------------------------------------------------------------- */
4400 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4402 + return br->br_path.mnt;
4405 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4407 + return br->br_path.dentry;
4410 +static inline struct super_block *au_br_sb(struct au_branch *br)
4412 + return au_br_mnt(br)->mnt_sb;
4415 +static inline void au_br_get(struct au_branch *br)
4417 + percpu_counter_inc(&br->br_count);
4420 +static inline void au_br_put(struct au_branch *br)
4422 + percpu_counter_dec(&br->br_count);
4425 +static inline s64 au_br_count(struct au_branch *br)
4427 + return percpu_counter_sum(&br->br_count);
4430 +static inline void au_br_count_init(struct au_branch *br)
4432 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4435 +static inline void au_br_count_fin(struct au_branch *br)
4437 + percpu_counter_destroy(&br->br_count);
4440 +static inline int au_br_rdonly(struct au_branch *br)
4442 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4443 + || !au_br_writable(br->br_perm))
4447 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4449 +#ifdef CONFIG_AUFS_HNOTIFY
4450 + return !(brperm & AuBrPerm_RR);
4456 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4458 + int err, exec_flag;
4461 + exec_flag = oflag & __FMODE_EXEC;
4462 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4468 +/* ---------------------------------------------------------------------- */
4472 +void au_br_free(struct au_sbinfo *sinfo);
4473 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4475 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4477 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4478 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4479 +#ifdef CONFIG_COMPAT
4480 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4483 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4486 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4489 +static const loff_t au_loff_max = LLONG_MAX;
4491 +int au_xib_trunc(struct super_block *sb);
4492 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4494 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4495 + size_t size, loff_t *pos);
4496 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4497 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4498 +ino_t au_xino_new_ino(struct super_block *sb);
4499 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4500 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4502 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4504 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4505 + struct file *base_file, int do_test);
4506 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4508 +struct au_opt_xino;
4509 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4510 +void au_xino_clr(struct super_block *sb);
4511 +struct file *au_xino_def(struct super_block *sb);
4512 +int au_xino_path(struct seq_file *seq, struct file *file);
4514 +/* ---------------------------------------------------------------------- */
4516 +/* Superblock to branch */
4518 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4520 + return au_sbr(sb, bindex)->br_id;
4524 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4526 + return au_br_mnt(au_sbr(sb, bindex));
4530 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4532 + return au_br_sb(au_sbr(sb, bindex));
4535 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4537 + au_br_get(au_sbr(sb, bindex));
4540 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4542 + au_br_put(au_sbr(sb, bindex));
4545 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4547 + return au_sbr(sb, bindex)->br_perm;
4550 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4552 + return au_br_whable(au_sbr_perm(sb, bindex));
4555 +/* ---------------------------------------------------------------------- */
4558 + * wbr_wh_read_lock, wbr_wh_write_lock
4559 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4561 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4563 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4564 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4565 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4567 +/* ---------------------------------------------------------------------- */
4569 +#ifdef CONFIG_AUFS_FHSM
4570 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4572 + mutex_init(&brfhsm->bf_lock);
4573 + brfhsm->bf_jiffy = 0;
4574 + brfhsm->bf_readable = 0;
4577 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4579 + mutex_destroy(&brfhsm->bf_lock);
4582 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4583 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4586 +#endif /* __KERNEL__ */
4587 +#endif /* __AUFS_BRANCH_H__ */
4588 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4589 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4590 +++ linux/fs/aufs/conf.mk 2015-09-24 10:47:58.248052907 +0200
4593 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4597 +AuConfStr += ${1}=${${1}}
4601 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4603 + HNOTIFY HFSNOTIFY \
4614 +$(foreach i, ${AuConfAll}, \
4615 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4617 +AuConfName = ${obj}/conf.str
4618 +${AuConfName}.tmp: FORCE
4619 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4620 +${AuConfName}: ${AuConfName}.tmp
4621 + @diff -q $< $@ > /dev/null 2>&1 || { \
4622 + echo ' GEN ' $@; \
4626 +clean-files += ${AuConfName} ${AuConfName}.tmp
4627 +${obj}/sysfs.o: ${AuConfName}
4629 +-include ${srctree}/${src}/conf_priv.mk
4630 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4631 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4632 +++ linux/fs/aufs/cpup.c 2016-07-25 19:05:34.811159821 +0200
4635 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4637 + * This program, aufs is free software; you can redistribute it and/or modify
4638 + * it under the terms of the GNU General Public License as published by
4639 + * the Free Software Foundation; either version 2 of the License, or
4640 + * (at your option) any later version.
4642 + * This program is distributed in the hope that it will be useful,
4643 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4644 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4645 + * GNU General Public License for more details.
4647 + * You should have received a copy of the GNU General Public License
4648 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4652 + * copy-up functions, see wbr_policy.c for copy-down
4655 +#include <linux/fs_stack.h>
4656 +#include <linux/mm.h>
4657 +#include <linux/task_work.h>
4660 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4662 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4663 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4665 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4667 + dst->i_flags |= iflags & ~mask;
4668 + if (au_test_fs_notime(dst->i_sb))
4669 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4672 +void au_cpup_attr_timesizes(struct inode *inode)
4674 + struct inode *h_inode;
4676 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4677 + fsstack_copy_attr_times(inode, h_inode);
4678 + fsstack_copy_inode_size(inode, h_inode);
4681 +void au_cpup_attr_nlink(struct inode *inode, int force)
4683 + struct inode *h_inode;
4684 + struct super_block *sb;
4685 + aufs_bindex_t bindex, bbot;
4688 + bindex = au_ibtop(inode);
4689 + h_inode = au_h_iptr(inode, bindex);
4691 + && !S_ISDIR(h_inode->i_mode)
4692 + && au_opt_test(au_mntflags(sb), PLINK)
4693 + && au_plink_test(inode))
4697 + * 0 can happen in revalidating.
4698 + * h_inode->i_mutex may not be held here, but it is harmless since once
4699 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4701 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4702 + * the incorrect link count.
4704 + set_nlink(inode, h_inode->i_nlink);
4707 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4708 + * it may includes whplink directory.
4710 + if (S_ISDIR(h_inode->i_mode)) {
4711 + bbot = au_ibbot(inode);
4712 + for (bindex++; bindex <= bbot; bindex++) {
4713 + h_inode = au_h_iptr(inode, bindex);
4715 + au_add_nlink(inode, h_inode);
4720 +void au_cpup_attr_changeable(struct inode *inode)
4722 + struct inode *h_inode;
4724 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4725 + inode->i_mode = h_inode->i_mode;
4726 + inode->i_uid = h_inode->i_uid;
4727 + inode->i_gid = h_inode->i_gid;
4728 + au_cpup_attr_timesizes(inode);
4729 + au_cpup_attr_flags(inode, h_inode->i_flags);
4732 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4734 + struct au_iinfo *iinfo = au_ii(inode);
4736 + IiMustWriteLock(inode);
4738 + iinfo->ii_higen = h_inode->i_generation;
4739 + iinfo->ii_hsb1 = h_inode->i_sb;
4742 +void au_cpup_attr_all(struct inode *inode, int force)
4744 + struct inode *h_inode;
4746 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4747 + au_cpup_attr_changeable(inode);
4748 + if (inode->i_nlink > 0)
4749 + au_cpup_attr_nlink(inode, force);
4750 + inode->i_rdev = h_inode->i_rdev;
4751 + inode->i_blkbits = h_inode->i_blkbits;
4752 + au_cpup_igen(inode, h_inode);
4755 +/* ---------------------------------------------------------------------- */
4757 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4759 +/* keep the timestamps of the parent dir when cpup */
4760 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4761 + struct path *h_path)
4763 + struct inode *h_inode;
4765 + dt->dt_dentry = dentry;
4766 + dt->dt_h_path = *h_path;
4767 + h_inode = d_inode(h_path->dentry);
4768 + dt->dt_atime = h_inode->i_atime;
4769 + dt->dt_mtime = h_inode->i_mtime;
4773 +void au_dtime_revert(struct au_dtime *dt)
4775 + struct iattr attr;
4778 + attr.ia_atime = dt->dt_atime;
4779 + attr.ia_mtime = dt->dt_mtime;
4780 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4781 + | ATTR_ATIME | ATTR_ATIME_SET;
4783 + /* no delegation since this is a directory */
4784 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4785 + if (unlikely(err))
4786 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4789 +/* ---------------------------------------------------------------------- */
4791 +/* internal use only */
4792 +struct au_cpup_reg_attr {
4795 + unsigned int iflags; /* inode->i_flags */
4798 +static noinline_for_stack
4799 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4800 + struct au_cpup_reg_attr *h_src_attr)
4802 + int err, sbits, icex;
4803 + unsigned int mnt_flags;
4804 + unsigned char verbose;
4806 + struct path h_path;
4807 + struct inode *h_isrc, *h_idst;
4808 + struct kstat *h_st;
4809 + struct au_branch *br;
4811 + h_path.dentry = au_h_dptr(dst, bindex);
4812 + h_idst = d_inode(h_path.dentry);
4813 + br = au_sbr(dst->d_sb, bindex);
4814 + h_path.mnt = au_br_mnt(br);
4815 + h_isrc = d_inode(h_src);
4816 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4817 + | ATTR_ATIME | ATTR_MTIME
4818 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4819 + if (h_src_attr && h_src_attr->valid) {
4820 + h_st = &h_src_attr->st;
4821 + ia.ia_uid = h_st->uid;
4822 + ia.ia_gid = h_st->gid;
4823 + ia.ia_atime = h_st->atime;
4824 + ia.ia_mtime = h_st->mtime;
4825 + if (h_idst->i_mode != h_st->mode
4826 + && !S_ISLNK(h_idst->i_mode)) {
4827 + ia.ia_valid |= ATTR_MODE;
4828 + ia.ia_mode = h_st->mode;
4830 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4831 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4833 + ia.ia_uid = h_isrc->i_uid;
4834 + ia.ia_gid = h_isrc->i_gid;
4835 + ia.ia_atime = h_isrc->i_atime;
4836 + ia.ia_mtime = h_isrc->i_mtime;
4837 + if (h_idst->i_mode != h_isrc->i_mode
4838 + && !S_ISLNK(h_idst->i_mode)) {
4839 + ia.ia_valid |= ATTR_MODE;
4840 + ia.ia_mode = h_isrc->i_mode;
4842 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4843 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4845 + /* no delegation since it is just created */
4846 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4848 + /* is this nfs only? */
4849 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4850 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4851 + ia.ia_mode = h_isrc->i_mode;
4852 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4855 + icex = br->br_perm & AuBrAttr_ICEX;
4857 + mnt_flags = au_mntflags(dst->d_sb);
4858 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4859 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4865 +/* ---------------------------------------------------------------------- */
4867 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4868 + char *buf, unsigned long blksize)
4871 + size_t sz, rbytes, wbytes;
4872 + unsigned char all_zero;
4874 + struct inode *h_inode;
4875 + /* reduce stack usage */
4878 + zp = page_address(ZERO_PAGE(0));
4879 + if (unlikely(!zp))
4880 + return -ENOMEM; /* possible? */
4885 + AuDbg("len %lld\n", len);
4887 + if (len < blksize)
4891 + /* todo: signal_pending? */
4892 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4893 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4896 + if (unlikely(err < 0))
4900 + if (len >= rbytes && rbytes == blksize)
4901 + all_zero = !memcmp(buf, zp, rbytes);
4908 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4910 + /* todo: signal_pending? */
4911 + if (unlikely(err == -EAGAIN || err == -EINTR))
4913 + if (unlikely(err < 0))
4918 + if (unlikely(err < 0))
4924 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4926 + if (unlikely(res < 0))
4933 + /* the last block may be a hole */
4934 + if (!err && all_zero) {
4935 + AuLabel(last hole);
4938 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4939 + /* nfs requires this step to make last hole */
4940 + /* is this only nfs? */
4942 + /* todo: signal_pending? */
4943 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4944 + } while (err == -EAGAIN || err == -EINTR);
4951 + ia->ia_size = dst->f_pos;
4952 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4953 + ia->ia_file = dst;
4954 + h_inode = file_inode(dst);
4955 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
4956 + /* no delegation since it is just created */
4957 + err = vfsub_notify_change(&dst->f_path, ia,
4958 + /*delegated*/NULL);
4959 + inode_unlock(h_inode);
4966 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4969 + unsigned long blksize;
4970 + unsigned char do_kfree;
4974 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
4975 + if (!blksize || PAGE_SIZE < blksize)
4976 + blksize = PAGE_SIZE;
4977 + AuDbg("blksize %lu\n", blksize);
4978 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4980 + buf = kmalloc(blksize, GFP_NOFS);
4982 + buf = (void *)__get_free_page(GFP_NOFS);
4983 + if (unlikely(!buf))
4986 + if (len > (1 << 22))
4987 + AuDbg("copying a large file %lld\n", (long long)len);
4991 + err = au_do_copy_file(dst, src, len, buf, blksize);
4995 + free_page((unsigned long)buf);
5002 + * to support a sparse file which is opened with O_APPEND,
5003 + * we need to close the file.
5005 +static int au_cp_regular(struct au_cp_generic *cpg)
5008 + enum { SRC, DST };
5010 + aufs_bindex_t bindex;
5011 + unsigned int flags;
5012 + struct dentry *dentry;
5014 + struct file *file;
5018 + .bindex = cpg->bsrc,
5019 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5023 + .bindex = cpg->bdst,
5024 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5025 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5026 + .label = &&out_src
5029 + struct super_block *sb;
5030 + struct task_struct *tsk = current;
5032 + /* bsrc branch can be ro/rw. */
5033 + sb = cpg->dentry->d_sb;
5035 + for (i = 0; i < 2; i++, f++) {
5036 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5037 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5038 + /*file*/NULL, f->force_wr);
5039 + err = PTR_ERR(f->file);
5040 + if (IS_ERR(f->file))
5044 + /* try stopping to update while we copyup */
5045 + IMustLock(d_inode(file[SRC].dentry));
5046 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
5048 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5049 + if (tsk->flags & PF_KTHREAD)
5050 + __fput_sync(file[DST].file);
5052 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
5054 + fput(file[DST].file);
5057 + * we have to call both since we don't know which place the file
5061 + flush_delayed_fput();
5063 + au_sbr_put(sb, file[DST].bindex);
5066 + fput(file[SRC].file);
5067 + au_sbr_put(sb, file[SRC].bindex);
5072 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5073 + struct au_cpup_reg_attr *h_src_attr)
5077 + struct path h_path;
5078 + struct inode *h_src_inode, *h_dst_inode;
5081 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5082 + l = i_size_read(h_src_inode);
5083 + if (cpg->len == -1 || l < cpg->len)
5086 + /* try stopping to update while we are referencing */
5087 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5088 + au_pin_hdir_unlock(cpg->pin);
5090 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5091 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5092 + h_src_attr->iflags = h_src_inode->i_flags;
5093 + if (!au_test_nfs(h_src_inode->i_sb))
5094 + err = vfs_getattr(&h_path, &h_src_attr->st);
5096 + inode_unlock(h_src_inode);
5097 + err = vfs_getattr(&h_path, &h_src_attr->st);
5098 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5100 + if (unlikely(err)) {
5101 + inode_unlock(h_src_inode);
5104 + h_src_attr->valid = 1;
5105 + err = au_cp_regular(cpg);
5106 + inode_unlock(h_src_inode);
5107 + rerr = au_pin_hdir_relock(cpg->pin);
5111 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5112 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5113 + h_dst_inode = d_inode(h_path.dentry);
5114 + spin_lock(&h_dst_inode->i_lock);
5115 + h_dst_inode->i_state |= I_LINKABLE;
5116 + spin_unlock(&h_dst_inode->i_lock);
5123 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5124 + struct inode *h_dir)
5127 + mm_segment_t old_fs;
5132 + struct inode *h_inode = d_inode(h_src);
5133 + const struct inode_operations *h_iop = h_inode->i_op;
5136 + if (unlikely(!h_iop->readlink))
5140 + sym.k = (void *)__get_free_page(GFP_NOFS);
5141 + if (unlikely(!sym.k))
5144 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5145 + old_fs = get_fs();
5146 + set_fs(KERNEL_DS);
5147 + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX);
5152 + sym.k[symlen] = 0;
5153 + err = vfsub_symlink(h_dir, h_path, sym.k);
5155 + free_page((unsigned long)sym.k);
5162 + * regardless 'acl' option, reset all ACL.
5163 + * All ACL will be copied up later from the original entry on the lower branch.
5165 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5168 + struct dentry *h_dentry;
5169 + struct inode *h_inode;
5171 + h_dentry = h_path->dentry;
5172 + h_inode = d_inode(h_dentry);
5173 + /* forget_all_cached_acls(h_inode)); */
5174 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5176 + if (err == -EOPNOTSUPP)
5179 + err = vfsub_acl_chmod(h_inode, mode);
5185 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5186 + struct inode *h_dir, struct path *h_path)
5189 + struct inode *dir, *inode;
5191 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5193 + if (err == -EOPNOTSUPP)
5195 + if (unlikely(err))
5199 + * strange behaviour from the users view,
5200 + * particularry setattr case
5202 + dir = d_inode(dst_parent);
5203 + if (au_ibtop(dir) == cpg->bdst)
5204 + au_cpup_attr_nlink(dir, /*force*/1);
5205 + inode = d_inode(cpg->dentry);
5206 + au_cpup_attr_nlink(inode, /*force*/1);
5212 +static noinline_for_stack
5213 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5214 + struct au_cpup_reg_attr *h_src_attr)
5218 + unsigned int mnt_flags;
5219 + unsigned char isdir, isreg, force;
5220 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5221 + struct au_dtime dt;
5222 + struct path h_path;
5223 + struct dentry *h_src, *h_dst, *h_parent;
5224 + struct inode *h_inode, *h_dir;
5225 + struct super_block *sb;
5227 + /* bsrc branch can be ro/rw. */
5228 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5229 + h_inode = d_inode(h_src);
5230 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5232 + /* try stopping to be referenced while we are creating */
5233 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5234 + if (au_ftest_cpup(cpg->flags, RENAME))
5235 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5236 + AUFS_WH_PFX_LEN));
5237 + h_parent = h_dst->d_parent; /* dir inode is locked */
5238 + h_dir = d_inode(h_parent);
5240 + AuDebugOn(h_parent != h_dst->d_parent);
5242 + sb = cpg->dentry->d_sb;
5243 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5245 + h_path.dentry = h_parent;
5246 + au_dtime_store(&dt, dst_parent, &h_path);
5248 + h_path.dentry = h_dst;
5252 + mode = h_inode->i_mode;
5253 + switch (mode & S_IFMT) {
5256 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5257 + /*want_excl*/true);
5259 + err = au_do_cpup_regular(cpg, h_src_attr);
5263 + err = vfsub_mkdir(h_dir, &h_path, mode);
5265 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5268 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5272 + AuDebugOn(!capable(CAP_MKNOD));
5276 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5279 + AuIOErr("Unknown inode type 0%o\n", mode);
5283 + err = au_reset_acl(h_dir, &h_path, mode);
5285 + mnt_flags = au_mntflags(sb);
5286 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5288 + && au_opt_test(mnt_flags, XINO)
5289 + && (h_inode->i_nlink == 1
5290 + || (h_inode->i_state & I_LINKABLE))
5291 + /* todo: unnecessary? */
5292 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5293 + && cpg->bdst < cpg->bsrc
5294 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5295 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5296 + /* ignore this error */
5301 + force = !!cpg->len;
5302 + if (cpg->len == -1)
5303 + force = !!i_size_read(h_inode);
5305 + au_fhsm_wrote(sb, cpg->bdst, force);
5309 + au_dtime_revert(&dt);
5313 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5316 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5317 + struct inode *h_dir;
5318 + aufs_bindex_t bdst;
5320 + dentry = cpg->dentry;
5322 + h_dentry = au_h_dptr(dentry, bdst);
5323 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5325 + au_set_h_dptr(dentry, bdst, NULL);
5326 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5328 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5329 + au_set_h_dptr(dentry, bdst, h_dentry);
5332 + parent = dget_parent(dentry);
5333 + h_parent = au_h_dptr(parent, bdst);
5335 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5336 + if (IS_ERR(h_path->dentry))
5337 + err = PTR_ERR(h_path->dentry);
5339 + if (unlikely(err))
5342 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5343 + h_dir = d_inode(h_parent);
5345 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5346 + /* no delegation since it is just created */
5347 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
5348 + dput(h_path->dentry);
5355 + * copyup the @dentry from @bsrc to @bdst.
5356 + * the caller must set the both of lower dentries.
5357 + * @len is for truncating when it is -1 copyup the entire file.
5358 + * in link/rename cases, @dst_parent may be different from the real one.
5359 + * basic->bsrc can be larger than basic->bdst.
5361 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5364 + aufs_bindex_t old_ibtop;
5365 + unsigned char isdir, plink;
5366 + struct dentry *h_src, *h_dst, *h_parent;
5367 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5368 + struct super_block *sb;
5369 + struct au_branch *br;
5370 + /* to reuduce stack size */
5372 + struct au_dtime dt;
5373 + struct path h_path;
5374 + struct au_cpup_reg_attr h_src_attr;
5378 + a = kmalloc(sizeof(*a), GFP_NOFS);
5381 + a->h_src_attr.valid = 0;
5383 + sb = cpg->dentry->d_sb;
5384 + br = au_sbr(sb, cpg->bdst);
5385 + a->h_path.mnt = au_br_mnt(br);
5386 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5387 + h_parent = h_dst->d_parent; /* dir inode is locked */
5388 + h_dir = d_inode(h_parent);
5391 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5392 + inode = d_inode(cpg->dentry);
5395 + dst_parent = dget_parent(cpg->dentry);
5399 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5400 + dst_inode = au_h_iptr(inode, cpg->bdst);
5402 + if (unlikely(!plink)) {
5404 + AuIOErr("hi%lu(i%lu) exists on b%d "
5405 + "but plink is disabled\n",
5406 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5410 + if (dst_inode->i_nlink) {
5411 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5413 + h_src = au_plink_lkup(inode, cpg->bdst);
5414 + err = PTR_ERR(h_src);
5415 + if (IS_ERR(h_src))
5417 + if (unlikely(d_is_negative(h_src))) {
5419 + AuIOErr("i%lu exists on b%d "
5420 + "but not pseudo-linked\n",
5421 + inode->i_ino, cpg->bdst);
5427 + a->h_path.dentry = h_parent;
5428 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5431 + a->h_path.dentry = h_dst;
5433 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5434 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5435 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5437 + au_dtime_revert(&a->dt);
5438 + if (unlikely(err == -EWOULDBLOCK)) {
5439 + pr_warn("cannot retry for NFSv4 delegation"
5440 + " for an internal link\n");
5446 + /* todo: cpup_wh_file? */
5448 + au_update_ibrange(inode, /*do_put_zero*/1);
5451 + isdir = S_ISDIR(inode->i_mode);
5452 + old_ibtop = au_ibtop(inode);
5453 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5454 + if (unlikely(err))
5456 + dst_inode = d_inode(h_dst);
5457 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5458 + /* todo: necessary? */
5459 + /* au_pin_hdir_unlock(cpg->pin); */
5461 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5462 + if (unlikely(err)) {
5463 + /* todo: necessary? */
5464 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5465 + inode_unlock(dst_inode);
5469 + if (cpg->bdst < old_ibtop) {
5470 + if (S_ISREG(inode->i_mode)) {
5471 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5472 + if (unlikely(err)) {
5473 + /* ignore an error */
5474 + /* au_pin_hdir_relock(cpg->pin); */
5475 + inode_unlock(dst_inode);
5479 + au_set_ibtop(inode, cpg->bdst);
5481 + au_set_ibbot(inode, cpg->bdst);
5482 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5483 + au_hi_flags(inode, isdir));
5485 + /* todo: necessary? */
5486 + /* err = au_pin_hdir_relock(cpg->pin); */
5487 + inode_unlock(dst_inode);
5488 + if (unlikely(err))
5491 + src_inode = d_inode(h_src);
5493 + && (src_inode->i_nlink > 1
5494 + || src_inode->i_state & I_LINKABLE)
5496 + au_plink_append(inode, cpg->bdst, h_dst);
5498 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5499 + a->h_path.dentry = h_dst;
5500 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5503 + goto out_parent; /* success */
5507 + a->h_path.dentry = h_parent;
5508 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5509 + a->h_path.dentry = h_dst;
5511 + if (d_is_positive(h_dst)) {
5513 + /* no delegation since it is just created */
5514 + rerr = vfsub_unlink(h_dir, &a->h_path,
5515 + /*delegated*/NULL, /*force*/0);
5517 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5519 + au_dtime_revert(&a->dt);
5521 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5531 +#if 0 /* reserved */
5532 +struct au_cpup_single_args {
5534 + struct au_cp_generic *cpg;
5535 + struct dentry *dst_parent;
5538 +static void au_call_cpup_single(void *args)
5540 + struct au_cpup_single_args *a = args;
5542 + au_pin_hdir_acquire_nest(a->cpg->pin);
5543 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5544 + au_pin_hdir_release(a->cpg->pin);
5549 + * prevent SIGXFSZ in copy-up.
5550 + * testing CAP_MKNOD is for generic fs,
5551 + * but CAP_FSETID is for xfs only, currently.
5553 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5556 + struct super_block *sb;
5557 + struct inode *h_dir;
5560 + sb = au_pinned_parent(pin)->d_sb;
5561 + if (!au_wkq_test()
5562 + && (!au_sbi(sb)->si_plink_maint_pid
5563 + || au_plink_maint(sb, AuLock_NOPLM))) {
5564 + switch (mode & S_IFMT) {
5566 + /* no condition about RLIMIT_FSIZE and the file size */
5571 + do_sio = !capable(CAP_MKNOD);
5575 + do_sio = ((mode & (S_ISUID | S_ISGID))
5576 + && !capable(CAP_FSETID));
5577 + /* this workaround may be removed in the future */
5579 + h_dir = au_pinned_h_dir(pin);
5580 + do_sio = h_dir->i_mode & S_ISVTX;
5587 +#if 0 /* reserved */
5588 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5591 + struct dentry *h_dentry;
5593 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5594 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5595 + err = au_cpup_single(cpg, dst_parent);
5597 + struct au_cpup_single_args args = {
5600 + .dst_parent = dst_parent
5602 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5603 + if (unlikely(wkq_err))
5612 + * copyup the @dentry from the first active lower branch to @bdst,
5613 + * using au_cpup_single().
5615 +static int au_cpup_simple(struct au_cp_generic *cpg)
5618 + unsigned int flags_orig;
5619 + struct dentry *dentry;
5621 + AuDebugOn(cpg->bsrc < 0);
5623 + dentry = cpg->dentry;
5624 + DiMustWriteLock(dentry);
5626 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5628 + flags_orig = cpg->flags;
5629 + au_fset_cpup(cpg->flags, RENAME);
5630 + err = au_cpup_single(cpg, NULL);
5631 + cpg->flags = flags_orig;
5633 + return 0; /* success */
5636 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5637 + au_set_dbtop(dentry, cpg->bsrc);
5643 +struct au_cpup_simple_args {
5645 + struct au_cp_generic *cpg;
5648 +static void au_call_cpup_simple(void *args)
5650 + struct au_cpup_simple_args *a = args;
5652 + au_pin_hdir_acquire_nest(a->cpg->pin);
5653 + *a->errp = au_cpup_simple(a->cpg);
5654 + au_pin_hdir_release(a->cpg->pin);
5657 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5660 + struct dentry *dentry, *parent;
5661 + struct file *h_file;
5662 + struct inode *h_dir;
5664 + dentry = cpg->dentry;
5666 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5667 + AuDebugOn(cpg->bsrc < 0);
5668 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5669 + err = PTR_ERR(h_file);
5670 + if (IS_ERR(h_file))
5674 + parent = dget_parent(dentry);
5675 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5676 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5677 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5678 + err = au_cpup_simple(cpg);
5680 + struct au_cpup_simple_args args = {
5684 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5685 + if (unlikely(wkq_err))
5691 + au_h_open_post(dentry, cpg->bsrc, h_file);
5697 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5699 + aufs_bindex_t bsrc, bbot;
5700 + struct dentry *dentry, *h_dentry;
5702 + if (cpg->bsrc < 0) {
5703 + dentry = cpg->dentry;
5704 + bbot = au_dbbot(dentry);
5705 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5706 + h_dentry = au_h_dptr(dentry, bsrc);
5708 + AuDebugOn(d_is_negative(h_dentry));
5712 + AuDebugOn(bsrc > bbot);
5715 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5716 + return au_do_sio_cpup_simple(cpg);
5719 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5721 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5722 + return au_do_sio_cpup_simple(cpg);
5725 +/* ---------------------------------------------------------------------- */
5728 + * copyup the deleted file for writing.
5730 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5731 + struct file *file)
5734 + unsigned int flags_orig;
5735 + aufs_bindex_t bsrc_orig;
5736 + struct au_dinfo *dinfo;
5738 + struct au_hdentry *hd;
5739 + struct dentry *h_dentry;
5742 + dinfo = au_di(cpg->dentry);
5743 + AuRwMustWriteLock(&dinfo->di_rwsem);
5745 + bsrc_orig = cpg->bsrc;
5746 + cpg->bsrc = dinfo->di_btop;
5747 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5748 + hdst.h_dentry = hdst.hd->hd_dentry;
5749 + hdst.hd->hd_dentry = wh_dentry;
5750 + dinfo->di_btop = cpg->bdst;
5752 + hsrc.h_dentry = NULL;
5754 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5755 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5756 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5758 + flags_orig = cpg->flags;
5759 + cpg->flags = !AuCpup_DTIME;
5760 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5761 + cpg->flags = flags_orig;
5764 + err = au_reopen_nondir(file);
5765 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5767 + hdst.hd->hd_dentry = hdst.h_dentry;
5768 + dinfo->di_btop = cpg->bsrc;
5769 + cpg->bsrc = bsrc_orig;
5774 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5777 + aufs_bindex_t bdst;
5778 + struct au_dtime dt;
5779 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5780 + struct au_branch *br;
5781 + struct path h_path;
5783 + dentry = cpg->dentry;
5785 + br = au_sbr(dentry->d_sb, bdst);
5786 + parent = dget_parent(dentry);
5787 + h_parent = au_h_dptr(parent, bdst);
5788 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5789 + err = PTR_ERR(wh_dentry);
5790 + if (IS_ERR(wh_dentry))
5793 + h_path.dentry = h_parent;
5794 + h_path.mnt = au_br_mnt(br);
5795 + au_dtime_store(&dt, parent, &h_path);
5796 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5797 + if (unlikely(err))
5801 + h_path.dentry = wh_dentry;
5802 + if (!d_is_dir(wh_dentry)) {
5803 + /* no delegation since it is just created */
5804 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5805 + /*delegated*/NULL, /*force*/0);
5807 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5808 + if (unlikely(err)) {
5809 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5813 + au_dtime_revert(&dt);
5814 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5823 +struct au_cpup_wh_args {
5825 + struct au_cp_generic *cpg;
5826 + struct file *file;
5829 +static void au_call_cpup_wh(void *args)
5831 + struct au_cpup_wh_args *a = args;
5833 + au_pin_hdir_acquire_nest(a->cpg->pin);
5834 + *a->errp = au_cpup_wh(a->cpg, a->file);
5835 + au_pin_hdir_release(a->cpg->pin);
5838 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5841 + aufs_bindex_t bdst;
5842 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5843 + struct inode *dir, *h_dir, *h_tmpdir;
5844 + struct au_wbr *wbr;
5845 + struct au_pin wh_pin, *pin_orig;
5847 + dentry = cpg->dentry;
5849 + parent = dget_parent(dentry);
5850 + dir = d_inode(parent);
5853 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5856 + if (!h_dir->i_nlink) {
5857 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5858 + h_orph = wbr->wbr_orph;
5860 + h_parent = dget(au_h_dptr(parent, bdst));
5861 + au_set_h_dptr(parent, bdst, dget(h_orph));
5862 + h_tmpdir = d_inode(h_orph);
5863 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5865 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
5866 + /* todo: au_h_open_pre()? */
5868 + pin_orig = cpg->pin;
5869 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5870 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5871 + cpg->pin = &wh_pin;
5874 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5875 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5876 + err = au_cpup_wh(cpg, file);
5878 + struct au_cpup_wh_args args = {
5883 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5884 + if (unlikely(wkq_err))
5889 + inode_unlock(h_tmpdir);
5890 + /* todo: au_h_open_post()? */
5891 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5892 + au_set_h_dptr(parent, bdst, h_parent);
5893 + AuDebugOn(!pin_orig);
5894 + cpg->pin = pin_orig;
5902 +/* ---------------------------------------------------------------------- */
5905 + * generic routine for both of copy-up and copy-down.
5907 +/* cf. revalidate function in file.c */
5908 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5909 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5910 + struct au_pin *pin,
5911 + struct dentry *h_parent, void *arg),
5915 + struct au_pin pin;
5916 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
5919 + parent = dget_parent(dentry);
5920 + if (IS_ROOT(parent))
5923 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5924 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5926 + /* do not use au_dpage */
5927 + real_parent = parent;
5930 + parent = dget_parent(dentry);
5931 + h_parent = au_h_dptr(parent, bdst);
5933 + goto out; /* success */
5935 + /* find top dir which is necessary to cpup */
5939 + parent = dget_parent(d);
5940 + di_read_lock_parent3(parent, !AuLock_IR);
5941 + h_parent = au_h_dptr(parent, bdst);
5942 + di_read_unlock(parent, !AuLock_IR);
5943 + } while (!h_parent);
5945 + if (d != real_parent)
5946 + di_write_lock_child3(d);
5948 + /* somebody else might create while we were sleeping */
5949 + h_dentry = au_h_dptr(d, bdst);
5950 + if (!h_dentry || d_is_negative(h_dentry)) {
5952 + au_update_dbtop(d);
5954 + au_pin_set_dentry(&pin, d);
5955 + err = au_do_pin(&pin);
5957 + err = cp(d, bdst, &pin, h_parent, arg);
5962 + if (d != real_parent)
5963 + di_write_unlock(d);
5964 + if (unlikely(err))
5973 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5974 + struct au_pin *pin,
5975 + struct dentry *h_parent __maybe_unused,
5976 + void *arg __maybe_unused)
5978 + struct au_cp_generic cpg = {
5984 + .flags = AuCpup_DTIME
5986 + return au_sio_cpup_simple(&cpg);
5989 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5991 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
5994 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
5997 + struct dentry *parent;
5998 + struct inode *dir;
6000 + parent = dget_parent(dentry);
6001 + dir = d_inode(parent);
6003 + if (au_h_iptr(dir, bdst))
6006 + di_read_unlock(parent, AuLock_IR);
6007 + di_write_lock_parent(parent);
6008 + /* someone else might change our inode while we were sleeping */
6009 + if (!au_h_iptr(dir, bdst))
6010 + err = au_cpup_dirs(dentry, bdst);
6011 + di_downgrade_lock(parent, AuLock_IR);
6017 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6018 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6019 +++ linux/fs/aufs/cpup.h 2016-07-25 19:05:34.811159821 +0200
6022 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6024 + * This program, aufs is free software; you can redistribute it and/or modify
6025 + * it under the terms of the GNU General Public License as published by
6026 + * the Free Software Foundation; either version 2 of the License, or
6027 + * (at your option) any later version.
6029 + * This program is distributed in the hope that it will be useful,
6030 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6031 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6032 + * GNU General Public License for more details.
6034 + * You should have received a copy of the GNU General Public License
6035 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6039 + * copy-up/down functions
6042 +#ifndef __AUFS_CPUP_H__
6043 +#define __AUFS_CPUP_H__
6047 +#include <linux/path.h>
6053 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6054 +void au_cpup_attr_timesizes(struct inode *inode);
6055 +void au_cpup_attr_nlink(struct inode *inode, int force);
6056 +void au_cpup_attr_changeable(struct inode *inode);
6057 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6058 +void au_cpup_attr_all(struct inode *inode, int force);
6060 +/* ---------------------------------------------------------------------- */
6062 +struct au_cp_generic {
6063 + struct dentry *dentry;
6064 + aufs_bindex_t bdst, bsrc;
6066 + struct au_pin *pin;
6067 + unsigned int flags;
6071 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6072 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6074 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6075 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6077 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6079 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6080 + the branch is marked as RO */
6082 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6083 +#define au_fset_cpup(flags, name) \
6084 + do { (flags) |= AuCpup_##name; } while (0)
6085 +#define au_fclr_cpup(flags, name) \
6086 + do { (flags) &= ~AuCpup_##name; } while (0)
6088 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6089 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6090 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6091 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6093 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6094 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6095 + struct au_pin *pin,
6096 + struct dentry *h_parent, void *arg),
6098 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6099 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6101 +/* ---------------------------------------------------------------------- */
6103 +/* keep timestamps when copyup */
6105 + struct dentry *dt_dentry;
6106 + struct path dt_h_path;
6107 + struct timespec dt_atime, dt_mtime;
6109 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6110 + struct path *h_path);
6111 +void au_dtime_revert(struct au_dtime *dt);
6113 +#endif /* __KERNEL__ */
6114 +#endif /* __AUFS_CPUP_H__ */
6115 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6116 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6117 +++ linux/fs/aufs/dbgaufs.c 2016-07-25 19:05:34.811159821 +0200
6120 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6122 + * This program, aufs is free software; you can redistribute it and/or modify
6123 + * it under the terms of the GNU General Public License as published by
6124 + * the Free Software Foundation; either version 2 of the License, or
6125 + * (at your option) any later version.
6127 + * This program is distributed in the hope that it will be useful,
6128 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6129 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6130 + * GNU General Public License for more details.
6132 + * You should have received a copy of the GNU General Public License
6133 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6137 + * debugfs interface
6140 +#include <linux/debugfs.h>
6143 +#ifndef CONFIG_SYSFS
6144 +#error DEBUG_FS depends upon SYSFS
6147 +static struct dentry *dbgaufs;
6148 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6150 +/* 20 is max digits length of ulong 64 */
6151 +struct dbgaufs_arg {
6157 + * common function for all XINO files
6159 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6160 + struct file *file)
6162 + kfree(file->private_data);
6166 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6170 + struct dbgaufs_arg *p;
6173 + p = kmalloc(sizeof(*p), GFP_NOFS);
6179 + file->private_data = p;
6183 + err = vfs_getattr(&xf->f_path, &st);
6187 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
6188 + (long)file_count(xf), st.blocks, st.blksize,
6189 + (long long)st.size);
6191 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
6192 + st.blocks, st.blksize,
6193 + (long long)st.size);
6194 + AuDebugOn(p->n >= sizeof(p->a));
6196 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6205 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6206 + size_t count, loff_t *ppos)
6208 + struct dbgaufs_arg *p;
6210 + p = file->private_data;
6211 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6214 +/* ---------------------------------------------------------------------- */
6216 +struct dbgaufs_plink_arg {
6221 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6222 + struct file *file)
6224 + free_page((unsigned long)file->private_data);
6228 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6230 + int err, i, limit;
6231 + unsigned long n, sum;
6232 + struct dbgaufs_plink_arg *p;
6233 + struct au_sbinfo *sbinfo;
6234 + struct super_block *sb;
6235 + struct au_sphlhead *sphl;
6238 + p = (void *)get_zeroed_page(GFP_NOFS);
6243 + sbinfo = inode->i_private;
6244 + sb = sbinfo->si_sb;
6245 + si_noflush_read_lock(sb);
6246 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6247 + limit = PAGE_SIZE - sizeof(p->n);
6249 + /* the number of buckets */
6250 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6255 + for (i = 0, sphl = sbinfo->si_plink;
6256 + i < AuPlink_NHASH;
6258 + n = au_sphl_count(sphl);
6261 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6264 + if (unlikely(limit <= 0))
6267 + p->a[p->n - 1] = '\n';
6269 + /* the sum of plinks */
6270 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6273 + if (unlikely(limit <= 0))
6276 +#define str "1\n0\n0\n"
6277 + p->n = sizeof(str) - 1;
6278 + strcpy(p->a, str);
6281 + si_read_unlock(sb);
6284 + file->private_data = p;
6285 + goto out; /* success */
6288 + free_page((unsigned long)p);
6293 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6294 + size_t count, loff_t *ppos)
6296 + struct dbgaufs_plink_arg *p;
6298 + p = file->private_data;
6299 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6302 +static const struct file_operations dbgaufs_plink_fop = {
6303 + .owner = THIS_MODULE,
6304 + .open = dbgaufs_plink_open,
6305 + .release = dbgaufs_plink_release,
6306 + .read = dbgaufs_plink_read
6309 +/* ---------------------------------------------------------------------- */
6311 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6314 + struct au_sbinfo *sbinfo;
6315 + struct super_block *sb;
6317 + sbinfo = inode->i_private;
6318 + sb = sbinfo->si_sb;
6319 + si_noflush_read_lock(sb);
6320 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6321 + si_read_unlock(sb);
6325 +static const struct file_operations dbgaufs_xib_fop = {
6326 + .owner = THIS_MODULE,
6327 + .open = dbgaufs_xib_open,
6328 + .release = dbgaufs_xi_release,
6329 + .read = dbgaufs_xi_read
6332 +/* ---------------------------------------------------------------------- */
6334 +#define DbgaufsXi_PREFIX "xi"
6336 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6340 + struct au_sbinfo *sbinfo;
6341 + struct super_block *sb;
6343 + struct qstr *name;
6347 + name = &file->f_path.dentry->d_name;
6348 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6349 + || memcmp(name->name, DbgaufsXi_PREFIX,
6350 + sizeof(DbgaufsXi_PREFIX) - 1)))
6352 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6353 + if (unlikely(err))
6356 + sbinfo = inode->i_private;
6357 + sb = sbinfo->si_sb;
6358 + si_noflush_read_lock(sb);
6359 + if (l <= au_sbbot(sb)) {
6360 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6361 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6364 + si_read_unlock(sb);
6370 +static const struct file_operations dbgaufs_xino_fop = {
6371 + .owner = THIS_MODULE,
6372 + .open = dbgaufs_xino_open,
6373 + .release = dbgaufs_xi_release,
6374 + .read = dbgaufs_xi_read
6377 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6379 + aufs_bindex_t bbot;
6380 + struct au_branch *br;
6381 + struct au_xino_file *xi;
6383 + if (!au_sbi(sb)->si_dbgaufs)
6386 + bbot = au_sbbot(sb);
6387 + for (; bindex <= bbot; bindex++) {
6388 + br = au_sbr(sb, bindex);
6389 + xi = &br->br_xino;
6390 + debugfs_remove(xi->xi_dbgaufs);
6391 + xi->xi_dbgaufs = NULL;
6395 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6397 + struct au_sbinfo *sbinfo;
6398 + struct dentry *parent;
6399 + struct au_branch *br;
6400 + struct au_xino_file *xi;
6401 + aufs_bindex_t bbot;
6402 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6404 + sbinfo = au_sbi(sb);
6405 + parent = sbinfo->si_dbgaufs;
6409 + bbot = au_sbbot(sb);
6410 + for (; bindex <= bbot; bindex++) {
6411 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6412 + br = au_sbr(sb, bindex);
6413 + xi = &br->br_xino;
6414 + AuDebugOn(xi->xi_dbgaufs);
6415 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6416 + sbinfo, &dbgaufs_xino_fop);
6417 + /* ignore an error */
6418 + if (unlikely(!xi->xi_dbgaufs))
6419 + AuWarn1("failed %s under debugfs\n", name);
6423 +/* ---------------------------------------------------------------------- */
6425 +#ifdef CONFIG_AUFS_EXPORT
6426 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6429 + struct au_sbinfo *sbinfo;
6430 + struct super_block *sb;
6432 + sbinfo = inode->i_private;
6433 + sb = sbinfo->si_sb;
6434 + si_noflush_read_lock(sb);
6435 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6436 + si_read_unlock(sb);
6440 +static const struct file_operations dbgaufs_xigen_fop = {
6441 + .owner = THIS_MODULE,
6442 + .open = dbgaufs_xigen_open,
6443 + .release = dbgaufs_xi_release,
6444 + .read = dbgaufs_xi_read
6447 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6452 + * This function is a dynamic '__init' function actually,
6453 + * so the tiny check for si_rwsem is unnecessary.
6455 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6458 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6459 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6460 + &dbgaufs_xigen_fop);
6461 + if (sbinfo->si_dbgaufs_xigen)
6467 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6471 +#endif /* CONFIG_AUFS_EXPORT */
6473 +/* ---------------------------------------------------------------------- */
6475 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6478 + * This function is a dynamic '__fin' function actually,
6479 + * so the tiny check for si_rwsem is unnecessary.
6481 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6483 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6484 + sbinfo->si_dbgaufs = NULL;
6485 + kobject_put(&sbinfo->si_kobj);
6488 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6491 + char name[SysaufsSiNameLen];
6494 + * This function is a dynamic '__init' function actually,
6495 + * so the tiny check for si_rwsem is unnecessary.
6497 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6501 + AuErr1("/debug/aufs is uninitialized\n");
6506 + sysaufs_name(sbinfo, name);
6507 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6508 + if (unlikely(!sbinfo->si_dbgaufs))
6510 + kobject_get(&sbinfo->si_kobj);
6512 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6513 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6514 + &dbgaufs_xib_fop);
6515 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6518 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6519 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6520 + &dbgaufs_plink_fop);
6521 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6524 + err = dbgaufs_xigen_init(sbinfo);
6526 + goto out; /* success */
6529 + dbgaufs_si_fin(sbinfo);
6534 +/* ---------------------------------------------------------------------- */
6536 +void dbgaufs_fin(void)
6538 + debugfs_remove(dbgaufs);
6541 +int __init dbgaufs_init(void)
6546 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6551 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6552 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6553 +++ linux/fs/aufs/dbgaufs.h 2016-07-25 19:05:34.811159821 +0200
6556 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6558 + * This program, aufs is free software; you can redistribute it and/or modify
6559 + * it under the terms of the GNU General Public License as published by
6560 + * the Free Software Foundation; either version 2 of the License, or
6561 + * (at your option) any later version.
6563 + * This program is distributed in the hope that it will be useful,
6564 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6565 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6566 + * GNU General Public License for more details.
6568 + * You should have received a copy of the GNU General Public License
6569 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6573 + * debugfs interface
6576 +#ifndef __DBGAUFS_H__
6577 +#define __DBGAUFS_H__
6581 +struct super_block;
6584 +#ifdef CONFIG_DEBUG_FS
6586 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6587 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6588 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6589 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6590 +void dbgaufs_fin(void);
6591 +int __init dbgaufs_init(void);
6593 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6594 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6595 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6596 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6597 +AuStubVoid(dbgaufs_fin, void)
6598 +AuStubInt0(__init dbgaufs_init, void)
6599 +#endif /* CONFIG_DEBUG_FS */
6601 +#endif /* __KERNEL__ */
6602 +#endif /* __DBGAUFS_H__ */
6603 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6604 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6605 +++ linux/fs/aufs/dcsub.c 2016-07-25 19:05:34.811159821 +0200
6608 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6610 + * This program, aufs is free software; you can redistribute it and/or modify
6611 + * it under the terms of the GNU General Public License as published by
6612 + * the Free Software Foundation; either version 2 of the License, or
6613 + * (at your option) any later version.
6615 + * This program is distributed in the hope that it will be useful,
6616 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6617 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6618 + * GNU General Public License for more details.
6620 + * You should have received a copy of the GNU General Public License
6621 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6625 + * sub-routines for dentry cache
6630 +static void au_dpage_free(struct au_dpage *dpage)
6633 + struct dentry **p;
6635 + p = dpage->dentries;
6636 + for (i = 0; i < dpage->ndentry; i++)
6638 + free_page((unsigned long)dpage->dentries);
6641 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6647 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6648 + if (unlikely(!dpages->dpages))
6651 + p = (void *)__get_free_page(gfp);
6655 + dpages->dpages[0].ndentry = 0;
6656 + dpages->dpages[0].dentries = p;
6657 + dpages->ndpage = 1;
6658 + return 0; /* success */
6661 + kfree(dpages->dpages);
6666 +void au_dpages_free(struct au_dcsub_pages *dpages)
6669 + struct au_dpage *p;
6671 + p = dpages->dpages;
6672 + for (i = 0; i < dpages->ndpage; i++)
6673 + au_dpage_free(p++);
6674 + kfree(dpages->dpages);
6677 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6678 + struct dentry *dentry, gfp_t gfp)
6681 + struct au_dpage *dpage;
6684 + dpage = dpages->dpages + dpages->ndpage - 1;
6685 + sz = PAGE_SIZE / sizeof(dentry);
6686 + if (unlikely(dpage->ndentry >= sz)) {
6687 + AuLabel(new dpage);
6689 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6690 + p = au_kzrealloc(dpages->dpages, sz,
6691 + sz + sizeof(*dpages->dpages), gfp);
6695 + dpages->dpages = p;
6696 + dpage = dpages->dpages + dpages->ndpage;
6697 + p = (void *)__get_free_page(gfp);
6701 + dpage->ndentry = 0;
6702 + dpage->dentries = p;
6706 + AuDebugOn(au_dcount(dentry) <= 0);
6707 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6708 + return 0; /* success */
6714 +/* todo: BAD approach */
6715 +/* copied from linux/fs/dcache.c */
6723 +extern void d_walk(struct dentry *parent, void *data,
6724 + enum d_walk_ret (*enter)(void *, struct dentry *),
6725 + void (*finish)(void *));
6727 +struct ac_dpages_arg {
6729 + struct au_dcsub_pages *dpages;
6730 + struct super_block *sb;
6731 + au_dpages_test test;
6735 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6737 + enum d_walk_ret ret;
6738 + struct ac_dpages_arg *arg = _arg;
6740 + ret = D_WALK_CONTINUE;
6741 + if (dentry->d_sb == arg->sb
6742 + && !IS_ROOT(dentry)
6743 + && au_dcount(dentry) > 0
6745 + && (!arg->test || arg->test(dentry, arg->arg))) {
6746 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6747 + if (unlikely(arg->err))
6748 + ret = D_WALK_QUIT;
6754 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6755 + au_dpages_test test, void *arg)
6757 + struct ac_dpages_arg args = {
6765 + d_walk(root, &args, au_call_dpages_append, NULL);
6770 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6771 + int do_include, au_dpages_test test, void *arg)
6776 + write_seqlock(&rename_lock);
6777 + spin_lock(&dentry->d_lock);
6779 + && au_dcount(dentry) > 0
6780 + && (!test || test(dentry, arg)))
6781 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6782 + spin_unlock(&dentry->d_lock);
6783 + if (unlikely(err))
6787 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6790 + while (!IS_ROOT(dentry)) {
6791 + dentry = dentry->d_parent; /* rename_lock is locked */
6792 + spin_lock(&dentry->d_lock);
6793 + if (au_dcount(dentry) > 0
6794 + && (!test || test(dentry, arg)))
6795 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6796 + spin_unlock(&dentry->d_lock);
6797 + if (unlikely(err))
6802 + write_sequnlock(&rename_lock);
6806 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6808 + return au_di(dentry) && dentry->d_sb == arg;
6811 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6812 + struct dentry *dentry, int do_include)
6814 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6815 + au_dcsub_dpages_aufs, dentry->d_sb);
6818 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6820 + struct path path[2] = {
6829 + return path_is_under(path + 0, path + 1);
6831 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6832 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6833 +++ linux/fs/aufs/dcsub.h 2016-07-25 19:05:34.811159821 +0200
6836 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6838 + * This program, aufs is free software; you can redistribute it and/or modify
6839 + * it under the terms of the GNU General Public License as published by
6840 + * the Free Software Foundation; either version 2 of the License, or
6841 + * (at your option) any later version.
6843 + * This program is distributed in the hope that it will be useful,
6844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6846 + * GNU General Public License for more details.
6848 + * You should have received a copy of the GNU General Public License
6849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6853 + * sub-routines for dentry cache
6856 +#ifndef __AUFS_DCSUB_H__
6857 +#define __AUFS_DCSUB_H__
6861 +#include <linux/dcache.h>
6862 +#include <linux/fs.h>
6866 + struct dentry **dentries;
6869 +struct au_dcsub_pages {
6871 + struct au_dpage *dpages;
6874 +/* ---------------------------------------------------------------------- */
6877 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6878 +void au_dpages_free(struct au_dcsub_pages *dpages);
6879 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6880 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6881 + au_dpages_test test, void *arg);
6882 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6883 + int do_include, au_dpages_test test, void *arg);
6884 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6885 + struct dentry *dentry, int do_include);
6886 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6888 +/* ---------------------------------------------------------------------- */
6891 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6892 + * include/linux/dcache.h. Try them (in the future).
6895 +static inline int au_d_hashed_positive(struct dentry *d)
6898 + struct inode *inode = d_inode(d);
6901 + if (unlikely(d_unhashed(d)
6902 + || d_is_negative(d)
6903 + || !inode->i_nlink))
6908 +static inline int au_d_linkable(struct dentry *d)
6911 + struct inode *inode = d_inode(d);
6913 + err = au_d_hashed_positive(d);
6915 + && d_is_positive(d)
6916 + && (inode->i_state & I_LINKABLE))
6921 +static inline int au_d_alive(struct dentry *d)
6924 + struct inode *inode;
6928 + err = au_d_hashed_positive(d);
6930 + inode = d_inode(d);
6931 + if (unlikely(d_unlinked(d)
6932 + || d_is_negative(d)
6933 + || !inode->i_nlink))
6939 +static inline int au_alive_dir(struct dentry *d)
6943 + err = au_d_alive(d);
6944 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
6949 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6951 + return a->len == b->len
6952 + && !memcmp(a->name, b->name, a->len);
6957 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
6959 + * the type of d_lockref.count became int, but the inlined function d_count()
6960 + * still returns unsigned int.
6961 + * I don't know why. Maybe it is for every d_count() users?
6962 + * Anyway au_dcount() lives on.
6964 +static inline int au_dcount(struct dentry *d)
6966 + return (int)d_count(d);
6969 +#endif /* __KERNEL__ */
6970 +#endif /* __AUFS_DCSUB_H__ */
6971 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6972 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6973 +++ linux/fs/aufs/debug.c 2016-07-25 19:05:34.811159821 +0200
6976 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6978 + * This program, aufs is free software; you can redistribute it and/or modify
6979 + * it under the terms of the GNU General Public License as published by
6980 + * the Free Software Foundation; either version 2 of the License, or
6981 + * (at your option) any later version.
6983 + * This program is distributed in the hope that it will be useful,
6984 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6985 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6986 + * GNU General Public License for more details.
6988 + * You should have received a copy of the GNU General Public License
6989 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6993 + * debug print functions
6998 +/* Returns 0, or -errno. arg is in kp->arg. */
6999 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7003 + err = kstrtoint(val, 0, &n);
7013 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7014 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7019 + return sprintf(buffer, "%d", atomic_read(a));
7022 +static struct kernel_param_ops param_ops_atomic_t = {
7023 + .set = param_atomic_t_set,
7024 + .get = param_atomic_t_get
7025 + /* void (*free)(void *arg) */
7028 +atomic_t aufs_debug = ATOMIC_INIT(0);
7029 +MODULE_PARM_DESC(debug, "debug print");
7030 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7032 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7033 +char *au_plevel = KERN_DEBUG;
7034 +#define dpri(fmt, ...) do { \
7036 + && strcmp(au_plevel, KERN_DEBUG)) \
7037 + || au_debug_test()) \
7038 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7041 +/* ---------------------------------------------------------------------- */
7043 +void au_dpri_whlist(struct au_nhash *whlist)
7045 + unsigned long ul, n;
7046 + struct hlist_head *head;
7047 + struct au_vdir_wh *pos;
7049 + n = whlist->nh_num;
7050 + head = whlist->nh_head;
7051 + for (ul = 0; ul < n; ul++) {
7052 + hlist_for_each_entry(pos, head, wh_hash)
7053 + dpri("b%d, %.*s, %d\n",
7055 + pos->wh_str.len, pos->wh_str.name,
7061 +void au_dpri_vdir(struct au_vdir *vdir)
7064 + union au_vdir_deblk_p p;
7067 + if (!vdir || IS_ERR(vdir)) {
7068 + dpri("err %ld\n", PTR_ERR(vdir));
7072 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
7073 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7074 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7075 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7076 + p.deblk = vdir->vd_deblk[ul];
7078 + dpri("[%lu]: %p\n", ul, o);
7082 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7083 + struct dentry *wh)
7088 + if (!inode || IS_ERR(inode)) {
7089 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7093 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7094 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7095 + && sizeof(inode->i_blocks) != sizeof(u64));
7097 + n = (void *)wh->d_name.name;
7098 + l = wh->d_name.len;
7101 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7102 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7104 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7105 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7106 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7107 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7108 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7109 + inode->i_state, inode->i_flags, inode->i_version,
7110 + inode->i_generation,
7111 + l ? ", wh " : "", l, n);
7115 +void au_dpri_inode(struct inode *inode)
7117 + struct au_iinfo *iinfo;
7118 + struct au_hinode *hi;
7119 + aufs_bindex_t bindex;
7122 + err = do_pri_inode(-1, inode, -1, NULL);
7123 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7126 + iinfo = au_ii(inode);
7127 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7128 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7129 + if (iinfo->ii_btop < 0)
7132 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7133 + hi = au_hinode(iinfo, bindex);
7135 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7139 +void au_dpri_dalias(struct inode *inode)
7143 + spin_lock(&inode->i_lock);
7144 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7145 + au_dpri_dentry(d);
7146 + spin_unlock(&inode->i_lock);
7149 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7151 + struct dentry *wh = NULL;
7153 + struct inode *inode;
7154 + struct au_iinfo *iinfo;
7155 + struct au_hinode *hi;
7157 + if (!dentry || IS_ERR(dentry)) {
7158 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7161 + /* do not call dget_parent() here */
7162 + /* note: access d_xxx without d_lock */
7163 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7164 + bindex, dentry, dentry,
7165 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7166 + au_dcount(dentry), dentry->d_flags,
7167 + d_unhashed(dentry) ? "un" : "");
7170 + if (d_is_positive(dentry))
7171 + inode = d_inode(dentry);
7173 + && au_test_aufs(dentry->d_sb)
7175 + && !au_is_bad_inode(inode)) {
7176 + iinfo = au_ii(inode);
7177 + hi = au_hinode(iinfo, bindex);
7179 + wh = hi->hi_whdentry;
7181 + do_pri_inode(bindex, inode, hn, wh);
7185 +void au_dpri_dentry(struct dentry *dentry)
7187 + struct au_dinfo *dinfo;
7188 + aufs_bindex_t bindex;
7191 + err = do_pri_dentry(-1, dentry);
7192 + if (err || !au_test_aufs(dentry->d_sb))
7195 + dinfo = au_di(dentry);
7198 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7199 + dinfo->di_btop, dinfo->di_bbot,
7200 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7201 + dinfo->di_tmpfile);
7202 + if (dinfo->di_btop < 0)
7204 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7205 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7208 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7212 + if (!file || IS_ERR(file)) {
7213 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7218 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7219 + && au_test_aufs(file->f_path.dentry->d_sb)
7221 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7222 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7223 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7224 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7225 + file->f_version, file->f_pos, a);
7226 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7227 + do_pri_dentry(bindex, file->f_path.dentry);
7231 +void au_dpri_file(struct file *file)
7233 + struct au_finfo *finfo;
7234 + struct au_fidir *fidir;
7235 + struct au_hfile *hfile;
7236 + aufs_bindex_t bindex;
7239 + err = do_pri_file(-1, file);
7241 + || IS_ERR_OR_NULL(file->f_path.dentry)
7242 + || !au_test_aufs(file->f_path.dentry->d_sb))
7245 + finfo = au_fi(file);
7248 + if (finfo->fi_btop < 0)
7250 + fidir = finfo->fi_hdir;
7252 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7254 + for (bindex = finfo->fi_btop;
7255 + bindex >= 0 && bindex <= fidir->fd_bbot;
7257 + hfile = fidir->fd_hfile + bindex;
7258 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7262 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7264 + struct vfsmount *mnt;
7265 + struct super_block *sb;
7267 + if (!br || IS_ERR(br))
7269 + mnt = au_br_mnt(br);
7270 + if (!mnt || IS_ERR(mnt))
7273 + if (!sb || IS_ERR(sb))
7276 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7277 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7279 + bindex, br->br_perm, br->br_id, au_br_count(br),
7280 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7281 + sb->s_flags, sb->s_count,
7282 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7286 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7290 +void au_dpri_sb(struct super_block *sb)
7292 + struct au_sbinfo *sbinfo;
7293 + aufs_bindex_t bindex;
7295 + /* to reuduce stack size */
7297 + struct vfsmount mnt;
7298 + struct au_branch fake;
7301 + /* this function can be called from magic sysrq */
7302 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7303 + if (unlikely(!a)) {
7304 + dpri("no memory\n");
7308 + a->mnt.mnt_sb = sb;
7309 + a->fake.br_path.mnt = &a->mnt;
7310 + au_br_count_init(&a->fake);
7311 + err = do_pri_br(-1, &a->fake);
7312 + au_br_count_fin(&a->fake);
7314 + dpri("dev 0x%x\n", sb->s_dev);
7315 + if (err || !au_test_aufs(sb))
7318 + sbinfo = au_sbi(sb);
7321 + dpri("nw %lld, gen %u, kobj %d\n",
7322 + percpu_counter_sum(&sbinfo->si_nowait.nw_len),
7323 + sbinfo->si_generation,
7324 + atomic_read(&sbinfo->si_kobj.kref.refcount));
7325 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7326 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7329 +/* ---------------------------------------------------------------------- */
7331 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7333 + struct inode *h_inode, *inode = d_inode(dentry);
7334 + struct dentry *h_dentry;
7335 + aufs_bindex_t bindex, bbot, bi;
7337 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7340 + bbot = au_dbbot(dentry);
7341 + bi = au_ibbot(inode);
7344 + bindex = au_dbtop(dentry);
7345 + bi = au_ibtop(inode);
7349 + for (; bindex <= bbot; bindex++) {
7350 + h_dentry = au_h_dptr(dentry, bindex);
7353 + h_inode = au_h_iptr(inode, bindex);
7354 + if (unlikely(h_inode != d_inode(h_dentry))) {
7356 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7357 + AuDbgDentry(dentry);
7358 + AuDbgInode(inode);
7365 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7368 + struct au_dcsub_pages dpages;
7369 + struct au_dpage *dpage;
7370 + struct dentry **dentries;
7372 + err = au_dpages_init(&dpages, GFP_NOFS);
7374 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7376 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7377 + dpage = dpages.dpages + i;
7378 + dentries = dpage->dentries;
7379 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7380 + AuDebugOn(au_digen_test(dentries[j], sigen));
7382 + au_dpages_free(&dpages);
7385 +void au_dbg_verify_kthread(void)
7387 + if (au_wkq_test()) {
7390 + * It may be recursive, but udba=notify between two aufs mounts,
7391 + * where a single ro branch is shared, is not a problem.
7397 +/* ---------------------------------------------------------------------- */
7399 +int __init au_debug_init(void)
7401 + aufs_bindex_t bindex;
7402 + struct au_vdir_destr destr;
7405 + AuDebugOn(bindex >= 0);
7408 + AuDebugOn(destr.len < NAME_MAX);
7410 +#ifdef CONFIG_4KSTACKS
7411 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7416 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7417 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7418 +++ linux/fs/aufs/debug.h 2016-07-25 19:05:34.811159821 +0200
7421 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7423 + * This program, aufs is free software; you can redistribute it and/or modify
7424 + * it under the terms of the GNU General Public License as published by
7425 + * the Free Software Foundation; either version 2 of the License, or
7426 + * (at your option) any later version.
7428 + * This program is distributed in the hope that it will be useful,
7429 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7430 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7431 + * GNU General Public License for more details.
7433 + * You should have received a copy of the GNU General Public License
7434 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7438 + * debug print functions
7441 +#ifndef __AUFS_DEBUG_H__
7442 +#define __AUFS_DEBUG_H__
7446 +#include <linux/atomic.h>
7447 +#include <linux/module.h>
7448 +#include <linux/kallsyms.h>
7449 +#include <linux/sysrq.h>
7451 +#ifdef CONFIG_AUFS_DEBUG
7452 +#define AuDebugOn(a) BUG_ON(a)
7454 +/* module parameter */
7455 +extern atomic_t aufs_debug;
7456 +static inline void au_debug_on(void)
7458 + atomic_inc(&aufs_debug);
7460 +static inline void au_debug_off(void)
7462 + atomic_dec_if_positive(&aufs_debug);
7465 +static inline int au_debug_test(void)
7467 + return atomic_read(&aufs_debug) > 0;
7470 +#define AuDebugOn(a) do {} while (0)
7471 +AuStubVoid(au_debug_on, void)
7472 +AuStubVoid(au_debug_off, void)
7473 +AuStubInt0(au_debug_test, void)
7474 +#endif /* CONFIG_AUFS_DEBUG */
7476 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7478 +/* ---------------------------------------------------------------------- */
7482 +#define AuDbg(fmt, ...) do { \
7483 + if (au_debug_test()) \
7484 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7486 +#define AuLabel(l) AuDbg(#l "\n")
7487 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7488 +#define AuWarn1(fmt, ...) do { \
7489 + static unsigned char _c; \
7491 + pr_warn(fmt, ##__VA_ARGS__); \
7494 +#define AuErr1(fmt, ...) do { \
7495 + static unsigned char _c; \
7497 + pr_err(fmt, ##__VA_ARGS__); \
7500 +#define AuIOErr1(fmt, ...) do { \
7501 + static unsigned char _c; \
7503 + AuIOErr(fmt, ##__VA_ARGS__); \
7506 +#define AuUnsupportMsg "This operation is not supported." \
7507 + " Please report this application to aufs-users ML."
7508 +#define AuUnsupport(fmt, ...) do { \
7509 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7513 +#define AuTraceErr(e) do { \
7514 + if (unlikely((e) < 0)) \
7515 + AuDbg("err %d\n", (int)(e)); \
7518 +#define AuTraceErrPtr(p) do { \
7520 + AuDbg("err %ld\n", PTR_ERR(p)); \
7523 +/* dirty macros for debug print, use with "%.*s" and caution */
7524 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7526 +/* ---------------------------------------------------------------------- */
7529 +#ifdef CONFIG_AUFS_DEBUG
7530 +extern struct mutex au_dbg_mtx;
7531 +extern char *au_plevel;
7533 +void au_dpri_whlist(struct au_nhash *whlist);
7535 +void au_dpri_vdir(struct au_vdir *vdir);
7537 +void au_dpri_inode(struct inode *inode);
7538 +void au_dpri_dalias(struct inode *inode);
7539 +void au_dpri_dentry(struct dentry *dentry);
7541 +void au_dpri_file(struct file *filp);
7542 +struct super_block;
7543 +void au_dpri_sb(struct super_block *sb);
7545 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7546 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7547 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7548 +void au_dbg_verify_kthread(void);
7550 +int __init au_debug_init(void);
7552 +#define AuDbgWhlist(w) do { \
7553 + mutex_lock(&au_dbg_mtx); \
7555 + au_dpri_whlist(w); \
7556 + mutex_unlock(&au_dbg_mtx); \
7559 +#define AuDbgVdir(v) do { \
7560 + mutex_lock(&au_dbg_mtx); \
7562 + au_dpri_vdir(v); \
7563 + mutex_unlock(&au_dbg_mtx); \
7566 +#define AuDbgInode(i) do { \
7567 + mutex_lock(&au_dbg_mtx); \
7569 + au_dpri_inode(i); \
7570 + mutex_unlock(&au_dbg_mtx); \
7573 +#define AuDbgDAlias(i) do { \
7574 + mutex_lock(&au_dbg_mtx); \
7576 + au_dpri_dalias(i); \
7577 + mutex_unlock(&au_dbg_mtx); \
7580 +#define AuDbgDentry(d) do { \
7581 + mutex_lock(&au_dbg_mtx); \
7583 + au_dpri_dentry(d); \
7584 + mutex_unlock(&au_dbg_mtx); \
7587 +#define AuDbgFile(f) do { \
7588 + mutex_lock(&au_dbg_mtx); \
7590 + au_dpri_file(f); \
7591 + mutex_unlock(&au_dbg_mtx); \
7594 +#define AuDbgSb(sb) do { \
7595 + mutex_lock(&au_dbg_mtx); \
7596 + AuDbg(#sb "\n"); \
7598 + mutex_unlock(&au_dbg_mtx); \
7601 +#define AuDbgSym(addr) do { \
7602 + char sym[KSYM_SYMBOL_LEN]; \
7603 + sprint_symbol(sym, (unsigned long)addr); \
7604 + AuDbg("%s\n", sym); \
7607 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7608 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7609 +AuStubVoid(au_dbg_verify_kthread, void)
7610 +AuStubInt0(__init au_debug_init, void)
7612 +#define AuDbgWhlist(w) do {} while (0)
7613 +#define AuDbgVdir(v) do {} while (0)
7614 +#define AuDbgInode(i) do {} while (0)
7615 +#define AuDbgDAlias(i) do {} while (0)
7616 +#define AuDbgDentry(d) do {} while (0)
7617 +#define AuDbgFile(f) do {} while (0)
7618 +#define AuDbgSb(sb) do {} while (0)
7619 +#define AuDbgSym(addr) do {} while (0)
7620 +#endif /* CONFIG_AUFS_DEBUG */
7622 +/* ---------------------------------------------------------------------- */
7624 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7625 +int __init au_sysrq_init(void);
7626 +void au_sysrq_fin(void);
7628 +#ifdef CONFIG_HW_CONSOLE
7629 +#define au_dbg_blocked() do { \
7631 + handle_sysrq('w'); \
7634 +AuStubVoid(au_dbg_blocked, void)
7638 +AuStubInt0(__init au_sysrq_init, void)
7639 +AuStubVoid(au_sysrq_fin, void)
7640 +AuStubVoid(au_dbg_blocked, void)
7641 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7643 +#endif /* __KERNEL__ */
7644 +#endif /* __AUFS_DEBUG_H__ */
7645 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7646 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7647 +++ linux/fs/aufs/dentry.c 2016-07-25 19:05:34.811159821 +0200
7650 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7652 + * This program, aufs is free software; you can redistribute it and/or modify
7653 + * it under the terms of the GNU General Public License as published by
7654 + * the Free Software Foundation; either version 2 of the License, or
7655 + * (at your option) any later version.
7657 + * This program is distributed in the hope that it will be useful,
7658 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7659 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7660 + * GNU General Public License for more details.
7662 + * You should have received a copy of the GNU General Public License
7663 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7667 + * lookup and dentry operations
7670 +#include <linux/namei.h>
7673 +struct au_do_lookup_args {
7674 + unsigned int flags;
7679 + * returns positive/negative dentry, NULL or an error.
7680 + * NULL means whiteout-ed or not-found.
7682 +static struct dentry*
7683 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7684 + aufs_bindex_t bindex, struct qstr *wh_name,
7685 + struct au_do_lookup_args *args)
7687 + struct dentry *h_dentry;
7688 + struct inode *h_inode;
7689 + struct au_branch *br;
7690 + int wh_found, opq;
7691 + unsigned char wh_able;
7692 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7693 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7697 + br = au_sbr(dentry->d_sb, bindex);
7698 + wh_able = !!au_br_whable(br->br_perm);
7700 + wh_found = au_wh_test(h_parent, wh_name, /*try_sio*/0);
7701 + h_dentry = ERR_PTR(wh_found);
7704 + if (unlikely(wh_found < 0))
7707 + /* We found a whiteout */
7708 + /* au_set_dbbot(dentry, bindex); */
7709 + au_set_dbwh(dentry, bindex);
7711 + return NULL; /* success */
7715 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7717 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7718 + if (IS_ERR(h_dentry)) {
7719 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7725 + h_inode = d_inode(h_dentry);
7726 + if (d_is_negative(h_dentry)) {
7729 + } else if (wh_found
7730 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7733 + if (au_dbbot(dentry) <= bindex)
7734 + au_set_dbbot(dentry, bindex);
7735 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
7736 + au_set_dbtop(dentry, bindex);
7737 + au_set_h_dptr(dentry, bindex, h_dentry);
7739 + if (!d_is_dir(h_dentry)
7741 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7742 + goto out; /* success */
7744 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
7745 + opq = au_diropq_test(h_dentry);
7746 + inode_unlock(h_inode);
7748 + au_set_dbdiropq(dentry, bindex);
7749 + else if (unlikely(opq < 0)) {
7750 + au_set_h_dptr(dentry, bindex, NULL);
7751 + h_dentry = ERR_PTR(opq);
7762 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7764 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7765 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7771 + * returns the number of lower positive dentries,
7772 + * otherwise an error.
7773 + * can be called at unlinking with @type is zero.
7775 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
7776 + unsigned int flags)
7778 + int npositive, err;
7779 + aufs_bindex_t bindex, btail, bdiropq;
7780 + unsigned char isdir, dirperm1;
7781 + struct qstr whname;
7782 + struct au_do_lookup_args args = {
7785 + const struct qstr *name = &dentry->d_name;
7786 + struct dentry *parent;
7787 + struct super_block *sb;
7789 + sb = dentry->d_sb;
7790 + err = au_test_shwh(sb, name);
7791 + if (unlikely(err))
7794 + err = au_wh_name_alloc(&whname, name);
7795 + if (unlikely(err))
7798 + isdir = !!d_is_dir(dentry);
7799 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7802 + parent = dget_parent(dentry);
7803 + btail = au_dbtaildir(parent);
7804 + for (bindex = btop; bindex <= btail; bindex++) {
7805 + struct dentry *h_parent, *h_dentry;
7806 + struct inode *h_inode, *h_dir;
7808 + h_dentry = au_h_dptr(dentry, bindex);
7810 + if (d_is_positive(h_dentry))
7814 + h_parent = au_h_dptr(parent, bindex);
7815 + if (!h_parent || !d_is_dir(h_parent))
7818 + h_dir = d_inode(h_parent);
7819 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
7820 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7822 + inode_unlock(h_dir);
7823 + err = PTR_ERR(h_dentry);
7824 + if (IS_ERR(h_dentry))
7827 + au_fclr_lkup(args.flags, ALLOW_NEG);
7829 + au_fset_lkup(args.flags, IGNORE_PERM);
7831 + if (au_dbwh(dentry) == bindex)
7835 + if (d_is_negative(h_dentry))
7837 + h_inode = d_inode(h_dentry);
7840 + args.type = h_inode->i_mode & S_IFMT;
7841 + if (args.type != S_IFDIR)
7844 + /* the type of lower may be different */
7845 + bdiropq = au_dbdiropq(dentry);
7846 + if (bdiropq >= 0 && bdiropq <= bindex)
7852 + AuLabel(positive);
7853 + au_update_dbtop(dentry);
7856 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7857 + && au_dbtop(dentry) < 0)) {
7859 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7865 + kfree(whname.name);
7870 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7872 + struct dentry *dentry;
7875 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7876 + dentry = vfsub_lkup_one(name, parent);
7878 + struct vfsub_lkup_one_args args = {
7884 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7885 + if (unlikely(wkq_err))
7886 + dentry = ERR_PTR(wkq_err);
7893 + * lookup @dentry on @bindex which should be negative.
7895 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7898 + struct dentry *parent, *h_parent, *h_dentry;
7899 + struct au_branch *br;
7901 + parent = dget_parent(dentry);
7902 + h_parent = au_h_dptr(parent, bindex);
7903 + br = au_sbr(dentry->d_sb, bindex);
7905 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7907 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7908 + err = PTR_ERR(h_dentry);
7909 + if (IS_ERR(h_dentry))
7911 + if (unlikely(d_is_positive(h_dentry))) {
7913 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7919 + if (bindex < au_dbtop(dentry))
7920 + au_set_dbtop(dentry, bindex);
7921 + if (au_dbbot(dentry) < bindex)
7922 + au_set_dbbot(dentry, bindex);
7923 + au_set_h_dptr(dentry, bindex, h_dentry);
7930 +/* ---------------------------------------------------------------------- */
7932 +/* subset of struct inode */
7934 + unsigned long i_ino;
7935 + /* unsigned int i_nlink; */
7941 + blkcnt_t i_blocks;
7946 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7948 + ia->i_ino = h_inode->i_ino;
7949 + /* ia->i_nlink = h_inode->i_nlink; */
7950 + ia->i_uid = h_inode->i_uid;
7951 + ia->i_gid = h_inode->i_gid;
7952 + ia->i_version = h_inode->i_version;
7954 + ia->i_size = h_inode->i_size;
7955 + ia->i_blocks = h_inode->i_blocks;
7957 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7960 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7962 + return ia->i_ino != h_inode->i_ino
7963 + /* || ia->i_nlink != h_inode->i_nlink */
7964 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7965 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7966 + || ia->i_version != h_inode->i_version
7968 + || ia->i_size != h_inode->i_size
7969 + || ia->i_blocks != h_inode->i_blocks
7971 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7974 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7975 + struct au_branch *br)
7978 + struct au_iattr ia;
7979 + struct inode *h_inode;
7980 + struct dentry *h_d;
7981 + struct super_block *h_sb;
7984 + memset(&ia, -1, sizeof(ia));
7985 + h_sb = h_dentry->d_sb;
7987 + if (d_is_positive(h_dentry)) {
7988 + h_inode = d_inode(h_dentry);
7989 + au_iattr_save(&ia, h_inode);
7990 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
7991 + /* nfs d_revalidate may return 0 for negative dentry */
7992 + /* fuse d_revalidate always return 0 for negative dentry */
7995 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
7996 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
7997 + err = PTR_ERR(h_d);
8002 + if (unlikely(h_d != h_dentry
8003 + || d_inode(h_d) != h_inode
8004 + || (h_inode && au_iattr_test(&ia, h_inode))))
8005 + err = au_busy_or_stale();
8013 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8014 + struct dentry *h_parent, struct au_branch *br)
8019 + if (udba == AuOpt_UDBA_REVAL
8020 + && !au_test_fs_remote(h_dentry->d_sb)) {
8022 + err = (d_inode(h_dentry->d_parent) != h_dir);
8023 + } else if (udba != AuOpt_UDBA_NONE)
8024 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8029 +/* ---------------------------------------------------------------------- */
8031 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8034 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8035 + struct au_hdentry tmp, *p, *q;
8036 + struct au_dinfo *dinfo;
8037 + struct super_block *sb;
8039 + DiMustWriteLock(dentry);
8041 + sb = dentry->d_sb;
8042 + dinfo = au_di(dentry);
8043 + bbot = dinfo->di_bbot;
8044 + bwh = dinfo->di_bwh;
8045 + bdiropq = dinfo->di_bdiropq;
8046 + bindex = dinfo->di_btop;
8047 + p = au_hdentry(dinfo, bindex);
8048 + for (; bindex <= bbot; bindex++, p++) {
8049 + if (!p->hd_dentry)
8052 + new_bindex = au_br_index(sb, p->hd_id);
8053 + if (new_bindex == bindex)
8056 + if (dinfo->di_bwh == bindex)
8058 + if (dinfo->di_bdiropq == bindex)
8059 + bdiropq = new_bindex;
8060 + if (new_bindex < 0) {
8062 + p->hd_dentry = NULL;
8066 + /* swap two lower dentries, and loop again */
8067 + q = au_hdentry(dinfo, new_bindex);
8071 + if (tmp.hd_dentry) {
8077 + dinfo->di_bwh = -1;
8078 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8079 + dinfo->di_bwh = bwh;
8081 + dinfo->di_bdiropq = -1;
8083 + && bdiropq <= au_sbbot(sb)
8084 + && au_sbr_whable(sb, bdiropq))
8085 + dinfo->di_bdiropq = bdiropq;
8088 + dinfo->di_btop = -1;
8089 + dinfo->di_bbot = -1;
8090 + bbot = au_dbbot(parent);
8092 + p = au_hdentry(dinfo, bindex);
8093 + for (; bindex <= bbot; bindex++, p++)
8094 + if (p->hd_dentry) {
8095 + dinfo->di_btop = bindex;
8099 + if (dinfo->di_btop >= 0) {
8101 + p = au_hdentry(dinfo, bindex);
8102 + for (; bindex >= 0; bindex--, p--)
8103 + if (p->hd_dentry) {
8104 + dinfo->di_bbot = bindex;
8113 +static void au_do_hide(struct dentry *dentry)
8115 + struct inode *inode;
8117 + if (d_really_is_positive(dentry)) {
8118 + inode = d_inode(dentry);
8119 + if (!d_is_dir(dentry)) {
8120 + if (inode->i_nlink && !d_unhashed(dentry))
8121 + drop_nlink(inode);
8123 + clear_nlink(inode);
8124 + /* stop next lookup */
8125 + inode->i_flags |= S_DEAD;
8127 + smp_mb(); /* necessary? */
8132 +static int au_hide_children(struct dentry *parent)
8134 + int err, i, j, ndentry;
8135 + struct au_dcsub_pages dpages;
8136 + struct au_dpage *dpage;
8137 + struct dentry *dentry;
8139 + err = au_dpages_init(&dpages, GFP_NOFS);
8140 + if (unlikely(err))
8142 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8143 + if (unlikely(err))
8146 + /* in reverse order */
8147 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8148 + dpage = dpages.dpages + i;
8149 + ndentry = dpage->ndentry;
8150 + for (j = ndentry - 1; j >= 0; j--) {
8151 + dentry = dpage->dentries[j];
8152 + if (dentry != parent)
8153 + au_do_hide(dentry);
8158 + au_dpages_free(&dpages);
8163 +static void au_hide(struct dentry *dentry)
8167 + AuDbgDentry(dentry);
8168 + if (d_is_dir(dentry)) {
8169 + /* shrink_dcache_parent(dentry); */
8170 + err = au_hide_children(dentry);
8171 + if (unlikely(err))
8172 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8175 + au_do_hide(dentry);
8179 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8181 + * a dirty branch is added
8182 + * - on the top of layers
8183 + * - in the middle of layers
8184 + * - to the bottom of layers
8186 + * on the added branch there exists
8189 + * - a same named entry
8191 + * * negative --> positive
8192 + * * positive --> positive
8193 + * - type is unchanged
8194 + * - type is changed
8196 + * * negative --> negative
8197 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8200 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8201 + struct au_dinfo *tmp)
8204 + aufs_bindex_t bindex, bbot;
8206 + struct dentry *dentry;
8207 + struct inode *inode;
8209 + } orig_h, tmp_h = {
8212 + struct au_hdentry *hd;
8213 + struct inode *inode, *h_inode;
8214 + struct dentry *h_dentry;
8217 + AuDebugOn(dinfo->di_btop < 0);
8219 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8220 + orig_h.inode = NULL;
8221 + if (d_is_positive(orig_h.dentry)) {
8222 + orig_h.inode = d_inode(orig_h.dentry);
8223 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8225 + if (tmp->di_btop >= 0) {
8226 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8227 + if (d_is_positive(tmp_h.dentry)) {
8228 + tmp_h.inode = d_inode(tmp_h.dentry);
8229 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8234 + if (d_really_is_positive(dentry))
8235 + inode = d_inode(dentry);
8236 + if (!orig_h.inode) {
8237 + AuDbg("nagative originally\n");
8243 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8244 + AuDebugOn(dinfo->di_bdiropq != -1);
8246 + if (!tmp_h.inode) {
8247 + AuDbg("negative --> negative\n");
8248 + /* should have only one negative lower */
8249 + if (tmp->di_btop >= 0
8250 + && tmp->di_btop < dinfo->di_btop) {
8251 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8252 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8253 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8254 + au_di_cp(dinfo, tmp);
8255 + hd = au_hdentry(tmp, tmp->di_btop);
8256 + au_set_h_dptr(dentry, tmp->di_btop,
8257 + dget(hd->hd_dentry));
8259 + au_dbg_verify_dinode(dentry);
8261 + AuDbg("negative --> positive\n");
8263 + * similar to the behaviour of creating with bypassing
8265 + * unhash it in order to force an error in the
8266 + * succeeding create operation.
8267 + * we should not set S_DEAD here.
8270 + /* au_di_swap(tmp, dinfo); */
8271 + au_dbg_verify_dinode(dentry);
8274 + AuDbg("positive originally\n");
8275 + /* inode may be NULL */
8276 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8277 + if (!tmp_h.inode) {
8278 + AuDbg("positive --> negative\n");
8279 + /* or bypassing aufs */
8281 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8282 + dinfo->di_bwh = tmp->di_bwh;
8284 + err = au_refresh_hinode_self(inode);
8285 + au_dbg_verify_dinode(dentry);
8286 + } else if (orig_h.mode == tmp_h.mode) {
8287 + AuDbg("positive --> positive, same type\n");
8288 + if (!S_ISDIR(orig_h.mode)
8289 + && dinfo->di_btop > tmp->di_btop) {
8291 + * similar to the behaviour of removing and
8296 + err = au_refresh_hinode_self(inode);
8297 + au_dbg_verify_dinode(dentry);
8299 + /* fill empty slots */
8300 + if (dinfo->di_btop > tmp->di_btop)
8301 + dinfo->di_btop = tmp->di_btop;
8302 + if (dinfo->di_bbot < tmp->di_bbot)
8303 + dinfo->di_bbot = tmp->di_bbot;
8304 + dinfo->di_bwh = tmp->di_bwh;
8305 + dinfo->di_bdiropq = tmp->di_bdiropq;
8306 + bbot = dinfo->di_bbot;
8307 + bindex = tmp->di_btop;
8308 + hd = au_hdentry(tmp, bindex);
8309 + for (; bindex <= bbot; bindex++, hd++) {
8310 + if (au_h_dptr(dentry, bindex))
8312 + h_dentry = hd->hd_dentry;
8315 + AuDebugOn(d_is_negative(h_dentry));
8316 + h_inode = d_inode(h_dentry);
8317 + AuDebugOn(orig_h.mode
8318 + != (h_inode->i_mode
8320 + au_set_h_dptr(dentry, bindex,
8324 + err = au_refresh_hinode(inode, dentry);
8325 + au_dbg_verify_dinode(dentry);
8328 + AuDbg("positive --> positive, different type\n");
8329 + /* similar to the behaviour of removing and creating */
8332 + err = au_refresh_hinode_self(inode);
8333 + au_dbg_verify_dinode(dentry);
8341 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8343 + const struct dentry_operations *dop
8344 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8345 + static const unsigned int mask
8346 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8348 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8350 + if (dentry->d_op == dop)
8353 + AuDbg("%pd\n", dentry);
8354 + spin_lock(&dentry->d_lock);
8355 + if (dop == &aufs_dop)
8356 + dentry->d_flags |= mask;
8358 + dentry->d_flags &= ~mask;
8359 + dentry->d_op = dop;
8360 + spin_unlock(&dentry->d_lock);
8363 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8366 + unsigned int sigen;
8367 + struct au_dinfo *dinfo, *tmp;
8368 + struct super_block *sb;
8369 + struct inode *inode;
8371 + DiMustWriteLock(dentry);
8372 + AuDebugOn(IS_ROOT(dentry));
8373 + AuDebugOn(d_really_is_negative(parent));
8375 + sb = dentry->d_sb;
8376 + sigen = au_sigen(sb);
8377 + err = au_digen_test(parent, sigen);
8378 + if (unlikely(err))
8381 + dinfo = au_di(dentry);
8382 + err = au_di_realloc(dinfo, au_sbbot(sb) + 1);
8383 + if (unlikely(err))
8385 + ebrange = au_dbrange_test(dentry);
8387 + ebrange = au_do_refresh_hdentry(dentry, parent);
8389 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8390 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8391 + if (d_really_is_positive(dentry)) {
8392 + inode = d_inode(dentry);
8393 + err = au_refresh_hinode_self(inode);
8395 + au_dbg_verify_dinode(dentry);
8397 + goto out_dgen; /* success */
8401 + /* temporary dinfo */
8402 + AuDbgDentry(dentry);
8404 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8405 + if (unlikely(!tmp))
8407 + au_di_swap(tmp, dinfo);
8408 + /* returns the number of positive dentries */
8410 + * if current working dir is removed, it returns an error.
8411 + * but the dentry is legal.
8413 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8414 + AuDbgDentry(dentry);
8415 + au_di_swap(tmp, dinfo);
8416 + if (err == -ENOENT)
8419 + /* compare/refresh by dinfo */
8420 + AuDbgDentry(dentry);
8421 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8422 + au_dbg_verify_dinode(dentry);
8425 + au_rw_write_unlock(&tmp->di_rwsem);
8427 + if (unlikely(err))
8431 + au_update_digen(dentry);
8433 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8434 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8435 + AuDbgDentry(dentry);
8441 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8442 + struct dentry *dentry, aufs_bindex_t bindex)
8447 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8450 + AuDbg("b%d\n", bindex);
8452 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8453 + * due to whiteout and branch permission.
8455 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8456 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8457 + /* it may return tri-state */
8458 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8460 + if (unlikely(valid < 0))
8470 +/* todo: remove this */
8471 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8472 + unsigned int flags, int do_udba)
8475 + umode_t mode, h_mode;
8476 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8477 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8478 + struct inode *h_inode, *h_cached_inode;
8479 + struct dentry *h_dentry;
8480 + struct qstr *name, *h_name;
8487 + unhashed = !!d_unhashed(dentry);
8488 + is_root = !!IS_ROOT(dentry);
8489 + name = &dentry->d_name;
8490 + tmpfile = au_di(dentry)->di_tmpfile;
8493 + * Theoretically, REVAL test should be unnecessary in case of
8495 + * But {fs,i}notify doesn't fire some necessary events,
8496 + * IN_ATTRIB for atime/nlink/pageio
8497 + * Let's do REVAL test too.
8499 + if (do_udba && inode) {
8500 + mode = (inode->i_mode & S_IFMT);
8501 + plus = (inode->i_nlink > 0);
8502 + ibs = au_ibtop(inode);
8503 + ibe = au_ibbot(inode);
8506 + btop = au_dbtop(dentry);
8508 + if (inode && S_ISDIR(inode->i_mode))
8509 + btail = au_dbtaildir(dentry);
8510 + for (bindex = btop; bindex <= btail; bindex++) {
8511 + h_dentry = au_h_dptr(dentry, bindex);
8515 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8516 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8517 + spin_lock(&h_dentry->d_lock);
8518 + h_name = &h_dentry->d_name;
8519 + if (unlikely(do_udba
8522 + && (unhashed != !!d_unhashed(h_dentry)
8524 + && !au_qstreq(name, h_name))
8527 + && !(flags & LOOKUP_OPEN)
8528 + && (h_dentry->d_flags
8529 + & DCACHE_NFSFS_RENAMED)))
8533 + h_unhashed = d_unhashed(h_dentry);
8534 + spin_unlock(&h_dentry->d_lock);
8535 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8536 + unhashed, h_unhashed, dentry, h_dentry);
8539 + spin_unlock(&h_dentry->d_lock);
8541 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8542 + if (unlikely(err))
8543 + /* do not goto err, to keep the errno */
8546 + /* todo: plink too? */
8551 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8555 + if (d_is_positive(h_dentry))
8556 + h_inode = d_inode(h_dentry);
8559 + h_cached_inode = h_inode;
8561 + h_mode = (h_inode->i_mode & S_IFMT);
8562 + h_plus = (h_inode->i_nlink > 0);
8564 + if (inode && ibs <= bindex && bindex <= ibe)
8565 + h_cached_inode = au_h_iptr(inode, bindex);
8568 + if (unlikely(plus != h_plus && !tmpfile))
8571 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8573 + && !IS_ROOT(h_dentry)
8574 + && unhashed != d_unhashed(h_dentry)))
8577 + if (unlikely(mode != h_mode
8578 + || h_cached_inode != h_inode))
8591 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8592 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8595 + struct dentry *parent;
8597 + if (!au_digen_test(dentry, sigen))
8600 + parent = dget_parent(dentry);
8601 + di_read_lock_parent(parent, AuLock_IR);
8602 + AuDebugOn(au_digen_test(parent, sigen));
8603 + au_dbg_verify_gen(parent, sigen);
8604 + err = au_refresh_dentry(dentry, parent);
8605 + di_read_unlock(parent, AuLock_IR);
8611 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8614 + struct dentry *d, *parent;
8616 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8617 + return simple_reval_dpath(dentry, sigen);
8619 + /* slow loop, keep it simple and stupid */
8620 + /* cf: au_cpup_dirs() */
8623 + while (au_digen_test(dentry, sigen)) {
8627 + parent = dget_parent(d);
8628 + if (!au_digen_test(parent, sigen))
8634 + di_write_lock_child2(d);
8636 + /* someone might update our dentry while we were sleeping */
8637 + if (au_digen_test(d, sigen)) {
8639 + * todo: consolidate with simple_reval_dpath(),
8640 + * do_refresh() and au_reval_for_attr().
8642 + di_read_lock_parent(parent, AuLock_IR);
8643 + err = au_refresh_dentry(d, parent);
8644 + di_read_unlock(parent, AuLock_IR);
8648 + di_write_unlock(d);
8650 + if (unlikely(err))
8658 + * if valid returns 1, otherwise 0.
8660 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8663 + unsigned int sigen;
8664 + unsigned char do_udba;
8665 + struct super_block *sb;
8666 + struct inode *inode;
8668 + /* todo: support rcu-walk? */
8669 + if (flags & LOOKUP_RCU)
8673 + if (unlikely(!au_di(dentry)))
8677 + sb = dentry->d_sb;
8680 + * i_mutex of parent dir may be held,
8681 + * but we should not return 'invalid' due to busy.
8683 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8684 + if (unlikely(err)) {
8690 + if (d_really_is_positive(dentry))
8691 + inode = d_inode(dentry);
8692 + if (unlikely(inode && au_is_bad_inode(inode))) {
8697 + if (unlikely(au_dbrange_test(dentry))) {
8703 + sigen = au_sigen(sb);
8704 + if (au_digen_test(dentry, sigen)) {
8705 + AuDebugOn(IS_ROOT(dentry));
8706 + err = au_reval_dpath(dentry, sigen);
8707 + if (unlikely(err)) {
8712 + di_downgrade_lock(dentry, AuLock_IR);
8715 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8717 + && !(inode->i_state && I_LINKABLE)
8718 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
8723 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8724 + if (do_udba && inode) {
8725 + aufs_bindex_t btop = au_ibtop(inode);
8726 + struct inode *h_inode;
8729 + h_inode = au_h_iptr(inode, btop);
8730 + if (h_inode && au_test_higen(inode, h_inode)) {
8737 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8738 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
8740 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8746 + di_downgrade_lock(dentry, AuLock_IR);
8748 + aufs_read_unlock(dentry, AuLock_IR);
8753 + AuDbg("%pd invalid, %d\n", dentry, valid);
8759 +static void aufs_d_release(struct dentry *dentry)
8761 + if (au_di(dentry)) {
8762 + au_di_fin(dentry);
8763 + au_hn_di_reinit(dentry);
8767 +const struct dentry_operations aufs_dop = {
8768 + .d_revalidate = aufs_d_revalidate,
8769 + .d_weak_revalidate = aufs_d_revalidate,
8770 + .d_release = aufs_d_release
8773 +/* aufs_dop without d_revalidate */
8774 +const struct dentry_operations aufs_dop_noreval = {
8775 + .d_release = aufs_d_release
8777 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8778 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8779 +++ linux/fs/aufs/dentry.h 2016-07-25 19:05:34.811159821 +0200
8782 + * Copyright (C) 2005-2016 Junjiro R. Okajima
8784 + * This program, aufs is free software; you can redistribute it and/or modify
8785 + * it under the terms of the GNU General Public License as published by
8786 + * the Free Software Foundation; either version 2 of the License, or
8787 + * (at your option) any later version.
8789 + * This program is distributed in the hope that it will be useful,
8790 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8791 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8792 + * GNU General Public License for more details.
8794 + * You should have received a copy of the GNU General Public License
8795 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8799 + * lookup and dentry operations
8802 +#ifndef __AUFS_DENTRY_H__
8803 +#define __AUFS_DENTRY_H__
8807 +#include <linux/dcache.h>
8810 +struct au_hdentry {
8811 + struct dentry *hd_dentry;
8812 + aufs_bindex_t hd_id;
8816 + atomic_t di_generation;
8818 + struct au_rwsem di_rwsem;
8819 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
8820 + unsigned char di_tmpfile; /* to allow the different name */
8821 + struct au_hdentry *di_hdentry;
8822 +} ____cacheline_aligned_in_smp;
8824 +/* ---------------------------------------------------------------------- */
8826 +/* flags for au_lkup_dentry() */
8827 +#define AuLkup_ALLOW_NEG 1
8828 +#define AuLkup_IGNORE_PERM (1 << 1)
8829 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
8830 +#define au_fset_lkup(flags, name) \
8831 + do { (flags) |= AuLkup_##name; } while (0)
8832 +#define au_fclr_lkup(flags, name) \
8833 + do { (flags) &= ~AuLkup_##name; } while (0)
8835 +/* ---------------------------------------------------------------------- */
8838 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
8840 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8841 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8842 + struct dentry *h_parent, struct au_branch *br);
8844 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8845 + unsigned int flags);
8846 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8847 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8848 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8849 +void au_refresh_dop(struct dentry *dentry, int force_reval);
8852 +void au_di_init_once(void *_di);
8853 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8854 +void au_di_free(struct au_dinfo *dinfo);
8855 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8856 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8857 +int au_di_init(struct dentry *dentry);
8858 +void au_di_fin(struct dentry *dentry);
8859 +int au_di_realloc(struct au_dinfo *dinfo, int nbr);
8861 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8862 +void di_read_unlock(struct dentry *d, int flags);
8863 +void di_downgrade_lock(struct dentry *d, int flags);
8864 +void di_write_lock(struct dentry *d, unsigned int lsc);
8865 +void di_write_unlock(struct dentry *d);
8866 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8867 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8868 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8870 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8871 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8872 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8873 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8875 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8876 + struct dentry *h_dentry);
8877 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8878 +int au_dbrange_test(struct dentry *dentry);
8879 +void au_update_digen(struct dentry *dentry);
8880 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8881 +void au_update_dbtop(struct dentry *dentry);
8882 +void au_update_dbbot(struct dentry *dentry);
8883 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8885 +/* ---------------------------------------------------------------------- */
8887 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8889 + return dentry->d_fsdata;
8892 +/* ---------------------------------------------------------------------- */
8894 +/* lock subclass for dinfo */
8896 + AuLsc_DI_CHILD, /* child first */
8897 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8898 + AuLsc_DI_CHILD3, /* copyup dirs */
8902 + AuLsc_DI_TMP /* temp for replacing dinfo */
8906 + * di_read_lock_child, di_write_lock_child,
8907 + * di_read_lock_child2, di_write_lock_child2,
8908 + * di_read_lock_child3, di_write_lock_child3,
8909 + * di_read_lock_parent, di_write_lock_parent,
8910 + * di_read_lock_parent2, di_write_lock_parent2,
8911 + * di_read_lock_parent3, di_write_lock_parent3,
8913 +#define AuReadLockFunc(name, lsc) \
8914 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8915 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8917 +#define AuWriteLockFunc(name, lsc) \
8918 +static inline void di_write_lock_##name(struct dentry *d) \
8919 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8921 +#define AuRWLockFuncs(name, lsc) \
8922 + AuReadLockFunc(name, lsc) \
8923 + AuWriteLockFunc(name, lsc)
8925 +AuRWLockFuncs(child, CHILD);
8926 +AuRWLockFuncs(child2, CHILD2);
8927 +AuRWLockFuncs(child3, CHILD3);
8928 +AuRWLockFuncs(parent, PARENT);
8929 +AuRWLockFuncs(parent2, PARENT2);
8930 +AuRWLockFuncs(parent3, PARENT3);
8932 +#undef AuReadLockFunc
8933 +#undef AuWriteLockFunc
8934 +#undef AuRWLockFuncs
8936 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8937 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8938 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8940 +/* ---------------------------------------------------------------------- */
8942 +/* todo: memory barrier? */
8943 +static inline unsigned int au_digen(struct dentry *d)
8945 + return atomic_read(&au_di(d)->di_generation);
8948 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8950 + hdentry->hd_dentry = NULL;
8953 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
8954 + aufs_bindex_t bindex)
8956 + return di->di_hdentry + bindex;
8959 +static inline void au_hdput(struct au_hdentry *hd)
8962 + dput(hd->hd_dentry);
8965 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
8967 + DiMustAnyLock(dentry);
8968 + return au_di(dentry)->di_btop;
8971 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
8973 + DiMustAnyLock(dentry);
8974 + return au_di(dentry)->di_bbot;
8977 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
8979 + DiMustAnyLock(dentry);
8980 + return au_di(dentry)->di_bwh;
8983 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
8985 + DiMustAnyLock(dentry);
8986 + return au_di(dentry)->di_bdiropq;
8989 +/* todo: hard/soft set? */
8990 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
8992 + DiMustWriteLock(dentry);
8993 + au_di(dentry)->di_btop = bindex;
8996 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
8998 + DiMustWriteLock(dentry);
8999 + au_di(dentry)->di_bbot = bindex;
9002 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9004 + DiMustWriteLock(dentry);
9005 + /* dbwh can be outside of btop - bbot range */
9006 + au_di(dentry)->di_bwh = bindex;
9009 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9011 + DiMustWriteLock(dentry);
9012 + au_di(dentry)->di_bdiropq = bindex;
9015 +/* ---------------------------------------------------------------------- */
9017 +#ifdef CONFIG_AUFS_HNOTIFY
9018 +static inline void au_digen_dec(struct dentry *d)
9020 + atomic_dec(&au_di(d)->di_generation);
9023 +static inline void au_hn_di_reinit(struct dentry *dentry)
9025 + dentry->d_fsdata = NULL;
9028 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9029 +#endif /* CONFIG_AUFS_HNOTIFY */
9031 +#endif /* __KERNEL__ */
9032 +#endif /* __AUFS_DENTRY_H__ */
9033 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9034 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9035 +++ linux/fs/aufs/dinfo.c 2016-07-25 19:05:34.811159821 +0200
9038 + * Copyright (C) 2005-2016 Junjiro R. Okajima
9040 + * This program, aufs is free software; you can redistribute it and/or modify
9041 + * it under the terms of the GNU General Public License as published by
9042 + * the Free Software Foundation; either version 2 of the License, or
9043 + * (at your option) any later version.
9045 + * This program is distributed in the hope that it will be useful,
9046 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9047 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9048 + * GNU General Public License for more details.
9050 + * You should have received a copy of the GNU General Public License
9051 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9055 + * dentry private data
9060 +void au_di_init_once(void *_dinfo)
9062 + struct au_dinfo *dinfo = _dinfo;
9064 + au_rw_init(&dinfo->di_rwsem);
9067 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9069 + struct au_dinfo *dinfo;
9072 + dinfo = au_cache_alloc_dinfo();
9073 + if (unlikely(!dinfo))
9076 + nbr = au_sbbot(sb) + 1;
9079 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9080 + if (dinfo->di_hdentry) {
9081 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9082 + dinfo->di_btop = -1;
9083 + dinfo->di_bbot = -1;
9084 + dinfo->di_bwh = -1;
9085 + dinfo->di_bdiropq = -1;
9086 + dinfo->di_tmpfile = 0;
9087 + for (i = 0; i < nbr; i++)
9088 + dinfo->di_hdentry[i].hd_id = -1;
9092 + au_cache_free_dinfo(dinfo);
9099 +void au_di_free(struct au_dinfo *dinfo)
9101 + struct au_hdentry *p;
9102 + aufs_bindex_t bbot, bindex;
9104 + /* dentry may not be revalidated */
9105 + bindex = dinfo->di_btop;
9106 + if (bindex >= 0) {
9107 + bbot = dinfo->di_bbot;
9108 + p = au_hdentry(dinfo, bindex);
9109 + while (bindex++ <= bbot)
9112 + kfree(dinfo->di_hdentry);
9113 + au_cache_free_dinfo(dinfo);
9116 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9118 + struct au_hdentry *p;
9121 + AuRwMustWriteLock(&a->di_rwsem);
9122 + AuRwMustWriteLock(&b->di_rwsem);
9124 +#define DiSwap(v, name) \
9126 + v = a->di_##name; \
9127 + a->di_##name = b->di_##name; \
9128 + b->di_##name = v; \
9131 + DiSwap(p, hdentry);
9135 + DiSwap(bi, bdiropq);
9141 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9143 + AuRwMustWriteLock(&dst->di_rwsem);
9144 + AuRwMustWriteLock(&src->di_rwsem);
9146 + dst->di_btop = src->di_btop;
9147 + dst->di_bbot = src->di_bbot;
9148 + dst->di_bwh = src->di_bwh;
9149 + dst->di_bdiropq = src->di_bdiropq;
9153 +int au_di_init(struct dentry *dentry)
9156 + struct super_block *sb;
9157 + struct au_dinfo *dinfo;
9160 + sb = dentry->d_sb;
9161 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9163 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9164 + /* smp_mb(); */ /* atomic_set */
9165 + dentry->d_fsdata = dinfo;
9172 +void au_di_fin(struct dentry *dentry)
9174 + struct au_dinfo *dinfo;
9176 + dinfo = au_di(dentry);
9177 + AuRwDestroy(&dinfo->di_rwsem);
9178 + au_di_free(dinfo);
9181 +int au_di_realloc(struct au_dinfo *dinfo, int nbr)
9184 + struct au_hdentry *hdp;
9186 + AuRwMustWriteLock(&dinfo->di_rwsem);
9189 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9191 + sz = sizeof(*hdp);
9192 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS);
9194 + dinfo->di_hdentry = hdp;
9201 +/* ---------------------------------------------------------------------- */
9203 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9206 + case AuLsc_DI_CHILD:
9207 + ii_write_lock_child(inode);
9209 + case AuLsc_DI_CHILD2:
9210 + ii_write_lock_child2(inode);
9212 + case AuLsc_DI_CHILD3:
9213 + ii_write_lock_child3(inode);
9215 + case AuLsc_DI_PARENT:
9216 + ii_write_lock_parent(inode);
9218 + case AuLsc_DI_PARENT2:
9219 + ii_write_lock_parent2(inode);
9221 + case AuLsc_DI_PARENT3:
9222 + ii_write_lock_parent3(inode);
9229 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9232 + case AuLsc_DI_CHILD:
9233 + ii_read_lock_child(inode);
9235 + case AuLsc_DI_CHILD2:
9236 + ii_read_lock_child2(inode);
9238 + case AuLsc_DI_CHILD3:
9239 + ii_read_lock_child3(inode);
9241 + case AuLsc_DI_PARENT:
9242 + ii_read_lock_parent(inode);
9244 + case AuLsc_DI_PARENT2:
9245 + ii_read_lock_parent2(inode);
9247 + case AuLsc_DI_PARENT3:
9248 + ii_read_lock_parent3(inode);
9255 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9257 + struct inode *inode;
9259 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9260 + if (d_really_is_positive(d)) {
9261 + inode = d_inode(d);
9262 + if (au_ftest_lock(flags, IW))
9263 + do_ii_write_lock(inode, lsc);
9264 + else if (au_ftest_lock(flags, IR))
9265 + do_ii_read_lock(inode, lsc);
9269 +void di_read_unlock(struct dentry *d, int flags)
9271 + struct inode *inode;
9273 + if (d_really_is_positive(d)) {
9274 + inode = d_inode(d);
9275 + if (au_ftest_lock(flags, IW)) {
9276 + au_dbg_verify_dinode(d);
9277 + ii_write_unlock(inode);
9278 + } else if (au_ftest_lock(flags, IR)) {
9279 + au_dbg_verify_dinode(d);
9280 + ii_read_unlock(inode);
9283 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9286 +void di_downgrade_lock(struct dentry *d, int flags)
9288 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9289 + ii_downgrade_lock(d_inode(d));
9290 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9293 +void di_write_lock(struct dentry *d, unsigned int lsc)
9295 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9296 + if (d_really_is_positive(d))
9297 + do_ii_write_lock(d_inode(d), lsc);
9300 +void di_write_unlock(struct dentry *d)
9302 + au_dbg_verify_dinode(d);
9303 + if (d_really_is_positive(d))
9304 + ii_write_unlock(d_inode(d));
9305 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9308 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9310 + AuDebugOn(d1 == d2
9311 + || d_inode(d1) == d_inode(d2)
9312 + || d1->d_sb != d2->d_sb);
9314 + if (isdir && au_test_subdir(d1, d2)) {
9315 + di_write_lock_child(d1);
9316 + di_write_lock_child2(d2);
9318 + /* there should be no races */
9319 + di_write_lock_child(d2);
9320 + di_write_lock_child2(d1);
9324 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9326 + AuDebugOn(d1 == d2
9327 + || d_inode(d1) == d_inode(d2)
9328 + || d1->d_sb != d2->d_sb);
9330 + if (isdir && au_test_subdir(d1, d2)) {
9331 + di_write_lock_parent(d1);
9332 + di_write_lock_parent2(d2);
9334 + /* there should be no races */
9335 + di_write_lock_parent(d2);
9336 + di_write_lock_parent2(d1);
9340 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9342 + di_write_unlock(d1);
9343 + if (d_inode(d1) == d_inode(d2))
9344 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9346 + di_write_unlock(d2);
9349 +/* ---------------------------------------------------------------------- */
9351 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9355 + DiMustAnyLock(dentry);
9357 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9359 + AuDebugOn(bindex < 0);
9360 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9361 + AuDebugOn(d && au_dcount(d) <= 0);
9366 + * extended version of au_h_dptr().
9367 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9370 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9372 + struct dentry *h_dentry;
9373 + struct inode *inode, *h_inode;
9375 + AuDebugOn(d_really_is_negative(dentry));
9378 + if (au_dbtop(dentry) <= bindex
9379 + && bindex <= au_dbbot(dentry))
9380 + h_dentry = au_h_dptr(dentry, bindex);
9381 + if (h_dentry && !au_d_linkable(h_dentry)) {
9383 + goto out; /* success */
9386 + inode = d_inode(dentry);
9387 + AuDebugOn(bindex < au_ibtop(inode));
9388 + AuDebugOn(au_ibbot(inode) < bindex);
9389 + h_inode = au_h_iptr(inode, bindex);
9390 + h_dentry = d_find_alias(h_inode);
9392 + if (!IS_ERR(h_dentry)) {
9393 + if (!au_d_linkable(h_dentry))
9394 + goto out; /* success */
9400 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9401 + h_dentry = au_plink_lkup(inode, bindex);
9402 + AuDebugOn(!h_dentry);
9403 + if (!IS_ERR(h_dentry)) {
9404 + if (!au_d_hashed_positive(h_dentry))
9405 + goto out; /* success */
9412 + AuDbgDentry(h_dentry);
9416 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9418 + aufs_bindex_t bbot, bwh;
9420 + bbot = au_dbbot(dentry);
9422 + bwh = au_dbwh(dentry);
9425 + if (0 < bwh && bwh < bbot)
9431 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9433 + aufs_bindex_t bbot, bopq;
9435 + bbot = au_dbtail(dentry);
9437 + bopq = au_dbdiropq(dentry);
9438 + if (0 <= bopq && bopq < bbot)
9444 +/* ---------------------------------------------------------------------- */
9446 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9447 + struct dentry *h_dentry)
9449 + struct au_dinfo *dinfo;
9450 + struct au_hdentry *hd;
9451 + struct au_branch *br;
9453 + DiMustWriteLock(dentry);
9455 + dinfo = au_di(dentry);
9456 + hd = au_hdentry(dinfo, bindex);
9458 + hd->hd_dentry = h_dentry;
9460 + br = au_sbr(dentry->d_sb, bindex);
9461 + hd->hd_id = br->br_id;
9465 +int au_dbrange_test(struct dentry *dentry)
9468 + aufs_bindex_t btop, bbot;
9471 + btop = au_dbtop(dentry);
9472 + bbot = au_dbbot(dentry);
9474 + AuDebugOn(bbot < 0 && btop > bbot);
9477 + AuDebugOn(bbot >= 0);
9483 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9488 + if (unlikely(au_digen(dentry) != sigen
9489 + || au_iigen_test(d_inode(dentry), sigen)))
9495 +void au_update_digen(struct dentry *dentry)
9497 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9498 + /* smp_mb(); */ /* atomic_set */
9501 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9503 + struct au_dinfo *dinfo;
9504 + struct dentry *h_d;
9505 + struct au_hdentry *hdp;
9506 + aufs_bindex_t bindex, bbot;
9508 + DiMustWriteLock(dentry);
9510 + dinfo = au_di(dentry);
9511 + if (!dinfo || dinfo->di_btop < 0)
9514 + if (do_put_zero) {
9515 + bbot = dinfo->di_bbot;
9516 + bindex = dinfo->di_btop;
9517 + hdp = au_hdentry(dinfo, bindex);
9518 + for (; bindex <= bbot; bindex++, hdp++) {
9519 + h_d = hdp->hd_dentry;
9520 + if (h_d && d_is_negative(h_d))
9521 + au_set_h_dptr(dentry, bindex, NULL);
9525 + dinfo->di_btop = 0;
9526 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9527 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9528 + if (hdp->hd_dentry)
9530 + if (dinfo->di_btop > dinfo->di_bbot) {
9531 + dinfo->di_btop = -1;
9532 + dinfo->di_bbot = -1;
9536 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9537 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9538 + if (hdp->hd_dentry)
9540 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9543 +void au_update_dbtop(struct dentry *dentry)
9545 + aufs_bindex_t bindex, bbot;
9546 + struct dentry *h_dentry;
9548 + bbot = au_dbbot(dentry);
9549 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9550 + h_dentry = au_h_dptr(dentry, bindex);
9553 + if (d_is_positive(h_dentry)) {
9554 + au_set_dbtop(dentry, bindex);
9557 + au_set_h_dptr(dentry, bindex, NULL);
9561 +void au_update_dbbot(struct dentry *dentry)
9563 + aufs_bindex_t bindex, btop;
9564 + struct dentry *h_dentry;
9566 + btop = au_dbtop(dentry);
9567 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9568 + h_dentry = au_h_dptr(dentry, bindex);
9571 + if (d_is_positive(h_dentry)) {
9572 + au_set_dbbot(dentry, bindex);
9575 + au_set_h_dptr(dentry, bindex, NULL);
9579 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9581 + aufs_bindex_t bindex, bbot;
9583 + bbot = au_dbbot(dentry);
9584 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9585 + if (au_h_dptr(dentry, bindex) == h_dentry)
9589 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9590 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9591 +++ linux/fs/aufs/dir.c 2016-07-25 19:05:34.811159821 +0200
9594 + * Copyright (C) 2005-2016 Junjiro R. Okajima
9596 + * This program, aufs is free software; you can redistribute it and/or modify
9597 + * it under the terms of the GNU General Public License as published by
9598 + * the Free Software Foundation; either version 2 of the License, or
9599 + * (at your option) any later version.
9601 + * This program is distributed in the hope that it will be useful,
9602 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9603 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9604 + * GNU General Public License for more details.
9606 + * You should have received a copy of the GNU General Public License
9607 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9611 + * directory operations
9614 +#include <linux/fs_stack.h>
9617 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9619 + unsigned int nlink;
9621 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9623 + nlink = dir->i_nlink;
9624 + nlink += h_dir->i_nlink - 2;
9625 + if (h_dir->i_nlink < 2)
9627 + smp_mb(); /* for i_nlink */
9628 + /* 0 can happen in revaliding */
9629 + set_nlink(dir, nlink);
9632 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9634 + unsigned int nlink;
9636 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9638 + nlink = dir->i_nlink;
9639 + nlink -= h_dir->i_nlink - 2;
9640 + if (h_dir->i_nlink < 2)
9642 + smp_mb(); /* for i_nlink */
9643 + /* nlink == 0 means the branch-fs is broken */
9644 + set_nlink(dir, nlink);
9647 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9650 + aufs_bindex_t bindex, bbot;
9651 + struct file *h_file;
9652 + struct dentry *h_dentry;
9656 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9658 + bbot = au_fbbot_dir(file);
9659 + for (bindex = au_fbtop(file);
9660 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9662 + h_file = au_hf_dir(file, bindex);
9663 + if (h_file && file_inode(h_file))
9664 + sz += vfsub_f_size_read(h_file);
9667 + AuDebugOn(!dentry);
9668 + AuDebugOn(!d_is_dir(dentry));
9670 + bbot = au_dbtaildir(dentry);
9671 + for (bindex = au_dbtop(dentry);
9672 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9674 + h_dentry = au_h_dptr(dentry, bindex);
9675 + if (h_dentry && d_is_positive(h_dentry))
9676 + sz += i_size_read(d_inode(h_dentry));
9679 + if (sz < KMALLOC_MAX_SIZE)
9680 + sz = roundup_pow_of_two(sz);
9681 + if (sz > KMALLOC_MAX_SIZE)
9682 + sz = KMALLOC_MAX_SIZE;
9683 + else if (sz < NAME_MAX) {
9684 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9685 + sz = AUFS_RDBLK_DEF;
9690 +struct au_dir_ts_arg {
9691 + struct dentry *dentry;
9692 + aufs_bindex_t brid;
9695 +static void au_do_dir_ts(void *arg)
9697 + struct au_dir_ts_arg *a = arg;
9698 + struct au_dtime dt;
9699 + struct path h_path;
9700 + struct inode *dir, *h_dir;
9701 + struct super_block *sb;
9702 + struct au_branch *br;
9703 + struct au_hinode *hdir;
9705 + aufs_bindex_t btop, bindex;
9707 + sb = a->dentry->d_sb;
9708 + if (d_really_is_negative(a->dentry))
9710 + /* no dir->i_mutex lock */
9711 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
9713 + dir = d_inode(a->dentry);
9714 + btop = au_ibtop(dir);
9715 + bindex = au_br_index(sb, a->brid);
9716 + if (bindex < btop)
9719 + br = au_sbr(sb, bindex);
9720 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9721 + if (!h_path.dentry)
9723 + h_path.mnt = au_br_mnt(br);
9724 + au_dtime_store(&dt, a->dentry, &h_path);
9726 + br = au_sbr(sb, btop);
9727 + if (!au_br_writable(br->br_perm))
9729 + h_path.dentry = au_h_dptr(a->dentry, btop);
9730 + h_path.mnt = au_br_mnt(br);
9731 + err = vfsub_mnt_want_write(h_path.mnt);
9734 + hdir = au_hi(dir, btop);
9735 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
9736 + h_dir = au_h_iptr(dir, btop);
9737 + if (h_dir->i_nlink
9738 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9739 + dt.dt_h_path = h_path;
9740 + au_dtime_revert(&dt);
9742 + au_hn_inode_unlock(hdir);
9743 + vfsub_mnt_drop_write(h_path.mnt);
9744 + au_cpup_attr_timesizes(dir);
9747 + aufs_read_unlock(a->dentry, AuLock_DW);
9750 + au_nwt_done(&au_sbi(sb)->si_nowait);
9754 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9756 + int perm, wkq_err;
9757 + aufs_bindex_t btop;
9758 + struct au_dir_ts_arg *arg;
9759 + struct dentry *dentry;
9760 + struct super_block *sb;
9764 + dentry = d_find_any_alias(dir);
9765 + AuDebugOn(!dentry);
9766 + sb = dentry->d_sb;
9767 + btop = au_ibtop(dir);
9768 + if (btop == bindex) {
9769 + au_cpup_attr_timesizes(dir);
9773 + perm = au_sbr_perm(sb, btop);
9774 + if (!au_br_writable(perm))
9777 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9781 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9782 + arg->brid = au_sbr_id(sb, bindex);
9783 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9784 + if (unlikely(wkq_err)) {
9785 + pr_err("wkq %d\n", wkq_err);
9794 +/* ---------------------------------------------------------------------- */
9796 +static int reopen_dir(struct file *file)
9799 + unsigned int flags;
9800 + aufs_bindex_t bindex, btail, btop;
9801 + struct dentry *dentry, *h_dentry;
9802 + struct file *h_file;
9804 + /* open all lower dirs */
9805 + dentry = file->f_path.dentry;
9806 + btop = au_dbtop(dentry);
9807 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
9808 + au_set_h_fptr(file, bindex, NULL);
9809 + au_set_fbtop(file, btop);
9811 + btail = au_dbtaildir(dentry);
9812 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
9813 + au_set_h_fptr(file, bindex, NULL);
9814 + au_set_fbbot_dir(file, btail);
9816 + flags = vfsub_file_flags(file);
9817 + for (bindex = btop; bindex <= btail; bindex++) {
9818 + h_dentry = au_h_dptr(dentry, bindex);
9821 + h_file = au_hf_dir(file, bindex);
9825 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9826 + err = PTR_ERR(h_file);
9827 + if (IS_ERR(h_file))
9828 + goto out; /* close all? */
9829 + au_set_h_fptr(file, bindex, h_file);
9831 + au_update_figen(file);
9832 + /* todo: necessary? */
9833 + /* file->f_ra = h_file->f_ra; */
9840 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9843 + aufs_bindex_t bindex, btail;
9844 + struct dentry *dentry, *h_dentry;
9845 + struct vfsmount *mnt;
9847 + FiMustWriteLock(file);
9848 + AuDebugOn(h_file);
9851 + mnt = file->f_path.mnt;
9852 + dentry = file->f_path.dentry;
9853 + file->f_version = d_inode(dentry)->i_version;
9854 + bindex = au_dbtop(dentry);
9855 + au_set_fbtop(file, bindex);
9856 + btail = au_dbtaildir(dentry);
9857 + au_set_fbbot_dir(file, btail);
9858 + for (; !err && bindex <= btail; bindex++) {
9859 + h_dentry = au_h_dptr(dentry, bindex);
9863 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
9864 + if (unlikely(err))
9866 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9867 + if (IS_ERR(h_file)) {
9868 + err = PTR_ERR(h_file);
9871 + au_set_h_fptr(file, bindex, h_file);
9873 + au_update_figen(file);
9874 + /* todo: necessary? */
9875 + /* file->f_ra = h_file->f_ra; */
9877 + return 0; /* success */
9880 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
9881 + au_set_h_fptr(file, bindex, NULL);
9882 + au_set_fbtop(file, -1);
9883 + au_set_fbbot_dir(file, -1);
9888 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9889 + struct file *file)
9892 + struct super_block *sb;
9893 + struct au_fidir *fidir;
9896 + sb = file->f_path.dentry->d_sb;
9897 + si_read_lock(sb, AuLock_FLUSH);
9898 + fidir = au_fidir_alloc(sb);
9900 + struct au_do_open_args args = {
9901 + .open = do_open_dir,
9904 + err = au_do_open(file, &args);
9905 + if (unlikely(err))
9908 + si_read_unlock(sb);
9912 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9913 + struct file *file)
9915 + struct au_vdir *vdir_cache;
9916 + struct au_finfo *finfo;
9917 + struct au_fidir *fidir;
9918 + aufs_bindex_t bindex, bbot;
9920 + finfo = au_fi(file);
9921 + fidir = finfo->fi_hdir;
9923 + au_sphl_del(&finfo->fi_hlist,
9924 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9925 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9927 + au_vdir_free(vdir_cache);
9929 + bindex = finfo->fi_btop;
9930 + if (bindex >= 0) {
9932 + * calls fput() instead of filp_close(),
9933 + * since no dnotify or lock for the lower file.
9935 + bbot = fidir->fd_bbot;
9936 + for (; bindex <= bbot; bindex++)
9937 + au_set_h_fptr(file, bindex, NULL);
9940 + finfo->fi_hdir = NULL;
9942 + au_finfo_fin(file);
9946 +/* ---------------------------------------------------------------------- */
9948 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9951 + aufs_bindex_t bindex, bbot;
9952 + struct file *h_file;
9955 + bbot = au_fbbot_dir(file);
9956 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
9957 + h_file = au_hf_dir(file, bindex);
9959 + err = vfsub_flush(h_file, id);
9964 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9966 + return au_do_flush(file, id, au_do_flush_dir);
9969 +/* ---------------------------------------------------------------------- */
9971 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
9974 + aufs_bindex_t bbot, bindex;
9975 + struct inode *inode;
9976 + struct super_block *sb;
9979 + sb = dentry->d_sb;
9980 + inode = d_inode(dentry);
9982 + bbot = au_dbbot(dentry);
9983 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
9984 + struct path h_path;
9986 + if (au_test_ro(sb, bindex, inode))
9988 + h_path.dentry = au_h_dptr(dentry, bindex);
9989 + if (!h_path.dentry)
9992 + h_path.mnt = au_sbr_mnt(sb, bindex);
9993 + err = vfsub_fsync(NULL, &h_path, datasync);
9999 +static int au_do_fsync_dir(struct file *file, int datasync)
10002 + aufs_bindex_t bbot, bindex;
10003 + struct file *h_file;
10004 + struct super_block *sb;
10005 + struct inode *inode;
10007 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
10008 + if (unlikely(err))
10011 + inode = file_inode(file);
10012 + sb = inode->i_sb;
10013 + bbot = au_fbbot_dir(file);
10014 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10015 + h_file = au_hf_dir(file, bindex);
10016 + if (!h_file || au_test_ro(sb, bindex, inode))
10019 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10027 + * @file may be NULL
10029 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10033 + struct dentry *dentry;
10034 + struct inode *inode;
10035 + struct super_block *sb;
10038 + dentry = file->f_path.dentry;
10039 + inode = d_inode(dentry);
10040 + inode_lock(inode);
10041 + sb = dentry->d_sb;
10042 + si_noflush_read_lock(sb);
10044 + err = au_do_fsync_dir(file, datasync);
10046 + di_write_lock_child(dentry);
10047 + err = au_do_fsync_dir_no_file(dentry, datasync);
10049 + au_cpup_attr_timesizes(inode);
10050 + di_write_unlock(dentry);
10052 + fi_write_unlock(file);
10054 + si_read_unlock(sb);
10055 + inode_unlock(inode);
10059 +/* ---------------------------------------------------------------------- */
10061 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10064 + struct dentry *dentry;
10065 + struct inode *inode, *h_inode;
10066 + struct super_block *sb;
10068 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
10070 + dentry = file->f_path.dentry;
10071 + inode = d_inode(dentry);
10072 + IMustLock(inode);
10074 + sb = dentry->d_sb;
10075 + si_read_lock(sb, AuLock_FLUSH);
10076 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
10077 + if (unlikely(err))
10079 + err = au_alive_dir(dentry);
10081 + err = au_vdir_init(file);
10082 + di_downgrade_lock(dentry, AuLock_IR);
10083 + if (unlikely(err))
10086 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10087 + if (!au_test_nfsd()) {
10088 + err = au_vdir_fill_de(file, ctx);
10089 + fsstack_copy_attr_atime(inode, h_inode);
10092 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10093 + * encode_fh() and others.
10095 + atomic_inc(&h_inode->i_count);
10096 + di_read_unlock(dentry, AuLock_IR);
10097 + si_read_unlock(sb);
10098 + err = au_vdir_fill_de(file, ctx);
10099 + fsstack_copy_attr_atime(inode, h_inode);
10100 + fi_write_unlock(file);
10108 + di_read_unlock(dentry, AuLock_IR);
10109 + fi_write_unlock(file);
10111 + si_read_unlock(sb);
10115 +/* ---------------------------------------------------------------------- */
10117 +#define AuTestEmpty_WHONLY 1
10118 +#define AuTestEmpty_CALLED (1 << 1)
10119 +#define AuTestEmpty_SHWH (1 << 2)
10120 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10121 +#define au_fset_testempty(flags, name) \
10122 + do { (flags) |= AuTestEmpty_##name; } while (0)
10123 +#define au_fclr_testempty(flags, name) \
10124 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10126 +#ifndef CONFIG_AUFS_SHWH
10127 +#undef AuTestEmpty_SHWH
10128 +#define AuTestEmpty_SHWH 0
10131 +struct test_empty_arg {
10132 + struct dir_context ctx;
10133 + struct au_nhash *whlist;
10134 + unsigned int flags;
10136 + aufs_bindex_t bindex;
10139 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10140 + int namelen, loff_t offset __maybe_unused, u64 ino,
10141 + unsigned int d_type)
10143 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10145 + char *name = (void *)__name;
10148 + au_fset_testempty(arg->flags, CALLED);
10150 + if (name[0] == '.'
10151 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10152 + goto out; /* success */
10154 + if (namelen <= AUFS_WH_PFX_LEN
10155 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10156 + if (au_ftest_testempty(arg->flags, WHONLY)
10157 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10158 + arg->err = -ENOTEMPTY;
10162 + name += AUFS_WH_PFX_LEN;
10163 + namelen -= AUFS_WH_PFX_LEN;
10164 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10165 + arg->err = au_nhash_append_wh
10166 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10167 + au_ftest_testempty(arg->flags, SHWH));
10171 + AuTraceErr(arg->err);
10175 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10178 + struct file *h_file;
10180 + h_file = au_h_open(dentry, arg->bindex,
10181 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10182 + /*file*/NULL, /*force_wr*/0);
10183 + err = PTR_ERR(h_file);
10184 + if (IS_ERR(h_file))
10188 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10189 + && !file_inode(h_file)->i_nlink)
10194 + au_fclr_testempty(arg->flags, CALLED);
10196 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10199 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10203 + au_sbr_put(dentry->d_sb, arg->bindex);
10208 +struct do_test_empty_args {
10210 + struct dentry *dentry;
10211 + struct test_empty_arg *arg;
10214 +static void call_do_test_empty(void *args)
10216 + struct do_test_empty_args *a = args;
10217 + *a->errp = do_test_empty(a->dentry, a->arg);
10220 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10222 + int err, wkq_err;
10223 + struct dentry *h_dentry;
10224 + struct inode *h_inode;
10226 + h_dentry = au_h_dptr(dentry, arg->bindex);
10227 + h_inode = d_inode(h_dentry);
10228 + /* todo: i_mode changes anytime? */
10229 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
10230 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10231 + inode_unlock(h_inode);
10233 + err = do_test_empty(dentry, arg);
10235 + struct do_test_empty_args args = {
10237 + .dentry = dentry,
10240 + unsigned int flags = arg->flags;
10242 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10243 + if (unlikely(wkq_err))
10245 + arg->flags = flags;
10251 +int au_test_empty_lower(struct dentry *dentry)
10254 + unsigned int rdhash;
10255 + aufs_bindex_t bindex, btop, btail;
10256 + struct au_nhash whlist;
10257 + struct test_empty_arg arg = {
10259 + .actor = test_empty_cb
10262 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10264 + SiMustAnyLock(dentry->d_sb);
10266 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10268 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10269 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10270 + if (unlikely(err))
10274 + arg.whlist = &whlist;
10275 + btop = au_dbtop(dentry);
10276 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10277 + au_fset_testempty(arg.flags, SHWH);
10278 + test_empty = do_test_empty;
10279 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10280 + test_empty = sio_test_empty;
10281 + arg.bindex = btop;
10282 + err = test_empty(dentry, &arg);
10283 + if (unlikely(err))
10286 + au_fset_testempty(arg.flags, WHONLY);
10287 + btail = au_dbtaildir(dentry);
10288 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10289 + struct dentry *h_dentry;
10291 + h_dentry = au_h_dptr(dentry, bindex);
10292 + if (h_dentry && d_is_positive(h_dentry)) {
10293 + arg.bindex = bindex;
10294 + err = test_empty(dentry, &arg);
10299 + au_nhash_wh_free(&whlist);
10304 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10307 + struct test_empty_arg arg = {
10309 + .actor = test_empty_cb
10312 + aufs_bindex_t bindex, btail;
10315 + arg.whlist = whlist;
10316 + arg.flags = AuTestEmpty_WHONLY;
10317 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10318 + au_fset_testempty(arg.flags, SHWH);
10319 + btail = au_dbtaildir(dentry);
10320 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10321 + struct dentry *h_dentry;
10323 + h_dentry = au_h_dptr(dentry, bindex);
10324 + if (h_dentry && d_is_positive(h_dentry)) {
10325 + arg.bindex = bindex;
10326 + err = sio_test_empty(dentry, &arg);
10333 +/* ---------------------------------------------------------------------- */
10335 +const struct file_operations aufs_dir_fop = {
10336 + .owner = THIS_MODULE,
10337 + .llseek = default_llseek,
10338 + .read = generic_read_dir,
10339 + .iterate_shared = aufs_iterate_shared,
10340 + .unlocked_ioctl = aufs_ioctl_dir,
10341 +#ifdef CONFIG_COMPAT
10342 + .compat_ioctl = aufs_compat_ioctl_dir,
10344 + .open = aufs_open_dir,
10345 + .release = aufs_release_dir,
10346 + .flush = aufs_flush_dir,
10347 + .fsync = aufs_fsync_dir
10349 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10350 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10351 +++ linux/fs/aufs/dir.h 2016-07-25 19:05:34.811159821 +0200
10354 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10356 + * This program, aufs is free software; you can redistribute it and/or modify
10357 + * it under the terms of the GNU General Public License as published by
10358 + * the Free Software Foundation; either version 2 of the License, or
10359 + * (at your option) any later version.
10361 + * This program is distributed in the hope that it will be useful,
10362 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10363 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10364 + * GNU General Public License for more details.
10366 + * You should have received a copy of the GNU General Public License
10367 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10371 + * directory operations
10374 +#ifndef __AUFS_DIR_H__
10375 +#define __AUFS_DIR_H__
10379 +#include <linux/fs.h>
10381 +/* ---------------------------------------------------------------------- */
10383 +/* need to be faster and smaller */
10386 + unsigned int nh_num;
10387 + struct hlist_head *nh_head;
10390 +struct au_vdir_destr {
10391 + unsigned char len;
10392 + unsigned char name[0];
10395 +struct au_vdir_dehstr {
10396 + struct hlist_node hash;
10397 + struct au_vdir_destr *str;
10398 +} ____cacheline_aligned_in_smp;
10400 +struct au_vdir_de {
10402 + unsigned char de_type;
10403 + /* caution: packed */
10404 + struct au_vdir_destr de_str;
10407 +struct au_vdir_wh {
10408 + struct hlist_node wh_hash;
10409 +#ifdef CONFIG_AUFS_SHWH
10411 + aufs_bindex_t wh_bindex;
10412 + unsigned char wh_type;
10414 + aufs_bindex_t wh_bindex;
10416 + /* caution: packed */
10417 + struct au_vdir_destr wh_str;
10420 +union au_vdir_deblk_p {
10421 + unsigned char *deblk;
10422 + struct au_vdir_de *de;
10426 + unsigned char **vd_deblk;
10427 + unsigned long vd_nblk;
10429 + unsigned long ul;
10430 + union au_vdir_deblk_p p;
10433 + unsigned long vd_version;
10434 + unsigned int vd_deblk_sz;
10435 + unsigned long vd_jiffy;
10436 +} ____cacheline_aligned_in_smp;
10438 +/* ---------------------------------------------------------------------- */
10441 +extern const struct file_operations aufs_dir_fop;
10442 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10443 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10444 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10445 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10446 +int au_test_empty_lower(struct dentry *dentry);
10447 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10450 +unsigned int au_rdhash_est(loff_t sz);
10451 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10452 +void au_nhash_wh_free(struct au_nhash *whlist);
10453 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10455 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10456 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10457 + unsigned int d_type, aufs_bindex_t bindex,
10458 + unsigned char shwh);
10459 +void au_vdir_free(struct au_vdir *vdir);
10460 +int au_vdir_init(struct file *file);
10461 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10464 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10466 +#ifdef CONFIG_AUFS_RDU
10468 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10469 +#ifdef CONFIG_COMPAT
10470 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10471 + unsigned long arg);
10474 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10475 + unsigned int cmd, unsigned long arg)
10476 +#ifdef CONFIG_COMPAT
10477 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10478 + unsigned int cmd, unsigned long arg)
10482 +#endif /* __KERNEL__ */
10483 +#endif /* __AUFS_DIR_H__ */
10484 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10485 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10486 +++ linux/fs/aufs/dynop.c 2016-07-25 19:05:34.811159821 +0200
10489 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10491 + * This program, aufs is free software; you can redistribute it and/or modify
10492 + * it under the terms of the GNU General Public License as published by
10493 + * the Free Software Foundation; either version 2 of the License, or
10494 + * (at your option) any later version.
10496 + * This program is distributed in the hope that it will be useful,
10497 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10498 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10499 + * GNU General Public License for more details.
10501 + * You should have received a copy of the GNU General Public License
10502 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10506 + * dynamically customizable operations for regular files
10511 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10514 + * How large will these lists be?
10515 + * Usually just a few elements, 20-30 at most for each, I guess.
10517 +static struct au_splhead dynop[AuDyLast];
10519 +static struct au_dykey *dy_gfind_get(struct au_splhead *spl, const void *h_op)
10521 + struct au_dykey *key, *tmp;
10522 + struct list_head *head;
10525 + head = &spl->head;
10527 + list_for_each_entry_rcu(tmp, head, dk_list)
10528 + if (tmp->dk_op.dy_hop == h_op) {
10530 + kref_get(&key->dk_kref);
10533 + rcu_read_unlock();
10538 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10540 + struct au_dykey **k, *found;
10541 + const void *h_op = key->dk_op.dy_hop;
10545 + k = br->br_dykey;
10546 + for (i = 0; i < AuBrDynOp; i++)
10548 + if (k[i]->dk_op.dy_hop == h_op) {
10555 + spin_lock(&br->br_dykey_lock);
10556 + for (; i < AuBrDynOp; i++)
10558 + if (k[i]->dk_op.dy_hop == h_op) {
10566 + spin_unlock(&br->br_dykey_lock);
10567 + BUG_ON(i == AuBrDynOp); /* expand the array */
10573 +/* kref_get() if @key is already added */
10574 +static struct au_dykey *dy_gadd(struct au_splhead *spl, struct au_dykey *key)
10576 + struct au_dykey *tmp, *found;
10577 + struct list_head *head;
10578 + const void *h_op = key->dk_op.dy_hop;
10581 + head = &spl->head;
10582 + spin_lock(&spl->spin);
10583 + list_for_each_entry(tmp, head, dk_list)
10584 + if (tmp->dk_op.dy_hop == h_op) {
10585 + kref_get(&tmp->dk_kref);
10590 + list_add_rcu(&key->dk_list, head);
10591 + spin_unlock(&spl->spin);
10598 +static void dy_free_rcu(struct rcu_head *rcu)
10600 + struct au_dykey *key;
10602 + key = container_of(rcu, struct au_dykey, dk_rcu);
10607 +static void dy_free(struct kref *kref)
10609 + struct au_dykey *key;
10610 + struct au_splhead *spl;
10612 + key = container_of(kref, struct au_dykey, dk_kref);
10613 + spl = dynop + key->dk_op.dy_type;
10614 + au_spl_del_rcu(&key->dk_list, spl);
10615 + call_rcu(&key->dk_rcu, dy_free_rcu);
10618 +void au_dy_put(struct au_dykey *key)
10620 + kref_put(&key->dk_kref, dy_free);
10623 +/* ---------------------------------------------------------------------- */
10625 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10627 +#ifdef CONFIG_AUFS_DEBUG
10628 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10629 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10631 +#define DyDbgDeclare(cnt) do {} while (0)
10632 +#define DyDbgInc(cnt) do {} while (0)
10635 +#define DySet(func, dst, src, h_op, h_sb) do { \
10637 + if (h_op->func) { \
10639 + dst.func = src.func; \
10641 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10645 +#define DySetForce(func, dst, src) do { \
10646 + AuDebugOn(!src.func); \
10648 + dst.func = src.func; \
10651 +#define DySetAop(func) \
10652 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10653 +#define DySetAopForce(func) \
10654 + DySetForce(func, dyaop->da_op, aufs_aop)
10656 +static void dy_aop(struct au_dykey *key, const void *h_op,
10657 + struct super_block *h_sb __maybe_unused)
10659 + struct au_dyaop *dyaop = (void *)key;
10660 + const struct address_space_operations *h_aop = h_op;
10661 + DyDbgDeclare(cnt);
10663 + AuDbg("%s\n", au_sbtype(h_sb));
10665 + DySetAop(writepage);
10666 + DySetAopForce(readpage); /* force */
10667 + DySetAop(writepages);
10668 + DySetAop(set_page_dirty);
10669 + DySetAop(readpages);
10670 + DySetAop(write_begin);
10671 + DySetAop(write_end);
10673 + DySetAop(invalidatepage);
10674 + DySetAop(releasepage);
10675 + DySetAop(freepage);
10676 + /* this one will be changed according to an aufs mount option */
10677 + DySetAop(direct_IO);
10678 + DySetAop(migratepage);
10679 + DySetAop(launder_page);
10680 + DySetAop(is_partially_uptodate);
10681 + DySetAop(is_dirty_writeback);
10682 + DySetAop(error_remove_page);
10683 + DySetAop(swap_activate);
10684 + DySetAop(swap_deactivate);
10686 + DyDbgSize(cnt, *h_aop);
10689 +/* ---------------------------------------------------------------------- */
10691 +static void dy_bug(struct kref *kref)
10696 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10698 + struct au_dykey *key, *old;
10699 + struct au_splhead *spl;
10702 + void (*set)(struct au_dykey *key, const void *h_op,
10703 + struct super_block *h_sb __maybe_unused);
10705 + static const struct op a[] = {
10707 + .sz = sizeof(struct au_dyaop),
10711 + const struct op *p;
10713 + spl = dynop + op->dy_type;
10714 + key = dy_gfind_get(spl, op->dy_hop);
10716 + goto out_add; /* success */
10718 + p = a + op->dy_type;
10719 + key = kzalloc(p->sz, GFP_NOFS);
10720 + if (unlikely(!key)) {
10721 + key = ERR_PTR(-ENOMEM);
10725 + key->dk_op.dy_hop = op->dy_hop;
10726 + kref_init(&key->dk_kref);
10727 + p->set(key, op->dy_hop, au_br_sb(br));
10728 + old = dy_gadd(spl, key);
10735 + old = dy_bradd(br, key);
10737 + /* its ref-count should never be zero here */
10738 + kref_put(&key->dk_kref, dy_bug);
10743 +/* ---------------------------------------------------------------------- */
10745 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10746 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10747 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10748 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10749 + * See the aufs manual in detail.
10751 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10754 + dyaop->da_op.direct_IO = NULL;
10756 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10759 +static struct au_dyaop *dy_aget(struct au_branch *br,
10760 + const struct address_space_operations *h_aop,
10763 + struct au_dyaop *dyaop;
10764 + struct au_dynop op;
10766 + op.dy_type = AuDy_AOP;
10767 + op.dy_haop = h_aop;
10768 + dyaop = (void *)dy_get(&op, br);
10769 + if (IS_ERR(dyaop))
10771 + dy_adx(dyaop, do_dx);
10777 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10778 + struct inode *h_inode)
10781 + struct super_block *sb;
10782 + struct au_branch *br;
10783 + struct au_dyaop *dyaop;
10785 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10786 + IiMustWriteLock(inode);
10788 + sb = inode->i_sb;
10789 + br = au_sbr(sb, bindex);
10790 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10791 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10792 + err = PTR_ERR(dyaop);
10793 + if (IS_ERR(dyaop))
10794 + /* unnecessary to call dy_fput() */
10798 + inode->i_mapping->a_ops = &dyaop->da_op;
10805 + * Is it safe to replace a_ops during the inode/file is in operation?
10806 + * Yes, I hope so.
10808 +int au_dy_irefresh(struct inode *inode)
10811 + aufs_bindex_t btop;
10812 + struct inode *h_inode;
10815 + if (S_ISREG(inode->i_mode)) {
10816 + btop = au_ibtop(inode);
10817 + h_inode = au_h_iptr(inode, btop);
10818 + err = au_dy_iaop(inode, btop, h_inode);
10823 +void au_dy_arefresh(int do_dx)
10825 + struct au_splhead *spl;
10826 + struct list_head *head;
10827 + struct au_dykey *key;
10829 + spl = dynop + AuDy_AOP;
10830 + head = &spl->head;
10831 + spin_lock(&spl->spin);
10832 + list_for_each_entry(key, head, dk_list)
10833 + dy_adx((void *)key, do_dx);
10834 + spin_unlock(&spl->spin);
10837 +/* ---------------------------------------------------------------------- */
10839 +void __init au_dy_init(void)
10843 + /* make sure that 'struct au_dykey *' can be any type */
10844 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10846 + for (i = 0; i < AuDyLast; i++)
10847 + au_spl_init(dynop + i);
10850 +void au_dy_fin(void)
10854 + for (i = 0; i < AuDyLast; i++)
10855 + WARN_ON(!list_empty(&dynop[i].head));
10857 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10858 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10859 +++ linux/fs/aufs/dynop.h 2016-07-25 19:05:34.811159821 +0200
10862 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10864 + * This program, aufs is free software; you can redistribute it and/or modify
10865 + * it under the terms of the GNU General Public License as published by
10866 + * the Free Software Foundation; either version 2 of the License, or
10867 + * (at your option) any later version.
10869 + * This program is distributed in the hope that it will be useful,
10870 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10871 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10872 + * GNU General Public License for more details.
10874 + * You should have received a copy of the GNU General Public License
10875 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10879 + * dynamically customizable operations (for regular files only)
10882 +#ifndef __AUFS_DYNOP_H__
10883 +#define __AUFS_DYNOP_H__
10887 +#include <linux/fs.h>
10888 +#include <linux/kref.h>
10890 +enum {AuDy_AOP, AuDyLast};
10895 + const void *dy_hop;
10896 + const struct address_space_operations *dy_haop;
10902 + struct list_head dk_list;
10903 + struct rcu_head dk_rcu;
10905 + struct au_dynop dk_op;
10908 + * during I am in the branch local array, kref is gotten. when the
10909 + * branch is removed, kref is put.
10911 + struct kref dk_kref;
10914 +/* stop unioning since their sizes are very different from each other */
10916 + struct au_dykey da_key;
10917 + struct address_space_operations da_op; /* not const */
10920 +/* ---------------------------------------------------------------------- */
10924 +void au_dy_put(struct au_dykey *key);
10925 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10926 + struct inode *h_inode);
10927 +int au_dy_irefresh(struct inode *inode);
10928 +void au_dy_arefresh(int do_dio);
10930 +void __init au_dy_init(void);
10931 +void au_dy_fin(void);
10933 +#endif /* __KERNEL__ */
10934 +#endif /* __AUFS_DYNOP_H__ */
10935 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10936 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10937 +++ linux/fs/aufs/export.c 2016-07-25 19:05:34.811159821 +0200
10940 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10942 + * This program, aufs is free software; you can redistribute it and/or modify
10943 + * it under the terms of the GNU General Public License as published by
10944 + * the Free Software Foundation; either version 2 of the License, or
10945 + * (at your option) any later version.
10947 + * This program is distributed in the hope that it will be useful,
10948 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10949 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10950 + * GNU General Public License for more details.
10952 + * You should have received a copy of the GNU General Public License
10953 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10960 +#include <linux/exportfs.h>
10961 +#include <linux/fs_struct.h>
10962 +#include <linux/namei.h>
10963 +#include <linux/nsproxy.h>
10964 +#include <linux/random.h>
10965 +#include <linux/writeback.h>
10966 +#include "../fs/mount.h"
10970 +#ifdef CONFIG_AUFS_INO_T_64
10978 +static ino_t decode_ino(__u32 *a)
10982 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
10984 +#ifdef CONFIG_AUFS_INO_T_64
10990 +static void encode_ino(__u32 *a, ino_t ino)
10996 +#ifdef CONFIG_AUFS_INO_T_64
11001 +/* NFS file handle */
11005 +#ifdef CONFIG_AUFS_INO_T_64
11006 + /* support 64bit inode number */
11019 + Fh_ino = Fh_ino1,
11020 + Fh_dir_ino = Fh_dir_ino1
11023 +static int au_test_anon(struct dentry *dentry)
11025 + /* note: read d_flags without d_lock */
11026 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
11029 +int au_test_nfsd(void)
11032 + struct task_struct *tsk = current;
11033 + char comm[sizeof(tsk->comm)];
11036 + if (tsk->flags & PF_KTHREAD) {
11037 + get_task_comm(comm, tsk);
11038 + ret = !strcmp(comm, "nfsd");
11044 +/* ---------------------------------------------------------------------- */
11045 +/* inode generation external table */
11047 +void au_xigen_inc(struct inode *inode)
11052 + struct super_block *sb;
11053 + struct au_sbinfo *sbinfo;
11055 + sb = inode->i_sb;
11056 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
11058 + sbinfo = au_sbi(sb);
11059 + pos = inode->i_ino;
11060 + pos *= sizeof(igen);
11061 + igen = inode->i_generation + 1;
11062 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
11063 + sizeof(igen), &pos);
11064 + if (sz == sizeof(igen))
11065 + return; /* success */
11067 + if (unlikely(sz >= 0))
11068 + AuIOErr("xigen error (%zd)\n", sz);
11071 +int au_xigen_new(struct inode *inode)
11076 + struct super_block *sb;
11077 + struct au_sbinfo *sbinfo;
11078 + struct file *file;
11081 + /* todo: dirty, at mount time */
11082 + if (inode->i_ino == AUFS_ROOT_INO)
11084 + sb = inode->i_sb;
11085 + SiMustAnyLock(sb);
11086 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11090 + pos = inode->i_ino;
11091 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
11092 + AuIOErr1("too large i%lld\n", pos);
11095 + pos *= sizeof(inode->i_generation);
11098 + sbinfo = au_sbi(sb);
11099 + file = sbinfo->si_xigen;
11102 + if (vfsub_f_size_read(file)
11103 + < pos + sizeof(inode->i_generation)) {
11104 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
11105 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
11106 + sizeof(inode->i_generation), &pos);
11108 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
11109 + sizeof(inode->i_generation), &pos);
11110 + if (sz == sizeof(inode->i_generation))
11111 + goto out; /* success */
11114 + if (unlikely(sz >= 0)) {
11116 + AuIOErr("xigen error (%zd)\n", sz);
11123 +int au_xigen_set(struct super_block *sb, struct file *base)
11126 + struct au_sbinfo *sbinfo;
11127 + struct file *file;
11129 + SiMustWriteLock(sb);
11131 + sbinfo = au_sbi(sb);
11132 + file = au_xino_create2(base, sbinfo->si_xigen);
11133 + err = PTR_ERR(file);
11134 + if (IS_ERR(file))
11137 + if (sbinfo->si_xigen)
11138 + fput(sbinfo->si_xigen);
11139 + sbinfo->si_xigen = file;
11145 +void au_xigen_clr(struct super_block *sb)
11147 + struct au_sbinfo *sbinfo;
11149 + SiMustWriteLock(sb);
11151 + sbinfo = au_sbi(sb);
11152 + if (sbinfo->si_xigen) {
11153 + fput(sbinfo->si_xigen);
11154 + sbinfo->si_xigen = NULL;
11158 +/* ---------------------------------------------------------------------- */
11160 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
11163 + struct dentry *dentry, *d;
11164 + struct inode *inode;
11165 + unsigned int sigen;
11168 + inode = ilookup(sb, ino);
11172 + dentry = ERR_PTR(-ESTALE);
11173 + sigen = au_sigen(sb);
11174 + if (unlikely(au_is_bad_inode(inode)
11175 + || IS_DEADDIR(inode)
11176 + || sigen != au_iigen(inode, NULL)))
11180 + if (!dir_ino || S_ISDIR(inode->i_mode))
11181 + dentry = d_find_alias(inode);
11183 + spin_lock(&inode->i_lock);
11184 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
11185 + spin_lock(&d->d_lock);
11186 + if (!au_test_anon(d)
11187 + && d_inode(d->d_parent)->i_ino == dir_ino) {
11188 + dentry = dget_dlock(d);
11189 + spin_unlock(&d->d_lock);
11192 + spin_unlock(&d->d_lock);
11194 + spin_unlock(&inode->i_lock);
11196 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
11197 + /* need to refresh */
11205 + AuTraceErrPtr(dentry);
11209 +/* ---------------------------------------------------------------------- */
11211 +/* todo: dirty? */
11212 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
11214 +struct au_compare_mnt_args {
11216 + struct super_block *sb;
11219 + struct vfsmount *mnt;
11222 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
11224 + struct au_compare_mnt_args *a = arg;
11226 + if (mnt->mnt_sb != a->sb)
11228 + a->mnt = mntget(mnt);
11232 +static struct vfsmount *au_mnt_get(struct super_block *sb)
11235 + struct path root;
11236 + struct au_compare_mnt_args args = {
11240 + get_fs_root(current->fs, &root);
11242 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
11243 + rcu_read_unlock();
11246 + AuDebugOn(!args.mnt);
11250 +struct au_nfsd_si_lock {
11251 + unsigned int sigen;
11252 + aufs_bindex_t bindex, br_id;
11253 + unsigned char force_lock;
11256 +static int si_nfsd_read_lock(struct super_block *sb,
11257 + struct au_nfsd_si_lock *nsi_lock)
11260 + aufs_bindex_t bindex;
11262 + si_read_lock(sb, AuLock_FLUSH);
11264 + /* branch id may be wrapped around */
11266 + bindex = au_br_index(sb, nsi_lock->br_id);
11267 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11268 + goto out; /* success */
11272 + if (!nsi_lock->force_lock)
11273 + si_read_unlock(sb);
11276 + nsi_lock->bindex = bindex;
11280 +struct find_name_by_ino {
11281 + struct dir_context ctx;
11282 + int called, found;
11289 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11290 + loff_t offset, u64 ino, unsigned int d_type)
11292 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11296 + if (a->ino != ino)
11299 + memcpy(a->name, name, namelen);
11300 + a->namelen = namelen;
11305 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11306 + struct au_nfsd_si_lock *nsi_lock)
11308 + struct dentry *dentry, *parent;
11309 + struct file *file;
11310 + struct inode *dir;
11311 + struct find_name_by_ino arg = {
11313 + .actor = find_name_by_ino
11318 + parent = path->dentry;
11320 + si_read_unlock(parent->d_sb);
11321 + file = vfsub_dentry_open(path, au_dir_roflags);
11322 + dentry = (void *)file;
11323 + if (IS_ERR(file))
11326 + dentry = ERR_PTR(-ENOMEM);
11327 + arg.name = (void *)__get_free_page(GFP_NOFS);
11328 + if (unlikely(!arg.name))
11335 + err = vfsub_iterate_dir(file, &arg.ctx);
11336 + } while (!err && !arg.found && arg.called);
11337 + dentry = ERR_PTR(err);
11338 + if (unlikely(err))
11340 + /* instead of ENOENT */
11341 + dentry = ERR_PTR(-ESTALE);
11345 + /* do not call vfsub_lkup_one() */
11346 + dir = d_inode(parent);
11347 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
11348 + AuTraceErrPtr(dentry);
11349 + if (IS_ERR(dentry))
11351 + AuDebugOn(au_test_anon(dentry));
11352 + if (unlikely(d_really_is_negative(dentry))) {
11354 + dentry = ERR_PTR(-ENOENT);
11358 + free_page((unsigned long)arg.name);
11362 + if (unlikely(nsi_lock
11363 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11364 + if (!IS_ERR(dentry)) {
11366 + dentry = ERR_PTR(-ESTALE);
11368 + AuTraceErrPtr(dentry);
11372 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11374 + struct au_nfsd_si_lock *nsi_lock)
11376 + struct dentry *dentry;
11377 + struct path path;
11379 + if (dir_ino != AUFS_ROOT_INO) {
11380 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11381 + dentry = path.dentry;
11382 + if (!path.dentry || IS_ERR(path.dentry))
11384 + AuDebugOn(au_test_anon(path.dentry));
11386 + path.dentry = dget(sb->s_root);
11388 + path.mnt = au_mnt_get(sb);
11389 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11393 + AuTraceErrPtr(dentry);
11397 +/* ---------------------------------------------------------------------- */
11399 +static int h_acceptable(void *expv, struct dentry *dentry)
11404 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11405 + char *buf, int len, struct super_block *sb)
11409 + struct path path;
11411 + p = d_path(h_rootpath, buf, len);
11416 + path.mnt = h_rootpath->mnt;
11417 + path.dentry = h_parent;
11418 + p = d_path(&path, buf, len);
11424 + path.mnt = au_mnt_get(sb);
11425 + path.dentry = sb->s_root;
11426 + p = d_path(&path, buf, len - strlen(p));
11427 + mntput(path.mnt);
11431 + p[strlen(p)] = '/';
11434 + AuTraceErrPtr(p);
11439 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11440 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11442 + struct dentry *dentry, *h_parent, *root;
11443 + struct super_block *h_sb;
11444 + char *pathname, *p;
11445 + struct vfsmount *h_mnt;
11446 + struct au_branch *br;
11448 + struct path path;
11450 + br = au_sbr(sb, nsi_lock->bindex);
11451 + h_mnt = au_br_mnt(br);
11452 + h_sb = h_mnt->mnt_sb;
11453 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11455 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11456 + fh_len - Fh_tail, fh[Fh_h_type],
11457 + h_acceptable, /*context*/NULL);
11459 + dentry = h_parent;
11460 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11461 + AuWarn1("%s decode_fh failed, %ld\n",
11462 + au_sbtype(h_sb), PTR_ERR(h_parent));
11466 + if (unlikely(au_test_anon(h_parent))) {
11467 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11468 + au_sbtype(h_sb));
11469 + goto out_h_parent;
11472 + dentry = ERR_PTR(-ENOMEM);
11473 + pathname = (void *)__get_free_page(GFP_NOFS);
11474 + if (unlikely(!pathname))
11475 + goto out_h_parent;
11477 + root = sb->s_root;
11478 + path.mnt = h_mnt;
11479 + di_read_lock_parent(root, !AuLock_IR);
11480 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11481 + di_read_unlock(root, !AuLock_IR);
11482 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11483 + dentry = (void *)p;
11485 + goto out_pathname;
11487 + si_read_unlock(sb);
11488 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11489 + dentry = ERR_PTR(err);
11490 + if (unlikely(err))
11493 + dentry = ERR_PTR(-ENOENT);
11494 + AuDebugOn(au_test_anon(path.dentry));
11495 + if (unlikely(d_really_is_negative(path.dentry)))
11498 + if (ino != d_inode(path.dentry)->i_ino)
11499 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11501 + dentry = dget(path.dentry);
11506 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11507 + if (!IS_ERR(dentry)) {
11509 + dentry = ERR_PTR(-ESTALE);
11512 + free_page((unsigned long)pathname);
11516 + AuTraceErrPtr(dentry);
11520 +/* ---------------------------------------------------------------------- */
11522 +static struct dentry *
11523 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11526 + struct dentry *dentry;
11527 + __u32 *fh = fid->raw;
11528 + struct au_branch *br;
11529 + ino_t ino, dir_ino;
11530 + struct au_nfsd_si_lock nsi_lock = {
11534 + dentry = ERR_PTR(-ESTALE);
11535 + /* it should never happen, but the file handle is unreliable */
11536 + if (unlikely(fh_len < Fh_tail))
11538 + nsi_lock.sigen = fh[Fh_sigen];
11539 + nsi_lock.br_id = fh[Fh_br_id];
11541 + /* branch id may be wrapped around */
11543 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11545 + nsi_lock.force_lock = 1;
11547 + /* is this inode still cached? */
11548 + ino = decode_ino(fh + Fh_ino);
11549 + /* it should never happen */
11550 + if (unlikely(ino == AUFS_ROOT_INO))
11553 + dir_ino = decode_ino(fh + Fh_dir_ino);
11554 + dentry = decode_by_ino(sb, ino, dir_ino);
11555 + if (IS_ERR(dentry))
11560 + /* is the parent dir cached? */
11561 + br = au_sbr(sb, nsi_lock.bindex);
11563 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11564 + if (IS_ERR(dentry))
11569 + /* lookup path */
11570 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11571 + if (IS_ERR(dentry))
11573 + if (unlikely(!dentry))
11574 + /* todo?: make it ESTALE */
11578 + if (!au_digen_test(dentry, au_sigen(sb))
11579 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11580 + goto out_unlock; /* success */
11583 + dentry = ERR_PTR(-ESTALE);
11587 + si_read_unlock(sb);
11589 + AuTraceErrPtr(dentry);
11593 +#if 0 /* reserved for future use */
11594 +/* support subtreecheck option */
11595 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11596 + int fh_len, int fh_type)
11598 + struct dentry *parent;
11599 + __u32 *fh = fid->raw;
11602 + dir_ino = decode_ino(fh + Fh_dir_ino);
11603 + parent = decode_by_ino(sb, dir_ino, 0);
11604 + if (IS_ERR(parent))
11607 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11608 + dir_ino, fh, fh_len);
11611 + AuTraceErrPtr(parent);
11616 +/* ---------------------------------------------------------------------- */
11618 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11619 + struct inode *dir)
11622 + aufs_bindex_t bindex;
11623 + struct super_block *sb, *h_sb;
11624 + struct dentry *dentry, *parent, *h_parent;
11625 + struct inode *h_dir;
11626 + struct au_branch *br;
11629 + if (unlikely(*max_len <= Fh_tail)) {
11630 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11634 + err = FILEID_ROOT;
11635 + if (inode->i_ino == AUFS_ROOT_INO) {
11636 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11641 + sb = inode->i_sb;
11642 + err = si_read_lock(sb, AuLock_FLUSH);
11643 + if (unlikely(err))
11646 +#ifdef CONFIG_AUFS_DEBUG
11647 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11648 + AuWarn1("NFS-exporting requires xino\n");
11652 + ii_read_lock_child(inode);
11653 + bindex = au_ibtop(inode);
11655 + dentry = d_find_any_alias(inode);
11656 + if (unlikely(!dentry))
11658 + AuDebugOn(au_test_anon(dentry));
11659 + parent = dget_parent(dentry);
11661 + if (unlikely(!parent))
11663 + if (d_really_is_positive(parent))
11664 + dir = d_inode(parent);
11667 + ii_read_lock_parent(dir);
11668 + h_dir = au_h_iptr(dir, bindex);
11669 + ii_read_unlock(dir);
11670 + if (unlikely(!h_dir))
11672 + h_parent = d_find_any_alias(h_dir);
11673 + if (unlikely(!h_parent))
11674 + goto out_hparent;
11677 + br = au_sbr(sb, bindex);
11678 + h_sb = au_br_sb(br);
11679 + if (unlikely(!h_sb->s_export_op)) {
11680 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11681 + goto out_hparent;
11684 + fh[Fh_br_id] = br->br_id;
11685 + fh[Fh_sigen] = au_sigen(sb);
11686 + encode_ino(fh + Fh_ino, inode->i_ino);
11687 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11688 + fh[Fh_igen] = inode->i_generation;
11690 + *max_len -= Fh_tail;
11691 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11693 + /*connectable or subtreecheck*/0);
11694 + err = fh[Fh_h_type];
11695 + *max_len += Fh_tail;
11696 + /* todo: macros? */
11697 + if (err != FILEID_INVALID)
11700 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11707 + ii_read_unlock(inode);
11708 + si_read_unlock(sb);
11710 + if (unlikely(err < 0))
11711 + err = FILEID_INVALID;
11715 +/* ---------------------------------------------------------------------- */
11717 +static int aufs_commit_metadata(struct inode *inode)
11720 + aufs_bindex_t bindex;
11721 + struct super_block *sb;
11722 + struct inode *h_inode;
11723 + int (*f)(struct inode *inode);
11725 + sb = inode->i_sb;
11726 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11727 + ii_write_lock_child(inode);
11728 + bindex = au_ibtop(inode);
11729 + AuDebugOn(bindex < 0);
11730 + h_inode = au_h_iptr(inode, bindex);
11732 + f = h_inode->i_sb->s_export_op->commit_metadata;
11734 + err = f(h_inode);
11736 + struct writeback_control wbc = {
11737 + .sync_mode = WB_SYNC_ALL,
11738 + .nr_to_write = 0 /* metadata only */
11741 + err = sync_inode(h_inode, &wbc);
11744 + au_cpup_attr_timesizes(inode);
11745 + ii_write_unlock(inode);
11746 + si_read_unlock(sb);
11750 +/* ---------------------------------------------------------------------- */
11752 +static struct export_operations aufs_export_op = {
11753 + .fh_to_dentry = aufs_fh_to_dentry,
11754 + /* .fh_to_parent = aufs_fh_to_parent, */
11755 + .encode_fh = aufs_encode_fh,
11756 + .commit_metadata = aufs_commit_metadata
11759 +void au_export_init(struct super_block *sb)
11761 + struct au_sbinfo *sbinfo;
11764 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
11765 + && IS_MODULE(CONFIG_EXPORTFS),
11766 + AUFS_NAME ": unsupported configuration "
11767 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
11769 + sb->s_export_op = &aufs_export_op;
11770 + sbinfo = au_sbi(sb);
11771 + sbinfo->si_xigen = NULL;
11772 + get_random_bytes(&u, sizeof(u));
11773 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11774 + atomic_set(&sbinfo->si_xigen_next, u);
11776 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11777 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11778 +++ linux/fs/aufs/fhsm.c 2016-07-25 19:05:34.814493242 +0200
11781 + * Copyright (C) 2011-2016 Junjiro R. Okajima
11783 + * This program, aufs is free software; you can redistribute it and/or modify
11784 + * it under the terms of the GNU General Public License as published by
11785 + * the Free Software Foundation; either version 2 of the License, or
11786 + * (at your option) any later version.
11788 + * This program is distributed in the hope that it will be useful,
11789 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11790 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11791 + * GNU General Public License for more details.
11793 + * You should have received a copy of the GNU General Public License
11794 + * along with this program; if not, write to the Free Software
11795 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11799 + * File-based Hierarchy Storage Management
11802 +#include <linux/anon_inodes.h>
11803 +#include <linux/poll.h>
11804 +#include <linux/seq_file.h>
11805 +#include <linux/statfs.h>
11808 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11810 + struct au_sbinfo *sbinfo;
11811 + struct au_fhsm *fhsm;
11813 + SiMustAnyLock(sb);
11815 + sbinfo = au_sbi(sb);
11816 + fhsm = &sbinfo->si_fhsm;
11817 + AuDebugOn(!fhsm);
11818 + return fhsm->fhsm_bottom;
11821 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11823 + struct au_sbinfo *sbinfo;
11824 + struct au_fhsm *fhsm;
11826 + SiMustWriteLock(sb);
11828 + sbinfo = au_sbi(sb);
11829 + fhsm = &sbinfo->si_fhsm;
11830 + AuDebugOn(!fhsm);
11831 + fhsm->fhsm_bottom = bindex;
11834 +/* ---------------------------------------------------------------------- */
11836 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11838 + struct au_br_fhsm *bf;
11840 + bf = br->br_fhsm;
11841 + MtxMustLock(&bf->bf_lock);
11843 + return !bf->bf_readable
11844 + || time_after(jiffies,
11845 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11848 +/* ---------------------------------------------------------------------- */
11850 +static void au_fhsm_notify(struct super_block *sb, int val)
11852 + struct au_sbinfo *sbinfo;
11853 + struct au_fhsm *fhsm;
11855 + SiMustAnyLock(sb);
11857 + sbinfo = au_sbi(sb);
11858 + fhsm = &sbinfo->si_fhsm;
11859 + if (au_fhsm_pid(fhsm)
11860 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11861 + atomic_set(&fhsm->fhsm_readable, val);
11863 + wake_up(&fhsm->fhsm_wqh);
11867 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11868 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11871 + struct au_branch *br;
11872 + struct au_br_fhsm *bf;
11874 + br = au_sbr(sb, bindex);
11875 + AuDebugOn(au_br_rdonly(br));
11876 + bf = br->br_fhsm;
11880 + mutex_lock(&bf->bf_lock);
11882 + MtxMustLock(&bf->bf_lock);
11884 + /* sb->s_root for NFS is unreliable */
11885 + err = au_br_stfs(br, &bf->bf_stfs);
11886 + if (unlikely(err)) {
11887 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11891 + bf->bf_jiffy = jiffies;
11892 + bf->bf_readable = 1;
11894 + au_fhsm_notify(sb, /*val*/1);
11896 + *rstfs = bf->bf_stfs;
11900 + mutex_unlock(&bf->bf_lock);
11901 + au_fhsm_notify(sb, /*val*/1);
11906 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11909 + struct au_sbinfo *sbinfo;
11910 + struct au_fhsm *fhsm;
11911 + struct au_branch *br;
11912 + struct au_br_fhsm *bf;
11914 + AuDbg("b%d, force %d\n", bindex, force);
11915 + SiMustAnyLock(sb);
11917 + sbinfo = au_sbi(sb);
11918 + fhsm = &sbinfo->si_fhsm;
11919 + if (!au_ftest_si(sbinfo, FHSM)
11920 + || fhsm->fhsm_bottom == bindex)
11923 + br = au_sbr(sb, bindex);
11924 + bf = br->br_fhsm;
11926 + mutex_lock(&bf->bf_lock);
11928 + || au_fhsm_pid(fhsm)
11929 + || au_fhsm_test_jiffy(sbinfo, br))
11930 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11932 + mutex_unlock(&bf->bf_lock);
11935 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11937 + aufs_bindex_t bindex, bbot;
11938 + struct au_branch *br;
11940 + /* exclude the bottom */
11941 + bbot = au_fhsm_bottom(sb);
11942 + for (bindex = 0; bindex < bbot; bindex++) {
11943 + br = au_sbr(sb, bindex);
11944 + if (au_br_fhsm(br->br_perm))
11945 + au_fhsm_wrote(sb, bindex, force);
11949 +/* ---------------------------------------------------------------------- */
11951 +static unsigned int au_fhsm_poll(struct file *file,
11952 + struct poll_table_struct *wait)
11954 + unsigned int mask;
11955 + struct au_sbinfo *sbinfo;
11956 + struct au_fhsm *fhsm;
11959 + sbinfo = file->private_data;
11960 + fhsm = &sbinfo->si_fhsm;
11961 + poll_wait(file, &fhsm->fhsm_wqh, wait);
11962 + if (atomic_read(&fhsm->fhsm_readable))
11963 + mask = POLLIN /* | POLLRDNORM */;
11965 + AuTraceErr((int)mask);
11969 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
11970 + struct aufs_stfs *stfs, __s16 brid)
11974 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
11976 + err = __put_user(brid, &stbr->brid);
11977 + if (unlikely(err))
11983 +static ssize_t au_fhsm_do_read(struct super_block *sb,
11984 + struct aufs_stbr __user *stbr, size_t count)
11988 + aufs_bindex_t bindex, bbot;
11989 + struct au_branch *br;
11990 + struct au_br_fhsm *bf;
11992 + /* except the bottom branch */
11995 + bbot = au_fhsm_bottom(sb);
11996 + for (bindex = 0; !err && bindex < bbot; bindex++) {
11997 + br = au_sbr(sb, bindex);
11998 + if (!au_br_fhsm(br->br_perm))
12001 + bf = br->br_fhsm;
12002 + mutex_lock(&bf->bf_lock);
12003 + if (bf->bf_readable) {
12005 + if (count >= sizeof(*stbr))
12006 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
12009 + bf->bf_readable = 0;
12010 + count -= sizeof(*stbr);
12014 + mutex_unlock(&bf->bf_lock);
12017 + err = sizeof(*stbr) * nstbr;
12022 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
12027 + aufs_bindex_t nfhsm, bindex, bbot;
12028 + struct au_sbinfo *sbinfo;
12029 + struct au_fhsm *fhsm;
12030 + struct au_branch *br;
12031 + struct super_block *sb;
12034 + sbinfo = file->private_data;
12035 + fhsm = &sbinfo->si_fhsm;
12037 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
12038 + if (!atomic_read(&fhsm->fhsm_readable)) {
12039 + if (vfsub_file_flags(file) & O_NONBLOCK)
12042 + err = wait_event_interruptible_locked_irq
12044 + atomic_read(&fhsm->fhsm_readable));
12046 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
12047 + if (unlikely(err))
12050 + /* sb may already be dead */
12051 + au_rw_read_lock(&sbinfo->si_rwsem);
12052 + readable = atomic_read(&fhsm->fhsm_readable);
12053 + if (readable > 0) {
12054 + sb = sbinfo->si_sb;
12056 + /* exclude the bottom branch */
12058 + bbot = au_fhsm_bottom(sb);
12059 + for (bindex = 0; bindex < bbot; bindex++) {
12060 + br = au_sbr(sb, bindex);
12061 + if (au_br_fhsm(br->br_perm))
12065 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
12066 + atomic_set(&fhsm->fhsm_readable, 0);
12067 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
12071 + au_rw_read_unlock(&sbinfo->si_rwsem);
12079 +static int au_fhsm_release(struct inode *inode, struct file *file)
12081 + struct au_sbinfo *sbinfo;
12082 + struct au_fhsm *fhsm;
12084 + /* sb may already be dead */
12085 + sbinfo = file->private_data;
12086 + fhsm = &sbinfo->si_fhsm;
12087 + spin_lock(&fhsm->fhsm_spin);
12088 + fhsm->fhsm_pid = 0;
12089 + spin_unlock(&fhsm->fhsm_spin);
12090 + kobject_put(&sbinfo->si_kobj);
12095 +static const struct file_operations au_fhsm_fops = {
12096 + .owner = THIS_MODULE,
12097 + .llseek = noop_llseek,
12098 + .read = au_fhsm_read,
12099 + .poll = au_fhsm_poll,
12100 + .release = au_fhsm_release
12103 +int au_fhsm_fd(struct super_block *sb, int oflags)
12106 + struct au_sbinfo *sbinfo;
12107 + struct au_fhsm *fhsm;
12110 + if (unlikely(!capable(CAP_SYS_ADMIN)))
12114 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
12118 + sbinfo = au_sbi(sb);
12119 + fhsm = &sbinfo->si_fhsm;
12120 + spin_lock(&fhsm->fhsm_spin);
12121 + if (!fhsm->fhsm_pid)
12122 + fhsm->fhsm_pid = current->pid;
12125 + spin_unlock(&fhsm->fhsm_spin);
12126 + if (unlikely(err))
12129 + oflags |= O_RDONLY;
12130 + /* oflags |= FMODE_NONOTIFY; */
12131 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
12133 + if (unlikely(fd < 0))
12136 + /* succeed reglardless 'fhsm' status */
12137 + kobject_get(&sbinfo->si_kobj);
12138 + si_noflush_read_lock(sb);
12139 + if (au_ftest_si(sbinfo, FHSM))
12140 + au_fhsm_wrote_all(sb, /*force*/0);
12141 + si_read_unlock(sb);
12142 + goto out; /* success */
12145 + spin_lock(&fhsm->fhsm_spin);
12146 + fhsm->fhsm_pid = 0;
12147 + spin_unlock(&fhsm->fhsm_spin);
12153 +/* ---------------------------------------------------------------------- */
12155 +int au_fhsm_br_alloc(struct au_branch *br)
12160 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
12162 + au_br_fhsm_init(br->br_fhsm);
12169 +/* ---------------------------------------------------------------------- */
12171 +void au_fhsm_fin(struct super_block *sb)
12173 + au_fhsm_notify(sb, /*val*/-1);
12176 +void au_fhsm_init(struct au_sbinfo *sbinfo)
12178 + struct au_fhsm *fhsm;
12180 + fhsm = &sbinfo->si_fhsm;
12181 + spin_lock_init(&fhsm->fhsm_spin);
12182 + init_waitqueue_head(&fhsm->fhsm_wqh);
12183 + atomic_set(&fhsm->fhsm_readable, 0);
12184 + fhsm->fhsm_expire
12185 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
12186 + fhsm->fhsm_bottom = -1;
12189 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
12191 + sbinfo->si_fhsm.fhsm_expire
12192 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
12195 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
12199 + if (!au_ftest_si(sbinfo, FHSM))
12202 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
12203 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
12204 + seq_printf(seq, ",fhsm_sec=%u", u);
12206 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
12207 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
12208 +++ linux/fs/aufs/file.c 2016-07-25 19:05:34.814493242 +0200
12211 + * Copyright (C) 2005-2016 Junjiro R. Okajima
12213 + * This program, aufs is free software; you can redistribute it and/or modify
12214 + * it under the terms of the GNU General Public License as published by
12215 + * the Free Software Foundation; either version 2 of the License, or
12216 + * (at your option) any later version.
12218 + * This program is distributed in the hope that it will be useful,
12219 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12220 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12221 + * GNU General Public License for more details.
12223 + * You should have received a copy of the GNU General Public License
12224 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12228 + * handling file/dir, and address_space operation
12231 +#ifdef CONFIG_AUFS_DEBUG
12232 +#include <linux/migrate.h>
12234 +#include <linux/pagemap.h>
12237 +/* drop flags for writing */
12238 +unsigned int au_file_roflags(unsigned int flags)
12240 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12241 + flags |= O_RDONLY | O_NOATIME;
12245 +/* common functions to regular file and dir */
12246 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12247 + struct file *file, int force_wr)
12249 + struct file *h_file;
12250 + struct dentry *h_dentry;
12251 + struct inode *h_inode;
12252 + struct super_block *sb;
12253 + struct au_branch *br;
12254 + struct path h_path;
12257 + /* a race condition can happen between open and unlink/rmdir */
12258 + h_file = ERR_PTR(-ENOENT);
12259 + h_dentry = au_h_dptr(dentry, bindex);
12260 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12262 + h_inode = d_inode(h_dentry);
12263 + spin_lock(&h_dentry->d_lock);
12264 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12265 + /* || !d_inode(dentry)->i_nlink */
12267 + spin_unlock(&h_dentry->d_lock);
12268 + if (unlikely(err))
12271 + sb = dentry->d_sb;
12272 + br = au_sbr(sb, bindex);
12273 + err = au_br_test_oflag(flags, br);
12274 + h_file = ERR_PTR(err);
12275 + if (unlikely(err))
12278 + /* drop flags for writing */
12279 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12280 + if (force_wr && !(flags & O_WRONLY))
12282 + flags = au_file_roflags(flags);
12284 + h_file = ERR_PTR(-EROFS);
12285 + flags = au_file_roflags(flags);
12286 + if (unlikely(vfsub_native_ro(h_inode)
12287 + || IS_APPEND(h_inode)))
12289 + flags &= ~O_ACCMODE;
12290 + flags |= O_WRONLY;
12293 + flags &= ~O_CREAT;
12295 + h_path.dentry = h_dentry;
12296 + h_path.mnt = au_br_mnt(br);
12297 + h_file = vfsub_dentry_open(&h_path, flags);
12298 + if (IS_ERR(h_file))
12301 + if (flags & __FMODE_EXEC) {
12302 + err = deny_write_access(h_file);
12303 + if (unlikely(err)) {
12305 + h_file = ERR_PTR(err);
12309 + fsnotify_open(h_file);
12310 + goto out; /* success */
12318 +static int au_cmoo(struct dentry *dentry)
12321 + unsigned int udba;
12322 + struct path h_path;
12323 + struct au_pin pin;
12324 + struct au_cp_generic cpg = {
12325 + .dentry = dentry,
12330 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12332 + struct inode *delegated;
12333 + struct super_block *sb;
12334 + struct au_sbinfo *sbinfo;
12335 + struct au_fhsm *fhsm;
12337 + struct au_branch *br;
12338 + struct dentry *parent;
12339 + struct au_hinode *hdir;
12341 + DiMustWriteLock(dentry);
12342 + IiMustWriteLock(d_inode(dentry));
12345 + if (IS_ROOT(dentry))
12347 + cpg.bsrc = au_dbtop(dentry);
12351 + sb = dentry->d_sb;
12352 + sbinfo = au_sbi(sb);
12353 + fhsm = &sbinfo->si_fhsm;
12354 + pid = au_fhsm_pid(fhsm);
12356 + && (current->pid == pid
12357 + || current->real_parent->pid == pid))
12360 + br = au_sbr(sb, cpg.bsrc);
12361 + cmoo = au_br_cmoo(br->br_perm);
12364 + if (!d_is_reg(dentry))
12365 + cmoo &= AuBrAttr_COO_ALL;
12369 + parent = dget_parent(dentry);
12370 + di_write_lock_parent(parent);
12371 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12373 + if (unlikely(err < 0)) {
12374 + err = 0; /* there is no upper writable branch */
12377 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12379 + /* do not respect the coo attrib for the target branch */
12380 + err = au_cpup_dirs(dentry, cpg.bdst);
12381 + if (unlikely(err))
12384 + di_downgrade_lock(parent, AuLock_IR);
12385 + udba = au_opt_udba(sb);
12386 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12387 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12388 + if (unlikely(err))
12391 + err = au_sio_cpup_simple(&cpg);
12393 + if (unlikely(err))
12395 + if (!(cmoo & AuBrWAttr_MOO))
12396 + goto out_parent; /* success */
12398 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12399 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12400 + if (unlikely(err))
12403 + h_path.mnt = au_br_mnt(br);
12404 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12405 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12406 + delegated = NULL;
12407 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12409 + /* todo: keep h_dentry or not? */
12410 + if (unlikely(err == -EWOULDBLOCK)) {
12411 + pr_warn("cannot retry for NFSv4 delegation"
12412 + " for an internal unlink\n");
12415 + if (unlikely(err)) {
12416 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12420 + goto out_parent; /* success */
12423 + di_downgrade_lock(parent, AuLock_IR);
12425 + di_read_unlock(parent, AuLock_IR);
12432 +int au_do_open(struct file *file, struct au_do_open_args *args)
12434 + int err, no_lock = args->no_lock;
12435 + struct dentry *dentry;
12436 + struct au_finfo *finfo;
12439 + err = au_finfo_init(file, args->fidir);
12442 + err = au_finfo_init(file, args->fidir);
12445 + if (unlikely(err))
12448 + dentry = file->f_path.dentry;
12449 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12451 + di_write_lock_child(dentry);
12452 + err = au_cmoo(dentry);
12453 + di_downgrade_lock(dentry, AuLock_IR);
12455 + err = args->open(file, vfsub_file_flags(file), NULL);
12456 + di_read_unlock(dentry, AuLock_IR);
12458 + err = au_cmoo(dentry);
12460 + err = args->open(file, vfsub_file_flags(file),
12462 + if (!err && au_fbtop(file) != au_dbtop(dentry))
12464 + * cmoo happens after h_file was opened.
12465 + * need to refresh file later.
12467 + atomic_dec(&au_fi(file)->fi_generation);
12470 + finfo = au_fi(file);
12472 + finfo->fi_file = file;
12473 + au_sphl_add(&finfo->fi_hlist,
12474 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12477 + fi_write_unlock(file);
12480 + fi_write_unlock(file);
12483 + if (unlikely(err)) {
12484 + finfo->fi_hdir = NULL;
12485 + au_finfo_fin(file);
12492 +int au_reopen_nondir(struct file *file)
12495 + aufs_bindex_t btop;
12496 + struct dentry *dentry;
12497 + struct file *h_file, *h_file_tmp;
12499 + dentry = file->f_path.dentry;
12500 + btop = au_dbtop(dentry);
12501 + h_file_tmp = NULL;
12502 + if (au_fbtop(file) == btop) {
12503 + h_file = au_hf_top(file);
12504 + if (file->f_mode == h_file->f_mode)
12505 + return 0; /* success */
12506 + h_file_tmp = h_file;
12507 + get_file(h_file_tmp);
12508 + au_set_h_fptr(file, btop, NULL);
12510 + AuDebugOn(au_fi(file)->fi_hdir);
12513 + * file exists on both of rw and ro
12514 + * open --> dbtop and fbtop are both 0
12515 + * prepend a branch as rw, "rw" become ro
12517 + * delete the top branch, "rw" becomes rw again
12518 + * --> dbtop is 1, fbtop is still 0
12519 + * write --> fbtop is 0 but dbtop is 1
12521 + /* AuDebugOn(au_fbtop(file) < btop); */
12523 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
12524 + file, /*force_wr*/0);
12525 + err = PTR_ERR(h_file);
12526 + if (IS_ERR(h_file)) {
12527 + if (h_file_tmp) {
12528 + au_sbr_get(dentry->d_sb, btop);
12529 + au_set_h_fptr(file, btop, h_file_tmp);
12530 + h_file_tmp = NULL;
12532 + goto out; /* todo: close all? */
12536 + au_set_fbtop(file, btop);
12537 + au_set_h_fptr(file, btop, h_file);
12538 + au_update_figen(file);
12539 + /* todo: necessary? */
12540 + /* file->f_ra = h_file->f_ra; */
12544 + fput(h_file_tmp);
12548 +/* ---------------------------------------------------------------------- */
12550 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12551 + struct dentry *hi_wh)
12554 + aufs_bindex_t btop;
12555 + struct au_dinfo *dinfo;
12556 + struct dentry *h_dentry;
12557 + struct au_hdentry *hdp;
12559 + dinfo = au_di(file->f_path.dentry);
12560 + AuRwMustWriteLock(&dinfo->di_rwsem);
12562 + btop = dinfo->di_btop;
12563 + dinfo->di_btop = btgt;
12564 + hdp = au_hdentry(dinfo, btgt);
12565 + h_dentry = hdp->hd_dentry;
12566 + hdp->hd_dentry = hi_wh;
12567 + err = au_reopen_nondir(file);
12568 + hdp->hd_dentry = h_dentry;
12569 + dinfo->di_btop = btop;
12574 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12575 + aufs_bindex_t bcpup, struct au_pin *pin)
12578 + struct inode *inode, *h_inode;
12579 + struct dentry *h_dentry, *hi_wh;
12580 + struct au_cp_generic cpg = {
12581 + .dentry = file->f_path.dentry,
12588 + au_update_dbtop(cpg.dentry);
12589 + inode = d_inode(cpg.dentry);
12591 + if (au_dbtop(cpg.dentry) <= bcpup
12592 + && au_dbbot(cpg.dentry) >= bcpup) {
12593 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12594 + if (h_dentry && d_is_positive(h_dentry))
12595 + h_inode = d_inode(h_dentry);
12597 + hi_wh = au_hi_wh(inode, bcpup);
12598 + if (!hi_wh && !h_inode)
12599 + err = au_sio_cpup_wh(&cpg, file);
12601 + /* already copied-up after unlink */
12602 + err = au_reopen_wh(file, bcpup, hi_wh);
12605 + && (inode->i_nlink > 1
12606 + || (inode->i_state & I_LINKABLE))
12607 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12608 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12614 + * prepare the @file for writing.
12616 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12619 + aufs_bindex_t dbtop;
12620 + struct dentry *parent;
12621 + struct inode *inode;
12622 + struct super_block *sb;
12623 + struct file *h_file;
12624 + struct au_cp_generic cpg = {
12625 + .dentry = file->f_path.dentry,
12630 + .flags = AuCpup_DTIME
12633 + sb = cpg.dentry->d_sb;
12634 + inode = d_inode(cpg.dentry);
12635 + cpg.bsrc = au_fbtop(file);
12636 + err = au_test_ro(sb, cpg.bsrc, inode);
12637 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12638 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12643 + /* need to cpup or reopen */
12644 + parent = dget_parent(cpg.dentry);
12645 + di_write_lock_parent(parent);
12646 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12648 + if (unlikely(err < 0))
12652 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12653 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12654 + if (unlikely(err))
12658 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12659 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12660 + if (unlikely(err))
12663 + dbtop = au_dbtop(cpg.dentry);
12664 + if (dbtop <= cpg.bdst)
12665 + cpg.bsrc = cpg.bdst;
12667 + if (dbtop <= cpg.bdst /* just reopen */
12668 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12670 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12671 + if (IS_ERR(h_file))
12672 + err = PTR_ERR(h_file);
12674 + di_downgrade_lock(parent, AuLock_IR);
12675 + if (dbtop > cpg.bdst)
12676 + err = au_sio_cpup_simple(&cpg);
12678 + err = au_reopen_nondir(file);
12679 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12681 + } else { /* copyup as wh and reopen */
12683 + * since writable hfsplus branch is not supported,
12684 + * h_open_pre/post() are unnecessary.
12686 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12687 + di_downgrade_lock(parent, AuLock_IR);
12691 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12692 + goto out_dput; /* success */
12698 + di_downgrade_lock(parent, AuLock_IR);
12700 + di_read_unlock(parent, AuLock_IR);
12707 +/* ---------------------------------------------------------------------- */
12709 +int au_do_flush(struct file *file, fl_owner_t id,
12710 + int (*flush)(struct file *file, fl_owner_t id))
12713 + struct super_block *sb;
12714 + struct inode *inode;
12716 + inode = file_inode(file);
12717 + sb = inode->i_sb;
12718 + si_noflush_read_lock(sb);
12719 + fi_read_lock(file);
12720 + ii_read_lock_child(inode);
12722 + err = flush(file, id);
12723 + au_cpup_attr_timesizes(inode);
12725 + ii_read_unlock(inode);
12726 + fi_read_unlock(file);
12727 + si_read_unlock(sb);
12731 +/* ---------------------------------------------------------------------- */
12733 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12736 + struct au_pin pin;
12737 + struct au_finfo *finfo;
12738 + struct dentry *parent, *hi_wh;
12739 + struct inode *inode;
12740 + struct super_block *sb;
12741 + struct au_cp_generic cpg = {
12742 + .dentry = file->f_path.dentry,
12747 + .flags = AuCpup_DTIME
12750 + FiMustWriteLock(file);
12753 + finfo = au_fi(file);
12754 + sb = cpg.dentry->d_sb;
12755 + inode = d_inode(cpg.dentry);
12756 + cpg.bdst = au_ibtop(inode);
12757 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12760 + parent = dget_parent(cpg.dentry);
12761 + if (au_test_ro(sb, cpg.bdst, inode)) {
12762 + di_read_lock_parent(parent, !AuLock_IR);
12763 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12765 + di_read_unlock(parent, !AuLock_IR);
12766 + if (unlikely(err < 0))
12771 + di_read_lock_parent(parent, AuLock_IR);
12772 + hi_wh = au_hi_wh(inode, cpg.bdst);
12773 + if (!S_ISDIR(inode->i_mode)
12774 + && au_opt_test(au_mntflags(sb), PLINK)
12775 + && au_plink_test(inode)
12776 + && !d_unhashed(cpg.dentry)
12777 + && cpg.bdst < au_dbtop(cpg.dentry)) {
12778 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12779 + if (unlikely(err))
12782 + /* always superio. */
12783 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12784 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12786 + err = au_sio_cpup_simple(&cpg);
12789 + } else if (hi_wh) {
12790 + /* already copied-up after unlink */
12791 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12792 + *need_reopen = 0;
12796 + di_read_unlock(parent, AuLock_IR);
12803 +static void au_do_refresh_dir(struct file *file)
12805 + aufs_bindex_t bindex, bbot, new_bindex, brid;
12806 + struct au_hfile *p, tmp, *q;
12807 + struct au_finfo *finfo;
12808 + struct super_block *sb;
12809 + struct au_fidir *fidir;
12811 + FiMustWriteLock(file);
12813 + sb = file->f_path.dentry->d_sb;
12814 + finfo = au_fi(file);
12815 + fidir = finfo->fi_hdir;
12816 + AuDebugOn(!fidir);
12817 + p = fidir->fd_hfile + finfo->fi_btop;
12818 + brid = p->hf_br->br_id;
12819 + bbot = fidir->fd_bbot;
12820 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
12824 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12825 + if (new_bindex == bindex)
12827 + if (new_bindex < 0) {
12828 + au_set_h_fptr(file, bindex, NULL);
12832 + /* swap two lower inode, and loop again */
12833 + q = fidir->fd_hfile + new_bindex;
12837 + if (tmp.hf_file) {
12843 + p = fidir->fd_hfile;
12844 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12845 + bbot = au_sbbot(sb);
12846 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
12847 + finfo->fi_btop++, p++)
12848 + if (p->hf_file) {
12849 + if (file_inode(p->hf_file))
12851 + au_hfput(p, file);
12854 + bbot = au_br_index(sb, brid);
12855 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
12856 + finfo->fi_btop++, p++)
12858 + au_hfput(p, file);
12859 + bbot = au_sbbot(sb);
12862 + p = fidir->fd_hfile + bbot;
12863 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
12864 + fidir->fd_bbot--, p--)
12865 + if (p->hf_file) {
12866 + if (file_inode(p->hf_file))
12868 + au_hfput(p, file);
12870 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12874 + * after branch manipulating, refresh the file.
12876 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12878 + int err, need_reopen;
12879 + aufs_bindex_t bbot, bindex;
12880 + struct dentry *dentry;
12881 + struct au_finfo *finfo;
12882 + struct au_hfile *hfile;
12884 + dentry = file->f_path.dentry;
12885 + finfo = au_fi(file);
12886 + if (!finfo->fi_hdir) {
12887 + hfile = &finfo->fi_htop;
12888 + AuDebugOn(!hfile->hf_file);
12889 + bindex = au_br_index(dentry->d_sb, hfile->hf_br->br_id);
12890 + AuDebugOn(bindex < 0);
12891 + if (bindex != finfo->fi_btop)
12892 + au_set_fbtop(file, bindex);
12894 + err = au_fidir_realloc(finfo, au_sbbot(dentry->d_sb) + 1);
12895 + if (unlikely(err))
12897 + au_do_refresh_dir(file);
12902 + if (!au_test_mmapped(file))
12903 + err = au_file_refresh_by_inode(file, &need_reopen);
12904 + if (!err && need_reopen && !d_unlinked(dentry))
12905 + err = reopen(file);
12907 + au_update_figen(file);
12908 + goto out; /* success */
12911 + /* error, close all lower files */
12912 + if (finfo->fi_hdir) {
12913 + bbot = au_fbbot_dir(file);
12914 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
12915 + au_set_h_fptr(file, bindex, NULL);
12922 +/* common function to regular file and dir */
12923 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12927 + unsigned int sigen, figen;
12928 + aufs_bindex_t btop;
12929 + unsigned char pseudo_link;
12930 + struct dentry *dentry;
12931 + struct inode *inode;
12934 + dentry = file->f_path.dentry;
12935 + inode = d_inode(dentry);
12936 + sigen = au_sigen(dentry->d_sb);
12937 + fi_write_lock(file);
12938 + figen = au_figen(file);
12939 + di_write_lock_child(dentry);
12940 + btop = au_dbtop(dentry);
12941 + pseudo_link = (btop != au_ibtop(inode));
12942 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
12944 + di_downgrade_lock(dentry, AuLock_IR);
12945 + fi_downgrade_lock(file);
12947 + goto out; /* success */
12950 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12951 + if (au_digen_test(dentry, sigen)) {
12952 + err = au_reval_dpath(dentry, sigen);
12953 + AuDebugOn(!err && au_digen_test(dentry, sigen));
12957 + err = refresh_file(file, reopen);
12960 + di_downgrade_lock(dentry, AuLock_IR);
12961 + fi_downgrade_lock(file);
12964 + di_write_unlock(dentry);
12965 + fi_write_unlock(file);
12972 +/* ---------------------------------------------------------------------- */
12974 +/* cf. aufs_nopage() */
12975 +/* for madvise(2) */
12976 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
12978 + unlock_page(page);
12982 +/* it will never be called, but necessary to support O_DIRECT */
12983 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
12984 +{ BUG(); return 0; }
12986 +/* they will never be called. */
12987 +#ifdef CONFIG_AUFS_DEBUG
12988 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
12989 + loff_t pos, unsigned len, unsigned flags,
12990 + struct page **pagep, void **fsdata)
12991 +{ AuUnsupport(); return 0; }
12992 +static int aufs_write_end(struct file *file, struct address_space *mapping,
12993 + loff_t pos, unsigned len, unsigned copied,
12994 + struct page *page, void *fsdata)
12995 +{ AuUnsupport(); return 0; }
12996 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
12997 +{ AuUnsupport(); return 0; }
12999 +static int aufs_set_page_dirty(struct page *page)
13000 +{ AuUnsupport(); return 0; }
13001 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
13002 + unsigned int length)
13003 +{ AuUnsupport(); }
13004 +static int aufs_releasepage(struct page *page, gfp_t gfp)
13005 +{ AuUnsupport(); return 0; }
13006 +#if 0 /* called by memory compaction regardless file */
13007 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
13008 + struct page *page, enum migrate_mode mode)
13009 +{ AuUnsupport(); return 0; }
13011 +static int aufs_launder_page(struct page *page)
13012 +{ AuUnsupport(); return 0; }
13013 +static int aufs_is_partially_uptodate(struct page *page,
13014 + unsigned long from,
13015 + unsigned long count)
13016 +{ AuUnsupport(); return 0; }
13017 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
13019 +{ AuUnsupport(); }
13020 +static int aufs_error_remove_page(struct address_space *mapping,
13021 + struct page *page)
13022 +{ AuUnsupport(); return 0; }
13023 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
13025 +{ AuUnsupport(); return 0; }
13026 +static void aufs_swap_deactivate(struct file *file)
13027 +{ AuUnsupport(); }
13028 +#endif /* CONFIG_AUFS_DEBUG */
13030 +const struct address_space_operations aufs_aop = {
13031 + .readpage = aufs_readpage,
13032 + .direct_IO = aufs_direct_IO,
13033 +#ifdef CONFIG_AUFS_DEBUG
13034 + .writepage = aufs_writepage,
13035 + /* no writepages, because of writepage */
13036 + .set_page_dirty = aufs_set_page_dirty,
13037 + /* no readpages, because of readpage */
13038 + .write_begin = aufs_write_begin,
13039 + .write_end = aufs_write_end,
13040 + /* no bmap, no block device */
13041 + .invalidatepage = aufs_invalidatepage,
13042 + .releasepage = aufs_releasepage,
13043 + /* is fallback_migrate_page ok? */
13044 + /* .migratepage = aufs_migratepage, */
13045 + .launder_page = aufs_launder_page,
13046 + .is_partially_uptodate = aufs_is_partially_uptodate,
13047 + .is_dirty_writeback = aufs_is_dirty_writeback,
13048 + .error_remove_page = aufs_error_remove_page,
13049 + .swap_activate = aufs_swap_activate,
13050 + .swap_deactivate = aufs_swap_deactivate
13051 +#endif /* CONFIG_AUFS_DEBUG */
13053 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
13054 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
13055 +++ linux/fs/aufs/file.h 2016-07-25 19:05:34.814493242 +0200
13058 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13060 + * This program, aufs is free software; you can redistribute it and/or modify
13061 + * it under the terms of the GNU General Public License as published by
13062 + * the Free Software Foundation; either version 2 of the License, or
13063 + * (at your option) any later version.
13065 + * This program is distributed in the hope that it will be useful,
13066 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13067 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13068 + * GNU General Public License for more details.
13070 + * You should have received a copy of the GNU General Public License
13071 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13075 + * file operations
13078 +#ifndef __AUFS_FILE_H__
13079 +#define __AUFS_FILE_H__
13083 +#include <linux/file.h>
13084 +#include <linux/fs.h>
13085 +#include <linux/poll.h>
13086 +#include "rwsem.h"
13090 + struct file *hf_file;
13091 + struct au_branch *hf_br;
13096 + aufs_bindex_t fd_bbot;
13097 + aufs_bindex_t fd_nent;
13098 + struct au_vdir *fd_vdir_cache;
13099 + struct au_hfile fd_hfile[];
13102 +static inline int au_fidir_sz(int nent)
13104 + AuDebugOn(nent < 0);
13105 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
13109 + atomic_t fi_generation;
13111 + struct au_rwsem fi_rwsem;
13112 + aufs_bindex_t fi_btop;
13114 + /* do not union them */
13115 + struct { /* for non-dir */
13116 + struct au_hfile fi_htop;
13117 + atomic_t fi_mmapped;
13119 + struct au_fidir *fi_hdir; /* for dir only */
13121 + struct hlist_node fi_hlist;
13122 + struct file *fi_file; /* very ugly */
13123 +} ____cacheline_aligned_in_smp;
13125 +/* ---------------------------------------------------------------------- */
13128 +extern const struct address_space_operations aufs_aop;
13129 +unsigned int au_file_roflags(unsigned int flags);
13130 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
13131 + struct file *file, int force_wr);
13132 +struct au_do_open_args {
13134 + int (*open)(struct file *file, int flags,
13135 + struct file *h_file);
13136 + struct au_fidir *fidir;
13137 + struct file *h_file;
13139 +int au_do_open(struct file *file, struct au_do_open_args *args);
13140 +int au_reopen_nondir(struct file *file);
13142 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
13143 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13145 +int au_do_flush(struct file *file, fl_owner_t id,
13146 + int (*flush)(struct file *file, fl_owner_t id));
13149 +#ifdef CONFIG_AUFS_POLL
13150 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13153 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13155 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13157 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13158 + struct file *h_file);
13160 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13161 + aufs_bindex_t bindex, int force_wr)
13162 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13163 + struct file *h_file);
13167 +extern const struct file_operations aufs_file_fop;
13168 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13169 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13170 +struct file *au_read_pre(struct file *file, int keep_fi);
13173 +void au_hfput(struct au_hfile *hf, struct file *file);
13174 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13175 + struct file *h_file);
13177 +void au_update_figen(struct file *file);
13178 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13179 +int au_fidir_realloc(struct au_finfo *finfo, int nbr);
13181 +void au_fi_init_once(void *_fi);
13182 +void au_finfo_fin(struct file *file);
13183 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13186 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13187 +#ifdef CONFIG_COMPAT
13188 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13189 + unsigned long arg);
13190 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13191 + unsigned long arg);
13194 +/* ---------------------------------------------------------------------- */
13196 +static inline struct au_finfo *au_fi(struct file *file)
13198 + return file->private_data;
13201 +/* ---------------------------------------------------------------------- */
13204 + * fi_read_lock, fi_write_lock,
13205 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13207 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13209 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13210 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13211 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13213 +/* ---------------------------------------------------------------------- */
13215 +/* todo: hard/soft set? */
13216 +static inline aufs_bindex_t au_fbtop(struct file *file)
13218 + FiMustAnyLock(file);
13219 + return au_fi(file)->fi_btop;
13222 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
13224 + FiMustAnyLock(file);
13225 + AuDebugOn(!au_fi(file)->fi_hdir);
13226 + return au_fi(file)->fi_hdir->fd_bbot;
13229 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13231 + FiMustAnyLock(file);
13232 + AuDebugOn(!au_fi(file)->fi_hdir);
13233 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13236 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
13238 + FiMustWriteLock(file);
13239 + au_fi(file)->fi_btop = bindex;
13242 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
13244 + FiMustWriteLock(file);
13245 + AuDebugOn(!au_fi(file)->fi_hdir);
13246 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13249 +static inline void au_set_fvdir_cache(struct file *file,
13250 + struct au_vdir *vdir_cache)
13252 + FiMustWriteLock(file);
13253 + AuDebugOn(!au_fi(file)->fi_hdir);
13254 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13257 +static inline struct file *au_hf_top(struct file *file)
13259 + FiMustAnyLock(file);
13260 + AuDebugOn(au_fi(file)->fi_hdir);
13261 + return au_fi(file)->fi_htop.hf_file;
13264 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13266 + FiMustAnyLock(file);
13267 + AuDebugOn(!au_fi(file)->fi_hdir);
13268 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13271 +/* todo: memory barrier? */
13272 +static inline unsigned int au_figen(struct file *f)
13274 + return atomic_read(&au_fi(f)->fi_generation);
13277 +static inline void au_set_mmapped(struct file *f)
13279 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13281 + pr_warn("fi_mmapped wrapped around\n");
13282 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13286 +static inline void au_unset_mmapped(struct file *f)
13288 + atomic_dec(&au_fi(f)->fi_mmapped);
13291 +static inline int au_test_mmapped(struct file *f)
13293 + return atomic_read(&au_fi(f)->fi_mmapped);
13296 +/* customize vma->vm_file */
13298 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13299 + struct file *file)
13303 + f = vma->vm_file;
13305 + vma->vm_file = file;
13310 +#define AuDbgVmRegion(file, vma) do {} while (0)
13312 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13313 + struct file *file)
13315 + au_do_vm_file_reset(vma, file);
13318 +#define AuDbgVmRegion(file, vma) \
13319 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13321 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13322 + struct file *file)
13326 + au_do_vm_file_reset(vma, file);
13327 + f = vma->vm_region->vm_file;
13329 + vma->vm_region->vm_file = file;
13332 +#endif /* CONFIG_MMU */
13334 +/* handle vma->vm_prfile */
13335 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13336 + struct file *file)
13339 + vma->vm_prfile = file;
13340 +#ifndef CONFIG_MMU
13342 + vma->vm_region->vm_prfile = file;
13346 +#endif /* __KERNEL__ */
13347 +#endif /* __AUFS_FILE_H__ */
13348 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13349 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13350 +++ linux/fs/aufs/finfo.c 2016-07-25 19:05:34.814493242 +0200
13353 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13355 + * This program, aufs is free software; you can redistribute it and/or modify
13356 + * it under the terms of the GNU General Public License as published by
13357 + * the Free Software Foundation; either version 2 of the License, or
13358 + * (at your option) any later version.
13360 + * This program is distributed in the hope that it will be useful,
13361 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13362 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13363 + * GNU General Public License for more details.
13365 + * You should have received a copy of the GNU General Public License
13366 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13370 + * file private data
13375 +void au_hfput(struct au_hfile *hf, struct file *file)
13377 + /* todo: direct access f_flags */
13378 + if (vfsub_file_flags(file) & __FMODE_EXEC)
13379 + allow_write_access(hf->hf_file);
13380 + fput(hf->hf_file);
13381 + hf->hf_file = NULL;
13382 + au_br_put(hf->hf_br);
13383 + hf->hf_br = NULL;
13386 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13388 + struct au_finfo *finfo = au_fi(file);
13389 + struct au_hfile *hf;
13390 + struct au_fidir *fidir;
13392 + fidir = finfo->fi_hdir;
13394 + AuDebugOn(finfo->fi_btop != bindex);
13395 + hf = &finfo->fi_htop;
13397 + hf = fidir->fd_hfile + bindex;
13399 + if (hf && hf->hf_file)
13400 + au_hfput(hf, file);
13402 + FiMustWriteLock(file);
13403 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13404 + hf->hf_file = val;
13405 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13409 +void au_update_figen(struct file *file)
13411 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13412 + /* smp_mb(); */ /* atomic_set */
13415 +/* ---------------------------------------------------------------------- */
13417 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13419 + struct au_fidir *fidir;
13422 + nbr = au_sbbot(sb) + 1;
13424 + nbr = 2; /* initial allocate for 2 branches */
13425 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13427 + fidir->fd_bbot = -1;
13428 + fidir->fd_nent = nbr;
13434 +int au_fidir_realloc(struct au_finfo *finfo, int nbr)
13437 + struct au_fidir *fidir, *p;
13439 + AuRwMustWriteLock(&finfo->fi_rwsem);
13440 + fidir = finfo->fi_hdir;
13441 + AuDebugOn(!fidir);
13444 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13447 + p->fd_nent = nbr;
13448 + finfo->fi_hdir = p;
13455 +/* ---------------------------------------------------------------------- */
13457 +void au_finfo_fin(struct file *file)
13459 + struct au_finfo *finfo;
13461 + au_nfiles_dec(file->f_path.dentry->d_sb);
13463 + finfo = au_fi(file);
13464 + AuDebugOn(finfo->fi_hdir);
13465 + AuRwDestroy(&finfo->fi_rwsem);
13466 + au_cache_free_finfo(finfo);
13469 +void au_fi_init_once(void *_finfo)
13471 + struct au_finfo *finfo = _finfo;
13473 + au_rw_init(&finfo->fi_rwsem);
13476 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13479 + struct au_finfo *finfo;
13480 + struct dentry *dentry;
13483 + dentry = file->f_path.dentry;
13484 + finfo = au_cache_alloc_finfo();
13485 + if (unlikely(!finfo))
13489 + au_nfiles_inc(dentry->d_sb);
13490 + au_rw_write_lock(&finfo->fi_rwsem);
13491 + finfo->fi_btop = -1;
13492 + finfo->fi_hdir = fidir;
13493 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13494 + /* smp_mb(); */ /* atomic_set */
13496 + file->private_data = finfo;
13501 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13502 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13503 +++ linux/fs/aufs/f_op.c 2016-07-25 19:05:34.811159821 +0200
13506 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13508 + * This program, aufs is free software; you can redistribute it and/or modify
13509 + * it under the terms of the GNU General Public License as published by
13510 + * the Free Software Foundation; either version 2 of the License, or
13511 + * (at your option) any later version.
13513 + * This program is distributed in the hope that it will be useful,
13514 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13515 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13516 + * GNU General Public License for more details.
13518 + * You should have received a copy of the GNU General Public License
13519 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13523 + * file and vm operations
13526 +#include <linux/aio.h>
13527 +#include <linux/fs_stack.h>
13528 +#include <linux/mman.h>
13529 +#include <linux/security.h>
13532 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13535 + aufs_bindex_t bindex;
13536 + struct dentry *dentry, *h_dentry;
13537 + struct au_finfo *finfo;
13538 + struct inode *h_inode;
13540 + FiMustWriteLock(file);
13543 + dentry = file->f_path.dentry;
13544 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13545 + finfo = au_fi(file);
13546 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13547 + atomic_set(&finfo->fi_mmapped, 0);
13548 + bindex = au_dbtop(dentry);
13550 + h_dentry = au_h_dptr(dentry, bindex);
13551 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13552 + if (unlikely(err))
13554 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13556 + h_dentry = h_file->f_path.dentry;
13557 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13558 + if (unlikely(err))
13560 + get_file(h_file);
13562 + if (IS_ERR(h_file))
13563 + err = PTR_ERR(h_file);
13565 + if ((flags & __O_TMPFILE)
13566 + && !(flags & O_EXCL)) {
13567 + h_inode = file_inode(h_file);
13568 + spin_lock(&h_inode->i_lock);
13569 + h_inode->i_state |= I_LINKABLE;
13570 + spin_unlock(&h_inode->i_lock);
13572 + au_set_fbtop(file, bindex);
13573 + au_set_h_fptr(file, bindex, h_file);
13574 + au_update_figen(file);
13575 + /* todo: necessary? */
13576 + /* file->f_ra = h_file->f_ra; */
13583 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13584 + struct file *file)
13587 + struct super_block *sb;
13588 + struct au_do_open_args args = {
13589 + .open = au_do_open_nondir
13592 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13593 + file, vfsub_file_flags(file), file->f_mode);
13595 + sb = file->f_path.dentry->d_sb;
13596 + si_read_lock(sb, AuLock_FLUSH);
13597 + err = au_do_open(file, &args);
13598 + si_read_unlock(sb);
13602 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13604 + struct au_finfo *finfo;
13605 + aufs_bindex_t bindex;
13607 + finfo = au_fi(file);
13608 + au_sphl_del(&finfo->fi_hlist,
13609 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13610 + bindex = finfo->fi_btop;
13612 + au_set_h_fptr(file, bindex, NULL);
13614 + au_finfo_fin(file);
13618 +/* ---------------------------------------------------------------------- */
13620 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13623 + struct file *h_file;
13626 + h_file = au_hf_top(file);
13628 + err = vfsub_flush(h_file, id);
13632 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13634 + return au_do_flush(file, id, au_do_flush_nondir);
13637 +/* ---------------------------------------------------------------------- */
13639 + * read and write functions acquire [fdi]_rwsem once, but release before
13640 + * mmap_sem. This is because to stop a race condition between mmap(2).
13641 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13642 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13643 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13646 +/* Callers should call au_read_post() or fput() in the end */
13647 +struct file *au_read_pre(struct file *file, int keep_fi)
13649 + struct file *h_file;
13652 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13654 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13655 + h_file = au_hf_top(file);
13656 + get_file(h_file);
13658 + fi_read_unlock(file);
13660 + h_file = ERR_PTR(err);
13665 +static void au_read_post(struct inode *inode, struct file *h_file)
13667 + /* update without lock, I don't think it a problem */
13668 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13672 +struct au_write_pre {
13674 + aufs_bindex_t btop;
13678 + * return with iinfo is write-locked
13679 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13682 +static struct file *au_write_pre(struct file *file, int do_ready,
13683 + struct au_write_pre *wpre)
13685 + struct file *h_file;
13686 + struct dentry *dentry;
13688 + struct au_pin pin;
13690 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13691 + h_file = ERR_PTR(err);
13692 + if (unlikely(err))
13695 + dentry = file->f_path.dentry;
13697 + err = au_ready_to_write(file, -1, &pin);
13698 + if (unlikely(err)) {
13699 + h_file = ERR_PTR(err);
13700 + di_write_unlock(dentry);
13705 + di_downgrade_lock(dentry, /*flags*/0);
13707 + wpre->btop = au_fbtop(file);
13708 + h_file = au_hf_top(file);
13709 + get_file(h_file);
13711 + wpre->blks = file_inode(h_file)->i_blocks;
13714 + di_read_unlock(dentry, /*flags*/0);
13717 + fi_write_unlock(file);
13722 +static void au_write_post(struct inode *inode, struct file *h_file,
13723 + struct au_write_pre *wpre, ssize_t written)
13725 + struct inode *h_inode;
13727 + au_cpup_attr_timesizes(inode);
13728 + AuDebugOn(au_ibtop(inode) != wpre->btop);
13729 + h_inode = file_inode(h_file);
13730 + inode->i_mode = h_inode->i_mode;
13731 + ii_write_unlock(inode);
13734 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13736 + au_fhsm_wrote(inode->i_sb, wpre->btop,
13737 + /*force*/h_inode->i_blocks > wpre->blks);
13740 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13744 + struct inode *inode;
13745 + struct file *h_file;
13746 + struct super_block *sb;
13748 + inode = file_inode(file);
13749 + sb = inode->i_sb;
13750 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13752 + h_file = au_read_pre(file, /*keep_fi*/0);
13753 + err = PTR_ERR(h_file);
13754 + if (IS_ERR(h_file))
13757 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13758 + err = vfsub_read_u(h_file, buf, count, ppos);
13759 + /* todo: necessary? */
13760 + /* file->f_ra = h_file->f_ra; */
13761 + au_read_post(inode, h_file);
13764 + si_read_unlock(sb);
13769 + * todo: very ugly
13770 + * it locks both of i_mutex and si_rwsem for read in safe.
13771 + * if the plink maintenance mode continues forever (that is the problem),
13772 + * may loop forever.
13774 +static void au_mtx_and_read_lock(struct inode *inode)
13777 + struct super_block *sb = inode->i_sb;
13780 + inode_lock(inode);
13781 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13784 + inode_unlock(inode);
13785 + si_read_lock(sb, AuLock_NOPLMW);
13786 + si_read_unlock(sb);
13790 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13791 + size_t count, loff_t *ppos)
13794 + struct au_write_pre wpre;
13795 + struct inode *inode;
13796 + struct file *h_file;
13797 + char __user *buf = (char __user *)ubuf;
13799 + inode = file_inode(file);
13800 + au_mtx_and_read_lock(inode);
13802 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13803 + err = PTR_ERR(h_file);
13804 + if (IS_ERR(h_file))
13807 + err = vfsub_write_u(h_file, buf, count, ppos);
13808 + au_write_post(inode, h_file, &wpre, err);
13811 + si_read_unlock(inode->i_sb);
13812 + inode_unlock(inode);
13816 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13817 + struct iov_iter *iov_iter)
13820 + struct file *file;
13821 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13823 + err = security_file_permission(h_file, rw);
13824 + if (unlikely(err))
13829 + if (rw == MAY_READ)
13830 + iter = h_file->f_op->read_iter;
13831 + else if (rw == MAY_WRITE)
13832 + iter = h_file->f_op->write_iter;
13834 + file = kio->ki_filp;
13835 + kio->ki_filp = h_file;
13838 + err = iter(kio, iov_iter);
13841 + /* currently there is no such fs */
13843 + kio->ki_filp = file;
13849 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13852 + struct file *file, *h_file;
13853 + struct inode *inode;
13854 + struct super_block *sb;
13856 + file = kio->ki_filp;
13857 + inode = file_inode(file);
13858 + sb = inode->i_sb;
13859 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13861 + h_file = au_read_pre(file, /*keep_fi*/1);
13862 + err = PTR_ERR(h_file);
13863 + if (IS_ERR(h_file))
13866 + if (au_test_loopback_kthread()) {
13867 + au_warn_loopback(h_file->f_path.dentry->d_sb);
13868 + if (file->f_mapping != h_file->f_mapping) {
13869 + file->f_mapping = h_file->f_mapping;
13870 + smp_mb(); /* unnecessary? */
13873 + fi_read_unlock(file);
13875 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13876 + /* todo: necessary? */
13877 + /* file->f_ra = h_file->f_ra; */
13878 + au_read_post(inode, h_file);
13881 + si_read_unlock(sb);
13885 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13888 + struct au_write_pre wpre;
13889 + struct inode *inode;
13890 + struct file *file, *h_file;
13892 + file = kio->ki_filp;
13893 + inode = file_inode(file);
13894 + au_mtx_and_read_lock(inode);
13896 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13897 + err = PTR_ERR(h_file);
13898 + if (IS_ERR(h_file))
13901 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13902 + au_write_post(inode, h_file, &wpre, err);
13905 + si_read_unlock(inode->i_sb);
13906 + inode_unlock(inode);
13910 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13911 + struct pipe_inode_info *pipe, size_t len,
13912 + unsigned int flags)
13915 + struct file *h_file;
13916 + struct inode *inode;
13917 + struct super_block *sb;
13919 + inode = file_inode(file);
13920 + sb = inode->i_sb;
13921 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13923 + h_file = au_read_pre(file, /*keep_fi*/0);
13924 + err = PTR_ERR(h_file);
13925 + if (IS_ERR(h_file))
13928 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13929 + /* todo: necessasry? */
13930 + /* file->f_ra = h_file->f_ra; */
13931 + au_read_post(inode, h_file);
13934 + si_read_unlock(sb);
13939 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
13940 + size_t len, unsigned int flags)
13943 + struct au_write_pre wpre;
13944 + struct inode *inode;
13945 + struct file *h_file;
13947 + inode = file_inode(file);
13948 + au_mtx_and_read_lock(inode);
13950 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13951 + err = PTR_ERR(h_file);
13952 + if (IS_ERR(h_file))
13955 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
13956 + au_write_post(inode, h_file, &wpre, err);
13959 + si_read_unlock(inode->i_sb);
13960 + inode_unlock(inode);
13964 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
13968 + struct au_write_pre wpre;
13969 + struct inode *inode;
13970 + struct file *h_file;
13972 + inode = file_inode(file);
13973 + au_mtx_and_read_lock(inode);
13975 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13976 + err = PTR_ERR(h_file);
13977 + if (IS_ERR(h_file))
13981 + err = vfs_fallocate(h_file, mode, offset, len);
13983 + au_write_post(inode, h_file, &wpre, /*written*/1);
13986 + si_read_unlock(inode->i_sb);
13987 + inode_unlock(inode);
13991 +/* ---------------------------------------------------------------------- */
13994 + * The locking order around current->mmap_sem.
13995 + * - in most and regular cases
13996 + * file I/O syscall -- aufs_read() or something
13997 + * -- si_rwsem for read -- mmap_sem
13998 + * (Note that [fdi]i_rwsem are released before mmap_sem).
14000 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
14001 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
14002 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
14003 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
14004 + * It means that when aufs acquires si_rwsem for write, the process should never
14005 + * acquire mmap_sem.
14007 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
14008 + * problem either since any directory is not able to be mmap-ed.
14009 + * The similar scenario is applied to aufs_readlink() too.
14012 +#if 0 /* stop calling security_file_mmap() */
14013 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
14014 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
14016 +static unsigned long au_arch_prot_conv(unsigned long flags)
14018 + /* currently ppc64 only */
14019 +#ifdef CONFIG_PPC64
14020 + /* cf. linux/arch/powerpc/include/asm/mman.h */
14021 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
14022 + return AuConv_VM_PROT(flags, SAO);
14024 + AuDebugOn(arch_calc_vm_prot_bits(-1));
14029 +static unsigned long au_prot_conv(unsigned long flags)
14031 + return AuConv_VM_PROT(flags, READ)
14032 + | AuConv_VM_PROT(flags, WRITE)
14033 + | AuConv_VM_PROT(flags, EXEC)
14034 + | au_arch_prot_conv(flags);
14037 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
14038 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
14040 +static unsigned long au_flag_conv(unsigned long flags)
14042 + return AuConv_VM_MAP(flags, GROWSDOWN)
14043 + | AuConv_VM_MAP(flags, DENYWRITE)
14044 + | AuConv_VM_MAP(flags, LOCKED);
14048 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
14051 + const unsigned char wlock
14052 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
14053 + struct super_block *sb;
14054 + struct file *h_file;
14055 + struct inode *inode;
14057 + AuDbgVmRegion(file, vma);
14059 + inode = file_inode(file);
14060 + sb = inode->i_sb;
14062 + si_read_lock(sb, AuLock_NOPLMW);
14064 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
14066 + err = PTR_ERR(h_file);
14067 + if (IS_ERR(h_file))
14071 + au_set_mmapped(file);
14072 + au_vm_file_reset(vma, h_file);
14074 + * we cannot call security_mmap_file() here since it may acquire
14075 + * mmap_sem or i_mutex.
14077 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
14078 + * au_flag_conv(vma->vm_flags));
14081 + err = h_file->f_op->mmap(h_file, vma);
14083 + au_vm_prfile_set(vma, file);
14084 + fsstack_copy_attr_atime(inode, file_inode(h_file));
14085 + goto out_fput; /* success */
14087 + au_unset_mmapped(file);
14088 + au_vm_file_reset(vma, file);
14092 + ii_write_unlock(inode);
14097 + si_read_unlock(sb);
14103 +/* ---------------------------------------------------------------------- */
14105 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
14109 + struct au_write_pre wpre;
14110 + struct inode *inode;
14111 + struct file *h_file;
14113 + err = 0; /* -EBADF; */ /* posix? */
14114 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14117 + inode = file_inode(file);
14118 + au_mtx_and_read_lock(inode);
14120 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14121 + err = PTR_ERR(h_file);
14122 + if (IS_ERR(h_file))
14125 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
14126 + au_write_post(inode, h_file, &wpre, /*written*/0);
14129 + si_read_unlock(inode->i_sb);
14130 + inode_unlock(inode);
14135 +/* no one supports this operation, currently */
14137 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
14140 + struct au_write_pre wpre;
14141 + struct inode *inode, *h_inode;
14142 + struct file *file, *h_file;
14144 + err = 0; /* -EBADF; */ /* posix? */
14145 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14148 + file = kio->ki_filp;
14149 + inode = file_inode(file);
14150 + au_mtx_and_read_lock(inode);
14152 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14153 + err = PTR_ERR(h_file);
14154 + if (IS_ERR(h_file))
14158 + h_file = au_hf_top(file);
14159 + if (h_file->f_op->aio_fsync) {
14160 + h_inode = file_inode(h_file);
14161 + if (!is_sync_kiocb(kio)) {
14162 + get_file(h_file);
14165 + kio->ki_filp = h_file;
14166 + err = h_file->f_op->aio_fsync(kio, datasync);
14167 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
14169 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
14171 + inode_unlock(h_inode);
14173 + au_write_post(inode, h_file, &wpre, /*written*/0);
14176 + si_read_unlock(inode->sb);
14177 + inode_unlock(inode);
14183 +static int aufs_fasync(int fd, struct file *file, int flag)
14186 + struct file *h_file;
14187 + struct super_block *sb;
14189 + sb = file->f_path.dentry->d_sb;
14190 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14192 + h_file = au_read_pre(file, /*keep_fi*/0);
14193 + err = PTR_ERR(h_file);
14194 + if (IS_ERR(h_file))
14197 + if (h_file->f_op->fasync)
14198 + err = h_file->f_op->fasync(fd, h_file, flag);
14199 + fput(h_file); /* instead of au_read_post() */
14202 + si_read_unlock(sb);
14206 +static int aufs_setfl(struct file *file, unsigned long arg)
14209 + struct file *h_file;
14210 + struct super_block *sb;
14212 + sb = file->f_path.dentry->d_sb;
14213 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14215 + h_file = au_read_pre(file, /*keep_fi*/0);
14216 + err = PTR_ERR(h_file);
14217 + if (IS_ERR(h_file))
14220 + arg |= vfsub_file_flags(file) & FASYNC; /* stop calling h_file->fasync */
14221 + err = setfl(/*unused fd*/-1, h_file, arg);
14222 + fput(h_file); /* instead of au_read_post() */
14225 + si_read_unlock(sb);
14229 +/* ---------------------------------------------------------------------- */
14231 +/* no one supports this operation, currently */
14233 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
14234 + size_t len, loff_t *pos, int more)
14239 +/* ---------------------------------------------------------------------- */
14241 +const struct file_operations aufs_file_fop = {
14242 + .owner = THIS_MODULE,
14244 + .llseek = default_llseek,
14246 + .read = aufs_read,
14247 + .write = aufs_write,
14248 + .read_iter = aufs_read_iter,
14249 + .write_iter = aufs_write_iter,
14251 +#ifdef CONFIG_AUFS_POLL
14252 + .poll = aufs_poll,
14254 + .unlocked_ioctl = aufs_ioctl_nondir,
14255 +#ifdef CONFIG_COMPAT
14256 + .compat_ioctl = aufs_compat_ioctl_nondir,
14258 + .mmap = aufs_mmap,
14259 + .open = aufs_open_nondir,
14260 + .flush = aufs_flush_nondir,
14261 + .release = aufs_release_nondir,
14262 + .fsync = aufs_fsync_nondir,
14263 + /* .aio_fsync = aufs_aio_fsync_nondir, */
14264 + .fasync = aufs_fasync,
14265 + /* .sendpage = aufs_sendpage, */
14266 + .setfl = aufs_setfl,
14267 + .splice_write = aufs_splice_write,
14268 + .splice_read = aufs_splice_read,
14270 + .aio_splice_write = aufs_aio_splice_write,
14271 + .aio_splice_read = aufs_aio_splice_read,
14273 + .fallocate = aufs_fallocate
14275 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14276 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14277 +++ linux/fs/aufs/fstype.h 2016-07-25 19:05:34.814493242 +0200
14280 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14282 + * This program, aufs is free software; you can redistribute it and/or modify
14283 + * it under the terms of the GNU General Public License as published by
14284 + * the Free Software Foundation; either version 2 of the License, or
14285 + * (at your option) any later version.
14287 + * This program is distributed in the hope that it will be useful,
14288 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14289 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14290 + * GNU General Public License for more details.
14292 + * You should have received a copy of the GNU General Public License
14293 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14297 + * judging filesystem type
14300 +#ifndef __AUFS_FSTYPE_H__
14301 +#define __AUFS_FSTYPE_H__
14305 +#include <linux/fs.h>
14306 +#include <linux/magic.h>
14307 +#include <linux/nfs_fs.h>
14308 +#include <linux/romfs_fs.h>
14310 +static inline int au_test_aufs(struct super_block *sb)
14312 + return sb->s_magic == AUFS_SUPER_MAGIC;
14315 +static inline const char *au_sbtype(struct super_block *sb)
14317 + return sb->s_type->name;
14320 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14322 +#if defined(CONFIG_ISO9660_FS) || defined(CONFIG_ISO9660_FS_MODULE)
14323 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14329 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14331 +#if defined(CONFIG_ROMFS_FS) || defined(CONFIG_ROMFS_FS_MODULE)
14332 + return sb->s_magic == ROMFS_MAGIC;
14338 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14340 +#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
14341 + return sb->s_magic == CRAMFS_MAGIC;
14346 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14348 +#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
14349 + return sb->s_magic == NFS_SUPER_MAGIC;
14355 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14357 +#if defined(CONFIG_FUSE_FS) || defined(CONFIG_FUSE_FS_MODULE)
14358 + return sb->s_magic == FUSE_SUPER_MAGIC;
14364 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14366 +#if defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE)
14367 + return sb->s_magic == XFS_SB_MAGIC;
14373 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14375 +#ifdef CONFIG_TMPFS
14376 + return sb->s_magic == TMPFS_MAGIC;
14382 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14384 +#if defined(CONFIG_ECRYPT_FS) || defined(CONFIG_ECRYPT_FS_MODULE)
14385 + return !strcmp(au_sbtype(sb), "ecryptfs");
14391 +static inline int au_test_ramfs(struct super_block *sb)
14393 + return sb->s_magic == RAMFS_MAGIC;
14396 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14398 +#if defined(CONFIG_UBIFS_FS) || defined(CONFIG_UBIFS_FS_MODULE)
14399 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14405 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14407 +#ifdef CONFIG_PROC_FS
14408 + return sb->s_magic == PROC_SUPER_MAGIC;
14414 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14416 +#ifdef CONFIG_SYSFS
14417 + return sb->s_magic == SYSFS_MAGIC;
14423 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14425 +#if defined(CONFIG_CONFIGFS_FS) || defined(CONFIG_CONFIGFS_FS_MODULE)
14426 + return sb->s_magic == CONFIGFS_MAGIC;
14432 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14434 +#if defined(CONFIG_MINIX_FS) || defined(CONFIG_MINIX_FS_MODULE)
14435 + return sb->s_magic == MINIX3_SUPER_MAGIC
14436 + || sb->s_magic == MINIX2_SUPER_MAGIC
14437 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14438 + || sb->s_magic == MINIX_SUPER_MAGIC
14439 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14445 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14447 +#if defined(CONFIG_FAT_FS) || defined(CONFIG_FAT_FS_MODULE)
14448 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14454 +static inline int au_test_msdos(struct super_block *sb)
14456 + return au_test_fat(sb);
14459 +static inline int au_test_vfat(struct super_block *sb)
14461 + return au_test_fat(sb);
14464 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14466 +#ifdef CONFIG_SECURITYFS
14467 + return sb->s_magic == SECURITYFS_MAGIC;
14473 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14475 +#if defined(CONFIG_SQUASHFS) || defined(CONFIG_SQUASHFS_MODULE)
14476 + return sb->s_magic == SQUASHFS_MAGIC;
14482 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14484 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
14485 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14491 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14493 +#if defined(CONFIG_XENFS) || defined(CONFIG_XENFS_MODULE)
14494 + return sb->s_magic == XENFS_SUPER_MAGIC;
14500 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14502 +#ifdef CONFIG_DEBUG_FS
14503 + return sb->s_magic == DEBUGFS_MAGIC;
14509 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14511 +#if defined(CONFIG_NILFS) || defined(CONFIG_NILFS_MODULE)
14512 + return sb->s_magic == NILFS_SUPER_MAGIC;
14518 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14520 +#if defined(CONFIG_HFSPLUS_FS) || defined(CONFIG_HFSPLUS_FS_MODULE)
14521 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14527 +/* ---------------------------------------------------------------------- */
14529 + * they can't be an aufs branch.
14531 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14534 +#ifndef CONFIG_AUFS_BR_RAMFS
14535 + au_test_ramfs(sb) ||
14537 + au_test_procfs(sb)
14538 + || au_test_sysfs(sb)
14539 + || au_test_configfs(sb)
14540 + || au_test_debugfs(sb)
14541 + || au_test_securityfs(sb)
14542 + || au_test_xenfs(sb)
14543 + || au_test_ecryptfs(sb)
14544 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14545 + || au_test_aufs(sb); /* will be supported in next version */
14548 +static inline int au_test_fs_remote(struct super_block *sb)
14550 + return !au_test_tmpfs(sb)
14551 +#ifdef CONFIG_AUFS_BR_RAMFS
14552 + && !au_test_ramfs(sb)
14554 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14557 +/* ---------------------------------------------------------------------- */
14560 + * Note: these functions (below) are created after reading ->getattr() in all
14561 + * filesystems under linux/fs. it means we have to do so in every update...
14565 + * some filesystems require getattr to refresh the inode attributes before
14567 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14568 + * and leave the work for d_revalidate()
14570 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14572 + return au_test_nfs(sb)
14573 + || au_test_fuse(sb)
14574 + /* || au_test_btrfs(sb) */ /* untested */
14579 + * filesystems which don't maintain i_size or i_blocks.
14581 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14583 + return au_test_xfs(sb)
14584 + || au_test_btrfs(sb)
14585 + || au_test_ubifs(sb)
14586 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14587 + /* || au_test_minix(sb) */ /* untested */
14592 + * filesystems which don't store the correct value in some of their inode
14595 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14597 + return au_test_fs_bad_iattr_size(sb)
14598 + || au_test_fat(sb)
14599 + || au_test_msdos(sb)
14600 + || au_test_vfat(sb);
14603 +/* they don't check i_nlink in link(2) */
14604 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14606 + return au_test_tmpfs(sb)
14607 +#ifdef CONFIG_AUFS_BR_RAMFS
14608 + || au_test_ramfs(sb)
14610 + || au_test_ubifs(sb)
14611 + || au_test_hfsplus(sb);
14615 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14617 +static inline int au_test_fs_notime(struct super_block *sb)
14619 + return au_test_nfs(sb)
14620 + || au_test_fuse(sb)
14621 + || au_test_ubifs(sb)
14625 +/* temporary support for i#1 in cramfs */
14626 +static inline int au_test_fs_unique_ino(struct inode *inode)
14628 + if (au_test_cramfs(inode->i_sb))
14629 + return inode->i_ino != 1;
14633 +/* ---------------------------------------------------------------------- */
14636 + * the filesystem where the xino files placed must support i/o after unlink and
14637 + * maintain i_size and i_blocks.
14639 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14641 + return au_test_fs_remote(sb)
14642 + || au_test_fs_bad_iattr_size(sb)
14643 + /* don't want unnecessary work for xino */
14644 + || au_test_aufs(sb)
14645 + || au_test_ecryptfs(sb)
14646 + || au_test_nilfs(sb);
14649 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14651 + return au_test_tmpfs(sb)
14652 + || au_test_ramfs(sb);
14656 + * test if the @sb is real-readonly.
14658 +static inline int au_test_fs_rr(struct super_block *sb)
14660 + return au_test_squashfs(sb)
14661 + || au_test_iso9660(sb)
14662 + || au_test_cramfs(sb)
14663 + || au_test_romfs(sb);
14667 + * test if the @inode is nfs with 'noacl' option
14668 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14670 +static inline int au_test_nfs_noacl(struct inode *inode)
14672 + return au_test_nfs(inode->i_sb)
14673 + /* && IS_POSIXACL(inode) */
14674 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14677 +#endif /* __KERNEL__ */
14678 +#endif /* __AUFS_FSTYPE_H__ */
14679 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14680 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14681 +++ linux/fs/aufs/hfsnotify.c 2016-07-25 19:05:34.814493242 +0200
14684 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14686 + * This program, aufs is free software; you can redistribute it and/or modify
14687 + * it under the terms of the GNU General Public License as published by
14688 + * the Free Software Foundation; either version 2 of the License, or
14689 + * (at your option) any later version.
14691 + * This program is distributed in the hope that it will be useful,
14692 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14693 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14694 + * GNU General Public License for more details.
14696 + * You should have received a copy of the GNU General Public License
14697 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14701 + * fsnotify for the lower directories
14706 +/* FS_IN_IGNORED is unnecessary */
14707 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14708 + | FS_CREATE | FS_EVENT_ON_CHILD);
14709 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14710 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14712 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14714 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14716 + /* AuDbg("here\n"); */
14717 + au_cache_free_hnotify(hn);
14718 + smp_mb__before_atomic();
14719 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14720 + wake_up(&au_hfsn_wq);
14723 +static int au_hfsn_alloc(struct au_hinode *hinode)
14726 + struct au_hnotify *hn;
14727 + struct super_block *sb;
14728 + struct au_branch *br;
14729 + struct fsnotify_mark *mark;
14730 + aufs_bindex_t bindex;
14732 + hn = hinode->hi_notify;
14733 + sb = hn->hn_aufs_inode->i_sb;
14734 + bindex = au_br_index(sb, hinode->hi_id);
14735 + br = au_sbr(sb, bindex);
14736 + AuDebugOn(!br->br_hfsn);
14738 + mark = &hn->hn_mark;
14739 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14740 + mark->mask = AuHfsnMask;
14742 + * by udba rename or rmdir, aufs assign a new inode to the known
14743 + * h_inode, so specify 1 to allow dups.
14746 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14747 + /*mnt*/NULL, /*allow_dups*/1);
14753 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14755 + struct fsnotify_mark *mark;
14756 + unsigned long long ull;
14757 + struct fsnotify_group *group;
14759 + ull = atomic64_inc_return(&au_hfsn_ifree);
14762 + mark = &hn->hn_mark;
14763 + spin_lock(&mark->lock);
14764 + group = mark->group;
14765 + fsnotify_get_group(group);
14766 + spin_unlock(&mark->lock);
14768 + fsnotify_destroy_mark(mark, group);
14769 + fsnotify_put_mark(mark);
14770 + fsnotify_put_group(group);
14773 + /* free hn by myself */
14777 +/* ---------------------------------------------------------------------- */
14779 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14781 + struct fsnotify_mark *mark;
14783 + mark = &hinode->hi_notify->hn_mark;
14784 + spin_lock(&mark->lock);
14786 + AuDebugOn(mark->mask & AuHfsnMask);
14787 + mark->mask |= AuHfsnMask;
14789 + AuDebugOn(!(mark->mask & AuHfsnMask));
14790 + mark->mask &= ~AuHfsnMask;
14792 + spin_unlock(&mark->lock);
14793 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14796 +/* ---------------------------------------------------------------------- */
14798 +/* #define AuDbgHnotify */
14799 +#ifdef AuDbgHnotify
14800 +static char *au_hfsn_name(u32 mask)
14802 +#ifdef CONFIG_AUFS_DEBUG
14803 +#define test_ret(flag) \
14805 + if (mask & flag) \
14808 + test_ret(FS_ACCESS);
14809 + test_ret(FS_MODIFY);
14810 + test_ret(FS_ATTRIB);
14811 + test_ret(FS_CLOSE_WRITE);
14812 + test_ret(FS_CLOSE_NOWRITE);
14813 + test_ret(FS_OPEN);
14814 + test_ret(FS_MOVED_FROM);
14815 + test_ret(FS_MOVED_TO);
14816 + test_ret(FS_CREATE);
14817 + test_ret(FS_DELETE);
14818 + test_ret(FS_DELETE_SELF);
14819 + test_ret(FS_MOVE_SELF);
14820 + test_ret(FS_UNMOUNT);
14821 + test_ret(FS_Q_OVERFLOW);
14822 + test_ret(FS_IN_IGNORED);
14823 + test_ret(FS_ISDIR);
14824 + test_ret(FS_IN_ONESHOT);
14825 + test_ret(FS_EVENT_ON_CHILD);
14834 +/* ---------------------------------------------------------------------- */
14836 +static void au_hfsn_free_group(struct fsnotify_group *group)
14838 + struct au_br_hfsnotify *hfsn = group->private;
14840 + /* AuDbg("here\n"); */
14844 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14845 + struct inode *inode,
14846 + struct fsnotify_mark *inode_mark,
14847 + struct fsnotify_mark *vfsmount_mark,
14848 + u32 mask, void *data, int data_type,
14849 + const unsigned char *file_name, u32 cookie)
14852 + struct au_hnotify *hnotify;
14853 + struct inode *h_dir, *h_inode;
14854 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14856 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14859 + /* if FS_UNMOUNT happens, there must be another bug */
14860 + AuDebugOn(mask & FS_UNMOUNT);
14861 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14866 +#ifdef AuDbgHnotify
14868 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14869 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14870 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14871 + h_dir->i_ino, mask, au_hfsn_name(mask),
14872 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14873 + /* WARN_ON(1); */
14878 + AuDebugOn(!inode_mark);
14879 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14880 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14886 +static struct fsnotify_ops au_hfsn_ops = {
14887 + .handle_event = au_hfsn_handle_event,
14888 + .free_group_priv = au_hfsn_free_group
14891 +/* ---------------------------------------------------------------------- */
14893 +static void au_hfsn_fin_br(struct au_branch *br)
14895 + struct au_br_hfsnotify *hfsn;
14897 + hfsn = br->br_hfsn;
14900 + fsnotify_put_group(hfsn->hfsn_group);
14905 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14908 + struct fsnotify_group *group;
14909 + struct au_br_hfsnotify *hfsn;
14912 + br->br_hfsn = NULL;
14913 + if (!au_br_hnotifyable(perm))
14917 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14918 + if (unlikely(!hfsn))
14922 + group = fsnotify_alloc_group(&au_hfsn_ops);
14923 + if (IS_ERR(group)) {
14924 + err = PTR_ERR(group);
14925 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14929 + group->private = hfsn;
14930 + hfsn->hfsn_group = group;
14931 + br->br_hfsn = hfsn;
14932 + goto out; /* success */
14940 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14945 + if (!br->br_hfsn)
14946 + err = au_hfsn_init_br(br, perm);
14951 +/* ---------------------------------------------------------------------- */
14953 +static void au_hfsn_fin(void)
14955 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14956 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14959 +const struct au_hnotify_op au_hnotify_op = {
14960 + .ctl = au_hfsn_ctl,
14961 + .alloc = au_hfsn_alloc,
14962 + .free = au_hfsn_free,
14964 + .fin = au_hfsn_fin,
14966 + .reset_br = au_hfsn_reset_br,
14967 + .fin_br = au_hfsn_fin_br,
14968 + .init_br = au_hfsn_init_br
14970 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14971 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14972 +++ linux/fs/aufs/hfsplus.c 2016-07-25 19:05:34.814493242 +0200
14975 + * Copyright (C) 2010-2016 Junjiro R. Okajima
14977 + * This program, aufs is free software; you can redistribute it and/or modify
14978 + * it under the terms of the GNU General Public License as published by
14979 + * the Free Software Foundation; either version 2 of the License, or
14980 + * (at your option) any later version.
14982 + * This program is distributed in the hope that it will be useful,
14983 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14984 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14985 + * GNU General Public License for more details.
14987 + * You should have received a copy of the GNU General Public License
14988 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14992 + * special support for filesystems which aqucires an inode mutex
14993 + * at final closing a file, eg, hfsplus.
14995 + * This trick is very simple and stupid, just to open the file before really
14996 + * neceeary open to tell hfsplus that this is not the final closing.
14997 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
14998 + * and au_h_open_post() after releasing it.
15003 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15006 + struct file *h_file;
15007 + struct dentry *h_dentry;
15009 + h_dentry = au_h_dptr(dentry, bindex);
15010 + AuDebugOn(!h_dentry);
15011 + AuDebugOn(d_is_negative(h_dentry));
15014 + if (au_test_hfsplus(h_dentry->d_sb)
15015 + && d_is_reg(h_dentry))
15016 + h_file = au_h_open(dentry, bindex,
15017 + O_RDONLY | O_NOATIME | O_LARGEFILE,
15018 + /*file*/NULL, force_wr);
15022 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15023 + struct file *h_file)
15027 + au_sbr_put(dentry->d_sb, bindex);
15030 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
15031 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
15032 +++ linux/fs/aufs/hnotify.c 2016-07-25 19:05:34.814493242 +0200
15035 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15037 + * This program, aufs is free software; you can redistribute it and/or modify
15038 + * it under the terms of the GNU General Public License as published by
15039 + * the Free Software Foundation; either version 2 of the License, or
15040 + * (at your option) any later version.
15042 + * This program is distributed in the hope that it will be useful,
15043 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15044 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15045 + * GNU General Public License for more details.
15047 + * You should have received a copy of the GNU General Public License
15048 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15052 + * abstraction to notify the direct changes on lower directories
15057 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
15060 + struct au_hnotify *hn;
15063 + hn = au_cache_alloc_hnotify();
15065 + hn->hn_aufs_inode = inode;
15066 + hinode->hi_notify = hn;
15067 + err = au_hnotify_op.alloc(hinode);
15069 + if (unlikely(err)) {
15070 + hinode->hi_notify = NULL;
15071 + au_cache_free_hnotify(hn);
15073 + * The upper dir was removed by udba, but the same named
15074 + * dir left. In this case, aufs assignes a new inode
15075 + * number and set the monitor again.
15076 + * For the lower dir, the old monitnor is still left.
15078 + if (err == -EEXIST)
15087 +void au_hn_free(struct au_hinode *hinode)
15089 + struct au_hnotify *hn;
15091 + hn = hinode->hi_notify;
15093 + hinode->hi_notify = NULL;
15094 + if (au_hnotify_op.free(hinode, hn))
15095 + au_cache_free_hnotify(hn);
15099 +/* ---------------------------------------------------------------------- */
15101 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
15103 + if (hinode->hi_notify)
15104 + au_hnotify_op.ctl(hinode, do_set);
15107 +void au_hn_reset(struct inode *inode, unsigned int flags)
15109 + aufs_bindex_t bindex, bbot;
15110 + struct inode *hi;
15111 + struct dentry *iwhdentry;
15113 + bbot = au_ibbot(inode);
15114 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
15115 + hi = au_h_iptr(inode, bindex);
15119 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
15120 + iwhdentry = au_hi_wh(inode, bindex);
15124 + au_set_h_iptr(inode, bindex, NULL, 0);
15125 + au_set_h_iptr(inode, bindex, au_igrab(hi),
15126 + flags & ~AuHi_XINO);
15129 + /* inode_unlock(hi); */
15133 +/* ---------------------------------------------------------------------- */
15135 +static int hn_xino(struct inode *inode, struct inode *h_inode)
15138 + aufs_bindex_t bindex, bbot, bfound, btop;
15139 + struct inode *h_i;
15142 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15143 + pr_warn("branch root dir was changed\n");
15148 + bbot = au_ibbot(inode);
15149 + btop = au_ibtop(inode);
15150 +#if 0 /* reserved for future use */
15151 + if (bindex == bbot) {
15152 + /* keep this ino in rename case */
15156 + for (bindex = btop; bindex <= bbot; bindex++)
15157 + if (au_h_iptr(inode, bindex) == h_inode) {
15164 + for (bindex = btop; bindex <= bbot; bindex++) {
15165 + h_i = au_h_iptr(inode, bindex);
15169 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
15170 + /* ignore this error */
15171 + /* bad action? */
15174 + /* children inode number will be broken */
15181 +static int hn_gen_tree(struct dentry *dentry)
15183 + int err, i, j, ndentry;
15184 + struct au_dcsub_pages dpages;
15185 + struct au_dpage *dpage;
15186 + struct dentry **dentries;
15188 + err = au_dpages_init(&dpages, GFP_NOFS);
15189 + if (unlikely(err))
15191 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
15192 + if (unlikely(err))
15195 + for (i = 0; i < dpages.ndpage; i++) {
15196 + dpage = dpages.dpages + i;
15197 + dentries = dpage->dentries;
15198 + ndentry = dpage->ndentry;
15199 + for (j = 0; j < ndentry; j++) {
15200 + struct dentry *d;
15207 + if (d_really_is_positive(d))
15208 + /* todo: reset children xino?
15209 + cached children only? */
15210 + au_iigen_dec(d_inode(d));
15215 + au_dpages_free(&dpages);
15218 + /* discard children */
15219 + dentry_unhash(dentry);
15227 + * return 0 if processed.
15229 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
15230 + const unsigned int isdir)
15233 + struct dentry *d;
15234 + struct qstr *dname;
15237 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15238 + pr_warn("branch root dir was changed\n");
15244 + AuDebugOn(!name);
15245 + au_iigen_dec(inode);
15246 + spin_lock(&inode->i_lock);
15247 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
15248 + spin_lock(&d->d_lock);
15249 + dname = &d->d_name;
15250 + if (dname->len != nlen
15251 + && memcmp(dname->name, name, nlen)) {
15252 + spin_unlock(&d->d_lock);
15257 + spin_unlock(&d->d_lock);
15260 + spin_unlock(&inode->i_lock);
15262 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15263 + d = d_find_any_alias(inode);
15265 + au_iigen_dec(inode);
15269 + spin_lock(&d->d_lock);
15270 + dname = &d->d_name;
15271 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15272 + spin_unlock(&d->d_lock);
15273 + err = hn_gen_tree(d);
15274 + spin_lock(&d->d_lock);
15276 + spin_unlock(&d->d_lock);
15285 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15289 + if (IS_ROOT(dentry)) {
15290 + pr_warn("branch root dir was changed\n");
15296 + au_digen_dec(dentry);
15297 + if (d_really_is_positive(dentry))
15298 + au_iigen_dec(d_inode(dentry));
15300 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15301 + if (d_really_is_positive(dentry))
15302 + err = hn_gen_tree(dentry);
15309 +/* ---------------------------------------------------------------------- */
15311 +/* hnotify job flags */
15312 +#define AuHnJob_XINO0 1
15313 +#define AuHnJob_GEN (1 << 1)
15314 +#define AuHnJob_DIRENT (1 << 2)
15315 +#define AuHnJob_ISDIR (1 << 3)
15316 +#define AuHnJob_TRYXINO0 (1 << 4)
15317 +#define AuHnJob_MNTPNT (1 << 5)
15318 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15319 +#define au_fset_hnjob(flags, name) \
15320 + do { (flags) |= AuHnJob_##name; } while (0)
15321 +#define au_fclr_hnjob(flags, name) \
15322 + do { (flags) &= ~AuHnJob_##name; } while (0)
15330 +struct au_hnotify_args {
15331 + struct inode *h_dir, *dir, *h_child_inode;
15333 + unsigned int flags[AuHnLast];
15334 + unsigned int h_child_nlen;
15335 + char h_child_name[];
15338 +struct hn_job_args {
15339 + unsigned int flags;
15340 + struct inode *inode, *h_inode, *dir, *h_dir;
15341 + struct dentry *dentry;
15346 +static int hn_job(struct hn_job_args *a)
15348 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15352 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15353 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15355 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15358 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
15359 + if (!a->h_inode->i_nlink
15360 + && !(a->h_inode->i_state & I_LINKABLE))
15361 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15362 + inode_unlock(a->h_inode);
15365 + /* make the generation obsolete */
15366 + if (au_ftest_hnjob(a->flags, GEN)) {
15369 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15371 + if (e && a->dentry)
15372 + hn_gen_by_name(a->dentry, isdir);
15373 + /* ignore this error */
15376 + /* make dir entries obsolete */
15377 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15378 + struct au_vdir *vdir;
15380 + vdir = au_ivdir(a->inode);
15382 + vdir->vd_jiffy = 0;
15383 + /* IMustLock(a->inode); */
15384 + /* a->inode->i_version++; */
15387 + /* can do nothing but warn */
15388 + if (au_ftest_hnjob(a->flags, MNTPNT)
15390 + && d_mountpoint(a->dentry))
15391 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15396 +/* ---------------------------------------------------------------------- */
15398 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15399 + struct inode *dir)
15401 + struct dentry *dentry, *d, *parent;
15402 + struct qstr *dname;
15404 + parent = d_find_any_alias(dir);
15409 + spin_lock(&parent->d_lock);
15410 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15411 + /* AuDbg("%pd\n", d); */
15412 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15413 + dname = &d->d_name;
15414 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15415 + goto cont_unlock;
15419 + goto cont_unlock;
15420 + if (au_dcount(d) > 0) {
15421 + dentry = dget_dlock(d);
15422 + spin_unlock(&d->d_lock);
15427 + spin_unlock(&d->d_lock);
15429 + spin_unlock(&parent->d_lock);
15433 + di_write_lock_child(dentry);
15438 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15439 + aufs_bindex_t bindex, ino_t h_ino)
15441 + struct inode *inode;
15446 + err = au_xino_read(sb, bindex, h_ino, &ino);
15448 + inode = ilookup(sb, ino);
15452 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15453 + pr_warn("wrong root branch\n");
15459 + ii_write_lock_child(inode);
15465 +static void au_hn_bh(void *_args)
15467 + struct au_hnotify_args *a = _args;
15468 + struct super_block *sb;
15469 + aufs_bindex_t bindex, bbot, bfound;
15470 + unsigned char xino, try_iput;
15472 + struct inode *inode;
15474 + struct hn_job_args args;
15475 + struct dentry *dentry;
15476 + struct au_sbinfo *sbinfo;
15478 + AuDebugOn(!_args);
15479 + AuDebugOn(!a->h_dir);
15480 + AuDebugOn(!a->dir);
15481 + AuDebugOn(!a->mask);
15482 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15483 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15484 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15489 + * do not lock a->dir->i_mutex here
15490 + * because of d_revalidate() may cause a deadlock.
15492 + sb = a->dir->i_sb;
15494 + sbinfo = au_sbi(sb);
15495 + AuDebugOn(!sbinfo);
15496 + si_write_lock(sb, AuLock_NOPLMW);
15498 + ii_read_lock_parent(a->dir);
15500 + bbot = au_ibbot(a->dir);
15501 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
15502 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15506 + ii_read_unlock(a->dir);
15507 + if (unlikely(bfound < 0))
15510 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15512 + if (a->h_child_inode)
15513 + h_ino = a->h_child_inode->i_ino;
15515 + if (a->h_child_nlen
15516 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15517 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15518 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15521 + if (dentry && d_really_is_positive(dentry))
15522 + inode = d_inode(dentry);
15523 + if (xino && !inode && h_ino
15524 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15525 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15526 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15527 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15531 + args.flags = a->flags[AuHn_CHILD];
15532 + args.dentry = dentry;
15533 + args.inode = inode;
15534 + args.h_inode = a->h_child_inode;
15535 + args.dir = a->dir;
15536 + args.h_dir = a->h_dir;
15537 + args.h_name = a->h_child_name;
15538 + args.h_nlen = a->h_child_nlen;
15539 + err = hn_job(&args);
15541 + if (au_di(dentry))
15542 + di_write_unlock(dentry);
15545 + if (inode && try_iput) {
15546 + ii_write_unlock(inode);
15550 + ii_write_lock_parent(a->dir);
15551 + args.flags = a->flags[AuHn_PARENT];
15552 + args.dentry = NULL;
15553 + args.inode = a->dir;
15554 + args.h_inode = a->h_dir;
15556 + args.h_dir = NULL;
15557 + args.h_name = NULL;
15559 + err = hn_job(&args);
15560 + ii_write_unlock(a->dir);
15563 + iput(a->h_child_inode);
15566 + si_write_unlock(sb);
15567 + au_nwt_done(&sbinfo->si_nowait);
15571 +/* ---------------------------------------------------------------------- */
15573 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15574 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15577 + unsigned int flags[AuHnLast], f;
15578 + unsigned char isdir, isroot, wh;
15579 + struct inode *dir;
15580 + struct au_hnotify_args *args;
15581 + char *p, *h_child_name;
15584 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15585 + dir = igrab(hnotify->hn_aufs_inode);
15589 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15591 + h_child_name = (void *)h_child_qstr->name;
15592 + len = h_child_qstr->len;
15593 + if (h_child_name) {
15594 + if (len > AUFS_WH_PFX_LEN
15595 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15596 + h_child_name += AUFS_WH_PFX_LEN;
15597 + len -= AUFS_WH_PFX_LEN;
15603 + if (h_child_inode)
15604 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15605 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15606 + flags[AuHn_CHILD] = 0;
15608 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15609 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15610 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15611 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15612 + case FS_MOVED_FROM:
15613 + case FS_MOVED_TO:
15614 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15615 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15618 + AuDebugOn(!h_child_name);
15623 + * aufs never be able to get this child inode.
15624 + * revalidation should be in d_revalidate()
15625 + * by checking i_nlink, i_generation or d_unhashed().
15627 + AuDebugOn(!h_child_name);
15628 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15629 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15637 + h_child_inode = NULL;
15640 + /* iput() and kfree() will be called in au_hnotify() */
15641 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15642 + if (unlikely(!args)) {
15643 + AuErr1("no memory\n");
15647 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15648 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15649 + args->mask = mask;
15651 + args->h_dir = igrab(h_dir);
15652 + if (h_child_inode)
15653 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15654 + args->h_child_inode = h_child_inode;
15655 + args->h_child_nlen = len;
15657 + p = (void *)args;
15658 + p += sizeof(*args);
15659 + memcpy(p, h_child_name, len);
15663 + /* NFS fires the event for silly-renamed one from kworker */
15665 + if (!dir->i_nlink
15666 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15668 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15669 + if (unlikely(err)) {
15670 + pr_err("wkq %d\n", err);
15671 + iput(args->h_child_inode);
15672 + iput(args->h_dir);
15681 +/* ---------------------------------------------------------------------- */
15683 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15687 + AuDebugOn(!(udba & AuOptMask_UDBA));
15690 + if (au_hnotify_op.reset_br)
15691 + err = au_hnotify_op.reset_br(udba, br, perm);
15696 +int au_hnotify_init_br(struct au_branch *br, int perm)
15701 + if (au_hnotify_op.init_br)
15702 + err = au_hnotify_op.init_br(br, perm);
15707 +void au_hnotify_fin_br(struct au_branch *br)
15709 + if (au_hnotify_op.fin_br)
15710 + au_hnotify_op.fin_br(br);
15713 +static void au_hn_destroy_cache(void)
15715 + kmem_cache_destroy(au_cachep[AuCache_HNOTIFY]);
15716 + au_cachep[AuCache_HNOTIFY] = NULL;
15719 +int __init au_hnotify_init(void)
15724 + au_cachep[AuCache_HNOTIFY] = AuCache(au_hnotify);
15725 + if (au_cachep[AuCache_HNOTIFY]) {
15727 + if (au_hnotify_op.init)
15728 + err = au_hnotify_op.init();
15729 + if (unlikely(err))
15730 + au_hn_destroy_cache();
15736 +void au_hnotify_fin(void)
15738 + if (au_hnotify_op.fin)
15739 + au_hnotify_op.fin();
15740 + /* cf. au_cache_fin() */
15741 + if (au_cachep[AuCache_HNOTIFY])
15742 + au_hn_destroy_cache();
15744 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15745 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15746 +++ linux/fs/aufs/iinfo.c 2016-07-25 19:05:34.814493242 +0200
15749 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15751 + * This program, aufs is free software; you can redistribute it and/or modify
15752 + * it under the terms of the GNU General Public License as published by
15753 + * the Free Software Foundation; either version 2 of the License, or
15754 + * (at your option) any later version.
15756 + * This program is distributed in the hope that it will be useful,
15757 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15758 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15759 + * GNU General Public License for more details.
15761 + * You should have received a copy of the GNU General Public License
15762 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15766 + * inode private data
15771 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15773 + struct inode *h_inode;
15774 + struct au_hinode *hinode;
15776 + IiMustAnyLock(inode);
15778 + hinode = au_hinode(au_ii(inode), bindex);
15779 + h_inode = hinode->hi_inode;
15780 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15784 +/* todo: hard/soft set? */
15785 +void au_hiput(struct au_hinode *hinode)
15787 + au_hn_free(hinode);
15788 + dput(hinode->hi_whdentry);
15789 + iput(hinode->hi_inode);
15792 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15794 + unsigned int flags;
15795 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15798 + if (au_opt_test(mnt_flags, XINO))
15799 + au_fset_hi(flags, XINO);
15800 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15801 + au_fset_hi(flags, HNOTIFY);
15805 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15806 + struct inode *h_inode, unsigned int flags)
15808 + struct au_hinode *hinode;
15809 + struct inode *hi;
15810 + struct au_iinfo *iinfo = au_ii(inode);
15812 + IiMustWriteLock(inode);
15814 + hinode = au_hinode(iinfo, bindex);
15815 + hi = hinode->hi_inode;
15816 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15819 + au_hiput(hinode);
15820 + hinode->hi_inode = h_inode;
15823 + struct super_block *sb = inode->i_sb;
15824 + struct au_branch *br;
15826 + AuDebugOn(inode->i_mode
15827 + && (h_inode->i_mode & S_IFMT)
15828 + != (inode->i_mode & S_IFMT));
15829 + if (bindex == iinfo->ii_btop)
15830 + au_cpup_igen(inode, h_inode);
15831 + br = au_sbr(sb, bindex);
15832 + hinode->hi_id = br->br_id;
15833 + if (au_ftest_hi(flags, XINO)) {
15834 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15836 + if (unlikely(err))
15837 + AuIOErr1("failed au_xino_write() %d\n", err);
15840 + if (au_ftest_hi(flags, HNOTIFY)
15841 + && au_br_hnotifyable(br->br_perm)) {
15842 + err = au_hn_alloc(hinode, inode);
15843 + if (unlikely(err))
15844 + AuIOErr1("au_hn_alloc() %d\n", err);
15849 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15850 + struct dentry *h_wh)
15852 + struct au_hinode *hinode;
15854 + IiMustWriteLock(inode);
15856 + hinode = au_hinode(au_ii(inode), bindex);
15857 + AuDebugOn(hinode->hi_whdentry);
15858 + hinode->hi_whdentry = h_wh;
15861 +void au_update_iigen(struct inode *inode, int half)
15863 + struct au_iinfo *iinfo;
15864 + struct au_iigen *iigen;
15865 + unsigned int sigen;
15867 + sigen = au_sigen(inode->i_sb);
15868 + iinfo = au_ii(inode);
15869 + iigen = &iinfo->ii_generation;
15870 + spin_lock(&iigen->ig_spin);
15871 + iigen->ig_generation = sigen;
15873 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15875 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15876 + spin_unlock(&iigen->ig_spin);
15879 +/* it may be called at remount time, too */
15880 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15882 + struct au_iinfo *iinfo;
15883 + aufs_bindex_t bindex, bbot;
15885 + AuDebugOn(au_is_bad_inode(inode));
15886 + IiMustWriteLock(inode);
15888 + iinfo = au_ii(inode);
15889 + if (do_put_zero && iinfo->ii_btop >= 0) {
15890 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
15892 + struct inode *h_i;
15894 + h_i = au_hinode(iinfo, bindex)->hi_inode;
15897 + && !(h_i->i_state & I_LINKABLE))
15898 + au_set_h_iptr(inode, bindex, NULL, 0);
15902 + iinfo->ii_btop = -1;
15903 + iinfo->ii_bbot = -1;
15904 + bbot = au_sbbot(inode->i_sb);
15905 + for (bindex = 0; bindex <= bbot; bindex++)
15906 + if (au_hinode(iinfo, bindex)->hi_inode) {
15907 + iinfo->ii_btop = bindex;
15910 + if (iinfo->ii_btop >= 0)
15911 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
15912 + if (au_hinode(iinfo, bindex)->hi_inode) {
15913 + iinfo->ii_bbot = bindex;
15916 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
15919 +/* ---------------------------------------------------------------------- */
15921 +void au_icntnr_init_once(void *_c)
15923 + struct au_icntnr *c = _c;
15924 + struct au_iinfo *iinfo = &c->iinfo;
15926 + spin_lock_init(&iinfo->ii_generation.ig_spin);
15927 + au_rw_init(&iinfo->ii_rwsem);
15928 + inode_init_once(&c->vfs_inode);
15931 +void au_hinode_init(struct au_hinode *hinode)
15933 + hinode->hi_inode = NULL;
15934 + hinode->hi_id = -1;
15935 + au_hn_init(hinode);
15936 + hinode->hi_whdentry = NULL;
15939 +int au_iinfo_init(struct inode *inode)
15941 + struct au_iinfo *iinfo;
15942 + struct super_block *sb;
15943 + struct au_hinode *hi;
15946 + sb = inode->i_sb;
15947 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15948 + nbr = au_sbbot(sb) + 1;
15949 + if (unlikely(nbr <= 0))
15951 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15953 + au_ninodes_inc(sb);
15955 + iinfo->ii_hinode = hi;
15956 + for (i = 0; i < nbr; i++, hi++)
15957 + au_hinode_init(hi);
15959 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15960 + iinfo->ii_btop = -1;
15961 + iinfo->ii_bbot = -1;
15962 + iinfo->ii_vdir = NULL;
15968 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr)
15971 + struct au_hinode *hip;
15973 + AuRwMustWriteLock(&iinfo->ii_rwsem);
15976 + hip = krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS);
15978 + iinfo->ii_hinode = hip;
15979 + i = iinfo->ii_bbot + 1;
15981 + for (; i < nbr; i++, hip++)
15982 + au_hinode_init(hip);
15989 +void au_iinfo_fin(struct inode *inode)
15991 + struct au_iinfo *iinfo;
15992 + struct au_hinode *hi;
15993 + struct super_block *sb;
15994 + aufs_bindex_t bindex, bbot;
15995 + const unsigned char unlinked = !inode->i_nlink;
15997 + AuDebugOn(au_is_bad_inode(inode));
15999 + sb = inode->i_sb;
16000 + au_ninodes_dec(sb);
16001 + if (si_pid_test(sb))
16002 + au_xino_delete_inode(inode, unlinked);
16005 + * it is safe to hide the dependency between sbinfo and
16009 + si_noflush_read_lock(sb);
16010 + au_xino_delete_inode(inode, unlinked);
16011 + si_read_unlock(sb);
16015 + iinfo = au_ii(inode);
16016 + if (iinfo->ii_vdir)
16017 + au_vdir_free(iinfo->ii_vdir);
16019 + bindex = iinfo->ii_btop;
16020 + if (bindex >= 0) {
16021 + hi = au_hinode(iinfo, bindex);
16022 + bbot = iinfo->ii_bbot;
16023 + while (bindex++ <= bbot) {
16024 + if (hi->hi_inode)
16029 + kfree(iinfo->ii_hinode);
16030 + AuRwDestroy(&iinfo->ii_rwsem);
16032 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
16033 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
16034 +++ linux/fs/aufs/inode.c 2016-07-25 19:05:34.814493242 +0200
16037 + * Copyright (C) 2005-2016 Junjiro R. Okajima
16039 + * This program, aufs is free software; you can redistribute it and/or modify
16040 + * it under the terms of the GNU General Public License as published by
16041 + * the Free Software Foundation; either version 2 of the License, or
16042 + * (at your option) any later version.
16044 + * This program is distributed in the hope that it will be useful,
16045 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16046 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16047 + * GNU General Public License for more details.
16049 + * You should have received a copy of the GNU General Public License
16050 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16054 + * inode functions
16059 +struct inode *au_igrab(struct inode *inode)
16062 + AuDebugOn(!atomic_read(&inode->i_count));
16068 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
16070 + au_cpup_attr_all(inode, /*force*/0);
16071 + au_update_iigen(inode, /*half*/1);
16073 + inode->i_version++;
16076 +static int au_ii_refresh(struct inode *inode, int *update)
16080 + aufs_bindex_t bindex, new_bindex;
16081 + struct super_block *sb;
16082 + struct au_iinfo *iinfo;
16083 + struct au_hinode *p, *q, tmp;
16085 + AuDebugOn(au_is_bad_inode(inode));
16086 + IiMustWriteLock(inode);
16089 + sb = inode->i_sb;
16090 + type = inode->i_mode & S_IFMT;
16091 + iinfo = au_ii(inode);
16092 + err = au_hinode_realloc(iinfo, au_sbbot(sb) + 1);
16093 + if (unlikely(err))
16096 + AuDebugOn(iinfo->ii_btop < 0);
16097 + p = au_hinode(iinfo, iinfo->ii_btop);
16098 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
16100 + if (!p->hi_inode)
16103 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
16104 + new_bindex = au_br_index(sb, p->hi_id);
16105 + if (new_bindex == bindex)
16108 + if (new_bindex < 0) {
16111 + p->hi_inode = NULL;
16115 + if (new_bindex < iinfo->ii_btop)
16116 + iinfo->ii_btop = new_bindex;
16117 + if (iinfo->ii_bbot < new_bindex)
16118 + iinfo->ii_bbot = new_bindex;
16119 + /* swap two lower inode, and loop again */
16120 + q = au_hinode(iinfo, new_bindex);
16124 + if (tmp.hi_inode) {
16129 + au_update_ibrange(inode, /*do_put_zero*/0);
16130 + e = au_dy_irefresh(inode);
16131 + if (unlikely(e && !err))
16139 +void au_refresh_iop(struct inode *inode, int force_getattr)
16142 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
16143 + const struct inode_operations *iop
16144 + = force_getattr ? aufs_iop : sbi->si_iop_array;
16146 + if (inode->i_op == iop)
16149 + switch (inode->i_mode & S_IFMT) {
16151 + type = AuIop_DIR;
16154 + type = AuIop_SYMLINK;
16157 + type = AuIop_OTHER;
16161 + inode->i_op = iop + type;
16162 + /* unnecessary smp_wmb() */
16165 +int au_refresh_hinode_self(struct inode *inode)
16169 + err = au_ii_refresh(inode, &update);
16171 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
16177 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
16179 + int err, e, update;
16180 + unsigned int flags;
16182 + aufs_bindex_t bindex, bbot;
16183 + unsigned char isdir;
16184 + struct au_hinode *p;
16185 + struct au_iinfo *iinfo;
16187 + err = au_ii_refresh(inode, &update);
16188 + if (unlikely(err))
16192 + iinfo = au_ii(inode);
16193 + p = au_hinode(iinfo, iinfo->ii_btop);
16194 + mode = (inode->i_mode & S_IFMT);
16195 + isdir = S_ISDIR(mode);
16196 + flags = au_hi_flags(inode, isdir);
16197 + bbot = au_dbbot(dentry);
16198 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
16199 + struct inode *h_i, *h_inode;
16200 + struct dentry *h_d;
16202 + h_d = au_h_dptr(dentry, bindex);
16203 + if (!h_d || d_is_negative(h_d))
16206 + h_inode = d_inode(h_d);
16207 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
16208 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
16209 + h_i = au_h_iptr(inode, bindex);
16211 + if (h_i == h_inode)
16217 + if (bindex < iinfo->ii_btop)
16218 + iinfo->ii_btop = bindex;
16219 + if (iinfo->ii_bbot < bindex)
16220 + iinfo->ii_bbot = bindex;
16221 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
16224 + au_update_ibrange(inode, /*do_put_zero*/0);
16225 + e = au_dy_irefresh(inode);
16226 + if (unlikely(e && !err))
16229 + au_refresh_hinode_attr(inode, update && isdir);
16236 +static int set_inode(struct inode *inode, struct dentry *dentry)
16239 + unsigned int flags;
16241 + aufs_bindex_t bindex, btop, btail;
16242 + unsigned char isdir;
16243 + struct dentry *h_dentry;
16244 + struct inode *h_inode;
16245 + struct au_iinfo *iinfo;
16246 + struct inode_operations *iop;
16248 + IiMustWriteLock(inode);
16252 + iop = au_sbi(inode->i_sb)->si_iop_array;
16253 + btop = au_dbtop(dentry);
16254 + h_dentry = au_h_dptr(dentry, btop);
16255 + h_inode = d_inode(h_dentry);
16256 + mode = h_inode->i_mode;
16257 + switch (mode & S_IFMT) {
16259 + btail = au_dbtail(dentry);
16260 + inode->i_op = iop + AuIop_OTHER;
16261 + inode->i_fop = &aufs_file_fop;
16262 + err = au_dy_iaop(inode, btop, h_inode);
16263 + if (unlikely(err))
16268 + btail = au_dbtaildir(dentry);
16269 + inode->i_op = iop + AuIop_DIR;
16270 + inode->i_fop = &aufs_dir_fop;
16273 + btail = au_dbtail(dentry);
16274 + inode->i_op = iop + AuIop_SYMLINK;
16280 + btail = au_dbtail(dentry);
16281 + inode->i_op = iop + AuIop_OTHER;
16282 + init_special_inode(inode, mode, h_inode->i_rdev);
16285 + AuIOErr("Unknown file type 0%o\n", mode);
16290 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
16291 + flags = au_hi_flags(inode, isdir);
16292 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
16293 + && au_ftest_hi(flags, HNOTIFY)
16294 + && dentry->d_name.len > AUFS_WH_PFX_LEN
16295 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
16296 + au_fclr_hi(flags, HNOTIFY);
16297 + iinfo = au_ii(inode);
16298 + iinfo->ii_btop = btop;
16299 + iinfo->ii_bbot = btail;
16300 + for (bindex = btop; bindex <= btail; bindex++) {
16301 + h_dentry = au_h_dptr(dentry, bindex);
16303 + au_set_h_iptr(inode, bindex,
16304 + au_igrab(d_inode(h_dentry)), flags);
16306 + au_cpup_attr_all(inode, /*force*/1);
16308 + * to force calling aufs_get_acl() every time,
16309 + * do not call cache_no_acl() for aufs inode.
16317 + * successful returns with iinfo write_locked
16319 + * zero: success, matched
16320 + * plus: no error, but unmatched
16322 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16325 + unsigned int gen, igflags;
16326 + aufs_bindex_t bindex, bbot;
16327 + struct inode *h_inode, *h_dinode;
16328 + struct dentry *h_dentry;
16331 + * before this function, if aufs got any iinfo lock, it must be only
16332 + * one, the parent dir.
16333 + * it can happen by UDBA and the obsoleted inode number.
16336 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16340 + ii_write_lock_new_child(inode);
16341 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
16342 + h_dinode = d_inode(h_dentry);
16343 + bbot = au_ibbot(inode);
16344 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
16345 + h_inode = au_h_iptr(inode, bindex);
16346 + if (!h_inode || h_inode != h_dinode)
16350 + gen = au_iigen(inode, &igflags);
16351 + if (gen == au_digen(dentry)
16352 + && !au_ig_ftest(igflags, HALF_REFRESHED))
16355 + /* fully refresh inode using dentry */
16356 + err = au_refresh_hinode(inode, dentry);
16358 + au_update_iigen(inode, /*half*/0);
16362 + if (unlikely(err))
16363 + ii_write_unlock(inode);
16368 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16369 + unsigned int d_type, ino_t *ino)
16372 + struct mutex *mtx;
16374 + /* prevent hardlinked inode number from race condition */
16376 + if (d_type != DT_DIR) {
16377 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16380 + err = au_xino_read(sb, bindex, h_ino, ino);
16381 + if (unlikely(err))
16386 + *ino = au_xino_new_ino(sb);
16387 + if (unlikely(!*ino))
16389 + err = au_xino_write(sb, bindex, h_ino, *ino);
16390 + if (unlikely(err))
16396 + mutex_unlock(mtx);
16400 +/* successful returns with iinfo write_locked */
16401 +/* todo: return with unlocked? */
16402 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16404 + struct inode *inode, *h_inode;
16405 + struct dentry *h_dentry;
16406 + struct super_block *sb;
16407 + struct mutex *mtx;
16408 + ino_t h_ino, ino;
16410 + aufs_bindex_t btop;
16412 + sb = dentry->d_sb;
16413 + btop = au_dbtop(dentry);
16414 + h_dentry = au_h_dptr(dentry, btop);
16415 + h_inode = d_inode(h_dentry);
16416 + h_ino = h_inode->i_ino;
16419 + * stop 'race'-ing between hardlinks under different
16423 + if (!d_is_dir(h_dentry))
16424 + mtx = &au_sbr(sb, btop)->br_xino.xi_nondir_mtx;
16429 + err = au_xino_read(sb, btop, h_ino, &ino);
16430 + inode = ERR_PTR(err);
16431 + if (unlikely(err))
16435 + ino = au_xino_new_ino(sb);
16436 + if (unlikely(!ino)) {
16437 + inode = ERR_PTR(-EIO);
16442 + AuDbg("i%lu\n", (unsigned long)ino);
16443 + inode = au_iget_locked(sb, ino);
16444 + err = PTR_ERR(inode);
16445 + if (IS_ERR(inode))
16448 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16449 + if (inode->i_state & I_NEW) {
16450 + ii_write_lock_new_child(inode);
16451 + err = set_inode(inode, dentry);
16453 + unlock_new_inode(inode);
16454 + goto out; /* success */
16458 + * iget_failed() calls iput(), but we need to call
16459 + * ii_write_unlock() after iget_failed(). so dirty hack for
16462 + atomic_inc(&inode->i_count);
16463 + iget_failed(inode);
16464 + ii_write_unlock(inode);
16465 + au_xino_write(sb, btop, h_ino, /*ino*/0);
16466 + /* ignore this error */
16468 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16470 + * horrible race condition between lookup, readdir and copyup
16471 + * (or something).
16474 + mutex_unlock(mtx);
16475 + err = reval_inode(inode, dentry);
16476 + if (unlikely(err < 0)) {
16483 + goto out; /* success */
16488 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16489 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16490 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16491 + btop, au_sbtype(h_dentry->d_sb), dentry,
16492 + (unsigned long)h_ino, (unsigned long)ino);
16494 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
16498 + mutex_unlock(mtx);
16504 + inode = ERR_PTR(err);
16507 + mutex_unlock(mtx);
16511 +/* ---------------------------------------------------------------------- */
16513 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16514 + struct inode *inode)
16517 + struct inode *hi;
16519 + err = au_br_rdonly(au_sbr(sb, bindex));
16521 + /* pseudo-link after flushed may happen out of bounds */
16524 + && au_ibtop(inode) <= bindex
16525 + && bindex <= au_ibbot(inode)) {
16527 + * permission check is unnecessary since vfsub routine
16528 + * will be called later
16530 + hi = au_h_iptr(inode, bindex);
16532 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16538 +int au_test_h_perm(struct inode *h_inode, int mask)
16540 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16542 + return inode_permission(h_inode, mask);
16545 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16547 + if (au_test_nfs(h_inode->i_sb)
16548 + && (mask & MAY_WRITE)
16549 + && S_ISDIR(h_inode->i_mode))
16550 + mask |= MAY_READ; /* force permission check */
16551 + return au_test_h_perm(h_inode, mask);
16553 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16554 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16555 +++ linux/fs/aufs/inode.h 2016-07-25 19:05:34.814493242 +0200
16558 + * Copyright (C) 2005-2016 Junjiro R. Okajima
16560 + * This program, aufs is free software; you can redistribute it and/or modify
16561 + * it under the terms of the GNU General Public License as published by
16562 + * the Free Software Foundation; either version 2 of the License, or
16563 + * (at your option) any later version.
16565 + * This program is distributed in the hope that it will be useful,
16566 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16567 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16568 + * GNU General Public License for more details.
16570 + * You should have received a copy of the GNU General Public License
16571 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16575 + * inode operations
16578 +#ifndef __AUFS_INODE_H__
16579 +#define __AUFS_INODE_H__
16583 +#include <linux/fsnotify.h>
16584 +#include "rwsem.h"
16588 +struct au_hnotify {
16589 +#ifdef CONFIG_AUFS_HNOTIFY
16590 +#ifdef CONFIG_AUFS_HFSNOTIFY
16591 + /* never use fsnotify_add_vfsmount_mark() */
16592 + struct fsnotify_mark hn_mark;
16594 + struct inode *hn_aufs_inode; /* no get/put */
16596 +} ____cacheline_aligned_in_smp;
16598 +struct au_hinode {
16599 + struct inode *hi_inode;
16600 + aufs_bindex_t hi_id;
16601 +#ifdef CONFIG_AUFS_HNOTIFY
16602 + struct au_hnotify *hi_notify;
16605 + /* reference to the copied-up whiteout with get/put */
16606 + struct dentry *hi_whdentry;
16610 +#define AuIG_HALF_REFRESHED 1
16611 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16612 +#define au_ig_fset(flags, name) \
16613 + do { (flags) |= AuIG_##name; } while (0)
16614 +#define au_ig_fclr(flags, name) \
16615 + do { (flags) &= ~AuIG_##name; } while (0)
16618 + spinlock_t ig_spin;
16619 + __u32 ig_generation, ig_flags;
16624 + struct au_iigen ii_generation;
16625 + struct super_block *ii_hsb1; /* no get/put */
16627 + struct au_rwsem ii_rwsem;
16628 + aufs_bindex_t ii_btop, ii_bbot;
16630 + struct au_hinode *ii_hinode;
16631 + struct au_vdir *ii_vdir;
16634 +struct au_icntnr {
16635 + struct au_iinfo iinfo;
16636 + struct inode vfs_inode;
16637 + struct hlist_node plink;
16638 +} ____cacheline_aligned_in_smp;
16640 +/* au_pin flags */
16641 +#define AuPin_DI_LOCKED 1
16642 +#define AuPin_MNT_WRITE (1 << 1)
16643 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16644 +#define au_fset_pin(flags, name) \
16645 + do { (flags) |= AuPin_##name; } while (0)
16646 +#define au_fclr_pin(flags, name) \
16647 + do { (flags) &= ~AuPin_##name; } while (0)
16651 + struct dentry *dentry;
16652 + unsigned int udba;
16653 + unsigned char lsc_di, lsc_hi, flags;
16654 + aufs_bindex_t bindex;
16657 + struct dentry *parent;
16658 + struct au_hinode *hdir;
16659 + struct vfsmount *h_mnt;
16661 + /* temporary unlock/relock for copyup */
16662 + struct dentry *h_dentry, *h_parent;
16663 + struct au_branch *br;
16664 + struct task_struct *task;
16667 +void au_pin_hdir_unlock(struct au_pin *p);
16668 +int au_pin_hdir_lock(struct au_pin *p);
16669 +int au_pin_hdir_relock(struct au_pin *p);
16670 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16671 +void au_pin_hdir_release(struct au_pin *p);
16673 +/* ---------------------------------------------------------------------- */
16675 +static inline struct au_iinfo *au_ii(struct inode *inode)
16677 + BUG_ON(is_bad_inode(inode));
16678 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16681 +/* ---------------------------------------------------------------------- */
16684 +struct inode *au_igrab(struct inode *inode);
16685 +void au_refresh_iop(struct inode *inode, int force_getattr);
16686 +int au_refresh_hinode_self(struct inode *inode);
16687 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16688 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16689 + unsigned int d_type, ino_t *ino);
16690 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16691 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16692 + struct inode *inode);
16693 +int au_test_h_perm(struct inode *h_inode, int mask);
16694 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16696 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16697 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16699 +#ifdef CONFIG_AUFS_SHWH
16700 + return au_ino(sb, bindex, h_ino, d_type, ino);
16713 +extern struct inode_operations aufs_iop[AuIop_Last],
16714 + aufs_iop_nogetattr[AuIop_Last];
16716 +/* au_wr_dir flags */
16717 +#define AuWrDir_ADD_ENTRY 1
16718 +#define AuWrDir_ISDIR (1 << 1)
16719 +#define AuWrDir_TMPFILE (1 << 2)
16720 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16721 +#define au_fset_wrdir(flags, name) \
16722 + do { (flags) |= AuWrDir_##name; } while (0)
16723 +#define au_fclr_wrdir(flags, name) \
16724 + do { (flags) &= ~AuWrDir_##name; } while (0)
16726 +struct au_wr_dir_args {
16727 + aufs_bindex_t force_btgt;
16728 + unsigned char flags;
16730 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16731 + struct au_wr_dir_args *args);
16733 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16734 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16735 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16736 + unsigned int udba, unsigned char flags);
16737 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16738 + unsigned int udba, unsigned char flags) __must_check;
16739 +int au_do_pin(struct au_pin *pin) __must_check;
16740 +void au_unpin(struct au_pin *pin);
16741 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16743 +#define AuIcpup_DID_CPUP 1
16744 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16745 +#define au_fset_icpup(flags, name) \
16746 + do { (flags) |= AuIcpup_##name; } while (0)
16747 +#define au_fclr_icpup(flags, name) \
16748 + do { (flags) &= ~AuIcpup_##name; } while (0)
16750 +struct au_icpup_args {
16751 + unsigned char flags;
16752 + unsigned char pin_flags;
16753 + aufs_bindex_t btgt;
16754 + unsigned int udba;
16755 + struct au_pin pin;
16756 + struct path h_path;
16757 + struct inode *h_inode;
16760 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16761 + struct au_icpup_args *a);
16763 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16766 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16767 + struct dentry *h_parent, int isdir);
16768 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16770 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16771 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16773 +struct vfsub_aopen_args;
16774 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
16775 + struct vfsub_aopen_args *args);
16776 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16777 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16778 + struct dentry *dentry);
16779 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16782 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16783 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16784 + struct dentry *h_parent, int isdir);
16785 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16786 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16789 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16790 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16791 + struct inode *dir, struct dentry *dentry);
16794 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16795 +void au_hiput(struct au_hinode *hinode);
16796 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16797 + struct dentry *h_wh);
16798 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16800 +/* hinode flags */
16801 +#define AuHi_XINO 1
16802 +#define AuHi_HNOTIFY (1 << 1)
16803 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16804 +#define au_fset_hi(flags, name) \
16805 + do { (flags) |= AuHi_##name; } while (0)
16806 +#define au_fclr_hi(flags, name) \
16807 + do { (flags) &= ~AuHi_##name; } while (0)
16809 +#ifndef CONFIG_AUFS_HNOTIFY
16810 +#undef AuHi_HNOTIFY
16811 +#define AuHi_HNOTIFY 0
16814 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16815 + struct inode *h_inode, unsigned int flags);
16817 +void au_update_iigen(struct inode *inode, int half);
16818 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16820 +void au_icntnr_init_once(void *_c);
16821 +void au_hinode_init(struct au_hinode *hinode);
16822 +int au_iinfo_init(struct inode *inode);
16823 +void au_iinfo_fin(struct inode *inode);
16824 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr);
16826 +#ifdef CONFIG_PROC_FS
16828 +int au_plink_maint(struct super_block *sb, int flags);
16830 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16831 +int au_plink_maint_enter(struct super_block *sb);
16832 +#ifdef CONFIG_AUFS_DEBUG
16833 +void au_plink_list(struct super_block *sb);
16835 +AuStubVoid(au_plink_list, struct super_block *sb)
16837 +int au_plink_test(struct inode *inode);
16838 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16839 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16840 + struct dentry *h_dentry);
16841 +void au_plink_put(struct super_block *sb, int verbose);
16842 +void au_plink_clean(struct super_block *sb, int verbose);
16843 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16845 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16846 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16847 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16848 +AuStubVoid(au_plink_list, struct super_block *sb);
16849 +AuStubInt0(au_plink_test, struct inode *inode);
16850 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16851 + struct inode *inode, aufs_bindex_t bindex);
16852 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16853 + struct dentry *h_dentry);
16854 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16855 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16856 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16857 +#endif /* CONFIG_PROC_FS */
16859 +#ifdef CONFIG_AUFS_XATTR
16861 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
16862 + unsigned int verbose);
16863 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16864 +ssize_t aufs_getxattr(struct dentry *dentry, struct inode *inode,
16865 + const char *name, void *value, size_t size);
16866 +int aufs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
16867 + const void *value, size_t size, int flags);
16868 +int aufs_removexattr(struct dentry *dentry, const char *name);
16870 +/* void au_xattr_init(struct super_block *sb); */
16872 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16873 + int ignore_flags, unsigned int verbose);
16874 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
16877 +#ifdef CONFIG_FS_POSIX_ACL
16878 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16879 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16882 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16889 +struct au_srxattr {
16893 + const char *name;
16894 + const void *value;
16899 + const char *name;
16902 + struct posix_acl *acl;
16907 +ssize_t au_srxattr(struct dentry *dentry, struct inode *inode,
16908 + struct au_srxattr *arg);
16911 +/* ---------------------------------------------------------------------- */
16913 +/* lock subclass for iinfo */
16915 + AuLsc_II_CHILD, /* child first */
16916 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16917 + AuLsc_II_CHILD3, /* copyup dirs */
16918 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16919 + AuLsc_II_PARENT2,
16920 + AuLsc_II_PARENT3, /* copyup dirs */
16921 + AuLsc_II_NEW_CHILD
16925 + * ii_read_lock_child, ii_write_lock_child,
16926 + * ii_read_lock_child2, ii_write_lock_child2,
16927 + * ii_read_lock_child3, ii_write_lock_child3,
16928 + * ii_read_lock_parent, ii_write_lock_parent,
16929 + * ii_read_lock_parent2, ii_write_lock_parent2,
16930 + * ii_read_lock_parent3, ii_write_lock_parent3,
16931 + * ii_read_lock_new_child, ii_write_lock_new_child,
16933 +#define AuReadLockFunc(name, lsc) \
16934 +static inline void ii_read_lock_##name(struct inode *i) \
16936 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16939 +#define AuWriteLockFunc(name, lsc) \
16940 +static inline void ii_write_lock_##name(struct inode *i) \
16942 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16945 +#define AuRWLockFuncs(name, lsc) \
16946 + AuReadLockFunc(name, lsc) \
16947 + AuWriteLockFunc(name, lsc)
16949 +AuRWLockFuncs(child, CHILD);
16950 +AuRWLockFuncs(child2, CHILD2);
16951 +AuRWLockFuncs(child3, CHILD3);
16952 +AuRWLockFuncs(parent, PARENT);
16953 +AuRWLockFuncs(parent2, PARENT2);
16954 +AuRWLockFuncs(parent3, PARENT3);
16955 +AuRWLockFuncs(new_child, NEW_CHILD);
16957 +#undef AuReadLockFunc
16958 +#undef AuWriteLockFunc
16959 +#undef AuRWLockFuncs
16962 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
16964 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
16966 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
16967 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
16968 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
16970 +/* ---------------------------------------------------------------------- */
16972 +static inline void au_icntnr_init(struct au_icntnr *c)
16974 +#ifdef CONFIG_AUFS_DEBUG
16975 + c->vfs_inode.i_mode = 0;
16979 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
16981 + unsigned int gen;
16982 + struct au_iinfo *iinfo;
16983 + struct au_iigen *iigen;
16985 + iinfo = au_ii(inode);
16986 + iigen = &iinfo->ii_generation;
16987 + spin_lock(&iigen->ig_spin);
16989 + *igflags = iigen->ig_flags;
16990 + gen = iigen->ig_generation;
16991 + spin_unlock(&iigen->ig_spin);
16996 +/* tiny test for inode number */
16997 +/* tmpfs generation is too rough */
16998 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
17000 + struct au_iinfo *iinfo;
17002 + iinfo = au_ii(inode);
17003 + AuRwMustAnyLock(&iinfo->ii_rwsem);
17004 + return !(iinfo->ii_hsb1 == h_inode->i_sb
17005 + && iinfo->ii_higen == h_inode->i_generation);
17008 +static inline void au_iigen_dec(struct inode *inode)
17010 + struct au_iinfo *iinfo;
17011 + struct au_iigen *iigen;
17013 + iinfo = au_ii(inode);
17014 + iigen = &iinfo->ii_generation;
17015 + spin_lock(&iigen->ig_spin);
17016 + iigen->ig_generation--;
17017 + spin_unlock(&iigen->ig_spin);
17020 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
17025 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
17031 +/* ---------------------------------------------------------------------- */
17033 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
17034 + aufs_bindex_t bindex)
17036 + return iinfo->ii_hinode + bindex;
17039 +static inline int au_is_bad_inode(struct inode *inode)
17041 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
17044 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
17045 + aufs_bindex_t bindex)
17047 + IiMustAnyLock(inode);
17048 + return au_hinode(au_ii(inode), bindex)->hi_id;
17051 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
17053 + IiMustAnyLock(inode);
17054 + return au_ii(inode)->ii_btop;
17057 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
17059 + IiMustAnyLock(inode);
17060 + return au_ii(inode)->ii_bbot;
17063 +static inline struct au_vdir *au_ivdir(struct inode *inode)
17065 + IiMustAnyLock(inode);
17066 + return au_ii(inode)->ii_vdir;
17069 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
17071 + IiMustAnyLock(inode);
17072 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
17075 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
17077 + IiMustWriteLock(inode);
17078 + au_ii(inode)->ii_btop = bindex;
17081 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
17083 + IiMustWriteLock(inode);
17084 + au_ii(inode)->ii_bbot = bindex;
17087 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
17089 + IiMustWriteLock(inode);
17090 + au_ii(inode)->ii_vdir = vdir;
17093 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
17095 + IiMustAnyLock(inode);
17096 + return au_hinode(au_ii(inode), bindex);
17099 +/* ---------------------------------------------------------------------- */
17101 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
17104 + return pin->parent;
17108 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
17110 + if (pin && pin->hdir)
17111 + return pin->hdir->hi_inode;
17115 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
17118 + return pin->hdir;
17122 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
17125 + pin->dentry = dentry;
17128 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
17129 + unsigned char lflag)
17133 + au_fset_pin(pin->flags, DI_LOCKED);
17135 + au_fclr_pin(pin->flags, DI_LOCKED);
17139 +#if 0 /* reserved */
17140 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
17143 + dput(pin->parent);
17144 + pin->parent = dget(parent);
17149 +/* ---------------------------------------------------------------------- */
17152 +#ifdef CONFIG_AUFS_HNOTIFY
17153 +struct au_hnotify_op {
17154 + void (*ctl)(struct au_hinode *hinode, int do_set);
17155 + int (*alloc)(struct au_hinode *hinode);
17158 + * if it returns true, the the caller should free hinode->hi_notify,
17159 + * otherwise ->free() frees it.
17161 + int (*free)(struct au_hinode *hinode,
17162 + struct au_hnotify *hn) __must_check;
17164 + void (*fin)(void);
17165 + int (*init)(void);
17167 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
17168 + void (*fin_br)(struct au_branch *br);
17169 + int (*init_br)(struct au_branch *br, int perm);
17173 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
17174 +void au_hn_free(struct au_hinode *hinode);
17175 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
17176 +void au_hn_reset(struct inode *inode, unsigned int flags);
17177 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17178 + struct qstr *h_child_qstr, struct inode *h_child_inode);
17179 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
17180 +int au_hnotify_init_br(struct au_branch *br, int perm);
17181 +void au_hnotify_fin_br(struct au_branch *br);
17182 +int __init au_hnotify_init(void);
17183 +void au_hnotify_fin(void);
17186 +extern const struct au_hnotify_op au_hnotify_op;
17189 +void au_hn_init(struct au_hinode *hinode)
17191 + hinode->hi_notify = NULL;
17194 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
17196 + return hinode->hi_notify;
17200 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
17201 + struct au_hinode *hinode __maybe_unused,
17202 + struct inode *inode __maybe_unused)
17203 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
17204 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
17205 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
17206 + int do_set __maybe_unused)
17207 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
17208 + unsigned int flags __maybe_unused)
17209 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
17210 + struct au_branch *br __maybe_unused,
17211 + int perm __maybe_unused)
17212 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
17213 + int perm __maybe_unused)
17214 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
17215 +AuStubInt0(__init au_hnotify_init, void)
17216 +AuStubVoid(au_hnotify_fin, void)
17217 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
17218 +#endif /* CONFIG_AUFS_HNOTIFY */
17220 +static inline void au_hn_suspend(struct au_hinode *hdir)
17222 + au_hn_ctl(hdir, /*do_set*/0);
17225 +static inline void au_hn_resume(struct au_hinode *hdir)
17227 + au_hn_ctl(hdir, /*do_set*/1);
17230 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
17232 + inode_lock(hdir->hi_inode);
17233 + au_hn_suspend(hdir);
17236 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
17237 + unsigned int sc __maybe_unused)
17239 + inode_lock_nested(hdir->hi_inode, sc);
17240 + au_hn_suspend(hdir);
17243 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
17245 + au_hn_resume(hdir);
17246 + inode_unlock(hdir->hi_inode);
17249 +#endif /* __KERNEL__ */
17250 +#endif /* __AUFS_INODE_H__ */
17251 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
17252 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
17253 +++ linux/fs/aufs/ioctl.c 2016-07-25 19:05:34.814493242 +0200
17256 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17258 + * This program, aufs is free software; you can redistribute it and/or modify
17259 + * it under the terms of the GNU General Public License as published by
17260 + * the Free Software Foundation; either version 2 of the License, or
17261 + * (at your option) any later version.
17263 + * This program is distributed in the hope that it will be useful,
17264 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17265 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17266 + * GNU General Public License for more details.
17268 + * You should have received a copy of the GNU General Public License
17269 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17274 + * plink-management and readdir in userspace.
17275 + * assist the pathconf(3) wrapper library.
17277 + * File-based Hierarchical Storage Management.
17280 +#include <linux/compat.h>
17281 +#include <linux/file.h>
17284 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
17287 + aufs_bindex_t wbi, bindex, bbot;
17288 + struct file *h_file;
17289 + struct super_block *sb;
17290 + struct dentry *root;
17291 + struct au_branch *br;
17292 + struct aufs_wbr_fd wbrfd = {
17293 + .oflags = au_dir_roflags,
17296 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17297 + | O_NOATIME | O_CLOEXEC;
17299 + AuDebugOn(wbrfd.oflags & ~valid);
17302 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17303 + if (unlikely(err)) {
17309 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17310 + wbrfd.oflags |= au_dir_roflags;
17311 + AuDbg("0%o\n", wbrfd.oflags);
17312 + if (unlikely(wbrfd.oflags & ~valid))
17316 + fd = get_unused_fd_flags(0);
17318 + if (unlikely(fd < 0))
17321 + h_file = ERR_PTR(-EINVAL);
17324 + sb = path->dentry->d_sb;
17325 + root = sb->s_root;
17326 + aufs_read_lock(root, AuLock_IR);
17327 + bbot = au_sbbot(sb);
17328 + if (wbrfd.brid >= 0) {
17329 + wbi = au_br_index(sb, wbrfd.brid);
17330 + if (unlikely(wbi < 0 || wbi > bbot))
17334 + h_file = ERR_PTR(-ENOENT);
17335 + br = au_sbr(sb, wbi);
17336 + if (!au_br_writable(br->br_perm)) {
17340 + bindex = wbi + 1;
17342 + for (; bindex <= bbot; bindex++) {
17343 + br = au_sbr(sb, bindex);
17344 + if (au_br_writable(br->br_perm)) {
17346 + br = au_sbr(sb, wbi);
17351 + AuDbg("wbi %d\n", wbi);
17353 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17357 + aufs_read_unlock(root, AuLock_IR);
17358 + err = PTR_ERR(h_file);
17359 + if (IS_ERR(h_file))
17362 + au_br_put(br); /* cf. au_h_open() */
17363 + fd_install(fd, h_file);
17365 + goto out; /* success */
17368 + put_unused_fd(fd);
17374 +/* ---------------------------------------------------------------------- */
17376 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17379 + struct dentry *dentry;
17382 + case AUFS_CTL_RDU:
17383 + case AUFS_CTL_RDU_INO:
17384 + err = au_rdu_ioctl(file, cmd, arg);
17387 + case AUFS_CTL_WBR_FD:
17388 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17391 + case AUFS_CTL_IBUSY:
17392 + err = au_ibusy_ioctl(file, arg);
17395 + case AUFS_CTL_BRINFO:
17396 + err = au_brinfo_ioctl(file, arg);
17399 + case AUFS_CTL_FHSM_FD:
17400 + dentry = file->f_path.dentry;
17401 + if (IS_ROOT(dentry))
17402 + err = au_fhsm_fd(dentry->d_sb, arg);
17408 + /* do not call the lower */
17409 + AuDbg("0x%x\n", cmd);
17417 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17422 + case AUFS_CTL_MVDOWN:
17423 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17426 + case AUFS_CTL_WBR_FD:
17427 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17431 + /* do not call the lower */
17432 + AuDbg("0x%x\n", cmd);
17440 +#ifdef CONFIG_COMPAT
17441 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17442 + unsigned long arg)
17447 + case AUFS_CTL_RDU:
17448 + case AUFS_CTL_RDU_INO:
17449 + err = au_rdu_compat_ioctl(file, cmd, arg);
17452 + case AUFS_CTL_IBUSY:
17453 + err = au_ibusy_compat_ioctl(file, arg);
17456 + case AUFS_CTL_BRINFO:
17457 + err = au_brinfo_compat_ioctl(file, arg);
17461 + err = aufs_ioctl_dir(file, cmd, arg);
17468 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17469 + unsigned long arg)
17471 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17474 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17475 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17476 +++ linux/fs/aufs/i_op_add.c 2016-07-25 19:05:34.814493242 +0200
17479 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17481 + * This program, aufs is free software; you can redistribute it and/or modify
17482 + * it under the terms of the GNU General Public License as published by
17483 + * the Free Software Foundation; either version 2 of the License, or
17484 + * (at your option) any later version.
17486 + * This program is distributed in the hope that it will be useful,
17487 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17488 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17489 + * GNU General Public License for more details.
17491 + * You should have received a copy of the GNU General Public License
17492 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17496 + * inode operations (add entry)
17502 + * final procedure of adding a new entry, except link(2).
17503 + * remove whiteout, instantiate, copyup the parent dir's times and size
17504 + * and update version.
17505 + * if it failed, re-create the removed whiteout.
17507 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17508 + struct dentry *wh_dentry, struct dentry *dentry)
17511 + aufs_bindex_t bwh;
17512 + struct path h_path;
17513 + struct super_block *sb;
17514 + struct inode *inode, *h_dir;
17515 + struct dentry *wh;
17520 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17521 + IMustLock(h_dir);
17522 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17523 + bwh = au_dbwh(dentry);
17524 + h_path.dentry = wh_dentry;
17525 + h_path.mnt = au_sbr_mnt(sb, bindex);
17526 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17528 + if (unlikely(err))
17532 + inode = au_new_inode(dentry, /*must_new*/1);
17533 + if (!IS_ERR(inode)) {
17534 + d_instantiate(dentry, inode);
17535 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17537 + au_dir_ts(dir, bindex);
17538 + dir->i_version++;
17539 + au_fhsm_wrote(sb, bindex, /*force*/0);
17540 + return 0; /* success */
17543 + err = PTR_ERR(inode);
17548 + /* dir inode is locked */
17549 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17550 + rerr = PTR_ERR(wh);
17551 + if (IS_ERR(wh)) {
17552 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17553 + dentry, err, rerr);
17562 +static int au_d_may_add(struct dentry *dentry)
17567 + if (unlikely(d_unhashed(dentry)))
17569 + if (unlikely(d_really_is_positive(dentry)))
17575 + * simple tests for the adding inode operations.
17576 + * following the checks in vfs, plus the parent-child relationship.
17578 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17579 + struct dentry *h_parent, int isdir)
17583 + struct dentry *h_dentry;
17584 + struct inode *h_inode;
17586 + err = -ENAMETOOLONG;
17587 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17590 + h_dentry = au_h_dptr(dentry, bindex);
17591 + if (d_really_is_negative(dentry)) {
17593 + if (unlikely(d_is_positive(h_dentry)))
17596 + /* rename(2) case */
17598 + if (unlikely(d_is_negative(h_dentry)))
17600 + h_inode = d_inode(h_dentry);
17601 + if (unlikely(!h_inode->i_nlink))
17604 + h_mode = h_inode->i_mode;
17607 + if (unlikely(S_ISDIR(h_mode)))
17609 + } else if (unlikely(!S_ISDIR(h_mode))) {
17616 + /* expected parent dir is locked */
17617 + if (unlikely(h_parent != h_dentry->d_parent))
17626 + * initial procedure of adding a new entry.
17627 + * prepare writable branch and the parent dir, lock it,
17628 + * and lookup whiteout for the new entry.
17630 +static struct dentry*
17631 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17632 + struct dentry *src_dentry, struct au_pin *pin,
17633 + struct au_wr_dir_args *wr_dir_args)
17635 + struct dentry *wh_dentry, *h_parent;
17636 + struct super_block *sb;
17637 + struct au_branch *br;
17639 + unsigned int udba;
17640 + aufs_bindex_t bcpup;
17642 + AuDbg("%pd\n", dentry);
17644 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17646 + wh_dentry = ERR_PTR(err);
17647 + if (unlikely(err < 0))
17650 + sb = dentry->d_sb;
17651 + udba = au_opt_udba(sb);
17652 + err = au_pin(pin, dentry, bcpup, udba,
17653 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17654 + wh_dentry = ERR_PTR(err);
17655 + if (unlikely(err))
17658 + h_parent = au_pinned_h_parent(pin);
17659 + if (udba != AuOpt_UDBA_NONE
17660 + && au_dbtop(dentry) == bcpup)
17661 + err = au_may_add(dentry, bcpup, h_parent,
17662 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17663 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17664 + err = -ENAMETOOLONG;
17665 + wh_dentry = ERR_PTR(err);
17666 + if (unlikely(err))
17669 + br = au_sbr(sb, bcpup);
17671 + struct path tmp = {
17672 + .dentry = h_parent,
17673 + .mnt = au_br_mnt(br)
17675 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17678 + wh_dentry = NULL;
17679 + if (bcpup != au_dbwh(dentry))
17680 + goto out; /* success */
17683 + * ENAMETOOLONG here means that if we allowed create such name, then it
17684 + * would not be able to removed in the future. So we don't allow such
17685 + * name here and we don't handle ENAMETOOLONG differently here.
17687 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17690 + if (IS_ERR(wh_dentry))
17693 + return wh_dentry;
17696 +/* ---------------------------------------------------------------------- */
17698 +enum { Mknod, Symlink, Creat };
17699 +struct simple_arg {
17706 + struct vfsub_aopen_args *aopen;
17709 + const char *symname;
17718 +static int add_simple(struct inode *dir, struct dentry *dentry,
17719 + struct simple_arg *arg)
17722 + aufs_bindex_t btop;
17723 + unsigned char created;
17724 + const unsigned char try_aopen
17725 + = (arg->type == Creat && arg->u.c.try_aopen);
17726 + struct dentry *wh_dentry, *parent;
17727 + struct inode *h_dir;
17728 + struct super_block *sb;
17729 + struct au_branch *br;
17730 + /* to reuduce stack size */
17732 + struct au_dtime dt;
17733 + struct au_pin pin;
17734 + struct path h_path;
17735 + struct au_wr_dir_args wr_dir_args;
17738 + AuDbg("%pd\n", dentry);
17742 + a = kmalloc(sizeof(*a), GFP_NOFS);
17743 + if (unlikely(!a))
17745 + a->wr_dir_args.force_btgt = -1;
17746 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17748 + parent = dentry->d_parent; /* dir inode is locked */
17749 + if (!try_aopen) {
17750 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17751 + if (unlikely(err))
17754 + err = au_d_may_add(dentry);
17755 + if (unlikely(err))
17758 + di_write_lock_parent(parent);
17759 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17760 + &a->pin, &a->wr_dir_args);
17761 + err = PTR_ERR(wh_dentry);
17762 + if (IS_ERR(wh_dentry))
17765 + btop = au_dbtop(dentry);
17766 + sb = dentry->d_sb;
17767 + br = au_sbr(sb, btop);
17768 + a->h_path.dentry = au_h_dptr(dentry, btop);
17769 + a->h_path.mnt = au_br_mnt(br);
17770 + h_dir = au_pinned_h_dir(&a->pin);
17771 + switch (arg->type) {
17774 + if (!try_aopen || !h_dir->i_op->atomic_open)
17775 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17776 + arg->u.c.want_excl);
17778 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
17779 + arg->u.c.aopen, br);
17782 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17785 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17793 + err = epilog(dir, btop, wh_dentry, dentry);
17796 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
17797 + /* no delegation since it is just created */
17798 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17801 + AuIOErr("%pd revert failure(%d, %d)\n",
17802 + dentry, err, rerr);
17805 + au_dtime_revert(&a->dt);
17808 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
17809 + *arg->u.c.aopen->opened |= FILE_CREATED;
17811 + au_unpin(&a->pin);
17816 + di_write_unlock(parent);
17818 + if (unlikely(err)) {
17819 + au_update_dbtop(dentry);
17823 + aufs_read_unlock(dentry, AuLock_DW);
17830 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17833 + struct simple_arg arg = {
17840 + return add_simple(dir, dentry, &arg);
17843 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17845 + struct simple_arg arg = {
17847 + .u.s.symname = symname
17849 + return add_simple(dir, dentry, &arg);
17852 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17855 + struct simple_arg arg = {
17859 + .want_excl = want_excl
17862 + return add_simple(dir, dentry, &arg);
17865 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17866 + struct vfsub_aopen_args *aopen_args)
17868 + struct simple_arg arg = {
17871 + .mode = aopen_args->create_mode,
17872 + .want_excl = aopen_args->open_flag & O_EXCL,
17873 + .try_aopen = true,
17874 + .aopen = aopen_args
17877 + return add_simple(dir, dentry, &arg);
17880 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17883 + aufs_bindex_t bindex;
17884 + struct super_block *sb;
17885 + struct dentry *parent, *h_parent, *h_dentry;
17886 + struct inode *h_dir, *inode;
17887 + struct vfsmount *h_mnt;
17888 + struct au_wr_dir_args wr_dir_args = {
17889 + .force_btgt = -1,
17890 + .flags = AuWrDir_TMPFILE
17893 + /* copy-up may happen */
17897 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17898 + if (unlikely(err))
17901 + err = au_di_init(dentry);
17902 + if (unlikely(err))
17906 + parent = d_find_any_alias(dir);
17907 + AuDebugOn(!parent);
17908 + di_write_lock_parent(parent);
17909 + if (unlikely(d_inode(parent) != dir))
17912 + err = au_digen_test(parent, au_sigen(sb));
17913 + if (unlikely(err))
17916 + bindex = au_dbtop(parent);
17917 + au_set_dbtop(dentry, bindex);
17918 + au_set_dbbot(dentry, bindex);
17919 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17921 + if (unlikely(err < 0))
17924 + err = -EOPNOTSUPP;
17925 + h_dir = au_h_iptr(dir, bindex);
17926 + if (unlikely(!h_dir->i_op->tmpfile))
17929 + h_mnt = au_sbr_mnt(sb, bindex);
17930 + err = vfsub_mnt_want_write(h_mnt);
17931 + if (unlikely(err))
17934 + h_parent = au_h_dptr(parent, bindex);
17935 + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC);
17936 + if (unlikely(err))
17940 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17941 + if (unlikely(!h_dentry))
17944 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17945 + if (unlikely(err))
17948 + au_set_dbtop(dentry, bindex);
17949 + au_set_dbbot(dentry, bindex);
17950 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17951 + inode = au_new_inode(dentry, /*must_new*/1);
17952 + if (IS_ERR(inode)) {
17953 + err = PTR_ERR(inode);
17954 + au_set_h_dptr(dentry, bindex, NULL);
17955 + au_set_dbtop(dentry, -1);
17956 + au_set_dbbot(dentry, -1);
17958 + if (!inode->i_nlink)
17959 + set_nlink(inode, 1);
17960 + d_tmpfile(dentry, inode);
17961 + au_di(dentry)->di_tmpfile = 1;
17963 + /* update without i_mutex */
17964 + if (au_ibtop(dir) == au_dbtop(dentry))
17965 + au_cpup_attr_timesizes(dir);
17971 + vfsub_mnt_drop_write(h_mnt);
17973 + di_write_unlock(parent);
17975 + di_write_unlock(dentry);
17976 + if (unlikely(err)) {
17977 + au_di_fin(dentry);
17978 + dentry->d_fsdata = NULL;
17981 + si_read_unlock(sb);
17983 + inode_unlock(dir);
17987 +/* ---------------------------------------------------------------------- */
17989 +struct au_link_args {
17990 + aufs_bindex_t bdst, bsrc;
17991 + struct au_pin pin;
17992 + struct path h_path;
17993 + struct dentry *src_parent, *parent;
17996 +static int au_cpup_before_link(struct dentry *src_dentry,
17997 + struct au_link_args *a)
18000 + struct dentry *h_src_dentry;
18001 + struct au_cp_generic cpg = {
18002 + .dentry = src_dentry,
18007 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
18010 + di_read_lock_parent(a->src_parent, AuLock_IR);
18011 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
18012 + if (unlikely(err))
18015 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
18016 + err = au_pin(&a->pin, src_dentry, a->bdst,
18017 + au_opt_udba(src_dentry->d_sb),
18018 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18019 + if (unlikely(err))
18022 + err = au_sio_cpup_simple(&cpg);
18023 + au_unpin(&a->pin);
18026 + di_read_unlock(a->src_parent, AuLock_IR);
18030 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
18031 + struct au_link_args *a)
18034 + unsigned char plink;
18035 + aufs_bindex_t bbot;
18036 + struct dentry *h_src_dentry;
18037 + struct inode *h_inode, *inode, *delegated;
18038 + struct super_block *sb;
18039 + struct file *h_file;
18043 + sb = src_dentry->d_sb;
18044 + inode = d_inode(src_dentry);
18045 + if (au_ibtop(inode) <= a->bdst)
18046 + h_inode = au_h_iptr(inode, a->bdst);
18047 + if (!h_inode || !h_inode->i_nlink) {
18048 + /* copyup src_dentry as the name of dentry. */
18049 + bbot = au_dbbot(dentry);
18050 + if (bbot < a->bsrc)
18051 + au_set_dbbot(dentry, a->bsrc);
18052 + au_set_h_dptr(dentry, a->bsrc,
18053 + dget(au_h_dptr(src_dentry, a->bsrc)));
18054 + dget(a->h_path.dentry);
18055 + au_set_h_dptr(dentry, a->bdst, NULL);
18056 + AuDbg("temporary d_inode...\n");
18057 + spin_lock(&dentry->d_lock);
18058 + dentry->d_inode = d_inode(src_dentry); /* tmp */
18059 + spin_unlock(&dentry->d_lock);
18060 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
18061 + if (IS_ERR(h_file))
18062 + err = PTR_ERR(h_file);
18064 + struct au_cp_generic cpg = {
18065 + .dentry = dentry,
18070 + .flags = AuCpup_KEEPLINO
18072 + err = au_sio_cpup_simple(&cpg);
18073 + au_h_open_post(dentry, a->bsrc, h_file);
18075 + dput(a->h_path.dentry);
18076 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18078 + au_set_h_dptr(dentry, a->bdst,
18079 + a->h_path.dentry);
18081 + spin_lock(&dentry->d_lock);
18082 + dentry->d_inode = NULL; /* restore */
18083 + spin_unlock(&dentry->d_lock);
18084 + AuDbg("temporary d_inode...done\n");
18085 + au_set_h_dptr(dentry, a->bsrc, NULL);
18086 + au_set_dbbot(dentry, bbot);
18088 + /* the inode of src_dentry already exists on a.bdst branch */
18089 + h_src_dentry = d_find_alias(h_inode);
18090 + if (!h_src_dentry && au_plink_test(inode)) {
18092 + h_src_dentry = au_plink_lkup(inode, a->bdst);
18093 + err = PTR_ERR(h_src_dentry);
18094 + if (IS_ERR(h_src_dentry))
18097 + if (unlikely(d_is_negative(h_src_dentry))) {
18098 + dput(h_src_dentry);
18099 + h_src_dentry = NULL;
18103 + if (h_src_dentry) {
18104 + delegated = NULL;
18105 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18106 + &a->h_path, &delegated);
18107 + if (unlikely(err == -EWOULDBLOCK)) {
18108 + pr_warn("cannot retry for NFSv4 delegation"
18109 + " for an internal link\n");
18112 + dput(h_src_dentry);
18114 + AuIOErr("no dentry found for hi%lu on b%d\n",
18115 + h_inode->i_ino, a->bdst);
18120 + if (!err && !plink)
18121 + au_plink_append(inode, a->bdst, a->h_path.dentry);
18128 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18129 + struct dentry *dentry)
18132 + struct au_dtime dt;
18133 + struct au_link_args *a;
18134 + struct dentry *wh_dentry, *h_src_dentry;
18135 + struct inode *inode, *delegated;
18136 + struct super_block *sb;
18137 + struct au_wr_dir_args wr_dir_args = {
18138 + /* .force_btgt = -1, */
18139 + .flags = AuWrDir_ADD_ENTRY
18143 + inode = d_inode(src_dentry);
18144 + IMustLock(inode);
18147 + a = kzalloc(sizeof(*a), GFP_NOFS);
18148 + if (unlikely(!a))
18151 + a->parent = dentry->d_parent; /* dir inode is locked */
18152 + err = aufs_read_and_write_lock2(dentry, src_dentry,
18153 + AuLock_NOPLM | AuLock_GEN);
18154 + if (unlikely(err))
18156 + err = au_d_linkable(src_dentry);
18157 + if (unlikely(err))
18159 + err = au_d_may_add(dentry);
18160 + if (unlikely(err))
18163 + a->src_parent = dget_parent(src_dentry);
18164 + wr_dir_args.force_btgt = au_ibtop(inode);
18166 + di_write_lock_parent(a->parent);
18167 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
18168 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
18170 + err = PTR_ERR(wh_dentry);
18171 + if (IS_ERR(wh_dentry))
18175 + sb = dentry->d_sb;
18176 + a->bdst = au_dbtop(dentry);
18177 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18178 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
18179 + a->bsrc = au_ibtop(inode);
18180 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18181 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
18182 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
18183 + if (!h_src_dentry) {
18184 + a->bsrc = au_dbtop(src_dentry);
18185 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18186 + AuDebugOn(!h_src_dentry);
18187 + } else if (IS_ERR(h_src_dentry)) {
18188 + err = PTR_ERR(h_src_dentry);
18192 + if (au_opt_test(au_mntflags(sb), PLINK)) {
18193 + if (a->bdst < a->bsrc
18194 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
18195 + err = au_cpup_or_link(src_dentry, dentry, a);
18197 + delegated = NULL;
18198 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18199 + &a->h_path, &delegated);
18200 + if (unlikely(err == -EWOULDBLOCK)) {
18201 + pr_warn("cannot retry for NFSv4 delegation"
18202 + " for an internal link\n");
18206 + dput(h_src_dentry);
18209 + * copyup src_dentry to the branch we process,
18210 + * and then link(2) to it.
18212 + dput(h_src_dentry);
18213 + if (a->bdst < a->bsrc
18214 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
18215 + au_unpin(&a->pin);
18216 + di_write_unlock(a->parent);
18217 + err = au_cpup_before_link(src_dentry, a);
18218 + di_write_lock_parent(a->parent);
18220 + err = au_pin(&a->pin, dentry, a->bdst,
18222 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18223 + if (unlikely(err))
18227 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
18229 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
18230 + delegated = NULL;
18231 + err = vfsub_link(h_src_dentry,
18232 + au_pinned_h_dir(&a->pin),
18233 + &a->h_path, &delegated);
18234 + if (unlikely(err == -EWOULDBLOCK)) {
18235 + pr_warn("cannot retry"
18236 + " for NFSv4 delegation"
18237 + " for an internal link\n");
18243 + if (unlikely(err))
18247 + a->h_path.dentry = wh_dentry;
18248 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
18250 + if (unlikely(err))
18254 + au_dir_ts(dir, a->bdst);
18255 + dir->i_version++;
18256 + inc_nlink(inode);
18257 + inode->i_ctime = dir->i_ctime;
18258 + d_instantiate(dentry, au_igrab(inode));
18259 + if (d_unhashed(a->h_path.dentry))
18260 + /* some filesystem calls d_drop() */
18262 + /* some filesystems consume an inode even hardlink */
18263 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
18264 + goto out_unpin; /* success */
18267 + /* no delegation since it is just created */
18268 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
18269 + /*delegated*/NULL, /*force*/0);
18270 + if (unlikely(rerr)) {
18271 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
18274 + au_dtime_revert(&dt);
18276 + au_unpin(&a->pin);
18280 + di_write_unlock(a->parent);
18281 + dput(a->src_parent);
18283 + if (unlikely(err)) {
18284 + au_update_dbtop(dentry);
18287 + aufs_read_and_write_unlock2(dentry, src_dentry);
18295 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18298 + aufs_bindex_t bindex;
18299 + unsigned char diropq;
18300 + struct path h_path;
18301 + struct dentry *wh_dentry, *parent, *opq_dentry;
18302 + struct inode *h_inode;
18303 + struct super_block *sb;
18305 + struct au_pin pin;
18306 + struct au_dtime dt;
18307 + } *a; /* reduce the stack usage */
18308 + struct au_wr_dir_args wr_dir_args = {
18309 + .force_btgt = -1,
18310 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18316 + a = kmalloc(sizeof(*a), GFP_NOFS);
18317 + if (unlikely(!a))
18320 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18321 + if (unlikely(err))
18323 + err = au_d_may_add(dentry);
18324 + if (unlikely(err))
18327 + parent = dentry->d_parent; /* dir inode is locked */
18328 + di_write_lock_parent(parent);
18329 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18330 + &a->pin, &wr_dir_args);
18331 + err = PTR_ERR(wh_dentry);
18332 + if (IS_ERR(wh_dentry))
18335 + sb = dentry->d_sb;
18336 + bindex = au_dbtop(dentry);
18337 + h_path.dentry = au_h_dptr(dentry, bindex);
18338 + h_path.mnt = au_sbr_mnt(sb, bindex);
18339 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18340 + if (unlikely(err))
18343 + /* make the dir opaque */
18345 + h_inode = d_inode(h_path.dentry);
18347 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18348 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18349 + opq_dentry = au_diropq_create(dentry, bindex);
18350 + inode_unlock(h_inode);
18351 + err = PTR_ERR(opq_dentry);
18352 + if (IS_ERR(opq_dentry))
18354 + dput(opq_dentry);
18358 + err = epilog(dir, bindex, wh_dentry, dentry);
18361 + goto out_unpin; /* success */
18366 + AuLabel(revert opq);
18367 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18368 + rerr = au_diropq_remove(dentry, bindex);
18369 + inode_unlock(h_inode);
18371 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18372 + dentry, err, rerr);
18378 + AuLabel(revert dir);
18379 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18381 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18382 + dentry, err, rerr);
18385 + au_dtime_revert(&a->dt);
18387 + au_unpin(&a->pin);
18390 + di_write_unlock(parent);
18392 + if (unlikely(err)) {
18393 + au_update_dbtop(dentry);
18396 + aufs_read_unlock(dentry, AuLock_DW);
18402 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18403 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18404 +++ linux/fs/aufs/i_op.c 2016-07-25 19:05:34.814493242 +0200
18407 + * Copyright (C) 2005-2016 Junjiro R. Okajima
18409 + * This program, aufs is free software; you can redistribute it and/or modify
18410 + * it under the terms of the GNU General Public License as published by
18411 + * the Free Software Foundation; either version 2 of the License, or
18412 + * (at your option) any later version.
18414 + * This program is distributed in the hope that it will be useful,
18415 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18416 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18417 + * GNU General Public License for more details.
18419 + * You should have received a copy of the GNU General Public License
18420 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18424 + * inode operations (except add/del/rename)
18427 +#include <linux/device_cgroup.h>
18428 +#include <linux/fs_stack.h>
18429 +#include <linux/namei.h>
18430 +#include <linux/security.h>
18433 +static int h_permission(struct inode *h_inode, int mask,
18434 + struct path *h_path, int brperm)
18437 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18440 + if ((write_mask && IS_IMMUTABLE(h_inode))
18441 + || ((mask & MAY_EXEC)
18442 + && S_ISREG(h_inode->i_mode)
18443 + && (path_noexec(h_path)
18444 + || !(h_inode->i_mode & S_IXUGO))))
18448 + * - skip the lower fs test in the case of write to ro branch.
18449 + * - nfs dir permission write check is optimized, but a policy for
18450 + * link/rename requires a real check.
18451 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18452 + * in this case, generic_permission() returns -EOPNOTSUPP.
18454 + if ((write_mask && !au_br_writable(brperm))
18455 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18456 + && write_mask && !(mask & MAY_READ))
18457 + || !h_inode->i_op->permission) {
18458 + /* AuLabel(generic_permission); */
18459 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18460 + err = generic_permission(h_inode, mask);
18461 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18462 + err = h_inode->i_op->permission(h_inode, mask);
18465 + /* AuLabel(h_inode->permission); */
18466 + err = h_inode->i_op->permission(h_inode, mask);
18471 + err = devcgroup_inode_permission(h_inode, mask);
18473 + err = security_inode_permission(h_inode, mask);
18477 + /* todo: do we need to call ima_path_check()? */
18478 + struct path h_path = {
18482 + err = ima_path_check(&h_path,
18483 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18484 + IMA_COUNT_LEAVE);
18492 +static int aufs_permission(struct inode *inode, int mask)
18495 + aufs_bindex_t bindex, bbot;
18496 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18497 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18498 + struct inode *h_inode;
18499 + struct super_block *sb;
18500 + struct au_branch *br;
18502 + /* todo: support rcu-walk? */
18503 + if (mask & MAY_NOT_BLOCK)
18506 + sb = inode->i_sb;
18507 + si_read_lock(sb, AuLock_FLUSH);
18508 + ii_read_lock_child(inode);
18510 + err = au_iigen_test(inode, au_sigen(sb));
18511 + if (unlikely(err))
18517 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18518 + err = au_busy_or_stale();
18519 + h_inode = au_h_iptr(inode, au_ibtop(inode));
18520 + if (unlikely(!h_inode
18521 + || (h_inode->i_mode & S_IFMT)
18522 + != (inode->i_mode & S_IFMT)))
18526 + bindex = au_ibtop(inode);
18527 + br = au_sbr(sb, bindex);
18528 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
18531 + && !special_file(h_inode->i_mode)) {
18532 + /* test whether the upper writable branch exists */
18534 + for (; bindex >= 0; bindex--)
18535 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18543 + /* non-write to dir */
18545 + bbot = au_ibbot(inode);
18546 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
18547 + h_inode = au_h_iptr(inode, bindex);
18549 + err = au_busy_or_stale();
18550 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18553 + br = au_sbr(sb, bindex);
18554 + err = h_permission(h_inode, mask, &br->br_path,
18560 + ii_read_unlock(inode);
18561 + si_read_unlock(sb);
18565 +/* ---------------------------------------------------------------------- */
18567 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18568 + unsigned int flags)
18570 + struct dentry *ret, *parent;
18571 + struct inode *inode;
18572 + struct super_block *sb;
18573 + int err, npositive;
18577 + /* todo: support rcu-walk? */
18578 + ret = ERR_PTR(-ECHILD);
18579 + if (flags & LOOKUP_RCU)
18582 + ret = ERR_PTR(-ENAMETOOLONG);
18583 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18587 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18588 + ret = ERR_PTR(err);
18589 + if (unlikely(err))
18592 + err = au_di_init(dentry);
18593 + ret = ERR_PTR(err);
18594 + if (unlikely(err))
18598 + npositive = 0; /* suppress a warning */
18599 + parent = dentry->d_parent; /* dir inode is locked */
18600 + di_read_lock_parent(parent, AuLock_IR);
18601 + err = au_alive_dir(parent);
18603 + err = au_digen_test(parent, au_sigen(sb));
18605 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
18606 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
18607 + AuLkup_ALLOW_NEG);
18610 + di_read_unlock(parent, AuLock_IR);
18611 + ret = ERR_PTR(err);
18612 + if (unlikely(err < 0))
18616 + inode = au_new_inode(dentry, /*must_new*/0);
18617 + if (IS_ERR(inode)) {
18618 + ret = (void *)inode;
18625 + atomic_inc(&inode->i_count);
18626 + ret = d_splice_alias(inode, dentry);
18628 + if (unlikely(d_need_lookup(dentry))) {
18629 + spin_lock(&dentry->d_lock);
18630 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18631 + spin_unlock(&dentry->d_lock);
18635 + if (!IS_ERR(ret)) {
18637 + if (ret && ret != dentry)
18638 + ii_write_unlock(inode);
18640 + ii_write_unlock(inode);
18647 + di_write_unlock(dentry);
18649 + si_read_unlock(sb);
18654 +/* ---------------------------------------------------------------------- */
18656 +struct aopen_node {
18657 + struct hlist_node hlist;
18658 + struct file *file, *h_file;
18661 +static int au_do_aopen(struct inode *inode, struct file *file)
18663 + struct au_sphlhead *aopen;
18664 + struct aopen_node *node;
18665 + struct au_do_open_args args = {
18667 + .open = au_do_open_nondir
18670 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18671 + spin_lock(&aopen->spin);
18672 + hlist_for_each_entry(node, &aopen->head, hlist)
18673 + if (node->file == file) {
18674 + args.h_file = node->h_file;
18677 + spin_unlock(&aopen->spin);
18678 + /* AuDebugOn(!args.h_file); */
18680 + return au_do_open(file, &args);
18683 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18684 + struct file *file, unsigned int open_flag,
18685 + umode_t create_mode, int *opened)
18687 + int err, h_opened = *opened;
18688 + unsigned int lkup_flags;
18689 + struct dentry *parent;
18690 + struct dentry *d;
18691 + struct au_sphlhead *aopen;
18692 + struct vfsub_aopen_args args = {
18693 + .open_flag = open_flag,
18694 + .create_mode = create_mode,
18695 + .opened = &h_opened
18697 + struct aopen_node aopen_node = {
18702 + AuDbg("open_flag 0%o\n", open_flag);
18703 + AuDbgDentry(dentry);
18706 + if (!au_di(dentry)) {
18707 + lkup_flags = LOOKUP_OPEN;
18708 + if (open_flag & O_CREAT)
18709 + lkup_flags |= LOOKUP_CREATE;
18710 + d = aufs_lookup(dir, dentry, lkup_flags);
18712 + err = PTR_ERR(d);
18717 + * obsoleted dentry found.
18718 + * another error will be returned later.
18724 + AuDbgDentry(dentry);
18727 + if (d_is_positive(dentry)
18728 + || d_unhashed(dentry)
18729 + || d_unlinked(dentry)
18730 + || !(open_flag & O_CREAT))
18731 + goto out_no_open;
18733 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18734 + if (unlikely(err))
18737 + parent = dentry->d_parent; /* dir is locked */
18738 + di_write_lock_parent(parent);
18739 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
18740 + if (unlikely(err))
18743 + AuDbgDentry(dentry);
18744 + if (d_is_positive(dentry))
18747 + args.file = get_empty_filp();
18748 + err = PTR_ERR(args.file);
18749 + if (IS_ERR(args.file))
18752 + args.file->f_flags = file->f_flags;
18753 + err = au_aopen_or_create(dir, dentry, &args);
18755 + AuDbgFile(args.file);
18756 + if (unlikely(err < 0)) {
18757 + if (h_opened & FILE_OPENED)
18760 + put_filp(args.file);
18764 + /* some filesystems don't set FILE_CREATED while succeeded? */
18765 + *opened |= FILE_CREATED;
18766 + if (h_opened & FILE_OPENED)
18767 + aopen_node.h_file = args.file;
18769 + put_filp(args.file);
18770 + args.file = NULL;
18772 + aopen = &au_sbi(dir->i_sb)->si_aopen;
18773 + au_sphl_add(&aopen_node.hlist, aopen);
18774 + err = finish_open(file, dentry, au_do_aopen, opened);
18775 + au_sphl_del(&aopen_node.hlist, aopen);
18778 + if (aopen_node.h_file)
18779 + fput(aopen_node.h_file);
18782 + di_write_unlock(parent);
18783 + aufs_read_unlock(dentry, AuLock_DW);
18784 + AuDbgDentry(dentry);
18785 + if (unlikely(err))
18788 + if (!err && !(*opened & FILE_CREATED)) {
18789 + AuLabel(out_no_open);
18791 + err = finish_no_open(file, dentry);
18794 + AuDbg("%pd%s%s\n", dentry,
18795 + (*opened & FILE_CREATED) ? " created" : "",
18796 + (*opened & FILE_OPENED) ? " opened" : "");
18802 +/* ---------------------------------------------------------------------- */
18804 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18805 + const unsigned char add_entry, aufs_bindex_t bcpup,
18806 + aufs_bindex_t btop)
18809 + struct dentry *h_parent;
18810 + struct inode *h_dir;
18813 + IMustLock(d_inode(parent));
18815 + di_write_lock_parent(parent);
18818 + if (!au_h_dptr(parent, bcpup)) {
18819 + if (btop > bcpup)
18820 + err = au_cpup_dirs(dentry, bcpup);
18821 + else if (btop < bcpup)
18822 + err = au_cpdown_dirs(dentry, bcpup);
18826 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18827 + h_parent = au_h_dptr(parent, bcpup);
18828 + h_dir = d_inode(h_parent);
18829 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
18830 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
18831 + /* todo: no unlock here */
18832 + inode_unlock(h_dir);
18834 + AuDbg("bcpup %d\n", bcpup);
18836 + if (d_really_is_negative(dentry))
18837 + au_set_h_dptr(dentry, btop, NULL);
18838 + au_update_dbrange(dentry, /*do_put_zero*/0);
18843 + di_write_unlock(parent);
18845 + err = bcpup; /* success */
18852 + * decide the branch and the parent dir where we will create a new entry.
18853 + * returns new bindex or an error.
18854 + * copyup the parent dir if needed.
18856 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18857 + struct au_wr_dir_args *args)
18860 + unsigned int flags;
18861 + aufs_bindex_t bcpup, btop, src_btop;
18862 + const unsigned char add_entry
18863 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18864 + | au_ftest_wrdir(args->flags, TMPFILE);
18865 + struct super_block *sb;
18866 + struct dentry *parent;
18867 + struct au_sbinfo *sbinfo;
18869 + sb = dentry->d_sb;
18870 + sbinfo = au_sbi(sb);
18871 + parent = dget_parent(dentry);
18872 + btop = au_dbtop(dentry);
18874 + if (args->force_btgt < 0) {
18875 + if (src_dentry) {
18876 + src_btop = au_dbtop(src_dentry);
18877 + if (src_btop < btop)
18878 + bcpup = src_btop;
18879 + } else if (add_entry) {
18881 + if (au_ftest_wrdir(args->flags, ISDIR))
18882 + au_fset_wbr(flags, DIR);
18883 + err = AuWbrCreate(sbinfo, dentry, flags);
18887 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
18889 + err = AuWbrCopyup(sbinfo, dentry);
18891 + if (!IS_ROOT(dentry)) {
18892 + di_read_lock_parent(parent, !AuLock_IR);
18893 + err = AuWbrCopyup(sbinfo, dentry);
18894 + di_read_unlock(parent, !AuLock_IR);
18896 + err = AuWbrCopyup(sbinfo, dentry);
18899 + if (unlikely(err < 0))
18903 + bcpup = args->force_btgt;
18904 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
18907 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
18909 + if (bcpup == btop)
18910 + goto out; /* success */
18912 + /* copyup the new parent into the branch we process */
18913 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
18915 + if (d_really_is_negative(dentry)) {
18916 + au_set_h_dptr(dentry, btop, NULL);
18917 + au_set_dbtop(dentry, bcpup);
18918 + au_set_dbbot(dentry, bcpup);
18920 + AuDebugOn(add_entry
18921 + && !au_ftest_wrdir(args->flags, TMPFILE)
18922 + && !au_h_dptr(dentry, bcpup));
18930 +/* ---------------------------------------------------------------------- */
18932 +void au_pin_hdir_unlock(struct au_pin *p)
18935 + au_hn_inode_unlock(p->hdir);
18938 +int au_pin_hdir_lock(struct au_pin *p)
18946 + /* even if an error happens later, keep this lock */
18947 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
18950 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
18955 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18956 + p->h_parent, p->br);
18962 +int au_pin_hdir_relock(struct au_pin *p)
18965 + struct inode *h_i;
18966 + struct dentry *h_d[] = {
18971 + err = au_pin_hdir_lock(p);
18972 + if (unlikely(err))
18975 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
18978 + if (d_is_positive(h_d[i])) {
18979 + h_i = d_inode(h_d[i]);
18980 + err = !h_i->i_nlink;
18988 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
18990 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
18991 + p->hdir->hi_inode->i_rwsem.owner = task;
18995 +void au_pin_hdir_acquire_nest(struct au_pin *p)
18998 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
18999 + p->lsc_hi, 0, NULL, _RET_IP_);
19000 + au_pin_hdir_set_owner(p, current);
19004 +void au_pin_hdir_release(struct au_pin *p)
19007 + au_pin_hdir_set_owner(p, p->task);
19008 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
19012 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
19014 + if (pin && pin->parent)
19015 + return au_h_dptr(pin->parent, pin->bindex);
19019 +void au_unpin(struct au_pin *p)
19022 + au_pin_hdir_unlock(p);
19023 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
19024 + vfsub_mnt_drop_write(p->h_mnt);
19028 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19029 + di_read_unlock(p->parent, AuLock_IR);
19030 + iput(p->hdir->hi_inode);
19032 + p->parent = NULL;
19035 + /* do not clear p->task */
19038 +int au_do_pin(struct au_pin *p)
19041 + struct super_block *sb;
19042 + struct inode *h_dir;
19045 + sb = p->dentry->d_sb;
19046 + p->br = au_sbr(sb, p->bindex);
19047 + if (IS_ROOT(p->dentry)) {
19048 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19049 + p->h_mnt = au_br_mnt(p->br);
19050 + err = vfsub_mnt_want_write(p->h_mnt);
19051 + if (unlikely(err)) {
19052 + au_fclr_pin(p->flags, MNT_WRITE);
19059 + p->h_dentry = NULL;
19060 + if (p->bindex <= au_dbbot(p->dentry))
19061 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
19063 + p->parent = dget_parent(p->dentry);
19064 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19065 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
19068 + p->h_parent = au_h_dptr(p->parent, p->bindex);
19069 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
19071 + h_dir = p->hdir->hi_inode;
19075 + * if DI_LOCKED is not set, then p->parent may be different
19076 + * and h_parent can be NULL.
19078 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
19080 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19081 + di_read_unlock(p->parent, AuLock_IR);
19083 + p->parent = NULL;
19087 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19088 + p->h_mnt = au_br_mnt(p->br);
19089 + err = vfsub_mnt_want_write(p->h_mnt);
19090 + if (unlikely(err)) {
19091 + au_fclr_pin(p->flags, MNT_WRITE);
19092 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19093 + di_read_unlock(p->parent, AuLock_IR);
19095 + p->parent = NULL;
19101 + err = au_pin_hdir_lock(p);
19103 + goto out; /* success */
19108 + pr_err("err %d\n", err);
19109 + err = au_busy_or_stale();
19114 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
19115 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19116 + unsigned int udba, unsigned char flags)
19118 + p->dentry = dentry;
19120 + p->lsc_di = lsc_di;
19121 + p->lsc_hi = lsc_hi;
19122 + p->flags = flags;
19123 + p->bindex = bindex;
19125 + p->parent = NULL;
19129 + p->h_dentry = NULL;
19130 + p->h_parent = NULL;
19132 + p->task = current;
19135 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19136 + unsigned int udba, unsigned char flags)
19138 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
19140 + return au_do_pin(pin);
19143 +/* ---------------------------------------------------------------------- */
19146 + * ->setattr() and ->getattr() are called in various cases.
19147 + * chmod, stat: dentry is revalidated.
19148 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
19150 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
19152 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
19153 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
19156 + struct dentry *parent;
19159 + if (au_digen_test(dentry, sigen)) {
19160 + parent = dget_parent(dentry);
19161 + di_read_lock_parent(parent, AuLock_IR);
19162 + err = au_refresh_dentry(dentry, parent);
19163 + di_read_unlock(parent, AuLock_IR);
19171 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19172 + struct au_icpup_args *a)
19176 + aufs_bindex_t btop, ibtop;
19177 + struct dentry *hi_wh, *parent;
19178 + struct inode *inode;
19179 + struct au_wr_dir_args wr_dir_args = {
19180 + .force_btgt = -1,
19184 + if (d_is_dir(dentry))
19185 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19186 + /* plink or hi_wh() case */
19187 + btop = au_dbtop(dentry);
19188 + inode = d_inode(dentry);
19189 + ibtop = au_ibtop(inode);
19190 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
19191 + wr_dir_args.force_btgt = ibtop;
19192 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19193 + if (unlikely(err < 0))
19197 + au_fset_icpup(a->flags, DID_CPUP);
19200 + a->pin_flags = AuPin_MNT_WRITE;
19202 + if (!IS_ROOT(dentry)) {
19203 + au_fset_pin(a->pin_flags, DI_LOCKED);
19204 + parent = dget_parent(dentry);
19205 + di_write_lock_parent(parent);
19208 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
19209 + if (unlikely(err))
19213 + a->h_path.dentry = au_h_dptr(dentry, btop);
19214 + a->h_inode = d_inode(a->h_path.dentry);
19215 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
19216 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19217 + if (ia->ia_size < i_size_read(a->h_inode))
19218 + sz = ia->ia_size;
19219 + inode_unlock(a->h_inode);
19223 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
19224 + hi_wh = au_hi_wh(inode, a->btgt);
19226 + struct au_cp_generic cpg = {
19227 + .dentry = dentry,
19233 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
19234 + if (unlikely(err))
19236 + hi_wh = au_hi_wh(inode, a->btgt);
19237 + /* todo: revalidate hi_wh? */
19242 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
19243 + di_downgrade_lock(parent, AuLock_IR);
19247 + if (!au_ftest_icpup(a->flags, DID_CPUP))
19248 + goto out; /* success */
19250 + if (!d_unhashed(dentry)) {
19251 + struct au_cp_generic cpg = {
19252 + .dentry = dentry,
19257 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19259 + err = au_sio_cpup_simple(&cpg);
19261 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19262 + } else if (!hi_wh)
19263 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19265 + a->h_path.dentry = hi_wh; /* do not dget here */
19268 + a->h_inode = d_inode(a->h_path.dentry);
19270 + goto out; /* success */
19271 + au_unpin(&a->pin);
19274 + di_write_unlock(parent);
19279 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19283 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19286 + struct inode *inode, *delegated;
19287 + struct super_block *sb;
19288 + struct file *file;
19289 + struct au_icpup_args *a;
19291 + inode = d_inode(dentry);
19292 + IMustLock(inode);
19295 + a = kzalloc(sizeof(*a), GFP_NOFS);
19296 + if (unlikely(!a))
19299 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19300 + ia->ia_valid &= ~ATTR_MODE;
19303 + sb = dentry->d_sb;
19304 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19305 + if (unlikely(err))
19308 + if (ia->ia_valid & ATTR_FILE) {
19309 + /* currently ftruncate(2) only */
19310 + AuDebugOn(!d_is_reg(dentry));
19311 + file = ia->ia_file;
19312 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
19313 + if (unlikely(err))
19315 + ia->ia_file = au_hf_top(file);
19316 + a->udba = AuOpt_UDBA_NONE;
19318 + /* fchmod() doesn't pass ia_file */
19319 + a->udba = au_opt_udba(sb);
19320 + di_write_lock_child(dentry);
19321 + /* no d_unlinked(), to set UDBA_NONE for root */
19322 + if (d_unhashed(dentry))
19323 + a->udba = AuOpt_UDBA_NONE;
19324 + if (a->udba != AuOpt_UDBA_NONE) {
19325 + AuDebugOn(IS_ROOT(dentry));
19326 + err = au_reval_for_attr(dentry, au_sigen(sb));
19327 + if (unlikely(err))
19332 + err = au_pin_and_icpup(dentry, ia, a);
19333 + if (unlikely(err < 0))
19335 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19336 + ia->ia_file = NULL;
19337 + ia->ia_valid &= ~ATTR_FILE;
19340 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19341 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19342 + == (ATTR_MODE | ATTR_CTIME)) {
19343 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19344 + if (unlikely(err))
19346 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19347 + && (ia->ia_valid & ATTR_CTIME)) {
19348 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19349 + if (unlikely(err))
19353 + if (ia->ia_valid & ATTR_SIZE) {
19356 + if (ia->ia_size < i_size_read(inode))
19358 + truncate_setsize(inode, ia->ia_size);
19361 + if (ia->ia_valid & ATTR_FILE)
19363 + inode_unlock(a->h_inode);
19364 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19365 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19367 + delegated = NULL;
19369 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19371 + err = break_deleg_wait(&delegated);
19379 + * regardless aufs 'acl' option setting.
19380 + * why don't all acl-aware fs call this func from their ->setattr()?
19382 + if (!err && (ia->ia_valid & ATTR_MODE))
19383 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
19385 + au_cpup_attr_changeable(inode);
19388 + inode_unlock(a->h_inode);
19389 + au_unpin(&a->pin);
19390 + if (unlikely(err))
19391 + au_update_dbtop(dentry);
19393 + di_write_unlock(dentry);
19395 + fi_write_unlock(file);
19396 + ia->ia_file = file;
19397 + ia->ia_valid |= ATTR_FILE;
19400 + si_read_unlock(sb);
19408 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19409 +static int au_h_path_to_set_attr(struct dentry *dentry,
19410 + struct au_icpup_args *a, struct path *h_path)
19413 + struct super_block *sb;
19415 + sb = dentry->d_sb;
19416 + a->udba = au_opt_udba(sb);
19417 + /* no d_unlinked(), to set UDBA_NONE for root */
19418 + if (d_unhashed(dentry))
19419 + a->udba = AuOpt_UDBA_NONE;
19420 + if (a->udba != AuOpt_UDBA_NONE) {
19421 + AuDebugOn(IS_ROOT(dentry));
19422 + err = au_reval_for_attr(dentry, au_sigen(sb));
19423 + if (unlikely(err))
19426 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19427 + if (unlikely(err < 0))
19430 + h_path->dentry = a->h_path.dentry;
19431 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19437 +ssize_t au_srxattr(struct dentry *dentry, struct inode *inode,
19438 + struct au_srxattr *arg)
19441 + struct path h_path;
19442 + struct super_block *sb;
19443 + struct au_icpup_args *a;
19444 + struct inode *h_inode;
19446 + IMustLock(inode);
19449 + a = kzalloc(sizeof(*a), GFP_NOFS);
19450 + if (unlikely(!a))
19453 + sb = dentry->d_sb;
19454 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19455 + if (unlikely(err))
19458 + h_path.dentry = NULL; /* silence gcc */
19459 + di_write_lock_child(dentry);
19460 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19461 + if (unlikely(err))
19464 + inode_unlock(a->h_inode);
19465 + switch (arg->type) {
19466 + case AU_XATTR_SET:
19467 + AuDebugOn(d_is_negative(h_path.dentry));
19468 + err = vfsub_setxattr(h_path.dentry,
19469 + arg->u.set.name, arg->u.set.value,
19470 + arg->u.set.size, arg->u.set.flags);
19472 + case AU_XATTR_REMOVE:
19473 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
19476 + err = -EOPNOTSUPP;
19477 + h_inode = d_inode(h_path.dentry);
19478 + if (h_inode->i_op->set_acl)
19479 + err = h_inode->i_op->set_acl(h_inode,
19480 + arg->u.acl_set.acl,
19481 + arg->u.acl_set.type);
19485 + au_cpup_attr_timesizes(inode);
19487 + au_unpin(&a->pin);
19488 + if (unlikely(err))
19489 + au_update_dbtop(dentry);
19492 + di_write_unlock(dentry);
19493 + si_read_unlock(sb);
19502 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19503 + unsigned int nlink)
19507 + inode->i_mode = st->mode;
19508 + /* don't i_[ug]id_write() here */
19509 + inode->i_uid = st->uid;
19510 + inode->i_gid = st->gid;
19511 + inode->i_atime = st->atime;
19512 + inode->i_mtime = st->mtime;
19513 + inode->i_ctime = st->ctime;
19515 + au_cpup_attr_nlink(inode, /*force*/0);
19516 + if (S_ISDIR(inode->i_mode)) {
19517 + n = inode->i_nlink;
19520 + smp_mb(); /* for i_nlink */
19521 + /* 0 can happen */
19522 + set_nlink(inode, n);
19525 + spin_lock(&inode->i_lock);
19526 + inode->i_blocks = st->blocks;
19527 + i_size_write(inode, st->size);
19528 + spin_unlock(&inode->i_lock);
19532 + * common routine for aufs_getattr() and aufs_getxattr().
19533 + * returns zero or negative (an error).
19534 + * @dentry will be read-locked in success.
19536 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
19539 + unsigned int mnt_flags, sigen;
19540 + unsigned char udba_none;
19541 + aufs_bindex_t bindex;
19542 + struct super_block *sb, *h_sb;
19543 + struct inode *inode;
19545 + h_path->mnt = NULL;
19546 + h_path->dentry = NULL;
19549 + sb = dentry->d_sb;
19550 + mnt_flags = au_mntflags(sb);
19551 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19553 + /* support fstat(2) */
19554 + if (!d_unlinked(dentry) && !udba_none) {
19555 + sigen = au_sigen(sb);
19556 + err = au_digen_test(dentry, sigen);
19558 + di_read_lock_child(dentry, AuLock_IR);
19559 + err = au_dbrange_test(dentry);
19560 + if (unlikely(err)) {
19561 + di_read_unlock(dentry, AuLock_IR);
19565 + AuDebugOn(IS_ROOT(dentry));
19566 + di_write_lock_child(dentry);
19567 + err = au_dbrange_test(dentry);
19569 + err = au_reval_for_attr(dentry, sigen);
19571 + di_downgrade_lock(dentry, AuLock_IR);
19573 + di_write_unlock(dentry);
19578 + di_read_lock_child(dentry, AuLock_IR);
19580 + inode = d_inode(dentry);
19581 + bindex = au_ibtop(inode);
19582 + h_path->mnt = au_sbr_mnt(sb, bindex);
19583 + h_sb = h_path->mnt->mnt_sb;
19585 + && !au_test_fs_bad_iattr(h_sb)
19587 + goto out; /* success */
19589 + if (au_dbtop(dentry) == bindex)
19590 + h_path->dentry = au_h_dptr(dentry, bindex);
19591 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19592 + h_path->dentry = au_plink_lkup(inode, bindex);
19593 + if (IS_ERR(h_path->dentry))
19594 + /* pretending success */
19595 + h_path->dentry = NULL;
19597 + dput(h_path->dentry);
19604 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19605 + struct dentry *dentry, struct kstat *st)
19608 + unsigned char positive;
19609 + struct path h_path;
19610 + struct inode *inode;
19611 + struct super_block *sb;
19613 + inode = d_inode(dentry);
19614 + sb = dentry->d_sb;
19615 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19616 + if (unlikely(err))
19618 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
19619 + if (unlikely(err))
19621 + if (unlikely(!h_path.dentry))
19622 + /* illegally overlapped or something */
19623 + goto out_fill; /* pretending success */
19625 + positive = d_is_positive(h_path.dentry);
19627 + err = vfs_getattr(&h_path, st);
19630 + au_refresh_iattr(inode, st,
19631 + d_inode(h_path.dentry)->i_nlink);
19632 + goto out_fill; /* success */
19638 + generic_fillattr(inode, st);
19640 + di_read_unlock(dentry, AuLock_IR);
19642 + si_read_unlock(sb);
19648 +/* ---------------------------------------------------------------------- */
19650 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
19651 + struct delayed_call *done)
19654 + struct dentry *h_dentry;
19655 + struct inode *h_inode;
19657 + aufs_bindex_t bindex;
19659 + ret = NULL; /* suppress a warning */
19664 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19665 + if (unlikely(err))
19668 + err = au_d_hashed_positive(dentry);
19669 + if (unlikely(err))
19673 + inode = d_inode(dentry);
19674 + bindex = au_ibtop(inode);
19675 + h_inode = au_h_iptr(inode, bindex);
19676 + if (unlikely(!h_inode->i_op->get_link))
19681 + if (au_dbtop(dentry) <= bindex) {
19682 + h_dentry = au_h_dptr(dentry, bindex);
19687 + h_dentry = d_find_any_alias(h_inode);
19688 + if (IS_ERR(h_dentry)) {
19689 + err = PTR_ERR(h_dentry);
19693 + if (unlikely(!h_dentry))
19697 + AuDbg("%pf\n", h_inode->i_op->get_link);
19698 + AuDbgDentry(h_dentry);
19699 + ret = h_inode->i_op->get_link(h_dentry, h_inode, done);
19702 + err = PTR_ERR(ret);
19705 + aufs_read_unlock(dentry, AuLock_IR);
19707 + if (unlikely(err))
19708 + ret = ERR_PTR(err);
19709 + AuTraceErrPtr(ret);
19713 +/* ---------------------------------------------------------------------- */
19715 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19718 + struct super_block *sb;
19719 + struct inode *h_inode;
19721 + sb = inode->i_sb;
19722 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19724 + si_read_lock(sb, AuLock_FLUSH);
19725 + ii_write_lock_child(inode);
19727 + h_inode = au_h_iptr(inode, au_ibtop(inode));
19728 + err = vfsub_update_time(h_inode, ts, flags);
19731 + au_cpup_attr_timesizes(inode);
19732 + ii_write_unlock(inode);
19733 + si_read_unlock(sb);
19736 + if (!err && (flags & S_VERSION))
19737 + inode_inc_iversion(inode);
19742 +/* ---------------------------------------------------------------------- */
19744 +/* no getattr version will be set by module.c:aufs_init() */
19745 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
19747 + [AuIop_SYMLINK] = {
19748 + .permission = aufs_permission,
19749 +#ifdef CONFIG_FS_POSIX_ACL
19750 + .get_acl = aufs_get_acl,
19751 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19754 + .setattr = aufs_setattr,
19755 + .getattr = aufs_getattr,
19757 +#ifdef CONFIG_AUFS_XATTR
19758 + .setxattr = aufs_setxattr,
19759 + .getxattr = aufs_getxattr,
19760 + .listxattr = aufs_listxattr,
19761 + .removexattr = aufs_removexattr,
19764 + .readlink = generic_readlink,
19765 + .get_link = aufs_get_link,
19767 + /* .update_time = aufs_update_time */
19770 + .create = aufs_create,
19771 + .lookup = aufs_lookup,
19772 + .link = aufs_link,
19773 + .unlink = aufs_unlink,
19774 + .symlink = aufs_symlink,
19775 + .mkdir = aufs_mkdir,
19776 + .rmdir = aufs_rmdir,
19777 + .mknod = aufs_mknod,
19778 + .rename = aufs_rename,
19780 + .permission = aufs_permission,
19781 +#ifdef CONFIG_FS_POSIX_ACL
19782 + .get_acl = aufs_get_acl,
19783 + .set_acl = aufs_set_acl,
19786 + .setattr = aufs_setattr,
19787 + .getattr = aufs_getattr,
19789 +#ifdef CONFIG_AUFS_XATTR
19790 + .setxattr = aufs_setxattr,
19791 + .getxattr = aufs_getxattr,
19792 + .listxattr = aufs_listxattr,
19793 + .removexattr = aufs_removexattr,
19796 + .update_time = aufs_update_time,
19797 + .atomic_open = aufs_atomic_open,
19798 + .tmpfile = aufs_tmpfile
19800 + [AuIop_OTHER] = {
19801 + .permission = aufs_permission,
19802 +#ifdef CONFIG_FS_POSIX_ACL
19803 + .get_acl = aufs_get_acl,
19804 + .set_acl = aufs_set_acl,
19807 + .setattr = aufs_setattr,
19808 + .getattr = aufs_getattr,
19810 +#ifdef CONFIG_AUFS_XATTR
19811 + .setxattr = aufs_setxattr,
19812 + .getxattr = aufs_getxattr,
19813 + .listxattr = aufs_listxattr,
19814 + .removexattr = aufs_removexattr,
19817 + .update_time = aufs_update_time
19820 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19821 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19822 +++ linux/fs/aufs/i_op_del.c 2016-07-25 19:05:34.814493242 +0200
19825 + * Copyright (C) 2005-2016 Junjiro R. Okajima
19827 + * This program, aufs is free software; you can redistribute it and/or modify
19828 + * it under the terms of the GNU General Public License as published by
19829 + * the Free Software Foundation; either version 2 of the License, or
19830 + * (at your option) any later version.
19832 + * This program is distributed in the hope that it will be useful,
19833 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19834 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19835 + * GNU General Public License for more details.
19837 + * You should have received a copy of the GNU General Public License
19838 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19842 + * inode operations (del entry)
19848 + * decide if a new whiteout for @dentry is necessary or not.
19849 + * when it is necessary, prepare the parent dir for the upper branch whose
19850 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19851 + * be done by caller.
19853 + * 0: wh is unnecessary
19854 + * plus: wh is necessary
19857 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19859 + int need_wh, err;
19860 + aufs_bindex_t btop;
19861 + struct super_block *sb;
19863 + sb = dentry->d_sb;
19864 + btop = au_dbtop(dentry);
19865 + if (*bcpup < 0) {
19867 + if (au_test_ro(sb, btop, d_inode(dentry))) {
19868 + err = AuWbrCopyup(au_sbi(sb), dentry);
19870 + if (unlikely(err < 0))
19874 + AuDebugOn(btop < *bcpup
19875 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
19876 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
19878 + if (*bcpup != btop) {
19879 + err = au_cpup_dirs(dentry, *bcpup);
19880 + if (unlikely(err))
19884 + struct au_dinfo *dinfo, *tmp;
19886 + need_wh = -ENOMEM;
19887 + dinfo = au_di(dentry);
19888 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19890 + au_di_cp(tmp, dinfo);
19891 + au_di_swap(tmp, dinfo);
19892 + /* returns the number of positive dentries */
19893 + need_wh = au_lkup_dentry(dentry, btop + 1,
19894 + /* AuLkup_IGNORE_PERM */ 0);
19895 + au_di_swap(tmp, dinfo);
19896 + au_rw_write_unlock(&tmp->di_rwsem);
19900 + AuDbg("need_wh %d\n", need_wh);
19908 + * simple tests for the del-entry operations.
19909 + * following the checks in vfs, plus the parent-child relationship.
19911 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19912 + struct dentry *h_parent, int isdir)
19916 + struct dentry *h_dentry, *h_latest;
19917 + struct inode *h_inode;
19919 + h_dentry = au_h_dptr(dentry, bindex);
19920 + if (d_really_is_positive(dentry)) {
19922 + if (unlikely(d_is_negative(h_dentry)))
19924 + h_inode = d_inode(h_dentry);
19925 + if (unlikely(!h_inode->i_nlink))
19928 + h_mode = h_inode->i_mode;
19931 + if (unlikely(S_ISDIR(h_mode)))
19933 + } else if (unlikely(!S_ISDIR(h_mode))) {
19938 + /* rename(2) case */
19940 + if (unlikely(d_is_positive(h_dentry)))
19945 + /* expected parent dir is locked */
19946 + if (unlikely(h_parent != h_dentry->d_parent))
19951 + * rmdir a dir may break the consistency on some filesystem.
19952 + * let's try heavy test.
19955 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
19956 + && au_test_h_perm(d_inode(h_parent),
19957 + MAY_EXEC | MAY_WRITE)))
19960 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
19962 + if (IS_ERR(h_latest))
19964 + if (h_latest == h_dentry)
19973 + * decide the branch where we operate for @dentry. the branch index will be set
19974 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
19975 + * dir for reverting.
19976 + * when a new whiteout is necessary, create it.
19978 +static struct dentry*
19979 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
19980 + struct au_dtime *dt, struct au_pin *pin)
19982 + struct dentry *wh_dentry;
19983 + struct super_block *sb;
19984 + struct path h_path;
19985 + int err, need_wh;
19986 + unsigned int udba;
19987 + aufs_bindex_t bcpup;
19989 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
19990 + wh_dentry = ERR_PTR(need_wh);
19991 + if (unlikely(need_wh < 0))
19994 + sb = dentry->d_sb;
19995 + udba = au_opt_udba(sb);
19997 + err = au_pin(pin, dentry, bcpup, udba,
19998 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
19999 + wh_dentry = ERR_PTR(err);
20000 + if (unlikely(err))
20003 + h_path.dentry = au_pinned_h_parent(pin);
20004 + if (udba != AuOpt_UDBA_NONE
20005 + && au_dbtop(dentry) == bcpup) {
20006 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
20007 + wh_dentry = ERR_PTR(err);
20008 + if (unlikely(err))
20012 + h_path.mnt = au_sbr_mnt(sb, bcpup);
20013 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
20014 + wh_dentry = NULL;
20016 + goto out; /* success, no need to create whiteout */
20018 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
20019 + if (IS_ERR(wh_dentry))
20022 + /* returns with the parent is locked and wh_dentry is dget-ed */
20023 + goto out; /* success */
20028 + return wh_dentry;
20032 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
20033 + * in order to be revertible and save time for removing many child whiteouts
20035 + * returns 1 when there are too many child whiteout and caller should remove
20036 + * them asynchronously. returns 0 when the number of children is enough small to
20037 + * remove now or the branch fs is a remote fs.
20038 + * otherwise return an error.
20040 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
20041 + struct au_nhash *whlist, struct inode *dir)
20043 + int rmdir_later, err, dirwh;
20044 + struct dentry *h_dentry;
20045 + struct super_block *sb;
20046 + struct inode *inode;
20048 + sb = dentry->d_sb;
20049 + SiMustAnyLock(sb);
20050 + h_dentry = au_h_dptr(dentry, bindex);
20051 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
20052 + if (unlikely(err))
20055 + /* stop monitoring */
20056 + inode = d_inode(dentry);
20057 + au_hn_free(au_hi(inode, bindex));
20059 + if (!au_test_fs_remote(h_dentry->d_sb)) {
20060 + dirwh = au_sbi(sb)->si_dirwh;
20061 + rmdir_later = (dirwh <= 1);
20062 + if (!rmdir_later)
20063 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
20066 + return rmdir_later;
20069 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
20070 + if (unlikely(err)) {
20071 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
20072 + h_dentry, bindex, err);
20082 + * final procedure for deleting a entry.
20083 + * maintain dentry and iattr.
20085 +static void epilog(struct inode *dir, struct dentry *dentry,
20086 + aufs_bindex_t bindex)
20088 + struct inode *inode;
20090 + inode = d_inode(dentry);
20092 + inode->i_ctime = dir->i_ctime;
20094 + au_dir_ts(dir, bindex);
20095 + dir->i_version++;
20099 + * when an error happened, remove the created whiteout and revert everything.
20101 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
20102 + aufs_bindex_t bwh, struct dentry *wh_dentry,
20103 + struct dentry *dentry, struct au_dtime *dt)
20106 + struct path h_path = {
20107 + .dentry = wh_dentry,
20108 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
20111 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
20113 + au_set_dbwh(dentry, bwh);
20114 + au_dtime_revert(dt);
20118 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
20122 +/* ---------------------------------------------------------------------- */
20124 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
20127 + aufs_bindex_t bwh, bindex, btop;
20128 + struct inode *inode, *h_dir, *delegated;
20129 + struct dentry *parent, *wh_dentry;
20130 + /* to reuduce stack size */
20132 + struct au_dtime dt;
20133 + struct au_pin pin;
20134 + struct path h_path;
20140 + a = kmalloc(sizeof(*a), GFP_NOFS);
20141 + if (unlikely(!a))
20144 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20145 + if (unlikely(err))
20147 + err = au_d_hashed_positive(dentry);
20148 + if (unlikely(err))
20150 + inode = d_inode(dentry);
20151 + IMustLock(inode);
20153 + if (unlikely(d_is_dir(dentry)))
20154 + goto out_unlock; /* possible? */
20156 + btop = au_dbtop(dentry);
20157 + bwh = au_dbwh(dentry);
20159 + parent = dentry->d_parent; /* dir inode is locked */
20160 + di_write_lock_parent(parent);
20161 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
20163 + err = PTR_ERR(wh_dentry);
20164 + if (IS_ERR(wh_dentry))
20167 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
20168 + a->h_path.dentry = au_h_dptr(dentry, btop);
20169 + dget(a->h_path.dentry);
20170 + if (bindex == btop) {
20171 + h_dir = au_pinned_h_dir(&a->pin);
20172 + delegated = NULL;
20173 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
20174 + if (unlikely(err == -EWOULDBLOCK)) {
20175 + pr_warn("cannot retry for NFSv4 delegation"
20176 + " for an internal unlink\n");
20180 + /* dir inode is locked */
20181 + h_dir = d_inode(wh_dentry->d_parent);
20182 + IMustLock(h_dir);
20187 + vfsub_drop_nlink(inode);
20188 + epilog(dir, dentry, bindex);
20190 + /* update target timestamps */
20191 + if (bindex == btop) {
20192 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
20194 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20196 + /* todo: this timestamp may be reverted later */
20197 + inode->i_ctime = h_dir->i_ctime;
20198 + goto out_unpin; /* success */
20205 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20212 + au_unpin(&a->pin);
20214 + dput(a->h_path.dentry);
20216 + di_write_unlock(parent);
20218 + aufs_read_unlock(dentry, AuLock_DW);
20225 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
20227 + int err, rmdir_later;
20228 + aufs_bindex_t bwh, bindex, btop;
20229 + struct inode *inode;
20230 + struct dentry *parent, *wh_dentry, *h_dentry;
20231 + struct au_whtmp_rmdir *args;
20232 + /* to reuduce stack size */
20234 + struct au_dtime dt;
20235 + struct au_pin pin;
20241 + a = kmalloc(sizeof(*a), GFP_NOFS);
20242 + if (unlikely(!a))
20245 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20246 + if (unlikely(err))
20248 + err = au_alive_dir(dentry);
20249 + if (unlikely(err))
20251 + inode = d_inode(dentry);
20252 + IMustLock(inode);
20254 + if (unlikely(!d_is_dir(dentry)))
20255 + goto out_unlock; /* possible? */
20258 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20259 + if (unlikely(!args))
20262 + parent = dentry->d_parent; /* dir inode is locked */
20263 + di_write_lock_parent(parent);
20264 + err = au_test_empty(dentry, &args->whlist);
20265 + if (unlikely(err))
20268 + btop = au_dbtop(dentry);
20269 + bwh = au_dbwh(dentry);
20271 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20273 + err = PTR_ERR(wh_dentry);
20274 + if (IS_ERR(wh_dentry))
20277 + h_dentry = au_h_dptr(dentry, btop);
20280 + if (bindex == btop) {
20281 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
20283 + rmdir_later = err;
20287 + /* stop monitoring */
20288 + au_hn_free(au_hi(inode, btop));
20290 + /* dir inode is locked */
20291 + IMustLock(d_inode(wh_dentry->d_parent));
20296 + vfsub_dead_dir(inode);
20297 + au_set_dbdiropq(dentry, -1);
20298 + epilog(dir, dentry, bindex);
20300 + if (rmdir_later) {
20301 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
20305 + goto out_unpin; /* success */
20313 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20320 + au_unpin(&a->pin);
20324 + di_write_unlock(parent);
20326 + au_whtmp_rmdir_free(args);
20328 + aufs_read_unlock(dentry, AuLock_DW);
20335 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20336 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20337 +++ linux/fs/aufs/i_op_ren.c 2016-07-25 19:05:34.814493242 +0200
20340 + * Copyright (C) 2005-2016 Junjiro R. Okajima
20342 + * This program, aufs is free software; you can redistribute it and/or modify
20343 + * it under the terms of the GNU General Public License as published by
20344 + * the Free Software Foundation; either version 2 of the License, or
20345 + * (at your option) any later version.
20347 + * This program is distributed in the hope that it will be useful,
20348 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20349 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20350 + * GNU General Public License for more details.
20352 + * You should have received a copy of the GNU General Public License
20353 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20357 + * inode operation (rename entry)
20358 + * todo: this is crazy monster
20363 +enum { AuSRC, AuDST, AuSrcDst };
20364 +enum { AuPARENT, AuCHILD, AuParentChild };
20366 +#define AuRen_ISDIR 1
20367 +#define AuRen_ISSAMEDIR (1 << 1)
20368 +#define AuRen_WHSRC (1 << 2)
20369 +#define AuRen_WHDST (1 << 3)
20370 +#define AuRen_MNT_WRITE (1 << 4)
20371 +#define AuRen_DT_DSTDIR (1 << 5)
20372 +#define AuRen_DIROPQ (1 << 6)
20373 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20374 +#define au_fset_ren(flags, name) \
20375 + do { (flags) |= AuRen_##name; } while (0)
20376 +#define au_fclr_ren(flags, name) \
20377 + do { (flags) &= ~AuRen_##name; } while (0)
20379 +struct au_ren_args {
20381 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20383 + struct inode *dir, *inode;
20384 + struct au_hinode *hdir;
20385 + struct au_dtime dt[AuParentChild];
20386 + aufs_bindex_t btop;
20389 +#define src_dentry sd[AuSRC].dentry
20390 +#define src_dir sd[AuSRC].dir
20391 +#define src_inode sd[AuSRC].inode
20392 +#define src_h_dentry sd[AuSRC].h_dentry
20393 +#define src_parent sd[AuSRC].parent
20394 +#define src_h_parent sd[AuSRC].h_parent
20395 +#define src_wh_dentry sd[AuSRC].wh_dentry
20396 +#define src_hdir sd[AuSRC].hdir
20397 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20398 +#define src_dt sd[AuSRC].dt
20399 +#define src_btop sd[AuSRC].btop
20401 +#define dst_dentry sd[AuDST].dentry
20402 +#define dst_dir sd[AuDST].dir
20403 +#define dst_inode sd[AuDST].inode
20404 +#define dst_h_dentry sd[AuDST].h_dentry
20405 +#define dst_parent sd[AuDST].parent
20406 +#define dst_h_parent sd[AuDST].h_parent
20407 +#define dst_wh_dentry sd[AuDST].wh_dentry
20408 +#define dst_hdir sd[AuDST].hdir
20409 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20410 +#define dst_dt sd[AuDST].dt
20411 +#define dst_btop sd[AuDST].btop
20413 + struct dentry *h_trap;
20414 + struct au_branch *br;
20415 + struct au_hinode *src_hinode;
20416 + struct path h_path;
20417 + struct au_nhash whlist;
20418 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
20420 + unsigned int flags;
20422 + struct au_whtmp_rmdir *thargs;
20423 + struct dentry *h_dst;
20426 +/* ---------------------------------------------------------------------- */
20429 + * functions for reverting.
20430 + * when an error happened in a single rename systemcall, we should revert
20431 + * everything as if nothing happened.
20432 + * we don't need to revert the copied-up/down the parent dir since they are
20436 +#define RevertFailure(fmt, ...) do { \
20437 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20438 + ##__VA_ARGS__, err, rerr); \
20442 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20446 + au_hn_inode_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20447 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
20448 + au_hn_inode_unlock(a->src_hinode);
20449 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
20451 + RevertFailure("remove diropq %pd", a->src_dentry);
20454 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20457 + struct inode *delegated;
20459 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20460 + a->src_h_parent);
20461 + rerr = PTR_ERR(a->h_path.dentry);
20462 + if (IS_ERR(a->h_path.dentry)) {
20463 + RevertFailure("lkup one %pd", a->src_dentry);
20467 + delegated = NULL;
20468 + rerr = vfsub_rename(a->dst_h_dir,
20469 + au_h_dptr(a->src_dentry, a->btgt),
20470 + a->src_h_dir, &a->h_path, &delegated);
20471 + if (unlikely(rerr == -EWOULDBLOCK)) {
20472 + pr_warn("cannot retry for NFSv4 delegation"
20473 + " for an internal rename\n");
20476 + d_drop(a->h_path.dentry);
20477 + dput(a->h_path.dentry);
20478 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20480 + RevertFailure("rename %pd", a->src_dentry);
20483 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20486 + struct inode *delegated;
20488 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20489 + a->dst_h_parent);
20490 + rerr = PTR_ERR(a->h_path.dentry);
20491 + if (IS_ERR(a->h_path.dentry)) {
20492 + RevertFailure("lkup one %pd", a->dst_dentry);
20495 + if (d_is_positive(a->h_path.dentry)) {
20496 + d_drop(a->h_path.dentry);
20497 + dput(a->h_path.dentry);
20501 + delegated = NULL;
20502 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20504 + if (unlikely(rerr == -EWOULDBLOCK)) {
20505 + pr_warn("cannot retry for NFSv4 delegation"
20506 + " for an internal rename\n");
20509 + d_drop(a->h_path.dentry);
20510 + dput(a->h_path.dentry);
20512 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20514 + RevertFailure("rename %pd", a->h_dst);
20517 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20521 + a->h_path.dentry = a->src_wh_dentry;
20522 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20523 + au_set_dbwh(a->src_dentry, a->src_bwh);
20525 + RevertFailure("unlink %pd", a->src_wh_dentry);
20527 +#undef RevertFailure
20529 +/* ---------------------------------------------------------------------- */
20532 + * when we have to copyup the renaming entry, do it with the rename-target name
20533 + * in order to minimize the cost (the later actual rename is unnecessary).
20534 + * otherwise rename it on the target branch.
20536 +static int au_ren_or_cpup(struct au_ren_args *a)
20539 + struct dentry *d;
20540 + struct inode *delegated;
20542 + d = a->src_dentry;
20543 + if (au_dbtop(d) == a->btgt) {
20544 + a->h_path.dentry = a->dst_h_dentry;
20545 + if (au_ftest_ren(a->flags, DIROPQ)
20546 + && au_dbdiropq(d) == a->btgt)
20547 + au_fclr_ren(a->flags, DIROPQ);
20548 + AuDebugOn(au_dbtop(d) != a->btgt);
20549 + delegated = NULL;
20550 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20551 + a->dst_h_dir, &a->h_path, &delegated);
20552 + if (unlikely(err == -EWOULDBLOCK)) {
20553 + pr_warn("cannot retry for NFSv4 delegation"
20554 + " for an internal rename\n");
20560 + if (!err && a->h_dst)
20561 + /* it will be set to dinfo later */
20567 +/* cf. aufs_rmdir() */
20568 +static int au_ren_del_whtmp(struct au_ren_args *a)
20571 + struct inode *dir;
20573 + dir = a->dst_dir;
20574 + SiMustAnyLock(dir->i_sb);
20575 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20576 + au_sbi(dir->i_sb)->si_dirwh)
20577 + || au_test_fs_remote(a->h_dst->d_sb)) {
20578 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20579 + if (unlikely(err))
20580 + pr_warn("failed removing whtmp dir %pd (%d), "
20581 + "ignored.\n", a->h_dst, err);
20583 + au_nhash_wh_free(&a->thargs->whlist);
20584 + a->thargs->whlist = a->whlist;
20585 + a->whlist.nh_num = 0;
20586 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20588 + a->thargs = NULL;
20594 +/* make it 'opaque' dir. */
20595 +static int au_ren_diropq(struct au_ren_args *a)
20598 + struct dentry *diropq;
20601 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
20602 + a->src_hinode = au_hi(a->src_inode, a->btgt);
20603 + au_hn_inode_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20604 + diropq = au_diropq_create(a->src_dentry, a->btgt);
20605 + au_hn_inode_unlock(a->src_hinode);
20606 + if (IS_ERR(diropq))
20607 + err = PTR_ERR(diropq);
20614 +static int do_rename(struct au_ren_args *a)
20617 + struct dentry *d, *h_d;
20619 + /* prepare workqueue args for asynchronous rmdir */
20620 + h_d = a->dst_h_dentry;
20621 + if (au_ftest_ren(a->flags, ISDIR) && d_is_positive(h_d)) {
20623 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
20624 + if (unlikely(!a->thargs))
20626 + a->h_dst = dget(h_d);
20629 + /* create whiteout for src_dentry */
20630 + if (au_ftest_ren(a->flags, WHSRC)) {
20631 + a->src_bwh = au_dbwh(a->src_dentry);
20632 + AuDebugOn(a->src_bwh >= 0);
20634 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
20635 + err = PTR_ERR(a->src_wh_dentry);
20636 + if (IS_ERR(a->src_wh_dentry))
20640 + /* lookup whiteout for dentry */
20641 + if (au_ftest_ren(a->flags, WHDST)) {
20642 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
20644 + err = PTR_ERR(h_d);
20647 + if (d_is_negative(h_d))
20650 + a->dst_wh_dentry = h_d;
20653 + /* rename dentry to tmpwh */
20655 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20656 + if (unlikely(err))
20659 + d = a->dst_dentry;
20660 + au_set_h_dptr(d, a->btgt, NULL);
20661 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20662 + if (unlikely(err))
20664 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20667 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
20669 + /* rename by vfs_rename or cpup */
20670 + d = a->dst_dentry;
20671 + if (au_ftest_ren(a->flags, ISDIR)
20672 + && (a->dst_wh_dentry
20673 + || au_dbdiropq(d) == a->btgt
20674 + /* hide the lower to keep xino */
20675 + || a->btgt < au_dbbot(d)
20676 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
20677 + au_fset_ren(a->flags, DIROPQ);
20678 + err = au_ren_or_cpup(a);
20679 + if (unlikely(err))
20680 + /* leave the copied-up one */
20683 + /* make dir opaque */
20684 + if (au_ftest_ren(a->flags, DIROPQ)) {
20685 + err = au_ren_diropq(a);
20686 + if (unlikely(err))
20690 + /* update target timestamps */
20691 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
20692 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20693 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20694 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20696 + /* remove whiteout for dentry */
20697 + if (a->dst_wh_dentry) {
20698 + a->h_path.dentry = a->dst_wh_dentry;
20699 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20701 + if (unlikely(err))
20705 + /* remove whtmp */
20707 + au_ren_del_whtmp(a); /* ignore this error */
20709 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20711 + goto out_success;
20714 + if (au_ftest_ren(a->flags, DIROPQ))
20715 + au_ren_rev_diropq(err, a);
20717 + au_ren_rev_rename(err, a);
20721 + au_ren_rev_whtmp(err, a);
20723 + dput(a->dst_wh_dentry);
20724 + a->dst_wh_dentry = NULL;
20726 + if (a->src_wh_dentry)
20727 + au_ren_rev_whsrc(err, a);
20729 + dput(a->src_wh_dentry);
20730 + dput(a->dst_wh_dentry);
20734 + au_whtmp_rmdir_free(a->thargs);
20735 + a->thargs = NULL;
20741 +/* ---------------------------------------------------------------------- */
20744 + * test if @dentry dir can be rename destination or not.
20745 + * success means, it is a logically empty dir.
20747 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20749 + return au_test_empty(dentry, whlist);
20753 + * test if @dentry dir can be rename source or not.
20754 + * if it can, return 0 and @children is filled.
20756 + * - it is a logically empty dir.
20757 + * - or, it exists on writable branch and has no children including whiteouts
20758 + * on the lower branch.
20760 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20763 + unsigned int rdhash;
20764 + aufs_bindex_t btop;
20766 + btop = au_dbtop(dentry);
20767 + if (btop != btgt) {
20768 + struct au_nhash whlist;
20770 + SiMustAnyLock(dentry->d_sb);
20771 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20773 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20775 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20776 + if (unlikely(err))
20778 + err = au_test_empty(dentry, &whlist);
20779 + au_nhash_wh_free(&whlist);
20783 + if (btop == au_dbtaildir(dentry))
20784 + return 0; /* success */
20786 + err = au_test_empty_lower(dentry);
20789 + if (err == -ENOTEMPTY) {
20790 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20791 + " is not supported\n");
20797 +/* side effect: sets whlist and h_dentry */
20798 +static int au_ren_may_dir(struct au_ren_args *a)
20801 + unsigned int rdhash;
20802 + struct dentry *d;
20804 + d = a->dst_dentry;
20805 + SiMustAnyLock(d->d_sb);
20808 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
20809 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20811 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20812 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20813 + if (unlikely(err))
20816 + au_set_dbtop(d, a->dst_btop);
20817 + err = may_rename_dstdir(d, &a->whlist);
20818 + au_set_dbtop(d, a->btgt);
20820 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
20821 + if (unlikely(err))
20824 + d = a->src_dentry;
20825 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
20826 + if (au_ftest_ren(a->flags, ISDIR)) {
20827 + err = may_rename_srcdir(d, a->btgt);
20828 + if (unlikely(err)) {
20829 + au_nhash_wh_free(&a->whlist);
20830 + a->whlist.nh_num = 0;
20837 +/* ---------------------------------------------------------------------- */
20840 + * simple tests for rename.
20841 + * following the checks in vfs, plus the parent-child relationship.
20843 +static int au_may_ren(struct au_ren_args *a)
20846 + struct inode *h_inode;
20848 + if (a->src_btop == a->btgt) {
20849 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20850 + au_ftest_ren(a->flags, ISDIR));
20851 + if (unlikely(err))
20854 + if (unlikely(a->src_h_dentry == a->h_trap))
20859 + if (a->dst_btop != a->btgt)
20862 + err = -ENOTEMPTY;
20863 + if (unlikely(a->dst_h_dentry == a->h_trap))
20867 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20868 + if (d_really_is_negative(a->dst_dentry)) {
20869 + if (d_is_negative(a->dst_h_dentry))
20870 + err = au_may_add(a->dst_dentry, a->btgt,
20871 + a->dst_h_parent, isdir);
20873 + if (unlikely(d_is_negative(a->dst_h_dentry)))
20875 + h_inode = d_inode(a->dst_h_dentry);
20876 + if (h_inode->i_nlink)
20877 + err = au_may_del(a->dst_dentry, a->btgt,
20878 + a->dst_h_parent, isdir);
20882 + if (unlikely(err == -ENOENT || err == -EEXIST))
20888 +/* ---------------------------------------------------------------------- */
20893 + * - src_dir and dir by lock_rename()
20894 + * - inode if exitsts
20897 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
20899 + * + di_write_lock2_child()
20900 + * + di_write_lock_child()
20901 + * + ii_write_lock_child()
20902 + * + di_write_lock_child2()
20903 + * + ii_write_lock_child2()
20904 + * + src_parent and parent
20905 + * + di_write_lock_parent()
20906 + * + ii_write_lock_parent()
20907 + * + di_write_lock_parent2()
20908 + * + ii_write_lock_parent2()
20909 + * + lower src_dir and dir by vfsub_lock_rename()
20910 + * + verify the every relationships between child and parent. if any
20911 + * of them failed, unlock all and return -EBUSY.
20913 +static void au_ren_unlock(struct au_ren_args *a)
20915 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
20916 + a->dst_h_parent, a->dst_hdir);
20917 + if (au_ftest_ren(a->flags, MNT_WRITE))
20918 + vfsub_mnt_drop_write(au_br_mnt(a->br));
20921 +static int au_ren_lock(struct au_ren_args *a)
20924 + unsigned int udba;
20927 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
20928 + a->src_hdir = au_hi(a->src_dir, a->btgt);
20929 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
20930 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
20932 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
20933 + if (unlikely(err))
20935 + au_fset_ren(a->flags, MNT_WRITE);
20936 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
20937 + a->dst_h_parent, a->dst_hdir);
20938 + udba = au_opt_udba(a->src_dentry->d_sb);
20939 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
20940 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
20941 + err = au_busy_or_stale();
20942 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
20943 + err = au_h_verify(a->src_h_dentry, udba,
20944 + d_inode(a->src_h_parent), a->src_h_parent,
20946 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
20947 + err = au_h_verify(a->dst_h_dentry, udba,
20948 + d_inode(a->dst_h_parent), a->dst_h_parent,
20951 + goto out; /* success */
20953 + err = au_busy_or_stale();
20954 + au_ren_unlock(a);
20960 +/* ---------------------------------------------------------------------- */
20962 +static void au_ren_refresh_dir(struct au_ren_args *a)
20964 + struct inode *dir;
20966 + dir = a->dst_dir;
20967 + dir->i_version++;
20968 + if (au_ftest_ren(a->flags, ISDIR)) {
20969 + /* is this updating defined in POSIX? */
20970 + au_cpup_attr_timesizes(a->src_inode);
20971 + au_cpup_attr_nlink(dir, /*force*/1);
20974 + au_dir_ts(dir, a->btgt);
20976 + if (au_ftest_ren(a->flags, ISSAMEDIR))
20979 + dir = a->src_dir;
20980 + dir->i_version++;
20981 + if (au_ftest_ren(a->flags, ISDIR))
20982 + au_cpup_attr_nlink(dir, /*force*/1);
20983 + au_dir_ts(dir, a->btgt);
20986 +static void au_ren_refresh(struct au_ren_args *a)
20988 + aufs_bindex_t bbot, bindex;
20989 + struct dentry *d, *h_d;
20990 + struct inode *i, *h_i;
20991 + struct super_block *sb;
20993 + d = a->dst_dentry;
20996 + /* already dget-ed by au_ren_or_cpup() */
20997 + au_set_h_dptr(d, a->btgt, a->h_dst);
20999 + i = a->dst_inode;
21001 + if (!au_ftest_ren(a->flags, ISDIR))
21002 + vfsub_drop_nlink(i);
21004 + vfsub_dead_dir(i);
21005 + au_cpup_attr_timesizes(i);
21007 + au_update_dbrange(d, /*do_put_zero*/1);
21010 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
21011 + au_set_h_dptr(d, bindex, NULL);
21012 + bbot = au_dbbot(d);
21013 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
21014 + au_set_h_dptr(d, bindex, NULL);
21015 + au_update_dbrange(d, /*do_put_zero*/0);
21018 + d = a->src_dentry;
21019 + au_set_dbwh(d, -1);
21020 + bbot = au_dbbot(d);
21021 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21022 + h_d = au_h_dptr(d, bindex);
21024 + au_set_h_dptr(d, bindex, NULL);
21026 + au_set_dbbot(d, a->btgt);
21029 + i = a->src_inode;
21030 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
21031 + return; /* success */
21033 + bbot = au_ibbot(i);
21034 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21035 + h_i = au_h_iptr(i, bindex);
21037 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
21038 + /* ignore this error */
21039 + au_set_h_iptr(i, bindex, NULL, 0);
21042 + au_set_ibbot(i, a->btgt);
21045 +/* ---------------------------------------------------------------------- */
21047 +/* mainly for link(2) and rename(2) */
21048 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
21050 + aufs_bindex_t bdiropq, bwh;
21051 + struct dentry *parent;
21052 + struct au_branch *br;
21054 + parent = dentry->d_parent;
21055 + IMustLock(d_inode(parent)); /* dir is locked */
21057 + bdiropq = au_dbdiropq(parent);
21058 + bwh = au_dbwh(dentry);
21059 + br = au_sbr(dentry->d_sb, btgt);
21060 + if (au_br_rdonly(br)
21061 + || (0 <= bdiropq && bdiropq < btgt)
21062 + || (0 <= bwh && bwh < btgt))
21065 + AuDbg("btgt %d\n", btgt);
21069 +/* sets src_btop, dst_btop and btgt */
21070 +static int au_ren_wbr(struct au_ren_args *a)
21073 + struct au_wr_dir_args wr_dir_args = {
21074 + /* .force_btgt = -1, */
21075 + .flags = AuWrDir_ADD_ENTRY
21078 + a->src_btop = au_dbtop(a->src_dentry);
21079 + a->dst_btop = au_dbtop(a->dst_dentry);
21080 + if (au_ftest_ren(a->flags, ISDIR))
21081 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21082 + wr_dir_args.force_btgt = a->src_btop;
21083 + if (a->dst_inode && a->dst_btop < a->src_btop)
21084 + wr_dir_args.force_btgt = a->dst_btop;
21085 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
21086 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
21092 +static void au_ren_dt(struct au_ren_args *a)
21094 + a->h_path.dentry = a->src_h_parent;
21095 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
21096 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
21097 + a->h_path.dentry = a->dst_h_parent;
21098 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
21101 + au_fclr_ren(a->flags, DT_DSTDIR);
21102 + if (!au_ftest_ren(a->flags, ISDIR))
21105 + a->h_path.dentry = a->src_h_dentry;
21106 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
21107 + if (d_is_positive(a->dst_h_dentry)) {
21108 + au_fset_ren(a->flags, DT_DSTDIR);
21109 + a->h_path.dentry = a->dst_h_dentry;
21110 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
21114 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
21116 + struct dentry *h_d;
21117 + struct inode *h_inode;
21119 + au_dtime_revert(a->src_dt + AuPARENT);
21120 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
21121 + au_dtime_revert(a->dst_dt + AuPARENT);
21123 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
21124 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
21125 + h_inode = d_inode(h_d);
21126 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21127 + au_dtime_revert(a->src_dt + AuCHILD);
21128 + inode_unlock(h_inode);
21130 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
21131 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
21132 + h_inode = d_inode(h_d);
21133 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21134 + au_dtime_revert(a->dst_dt + AuCHILD);
21135 + inode_unlock(h_inode);
21140 +/* ---------------------------------------------------------------------- */
21142 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
21143 + struct inode *_dst_dir, struct dentry *_dst_dentry)
21146 + /* reduce stack space */
21147 + struct au_ren_args *a;
21149 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
21150 + IMustLock(_src_dir);
21151 + IMustLock(_dst_dir);
21154 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
21155 + a = kzalloc(sizeof(*a), GFP_NOFS);
21156 + if (unlikely(!a))
21159 + a->src_dir = _src_dir;
21160 + a->src_dentry = _src_dentry;
21161 + a->src_inode = NULL;
21162 + if (d_really_is_positive(a->src_dentry))
21163 + a->src_inode = d_inode(a->src_dentry);
21164 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
21165 + a->dst_dir = _dst_dir;
21166 + a->dst_dentry = _dst_dentry;
21167 + a->dst_inode = NULL;
21168 + if (d_really_is_positive(a->dst_dentry))
21169 + a->dst_inode = d_inode(a->dst_dentry);
21170 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
21171 + if (a->dst_inode) {
21172 + IMustLock(a->dst_inode);
21173 + au_igrab(a->dst_inode);
21177 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
21178 + if (d_is_dir(a->src_dentry)) {
21179 + au_fset_ren(a->flags, ISDIR);
21180 + if (unlikely(d_really_is_positive(a->dst_dentry)
21181 + && !d_is_dir(a->dst_dentry)))
21183 + flags |= AuLock_DIRS;
21185 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, flags);
21186 + if (unlikely(err))
21189 + err = au_d_hashed_positive(a->src_dentry);
21190 + if (unlikely(err))
21193 + if (a->dst_inode) {
21195 + * If it is a dir, VFS unhash dst_dentry before this
21196 + * function. It means we cannot rely upon d_unhashed().
21198 + if (unlikely(!a->dst_inode->i_nlink))
21200 + if (!S_ISDIR(a->dst_inode->i_mode)) {
21201 + err = au_d_hashed_positive(a->dst_dentry);
21202 + if (unlikely(err))
21204 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
21206 + } else if (unlikely(d_unhashed(a->dst_dentry)))
21210 + * is it possible?
21211 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
21212 + * there may exist a problem somewhere else.
21215 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
21218 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
21219 + di_write_lock_parent(a->dst_parent);
21221 + /* which branch we process */
21222 + err = au_ren_wbr(a);
21223 + if (unlikely(err < 0))
21225 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
21226 + a->h_path.mnt = au_br_mnt(a->br);
21228 + /* are they available to be renamed */
21229 + err = au_ren_may_dir(a);
21230 + if (unlikely(err))
21231 + goto out_children;
21233 + /* prepare the writable parent dir on the same branch */
21234 + if (a->dst_btop == a->btgt) {
21235 + au_fset_ren(a->flags, WHDST);
21237 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
21238 + if (unlikely(err))
21239 + goto out_children;
21242 + if (a->src_dir != a->dst_dir) {
21244 + * this temporary unlock is safe,
21245 + * because both dir->i_mutex are locked.
21247 + di_write_unlock(a->dst_parent);
21248 + di_write_lock_parent(a->src_parent);
21249 + err = au_wr_dir_need_wh(a->src_dentry,
21250 + au_ftest_ren(a->flags, ISDIR),
21252 + di_write_unlock(a->src_parent);
21253 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
21254 + au_fclr_ren(a->flags, ISSAMEDIR);
21256 + err = au_wr_dir_need_wh(a->src_dentry,
21257 + au_ftest_ren(a->flags, ISDIR),
21259 + if (unlikely(err < 0))
21260 + goto out_children;
21262 + au_fset_ren(a->flags, WHSRC);
21265 + if (a->src_btop != a->btgt) {
21266 + struct au_pin pin;
21268 + err = au_pin(&pin, a->src_dentry, a->btgt,
21269 + au_opt_udba(a->src_dentry->d_sb),
21270 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21272 + struct au_cp_generic cpg = {
21273 + .dentry = a->src_dentry,
21275 + .bsrc = a->src_btop,
21278 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21280 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
21281 + err = au_sio_cpup_simple(&cpg);
21284 + if (unlikely(err))
21285 + goto out_children;
21286 + a->src_btop = a->btgt;
21287 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21288 + au_fset_ren(a->flags, WHSRC);
21291 + /* lock them all */
21292 + err = au_ren_lock(a);
21293 + if (unlikely(err))
21294 + /* leave the copied-up one */
21295 + goto out_children;
21297 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21298 + err = au_may_ren(a);
21299 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21300 + err = -ENAMETOOLONG;
21301 + if (unlikely(err))
21304 + /* store timestamps to be revertible */
21308 + err = do_rename(a);
21309 + if (unlikely(err))
21312 + /* update dir attributes */
21313 + au_ren_refresh_dir(a);
21315 + /* dput/iput all lower dentries */
21316 + au_ren_refresh(a);
21318 + goto out_hdir; /* success */
21321 + au_ren_rev_dt(err, a);
21323 + au_ren_unlock(a);
21325 + au_nhash_wh_free(&a->whlist);
21326 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
21327 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
21328 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21329 + au_set_dbtop(a->dst_dentry, a->dst_btop);
21333 + d_move(a->src_dentry, a->dst_dentry);
21335 + au_update_dbtop(a->dst_dentry);
21336 + if (!a->dst_inode)
21337 + d_drop(a->dst_dentry);
21339 + if (au_ftest_ren(a->flags, ISSAMEDIR))
21340 + di_write_unlock(a->dst_parent);
21342 + di_write_unlock2(a->src_parent, a->dst_parent);
21344 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21346 + iput(a->dst_inode);
21348 + au_whtmp_rmdir_free(a->thargs);
21354 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21355 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21356 +++ linux/fs/aufs/Kconfig 2015-09-24 10:47:58.248052907 +0200
21359 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21361 + Aufs is a stackable unification filesystem such as Unionfs,
21362 + which unifies several directories and provides a merged single
21364 + In the early days, aufs was entirely re-designed and
21365 + re-implemented Unionfs Version 1.x series. Introducing many
21366 + original ideas, approaches and improvements, it becomes totally
21367 + different from Unionfs while keeping the basic features.
21371 + prompt "Maximum number of branches"
21372 + default AUFS_BRANCH_MAX_127
21374 + Specifies the maximum number of branches (or member directories)
21375 + in a single aufs. The larger value consumes more system
21376 + resources and has a minor impact to performance.
21377 +config AUFS_BRANCH_MAX_127
21380 + Specifies the maximum number of branches (or member directories)
21381 + in a single aufs. The larger value consumes more system
21382 + resources and has a minor impact to performance.
21383 +config AUFS_BRANCH_MAX_511
21386 + Specifies the maximum number of branches (or member directories)
21387 + in a single aufs. The larger value consumes more system
21388 + resources and has a minor impact to performance.
21389 +config AUFS_BRANCH_MAX_1023
21392 + Specifies the maximum number of branches (or member directories)
21393 + in a single aufs. The larger value consumes more system
21394 + resources and has a minor impact to performance.
21395 +config AUFS_BRANCH_MAX_32767
21398 + Specifies the maximum number of branches (or member directories)
21399 + in a single aufs. The larger value consumes more system
21400 + resources and has a minor impact to performance.
21403 +config AUFS_SBILIST
21405 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21408 + Automatic configuration for internal use.
21409 + When aufs supports Magic SysRq or /proc, enabled automatically.
21411 +config AUFS_HNOTIFY
21412 + bool "Detect direct branch access (bypassing aufs)"
21414 + If you want to modify files on branches directly, eg. bypassing aufs,
21415 + and want aufs to detect the changes of them fully, then enable this
21416 + option and use 'udba=notify' mount option.
21417 + Currently there is only one available configuration, "fsnotify".
21418 + It will have a negative impact to the performance.
21419 + See detail in aufs.5.
21422 + prompt "method" if AUFS_HNOTIFY
21423 + default AUFS_HFSNOTIFY
21424 +config AUFS_HFSNOTIFY
21429 +config AUFS_EXPORT
21430 + bool "NFS-exportable aufs"
21431 + depends on EXPORTFS
21433 + If you want to export your mounted aufs via NFS, then enable this
21434 + option. There are several requirements for this configuration.
21435 + See detail in aufs.5.
21437 +config AUFS_INO_T_64
21439 + depends on AUFS_EXPORT
21440 + depends on 64BIT && !(ALPHA || S390)
21443 + Automatic configuration for internal use.
21444 + /* typedef unsigned long/int __kernel_ino_t */
21445 + /* alpha and s390x are int */
21448 + bool "support for XATTR/EA (including Security Labels)"
21450 + If your branch fs supports XATTR/EA and you want to make them
21451 + available in aufs too, then enable this opsion and specify the
21452 + branch attributes for EA.
21453 + See detail in aufs.5.
21456 + bool "File-based Hierarchical Storage Management"
21458 + Hierarchical Storage Management (or HSM) is a well-known feature
21459 + in the storage world. Aufs provides this feature as file-based.
21460 + with multiple branches.
21461 + These multiple branches are prioritized, ie. the topmost one
21462 + should be the fastest drive and be used heavily.
21465 + bool "Readdir in userspace"
21467 + Aufs has two methods to provide a merged view for a directory,
21468 + by a user-space library and by kernel-space natively. The latter
21469 + is always enabled but sometimes large and slow.
21470 + If you enable this option, install the library in aufs2-util
21471 + package, and set some environment variables for your readdir(3),
21472 + then the work will be handled in user-space which generally
21473 + shows better performance in most cases.
21474 + See detail in aufs.5.
21477 + bool "Show whiteouts"
21479 + If you want to make the whiteouts in aufs visible, then enable
21480 + this option and specify 'shwh' mount option. Although it may
21481 + sounds like philosophy or something, but in technically it
21482 + simply shows the name of whiteout with keeping its behaviour.
21484 +config AUFS_BR_RAMFS
21485 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21487 + If you want to use ramfs as an aufs branch fs, then enable this
21488 + option. Generally tmpfs is recommended.
21489 + Aufs prohibited them to be a branch fs by default, because
21490 + initramfs becomes unusable after switch_root or something
21491 + generally. If you sets initramfs as an aufs branch and boot your
21492 + system by switch_root, you will meet a problem easily since the
21493 + files in initramfs may be inaccessible.
21494 + Unless you are going to use ramfs as an aufs branch fs without
21495 + switch_root or something, leave it N.
21497 +config AUFS_BR_FUSE
21498 + bool "Fuse fs as an aufs branch"
21499 + depends on FUSE_FS
21502 + If you want to use fuse-based userspace filesystem as an aufs
21503 + branch fs, then enable this option.
21504 + It implements the internal poll(2) operation which is
21505 + implemented by fuse only (curretnly).
21510 + Automatic configuration for internal use.
21512 +config AUFS_BR_HFSPLUS
21513 + bool "Hfsplus as an aufs branch"
21514 + depends on HFSPLUS_FS
21517 + If you want to use hfsplus fs as an aufs branch fs, then enable
21518 + this option. This option introduces a small overhead at
21519 + copying-up a file on hfsplus.
21521 +config AUFS_BDEV_LOOP
21523 + depends on BLK_DEV_LOOP
21526 + Automatic configuration for internal use.
21527 + Convert =[ym] into =y.
21530 + bool "Debug aufs"
21532 + Enable this to compile aufs internal debug code.
21533 + It will have a negative impact to the performance.
21535 +config AUFS_MAGIC_SYSRQ
21537 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21540 + Automatic configuration for internal use.
21541 + When aufs supports Magic SysRq, enabled automatically.
21543 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21544 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21545 +++ linux/fs/aufs/loop.c 2016-07-25 19:05:34.814493242 +0200
21548 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21550 + * This program, aufs is free software; you can redistribute it and/or modify
21551 + * it under the terms of the GNU General Public License as published by
21552 + * the Free Software Foundation; either version 2 of the License, or
21553 + * (at your option) any later version.
21555 + * This program is distributed in the hope that it will be useful,
21556 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21557 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21558 + * GNU General Public License for more details.
21560 + * You should have received a copy of the GNU General Public License
21561 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21565 + * support for loopback block device as a branch
21570 +/* added into drivers/block/loop.c */
21571 +static struct file *(*backing_file_func)(struct super_block *sb);
21574 + * test if two lower dentries have overlapping branches.
21576 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21578 + struct super_block *h_sb;
21579 + struct file *backing_file;
21581 + if (unlikely(!backing_file_func)) {
21582 + /* don't load "loop" module here */
21583 + backing_file_func = symbol_get(loop_backing_file);
21584 + if (unlikely(!backing_file_func))
21585 + /* "loop" module is not loaded */
21589 + h_sb = h_adding->d_sb;
21590 + backing_file = backing_file_func(h_sb);
21591 + if (!backing_file)
21594 + h_adding = backing_file->f_path.dentry;
21596 + * h_adding can be local NFS.
21597 + * in this case aufs cannot detect the loop.
21599 + if (unlikely(h_adding->d_sb == sb))
21601 + return !!au_test_subdir(h_adding, sb->s_root);
21604 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21605 +int au_test_loopback_kthread(void)
21608 + struct task_struct *tsk = current;
21609 + char c, comm[sizeof(tsk->comm)];
21612 + if (tsk->flags & PF_KTHREAD) {
21613 + get_task_comm(comm, tsk);
21615 + ret = ('0' <= c && c <= '9'
21616 + && !strncmp(comm, "loop", 4));
21622 +/* ---------------------------------------------------------------------- */
21624 +#define au_warn_loopback_step 16
21625 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21626 +static unsigned long *au_warn_loopback_array;
21628 +void au_warn_loopback(struct super_block *h_sb)
21630 + int i, new_nelem;
21631 + unsigned long *a, magic;
21632 + static DEFINE_SPINLOCK(spin);
21634 + magic = h_sb->s_magic;
21635 + spin_lock(&spin);
21636 + a = au_warn_loopback_array;
21637 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21638 + if (a[i] == magic) {
21639 + spin_unlock(&spin);
21643 + /* h_sb is new to us, print it */
21644 + if (i < au_warn_loopback_nelem) {
21649 + /* expand the array */
21650 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21651 + a = au_kzrealloc(au_warn_loopback_array,
21652 + au_warn_loopback_nelem * sizeof(unsigned long),
21653 + new_nelem * sizeof(unsigned long), GFP_ATOMIC);
21655 + au_warn_loopback_nelem = new_nelem;
21656 + au_warn_loopback_array = a;
21661 + spin_unlock(&spin);
21662 + AuWarn1("realloc failed, ignored\n");
21666 + spin_unlock(&spin);
21667 + pr_warn("you may want to try another patch for loopback file "
21668 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21671 +int au_loopback_init(void)
21674 + struct super_block *sb __maybe_unused;
21676 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
21679 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21680 + sizeof(unsigned long), GFP_NOFS);
21681 + if (unlikely(!au_warn_loopback_array))
21687 +void au_loopback_fin(void)
21689 + if (backing_file_func)
21690 + symbol_put(loop_backing_file);
21691 + kfree(au_warn_loopback_array);
21693 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21694 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21695 +++ linux/fs/aufs/loop.h 2016-07-25 19:05:34.814493242 +0200
21698 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21700 + * This program, aufs is free software; you can redistribute it and/or modify
21701 + * it under the terms of the GNU General Public License as published by
21702 + * the Free Software Foundation; either version 2 of the License, or
21703 + * (at your option) any later version.
21705 + * This program is distributed in the hope that it will be useful,
21706 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21707 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21708 + * GNU General Public License for more details.
21710 + * You should have received a copy of the GNU General Public License
21711 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21715 + * support for loopback mount as a branch
21718 +#ifndef __AUFS_LOOP_H__
21719 +#define __AUFS_LOOP_H__
21724 +struct super_block;
21726 +#ifdef CONFIG_AUFS_BDEV_LOOP
21727 +/* drivers/block/loop.c */
21728 +struct file *loop_backing_file(struct super_block *sb);
21731 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21732 +int au_test_loopback_kthread(void);
21733 +void au_warn_loopback(struct super_block *h_sb);
21735 +int au_loopback_init(void);
21736 +void au_loopback_fin(void);
21738 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21739 + struct dentry *h_adding)
21740 +AuStubInt0(au_test_loopback_kthread, void)
21741 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21743 +AuStubInt0(au_loopback_init, void)
21744 +AuStubVoid(au_loopback_fin, void)
21745 +#endif /* BLK_DEV_LOOP */
21747 +#endif /* __KERNEL__ */
21748 +#endif /* __AUFS_LOOP_H__ */
21749 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21750 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21751 +++ linux/fs/aufs/magic.mk 2015-09-24 10:47:58.254719746 +0200
21754 +# defined in ${srctree}/fs/fuse/inode.c
21756 +ifdef CONFIG_FUSE_FS
21757 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21760 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21762 +ifdef CONFIG_XFS_FS
21763 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21766 +# defined in ${srctree}/fs/configfs/mount.c
21768 +ifdef CONFIG_CONFIGFS_FS
21769 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21772 +# defined in ${srctree}/fs/ubifs/ubifs.h
21774 +ifdef CONFIG_UBIFS_FS
21775 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21778 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21780 +ifdef CONFIG_HFSPLUS_FS
21781 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21783 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
21784 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
21785 +++ linux/fs/aufs/Makefile 2015-09-24 10:47:58.248052907 +0200
21788 +include ${src}/magic.mk
21789 +ifeq (${CONFIG_AUFS_FS},m)
21790 +include ${src}/conf.mk
21792 +-include ${src}/priv_def.mk
21794 +# cf. include/linux/kernel.h
21796 +ccflags-y += -DDEBUG
21797 +# sparse requires the full pathname
21799 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
21801 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
21804 +obj-$(CONFIG_AUFS_FS) += aufs.o
21805 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
21806 + wkq.o vfsub.o dcsub.o \
21807 + cpup.o whout.o wbr_policy.o \
21808 + dinfo.o dentry.o \
21810 + finfo.o file.o f_op.o \
21812 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
21816 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
21817 +aufs-$(CONFIG_SYSFS) += sysfs.o
21818 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
21819 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
21820 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
21821 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
21822 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
21823 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
21824 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
21825 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
21826 +aufs-$(CONFIG_AUFS_POLL) += poll.o
21827 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
21828 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
21829 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
21830 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
21831 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
21832 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21833 +++ linux/fs/aufs/module.c 2016-07-25 19:05:34.814493242 +0200
21836 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21838 + * This program, aufs is free software; you can redistribute it and/or modify
21839 + * it under the terms of the GNU General Public License as published by
21840 + * the Free Software Foundation; either version 2 of the License, or
21841 + * (at your option) any later version.
21843 + * This program is distributed in the hope that it will be useful,
21844 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21845 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21846 + * GNU General Public License for more details.
21848 + * You should have received a copy of the GNU General Public License
21849 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21853 + * module global variables and operations
21856 +#include <linux/module.h>
21857 +#include <linux/seq_file.h>
21860 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp)
21862 + if (new_sz <= nused)
21865 + p = krealloc(p, new_sz, gfp);
21867 + memset(p + nused, 0, new_sz - nused);
21871 +/* ---------------------------------------------------------------------- */
21876 +struct kmem_cache *au_cachep[AuCache_Last] = {
21880 +static void au_cache_fin(void)
21885 + * Make sure all delayed rcu free inodes are flushed before we
21890 + /* excluding AuCache_HNOTIFY */
21891 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
21892 + for (i = 0; i < AuCache_HNOTIFY; i++) {
21893 + kmem_cache_destroy(au_cachep[i]);
21894 + au_cachep[i] = NULL;
21898 +static int __init au_cache_init(void)
21900 + au_cachep[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once);
21901 + if (au_cachep[AuCache_DINFO])
21902 + /* SLAB_DESTROY_BY_RCU */
21903 + au_cachep[AuCache_ICNTNR] = AuCacheCtor(au_icntnr,
21904 + au_icntnr_init_once);
21905 + if (au_cachep[AuCache_ICNTNR])
21906 + au_cachep[AuCache_FINFO] = AuCacheCtor(au_finfo,
21907 + au_fi_init_once);
21908 + if (au_cachep[AuCache_FINFO])
21909 + au_cachep[AuCache_VDIR] = AuCache(au_vdir);
21910 + if (au_cachep[AuCache_VDIR])
21911 + au_cachep[AuCache_DEHSTR] = AuCache(au_vdir_dehstr);
21912 + if (au_cachep[AuCache_DEHSTR])
21919 +/* ---------------------------------------------------------------------- */
21921 +int au_dir_roflags;
21923 +#ifdef CONFIG_AUFS_SBILIST
21925 + * iterate_supers_type() doesn't protect us from
21926 + * remounting (branch management)
21928 +struct au_sphlhead au_sbilist;
21932 + * functions for module interface.
21934 +MODULE_LICENSE("GPL");
21935 +/* MODULE_LICENSE("GPL v2"); */
21936 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
21937 +MODULE_DESCRIPTION(AUFS_NAME
21938 + " -- Advanced multi layered unification filesystem");
21939 +MODULE_VERSION(AUFS_VERSION);
21940 +MODULE_ALIAS_FS(AUFS_NAME);
21942 +/* this module parameter has no meaning when SYSFS is disabled */
21943 +int sysaufs_brs = 1;
21944 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
21945 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
21947 +/* this module parameter has no meaning when USER_NS is disabled */
21949 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
21950 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
21952 +/* ---------------------------------------------------------------------- */
21954 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
21956 +int au_seq_path(struct seq_file *seq, struct path *path)
21960 + err = seq_path(seq, path, au_esc_chars);
21963 + else if (err < 0)
21969 +/* ---------------------------------------------------------------------- */
21971 +static int __init aufs_init(void)
21976 + p = au_esc_chars;
21977 + for (i = 1; i <= ' '; i++)
21983 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
21985 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
21986 + for (i = 0; i < AuIop_Last; i++)
21987 + aufs_iop_nogetattr[i].getattr = NULL;
21989 + au_sbilist_init();
21990 + sysaufs_brs_init();
21993 + err = sysaufs_init();
21994 + if (unlikely(err))
21996 + err = au_procfs_init();
21997 + if (unlikely(err))
21998 + goto out_sysaufs;
21999 + err = au_wkq_init();
22000 + if (unlikely(err))
22002 + err = au_loopback_init();
22003 + if (unlikely(err))
22005 + err = au_hnotify_init();
22006 + if (unlikely(err))
22007 + goto out_loopback;
22008 + err = au_sysrq_init();
22009 + if (unlikely(err))
22011 + err = au_cache_init();
22012 + if (unlikely(err))
22015 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
22016 + err = register_filesystem(&aufs_fs_type);
22017 + if (unlikely(err))
22020 + /* since we define pr_fmt, call printk directly */
22021 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
22022 + goto out; /* success */
22029 + au_hnotify_fin();
22031 + au_loopback_fin();
22043 +static void __exit aufs_exit(void)
22045 + unregister_filesystem(&aufs_fs_type);
22048 + au_hnotify_fin();
22049 + au_loopback_fin();
22056 +module_init(aufs_init);
22057 +module_exit(aufs_exit);
22058 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
22059 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
22060 +++ linux/fs/aufs/module.h 2016-07-25 19:05:34.814493242 +0200
22063 + * Copyright (C) 2005-2016 Junjiro R. Okajima
22065 + * This program, aufs is free software; you can redistribute it and/or modify
22066 + * it under the terms of the GNU General Public License as published by
22067 + * the Free Software Foundation; either version 2 of the License, or
22068 + * (at your option) any later version.
22070 + * This program is distributed in the hope that it will be useful,
22071 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22072 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22073 + * GNU General Public License for more details.
22075 + * You should have received a copy of the GNU General Public License
22076 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22080 + * module initialization and module-global
22083 +#ifndef __AUFS_MODULE_H__
22084 +#define __AUFS_MODULE_H__
22088 +#include <linux/slab.h>
22093 +/* module parameters */
22094 +extern int sysaufs_brs;
22095 +extern bool au_userns;
22097 +/* ---------------------------------------------------------------------- */
22099 +extern int au_dir_roflags;
22101 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp);
22102 +int au_seq_path(struct seq_file *seq, struct path *path);
22104 +#ifdef CONFIG_PROC_FS
22106 +int __init au_procfs_init(void);
22107 +void au_procfs_fin(void);
22109 +AuStubInt0(au_procfs_init, void);
22110 +AuStubVoid(au_procfs_fin, void);
22113 +/* ---------------------------------------------------------------------- */
22122 + AuCache_HNOTIFY, /* must be last */
22126 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
22127 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
22128 +#define AuCacheCtor(type, ctor) \
22129 + kmem_cache_create(#type, sizeof(struct type), \
22130 + __alignof__(struct type), AuCacheFlags, ctor)
22132 +extern struct kmem_cache *au_cachep[];
22134 +#define AuCacheFuncs(name, index) \
22135 +static inline struct au_##name *au_cache_alloc_##name(void) \
22136 +{ return kmem_cache_alloc(au_cachep[AuCache_##index], GFP_NOFS); } \
22137 +static inline void au_cache_free_##name(struct au_##name *p) \
22138 +{ kmem_cache_free(au_cachep[AuCache_##index], p); }
22140 +AuCacheFuncs(dinfo, DINFO);
22141 +AuCacheFuncs(icntnr, ICNTNR);
22142 +AuCacheFuncs(finfo, FINFO);
22143 +AuCacheFuncs(vdir, VDIR);
22144 +AuCacheFuncs(vdir_dehstr, DEHSTR);
22145 +#ifdef CONFIG_AUFS_HNOTIFY
22146 +AuCacheFuncs(hnotify, HNOTIFY);
22149 +#endif /* __KERNEL__ */
22150 +#endif /* __AUFS_MODULE_H__ */
22151 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
22152 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
22153 +++ linux/fs/aufs/mvdown.c 2016-07-25 19:05:34.814493242 +0200
22156 + * Copyright (C) 2011-2016 Junjiro R. Okajima
22158 + * This program, aufs is free software; you can redistribute it and/or modify
22159 + * it under the terms of the GNU General Public License as published by
22160 + * the Free Software Foundation; either version 2 of the License, or
22161 + * (at your option) any later version.
22163 + * This program is distributed in the hope that it will be useful,
22164 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22165 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22166 + * GNU General Public License for more details.
22168 + * You should have received a copy of the GNU General Public License
22169 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22173 + * move-down, opposite of copy-up
22178 +struct au_mvd_args {
22180 + struct super_block *h_sb;
22181 + struct dentry *h_parent;
22182 + struct au_hinode *hdir;
22183 + struct inode *h_dir, *h_inode;
22184 + struct au_pin pin;
22185 + } info[AUFS_MVDOWN_NARRAY];
22187 + struct aufs_mvdown mvdown;
22188 + struct dentry *dentry, *parent;
22189 + struct inode *inode, *dir;
22190 + struct super_block *sb;
22191 + aufs_bindex_t bopq, bwh, bfound;
22192 + unsigned char rename_lock;
22195 +#define mvd_errno mvdown.au_errno
22196 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
22197 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
22198 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
22199 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
22201 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
22202 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
22203 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
22204 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
22205 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
22206 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
22208 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
22209 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
22210 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
22211 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
22212 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
22213 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
22215 +#define AU_MVD_PR(flag, ...) do { \
22217 + pr_err(__VA_ARGS__); \
22220 +static int find_lower_writable(struct au_mvd_args *a)
22222 + struct super_block *sb;
22223 + aufs_bindex_t bindex, bbot;
22224 + struct au_branch *br;
22227 + bindex = a->mvd_bsrc;
22228 + bbot = au_sbbot(sb);
22229 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
22230 + for (bindex++; bindex <= bbot; bindex++) {
22231 + br = au_sbr(sb, bindex);
22232 + if (au_br_fhsm(br->br_perm)
22233 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
22236 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
22237 + for (bindex++; bindex <= bbot; bindex++) {
22238 + br = au_sbr(sb, bindex);
22239 + if (!au_br_rdonly(br))
22243 + for (bindex++; bindex <= bbot; bindex++) {
22244 + br = au_sbr(sb, bindex);
22245 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
22246 + if (au_br_rdonly(br))
22248 + |= AUFS_MVDOWN_ROLOWER_R;
22256 +/* make the parent dir on bdst */
22257 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22262 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22263 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22264 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22265 + a->mvd_h_dst_parent = NULL;
22266 + if (au_dbbot(a->parent) >= a->mvd_bdst)
22267 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22268 + if (!a->mvd_h_dst_parent) {
22269 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22270 + if (unlikely(err)) {
22271 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22274 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22282 +/* lock them all */
22283 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22286 + struct dentry *h_trap;
22288 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22289 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22290 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22291 + au_opt_udba(a->sb),
22292 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22294 + if (unlikely(err)) {
22295 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22299 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22300 + a->rename_lock = 0;
22301 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22302 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22303 + au_opt_udba(a->sb),
22304 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22305 + err = au_do_pin(&a->mvd_pin_src);
22307 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22308 + if (unlikely(err)) {
22309 + AU_MVD_PR(dmsg, "pin_src failed\n");
22312 + goto out; /* success */
22315 + a->rename_lock = 1;
22316 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22317 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22318 + au_opt_udba(a->sb),
22319 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22321 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22322 + if (unlikely(err)) {
22323 + AU_MVD_PR(dmsg, "pin_src failed\n");
22324 + au_pin_hdir_lock(&a->mvd_pin_dst);
22327 + au_pin_hdir_unlock(&a->mvd_pin_src);
22328 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22329 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22331 + err = (h_trap != a->mvd_h_src_parent);
22333 + err = (h_trap != a->mvd_h_dst_parent);
22335 + BUG_ON(err); /* it should never happen */
22336 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22339 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22340 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22341 + au_pin_hdir_lock(&a->mvd_pin_src);
22342 + au_unpin(&a->mvd_pin_src);
22343 + au_pin_hdir_lock(&a->mvd_pin_dst);
22346 + goto out; /* success */
22349 + au_unpin(&a->mvd_pin_dst);
22355 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22357 + if (!a->rename_lock)
22358 + au_unpin(&a->mvd_pin_src);
22360 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22361 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22362 + au_pin_hdir_lock(&a->mvd_pin_src);
22363 + au_unpin(&a->mvd_pin_src);
22364 + au_pin_hdir_lock(&a->mvd_pin_dst);
22366 + au_unpin(&a->mvd_pin_dst);
22369 +/* copy-down the file */
22370 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22373 + struct au_cp_generic cpg = {
22374 + .dentry = a->dentry,
22375 + .bdst = a->mvd_bdst,
22376 + .bsrc = a->mvd_bsrc,
22378 + .pin = &a->mvd_pin_dst,
22379 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22382 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22383 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22384 + au_fset_cpup(cpg.flags, OVERWRITE);
22385 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22386 + au_fset_cpup(cpg.flags, RWDST);
22387 + err = au_sio_cpdown_simple(&cpg);
22388 + if (unlikely(err))
22389 + AU_MVD_PR(dmsg, "cpdown failed\n");
22396 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22399 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22402 + struct path h_path;
22403 + struct au_branch *br;
22404 + struct inode *delegated;
22406 + br = au_sbr(a->sb, a->mvd_bdst);
22407 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22408 + err = PTR_ERR(h_path.dentry);
22409 + if (IS_ERR(h_path.dentry)) {
22410 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22415 + if (d_is_positive(h_path.dentry)) {
22416 + h_path.mnt = au_br_mnt(br);
22417 + delegated = NULL;
22418 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22419 + &delegated, /*force*/0);
22420 + if (unlikely(err == -EWOULDBLOCK)) {
22421 + pr_warn("cannot retry for NFSv4 delegation"
22422 + " for an internal unlink\n");
22425 + if (unlikely(err))
22426 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22428 + dput(h_path.dentry);
22436 + * unlink the topmost h_dentry
22438 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22441 + struct path h_path;
22442 + struct inode *delegated;
22444 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22445 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22446 + delegated = NULL;
22447 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22448 + if (unlikely(err == -EWOULDBLOCK)) {
22449 + pr_warn("cannot retry for NFSv4 delegation"
22450 + " for an internal unlink\n");
22453 + if (unlikely(err))
22454 + AU_MVD_PR(dmsg, "unlink failed\n");
22460 +/* Since mvdown succeeded, we ignore an error of this function */
22461 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22464 + struct au_branch *br;
22466 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22467 + br = au_sbr(a->sb, a->mvd_bsrc);
22468 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22470 + br = au_sbr(a->sb, a->mvd_bdst);
22471 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22472 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22475 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22477 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22481 + * copy-down the file and unlink the bsrc file.
22482 + * - unlink the bdst whout if exist
22483 + * - copy-down the file (with whtmp name and rename)
22484 + * - unlink the bsrc file
22486 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22490 + err = au_do_mkdir(dmsg, a);
22492 + err = au_do_lock(dmsg, a);
22493 + if (unlikely(err))
22497 + * do not revert the activities we made on bdst since they should be
22498 + * harmless in aufs.
22501 + err = au_do_cpdown(dmsg, a);
22503 + err = au_do_unlink_wh(dmsg, a);
22504 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22505 + err = au_do_unlink(dmsg, a);
22506 + if (unlikely(err))
22509 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22510 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22511 + if (find_lower_writable(a) < 0)
22512 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22514 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22515 + au_do_stfs(dmsg, a);
22517 + /* maintain internal array */
22518 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22519 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22520 + au_set_dbtop(a->dentry, a->mvd_bdst);
22521 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22522 + au_set_ibtop(a->inode, a->mvd_bdst);
22524 + /* hide the lower */
22525 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
22526 + au_set_dbbot(a->dentry, a->mvd_bsrc);
22527 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
22528 + au_set_ibbot(a->inode, a->mvd_bsrc);
22530 + if (au_dbbot(a->dentry) < a->mvd_bdst)
22531 + au_set_dbbot(a->dentry, a->mvd_bdst);
22532 + if (au_ibbot(a->inode) < a->mvd_bdst)
22533 + au_set_ibbot(a->inode, a->mvd_bdst);
22536 + au_do_unlock(dmsg, a);
22542 +/* ---------------------------------------------------------------------- */
22544 +/* make sure the file is idle */
22545 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22547 + int err, plinked;
22550 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22551 + if (au_dbtop(a->dentry) == a->mvd_bsrc
22552 + && au_dcount(a->dentry) == 1
22553 + && atomic_read(&a->inode->i_count) == 1
22554 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22555 + && (!plinked || !au_plink_test(a->inode))
22556 + && a->inode->i_nlink == 1)
22561 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22562 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
22563 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22564 + a->mvd_h_src_inode->i_nlink,
22565 + plinked, plinked ? au_plink_test(a->inode) : 0);
22572 +/* make sure the parent dir is fine */
22573 +static int au_mvd_args_parent(const unsigned char dmsg,
22574 + struct au_mvd_args *a)
22577 + aufs_bindex_t bindex;
22580 + if (unlikely(au_alive_dir(a->parent))) {
22582 + AU_MVD_PR(dmsg, "parent dir is dead\n");
22586 + a->bopq = au_dbdiropq(a->parent);
22587 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
22588 + AuDbg("b%d\n", bindex);
22589 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
22590 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
22592 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
22593 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
22594 + a->bopq, a->mvd_bdst);
22602 +static int au_mvd_args_intermediate(const unsigned char dmsg,
22603 + struct au_mvd_args *a)
22606 + struct au_dinfo *dinfo, *tmp;
22608 + /* lookup the next lower positive entry */
22610 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
22611 + if (unlikely(!tmp))
22616 + dinfo = au_di(a->dentry);
22617 + au_di_cp(tmp, dinfo);
22618 + au_di_swap(tmp, dinfo);
22620 + /* returns the number of positive dentries */
22621 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
22622 + /* AuLkup_IGNORE_PERM */ 0);
22624 + a->bwh = au_dbwh(a->dentry);
22625 + else if (err > 0)
22626 + a->bfound = au_dbtop(a->dentry);
22628 + au_di_swap(tmp, dinfo);
22629 + au_rw_write_unlock(&tmp->di_rwsem);
22631 + if (unlikely(err < 0))
22632 + AU_MVD_PR(dmsg, "failed look-up lower\n");
22635 + * here, we have these cases.
22637 + * no positive dentry under bsrc. there are more sub-cases.
22639 + * there no whiteout, we can safely move-down.
22642 + * bsrc < bwh && bwh < bdst
22643 + * there is a whiteout on RO branch. cannot proceed.
22645 + * there is a whiteout on the RW target branch. it should
22648 + * there is a whiteout somewhere unrelated branch.
22649 + * -1 < bfound && bfound <= bsrc
22652 + * found, but it is on RO branch between bsrc and bdst. cannot
22655 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
22658 + * found, after we create the file on bdst, it will be hidden.
22661 + AuDebugOn(a->bfound == -1
22663 + && a->bwh <= a->mvd_bsrc);
22664 + AuDebugOn(-1 < a->bfound
22665 + && a->bfound <= a->mvd_bsrc);
22668 + if (a->bfound == -1
22669 + && a->mvd_bsrc < a->bwh
22671 + && a->bwh < a->mvd_bdst) {
22672 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
22673 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
22674 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
22676 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
22677 + a->mvd_errno = EAU_MVDOWN_UPPER;
22678 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
22679 + a->mvd_bdst, a->bfound);
22683 + err = 0; /* success */
22690 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
22695 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22696 + && a->bfound == a->mvd_bdst)
22702 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
22705 + struct au_branch *br;
22708 + if (unlikely(S_ISDIR(a->inode->i_mode)))
22712 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
22713 + a->mvd_bsrc = au_ibtop(a->inode);
22715 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
22716 + if (unlikely(a->mvd_bsrc < 0
22717 + || (a->mvd_bsrc < au_dbtop(a->dentry)
22718 + || au_dbbot(a->dentry) < a->mvd_bsrc
22719 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
22720 + || (a->mvd_bsrc < au_ibtop(a->inode)
22721 + || au_ibbot(a->inode) < a->mvd_bsrc
22722 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
22723 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
22724 + AU_MVD_PR(dmsg, "no upper\n");
22728 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
22729 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22730 + AU_MVD_PR(dmsg, "on the bottom\n");
22733 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
22734 + br = au_sbr(a->sb, a->mvd_bsrc);
22735 + err = au_br_rdonly(br);
22736 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
22737 + if (unlikely(err))
22739 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
22740 + || IS_APPEND(a->mvd_h_src_inode))) {
22742 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
22748 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
22749 + a->mvd_bdst = find_lower_writable(a);
22750 + if (unlikely(a->mvd_bdst < 0)) {
22751 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
22752 + AU_MVD_PR(dmsg, "no writable lower branch\n");
22756 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
22757 + if (unlikely(a->mvd_bdst < 0
22758 + || au_sbbot(a->sb) < a->mvd_bdst)) {
22759 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
22760 + AU_MVD_PR(dmsg, "no lower brid\n");
22765 + err = au_mvd_args_busy(dmsg, a);
22767 + err = au_mvd_args_parent(dmsg, a);
22769 + err = au_mvd_args_intermediate(dmsg, a);
22771 + err = au_mvd_args_exist(dmsg, a);
22773 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
22780 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
22783 + unsigned char dmsg;
22784 + struct au_mvd_args *args;
22785 + struct inode *inode;
22787 + inode = d_inode(dentry);
22789 + if (unlikely(!capable(CAP_SYS_ADMIN)))
22793 + args = kmalloc(sizeof(*args), GFP_NOFS);
22794 + if (unlikely(!args))
22797 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
22799 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
22800 + if (unlikely(err)) {
22805 + AuDbg("flags 0x%x\n", args->mvdown.flags);
22806 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
22807 + args->mvdown.au_errno = 0;
22808 + args->dentry = dentry;
22809 + args->inode = inode;
22810 + args->sb = dentry->d_sb;
22813 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
22814 + args->parent = dget_parent(dentry);
22815 + args->dir = d_inode(args->parent);
22816 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
22817 + dput(args->parent);
22818 + if (unlikely(args->parent != dentry->d_parent)) {
22819 + AU_MVD_PR(dmsg, "parent dir is moved\n");
22823 + inode_lock_nested(inode, I_MUTEX_CHILD);
22824 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
22825 + if (unlikely(err))
22828 + di_write_lock_parent(args->parent);
22829 + err = au_mvd_args(dmsg, args);
22830 + if (unlikely(err))
22833 + err = au_do_mvdown(dmsg, args);
22834 + if (unlikely(err))
22837 + au_cpup_attr_timesizes(args->dir);
22838 + au_cpup_attr_timesizes(inode);
22839 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
22840 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
22841 + /* au_digen_dec(dentry); */
22844 + di_write_unlock(args->parent);
22845 + aufs_read_unlock(dentry, AuLock_DW);
22847 + inode_unlock(inode);
22849 + inode_unlock(args->dir);
22851 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
22859 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
22860 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
22861 +++ linux/fs/aufs/opts.c 2016-07-25 19:05:34.814493242 +0200
22864 + * Copyright (C) 2005-2016 Junjiro R. Okajima
22866 + * This program, aufs is free software; you can redistribute it and/or modify
22867 + * it under the terms of the GNU General Public License as published by
22868 + * the Free Software Foundation; either version 2 of the License, or
22869 + * (at your option) any later version.
22871 + * This program is distributed in the hope that it will be useful,
22872 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22873 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22874 + * GNU General Public License for more details.
22876 + * You should have received a copy of the GNU General Public License
22877 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22881 + * mount options/flags
22884 +#include <linux/namei.h>
22885 +#include <linux/types.h> /* a distribution requires */
22886 +#include <linux/parser.h>
22889 +/* ---------------------------------------------------------------------- */
22893 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
22894 + Opt_idel, Opt_imod,
22895 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
22896 + Opt_rdblk_def, Opt_rdhash_def,
22897 + Opt_xino, Opt_noxino,
22898 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
22899 + Opt_trunc_xino_path, Opt_itrunc_xino,
22900 + Opt_trunc_xib, Opt_notrunc_xib,
22901 + Opt_shwh, Opt_noshwh,
22902 + Opt_plink, Opt_noplink, Opt_list_plink,
22904 + Opt_dio, Opt_nodio,
22905 + Opt_diropq_a, Opt_diropq_w,
22906 + Opt_warn_perm, Opt_nowarn_perm,
22907 + Opt_wbr_copyup, Opt_wbr_create,
22909 + Opt_verbose, Opt_noverbose,
22910 + Opt_sum, Opt_nosum, Opt_wsum,
22911 + Opt_dirperm1, Opt_nodirperm1,
22912 + Opt_acl, Opt_noacl,
22913 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
22916 +static match_table_t options = {
22917 + {Opt_br, "br=%s"},
22918 + {Opt_br, "br:%s"},
22920 + {Opt_add, "add=%d:%s"},
22921 + {Opt_add, "add:%d:%s"},
22922 + {Opt_add, "ins=%d:%s"},
22923 + {Opt_add, "ins:%d:%s"},
22924 + {Opt_append, "append=%s"},
22925 + {Opt_append, "append:%s"},
22926 + {Opt_prepend, "prepend=%s"},
22927 + {Opt_prepend, "prepend:%s"},
22929 + {Opt_del, "del=%s"},
22930 + {Opt_del, "del:%s"},
22931 + /* {Opt_idel, "idel:%d"}, */
22932 + {Opt_mod, "mod=%s"},
22933 + {Opt_mod, "mod:%s"},
22934 + /* {Opt_imod, "imod:%d:%s"}, */
22936 + {Opt_dirwh, "dirwh=%d"},
22938 + {Opt_xino, "xino=%s"},
22939 + {Opt_noxino, "noxino"},
22940 + {Opt_trunc_xino, "trunc_xino"},
22941 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
22942 + {Opt_notrunc_xino, "notrunc_xino"},
22943 + {Opt_trunc_xino_path, "trunc_xino=%s"},
22944 + {Opt_itrunc_xino, "itrunc_xino=%d"},
22945 + /* {Opt_zxino, "zxino=%s"}, */
22946 + {Opt_trunc_xib, "trunc_xib"},
22947 + {Opt_notrunc_xib, "notrunc_xib"},
22949 +#ifdef CONFIG_PROC_FS
22950 + {Opt_plink, "plink"},
22952 + {Opt_ignore_silent, "plink"},
22955 + {Opt_noplink, "noplink"},
22957 +#ifdef CONFIG_AUFS_DEBUG
22958 + {Opt_list_plink, "list_plink"},
22961 + {Opt_udba, "udba=%s"},
22963 + {Opt_dio, "dio"},
22964 + {Opt_nodio, "nodio"},
22966 +#ifdef CONFIG_AUFS_FHSM
22967 + {Opt_fhsm_sec, "fhsm_sec=%d"},
22969 + {Opt_ignore_silent, "fhsm_sec=%d"},
22972 + {Opt_diropq_a, "diropq=always"},
22973 + {Opt_diropq_a, "diropq=a"},
22974 + {Opt_diropq_w, "diropq=whiteouted"},
22975 + {Opt_diropq_w, "diropq=w"},
22977 + {Opt_warn_perm, "warn_perm"},
22978 + {Opt_nowarn_perm, "nowarn_perm"},
22980 + /* keep them temporary */
22981 + {Opt_ignore_silent, "nodlgt"},
22982 + {Opt_ignore_silent, "clean_plink"},
22984 +#ifdef CONFIG_AUFS_SHWH
22985 + {Opt_shwh, "shwh"},
22987 + {Opt_noshwh, "noshwh"},
22989 + {Opt_dirperm1, "dirperm1"},
22990 + {Opt_nodirperm1, "nodirperm1"},
22992 + {Opt_verbose, "verbose"},
22993 + {Opt_verbose, "v"},
22994 + {Opt_noverbose, "noverbose"},
22995 + {Opt_noverbose, "quiet"},
22996 + {Opt_noverbose, "q"},
22997 + {Opt_noverbose, "silent"},
22999 + {Opt_sum, "sum"},
23000 + {Opt_nosum, "nosum"},
23001 + {Opt_wsum, "wsum"},
23003 + {Opt_rdcache, "rdcache=%d"},
23004 + {Opt_rdblk, "rdblk=%d"},
23005 + {Opt_rdblk_def, "rdblk=def"},
23006 + {Opt_rdhash, "rdhash=%d"},
23007 + {Opt_rdhash_def, "rdhash=def"},
23009 + {Opt_wbr_create, "create=%s"},
23010 + {Opt_wbr_create, "create_policy=%s"},
23011 + {Opt_wbr_copyup, "cpup=%s"},
23012 + {Opt_wbr_copyup, "copyup=%s"},
23013 + {Opt_wbr_copyup, "copyup_policy=%s"},
23015 + /* generic VFS flag */
23016 +#ifdef CONFIG_FS_POSIX_ACL
23017 + {Opt_acl, "acl"},
23018 + {Opt_noacl, "noacl"},
23020 + {Opt_ignore_silent, "acl"},
23021 + {Opt_ignore_silent, "noacl"},
23024 + /* internal use for the scripts */
23025 + {Opt_ignore_silent, "si=%s"},
23027 + {Opt_br, "dirs=%s"},
23028 + {Opt_ignore, "debug=%d"},
23029 + {Opt_ignore, "delete=whiteout"},
23030 + {Opt_ignore, "delete=all"},
23031 + {Opt_ignore, "imap=%s"},
23033 + /* temporary workaround, due to old mount(8)? */
23034 + {Opt_ignore_silent, "relatime"},
23039 +/* ---------------------------------------------------------------------- */
23041 +static const char *au_parser_pattern(int val, match_table_t tbl)
23043 + struct match_token *p;
23046 + while (p->pattern) {
23047 + if (p->token == val)
23048 + return p->pattern;
23055 +static const char *au_optstr(int *val, match_table_t tbl)
23057 + struct match_token *p;
23064 + while (p->pattern) {
23066 + && (v & p->token) == p->token) {
23067 + *val &= ~p->token;
23068 + return p->pattern;
23077 +/* ---------------------------------------------------------------------- */
23079 +static match_table_t brperm = {
23080 + {AuBrPerm_RO, AUFS_BRPERM_RO},
23081 + {AuBrPerm_RR, AUFS_BRPERM_RR},
23082 + {AuBrPerm_RW, AUFS_BRPERM_RW},
23086 +static match_table_t brattr = {
23088 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
23089 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
23090 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
23091 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
23092 +#ifdef CONFIG_AUFS_FHSM
23093 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
23095 +#ifdef CONFIG_AUFS_XATTR
23096 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
23097 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
23098 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
23099 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
23100 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
23101 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
23104 + /* ro/rr branch */
23105 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
23108 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
23109 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
23114 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
23121 + p = strchr(str, '+');
23124 + v = match_token(str, table, args);
23126 + if (v & AuBrAttr_CMOO_Mask)
23127 + attr &= ~AuBrAttr_CMOO_Mask;
23132 + pr_warn("ignored branch attribute %s\n", str);
23142 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
23150 + p = au_optstr(&perm, brattr);
23153 + memcpy(q, p, sz + 1);
23159 + p = au_optstr(&perm, brattr);
23163 + memcpy(q, p, sz + 1);
23169 + return q - str->a;
23172 +static int noinline_for_stack br_perm_val(char *perm)
23174 + int val, bad, sz;
23176 + substring_t args[MAX_OPT_ARGS];
23177 + au_br_perm_str_t attr;
23179 + p = strchr(perm, '+');
23182 + val = match_token(perm, brperm, args);
23186 + pr_warn("ignored branch permission %s\n", perm);
23187 + val = AuBrPerm_RO;
23193 + val |= br_attr_val(p + 1, brattr, args);
23196 + switch (val & AuBrPerm_Mask) {
23197 + case AuBrPerm_RO:
23198 + case AuBrPerm_RR:
23199 + bad = val & AuBrWAttr_Mask;
23200 + val &= ~AuBrWAttr_Mask;
23202 + case AuBrPerm_RW:
23203 + bad = val & AuBrRAttr_Mask;
23204 + val &= ~AuBrRAttr_Mask;
23209 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
23210 + * does not treat it as an error, just warning.
23211 + * this is a tiny guard for the user operation.
23213 + if (val & AuBrAttr_UNPIN) {
23214 + bad |= AuBrAttr_UNPIN;
23215 + val &= ~AuBrAttr_UNPIN;
23218 + if (unlikely(bad)) {
23219 + sz = au_do_optstr_br_attr(&attr, bad);
23221 + pr_warn("ignored branch attribute %s\n", attr.a);
23228 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
23230 + au_br_perm_str_t attr;
23236 + p = au_optstr(&perm, brperm);
23237 + AuDebugOn(!p || !*p);
23239 + memcpy(q, p, sz + 1);
23242 + sz = au_do_optstr_br_attr(&attr, perm);
23245 + memcpy(q, attr.a, sz + 1);
23248 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
23251 +/* ---------------------------------------------------------------------- */
23253 +static match_table_t udbalevel = {
23254 + {AuOpt_UDBA_REVAL, "reval"},
23255 + {AuOpt_UDBA_NONE, "none"},
23256 +#ifdef CONFIG_AUFS_HNOTIFY
23257 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
23258 +#ifdef CONFIG_AUFS_HFSNOTIFY
23259 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23265 +static int noinline_for_stack udba_val(char *str)
23267 + substring_t args[MAX_OPT_ARGS];
23269 + return match_token(str, udbalevel, args);
23272 +const char *au_optstr_udba(int udba)
23274 + return au_parser_pattern(udba, udbalevel);
23277 +/* ---------------------------------------------------------------------- */
23279 +static match_table_t au_wbr_create_policy = {
23280 + {AuWbrCreate_TDP, "tdp"},
23281 + {AuWbrCreate_TDP, "top-down-parent"},
23282 + {AuWbrCreate_RR, "rr"},
23283 + {AuWbrCreate_RR, "round-robin"},
23284 + {AuWbrCreate_MFS, "mfs"},
23285 + {AuWbrCreate_MFS, "most-free-space"},
23286 + {AuWbrCreate_MFSV, "mfs:%d"},
23287 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23289 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23290 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23291 + {AuWbrCreate_PMFS, "pmfs"},
23292 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23293 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23294 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23300 + * cf. linux/lib/parser.c and cmdline.c
23301 + * gave up calling memparse() since it uses simple_strtoull() instead of
23304 +static int noinline_for_stack
23305 +au_match_ull(substring_t *s, unsigned long long *result)
23308 + unsigned int len;
23312 + len = s->to - s->from;
23313 + if (len + 1 <= sizeof(a)) {
23314 + memcpy(a, s->from, len);
23316 + err = kstrtoull(a, 0, result);
23321 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23322 + struct au_opt_wbr_create *create)
23325 + unsigned long long ull;
23328 + if (!au_match_ull(arg, &ull))
23329 + create->mfsrr_watermark = ull;
23331 + pr_err("bad integer in %s\n", str);
23338 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23339 + struct au_opt_wbr_create *create)
23344 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23345 + create->mfs_second = n;
23347 + pr_err("bad integer in %s\n", str);
23354 +static int noinline_for_stack
23355 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23358 + substring_t args[MAX_OPT_ARGS];
23360 + err = match_token(str, au_wbr_create_policy, args);
23361 + create->wbr_create = err;
23363 + case AuWbrCreate_MFSRRV:
23364 + case AuWbrCreate_PMFSRRV:
23365 + e = au_wbr_mfs_wmark(&args[0], str, create);
23367 + e = au_wbr_mfs_sec(&args[1], str, create);
23371 + case AuWbrCreate_MFSRR:
23372 + case AuWbrCreate_PMFSRR:
23373 + e = au_wbr_mfs_wmark(&args[0], str, create);
23374 + if (unlikely(e)) {
23379 + case AuWbrCreate_MFS:
23380 + case AuWbrCreate_PMFS:
23381 + create->mfs_second = AUFS_MFS_DEF_SEC;
23383 + case AuWbrCreate_MFSV:
23384 + case AuWbrCreate_PMFSV:
23385 + e = au_wbr_mfs_sec(&args[0], str, create);
23394 +const char *au_optstr_wbr_create(int wbr_create)
23396 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23399 +static match_table_t au_wbr_copyup_policy = {
23400 + {AuWbrCopyup_TDP, "tdp"},
23401 + {AuWbrCopyup_TDP, "top-down-parent"},
23402 + {AuWbrCopyup_BUP, "bup"},
23403 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23404 + {AuWbrCopyup_BU, "bu"},
23405 + {AuWbrCopyup_BU, "bottom-up"},
23409 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23411 + substring_t args[MAX_OPT_ARGS];
23413 + return match_token(str, au_wbr_copyup_policy, args);
23416 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23418 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23421 +/* ---------------------------------------------------------------------- */
23423 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23425 +static void dump_opts(struct au_opts *opts)
23427 +#ifdef CONFIG_AUFS_DEBUG
23428 + /* reduce stack space */
23430 + struct au_opt_add *add;
23431 + struct au_opt_del *del;
23432 + struct au_opt_mod *mod;
23433 + struct au_opt_xino *xino;
23434 + struct au_opt_xino_itrunc *xino_itrunc;
23435 + struct au_opt_wbr_create *create;
23437 + struct au_opt *opt;
23440 + while (opt->type != Opt_tail) {
23441 + switch (opt->type) {
23443 + u.add = &opt->add;
23444 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23445 + u.add->bindex, u.add->pathname, u.add->perm,
23446 + u.add->path.dentry);
23450 + u.del = &opt->del;
23451 + AuDbg("del {%s, %p}\n",
23452 + u.del->pathname, u.del->h_path.dentry);
23456 + u.mod = &opt->mod;
23457 + AuDbg("mod {%s, 0x%x, %p}\n",
23458 + u.mod->path, u.mod->perm, u.mod->h_root);
23461 + u.add = &opt->add;
23462 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23463 + u.add->bindex, u.add->pathname, u.add->perm,
23464 + u.add->path.dentry);
23466 + case Opt_prepend:
23467 + u.add = &opt->add;
23468 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23469 + u.add->bindex, u.add->pathname, u.add->perm,
23470 + u.add->path.dentry);
23473 + AuDbg("dirwh %d\n", opt->dirwh);
23475 + case Opt_rdcache:
23476 + AuDbg("rdcache %d\n", opt->rdcache);
23479 + AuDbg("rdblk %u\n", opt->rdblk);
23481 + case Opt_rdblk_def:
23482 + AuDbg("rdblk_def\n");
23485 + AuDbg("rdhash %u\n", opt->rdhash);
23487 + case Opt_rdhash_def:
23488 + AuDbg("rdhash_def\n");
23491 + u.xino = &opt->xino;
23492 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23494 + case Opt_trunc_xino:
23495 + AuLabel(trunc_xino);
23497 + case Opt_notrunc_xino:
23498 + AuLabel(notrunc_xino);
23500 + case Opt_trunc_xino_path:
23501 + case Opt_itrunc_xino:
23502 + u.xino_itrunc = &opt->xino_itrunc;
23503 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23508 + case Opt_trunc_xib:
23509 + AuLabel(trunc_xib);
23511 + case Opt_notrunc_xib:
23512 + AuLabel(notrunc_xib);
23520 + case Opt_dirperm1:
23521 + AuLabel(dirperm1);
23523 + case Opt_nodirperm1:
23524 + AuLabel(nodirperm1);
23529 + case Opt_noplink:
23530 + AuLabel(noplink);
23532 + case Opt_list_plink:
23533 + AuLabel(list_plink);
23536 + AuDbg("udba %d, %s\n",
23537 + opt->udba, au_optstr_udba(opt->udba));
23545 + case Opt_diropq_a:
23546 + AuLabel(diropq_a);
23548 + case Opt_diropq_w:
23549 + AuLabel(diropq_w);
23551 + case Opt_warn_perm:
23552 + AuLabel(warn_perm);
23554 + case Opt_nowarn_perm:
23555 + AuLabel(nowarn_perm);
23557 + case Opt_verbose:
23558 + AuLabel(verbose);
23560 + case Opt_noverbose:
23561 + AuLabel(noverbose);
23572 + case Opt_wbr_create:
23573 + u.create = &opt->wbr_create;
23574 + AuDbg("create %d, %s\n", u.create->wbr_create,
23575 + au_optstr_wbr_create(u.create->wbr_create));
23576 + switch (u.create->wbr_create) {
23577 + case AuWbrCreate_MFSV:
23578 + case AuWbrCreate_PMFSV:
23579 + AuDbg("%d sec\n", u.create->mfs_second);
23581 + case AuWbrCreate_MFSRR:
23582 + AuDbg("%llu watermark\n",
23583 + u.create->mfsrr_watermark);
23585 + case AuWbrCreate_MFSRRV:
23586 + case AuWbrCreate_PMFSRRV:
23587 + AuDbg("%llu watermark, %d sec\n",
23588 + u.create->mfsrr_watermark,
23589 + u.create->mfs_second);
23593 + case Opt_wbr_copyup:
23594 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
23595 + au_optstr_wbr_copyup(opt->wbr_copyup));
23597 + case Opt_fhsm_sec:
23598 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
23614 +void au_opts_free(struct au_opts *opts)
23616 + struct au_opt *opt;
23619 + while (opt->type != Opt_tail) {
23620 + switch (opt->type) {
23623 + case Opt_prepend:
23624 + path_put(&opt->add.path);
23628 + path_put(&opt->del.h_path);
23632 + dput(opt->mod.h_root);
23635 + fput(opt->xino.file);
23642 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
23643 + aufs_bindex_t bindex)
23646 + struct au_opt_add *add = &opt->add;
23649 + add->bindex = bindex;
23650 + add->perm = AuBrPerm_RO;
23651 + add->pathname = opt_str;
23652 + p = strchr(opt_str, '=');
23656 + add->perm = br_perm_val(p);
23659 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
23662 + add->perm = AuBrPerm_RO;
23663 + if (au_test_fs_rr(add->path.dentry->d_sb))
23664 + add->perm = AuBrPerm_RR;
23665 + else if (!bindex && !(sb_flags & MS_RDONLY))
23666 + add->perm = AuBrPerm_RW;
23668 + opt->type = Opt_add;
23671 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
23678 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
23682 + del->pathname = args[0].from;
23683 + AuDbg("del path %s\n", del->pathname);
23685 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
23686 + if (unlikely(err))
23687 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
23692 +#if 0 /* reserved for future use */
23693 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
23694 + struct au_opt_del *del, substring_t args[])
23697 + struct dentry *root;
23700 + root = sb->s_root;
23701 + aufs_read_lock(root, AuLock_FLUSH);
23702 + if (bindex < 0 || au_sbbot(sb) < bindex) {
23703 + pr_err("out of bounds, %d\n", bindex);
23708 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
23709 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
23712 + aufs_read_unlock(root, !AuLock_IR);
23717 +static int noinline_for_stack
23718 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
23721 + struct path path;
23725 + mod->path = args[0].from;
23726 + p = strchr(mod->path, '=');
23727 + if (unlikely(!p)) {
23728 + pr_err("no permssion %s\n", args[0].from);
23733 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
23734 + if (unlikely(err)) {
23735 + pr_err("lookup failed %s (%d)\n", mod->path, err);
23739 + mod->perm = br_perm_val(p);
23740 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
23741 + mod->h_root = dget(path.dentry);
23748 +#if 0 /* reserved for future use */
23749 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
23750 + struct au_opt_mod *mod, substring_t args[])
23753 + struct dentry *root;
23756 + root = sb->s_root;
23757 + aufs_read_lock(root, AuLock_FLUSH);
23758 + if (bindex < 0 || au_sbbot(sb) < bindex) {
23759 + pr_err("out of bounds, %d\n", bindex);
23764 + mod->perm = br_perm_val(args[1].from);
23765 + AuDbg("mod path %s, perm 0x%x, %s\n",
23766 + mod->path, mod->perm, args[1].from);
23767 + mod->h_root = dget(au_h_dptr(root, bindex));
23770 + aufs_read_unlock(root, !AuLock_IR);
23775 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
23776 + substring_t args[])
23779 + struct file *file;
23781 + file = au_xino_create(sb, args[0].from, /*silent*/0);
23782 + err = PTR_ERR(file);
23783 + if (IS_ERR(file))
23787 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
23789 + pr_err("%s must be outside\n", args[0].from);
23794 + xino->file = file;
23795 + xino->path = args[0].from;
23801 +static int noinline_for_stack
23802 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
23803 + struct au_opt_xino_itrunc *xino_itrunc,
23804 + substring_t args[])
23807 + aufs_bindex_t bbot, bindex;
23808 + struct path path;
23809 + struct dentry *root;
23811 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
23812 + if (unlikely(err)) {
23813 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
23817 + xino_itrunc->bindex = -1;
23818 + root = sb->s_root;
23819 + aufs_read_lock(root, AuLock_FLUSH);
23820 + bbot = au_sbbot(sb);
23821 + for (bindex = 0; bindex <= bbot; bindex++) {
23822 + if (au_h_dptr(root, bindex) == path.dentry) {
23823 + xino_itrunc->bindex = bindex;
23827 + aufs_read_unlock(root, !AuLock_IR);
23830 + if (unlikely(xino_itrunc->bindex < 0)) {
23831 + pr_err("no such branch %s\n", args[0].from);
23839 +/* called without aufs lock */
23840 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
23842 + int err, n, token;
23843 + aufs_bindex_t bindex;
23844 + unsigned char skipped;
23845 + struct dentry *root;
23846 + struct au_opt *opt, *opt_tail;
23848 + /* reduce the stack space */
23850 + struct au_opt_xino_itrunc *xino_itrunc;
23851 + struct au_opt_wbr_create *create;
23854 + substring_t args[MAX_OPT_ARGS];
23858 + a = kmalloc(sizeof(*a), GFP_NOFS);
23859 + if (unlikely(!a))
23862 + root = sb->s_root;
23866 + opt_tail = opt + opts->max_opt - 1;
23867 + opt->type = Opt_tail;
23868 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
23871 + token = match_token(opt_str, options, a->args);
23875 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
23877 + err = opt_add(opt, opt_str, opts->sb_flags,
23879 + if (unlikely(!err && ++opt > opt_tail)) {
23883 + opt->type = Opt_tail;
23888 + if (unlikely(match_int(&a->args[0], &n))) {
23889 + pr_err("bad integer in %s\n", opt_str);
23893 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
23896 + opt->type = token;
23899 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23900 + /*dummy bindex*/1);
23902 + opt->type = token;
23904 + case Opt_prepend:
23905 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
23908 + opt->type = token;
23911 + err = au_opts_parse_del(&opt->del, a->args);
23913 + opt->type = token;
23915 +#if 0 /* reserved for future use */
23917 + del->pathname = "(indexed)";
23918 + if (unlikely(match_int(&args[0], &n))) {
23919 + pr_err("bad integer in %s\n", opt_str);
23922 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
23924 + opt->type = token;
23928 + err = au_opts_parse_mod(&opt->mod, a->args);
23930 + opt->type = token;
23932 +#ifdef IMOD /* reserved for future use */
23934 + u.mod->path = "(indexed)";
23935 + if (unlikely(match_int(&a->args[0], &n))) {
23936 + pr_err("bad integer in %s\n", opt_str);
23939 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
23941 + opt->type = token;
23945 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
23947 + opt->type = token;
23950 + case Opt_trunc_xino_path:
23951 + err = au_opts_parse_xino_itrunc_path
23952 + (sb, &opt->xino_itrunc, a->args);
23954 + opt->type = token;
23957 + case Opt_itrunc_xino:
23958 + u.xino_itrunc = &opt->xino_itrunc;
23959 + if (unlikely(match_int(&a->args[0], &n))) {
23960 + pr_err("bad integer in %s\n", opt_str);
23963 + u.xino_itrunc->bindex = n;
23964 + aufs_read_lock(root, AuLock_FLUSH);
23965 + if (n < 0 || au_sbbot(sb) < n) {
23966 + pr_err("out of bounds, %d\n", n);
23967 + aufs_read_unlock(root, !AuLock_IR);
23970 + aufs_read_unlock(root, !AuLock_IR);
23972 + opt->type = token;
23976 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
23979 + opt->type = token;
23982 + case Opt_rdcache:
23983 + if (unlikely(match_int(&a->args[0], &n))) {
23984 + pr_err("bad integer in %s\n", opt_str);
23987 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
23988 + pr_err("rdcache must be smaller than %d\n",
23989 + AUFS_RDCACHE_MAX);
23992 + opt->rdcache = n;
23994 + opt->type = token;
23997 + if (unlikely(match_int(&a->args[0], &n)
23999 + || n > KMALLOC_MAX_SIZE)) {
24000 + pr_err("bad integer in %s\n", opt_str);
24003 + if (unlikely(n && n < NAME_MAX)) {
24004 + pr_err("rdblk must be larger than %d\n",
24010 + opt->type = token;
24013 + if (unlikely(match_int(&a->args[0], &n)
24015 + || n * sizeof(struct hlist_head)
24016 + > KMALLOC_MAX_SIZE)) {
24017 + pr_err("bad integer in %s\n", opt_str);
24022 + opt->type = token;
24025 + case Opt_trunc_xino:
24026 + case Opt_notrunc_xino:
24028 + case Opt_trunc_xib:
24029 + case Opt_notrunc_xib:
24032 + case Opt_dirperm1:
24033 + case Opt_nodirperm1:
24035 + case Opt_noplink:
24036 + case Opt_list_plink:
24039 + case Opt_diropq_a:
24040 + case Opt_diropq_w:
24041 + case Opt_warn_perm:
24042 + case Opt_nowarn_perm:
24043 + case Opt_verbose:
24044 + case Opt_noverbose:
24048 + case Opt_rdblk_def:
24049 + case Opt_rdhash_def:
24053 + opt->type = token;
24057 + opt->udba = udba_val(a->args[0].from);
24058 + if (opt->udba >= 0) {
24060 + opt->type = token;
24062 + pr_err("wrong value, %s\n", opt_str);
24065 + case Opt_wbr_create:
24066 + u.create = &opt->wbr_create;
24067 + u.create->wbr_create
24068 + = au_wbr_create_val(a->args[0].from, u.create);
24069 + if (u.create->wbr_create >= 0) {
24071 + opt->type = token;
24073 + pr_err("wrong value, %s\n", opt_str);
24075 + case Opt_wbr_copyup:
24076 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
24077 + if (opt->wbr_copyup >= 0) {
24079 + opt->type = token;
24081 + pr_err("wrong value, %s\n", opt_str);
24084 + case Opt_fhsm_sec:
24085 + if (unlikely(match_int(&a->args[0], &n)
24087 + pr_err("bad integer in %s\n", opt_str);
24090 + if (sysaufs_brs) {
24091 + opt->fhsm_second = n;
24092 + opt->type = token;
24094 + pr_warn("ignored %s\n", opt_str);
24099 + pr_warn("ignored %s\n", opt_str);
24101 + case Opt_ignore_silent:
24106 + pr_err("unknown option %s\n", opt_str);
24110 + if (!err && !skipped) {
24111 + if (unlikely(++opt > opt_tail)) {
24114 + opt->type = Opt_tail;
24117 + opt->type = Opt_tail;
24123 + if (unlikely(err))
24124 + au_opts_free(opts);
24130 +static int au_opt_wbr_create(struct super_block *sb,
24131 + struct au_opt_wbr_create *create)
24134 + struct au_sbinfo *sbinfo;
24136 + SiMustWriteLock(sb);
24138 + err = 1; /* handled */
24139 + sbinfo = au_sbi(sb);
24140 + if (sbinfo->si_wbr_create_ops->fin) {
24141 + err = sbinfo->si_wbr_create_ops->fin(sb);
24146 + sbinfo->si_wbr_create = create->wbr_create;
24147 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
24148 + switch (create->wbr_create) {
24149 + case AuWbrCreate_MFSRRV:
24150 + case AuWbrCreate_MFSRR:
24151 + case AuWbrCreate_PMFSRR:
24152 + case AuWbrCreate_PMFSRRV:
24153 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
24155 + case AuWbrCreate_MFS:
24156 + case AuWbrCreate_MFSV:
24157 + case AuWbrCreate_PMFS:
24158 + case AuWbrCreate_PMFSV:
24159 + sbinfo->si_wbr_mfs.mfs_expire
24160 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
24164 + if (sbinfo->si_wbr_create_ops->init)
24165 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
24172 + * plus: processed without an error
24173 + * zero: unprocessed
24175 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
24176 + struct au_opts *opts)
24179 + struct au_sbinfo *sbinfo;
24181 + SiMustWriteLock(sb);
24183 + err = 1; /* handled */
24184 + sbinfo = au_sbi(sb);
24185 + switch (opt->type) {
24187 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24188 + sbinfo->si_mntflags |= opt->udba;
24189 + opts->given_udba |= opt->udba;
24193 + au_opt_set(sbinfo->si_mntflags, PLINK);
24195 + case Opt_noplink:
24196 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24197 + au_plink_put(sb, /*verbose*/1);
24198 + au_opt_clr(sbinfo->si_mntflags, PLINK);
24200 + case Opt_list_plink:
24201 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24202 + au_plink_list(sb);
24206 + au_opt_set(sbinfo->si_mntflags, DIO);
24207 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24210 + au_opt_clr(sbinfo->si_mntflags, DIO);
24211 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24214 + case Opt_fhsm_sec:
24215 + au_fhsm_set(sbinfo, opt->fhsm_second);
24218 + case Opt_diropq_a:
24219 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24221 + case Opt_diropq_w:
24222 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24225 + case Opt_warn_perm:
24226 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
24228 + case Opt_nowarn_perm:
24229 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
24232 + case Opt_verbose:
24233 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
24235 + case Opt_noverbose:
24236 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
24240 + au_opt_set(sbinfo->si_mntflags, SUM);
24243 + au_opt_clr(sbinfo->si_mntflags, SUM);
24244 + au_opt_set(sbinfo->si_mntflags, SUM_W);
24246 + au_opt_clr(sbinfo->si_mntflags, SUM);
24247 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
24250 + case Opt_wbr_create:
24251 + err = au_opt_wbr_create(sb, &opt->wbr_create);
24253 + case Opt_wbr_copyup:
24254 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
24255 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
24259 + sbinfo->si_dirwh = opt->dirwh;
24262 + case Opt_rdcache:
24263 + sbinfo->si_rdcache
24264 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24267 + sbinfo->si_rdblk = opt->rdblk;
24269 + case Opt_rdblk_def:
24270 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24273 + sbinfo->si_rdhash = opt->rdhash;
24275 + case Opt_rdhash_def:
24276 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24280 + au_opt_set(sbinfo->si_mntflags, SHWH);
24283 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24286 + case Opt_dirperm1:
24287 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24289 + case Opt_nodirperm1:
24290 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24293 + case Opt_trunc_xino:
24294 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24296 + case Opt_notrunc_xino:
24297 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24300 + case Opt_trunc_xino_path:
24301 + case Opt_itrunc_xino:
24302 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24307 + case Opt_trunc_xib:
24308 + au_fset_opts(opts->flags, TRUNC_XIB);
24310 + case Opt_notrunc_xib:
24311 + au_fclr_opts(opts->flags, TRUNC_XIB);
24315 + sb->s_flags |= MS_POSIXACL;
24318 + sb->s_flags &= ~MS_POSIXACL;
24330 + * returns tri-state.
24331 + * plus: processed without an error
24332 + * zero: unprocessed
24335 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24336 + struct au_opts *opts)
24338 + int err, do_refresh;
24341 + switch (opt->type) {
24343 + opt->add.bindex = au_sbbot(sb) + 1;
24344 + if (opt->add.bindex < 0)
24345 + opt->add.bindex = 0;
24347 + case Opt_prepend:
24348 + opt->add.bindex = 0;
24349 + add: /* indented label */
24351 + err = au_br_add(sb, &opt->add,
24352 + au_ftest_opts(opts->flags, REMOUNT));
24355 + au_fset_opts(opts->flags, REFRESH);
24361 + err = au_br_del(sb, &opt->del,
24362 + au_ftest_opts(opts->flags, REMOUNT));
24365 + au_fset_opts(opts->flags, TRUNC_XIB);
24366 + au_fset_opts(opts->flags, REFRESH);
24372 + err = au_br_mod(sb, &opt->mod,
24373 + au_ftest_opts(opts->flags, REMOUNT),
24378 + au_fset_opts(opts->flags, REFRESH);
24386 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24387 + struct au_opt_xino **opt_xino,
24388 + struct au_opts *opts)
24391 + aufs_bindex_t bbot, bindex;
24392 + struct dentry *root, *parent, *h_root;
24395 + switch (opt->type) {
24397 + err = au_xino_set(sb, &opt->xino,
24398 + !!au_ftest_opts(opts->flags, REMOUNT));
24399 + if (unlikely(err))
24402 + *opt_xino = &opt->xino;
24403 + au_xino_brid_set(sb, -1);
24405 + /* safe d_parent access */
24406 + parent = opt->xino.file->f_path.dentry->d_parent;
24407 + root = sb->s_root;
24408 + bbot = au_sbbot(sb);
24409 + for (bindex = 0; bindex <= bbot; bindex++) {
24410 + h_root = au_h_dptr(root, bindex);
24411 + if (h_root == parent) {
24412 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24420 + au_xino_brid_set(sb, -1);
24421 + *opt_xino = (void *)-1;
24428 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24429 + unsigned int pending)
24432 + aufs_bindex_t bindex, bbot;
24433 + unsigned char do_plink, skip, do_free, can_no_dreval;
24434 + struct au_branch *br;
24435 + struct au_wbr *wbr;
24436 + struct dentry *root, *dentry;
24437 + struct inode *dir, *h_dir;
24438 + struct au_sbinfo *sbinfo;
24439 + struct au_hinode *hdir;
24441 + SiMustAnyLock(sb);
24443 + sbinfo = au_sbi(sb);
24444 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24446 + if (!(sb_flags & MS_RDONLY)) {
24447 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24448 + pr_warn("first branch should be rw\n");
24449 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24450 + pr_warn_once("shwh should be used with ro\n");
24453 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24454 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24455 + pr_warn_once("udba=*notify requires xino\n");
24457 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24458 + pr_warn_once("dirperm1 breaks the protection"
24459 + " by the permission bits on the lower branch\n");
24463 + root = sb->s_root;
24464 + dir = d_inode(root);
24465 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24466 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
24468 + bbot = au_sbbot(sb);
24469 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
24471 + h_dir = au_h_iptr(dir, bindex);
24472 + br = au_sbr(sb, bindex);
24474 + if ((br->br_perm & AuBrAttr_ICEX)
24475 + && !h_dir->i_op->listxattr)
24476 + br->br_perm &= ~AuBrAttr_ICEX;
24478 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24479 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24480 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24484 + wbr = br->br_wbr;
24486 + wbr_wh_read_lock(wbr);
24488 + if (!au_br_writable(br->br_perm)) {
24491 + || (!wbr->wbr_whbase
24492 + && !wbr->wbr_plink
24493 + && !wbr->wbr_orph));
24494 + } else if (!au_br_wh_linkable(br->br_perm)) {
24495 + /* skip = (!br->br_whbase && !br->br_orph); */
24496 + skip = (!wbr || !wbr->wbr_whbase);
24497 + if (skip && wbr) {
24499 + skip = !!wbr->wbr_plink;
24501 + skip = !wbr->wbr_plink;
24504 + /* skip = (br->br_whbase && br->br_ohph); */
24505 + skip = (wbr && wbr->wbr_whbase);
24508 + skip = !!wbr->wbr_plink;
24510 + skip = !wbr->wbr_plink;
24514 + wbr_wh_read_unlock(wbr);
24516 + if (can_no_dreval) {
24517 + dentry = br->br_path.dentry;
24518 + spin_lock(&dentry->d_lock);
24519 + if (dentry->d_flags &
24520 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
24521 + can_no_dreval = 0;
24522 + spin_unlock(&dentry->d_lock);
24525 + if (au_br_fhsm(br->br_perm)) {
24527 + AuDebugOn(!br->br_fhsm);
24533 + hdir = au_hi(dir, bindex);
24534 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
24536 + wbr_wh_write_lock(wbr);
24537 + err = au_wh_init(br, sb);
24539 + wbr_wh_write_unlock(wbr);
24540 + au_hn_inode_unlock(hdir);
24542 + if (!err && do_free) {
24544 + br->br_wbr = NULL;
24548 + if (can_no_dreval)
24549 + au_fset_si(sbinfo, NO_DREVAL);
24551 + au_fclr_si(sbinfo, NO_DREVAL);
24554 + au_fset_si(sbinfo, FHSM);
24555 + for (bindex = bbot; bindex >= 0; bindex--) {
24556 + br = au_sbr(sb, bindex);
24557 + if (au_br_fhsm(br->br_perm)) {
24558 + au_fhsm_set_bottom(sb, bindex);
24563 + au_fclr_si(sbinfo, FHSM);
24564 + au_fhsm_set_bottom(sb, -1);
24570 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24573 + unsigned int tmp;
24574 + aufs_bindex_t bindex, bbot;
24575 + struct au_opt *opt;
24576 + struct au_opt_xino *opt_xino, xino;
24577 + struct au_sbinfo *sbinfo;
24578 + struct au_branch *br;
24579 + struct inode *dir;
24581 + SiMustWriteLock(sb);
24586 + while (err >= 0 && opt->type != Opt_tail)
24587 + err = au_opt_simple(sb, opt++, opts);
24590 + else if (unlikely(err < 0))
24593 + /* disable xino and udba temporary */
24594 + sbinfo = au_sbi(sb);
24595 + tmp = sbinfo->si_mntflags;
24596 + au_opt_clr(sbinfo->si_mntflags, XINO);
24597 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
24600 + while (err >= 0 && opt->type != Opt_tail)
24601 + err = au_opt_br(sb, opt++, opts);
24604 + else if (unlikely(err < 0))
24607 + bbot = au_sbbot(sb);
24608 + if (unlikely(bbot < 0)) {
24610 + pr_err("no branches\n");
24614 + if (au_opt_test(tmp, XINO))
24615 + au_opt_set(sbinfo->si_mntflags, XINO);
24617 + while (!err && opt->type != Opt_tail)
24618 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
24619 + if (unlikely(err))
24622 + err = au_opts_verify(sb, sb->s_flags, tmp);
24623 + if (unlikely(err))
24626 + /* restore xino */
24627 + if (au_opt_test(tmp, XINO) && !opt_xino) {
24628 + xino.file = au_xino_def(sb);
24629 + err = PTR_ERR(xino.file);
24630 + if (IS_ERR(xino.file))
24633 + err = au_xino_set(sb, &xino, /*remount*/0);
24635 + if (unlikely(err))
24639 + /* restore udba */
24640 + tmp &= AuOptMask_UDBA;
24641 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24642 + sbinfo->si_mntflags |= tmp;
24643 + bbot = au_sbbot(sb);
24644 + for (bindex = 0; bindex <= bbot; bindex++) {
24645 + br = au_sbr(sb, bindex);
24646 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
24647 + if (unlikely(err))
24648 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24650 + /* go on even if err */
24652 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
24653 + dir = d_inode(sb->s_root);
24654 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
24661 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
24664 + unsigned char no_dreval;
24665 + struct inode *dir;
24666 + struct au_opt_xino *opt_xino;
24667 + struct au_opt *opt;
24668 + struct au_sbinfo *sbinfo;
24670 + SiMustWriteLock(sb);
24673 + dir = d_inode(sb->s_root);
24674 + sbinfo = au_sbi(sb);
24677 + while (err >= 0 && opt->type != Opt_tail) {
24678 + err = au_opt_simple(sb, opt, opts);
24680 + err = au_opt_br(sb, opt, opts);
24682 + err = au_opt_xino(sb, opt, &opt_xino, opts);
24688 + /* go on even err */
24690 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
24691 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
24692 + if (unlikely(rerr && !err))
24695 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
24696 + au_fset_opts(opts->flags, REFRESH_IDOP);
24698 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
24699 + rerr = au_xib_trunc(sb);
24700 + if (unlikely(rerr && !err))
24704 + /* will be handled by the caller */
24705 + if (!au_ftest_opts(opts->flags, REFRESH)
24706 + && (opts->given_udba
24707 + || au_opt_test(sbinfo->si_mntflags, XINO)
24708 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
24710 + au_fset_opts(opts->flags, REFRESH);
24712 + AuDbg("status 0x%x\n", opts->flags);
24716 +/* ---------------------------------------------------------------------- */
24718 +unsigned int au_opt_udba(struct super_block *sb)
24720 + return au_mntflags(sb) & AuOptMask_UDBA;
24722 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
24723 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
24724 +++ linux/fs/aufs/opts.h 2016-07-25 19:05:34.814493242 +0200
24727 + * Copyright (C) 2005-2016 Junjiro R. Okajima
24729 + * This program, aufs is free software; you can redistribute it and/or modify
24730 + * it under the terms of the GNU General Public License as published by
24731 + * the Free Software Foundation; either version 2 of the License, or
24732 + * (at your option) any later version.
24734 + * This program is distributed in the hope that it will be useful,
24735 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24736 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24737 + * GNU General Public License for more details.
24739 + * You should have received a copy of the GNU General Public License
24740 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24744 + * mount options/flags
24747 +#ifndef __AUFS_OPTS_H__
24748 +#define __AUFS_OPTS_H__
24752 +#include <linux/path.h>
24755 +struct super_block;
24757 +/* ---------------------------------------------------------------------- */
24760 +#define AuOpt_XINO 1 /* external inode number bitmap
24761 + and translation table */
24762 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
24763 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
24764 +#define AuOpt_UDBA_REVAL (1 << 3)
24765 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
24766 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
24767 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
24768 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
24770 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
24771 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
24772 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
24773 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
24774 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
24775 +#define AuOpt_DIO (1 << 14) /* direct io */
24777 +#ifndef CONFIG_AUFS_HNOTIFY
24778 +#undef AuOpt_UDBA_HNOTIFY
24779 +#define AuOpt_UDBA_HNOTIFY 0
24781 +#ifndef CONFIG_AUFS_SHWH
24783 +#define AuOpt_SHWH 0
24786 +#define AuOpt_Def (AuOpt_XINO \
24787 + | AuOpt_UDBA_REVAL \
24789 + /* | AuOpt_DIRPERM1 */ \
24790 + | AuOpt_WARN_PERM)
24791 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
24792 + | AuOpt_UDBA_REVAL \
24793 + | AuOpt_UDBA_HNOTIFY)
24795 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
24796 +#define au_opt_set(flags, name) do { \
24797 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
24798 + ((flags) |= AuOpt_##name); \
24800 +#define au_opt_set_udba(flags, name) do { \
24801 + (flags) &= ~AuOptMask_UDBA; \
24802 + ((flags) |= AuOpt_##name); \
24804 +#define au_opt_clr(flags, name) do { \
24805 + ((flags) &= ~AuOpt_##name); \
24808 +static inline unsigned int au_opts_plink(unsigned int mntflags)
24810 +#ifdef CONFIG_PROC_FS
24813 + return mntflags & ~AuOpt_PLINK;
24817 +/* ---------------------------------------------------------------------- */
24819 +/* policies to select one among multiple writable branches */
24821 + AuWbrCreate_TDP, /* top down parent */
24822 + AuWbrCreate_RR, /* round robin */
24823 + AuWbrCreate_MFS, /* most free space */
24824 + AuWbrCreate_MFSV, /* mfs with seconds */
24825 + AuWbrCreate_MFSRR, /* mfs then rr */
24826 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
24827 + AuWbrCreate_PMFS, /* parent and mfs */
24828 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
24829 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
24830 + AuWbrCreate_PMFSRRV, /* plus seconds */
24832 + AuWbrCreate_Def = AuWbrCreate_TDP
24836 + AuWbrCopyup_TDP, /* top down parent */
24837 + AuWbrCopyup_BUP, /* bottom up parent */
24838 + AuWbrCopyup_BU, /* bottom up */
24840 + AuWbrCopyup_Def = AuWbrCopyup_TDP
24843 +/* ---------------------------------------------------------------------- */
24845 +struct au_opt_add {
24846 + aufs_bindex_t bindex;
24849 + struct path path;
24852 +struct au_opt_del {
24854 + struct path h_path;
24857 +struct au_opt_mod {
24860 + struct dentry *h_root;
24863 +struct au_opt_xino {
24865 + struct file *file;
24868 +struct au_opt_xino_itrunc {
24869 + aufs_bindex_t bindex;
24872 +struct au_opt_wbr_create {
24875 + unsigned long long mfsrr_watermark;
24881 + struct au_opt_xino xino;
24882 + struct au_opt_xino_itrunc xino_itrunc;
24883 + struct au_opt_add add;
24884 + struct au_opt_del del;
24885 + struct au_opt_mod mod;
24888 + unsigned int rdblk;
24889 + unsigned int rdhash;
24891 + struct au_opt_wbr_create wbr_create;
24893 + unsigned int fhsm_second;
24898 +#define AuOpts_REMOUNT 1
24899 +#define AuOpts_REFRESH (1 << 1)
24900 +#define AuOpts_TRUNC_XIB (1 << 2)
24901 +#define AuOpts_REFRESH_DYAOP (1 << 3)
24902 +#define AuOpts_REFRESH_IDOP (1 << 4)
24903 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
24904 +#define au_fset_opts(flags, name) \
24905 + do { (flags) |= AuOpts_##name; } while (0)
24906 +#define au_fclr_opts(flags, name) \
24907 + do { (flags) &= ~AuOpts_##name; } while (0)
24910 + struct au_opt *opt;
24913 + unsigned int given_udba;
24914 + unsigned int flags;
24915 + unsigned long sb_flags;
24918 +/* ---------------------------------------------------------------------- */
24921 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
24922 +const char *au_optstr_udba(int udba);
24923 +const char *au_optstr_wbr_copyup(int wbr_copyup);
24924 +const char *au_optstr_wbr_create(int wbr_create);
24926 +void au_opts_free(struct au_opts *opts);
24927 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
24928 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24929 + unsigned int pending);
24930 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
24931 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
24933 +unsigned int au_opt_udba(struct super_block *sb);
24935 +#endif /* __KERNEL__ */
24936 +#endif /* __AUFS_OPTS_H__ */
24937 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
24938 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
24939 +++ linux/fs/aufs/plink.c 2016-07-25 19:05:34.817826663 +0200
24942 + * Copyright (C) 2005-2016 Junjiro R. Okajima
24944 + * This program, aufs is free software; you can redistribute it and/or modify
24945 + * it under the terms of the GNU General Public License as published by
24946 + * the Free Software Foundation; either version 2 of the License, or
24947 + * (at your option) any later version.
24949 + * This program is distributed in the hope that it will be useful,
24950 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
24951 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24952 + * GNU General Public License for more details.
24954 + * You should have received a copy of the GNU General Public License
24955 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
24965 + * the pseudo-link maintenance mode.
24966 + * during a user process maintains the pseudo-links,
24967 + * prohibit adding a new plink and branch manipulation.
24971 + * For entry functions which will handle plink, and i_mutex is already held
24973 + * They cannot wait and should return an error at once.
24974 + * Callers has to check the error.
24976 + * For entry functions which will handle plink, but i_mutex is not held
24978 + * They can wait the plink maintenance mode to finish.
24980 + * They behave like F_SETLK and F_SETLKW.
24981 + * If the caller never handle plink, then both flags are unnecessary.
24984 +int au_plink_maint(struct super_block *sb, int flags)
24988 + struct au_sbinfo *sbi;
24990 + SiMustAnyLock(sb);
24993 + if (!au_opt_test(au_mntflags(sb), PLINK))
24996 + sbi = au_sbi(sb);
24997 + pid = sbi->si_plink_maint_pid;
24998 + if (!pid || pid == current->pid)
25001 + /* todo: it highly depends upon /sbin/mount.aufs */
25003 + ppid = task_pid_vnr(rcu_dereference(current->real_parent));
25004 + rcu_read_unlock();
25008 + if (au_ftest_lock(flags, NOPLMW)) {
25009 + /* if there is no i_mutex lock in VFS, we don't need to wait */
25010 + /* AuDebugOn(!lockdep_depth(current)); */
25011 + while (sbi->si_plink_maint_pid) {
25012 + si_read_unlock(sb);
25013 + /* gave up wake_up_bit() */
25014 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
25016 + if (au_ftest_lock(flags, FLUSH))
25017 + au_nwt_flush(&sbi->si_nowait);
25018 + si_noflush_read_lock(sb);
25020 + } else if (au_ftest_lock(flags, NOPLM)) {
25021 + AuDbg("ppid %d, pid %d\n", ppid, pid);
25029 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
25031 + spin_lock(&sbinfo->si_plink_maint_lock);
25032 + sbinfo->si_plink_maint_pid = 0;
25033 + spin_unlock(&sbinfo->si_plink_maint_lock);
25034 + wake_up_all(&sbinfo->si_plink_wq);
25037 +int au_plink_maint_enter(struct super_block *sb)
25040 + struct au_sbinfo *sbinfo;
25043 + sbinfo = au_sbi(sb);
25044 + /* make sure i am the only one in this fs */
25045 + si_write_lock(sb, AuLock_FLUSH);
25046 + if (au_opt_test(au_mntflags(sb), PLINK)) {
25047 + spin_lock(&sbinfo->si_plink_maint_lock);
25048 + if (!sbinfo->si_plink_maint_pid)
25049 + sbinfo->si_plink_maint_pid = current->pid;
25052 + spin_unlock(&sbinfo->si_plink_maint_lock);
25054 + si_write_unlock(sb);
25059 +/* ---------------------------------------------------------------------- */
25061 +#ifdef CONFIG_AUFS_DEBUG
25062 +void au_plink_list(struct super_block *sb)
25065 + struct au_sbinfo *sbinfo;
25066 + struct hlist_head *plink_hlist;
25067 + struct au_icntnr *icntnr;
25069 + SiMustAnyLock(sb);
25071 + sbinfo = au_sbi(sb);
25072 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25073 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25075 + for (i = 0; i < AuPlink_NHASH; i++) {
25076 + plink_hlist = &sbinfo->si_plink[i].head;
25078 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25079 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
25080 + rcu_read_unlock();
25085 +/* is the inode pseudo-linked? */
25086 +int au_plink_test(struct inode *inode)
25089 + struct au_sbinfo *sbinfo;
25090 + struct hlist_head *plink_hlist;
25091 + struct au_icntnr *icntnr;
25093 + sbinfo = au_sbi(inode->i_sb);
25094 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25095 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
25096 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25099 + i = au_plink_hash(inode->i_ino);
25100 + plink_hlist = &sbinfo->si_plink[i].head;
25102 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25103 + if (&icntnr->vfs_inode == inode) {
25107 + rcu_read_unlock();
25111 +/* ---------------------------------------------------------------------- */
25114 + * generate a name for plink.
25115 + * the file will be stored under AUFS_WH_PLINKDIR.
25117 +/* 20 is max digits length of ulong 64 */
25118 +#define PLINK_NAME_LEN ((20 + 1) * 2)
25120 +static int plink_name(char *name, int len, struct inode *inode,
25121 + aufs_bindex_t bindex)
25124 + struct inode *h_inode;
25126 + h_inode = au_h_iptr(inode, bindex);
25127 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
25131 +struct au_do_plink_lkup_args {
25132 + struct dentry **errp;
25133 + struct qstr *tgtname;
25134 + struct dentry *h_parent;
25135 + struct au_branch *br;
25138 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
25139 + struct dentry *h_parent,
25140 + struct au_branch *br)
25142 + struct dentry *h_dentry;
25143 + struct inode *h_inode;
25145 + h_inode = d_inode(h_parent);
25146 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
25147 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
25148 + inode_unlock(h_inode);
25152 +static void au_call_do_plink_lkup(void *args)
25154 + struct au_do_plink_lkup_args *a = args;
25155 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
25158 +/* lookup the plink-ed @inode under the branch at @bindex */
25159 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
25161 + struct dentry *h_dentry, *h_parent;
25162 + struct au_branch *br;
25164 + char a[PLINK_NAME_LEN];
25165 + struct qstr tgtname = QSTR_INIT(a, 0);
25167 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25169 + br = au_sbr(inode->i_sb, bindex);
25170 + h_parent = br->br_wbr->wbr_plink;
25171 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25173 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25174 + struct au_do_plink_lkup_args args = {
25175 + .errp = &h_dentry,
25176 + .tgtname = &tgtname,
25177 + .h_parent = h_parent,
25181 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
25182 + if (unlikely(wkq_err))
25183 + h_dentry = ERR_PTR(wkq_err);
25185 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
25190 +/* create a pseudo-link */
25191 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
25192 + struct dentry *h_dentry, struct au_branch *br)
25195 + struct path h_path = {
25196 + .mnt = au_br_mnt(br)
25198 + struct inode *h_dir, *delegated;
25200 + h_dir = d_inode(h_parent);
25201 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
25203 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
25204 + err = PTR_ERR(h_path.dentry);
25205 + if (IS_ERR(h_path.dentry))
25209 + /* wh.plink dir is not monitored */
25210 + /* todo: is it really safe? */
25211 + if (d_is_positive(h_path.dentry)
25212 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
25213 + delegated = NULL;
25214 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
25215 + if (unlikely(err == -EWOULDBLOCK)) {
25216 + pr_warn("cannot retry for NFSv4 delegation"
25217 + " for an internal unlink\n");
25220 + dput(h_path.dentry);
25221 + h_path.dentry = NULL;
25225 + if (!err && d_is_negative(h_path.dentry)) {
25226 + delegated = NULL;
25227 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
25228 + if (unlikely(err == -EWOULDBLOCK)) {
25229 + pr_warn("cannot retry for NFSv4 delegation"
25230 + " for an internal link\n");
25234 + dput(h_path.dentry);
25237 + inode_unlock(h_dir);
25241 +struct do_whplink_args {
25243 + struct qstr *tgt;
25244 + struct dentry *h_parent;
25245 + struct dentry *h_dentry;
25246 + struct au_branch *br;
25249 +static void call_do_whplink(void *args)
25251 + struct do_whplink_args *a = args;
25252 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
25255 +static int whplink(struct dentry *h_dentry, struct inode *inode,
25256 + aufs_bindex_t bindex, struct au_branch *br)
25258 + int err, wkq_err;
25259 + struct au_wbr *wbr;
25260 + struct dentry *h_parent;
25261 + char a[PLINK_NAME_LEN];
25262 + struct qstr tgtname = QSTR_INIT(a, 0);
25264 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
25265 + h_parent = wbr->wbr_plink;
25266 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25268 + /* always superio. */
25269 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25270 + struct do_whplink_args args = {
25273 + .h_parent = h_parent,
25274 + .h_dentry = h_dentry,
25277 + wkq_err = au_wkq_wait(call_do_whplink, &args);
25278 + if (unlikely(wkq_err))
25281 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
25287 + * create a new pseudo-link for @h_dentry on @bindex.
25288 + * the linked inode is held in aufs @inode.
25290 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25291 + struct dentry *h_dentry)
25293 + struct super_block *sb;
25294 + struct au_sbinfo *sbinfo;
25295 + struct hlist_head *plink_hlist;
25296 + struct au_icntnr *icntnr;
25297 + struct au_sphlhead *sphl;
25298 + int found, err, cnt, i;
25300 + sb = inode->i_sb;
25301 + sbinfo = au_sbi(sb);
25302 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25303 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25305 + found = au_plink_test(inode);
25309 + i = au_plink_hash(inode->i_ino);
25310 + sphl = sbinfo->si_plink + i;
25311 + plink_hlist = &sphl->head;
25314 + spin_lock(&sphl->spin);
25315 + hlist_for_each_entry(icntnr, plink_hlist, plink) {
25316 + if (&icntnr->vfs_inode == inode) {
25322 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
25323 + hlist_add_head_rcu(&icntnr->plink, plink_hlist);
25325 + spin_unlock(&sphl->spin);
25327 + cnt = au_sphl_count(sphl);
25328 +#define msg "unexpectedly unblanced or too many pseudo-links"
25329 + if (cnt > AUFS_PLINK_WARN)
25330 + AuWarn1(msg ", %d\n", cnt);
25332 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25333 + if (unlikely(err)) {
25334 + pr_warn("err %d, damaged pseudo link.\n", err);
25335 + au_sphl_del_rcu(&icntnr->plink, sphl);
25336 + iput(&icntnr->vfs_inode);
25339 + iput(&icntnr->vfs_inode);
25342 +/* free all plinks */
25343 +void au_plink_put(struct super_block *sb, int verbose)
25346 + struct au_sbinfo *sbinfo;
25347 + struct hlist_head *plink_hlist;
25348 + struct hlist_node *tmp;
25349 + struct au_icntnr *icntnr;
25351 + SiMustWriteLock(sb);
25353 + sbinfo = au_sbi(sb);
25354 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25355 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25357 + /* no spin_lock since sbinfo is write-locked */
25359 + for (i = 0; i < AuPlink_NHASH; i++) {
25360 + plink_hlist = &sbinfo->si_plink[i].head;
25361 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25362 + pr_warn("pseudo-link is not flushed");
25365 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink)
25366 + iput(&icntnr->vfs_inode);
25367 + INIT_HLIST_HEAD(plink_hlist);
25371 +void au_plink_clean(struct super_block *sb, int verbose)
25373 + struct dentry *root;
25375 + root = sb->s_root;
25376 + aufs_write_lock(root);
25377 + if (au_opt_test(au_mntflags(sb), PLINK))
25378 + au_plink_put(sb, verbose);
25379 + aufs_write_unlock(root);
25382 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25385 + aufs_bindex_t btop, bbot, bindex;
25388 + btop = au_ibtop(inode);
25389 + bbot = au_ibbot(inode);
25391 + for (bindex = btop; bindex <= bbot; bindex++) {
25392 + if (!au_h_iptr(inode, bindex)
25393 + || au_ii_br_id(inode, bindex) != br_id)
25395 + au_set_h_iptr(inode, bindex, NULL, 0);
25400 + for (bindex = btop; bindex <= bbot; bindex++)
25401 + if (au_h_iptr(inode, bindex)) {
25411 +/* free the plinks on a branch specified by @br_id */
25412 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25414 + struct au_sbinfo *sbinfo;
25415 + struct hlist_head *plink_hlist;
25416 + struct hlist_node *tmp;
25417 + struct au_icntnr *icntnr;
25418 + struct inode *inode;
25421 + SiMustWriteLock(sb);
25423 + sbinfo = au_sbi(sb);
25424 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25425 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25427 + /* no spin_lock since sbinfo is write-locked */
25428 + for (i = 0; i < AuPlink_NHASH; i++) {
25429 + plink_hlist = &sbinfo->si_plink[i].head;
25430 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink) {
25431 + inode = au_igrab(&icntnr->vfs_inode);
25432 + ii_write_lock_child(inode);
25433 + do_put = au_plink_do_half_refresh(inode, br_id);
25435 + hlist_del(&icntnr->plink);
25438 + ii_write_unlock(inode);
25443 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25444 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25445 +++ linux/fs/aufs/poll.c 2016-07-25 19:05:34.817826663 +0200
25448 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25450 + * This program, aufs is free software; you can redistribute it and/or modify
25451 + * it under the terms of the GNU General Public License as published by
25452 + * the Free Software Foundation; either version 2 of the License, or
25453 + * (at your option) any later version.
25455 + * This program is distributed in the hope that it will be useful,
25456 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25457 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25458 + * GNU General Public License for more details.
25460 + * You should have received a copy of the GNU General Public License
25461 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25466 + * There is only one filesystem which implements ->poll operation, currently.
25471 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25473 + unsigned int mask;
25475 + struct file *h_file;
25476 + struct super_block *sb;
25478 + /* We should pretend an error happened. */
25479 + mask = POLLERR /* | POLLIN | POLLOUT */;
25480 + sb = file->f_path.dentry->d_sb;
25481 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25483 + h_file = au_read_pre(file, /*keep_fi*/0);
25484 + err = PTR_ERR(h_file);
25485 + if (IS_ERR(h_file))
25488 + /* it is not an error if h_file has no operation */
25489 + mask = DEFAULT_POLLMASK;
25490 + if (h_file->f_op->poll)
25491 + mask = h_file->f_op->poll(h_file, wait);
25492 + fput(h_file); /* instead of au_read_post() */
25495 + si_read_unlock(sb);
25496 + AuTraceErr((int)mask);
25499 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25500 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25501 +++ linux/fs/aufs/posix_acl.c 2016-07-25 19:05:34.817826663 +0200
25504 + * Copyright (C) 2014-2016 Junjiro R. Okajima
25506 + * This program, aufs is free software; you can redistribute it and/or modify
25507 + * it under the terms of the GNU General Public License as published by
25508 + * the Free Software Foundation; either version 2 of the License, or
25509 + * (at your option) any later version.
25511 + * This program is distributed in the hope that it will be useful,
25512 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25513 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25514 + * GNU General Public License for more details.
25516 + * You should have received a copy of the GNU General Public License
25517 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25521 + * posix acl operations
25524 +#include <linux/fs.h>
25527 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25529 + struct posix_acl *acl;
25531 + aufs_bindex_t bindex;
25532 + struct inode *h_inode;
25533 + struct super_block *sb;
25536 + sb = inode->i_sb;
25537 + si_read_lock(sb, AuLock_FLUSH);
25538 + ii_read_lock_child(inode);
25539 + if (!(sb->s_flags & MS_POSIXACL))
25542 + bindex = au_ibtop(inode);
25543 + h_inode = au_h_iptr(inode, bindex);
25544 + if (unlikely(!h_inode
25545 + || ((h_inode->i_mode & S_IFMT)
25546 + != (inode->i_mode & S_IFMT)))) {
25547 + err = au_busy_or_stale();
25548 + acl = ERR_PTR(err);
25552 + /* always topmost only */
25553 + acl = get_acl(h_inode, type);
25556 + ii_read_unlock(inode);
25557 + si_read_unlock(sb);
25559 + AuTraceErrPtr(acl);
25563 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25567 + struct dentry *dentry;
25568 + struct au_srxattr arg = {
25569 + .type = AU_ACL_SET,
25576 + IMustLock(inode);
25578 + if (inode->i_ino == AUFS_ROOT_INO)
25579 + dentry = dget(inode->i_sb->s_root);
25581 + dentry = d_find_alias(inode);
25583 + dentry = d_find_any_alias(inode);
25585 + pr_warn("cannot handle this inode, "
25586 + "please report to aufs-users ML\n");
25592 + ssz = au_srxattr(dentry, inode, &arg);
25601 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
25602 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
25603 +++ linux/fs/aufs/procfs.c 2016-07-25 19:05:34.817826663 +0200
25606 + * Copyright (C) 2010-2016 Junjiro R. Okajima
25608 + * This program, aufs is free software; you can redistribute it and/or modify
25609 + * it under the terms of the GNU General Public License as published by
25610 + * the Free Software Foundation; either version 2 of the License, or
25611 + * (at your option) any later version.
25613 + * This program is distributed in the hope that it will be useful,
25614 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25615 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25616 + * GNU General Public License for more details.
25618 + * You should have received a copy of the GNU General Public License
25619 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25623 + * procfs interfaces
25626 +#include <linux/proc_fs.h>
25629 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
25631 + struct au_sbinfo *sbinfo;
25633 + sbinfo = file->private_data;
25635 + au_plink_maint_leave(sbinfo);
25636 + kobject_put(&sbinfo->si_kobj);
25642 +static void au_procfs_plm_write_clean(struct file *file)
25644 + struct au_sbinfo *sbinfo;
25646 + sbinfo = file->private_data;
25648 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
25651 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
25654 + struct super_block *sb;
25655 + struct au_sbinfo *sbinfo;
25658 + if (unlikely(file->private_data))
25662 + /* don't use au_sbilist_lock() here */
25663 + spin_lock(&au_sbilist.spin);
25664 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
25665 + if (id == sysaufs_si_id(sbinfo)) {
25666 + kobject_get(&sbinfo->si_kobj);
25667 + sb = sbinfo->si_sb;
25670 + spin_unlock(&au_sbilist.spin);
25673 + if (unlikely(!sb))
25676 + err = au_plink_maint_enter(sb);
25678 + /* keep kobject_get() */
25679 + file->private_data = sbinfo;
25681 + kobject_put(&sbinfo->si_kobj);
25687 + * Accept a valid "si=xxxx" only.
25688 + * Once it is accepted successfully, accept "clean" too.
25690 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
25691 + size_t count, loff_t *ppos)
25694 + unsigned long id;
25695 + /* last newline is allowed */
25696 + char buf[3 + sizeof(unsigned long) * 2 + 1];
25699 + if (unlikely(!capable(CAP_SYS_ADMIN)))
25703 + if (unlikely(count > sizeof(buf)))
25706 + err = copy_from_user(buf, ubuf, count);
25707 + if (unlikely(err)) {
25714 + if (!strcmp("clean", buf)) {
25715 + au_procfs_plm_write_clean(file);
25716 + goto out_success;
25717 + } else if (unlikely(strncmp("si=", buf, 3)))
25720 + err = kstrtoul(buf + 3, 16, &id);
25721 + if (unlikely(err))
25724 + err = au_procfs_plm_write_si(file, id);
25725 + if (unlikely(err))
25729 + err = count; /* success */
25734 +static const struct file_operations au_procfs_plm_fop = {
25735 + .write = au_procfs_plm_write,
25736 + .release = au_procfs_plm_release,
25737 + .owner = THIS_MODULE
25740 +/* ---------------------------------------------------------------------- */
25742 +static struct proc_dir_entry *au_procfs_dir;
25744 +void au_procfs_fin(void)
25746 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
25747 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25750 +int __init au_procfs_init(void)
25753 + struct proc_dir_entry *entry;
25756 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
25757 + if (unlikely(!au_procfs_dir))
25760 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
25761 + au_procfs_dir, &au_procfs_plm_fop);
25762 + if (unlikely(!entry))
25766 + goto out; /* success */
25770 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
25774 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
25775 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
25776 +++ linux/fs/aufs/rdu.c 2016-07-25 19:05:34.817826663 +0200
25779 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25781 + * This program, aufs is free software; you can redistribute it and/or modify
25782 + * it under the terms of the GNU General Public License as published by
25783 + * the Free Software Foundation; either version 2 of the License, or
25784 + * (at your option) any later version.
25786 + * This program is distributed in the hope that it will be useful,
25787 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25788 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25789 + * GNU General Public License for more details.
25791 + * You should have received a copy of the GNU General Public License
25792 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25796 + * readdir in userspace.
25799 +#include <linux/compat.h>
25800 +#include <linux/fs_stack.h>
25801 +#include <linux/security.h>
25804 +/* bits for struct aufs_rdu.flags */
25805 +#define AuRdu_CALLED 1
25806 +#define AuRdu_CONT (1 << 1)
25807 +#define AuRdu_FULL (1 << 2)
25808 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
25809 +#define au_fset_rdu(flags, name) \
25810 + do { (flags) |= AuRdu_##name; } while (0)
25811 +#define au_fclr_rdu(flags, name) \
25812 + do { (flags) &= ~AuRdu_##name; } while (0)
25814 +struct au_rdu_arg {
25815 + struct dir_context ctx;
25816 + struct aufs_rdu *rdu;
25817 + union au_rdu_ent_ul ent;
25818 + unsigned long end;
25820 + struct super_block *sb;
25824 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
25825 + loff_t offset, u64 h_ino, unsigned int d_type)
25828 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
25829 + struct aufs_rdu *rdu = arg->rdu;
25830 + struct au_rdu_ent ent;
25834 + au_fset_rdu(rdu->cookie.flags, CALLED);
25835 + len = au_rdu_len(nlen);
25836 + if (arg->ent.ul + len < arg->end) {
25838 + ent.bindex = rdu->cookie.bindex;
25839 + ent.type = d_type;
25841 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
25842 + ent.type = DT_UNKNOWN;
25844 + /* unnecessary to support mmap_sem since this is a dir */
25846 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
25848 + if (copy_to_user(arg->ent.e->name, name, nlen))
25850 + /* the terminating NULL */
25851 + if (__put_user(0, arg->ent.e->name + nlen))
25854 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
25855 + arg->ent.ul += len;
25859 + au_fset_rdu(rdu->cookie.flags, FULL);
25861 + rdu->tail = arg->ent;
25865 + /* AuTraceErr(err); */
25869 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
25873 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
25875 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
25876 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
25878 + if (unlikely(offset != cookie->h_pos))
25884 + au_fclr_rdu(cookie->flags, CALLED);
25886 + err = vfsub_iterate_dir(h_file, &arg->ctx);
25890 + && au_ftest_rdu(cookie->flags, CALLED)
25891 + && !au_ftest_rdu(cookie->flags, FULL));
25892 + cookie->h_pos = h_file->f_pos;
25899 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
25902 + aufs_bindex_t bbot;
25903 + struct au_rdu_arg arg = {
25905 + .actor = au_rdu_fill
25908 + struct dentry *dentry;
25909 + struct inode *inode;
25910 + struct file *h_file;
25911 + struct au_rdu_cookie *cookie = &rdu->cookie;
25913 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
25914 + if (unlikely(err)) {
25920 + rdu->tail = rdu->ent;
25923 + arg.ent = rdu->ent;
25924 + arg.end = arg.ent.ul;
25925 + arg.end += rdu->sz;
25928 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
25931 + err = security_file_permission(file, MAY_READ);
25933 + if (unlikely(err))
25936 + dentry = file->f_path.dentry;
25937 + inode = d_inode(dentry);
25938 + inode_lock_shared(inode);
25940 + arg.sb = inode->i_sb;
25941 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
25942 + if (unlikely(err))
25944 + err = au_alive_dir(dentry);
25945 + if (unlikely(err))
25947 + /* todo: reval? */
25948 + fi_read_lock(file);
25951 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
25952 + && cookie->generation != au_figen(file)))
25957 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
25959 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
25961 + bbot = au_fbtop(file);
25962 + if (cookie->bindex < bbot)
25963 + cookie->bindex = bbot;
25964 + bbot = au_fbbot_dir(file);
25965 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
25966 + for (; !err && cookie->bindex <= bbot;
25967 + cookie->bindex++, cookie->h_pos = 0) {
25968 + h_file = au_hf_dir(file, cookie->bindex);
25972 + au_fclr_rdu(cookie->flags, FULL);
25973 + err = au_rdu_do(h_file, &arg);
25975 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
25978 + AuDbg("rent %llu\n", rdu->rent);
25980 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
25981 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
25982 + au_fset_rdu(cookie->flags, CONT);
25983 + cookie->generation = au_figen(file);
25986 + ii_read_lock_child(inode);
25987 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
25988 + ii_read_unlock(inode);
25991 + fi_read_unlock(file);
25993 + si_read_unlock(arg.sb);
25995 + inode_unlock_shared(inode);
26001 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
26005 + unsigned long long nent;
26006 + union au_rdu_ent_ul *u;
26007 + struct au_rdu_ent ent;
26008 + struct super_block *sb;
26011 + nent = rdu->nent;
26013 + sb = file->f_path.dentry->d_sb;
26014 + si_read_lock(sb, AuLock_FLUSH);
26015 + while (nent-- > 0) {
26016 + /* unnecessary to support mmap_sem since this is a dir */
26017 + err = copy_from_user(&ent, u->e, sizeof(ent));
26019 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
26020 + if (unlikely(err)) {
26026 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
26028 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
26030 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
26032 + if (unlikely(err)) {
26037 + err = __put_user(ino, &u->e->ino);
26038 + if (unlikely(err)) {
26043 + u->ul += au_rdu_len(ent.nlen);
26045 + si_read_unlock(sb);
26050 +/* ---------------------------------------------------------------------- */
26052 +static int au_rdu_verify(struct aufs_rdu *rdu)
26054 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
26055 + "%llu, b%d, 0x%x, g%u}\n",
26056 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
26058 + rdu->rent, rdu->shwh, rdu->full,
26059 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
26060 + rdu->cookie.generation);
26062 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
26066 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
26070 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26073 + struct aufs_rdu rdu;
26074 + void __user *p = (void __user *)arg;
26076 + err = copy_from_user(&rdu, p, sizeof(rdu));
26077 + if (unlikely(err)) {
26082 + err = au_rdu_verify(&rdu);
26083 + if (unlikely(err))
26087 + case AUFS_CTL_RDU:
26088 + err = au_rdu(file, &rdu);
26089 + if (unlikely(err))
26092 + e = copy_to_user(p, &rdu, sizeof(rdu));
26093 + if (unlikely(e)) {
26098 + case AUFS_CTL_RDU_INO:
26099 + err = au_rdu_ino(file, &rdu);
26103 + /* err = -ENOTTY; */
26112 +#ifdef CONFIG_COMPAT
26113 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26116 + struct aufs_rdu rdu;
26117 + void __user *p = compat_ptr(arg);
26119 + /* todo: get_user()? */
26120 + err = copy_from_user(&rdu, p, sizeof(rdu));
26121 + if (unlikely(err)) {
26126 + rdu.ent.e = compat_ptr(rdu.ent.ul);
26127 + err = au_rdu_verify(&rdu);
26128 + if (unlikely(err))
26132 + case AUFS_CTL_RDU:
26133 + err = au_rdu(file, &rdu);
26134 + if (unlikely(err))
26137 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
26138 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
26139 + e = copy_to_user(p, &rdu, sizeof(rdu));
26140 + if (unlikely(e)) {
26145 + case AUFS_CTL_RDU_INO:
26146 + err = au_rdu_ino(file, &rdu);
26150 + /* err = -ENOTTY; */
26159 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
26160 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
26161 +++ linux/fs/aufs/rwsem.h 2016-07-25 19:05:34.817826663 +0200
26164 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26166 + * This program, aufs is free software; you can redistribute it and/or modify
26167 + * it under the terms of the GNU General Public License as published by
26168 + * the Free Software Foundation; either version 2 of the License, or
26169 + * (at your option) any later version.
26171 + * This program is distributed in the hope that it will be useful,
26172 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26173 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26174 + * GNU General Public License for more details.
26176 + * You should have received a copy of the GNU General Public License
26177 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26181 + * simple read-write semaphore wrappers
26184 +#ifndef __AUFS_RWSEM_H__
26185 +#define __AUFS_RWSEM_H__
26189 +#include "debug.h"
26192 + struct rw_semaphore rwsem;
26193 +#ifdef CONFIG_AUFS_DEBUG
26194 + /* just for debugging, not almighty counter */
26195 + atomic_t rcnt, wcnt;
26199 +#ifdef CONFIG_LOCKDEP
26200 +#define au_lockdep_set_name(rw) \
26201 + lockdep_set_class_and_name(&(rw)->rwsem, \
26202 + /*original key*/(rw)->rwsem.dep_map.key, \
26205 +#define au_lockdep_set_name(rw) do {} while (0)
26208 +#ifdef CONFIG_AUFS_DEBUG
26209 +#define AuDbgCntInit(rw) do { \
26210 + atomic_set(&(rw)->rcnt, 0); \
26211 + atomic_set(&(rw)->wcnt, 0); \
26212 + smp_mb(); /* atomic set */ \
26215 +#define AuDbgCnt(rw, cnt) atomic_read(&(rw)->cnt)
26216 +#define AuDbgCntInc(rw, cnt) atomic_inc(&(rw)->cnt)
26217 +#define AuDbgCntDec(rw, cnt) WARN_ON(atomic_dec_return(&(rw)->cnt) < 0)
26218 +#define AuDbgRcntInc(rw) AuDbgCntInc(rw, rcnt)
26219 +#define AuDbgRcntDec(rw) AuDbgCntDec(rw, rcnt)
26220 +#define AuDbgWcntInc(rw) AuDbgCntInc(rw, wcnt)
26221 +#define AuDbgWcntDec(rw) AuDbgCntDec(rw, wcnt)
26223 +#define AuDbgCnt(rw, cnt) 0
26224 +#define AuDbgCntInit(rw) do {} while (0)
26225 +#define AuDbgRcntInc(rw) do {} while (0)
26226 +#define AuDbgRcntDec(rw) do {} while (0)
26227 +#define AuDbgWcntInc(rw) do {} while (0)
26228 +#define AuDbgWcntDec(rw) do {} while (0)
26229 +#endif /* CONFIG_AUFS_DEBUG */
26231 +/* to debug easier, do not make them inlined functions */
26232 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(&(rw)->rwsem))
26233 +/* rwsem_is_locked() is unusable */
26234 +#define AuRwMustReadLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0)
26235 +#define AuRwMustWriteLock(rw) AuDebugOn(AuDbgCnt(rw, wcnt) <= 0)
26236 +#define AuRwMustAnyLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0 \
26237 + && AuDbgCnt(rw, wcnt) <= 0)
26238 +#define AuRwDestroy(rw) AuDebugOn(AuDbgCnt(rw, rcnt) \
26239 + || AuDbgCnt(rw, wcnt))
26241 +#define au_rw_init(rw) do { \
26242 + AuDbgCntInit(rw); \
26243 + init_rwsem(&(rw)->rwsem); \
26244 + au_lockdep_set_name(rw); \
26247 +#define au_rw_init_wlock(rw) do { \
26248 + au_rw_init(rw); \
26249 + down_write(&(rw)->rwsem); \
26250 + AuDbgWcntInc(rw); \
26253 +#define au_rw_init_wlock_nested(rw, lsc) do { \
26254 + au_rw_init(rw); \
26255 + down_write_nested(&(rw)->rwsem, lsc); \
26256 + AuDbgWcntInc(rw); \
26259 +static inline void au_rw_read_lock(struct au_rwsem *rw)
26261 + down_read(&rw->rwsem);
26262 + AuDbgRcntInc(rw);
26265 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26267 + down_read_nested(&rw->rwsem, lsc);
26268 + AuDbgRcntInc(rw);
26271 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26273 + AuRwMustReadLock(rw);
26274 + AuDbgRcntDec(rw);
26275 + up_read(&rw->rwsem);
26278 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26280 + AuRwMustWriteLock(rw);
26281 + AuDbgRcntInc(rw);
26282 + AuDbgWcntDec(rw);
26283 + downgrade_write(&rw->rwsem);
26286 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26288 + down_write(&rw->rwsem);
26289 + AuDbgWcntInc(rw);
26292 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26293 + unsigned int lsc)
26295 + down_write_nested(&rw->rwsem, lsc);
26296 + AuDbgWcntInc(rw);
26299 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26301 + AuRwMustWriteLock(rw);
26302 + AuDbgWcntDec(rw);
26303 + up_write(&rw->rwsem);
26306 +/* why is not _nested version defined */
26307 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26311 + ret = down_read_trylock(&rw->rwsem);
26313 + AuDbgRcntInc(rw);
26317 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26321 + ret = down_write_trylock(&rw->rwsem);
26323 + AuDbgWcntInc(rw);
26327 +#undef AuDbgCntDec
26328 +#undef AuDbgRcntInc
26329 +#undef AuDbgRcntDec
26330 +#undef AuDbgWcntDec
26332 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26333 +static inline void prefix##_read_lock(param) \
26334 +{ au_rw_read_lock(rwsem); } \
26335 +static inline void prefix##_write_lock(param) \
26336 +{ au_rw_write_lock(rwsem); } \
26337 +static inline int prefix##_read_trylock(param) \
26338 +{ return au_rw_read_trylock(rwsem); } \
26339 +static inline int prefix##_write_trylock(param) \
26340 +{ return au_rw_write_trylock(rwsem); }
26341 +/* why is not _nested version defined */
26342 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26343 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26344 +static inline void prefix##_write_trylock_nestd(param, lsc)
26345 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26347 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26348 +static inline void prefix##_read_unlock(param) \
26349 +{ au_rw_read_unlock(rwsem); } \
26350 +static inline void prefix##_write_unlock(param) \
26351 +{ au_rw_write_unlock(rwsem); } \
26352 +static inline void prefix##_downgrade_lock(param) \
26353 +{ au_rw_dgrade_lock(rwsem); }
26355 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26356 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26357 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26359 +#endif /* __KERNEL__ */
26360 +#endif /* __AUFS_RWSEM_H__ */
26361 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26362 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26363 +++ linux/fs/aufs/sbinfo.c 2016-07-25 19:05:34.817826663 +0200
26366 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26368 + * This program, aufs is free software; you can redistribute it and/or modify
26369 + * it under the terms of the GNU General Public License as published by
26370 + * the Free Software Foundation; either version 2 of the License, or
26371 + * (at your option) any later version.
26373 + * This program is distributed in the hope that it will be useful,
26374 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26375 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26376 + * GNU General Public License for more details.
26378 + * You should have received a copy of the GNU General Public License
26379 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26383 + * superblock private data
26389 + * they are necessary regardless sysfs is disabled.
26391 +void au_si_free(struct kobject *kobj)
26394 + struct au_sbinfo *sbinfo;
26395 + char *locked __maybe_unused; /* debug only */
26397 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26398 + for (i = 0; i < AuPlink_NHASH; i++)
26399 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26400 + au_nwt_fin(&sbinfo->si_nowait);
26402 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
26403 + percpu_counter_destroy(&sbinfo->si_ninodes);
26404 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
26405 + percpu_counter_destroy(&sbinfo->si_nfiles);
26407 + au_rw_write_lock(&sbinfo->si_rwsem);
26408 + au_br_free(sbinfo);
26409 + au_rw_write_unlock(&sbinfo->si_rwsem);
26411 + kfree(sbinfo->si_branch);
26412 + for (i = 0; i < AU_NPIDMAP; i++)
26413 + kfree(sbinfo->au_si_pid.pid_bitmap[i]);
26414 + mutex_destroy(&sbinfo->au_si_pid.pid_mtx);
26415 + mutex_destroy(&sbinfo->si_xib_mtx);
26416 + AuRwDestroy(&sbinfo->si_rwsem);
26421 +int au_si_alloc(struct super_block *sb)
26424 + struct au_sbinfo *sbinfo;
26427 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26428 + if (unlikely(!sbinfo))
26431 + /* will be reallocated separately */
26432 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26433 + if (unlikely(!sbinfo->si_branch))
26436 + err = sysaufs_si_init(sbinfo);
26437 + if (unlikely(err))
26440 + au_nwt_init(&sbinfo->si_nowait);
26441 + au_rw_init_wlock(&sbinfo->si_rwsem);
26442 + mutex_init(&sbinfo->au_si_pid.pid_mtx);
26444 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
26445 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
26447 + sbinfo->si_bbot = -1;
26448 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26450 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26451 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26452 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26453 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26455 + au_fhsm_init(sbinfo);
26457 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26459 + sbinfo->si_xino_jiffy = jiffies;
26460 + sbinfo->si_xino_expire
26461 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26462 + mutex_init(&sbinfo->si_xib_mtx);
26463 + sbinfo->si_xino_brid = -1;
26464 + /* leave si_xib_last_pindex and si_xib_next_bit */
26466 + au_sphl_init(&sbinfo->si_aopen);
26468 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26469 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26470 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26471 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26473 + for (i = 0; i < AuPlink_NHASH; i++)
26474 + au_sphl_init(sbinfo->si_plink + i);
26475 + init_waitqueue_head(&sbinfo->si_plink_wq);
26476 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26478 + au_sphl_init(&sbinfo->si_files);
26480 + /* with getattr by default */
26481 + sbinfo->si_iop_array = aufs_iop;
26483 + /* leave other members for sysaufs and si_mnt. */
26484 + sbinfo->si_sb = sb;
26485 + sb->s_fs_info = sbinfo;
26487 + return 0; /* success */
26490 + kfree(sbinfo->si_branch);
26497 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr)
26500 + struct au_branch **brp;
26502 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26505 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
26506 + if (unlikely(!sz))
26507 + sz = sizeof(*brp);
26508 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS);
26510 + sbinfo->si_branch = brp;
26517 +/* ---------------------------------------------------------------------- */
26519 +unsigned int au_sigen_inc(struct super_block *sb)
26521 + unsigned int gen;
26522 + struct inode *inode;
26524 + SiMustWriteLock(sb);
26526 + gen = ++au_sbi(sb)->si_generation;
26527 + au_update_digen(sb->s_root);
26528 + inode = d_inode(sb->s_root);
26529 + au_update_iigen(inode, /*half*/0);
26530 + inode->i_version++;
26534 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26536 + aufs_bindex_t br_id;
26538 + struct au_sbinfo *sbinfo;
26540 + SiMustWriteLock(sb);
26542 + sbinfo = au_sbi(sb);
26543 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26544 + br_id = ++sbinfo->si_last_br_id;
26545 + AuDebugOn(br_id < 0);
26546 + if (br_id && au_br_index(sb, br_id) < 0)
26553 +/* ---------------------------------------------------------------------- */
26555 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26556 +int si_read_lock(struct super_block *sb, int flags)
26561 + if (au_ftest_lock(flags, FLUSH))
26562 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26564 + si_noflush_read_lock(sb);
26565 + err = au_plink_maint(sb, flags);
26566 + if (unlikely(err))
26567 + si_read_unlock(sb);
26572 +int si_write_lock(struct super_block *sb, int flags)
26576 + if (au_ftest_lock(flags, FLUSH))
26577 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26579 + si_noflush_write_lock(sb);
26580 + err = au_plink_maint(sb, flags);
26581 + if (unlikely(err))
26582 + si_write_unlock(sb);
26587 +/* dentry and super_block lock. call at entry point */
26588 +int aufs_read_lock(struct dentry *dentry, int flags)
26591 + struct super_block *sb;
26593 + sb = dentry->d_sb;
26594 + err = si_read_lock(sb, flags);
26595 + if (unlikely(err))
26598 + if (au_ftest_lock(flags, DW))
26599 + di_write_lock_child(dentry);
26601 + di_read_lock_child(dentry, flags);
26603 + if (au_ftest_lock(flags, GEN)) {
26604 + err = au_digen_test(dentry, au_sigen(sb));
26605 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
26606 + AuDebugOn(!err && au_dbrange_test(dentry));
26608 + err = au_dbrange_test(dentry);
26609 + if (unlikely(err))
26610 + aufs_read_unlock(dentry, flags);
26617 +void aufs_read_unlock(struct dentry *dentry, int flags)
26619 + if (au_ftest_lock(flags, DW))
26620 + di_write_unlock(dentry);
26622 + di_read_unlock(dentry, flags);
26623 + si_read_unlock(dentry->d_sb);
26626 +void aufs_write_lock(struct dentry *dentry)
26628 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
26629 + di_write_lock_child(dentry);
26632 +void aufs_write_unlock(struct dentry *dentry)
26634 + di_write_unlock(dentry);
26635 + si_write_unlock(dentry->d_sb);
26638 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
26641 + unsigned int sigen;
26642 + struct super_block *sb;
26645 + err = si_read_lock(sb, flags);
26646 + if (unlikely(err))
26649 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
26651 + if (au_ftest_lock(flags, GEN)) {
26652 + sigen = au_sigen(sb);
26653 + err = au_digen_test(d1, sigen);
26654 + AuDebugOn(!err && au_dbrange_test(d1));
26656 + err = au_digen_test(d2, sigen);
26657 + AuDebugOn(!err && au_dbrange_test(d2));
26659 + if (unlikely(err))
26660 + aufs_read_and_write_unlock2(d1, d2);
26667 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
26669 + di_write_unlock2(d1, d2);
26670 + si_read_unlock(d1->d_sb);
26673 +/* ---------------------------------------------------------------------- */
26675 +static void si_pid_alloc(struct au_si_pid *au_si_pid, int idx)
26677 + unsigned long *p;
26679 + BUILD_BUG_ON(sizeof(unsigned long) !=
26680 + sizeof(*au_si_pid->pid_bitmap));
26682 + mutex_lock(&au_si_pid->pid_mtx);
26683 + p = au_si_pid->pid_bitmap[idx];
26687 + * but keeping 'si_pid_set()' void is more important.
26689 + p = kcalloc(BITS_TO_LONGS(AU_PIDSTEP),
26690 + sizeof(*au_si_pid->pid_bitmap),
26696 + au_si_pid->pid_bitmap[idx] = p;
26697 + mutex_unlock(&au_si_pid->pid_mtx);
26700 +void si_pid_set(struct super_block *sb)
26704 + unsigned long *bitmap;
26705 + struct au_si_pid *au_si_pid;
26707 + si_pid_idx_bit(&idx, &bit);
26708 + au_si_pid = &au_sbi(sb)->au_si_pid;
26709 + bitmap = au_si_pid->pid_bitmap[idx];
26711 + si_pid_alloc(au_si_pid, idx);
26712 + bitmap = au_si_pid->pid_bitmap[idx];
26714 + AuDebugOn(test_bit(bit, bitmap));
26715 + set_bit(bit, bitmap);
26718 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
26719 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
26720 +++ linux/fs/aufs/spl.h 2016-07-25 19:05:34.817826663 +0200
26723 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26725 + * This program, aufs is free software; you can redistribute it and/or modify
26726 + * it under the terms of the GNU General Public License as published by
26727 + * the Free Software Foundation; either version 2 of the License, or
26728 + * (at your option) any later version.
26730 + * This program is distributed in the hope that it will be useful,
26731 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26732 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26733 + * GNU General Public License for more details.
26735 + * You should have received a copy of the GNU General Public License
26736 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26740 + * simple list protected by a spinlock
26743 +#ifndef __AUFS_SPL_H__
26744 +#define __AUFS_SPL_H__
26748 +struct au_splhead {
26750 + struct list_head head;
26753 +static inline void au_spl_init(struct au_splhead *spl)
26755 + spin_lock_init(&spl->spin);
26756 + INIT_LIST_HEAD(&spl->head);
26759 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
26761 + spin_lock(&spl->spin);
26762 + list_add(list, &spl->head);
26763 + spin_unlock(&spl->spin);
26766 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
26768 + spin_lock(&spl->spin);
26770 + spin_unlock(&spl->spin);
26773 +static inline void au_spl_del_rcu(struct list_head *list,
26774 + struct au_splhead *spl)
26776 + spin_lock(&spl->spin);
26777 + list_del_rcu(list);
26778 + spin_unlock(&spl->spin);
26781 +/* ---------------------------------------------------------------------- */
26783 +struct au_sphlhead {
26785 + struct hlist_head head;
26788 +static inline void au_sphl_init(struct au_sphlhead *sphl)
26790 + spin_lock_init(&sphl->spin);
26791 + INIT_HLIST_HEAD(&sphl->head);
26794 +static inline void au_sphl_add(struct hlist_node *hlist,
26795 + struct au_sphlhead *sphl)
26797 + spin_lock(&sphl->spin);
26798 + hlist_add_head(hlist, &sphl->head);
26799 + spin_unlock(&sphl->spin);
26802 +static inline void au_sphl_del(struct hlist_node *hlist,
26803 + struct au_sphlhead *sphl)
26805 + spin_lock(&sphl->spin);
26806 + hlist_del(hlist);
26807 + spin_unlock(&sphl->spin);
26810 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
26811 + struct au_sphlhead *sphl)
26813 + spin_lock(&sphl->spin);
26814 + hlist_del_rcu(hlist);
26815 + spin_unlock(&sphl->spin);
26818 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
26820 + unsigned long cnt;
26821 + struct hlist_node *pos;
26824 + spin_lock(&sphl->spin);
26825 + hlist_for_each(pos, &sphl->head)
26827 + spin_unlock(&sphl->spin);
26831 +#endif /* __KERNEL__ */
26832 +#endif /* __AUFS_SPL_H__ */
26833 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
26834 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
26835 +++ linux/fs/aufs/super.c 2016-07-25 19:05:34.817826663 +0200
26838 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26840 + * This program, aufs is free software; you can redistribute it and/or modify
26841 + * it under the terms of the GNU General Public License as published by
26842 + * the Free Software Foundation; either version 2 of the License, or
26843 + * (at your option) any later version.
26845 + * This program is distributed in the hope that it will be useful,
26846 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26847 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26848 + * GNU General Public License for more details.
26850 + * You should have received a copy of the GNU General Public License
26851 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26855 + * mount and super_block operations
26858 +#include <linux/mm.h>
26859 +#include <linux/seq_file.h>
26860 +#include <linux/statfs.h>
26861 +#include <linux/vmalloc.h>
26865 + * super_operations
26867 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
26869 + struct au_icntnr *c;
26871 + c = au_cache_alloc_icntnr();
26873 + au_icntnr_init(c);
26874 + c->vfs_inode.i_version = 1; /* sigen(sb); */
26875 + c->iinfo.ii_hinode = NULL;
26876 + return &c->vfs_inode;
26881 +static void aufs_destroy_inode_cb(struct rcu_head *head)
26883 + struct inode *inode = container_of(head, struct inode, i_rcu);
26885 + INIT_HLIST_HEAD(&inode->i_dentry);
26886 + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
26889 +static void aufs_destroy_inode(struct inode *inode)
26891 + if (!au_is_bad_inode(inode))
26892 + au_iinfo_fin(inode);
26893 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
26896 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
26898 + struct inode *inode;
26901 + inode = iget_locked(sb, ino);
26902 + if (unlikely(!inode)) {
26903 + inode = ERR_PTR(-ENOMEM);
26906 + if (!(inode->i_state & I_NEW))
26909 + err = au_xigen_new(inode);
26911 + err = au_iinfo_init(inode);
26913 + inode->i_version++;
26915 + iget_failed(inode);
26916 + inode = ERR_PTR(err);
26920 + /* never return NULL */
26921 + AuDebugOn(!inode);
26922 + AuTraceErrPtr(inode);
26926 +/* lock free root dinfo */
26927 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
26930 + aufs_bindex_t bindex, bbot;
26931 + struct path path;
26932 + struct au_hdentry *hdp;
26933 + struct au_branch *br;
26934 + au_br_perm_str_t perm;
26937 + bbot = au_sbbot(sb);
26939 + hdp = au_hdentry(au_di(sb->s_root), bindex);
26940 + for (; !err && bindex <= bbot; bindex++, hdp++) {
26941 + br = au_sbr(sb, bindex);
26942 + path.mnt = au_br_mnt(br);
26943 + path.dentry = hdp->hd_dentry;
26944 + err = au_seq_path(seq, &path);
26946 + au_optstr_br_perm(&perm, br->br_perm);
26947 + seq_printf(seq, "=%s", perm.a);
26948 + if (bindex != bbot)
26949 + seq_putc(seq, ':');
26952 + if (unlikely(err || seq_has_overflowed(seq)))
26958 +static void au_show_wbr_create(struct seq_file *m, int v,
26959 + struct au_sbinfo *sbinfo)
26963 + AuRwMustAnyLock(&sbinfo->si_rwsem);
26965 + seq_puts(m, ",create=");
26966 + pat = au_optstr_wbr_create(v);
26968 + case AuWbrCreate_TDP:
26969 + case AuWbrCreate_RR:
26970 + case AuWbrCreate_MFS:
26971 + case AuWbrCreate_PMFS:
26972 + seq_puts(m, pat);
26974 + case AuWbrCreate_MFSV:
26975 + seq_printf(m, /*pat*/"mfs:%lu",
26976 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26979 + case AuWbrCreate_PMFSV:
26980 + seq_printf(m, /*pat*/"pmfs:%lu",
26981 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26984 + case AuWbrCreate_MFSRR:
26985 + seq_printf(m, /*pat*/"mfsrr:%llu",
26986 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26988 + case AuWbrCreate_MFSRRV:
26989 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
26990 + sbinfo->si_wbr_mfs.mfsrr_watermark,
26991 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
26994 + case AuWbrCreate_PMFSRR:
26995 + seq_printf(m, /*pat*/"pmfsrr:%llu",
26996 + sbinfo->si_wbr_mfs.mfsrr_watermark);
26998 + case AuWbrCreate_PMFSRRV:
26999 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
27000 + sbinfo->si_wbr_mfs.mfsrr_watermark,
27001 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
27007 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
27009 +#ifdef CONFIG_SYSFS
27013 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
27014 + aufs_bindex_t bindex, brid;
27015 + struct qstr *name;
27017 + struct dentry *d, *h_root;
27019 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27022 + f = au_sbi(sb)->si_xib;
27026 + /* stop printing the default xino path on the first writable branch */
27028 + brid = au_xino_brid(sb);
27030 + bindex = au_br_index(sb, brid);
27031 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
27033 + d = f->f_path.dentry;
27034 + name = &d->d_name;
27035 + /* safe ->d_parent because the file is unlinked */
27036 + if (d->d_parent == h_root
27037 + && name->len == len
27038 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
27041 + seq_puts(seq, ",xino=");
27042 + err = au_xino_path(seq, f);
27049 +/* seq_file will re-call me in case of too long string */
27050 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
27053 + unsigned int mnt_flags, v;
27054 + struct super_block *sb;
27055 + struct au_sbinfo *sbinfo;
27057 +#define AuBool(name, str) do { \
27058 + v = au_opt_test(mnt_flags, name); \
27059 + if (v != au_opt_test(AuOpt_Def, name)) \
27060 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
27063 +#define AuStr(name, str) do { \
27064 + v = mnt_flags & AuOptMask_##name; \
27065 + if (v != (AuOpt_Def & AuOptMask_##name)) \
27066 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
27069 +#define AuUInt(name, str, val) do { \
27070 + if (val != AUFS_##name##_DEF) \
27071 + seq_printf(m, "," #str "=%u", val); \
27074 + sb = dentry->d_sb;
27075 + if (sb->s_flags & MS_POSIXACL)
27076 + seq_puts(m, ",acl");
27078 + /* lock free root dinfo */
27079 + si_noflush_read_lock(sb);
27080 + sbinfo = au_sbi(sb);
27081 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
27083 + mnt_flags = au_mntflags(sb);
27084 + if (au_opt_test(mnt_flags, XINO)) {
27085 + err = au_show_xino(m, sb);
27086 + if (unlikely(err))
27089 + seq_puts(m, ",noxino");
27091 + AuBool(TRUNC_XINO, trunc_xino);
27092 + AuStr(UDBA, udba);
27093 + AuBool(SHWH, shwh);
27094 + AuBool(PLINK, plink);
27095 + AuBool(DIO, dio);
27096 + AuBool(DIRPERM1, dirperm1);
27098 + v = sbinfo->si_wbr_create;
27099 + if (v != AuWbrCreate_Def)
27100 + au_show_wbr_create(m, v, sbinfo);
27102 + v = sbinfo->si_wbr_copyup;
27103 + if (v != AuWbrCopyup_Def)
27104 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
27106 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
27107 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
27108 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
27110 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
27112 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
27113 + AuUInt(RDCACHE, rdcache, v);
27115 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
27116 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
27118 + au_fhsm_show(m, sbinfo);
27120 + AuBool(SUM, sum);
27121 + /* AuBool(SUM_W, wsum); */
27122 + AuBool(WARN_PERM, warn_perm);
27123 + AuBool(VERBOSE, verbose);
27126 + /* be sure to print "br:" last */
27127 + if (!sysaufs_brs) {
27128 + seq_puts(m, ",br:");
27129 + au_show_brs(m, sb);
27131 + si_read_unlock(sb);
27139 +/* ---------------------------------------------------------------------- */
27141 +/* sum mode which returns the summation for statfs(2) */
27143 +static u64 au_add_till_max(u64 a, u64 b)
27151 + return ULLONG_MAX;
27154 +static u64 au_mul_till_max(u64 a, long mul)
27162 + return ULLONG_MAX;
27165 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
27168 + long bsize, factor;
27169 + u64 blocks, bfree, bavail, files, ffree;
27170 + aufs_bindex_t bbot, bindex, i;
27171 + unsigned char shared;
27172 + struct path h_path;
27173 + struct super_block *h_sb;
27176 + bsize = LONG_MAX;
27182 + bbot = au_sbbot(sb);
27183 + for (bindex = 0; bindex <= bbot; bindex++) {
27184 + h_path.mnt = au_sbr_mnt(sb, bindex);
27185 + h_sb = h_path.mnt->mnt_sb;
27187 + for (i = 0; !shared && i < bindex; i++)
27188 + shared = (au_sbr_sb(sb, i) == h_sb);
27192 + /* sb->s_root for NFS is unreliable */
27193 + h_path.dentry = h_path.mnt->mnt_root;
27194 + err = vfs_statfs(&h_path, buf);
27195 + if (unlikely(err))
27198 + if (bsize > buf->f_bsize) {
27200 + * we will reduce bsize, so we have to expand blocks
27201 + * etc. to match them again
27203 + factor = (bsize / buf->f_bsize);
27204 + blocks = au_mul_till_max(blocks, factor);
27205 + bfree = au_mul_till_max(bfree, factor);
27206 + bavail = au_mul_till_max(bavail, factor);
27207 + bsize = buf->f_bsize;
27210 + factor = (buf->f_bsize / bsize);
27211 + blocks = au_add_till_max(blocks,
27212 + au_mul_till_max(buf->f_blocks, factor));
27213 + bfree = au_add_till_max(bfree,
27214 + au_mul_till_max(buf->f_bfree, factor));
27215 + bavail = au_add_till_max(bavail,
27216 + au_mul_till_max(buf->f_bavail, factor));
27217 + files = au_add_till_max(files, buf->f_files);
27218 + ffree = au_add_till_max(ffree, buf->f_ffree);
27221 + buf->f_bsize = bsize;
27222 + buf->f_blocks = blocks;
27223 + buf->f_bfree = bfree;
27224 + buf->f_bavail = bavail;
27225 + buf->f_files = files;
27226 + buf->f_ffree = ffree;
27227 + buf->f_frsize = 0;
27233 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
27236 + struct path h_path;
27237 + struct super_block *sb;
27239 + /* lock free root dinfo */
27240 + sb = dentry->d_sb;
27241 + si_noflush_read_lock(sb);
27242 + if (!au_opt_test(au_mntflags(sb), SUM)) {
27243 + /* sb->s_root for NFS is unreliable */
27244 + h_path.mnt = au_sbr_mnt(sb, 0);
27245 + h_path.dentry = h_path.mnt->mnt_root;
27246 + err = vfs_statfs(&h_path, buf);
27248 + err = au_statfs_sum(sb, buf);
27249 + si_read_unlock(sb);
27252 + buf->f_type = AUFS_SUPER_MAGIC;
27253 + buf->f_namelen = AUFS_MAX_NAMELEN;
27254 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
27256 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27261 +/* ---------------------------------------------------------------------- */
27263 +static int aufs_sync_fs(struct super_block *sb, int wait)
27266 + aufs_bindex_t bbot, bindex;
27267 + struct au_branch *br;
27268 + struct super_block *h_sb;
27271 + si_noflush_read_lock(sb);
27272 + bbot = au_sbbot(sb);
27273 + for (bindex = 0; bindex <= bbot; bindex++) {
27274 + br = au_sbr(sb, bindex);
27275 + if (!au_br_writable(br->br_perm))
27278 + h_sb = au_sbr_sb(sb, bindex);
27279 + if (h_sb->s_op->sync_fs) {
27280 + e = h_sb->s_op->sync_fs(h_sb, wait);
27281 + if (unlikely(e && !err))
27283 + /* go on even if an error happens */
27286 + si_read_unlock(sb);
27291 +/* ---------------------------------------------------------------------- */
27293 +/* final actions when unmounting a file system */
27294 +static void aufs_put_super(struct super_block *sb)
27296 + struct au_sbinfo *sbinfo;
27298 + sbinfo = au_sbi(sb);
27302 + dbgaufs_si_fin(sbinfo);
27303 + kobject_put(&sbinfo->si_kobj);
27306 +/* ---------------------------------------------------------------------- */
27308 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
27309 + struct super_block *sb, void *arg)
27312 + unsigned long long n, sz;
27319 + if (*hint > ULLONG_MAX / sizeof(array)) {
27320 + array = ERR_PTR(-EMFILE);
27321 + pr_err("hint %llu\n", *hint);
27325 + sz = sizeof(array) * *hint;
27326 + array = kzalloc(sz, GFP_NOFS);
27327 + if (unlikely(!array))
27328 + array = vzalloc(sz);
27329 + if (unlikely(!array)) {
27330 + array = ERR_PTR(-ENOMEM);
27334 + n = cb(sb, array, *hint, arg);
27335 + AuDebugOn(n > *hint);
27342 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
27343 + unsigned long long max __maybe_unused,
27346 + unsigned long long n;
27347 + struct inode **p, *inode;
27348 + struct list_head *head;
27353 + spin_lock(&sb->s_inode_list_lock);
27354 + list_for_each_entry(inode, head, i_sb_list) {
27355 + if (!au_is_bad_inode(inode)
27356 + && au_ii(inode)->ii_btop >= 0) {
27357 + spin_lock(&inode->i_lock);
27358 + if (atomic_read(&inode->i_count)) {
27362 + AuDebugOn(n > max);
27364 + spin_unlock(&inode->i_lock);
27367 + spin_unlock(&sb->s_inode_list_lock);
27372 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27374 + *max = au_ninodes(sb);
27375 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
27378 +void au_iarray_free(struct inode **a, unsigned long long max)
27380 + unsigned long long ull;
27382 + for (ull = 0; ull < max; ull++)
27387 +/* ---------------------------------------------------------------------- */
27390 + * refresh dentry and inode at remount time.
27392 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27393 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27394 + struct dentry *parent)
27398 + di_write_lock_child(dentry);
27399 + di_read_lock_parent(parent, AuLock_IR);
27400 + err = au_refresh_dentry(dentry, parent);
27401 + if (!err && dir_flags)
27402 + au_hn_reset(d_inode(dentry), dir_flags);
27403 + di_read_unlock(parent, AuLock_IR);
27404 + di_write_unlock(dentry);
27409 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27410 + struct au_sbinfo *sbinfo,
27411 + const unsigned int dir_flags, unsigned int do_idop)
27414 + struct dentry *parent;
27417 + parent = dget_parent(dentry);
27418 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27419 + if (d_really_is_positive(dentry)) {
27420 + if (!d_is_dir(dentry))
27421 + err = au_do_refresh(dentry, /*dir_flags*/0,
27424 + err = au_do_refresh(dentry, dir_flags, parent);
27425 + if (unlikely(err))
27426 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27429 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27430 + AuDbgDentry(dentry);
27436 + au_refresh_dop(dentry, /*force_reval*/0);
27438 + au_refresh_dop(dentry, /*force_reval*/1);
27444 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
27446 + int err, i, j, ndentry, e;
27447 + unsigned int sigen;
27448 + struct au_dcsub_pages dpages;
27449 + struct au_dpage *dpage;
27450 + struct dentry **dentries, *d;
27451 + struct au_sbinfo *sbinfo;
27452 + struct dentry *root = sb->s_root;
27453 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
27456 + au_refresh_dop(root, /*force_reval*/0);
27458 + err = au_dpages_init(&dpages, GFP_NOFS);
27459 + if (unlikely(err))
27461 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27462 + if (unlikely(err))
27465 + sigen = au_sigen(sb);
27466 + sbinfo = au_sbi(sb);
27467 + for (i = 0; i < dpages.ndpage; i++) {
27468 + dpage = dpages.dpages + i;
27469 + dentries = dpage->dentries;
27470 + ndentry = dpage->ndentry;
27471 + for (j = 0; j < ndentry; j++) {
27473 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
27475 + if (unlikely(e && !err))
27477 + /* go on even err */
27482 + au_dpages_free(&dpages);
27487 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
27490 + unsigned int sigen;
27491 + unsigned long long max, ull;
27492 + struct inode *inode, **array;
27494 + array = au_iarray_alloc(sb, &max);
27495 + err = PTR_ERR(array);
27496 + if (IS_ERR(array))
27500 + sigen = au_sigen(sb);
27501 + for (ull = 0; ull < max; ull++) {
27502 + inode = array[ull];
27503 + if (unlikely(!inode))
27507 + ii_write_lock_child(inode);
27508 + if (au_iigen(inode, NULL) != sigen) {
27509 + e = au_refresh_hinode_self(inode);
27510 + if (unlikely(e)) {
27511 + au_refresh_iop(inode, /*force_getattr*/1);
27512 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27515 + /* go on even if err */
27518 + if (!e && do_idop)
27519 + au_refresh_iop(inode, /*force_getattr*/0);
27520 + ii_write_unlock(inode);
27523 + au_iarray_free(array, max);
27529 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
27532 + unsigned int udba;
27533 + aufs_bindex_t bindex, bbot;
27534 + struct dentry *root;
27535 + struct inode *inode;
27536 + struct au_branch *br;
27537 + struct au_sbinfo *sbi;
27539 + au_sigen_inc(sb);
27540 + sbi = au_sbi(sb);
27541 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
27543 + root = sb->s_root;
27544 + DiMustNoWaiters(root);
27545 + inode = d_inode(root);
27546 + IiMustNoWaiters(inode);
27548 + udba = au_opt_udba(sb);
27549 + bbot = au_sbbot(sb);
27550 + for (bindex = 0; bindex <= bbot; bindex++) {
27551 + br = au_sbr(sb, bindex);
27552 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27553 + if (unlikely(err))
27554 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27556 + /* go on even if err */
27558 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27561 + if (au_ftest_si(sbi, NO_DREVAL)) {
27562 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
27563 + sb->s_d_op = &aufs_dop_noreval;
27564 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
27565 + sbi->si_iop_array = aufs_iop_nogetattr;
27567 + AuDebugOn(sb->s_d_op == &aufs_dop);
27568 + sb->s_d_op = &aufs_dop;
27569 + AuDebugOn(sbi->si_iop_array == aufs_iop);
27570 + sbi->si_iop_array = aufs_iop;
27572 + pr_info("reset to %pf and %pf\n",
27573 + sb->s_d_op, sbi->si_iop_array);
27576 + di_write_unlock(root);
27577 + err = au_refresh_d(sb, do_idop);
27578 + e = au_refresh_i(sb, do_idop);
27579 + if (unlikely(e && !err))
27581 + /* aufs_write_lock() calls ..._child() */
27582 + di_write_lock_child(root);
27584 + au_cpup_attr_all(inode, /*force*/1);
27586 + if (unlikely(err))
27587 + AuIOErr("refresh failed, ignored, %d\n", err);
27590 +/* stop extra interpretation of errno in mount(8), and strange error messages */
27591 +static int cvt_err(int err)
27605 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
27608 + unsigned int mntflags;
27609 + struct au_opts opts = {
27612 + struct dentry *root;
27613 + struct inode *inode;
27614 + struct au_sbinfo *sbinfo;
27617 + root = sb->s_root;
27618 + if (!data || !*data) {
27619 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27621 + di_write_lock_child(root);
27622 + err = au_opts_verify(sb, *flags, /*pending*/0);
27623 + aufs_write_unlock(root);
27629 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27630 + if (unlikely(!opts.opt))
27632 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27633 + opts.flags = AuOpts_REMOUNT;
27634 + opts.sb_flags = *flags;
27636 + /* parse it before aufs lock */
27637 + err = au_opts_parse(sb, data, &opts);
27638 + if (unlikely(err))
27641 + sbinfo = au_sbi(sb);
27642 + inode = d_inode(root);
27643 + inode_lock(inode);
27644 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27645 + if (unlikely(err))
27647 + di_write_lock_child(root);
27649 + /* au_opts_remount() may return an error */
27650 + err = au_opts_remount(sb, &opts);
27651 + au_opts_free(&opts);
27653 + if (au_ftest_opts(opts.flags, REFRESH))
27654 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
27656 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
27657 + mntflags = au_mntflags(sb);
27658 + do_dx = !!au_opt_test(mntflags, DIO);
27659 + au_dy_arefresh(do_dx);
27662 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
27663 + aufs_write_unlock(root);
27666 + inode_unlock(inode);
27668 + free_page((unsigned long)opts.opt);
27670 + err = cvt_err(err);
27675 +static const struct super_operations aufs_sop = {
27676 + .alloc_inode = aufs_alloc_inode,
27677 + .destroy_inode = aufs_destroy_inode,
27678 + /* always deleting, no clearing */
27679 + .drop_inode = generic_delete_inode,
27680 + .show_options = aufs_show_options,
27681 + .statfs = aufs_statfs,
27682 + .put_super = aufs_put_super,
27683 + .sync_fs = aufs_sync_fs,
27684 + .remount_fs = aufs_remount_fs
27687 +/* ---------------------------------------------------------------------- */
27689 +static int alloc_root(struct super_block *sb)
27692 + struct inode *inode;
27693 + struct dentry *root;
27696 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
27697 + err = PTR_ERR(inode);
27698 + if (IS_ERR(inode))
27701 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
27702 + inode->i_fop = &aufs_dir_fop;
27703 + inode->i_mode = S_IFDIR;
27704 + set_nlink(inode, 2);
27705 + unlock_new_inode(inode);
27707 + root = d_make_root(inode);
27708 + if (unlikely(!root))
27710 + err = PTR_ERR(root);
27711 + if (IS_ERR(root))
27714 + err = au_di_init(root);
27716 + sb->s_root = root;
27717 + return 0; /* success */
27725 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
27726 + int silent __maybe_unused)
27729 + struct au_opts opts = {
27732 + struct au_sbinfo *sbinfo;
27733 + struct dentry *root;
27734 + struct inode *inode;
27735 + char *arg = raw_data;
27737 + if (unlikely(!arg || !*arg)) {
27739 + pr_err("no arg\n");
27744 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27745 + if (unlikely(!opts.opt))
27747 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27748 + opts.sb_flags = sb->s_flags;
27750 + err = au_si_alloc(sb);
27751 + if (unlikely(err))
27753 + sbinfo = au_sbi(sb);
27755 + /* all timestamps always follow the ones on the branch */
27756 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
27757 + sb->s_op = &aufs_sop;
27758 + sb->s_d_op = &aufs_dop;
27759 + sb->s_magic = AUFS_SUPER_MAGIC;
27760 + sb->s_maxbytes = 0;
27761 + sb->s_stack_depth = 1;
27762 + au_export_init(sb);
27763 + /* au_xattr_init(sb); */
27765 + err = alloc_root(sb);
27766 + if (unlikely(err)) {
27767 + si_write_unlock(sb);
27770 + root = sb->s_root;
27771 + inode = d_inode(root);
27774 + * actually we can parse options regardless aufs lock here.
27775 + * but at remount time, parsing must be done before aufs lock.
27776 + * so we follow the same rule.
27778 + ii_write_lock_parent(inode);
27779 + aufs_write_unlock(root);
27780 + err = au_opts_parse(sb, arg, &opts);
27781 + if (unlikely(err))
27784 + /* lock vfs_inode first, then aufs. */
27785 + inode_lock(inode);
27786 + aufs_write_lock(root);
27787 + err = au_opts_mount(sb, &opts);
27788 + au_opts_free(&opts);
27789 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
27790 + sb->s_d_op = &aufs_dop_noreval;
27791 + pr_info("%pf\n", sb->s_d_op);
27792 + au_refresh_dop(root, /*force_reval*/0);
27793 + sbinfo->si_iop_array = aufs_iop_nogetattr;
27794 + au_refresh_iop(inode, /*force_getattr*/0);
27796 + aufs_write_unlock(root);
27797 + inode_unlock(inode);
27799 + goto out_opts; /* success */
27803 + sb->s_root = NULL;
27805 + dbgaufs_si_fin(sbinfo);
27806 + kobject_put(&sbinfo->si_kobj);
27807 + sb->s_fs_info = NULL;
27809 + free_page((unsigned long)opts.opt);
27812 + err = cvt_err(err);
27817 +/* ---------------------------------------------------------------------- */
27819 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
27820 + const char *dev_name __maybe_unused,
27823 + struct dentry *root;
27824 + struct super_block *sb;
27826 + /* all timestamps always follow the ones on the branch */
27827 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
27828 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
27829 + if (IS_ERR(root))
27833 + si_write_lock(sb, !AuLock_FLUSH);
27834 + sysaufs_brs_add(sb, 0);
27835 + si_write_unlock(sb);
27836 + au_sbilist_add(sb);
27842 +static void aufs_kill_sb(struct super_block *sb)
27844 + struct au_sbinfo *sbinfo;
27846 + sbinfo = au_sbi(sb);
27848 + au_sbilist_del(sb);
27849 + aufs_write_lock(sb->s_root);
27851 + if (sbinfo->si_wbr_create_ops->fin)
27852 + sbinfo->si_wbr_create_ops->fin(sb);
27853 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
27854 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
27855 + au_remount_refresh(sb, /*do_idop*/0);
27857 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
27858 + au_plink_put(sb, /*verbose*/1);
27860 + sbinfo->si_sb = NULL;
27861 + aufs_write_unlock(sb->s_root);
27862 + au_nwt_flush(&sbinfo->si_nowait);
27864 + kill_anon_super(sb);
27867 +struct file_system_type aufs_fs_type = {
27868 + .name = AUFS_FSTYPE,
27869 + /* a race between rename and others */
27870 + .fs_flags = FS_RENAME_DOES_D_MOVE,
27871 + .mount = aufs_mount,
27872 + .kill_sb = aufs_kill_sb,
27873 + /* no need to __module_get() and module_put(). */
27874 + .owner = THIS_MODULE,
27876 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
27877 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
27878 +++ linux/fs/aufs/super.h 2016-07-25 19:05:34.817826663 +0200
27881 + * Copyright (C) 2005-2016 Junjiro R. Okajima
27883 + * This program, aufs is free software; you can redistribute it and/or modify
27884 + * it under the terms of the GNU General Public License as published by
27885 + * the Free Software Foundation; either version 2 of the License, or
27886 + * (at your option) any later version.
27888 + * This program is distributed in the hope that it will be useful,
27889 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27890 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27891 + * GNU General Public License for more details.
27893 + * You should have received a copy of the GNU General Public License
27894 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27898 + * super_block operations
27901 +#ifndef __AUFS_SUPER_H__
27902 +#define __AUFS_SUPER_H__
27906 +#include <linux/fs.h>
27907 +#include <linux/kobject.h>
27908 +#include "rwsem.h"
27912 +/* policies to select one among multiple writable branches */
27913 +struct au_wbr_copyup_operations {
27914 + int (*copyup)(struct dentry *dentry);
27917 +#define AuWbr_DIR 1 /* target is a dir */
27918 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
27920 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
27921 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
27922 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
27924 +struct au_wbr_create_operations {
27925 + int (*create)(struct dentry *dentry, unsigned int flags);
27926 + int (*init)(struct super_block *sb);
27927 + int (*fin)(struct super_block *sb);
27930 +struct au_wbr_mfs {
27931 + struct mutex mfs_lock; /* protect this structure */
27932 + unsigned long mfs_jiffy;
27933 + unsigned long mfs_expire;
27934 + aufs_bindex_t mfs_bindex;
27936 + unsigned long long mfsrr_bytes;
27937 + unsigned long long mfsrr_watermark;
27940 +#define AuPlink_NHASH 100
27941 +static inline int au_plink_hash(ino_t ino)
27943 + return ino % AuPlink_NHASH;
27946 +/* File-based Hierarchical Storage Management */
27948 +#ifdef CONFIG_AUFS_FHSM
27949 + /* allow only one process who can receive the notification */
27950 + spinlock_t fhsm_spin;
27952 + wait_queue_head_t fhsm_wqh;
27953 + atomic_t fhsm_readable;
27955 + /* these are protected by si_rwsem */
27956 + unsigned long fhsm_expire;
27957 + aufs_bindex_t fhsm_bottom;
27961 +#define AU_PIDSTEP (int)(BITS_TO_LONGS(PID_MAX_DEFAULT) * BITS_PER_LONG)
27962 +#define AU_NPIDMAP (int)DIV_ROUND_UP(PID_MAX_LIMIT, AU_PIDSTEP)
27963 +struct au_si_pid {
27964 + unsigned long *pid_bitmap[AU_NPIDMAP];
27965 + struct mutex pid_mtx;
27969 +struct au_sbinfo {
27970 + /* nowait tasks in the system-wide workqueue */
27971 + struct au_nowait_tasks si_nowait;
27974 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
27975 + * rwsem for au_sbinfo is necessary.
27977 + struct au_rwsem si_rwsem;
27979 + /* prevent recursive locking in deleting inode */
27980 + struct au_si_pid au_si_pid;
27983 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
27986 + struct percpu_counter si_ninodes, si_nfiles;
27988 + /* branch management */
27989 + unsigned int si_generation;
27991 + /* see AuSi_ flags */
27992 + unsigned char au_si_status;
27994 + aufs_bindex_t si_bbot;
27996 + /* dirty trick to keep br_id plus */
27997 + unsigned int si_last_br_id :
27998 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
27999 + struct au_branch **si_branch;
28001 + /* policy to select a writable branch */
28002 + unsigned char si_wbr_copyup;
28003 + unsigned char si_wbr_create;
28004 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
28005 + struct au_wbr_create_operations *si_wbr_create_ops;
28007 + /* round robin */
28008 + atomic_t si_wbr_rr_next;
28010 + /* most free space */
28011 + struct au_wbr_mfs si_wbr_mfs;
28013 + /* File-based Hierarchical Storage Management */
28014 + struct au_fhsm si_fhsm;
28016 + /* mount flags */
28017 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
28018 + unsigned int si_mntflags;
28020 + /* external inode number (bitmap and translation table) */
28021 + vfs_readf_t si_xread;
28022 + vfs_writef_t si_xwrite;
28023 + struct file *si_xib;
28024 + struct mutex si_xib_mtx; /* protect xib members */
28025 + unsigned long *si_xib_buf;
28026 + unsigned long si_xib_last_pindex;
28027 + int si_xib_next_bit;
28028 + aufs_bindex_t si_xino_brid;
28029 + unsigned long si_xino_jiffy;
28030 + unsigned long si_xino_expire;
28031 + /* reserved for future use */
28032 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
28034 +#ifdef CONFIG_AUFS_EXPORT
28035 + /* i_generation */
28036 + struct file *si_xigen;
28037 + atomic_t si_xigen_next;
28040 + /* dirty trick to suppoer atomic_open */
28041 + struct au_sphlhead si_aopen;
28043 + /* vdir parameters */
28044 + unsigned long si_rdcache; /* max cache time in jiffies */
28045 + unsigned int si_rdblk; /* deblk size */
28046 + unsigned int si_rdhash; /* hash size */
28049 + * If the number of whiteouts are larger than si_dirwh, leave all of
28050 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
28051 + * future fsck.aufs or kernel thread will remove them later.
28052 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
28054 + unsigned int si_dirwh;
28056 + /* pseudo_link list */
28057 + struct au_sphlhead si_plink[AuPlink_NHASH];
28058 + wait_queue_head_t si_plink_wq;
28059 + spinlock_t si_plink_maint_lock;
28060 + pid_t si_plink_maint_pid;
28063 + struct au_sphlhead si_files;
28065 + /* with/without getattr, brother of sb->s_d_op */
28066 + struct inode_operations *si_iop_array;
28069 + * sysfs and lifetime management.
28070 + * this is not a small structure and it may be a waste of memory in case
28071 + * of sysfs is disabled, particulary when many aufs-es are mounted.
28072 + * but using sysfs is majority.
28074 + struct kobject si_kobj;
28075 +#ifdef CONFIG_DEBUG_FS
28076 + struct dentry *si_dbgaufs;
28077 + struct dentry *si_dbgaufs_plink;
28078 + struct dentry *si_dbgaufs_xib;
28079 +#ifdef CONFIG_AUFS_EXPORT
28080 + struct dentry *si_dbgaufs_xigen;
28084 +#ifdef CONFIG_AUFS_SBILIST
28085 + struct hlist_node si_list;
28088 + /* dirty, necessary for unmounting, sysfs and sysrq */
28089 + struct super_block *si_sb;
28092 +/* sbinfo status flags */
28094 + * set true when refresh_dirs() failed at remount time.
28095 + * then try refreshing dirs at access time again.
28096 + * if it is false, refreshing dirs at access time is unnecesary
28098 +#define AuSi_FAILED_REFRESH_DIR 1
28099 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
28100 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
28102 +#ifndef CONFIG_AUFS_FHSM
28104 +#define AuSi_FHSM 0
28107 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
28108 + unsigned int flag)
28110 + AuRwMustAnyLock(&sbi->si_rwsem);
28111 + return sbi->au_si_status & flag;
28113 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
28114 +#define au_fset_si(sbinfo, name) do { \
28115 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28116 + (sbinfo)->au_si_status |= AuSi_##name; \
28118 +#define au_fclr_si(sbinfo, name) do { \
28119 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28120 + (sbinfo)->au_si_status &= ~AuSi_##name; \
28123 +/* ---------------------------------------------------------------------- */
28125 +/* policy to select one among writable branches */
28126 +#define AuWbrCopyup(sbinfo, ...) \
28127 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
28128 +#define AuWbrCreate(sbinfo, ...) \
28129 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
28131 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
28132 +#define AuLock_DW 1 /* write-lock dentry */
28133 +#define AuLock_IR (1 << 1) /* read-lock inode */
28134 +#define AuLock_IW (1 << 2) /* write-lock inode */
28135 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
28136 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
28137 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
28138 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
28139 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
28140 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
28141 +#define au_fset_lock(flags, name) \
28142 + do { (flags) |= AuLock_##name; } while (0)
28143 +#define au_fclr_lock(flags, name) \
28144 + do { (flags) &= ~AuLock_##name; } while (0)
28146 +/* ---------------------------------------------------------------------- */
28149 +extern struct file_system_type aufs_fs_type;
28150 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
28151 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
28152 + unsigned long long max, void *arg);
28153 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
28154 + struct super_block *sb, void *arg);
28155 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
28156 +void au_iarray_free(struct inode **a, unsigned long long max);
28159 +void au_si_free(struct kobject *kobj);
28160 +int au_si_alloc(struct super_block *sb);
28161 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr);
28163 +unsigned int au_sigen_inc(struct super_block *sb);
28164 +aufs_bindex_t au_new_br_id(struct super_block *sb);
28166 +int si_read_lock(struct super_block *sb, int flags);
28167 +int si_write_lock(struct super_block *sb, int flags);
28168 +int aufs_read_lock(struct dentry *dentry, int flags);
28169 +void aufs_read_unlock(struct dentry *dentry, int flags);
28170 +void aufs_write_lock(struct dentry *dentry);
28171 +void aufs_write_unlock(struct dentry *dentry);
28172 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
28173 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
28175 +/* wbr_policy.c */
28176 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
28177 +extern struct au_wbr_create_operations au_wbr_create_ops[];
28178 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
28179 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
28180 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
28183 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
28185 +#ifdef CONFIG_AUFS_FHSM
28188 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
28192 + spin_lock(&fhsm->fhsm_spin);
28193 + pid = fhsm->fhsm_pid;
28194 + spin_unlock(&fhsm->fhsm_spin);
28199 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
28200 +void au_fhsm_wrote_all(struct super_block *sb, int force);
28201 +int au_fhsm_fd(struct super_block *sb, int oflags);
28202 +int au_fhsm_br_alloc(struct au_branch *br);
28203 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
28204 +void au_fhsm_fin(struct super_block *sb);
28205 +void au_fhsm_init(struct au_sbinfo *sbinfo);
28206 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
28207 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
28209 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
28211 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
28212 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
28213 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
28214 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
28215 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
28216 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
28217 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
28218 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
28219 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
28222 +/* ---------------------------------------------------------------------- */
28224 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
28226 + return sb->s_fs_info;
28229 +/* ---------------------------------------------------------------------- */
28231 +#ifdef CONFIG_AUFS_EXPORT
28232 +int au_test_nfsd(void);
28233 +void au_export_init(struct super_block *sb);
28234 +void au_xigen_inc(struct inode *inode);
28235 +int au_xigen_new(struct inode *inode);
28236 +int au_xigen_set(struct super_block *sb, struct file *base);
28237 +void au_xigen_clr(struct super_block *sb);
28239 +static inline int au_busy_or_stale(void)
28241 + if (!au_test_nfsd())
28246 +AuStubInt0(au_test_nfsd, void)
28247 +AuStubVoid(au_export_init, struct super_block *sb)
28248 +AuStubVoid(au_xigen_inc, struct inode *inode)
28249 +AuStubInt0(au_xigen_new, struct inode *inode)
28250 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
28251 +AuStubVoid(au_xigen_clr, struct super_block *sb)
28252 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
28253 +#endif /* CONFIG_AUFS_EXPORT */
28255 +/* ---------------------------------------------------------------------- */
28257 +#ifdef CONFIG_AUFS_SBILIST
28259 +extern struct au_sphlhead au_sbilist;
28261 +static inline void au_sbilist_init(void)
28263 + au_sphl_init(&au_sbilist);
28266 +static inline void au_sbilist_add(struct super_block *sb)
28268 + au_sphl_add(&au_sbi(sb)->si_list, &au_sbilist);
28271 +static inline void au_sbilist_del(struct super_block *sb)
28273 + au_sphl_del(&au_sbi(sb)->si_list, &au_sbilist);
28276 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
28277 +static inline void au_sbilist_lock(void)
28279 + spin_lock(&au_sbilist.spin);
28282 +static inline void au_sbilist_unlock(void)
28284 + spin_unlock(&au_sbilist.spin);
28286 +#define AuGFP_SBILIST GFP_ATOMIC
28288 +AuStubVoid(au_sbilist_lock, void)
28289 +AuStubVoid(au_sbilist_unlock, void)
28290 +#define AuGFP_SBILIST GFP_NOFS
28291 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28293 +AuStubVoid(au_sbilist_init, void)
28294 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28295 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28296 +AuStubVoid(au_sbilist_lock, void)
28297 +AuStubVoid(au_sbilist_unlock, void)
28298 +#define AuGFP_SBILIST GFP_NOFS
28301 +/* ---------------------------------------------------------------------- */
28303 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28306 + * This function is a dynamic '__init' function actually,
28307 + * so the tiny check for si_rwsem is unnecessary.
28309 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28310 +#ifdef CONFIG_DEBUG_FS
28311 + sbinfo->si_dbgaufs = NULL;
28312 + sbinfo->si_dbgaufs_plink = NULL;
28313 + sbinfo->si_dbgaufs_xib = NULL;
28314 +#ifdef CONFIG_AUFS_EXPORT
28315 + sbinfo->si_dbgaufs_xigen = NULL;
28320 +/* ---------------------------------------------------------------------- */
28322 +static inline void si_pid_idx_bit(int *idx, pid_t *bit)
28324 + /* the origin of pid is 1, but the bitmap's is 0 */
28325 + *bit = current->pid - 1;
28326 + *idx = *bit / AU_PIDSTEP;
28327 + *bit %= AU_PIDSTEP;
28330 +static inline int si_pid_test(struct super_block *sb)
28334 + unsigned long *bitmap;
28336 + si_pid_idx_bit(&idx, &bit);
28337 + bitmap = au_sbi(sb)->au_si_pid.pid_bitmap[idx];
28339 + return test_bit(bit, bitmap);
28343 +static inline void si_pid_clr(struct super_block *sb)
28347 + unsigned long *bitmap;
28349 + si_pid_idx_bit(&idx, &bit);
28350 + bitmap = au_sbi(sb)->au_si_pid.pid_bitmap[idx];
28352 + AuDebugOn(!test_bit(bit, bitmap));
28353 + clear_bit(bit, bitmap);
28357 +void si_pid_set(struct super_block *sb);
28359 +/* ---------------------------------------------------------------------- */
28361 +/* lock superblock. mainly for entry point functions */
28363 + * __si_read_lock, __si_write_lock,
28364 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28366 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28368 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28369 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28370 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28372 +static inline void si_noflush_read_lock(struct super_block *sb)
28374 + __si_read_lock(sb);
28378 +static inline int si_noflush_read_trylock(struct super_block *sb)
28382 + locked = __si_read_trylock(sb);
28388 +static inline void si_noflush_write_lock(struct super_block *sb)
28390 + __si_write_lock(sb);
28394 +static inline int si_noflush_write_trylock(struct super_block *sb)
28398 + locked = __si_write_trylock(sb);
28404 +#if 0 /* reserved */
28405 +static inline int si_read_trylock(struct super_block *sb, int flags)
28407 + if (au_ftest_lock(flags, FLUSH))
28408 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28409 + return si_noflush_read_trylock(sb);
28413 +static inline void si_read_unlock(struct super_block *sb)
28416 + __si_read_unlock(sb);
28419 +#if 0 /* reserved */
28420 +static inline int si_write_trylock(struct super_block *sb, int flags)
28422 + if (au_ftest_lock(flags, FLUSH))
28423 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28424 + return si_noflush_write_trylock(sb);
28428 +static inline void si_write_unlock(struct super_block *sb)
28431 + __si_write_unlock(sb);
28434 +#if 0 /* reserved */
28435 +static inline void si_downgrade_lock(struct super_block *sb)
28437 + __si_downgrade_lock(sb);
28441 +/* ---------------------------------------------------------------------- */
28443 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
28445 + SiMustAnyLock(sb);
28446 + return au_sbi(sb)->si_bbot;
28449 +static inline unsigned int au_mntflags(struct super_block *sb)
28451 + SiMustAnyLock(sb);
28452 + return au_sbi(sb)->si_mntflags;
28455 +static inline unsigned int au_sigen(struct super_block *sb)
28457 + SiMustAnyLock(sb);
28458 + return au_sbi(sb)->si_generation;
28461 +static inline unsigned long long au_ninodes(struct super_block *sb)
28463 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
28469 +static inline void au_ninodes_inc(struct super_block *sb)
28471 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
28474 +static inline void au_ninodes_dec(struct super_block *sb)
28476 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
28479 +static inline unsigned long long au_nfiles(struct super_block *sb)
28481 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
28487 +static inline void au_nfiles_inc(struct super_block *sb)
28489 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
28492 +static inline void au_nfiles_dec(struct super_block *sb)
28494 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
28497 +static inline struct au_branch *au_sbr(struct super_block *sb,
28498 + aufs_bindex_t bindex)
28500 + SiMustAnyLock(sb);
28501 + return au_sbi(sb)->si_branch[0 + bindex];
28504 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28506 + SiMustWriteLock(sb);
28507 + au_sbi(sb)->si_xino_brid = brid;
28510 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28512 + SiMustAnyLock(sb);
28513 + return au_sbi(sb)->si_xino_brid;
28516 +#endif /* __KERNEL__ */
28517 +#endif /* __AUFS_SUPER_H__ */
28518 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28519 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28520 +++ linux/fs/aufs/sysaufs.c 2016-07-25 19:05:34.817826663 +0200
28523 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28525 + * This program, aufs is free software; you can redistribute it and/or modify
28526 + * it under the terms of the GNU General Public License as published by
28527 + * the Free Software Foundation; either version 2 of the License, or
28528 + * (at your option) any later version.
28530 + * This program is distributed in the hope that it will be useful,
28531 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28532 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28533 + * GNU General Public License for more details.
28535 + * You should have received a copy of the GNU General Public License
28536 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28540 + * sysfs interface and lifetime management
28541 + * they are necessary regardless sysfs is disabled.
28544 +#include <linux/random.h>
28547 +unsigned long sysaufs_si_mask;
28548 +struct kset *sysaufs_kset;
28550 +#define AuSiAttr(_name) { \
28551 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28552 + .show = sysaufs_si_##_name, \
28555 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28556 +struct attribute *sysaufs_si_attrs[] = {
28557 + &sysaufs_si_attr_xi_path.attr,
28561 +static const struct sysfs_ops au_sbi_ops = {
28562 + .show = sysaufs_si_show
28565 +static struct kobj_type au_sbi_ktype = {
28566 + .release = au_si_free,
28567 + .sysfs_ops = &au_sbi_ops,
28568 + .default_attrs = sysaufs_si_attrs
28571 +/* ---------------------------------------------------------------------- */
28573 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28577 + sbinfo->si_kobj.kset = sysaufs_kset;
28578 + /* cf. sysaufs_name() */
28579 + err = kobject_init_and_add
28580 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28581 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28583 + dbgaufs_si_null(sbinfo);
28585 + err = dbgaufs_si_init(sbinfo);
28586 + if (unlikely(err))
28587 + kobject_put(&sbinfo->si_kobj);
28592 +void sysaufs_fin(void)
28595 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28596 + kset_unregister(sysaufs_kset);
28599 +int __init sysaufs_init(void)
28604 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
28605 + } while (!sysaufs_si_mask);
28608 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
28609 + if (unlikely(!sysaufs_kset))
28611 + err = PTR_ERR(sysaufs_kset);
28612 + if (IS_ERR(sysaufs_kset))
28614 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28615 + if (unlikely(err)) {
28616 + kset_unregister(sysaufs_kset);
28620 + err = dbgaufs_init();
28621 + if (unlikely(err))
28626 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
28627 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
28628 +++ linux/fs/aufs/sysaufs.h 2016-07-25 19:05:34.817826663 +0200
28631 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28633 + * This program, aufs is free software; you can redistribute it and/or modify
28634 + * it under the terms of the GNU General Public License as published by
28635 + * the Free Software Foundation; either version 2 of the License, or
28636 + * (at your option) any later version.
28638 + * This program is distributed in the hope that it will be useful,
28639 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28640 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28641 + * GNU General Public License for more details.
28643 + * You should have received a copy of the GNU General Public License
28644 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28648 + * sysfs interface and mount lifetime management
28651 +#ifndef __SYSAUFS_H__
28652 +#define __SYSAUFS_H__
28656 +#include <linux/sysfs.h>
28657 +#include "module.h"
28659 +struct super_block;
28662 +struct sysaufs_si_attr {
28663 + struct attribute attr;
28664 + int (*show)(struct seq_file *seq, struct super_block *sb);
28667 +/* ---------------------------------------------------------------------- */
28670 +extern unsigned long sysaufs_si_mask;
28671 +extern struct kset *sysaufs_kset;
28672 +extern struct attribute *sysaufs_si_attrs[];
28673 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
28674 +int __init sysaufs_init(void);
28675 +void sysaufs_fin(void);
28677 +/* ---------------------------------------------------------------------- */
28679 +/* some people doesn't like to show a pointer in kernel */
28680 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
28682 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
28685 +#define SysaufsSiNamePrefix "si_"
28686 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
28687 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
28689 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
28690 + sysaufs_si_id(sbinfo));
28694 +#ifdef CONFIG_SYSFS
28696 +extern struct attribute_group *sysaufs_attr_group;
28698 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
28699 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28701 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
28702 +#ifdef CONFIG_COMPAT
28703 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
28706 +void sysaufs_br_init(struct au_branch *br);
28707 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
28708 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
28710 +#define sysaufs_brs_init() do {} while (0)
28713 +#define sysaufs_attr_group NULL
28715 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
28716 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
28717 + struct attribute *attr, char *buf)
28718 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
28719 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
28720 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
28722 +static inline void sysaufs_brs_init(void)
28727 +#endif /* CONFIG_SYSFS */
28729 +#endif /* __KERNEL__ */
28730 +#endif /* __SYSAUFS_H__ */
28731 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
28732 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
28733 +++ linux/fs/aufs/sysfs.c 2016-07-25 19:05:34.817826663 +0200
28736 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28738 + * This program, aufs is free software; you can redistribute it and/or modify
28739 + * it under the terms of the GNU General Public License as published by
28740 + * the Free Software Foundation; either version 2 of the License, or
28741 + * (at your option) any later version.
28743 + * This program is distributed in the hope that it will be useful,
28744 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28745 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28746 + * GNU General Public License for more details.
28748 + * You should have received a copy of the GNU General Public License
28749 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28753 + * sysfs interface
28756 +#include <linux/compat.h>
28757 +#include <linux/seq_file.h>
28760 +#ifdef CONFIG_AUFS_FS_MODULE
28761 +/* this entry violates the "one line per file" policy of sysfs */
28762 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
28766 + static char *conf =
28767 +/* this file is generated at compiling */
28768 +#include "conf.str"
28771 + err = snprintf(buf, PAGE_SIZE, conf);
28772 + if (unlikely(err >= PAGE_SIZE))
28777 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
28780 +static struct attribute *au_attr[] = {
28781 +#ifdef CONFIG_AUFS_FS_MODULE
28782 + &au_config_attr.attr,
28784 + NULL, /* need to NULL terminate the list of attributes */
28787 +static struct attribute_group sysaufs_attr_group_body = {
28791 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
28793 +/* ---------------------------------------------------------------------- */
28795 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
28799 + SiMustAnyLock(sb);
28802 + if (au_opt_test(au_mntflags(sb), XINO)) {
28803 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
28804 + seq_putc(seq, '\n');
28810 + * the lifetime of branch is independent from the entry under sysfs.
28811 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
28814 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
28815 + aufs_bindex_t bindex, int idx)
28818 + struct path path;
28819 + struct dentry *root;
28820 + struct au_branch *br;
28821 + au_br_perm_str_t perm;
28823 + AuDbg("b%d\n", bindex);
28826 + root = sb->s_root;
28827 + di_read_lock_parent(root, !AuLock_IR);
28828 + br = au_sbr(sb, bindex);
28831 + case AuBrSysfs_BR:
28832 + path.mnt = au_br_mnt(br);
28833 + path.dentry = au_h_dptr(root, bindex);
28834 + err = au_seq_path(seq, &path);
28836 + au_optstr_br_perm(&perm, br->br_perm);
28837 + seq_printf(seq, "=%s\n", perm.a);
28840 + case AuBrSysfs_BRID:
28841 + seq_printf(seq, "%d\n", br->br_id);
28844 + di_read_unlock(root, !AuLock_IR);
28845 + if (unlikely(err || seq_has_overflowed(seq)))
28851 +/* ---------------------------------------------------------------------- */
28853 +static struct seq_file *au_seq(char *p, ssize_t len)
28855 + struct seq_file *seq;
28857 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
28859 + /* mutex_init(&seq.lock); */
28862 + return seq; /* success */
28865 + seq = ERR_PTR(-ENOMEM);
28869 +#define SysaufsBr_PREFIX "br"
28870 +#define SysaufsBrid_PREFIX "brid"
28872 +/* todo: file size may exceed PAGE_SIZE */
28873 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
28879 + aufs_bindex_t bbot;
28880 + struct au_sbinfo *sbinfo;
28881 + struct super_block *sb;
28882 + struct seq_file *seq;
28884 + struct attribute **cattr;
28886 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
28887 + sb = sbinfo->si_sb;
28890 + * prevent a race condition between sysfs and aufs.
28891 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
28892 + * prohibits maintaining the sysfs entries.
28893 + * hew we acquire read lock after sysfs_get_active_two().
28894 + * on the other hand, the remount process may maintain the sysfs/aufs
28895 + * entries after acquiring write lock.
28896 + * it can cause a deadlock.
28897 + * simply we gave up processing read here.
28900 + if (unlikely(!si_noflush_read_trylock(sb)))
28903 + seq = au_seq(buf, PAGE_SIZE);
28904 + err = PTR_ERR(seq);
28908 + name = (void *)attr->name;
28909 + cattr = sysaufs_si_attrs;
28911 + if (!strcmp(name, (*cattr)->name)) {
28912 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
28919 + if (!strncmp(name, SysaufsBrid_PREFIX,
28920 + sizeof(SysaufsBrid_PREFIX) - 1)) {
28921 + idx = AuBrSysfs_BRID;
28922 + name += sizeof(SysaufsBrid_PREFIX) - 1;
28923 + } else if (!strncmp(name, SysaufsBr_PREFIX,
28924 + sizeof(SysaufsBr_PREFIX) - 1)) {
28925 + idx = AuBrSysfs_BR;
28926 + name += sizeof(SysaufsBr_PREFIX) - 1;
28930 + err = kstrtol(name, 10, &l);
28932 + bbot = au_sbbot(sb);
28934 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
28941 + err = seq->count;
28942 + /* sysfs limit */
28943 + if (unlikely(err == PAGE_SIZE))
28948 + si_read_unlock(sb);
28953 +/* ---------------------------------------------------------------------- */
28955 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
28959 + aufs_bindex_t bindex, bbot;
28962 + struct seq_file *seq;
28963 + struct au_branch *br;
28965 + si_read_lock(sb, AuLock_FLUSH);
28966 + bbot = au_sbbot(sb);
28972 + buf = (void *)__get_free_page(GFP_NOFS);
28973 + if (unlikely(!buf))
28976 + seq = au_seq(buf, PAGE_SIZE);
28977 + err = PTR_ERR(seq);
28981 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
28982 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
28983 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
28984 + if (unlikely(err))
28987 + br = au_sbr(sb, bindex);
28988 + brid = br->br_id;
28989 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
28990 + err = __put_user(brid, &arg->id);
28991 + if (unlikely(err))
28994 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
28995 + err = __put_user(br->br_perm, &arg->perm);
28996 + if (unlikely(err))
28999 + err = au_seq_path(seq, &br->br_path);
29000 + if (unlikely(err))
29002 + seq_putc(seq, '\0');
29003 + if (!seq_has_overflowed(seq)) {
29004 + err = copy_to_user(arg->path, seq->buf, seq->count);
29006 + if (unlikely(err))
29013 + if (unlikely(err))
29019 + free_page((unsigned long)buf);
29021 + si_read_unlock(sb);
29025 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
29027 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
29030 +#ifdef CONFIG_COMPAT
29031 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
29033 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
29037 +/* ---------------------------------------------------------------------- */
29039 +void sysaufs_br_init(struct au_branch *br)
29042 + struct au_brsysfs *br_sysfs;
29043 + struct attribute *attr;
29045 + br_sysfs = br->br_sysfs;
29046 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29047 + attr = &br_sysfs->attr;
29048 + sysfs_attr_init(attr);
29049 + attr->name = br_sysfs->name;
29050 + attr->mode = S_IRUGO;
29055 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
29057 + struct au_branch *br;
29058 + struct kobject *kobj;
29059 + struct au_brsysfs *br_sysfs;
29061 + aufs_bindex_t bbot;
29063 + dbgaufs_brs_del(sb, bindex);
29065 + if (!sysaufs_brs)
29068 + kobj = &au_sbi(sb)->si_kobj;
29069 + bbot = au_sbbot(sb);
29070 + for (; bindex <= bbot; bindex++) {
29071 + br = au_sbr(sb, bindex);
29072 + br_sysfs = br->br_sysfs;
29073 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29074 + sysfs_remove_file(kobj, &br_sysfs->attr);
29080 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
29083 + aufs_bindex_t bbot;
29084 + struct kobject *kobj;
29085 + struct au_branch *br;
29086 + struct au_brsysfs *br_sysfs;
29088 + dbgaufs_brs_add(sb, bindex);
29090 + if (!sysaufs_brs)
29093 + kobj = &au_sbi(sb)->si_kobj;
29094 + bbot = au_sbbot(sb);
29095 + for (; bindex <= bbot; bindex++) {
29096 + br = au_sbr(sb, bindex);
29097 + br_sysfs = br->br_sysfs;
29098 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
29099 + SysaufsBr_PREFIX "%d", bindex);
29100 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
29101 + SysaufsBrid_PREFIX "%d", bindex);
29102 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29103 + err = sysfs_create_file(kobj, &br_sysfs->attr);
29104 + if (unlikely(err))
29105 + pr_warn("failed %s under sysfs(%d)\n",
29106 + br_sysfs->name, err);
29111 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
29112 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
29113 +++ linux/fs/aufs/sysrq.c 2016-07-25 19:05:34.817826663 +0200
29116 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29118 + * This program, aufs is free software; you can redistribute it and/or modify
29119 + * it under the terms of the GNU General Public License as published by
29120 + * the Free Software Foundation; either version 2 of the License, or
29121 + * (at your option) any later version.
29123 + * This program is distributed in the hope that it will be useful,
29124 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29125 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29126 + * GNU General Public License for more details.
29128 + * You should have received a copy of the GNU General Public License
29129 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29133 + * magic sysrq hanlder
29136 +/* #include <linux/sysrq.h> */
29137 +#include <linux/writeback.h>
29140 +/* ---------------------------------------------------------------------- */
29142 +static void sysrq_sb(struct super_block *sb)
29145 + struct au_sbinfo *sbinfo;
29146 + struct file *file;
29147 + struct au_sphlhead *files;
29148 + struct au_finfo *finfo;
29150 + plevel = au_plevel;
29151 + au_plevel = KERN_WARNING;
29153 + /* since we define pr_fmt, call printk directly */
29154 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
29156 + sbinfo = au_sbi(sb);
29157 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
29158 + pr("superblock\n");
29162 + pr("root dentry\n");
29163 + au_dpri_dentry(sb->s_root);
29164 + pr("root inode\n");
29165 + au_dpri_inode(d_inode(sb->s_root));
29170 + int err, i, j, ndentry;
29171 + struct au_dcsub_pages dpages;
29172 + struct au_dpage *dpage;
29174 + err = au_dpages_init(&dpages, GFP_ATOMIC);
29175 + if (unlikely(err))
29177 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
29179 + for (i = 0; i < dpages.ndpage; i++) {
29180 + dpage = dpages.dpages + i;
29181 + ndentry = dpage->ndentry;
29182 + for (j = 0; j < ndentry; j++)
29183 + au_dpri_dentry(dpage->dentries[j]);
29185 + au_dpages_free(&dpages);
29193 + pr("isolated inode\n");
29194 + spin_lock(&sb->s_inode_list_lock);
29195 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
29196 + spin_lock(&i->i_lock);
29197 + if (1 || hlist_empty(&i->i_dentry))
29198 + au_dpri_inode(i);
29199 + spin_unlock(&i->i_lock);
29201 + spin_unlock(&sb->s_inode_list_lock);
29205 + files = &au_sbi(sb)->si_files;
29206 + spin_lock(&files->spin);
29207 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
29210 + file = finfo->fi_file;
29211 + mode = file_inode(file)->i_mode;
29212 + if (!special_file(mode))
29213 + au_dpri_file(file);
29215 + spin_unlock(&files->spin);
29219 + au_plevel = plevel;
29222 +/* ---------------------------------------------------------------------- */
29224 +/* module parameter */
29225 +static char *aufs_sysrq_key = "a";
29226 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
29227 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
29229 +static void au_sysrq(int key __maybe_unused)
29231 + struct au_sbinfo *sbinfo;
29234 + au_sbilist_lock();
29235 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
29236 + sysrq_sb(sbinfo->si_sb);
29237 + au_sbilist_unlock();
29241 +static struct sysrq_key_op au_sysrq_op = {
29242 + .handler = au_sysrq,
29243 + .help_msg = "Aufs",
29244 + .action_msg = "Aufs",
29245 + .enable_mask = SYSRQ_ENABLE_DUMP
29248 +/* ---------------------------------------------------------------------- */
29250 +int __init au_sysrq_init(void)
29256 + key = *aufs_sysrq_key;
29257 + if ('a' <= key && key <= 'z')
29258 + err = register_sysrq_key(key, &au_sysrq_op);
29259 + if (unlikely(err))
29260 + pr_err("err %d, sysrq=%c\n", err, key);
29264 +void au_sysrq_fin(void)
29268 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
29269 + if (unlikely(err))
29270 + pr_err("err %d (ignored)\n", err);
29272 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
29273 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
29274 +++ linux/fs/aufs/vdir.c 2016-07-25 19:05:34.817826663 +0200
29277 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29279 + * This program, aufs is free software; you can redistribute it and/or modify
29280 + * it under the terms of the GNU General Public License as published by
29281 + * the Free Software Foundation; either version 2 of the License, or
29282 + * (at your option) any later version.
29284 + * This program is distributed in the hope that it will be useful,
29285 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29286 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29287 + * GNU General Public License for more details.
29289 + * You should have received a copy of the GNU General Public License
29290 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29294 + * virtual or vertical directory
29299 +static unsigned int calc_size(int nlen)
29301 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29304 +static int set_deblk_end(union au_vdir_deblk_p *p,
29305 + union au_vdir_deblk_p *deblk_end)
29307 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29308 + p->de->de_str.len = 0;
29312 + return -1; /* error */
29315 +/* returns true or false */
29316 +static int is_deblk_end(union au_vdir_deblk_p *p,
29317 + union au_vdir_deblk_p *deblk_end)
29319 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29320 + return !p->de->de_str.len;
29324 +static unsigned char *last_deblk(struct au_vdir *vdir)
29326 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29329 +/* ---------------------------------------------------------------------- */
29331 +/* estimate the appropriate size for name hash table */
29332 +unsigned int au_rdhash_est(loff_t sz)
29340 + if (sz < AUFS_RDHASH_DEF)
29341 + n = AUFS_RDHASH_DEF;
29342 + /* pr_info("n %u\n", n); */
29347 + * the allocated memory has to be freed by
29348 + * au_nhash_wh_free() or au_nhash_de_free().
29350 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29352 + struct hlist_head *head;
29356 + sz = sizeof(*nhash->nh_head) * num_hash;
29357 + head = kmalloc(sz, gfp);
29359 + nhash->nh_num = num_hash;
29360 + nhash->nh_head = head;
29361 + for (u = 0; u < num_hash; u++)
29362 + INIT_HLIST_HEAD(head++);
29363 + return 0; /* success */
29369 +static void nhash_count(struct hlist_head *head)
29373 + struct hlist_node *pos;
29376 + hlist_for_each(pos, head)
29378 + pr_info("%lu\n", n);
29382 +static void au_nhash_wh_do_free(struct hlist_head *head)
29384 + struct au_vdir_wh *pos;
29385 + struct hlist_node *node;
29387 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29391 +static void au_nhash_de_do_free(struct hlist_head *head)
29393 + struct au_vdir_dehstr *pos;
29394 + struct hlist_node *node;
29396 + hlist_for_each_entry_safe(pos, node, head, hash)
29397 + au_cache_free_vdir_dehstr(pos);
29400 +static void au_nhash_do_free(struct au_nhash *nhash,
29401 + void (*free)(struct hlist_head *head))
29404 + struct hlist_head *head;
29406 + n = nhash->nh_num;
29410 + head = nhash->nh_head;
29411 + while (n-- > 0) {
29412 + nhash_count(head);
29415 + kfree(nhash->nh_head);
29418 +void au_nhash_wh_free(struct au_nhash *whlist)
29420 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29423 +static void au_nhash_de_free(struct au_nhash *delist)
29425 + au_nhash_do_free(delist, au_nhash_de_do_free);
29428 +/* ---------------------------------------------------------------------- */
29430 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29434 + unsigned int u, n;
29435 + struct hlist_head *head;
29436 + struct au_vdir_wh *pos;
29439 + n = whlist->nh_num;
29440 + head = whlist->nh_head;
29441 + for (u = 0; u < n; u++, head++)
29442 + hlist_for_each_entry(pos, head, wh_hash)
29443 + if (pos->wh_bindex == btgt && ++num > limit)
29448 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29449 + unsigned char *name,
29450 + unsigned int len)
29453 + /* const unsigned int magic_bit = 12; */
29455 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29460 + /* v = hash_long(v, magic_bit); */
29461 + v %= nhash->nh_num;
29462 + return nhash->nh_head + v;
29465 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29468 + return str->len == nlen && !memcmp(str->name, name, nlen);
29471 +/* returns found or not */
29472 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29474 + struct hlist_head *head;
29475 + struct au_vdir_wh *pos;
29476 + struct au_vdir_destr *str;
29478 + head = au_name_hash(whlist, name, nlen);
29479 + hlist_for_each_entry(pos, head, wh_hash) {
29480 + str = &pos->wh_str;
29481 + AuDbg("%.*s\n", str->len, str->name);
29482 + if (au_nhash_test_name(str, name, nlen))
29488 +/* returns found(true) or not */
29489 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29491 + struct hlist_head *head;
29492 + struct au_vdir_dehstr *pos;
29493 + struct au_vdir_destr *str;
29495 + head = au_name_hash(delist, name, nlen);
29496 + hlist_for_each_entry(pos, head, hash) {
29498 + AuDbg("%.*s\n", str->len, str->name);
29499 + if (au_nhash_test_name(str, name, nlen))
29505 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29506 + unsigned char d_type)
29508 +#ifdef CONFIG_AUFS_SHWH
29509 + wh->wh_ino = ino;
29510 + wh->wh_type = d_type;
29514 +/* ---------------------------------------------------------------------- */
29516 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29517 + unsigned int d_type, aufs_bindex_t bindex,
29518 + unsigned char shwh)
29521 + struct au_vdir_destr *str;
29522 + struct au_vdir_wh *wh;
29524 + AuDbg("%.*s\n", nlen, name);
29525 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29528 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29529 + if (unlikely(!wh))
29533 + wh->wh_bindex = bindex;
29535 + au_shwh_init_wh(wh, ino, d_type);
29536 + str = &wh->wh_str;
29538 + memcpy(str->name, name, nlen);
29539 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29546 +static int append_deblk(struct au_vdir *vdir)
29549 + unsigned long ul;
29550 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29551 + union au_vdir_deblk_p p, deblk_end;
29552 + unsigned char **o;
29555 + o = krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29557 + if (unlikely(!o))
29560 + vdir->vd_deblk = o;
29561 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29563 + ul = vdir->vd_nblk++;
29564 + vdir->vd_deblk[ul] = p.deblk;
29565 + vdir->vd_last.ul = ul;
29566 + vdir->vd_last.p.deblk = p.deblk;
29567 + deblk_end.deblk = p.deblk + deblk_sz;
29568 + err = set_deblk_end(&p, &deblk_end);
29575 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29576 + unsigned int d_type, struct au_nhash *delist)
29580 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29581 + union au_vdir_deblk_p p, *room, deblk_end;
29582 + struct au_vdir_dehstr *dehstr;
29584 + p.deblk = last_deblk(vdir);
29585 + deblk_end.deblk = p.deblk + deblk_sz;
29586 + room = &vdir->vd_last.p;
29587 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29588 + || !is_deblk_end(room, &deblk_end));
29590 + sz = calc_size(nlen);
29591 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29592 + err = append_deblk(vdir);
29593 + if (unlikely(err))
29596 + p.deblk = last_deblk(vdir);
29597 + deblk_end.deblk = p.deblk + deblk_sz;
29599 + AuDebugOn(room->deblk != p.deblk);
29603 + dehstr = au_cache_alloc_vdir_dehstr();
29604 + if (unlikely(!dehstr))
29607 + dehstr->str = &room->de->de_str;
29608 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
29609 + room->de->de_ino = ino;
29610 + room->de->de_type = d_type;
29611 + room->de->de_str.len = nlen;
29612 + memcpy(room->de->de_str.name, name, nlen);
29615 + room->deblk += sz;
29616 + if (unlikely(set_deblk_end(room, &deblk_end)))
29617 + err = append_deblk(vdir);
29624 +/* ---------------------------------------------------------------------- */
29626 +void au_vdir_free(struct au_vdir *vdir)
29628 + unsigned char **deblk;
29630 + deblk = vdir->vd_deblk;
29631 + while (vdir->vd_nblk--)
29633 + kfree(vdir->vd_deblk);
29634 + au_cache_free_vdir(vdir);
29637 +static struct au_vdir *alloc_vdir(struct file *file)
29639 + struct au_vdir *vdir;
29640 + struct super_block *sb;
29643 + sb = file->f_path.dentry->d_sb;
29644 + SiMustAnyLock(sb);
29647 + vdir = au_cache_alloc_vdir();
29648 + if (unlikely(!vdir))
29651 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
29652 + if (unlikely(!vdir->vd_deblk))
29655 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
29656 + if (!vdir->vd_deblk_sz) {
29657 + /* estimate the appropriate size for deblk */
29658 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
29659 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
29661 + vdir->vd_nblk = 0;
29662 + vdir->vd_version = 0;
29663 + vdir->vd_jiffy = 0;
29664 + err = append_deblk(vdir);
29666 + return vdir; /* success */
29668 + kfree(vdir->vd_deblk);
29671 + au_cache_free_vdir(vdir);
29673 + vdir = ERR_PTR(err);
29677 +static int reinit_vdir(struct au_vdir *vdir)
29680 + union au_vdir_deblk_p p, deblk_end;
29682 + while (vdir->vd_nblk > 1) {
29683 + kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
29684 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
29687 + p.deblk = vdir->vd_deblk[0];
29688 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
29689 + err = set_deblk_end(&p, &deblk_end);
29690 + /* keep vd_dblk_sz */
29691 + vdir->vd_last.ul = 0;
29692 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29693 + vdir->vd_version = 0;
29694 + vdir->vd_jiffy = 0;
29699 +/* ---------------------------------------------------------------------- */
29701 +#define AuFillVdir_CALLED 1
29702 +#define AuFillVdir_WHABLE (1 << 1)
29703 +#define AuFillVdir_SHWH (1 << 2)
29704 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
29705 +#define au_fset_fillvdir(flags, name) \
29706 + do { (flags) |= AuFillVdir_##name; } while (0)
29707 +#define au_fclr_fillvdir(flags, name) \
29708 + do { (flags) &= ~AuFillVdir_##name; } while (0)
29710 +#ifndef CONFIG_AUFS_SHWH
29711 +#undef AuFillVdir_SHWH
29712 +#define AuFillVdir_SHWH 0
29715 +struct fillvdir_arg {
29716 + struct dir_context ctx;
29717 + struct file *file;
29718 + struct au_vdir *vdir;
29719 + struct au_nhash delist;
29720 + struct au_nhash whlist;
29721 + aufs_bindex_t bindex;
29722 + unsigned int flags;
29726 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
29727 + loff_t offset __maybe_unused, u64 h_ino,
29728 + unsigned int d_type)
29730 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
29731 + char *name = (void *)__name;
29732 + struct super_block *sb;
29734 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
29737 + sb = arg->file->f_path.dentry->d_sb;
29738 + au_fset_fillvdir(arg->flags, CALLED);
29740 + if (nlen <= AUFS_WH_PFX_LEN
29741 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
29742 + if (test_known(&arg->delist, name, nlen)
29743 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
29744 + goto out; /* already exists or whiteouted */
29746 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
29748 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
29749 + d_type = DT_UNKNOWN;
29750 + arg->err = append_de(arg->vdir, name, nlen, ino,
29751 + d_type, &arg->delist);
29753 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
29754 + name += AUFS_WH_PFX_LEN;
29755 + nlen -= AUFS_WH_PFX_LEN;
29756 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
29757 + goto out; /* already whiteouted */
29760 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
29763 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
29764 + d_type = DT_UNKNOWN;
29765 + arg->err = au_nhash_append_wh
29766 + (&arg->whlist, name, nlen, ino, d_type,
29767 + arg->bindex, shwh);
29773 + arg->vdir->vd_jiffy = jiffies;
29775 + AuTraceErr(arg->err);
29779 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
29780 + struct au_nhash *whlist, struct au_nhash *delist)
29782 +#ifdef CONFIG_AUFS_SHWH
29784 + unsigned int nh, u;
29785 + struct hlist_head *head;
29786 + struct au_vdir_wh *pos;
29787 + struct hlist_node *n;
29789 + struct au_vdir_destr *destr;
29791 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
29794 + o = p = (void *)__get_free_page(GFP_NOFS);
29795 + if (unlikely(!p))
29799 + nh = whlist->nh_num;
29800 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
29801 + p += AUFS_WH_PFX_LEN;
29802 + for (u = 0; u < nh; u++) {
29803 + head = whlist->nh_head + u;
29804 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
29805 + destr = &pos->wh_str;
29806 + memcpy(p, destr->name, destr->len);
29807 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
29808 + pos->wh_ino, pos->wh_type, delist);
29809 + if (unlikely(err))
29814 + free_page((unsigned long)o);
29824 +static int au_do_read_vdir(struct fillvdir_arg *arg)
29827 + unsigned int rdhash;
29829 + aufs_bindex_t bbot, bindex, btop;
29830 + unsigned char shwh;
29831 + struct file *hf, *file;
29832 + struct super_block *sb;
29834 + file = arg->file;
29835 + sb = file->f_path.dentry->d_sb;
29836 + SiMustAnyLock(sb);
29838 + rdhash = au_sbi(sb)->si_rdhash;
29840 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
29841 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
29842 + if (unlikely(err))
29844 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
29845 + if (unlikely(err))
29851 + if (au_opt_test(au_mntflags(sb), SHWH)) {
29853 + au_fset_fillvdir(arg->flags, SHWH);
29855 + btop = au_fbtop(file);
29856 + bbot = au_fbbot_dir(file);
29857 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
29858 + hf = au_hf_dir(file, bindex);
29862 + offset = vfsub_llseek(hf, 0, SEEK_SET);
29864 + if (unlikely(offset))
29867 + arg->bindex = bindex;
29868 + au_fclr_fillvdir(arg->flags, WHABLE);
29870 + || (bindex != bbot
29871 + && au_br_whable(au_sbr_perm(sb, bindex))))
29872 + au_fset_fillvdir(arg->flags, WHABLE);
29875 + au_fclr_fillvdir(arg->flags, CALLED);
29877 + err = vfsub_iterate_dir(hf, &arg->ctx);
29880 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
29883 + * dir_relax() may be good for concurrency, but aufs should not
29884 + * use it since it will cause a lockdep problem.
29888 + if (!err && shwh)
29889 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
29891 + au_nhash_wh_free(&arg->whlist);
29894 + au_nhash_de_free(&arg->delist);
29899 +static int read_vdir(struct file *file, int may_read)
29902 + unsigned long expire;
29903 + unsigned char do_read;
29904 + struct fillvdir_arg arg = {
29906 + .actor = fillvdir
29909 + struct inode *inode;
29910 + struct au_vdir *vdir, *allocated;
29913 + inode = file_inode(file);
29914 + IMustLock(inode);
29915 + IiMustWriteLock(inode);
29916 + SiMustAnyLock(inode->i_sb);
29918 + allocated = NULL;
29920 + expire = au_sbi(inode->i_sb)->si_rdcache;
29921 + vdir = au_ivdir(inode);
29924 + vdir = alloc_vdir(file);
29925 + err = PTR_ERR(vdir);
29926 + if (IS_ERR(vdir))
29929 + allocated = vdir;
29930 + } else if (may_read
29931 + && (inode->i_version != vdir->vd_version
29932 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
29934 + err = reinit_vdir(vdir);
29935 + if (unlikely(err))
29940 + return 0; /* success */
29944 + err = au_do_read_vdir(&arg);
29946 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
29947 + vdir->vd_version = inode->i_version;
29948 + vdir->vd_last.ul = 0;
29949 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
29951 + au_set_ivdir(inode, allocated);
29952 + } else if (allocated)
29953 + au_vdir_free(allocated);
29959 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
29962 + unsigned long ul, n;
29963 + const unsigned int deblk_sz = src->vd_deblk_sz;
29965 + AuDebugOn(tgt->vd_nblk != 1);
29968 + if (tgt->vd_nblk < src->vd_nblk) {
29969 + unsigned char **p;
29971 + p = krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
29973 + if (unlikely(!p))
29975 + tgt->vd_deblk = p;
29978 + if (tgt->vd_deblk_sz != deblk_sz) {
29979 + unsigned char *p;
29981 + tgt->vd_deblk_sz = deblk_sz;
29982 + p = krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS);
29983 + if (unlikely(!p))
29985 + tgt->vd_deblk[0] = p;
29987 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
29988 + tgt->vd_version = src->vd_version;
29989 + tgt->vd_jiffy = src->vd_jiffy;
29991 + n = src->vd_nblk;
29992 + for (ul = 1; ul < n; ul++) {
29993 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
29995 + if (unlikely(!tgt->vd_deblk[ul]))
29999 + tgt->vd_nblk = n;
30000 + tgt->vd_last.ul = tgt->vd_last.ul;
30001 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
30002 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
30003 + - src->vd_deblk[src->vd_last.ul];
30005 + return 0; /* success */
30008 + rerr = reinit_vdir(tgt);
30013 +int au_vdir_init(struct file *file)
30016 + struct inode *inode;
30017 + struct au_vdir *vdir_cache, *allocated;
30019 + /* test file->f_pos here instead of ctx->pos */
30020 + err = read_vdir(file, !file->f_pos);
30021 + if (unlikely(err))
30024 + allocated = NULL;
30025 + vdir_cache = au_fvdir_cache(file);
30026 + if (!vdir_cache) {
30027 + vdir_cache = alloc_vdir(file);
30028 + err = PTR_ERR(vdir_cache);
30029 + if (IS_ERR(vdir_cache))
30031 + allocated = vdir_cache;
30032 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
30033 + /* test file->f_pos here instead of ctx->pos */
30034 + err = reinit_vdir(vdir_cache);
30035 + if (unlikely(err))
30038 + return 0; /* success */
30040 + inode = file_inode(file);
30041 + err = copy_vdir(vdir_cache, au_ivdir(inode));
30043 + file->f_version = inode->i_version;
30045 + au_set_fvdir_cache(file, allocated);
30046 + } else if (allocated)
30047 + au_vdir_free(allocated);
30053 +static loff_t calc_offset(struct au_vdir *vdir)
30056 + union au_vdir_deblk_p p;
30058 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
30059 + offset = vdir->vd_last.p.deblk - p.deblk;
30060 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
30064 +/* returns true or false */
30065 +static int seek_vdir(struct file *file, struct dir_context *ctx)
30068 + unsigned int deblk_sz;
30069 + unsigned long ul, n;
30071 + union au_vdir_deblk_p p, deblk_end;
30072 + struct au_vdir *vdir_cache;
30075 + vdir_cache = au_fvdir_cache(file);
30076 + offset = calc_offset(vdir_cache);
30077 + AuDbg("offset %lld\n", offset);
30078 + if (ctx->pos == offset)
30081 + vdir_cache->vd_last.ul = 0;
30082 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
30087 + deblk_sz = vdir_cache->vd_deblk_sz;
30088 + ul = div64_u64(ctx->pos, deblk_sz);
30089 + AuDbg("ul %lu\n", ul);
30090 + if (ul >= vdir_cache->vd_nblk)
30093 + n = vdir_cache->vd_nblk;
30094 + for (; ul < n; ul++) {
30095 + p.deblk = vdir_cache->vd_deblk[ul];
30096 + deblk_end.deblk = p.deblk + deblk_sz;
30098 + offset *= deblk_sz;
30099 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
30102 + l = calc_size(p.de->de_str.len);
30106 + if (!is_deblk_end(&p, &deblk_end)) {
30108 + vdir_cache->vd_last.ul = ul;
30109 + vdir_cache->vd_last.p = p;
30116 + AuTraceErr(!valid);
30120 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
30122 + unsigned int l, deblk_sz;
30123 + union au_vdir_deblk_p deblk_end;
30124 + struct au_vdir *vdir_cache;
30125 + struct au_vdir_de *de;
30127 + vdir_cache = au_fvdir_cache(file);
30128 + if (!seek_vdir(file, ctx))
30131 + deblk_sz = vdir_cache->vd_deblk_sz;
30133 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30134 + deblk_end.deblk += deblk_sz;
30135 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
30136 + de = vdir_cache->vd_last.p.de;
30137 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
30138 + de->de_str.len, de->de_str.name, ctx->pos,
30139 + (unsigned long)de->de_ino, de->de_type);
30140 + if (unlikely(!dir_emit(ctx, de->de_str.name,
30141 + de->de_str.len, de->de_ino,
30143 + /* todo: ignore the error caused by udba? */
30144 + /* return err; */
30148 + l = calc_size(de->de_str.len);
30149 + vdir_cache->vd_last.p.deblk += l;
30152 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
30153 + vdir_cache->vd_last.ul++;
30154 + vdir_cache->vd_last.p.deblk
30155 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30156 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
30165 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
30166 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
30167 +++ linux/fs/aufs/vfsub.c 2016-07-25 19:05:34.817826663 +0200
30170 + * Copyright (C) 2005-2016 Junjiro R. Okajima
30172 + * This program, aufs is free software; you can redistribute it and/or modify
30173 + * it under the terms of the GNU General Public License as published by
30174 + * the Free Software Foundation; either version 2 of the License, or
30175 + * (at your option) any later version.
30177 + * This program is distributed in the hope that it will be useful,
30178 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30179 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30180 + * GNU General Public License for more details.
30182 + * You should have received a copy of the GNU General Public License
30183 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30187 + * sub-routines for VFS
30190 +#include <linux/namei.h>
30191 +#include <linux/nsproxy.h>
30192 +#include <linux/security.h>
30193 +#include <linux/splice.h>
30194 +#include "../fs/mount.h"
30197 +#ifdef CONFIG_AUFS_BR_FUSE
30198 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
30200 + struct nsproxy *ns;
30202 + if (!au_test_fuse(h_sb) || !au_userns)
30205 + ns = current->nsproxy;
30206 + /* no {get,put}_nsproxy(ns) */
30207 + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES;
30211 +/* ---------------------------------------------------------------------- */
30213 +int vfsub_update_h_iattr(struct path *h_path, int *did)
30217 + struct super_block *h_sb;
30219 + /* for remote fs, leave work for its getattr or d_revalidate */
30220 + /* for bad i_attr fs, handle them in aufs_getattr() */
30221 + /* still some fs may acquire i_mutex. we need to skip them */
30225 + h_sb = h_path->dentry->d_sb;
30226 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
30228 + err = vfs_getattr(h_path, &st);
30233 +/* ---------------------------------------------------------------------- */
30235 +struct file *vfsub_dentry_open(struct path *path, int flags)
30237 + struct file *file;
30239 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
30241 + if (!IS_ERR_OR_NULL(file)
30242 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
30243 + i_readcount_inc(d_inode(path->dentry));
30248 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
30250 + struct file *file;
30253 + file = filp_open(path,
30254 + oflags /* | __FMODE_NONOTIFY */,
30257 + if (IS_ERR(file))
30259 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30266 + * Ideally this function should call VFS:do_last() in order to keep all its
30267 + * checkings. But it is very hard for aufs to regenerate several VFS internal
30268 + * structure such as nameidata. This is a second (or third) best approach.
30269 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
30271 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30272 + struct vfsub_aopen_args *args, struct au_branch *br)
30275 + struct file *file = args->file;
30276 + /* copied from linux/fs/namei.c:atomic_open() */
30277 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
30280 + AuDebugOn(!dir->i_op->atomic_open);
30282 + err = au_br_test_oflag(args->open_flag, br);
30283 + if (unlikely(err))
30286 + args->file->f_path.dentry = DENTRY_NOT_SET;
30287 + args->file->f_path.mnt = au_br_mnt(br);
30288 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
30289 + args->create_mode, args->opened);
30291 + /* some filesystems don't set FILE_CREATED while succeeded? */
30292 + if (*args->opened & FILE_CREATED)
30293 + fsnotify_create(dir, dentry);
30299 + /* todo: call VFS:may_open() here */
30300 + err = open_check_o_direct(file);
30301 + /* todo: ima_file_check() too? */
30302 + if (!err && (args->open_flag & __FMODE_EXEC))
30303 + err = deny_write_access(file);
30304 + if (unlikely(err))
30305 + /* note that the file is created and still opened */
30310 + fsnotify_open(file);
30316 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30320 + err = kern_path(name, flags, path);
30321 + if (!err && d_is_positive(path->dentry))
30322 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30326 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
30327 + struct dentry *parent, int len)
30329 + struct path path = {
30333 + path.dentry = lookup_one_len_unlocked(name, parent, len);
30334 + if (IS_ERR(path.dentry))
30336 + if (d_is_positive(path.dentry))
30337 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30340 + AuTraceErrPtr(path.dentry);
30341 + return path.dentry;
30344 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30347 + struct path path = {
30351 + /* VFS checks it too, but by WARN_ON_ONCE() */
30352 + IMustLock(d_inode(parent));
30354 + path.dentry = lookup_one_len(name, parent, len);
30355 + if (IS_ERR(path.dentry))
30357 + if (d_is_positive(path.dentry))
30358 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30361 + AuTraceErrPtr(path.dentry);
30362 + return path.dentry;
30365 +void vfsub_call_lkup_one(void *args)
30367 + struct vfsub_lkup_one_args *a = args;
30368 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30371 +/* ---------------------------------------------------------------------- */
30373 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30374 + struct dentry *d2, struct au_hinode *hdir2)
30376 + struct dentry *d;
30379 + d = lock_rename(d1, d2);
30381 + au_hn_suspend(hdir1);
30382 + if (hdir1 != hdir2)
30383 + au_hn_suspend(hdir2);
30388 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30389 + struct dentry *d2, struct au_hinode *hdir2)
30391 + au_hn_resume(hdir1);
30392 + if (hdir1 != hdir2)
30393 + au_hn_resume(hdir2);
30395 + unlock_rename(d1, d2);
30399 +/* ---------------------------------------------------------------------- */
30401 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30404 + struct dentry *d;
30408 + d = path->dentry;
30409 + path->dentry = d->d_parent;
30410 + err = security_path_mknod(path, d, mode, 0);
30411 + path->dentry = d;
30412 + if (unlikely(err))
30416 + err = vfs_create(dir, path->dentry, mode, want_excl);
30419 + struct path tmp = *path;
30422 + vfsub_update_h_iattr(&tmp, &did);
30424 + tmp.dentry = path->dentry->d_parent;
30425 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30434 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30437 + struct dentry *d;
30441 + d = path->dentry;
30442 + path->dentry = d->d_parent;
30443 + err = security_path_symlink(path, d, symname);
30444 + path->dentry = d;
30445 + if (unlikely(err))
30449 + err = vfs_symlink(dir, path->dentry, symname);
30452 + struct path tmp = *path;
30455 + vfsub_update_h_iattr(&tmp, &did);
30457 + tmp.dentry = path->dentry->d_parent;
30458 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30467 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30470 + struct dentry *d;
30474 + d = path->dentry;
30475 + path->dentry = d->d_parent;
30476 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30477 + path->dentry = d;
30478 + if (unlikely(err))
30482 + err = vfs_mknod(dir, path->dentry, mode, dev);
30485 + struct path tmp = *path;
30488 + vfsub_update_h_iattr(&tmp, &did);
30490 + tmp.dentry = path->dentry->d_parent;
30491 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30500 +static int au_test_nlink(struct inode *inode)
30502 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30504 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30505 + || inode->i_nlink < link_max)
30510 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30511 + struct inode **delegated_inode)
30514 + struct dentry *d;
30518 + err = au_test_nlink(d_inode(src_dentry));
30519 + if (unlikely(err))
30522 + /* we don't call may_linkat() */
30523 + d = path->dentry;
30524 + path->dentry = d->d_parent;
30525 + err = security_path_link(src_dentry, path, d);
30526 + path->dentry = d;
30527 + if (unlikely(err))
30531 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30534 + struct path tmp = *path;
30537 + /* fuse has different memory inode for the same inumber */
30538 + vfsub_update_h_iattr(&tmp, &did);
30540 + tmp.dentry = path->dentry->d_parent;
30541 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30542 + tmp.dentry = src_dentry;
30543 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30552 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30553 + struct inode *dir, struct path *path,
30554 + struct inode **delegated_inode)
30557 + struct path tmp = {
30560 + struct dentry *d;
30563 + IMustLock(src_dir);
30565 + d = path->dentry;
30566 + path->dentry = d->d_parent;
30567 + tmp.dentry = src_dentry->d_parent;
30568 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30569 + path->dentry = d;
30570 + if (unlikely(err))
30574 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30575 + delegated_inode, /*flags*/0);
30580 + tmp.dentry = d->d_parent;
30581 + vfsub_update_h_iattr(&tmp, &did);
30583 + tmp.dentry = src_dentry;
30584 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30585 + tmp.dentry = src_dentry->d_parent;
30586 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30595 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
30598 + struct dentry *d;
30602 + d = path->dentry;
30603 + path->dentry = d->d_parent;
30604 + err = security_path_mkdir(path, d, mode);
30605 + path->dentry = d;
30606 + if (unlikely(err))
30610 + err = vfs_mkdir(dir, path->dentry, mode);
30613 + struct path tmp = *path;
30616 + vfsub_update_h_iattr(&tmp, &did);
30618 + tmp.dentry = path->dentry->d_parent;
30619 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30628 +int vfsub_rmdir(struct inode *dir, struct path *path)
30631 + struct dentry *d;
30635 + d = path->dentry;
30636 + path->dentry = d->d_parent;
30637 + err = security_path_rmdir(path, d);
30638 + path->dentry = d;
30639 + if (unlikely(err))
30643 + err = vfs_rmdir(dir, path->dentry);
30646 + struct path tmp = {
30647 + .dentry = path->dentry->d_parent,
30651 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30658 +/* ---------------------------------------------------------------------- */
30660 +/* todo: support mmap_sem? */
30661 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30667 + err = vfs_read(file, ubuf, count, ppos);
30670 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30674 +/* todo: kernel_read()? */
30675 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
30679 + mm_segment_t oldfs;
30686 + oldfs = get_fs();
30687 + set_fs(KERNEL_DS);
30688 + err = vfsub_read_u(file, buf.u, count, ppos);
30693 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
30699 + err = vfs_write(file, ubuf, count, ppos);
30702 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30706 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
30709 + mm_segment_t oldfs;
30712 + const char __user *u;
30716 + oldfs = get_fs();
30717 + set_fs(KERNEL_DS);
30718 + err = vfsub_write_u(file, buf.u, count, ppos);
30723 +int vfsub_flush(struct file *file, fl_owner_t id)
30728 + if (file->f_op->flush) {
30729 + if (!au_test_nfs(file->f_path.dentry->d_sb))
30730 + err = file->f_op->flush(file, id);
30733 + err = file->f_op->flush(file, id);
30737 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
30743 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
30747 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
30750 + err = iterate_dir(file, ctx);
30753 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30757 +long vfsub_splice_to(struct file *in, loff_t *ppos,
30758 + struct pipe_inode_info *pipe, size_t len,
30759 + unsigned int flags)
30764 + err = do_splice_to(in, ppos, pipe, len, flags);
30766 + file_accessed(in);
30768 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
30772 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
30773 + loff_t *ppos, size_t len, unsigned int flags)
30778 + err = do_splice_from(pipe, out, ppos, len, flags);
30781 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
30785 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
30789 + /* file can be NULL */
30791 + err = vfs_fsync(file, datasync);
30795 + AuDebugOn(!file);
30796 + path = &file->f_path;
30798 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30803 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
30804 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
30805 + struct file *h_file)
30808 + struct inode *h_inode;
30809 + struct super_block *h_sb;
30812 + err = vfsub_truncate(h_path, length);
30816 + h_inode = d_inode(h_path->dentry);
30817 + h_sb = h_inode->i_sb;
30819 + sb_start_write(h_sb);
30821 + err = locks_verify_truncate(h_inode, h_file, length);
30823 + err = security_path_truncate(h_path);
30826 + err = do_truncate(h_path->dentry, length, attr, h_file);
30830 + sb_end_write(h_sb);
30837 +/* ---------------------------------------------------------------------- */
30839 +struct au_vfsub_mkdir_args {
30841 + struct inode *dir;
30842 + struct path *path;
30846 +static void au_call_vfsub_mkdir(void *args)
30848 + struct au_vfsub_mkdir_args *a = args;
30849 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
30852 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
30854 + int err, do_sio, wkq_err;
30856 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30859 + err = vfsub_mkdir(dir, path, mode);
30862 + struct au_vfsub_mkdir_args args = {
30868 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
30869 + if (unlikely(wkq_err))
30876 +struct au_vfsub_rmdir_args {
30878 + struct inode *dir;
30879 + struct path *path;
30882 +static void au_call_vfsub_rmdir(void *args)
30884 + struct au_vfsub_rmdir_args *a = args;
30885 + *a->errp = vfsub_rmdir(a->dir, a->path);
30888 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
30890 + int err, do_sio, wkq_err;
30892 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
30895 + err = vfsub_rmdir(dir, path);
30898 + struct au_vfsub_rmdir_args args = {
30903 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
30904 + if (unlikely(wkq_err))
30911 +/* ---------------------------------------------------------------------- */
30913 +struct notify_change_args {
30915 + struct path *path;
30916 + struct iattr *ia;
30917 + struct inode **delegated_inode;
30920 +static void call_notify_change(void *args)
30922 + struct notify_change_args *a = args;
30923 + struct inode *h_inode;
30925 + h_inode = d_inode(a->path->dentry);
30926 + IMustLock(h_inode);
30928 + *a->errp = -EPERM;
30929 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
30931 + *a->errp = notify_change(a->path->dentry, a->ia,
30932 + a->delegated_inode);
30935 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
30937 + AuTraceErr(*a->errp);
30940 +int vfsub_notify_change(struct path *path, struct iattr *ia,
30941 + struct inode **delegated_inode)
30944 + struct notify_change_args args = {
30948 + .delegated_inode = delegated_inode
30951 + call_notify_change(&args);
30956 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
30957 + struct inode **delegated_inode)
30959 + int err, wkq_err;
30960 + struct notify_change_args args = {
30964 + .delegated_inode = delegated_inode
30967 + wkq_err = au_wkq_wait(call_notify_change, &args);
30968 + if (unlikely(wkq_err))
30974 +/* ---------------------------------------------------------------------- */
30976 +struct unlink_args {
30978 + struct inode *dir;
30979 + struct path *path;
30980 + struct inode **delegated_inode;
30983 +static void call_unlink(void *args)
30985 + struct unlink_args *a = args;
30986 + struct dentry *d = a->path->dentry;
30987 + struct inode *h_inode;
30988 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
30989 + && au_dcount(d) == 1);
30991 + IMustLock(a->dir);
30993 + a->path->dentry = d->d_parent;
30994 + *a->errp = security_path_unlink(a->path, d);
30995 + a->path->dentry = d;
30996 + if (unlikely(*a->errp))
30999 + if (!stop_sillyrename)
31002 + if (d_is_positive(d)) {
31003 + h_inode = d_inode(d);
31008 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
31011 + struct path tmp = {
31012 + .dentry = d->d_parent,
31013 + .mnt = a->path->mnt
31015 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31018 + if (!stop_sillyrename)
31023 + AuTraceErr(*a->errp);
31027 + * @dir: must be locked.
31028 + * @dentry: target dentry.
31030 +int vfsub_unlink(struct inode *dir, struct path *path,
31031 + struct inode **delegated_inode, int force)
31034 + struct unlink_args args = {
31038 + .delegated_inode = delegated_inode
31042 + call_unlink(&args);
31046 + wkq_err = au_wkq_wait(call_unlink, &args);
31047 + if (unlikely(wkq_err))
31053 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
31054 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
31055 +++ linux/fs/aufs/vfsub.h 2016-07-25 19:05:34.817826663 +0200
31058 + * Copyright (C) 2005-2016 Junjiro R. Okajima
31060 + * This program, aufs is free software; you can redistribute it and/or modify
31061 + * it under the terms of the GNU General Public License as published by
31062 + * the Free Software Foundation; either version 2 of the License, or
31063 + * (at your option) any later version.
31065 + * This program is distributed in the hope that it will be useful,
31066 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31067 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31068 + * GNU General Public License for more details.
31070 + * You should have received a copy of the GNU General Public License
31071 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31075 + * sub-routines for VFS
31078 +#ifndef __AUFS_VFSUB_H__
31079 +#define __AUFS_VFSUB_H__
31083 +#include <linux/fs.h>
31084 +#include <linux/mount.h>
31085 +#include <linux/posix_acl.h>
31086 +#include <linux/xattr.h>
31087 +#include "debug.h"
31089 +/* copied from linux/fs/internal.h */
31090 +/* todo: BAD approach!! */
31091 +extern void __mnt_drop_write(struct vfsmount *);
31092 +extern int open_check_o_direct(struct file *f);
31094 +/* ---------------------------------------------------------------------- */
31096 +/* lock subclass for lower inode */
31097 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
31098 +/* reduce? gave up. */
31100 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
31101 + AuLsc_I_PARENT, /* lower inode, parent first */
31102 + AuLsc_I_PARENT2, /* copyup dirs */
31103 + AuLsc_I_PARENT3, /* copyup wh */
31109 +/* to debug easier, do not make them inlined functions */
31110 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
31111 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
31113 +/* ---------------------------------------------------------------------- */
31115 +static inline void vfsub_drop_nlink(struct inode *inode)
31117 + AuDebugOn(!inode->i_nlink);
31118 + drop_nlink(inode);
31121 +static inline void vfsub_dead_dir(struct inode *inode)
31123 + AuDebugOn(!S_ISDIR(inode->i_mode));
31124 + inode->i_flags |= S_DEAD;
31125 + clear_nlink(inode);
31128 +static inline int vfsub_native_ro(struct inode *inode)
31130 + return (inode->i_sb->s_flags & MS_RDONLY)
31131 + || IS_RDONLY(inode)
31132 + /* || IS_APPEND(inode) */
31133 + || IS_IMMUTABLE(inode);
31136 +#ifdef CONFIG_AUFS_BR_FUSE
31137 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
31139 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
31142 +/* ---------------------------------------------------------------------- */
31144 +int vfsub_update_h_iattr(struct path *h_path, int *did);
31145 +struct file *vfsub_dentry_open(struct path *path, int flags);
31146 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
31147 +struct vfsub_aopen_args {
31148 + struct file *file;
31149 + unsigned int open_flag;
31150 + umode_t create_mode;
31154 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
31155 + struct vfsub_aopen_args *args, struct au_branch *br);
31156 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
31158 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
31159 + struct dentry *parent, int len);
31160 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
31163 +struct vfsub_lkup_one_args {
31164 + struct dentry **errp;
31165 + struct qstr *name;
31166 + struct dentry *parent;
31169 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
31170 + struct dentry *parent)
31172 + return vfsub_lookup_one_len(name->name, parent, name->len);
31175 +void vfsub_call_lkup_one(void *args);
31177 +/* ---------------------------------------------------------------------- */
31179 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
31184 + err = mnt_want_write(mnt);
31189 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
31192 + mnt_drop_write(mnt);
31196 +#if 0 /* reserved */
31197 +static inline void vfsub_mnt_drop_write_file(struct file *file)
31200 + mnt_drop_write_file(file);
31205 +/* ---------------------------------------------------------------------- */
31208 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
31209 + struct dentry *d2, struct au_hinode *hdir2);
31210 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
31211 + struct dentry *d2, struct au_hinode *hdir2);
31213 +int vfsub_create(struct inode *dir, struct path *path, int mode,
31215 +int vfsub_symlink(struct inode *dir, struct path *path,
31216 + const char *symname);
31217 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
31218 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
31219 + struct path *path, struct inode **delegated_inode);
31220 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
31221 + struct inode *hdir, struct path *path,
31222 + struct inode **delegated_inode);
31223 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
31224 +int vfsub_rmdir(struct inode *dir, struct path *path);
31226 +/* ---------------------------------------------------------------------- */
31228 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31230 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31232 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31234 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
31236 +int vfsub_flush(struct file *file, fl_owner_t id);
31237 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
31239 +static inline loff_t vfsub_f_size_read(struct file *file)
31241 + return i_size_read(file_inode(file));
31244 +static inline unsigned int vfsub_file_flags(struct file *file)
31246 + unsigned int flags;
31248 + spin_lock(&file->f_lock);
31249 + flags = file->f_flags;
31250 + spin_unlock(&file->f_lock);
31255 +#if 0 /* reserved */
31256 +static inline void vfsub_file_accessed(struct file *h_file)
31258 + file_accessed(h_file);
31259 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
31263 +#if 0 /* reserved */
31264 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
31265 + struct dentry *h_dentry)
31267 + struct path h_path = {
31268 + .dentry = h_dentry,
31271 + touch_atime(&h_path);
31272 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
31276 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
31279 + return update_time(h_inode, ts, flags);
31280 + /* no vfsub_update_h_iattr() since we don't have struct path */
31283 +#ifdef CONFIG_FS_POSIX_ACL
31284 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
31288 + err = posix_acl_chmod(h_inode, h_mode);
31289 + if (err == -EOPNOTSUPP)
31294 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
31297 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31298 + struct pipe_inode_info *pipe, size_t len,
31299 + unsigned int flags);
31300 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31301 + loff_t *ppos, size_t len, unsigned int flags);
31303 +static inline long vfsub_truncate(struct path *path, loff_t length)
31308 + err = vfs_truncate(path, length);
31313 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31314 + struct file *h_file);
31315 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
31317 +/* ---------------------------------------------------------------------- */
31319 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
31324 + err = vfs_llseek(file, offset, origin);
31329 +/* ---------------------------------------------------------------------- */
31331 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
31332 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
31333 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31334 + struct inode **delegated_inode);
31335 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31336 + struct inode **delegated_inode);
31337 +int vfsub_unlink(struct inode *dir, struct path *path,
31338 + struct inode **delegated_inode, int force);
31340 +/* ---------------------------------------------------------------------- */
31342 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
31343 + const void *value, size_t size, int flags)
31348 + err = vfs_setxattr(dentry, name, value, size, flags);
31354 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31359 + err = vfs_removexattr(dentry, name);
31365 +#endif /* __KERNEL__ */
31366 +#endif /* __AUFS_VFSUB_H__ */
31367 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31368 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31369 +++ linux/fs/aufs/wbr_policy.c 2016-07-25 19:05:34.817826663 +0200
31372 + * Copyright (C) 2005-2016 Junjiro R. Okajima
31374 + * This program, aufs is free software; you can redistribute it and/or modify
31375 + * it under the terms of the GNU General Public License as published by
31376 + * the Free Software Foundation; either version 2 of the License, or
31377 + * (at your option) any later version.
31379 + * This program is distributed in the hope that it will be useful,
31380 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31381 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31382 + * GNU General Public License for more details.
31384 + * You should have received a copy of the GNU General Public License
31385 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31389 + * policies for selecting one among multiple writable branches
31392 +#include <linux/statfs.h>
31395 +/* subset of cpup_attr() */
31396 +static noinline_for_stack
31397 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31401 + struct inode *h_isrc;
31403 + h_isrc = d_inode(h_src);
31404 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31405 + ia.ia_mode = h_isrc->i_mode;
31406 + ia.ia_uid = h_isrc->i_uid;
31407 + ia.ia_gid = h_isrc->i_gid;
31408 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31409 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31410 + /* no delegation since it is just created */
31411 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31413 + /* is this nfs only? */
31414 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31415 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31416 + ia.ia_mode = h_isrc->i_mode;
31417 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31423 +#define AuCpdown_PARENT_OPQ 1
31424 +#define AuCpdown_WHED (1 << 1)
31425 +#define AuCpdown_MADE_DIR (1 << 2)
31426 +#define AuCpdown_DIROPQ (1 << 3)
31427 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31428 +#define au_fset_cpdown(flags, name) \
31429 + do { (flags) |= AuCpdown_##name; } while (0)
31430 +#define au_fclr_cpdown(flags, name) \
31431 + do { (flags) &= ~AuCpdown_##name; } while (0)
31433 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31434 + unsigned int *flags)
31437 + struct dentry *opq_dentry;
31439 + opq_dentry = au_diropq_create(dentry, bdst);
31440 + err = PTR_ERR(opq_dentry);
31441 + if (IS_ERR(opq_dentry))
31443 + dput(opq_dentry);
31444 + au_fset_cpdown(*flags, DIROPQ);
31450 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31451 + struct inode *dir, aufs_bindex_t bdst)
31454 + struct path h_path;
31455 + struct au_branch *br;
31457 + br = au_sbr(dentry->d_sb, bdst);
31458 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31459 + err = PTR_ERR(h_path.dentry);
31460 + if (IS_ERR(h_path.dentry))
31464 + if (d_is_positive(h_path.dentry)) {
31465 + h_path.mnt = au_br_mnt(br);
31466 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31469 + dput(h_path.dentry);
31475 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31476 + struct au_pin *pin,
31477 + struct dentry *h_parent, void *arg)
31480 + aufs_bindex_t bopq, btop;
31481 + struct path h_path;
31482 + struct dentry *parent;
31483 + struct inode *h_dir, *h_inode, *inode, *dir;
31484 + unsigned int *flags = arg;
31486 + btop = au_dbtop(dentry);
31487 + /* dentry is di-locked */
31488 + parent = dget_parent(dentry);
31489 + dir = d_inode(parent);
31490 + h_dir = d_inode(h_parent);
31491 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31492 + IMustLock(h_dir);
31494 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31495 + if (unlikely(err < 0))
31497 + h_path.dentry = au_h_dptr(dentry, bdst);
31498 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31499 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31500 + S_IRWXU | S_IRUGO | S_IXUGO);
31501 + if (unlikely(err))
31503 + au_fset_cpdown(*flags, MADE_DIR);
31505 + bopq = au_dbdiropq(dentry);
31506 + au_fclr_cpdown(*flags, WHED);
31507 + au_fclr_cpdown(*flags, DIROPQ);
31508 + if (au_dbwh(dentry) == bdst)
31509 + au_fset_cpdown(*flags, WHED);
31510 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31511 + au_fset_cpdown(*flags, PARENT_OPQ);
31512 + h_inode = d_inode(h_path.dentry);
31513 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31514 + if (au_ftest_cpdown(*flags, WHED)) {
31515 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31516 + if (unlikely(err)) {
31517 + inode_unlock(h_inode);
31522 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
31523 + inode_unlock(h_inode);
31524 + if (unlikely(err))
31527 + if (au_ftest_cpdown(*flags, WHED)) {
31528 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
31529 + if (unlikely(err))
31533 + inode = d_inode(dentry);
31534 + if (au_ibbot(inode) < bdst)
31535 + au_set_ibbot(inode, bdst);
31536 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
31537 + au_hi_flags(inode, /*isdir*/1));
31538 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
31539 + goto out; /* success */
31543 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31544 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31545 + rerr = au_diropq_remove(dentry, bdst);
31546 + inode_unlock(h_inode);
31547 + if (unlikely(rerr)) {
31548 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
31549 + dentry, bdst, rerr);
31555 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
31556 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
31557 + if (unlikely(rerr)) {
31558 + AuIOErr("failed removing %pd b%d (%d)\n",
31559 + dentry, bdst, rerr);
31564 + au_set_h_dptr(dentry, bdst, NULL);
31565 + if (au_dbbot(dentry) == bdst)
31566 + au_update_dbbot(dentry);
31572 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
31575 + unsigned int flags;
31578 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
31583 +/* ---------------------------------------------------------------------- */
31585 +/* policies for create */
31587 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
31589 + int err, i, j, ndentry;
31590 + aufs_bindex_t bopq;
31591 + struct au_dcsub_pages dpages;
31592 + struct au_dpage *dpage;
31593 + struct dentry **dentries, *parent, *d;
31595 + err = au_dpages_init(&dpages, GFP_NOFS);
31596 + if (unlikely(err))
31598 + parent = dget_parent(dentry);
31599 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
31600 + if (unlikely(err))
31604 + for (i = 0; i < dpages.ndpage; i++) {
31605 + dpage = dpages.dpages + i;
31606 + dentries = dpage->dentries;
31607 + ndentry = dpage->ndentry;
31608 + for (j = 0; j < ndentry; j++) {
31610 + di_read_lock_parent2(d, !AuLock_IR);
31611 + bopq = au_dbdiropq(d);
31612 + di_read_unlock(d, !AuLock_IR);
31613 + if (bopq >= 0 && bopq < err)
31620 + au_dpages_free(&dpages);
31625 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
31627 + for (; bindex >= 0; bindex--)
31628 + if (!au_br_rdonly(au_sbr(sb, bindex)))
31633 +/* top down parent */
31634 +static int au_wbr_create_tdp(struct dentry *dentry,
31635 + unsigned int flags __maybe_unused)
31638 + aufs_bindex_t btop, bindex;
31639 + struct super_block *sb;
31640 + struct dentry *parent, *h_parent;
31642 + sb = dentry->d_sb;
31643 + btop = au_dbtop(dentry);
31645 + if (!au_br_rdonly(au_sbr(sb, btop)))
31649 + parent = dget_parent(dentry);
31650 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
31651 + h_parent = au_h_dptr(parent, bindex);
31652 + if (!h_parent || d_is_negative(h_parent))
31655 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31662 + /* bottom up here */
31663 + if (unlikely(err < 0)) {
31664 + err = au_wbr_bu(sb, btop - 1);
31666 + err = au_wbr_nonopq(dentry, err);
31670 + AuDbg("b%d\n", err);
31674 +/* ---------------------------------------------------------------------- */
31676 +/* an exception for the policy other than tdp */
31677 +static int au_wbr_create_exp(struct dentry *dentry)
31680 + aufs_bindex_t bwh, bdiropq;
31681 + struct dentry *parent;
31684 + bwh = au_dbwh(dentry);
31685 + parent = dget_parent(dentry);
31686 + bdiropq = au_dbdiropq(parent);
31688 + if (bdiropq >= 0)
31689 + err = min(bdiropq, bwh);
31692 + AuDbg("%d\n", err);
31693 + } else if (bdiropq >= 0) {
31695 + AuDbg("%d\n", err);
31700 + err = au_wbr_nonopq(dentry, err);
31702 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
31705 + AuDbg("%d\n", err);
31709 +/* ---------------------------------------------------------------------- */
31712 +static int au_wbr_create_init_rr(struct super_block *sb)
31716 + err = au_wbr_bu(sb, au_sbbot(sb));
31717 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
31720 + AuDbg("b%d\n", err);
31724 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
31728 + aufs_bindex_t bindex, bbot;
31729 + struct super_block *sb;
31732 + err = au_wbr_create_exp(dentry);
31736 + sb = dentry->d_sb;
31737 + next = &au_sbi(sb)->si_wbr_rr_next;
31738 + bbot = au_sbbot(sb);
31740 + for (bindex = 0; bindex <= bbot; bindex++) {
31741 + if (!au_ftest_wbr(flags, DIR)) {
31742 + err = atomic_dec_return(next) + 1;
31743 + /* modulo for 0 is meaningless */
31744 + if (unlikely(!err))
31745 + err = atomic_dec_return(next) + 1;
31747 + err = atomic_read(next);
31748 + AuDbg("%d\n", err);
31751 + AuDbg("%d\n", err);
31752 + if (!au_br_rdonly(au_sbr(sb, err)))
31758 + err = au_wbr_nonopq(dentry, err);
31761 + AuDbg("%d\n", err);
31765 +/* ---------------------------------------------------------------------- */
31767 +/* most free space */
31768 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
31770 + struct super_block *sb;
31771 + struct au_branch *br;
31772 + struct au_wbr_mfs *mfs;
31773 + struct dentry *h_parent;
31774 + aufs_bindex_t bindex, bbot;
31776 + unsigned long long b, bavail;
31777 + struct path h_path;
31778 + /* reduce the stack usage */
31779 + struct kstatfs *st;
31781 + st = kmalloc(sizeof(*st), GFP_NOFS);
31782 + if (unlikely(!st)) {
31783 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
31788 + sb = dentry->d_sb;
31789 + mfs = &au_sbi(sb)->si_wbr_mfs;
31790 + MtxMustLock(&mfs->mfs_lock);
31791 + mfs->mfs_bindex = -EROFS;
31792 + mfs->mfsrr_bytes = 0;
31795 + bbot = au_sbbot(sb);
31797 + bindex = au_dbtop(parent);
31798 + bbot = au_dbtaildir(parent);
31801 + for (; bindex <= bbot; bindex++) {
31803 + h_parent = au_h_dptr(parent, bindex);
31804 + if (!h_parent || d_is_negative(h_parent))
31807 + br = au_sbr(sb, bindex);
31808 + if (au_br_rdonly(br))
31811 + /* sb->s_root for NFS is unreliable */
31812 + h_path.mnt = au_br_mnt(br);
31813 + h_path.dentry = h_path.mnt->mnt_root;
31814 + err = vfs_statfs(&h_path, st);
31815 + if (unlikely(err)) {
31816 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
31820 + /* when the available size is equal, select the lower one */
31821 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
31822 + || sizeof(b) < sizeof(st->f_bsize));
31823 + b = st->f_bavail * st->f_bsize;
31824 + br->br_wbr->wbr_bytes = b;
31825 + if (b >= bavail) {
31827 + mfs->mfs_bindex = bindex;
31828 + mfs->mfs_jiffy = jiffies;
31832 + mfs->mfsrr_bytes = bavail;
31833 + AuDbg("b%d\n", mfs->mfs_bindex);
31837 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
31840 + struct dentry *parent;
31841 + struct super_block *sb;
31842 + struct au_wbr_mfs *mfs;
31844 + err = au_wbr_create_exp(dentry);
31848 + sb = dentry->d_sb;
31850 + if (au_ftest_wbr(flags, PARENT))
31851 + parent = dget_parent(dentry);
31852 + mfs = &au_sbi(sb)->si_wbr_mfs;
31853 + mutex_lock(&mfs->mfs_lock);
31854 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
31855 + || mfs->mfs_bindex < 0
31856 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
31857 + au_mfs(dentry, parent);
31858 + mutex_unlock(&mfs->mfs_lock);
31859 + err = mfs->mfs_bindex;
31863 + err = au_wbr_nonopq(dentry, err);
31866 + AuDbg("b%d\n", err);
31870 +static int au_wbr_create_init_mfs(struct super_block *sb)
31872 + struct au_wbr_mfs *mfs;
31874 + mfs = &au_sbi(sb)->si_wbr_mfs;
31875 + mutex_init(&mfs->mfs_lock);
31876 + mfs->mfs_jiffy = 0;
31877 + mfs->mfs_bindex = -EROFS;
31882 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
31884 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
31888 +/* ---------------------------------------------------------------------- */
31890 +/* most free space and then round robin */
31891 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
31894 + struct au_wbr_mfs *mfs;
31896 + err = au_wbr_create_mfs(dentry, flags);
31898 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
31899 + mutex_lock(&mfs->mfs_lock);
31900 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
31901 + err = au_wbr_create_rr(dentry, flags);
31902 + mutex_unlock(&mfs->mfs_lock);
31905 + AuDbg("b%d\n", err);
31909 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
31913 + au_wbr_create_init_mfs(sb); /* ignore */
31914 + err = au_wbr_create_init_rr(sb);
31919 +/* ---------------------------------------------------------------------- */
31921 +/* top down parent and most free space */
31922 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
31925 + unsigned long long b;
31926 + aufs_bindex_t bindex, btop, bbot;
31927 + struct super_block *sb;
31928 + struct dentry *parent, *h_parent;
31929 + struct au_branch *br;
31931 + err = au_wbr_create_tdp(dentry, flags);
31932 + if (unlikely(err < 0))
31934 + parent = dget_parent(dentry);
31935 + btop = au_dbtop(parent);
31936 + bbot = au_dbtaildir(parent);
31937 + if (btop == bbot)
31938 + goto out_parent; /* success */
31940 + e2 = au_wbr_create_mfs(dentry, flags);
31942 + goto out_parent; /* success */
31944 + /* when the available size is equal, select upper one */
31945 + sb = dentry->d_sb;
31946 + br = au_sbr(sb, err);
31947 + b = br->br_wbr->wbr_bytes;
31948 + AuDbg("b%d, %llu\n", err, b);
31950 + for (bindex = btop; bindex <= bbot; bindex++) {
31951 + h_parent = au_h_dptr(parent, bindex);
31952 + if (!h_parent || d_is_negative(h_parent))
31955 + br = au_sbr(sb, bindex);
31956 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
31957 + b = br->br_wbr->wbr_bytes;
31959 + AuDbg("b%d, %llu\n", err, b);
31964 + err = au_wbr_nonopq(dentry, err);
31969 + AuDbg("b%d\n", err);
31973 +/* ---------------------------------------------------------------------- */
31976 + * - top down parent
31977 + * - most free space with parent
31978 + * - most free space round-robin regardless parent
31980 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
31983 + unsigned long long watermark;
31984 + struct super_block *sb;
31985 + struct au_branch *br;
31986 + struct au_wbr_mfs *mfs;
31988 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
31989 + if (unlikely(err < 0))
31992 + sb = dentry->d_sb;
31993 + br = au_sbr(sb, err);
31994 + mfs = &au_sbi(sb)->si_wbr_mfs;
31995 + mutex_lock(&mfs->mfs_lock);
31996 + watermark = mfs->mfsrr_watermark;
31997 + mutex_unlock(&mfs->mfs_lock);
31998 + if (br->br_wbr->wbr_bytes < watermark)
31999 + /* regardless the parent dir */
32000 + err = au_wbr_create_mfsrr(dentry, flags);
32003 + AuDbg("b%d\n", err);
32007 +/* ---------------------------------------------------------------------- */
32009 +/* policies for copyup */
32011 +/* top down parent */
32012 +static int au_wbr_copyup_tdp(struct dentry *dentry)
32014 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
32017 +/* bottom up parent */
32018 +static int au_wbr_copyup_bup(struct dentry *dentry)
32021 + aufs_bindex_t bindex, btop;
32022 + struct dentry *parent, *h_parent;
32023 + struct super_block *sb;
32026 + sb = dentry->d_sb;
32027 + parent = dget_parent(dentry);
32028 + btop = au_dbtop(parent);
32029 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
32030 + h_parent = au_h_dptr(parent, bindex);
32031 + if (!h_parent || d_is_negative(h_parent))
32034 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32041 + /* bottom up here */
32042 + if (unlikely(err < 0))
32043 + err = au_wbr_bu(sb, btop - 1);
32045 + AuDbg("b%d\n", err);
32050 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
32054 + err = au_wbr_bu(dentry->d_sb, btop);
32055 + AuDbg("b%d\n", err);
32057 + err = au_wbr_nonopq(dentry, err);
32059 + AuDbg("b%d\n", err);
32063 +static int au_wbr_copyup_bu(struct dentry *dentry)
32066 + aufs_bindex_t btop;
32068 + btop = au_dbtop(dentry);
32069 + err = au_wbr_do_copyup_bu(dentry, btop);
32073 +/* ---------------------------------------------------------------------- */
32075 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
32076 + [AuWbrCopyup_TDP] = {
32077 + .copyup = au_wbr_copyup_tdp
32079 + [AuWbrCopyup_BUP] = {
32080 + .copyup = au_wbr_copyup_bup
32082 + [AuWbrCopyup_BU] = {
32083 + .copyup = au_wbr_copyup_bu
32087 +struct au_wbr_create_operations au_wbr_create_ops[] = {
32088 + [AuWbrCreate_TDP] = {
32089 + .create = au_wbr_create_tdp
32091 + [AuWbrCreate_RR] = {
32092 + .create = au_wbr_create_rr,
32093 + .init = au_wbr_create_init_rr
32095 + [AuWbrCreate_MFS] = {
32096 + .create = au_wbr_create_mfs,
32097 + .init = au_wbr_create_init_mfs,
32098 + .fin = au_wbr_create_fin_mfs
32100 + [AuWbrCreate_MFSV] = {
32101 + .create = au_wbr_create_mfs,
32102 + .init = au_wbr_create_init_mfs,
32103 + .fin = au_wbr_create_fin_mfs
32105 + [AuWbrCreate_MFSRR] = {
32106 + .create = au_wbr_create_mfsrr,
32107 + .init = au_wbr_create_init_mfsrr,
32108 + .fin = au_wbr_create_fin_mfs
32110 + [AuWbrCreate_MFSRRV] = {
32111 + .create = au_wbr_create_mfsrr,
32112 + .init = au_wbr_create_init_mfsrr,
32113 + .fin = au_wbr_create_fin_mfs
32115 + [AuWbrCreate_PMFS] = {
32116 + .create = au_wbr_create_pmfs,
32117 + .init = au_wbr_create_init_mfs,
32118 + .fin = au_wbr_create_fin_mfs
32120 + [AuWbrCreate_PMFSV] = {
32121 + .create = au_wbr_create_pmfs,
32122 + .init = au_wbr_create_init_mfs,
32123 + .fin = au_wbr_create_fin_mfs
32125 + [AuWbrCreate_PMFSRR] = {
32126 + .create = au_wbr_create_pmfsrr,
32127 + .init = au_wbr_create_init_mfsrr,
32128 + .fin = au_wbr_create_fin_mfs
32130 + [AuWbrCreate_PMFSRRV] = {
32131 + .create = au_wbr_create_pmfsrr,
32132 + .init = au_wbr_create_init_mfsrr,
32133 + .fin = au_wbr_create_fin_mfs
32136 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
32137 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
32138 +++ linux/fs/aufs/whout.c 2016-07-25 19:05:34.817826663 +0200
32141 + * Copyright (C) 2005-2016 Junjiro R. Okajima
32143 + * This program, aufs is free software; you can redistribute it and/or modify
32144 + * it under the terms of the GNU General Public License as published by
32145 + * the Free Software Foundation; either version 2 of the License, or
32146 + * (at your option) any later version.
32148 + * This program is distributed in the hope that it will be useful,
32149 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32150 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32151 + * GNU General Public License for more details.
32153 + * You should have received a copy of the GNU General Public License
32154 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32158 + * whiteout for logical deletion and opaque directory
32163 +#define WH_MASK S_IRUGO
32166 + * If a directory contains this file, then it is opaque. We start with the
32167 + * .wh. flag so that it is blocked by lookup.
32169 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
32170 + sizeof(AUFS_WH_DIROPQ) - 1);
32173 + * generate whiteout name, which is NOT terminated by NULL.
32174 + * @name: original d_name.name
32175 + * @len: original d_name.len
32176 + * @wh: whiteout qstr
32177 + * returns zero when succeeds, otherwise error.
32178 + * succeeded value as wh->name should be freed by kfree().
32180 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
32184 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
32185 + return -ENAMETOOLONG;
32187 + wh->len = name->len + AUFS_WH_PFX_LEN;
32188 + p = kmalloc(wh->len, GFP_NOFS);
32191 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32192 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
32199 +/* ---------------------------------------------------------------------- */
32202 + * test if the @wh_name exists under @h_parent.
32203 + * @try_sio specifies the necessary of super-io.
32205 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
32208 + struct dentry *wh_dentry;
32211 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
32213 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
32214 + err = PTR_ERR(wh_dentry);
32215 + if (IS_ERR(wh_dentry)) {
32216 + if (err == -ENAMETOOLONG)
32222 + if (d_is_negative(wh_dentry))
32223 + goto out_wh; /* success */
32226 + if (d_is_reg(wh_dentry))
32227 + goto out_wh; /* success */
32230 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
32231 + wh_dentry, d_inode(wh_dentry)->i_mode);
32240 + * test if the @h_dentry sets opaque or not.
32242 +int au_diropq_test(struct dentry *h_dentry)
32245 + struct inode *h_dir;
32247 + h_dir = d_inode(h_dentry);
32248 + err = au_wh_test(h_dentry, &diropq_name,
32249 + au_test_h_perm_sio(h_dir, MAY_EXEC));
32254 + * returns a negative dentry whose name is unique and temporary.
32256 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32257 + struct qstr *prefix)
32259 + struct dentry *dentry;
32261 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
32263 + /* strict atomic_t is unnecessary here */
32264 + static unsigned short cnt;
32267 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
32270 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
32271 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
32272 + dentry = ERR_PTR(-ENAMETOOLONG);
32273 + if (unlikely(qs.len > NAME_MAX))
32275 + dentry = ERR_PTR(-ENOMEM);
32276 + name = kmalloc(qs.len + 1, GFP_NOFS);
32277 + if (unlikely(!name))
32281 + /* doubly whiteout-ed */
32282 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
32283 + p = name + AUFS_WH_PFX_LEN * 2;
32284 + memcpy(p, prefix->name, prefix->len);
32285 + p += prefix->len;
32287 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
32290 + for (i = 0; i < 3; i++) {
32291 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
32292 + dentry = au_sio_lkup_one(&qs, h_parent);
32293 + if (IS_ERR(dentry) || d_is_negative(dentry))
32297 + /* pr_warn("could not get random name\n"); */
32298 + dentry = ERR_PTR(-EEXIST);
32299 + AuDbg("%.*s\n", AuLNPair(&qs));
32303 + if (name != defname)
32306 + AuTraceErrPtr(dentry);
32311 + * rename the @h_dentry on @br to the whiteouted temporary name.
32313 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
32316 + struct path h_path = {
32317 + .mnt = au_br_mnt(br)
32319 + struct inode *h_dir, *delegated;
32320 + struct dentry *h_parent;
32322 + h_parent = h_dentry->d_parent; /* dir inode is locked */
32323 + h_dir = d_inode(h_parent);
32324 + IMustLock(h_dir);
32326 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
32327 + err = PTR_ERR(h_path.dentry);
32328 + if (IS_ERR(h_path.dentry))
32331 + /* under the same dir, no need to lock_rename() */
32332 + delegated = NULL;
32333 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
32335 + if (unlikely(err == -EWOULDBLOCK)) {
32336 + pr_warn("cannot retry for NFSv4 delegation"
32337 + " for an internal rename\n");
32340 + dput(h_path.dentry);
32347 +/* ---------------------------------------------------------------------- */
32349 + * functions for removing a whiteout
32352 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
32355 + struct inode *delegated;
32358 + * forces superio when the dir has a sticky bit.
32359 + * this may be a violation of unix fs semantics.
32361 + force = (h_dir->i_mode & S_ISVTX)
32362 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32363 + delegated = NULL;
32364 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32365 + if (unlikely(err == -EWOULDBLOCK)) {
32366 + pr_warn("cannot retry for NFSv4 delegation"
32367 + " for an internal unlink\n");
32373 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32374 + struct dentry *dentry)
32378 + err = do_unlink_wh(h_dir, h_path);
32379 + if (!err && dentry)
32380 + au_set_dbwh(dentry, -1);
32385 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32386 + struct au_branch *br)
32389 + struct path h_path = {
32390 + .mnt = au_br_mnt(br)
32394 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32395 + if (IS_ERR(h_path.dentry))
32396 + err = PTR_ERR(h_path.dentry);
32398 + if (d_is_reg(h_path.dentry))
32399 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32400 + dput(h_path.dentry);
32406 +/* ---------------------------------------------------------------------- */
32408 + * initialize/clean whiteout for a branch
32411 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32415 + struct inode *delegated;
32417 + if (d_is_negative(whpath->dentry))
32421 + err = vfsub_rmdir(h_dir, whpath);
32423 + delegated = NULL;
32424 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32425 + if (unlikely(err == -EWOULDBLOCK)) {
32426 + pr_warn("cannot retry for NFSv4 delegation"
32427 + " for an internal unlink\n");
32431 + if (unlikely(err))
32432 + pr_warn("failed removing %pd (%d), ignored.\n",
32433 + whpath->dentry, err);
32436 +static int test_linkable(struct dentry *h_root)
32438 + struct inode *h_dir = d_inode(h_root);
32440 + if (h_dir->i_op->link)
32443 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32444 + h_root, au_sbtype(h_root->d_sb));
32448 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32449 +static int au_whdir(struct inode *h_dir, struct path *path)
32454 + if (d_is_negative(path->dentry)) {
32455 + int mode = S_IRWXU;
32457 + if (au_test_nfs(path->dentry->d_sb))
32459 + err = vfsub_mkdir(h_dir, path, mode);
32460 + } else if (d_is_dir(path->dentry))
32463 + pr_err("unknown %pd exists\n", path->dentry);
32468 +struct au_wh_base {
32469 + const struct qstr *name;
32470 + struct dentry *dentry;
32473 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
32474 + struct path *h_path)
32476 + h_path->dentry = base[AuBrWh_BASE].dentry;
32477 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32478 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32479 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32480 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32481 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32485 + * returns tri-state,
32486 + * minus: error, caller should print the message
32488 + * plus: error, caller should NOT print the message
32490 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
32491 + int do_plink, struct au_wh_base base[],
32492 + struct path *h_path)
32495 + struct inode *h_dir;
32497 + h_dir = d_inode(h_root);
32498 + h_path->dentry = base[AuBrWh_BASE].dentry;
32499 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32500 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32502 + err = test_linkable(h_root);
32503 + if (unlikely(err)) {
32508 + err = au_whdir(h_dir, h_path);
32509 + if (unlikely(err))
32511 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32513 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32514 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32515 + err = au_whdir(h_dir, h_path);
32516 + if (unlikely(err))
32518 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32525 + * for the moment, aufs supports the branch filesystem which does not support
32526 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
32527 + * copyup failed. finally, such filesystem will not be used as the writable
32530 + * returns tri-state, see above.
32532 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
32533 + int do_plink, struct au_wh_base base[],
32534 + struct path *h_path)
32537 + struct inode *h_dir;
32539 + WbrWhMustWriteLock(wbr);
32541 + err = test_linkable(h_root);
32542 + if (unlikely(err)) {
32548 + * todo: should this create be done in /sbin/mount.aufs helper?
32551 + h_dir = d_inode(h_root);
32552 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
32553 + h_path->dentry = base[AuBrWh_BASE].dentry;
32554 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
32555 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
32558 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
32559 + if (unlikely(err))
32562 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32564 + err = au_whdir(h_dir, h_path);
32565 + if (unlikely(err))
32567 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32569 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32570 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
32572 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32573 + err = au_whdir(h_dir, h_path);
32574 + if (unlikely(err))
32576 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32583 + * initialize the whiteout base file/dir for @br.
32585 +int au_wh_init(struct au_branch *br, struct super_block *sb)
32588 + const unsigned char do_plink
32589 + = !!au_opt_test(au_mntflags(sb), PLINK);
32590 + struct inode *h_dir;
32591 + struct path path = br->br_path;
32592 + struct dentry *h_root = path.dentry;
32593 + struct au_wbr *wbr = br->br_wbr;
32594 + static const struct qstr base_name[] = {
32595 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
32596 + sizeof(AUFS_BASE_NAME) - 1),
32597 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
32598 + sizeof(AUFS_PLINKDIR_NAME) - 1),
32599 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
32600 + sizeof(AUFS_ORPHDIR_NAME) - 1)
32602 + struct au_wh_base base[] = {
32603 + [AuBrWh_BASE] = {
32604 + .name = base_name + AuBrWh_BASE,
32607 + [AuBrWh_PLINK] = {
32608 + .name = base_name + AuBrWh_PLINK,
32611 + [AuBrWh_ORPH] = {
32612 + .name = base_name + AuBrWh_ORPH,
32618 + WbrWhMustWriteLock(wbr);
32620 + for (i = 0; i < AuBrWh_Last; i++) {
32621 + /* doubly whiteouted */
32622 + struct dentry *d;
32624 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
32625 + err = PTR_ERR(d);
32629 + base[i].dentry = d;
32631 + && wbr->wbr_wh[i]
32632 + && wbr->wbr_wh[i] != base[i].dentry);
32636 + for (i = 0; i < AuBrWh_Last; i++) {
32637 + dput(wbr->wbr_wh[i]);
32638 + wbr->wbr_wh[i] = NULL;
32642 + if (!au_br_writable(br->br_perm)) {
32643 + h_dir = d_inode(h_root);
32644 + au_wh_init_ro(h_dir, base, &path);
32645 + } else if (!au_br_wh_linkable(br->br_perm)) {
32646 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
32652 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
32658 + goto out; /* success */
32661 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
32662 + err, h_root, au_sbtype(h_root->d_sb));
32664 + for (i = 0; i < AuBrWh_Last; i++)
32665 + dput(base[i].dentry);
32669 +/* ---------------------------------------------------------------------- */
32671 + * whiteouts are all hard-linked usually.
32672 + * when its link count reaches a ceiling, we create a new whiteout base
32673 + * asynchronously.
32676 +struct reinit_br_wh {
32677 + struct super_block *sb;
32678 + struct au_branch *br;
32681 +static void reinit_br_wh(void *arg)
32684 + aufs_bindex_t bindex;
32685 + struct path h_path;
32686 + struct reinit_br_wh *a = arg;
32687 + struct au_wbr *wbr;
32688 + struct inode *dir, *delegated;
32689 + struct dentry *h_root;
32690 + struct au_hinode *hdir;
32693 + wbr = a->br->br_wbr;
32694 + /* big aufs lock */
32695 + si_noflush_write_lock(a->sb);
32696 + if (!au_br_writable(a->br->br_perm))
32698 + bindex = au_br_index(a->sb, a->br->br_id);
32699 + if (unlikely(bindex < 0))
32702 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
32703 + dir = d_inode(a->sb->s_root);
32704 + hdir = au_hi(dir, bindex);
32705 + h_root = au_h_dptr(a->sb->s_root, bindex);
32706 + AuDebugOn(h_root != au_br_dentry(a->br));
32708 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
32709 + wbr_wh_write_lock(wbr);
32710 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
32713 + h_path.dentry = wbr->wbr_whbase;
32714 + h_path.mnt = au_br_mnt(a->br);
32715 + delegated = NULL;
32716 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
32718 + if (unlikely(err == -EWOULDBLOCK)) {
32719 + pr_warn("cannot retry for NFSv4 delegation"
32720 + " for an internal unlink\n");
32724 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
32727 + dput(wbr->wbr_whbase);
32728 + wbr->wbr_whbase = NULL;
32730 + err = au_wh_init(a->br, a->sb);
32731 + wbr_wh_write_unlock(wbr);
32732 + au_hn_inode_unlock(hdir);
32733 + di_read_unlock(a->sb->s_root, AuLock_IR);
32735 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
32739 + atomic_dec(&wbr->wbr_wh_running);
32740 + au_br_put(a->br);
32741 + si_write_unlock(a->sb);
32742 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
32744 + if (unlikely(err))
32745 + AuIOErr("err %d\n", err);
32748 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
32750 + int do_dec, wkq_err;
32751 + struct reinit_br_wh *arg;
32754 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
32757 + /* ignore ENOMEM */
32758 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
32761 + * dec(wh_running), kfree(arg) and dec(br_count)
32762 + * in reinit function
32767 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
32768 + if (unlikely(wkq_err)) {
32769 + atomic_dec(&br->br_wbr->wbr_wh_running);
32778 + atomic_dec(&br->br_wbr->wbr_wh_running);
32781 +/* ---------------------------------------------------------------------- */
32784 + * create the whiteout @wh.
32786 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
32787 + struct dentry *wh)
32790 + struct path h_path = {
32793 + struct au_branch *br;
32794 + struct au_wbr *wbr;
32795 + struct dentry *h_parent;
32796 + struct inode *h_dir, *delegated;
32798 + h_parent = wh->d_parent; /* dir inode is locked */
32799 + h_dir = d_inode(h_parent);
32800 + IMustLock(h_dir);
32802 + br = au_sbr(sb, bindex);
32803 + h_path.mnt = au_br_mnt(br);
32804 + wbr = br->br_wbr;
32805 + wbr_wh_read_lock(wbr);
32806 + if (wbr->wbr_whbase) {
32807 + delegated = NULL;
32808 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
32809 + if (unlikely(err == -EWOULDBLOCK)) {
32810 + pr_warn("cannot retry for NFSv4 delegation"
32811 + " for an internal link\n");
32814 + if (!err || err != -EMLINK)
32817 + /* link count full. re-initialize br_whbase. */
32818 + kick_reinit_br_wh(sb, br);
32821 + /* return this error in this context */
32822 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
32824 + au_fhsm_wrote(sb, bindex, /*force*/0);
32827 + wbr_wh_read_unlock(wbr);
32831 +/* ---------------------------------------------------------------------- */
32834 + * create or remove the diropq.
32836 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
32837 + unsigned int flags)
32839 + struct dentry *opq_dentry, *h_dentry;
32840 + struct super_block *sb;
32841 + struct au_branch *br;
32844 + sb = dentry->d_sb;
32845 + br = au_sbr(sb, bindex);
32846 + h_dentry = au_h_dptr(dentry, bindex);
32847 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
32848 + if (IS_ERR(opq_dentry))
32851 + if (au_ftest_diropq(flags, CREATE)) {
32852 + err = link_or_create_wh(sb, bindex, opq_dentry);
32854 + au_set_dbdiropq(dentry, bindex);
32855 + goto out; /* success */
32858 + struct path tmp = {
32859 + .dentry = opq_dentry,
32860 + .mnt = au_br_mnt(br)
32862 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
32864 + au_set_dbdiropq(dentry, -1);
32866 + dput(opq_dentry);
32867 + opq_dentry = ERR_PTR(err);
32870 + return opq_dentry;
32873 +struct do_diropq_args {
32874 + struct dentry **errp;
32875 + struct dentry *dentry;
32876 + aufs_bindex_t bindex;
32877 + unsigned int flags;
32880 +static void call_do_diropq(void *args)
32882 + struct do_diropq_args *a = args;
32883 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
32886 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
32887 + unsigned int flags)
32889 + struct dentry *diropq, *h_dentry;
32891 + h_dentry = au_h_dptr(dentry, bindex);
32892 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
32893 + diropq = do_diropq(dentry, bindex, flags);
32896 + struct do_diropq_args args = {
32898 + .dentry = dentry,
32899 + .bindex = bindex,
32903 + wkq_err = au_wkq_wait(call_do_diropq, &args);
32904 + if (unlikely(wkq_err))
32905 + diropq = ERR_PTR(wkq_err);
32911 +/* ---------------------------------------------------------------------- */
32914 + * lookup whiteout dentry.
32915 + * @h_parent: lower parent dentry which must exist and be locked
32916 + * @base_name: name of dentry which will be whiteouted
32917 + * returns dentry for whiteout.
32919 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
32920 + struct au_branch *br)
32923 + struct qstr wh_name;
32924 + struct dentry *wh_dentry;
32926 + err = au_wh_name_alloc(&wh_name, base_name);
32927 + wh_dentry = ERR_PTR(err);
32929 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
32930 + kfree(wh_name.name);
32932 + return wh_dentry;
32936 + * link/create a whiteout for @dentry on @bindex.
32938 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
32939 + struct dentry *h_parent)
32941 + struct dentry *wh_dentry;
32942 + struct super_block *sb;
32945 + sb = dentry->d_sb;
32946 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
32947 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
32948 + err = link_or_create_wh(sb, bindex, wh_dentry);
32950 + au_set_dbwh(dentry, bindex);
32951 + au_fhsm_wrote(sb, bindex, /*force*/0);
32954 + wh_dentry = ERR_PTR(err);
32958 + return wh_dentry;
32961 +/* ---------------------------------------------------------------------- */
32963 +/* Delete all whiteouts in this directory on branch bindex. */
32964 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
32965 + aufs_bindex_t bindex, struct au_branch *br)
32968 + unsigned long ul, n;
32969 + struct qstr wh_name;
32971 + struct hlist_head *head;
32972 + struct au_vdir_wh *pos;
32973 + struct au_vdir_destr *str;
32976 + p = (void *)__get_free_page(GFP_NOFS);
32977 + wh_name.name = p;
32978 + if (unlikely(!wh_name.name))
32982 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32983 + p += AUFS_WH_PFX_LEN;
32984 + n = whlist->nh_num;
32985 + head = whlist->nh_head;
32986 + for (ul = 0; !err && ul < n; ul++, head++) {
32987 + hlist_for_each_entry(pos, head, wh_hash) {
32988 + if (pos->wh_bindex != bindex)
32991 + str = &pos->wh_str;
32992 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
32993 + memcpy(p, str->name, str->len);
32994 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
32995 + err = unlink_wh_name(h_dentry, &wh_name, br);
33000 + AuIOErr("whiteout name too long %.*s\n",
33001 + str->len, str->name);
33006 + free_page((unsigned long)wh_name.name);
33012 +struct del_wh_children_args {
33014 + struct dentry *h_dentry;
33015 + struct au_nhash *whlist;
33016 + aufs_bindex_t bindex;
33017 + struct au_branch *br;
33020 +static void call_del_wh_children(void *args)
33022 + struct del_wh_children_args *a = args;
33023 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
33026 +/* ---------------------------------------------------------------------- */
33028 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
33030 + struct au_whtmp_rmdir *whtmp;
33032 + unsigned int rdhash;
33034 + SiMustAnyLock(sb);
33036 + whtmp = kzalloc(sizeof(*whtmp), gfp);
33037 + if (unlikely(!whtmp)) {
33038 + whtmp = ERR_PTR(-ENOMEM);
33042 + /* no estimation for dir size */
33043 + rdhash = au_sbi(sb)->si_rdhash;
33045 + rdhash = AUFS_RDHASH_DEF;
33046 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
33047 + if (unlikely(err)) {
33049 + whtmp = ERR_PTR(err);
33056 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
33059 + au_br_put(whtmp->br);
33060 + dput(whtmp->wh_dentry);
33061 + iput(whtmp->dir);
33062 + au_nhash_wh_free(&whtmp->whlist);
33067 + * rmdir the whiteouted temporary named dir @h_dentry.
33068 + * @whlist: whiteouted children.
33070 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33071 + struct dentry *wh_dentry, struct au_nhash *whlist)
33074 + unsigned int h_nlink;
33075 + struct path h_tmp;
33076 + struct inode *wh_inode, *h_dir;
33077 + struct au_branch *br;
33079 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
33080 + IMustLock(h_dir);
33082 + br = au_sbr(dir->i_sb, bindex);
33083 + wh_inode = d_inode(wh_dentry);
33084 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
33087 + * someone else might change some whiteouts while we were sleeping.
33088 + * it means this whlist may have an obsoleted entry.
33090 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
33091 + err = del_wh_children(wh_dentry, whlist, bindex, br);
33094 + struct del_wh_children_args args = {
33096 + .h_dentry = wh_dentry,
33097 + .whlist = whlist,
33098 + .bindex = bindex,
33102 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
33103 + if (unlikely(wkq_err))
33106 + inode_unlock(wh_inode);
33109 + h_tmp.dentry = wh_dentry;
33110 + h_tmp.mnt = au_br_mnt(br);
33111 + h_nlink = h_dir->i_nlink;
33112 + err = vfsub_rmdir(h_dir, &h_tmp);
33113 + /* some fs doesn't change the parent nlink in some cases */
33114 + h_nlink -= h_dir->i_nlink;
33118 + if (au_ibtop(dir) == bindex) {
33119 + /* todo: dir->i_mutex is necessary */
33120 + au_cpup_attr_timesizes(dir);
33122 + vfsub_drop_nlink(dir);
33124 + return 0; /* success */
33127 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
33131 +static void call_rmdir_whtmp(void *args)
33134 + aufs_bindex_t bindex;
33135 + struct au_whtmp_rmdir *a = args;
33136 + struct super_block *sb;
33137 + struct dentry *h_parent;
33138 + struct inode *h_dir;
33139 + struct au_hinode *hdir;
33141 + /* rmdir by nfsd may cause deadlock with this i_mutex */
33142 + /* inode_lock(a->dir); */
33144 + sb = a->dir->i_sb;
33145 + si_read_lock(sb, !AuLock_FLUSH);
33146 + if (!au_br_writable(a->br->br_perm))
33148 + bindex = au_br_index(sb, a->br->br_id);
33149 + if (unlikely(bindex < 0))
33153 + ii_write_lock_parent(a->dir);
33154 + h_parent = dget_parent(a->wh_dentry);
33155 + h_dir = d_inode(h_parent);
33156 + hdir = au_hi(a->dir, bindex);
33157 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
33158 + if (unlikely(err))
33160 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33161 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
33164 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
33165 + au_hn_inode_unlock(hdir);
33166 + vfsub_mnt_drop_write(au_br_mnt(a->br));
33170 + ii_write_unlock(a->dir);
33172 + /* inode_unlock(a->dir); */
33173 + au_whtmp_rmdir_free(a);
33174 + si_read_unlock(sb);
33175 + au_nwt_done(&au_sbi(sb)->si_nowait);
33176 + if (unlikely(err))
33177 + AuIOErr("err %d\n", err);
33180 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33181 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
33184 + struct super_block *sb;
33188 + /* all post-process will be done in do_rmdir_whtmp(). */
33190 + args->dir = au_igrab(dir);
33191 + args->br = au_sbr(sb, bindex);
33192 + au_br_get(args->br);
33193 + args->wh_dentry = dget(wh_dentry);
33194 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
33195 + if (unlikely(wkq_err)) {
33196 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
33197 + au_whtmp_rmdir_free(args);
33200 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
33201 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
33202 +++ linux/fs/aufs/whout.h 2016-07-25 19:05:34.817826663 +0200
33205 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33207 + * This program, aufs is free software; you can redistribute it and/or modify
33208 + * it under the terms of the GNU General Public License as published by
33209 + * the Free Software Foundation; either version 2 of the License, or
33210 + * (at your option) any later version.
33212 + * This program is distributed in the hope that it will be useful,
33213 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33214 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33215 + * GNU General Public License for more details.
33217 + * You should have received a copy of the GNU General Public License
33218 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33222 + * whiteout for logical deletion and opaque directory
33225 +#ifndef __AUFS_WHOUT_H__
33226 +#define __AUFS_WHOUT_H__
33233 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
33234 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
33235 +int au_diropq_test(struct dentry *h_dentry);
33237 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
33238 + struct qstr *prefix);
33239 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
33240 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33241 + struct dentry *dentry);
33242 +int au_wh_init(struct au_branch *br, struct super_block *sb);
33244 +/* diropq flags */
33245 +#define AuDiropq_CREATE 1
33246 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
33247 +#define au_fset_diropq(flags, name) \
33248 + do { (flags) |= AuDiropq_##name; } while (0)
33249 +#define au_fclr_diropq(flags, name) \
33250 + do { (flags) &= ~AuDiropq_##name; } while (0)
33252 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33253 + unsigned int flags);
33254 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33255 + struct au_branch *br);
33256 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33257 + struct dentry *h_parent);
33259 +/* real rmdir for the whiteout-ed dir */
33260 +struct au_whtmp_rmdir {
33261 + struct inode *dir;
33262 + struct au_branch *br;
33263 + struct dentry *wh_dentry;
33264 + struct au_nhash whlist;
33267 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
33268 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
33269 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33270 + struct dentry *wh_dentry, struct au_nhash *whlist);
33271 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33272 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
33274 +/* ---------------------------------------------------------------------- */
33276 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
33277 + aufs_bindex_t bindex)
33279 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
33282 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
33284 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
33287 +#endif /* __KERNEL__ */
33288 +#endif /* __AUFS_WHOUT_H__ */
33289 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
33290 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
33291 +++ linux/fs/aufs/wkq.c 2016-07-25 19:05:34.817826663 +0200
33294 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33296 + * This program, aufs is free software; you can redistribute it and/or modify
33297 + * it under the terms of the GNU General Public License as published by
33298 + * the Free Software Foundation; either version 2 of the License, or
33299 + * (at your option) any later version.
33301 + * This program is distributed in the hope that it will be useful,
33302 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33303 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33304 + * GNU General Public License for more details.
33306 + * You should have received a copy of the GNU General Public License
33307 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33311 + * workqueue for asynchronous/super-io operations
33312 + * todo: try new dredential scheme
33315 +#include <linux/module.h>
33318 +/* internal workqueue named AUFS_WKQ_NAME */
33320 +static struct workqueue_struct *au_wkq;
33322 +struct au_wkinfo {
33323 + struct work_struct wk;
33324 + struct kobject *kobj;
33326 + unsigned int flags; /* see wkq.h */
33328 + au_wkq_func_t func;
33331 + struct completion *comp;
33334 +/* ---------------------------------------------------------------------- */
33336 +static void wkq_func(struct work_struct *wk)
33338 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
33340 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
33341 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
33343 + wkinfo->func(wkinfo->args);
33344 + if (au_ftest_wkq(wkinfo->flags, WAIT))
33345 + complete(wkinfo->comp);
33347 + kobject_put(wkinfo->kobj);
33348 + module_put(THIS_MODULE); /* todo: ?? */
33354 + * Since struct completion is large, try allocating it dynamically.
33356 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
33357 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33359 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33361 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33363 + init_completion(*comp);
33364 + wkinfo->comp = *comp;
33370 +static void au_wkq_comp_free(struct completion *comp)
33378 +#define AuWkqCompDeclare(name) \
33379 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33380 + struct completion *comp = &_ ## name
33382 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33384 + wkinfo->comp = *comp;
33388 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33392 +#endif /* 4KSTACKS */
33394 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33396 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33397 + if (au_wkq_test()) {
33398 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33399 + " due to a dead dir by UDBA?\n");
33400 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33403 + au_dbg_verify_kthread();
33405 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33406 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33407 + queue_work(au_wkq, &wkinfo->wk);
33409 + INIT_WORK(&wkinfo->wk, wkq_func);
33410 + schedule_work(&wkinfo->wk);
33415 + * Be careful. It is easy to make deadlock happen.
33416 + * processA: lock, wkq and wait
33417 + * processB: wkq and wait, lock in wkq
33420 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33423 + AuWkqCompDeclare(comp);
33424 + struct au_wkinfo wkinfo = {
33430 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33432 + au_wkq_run(&wkinfo);
33433 + /* no timeout, no interrupt */
33434 + wait_for_completion(wkinfo.comp);
33435 + au_wkq_comp_free(comp);
33436 + destroy_work_on_stack(&wkinfo.wk);
33444 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33445 + * problem in a concurrent umounting.
33447 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33448 + unsigned int flags)
33451 + struct au_wkinfo *wkinfo;
33453 + percpu_counter_inc(&au_sbi(sb)->si_nowait.nw_len);
33456 + * wkq_func() must free this wkinfo.
33457 + * it highly depends upon the implementation of workqueue.
33460 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
33462 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
33463 + wkinfo->flags = flags & ~AuWkq_WAIT;
33464 + wkinfo->func = func;
33465 + wkinfo->args = args;
33466 + wkinfo->comp = NULL;
33467 + kobject_get(wkinfo->kobj);
33468 + __module_get(THIS_MODULE); /* todo: ?? */
33470 + au_wkq_run(wkinfo);
33473 + au_nwt_done(&au_sbi(sb)->si_nowait);
33479 +/* ---------------------------------------------------------------------- */
33481 +void au_nwt_init(struct au_nowait_tasks *nwt)
33483 + percpu_counter_init(&nwt->nw_len, 0, GFP_NOFS);
33484 + init_waitqueue_head(&nwt->nw_wq);
33487 +void au_nwt_fin(struct au_nowait_tasks *nwt)
33489 + AuDebugOn(percpu_counter_sum(&nwt->nw_len));
33490 + percpu_counter_destroy(&nwt->nw_len);
33493 +void au_wkq_fin(void)
33495 + destroy_workqueue(au_wkq);
33498 +int __init au_wkq_init(void)
33503 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
33504 + if (IS_ERR(au_wkq))
33505 + err = PTR_ERR(au_wkq);
33506 + else if (!au_wkq)
33511 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
33512 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
33513 +++ linux/fs/aufs/wkq.h 2016-07-25 19:05:34.817826663 +0200
33516 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33518 + * This program, aufs is free software; you can redistribute it and/or modify
33519 + * it under the terms of the GNU General Public License as published by
33520 + * the Free Software Foundation; either version 2 of the License, or
33521 + * (at your option) any later version.
33523 + * This program is distributed in the hope that it will be useful,
33524 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33525 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33526 + * GNU General Public License for more details.
33528 + * You should have received a copy of the GNU General Public License
33529 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33533 + * workqueue for asynchronous/super-io operations
33534 + * todo: try new credentials management scheme
33537 +#ifndef __AUFS_WKQ_H__
33538 +#define __AUFS_WKQ_H__
33542 +#include <linux/percpu_counter.h>
33544 +struct super_block;
33546 +/* ---------------------------------------------------------------------- */
33549 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
33551 +struct au_nowait_tasks {
33552 + struct percpu_counter nw_len;
33553 + wait_queue_head_t nw_wq;
33556 +/* ---------------------------------------------------------------------- */
33558 +typedef void (*au_wkq_func_t)(void *args);
33561 +#define AuWkq_WAIT 1
33562 +#define AuWkq_NEST (1 << 1)
33563 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
33564 +#define au_fset_wkq(flags, name) \
33565 + do { (flags) |= AuWkq_##name; } while (0)
33566 +#define au_fclr_wkq(flags, name) \
33567 + do { (flags) &= ~AuWkq_##name; } while (0)
33569 +#ifndef CONFIG_AUFS_HNOTIFY
33571 +#define AuWkq_NEST 0
33575 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
33576 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33577 + unsigned int flags);
33578 +void au_nwt_init(struct au_nowait_tasks *nwt);
33579 +void au_nwt_fin(struct au_nowait_tasks *nwt);
33580 +int __init au_wkq_init(void);
33581 +void au_wkq_fin(void);
33583 +/* ---------------------------------------------------------------------- */
33585 +static inline int au_wkq_test(void)
33587 + return current->flags & PF_WQ_WORKER;
33590 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
33592 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
33595 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
33597 + percpu_counter_dec(&nwt->nw_len);
33598 + if (!percpu_counter_sum(&nwt->nw_len))
33599 + wake_up_all(&nwt->nw_wq);
33602 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
33604 + wait_event(nwt->nw_wq, !percpu_counter_sum(&nwt->nw_len));
33608 +#endif /* __KERNEL__ */
33609 +#endif /* __AUFS_WKQ_H__ */
33610 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
33611 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
33612 +++ linux/fs/aufs/xattr.c 2016-07-25 19:05:34.817826663 +0200
33615 + * Copyright (C) 2014-2016 Junjiro R. Okajima
33617 + * This program, aufs is free software; you can redistribute it and/or modify
33618 + * it under the terms of the GNU General Public License as published by
33619 + * the Free Software Foundation; either version 2 of the License, or
33620 + * (at your option) any later version.
33622 + * This program is distributed in the hope that it will be useful,
33623 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33624 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33625 + * GNU General Public License for more details.
33627 + * You should have received a copy of the GNU General Public License
33628 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33632 + * handling xattr functions
33635 +#include <linux/xattr.h>
33638 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
33640 + if (!ignore_flags)
33648 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
33653 +#define cmp(brattr, prefix) do { \
33654 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
33655 + XATTR_##prefix##_PREFIX_LEN)) { \
33656 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
33662 + cmp(SEC, SECURITY);
33663 + cmp(SYS, SYSTEM);
33664 + cmp(TR, TRUSTED);
33668 + if (ignore_flags & AuBrAttr_ICEX_OTH)
33675 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
33677 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
33678 + char *name, char **buf, unsigned int ignore_flags,
33679 + unsigned int verbose)
33683 + struct inode *h_idst;
33685 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
33687 + if (unlikely(err <= 0)) {
33688 + if (err == -ENODATA
33689 + || (err == -EOPNOTSUPP
33690 + && ((ignore_flags & au_xattr_out_of_list)
33691 + || (au_test_nfs_noacl(d_inode(h_src))
33692 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
33694 + XATTR_NAME_POSIX_ACL_DEFAULT))))
33697 + if (err && (verbose || au_debug_test()))
33698 + pr_err("%s, err %d\n", name, err);
33702 + /* unlock it temporary */
33703 + h_idst = d_inode(h_dst);
33704 + inode_unlock(h_idst);
33705 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
33706 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
33707 + if (unlikely(err)) {
33708 + if (verbose || au_debug_test())
33709 + pr_err("%s, err %d\n", name, err);
33710 + err = au_xattr_ignore(err, name, ignore_flags);
33717 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
33718 + unsigned int verbose)
33720 + int err, unlocked, acl_access, acl_default;
33722 + struct inode *h_isrc, *h_idst;
33723 + char *value, *p, *o, *e;
33725 + /* try stopping to update the source inode while we are referencing */
33726 + /* there should not be the parent-child relationship between them */
33727 + h_isrc = d_inode(h_src);
33728 + h_idst = d_inode(h_dst);
33729 + inode_unlock(h_idst);
33730 + inode_lock_nested(h_isrc, AuLsc_I_CHILD);
33731 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
33734 + /* some filesystems don't list POSIX ACL, for example tmpfs */
33735 + ssz = vfs_listxattr(h_src, NULL, 0);
33737 + if (unlikely(err < 0)) {
33739 + if (err == -ENODATA
33740 + || err == -EOPNOTSUPP)
33741 + err = 0; /* ignore */
33750 + p = kmalloc(ssz, GFP_NOFS);
33752 + if (unlikely(!p))
33754 + err = vfs_listxattr(h_src, p, ssz);
33756 + inode_unlock(h_isrc);
33758 + AuDbg("err %d, ssz %zd\n", err, ssz);
33759 + if (unlikely(err < 0))
33767 + while (!err && p < e) {
33768 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
33769 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
33770 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
33771 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
33773 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
33775 + p += strlen(p) + 1;
33778 + ignore_flags |= au_xattr_out_of_list;
33779 + if (!err && !acl_access) {
33780 + err = au_do_cpup_xattr(h_dst, h_src,
33781 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
33782 + ignore_flags, verbose);
33785 + if (!err && !acl_default) {
33786 + err = au_do_cpup_xattr(h_dst, h_src,
33787 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
33788 + ignore_flags, verbose);
33798 + inode_unlock(h_isrc);
33803 +/* ---------------------------------------------------------------------- */
33810 +struct au_lgxattr {
33818 + const char *name;
33825 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
33828 + struct path h_path;
33829 + struct super_block *sb;
33831 + sb = dentry->d_sb;
33832 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
33833 + if (unlikely(err))
33835 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
33836 + if (unlikely(err))
33838 + if (unlikely(!h_path.dentry))
33839 + /* illegally overlapped or something */
33840 + goto out_di; /* pretending success */
33842 + /* always topmost entry only */
33843 + switch (arg->type) {
33844 + case AU_XATTR_LIST:
33845 + err = vfs_listxattr(h_path.dentry,
33846 + arg->u.list.list, arg->u.list.size);
33848 + case AU_XATTR_GET:
33849 + AuDebugOn(d_is_negative(h_path.dentry));
33850 + err = vfs_getxattr(h_path.dentry,
33851 + arg->u.get.name, arg->u.get.value,
33852 + arg->u.get.size);
33857 + di_read_unlock(dentry, AuLock_IR);
33859 + si_read_unlock(sb);
33865 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
33867 + struct au_lgxattr arg = {
33868 + .type = AU_XATTR_LIST,
33875 + return au_lgxattr(dentry, &arg);
33878 +ssize_t aufs_getxattr(struct dentry *dentry, struct inode *inode __maybe_unused,
33879 + const char *name, void *value, size_t size)
33881 + struct au_lgxattr arg = {
33882 + .type = AU_XATTR_GET,
33890 + return au_lgxattr(dentry, &arg);
33893 +int aufs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
33894 + const void *value, size_t size, int flags)
33896 + struct au_srxattr arg = {
33897 + .type = AU_XATTR_SET,
33906 + return au_srxattr(dentry, inode, &arg);
33909 +int aufs_removexattr(struct dentry *dentry, const char *name)
33911 + struct au_srxattr arg = {
33912 + .type = AU_XATTR_REMOVE,
33918 + return au_srxattr(dentry, d_inode(dentry), &arg);
33921 +/* ---------------------------------------------------------------------- */
33924 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
33925 + const char *name, size_t name_len, int type)
33927 + return aufs_listxattr(dentry, list, list_size);
33930 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
33931 + size_t size, int type)
33933 + return aufs_getxattr(dentry, name, buffer, size);
33936 +static int au_xattr_set(struct dentry *dentry, const char *name,
33937 + const void *value, size_t size, int flags, int type)
33939 + return aufs_setxattr(dentry, name, value, size, flags);
33942 +static const struct xattr_handler au_xattr_handler = {
33943 + /* no prefix, no flags */
33944 + .list = au_xattr_list,
33945 + .get = au_xattr_get,
33946 + .set = au_xattr_set
33947 + /* why no remove? */
33950 +static const struct xattr_handler *au_xattr_handlers[] = {
33951 + &au_xattr_handler
33954 +void au_xattr_init(struct super_block *sb)
33956 + /* sb->s_xattr = au_xattr_handlers; */
33959 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
33960 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
33961 +++ linux/fs/aufs/xino.c 2016-07-25 19:05:34.817826663 +0200
33964 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33966 + * This program, aufs is free software; you can redistribute it and/or modify
33967 + * it under the terms of the GNU General Public License as published by
33968 + * the Free Software Foundation; either version 2 of the License, or
33969 + * (at your option) any later version.
33971 + * This program is distributed in the hope that it will be useful,
33972 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33973 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33974 + * GNU General Public License for more details.
33976 + * You should have received a copy of the GNU General Public License
33977 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33981 + * external inode number translation table and bitmap
33984 +#include <linux/seq_file.h>
33985 +#include <linux/statfs.h>
33988 +/* todo: unnecessary to support mmap_sem since kernel-space? */
33989 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
33993 + mm_segment_t oldfs;
34000 + oldfs = get_fs();
34001 + set_fs(KERNEL_DS);
34003 + /* todo: signal_pending? */
34004 + err = func(file, buf.u, size, pos);
34005 + } while (err == -EAGAIN || err == -EINTR);
34008 +#if 0 /* reserved for future use */
34010 + fsnotify_access(file->f_path.dentry);
34016 +/* ---------------------------------------------------------------------- */
34018 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34019 + size_t size, loff_t *pos);
34021 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
34022 + size_t size, loff_t *pos)
34025 + mm_segment_t oldfs;
34028 + const char __user *u;
34031 + const int prevent_endless = 10;
34035 + oldfs = get_fs();
34036 + set_fs(KERNEL_DS);
34038 + err = func(file, buf.u, size, pos);
34039 + if (err == -EINTR
34040 + && !au_wkq_test()
34041 + && fatal_signal_pending(current)) {
34043 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
34044 + BUG_ON(err == -EINTR);
34045 + oldfs = get_fs();
34046 + set_fs(KERNEL_DS);
34048 + } while (i++ < prevent_endless
34049 + && (err == -EAGAIN || err == -EINTR));
34052 +#if 0 /* reserved for future use */
34054 + fsnotify_modify(file->f_path.dentry);
34060 +struct do_xino_fwrite_args {
34062 + vfs_writef_t func;
34063 + struct file *file;
34069 +static void call_do_xino_fwrite(void *args)
34071 + struct do_xino_fwrite_args *a = args;
34072 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
34075 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34076 + size_t size, loff_t *pos)
34080 + struct do_xino_fwrite_args args = {
34090 + * it breaks RLIMIT_FSIZE and normal user's limit,
34091 + * users should care about quota and real 'filesystem full.'
34093 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
34094 + if (unlikely(wkq_err))
34100 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
34101 + size_t size, loff_t *pos)
34105 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
34107 + err = do_xino_fwrite(func, file, buf, size, pos);
34110 + err = xino_fwrite_wkq(func, file, buf, size, pos);
34115 +/* ---------------------------------------------------------------------- */
34118 + * create a new xinofile at the same place/path as @base_file.
34120 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
34122 + struct file *file;
34123 + struct dentry *base, *parent;
34124 + struct inode *dir, *delegated;
34125 + struct qstr *name;
34126 + struct path path;
34129 + base = base_file->f_path.dentry;
34130 + parent = base->d_parent; /* dir inode is locked */
34131 + dir = d_inode(parent);
34134 + file = ERR_PTR(-EINVAL);
34135 + name = &base->d_name;
34136 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
34137 + if (IS_ERR(path.dentry)) {
34138 + file = (void *)path.dentry;
34139 + pr_err("%pd lookup err %ld\n",
34140 + base, PTR_ERR(path.dentry));
34144 + /* no need to mnt_want_write() since we call dentry_open() later */
34145 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
34146 + if (unlikely(err)) {
34147 + file = ERR_PTR(err);
34148 + pr_err("%pd create err %d\n", base, err);
34152 + path.mnt = base_file->f_path.mnt;
34153 + file = vfsub_dentry_open(&path,
34154 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34155 + /* | __FMODE_NONOTIFY */);
34156 + if (IS_ERR(file)) {
34157 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
34161 + delegated = NULL;
34162 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
34163 + if (unlikely(err == -EWOULDBLOCK)) {
34164 + pr_warn("cannot retry for NFSv4 delegation"
34165 + " for an internal unlink\n");
34168 + if (unlikely(err)) {
34169 + pr_err("%pd unlink err %d\n", base, err);
34174 + /* no one can touch copy_src xino */
34175 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
34176 + if (unlikely(err)) {
34177 + pr_err("%pd copy err %d\n", base, err);
34181 + goto out_dput; /* success */
34185 + file = ERR_PTR(err);
34187 + dput(path.dentry);
34192 +struct au_xino_lock_dir {
34193 + struct au_hinode *hdir;
34194 + struct dentry *parent;
34195 + struct inode *dir;
34198 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
34199 + struct au_xino_lock_dir *ldir)
34201 + aufs_bindex_t brid, bindex;
34203 + ldir->hdir = NULL;
34205 + brid = au_xino_brid(sb);
34207 + bindex = au_br_index(sb, brid);
34208 + if (bindex >= 0) {
34209 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
34210 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
34212 + ldir->parent = dget_parent(xino->f_path.dentry);
34213 + ldir->dir = d_inode(ldir->parent);
34214 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
34218 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
34221 + au_hn_inode_unlock(ldir->hdir);
34223 + inode_unlock(ldir->dir);
34224 + dput(ldir->parent);
34228 +/* ---------------------------------------------------------------------- */
34230 +/* trucate xino files asynchronously */
34232 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
34235 + unsigned long jiffy;
34237 + aufs_bindex_t bi, bbot;
34238 + struct kstatfs *st;
34239 + struct au_branch *br;
34240 + struct file *new_xino, *file;
34241 + struct super_block *h_sb;
34242 + struct au_xino_lock_dir ldir;
34245 + st = kmalloc(sizeof(*st), GFP_NOFS);
34246 + if (unlikely(!st))
34250 + bbot = au_sbbot(sb);
34251 + if (unlikely(bindex < 0 || bbot < bindex))
34253 + br = au_sbr(sb, bindex);
34254 + file = br->br_xino.xi_file;
34258 + err = vfs_statfs(&file->f_path, st);
34259 + if (unlikely(err))
34260 + AuErr1("statfs err %d, ignored\n", err);
34262 + blocks = file_inode(file)->i_blocks;
34263 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34264 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
34266 + au_xino_lock_dir(sb, file, &ldir);
34267 + /* mnt_want_write() is unnecessary here */
34268 + new_xino = au_xino_create2(file, file);
34269 + au_xino_unlock_dir(&ldir);
34270 + err = PTR_ERR(new_xino);
34271 + if (IS_ERR(new_xino)) {
34272 + pr_err("err %d, ignored\n", err);
34277 + br->br_xino.xi_file = new_xino;
34279 + h_sb = au_br_sb(br);
34280 + for (bi = 0; bi <= bbot; bi++) {
34281 + if (unlikely(bi == bindex))
34283 + br = au_sbr(sb, bi);
34284 + if (au_br_sb(br) != h_sb)
34287 + fput(br->br_xino.xi_file);
34288 + br->br_xino.xi_file = new_xino;
34289 + get_file(new_xino);
34292 + err = vfs_statfs(&new_xino->f_path, st);
34294 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34295 + bindex, (u64)file_inode(new_xino)->i_blocks,
34296 + st->f_bfree, st->f_blocks);
34297 + if (file_inode(new_xino)->i_blocks < blocks)
34298 + au_sbi(sb)->si_xino_jiffy = jiffy;
34300 + AuErr1("statfs err %d, ignored\n", err);
34308 +struct xino_do_trunc_args {
34309 + struct super_block *sb;
34310 + struct au_branch *br;
34313 +static void xino_do_trunc(void *_args)
34315 + struct xino_do_trunc_args *args = _args;
34316 + struct super_block *sb;
34317 + struct au_branch *br;
34318 + struct inode *dir;
34320 + aufs_bindex_t bindex;
34324 + dir = d_inode(sb->s_root);
34327 + si_noflush_write_lock(sb);
34328 + ii_read_lock_parent(dir);
34329 + bindex = au_br_index(sb, br->br_id);
34330 + err = au_xino_trunc(sb, bindex);
34331 + ii_read_unlock(dir);
34332 + if (unlikely(err))
34333 + pr_warn("err b%d, (%d)\n", bindex, err);
34334 + atomic_dec(&br->br_xino_running);
34336 + si_write_unlock(sb);
34337 + au_nwt_done(&au_sbi(sb)->si_nowait);
34341 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
34344 + struct kstatfs st;
34345 + struct au_sbinfo *sbinfo;
34347 + /* todo: si_xino_expire and the ratio should be customizable */
34348 + sbinfo = au_sbi(sb);
34349 + if (time_before(jiffies,
34350 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
34353 + /* truncation border */
34354 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
34355 + if (unlikely(err)) {
34356 + AuErr1("statfs err %d, ignored\n", err);
34359 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
34365 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
34367 + struct xino_do_trunc_args *args;
34370 + if (!xino_trunc_test(sb, br))
34373 + if (atomic_inc_return(&br->br_xino_running) > 1)
34376 + /* lock and kfree() will be called in trunc_xino() */
34377 + args = kmalloc(sizeof(*args), GFP_NOFS);
34378 + if (unlikely(!args)) {
34379 + AuErr1("no memory\n");
34386 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
34388 + return; /* success */
34390 + pr_err("wkq %d\n", wkq_err);
34396 + atomic_dec(&br->br_xino_running);
34399 +/* ---------------------------------------------------------------------- */
34401 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34402 + ino_t h_ino, ino_t ino)
34408 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34409 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34412 + pos *= sizeof(ino);
34413 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34414 + if (sz == sizeof(ino))
34415 + return 0; /* success */
34417 + AuIOErr("write failed (%zd)\n", sz);
34422 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34423 + * at the position of @h_ino.
34424 + * even if @ino is zero, it is written to the xinofile and means no entry.
34425 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34426 + * try truncating it.
34428 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34432 + unsigned int mnt_flags;
34433 + struct au_branch *br;
34435 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34436 + || ((loff_t)-1) > 0);
34437 + SiMustAnyLock(sb);
34439 + mnt_flags = au_mntflags(sb);
34440 + if (!au_opt_test(mnt_flags, XINO))
34443 + br = au_sbr(sb, bindex);
34444 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34447 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34448 + && au_test_fs_trunc_xino(au_br_sb(br)))
34449 + xino_try_trunc(sb, br);
34450 + return 0; /* success */
34453 + AuIOErr("write failed (%d)\n", err);
34457 +/* ---------------------------------------------------------------------- */
34459 +/* aufs inode number bitmap */
34461 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
34462 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
34466 + AuDebugOn(bit < 0 || page_bits <= bit);
34467 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
34471 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
34473 + AuDebugOn(ino < AUFS_FIRST_INO);
34474 + ino -= AUFS_FIRST_INO;
34475 + *pindex = ino / page_bits;
34476 + *bit = ino % page_bits;
34479 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
34484 + struct au_sbinfo *sbinfo;
34485 + struct file *xib;
34486 + unsigned long *p;
34488 + sbinfo = au_sbi(sb);
34489 + MtxMustLock(&sbinfo->si_xib_mtx);
34490 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
34491 + || !au_opt_test(sbinfo->si_mntflags, XINO));
34493 + if (pindex == sbinfo->si_xib_last_pindex)
34496 + xib = sbinfo->si_xib;
34497 + p = sbinfo->si_xib_buf;
34498 + pos = sbinfo->si_xib_last_pindex;
34499 + pos *= PAGE_SIZE;
34500 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34501 + if (unlikely(sz != PAGE_SIZE))
34505 + pos *= PAGE_SIZE;
34506 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
34507 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
34509 + memset(p, 0, PAGE_SIZE);
34510 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34512 + if (sz == PAGE_SIZE) {
34513 + sbinfo->si_xib_last_pindex = pindex;
34514 + return 0; /* success */
34518 + AuIOErr1("write failed (%zd)\n", sz);
34525 +/* ---------------------------------------------------------------------- */
34527 +static void au_xib_clear_bit(struct inode *inode)
34530 + unsigned long pindex;
34531 + struct super_block *sb;
34532 + struct au_sbinfo *sbinfo;
34534 + AuDebugOn(inode->i_nlink);
34536 + sb = inode->i_sb;
34537 + xib_calc_bit(inode->i_ino, &pindex, &bit);
34538 + AuDebugOn(page_bits <= bit);
34539 + sbinfo = au_sbi(sb);
34540 + mutex_lock(&sbinfo->si_xib_mtx);
34541 + err = xib_pindex(sb, pindex);
34543 + clear_bit(bit, sbinfo->si_xib_buf);
34544 + sbinfo->si_xib_next_bit = bit;
34546 + mutex_unlock(&sbinfo->si_xib_mtx);
34549 +/* for s_op->delete_inode() */
34550 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
34553 + unsigned int mnt_flags;
34554 + aufs_bindex_t bindex, bbot, bi;
34555 + unsigned char try_trunc;
34556 + struct au_iinfo *iinfo;
34557 + struct super_block *sb;
34558 + struct au_hinode *hi;
34559 + struct inode *h_inode;
34560 + struct au_branch *br;
34561 + vfs_writef_t xwrite;
34563 + AuDebugOn(au_is_bad_inode(inode));
34565 + sb = inode->i_sb;
34566 + mnt_flags = au_mntflags(sb);
34567 + if (!au_opt_test(mnt_flags, XINO)
34568 + || inode->i_ino == AUFS_ROOT_INO)
34572 + au_xigen_inc(inode);
34573 + au_xib_clear_bit(inode);
34576 + iinfo = au_ii(inode);
34577 + bindex = iinfo->ii_btop;
34581 + xwrite = au_sbi(sb)->si_xwrite;
34582 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
34583 + hi = au_hinode(iinfo, bindex);
34584 + bbot = iinfo->ii_bbot;
34585 + for (; bindex <= bbot; bindex++, hi++) {
34586 + h_inode = hi->hi_inode;
34588 + || (!unlinked && h_inode->i_nlink))
34591 + /* inode may not be revalidated */
34592 + bi = au_br_index(sb, hi->hi_id);
34596 + br = au_sbr(sb, bi);
34597 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
34598 + h_inode->i_ino, /*ino*/0);
34599 + if (!err && try_trunc
34600 + && au_test_fs_trunc_xino(au_br_sb(br)))
34601 + xino_try_trunc(sb, br);
34605 +/* get an unused inode number from bitmap */
34606 +ino_t au_xino_new_ino(struct super_block *sb)
34609 + unsigned long *p, pindex, ul, pend;
34610 + struct au_sbinfo *sbinfo;
34611 + struct file *file;
34612 + int free_bit, err;
34614 + if (!au_opt_test(au_mntflags(sb), XINO))
34615 + return iunique(sb, AUFS_FIRST_INO);
34617 + sbinfo = au_sbi(sb);
34618 + mutex_lock(&sbinfo->si_xib_mtx);
34619 + p = sbinfo->si_xib_buf;
34620 + free_bit = sbinfo->si_xib_next_bit;
34621 + if (free_bit < page_bits && !test_bit(free_bit, p))
34622 + goto out; /* success */
34623 + free_bit = find_first_zero_bit(p, page_bits);
34624 + if (free_bit < page_bits)
34625 + goto out; /* success */
34627 + pindex = sbinfo->si_xib_last_pindex;
34628 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
34629 + err = xib_pindex(sb, ul);
34630 + if (unlikely(err))
34632 + free_bit = find_first_zero_bit(p, page_bits);
34633 + if (free_bit < page_bits)
34634 + goto out; /* success */
34637 + file = sbinfo->si_xib;
34638 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
34639 + for (ul = pindex + 1; ul <= pend; ul++) {
34640 + err = xib_pindex(sb, ul);
34641 + if (unlikely(err))
34643 + free_bit = find_first_zero_bit(p, page_bits);
34644 + if (free_bit < page_bits)
34645 + goto out; /* success */
34650 + set_bit(free_bit, p);
34651 + sbinfo->si_xib_next_bit = free_bit + 1;
34652 + pindex = sbinfo->si_xib_last_pindex;
34653 + mutex_unlock(&sbinfo->si_xib_mtx);
34654 + ino = xib_calc_ino(pindex, free_bit);
34655 + AuDbg("i%lu\n", (unsigned long)ino);
34658 + mutex_unlock(&sbinfo->si_xib_mtx);
34664 + * read @ino from xinofile for the specified branch{@sb, @bindex}
34665 + * at the position of @h_ino.
34666 + * if @ino does not exist and @do_new is true, get new one.
34668 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34674 + struct file *file;
34675 + struct au_sbinfo *sbinfo;
34678 + if (!au_opt_test(au_mntflags(sb), XINO))
34679 + return 0; /* no xino */
34682 + sbinfo = au_sbi(sb);
34684 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
34685 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34688 + pos *= sizeof(*ino);
34690 + file = au_sbr(sb, bindex)->br_xino.xi_file;
34691 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
34692 + return 0; /* no ino */
34694 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
34695 + if (sz == sizeof(*ino))
34696 + return 0; /* success */
34699 + if (unlikely(sz >= 0)) {
34701 + AuIOErr("xino read error (%zd)\n", sz);
34707 +/* ---------------------------------------------------------------------- */
34709 +/* create and set a new xino file */
34711 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
34713 + struct file *file;
34714 + struct dentry *h_parent, *d;
34715 + struct inode *h_dir, *inode;
34719 + * at mount-time, and the xino file is the default path,
34720 + * hnotify is disabled so we have no notify events to ignore.
34721 + * when a user specified the xino, we cannot get au_hdir to be ignored.
34723 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34724 + /* | __FMODE_NONOTIFY */,
34725 + S_IRUGO | S_IWUGO);
34726 + if (IS_ERR(file)) {
34728 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
34732 + /* keep file count */
34734 + inode = file_inode(file);
34735 + h_parent = dget_parent(file->f_path.dentry);
34736 + h_dir = d_inode(h_parent);
34737 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
34738 + /* mnt_want_write() is unnecessary here */
34739 + /* no delegation since it is just created */
34740 + if (inode->i_nlink)
34741 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
34743 + inode_unlock(h_dir);
34745 + if (unlikely(err)) {
34747 + pr_err("unlink %s(%d)\n", fname, err);
34752 + d = file->f_path.dentry;
34753 + if (unlikely(sb == d->d_sb)) {
34755 + pr_err("%s must be outside\n", fname);
34758 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
34760 + pr_err("xino doesn't support %s(%s)\n",
34761 + fname, au_sbtype(d->d_sb));
34764 + return file; /* success */
34768 + file = ERR_PTR(err);
34773 + * find another branch who is on the same filesystem of the specified
34774 + * branch{@btgt}. search until @bbot.
34776 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
34777 + aufs_bindex_t bbot)
34779 + aufs_bindex_t bindex;
34780 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
34782 + for (bindex = 0; bindex < btgt; bindex++)
34783 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34785 + for (bindex++; bindex <= bbot; bindex++)
34786 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
34791 +/* ---------------------------------------------------------------------- */
34794 + * initialize the xinofile for the specified branch @br
34795 + * at the place/path where @base_file indicates.
34796 + * test whether another branch is on the same filesystem or not,
34797 + * if @do_test is true.
34799 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
34800 + struct file *base_file, int do_test)
34804 + aufs_bindex_t bbot, bindex;
34805 + struct au_branch *shared_br, *b;
34806 + struct file *file;
34807 + struct super_block *tgt_sb;
34809 + shared_br = NULL;
34810 + bbot = au_sbbot(sb);
34812 + tgt_sb = au_br_sb(br);
34813 + for (bindex = 0; bindex <= bbot; bindex++) {
34814 + b = au_sbr(sb, bindex);
34815 + if (tgt_sb == au_br_sb(b)) {
34822 + if (!shared_br || !shared_br->br_xino.xi_file) {
34823 + struct au_xino_lock_dir ldir;
34825 + au_xino_lock_dir(sb, base_file, &ldir);
34826 + /* mnt_want_write() is unnecessary here */
34827 + file = au_xino_create2(base_file, NULL);
34828 + au_xino_unlock_dir(&ldir);
34829 + err = PTR_ERR(file);
34830 + if (IS_ERR(file))
34832 + br->br_xino.xi_file = file;
34834 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
34835 + get_file(br->br_xino.xi_file);
34838 + ino = AUFS_ROOT_INO;
34839 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34841 + if (unlikely(err)) {
34842 + fput(br->br_xino.xi_file);
34843 + br->br_xino.xi_file = NULL;
34850 +/* ---------------------------------------------------------------------- */
34852 +/* trucate a xino bitmap file */
34855 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
34859 + unsigned long pindex;
34860 + loff_t pos, pend;
34861 + struct au_sbinfo *sbinfo;
34862 + vfs_readf_t func;
34864 + unsigned long *p;
34867 + sbinfo = au_sbi(sb);
34868 + MtxMustLock(&sbinfo->si_xib_mtx);
34869 + p = sbinfo->si_xib_buf;
34870 + func = sbinfo->si_xread;
34871 + pend = vfsub_f_size_read(file);
34873 + while (pos < pend) {
34874 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
34876 + if (unlikely(sz <= 0))
34880 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
34881 + if (unlikely(*ino < AUFS_FIRST_INO))
34884 + xib_calc_bit(*ino, &pindex, &bit);
34885 + AuDebugOn(page_bits <= bit);
34886 + err = xib_pindex(sb, pindex);
34898 +static int xib_restore(struct super_block *sb)
34901 + aufs_bindex_t bindex, bbot;
34905 + page = (void *)__get_free_page(GFP_NOFS);
34906 + if (unlikely(!page))
34910 + bbot = au_sbbot(sb);
34911 + for (bindex = 0; !err && bindex <= bbot; bindex++)
34912 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
34913 + err = do_xib_restore
34914 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
34916 + AuDbg("b%d\n", bindex);
34917 + free_page((unsigned long)page);
34923 +int au_xib_trunc(struct super_block *sb)
34928 + struct au_xino_lock_dir ldir;
34929 + struct au_sbinfo *sbinfo;
34930 + unsigned long *p;
34931 + struct file *file;
34933 + SiMustWriteLock(sb);
34936 + sbinfo = au_sbi(sb);
34937 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
34940 + file = sbinfo->si_xib;
34941 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
34944 + au_xino_lock_dir(sb, file, &ldir);
34945 + /* mnt_want_write() is unnecessary here */
34946 + file = au_xino_create2(sbinfo->si_xib, NULL);
34947 + au_xino_unlock_dir(&ldir);
34948 + err = PTR_ERR(file);
34949 + if (IS_ERR(file))
34951 + fput(sbinfo->si_xib);
34952 + sbinfo->si_xib = file;
34954 + p = sbinfo->si_xib_buf;
34955 + memset(p, 0, PAGE_SIZE);
34957 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
34958 + if (unlikely(sz != PAGE_SIZE)) {
34960 + AuIOErr("err %d\n", err);
34966 + mutex_lock(&sbinfo->si_xib_mtx);
34967 + /* mnt_want_write() is unnecessary here */
34968 + err = xib_restore(sb);
34969 + mutex_unlock(&sbinfo->si_xib_mtx);
34975 +/* ---------------------------------------------------------------------- */
34978 + * xino mount option handlers
34982 +static void xino_clear_xib(struct super_block *sb)
34984 + struct au_sbinfo *sbinfo;
34986 + SiMustWriteLock(sb);
34988 + sbinfo = au_sbi(sb);
34989 + sbinfo->si_xread = NULL;
34990 + sbinfo->si_xwrite = NULL;
34991 + if (sbinfo->si_xib)
34992 + fput(sbinfo->si_xib);
34993 + sbinfo->si_xib = NULL;
34994 + free_page((unsigned long)sbinfo->si_xib_buf);
34995 + sbinfo->si_xib_buf = NULL;
34998 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
35002 + struct au_sbinfo *sbinfo;
35003 + struct file *file;
35005 + SiMustWriteLock(sb);
35007 + sbinfo = au_sbi(sb);
35008 + file = au_xino_create2(base, sbinfo->si_xib);
35009 + err = PTR_ERR(file);
35010 + if (IS_ERR(file))
35012 + if (sbinfo->si_xib)
35013 + fput(sbinfo->si_xib);
35014 + sbinfo->si_xib = file;
35015 + sbinfo->si_xread = vfs_readf(file);
35016 + sbinfo->si_xwrite = vfs_writef(file);
35019 + if (!sbinfo->si_xib_buf)
35020 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
35021 + if (unlikely(!sbinfo->si_xib_buf))
35024 + sbinfo->si_xib_last_pindex = 0;
35025 + sbinfo->si_xib_next_bit = 0;
35026 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
35028 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
35029 + PAGE_SIZE, &pos);
35030 + if (unlikely(err != PAGE_SIZE))
35034 + goto out; /* success */
35037 + free_page((unsigned long)sbinfo->si_xib_buf);
35038 + sbinfo->si_xib_buf = NULL;
35042 + fput(sbinfo->si_xib);
35043 + sbinfo->si_xib = NULL;
35044 + sbinfo->si_xread = NULL;
35045 + sbinfo->si_xwrite = NULL;
35050 +/* xino for each branch */
35051 +static void xino_clear_br(struct super_block *sb)
35053 + aufs_bindex_t bindex, bbot;
35054 + struct au_branch *br;
35056 + bbot = au_sbbot(sb);
35057 + for (bindex = 0; bindex <= bbot; bindex++) {
35058 + br = au_sbr(sb, bindex);
35059 + if (!br || !br->br_xino.xi_file)
35062 + fput(br->br_xino.xi_file);
35063 + br->br_xino.xi_file = NULL;
35067 +static int au_xino_set_br(struct super_block *sb, struct file *base)
35071 + aufs_bindex_t bindex, bbot, bshared;
35073 + struct file *old, *new;
35075 + struct au_branch *br;
35076 + struct inode *inode;
35077 + vfs_writef_t writef;
35079 + SiMustWriteLock(sb);
35082 + bbot = au_sbbot(sb);
35083 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
35084 + if (unlikely(!fpair))
35087 + inode = d_inode(sb->s_root);
35088 + ino = AUFS_ROOT_INO;
35089 + writef = au_sbi(sb)->si_xwrite;
35090 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35091 + bshared = is_sb_shared(sb, bindex, bindex - 1);
35092 + if (bshared >= 0) {
35093 + /* shared xino */
35094 + *p = fpair[bshared];
35095 + get_file(p->new);
35100 + br = au_sbr(sb, bindex);
35101 + p->old = br->br_xino.xi_file;
35102 + p->new = au_xino_create2(base, br->br_xino.xi_file);
35103 + err = PTR_ERR(p->new);
35104 + if (IS_ERR(p->new)) {
35110 + err = au_xino_do_write(writef, p->new,
35111 + au_h_iptr(inode, bindex)->i_ino, ino);
35112 + if (unlikely(err))
35116 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35117 + br = au_sbr(sb, bindex);
35118 + if (br->br_xino.xi_file)
35119 + fput(br->br_xino.xi_file);
35120 + get_file(p->new);
35121 + br->br_xino.xi_file = p->new;
35125 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
35135 +void au_xino_clr(struct super_block *sb)
35137 + struct au_sbinfo *sbinfo;
35139 + au_xigen_clr(sb);
35140 + xino_clear_xib(sb);
35141 + xino_clear_br(sb);
35142 + sbinfo = au_sbi(sb);
35143 + /* lvalue, do not call au_mntflags() */
35144 + au_opt_clr(sbinfo->si_mntflags, XINO);
35147 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
35150 + struct dentry *parent, *cur_parent;
35151 + struct qstr *dname, *cur_name;
35152 + struct file *cur_xino;
35153 + struct inode *dir;
35154 + struct au_sbinfo *sbinfo;
35156 + SiMustWriteLock(sb);
35159 + sbinfo = au_sbi(sb);
35160 + parent = dget_parent(xino->file->f_path.dentry);
35163 + dname = &xino->file->f_path.dentry->d_name;
35164 + cur_xino = sbinfo->si_xib;
35166 + cur_parent = dget_parent(cur_xino->f_path.dentry);
35167 + cur_name = &cur_xino->f_path.dentry->d_name;
35168 + skip = (cur_parent == parent
35169 + && au_qstreq(dname, cur_name));
35170 + dput(cur_parent);
35176 + au_opt_set(sbinfo->si_mntflags, XINO);
35177 + dir = d_inode(parent);
35178 + inode_lock_nested(dir, AuLsc_I_PARENT);
35179 + /* mnt_want_write() is unnecessary here */
35180 + err = au_xino_set_xib(sb, xino->file);
35182 + err = au_xigen_set(sb, xino->file);
35184 + err = au_xino_set_br(sb, xino->file);
35185 + inode_unlock(dir);
35187 + goto out; /* success */
35190 + AuIOErr("failed creating xino(%d).\n", err);
35191 + au_xigen_clr(sb);
35192 + xino_clear_xib(sb);
35199 +/* ---------------------------------------------------------------------- */
35202 + * create a xinofile at the default place/path.
35204 +struct file *au_xino_def(struct super_block *sb)
35206 + struct file *file;
35208 + struct au_branch *br;
35209 + struct super_block *h_sb;
35210 + struct path path;
35211 + aufs_bindex_t bbot, bindex, bwr;
35214 + bbot = au_sbbot(sb);
35216 + for (bindex = 0; bindex <= bbot; bindex++) {
35217 + br = au_sbr(sb, bindex);
35218 + if (au_br_writable(br->br_perm)
35219 + && !au_test_fs_bad_xino(au_br_sb(br))) {
35226 + file = ERR_PTR(-ENOMEM);
35227 + page = (void *)__get_free_page(GFP_NOFS);
35228 + if (unlikely(!page))
35230 + path.mnt = au_br_mnt(br);
35231 + path.dentry = au_h_dptr(sb->s_root, bwr);
35232 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
35233 + file = (void *)p;
35234 + if (!IS_ERR(p)) {
35235 + strcat(p, "/" AUFS_XINO_FNAME);
35236 + AuDbg("%s\n", p);
35237 + file = au_xino_create(sb, p, /*silent*/0);
35238 + if (!IS_ERR(file))
35239 + au_xino_brid_set(sb, br->br_id);
35241 + free_page((unsigned long)page);
35243 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
35244 + if (IS_ERR(file))
35246 + h_sb = file->f_path.dentry->d_sb;
35247 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
35248 + pr_err("xino doesn't support %s(%s)\n",
35249 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
35251 + file = ERR_PTR(-EINVAL);
35253 + if (!IS_ERR(file))
35254 + au_xino_brid_set(sb, -1);
35261 +/* ---------------------------------------------------------------------- */
35263 +int au_xino_path(struct seq_file *seq, struct file *file)
35267 + err = au_seq_path(seq, &file->f_path);
35268 + if (unlikely(err))
35271 +#define Deleted "\\040(deleted)"
35272 + seq->count -= sizeof(Deleted) - 1;
35273 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
35274 + sizeof(Deleted) - 1));
35280 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
35281 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
35282 +++ linux/include/uapi/linux/aufs_type.h 2016-07-25 19:05:34.817826663 +0200
35285 + * Copyright (C) 2005-2016 Junjiro R. Okajima
35287 + * This program, aufs is free software; you can redistribute it and/or modify
35288 + * it under the terms of the GNU General Public License as published by
35289 + * the Free Software Foundation; either version 2 of the License, or
35290 + * (at your option) any later version.
35292 + * This program is distributed in the hope that it will be useful,
35293 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35294 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35295 + * GNU General Public License for more details.
35297 + * You should have received a copy of the GNU General Public License
35298 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35301 +#ifndef __AUFS_TYPE_H__
35302 +#define __AUFS_TYPE_H__
35304 +#define AUFS_NAME "aufs"
35308 + * define it before including all other headers.
35309 + * sched.h may use pr_* macros before defining "current", so define the
35310 + * no-current version first, and re-define later.
35312 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
35313 +#include <linux/sched.h>
35315 +#define pr_fmt(fmt) \
35316 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
35317 + (int)sizeof(current->comm), current->comm, current->pid
35319 +#include <stdint.h>
35320 +#include <sys/types.h>
35321 +#endif /* __KERNEL__ */
35323 +#include <linux/limits.h>
35325 +#define AUFS_VERSION "4.x-rcN-20160704"
35327 +/* todo? move this to linux-2.6.19/include/magic.h */
35328 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
35330 +/* ---------------------------------------------------------------------- */
35332 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
35333 +typedef int8_t aufs_bindex_t;
35334 +#define AUFS_BRANCH_MAX 127
35336 +typedef int16_t aufs_bindex_t;
35337 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
35338 +#define AUFS_BRANCH_MAX 511
35339 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
35340 +#define AUFS_BRANCH_MAX 1023
35341 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
35342 +#define AUFS_BRANCH_MAX 32767
35347 +#ifndef AUFS_BRANCH_MAX
35348 +#error unknown CONFIG_AUFS_BRANCH_MAX value
35350 +#endif /* __KERNEL__ */
35352 +/* ---------------------------------------------------------------------- */
35354 +#define AUFS_FSTYPE AUFS_NAME
35356 +#define AUFS_ROOT_INO 2
35357 +#define AUFS_FIRST_INO 11
35359 +#define AUFS_WH_PFX ".wh."
35360 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
35361 +#define AUFS_WH_TMP_LEN 4
35362 +/* a limit for rmdir/rename a dir and copyup */
35363 +#define AUFS_MAX_NAMELEN (NAME_MAX \
35364 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
35366 + - AUFS_WH_TMP_LEN) /* hex */
35367 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
35368 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
35369 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
35370 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
35371 +#define AUFS_DIRWH_DEF 3
35372 +#define AUFS_RDCACHE_DEF 10 /* seconds */
35373 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
35374 +#define AUFS_RDBLK_DEF 512 /* bytes */
35375 +#define AUFS_RDHASH_DEF 32
35376 +#define AUFS_WKQ_NAME AUFS_NAME "d"
35377 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
35378 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
35379 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
35380 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
35382 +/* pseudo-link maintenace under /proc */
35383 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
35384 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
35385 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
35387 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
35388 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
35390 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
35391 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
35392 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
35394 +/* doubly whiteouted */
35395 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
35396 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
35397 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
35399 +/* branch permissions and attributes */
35400 +#define AUFS_BRPERM_RW "rw"
35401 +#define AUFS_BRPERM_RO "ro"
35402 +#define AUFS_BRPERM_RR "rr"
35403 +#define AUFS_BRATTR_COO_REG "coo_reg"
35404 +#define AUFS_BRATTR_COO_ALL "coo_all"
35405 +#define AUFS_BRATTR_FHSM "fhsm"
35406 +#define AUFS_BRATTR_UNPIN "unpin"
35407 +#define AUFS_BRATTR_ICEX "icex"
35408 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
35409 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
35410 +#define AUFS_BRATTR_ICEX_TR "icextr"
35411 +#define AUFS_BRATTR_ICEX_USR "icexusr"
35412 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
35413 +#define AUFS_BRRATTR_WH "wh"
35414 +#define AUFS_BRWATTR_NLWH "nolwh"
35415 +#define AUFS_BRWATTR_MOO "moo"
35417 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
35418 +#define AuBrPerm_RO (1 << 1) /* readonly */
35419 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
35420 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
35422 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
35423 +#define AuBrAttr_COO_ALL (1 << 4)
35424 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
35426 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
35427 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
35428 + branch. meaningless since
35429 + linux-3.18-rc1 */
35431 +/* ignore error in copying XATTR */
35432 +#define AuBrAttr_ICEX_SEC (1 << 7)
35433 +#define AuBrAttr_ICEX_SYS (1 << 8)
35434 +#define AuBrAttr_ICEX_TR (1 << 9)
35435 +#define AuBrAttr_ICEX_USR (1 << 10)
35436 +#define AuBrAttr_ICEX_OTH (1 << 11)
35437 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
35438 + | AuBrAttr_ICEX_SYS \
35439 + | AuBrAttr_ICEX_TR \
35440 + | AuBrAttr_ICEX_USR \
35441 + | AuBrAttr_ICEX_OTH)
35443 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
35444 +#define AuBrRAttr_Mask AuBrRAttr_WH
35446 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
35447 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
35448 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
35450 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
35452 +/* #warning test userspace */
35454 +#ifndef CONFIG_AUFS_FHSM
35455 +#undef AuBrAttr_FHSM
35456 +#define AuBrAttr_FHSM 0
35458 +#ifndef CONFIG_AUFS_XATTR
35459 +#undef AuBrAttr_ICEX
35460 +#define AuBrAttr_ICEX 0
35461 +#undef AuBrAttr_ICEX_SEC
35462 +#define AuBrAttr_ICEX_SEC 0
35463 +#undef AuBrAttr_ICEX_SYS
35464 +#define AuBrAttr_ICEX_SYS 0
35465 +#undef AuBrAttr_ICEX_TR
35466 +#define AuBrAttr_ICEX_TR 0
35467 +#undef AuBrAttr_ICEX_USR
35468 +#define AuBrAttr_ICEX_USR 0
35469 +#undef AuBrAttr_ICEX_OTH
35470 +#define AuBrAttr_ICEX_OTH 0
35474 +/* the longest combination */
35475 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
35476 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
35477 + "+" AUFS_BRATTR_COO_REG \
35478 + "+" AUFS_BRATTR_FHSM \
35479 + "+" AUFS_BRATTR_UNPIN \
35480 + "+" AUFS_BRATTR_ICEX_SEC \
35481 + "+" AUFS_BRATTR_ICEX_SYS \
35482 + "+" AUFS_BRATTR_ICEX_USR \
35483 + "+" AUFS_BRATTR_ICEX_OTH \
35484 + "+" AUFS_BRWATTR_NLWH)
35487 + char a[AuBrPermStrSz];
35488 +} au_br_perm_str_t;
35490 +static inline int au_br_writable(int brperm)
35492 + return brperm & AuBrPerm_RW;
35495 +static inline int au_br_whable(int brperm)
35497 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
35500 +static inline int au_br_wh_linkable(int brperm)
35502 + return !(brperm & AuBrWAttr_NoLinkWH);
35505 +static inline int au_br_cmoo(int brperm)
35507 + return brperm & AuBrAttr_CMOO_Mask;
35510 +static inline int au_br_fhsm(int brperm)
35512 + return brperm & AuBrAttr_FHSM;
35515 +/* ---------------------------------------------------------------------- */
35519 + /* readdir in userspace */
35523 + AuCtl_WBR_FD, /* pathconf wrapper */
35524 + AuCtl_IBUSY, /* busy inode */
35525 + AuCtl_MVDOWN, /* move-down */
35526 + AuCtl_BR, /* info about branches */
35527 + AuCtl_FHSM_FD /* connection for fhsm */
35530 +/* borrowed from linux/include/linux/kernel.h */
35532 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
35533 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
35536 +/* borrowed from linux/include/linux/compiler-gcc3.h */
35538 +#define __aligned(x) __attribute__((aligned(x)))
35543 +#define __packed __attribute__((packed))
35547 +struct au_rdu_cookie {
35552 + uint32_t generation;
35555 +struct au_rdu_ent {
35564 +static inline int au_rdu_len(int nlen)
35566 + /* include the terminating NULL */
35567 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
35568 + sizeof(uint64_t));
35571 +union au_rdu_ent_ul {
35572 + struct au_rdu_ent __user *e;
35584 + uint64_t sz; /* AuCtl_RDU */
35585 + uint64_t nent; /* AuCtl_RDU_INO */
35587 + union au_rdu_ent_ul ent;
35588 + uint16_t verify[AufsCtlRduV_End];
35590 + /* input/output */
35594 + union au_rdu_ent_ul tail;
35595 + /* number of entries which were added in a single call */
35600 + struct au_rdu_cookie cookie;
35603 +/* ---------------------------------------------------------------------- */
35605 +struct aufs_wbr_fd {
35610 +/* ---------------------------------------------------------------------- */
35612 +struct aufs_ibusy {
35613 + uint64_t ino, h_ino;
35617 +/* ---------------------------------------------------------------------- */
35619 +/* error code for move-down */
35620 +/* the actual message strings are implemented in aufs-util.git */
35622 + EAU_MVDOWN_OPAQUE = 1,
35623 + EAU_MVDOWN_WHITEOUT,
35624 + EAU_MVDOWN_UPPER,
35625 + EAU_MVDOWN_BOTTOM,
35626 + EAU_MVDOWN_NOUPPER,
35627 + EAU_MVDOWN_NOLOWERBR,
35631 +/* flags for move-down */
35632 +#define AUFS_MVDOWN_DMSG 1
35633 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
35634 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
35635 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
35636 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
35637 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
35638 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
35639 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
35640 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
35641 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
35642 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
35643 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
35644 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
35646 +/* index for move-down */
35648 + AUFS_MVDOWN_UPPER,
35649 + AUFS_MVDOWN_LOWER,
35650 + AUFS_MVDOWN_NARRAY
35654 + * additional info of move-down
35655 + * number of free blocks and inodes.
35656 + * subset of struct kstatfs, but smaller and always 64bit.
35658 +struct aufs_stfs {
35659 + uint64_t f_blocks;
35660 + uint64_t f_bavail;
35661 + uint64_t f_files;
35662 + uint64_t f_ffree;
35665 +struct aufs_stbr {
35666 + int16_t brid; /* optional input */
35667 + int16_t bindex; /* output */
35668 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
35671 +struct aufs_mvdown {
35672 + uint32_t flags; /* input/output */
35673 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
35674 + int8_t au_errno; /* output */
35677 +/* ---------------------------------------------------------------------- */
35679 +union aufs_brinfo {
35680 + /* PATH_MAX may differ between kernel-space and user-space */
35681 + char _spacer[4096];
35689 +/* ---------------------------------------------------------------------- */
35691 +#define AuCtlType 'A'
35692 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
35693 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
35694 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
35695 + struct aufs_wbr_fd)
35696 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
35697 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
35698 + struct aufs_mvdown)
35699 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
35700 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
35702 +#endif /* __AUFS_TYPE_H__ */
35703 aufs4.x-rcN loopback patch
35705 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
35706 index 7339e65..76e5da4 100644
35707 --- a/drivers/block/loop.c
35708 +++ b/drivers/block/loop.c
35709 @@ -562,7 +562,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
35712 struct switch_request {
35713 - struct file *file;
35714 + struct file *file, *virt_file;
35715 struct completion wait;
35718 @@ -588,6 +588,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35719 mapping = file->f_mapping;
35720 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
35721 lo->lo_backing_file = file;
35722 + lo->lo_backing_virt_file = p->virt_file;
35723 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
35724 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
35725 lo->old_gfp_mask = mapping_gfp_mask(mapping);
35726 @@ -600,11 +601,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
35727 * First it needs to flush existing IO, it does this by sending a magic
35728 * BIO down the pipe. The completion of this BIO does the actual switch.
35730 -static int loop_switch(struct loop_device *lo, struct file *file)
35731 +static int loop_switch(struct loop_device *lo, struct file *file,
35732 + struct file *virt_file)
35734 struct switch_request w;
35737 + w.virt_file = virt_file;
35739 /* freeze queue and wait for completion of scheduled requests */
35740 blk_mq_freeze_queue(lo->lo_queue);
35741 @@ -623,7 +626,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
35743 static int loop_flush(struct loop_device *lo)
35745 - return loop_switch(lo, NULL);
35746 + return loop_switch(lo, NULL, NULL);
35749 +static struct file *loop_real_file(struct file *file)
35751 + struct file *f = NULL;
35753 + if (file->f_path.dentry->d_sb->s_op->real_loop)
35754 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
35758 static void loop_reread_partitions(struct loop_device *lo,
35759 @@ -660,6 +672,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35762 struct file *file, *old_file;
35763 + struct file *f, *virt_file = NULL, *old_virt_file;
35764 struct inode *inode;
35767 @@ -676,9 +689,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35771 + f = loop_real_file(file);
35773 + virt_file = file;
35778 inode = file->f_mapping->host;
35779 old_file = lo->lo_backing_file;
35780 + old_virt_file = lo->lo_backing_virt_file;
35784 @@ -690,17 +710,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
35787 /* and ... switch */
35788 - error = loop_switch(lo, file);
35789 + error = loop_switch(lo, file, virt_file);
35794 + if (old_virt_file)
35795 + fput(old_virt_file);
35796 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
35797 loop_reread_partitions(lo, bdev);
35807 @@ -887,7 +911,7 @@ static int loop_prepare_queue(struct loop_device *lo)
35808 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35809 struct block_device *bdev, unsigned int arg)
35811 - struct file *file, *f;
35812 + struct file *file, *f, *virt_file = NULL;
35813 struct inode *inode;
35814 struct address_space *mapping;
35815 unsigned lo_blocksize;
35816 @@ -902,6 +926,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35820 + f = loop_real_file(file);
35822 + virt_file = file;
35828 if (lo->lo_state != Lo_unbound)
35829 @@ -954,6 +984,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35830 lo->lo_device = bdev;
35831 lo->lo_flags = lo_flags;
35832 lo->lo_backing_file = file;
35833 + lo->lo_backing_virt_file = virt_file;
35834 lo->transfer = NULL;
35836 lo->lo_sizelimit = 0;
35837 @@ -986,6 +1017,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
35844 /* This is safe: open() is still holding a reference. */
35845 module_put(THIS_MODULE);
35846 @@ -1032,6 +1065,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
35847 static int loop_clr_fd(struct loop_device *lo)
35849 struct file *filp = lo->lo_backing_file;
35850 + struct file *virt_filp = lo->lo_backing_virt_file;
35851 gfp_t gfp = lo->old_gfp_mask;
35852 struct block_device *bdev = lo->lo_device;
35854 @@ -1063,6 +1097,7 @@ static int loop_clr_fd(struct loop_device *lo)
35855 spin_lock_irq(&lo->lo_lock);
35856 lo->lo_state = Lo_rundown;
35857 lo->lo_backing_file = NULL;
35858 + lo->lo_backing_virt_file = NULL;
35859 spin_unlock_irq(&lo->lo_lock);
35861 loop_release_xfer(lo);
35862 @@ -1107,6 +1142,8 @@ static int loop_clr_fd(struct loop_device *lo)
35863 * bd_mutex which is usually taken before lo_ctl_mutex.
35871 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
35872 index fb2237c..c3888c5 100644
35873 --- a/drivers/block/loop.h
35874 +++ b/drivers/block/loop.h
35875 @@ -46,7 +46,7 @@ struct loop_device {
35876 int (*ioctl)(struct loop_device *, int cmd,
35877 unsigned long arg);
35879 - struct file * lo_backing_file;
35880 + struct file * lo_backing_file, *lo_backing_virt_file;
35881 struct block_device *lo_device;
35882 unsigned lo_blocksize;
35884 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
35885 index 504b767..09426ad 100644
35886 --- a/fs/aufs/f_op.c
35887 +++ b/fs/aufs/f_op.c
35888 @@ -346,7 +346,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
35889 if (IS_ERR(h_file))
35892 - if (au_test_loopback_kthread()) {
35893 + if (0 && au_test_loopback_kthread()) {
35894 au_warn_loopback(h_file->f_path.dentry->d_sb);
35895 if (file->f_mapping != h_file->f_mapping) {
35896 file->f_mapping = h_file->f_mapping;
35897 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
35898 index 5711e7a..9df5d16 100644
35899 --- a/fs/aufs/loop.c
35900 +++ b/fs/aufs/loop.c
35901 @@ -131,3 +131,19 @@ void au_loopback_fin(void)
35902 symbol_put(loop_backing_file);
35903 kfree(au_warn_loopback_array);
35906 +/* ---------------------------------------------------------------------- */
35908 +/* support the loopback block device insude aufs */
35910 +struct file *aufs_real_loop(struct file *file)
35914 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
35915 + fi_read_lock(file);
35916 + f = au_hf_top(file);
35917 + fi_read_unlock(file);
35921 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
35922 index 48bf070..66afec7 100644
35923 --- a/fs/aufs/loop.h
35924 +++ b/fs/aufs/loop.h
35925 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
35927 int au_loopback_init(void);
35928 void au_loopback_fin(void);
35930 +struct file *aufs_real_loop(struct file *file);
35932 +AuStub(struct file *, loop_backing_file, return NULL)
35934 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
35935 struct dentry *h_adding)
35936 AuStubInt0(au_test_loopback_kthread, void)
35937 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
35939 AuStubInt0(au_loopback_init, void)
35940 AuStubVoid(au_loopback_fin, void)
35942 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
35943 #endif /* BLK_DEV_LOOP */
35945 #endif /* __KERNEL__ */
35946 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
35947 index 8bd2d9c..26581c0 100644
35948 --- a/fs/aufs/super.c
35949 +++ b/fs/aufs/super.c
35950 @@ -832,7 +832,10 @@ static const struct super_operations aufs_sop = {
35951 .statfs = aufs_statfs,
35952 .put_super = aufs_put_super,
35953 .sync_fs = aufs_sync_fs,
35954 - .remount_fs = aufs_remount_fs
35955 + .remount_fs = aufs_remount_fs,
35956 +#ifdef CONFIG_AUFS_BDEV_LOOP
35957 + .real_loop = aufs_real_loop
35961 /* ---------------------------------------------------------------------- */
35962 diff --git a/include/linux/fs.h b/include/linux/fs.h
35963 index 33c6953..f9b06a2 100644
35964 --- a/include/linux/fs.h
35965 +++ b/include/linux/fs.h
35966 @@ -1805,6 +1805,10 @@ struct super_operations {
35967 struct shrink_control *);
35968 long (*free_cached_objects)(struct super_block *,
35969 struct shrink_control *);
35970 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
35972 + struct file *(*real_loop)(struct file *);