1 aufs4.x-rcN kbuild patch
3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 2bc7ad7..3049386 100644
7 @@ -245,6 +245,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 ed2b632..aa6d14b 100644
19 @@ -129,3 +129,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 185f8ea..5deb0d1 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 f593300..8a17054 100644
42 @@ -2256,6 +2256,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 c9f2107..005e292 100644
64 --- a/drivers/block/loop.c
65 +++ b/drivers/block/loop.c
66 @@ -701,6 +701,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 5c7cc95..df0268c 100644
95 @@ -1164,7 +1164,7 @@ enum d_walk_ret {
97 * The @enter() and @finish() callbacks are called with d_lock held.
99 -static void d_walk(struct dentry *parent, void *data,
100 +void d_walk(struct dentry *parent, void *data,
101 enum d_walk_ret (*enter)(void *, struct dentry *),
102 void (*finish)(void *))
104 diff --git a/fs/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 7e3ef3a..675fe84 100644
130 @@ -1593,7 +1593,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 66215a7..a1da117 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 901e25d..a71aa9e 100644
214 --- a/include/linux/fs.h
215 +++ b/include/linux/fs.h
216 @@ -1275,6 +1275,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 @@ -1699,6 +1700,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 @@ -1759,6 +1761,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 @@ -2123,6 +2131,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 *);
259 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
260 extern const struct pipe_buf_operations default_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 ac0df4d..42255e5 100644
274 @@ -1938,7 +1938,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 f6fa99e..2750949 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 @@ -1634,7 +1637,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 ef815b9..a772481 100644
342 --- a/include/linux/mm.h
343 +++ b/include/linux/mm.h
344 @@ -1266,6 +1266,28 @@ static inline int fixup_user_fault(struc
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,
371 unsigned int gup_flags);
372 extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
373 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
374 index 903200f..55fc528 100644
375 --- a/include/linux/mm_types.h
376 +++ b/include/linux/mm_types.h
377 @@ -275,6 +275,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 @@ -349,6 +350,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 beb3172..ad4cfa8 100644
397 @@ -477,7 +477,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 2ca1faf..6b9da3f 100644
410 @@ -40,7 +40,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 2d0986a..4a31bad 100644
423 @@ -2284,7 +2284,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 793fe0f..45f39f3 100644
436 @@ -2113,7 +2113,7 @@ static inline int wp_page_reuse(struct fault_env *fe, pte_t orig_pte,
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 ca9d91b..f3ebc5a 100644
449 @@ -163,7 +163,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 @@ -790,7 +790,7 @@ again:
461 uprobe_munmap(next, next->vm_start, next->vm_end);
466 anon_vma_merge(vma, next);
467 @@ -1574,8 +1574,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 @@ -2380,7 +2380,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 @@ -2399,7 +2399,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 @@ -2550,7 +2550,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 @@ -2625,10 +2625,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 @@ -2903,7 +2920,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 95daf81..5086a29 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 df0268c..76280ee 100644
684 @@ -1272,6 +1272,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 6fcfb3f..ed9d646 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 675fe84..da063d3 100644
756 @@ -1602,6 +1602,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 7bb2cda..88ec098 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 @@ -1812,6 +1813,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 b47f7cf..618bc9e 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 @@ -100,6 +101,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 @@ -109,6 +111,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 @@ -137,6 +140,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 4fd6e25..ec6f532 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 a1da117..c643215 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 c243905..b60dc60 100644
920 @@ -214,6 +214,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 d513051..e056d54 100644
930 --- a/kernel/task_work.c
931 +++ b/kernel/task_work.c
932 @@ -119,3 +119,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 14540bd..4e3b242 100644
939 --- a/security/commoncap.c
940 +++ b/security/commoncap.c
941 @@ -1066,12 +1066,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 4838e7f..36c741e 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 @@ -758,6 +766,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 @@ -817,6 +826,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 2016-10-09 16:55:36.476034536 +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 2016-10-09 16:55:36.476034536 +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-10-09 16:55:36.479367956 +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-10-09 16:55:36.479367956 +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-10-09 16:55:36.479367956 +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-10-09 16:55:36.479367956 +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-10-09 16:55:36.482701377 +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-10-09 16:55:36.482701377 +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-10-09 16:55:36.482701377 +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-10-09 16:55:36.482701377 +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-10-09 16:55:36.482701377 +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-10-09 16:55:36.482701377 +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-10-09 16:55:36.482701377 +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-10-09 16:55:36.482701377 +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-10-09 16:55:36.479367956 +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-10-09 16:55:36.486034798 +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-10-09 16:55:38.886097714 +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 + au_delayed_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);
2937 + au_delayed_kfree(wbr);
2938 + au_delayed_kfree(br);
2942 + * frees all branches
2944 +void au_br_free(struct au_sbinfo *sbinfo)
2946 + aufs_bindex_t bmax;
2947 + struct au_branch **br;
2949 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2951 + bmax = sbinfo->si_bbot + 1;
2952 + br = sbinfo->si_branch;
2954 + au_br_do_free(*br++);
2958 + * find the index of a branch which is specified by @br_id.
2960 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2962 + aufs_bindex_t bindex, bbot;
2964 + bbot = au_sbbot(sb);
2965 + for (bindex = 0; bindex <= bbot; bindex++)
2966 + if (au_sbr_id(sb, bindex) == br_id)
2971 +/* ---------------------------------------------------------------------- */
2977 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2978 + struct dentry *h_root)
2980 + if (unlikely(h_adding == h_root
2981 + || au_test_loopback_overlap(sb, h_adding)))
2983 + if (h_adding->d_sb != h_root->d_sb)
2985 + return au_test_subdir(h_adding, h_root)
2986 + || au_test_subdir(h_root, h_adding);
2990 + * returns a newly allocated branch. @new_nbranch is a number of branches
2991 + * after adding a branch.
2993 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
2996 + struct au_branch *add_branch;
2997 + struct dentry *root;
2998 + struct inode *inode;
3002 + root = sb->s_root;
3003 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3004 + if (unlikely(!add_branch))
3007 + err = au_hnotify_init_br(add_branch, perm);
3008 + if (unlikely(err))
3011 + if (au_br_writable(perm)) {
3012 + /* may be freed separately at changing the branch permission */
3013 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3015 + if (unlikely(!add_branch->br_wbr))
3019 + if (au_br_fhsm(perm)) {
3020 + err = au_fhsm_br_alloc(add_branch);
3021 + if (unlikely(err))
3025 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3027 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3029 + inode = d_inode(root);
3030 + err = au_hinode_realloc(au_ii(inode), new_nbranch, /*may_shrink*/0);
3033 + return add_branch; /* success */
3036 + if (add_branch->br_wbr)
3037 + au_delayed_kfree(add_branch->br_wbr);
3039 + au_hnotify_fin_br(add_branch);
3041 + au_delayed_kfree(add_branch);
3043 + return ERR_PTR(err);
3047 + * test if the branch permission is legal or not.
3049 +static int test_br(struct inode *inode, int brperm, char *path)
3053 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3058 + pr_err("write permission for readonly mount or inode, %s\n", path);
3066 + * 0: success, the caller will add it
3067 + * plus: success, it is already unified, the caller should ignore it
3070 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3073 + aufs_bindex_t bbot, bindex;
3074 + struct dentry *root, *h_dentry;
3075 + struct inode *inode, *h_inode;
3077 + root = sb->s_root;
3078 + bbot = au_sbbot(sb);
3079 + if (unlikely(bbot >= 0
3080 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3084 + pr_err("%s duplicated\n", add->pathname);
3089 + err = -ENOSPC; /* -E2BIG; */
3090 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3091 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3092 + pr_err("number of branches exceeded %s\n", add->pathname);
3097 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3098 + pr_err("bad index %d\n", add->bindex);
3102 + inode = d_inode(add->path.dentry);
3104 + if (unlikely(!inode->i_nlink)) {
3105 + pr_err("no existence %s\n", add->pathname);
3110 + if (unlikely(inode->i_sb == sb)) {
3111 + pr_err("%s must be outside\n", add->pathname);
3115 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3116 + pr_err("unsupported filesystem, %s (%s)\n",
3117 + add->pathname, au_sbtype(inode->i_sb));
3121 + if (unlikely(inode->i_sb->s_stack_depth)) {
3122 + pr_err("already stacked, %s (%s)\n",
3123 + add->pathname, au_sbtype(inode->i_sb));
3127 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3128 + if (unlikely(err))
3132 + return 0; /* success */
3135 + for (bindex = 0; bindex <= bbot; bindex++)
3136 + if (unlikely(test_overlap(sb, add->path.dentry,
3137 + au_h_dptr(root, bindex)))) {
3138 + pr_err("%s is overlapped\n", add->pathname);
3143 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3144 + h_dentry = au_h_dptr(root, 0);
3145 + h_inode = d_inode(h_dentry);
3146 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3147 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3148 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3149 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3151 + i_uid_read(inode), i_gid_read(inode),
3152 + (inode->i_mode & S_IALLUGO),
3153 + i_uid_read(h_inode), i_gid_read(h_inode),
3154 + (h_inode->i_mode & S_IALLUGO));
3162 + * initialize or clean the whiteouts for an adding branch
3164 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3167 + int err, old_perm;
3168 + aufs_bindex_t bindex;
3169 + struct inode *h_inode;
3170 + struct au_wbr *wbr;
3171 + struct au_hinode *hdir;
3172 + struct dentry *h_dentry;
3174 + err = vfsub_mnt_want_write(au_br_mnt(br));
3175 + if (unlikely(err))
3179 + old_perm = br->br_perm;
3180 + br->br_perm = new_perm;
3183 + bindex = au_br_index(sb, br->br_id);
3184 + if (0 <= bindex) {
3185 + hdir = au_hi(d_inode(sb->s_root), bindex);
3186 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3188 + h_dentry = au_br_dentry(br);
3189 + h_inode = d_inode(h_dentry);
3190 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3193 + err = au_wh_init(br, sb);
3195 + wbr_wh_write_lock(wbr);
3196 + err = au_wh_init(br, sb);
3197 + wbr_wh_write_unlock(wbr);
3200 + au_hn_inode_unlock(hdir);
3202 + inode_unlock(h_inode);
3203 + vfsub_mnt_drop_write(au_br_mnt(br));
3204 + br->br_perm = old_perm;
3206 + if (!err && wbr && !au_br_writable(new_perm)) {
3207 + au_delayed_kfree(wbr);
3208 + br->br_wbr = NULL;
3215 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3219 + struct kstatfs kst;
3220 + struct au_wbr *wbr;
3223 + au_rw_init(&wbr->wbr_wh_rwsem);
3224 + atomic_set(&wbr->wbr_wh_running, 0);
3227 + * a limit for rmdir/rename a dir
3228 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3230 + err = vfs_statfs(&br->br_path, &kst);
3231 + if (unlikely(err))
3234 + if (kst.f_namelen >= NAME_MAX)
3235 + err = au_br_init_wh(sb, br, perm);
3237 + pr_err("%pd(%s), unsupported namelen %ld\n",
3239 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3245 +/* initialize a new branch */
3246 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3247 + struct au_opt_add *add)
3250 + struct inode *h_inode;
3253 + mutex_init(&br->br_xino.xi_nondir_mtx);
3254 + br->br_perm = add->perm;
3255 + br->br_path = add->path; /* set first, path_get() later */
3256 + spin_lock_init(&br->br_dykey_lock);
3257 + au_br_count_init(br);
3258 + atomic_set(&br->br_xino_running, 0);
3259 + br->br_id = au_new_br_id(sb);
3260 + AuDebugOn(br->br_id < 0);
3262 + if (au_br_writable(add->perm)) {
3263 + err = au_wbr_init(br, sb, add->perm);
3264 + if (unlikely(err))
3268 + if (au_opt_test(au_mntflags(sb), XINO)) {
3269 + h_inode = d_inode(add->path.dentry);
3270 + err = au_xino_br(sb, br, h_inode->i_ino,
3271 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3272 + if (unlikely(err)) {
3273 + AuDebugOn(br->br_xino.xi_file);
3278 + sysaufs_br_init(br);
3279 + path_get(&br->br_path);
3280 + goto out; /* success */
3283 + memset(&br->br_path, 0, sizeof(br->br_path));
3288 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3289 + struct au_branch *br, aufs_bindex_t bbot,
3290 + aufs_bindex_t amount)
3292 + struct au_branch **brp;
3294 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3296 + brp = sbinfo->si_branch + bindex;
3297 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3299 + sbinfo->si_bbot++;
3300 + if (unlikely(bbot < 0))
3301 + sbinfo->si_bbot = 0;
3304 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3305 + aufs_bindex_t bbot, aufs_bindex_t amount)
3307 + struct au_hdentry *hdp;
3309 + AuRwMustWriteLock(&dinfo->di_rwsem);
3311 + hdp = au_hdentry(dinfo, bindex);
3312 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3313 + au_h_dentry_init(hdp);
3315 + if (unlikely(bbot < 0))
3316 + dinfo->di_btop = 0;
3319 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3320 + aufs_bindex_t bbot, aufs_bindex_t amount)
3322 + struct au_hinode *hip;
3324 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3326 + hip = au_hinode(iinfo, bindex);
3327 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3328 + au_hinode_init(hip);
3330 + if (unlikely(bbot < 0))
3331 + iinfo->ii_btop = 0;
3334 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3335 + aufs_bindex_t bindex)
3337 + struct dentry *root, *h_dentry;
3338 + struct inode *root_inode, *h_inode;
3339 + aufs_bindex_t bbot, amount;
3341 + root = sb->s_root;
3342 + root_inode = d_inode(root);
3343 + bbot = au_sbbot(sb);
3344 + amount = bbot + 1 - bindex;
3345 + h_dentry = au_br_dentry(br);
3346 + au_sbilist_lock();
3347 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3348 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3349 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3350 + au_set_h_dptr(root, bindex, dget(h_dentry));
3351 + h_inode = d_inode(h_dentry);
3352 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3353 + au_sbilist_unlock();
3356 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3359 + aufs_bindex_t bbot, add_bindex;
3360 + struct dentry *root, *h_dentry;
3361 + struct inode *root_inode;
3362 + struct au_branch *add_branch;
3364 + root = sb->s_root;
3365 + root_inode = d_inode(root);
3366 + IMustLock(root_inode);
3367 + IiMustWriteLock(root_inode);
3368 + err = test_add(sb, add, remount);
3369 + if (unlikely(err < 0))
3373 + goto out; /* success */
3376 + bbot = au_sbbot(sb);
3377 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3378 + err = PTR_ERR(add_branch);
3379 + if (IS_ERR(add_branch))
3382 + err = au_br_init(add_branch, sb, add);
3383 + if (unlikely(err)) {
3384 + au_br_do_free(add_branch);
3388 + add_bindex = add->bindex;
3390 + au_br_do_add(sb, add_branch, add_bindex);
3392 + sysaufs_brs_del(sb, add_bindex);
3393 + au_br_do_add(sb, add_branch, add_bindex);
3394 + sysaufs_brs_add(sb, add_bindex);
3397 + h_dentry = add->path.dentry;
3398 + if (!add_bindex) {
3399 + au_cpup_attr_all(root_inode, /*force*/1);
3400 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3402 + au_add_nlink(root_inode, d_inode(h_dentry));
3405 + * this test/set prevents aufs from handling unnecesary notify events
3406 + * of xino files, in case of re-adding a writable branch which was
3407 + * once detached from aufs.
3409 + if (au_xino_brid(sb) < 0
3410 + && au_br_writable(add_branch->br_perm)
3411 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3412 + && add_branch->br_xino.xi_file
3413 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3414 + au_xino_brid_set(sb, add_branch->br_id);
3420 +/* ---------------------------------------------------------------------- */
3422 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3423 + unsigned long long max __maybe_unused,
3426 + unsigned long long n;
3427 + struct file **p, *f;
3428 + struct au_sphlhead *files;
3429 + struct au_finfo *finfo;
3433 + files = &au_sbi(sb)->si_files;
3434 + spin_lock(&files->spin);
3435 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3436 + f = finfo->fi_file;
3438 + && !special_file(file_inode(f)->i_mode)) {
3442 + AuDebugOn(n > max);
3445 + spin_unlock(&files->spin);
3450 +static struct file **au_farray_alloc(struct super_block *sb,
3451 + unsigned long long *max)
3453 + *max = au_nfiles(sb);
3454 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3457 +static void au_farray_free(struct file **a, unsigned long long max)
3459 + unsigned long long ull;
3461 + for (ull = 0; ull < max; ull++)
3467 +/* ---------------------------------------------------------------------- */
3473 +/* to show the line number, do not make it inlined function */
3474 +#define AuVerbose(do_info, fmt, ...) do { \
3476 + pr_info(fmt, ##__VA_ARGS__); \
3479 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3480 + aufs_bindex_t bbot)
3482 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3485 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3486 + aufs_bindex_t bbot)
3488 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3492 + * test if the branch is deletable or not.
3494 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3495 + unsigned int sigen, const unsigned int verbose)
3497 + int err, i, j, ndentry;
3498 + aufs_bindex_t btop, bbot;
3499 + struct au_dcsub_pages dpages;
3500 + struct au_dpage *dpage;
3503 + err = au_dpages_init(&dpages, GFP_NOFS);
3504 + if (unlikely(err))
3506 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3507 + if (unlikely(err))
3510 + for (i = 0; !err && i < dpages.ndpage; i++) {
3511 + dpage = dpages.dpages + i;
3512 + ndentry = dpage->ndentry;
3513 + for (j = 0; !err && j < ndentry; j++) {
3514 + d = dpage->dentries[j];
3515 + AuDebugOn(au_dcount(d) <= 0);
3516 + if (!au_digen_test(d, sigen)) {
3517 + di_read_lock_child(d, AuLock_IR);
3518 + if (unlikely(au_dbrange_test(d))) {
3519 + di_read_unlock(d, AuLock_IR);
3523 + di_write_lock_child(d);
3524 + if (unlikely(au_dbrange_test(d))) {
3525 + di_write_unlock(d);
3528 + err = au_reval_dpath(d, sigen);
3530 + di_downgrade_lock(d, AuLock_IR);
3532 + di_write_unlock(d);
3537 + /* AuDbgDentry(d); */
3538 + btop = au_dbtop(d);
3539 + bbot = au_dbbot(d);
3540 + if (btop <= bindex
3542 + && au_h_dptr(d, bindex)
3543 + && au_test_dbusy(d, btop, bbot)) {
3545 + AuVerbose(verbose, "busy %pd\n", d);
3548 + di_read_unlock(d, AuLock_IR);
3553 + au_dpages_free(&dpages);
3558 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3559 + unsigned int sigen, const unsigned int verbose)
3562 + unsigned long long max, ull;
3563 + struct inode *i, **array;
3564 + aufs_bindex_t btop, bbot;
3566 + array = au_iarray_alloc(sb, &max);
3567 + err = PTR_ERR(array);
3568 + if (IS_ERR(array))
3572 + AuDbg("b%d\n", bindex);
3573 + for (ull = 0; !err && ull < max; ull++) {
3577 + if (i->i_ino == AUFS_ROOT_INO)
3580 + /* AuDbgInode(i); */
3581 + if (au_iigen(i, NULL) == sigen)
3582 + ii_read_lock_child(i);
3584 + ii_write_lock_child(i);
3585 + err = au_refresh_hinode_self(i);
3588 + ii_downgrade_lock(i);
3590 + ii_write_unlock(i);
3595 + btop = au_ibtop(i);
3596 + bbot = au_ibbot(i);
3597 + if (btop <= bindex
3599 + && au_h_iptr(i, bindex)
3600 + && au_test_ibusy(i, btop, bbot)) {
3602 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3605 + ii_read_unlock(i);
3607 + au_iarray_free(array, max);
3613 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3614 + const unsigned int verbose)
3617 + unsigned int sigen;
3619 + sigen = au_sigen(root->d_sb);
3620 + DiMustNoWaiters(root);
3621 + IiMustNoWaiters(d_inode(root));
3622 + di_write_unlock(root);
3623 + err = test_dentry_busy(root, bindex, sigen, verbose);
3625 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3626 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3631 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3632 + struct file **to_free, int *idx)
3635 + unsigned char matched, root;
3636 + aufs_bindex_t bindex, bbot;
3637 + struct au_fidir *fidir;
3638 + struct au_hfile *hfile;
3641 + root = IS_ROOT(file->f_path.dentry);
3644 + to_free[*idx] = file;
3650 + fidir = au_fi(file)->fi_hdir;
3651 + AuDebugOn(!fidir);
3652 + bbot = au_fbbot_dir(file);
3653 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3654 + hfile = fidir->fd_hfile + bindex;
3655 + if (!hfile->hf_file)
3658 + if (hfile->hf_br->br_id == br_id) {
3670 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3671 + struct file **to_free, int opened)
3674 + unsigned long long ull, max;
3675 + aufs_bindex_t btop;
3676 + struct file *file, **array;
3677 + struct dentry *root;
3678 + struct au_hfile *hfile;
3680 + array = au_farray_alloc(sb, &max);
3681 + err = PTR_ERR(array);
3682 + if (IS_ERR(array))
3687 + root = sb->s_root;
3688 + di_write_unlock(root);
3689 + for (ull = 0; ull < max; ull++) {
3690 + file = array[ull];
3691 + if (unlikely(!file))
3694 + /* AuDbg("%pD\n", file); */
3695 + fi_read_lock(file);
3696 + btop = au_fbtop(file);
3697 + if (!d_is_dir(file->f_path.dentry)) {
3698 + hfile = &au_fi(file)->fi_htop;
3699 + if (hfile->hf_br->br_id == br_id)
3702 + err = test_dir_busy(file, br_id, to_free, &idx);
3703 + fi_read_unlock(file);
3704 + if (unlikely(err))
3707 + di_write_lock_child(root);
3708 + au_farray_free(array, max);
3709 + AuDebugOn(idx > opened);
3715 +static void br_del_file(struct file **to_free, unsigned long long opened,
3716 + aufs_bindex_t br_id)
3718 + unsigned long long ull;
3719 + aufs_bindex_t bindex, btop, bbot, bfound;
3720 + struct file *file;
3721 + struct au_fidir *fidir;
3722 + struct au_hfile *hfile;
3724 + for (ull = 0; ull < opened; ull++) {
3725 + file = to_free[ull];
3726 + if (unlikely(!file))
3729 + /* AuDbg("%pD\n", file); */
3730 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3732 + fidir = au_fi(file)->fi_hdir;
3733 + AuDebugOn(!fidir);
3734 + fi_write_lock(file);
3735 + btop = au_fbtop(file);
3736 + bbot = au_fbbot_dir(file);
3737 + for (bindex = btop; bindex <= bbot; bindex++) {
3738 + hfile = fidir->fd_hfile + bindex;
3739 + if (!hfile->hf_file)
3742 + if (hfile->hf_br->br_id == br_id) {
3747 + AuDebugOn(bfound < 0);
3748 + au_set_h_fptr(file, bfound, NULL);
3749 + if (bfound == btop) {
3750 + for (btop++; btop <= bbot; btop++)
3751 + if (au_hf_dir(file, btop)) {
3752 + au_set_fbtop(file, btop);
3756 + fi_write_unlock(file);
3760 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3761 + const aufs_bindex_t bindex,
3762 + const aufs_bindex_t bbot)
3764 + struct au_branch **brp, **p;
3766 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3768 + brp = sbinfo->si_branch + bindex;
3769 + if (bindex < bbot)
3770 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3771 + sbinfo->si_branch[0 + bbot] = NULL;
3772 + sbinfo->si_bbot--;
3774 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3777 + sbinfo->si_branch = p;
3778 + /* harmless error */
3781 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3782 + const aufs_bindex_t bbot)
3784 + struct au_hdentry *hdp, *p;
3786 + AuRwMustWriteLock(&dinfo->di_rwsem);
3788 + hdp = au_hdentry(dinfo, bindex);
3789 + if (bindex < bbot)
3790 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3791 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3794 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3797 + dinfo->di_hdentry = p;
3798 + /* harmless error */
3801 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3802 + const aufs_bindex_t bbot)
3804 + struct au_hinode *hip, *p;
3806 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3808 + hip = au_hinode(iinfo, bindex);
3809 + if (bindex < bbot)
3810 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3811 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3814 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3817 + iinfo->ii_hinode = p;
3818 + /* harmless error */
3821 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3822 + struct au_branch *br)
3824 + aufs_bindex_t bbot;
3825 + struct au_sbinfo *sbinfo;
3826 + struct dentry *root, *h_root;
3827 + struct inode *inode, *h_inode;
3828 + struct au_hinode *hinode;
3830 + SiMustWriteLock(sb);
3832 + root = sb->s_root;
3833 + inode = d_inode(root);
3834 + sbinfo = au_sbi(sb);
3835 + bbot = sbinfo->si_bbot;
3837 + h_root = au_h_dptr(root, bindex);
3838 + hinode = au_hi(inode, bindex);
3839 + h_inode = au_igrab(hinode->hi_inode);
3842 + au_sbilist_lock();
3843 + au_br_do_del_brp(sbinfo, bindex, bbot);
3844 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3845 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3846 + au_sbilist_unlock();
3850 + au_br_do_free(br);
3853 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3854 + unsigned long long max, void *arg)
3859 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3862 + unsigned long long opened;
3863 + unsigned int mnt_flags;
3864 + aufs_bindex_t bindex, bbot, br_id;
3865 + unsigned char do_wh, verbose;
3866 + struct au_branch *br;
3867 + struct au_wbr *wbr;
3868 + struct dentry *root;
3869 + struct file **to_free;
3874 + root = sb->s_root;
3875 + bindex = au_find_dbindex(root, del->h_path.dentry);
3878 + goto out; /* success */
3880 + pr_err("%s no such branch\n", del->pathname);
3883 + AuDbg("bindex b%d\n", bindex);
3886 + mnt_flags = au_mntflags(sb);
3887 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3888 + bbot = au_sbbot(sb);
3889 + if (unlikely(!bbot)) {
3890 + AuVerbose(verbose, "no more branches left\n");
3893 + br = au_sbr(sb, bindex);
3894 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3896 + br_id = br->br_id;
3897 + opened = au_br_count(br);
3898 + if (unlikely(opened)) {
3899 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3900 + err = PTR_ERR(to_free);
3901 + if (IS_ERR(to_free))
3904 + err = test_file_busy(sb, br_id, to_free, opened);
3905 + if (unlikely(err)) {
3906 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3912 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3914 + /* instead of WbrWhMustWriteLock(wbr) */
3915 + SiMustWriteLock(sb);
3916 + for (i = 0; i < AuBrWh_Last; i++) {
3917 + dput(wbr->wbr_wh[i]);
3918 + wbr->wbr_wh[i] = NULL;
3922 + err = test_children_busy(root, bindex, verbose);
3923 + if (unlikely(err)) {
3932 + * now we confirmed the branch is deletable.
3933 + * let's free the remaining opened dirs on the branch.
3935 + di_write_unlock(root);
3936 + br_del_file(to_free, opened, br_id);
3937 + di_write_lock_child(root);
3941 + au_br_do_del(sb, bindex, br);
3943 + sysaufs_brs_del(sb, bindex);
3944 + au_br_do_del(sb, bindex, br);
3945 + sysaufs_brs_add(sb, bindex);
3949 + au_cpup_attr_all(d_inode(root), /*force*/1);
3950 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3952 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3953 + if (au_opt_test(mnt_flags, PLINK))
3954 + au_plink_half_refresh(sb, br_id);
3956 + if (au_xino_brid(sb) == br_id)
3957 + au_xino_brid_set(sb, -1);
3958 + goto out; /* success */
3962 + rerr = au_br_init_wh(sb, br, br->br_perm);
3964 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3965 + del->pathname, rerr);
3968 + au_farray_free(to_free, opened);
3972 +/* ---------------------------------------------------------------------- */
3974 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3977 + aufs_bindex_t btop, bbot;
3978 + struct aufs_ibusy ibusy;
3979 + struct inode *inode, *h_inode;
3982 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3985 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3987 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3988 + if (unlikely(err)) {
3995 + si_read_lock(sb, AuLock_FLUSH);
3996 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4000 + ibusy.h_ino = 0; /* invalid */
4001 + inode = ilookup(sb, ibusy.ino);
4003 + || inode->i_ino == AUFS_ROOT_INO
4004 + || au_is_bad_inode(inode))
4007 + ii_read_lock_child(inode);
4008 + btop = au_ibtop(inode);
4009 + bbot = au_ibbot(inode);
4010 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4011 + h_inode = au_h_iptr(inode, ibusy.bindex);
4012 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4013 + ibusy.h_ino = h_inode->i_ino;
4015 + ii_read_unlock(inode);
4019 + si_read_unlock(sb);
4021 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4022 + if (unlikely(err)) {
4031 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4033 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4036 +#ifdef CONFIG_COMPAT
4037 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4039 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4043 +/* ---------------------------------------------------------------------- */
4046 + * change a branch permission
4049 +static void au_warn_ima(void)
4052 + /* since it doesn't support mark_files_ro() */
4053 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4057 +static int do_need_sigen_inc(int a, int b)
4059 + return au_br_whable(a) && !au_br_whable(b);
4062 +static int need_sigen_inc(int old, int new)
4064 + return do_need_sigen_inc(old, new)
4065 + || do_need_sigen_inc(new, old);
4068 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4071 + unsigned int mnt_flags;
4072 + unsigned long long ull, max;
4073 + aufs_bindex_t br_id;
4074 + unsigned char verbose, writer;
4075 + struct file *file, *hf, **array;
4076 + struct au_hfile *hfile;
4078 + mnt_flags = au_mntflags(sb);
4079 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4081 + array = au_farray_alloc(sb, &max);
4082 + err = PTR_ERR(array);
4083 + if (IS_ERR(array))
4087 + br_id = au_sbr_id(sb, bindex);
4088 + for (ull = 0; ull < max; ull++) {
4089 + file = array[ull];
4090 + if (unlikely(!file))
4093 + /* AuDbg("%pD\n", file); */
4094 + fi_read_lock(file);
4095 + if (unlikely(au_test_mmapped(file))) {
4097 + AuVerbose(verbose, "mmapped %pD\n", file);
4099 + FiMustNoWaiters(file);
4100 + fi_read_unlock(file);
4104 + hfile = &au_fi(file)->fi_htop;
4105 + hf = hfile->hf_file;
4106 + if (!d_is_reg(file->f_path.dentry)
4107 + || !(file->f_mode & FMODE_WRITE)
4108 + || hfile->hf_br->br_id != br_id
4109 + || !(hf->f_mode & FMODE_WRITE))
4110 + array[ull] = NULL;
4116 + FiMustNoWaiters(file);
4117 + fi_read_unlock(file);
4125 + for (ull = 0; ull < max; ull++) {
4126 + file = array[ull];
4130 + /* todo: already flushed? */
4132 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4133 + * approach which resets f_mode and calls mnt_drop_write() and
4134 + * file_release_write() for each file, because the branch
4135 + * attribute in aufs world is totally different from the native
4138 + /* fi_read_lock(file); */
4139 + hfile = &au_fi(file)->fi_htop;
4140 + hf = hfile->hf_file;
4141 + /* fi_read_unlock(file); */
4142 + spin_lock(&hf->f_lock);
4143 + writer = !!(hf->f_mode & FMODE_WRITER);
4144 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4145 + spin_unlock(&hf->f_lock);
4147 + put_write_access(file_inode(hf));
4148 + __mnt_drop_write(hf->f_path.mnt);
4153 + au_farray_free(array, max);
4159 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4163 + aufs_bindex_t bindex;
4164 + struct dentry *root;
4165 + struct au_branch *br;
4166 + struct au_br_fhsm *bf;
4168 + root = sb->s_root;
4169 + bindex = au_find_dbindex(root, mod->h_root);
4172 + return 0; /* success */
4174 + pr_err("%s no such branch\n", mod->path);
4177 + AuDbg("bindex b%d\n", bindex);
4179 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4180 + if (unlikely(err))
4183 + br = au_sbr(sb, bindex);
4184 + AuDebugOn(mod->h_root != au_br_dentry(br));
4185 + if (br->br_perm == mod->perm)
4186 + return 0; /* success */
4188 + /* pre-allocate for non-fhsm --> fhsm */
4190 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4191 + err = au_fhsm_br_alloc(br);
4192 + if (unlikely(err))
4195 + br->br_fhsm = NULL;
4198 + if (au_br_writable(br->br_perm)) {
4199 + /* remove whiteout base */
4200 + err = au_br_init_wh(sb, br, mod->perm);
4201 + if (unlikely(err))
4204 + if (!au_br_writable(mod->perm)) {
4205 + /* rw --> ro, file might be mmapped */
4206 + DiMustNoWaiters(root);
4207 + IiMustNoWaiters(d_inode(root));
4208 + di_write_unlock(root);
4209 + err = au_br_mod_files_ro(sb, bindex);
4210 + /* aufs_write_lock() calls ..._child() */
4211 + di_write_lock_child(root);
4213 + if (unlikely(err)) {
4215 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4218 + rerr = au_wbr_init(br, sb, br->br_perm);
4219 + if (unlikely(rerr)) {
4220 + AuIOErr("nested error %d (%d)\n",
4222 + br->br_perm = mod->perm;
4226 + } else if (au_br_writable(mod->perm)) {
4229 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4231 + err = au_wbr_init(br, sb, mod->perm);
4232 + if (unlikely(err)) {
4233 + au_delayed_kfree(br->br_wbr);
4234 + br->br_wbr = NULL;
4238 + if (unlikely(err))
4241 + if (au_br_fhsm(br->br_perm)) {
4242 + if (!au_br_fhsm(mod->perm)) {
4243 + /* fhsm --> non-fhsm */
4244 + au_br_fhsm_fin(br->br_fhsm);
4245 + au_delayed_kfree(br->br_fhsm);
4246 + br->br_fhsm = NULL;
4248 + } else if (au_br_fhsm(mod->perm))
4249 + /* non-fhsm --> fhsm */
4252 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4253 + br->br_perm = mod->perm;
4254 + goto out; /* success */
4258 + au_delayed_kfree(bf);
4264 +/* ---------------------------------------------------------------------- */
4266 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4269 + struct kstatfs kstfs;
4271 + err = vfs_statfs(&br->br_path, &kstfs);
4273 + stfs->f_blocks = kstfs.f_blocks;
4274 + stfs->f_bavail = kstfs.f_bavail;
4275 + stfs->f_files = kstfs.f_files;
4276 + stfs->f_ffree = kstfs.f_ffree;
4281 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4282 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4283 +++ linux/fs/aufs/branch.h 2016-10-09 16:55:36.486034798 +0200
4286 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4288 + * This program, aufs is free software; you can redistribute it and/or modify
4289 + * it under the terms of the GNU General Public License as published by
4290 + * the Free Software Foundation; either version 2 of the License, or
4291 + * (at your option) any later version.
4293 + * This program is distributed in the hope that it will be useful,
4294 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4295 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4296 + * GNU General Public License for more details.
4298 + * You should have received a copy of the GNU General Public License
4299 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4303 + * branch filesystems and xino for them
4306 +#ifndef __AUFS_BRANCH_H__
4307 +#define __AUFS_BRANCH_H__
4311 +#include <linux/mount.h>
4316 +/* ---------------------------------------------------------------------- */
4319 +struct au_xino_file {
4320 + struct file *xi_file;
4321 + struct mutex xi_nondir_mtx;
4323 + /* todo: make xino files an array to support huge inode number */
4325 +#ifdef CONFIG_DEBUG_FS
4326 + struct dentry *xi_dbgaufs;
4330 +/* File-based Hierarchical Storage Management */
4331 +struct au_br_fhsm {
4332 +#ifdef CONFIG_AUFS_FHSM
4333 + struct mutex bf_lock;
4334 + unsigned long bf_jiffy;
4335 + struct aufs_stfs bf_stfs;
4340 +/* members for writable branch only */
4341 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4343 + struct au_rwsem wbr_wh_rwsem;
4344 + struct dentry *wbr_wh[AuBrWh_Last];
4345 + atomic_t wbr_wh_running;
4346 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4347 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4348 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4351 + unsigned long long wbr_bytes;
4354 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4355 +#define AuBrDynOp (AuDyLast * 4)
4357 +#ifdef CONFIG_AUFS_HFSNOTIFY
4358 +/* support for asynchronous destruction */
4359 +struct au_br_hfsnotify {
4360 + struct fsnotify_group *hfsn_group;
4364 +/* sysfs entries */
4365 +struct au_brsysfs {
4367 + struct attribute attr;
4376 +/* protected by superblock rwsem */
4378 + struct au_xino_file br_xino;
4380 + aufs_bindex_t br_id;
4383 + struct path br_path;
4384 + spinlock_t br_dykey_lock;
4385 + struct au_dykey *br_dykey[AuBrDynOp];
4386 + struct percpu_counter br_count;
4388 + struct au_wbr *br_wbr;
4389 + struct au_br_fhsm *br_fhsm;
4391 + /* xino truncation */
4392 + atomic_t br_xino_running;
4394 +#ifdef CONFIG_AUFS_HFSNOTIFY
4395 + struct au_br_hfsnotify *br_hfsn;
4398 +#ifdef CONFIG_SYSFS
4399 + /* entries under sysfs per mount-point */
4400 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4404 +/* ---------------------------------------------------------------------- */
4406 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4408 + return br->br_path.mnt;
4411 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4413 + return br->br_path.dentry;
4416 +static inline struct super_block *au_br_sb(struct au_branch *br)
4418 + return au_br_mnt(br)->mnt_sb;
4421 +static inline void au_br_get(struct au_branch *br)
4423 + percpu_counter_inc(&br->br_count);
4426 +static inline void au_br_put(struct au_branch *br)
4428 + percpu_counter_dec(&br->br_count);
4431 +static inline s64 au_br_count(struct au_branch *br)
4433 + return percpu_counter_sum(&br->br_count);
4436 +static inline void au_br_count_init(struct au_branch *br)
4438 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4441 +static inline void au_br_count_fin(struct au_branch *br)
4443 + percpu_counter_destroy(&br->br_count);
4446 +static inline int au_br_rdonly(struct au_branch *br)
4448 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4449 + || !au_br_writable(br->br_perm))
4453 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4455 +#ifdef CONFIG_AUFS_HNOTIFY
4456 + return !(brperm & AuBrPerm_RR);
4462 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4464 + int err, exec_flag;
4467 + exec_flag = oflag & __FMODE_EXEC;
4468 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4474 +/* ---------------------------------------------------------------------- */
4478 +void au_br_free(struct au_sbinfo *sinfo);
4479 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4481 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4483 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4484 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4485 +#ifdef CONFIG_COMPAT
4486 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4489 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4492 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4495 +static const loff_t au_loff_max = LLONG_MAX;
4497 +int au_xib_trunc(struct super_block *sb);
4498 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4500 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4501 + size_t size, loff_t *pos);
4502 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4503 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4504 +ino_t au_xino_new_ino(struct super_block *sb);
4505 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4506 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4508 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4510 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4511 + struct file *base_file, int do_test);
4512 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4514 +struct au_opt_xino;
4515 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4516 +void au_xino_clr(struct super_block *sb);
4517 +struct file *au_xino_def(struct super_block *sb);
4518 +int au_xino_path(struct seq_file *seq, struct file *file);
4520 +/* ---------------------------------------------------------------------- */
4522 +/* Superblock to branch */
4524 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4526 + return au_sbr(sb, bindex)->br_id;
4530 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4532 + return au_br_mnt(au_sbr(sb, bindex));
4536 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4538 + return au_br_sb(au_sbr(sb, bindex));
4541 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4543 + au_br_get(au_sbr(sb, bindex));
4546 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4548 + au_br_put(au_sbr(sb, bindex));
4551 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4553 + return au_sbr(sb, bindex)->br_perm;
4556 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4558 + return au_br_whable(au_sbr_perm(sb, bindex));
4561 +/* ---------------------------------------------------------------------- */
4564 + * wbr_wh_read_lock, wbr_wh_write_lock
4565 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4567 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4569 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4570 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4571 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4573 +/* ---------------------------------------------------------------------- */
4575 +#ifdef CONFIG_AUFS_FHSM
4576 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4578 + mutex_init(&brfhsm->bf_lock);
4579 + brfhsm->bf_jiffy = 0;
4580 + brfhsm->bf_readable = 0;
4583 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4585 + mutex_destroy(&brfhsm->bf_lock);
4588 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4589 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4592 +#endif /* __KERNEL__ */
4593 +#endif /* __AUFS_BRANCH_H__ */
4594 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4595 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4596 +++ linux/fs/aufs/conf.mk 2016-10-09 16:55:36.486034798 +0200
4599 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4603 +AuConfStr += ${1}=${${1}}
4607 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4609 + HNOTIFY HFSNOTIFY \
4620 +$(foreach i, ${AuConfAll}, \
4621 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4623 +AuConfName = ${obj}/conf.str
4624 +${AuConfName}.tmp: FORCE
4625 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4626 +${AuConfName}: ${AuConfName}.tmp
4627 + @diff -q $< $@ > /dev/null 2>&1 || { \
4628 + echo ' GEN ' $@; \
4632 +clean-files += ${AuConfName} ${AuConfName}.tmp
4633 +${obj}/sysfs.o: ${AuConfName}
4635 +-include ${srctree}/${src}/conf_priv.mk
4636 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4637 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4638 +++ linux/fs/aufs/cpup.c 2016-10-09 16:55:38.886097714 +0200
4641 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4643 + * This program, aufs is free software; you can redistribute it and/or modify
4644 + * it under the terms of the GNU General Public License as published by
4645 + * the Free Software Foundation; either version 2 of the License, or
4646 + * (at your option) any later version.
4648 + * This program is distributed in the hope that it will be useful,
4649 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4650 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4651 + * GNU General Public License for more details.
4653 + * You should have received a copy of the GNU General Public License
4654 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4658 + * copy-up functions, see wbr_policy.c for copy-down
4661 +#include <linux/fs_stack.h>
4662 +#include <linux/mm.h>
4663 +#include <linux/task_work.h>
4666 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4668 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4669 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4671 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4673 + dst->i_flags |= iflags & ~mask;
4674 + if (au_test_fs_notime(dst->i_sb))
4675 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4678 +void au_cpup_attr_timesizes(struct inode *inode)
4680 + struct inode *h_inode;
4682 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4683 + fsstack_copy_attr_times(inode, h_inode);
4684 + fsstack_copy_inode_size(inode, h_inode);
4687 +void au_cpup_attr_nlink(struct inode *inode, int force)
4689 + struct inode *h_inode;
4690 + struct super_block *sb;
4691 + aufs_bindex_t bindex, bbot;
4694 + bindex = au_ibtop(inode);
4695 + h_inode = au_h_iptr(inode, bindex);
4697 + && !S_ISDIR(h_inode->i_mode)
4698 + && au_opt_test(au_mntflags(sb), PLINK)
4699 + && au_plink_test(inode))
4703 + * 0 can happen in revalidating.
4704 + * h_inode->i_mutex may not be held here, but it is harmless since once
4705 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4707 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4708 + * the incorrect link count.
4710 + set_nlink(inode, h_inode->i_nlink);
4713 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4714 + * it may includes whplink directory.
4716 + if (S_ISDIR(h_inode->i_mode)) {
4717 + bbot = au_ibbot(inode);
4718 + for (bindex++; bindex <= bbot; bindex++) {
4719 + h_inode = au_h_iptr(inode, bindex);
4721 + au_add_nlink(inode, h_inode);
4726 +void au_cpup_attr_changeable(struct inode *inode)
4728 + struct inode *h_inode;
4730 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4731 + inode->i_mode = h_inode->i_mode;
4732 + inode->i_uid = h_inode->i_uid;
4733 + inode->i_gid = h_inode->i_gid;
4734 + au_cpup_attr_timesizes(inode);
4735 + au_cpup_attr_flags(inode, h_inode->i_flags);
4738 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4740 + struct au_iinfo *iinfo = au_ii(inode);
4742 + IiMustWriteLock(inode);
4744 + iinfo->ii_higen = h_inode->i_generation;
4745 + iinfo->ii_hsb1 = h_inode->i_sb;
4748 +void au_cpup_attr_all(struct inode *inode, int force)
4750 + struct inode *h_inode;
4752 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4753 + au_cpup_attr_changeable(inode);
4754 + if (inode->i_nlink > 0)
4755 + au_cpup_attr_nlink(inode, force);
4756 + inode->i_rdev = h_inode->i_rdev;
4757 + inode->i_blkbits = h_inode->i_blkbits;
4758 + au_cpup_igen(inode, h_inode);
4761 +/* ---------------------------------------------------------------------- */
4763 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4765 +/* keep the timestamps of the parent dir when cpup */
4766 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4767 + struct path *h_path)
4769 + struct inode *h_inode;
4771 + dt->dt_dentry = dentry;
4772 + dt->dt_h_path = *h_path;
4773 + h_inode = d_inode(h_path->dentry);
4774 + dt->dt_atime = h_inode->i_atime;
4775 + dt->dt_mtime = h_inode->i_mtime;
4779 +void au_dtime_revert(struct au_dtime *dt)
4781 + struct iattr attr;
4784 + attr.ia_atime = dt->dt_atime;
4785 + attr.ia_mtime = dt->dt_mtime;
4786 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4787 + | ATTR_ATIME | ATTR_ATIME_SET;
4789 + /* no delegation since this is a directory */
4790 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4791 + if (unlikely(err))
4792 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4795 +/* ---------------------------------------------------------------------- */
4797 +/* internal use only */
4798 +struct au_cpup_reg_attr {
4801 + unsigned int iflags; /* inode->i_flags */
4804 +static noinline_for_stack
4805 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4806 + struct au_cpup_reg_attr *h_src_attr)
4808 + int err, sbits, icex;
4809 + unsigned int mnt_flags;
4810 + unsigned char verbose;
4812 + struct path h_path;
4813 + struct inode *h_isrc, *h_idst;
4814 + struct kstat *h_st;
4815 + struct au_branch *br;
4817 + h_path.dentry = au_h_dptr(dst, bindex);
4818 + h_idst = d_inode(h_path.dentry);
4819 + br = au_sbr(dst->d_sb, bindex);
4820 + h_path.mnt = au_br_mnt(br);
4821 + h_isrc = d_inode(h_src);
4822 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4823 + | ATTR_ATIME | ATTR_MTIME
4824 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4825 + if (h_src_attr && h_src_attr->valid) {
4826 + h_st = &h_src_attr->st;
4827 + ia.ia_uid = h_st->uid;
4828 + ia.ia_gid = h_st->gid;
4829 + ia.ia_atime = h_st->atime;
4830 + ia.ia_mtime = h_st->mtime;
4831 + if (h_idst->i_mode != h_st->mode
4832 + && !S_ISLNK(h_idst->i_mode)) {
4833 + ia.ia_valid |= ATTR_MODE;
4834 + ia.ia_mode = h_st->mode;
4836 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4837 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4839 + ia.ia_uid = h_isrc->i_uid;
4840 + ia.ia_gid = h_isrc->i_gid;
4841 + ia.ia_atime = h_isrc->i_atime;
4842 + ia.ia_mtime = h_isrc->i_mtime;
4843 + if (h_idst->i_mode != h_isrc->i_mode
4844 + && !S_ISLNK(h_idst->i_mode)) {
4845 + ia.ia_valid |= ATTR_MODE;
4846 + ia.ia_mode = h_isrc->i_mode;
4848 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4849 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4851 + /* no delegation since it is just created */
4852 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4854 + /* is this nfs only? */
4855 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4856 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4857 + ia.ia_mode = h_isrc->i_mode;
4858 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4861 + icex = br->br_perm & AuBrAttr_ICEX;
4863 + mnt_flags = au_mntflags(dst->d_sb);
4864 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4865 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4871 +/* ---------------------------------------------------------------------- */
4873 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4874 + char *buf, unsigned long blksize)
4877 + size_t sz, rbytes, wbytes;
4878 + unsigned char all_zero;
4880 + struct inode *h_inode;
4881 + /* reduce stack usage */
4884 + zp = page_address(ZERO_PAGE(0));
4885 + if (unlikely(!zp))
4886 + return -ENOMEM; /* possible? */
4891 + AuDbg("len %lld\n", len);
4893 + if (len < blksize)
4897 + /* todo: signal_pending? */
4898 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4899 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4902 + if (unlikely(err < 0))
4906 + if (len >= rbytes && rbytes == blksize)
4907 + all_zero = !memcmp(buf, zp, rbytes);
4914 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4916 + /* todo: signal_pending? */
4917 + if (unlikely(err == -EAGAIN || err == -EINTR))
4919 + if (unlikely(err < 0))
4924 + if (unlikely(err < 0))
4930 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4932 + if (unlikely(res < 0))
4939 + /* the last block may be a hole */
4940 + if (!err && all_zero) {
4941 + AuLabel(last hole);
4944 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4945 + /* nfs requires this step to make last hole */
4946 + /* is this only nfs? */
4948 + /* todo: signal_pending? */
4949 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4950 + } while (err == -EAGAIN || err == -EINTR);
4957 + ia->ia_size = dst->f_pos;
4958 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4959 + ia->ia_file = dst;
4960 + h_inode = file_inode(dst);
4961 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
4962 + /* no delegation since it is just created */
4963 + err = vfsub_notify_change(&dst->f_path, ia,
4964 + /*delegated*/NULL);
4965 + inode_unlock(h_inode);
4972 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4975 + unsigned long blksize;
4976 + unsigned char do_kfree;
4980 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
4981 + if (!blksize || PAGE_SIZE < blksize)
4982 + blksize = PAGE_SIZE;
4983 + AuDbg("blksize %lu\n", blksize);
4984 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4986 + buf = kmalloc(blksize, GFP_NOFS);
4988 + buf = (void *)__get_free_page(GFP_NOFS);
4989 + if (unlikely(!buf))
4992 + if (len > (1 << 22))
4993 + AuDbg("copying a large file %lld\n", (long long)len);
4997 + err = au_do_copy_file(dst, src, len, buf, blksize);
4999 + au_delayed_kfree(buf);
5001 + au_delayed_free_page((unsigned long)buf);
5008 + * to support a sparse file which is opened with O_APPEND,
5009 + * we need to close the file.
5011 +static int au_cp_regular(struct au_cp_generic *cpg)
5014 + enum { SRC, DST };
5016 + aufs_bindex_t bindex;
5017 + unsigned int flags;
5018 + struct dentry *dentry;
5020 + struct file *file;
5024 + .bindex = cpg->bsrc,
5025 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5029 + .bindex = cpg->bdst,
5030 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5031 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5032 + .label = &&out_src
5035 + struct super_block *sb;
5036 + struct inode *h_src_inode;
5037 + struct task_struct *tsk = current;
5039 + /* bsrc branch can be ro/rw. */
5040 + sb = cpg->dentry->d_sb;
5042 + for (i = 0; i < 2; i++, f++) {
5043 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5044 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5045 + /*file*/NULL, f->force_wr);
5046 + err = PTR_ERR(f->file);
5047 + if (IS_ERR(f->file))
5051 + /* try stopping to update while we copyup */
5052 + h_src_inode = d_inode(file[SRC].dentry);
5053 + if (!au_test_nfs(h_src_inode->i_sb))
5054 + IMustLock(h_src_inode);
5055 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
5057 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5058 + if (tsk->flags & PF_KTHREAD)
5059 + __fput_sync(file[DST].file);
5061 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
5063 + fput(file[DST].file);
5066 + * we have to call both since we don't know which place the file
5070 + flush_delayed_fput();
5072 + au_sbr_put(sb, file[DST].bindex);
5075 + fput(file[SRC].file);
5076 + au_sbr_put(sb, file[SRC].bindex);
5081 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5082 + struct au_cpup_reg_attr *h_src_attr)
5086 + struct path h_path;
5087 + struct inode *h_src_inode, *h_dst_inode;
5090 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5091 + l = i_size_read(h_src_inode);
5092 + if (cpg->len == -1 || l < cpg->len)
5095 + /* try stopping to update while we are referencing */
5096 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5097 + au_pin_hdir_unlock(cpg->pin);
5099 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5100 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5101 + h_src_attr->iflags = h_src_inode->i_flags;
5102 + if (!au_test_nfs(h_src_inode->i_sb))
5103 + err = vfs_getattr(&h_path, &h_src_attr->st);
5105 + inode_unlock(h_src_inode);
5106 + err = vfs_getattr(&h_path, &h_src_attr->st);
5107 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5109 + if (unlikely(err)) {
5110 + inode_unlock(h_src_inode);
5113 + h_src_attr->valid = 1;
5114 + if (!au_test_nfs(h_src_inode->i_sb)) {
5115 + err = au_cp_regular(cpg);
5116 + inode_unlock(h_src_inode);
5118 + inode_unlock(h_src_inode);
5119 + err = au_cp_regular(cpg);
5121 + rerr = au_pin_hdir_relock(cpg->pin);
5125 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5126 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5127 + h_dst_inode = d_inode(h_path.dentry);
5128 + spin_lock(&h_dst_inode->i_lock);
5129 + h_dst_inode->i_state |= I_LINKABLE;
5130 + spin_unlock(&h_dst_inode->i_lock);
5137 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5138 + struct inode *h_dir)
5141 + mm_segment_t old_fs;
5146 + struct inode *h_inode = d_inode(h_src);
5147 + const struct inode_operations *h_iop = h_inode->i_op;
5150 + if (unlikely(!h_iop->readlink))
5154 + sym.k = (void *)__get_free_page(GFP_NOFS);
5155 + if (unlikely(!sym.k))
5158 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5159 + old_fs = get_fs();
5160 + set_fs(KERNEL_DS);
5161 + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX);
5166 + sym.k[symlen] = 0;
5167 + err = vfsub_symlink(h_dir, h_path, sym.k);
5169 + au_delayed_free_page((unsigned long)sym.k);
5176 + * regardless 'acl' option, reset all ACL.
5177 + * All ACL will be copied up later from the original entry on the lower branch.
5179 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5182 + struct dentry *h_dentry;
5183 + struct inode *h_inode;
5185 + h_dentry = h_path->dentry;
5186 + h_inode = d_inode(h_dentry);
5187 + /* forget_all_cached_acls(h_inode)); */
5188 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5190 + if (err == -EOPNOTSUPP)
5193 + err = vfsub_acl_chmod(h_inode, mode);
5199 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5200 + struct inode *h_dir, struct path *h_path)
5203 + struct inode *dir, *inode;
5205 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5207 + if (err == -EOPNOTSUPP)
5209 + if (unlikely(err))
5213 + * strange behaviour from the users view,
5214 + * particularry setattr case
5216 + dir = d_inode(dst_parent);
5217 + if (au_ibtop(dir) == cpg->bdst)
5218 + au_cpup_attr_nlink(dir, /*force*/1);
5219 + inode = d_inode(cpg->dentry);
5220 + au_cpup_attr_nlink(inode, /*force*/1);
5226 +static noinline_for_stack
5227 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5228 + struct au_cpup_reg_attr *h_src_attr)
5232 + unsigned int mnt_flags;
5233 + unsigned char isdir, isreg, force;
5234 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5235 + struct au_dtime dt;
5236 + struct path h_path;
5237 + struct dentry *h_src, *h_dst, *h_parent;
5238 + struct inode *h_inode, *h_dir;
5239 + struct super_block *sb;
5241 + /* bsrc branch can be ro/rw. */
5242 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5243 + h_inode = d_inode(h_src);
5244 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5246 + /* try stopping to be referenced while we are creating */
5247 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5248 + if (au_ftest_cpup(cpg->flags, RENAME))
5249 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5250 + AUFS_WH_PFX_LEN));
5251 + h_parent = h_dst->d_parent; /* dir inode is locked */
5252 + h_dir = d_inode(h_parent);
5254 + AuDebugOn(h_parent != h_dst->d_parent);
5256 + sb = cpg->dentry->d_sb;
5257 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5259 + h_path.dentry = h_parent;
5260 + au_dtime_store(&dt, dst_parent, &h_path);
5262 + h_path.dentry = h_dst;
5266 + mode = h_inode->i_mode;
5267 + switch (mode & S_IFMT) {
5270 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5271 + /*want_excl*/true);
5273 + err = au_do_cpup_regular(cpg, h_src_attr);
5277 + err = vfsub_mkdir(h_dir, &h_path, mode);
5279 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5282 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5286 + AuDebugOn(!capable(CAP_MKNOD));
5290 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5293 + AuIOErr("Unknown inode type 0%o\n", mode);
5297 + err = au_reset_acl(h_dir, &h_path, mode);
5299 + mnt_flags = au_mntflags(sb);
5300 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5302 + && au_opt_test(mnt_flags, XINO)
5303 + && (h_inode->i_nlink == 1
5304 + || (h_inode->i_state & I_LINKABLE))
5305 + /* todo: unnecessary? */
5306 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5307 + && cpg->bdst < cpg->bsrc
5308 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5309 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5310 + /* ignore this error */
5315 + force = !!cpg->len;
5316 + if (cpg->len == -1)
5317 + force = !!i_size_read(h_inode);
5319 + au_fhsm_wrote(sb, cpg->bdst, force);
5323 + au_dtime_revert(&dt);
5327 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5330 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5331 + struct inode *h_dir;
5332 + aufs_bindex_t bdst;
5334 + dentry = cpg->dentry;
5336 + h_dentry = au_h_dptr(dentry, bdst);
5337 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5339 + au_set_h_dptr(dentry, bdst, NULL);
5340 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5342 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5343 + au_set_h_dptr(dentry, bdst, h_dentry);
5346 + parent = dget_parent(dentry);
5347 + h_parent = au_h_dptr(parent, bdst);
5349 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5350 + if (IS_ERR(h_path->dentry))
5351 + err = PTR_ERR(h_path->dentry);
5353 + if (unlikely(err))
5356 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5357 + h_dir = d_inode(h_parent);
5359 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5360 + /* no delegation since it is just created */
5361 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL);
5362 + dput(h_path->dentry);
5369 + * copyup the @dentry from @bsrc to @bdst.
5370 + * the caller must set the both of lower dentries.
5371 + * @len is for truncating when it is -1 copyup the entire file.
5372 + * in link/rename cases, @dst_parent may be different from the real one.
5373 + * basic->bsrc can be larger than basic->bdst.
5375 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5378 + aufs_bindex_t old_ibtop;
5379 + unsigned char isdir, plink;
5380 + struct dentry *h_src, *h_dst, *h_parent;
5381 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5382 + struct super_block *sb;
5383 + struct au_branch *br;
5384 + /* to reuduce stack size */
5386 + struct au_dtime dt;
5387 + struct path h_path;
5388 + struct au_cpup_reg_attr h_src_attr;
5392 + a = kmalloc(sizeof(*a), GFP_NOFS);
5395 + a->h_src_attr.valid = 0;
5397 + sb = cpg->dentry->d_sb;
5398 + br = au_sbr(sb, cpg->bdst);
5399 + a->h_path.mnt = au_br_mnt(br);
5400 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5401 + h_parent = h_dst->d_parent; /* dir inode is locked */
5402 + h_dir = d_inode(h_parent);
5405 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5406 + inode = d_inode(cpg->dentry);
5409 + dst_parent = dget_parent(cpg->dentry);
5413 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5414 + dst_inode = au_h_iptr(inode, cpg->bdst);
5416 + if (unlikely(!plink)) {
5418 + AuIOErr("hi%lu(i%lu) exists on b%d "
5419 + "but plink is disabled\n",
5420 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5424 + if (dst_inode->i_nlink) {
5425 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5427 + h_src = au_plink_lkup(inode, cpg->bdst);
5428 + err = PTR_ERR(h_src);
5429 + if (IS_ERR(h_src))
5431 + if (unlikely(d_is_negative(h_src))) {
5433 + AuIOErr("i%lu exists on b%d "
5434 + "but not pseudo-linked\n",
5435 + inode->i_ino, cpg->bdst);
5441 + a->h_path.dentry = h_parent;
5442 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5445 + a->h_path.dentry = h_dst;
5447 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5448 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5449 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5451 + au_dtime_revert(&a->dt);
5452 + if (unlikely(err == -EWOULDBLOCK)) {
5453 + pr_warn("cannot retry for NFSv4 delegation"
5454 + " for an internal link\n");
5460 + /* todo: cpup_wh_file? */
5462 + au_update_ibrange(inode, /*do_put_zero*/1);
5465 + isdir = S_ISDIR(inode->i_mode);
5466 + old_ibtop = au_ibtop(inode);
5467 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5468 + if (unlikely(err))
5470 + dst_inode = d_inode(h_dst);
5471 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5472 + /* todo: necessary? */
5473 + /* au_pin_hdir_unlock(cpg->pin); */
5475 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5476 + if (unlikely(err)) {
5477 + /* todo: necessary? */
5478 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5479 + inode_unlock(dst_inode);
5483 + if (cpg->bdst < old_ibtop) {
5484 + if (S_ISREG(inode->i_mode)) {
5485 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5486 + if (unlikely(err)) {
5487 + /* ignore an error */
5488 + /* au_pin_hdir_relock(cpg->pin); */
5489 + inode_unlock(dst_inode);
5493 + au_set_ibtop(inode, cpg->bdst);
5495 + au_set_ibbot(inode, cpg->bdst);
5496 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5497 + au_hi_flags(inode, isdir));
5499 + /* todo: necessary? */
5500 + /* err = au_pin_hdir_relock(cpg->pin); */
5501 + inode_unlock(dst_inode);
5502 + if (unlikely(err))
5505 + src_inode = d_inode(h_src);
5507 + && (src_inode->i_nlink > 1
5508 + || src_inode->i_state & I_LINKABLE)
5510 + au_plink_append(inode, cpg->bdst, h_dst);
5512 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5513 + a->h_path.dentry = h_dst;
5514 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5517 + goto out_parent; /* success */
5521 + a->h_path.dentry = h_parent;
5522 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5523 + a->h_path.dentry = h_dst;
5525 + if (d_is_positive(h_dst)) {
5527 + /* no delegation since it is just created */
5528 + rerr = vfsub_unlink(h_dir, &a->h_path,
5529 + /*delegated*/NULL, /*force*/0);
5531 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5533 + au_dtime_revert(&a->dt);
5535 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5540 + au_delayed_kfree(a);
5545 +#if 0 /* reserved */
5546 +struct au_cpup_single_args {
5548 + struct au_cp_generic *cpg;
5549 + struct dentry *dst_parent;
5552 +static void au_call_cpup_single(void *args)
5554 + struct au_cpup_single_args *a = args;
5556 + au_pin_hdir_acquire_nest(a->cpg->pin);
5557 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5558 + au_pin_hdir_release(a->cpg->pin);
5563 + * prevent SIGXFSZ in copy-up.
5564 + * testing CAP_MKNOD is for generic fs,
5565 + * but CAP_FSETID is for xfs only, currently.
5567 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5570 + struct super_block *sb;
5571 + struct inode *h_dir;
5574 + sb = au_pinned_parent(pin)->d_sb;
5575 + if (!au_wkq_test()
5576 + && (!au_sbi(sb)->si_plink_maint_pid
5577 + || au_plink_maint(sb, AuLock_NOPLM))) {
5578 + switch (mode & S_IFMT) {
5580 + /* no condition about RLIMIT_FSIZE and the file size */
5585 + do_sio = !capable(CAP_MKNOD);
5589 + do_sio = ((mode & (S_ISUID | S_ISGID))
5590 + && !capable(CAP_FSETID));
5591 + /* this workaround may be removed in the future */
5593 + h_dir = au_pinned_h_dir(pin);
5594 + do_sio = h_dir->i_mode & S_ISVTX;
5601 +#if 0 /* reserved */
5602 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5605 + struct dentry *h_dentry;
5607 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5608 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5609 + err = au_cpup_single(cpg, dst_parent);
5611 + struct au_cpup_single_args args = {
5614 + .dst_parent = dst_parent
5616 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5617 + if (unlikely(wkq_err))
5626 + * copyup the @dentry from the first active lower branch to @bdst,
5627 + * using au_cpup_single().
5629 +static int au_cpup_simple(struct au_cp_generic *cpg)
5632 + unsigned int flags_orig;
5633 + struct dentry *dentry;
5635 + AuDebugOn(cpg->bsrc < 0);
5637 + dentry = cpg->dentry;
5638 + DiMustWriteLock(dentry);
5640 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5642 + flags_orig = cpg->flags;
5643 + au_fset_cpup(cpg->flags, RENAME);
5644 + err = au_cpup_single(cpg, NULL);
5645 + cpg->flags = flags_orig;
5647 + return 0; /* success */
5650 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5651 + au_set_dbtop(dentry, cpg->bsrc);
5657 +struct au_cpup_simple_args {
5659 + struct au_cp_generic *cpg;
5662 +static void au_call_cpup_simple(void *args)
5664 + struct au_cpup_simple_args *a = args;
5666 + au_pin_hdir_acquire_nest(a->cpg->pin);
5667 + *a->errp = au_cpup_simple(a->cpg);
5668 + au_pin_hdir_release(a->cpg->pin);
5671 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5674 + struct dentry *dentry, *parent;
5675 + struct file *h_file;
5676 + struct inode *h_dir;
5678 + dentry = cpg->dentry;
5680 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5681 + AuDebugOn(cpg->bsrc < 0);
5682 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5683 + err = PTR_ERR(h_file);
5684 + if (IS_ERR(h_file))
5688 + parent = dget_parent(dentry);
5689 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5690 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5691 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5692 + err = au_cpup_simple(cpg);
5694 + struct au_cpup_simple_args args = {
5698 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5699 + if (unlikely(wkq_err))
5705 + au_h_open_post(dentry, cpg->bsrc, h_file);
5711 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5713 + aufs_bindex_t bsrc, bbot;
5714 + struct dentry *dentry, *h_dentry;
5716 + if (cpg->bsrc < 0) {
5717 + dentry = cpg->dentry;
5718 + bbot = au_dbbot(dentry);
5719 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5720 + h_dentry = au_h_dptr(dentry, bsrc);
5722 + AuDebugOn(d_is_negative(h_dentry));
5726 + AuDebugOn(bsrc > bbot);
5729 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5730 + return au_do_sio_cpup_simple(cpg);
5733 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5735 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5736 + return au_do_sio_cpup_simple(cpg);
5739 +/* ---------------------------------------------------------------------- */
5742 + * copyup the deleted file for writing.
5744 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5745 + struct file *file)
5748 + unsigned int flags_orig;
5749 + aufs_bindex_t bsrc_orig;
5750 + struct au_dinfo *dinfo;
5752 + struct au_hdentry *hd;
5753 + struct dentry *h_dentry;
5756 + dinfo = au_di(cpg->dentry);
5757 + AuRwMustWriteLock(&dinfo->di_rwsem);
5759 + bsrc_orig = cpg->bsrc;
5760 + cpg->bsrc = dinfo->di_btop;
5761 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5762 + hdst.h_dentry = hdst.hd->hd_dentry;
5763 + hdst.hd->hd_dentry = wh_dentry;
5764 + dinfo->di_btop = cpg->bdst;
5766 + hsrc.h_dentry = NULL;
5768 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5769 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5770 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5772 + flags_orig = cpg->flags;
5773 + cpg->flags = !AuCpup_DTIME;
5774 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5775 + cpg->flags = flags_orig;
5778 + err = au_reopen_nondir(file);
5779 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5781 + hdst.hd->hd_dentry = hdst.h_dentry;
5782 + dinfo->di_btop = cpg->bsrc;
5783 + cpg->bsrc = bsrc_orig;
5788 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5791 + aufs_bindex_t bdst;
5792 + struct au_dtime dt;
5793 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5794 + struct au_branch *br;
5795 + struct path h_path;
5797 + dentry = cpg->dentry;
5799 + br = au_sbr(dentry->d_sb, bdst);
5800 + parent = dget_parent(dentry);
5801 + h_parent = au_h_dptr(parent, bdst);
5802 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5803 + err = PTR_ERR(wh_dentry);
5804 + if (IS_ERR(wh_dentry))
5807 + h_path.dentry = h_parent;
5808 + h_path.mnt = au_br_mnt(br);
5809 + au_dtime_store(&dt, parent, &h_path);
5810 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5811 + if (unlikely(err))
5815 + h_path.dentry = wh_dentry;
5816 + if (!d_is_dir(wh_dentry)) {
5817 + /* no delegation since it is just created */
5818 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5819 + /*delegated*/NULL, /*force*/0);
5821 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5822 + if (unlikely(err)) {
5823 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5827 + au_dtime_revert(&dt);
5828 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5837 +struct au_cpup_wh_args {
5839 + struct au_cp_generic *cpg;
5840 + struct file *file;
5843 +static void au_call_cpup_wh(void *args)
5845 + struct au_cpup_wh_args *a = args;
5847 + au_pin_hdir_acquire_nest(a->cpg->pin);
5848 + *a->errp = au_cpup_wh(a->cpg, a->file);
5849 + au_pin_hdir_release(a->cpg->pin);
5852 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5855 + aufs_bindex_t bdst;
5856 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5857 + struct inode *dir, *h_dir, *h_tmpdir;
5858 + struct au_wbr *wbr;
5859 + struct au_pin wh_pin, *pin_orig;
5861 + dentry = cpg->dentry;
5863 + parent = dget_parent(dentry);
5864 + dir = d_inode(parent);
5867 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5870 + if (!h_dir->i_nlink) {
5871 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5872 + h_orph = wbr->wbr_orph;
5874 + h_parent = dget(au_h_dptr(parent, bdst));
5875 + au_set_h_dptr(parent, bdst, dget(h_orph));
5876 + h_tmpdir = d_inode(h_orph);
5877 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5879 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
5880 + /* todo: au_h_open_pre()? */
5882 + pin_orig = cpg->pin;
5883 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5884 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5885 + cpg->pin = &wh_pin;
5888 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5889 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5890 + err = au_cpup_wh(cpg, file);
5892 + struct au_cpup_wh_args args = {
5897 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5898 + if (unlikely(wkq_err))
5903 + inode_unlock(h_tmpdir);
5904 + /* todo: au_h_open_post()? */
5905 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5906 + au_set_h_dptr(parent, bdst, h_parent);
5907 + AuDebugOn(!pin_orig);
5908 + cpg->pin = pin_orig;
5916 +/* ---------------------------------------------------------------------- */
5919 + * generic routine for both of copy-up and copy-down.
5921 +/* cf. revalidate function in file.c */
5922 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5923 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5924 + struct au_pin *pin,
5925 + struct dentry *h_parent, void *arg),
5929 + struct au_pin pin;
5930 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
5933 + parent = dget_parent(dentry);
5934 + if (IS_ROOT(parent))
5937 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5938 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5940 + /* do not use au_dpage */
5941 + real_parent = parent;
5944 + parent = dget_parent(dentry);
5945 + h_parent = au_h_dptr(parent, bdst);
5947 + goto out; /* success */
5949 + /* find top dir which is necessary to cpup */
5953 + parent = dget_parent(d);
5954 + di_read_lock_parent3(parent, !AuLock_IR);
5955 + h_parent = au_h_dptr(parent, bdst);
5956 + di_read_unlock(parent, !AuLock_IR);
5957 + } while (!h_parent);
5959 + if (d != real_parent)
5960 + di_write_lock_child3(d);
5962 + /* somebody else might create while we were sleeping */
5963 + h_dentry = au_h_dptr(d, bdst);
5964 + if (!h_dentry || d_is_negative(h_dentry)) {
5966 + au_update_dbtop(d);
5968 + au_pin_set_dentry(&pin, d);
5969 + err = au_do_pin(&pin);
5971 + err = cp(d, bdst, &pin, h_parent, arg);
5976 + if (d != real_parent)
5977 + di_write_unlock(d);
5978 + if (unlikely(err))
5987 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
5988 + struct au_pin *pin,
5989 + struct dentry *h_parent __maybe_unused,
5990 + void *arg __maybe_unused)
5992 + struct au_cp_generic cpg = {
5998 + .flags = AuCpup_DTIME
6000 + return au_sio_cpup_simple(&cpg);
6003 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6005 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6008 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6011 + struct dentry *parent;
6012 + struct inode *dir;
6014 + parent = dget_parent(dentry);
6015 + dir = d_inode(parent);
6017 + if (au_h_iptr(dir, bdst))
6020 + di_read_unlock(parent, AuLock_IR);
6021 + di_write_lock_parent(parent);
6022 + /* someone else might change our inode while we were sleeping */
6023 + if (!au_h_iptr(dir, bdst))
6024 + err = au_cpup_dirs(dentry, bdst);
6025 + di_downgrade_lock(parent, AuLock_IR);
6031 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6032 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6033 +++ linux/fs/aufs/cpup.h 2016-10-09 16:55:36.486034798 +0200
6036 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6038 + * This program, aufs is free software; you can redistribute it and/or modify
6039 + * it under the terms of the GNU General Public License as published by
6040 + * the Free Software Foundation; either version 2 of the License, or
6041 + * (at your option) any later version.
6043 + * This program is distributed in the hope that it will be useful,
6044 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6045 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6046 + * GNU General Public License for more details.
6048 + * You should have received a copy of the GNU General Public License
6049 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6053 + * copy-up/down functions
6056 +#ifndef __AUFS_CPUP_H__
6057 +#define __AUFS_CPUP_H__
6061 +#include <linux/path.h>
6067 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6068 +void au_cpup_attr_timesizes(struct inode *inode);
6069 +void au_cpup_attr_nlink(struct inode *inode, int force);
6070 +void au_cpup_attr_changeable(struct inode *inode);
6071 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6072 +void au_cpup_attr_all(struct inode *inode, int force);
6074 +/* ---------------------------------------------------------------------- */
6076 +struct au_cp_generic {
6077 + struct dentry *dentry;
6078 + aufs_bindex_t bdst, bsrc;
6080 + struct au_pin *pin;
6081 + unsigned int flags;
6085 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6086 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6088 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6089 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6091 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6093 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6094 + the branch is marked as RO */
6096 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6097 +#define au_fset_cpup(flags, name) \
6098 + do { (flags) |= AuCpup_##name; } while (0)
6099 +#define au_fclr_cpup(flags, name) \
6100 + do { (flags) &= ~AuCpup_##name; } while (0)
6102 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6103 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6104 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6105 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6107 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6108 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6109 + struct au_pin *pin,
6110 + struct dentry *h_parent, void *arg),
6112 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6113 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6115 +/* ---------------------------------------------------------------------- */
6117 +/* keep timestamps when copyup */
6119 + struct dentry *dt_dentry;
6120 + struct path dt_h_path;
6121 + struct timespec dt_atime, dt_mtime;
6123 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6124 + struct path *h_path);
6125 +void au_dtime_revert(struct au_dtime *dt);
6127 +#endif /* __KERNEL__ */
6128 +#endif /* __AUFS_CPUP_H__ */
6129 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6130 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6131 +++ linux/fs/aufs/dbgaufs.c 2016-10-09 16:55:38.886097714 +0200
6134 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6136 + * This program, aufs is free software; you can redistribute it and/or modify
6137 + * it under the terms of the GNU General Public License as published by
6138 + * the Free Software Foundation; either version 2 of the License, or
6139 + * (at your option) any later version.
6141 + * This program is distributed in the hope that it will be useful,
6142 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6143 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6144 + * GNU General Public License for more details.
6146 + * You should have received a copy of the GNU General Public License
6147 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6151 + * debugfs interface
6154 +#include <linux/debugfs.h>
6157 +#ifndef CONFIG_SYSFS
6158 +#error DEBUG_FS depends upon SYSFS
6161 +static struct dentry *dbgaufs;
6162 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6164 +/* 20 is max digits length of ulong 64 */
6165 +struct dbgaufs_arg {
6171 + * common function for all XINO files
6173 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6174 + struct file *file)
6176 + au_delayed_kfree(file->private_data);
6180 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6184 + struct dbgaufs_arg *p;
6187 + p = kmalloc(sizeof(*p), GFP_NOFS);
6193 + file->private_data = p;
6197 + err = vfs_getattr(&xf->f_path, &st);
6201 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
6202 + (long)file_count(xf), st.blocks, st.blksize,
6203 + (long long)st.size);
6205 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
6206 + st.blocks, st.blksize,
6207 + (long long)st.size);
6208 + AuDebugOn(p->n >= sizeof(p->a));
6210 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6219 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6220 + size_t count, loff_t *ppos)
6222 + struct dbgaufs_arg *p;
6224 + p = file->private_data;
6225 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6228 +/* ---------------------------------------------------------------------- */
6230 +struct dbgaufs_plink_arg {
6235 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6236 + struct file *file)
6238 + au_delayed_free_page((unsigned long)file->private_data);
6242 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6244 + int err, i, limit;
6245 + unsigned long n, sum;
6246 + struct dbgaufs_plink_arg *p;
6247 + struct au_sbinfo *sbinfo;
6248 + struct super_block *sb;
6249 + struct au_sphlhead *sphl;
6252 + p = (void *)get_zeroed_page(GFP_NOFS);
6257 + sbinfo = inode->i_private;
6258 + sb = sbinfo->si_sb;
6259 + si_noflush_read_lock(sb);
6260 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6261 + limit = PAGE_SIZE - sizeof(p->n);
6263 + /* the number of buckets */
6264 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6269 + for (i = 0, sphl = sbinfo->si_plink;
6270 + i < AuPlink_NHASH;
6272 + n = au_sphl_count(sphl);
6275 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6278 + if (unlikely(limit <= 0))
6281 + p->a[p->n - 1] = '\n';
6283 + /* the sum of plinks */
6284 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6287 + if (unlikely(limit <= 0))
6290 +#define str "1\n0\n0\n"
6291 + p->n = sizeof(str) - 1;
6292 + strcpy(p->a, str);
6295 + si_read_unlock(sb);
6298 + file->private_data = p;
6299 + goto out; /* success */
6302 + au_delayed_free_page((unsigned long)p);
6307 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6308 + size_t count, loff_t *ppos)
6310 + struct dbgaufs_plink_arg *p;
6312 + p = file->private_data;
6313 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6316 +static const struct file_operations dbgaufs_plink_fop = {
6317 + .owner = THIS_MODULE,
6318 + .open = dbgaufs_plink_open,
6319 + .release = dbgaufs_plink_release,
6320 + .read = dbgaufs_plink_read
6323 +/* ---------------------------------------------------------------------- */
6325 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6328 + struct au_sbinfo *sbinfo;
6329 + struct super_block *sb;
6331 + sbinfo = inode->i_private;
6332 + sb = sbinfo->si_sb;
6333 + si_noflush_read_lock(sb);
6334 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6335 + si_read_unlock(sb);
6339 +static const struct file_operations dbgaufs_xib_fop = {
6340 + .owner = THIS_MODULE,
6341 + .open = dbgaufs_xib_open,
6342 + .release = dbgaufs_xi_release,
6343 + .read = dbgaufs_xi_read
6346 +/* ---------------------------------------------------------------------- */
6348 +#define DbgaufsXi_PREFIX "xi"
6350 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6354 + struct au_sbinfo *sbinfo;
6355 + struct super_block *sb;
6357 + struct qstr *name;
6361 + name = &file->f_path.dentry->d_name;
6362 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6363 + || memcmp(name->name, DbgaufsXi_PREFIX,
6364 + sizeof(DbgaufsXi_PREFIX) - 1)))
6366 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6367 + if (unlikely(err))
6370 + sbinfo = inode->i_private;
6371 + sb = sbinfo->si_sb;
6372 + si_noflush_read_lock(sb);
6373 + if (l <= au_sbbot(sb)) {
6374 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6375 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6378 + si_read_unlock(sb);
6384 +static const struct file_operations dbgaufs_xino_fop = {
6385 + .owner = THIS_MODULE,
6386 + .open = dbgaufs_xino_open,
6387 + .release = dbgaufs_xi_release,
6388 + .read = dbgaufs_xi_read
6391 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6393 + aufs_bindex_t bbot;
6394 + struct au_branch *br;
6395 + struct au_xino_file *xi;
6397 + if (!au_sbi(sb)->si_dbgaufs)
6400 + bbot = au_sbbot(sb);
6401 + for (; bindex <= bbot; bindex++) {
6402 + br = au_sbr(sb, bindex);
6403 + xi = &br->br_xino;
6404 + /* debugfs acquires the parent i_mutex */
6406 + debugfs_remove(xi->xi_dbgaufs);
6408 + xi->xi_dbgaufs = NULL;
6412 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6414 + struct au_sbinfo *sbinfo;
6415 + struct dentry *parent;
6416 + struct au_branch *br;
6417 + struct au_xino_file *xi;
6418 + aufs_bindex_t bbot;
6419 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6421 + sbinfo = au_sbi(sb);
6422 + parent = sbinfo->si_dbgaufs;
6426 + bbot = au_sbbot(sb);
6427 + for (; bindex <= bbot; bindex++) {
6428 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6429 + br = au_sbr(sb, bindex);
6430 + xi = &br->br_xino;
6431 + AuDebugOn(xi->xi_dbgaufs);
6432 + /* debugfs acquires the parent i_mutex */
6434 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6435 + sbinfo, &dbgaufs_xino_fop);
6437 + /* ignore an error */
6438 + if (unlikely(!xi->xi_dbgaufs))
6439 + AuWarn1("failed %s under debugfs\n", name);
6443 +/* ---------------------------------------------------------------------- */
6445 +#ifdef CONFIG_AUFS_EXPORT
6446 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6449 + struct au_sbinfo *sbinfo;
6450 + struct super_block *sb;
6452 + sbinfo = inode->i_private;
6453 + sb = sbinfo->si_sb;
6454 + si_noflush_read_lock(sb);
6455 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6456 + si_read_unlock(sb);
6460 +static const struct file_operations dbgaufs_xigen_fop = {
6461 + .owner = THIS_MODULE,
6462 + .open = dbgaufs_xigen_open,
6463 + .release = dbgaufs_xi_release,
6464 + .read = dbgaufs_xi_read
6467 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6472 + * This function is a dynamic '__init' function actually,
6473 + * so the tiny check for si_rwsem is unnecessary.
6475 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6478 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6479 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6480 + &dbgaufs_xigen_fop);
6481 + if (sbinfo->si_dbgaufs_xigen)
6487 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6491 +#endif /* CONFIG_AUFS_EXPORT */
6493 +/* ---------------------------------------------------------------------- */
6495 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6498 + * This function is a dynamic '__fin' function actually,
6499 + * so the tiny check for si_rwsem is unnecessary.
6501 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6503 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6504 + sbinfo->si_dbgaufs = NULL;
6505 + kobject_put(&sbinfo->si_kobj);
6508 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6511 + char name[SysaufsSiNameLen];
6514 + * This function is a dynamic '__init' function actually,
6515 + * so the tiny check for si_rwsem is unnecessary.
6517 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6521 + AuErr1("/debug/aufs is uninitialized\n");
6526 + sysaufs_name(sbinfo, name);
6527 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6528 + if (unlikely(!sbinfo->si_dbgaufs))
6530 + kobject_get(&sbinfo->si_kobj);
6532 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6533 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6534 + &dbgaufs_xib_fop);
6535 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6538 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6539 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6540 + &dbgaufs_plink_fop);
6541 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6544 + err = dbgaufs_xigen_init(sbinfo);
6546 + goto out; /* success */
6549 + dbgaufs_si_fin(sbinfo);
6554 +/* ---------------------------------------------------------------------- */
6556 +void dbgaufs_fin(void)
6558 + debugfs_remove(dbgaufs);
6561 +int __init dbgaufs_init(void)
6566 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6571 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6572 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6573 +++ linux/fs/aufs/dbgaufs.h 2016-10-09 16:55:36.486034798 +0200
6576 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6578 + * This program, aufs is free software; you can redistribute it and/or modify
6579 + * it under the terms of the GNU General Public License as published by
6580 + * the Free Software Foundation; either version 2 of the License, or
6581 + * (at your option) any later version.
6583 + * This program is distributed in the hope that it will be useful,
6584 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6585 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6586 + * GNU General Public License for more details.
6588 + * You should have received a copy of the GNU General Public License
6589 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6593 + * debugfs interface
6596 +#ifndef __DBGAUFS_H__
6597 +#define __DBGAUFS_H__
6601 +struct super_block;
6604 +#ifdef CONFIG_DEBUG_FS
6606 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6607 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6608 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6609 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6610 +void dbgaufs_fin(void);
6611 +int __init dbgaufs_init(void);
6613 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6614 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6615 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6616 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6617 +AuStubVoid(dbgaufs_fin, void)
6618 +AuStubInt0(__init dbgaufs_init, void)
6619 +#endif /* CONFIG_DEBUG_FS */
6621 +#endif /* __KERNEL__ */
6622 +#endif /* __DBGAUFS_H__ */
6623 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6624 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6625 +++ linux/fs/aufs/dcsub.c 2016-10-09 16:55:38.886097714 +0200
6628 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6630 + * This program, aufs is free software; you can redistribute it and/or modify
6631 + * it under the terms of the GNU General Public License as published by
6632 + * the Free Software Foundation; either version 2 of the License, or
6633 + * (at your option) any later version.
6635 + * This program is distributed in the hope that it will be useful,
6636 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6637 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6638 + * GNU General Public License for more details.
6640 + * You should have received a copy of the GNU General Public License
6641 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6645 + * sub-routines for dentry cache
6650 +static void au_dpage_free(struct au_dpage *dpage)
6653 + struct dentry **p;
6655 + p = dpage->dentries;
6656 + for (i = 0; i < dpage->ndentry; i++)
6658 + au_delayed_free_page((unsigned long)dpage->dentries);
6661 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6667 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6668 + if (unlikely(!dpages->dpages))
6671 + p = (void *)__get_free_page(gfp);
6675 + dpages->dpages[0].ndentry = 0;
6676 + dpages->dpages[0].dentries = p;
6677 + dpages->ndpage = 1;
6678 + return 0; /* success */
6681 + au_delayed_kfree(dpages->dpages);
6686 +void au_dpages_free(struct au_dcsub_pages *dpages)
6689 + struct au_dpage *p;
6691 + p = dpages->dpages;
6692 + for (i = 0; i < dpages->ndpage; i++)
6693 + au_dpage_free(p++);
6694 + au_delayed_kfree(dpages->dpages);
6697 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6698 + struct dentry *dentry, gfp_t gfp)
6701 + struct au_dpage *dpage;
6704 + dpage = dpages->dpages + dpages->ndpage - 1;
6705 + sz = PAGE_SIZE / sizeof(dentry);
6706 + if (unlikely(dpage->ndentry >= sz)) {
6707 + AuLabel(new dpage);
6709 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6710 + p = au_kzrealloc(dpages->dpages, sz,
6711 + sz + sizeof(*dpages->dpages), gfp,
6716 + dpages->dpages = p;
6717 + dpage = dpages->dpages + dpages->ndpage;
6718 + p = (void *)__get_free_page(gfp);
6722 + dpage->ndentry = 0;
6723 + dpage->dentries = p;
6727 + AuDebugOn(au_dcount(dentry) <= 0);
6728 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6729 + return 0; /* success */
6735 +/* todo: BAD approach */
6736 +/* copied from linux/fs/dcache.c */
6744 +extern void d_walk(struct dentry *parent, void *data,
6745 + enum d_walk_ret (*enter)(void *, struct dentry *),
6746 + void (*finish)(void *));
6748 +struct ac_dpages_arg {
6750 + struct au_dcsub_pages *dpages;
6751 + struct super_block *sb;
6752 + au_dpages_test test;
6756 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6758 + enum d_walk_ret ret;
6759 + struct ac_dpages_arg *arg = _arg;
6761 + ret = D_WALK_CONTINUE;
6762 + if (dentry->d_sb == arg->sb
6763 + && !IS_ROOT(dentry)
6764 + && au_dcount(dentry) > 0
6766 + && (!arg->test || arg->test(dentry, arg->arg))) {
6767 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6768 + if (unlikely(arg->err))
6769 + ret = D_WALK_QUIT;
6775 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6776 + au_dpages_test test, void *arg)
6778 + struct ac_dpages_arg args = {
6786 + d_walk(root, &args, au_call_dpages_append, NULL);
6791 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6792 + int do_include, au_dpages_test test, void *arg)
6797 + write_seqlock(&rename_lock);
6798 + spin_lock(&dentry->d_lock);
6800 + && au_dcount(dentry) > 0
6801 + && (!test || test(dentry, arg)))
6802 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6803 + spin_unlock(&dentry->d_lock);
6804 + if (unlikely(err))
6808 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6811 + while (!IS_ROOT(dentry)) {
6812 + dentry = dentry->d_parent; /* rename_lock is locked */
6813 + spin_lock(&dentry->d_lock);
6814 + if (au_dcount(dentry) > 0
6815 + && (!test || test(dentry, arg)))
6816 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6817 + spin_unlock(&dentry->d_lock);
6818 + if (unlikely(err))
6823 + write_sequnlock(&rename_lock);
6827 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6829 + return au_di(dentry) && dentry->d_sb == arg;
6832 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6833 + struct dentry *dentry, int do_include)
6835 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6836 + au_dcsub_dpages_aufs, dentry->d_sb);
6839 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6841 + struct path path[2] = {
6850 + return path_is_under(path + 0, path + 1);
6852 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6853 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6854 +++ linux/fs/aufs/dcsub.h 2016-10-09 16:55:36.486034798 +0200
6857 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6859 + * This program, aufs is free software; you can redistribute it and/or modify
6860 + * it under the terms of the GNU General Public License as published by
6861 + * the Free Software Foundation; either version 2 of the License, or
6862 + * (at your option) any later version.
6864 + * This program is distributed in the hope that it will be useful,
6865 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6866 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6867 + * GNU General Public License for more details.
6869 + * You should have received a copy of the GNU General Public License
6870 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6874 + * sub-routines for dentry cache
6877 +#ifndef __AUFS_DCSUB_H__
6878 +#define __AUFS_DCSUB_H__
6882 +#include <linux/dcache.h>
6883 +#include <linux/fs.h>
6887 + struct dentry **dentries;
6890 +struct au_dcsub_pages {
6892 + struct au_dpage *dpages;
6895 +/* ---------------------------------------------------------------------- */
6898 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6899 +void au_dpages_free(struct au_dcsub_pages *dpages);
6900 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6901 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6902 + au_dpages_test test, void *arg);
6903 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6904 + int do_include, au_dpages_test test, void *arg);
6905 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6906 + struct dentry *dentry, int do_include);
6907 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6909 +/* ---------------------------------------------------------------------- */
6912 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6913 + * include/linux/dcache.h. Try them (in the future).
6916 +static inline int au_d_hashed_positive(struct dentry *d)
6919 + struct inode *inode = d_inode(d);
6922 + if (unlikely(d_unhashed(d)
6923 + || d_is_negative(d)
6924 + || !inode->i_nlink))
6929 +static inline int au_d_linkable(struct dentry *d)
6932 + struct inode *inode = d_inode(d);
6934 + err = au_d_hashed_positive(d);
6936 + && d_is_positive(d)
6937 + && (inode->i_state & I_LINKABLE))
6942 +static inline int au_d_alive(struct dentry *d)
6945 + struct inode *inode;
6949 + err = au_d_hashed_positive(d);
6951 + inode = d_inode(d);
6952 + if (unlikely(d_unlinked(d)
6953 + || d_is_negative(d)
6954 + || !inode->i_nlink))
6960 +static inline int au_alive_dir(struct dentry *d)
6964 + err = au_d_alive(d);
6965 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
6970 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6972 + return a->len == b->len
6973 + && !memcmp(a->name, b->name, a->len);
6978 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
6980 + * the type of d_lockref.count became int, but the inlined function d_count()
6981 + * still returns unsigned int.
6982 + * I don't know why. Maybe it is for every d_count() users?
6983 + * Anyway au_dcount() lives on.
6985 +static inline int au_dcount(struct dentry *d)
6987 + return (int)d_count(d);
6990 +#endif /* __KERNEL__ */
6991 +#endif /* __AUFS_DCSUB_H__ */
6992 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
6993 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
6994 +++ linux/fs/aufs/debug.c 2016-10-09 16:55:36.486034798 +0200
6997 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6999 + * This program, aufs is free software; you can redistribute it and/or modify
7000 + * it under the terms of the GNU General Public License as published by
7001 + * the Free Software Foundation; either version 2 of the License, or
7002 + * (at your option) any later version.
7004 + * This program is distributed in the hope that it will be useful,
7005 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7006 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7007 + * GNU General Public License for more details.
7009 + * You should have received a copy of the GNU General Public License
7010 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7014 + * debug print functions
7019 +/* Returns 0, or -errno. arg is in kp->arg. */
7020 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7024 + err = kstrtoint(val, 0, &n);
7034 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7035 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7040 + return sprintf(buffer, "%d", atomic_read(a));
7043 +static struct kernel_param_ops param_ops_atomic_t = {
7044 + .set = param_atomic_t_set,
7045 + .get = param_atomic_t_get
7046 + /* void (*free)(void *arg) */
7049 +atomic_t aufs_debug = ATOMIC_INIT(0);
7050 +MODULE_PARM_DESC(debug, "debug print");
7051 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7053 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7054 +char *au_plevel = KERN_DEBUG;
7055 +#define dpri(fmt, ...) do { \
7057 + && strcmp(au_plevel, KERN_DEBUG)) \
7058 + || au_debug_test()) \
7059 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7062 +/* ---------------------------------------------------------------------- */
7064 +void au_dpri_whlist(struct au_nhash *whlist)
7066 + unsigned long ul, n;
7067 + struct hlist_head *head;
7068 + struct au_vdir_wh *pos;
7070 + n = whlist->nh_num;
7071 + head = whlist->nh_head;
7072 + for (ul = 0; ul < n; ul++) {
7073 + hlist_for_each_entry(pos, head, wh_hash)
7074 + dpri("b%d, %.*s, %d\n",
7076 + pos->wh_str.len, pos->wh_str.name,
7082 +void au_dpri_vdir(struct au_vdir *vdir)
7085 + union au_vdir_deblk_p p;
7088 + if (!vdir || IS_ERR(vdir)) {
7089 + dpri("err %ld\n", PTR_ERR(vdir));
7093 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
7094 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7095 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7096 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7097 + p.deblk = vdir->vd_deblk[ul];
7099 + dpri("[%lu]: %p\n", ul, o);
7103 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7104 + struct dentry *wh)
7109 + if (!inode || IS_ERR(inode)) {
7110 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7114 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7115 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7116 + && sizeof(inode->i_blocks) != sizeof(u64));
7118 + n = (void *)wh->d_name.name;
7119 + l = wh->d_name.len;
7122 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7123 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7125 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7126 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7127 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7128 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7129 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7130 + inode->i_state, inode->i_flags, inode->i_version,
7131 + inode->i_generation,
7132 + l ? ", wh " : "", l, n);
7136 +void au_dpri_inode(struct inode *inode)
7138 + struct au_iinfo *iinfo;
7139 + struct au_hinode *hi;
7140 + aufs_bindex_t bindex;
7143 + err = do_pri_inode(-1, inode, -1, NULL);
7144 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7147 + iinfo = au_ii(inode);
7148 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7149 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7150 + if (iinfo->ii_btop < 0)
7153 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7154 + hi = au_hinode(iinfo, bindex);
7156 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7160 +void au_dpri_dalias(struct inode *inode)
7164 + spin_lock(&inode->i_lock);
7165 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7166 + au_dpri_dentry(d);
7167 + spin_unlock(&inode->i_lock);
7170 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7172 + struct dentry *wh = NULL;
7174 + struct inode *inode;
7175 + struct au_iinfo *iinfo;
7176 + struct au_hinode *hi;
7178 + if (!dentry || IS_ERR(dentry)) {
7179 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7182 + /* do not call dget_parent() here */
7183 + /* note: access d_xxx without d_lock */
7184 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7185 + bindex, dentry, dentry,
7186 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7187 + au_dcount(dentry), dentry->d_flags,
7188 + d_unhashed(dentry) ? "un" : "");
7191 + if (d_is_positive(dentry))
7192 + inode = d_inode(dentry);
7194 + && au_test_aufs(dentry->d_sb)
7196 + && !au_is_bad_inode(inode)) {
7197 + iinfo = au_ii(inode);
7198 + hi = au_hinode(iinfo, bindex);
7200 + wh = hi->hi_whdentry;
7202 + do_pri_inode(bindex, inode, hn, wh);
7206 +void au_dpri_dentry(struct dentry *dentry)
7208 + struct au_dinfo *dinfo;
7209 + aufs_bindex_t bindex;
7212 + err = do_pri_dentry(-1, dentry);
7213 + if (err || !au_test_aufs(dentry->d_sb))
7216 + dinfo = au_di(dentry);
7219 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7220 + dinfo->di_btop, dinfo->di_bbot,
7221 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7222 + dinfo->di_tmpfile);
7223 + if (dinfo->di_btop < 0)
7225 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7226 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7229 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7233 + if (!file || IS_ERR(file)) {
7234 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7239 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7240 + && au_test_aufs(file->f_path.dentry->d_sb)
7242 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7243 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7244 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7245 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7246 + file->f_version, file->f_pos, a);
7247 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7248 + do_pri_dentry(bindex, file->f_path.dentry);
7252 +void au_dpri_file(struct file *file)
7254 + struct au_finfo *finfo;
7255 + struct au_fidir *fidir;
7256 + struct au_hfile *hfile;
7257 + aufs_bindex_t bindex;
7260 + err = do_pri_file(-1, file);
7262 + || IS_ERR_OR_NULL(file->f_path.dentry)
7263 + || !au_test_aufs(file->f_path.dentry->d_sb))
7266 + finfo = au_fi(file);
7269 + if (finfo->fi_btop < 0)
7271 + fidir = finfo->fi_hdir;
7273 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7275 + for (bindex = finfo->fi_btop;
7276 + bindex >= 0 && bindex <= fidir->fd_bbot;
7278 + hfile = fidir->fd_hfile + bindex;
7279 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7283 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7285 + struct vfsmount *mnt;
7286 + struct super_block *sb;
7288 + if (!br || IS_ERR(br))
7290 + mnt = au_br_mnt(br);
7291 + if (!mnt || IS_ERR(mnt))
7294 + if (!sb || IS_ERR(sb))
7297 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7298 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7300 + bindex, br->br_perm, br->br_id, au_br_count(br),
7301 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7302 + sb->s_flags, sb->s_count,
7303 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7307 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7311 +void au_dpri_sb(struct super_block *sb)
7313 + struct au_sbinfo *sbinfo;
7314 + aufs_bindex_t bindex;
7316 + /* to reuduce stack size */
7318 + struct vfsmount mnt;
7319 + struct au_branch fake;
7322 + /* this function can be called from magic sysrq */
7323 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7324 + if (unlikely(!a)) {
7325 + dpri("no memory\n");
7329 + a->mnt.mnt_sb = sb;
7330 + a->fake.br_path.mnt = &a->mnt;
7331 + au_br_count_init(&a->fake);
7332 + err = do_pri_br(-1, &a->fake);
7333 + au_br_count_fin(&a->fake);
7334 + au_delayed_kfree(a);
7335 + dpri("dev 0x%x\n", sb->s_dev);
7336 + if (err || !au_test_aufs(sb))
7339 + sbinfo = au_sbi(sb);
7342 + dpri("nw %d, gen %u, kobj %d\n",
7343 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7344 + atomic_read(&sbinfo->si_kobj.kref.refcount));
7345 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7346 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7349 +/* ---------------------------------------------------------------------- */
7351 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7353 + struct inode *h_inode, *inode = d_inode(dentry);
7354 + struct dentry *h_dentry;
7355 + aufs_bindex_t bindex, bbot, bi;
7357 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7360 + bbot = au_dbbot(dentry);
7361 + bi = au_ibbot(inode);
7364 + bindex = au_dbtop(dentry);
7365 + bi = au_ibtop(inode);
7369 + for (; bindex <= bbot; bindex++) {
7370 + h_dentry = au_h_dptr(dentry, bindex);
7373 + h_inode = au_h_iptr(inode, bindex);
7374 + if (unlikely(h_inode != d_inode(h_dentry))) {
7376 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7377 + AuDbgDentry(dentry);
7378 + AuDbgInode(inode);
7385 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7388 + struct au_dcsub_pages dpages;
7389 + struct au_dpage *dpage;
7390 + struct dentry **dentries;
7392 + err = au_dpages_init(&dpages, GFP_NOFS);
7394 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7396 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7397 + dpage = dpages.dpages + i;
7398 + dentries = dpage->dentries;
7399 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7400 + AuDebugOn(au_digen_test(dentries[j], sigen));
7402 + au_dpages_free(&dpages);
7405 +void au_dbg_verify_kthread(void)
7407 + if (au_wkq_test()) {
7410 + * It may be recursive, but udba=notify between two aufs mounts,
7411 + * where a single ro branch is shared, is not a problem.
7417 +/* ---------------------------------------------------------------------- */
7419 +int __init au_debug_init(void)
7421 + aufs_bindex_t bindex;
7422 + struct au_vdir_destr destr;
7425 + AuDebugOn(bindex >= 0);
7428 + AuDebugOn(destr.len < NAME_MAX);
7430 +#ifdef CONFIG_4KSTACKS
7431 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7436 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7437 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7438 +++ linux/fs/aufs/debug.h 2016-10-09 16:55:36.486034798 +0200
7441 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7443 + * This program, aufs is free software; you can redistribute it and/or modify
7444 + * it under the terms of the GNU General Public License as published by
7445 + * the Free Software Foundation; either version 2 of the License, or
7446 + * (at your option) any later version.
7448 + * This program is distributed in the hope that it will be useful,
7449 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7450 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7451 + * GNU General Public License for more details.
7453 + * You should have received a copy of the GNU General Public License
7454 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7458 + * debug print functions
7461 +#ifndef __AUFS_DEBUG_H__
7462 +#define __AUFS_DEBUG_H__
7466 +#include <linux/atomic.h>
7467 +#include <linux/module.h>
7468 +#include <linux/kallsyms.h>
7469 +#include <linux/sysrq.h>
7471 +#ifdef CONFIG_AUFS_DEBUG
7472 +#define AuDebugOn(a) BUG_ON(a)
7474 +/* module parameter */
7475 +extern atomic_t aufs_debug;
7476 +static inline void au_debug_on(void)
7478 + atomic_inc(&aufs_debug);
7480 +static inline void au_debug_off(void)
7482 + atomic_dec_if_positive(&aufs_debug);
7485 +static inline int au_debug_test(void)
7487 + return atomic_read(&aufs_debug) > 0;
7490 +#define AuDebugOn(a) do {} while (0)
7491 +AuStubVoid(au_debug_on, void)
7492 +AuStubVoid(au_debug_off, void)
7493 +AuStubInt0(au_debug_test, void)
7494 +#endif /* CONFIG_AUFS_DEBUG */
7496 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7498 +/* ---------------------------------------------------------------------- */
7502 +#define AuDbg(fmt, ...) do { \
7503 + if (au_debug_test()) \
7504 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7506 +#define AuLabel(l) AuDbg(#l "\n")
7507 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7508 +#define AuWarn1(fmt, ...) do { \
7509 + static unsigned char _c; \
7511 + pr_warn(fmt, ##__VA_ARGS__); \
7514 +#define AuErr1(fmt, ...) do { \
7515 + static unsigned char _c; \
7517 + pr_err(fmt, ##__VA_ARGS__); \
7520 +#define AuIOErr1(fmt, ...) do { \
7521 + static unsigned char _c; \
7523 + AuIOErr(fmt, ##__VA_ARGS__); \
7526 +#define AuUnsupportMsg "This operation is not supported." \
7527 + " Please report this application to aufs-users ML."
7528 +#define AuUnsupport(fmt, ...) do { \
7529 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7533 +#define AuTraceErr(e) do { \
7534 + if (unlikely((e) < 0)) \
7535 + AuDbg("err %d\n", (int)(e)); \
7538 +#define AuTraceErrPtr(p) do { \
7540 + AuDbg("err %ld\n", PTR_ERR(p)); \
7543 +/* dirty macros for debug print, use with "%.*s" and caution */
7544 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7546 +/* ---------------------------------------------------------------------- */
7549 +#ifdef CONFIG_AUFS_DEBUG
7550 +extern struct mutex au_dbg_mtx;
7551 +extern char *au_plevel;
7553 +void au_dpri_whlist(struct au_nhash *whlist);
7555 +void au_dpri_vdir(struct au_vdir *vdir);
7557 +void au_dpri_inode(struct inode *inode);
7558 +void au_dpri_dalias(struct inode *inode);
7559 +void au_dpri_dentry(struct dentry *dentry);
7561 +void au_dpri_file(struct file *filp);
7562 +struct super_block;
7563 +void au_dpri_sb(struct super_block *sb);
7565 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7566 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7567 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7568 +void au_dbg_verify_kthread(void);
7570 +int __init au_debug_init(void);
7572 +#define AuDbgWhlist(w) do { \
7573 + mutex_lock(&au_dbg_mtx); \
7575 + au_dpri_whlist(w); \
7576 + mutex_unlock(&au_dbg_mtx); \
7579 +#define AuDbgVdir(v) do { \
7580 + mutex_lock(&au_dbg_mtx); \
7582 + au_dpri_vdir(v); \
7583 + mutex_unlock(&au_dbg_mtx); \
7586 +#define AuDbgInode(i) do { \
7587 + mutex_lock(&au_dbg_mtx); \
7589 + au_dpri_inode(i); \
7590 + mutex_unlock(&au_dbg_mtx); \
7593 +#define AuDbgDAlias(i) do { \
7594 + mutex_lock(&au_dbg_mtx); \
7596 + au_dpri_dalias(i); \
7597 + mutex_unlock(&au_dbg_mtx); \
7600 +#define AuDbgDentry(d) do { \
7601 + mutex_lock(&au_dbg_mtx); \
7603 + au_dpri_dentry(d); \
7604 + mutex_unlock(&au_dbg_mtx); \
7607 +#define AuDbgFile(f) do { \
7608 + mutex_lock(&au_dbg_mtx); \
7610 + au_dpri_file(f); \
7611 + mutex_unlock(&au_dbg_mtx); \
7614 +#define AuDbgSb(sb) do { \
7615 + mutex_lock(&au_dbg_mtx); \
7616 + AuDbg(#sb "\n"); \
7618 + mutex_unlock(&au_dbg_mtx); \
7621 +#define AuDbgSym(addr) do { \
7622 + char sym[KSYM_SYMBOL_LEN]; \
7623 + sprint_symbol(sym, (unsigned long)addr); \
7624 + AuDbg("%s\n", sym); \
7627 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7628 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7629 +AuStubVoid(au_dbg_verify_kthread, void)
7630 +AuStubInt0(__init au_debug_init, void)
7632 +#define AuDbgWhlist(w) do {} while (0)
7633 +#define AuDbgVdir(v) do {} while (0)
7634 +#define AuDbgInode(i) do {} while (0)
7635 +#define AuDbgDAlias(i) do {} while (0)
7636 +#define AuDbgDentry(d) do {} while (0)
7637 +#define AuDbgFile(f) do {} while (0)
7638 +#define AuDbgSb(sb) do {} while (0)
7639 +#define AuDbgSym(addr) do {} while (0)
7640 +#endif /* CONFIG_AUFS_DEBUG */
7642 +/* ---------------------------------------------------------------------- */
7644 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7645 +int __init au_sysrq_init(void);
7646 +void au_sysrq_fin(void);
7648 +#ifdef CONFIG_HW_CONSOLE
7649 +#define au_dbg_blocked() do { \
7651 + handle_sysrq('w'); \
7654 +AuStubVoid(au_dbg_blocked, void)
7658 +AuStubInt0(__init au_sysrq_init, void)
7659 +AuStubVoid(au_sysrq_fin, void)
7660 +AuStubVoid(au_dbg_blocked, void)
7661 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7663 +#endif /* __KERNEL__ */
7664 +#endif /* __AUFS_DEBUG_H__ */
7665 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7666 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7667 +++ linux/fs/aufs/dentry.c 2016-10-09 16:55:38.889431135 +0200
7670 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7672 + * This program, aufs is free software; you can redistribute it and/or modify
7673 + * it under the terms of the GNU General Public License as published by
7674 + * the Free Software Foundation; either version 2 of the License, or
7675 + * (at your option) any later version.
7677 + * This program is distributed in the hope that it will be useful,
7678 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7679 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7680 + * GNU General Public License for more details.
7682 + * You should have received a copy of the GNU General Public License
7683 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7687 + * lookup and dentry operations
7690 +#include <linux/namei.h>
7693 +struct au_do_lookup_args {
7694 + unsigned int flags;
7699 + * returns positive/negative dentry, NULL or an error.
7700 + * NULL means whiteout-ed or not-found.
7702 +static struct dentry*
7703 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7704 + aufs_bindex_t bindex, struct qstr *wh_name,
7705 + struct au_do_lookup_args *args)
7707 + struct dentry *h_dentry;
7708 + struct inode *h_inode;
7709 + struct au_branch *br;
7710 + int wh_found, opq;
7711 + unsigned char wh_able;
7712 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7713 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7717 + br = au_sbr(dentry->d_sb, bindex);
7718 + wh_able = !!au_br_whable(br->br_perm);
7720 + wh_found = au_wh_test(h_parent, wh_name, ignore_perm);
7721 + h_dentry = ERR_PTR(wh_found);
7724 + if (unlikely(wh_found < 0))
7727 + /* We found a whiteout */
7728 + /* au_set_dbbot(dentry, bindex); */
7729 + au_set_dbwh(dentry, bindex);
7731 + return NULL; /* success */
7735 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7737 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7738 + if (IS_ERR(h_dentry)) {
7739 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7745 + h_inode = d_inode(h_dentry);
7746 + if (d_is_negative(h_dentry)) {
7749 + } else if (wh_found
7750 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7753 + if (au_dbbot(dentry) <= bindex)
7754 + au_set_dbbot(dentry, bindex);
7755 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
7756 + au_set_dbtop(dentry, bindex);
7757 + au_set_h_dptr(dentry, bindex, h_dentry);
7759 + if (!d_is_dir(h_dentry)
7761 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7762 + goto out; /* success */
7764 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
7765 + opq = au_diropq_test(h_dentry);
7766 + inode_unlock(h_inode);
7768 + au_set_dbdiropq(dentry, bindex);
7769 + else if (unlikely(opq < 0)) {
7770 + au_set_h_dptr(dentry, bindex, NULL);
7771 + h_dentry = ERR_PTR(opq);
7782 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7784 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7785 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7791 + * returns the number of lower positive dentries,
7792 + * otherwise an error.
7793 + * can be called at unlinking with @type is zero.
7795 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
7796 + unsigned int flags)
7798 + int npositive, err;
7799 + aufs_bindex_t bindex, btail, bdiropq;
7800 + unsigned char isdir, dirperm1;
7801 + struct qstr whname;
7802 + struct au_do_lookup_args args = {
7805 + const struct qstr *name = &dentry->d_name;
7806 + struct dentry *parent;
7807 + struct super_block *sb;
7809 + sb = dentry->d_sb;
7810 + err = au_test_shwh(sb, name);
7811 + if (unlikely(err))
7814 + err = au_wh_name_alloc(&whname, name);
7815 + if (unlikely(err))
7818 + isdir = !!d_is_dir(dentry);
7819 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7822 + parent = dget_parent(dentry);
7823 + btail = au_dbtaildir(parent);
7824 + for (bindex = btop; bindex <= btail; bindex++) {
7825 + struct dentry *h_parent, *h_dentry;
7826 + struct inode *h_inode, *h_dir;
7828 + h_dentry = au_h_dptr(dentry, bindex);
7830 + if (d_is_positive(h_dentry))
7834 + h_parent = au_h_dptr(parent, bindex);
7835 + if (!h_parent || !d_is_dir(h_parent))
7838 + h_dir = d_inode(h_parent);
7839 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
7840 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7842 + inode_unlock(h_dir);
7843 + err = PTR_ERR(h_dentry);
7844 + if (IS_ERR(h_dentry))
7847 + au_fclr_lkup(args.flags, ALLOW_NEG);
7849 + au_fset_lkup(args.flags, IGNORE_PERM);
7851 + if (au_dbwh(dentry) == bindex)
7855 + if (d_is_negative(h_dentry))
7857 + h_inode = d_inode(h_dentry);
7860 + args.type = h_inode->i_mode & S_IFMT;
7861 + if (args.type != S_IFDIR)
7864 + /* the type of lower may be different */
7865 + bdiropq = au_dbdiropq(dentry);
7866 + if (bdiropq >= 0 && bdiropq <= bindex)
7872 + AuLabel(positive);
7873 + au_update_dbtop(dentry);
7876 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7877 + && au_dbtop(dentry) < 0)) {
7879 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7885 + au_delayed_kfree(whname.name);
7890 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7892 + struct dentry *dentry;
7895 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7896 + dentry = vfsub_lkup_one(name, parent);
7898 + struct vfsub_lkup_one_args args = {
7904 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7905 + if (unlikely(wkq_err))
7906 + dentry = ERR_PTR(wkq_err);
7913 + * lookup @dentry on @bindex which should be negative.
7915 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7918 + struct dentry *parent, *h_parent, *h_dentry;
7919 + struct au_branch *br;
7921 + parent = dget_parent(dentry);
7922 + h_parent = au_h_dptr(parent, bindex);
7923 + br = au_sbr(dentry->d_sb, bindex);
7925 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7927 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7928 + err = PTR_ERR(h_dentry);
7929 + if (IS_ERR(h_dentry))
7931 + if (unlikely(d_is_positive(h_dentry))) {
7933 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7939 + if (bindex < au_dbtop(dentry))
7940 + au_set_dbtop(dentry, bindex);
7941 + if (au_dbbot(dentry) < bindex)
7942 + au_set_dbbot(dentry, bindex);
7943 + au_set_h_dptr(dentry, bindex, h_dentry);
7950 +/* ---------------------------------------------------------------------- */
7952 +/* subset of struct inode */
7954 + unsigned long i_ino;
7955 + /* unsigned int i_nlink; */
7961 + blkcnt_t i_blocks;
7966 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7968 + ia->i_ino = h_inode->i_ino;
7969 + /* ia->i_nlink = h_inode->i_nlink; */
7970 + ia->i_uid = h_inode->i_uid;
7971 + ia->i_gid = h_inode->i_gid;
7972 + ia->i_version = h_inode->i_version;
7974 + ia->i_size = h_inode->i_size;
7975 + ia->i_blocks = h_inode->i_blocks;
7977 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7980 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7982 + return ia->i_ino != h_inode->i_ino
7983 + /* || ia->i_nlink != h_inode->i_nlink */
7984 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7985 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7986 + || ia->i_version != h_inode->i_version
7988 + || ia->i_size != h_inode->i_size
7989 + || ia->i_blocks != h_inode->i_blocks
7991 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
7994 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
7995 + struct au_branch *br)
7998 + struct au_iattr ia;
7999 + struct inode *h_inode;
8000 + struct dentry *h_d;
8001 + struct super_block *h_sb;
8004 + memset(&ia, -1, sizeof(ia));
8005 + h_sb = h_dentry->d_sb;
8007 + if (d_is_positive(h_dentry)) {
8008 + h_inode = d_inode(h_dentry);
8009 + au_iattr_save(&ia, h_inode);
8010 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8011 + /* nfs d_revalidate may return 0 for negative dentry */
8012 + /* fuse d_revalidate always return 0 for negative dentry */
8015 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8016 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8017 + err = PTR_ERR(h_d);
8022 + if (unlikely(h_d != h_dentry
8023 + || d_inode(h_d) != h_inode
8024 + || (h_inode && au_iattr_test(&ia, h_inode))))
8025 + err = au_busy_or_stale();
8033 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8034 + struct dentry *h_parent, struct au_branch *br)
8039 + if (udba == AuOpt_UDBA_REVAL
8040 + && !au_test_fs_remote(h_dentry->d_sb)) {
8042 + err = (d_inode(h_dentry->d_parent) != h_dir);
8043 + } else if (udba != AuOpt_UDBA_NONE)
8044 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8049 +/* ---------------------------------------------------------------------- */
8051 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8054 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8055 + struct au_hdentry tmp, *p, *q;
8056 + struct au_dinfo *dinfo;
8057 + struct super_block *sb;
8059 + DiMustWriteLock(dentry);
8061 + sb = dentry->d_sb;
8062 + dinfo = au_di(dentry);
8063 + bbot = dinfo->di_bbot;
8064 + bwh = dinfo->di_bwh;
8065 + bdiropq = dinfo->di_bdiropq;
8066 + bindex = dinfo->di_btop;
8067 + p = au_hdentry(dinfo, bindex);
8068 + for (; bindex <= bbot; bindex++, p++) {
8069 + if (!p->hd_dentry)
8072 + new_bindex = au_br_index(sb, p->hd_id);
8073 + if (new_bindex == bindex)
8076 + if (dinfo->di_bwh == bindex)
8078 + if (dinfo->di_bdiropq == bindex)
8079 + bdiropq = new_bindex;
8080 + if (new_bindex < 0) {
8082 + p->hd_dentry = NULL;
8086 + /* swap two lower dentries, and loop again */
8087 + q = au_hdentry(dinfo, new_bindex);
8091 + if (tmp.hd_dentry) {
8097 + dinfo->di_bwh = -1;
8098 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8099 + dinfo->di_bwh = bwh;
8101 + dinfo->di_bdiropq = -1;
8103 + && bdiropq <= au_sbbot(sb)
8104 + && au_sbr_whable(sb, bdiropq))
8105 + dinfo->di_bdiropq = bdiropq;
8108 + dinfo->di_btop = -1;
8109 + dinfo->di_bbot = -1;
8110 + bbot = au_dbbot(parent);
8112 + p = au_hdentry(dinfo, bindex);
8113 + for (; bindex <= bbot; bindex++, p++)
8114 + if (p->hd_dentry) {
8115 + dinfo->di_btop = bindex;
8119 + if (dinfo->di_btop >= 0) {
8121 + p = au_hdentry(dinfo, bindex);
8122 + for (; bindex >= 0; bindex--, p--)
8123 + if (p->hd_dentry) {
8124 + dinfo->di_bbot = bindex;
8133 +static void au_do_hide(struct dentry *dentry)
8135 + struct inode *inode;
8137 + if (d_really_is_positive(dentry)) {
8138 + inode = d_inode(dentry);
8139 + if (!d_is_dir(dentry)) {
8140 + if (inode->i_nlink && !d_unhashed(dentry))
8141 + drop_nlink(inode);
8143 + clear_nlink(inode);
8144 + /* stop next lookup */
8145 + inode->i_flags |= S_DEAD;
8147 + smp_mb(); /* necessary? */
8152 +static int au_hide_children(struct dentry *parent)
8154 + int err, i, j, ndentry;
8155 + struct au_dcsub_pages dpages;
8156 + struct au_dpage *dpage;
8157 + struct dentry *dentry;
8159 + err = au_dpages_init(&dpages, GFP_NOFS);
8160 + if (unlikely(err))
8162 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8163 + if (unlikely(err))
8166 + /* in reverse order */
8167 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8168 + dpage = dpages.dpages + i;
8169 + ndentry = dpage->ndentry;
8170 + for (j = ndentry - 1; j >= 0; j--) {
8171 + dentry = dpage->dentries[j];
8172 + if (dentry != parent)
8173 + au_do_hide(dentry);
8178 + au_dpages_free(&dpages);
8183 +static void au_hide(struct dentry *dentry)
8187 + AuDbgDentry(dentry);
8188 + if (d_is_dir(dentry)) {
8189 + /* shrink_dcache_parent(dentry); */
8190 + err = au_hide_children(dentry);
8191 + if (unlikely(err))
8192 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8195 + au_do_hide(dentry);
8199 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8201 + * a dirty branch is added
8202 + * - on the top of layers
8203 + * - in the middle of layers
8204 + * - to the bottom of layers
8206 + * on the added branch there exists
8209 + * - a same named entry
8211 + * * negative --> positive
8212 + * * positive --> positive
8213 + * - type is unchanged
8214 + * - type is changed
8216 + * * negative --> negative
8217 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8220 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8221 + struct au_dinfo *tmp)
8224 + aufs_bindex_t bindex, bbot;
8226 + struct dentry *dentry;
8227 + struct inode *inode;
8229 + } orig_h, tmp_h = {
8232 + struct au_hdentry *hd;
8233 + struct inode *inode, *h_inode;
8234 + struct dentry *h_dentry;
8237 + AuDebugOn(dinfo->di_btop < 0);
8239 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8240 + orig_h.inode = NULL;
8241 + if (d_is_positive(orig_h.dentry)) {
8242 + orig_h.inode = d_inode(orig_h.dentry);
8243 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8245 + if (tmp->di_btop >= 0) {
8246 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8247 + if (d_is_positive(tmp_h.dentry)) {
8248 + tmp_h.inode = d_inode(tmp_h.dentry);
8249 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8254 + if (d_really_is_positive(dentry))
8255 + inode = d_inode(dentry);
8256 + if (!orig_h.inode) {
8257 + AuDbg("nagative originally\n");
8263 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8264 + AuDebugOn(dinfo->di_bdiropq != -1);
8266 + if (!tmp_h.inode) {
8267 + AuDbg("negative --> negative\n");
8268 + /* should have only one negative lower */
8269 + if (tmp->di_btop >= 0
8270 + && tmp->di_btop < dinfo->di_btop) {
8271 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8272 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8273 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8274 + au_di_cp(dinfo, tmp);
8275 + hd = au_hdentry(tmp, tmp->di_btop);
8276 + au_set_h_dptr(dentry, tmp->di_btop,
8277 + dget(hd->hd_dentry));
8279 + au_dbg_verify_dinode(dentry);
8281 + AuDbg("negative --> positive\n");
8283 + * similar to the behaviour of creating with bypassing
8285 + * unhash it in order to force an error in the
8286 + * succeeding create operation.
8287 + * we should not set S_DEAD here.
8290 + /* au_di_swap(tmp, dinfo); */
8291 + au_dbg_verify_dinode(dentry);
8294 + AuDbg("positive originally\n");
8295 + /* inode may be NULL */
8296 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8297 + if (!tmp_h.inode) {
8298 + AuDbg("positive --> negative\n");
8299 + /* or bypassing aufs */
8301 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8302 + dinfo->di_bwh = tmp->di_bwh;
8304 + err = au_refresh_hinode_self(inode);
8305 + au_dbg_verify_dinode(dentry);
8306 + } else if (orig_h.mode == tmp_h.mode) {
8307 + AuDbg("positive --> positive, same type\n");
8308 + if (!S_ISDIR(orig_h.mode)
8309 + && dinfo->di_btop > tmp->di_btop) {
8311 + * similar to the behaviour of removing and
8316 + err = au_refresh_hinode_self(inode);
8317 + au_dbg_verify_dinode(dentry);
8319 + /* fill empty slots */
8320 + if (dinfo->di_btop > tmp->di_btop)
8321 + dinfo->di_btop = tmp->di_btop;
8322 + if (dinfo->di_bbot < tmp->di_bbot)
8323 + dinfo->di_bbot = tmp->di_bbot;
8324 + dinfo->di_bwh = tmp->di_bwh;
8325 + dinfo->di_bdiropq = tmp->di_bdiropq;
8326 + bbot = dinfo->di_bbot;
8327 + bindex = tmp->di_btop;
8328 + hd = au_hdentry(tmp, bindex);
8329 + for (; bindex <= bbot; bindex++, hd++) {
8330 + if (au_h_dptr(dentry, bindex))
8332 + h_dentry = hd->hd_dentry;
8335 + AuDebugOn(d_is_negative(h_dentry));
8336 + h_inode = d_inode(h_dentry);
8337 + AuDebugOn(orig_h.mode
8338 + != (h_inode->i_mode
8340 + au_set_h_dptr(dentry, bindex,
8344 + err = au_refresh_hinode(inode, dentry);
8345 + au_dbg_verify_dinode(dentry);
8348 + AuDbg("positive --> positive, different type\n");
8349 + /* similar to the behaviour of removing and creating */
8352 + err = au_refresh_hinode_self(inode);
8353 + au_dbg_verify_dinode(dentry);
8361 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8363 + const struct dentry_operations *dop
8364 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8365 + static const unsigned int mask
8366 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8368 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8370 + if (dentry->d_op == dop)
8373 + AuDbg("%pd\n", dentry);
8374 + spin_lock(&dentry->d_lock);
8375 + if (dop == &aufs_dop)
8376 + dentry->d_flags |= mask;
8378 + dentry->d_flags &= ~mask;
8379 + dentry->d_op = dop;
8380 + spin_unlock(&dentry->d_lock);
8383 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8385 + int err, ebrange, nbr;
8386 + unsigned int sigen;
8387 + struct au_dinfo *dinfo, *tmp;
8388 + struct super_block *sb;
8389 + struct inode *inode;
8391 + DiMustWriteLock(dentry);
8392 + AuDebugOn(IS_ROOT(dentry));
8393 + AuDebugOn(d_really_is_negative(parent));
8395 + sb = dentry->d_sb;
8396 + sigen = au_sigen(sb);
8397 + err = au_digen_test(parent, sigen);
8398 + if (unlikely(err))
8401 + nbr = au_sbbot(sb) + 1;
8402 + dinfo = au_di(dentry);
8403 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8404 + if (unlikely(err))
8406 + ebrange = au_dbrange_test(dentry);
8408 + ebrange = au_do_refresh_hdentry(dentry, parent);
8410 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8411 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8412 + if (d_really_is_positive(dentry)) {
8413 + inode = d_inode(dentry);
8414 + err = au_refresh_hinode_self(inode);
8416 + au_dbg_verify_dinode(dentry);
8418 + goto out_dgen; /* success */
8422 + /* temporary dinfo */
8423 + AuDbgDentry(dentry);
8425 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8426 + if (unlikely(!tmp))
8428 + au_di_swap(tmp, dinfo);
8429 + /* returns the number of positive dentries */
8431 + * if current working dir is removed, it returns an error.
8432 + * but the dentry is legal.
8434 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8435 + AuDbgDentry(dentry);
8436 + au_di_swap(tmp, dinfo);
8437 + if (err == -ENOENT)
8440 + /* compare/refresh by dinfo */
8441 + AuDbgDentry(dentry);
8442 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8443 + au_dbg_verify_dinode(dentry);
8446 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8447 + au_rw_write_unlock(&tmp->di_rwsem);
8449 + if (unlikely(err))
8453 + au_update_digen(dentry);
8455 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8456 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8457 + AuDbgDentry(dentry);
8463 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8464 + struct dentry *dentry, aufs_bindex_t bindex)
8469 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8472 + AuDbg("b%d\n", bindex);
8474 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8475 + * due to whiteout and branch permission.
8477 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8478 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8479 + /* it may return tri-state */
8480 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8482 + if (unlikely(valid < 0))
8492 +/* todo: remove this */
8493 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8494 + unsigned int flags, int do_udba)
8497 + umode_t mode, h_mode;
8498 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8499 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8500 + struct inode *h_inode, *h_cached_inode;
8501 + struct dentry *h_dentry;
8502 + struct qstr *name, *h_name;
8509 + unhashed = !!d_unhashed(dentry);
8510 + is_root = !!IS_ROOT(dentry);
8511 + name = &dentry->d_name;
8512 + tmpfile = au_di(dentry)->di_tmpfile;
8515 + * Theoretically, REVAL test should be unnecessary in case of
8517 + * But {fs,i}notify doesn't fire some necessary events,
8518 + * IN_ATTRIB for atime/nlink/pageio
8519 + * Let's do REVAL test too.
8521 + if (do_udba && inode) {
8522 + mode = (inode->i_mode & S_IFMT);
8523 + plus = (inode->i_nlink > 0);
8524 + ibs = au_ibtop(inode);
8525 + ibe = au_ibbot(inode);
8528 + btop = au_dbtop(dentry);
8530 + if (inode && S_ISDIR(inode->i_mode))
8531 + btail = au_dbtaildir(dentry);
8532 + for (bindex = btop; bindex <= btail; bindex++) {
8533 + h_dentry = au_h_dptr(dentry, bindex);
8537 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8538 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8539 + spin_lock(&h_dentry->d_lock);
8540 + h_name = &h_dentry->d_name;
8541 + if (unlikely(do_udba
8544 + && (unhashed != !!d_unhashed(h_dentry)
8546 + && !au_qstreq(name, h_name))
8549 + && !(flags & LOOKUP_OPEN)
8550 + && (h_dentry->d_flags
8551 + & DCACHE_NFSFS_RENAMED)))
8555 + h_unhashed = d_unhashed(h_dentry);
8556 + spin_unlock(&h_dentry->d_lock);
8557 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8558 + unhashed, h_unhashed, dentry, h_dentry);
8561 + spin_unlock(&h_dentry->d_lock);
8563 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8564 + if (unlikely(err))
8565 + /* do not goto err, to keep the errno */
8568 + /* todo: plink too? */
8573 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8577 + if (d_is_positive(h_dentry))
8578 + h_inode = d_inode(h_dentry);
8581 + h_cached_inode = h_inode;
8583 + h_mode = (h_inode->i_mode & S_IFMT);
8584 + h_plus = (h_inode->i_nlink > 0);
8586 + if (inode && ibs <= bindex && bindex <= ibe)
8587 + h_cached_inode = au_h_iptr(inode, bindex);
8590 + if (unlikely(plus != h_plus && !tmpfile))
8593 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8595 + && !IS_ROOT(h_dentry)
8596 + && unhashed != d_unhashed(h_dentry)))
8599 + if (unlikely(mode != h_mode
8600 + || h_cached_inode != h_inode))
8613 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8614 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8617 + struct dentry *parent;
8619 + if (!au_digen_test(dentry, sigen))
8622 + parent = dget_parent(dentry);
8623 + di_read_lock_parent(parent, AuLock_IR);
8624 + AuDebugOn(au_digen_test(parent, sigen));
8625 + au_dbg_verify_gen(parent, sigen);
8626 + err = au_refresh_dentry(dentry, parent);
8627 + di_read_unlock(parent, AuLock_IR);
8633 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8636 + struct dentry *d, *parent;
8638 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8639 + return simple_reval_dpath(dentry, sigen);
8641 + /* slow loop, keep it simple and stupid */
8642 + /* cf: au_cpup_dirs() */
8645 + while (au_digen_test(dentry, sigen)) {
8649 + parent = dget_parent(d);
8650 + if (!au_digen_test(parent, sigen))
8656 + di_write_lock_child2(d);
8658 + /* someone might update our dentry while we were sleeping */
8659 + if (au_digen_test(d, sigen)) {
8661 + * todo: consolidate with simple_reval_dpath(),
8662 + * do_refresh() and au_reval_for_attr().
8664 + di_read_lock_parent(parent, AuLock_IR);
8665 + err = au_refresh_dentry(d, parent);
8666 + di_read_unlock(parent, AuLock_IR);
8670 + di_write_unlock(d);
8672 + if (unlikely(err))
8680 + * if valid returns 1, otherwise 0.
8682 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8685 + unsigned int sigen;
8686 + unsigned char do_udba;
8687 + struct super_block *sb;
8688 + struct inode *inode;
8690 + /* todo: support rcu-walk? */
8691 + if (flags & LOOKUP_RCU)
8695 + if (unlikely(!au_di(dentry)))
8699 + sb = dentry->d_sb;
8702 + * i_mutex of parent dir may be held,
8703 + * but we should not return 'invalid' due to busy.
8705 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8706 + if (unlikely(err)) {
8712 + if (d_really_is_positive(dentry))
8713 + inode = d_inode(dentry);
8714 + if (unlikely(inode && au_is_bad_inode(inode))) {
8719 + if (unlikely(au_dbrange_test(dentry))) {
8725 + sigen = au_sigen(sb);
8726 + if (au_digen_test(dentry, sigen)) {
8727 + AuDebugOn(IS_ROOT(dentry));
8728 + err = au_reval_dpath(dentry, sigen);
8729 + if (unlikely(err)) {
8734 + di_downgrade_lock(dentry, AuLock_IR);
8737 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8739 + && !(inode->i_state && I_LINKABLE)
8740 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
8745 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8746 + if (do_udba && inode) {
8747 + aufs_bindex_t btop = au_ibtop(inode);
8748 + struct inode *h_inode;
8751 + h_inode = au_h_iptr(inode, btop);
8752 + if (h_inode && au_test_higen(inode, h_inode)) {
8759 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8760 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
8762 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8768 + di_downgrade_lock(dentry, AuLock_IR);
8770 + aufs_read_unlock(dentry, AuLock_IR);
8775 + AuDbg("%pd invalid, %d\n", dentry, valid);
8781 +static void aufs_d_release(struct dentry *dentry)
8783 + if (au_di(dentry)) {
8784 + au_di_fin(dentry);
8785 + au_hn_di_reinit(dentry);
8789 +const struct dentry_operations aufs_dop = {
8790 + .d_revalidate = aufs_d_revalidate,
8791 + .d_weak_revalidate = aufs_d_revalidate,
8792 + .d_release = aufs_d_release
8795 +/* aufs_dop without d_revalidate */
8796 +const struct dentry_operations aufs_dop_noreval = {
8797 + .d_release = aufs_d_release
8799 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8800 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8801 +++ linux/fs/aufs/dentry.h 2016-10-09 16:55:38.889431135 +0200
8804 + * Copyright (C) 2005-2016 Junjiro R. Okajima
8806 + * This program, aufs is free software; you can redistribute it and/or modify
8807 + * it under the terms of the GNU General Public License as published by
8808 + * the Free Software Foundation; either version 2 of the License, or
8809 + * (at your option) any later version.
8811 + * This program is distributed in the hope that it will be useful,
8812 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8813 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8814 + * GNU General Public License for more details.
8816 + * You should have received a copy of the GNU General Public License
8817 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8821 + * lookup and dentry operations
8824 +#ifndef __AUFS_DENTRY_H__
8825 +#define __AUFS_DENTRY_H__
8829 +#include <linux/dcache.h>
8832 +struct au_hdentry {
8833 + struct dentry *hd_dentry;
8834 + aufs_bindex_t hd_id;
8838 + atomic_t di_generation;
8840 + struct au_rwsem di_rwsem;
8841 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
8842 + unsigned char di_tmpfile; /* to allow the different name */
8844 + struct au_hdentry *di_hdentry;
8845 + struct llist_node di_lnode; /* delayed free */
8847 +} ____cacheline_aligned_in_smp;
8849 +/* ---------------------------------------------------------------------- */
8851 +/* flags for au_lkup_dentry() */
8852 +#define AuLkup_ALLOW_NEG 1
8853 +#define AuLkup_IGNORE_PERM (1 << 1)
8854 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
8855 +#define au_fset_lkup(flags, name) \
8856 + do { (flags) |= AuLkup_##name; } while (0)
8857 +#define au_fclr_lkup(flags, name) \
8858 + do { (flags) &= ~AuLkup_##name; } while (0)
8860 +/* ---------------------------------------------------------------------- */
8863 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
8865 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8866 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8867 + struct dentry *h_parent, struct au_branch *br);
8869 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8870 + unsigned int flags);
8871 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8872 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8873 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8874 +void au_refresh_dop(struct dentry *dentry, int force_reval);
8877 +void au_di_init_once(void *_di);
8878 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8879 +void au_di_free(struct au_dinfo *dinfo);
8880 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8881 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8882 +int au_di_init(struct dentry *dentry);
8883 +void au_di_fin(struct dentry *dentry);
8884 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
8886 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8887 +void di_read_unlock(struct dentry *d, int flags);
8888 +void di_downgrade_lock(struct dentry *d, int flags);
8889 +void di_write_lock(struct dentry *d, unsigned int lsc);
8890 +void di_write_unlock(struct dentry *d);
8891 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8892 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8893 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8895 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8896 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8897 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8898 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8900 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8901 + struct dentry *h_dentry);
8902 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8903 +int au_dbrange_test(struct dentry *dentry);
8904 +void au_update_digen(struct dentry *dentry);
8905 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8906 +void au_update_dbtop(struct dentry *dentry);
8907 +void au_update_dbbot(struct dentry *dentry);
8908 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8910 +/* ---------------------------------------------------------------------- */
8912 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8914 + return dentry->d_fsdata;
8917 +/* ---------------------------------------------------------------------- */
8919 +/* lock subclass for dinfo */
8921 + AuLsc_DI_CHILD, /* child first */
8922 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8923 + AuLsc_DI_CHILD3, /* copyup dirs */
8927 + AuLsc_DI_TMP /* temp for replacing dinfo */
8931 + * di_read_lock_child, di_write_lock_child,
8932 + * di_read_lock_child2, di_write_lock_child2,
8933 + * di_read_lock_child3, di_write_lock_child3,
8934 + * di_read_lock_parent, di_write_lock_parent,
8935 + * di_read_lock_parent2, di_write_lock_parent2,
8936 + * di_read_lock_parent3, di_write_lock_parent3,
8938 +#define AuReadLockFunc(name, lsc) \
8939 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8940 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8942 +#define AuWriteLockFunc(name, lsc) \
8943 +static inline void di_write_lock_##name(struct dentry *d) \
8944 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8946 +#define AuRWLockFuncs(name, lsc) \
8947 + AuReadLockFunc(name, lsc) \
8948 + AuWriteLockFunc(name, lsc)
8950 +AuRWLockFuncs(child, CHILD);
8951 +AuRWLockFuncs(child2, CHILD2);
8952 +AuRWLockFuncs(child3, CHILD3);
8953 +AuRWLockFuncs(parent, PARENT);
8954 +AuRWLockFuncs(parent2, PARENT2);
8955 +AuRWLockFuncs(parent3, PARENT3);
8957 +#undef AuReadLockFunc
8958 +#undef AuWriteLockFunc
8959 +#undef AuRWLockFuncs
8961 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8962 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8963 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8965 +/* ---------------------------------------------------------------------- */
8967 +/* todo: memory barrier? */
8968 +static inline unsigned int au_digen(struct dentry *d)
8970 + return atomic_read(&au_di(d)->di_generation);
8973 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8975 + hdentry->hd_dentry = NULL;
8978 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
8979 + aufs_bindex_t bindex)
8981 + return di->di_hdentry + bindex;
8984 +static inline void au_hdput(struct au_hdentry *hd)
8987 + dput(hd->hd_dentry);
8990 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
8992 + DiMustAnyLock(dentry);
8993 + return au_di(dentry)->di_btop;
8996 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
8998 + DiMustAnyLock(dentry);
8999 + return au_di(dentry)->di_bbot;
9002 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9004 + DiMustAnyLock(dentry);
9005 + return au_di(dentry)->di_bwh;
9008 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9010 + DiMustAnyLock(dentry);
9011 + return au_di(dentry)->di_bdiropq;
9014 +/* todo: hard/soft set? */
9015 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9017 + DiMustWriteLock(dentry);
9018 + au_di(dentry)->di_btop = bindex;
9021 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9023 + DiMustWriteLock(dentry);
9024 + au_di(dentry)->di_bbot = bindex;
9027 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9029 + DiMustWriteLock(dentry);
9030 + /* dbwh can be outside of btop - bbot range */
9031 + au_di(dentry)->di_bwh = bindex;
9034 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9036 + DiMustWriteLock(dentry);
9037 + au_di(dentry)->di_bdiropq = bindex;
9040 +/* ---------------------------------------------------------------------- */
9042 +#ifdef CONFIG_AUFS_HNOTIFY
9043 +static inline void au_digen_dec(struct dentry *d)
9045 + atomic_dec(&au_di(d)->di_generation);
9048 +static inline void au_hn_di_reinit(struct dentry *dentry)
9050 + dentry->d_fsdata = NULL;
9053 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9054 +#endif /* CONFIG_AUFS_HNOTIFY */
9056 +#endif /* __KERNEL__ */
9057 +#endif /* __AUFS_DENTRY_H__ */
9058 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9059 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9060 +++ linux/fs/aufs/dinfo.c 2016-10-09 16:55:38.889431135 +0200
9063 + * Copyright (C) 2005-2016 Junjiro R. Okajima
9065 + * This program, aufs is free software; you can redistribute it and/or modify
9066 + * it under the terms of the GNU General Public License as published by
9067 + * the Free Software Foundation; either version 2 of the License, or
9068 + * (at your option) any later version.
9070 + * This program is distributed in the hope that it will be useful,
9071 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9072 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9073 + * GNU General Public License for more details.
9075 + * You should have received a copy of the GNU General Public License
9076 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9080 + * dentry private data
9085 +void au_di_init_once(void *_dinfo)
9087 + struct au_dinfo *dinfo = _dinfo;
9089 + au_rw_init(&dinfo->di_rwsem);
9092 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9094 + struct au_dinfo *dinfo;
9097 + dinfo = au_cache_alloc_dinfo();
9098 + if (unlikely(!dinfo))
9101 + nbr = au_sbbot(sb) + 1;
9104 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9105 + if (dinfo->di_hdentry) {
9106 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9107 + dinfo->di_btop = -1;
9108 + dinfo->di_bbot = -1;
9109 + dinfo->di_bwh = -1;
9110 + dinfo->di_bdiropq = -1;
9111 + dinfo->di_tmpfile = 0;
9112 + for (i = 0; i < nbr; i++)
9113 + dinfo->di_hdentry[i].hd_id = -1;
9117 + au_cache_dfree_dinfo(dinfo);
9124 +void au_di_free(struct au_dinfo *dinfo)
9126 + struct au_hdentry *p;
9127 + aufs_bindex_t bbot, bindex;
9129 + /* dentry may not be revalidated */
9130 + bindex = dinfo->di_btop;
9131 + if (bindex >= 0) {
9132 + bbot = dinfo->di_bbot;
9133 + p = au_hdentry(dinfo, bindex);
9134 + while (bindex++ <= bbot)
9137 + au_delayed_kfree(dinfo->di_hdentry);
9138 + au_cache_dfree_dinfo(dinfo);
9141 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9143 + struct au_hdentry *p;
9146 + AuRwMustWriteLock(&a->di_rwsem);
9147 + AuRwMustWriteLock(&b->di_rwsem);
9149 +#define DiSwap(v, name) \
9151 + v = a->di_##name; \
9152 + a->di_##name = b->di_##name; \
9153 + b->di_##name = v; \
9156 + DiSwap(p, hdentry);
9160 + DiSwap(bi, bdiropq);
9166 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9168 + AuRwMustWriteLock(&dst->di_rwsem);
9169 + AuRwMustWriteLock(&src->di_rwsem);
9171 + dst->di_btop = src->di_btop;
9172 + dst->di_bbot = src->di_bbot;
9173 + dst->di_bwh = src->di_bwh;
9174 + dst->di_bdiropq = src->di_bdiropq;
9178 +int au_di_init(struct dentry *dentry)
9181 + struct super_block *sb;
9182 + struct au_dinfo *dinfo;
9185 + sb = dentry->d_sb;
9186 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9188 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9189 + /* smp_mb(); */ /* atomic_set */
9190 + dentry->d_fsdata = dinfo;
9197 +void au_di_fin(struct dentry *dentry)
9199 + struct au_dinfo *dinfo;
9201 + dinfo = au_di(dentry);
9202 + AuRwDestroy(&dinfo->di_rwsem);
9203 + au_di_free(dinfo);
9206 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9209 + struct au_hdentry *hdp;
9211 + AuRwMustWriteLock(&dinfo->di_rwsem);
9214 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9216 + sz = sizeof(*hdp);
9217 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9220 + dinfo->di_hdentry = hdp;
9227 +/* ---------------------------------------------------------------------- */
9229 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9232 + case AuLsc_DI_CHILD:
9233 + ii_write_lock_child(inode);
9235 + case AuLsc_DI_CHILD2:
9236 + ii_write_lock_child2(inode);
9238 + case AuLsc_DI_CHILD3:
9239 + ii_write_lock_child3(inode);
9241 + case AuLsc_DI_PARENT:
9242 + ii_write_lock_parent(inode);
9244 + case AuLsc_DI_PARENT2:
9245 + ii_write_lock_parent2(inode);
9247 + case AuLsc_DI_PARENT3:
9248 + ii_write_lock_parent3(inode);
9255 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9258 + case AuLsc_DI_CHILD:
9259 + ii_read_lock_child(inode);
9261 + case AuLsc_DI_CHILD2:
9262 + ii_read_lock_child2(inode);
9264 + case AuLsc_DI_CHILD3:
9265 + ii_read_lock_child3(inode);
9267 + case AuLsc_DI_PARENT:
9268 + ii_read_lock_parent(inode);
9270 + case AuLsc_DI_PARENT2:
9271 + ii_read_lock_parent2(inode);
9273 + case AuLsc_DI_PARENT3:
9274 + ii_read_lock_parent3(inode);
9281 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9283 + struct inode *inode;
9285 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9286 + if (d_really_is_positive(d)) {
9287 + inode = d_inode(d);
9288 + if (au_ftest_lock(flags, IW))
9289 + do_ii_write_lock(inode, lsc);
9290 + else if (au_ftest_lock(flags, IR))
9291 + do_ii_read_lock(inode, lsc);
9295 +void di_read_unlock(struct dentry *d, int flags)
9297 + struct inode *inode;
9299 + if (d_really_is_positive(d)) {
9300 + inode = d_inode(d);
9301 + if (au_ftest_lock(flags, IW)) {
9302 + au_dbg_verify_dinode(d);
9303 + ii_write_unlock(inode);
9304 + } else if (au_ftest_lock(flags, IR)) {
9305 + au_dbg_verify_dinode(d);
9306 + ii_read_unlock(inode);
9309 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9312 +void di_downgrade_lock(struct dentry *d, int flags)
9314 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9315 + ii_downgrade_lock(d_inode(d));
9316 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9319 +void di_write_lock(struct dentry *d, unsigned int lsc)
9321 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9322 + if (d_really_is_positive(d))
9323 + do_ii_write_lock(d_inode(d), lsc);
9326 +void di_write_unlock(struct dentry *d)
9328 + au_dbg_verify_dinode(d);
9329 + if (d_really_is_positive(d))
9330 + ii_write_unlock(d_inode(d));
9331 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9334 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9336 + AuDebugOn(d1 == d2
9337 + || d_inode(d1) == d_inode(d2)
9338 + || d1->d_sb != d2->d_sb);
9340 + if (isdir && au_test_subdir(d1, d2)) {
9341 + di_write_lock_child(d1);
9342 + di_write_lock_child2(d2);
9344 + /* there should be no races */
9345 + di_write_lock_child(d2);
9346 + di_write_lock_child2(d1);
9350 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9352 + AuDebugOn(d1 == d2
9353 + || d_inode(d1) == d_inode(d2)
9354 + || d1->d_sb != d2->d_sb);
9356 + if (isdir && au_test_subdir(d1, d2)) {
9357 + di_write_lock_parent(d1);
9358 + di_write_lock_parent2(d2);
9360 + /* there should be no races */
9361 + di_write_lock_parent(d2);
9362 + di_write_lock_parent2(d1);
9366 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9368 + di_write_unlock(d1);
9369 + if (d_inode(d1) == d_inode(d2))
9370 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9372 + di_write_unlock(d2);
9375 +/* ---------------------------------------------------------------------- */
9377 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9381 + DiMustAnyLock(dentry);
9383 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9385 + AuDebugOn(bindex < 0);
9386 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9387 + AuDebugOn(d && au_dcount(d) <= 0);
9392 + * extended version of au_h_dptr().
9393 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9396 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9398 + struct dentry *h_dentry;
9399 + struct inode *inode, *h_inode;
9401 + AuDebugOn(d_really_is_negative(dentry));
9404 + if (au_dbtop(dentry) <= bindex
9405 + && bindex <= au_dbbot(dentry))
9406 + h_dentry = au_h_dptr(dentry, bindex);
9407 + if (h_dentry && !au_d_linkable(h_dentry)) {
9409 + goto out; /* success */
9412 + inode = d_inode(dentry);
9413 + AuDebugOn(bindex < au_ibtop(inode));
9414 + AuDebugOn(au_ibbot(inode) < bindex);
9415 + h_inode = au_h_iptr(inode, bindex);
9416 + h_dentry = d_find_alias(h_inode);
9418 + if (!IS_ERR(h_dentry)) {
9419 + if (!au_d_linkable(h_dentry))
9420 + goto out; /* success */
9426 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9427 + h_dentry = au_plink_lkup(inode, bindex);
9428 + AuDebugOn(!h_dentry);
9429 + if (!IS_ERR(h_dentry)) {
9430 + if (!au_d_hashed_positive(h_dentry))
9431 + goto out; /* success */
9438 + AuDbgDentry(h_dentry);
9442 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9444 + aufs_bindex_t bbot, bwh;
9446 + bbot = au_dbbot(dentry);
9448 + bwh = au_dbwh(dentry);
9451 + if (0 < bwh && bwh < bbot)
9457 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9459 + aufs_bindex_t bbot, bopq;
9461 + bbot = au_dbtail(dentry);
9463 + bopq = au_dbdiropq(dentry);
9464 + if (0 <= bopq && bopq < bbot)
9470 +/* ---------------------------------------------------------------------- */
9472 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9473 + struct dentry *h_dentry)
9475 + struct au_dinfo *dinfo;
9476 + struct au_hdentry *hd;
9477 + struct au_branch *br;
9479 + DiMustWriteLock(dentry);
9481 + dinfo = au_di(dentry);
9482 + hd = au_hdentry(dinfo, bindex);
9484 + hd->hd_dentry = h_dentry;
9486 + br = au_sbr(dentry->d_sb, bindex);
9487 + hd->hd_id = br->br_id;
9491 +int au_dbrange_test(struct dentry *dentry)
9494 + aufs_bindex_t btop, bbot;
9497 + btop = au_dbtop(dentry);
9498 + bbot = au_dbbot(dentry);
9500 + AuDebugOn(bbot < 0 && btop > bbot);
9503 + AuDebugOn(bbot >= 0);
9509 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9514 + if (unlikely(au_digen(dentry) != sigen
9515 + || au_iigen_test(d_inode(dentry), sigen)))
9521 +void au_update_digen(struct dentry *dentry)
9523 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9524 + /* smp_mb(); */ /* atomic_set */
9527 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9529 + struct au_dinfo *dinfo;
9530 + struct dentry *h_d;
9531 + struct au_hdentry *hdp;
9532 + aufs_bindex_t bindex, bbot;
9534 + DiMustWriteLock(dentry);
9536 + dinfo = au_di(dentry);
9537 + if (!dinfo || dinfo->di_btop < 0)
9540 + if (do_put_zero) {
9541 + bbot = dinfo->di_bbot;
9542 + bindex = dinfo->di_btop;
9543 + hdp = au_hdentry(dinfo, bindex);
9544 + for (; bindex <= bbot; bindex++, hdp++) {
9545 + h_d = hdp->hd_dentry;
9546 + if (h_d && d_is_negative(h_d))
9547 + au_set_h_dptr(dentry, bindex, NULL);
9551 + dinfo->di_btop = 0;
9552 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9553 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9554 + if (hdp->hd_dentry)
9556 + if (dinfo->di_btop > dinfo->di_bbot) {
9557 + dinfo->di_btop = -1;
9558 + dinfo->di_bbot = -1;
9562 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9563 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9564 + if (hdp->hd_dentry)
9566 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9569 +void au_update_dbtop(struct dentry *dentry)
9571 + aufs_bindex_t bindex, bbot;
9572 + struct dentry *h_dentry;
9574 + bbot = au_dbbot(dentry);
9575 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9576 + h_dentry = au_h_dptr(dentry, bindex);
9579 + if (d_is_positive(h_dentry)) {
9580 + au_set_dbtop(dentry, bindex);
9583 + au_set_h_dptr(dentry, bindex, NULL);
9587 +void au_update_dbbot(struct dentry *dentry)
9589 + aufs_bindex_t bindex, btop;
9590 + struct dentry *h_dentry;
9592 + btop = au_dbtop(dentry);
9593 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9594 + h_dentry = au_h_dptr(dentry, bindex);
9597 + if (d_is_positive(h_dentry)) {
9598 + au_set_dbbot(dentry, bindex);
9601 + au_set_h_dptr(dentry, bindex, NULL);
9605 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9607 + aufs_bindex_t bindex, bbot;
9609 + bbot = au_dbbot(dentry);
9610 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9611 + if (au_h_dptr(dentry, bindex) == h_dentry)
9615 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9616 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9617 +++ linux/fs/aufs/dir.c 2016-10-09 16:55:36.489368218 +0200
9620 + * Copyright (C) 2005-2016 Junjiro R. Okajima
9622 + * This program, aufs is free software; you can redistribute it and/or modify
9623 + * it under the terms of the GNU General Public License as published by
9624 + * the Free Software Foundation; either version 2 of the License, or
9625 + * (at your option) any later version.
9627 + * This program is distributed in the hope that it will be useful,
9628 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9629 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9630 + * GNU General Public License for more details.
9632 + * You should have received a copy of the GNU General Public License
9633 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9637 + * directory operations
9640 +#include <linux/fs_stack.h>
9643 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9645 + unsigned int nlink;
9647 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9649 + nlink = dir->i_nlink;
9650 + nlink += h_dir->i_nlink - 2;
9651 + if (h_dir->i_nlink < 2)
9653 + smp_mb(); /* for i_nlink */
9654 + /* 0 can happen in revaliding */
9655 + set_nlink(dir, nlink);
9658 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9660 + unsigned int nlink;
9662 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9664 + nlink = dir->i_nlink;
9665 + nlink -= h_dir->i_nlink - 2;
9666 + if (h_dir->i_nlink < 2)
9668 + smp_mb(); /* for i_nlink */
9669 + /* nlink == 0 means the branch-fs is broken */
9670 + set_nlink(dir, nlink);
9673 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9676 + aufs_bindex_t bindex, bbot;
9677 + struct file *h_file;
9678 + struct dentry *h_dentry;
9682 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9684 + bbot = au_fbbot_dir(file);
9685 + for (bindex = au_fbtop(file);
9686 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9688 + h_file = au_hf_dir(file, bindex);
9689 + if (h_file && file_inode(h_file))
9690 + sz += vfsub_f_size_read(h_file);
9693 + AuDebugOn(!dentry);
9694 + AuDebugOn(!d_is_dir(dentry));
9696 + bbot = au_dbtaildir(dentry);
9697 + for (bindex = au_dbtop(dentry);
9698 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9700 + h_dentry = au_h_dptr(dentry, bindex);
9701 + if (h_dentry && d_is_positive(h_dentry))
9702 + sz += i_size_read(d_inode(h_dentry));
9705 + if (sz < KMALLOC_MAX_SIZE)
9706 + sz = roundup_pow_of_two(sz);
9707 + if (sz > KMALLOC_MAX_SIZE)
9708 + sz = KMALLOC_MAX_SIZE;
9709 + else if (sz < NAME_MAX) {
9710 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9711 + sz = AUFS_RDBLK_DEF;
9716 +struct au_dir_ts_arg {
9717 + struct dentry *dentry;
9718 + aufs_bindex_t brid;
9721 +static void au_do_dir_ts(void *arg)
9723 + struct au_dir_ts_arg *a = arg;
9724 + struct au_dtime dt;
9725 + struct path h_path;
9726 + struct inode *dir, *h_dir;
9727 + struct super_block *sb;
9728 + struct au_branch *br;
9729 + struct au_hinode *hdir;
9731 + aufs_bindex_t btop, bindex;
9733 + sb = a->dentry->d_sb;
9734 + if (d_really_is_negative(a->dentry))
9736 + /* no dir->i_mutex lock */
9737 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
9739 + dir = d_inode(a->dentry);
9740 + btop = au_ibtop(dir);
9741 + bindex = au_br_index(sb, a->brid);
9742 + if (bindex < btop)
9745 + br = au_sbr(sb, bindex);
9746 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9747 + if (!h_path.dentry)
9749 + h_path.mnt = au_br_mnt(br);
9750 + au_dtime_store(&dt, a->dentry, &h_path);
9752 + br = au_sbr(sb, btop);
9753 + if (!au_br_writable(br->br_perm))
9755 + h_path.dentry = au_h_dptr(a->dentry, btop);
9756 + h_path.mnt = au_br_mnt(br);
9757 + err = vfsub_mnt_want_write(h_path.mnt);
9760 + hdir = au_hi(dir, btop);
9761 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
9762 + h_dir = au_h_iptr(dir, btop);
9763 + if (h_dir->i_nlink
9764 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9765 + dt.dt_h_path = h_path;
9766 + au_dtime_revert(&dt);
9768 + au_hn_inode_unlock(hdir);
9769 + vfsub_mnt_drop_write(h_path.mnt);
9770 + au_cpup_attr_timesizes(dir);
9773 + aufs_read_unlock(a->dentry, AuLock_DW);
9776 + au_nwt_done(&au_sbi(sb)->si_nowait);
9777 + au_delayed_kfree(arg);
9780 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9782 + int perm, wkq_err;
9783 + aufs_bindex_t btop;
9784 + struct au_dir_ts_arg *arg;
9785 + struct dentry *dentry;
9786 + struct super_block *sb;
9790 + dentry = d_find_any_alias(dir);
9791 + AuDebugOn(!dentry);
9792 + sb = dentry->d_sb;
9793 + btop = au_ibtop(dir);
9794 + if (btop == bindex) {
9795 + au_cpup_attr_timesizes(dir);
9799 + perm = au_sbr_perm(sb, btop);
9800 + if (!au_br_writable(perm))
9803 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9807 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9808 + arg->brid = au_sbr_id(sb, bindex);
9809 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9810 + if (unlikely(wkq_err)) {
9811 + pr_err("wkq %d\n", wkq_err);
9813 + au_delayed_kfree(arg);
9820 +/* ---------------------------------------------------------------------- */
9822 +static int reopen_dir(struct file *file)
9825 + unsigned int flags;
9826 + aufs_bindex_t bindex, btail, btop;
9827 + struct dentry *dentry, *h_dentry;
9828 + struct file *h_file;
9830 + /* open all lower dirs */
9831 + dentry = file->f_path.dentry;
9832 + btop = au_dbtop(dentry);
9833 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
9834 + au_set_h_fptr(file, bindex, NULL);
9835 + au_set_fbtop(file, btop);
9837 + btail = au_dbtaildir(dentry);
9838 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
9839 + au_set_h_fptr(file, bindex, NULL);
9840 + au_set_fbbot_dir(file, btail);
9842 + flags = vfsub_file_flags(file);
9843 + for (bindex = btop; bindex <= btail; bindex++) {
9844 + h_dentry = au_h_dptr(dentry, bindex);
9847 + h_file = au_hf_dir(file, bindex);
9851 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9852 + err = PTR_ERR(h_file);
9853 + if (IS_ERR(h_file))
9854 + goto out; /* close all? */
9855 + au_set_h_fptr(file, bindex, h_file);
9857 + au_update_figen(file);
9858 + /* todo: necessary? */
9859 + /* file->f_ra = h_file->f_ra; */
9866 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9869 + aufs_bindex_t bindex, btail;
9870 + struct dentry *dentry, *h_dentry;
9871 + struct vfsmount *mnt;
9873 + FiMustWriteLock(file);
9874 + AuDebugOn(h_file);
9877 + mnt = file->f_path.mnt;
9878 + dentry = file->f_path.dentry;
9879 + file->f_version = d_inode(dentry)->i_version;
9880 + bindex = au_dbtop(dentry);
9881 + au_set_fbtop(file, bindex);
9882 + btail = au_dbtaildir(dentry);
9883 + au_set_fbbot_dir(file, btail);
9884 + for (; !err && bindex <= btail; bindex++) {
9885 + h_dentry = au_h_dptr(dentry, bindex);
9889 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
9890 + if (unlikely(err))
9892 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9893 + if (IS_ERR(h_file)) {
9894 + err = PTR_ERR(h_file);
9897 + au_set_h_fptr(file, bindex, h_file);
9899 + au_update_figen(file);
9900 + /* todo: necessary? */
9901 + /* file->f_ra = h_file->f_ra; */
9903 + return 0; /* success */
9906 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
9907 + au_set_h_fptr(file, bindex, NULL);
9908 + au_set_fbtop(file, -1);
9909 + au_set_fbbot_dir(file, -1);
9914 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9915 + struct file *file)
9918 + struct super_block *sb;
9919 + struct au_fidir *fidir;
9922 + sb = file->f_path.dentry->d_sb;
9923 + si_read_lock(sb, AuLock_FLUSH);
9924 + fidir = au_fidir_alloc(sb);
9926 + struct au_do_open_args args = {
9927 + .open = do_open_dir,
9930 + err = au_do_open(file, &args);
9931 + if (unlikely(err))
9932 + au_delayed_kfree(fidir);
9934 + si_read_unlock(sb);
9938 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9939 + struct file *file)
9941 + struct au_vdir *vdir_cache;
9942 + struct au_finfo *finfo;
9943 + struct au_fidir *fidir;
9944 + struct au_hfile *hf;
9945 + aufs_bindex_t bindex, bbot;
9946 + int execed, delayed;
9948 + delayed = (current->flags & PF_KTHREAD) || in_interrupt();
9949 + finfo = au_fi(file);
9950 + fidir = finfo->fi_hdir;
9952 + au_sphl_del(&finfo->fi_hlist,
9953 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9954 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9956 + au_vdir_free(vdir_cache, delayed);
9958 + bindex = finfo->fi_btop;
9959 + if (bindex >= 0) {
9960 + execed = vfsub_file_execed(file);
9961 + hf = fidir->fd_hfile + bindex;
9963 + * calls fput() instead of filp_close(),
9964 + * since no dnotify or lock for the lower file.
9966 + bbot = fidir->fd_bbot;
9967 + for (; bindex <= bbot; bindex++, hf++)
9969 + au_hfput(hf, execed);
9971 + au_delayed_kfree(fidir);
9972 + finfo->fi_hdir = NULL;
9974 + au_finfo_fin(file, delayed);
9978 +/* ---------------------------------------------------------------------- */
9980 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9983 + aufs_bindex_t bindex, bbot;
9984 + struct file *h_file;
9987 + bbot = au_fbbot_dir(file);
9988 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
9989 + h_file = au_hf_dir(file, bindex);
9991 + err = vfsub_flush(h_file, id);
9996 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
9998 + return au_do_flush(file, id, au_do_flush_dir);
10001 +/* ---------------------------------------------------------------------- */
10003 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10006 + aufs_bindex_t bbot, bindex;
10007 + struct inode *inode;
10008 + struct super_block *sb;
10011 + sb = dentry->d_sb;
10012 + inode = d_inode(dentry);
10013 + IMustLock(inode);
10014 + bbot = au_dbbot(dentry);
10015 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10016 + struct path h_path;
10018 + if (au_test_ro(sb, bindex, inode))
10020 + h_path.dentry = au_h_dptr(dentry, bindex);
10021 + if (!h_path.dentry)
10024 + h_path.mnt = au_sbr_mnt(sb, bindex);
10025 + err = vfsub_fsync(NULL, &h_path, datasync);
10031 +static int au_do_fsync_dir(struct file *file, int datasync)
10034 + aufs_bindex_t bbot, bindex;
10035 + struct file *h_file;
10036 + struct super_block *sb;
10037 + struct inode *inode;
10039 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
10040 + if (unlikely(err))
10043 + inode = file_inode(file);
10044 + sb = inode->i_sb;
10045 + bbot = au_fbbot_dir(file);
10046 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10047 + h_file = au_hf_dir(file, bindex);
10048 + if (!h_file || au_test_ro(sb, bindex, inode))
10051 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10059 + * @file may be NULL
10061 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10065 + struct dentry *dentry;
10066 + struct inode *inode;
10067 + struct super_block *sb;
10070 + dentry = file->f_path.dentry;
10071 + inode = d_inode(dentry);
10072 + inode_lock(inode);
10073 + sb = dentry->d_sb;
10074 + si_noflush_read_lock(sb);
10076 + err = au_do_fsync_dir(file, datasync);
10078 + di_write_lock_child(dentry);
10079 + err = au_do_fsync_dir_no_file(dentry, datasync);
10081 + au_cpup_attr_timesizes(inode);
10082 + di_write_unlock(dentry);
10084 + fi_write_unlock(file);
10086 + si_read_unlock(sb);
10087 + inode_unlock(inode);
10091 +/* ---------------------------------------------------------------------- */
10093 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10096 + struct dentry *dentry;
10097 + struct inode *inode, *h_inode;
10098 + struct super_block *sb;
10100 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
10102 + dentry = file->f_path.dentry;
10103 + inode = d_inode(dentry);
10104 + IMustLock(inode);
10106 + sb = dentry->d_sb;
10107 + si_read_lock(sb, AuLock_FLUSH);
10108 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
10109 + if (unlikely(err))
10111 + err = au_alive_dir(dentry);
10113 + err = au_vdir_init(file);
10114 + di_downgrade_lock(dentry, AuLock_IR);
10115 + if (unlikely(err))
10118 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10119 + if (!au_test_nfsd()) {
10120 + err = au_vdir_fill_de(file, ctx);
10121 + fsstack_copy_attr_atime(inode, h_inode);
10124 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10125 + * encode_fh() and others.
10127 + atomic_inc(&h_inode->i_count);
10128 + di_read_unlock(dentry, AuLock_IR);
10129 + si_read_unlock(sb);
10130 + err = au_vdir_fill_de(file, ctx);
10131 + fsstack_copy_attr_atime(inode, h_inode);
10132 + fi_write_unlock(file);
10140 + di_read_unlock(dentry, AuLock_IR);
10141 + fi_write_unlock(file);
10143 + si_read_unlock(sb);
10147 +/* ---------------------------------------------------------------------- */
10149 +#define AuTestEmpty_WHONLY 1
10150 +#define AuTestEmpty_CALLED (1 << 1)
10151 +#define AuTestEmpty_SHWH (1 << 2)
10152 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10153 +#define au_fset_testempty(flags, name) \
10154 + do { (flags) |= AuTestEmpty_##name; } while (0)
10155 +#define au_fclr_testempty(flags, name) \
10156 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10158 +#ifndef CONFIG_AUFS_SHWH
10159 +#undef AuTestEmpty_SHWH
10160 +#define AuTestEmpty_SHWH 0
10163 +struct test_empty_arg {
10164 + struct dir_context ctx;
10165 + struct au_nhash *whlist;
10166 + unsigned int flags;
10168 + aufs_bindex_t bindex;
10171 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10172 + int namelen, loff_t offset __maybe_unused, u64 ino,
10173 + unsigned int d_type)
10175 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10177 + char *name = (void *)__name;
10180 + au_fset_testempty(arg->flags, CALLED);
10182 + if (name[0] == '.'
10183 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10184 + goto out; /* success */
10186 + if (namelen <= AUFS_WH_PFX_LEN
10187 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10188 + if (au_ftest_testempty(arg->flags, WHONLY)
10189 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10190 + arg->err = -ENOTEMPTY;
10194 + name += AUFS_WH_PFX_LEN;
10195 + namelen -= AUFS_WH_PFX_LEN;
10196 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10197 + arg->err = au_nhash_append_wh
10198 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10199 + au_ftest_testempty(arg->flags, SHWH));
10203 + AuTraceErr(arg->err);
10207 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10210 + struct file *h_file;
10212 + h_file = au_h_open(dentry, arg->bindex,
10213 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10214 + /*file*/NULL, /*force_wr*/0);
10215 + err = PTR_ERR(h_file);
10216 + if (IS_ERR(h_file))
10220 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10221 + && !file_inode(h_file)->i_nlink)
10226 + au_fclr_testempty(arg->flags, CALLED);
10228 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10231 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10235 + au_sbr_put(dentry->d_sb, arg->bindex);
10240 +struct do_test_empty_args {
10242 + struct dentry *dentry;
10243 + struct test_empty_arg *arg;
10246 +static void call_do_test_empty(void *args)
10248 + struct do_test_empty_args *a = args;
10249 + *a->errp = do_test_empty(a->dentry, a->arg);
10252 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10254 + int err, wkq_err;
10255 + struct dentry *h_dentry;
10256 + struct inode *h_inode;
10258 + h_dentry = au_h_dptr(dentry, arg->bindex);
10259 + h_inode = d_inode(h_dentry);
10260 + /* todo: i_mode changes anytime? */
10261 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
10262 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10263 + inode_unlock(h_inode);
10265 + err = do_test_empty(dentry, arg);
10267 + struct do_test_empty_args args = {
10269 + .dentry = dentry,
10272 + unsigned int flags = arg->flags;
10274 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10275 + if (unlikely(wkq_err))
10277 + arg->flags = flags;
10283 +int au_test_empty_lower(struct dentry *dentry)
10286 + unsigned int rdhash;
10287 + aufs_bindex_t bindex, btop, btail;
10288 + struct au_nhash whlist;
10289 + struct test_empty_arg arg = {
10291 + .actor = test_empty_cb
10294 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10296 + SiMustAnyLock(dentry->d_sb);
10298 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10300 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10301 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10302 + if (unlikely(err))
10306 + arg.whlist = &whlist;
10307 + btop = au_dbtop(dentry);
10308 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10309 + au_fset_testempty(arg.flags, SHWH);
10310 + test_empty = do_test_empty;
10311 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10312 + test_empty = sio_test_empty;
10313 + arg.bindex = btop;
10314 + err = test_empty(dentry, &arg);
10315 + if (unlikely(err))
10318 + au_fset_testempty(arg.flags, WHONLY);
10319 + btail = au_dbtaildir(dentry);
10320 + for (bindex = btop + 1; !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 = test_empty(dentry, &arg);
10331 + au_nhash_wh_free(&whlist);
10336 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10339 + struct test_empty_arg arg = {
10341 + .actor = test_empty_cb
10344 + aufs_bindex_t bindex, btail;
10347 + arg.whlist = whlist;
10348 + arg.flags = AuTestEmpty_WHONLY;
10349 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10350 + au_fset_testempty(arg.flags, SHWH);
10351 + btail = au_dbtaildir(dentry);
10352 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10353 + struct dentry *h_dentry;
10355 + h_dentry = au_h_dptr(dentry, bindex);
10356 + if (h_dentry && d_is_positive(h_dentry)) {
10357 + arg.bindex = bindex;
10358 + err = sio_test_empty(dentry, &arg);
10365 +/* ---------------------------------------------------------------------- */
10367 +const struct file_operations aufs_dir_fop = {
10368 + .owner = THIS_MODULE,
10369 + .llseek = default_llseek,
10370 + .read = generic_read_dir,
10371 + .iterate_shared = aufs_iterate_shared,
10372 + .unlocked_ioctl = aufs_ioctl_dir,
10373 +#ifdef CONFIG_COMPAT
10374 + .compat_ioctl = aufs_compat_ioctl_dir,
10376 + .open = aufs_open_dir,
10377 + .release = aufs_release_dir,
10378 + .flush = aufs_flush_dir,
10379 + .fsync = aufs_fsync_dir
10381 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10382 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10383 +++ linux/fs/aufs/dir.h 2016-10-09 16:55:36.489368218 +0200
10386 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10388 + * This program, aufs is free software; you can redistribute it and/or modify
10389 + * it under the terms of the GNU General Public License as published by
10390 + * the Free Software Foundation; either version 2 of the License, or
10391 + * (at your option) any later version.
10393 + * This program is distributed in the hope that it will be useful,
10394 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10395 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10396 + * GNU General Public License for more details.
10398 + * You should have received a copy of the GNU General Public License
10399 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10403 + * directory operations
10406 +#ifndef __AUFS_DIR_H__
10407 +#define __AUFS_DIR_H__
10411 +#include <linux/fs.h>
10413 +/* ---------------------------------------------------------------------- */
10415 +/* need to be faster and smaller */
10418 + unsigned int nh_num;
10419 + struct hlist_head *nh_head;
10422 +struct au_vdir_destr {
10423 + unsigned char len;
10424 + unsigned char name[0];
10427 +struct au_vdir_dehstr {
10428 + struct hlist_node hash;
10430 + struct au_vdir_destr *str;
10431 + struct llist_node lnode; /* delayed free */
10433 +} ____cacheline_aligned_in_smp;
10435 +struct au_vdir_de {
10437 + unsigned char de_type;
10438 + /* caution: packed */
10439 + struct au_vdir_destr de_str;
10442 +struct au_vdir_wh {
10443 + struct hlist_node wh_hash;
10444 +#ifdef CONFIG_AUFS_SHWH
10446 + aufs_bindex_t wh_bindex;
10447 + unsigned char wh_type;
10449 + aufs_bindex_t wh_bindex;
10451 + /* caution: packed */
10452 + struct au_vdir_destr wh_str;
10455 +union au_vdir_deblk_p {
10456 + unsigned char *deblk;
10457 + struct au_vdir_de *de;
10461 + unsigned char **vd_deblk;
10462 + unsigned long vd_nblk;
10464 + unsigned long ul;
10465 + union au_vdir_deblk_p p;
10468 + unsigned long vd_version;
10469 + unsigned int vd_deblk_sz;
10471 + unsigned long vd_jiffy;
10472 + struct llist_node vd_lnode; /* delayed free */
10474 +} ____cacheline_aligned_in_smp;
10476 +/* ---------------------------------------------------------------------- */
10479 +extern const struct file_operations aufs_dir_fop;
10480 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10481 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10482 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10483 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10484 +int au_test_empty_lower(struct dentry *dentry);
10485 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10488 +unsigned int au_rdhash_est(loff_t sz);
10489 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10490 +void au_nhash_wh_free(struct au_nhash *whlist);
10491 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10493 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10494 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10495 + unsigned int d_type, aufs_bindex_t bindex,
10496 + unsigned char shwh);
10497 +void au_vdir_free(struct au_vdir *vdir, int atonce);
10498 +int au_vdir_init(struct file *file);
10499 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10502 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10504 +#ifdef CONFIG_AUFS_RDU
10506 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10507 +#ifdef CONFIG_COMPAT
10508 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10509 + unsigned long arg);
10512 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10513 + unsigned int cmd, unsigned long arg)
10514 +#ifdef CONFIG_COMPAT
10515 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10516 + unsigned int cmd, unsigned long arg)
10520 +#endif /* __KERNEL__ */
10521 +#endif /* __AUFS_DIR_H__ */
10522 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10523 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10524 +++ linux/fs/aufs/dynop.c 2016-10-09 16:55:36.489368218 +0200
10527 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10529 + * This program, aufs is free software; you can redistribute it and/or modify
10530 + * it under the terms of the GNU General Public License as published by
10531 + * the Free Software Foundation; either version 2 of the License, or
10532 + * (at your option) any later version.
10534 + * This program is distributed in the hope that it will be useful,
10535 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10536 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10537 + * GNU General Public License for more details.
10539 + * You should have received a copy of the GNU General Public License
10540 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10544 + * dynamically customizable operations for regular files
10549 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10552 + * How large will these lists be?
10553 + * Usually just a few elements, 20-30 at most for each, I guess.
10555 +static struct au_sphlhead dynop[AuDyLast];
10557 +static struct au_dykey *dy_gfind_get(struct au_sphlhead *sphl, const void *h_op)
10559 + struct au_dykey *key, *tmp;
10560 + struct hlist_head *head;
10563 + head = &sphl->head;
10565 + hlist_for_each_entry_rcu(tmp, head, dk_hnode)
10566 + if (tmp->dk_op.dy_hop == h_op) {
10568 + kref_get(&key->dk_kref);
10571 + rcu_read_unlock();
10576 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10578 + struct au_dykey **k, *found;
10579 + const void *h_op = key->dk_op.dy_hop;
10583 + k = br->br_dykey;
10584 + for (i = 0; i < AuBrDynOp; i++)
10586 + if (k[i]->dk_op.dy_hop == h_op) {
10593 + spin_lock(&br->br_dykey_lock);
10594 + for (; i < AuBrDynOp; i++)
10596 + if (k[i]->dk_op.dy_hop == h_op) {
10604 + spin_unlock(&br->br_dykey_lock);
10605 + BUG_ON(i == AuBrDynOp); /* expand the array */
10611 +/* kref_get() if @key is already added */
10612 +static struct au_dykey *dy_gadd(struct au_sphlhead *sphl, struct au_dykey *key)
10614 + struct au_dykey *tmp, *found;
10615 + struct hlist_head *head;
10616 + const void *h_op = key->dk_op.dy_hop;
10619 + head = &sphl->head;
10620 + spin_lock(&sphl->spin);
10621 + hlist_for_each_entry(tmp, head, dk_hnode)
10622 + if (tmp->dk_op.dy_hop == h_op) {
10623 + kref_get(&tmp->dk_kref);
10628 + hlist_add_head_rcu(&key->dk_hnode, head);
10629 + spin_unlock(&sphl->spin);
10636 +static void dy_free_rcu(struct rcu_head *rcu)
10638 + struct au_dykey *key;
10640 + key = container_of(rcu, struct au_dykey, dk_rcu);
10642 + kfree(key); /* not delayed */
10645 +static void dy_free(struct kref *kref)
10647 + struct au_dykey *key;
10648 + struct au_sphlhead *sphl;
10650 + key = container_of(kref, struct au_dykey, dk_kref);
10651 + sphl = dynop + key->dk_op.dy_type;
10652 + au_sphl_del_rcu(&key->dk_hnode, sphl);
10653 + call_rcu(&key->dk_rcu, dy_free_rcu);
10656 +void au_dy_put(struct au_dykey *key)
10658 + kref_put(&key->dk_kref, dy_free);
10661 +/* ---------------------------------------------------------------------- */
10663 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10665 +#ifdef CONFIG_AUFS_DEBUG
10666 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10667 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10669 +#define DyDbgDeclare(cnt) do {} while (0)
10670 +#define DyDbgInc(cnt) do {} while (0)
10673 +#define DySet(func, dst, src, h_op, h_sb) do { \
10675 + if (h_op->func) { \
10677 + dst.func = src.func; \
10679 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10683 +#define DySetForce(func, dst, src) do { \
10684 + AuDebugOn(!src.func); \
10686 + dst.func = src.func; \
10689 +#define DySetAop(func) \
10690 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10691 +#define DySetAopForce(func) \
10692 + DySetForce(func, dyaop->da_op, aufs_aop)
10694 +static void dy_aop(struct au_dykey *key, const void *h_op,
10695 + struct super_block *h_sb __maybe_unused)
10697 + struct au_dyaop *dyaop = (void *)key;
10698 + const struct address_space_operations *h_aop = h_op;
10699 + DyDbgDeclare(cnt);
10701 + AuDbg("%s\n", au_sbtype(h_sb));
10703 + DySetAop(writepage);
10704 + DySetAopForce(readpage); /* force */
10705 + DySetAop(writepages);
10706 + DySetAop(set_page_dirty);
10707 + DySetAop(readpages);
10708 + DySetAop(write_begin);
10709 + DySetAop(write_end);
10711 + DySetAop(invalidatepage);
10712 + DySetAop(releasepage);
10713 + DySetAop(freepage);
10714 + /* this one will be changed according to an aufs mount option */
10715 + DySetAop(direct_IO);
10716 + DySetAop(migratepage);
10717 + DySetAop(isolate_page);
10718 + DySetAop(putback_page);
10719 + DySetAop(launder_page);
10720 + DySetAop(is_partially_uptodate);
10721 + DySetAop(is_dirty_writeback);
10722 + DySetAop(error_remove_page);
10723 + DySetAop(swap_activate);
10724 + DySetAop(swap_deactivate);
10726 + DyDbgSize(cnt, *h_aop);
10729 +/* ---------------------------------------------------------------------- */
10731 +static void dy_bug(struct kref *kref)
10736 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10738 + struct au_dykey *key, *old;
10739 + struct au_sphlhead *sphl;
10742 + void (*set)(struct au_dykey *key, const void *h_op,
10743 + struct super_block *h_sb __maybe_unused);
10745 + static const struct op a[] = {
10747 + .sz = sizeof(struct au_dyaop),
10751 + const struct op *p;
10753 + sphl = dynop + op->dy_type;
10754 + key = dy_gfind_get(sphl, op->dy_hop);
10756 + goto out_add; /* success */
10758 + p = a + op->dy_type;
10759 + key = kzalloc(p->sz, GFP_NOFS);
10760 + if (unlikely(!key)) {
10761 + key = ERR_PTR(-ENOMEM);
10765 + key->dk_op.dy_hop = op->dy_hop;
10766 + kref_init(&key->dk_kref);
10767 + p->set(key, op->dy_hop, au_br_sb(br));
10768 + old = dy_gadd(sphl, key);
10770 + au_delayed_kfree(key);
10775 + old = dy_bradd(br, key);
10777 + /* its ref-count should never be zero here */
10778 + kref_put(&key->dk_kref, dy_bug);
10783 +/* ---------------------------------------------------------------------- */
10785 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10786 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10787 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10788 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10789 + * See the aufs manual in detail.
10791 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10794 + dyaop->da_op.direct_IO = NULL;
10796 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10799 +static struct au_dyaop *dy_aget(struct au_branch *br,
10800 + const struct address_space_operations *h_aop,
10803 + struct au_dyaop *dyaop;
10804 + struct au_dynop op;
10806 + op.dy_type = AuDy_AOP;
10807 + op.dy_haop = h_aop;
10808 + dyaop = (void *)dy_get(&op, br);
10809 + if (IS_ERR(dyaop))
10811 + dy_adx(dyaop, do_dx);
10817 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10818 + struct inode *h_inode)
10821 + struct super_block *sb;
10822 + struct au_branch *br;
10823 + struct au_dyaop *dyaop;
10825 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10826 + IiMustWriteLock(inode);
10828 + sb = inode->i_sb;
10829 + br = au_sbr(sb, bindex);
10830 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10831 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10832 + err = PTR_ERR(dyaop);
10833 + if (IS_ERR(dyaop))
10834 + /* unnecessary to call dy_fput() */
10838 + inode->i_mapping->a_ops = &dyaop->da_op;
10845 + * Is it safe to replace a_ops during the inode/file is in operation?
10846 + * Yes, I hope so.
10848 +int au_dy_irefresh(struct inode *inode)
10851 + aufs_bindex_t btop;
10852 + struct inode *h_inode;
10855 + if (S_ISREG(inode->i_mode)) {
10856 + btop = au_ibtop(inode);
10857 + h_inode = au_h_iptr(inode, btop);
10858 + err = au_dy_iaop(inode, btop, h_inode);
10863 +void au_dy_arefresh(int do_dx)
10865 + struct au_sphlhead *sphl;
10866 + struct hlist_head *head;
10867 + struct au_dykey *key;
10869 + sphl = dynop + AuDy_AOP;
10870 + head = &sphl->head;
10871 + spin_lock(&sphl->spin);
10872 + hlist_for_each_entry(key, head, dk_hnode)
10873 + dy_adx((void *)key, do_dx);
10874 + spin_unlock(&sphl->spin);
10877 +/* ---------------------------------------------------------------------- */
10879 +void __init au_dy_init(void)
10883 + /* make sure that 'struct au_dykey *' can be any type */
10884 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10886 + for (i = 0; i < AuDyLast; i++)
10887 + au_sphl_init(dynop + i);
10890 +void au_dy_fin(void)
10894 + for (i = 0; i < AuDyLast; i++)
10895 + WARN_ON(!hlist_empty(&dynop[i].head));
10897 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10898 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10899 +++ linux/fs/aufs/dynop.h 2016-10-09 16:55:36.489368218 +0200
10902 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10904 + * This program, aufs is free software; you can redistribute it and/or modify
10905 + * it under the terms of the GNU General Public License as published by
10906 + * the Free Software Foundation; either version 2 of the License, or
10907 + * (at your option) any later version.
10909 + * This program is distributed in the hope that it will be useful,
10910 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10911 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10912 + * GNU General Public License for more details.
10914 + * You should have received a copy of the GNU General Public License
10915 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10919 + * dynamically customizable operations (for regular files only)
10922 +#ifndef __AUFS_DYNOP_H__
10923 +#define __AUFS_DYNOP_H__
10927 +#include <linux/fs.h>
10928 +#include <linux/kref.h>
10930 +enum {AuDy_AOP, AuDyLast};
10935 + const void *dy_hop;
10936 + const struct address_space_operations *dy_haop;
10942 + struct hlist_node dk_hnode;
10943 + struct rcu_head dk_rcu;
10945 + struct au_dynop dk_op;
10948 + * during I am in the branch local array, kref is gotten. when the
10949 + * branch is removed, kref is put.
10951 + struct kref dk_kref;
10954 +/* stop unioning since their sizes are very different from each other */
10956 + struct au_dykey da_key;
10957 + struct address_space_operations da_op; /* not const */
10960 +/* ---------------------------------------------------------------------- */
10964 +void au_dy_put(struct au_dykey *key);
10965 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10966 + struct inode *h_inode);
10967 +int au_dy_irefresh(struct inode *inode);
10968 +void au_dy_arefresh(int do_dio);
10970 +void __init au_dy_init(void);
10971 +void au_dy_fin(void);
10973 +#endif /* __KERNEL__ */
10974 +#endif /* __AUFS_DYNOP_H__ */
10975 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10976 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10977 +++ linux/fs/aufs/export.c 2016-10-09 16:55:36.489368218 +0200
10980 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10982 + * This program, aufs is free software; you can redistribute it and/or modify
10983 + * it under the terms of the GNU General Public License as published by
10984 + * the Free Software Foundation; either version 2 of the License, or
10985 + * (at your option) any later version.
10987 + * This program is distributed in the hope that it will be useful,
10988 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10989 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10990 + * GNU General Public License for more details.
10992 + * You should have received a copy of the GNU General Public License
10993 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11000 +#include <linux/exportfs.h>
11001 +#include <linux/fs_struct.h>
11002 +#include <linux/namei.h>
11003 +#include <linux/nsproxy.h>
11004 +#include <linux/random.h>
11005 +#include <linux/writeback.h>
11006 +#include "../fs/mount.h"
11010 +#ifdef CONFIG_AUFS_INO_T_64
11018 +static ino_t decode_ino(__u32 *a)
11022 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
11024 +#ifdef CONFIG_AUFS_INO_T_64
11030 +static void encode_ino(__u32 *a, ino_t ino)
11036 +#ifdef CONFIG_AUFS_INO_T_64
11041 +/* NFS file handle */
11045 +#ifdef CONFIG_AUFS_INO_T_64
11046 + /* support 64bit inode number */
11059 + Fh_ino = Fh_ino1,
11060 + Fh_dir_ino = Fh_dir_ino1
11063 +static int au_test_anon(struct dentry *dentry)
11065 + /* note: read d_flags without d_lock */
11066 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
11069 +int au_test_nfsd(void)
11072 + struct task_struct *tsk = current;
11073 + char comm[sizeof(tsk->comm)];
11076 + if (tsk->flags & PF_KTHREAD) {
11077 + get_task_comm(comm, tsk);
11078 + ret = !strcmp(comm, "nfsd");
11084 +/* ---------------------------------------------------------------------- */
11085 +/* inode generation external table */
11087 +void au_xigen_inc(struct inode *inode)
11092 + struct super_block *sb;
11093 + struct au_sbinfo *sbinfo;
11095 + sb = inode->i_sb;
11096 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
11098 + sbinfo = au_sbi(sb);
11099 + pos = inode->i_ino;
11100 + pos *= sizeof(igen);
11101 + igen = inode->i_generation + 1;
11102 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
11103 + sizeof(igen), &pos);
11104 + if (sz == sizeof(igen))
11105 + return; /* success */
11107 + if (unlikely(sz >= 0))
11108 + AuIOErr("xigen error (%zd)\n", sz);
11111 +int au_xigen_new(struct inode *inode)
11116 + struct super_block *sb;
11117 + struct au_sbinfo *sbinfo;
11118 + struct file *file;
11121 + /* todo: dirty, at mount time */
11122 + if (inode->i_ino == AUFS_ROOT_INO)
11124 + sb = inode->i_sb;
11125 + SiMustAnyLock(sb);
11126 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11130 + pos = inode->i_ino;
11131 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
11132 + AuIOErr1("too large i%lld\n", pos);
11135 + pos *= sizeof(inode->i_generation);
11138 + sbinfo = au_sbi(sb);
11139 + file = sbinfo->si_xigen;
11142 + if (vfsub_f_size_read(file)
11143 + < pos + sizeof(inode->i_generation)) {
11144 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
11145 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
11146 + sizeof(inode->i_generation), &pos);
11148 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
11149 + sizeof(inode->i_generation), &pos);
11150 + if (sz == sizeof(inode->i_generation))
11151 + goto out; /* success */
11154 + if (unlikely(sz >= 0)) {
11156 + AuIOErr("xigen error (%zd)\n", sz);
11163 +int au_xigen_set(struct super_block *sb, struct file *base)
11166 + struct au_sbinfo *sbinfo;
11167 + struct file *file;
11169 + SiMustWriteLock(sb);
11171 + sbinfo = au_sbi(sb);
11172 + file = au_xino_create2(base, sbinfo->si_xigen);
11173 + err = PTR_ERR(file);
11174 + if (IS_ERR(file))
11177 + if (sbinfo->si_xigen)
11178 + fput(sbinfo->si_xigen);
11179 + sbinfo->si_xigen = file;
11185 +void au_xigen_clr(struct super_block *sb)
11187 + struct au_sbinfo *sbinfo;
11189 + SiMustWriteLock(sb);
11191 + sbinfo = au_sbi(sb);
11192 + if (sbinfo->si_xigen) {
11193 + fput(sbinfo->si_xigen);
11194 + sbinfo->si_xigen = NULL;
11198 +/* ---------------------------------------------------------------------- */
11200 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
11203 + struct dentry *dentry, *d;
11204 + struct inode *inode;
11205 + unsigned int sigen;
11208 + inode = ilookup(sb, ino);
11212 + dentry = ERR_PTR(-ESTALE);
11213 + sigen = au_sigen(sb);
11214 + if (unlikely(au_is_bad_inode(inode)
11215 + || IS_DEADDIR(inode)
11216 + || sigen != au_iigen(inode, NULL)))
11220 + if (!dir_ino || S_ISDIR(inode->i_mode))
11221 + dentry = d_find_alias(inode);
11223 + spin_lock(&inode->i_lock);
11224 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
11225 + spin_lock(&d->d_lock);
11226 + if (!au_test_anon(d)
11227 + && d_inode(d->d_parent)->i_ino == dir_ino) {
11228 + dentry = dget_dlock(d);
11229 + spin_unlock(&d->d_lock);
11232 + spin_unlock(&d->d_lock);
11234 + spin_unlock(&inode->i_lock);
11236 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
11237 + /* need to refresh */
11245 + AuTraceErrPtr(dentry);
11249 +/* ---------------------------------------------------------------------- */
11251 +/* todo: dirty? */
11252 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
11254 +struct au_compare_mnt_args {
11256 + struct super_block *sb;
11259 + struct vfsmount *mnt;
11262 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
11264 + struct au_compare_mnt_args *a = arg;
11266 + if (mnt->mnt_sb != a->sb)
11268 + a->mnt = mntget(mnt);
11272 +static struct vfsmount *au_mnt_get(struct super_block *sb)
11275 + struct path root;
11276 + struct au_compare_mnt_args args = {
11280 + get_fs_root(current->fs, &root);
11282 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
11283 + rcu_read_unlock();
11286 + AuDebugOn(!args.mnt);
11290 +struct au_nfsd_si_lock {
11291 + unsigned int sigen;
11292 + aufs_bindex_t bindex, br_id;
11293 + unsigned char force_lock;
11296 +static int si_nfsd_read_lock(struct super_block *sb,
11297 + struct au_nfsd_si_lock *nsi_lock)
11300 + aufs_bindex_t bindex;
11302 + si_read_lock(sb, AuLock_FLUSH);
11304 + /* branch id may be wrapped around */
11306 + bindex = au_br_index(sb, nsi_lock->br_id);
11307 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11308 + goto out; /* success */
11312 + if (!nsi_lock->force_lock)
11313 + si_read_unlock(sb);
11316 + nsi_lock->bindex = bindex;
11320 +struct find_name_by_ino {
11321 + struct dir_context ctx;
11322 + int called, found;
11329 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11330 + loff_t offset, u64 ino, unsigned int d_type)
11332 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11336 + if (a->ino != ino)
11339 + memcpy(a->name, name, namelen);
11340 + a->namelen = namelen;
11345 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11346 + struct au_nfsd_si_lock *nsi_lock)
11348 + struct dentry *dentry, *parent;
11349 + struct file *file;
11350 + struct inode *dir;
11351 + struct find_name_by_ino arg = {
11353 + .actor = find_name_by_ino
11358 + parent = path->dentry;
11360 + si_read_unlock(parent->d_sb);
11361 + file = vfsub_dentry_open(path, au_dir_roflags);
11362 + dentry = (void *)file;
11363 + if (IS_ERR(file))
11366 + dentry = ERR_PTR(-ENOMEM);
11367 + arg.name = (void *)__get_free_page(GFP_NOFS);
11368 + if (unlikely(!arg.name))
11375 + err = vfsub_iterate_dir(file, &arg.ctx);
11376 + } while (!err && !arg.found && arg.called);
11377 + dentry = ERR_PTR(err);
11378 + if (unlikely(err))
11380 + /* instead of ENOENT */
11381 + dentry = ERR_PTR(-ESTALE);
11385 + /* do not call vfsub_lkup_one() */
11386 + dir = d_inode(parent);
11387 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
11388 + AuTraceErrPtr(dentry);
11389 + if (IS_ERR(dentry))
11391 + AuDebugOn(au_test_anon(dentry));
11392 + if (unlikely(d_really_is_negative(dentry))) {
11394 + dentry = ERR_PTR(-ENOENT);
11398 + au_delayed_free_page((unsigned long)arg.name);
11402 + if (unlikely(nsi_lock
11403 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11404 + if (!IS_ERR(dentry)) {
11406 + dentry = ERR_PTR(-ESTALE);
11408 + AuTraceErrPtr(dentry);
11412 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11414 + struct au_nfsd_si_lock *nsi_lock)
11416 + struct dentry *dentry;
11417 + struct path path;
11419 + if (dir_ino != AUFS_ROOT_INO) {
11420 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11421 + dentry = path.dentry;
11422 + if (!path.dentry || IS_ERR(path.dentry))
11424 + AuDebugOn(au_test_anon(path.dentry));
11426 + path.dentry = dget(sb->s_root);
11428 + path.mnt = au_mnt_get(sb);
11429 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11433 + AuTraceErrPtr(dentry);
11437 +/* ---------------------------------------------------------------------- */
11439 +static int h_acceptable(void *expv, struct dentry *dentry)
11444 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11445 + char *buf, int len, struct super_block *sb)
11449 + struct path path;
11451 + p = d_path(h_rootpath, buf, len);
11456 + path.mnt = h_rootpath->mnt;
11457 + path.dentry = h_parent;
11458 + p = d_path(&path, buf, len);
11464 + path.mnt = au_mnt_get(sb);
11465 + path.dentry = sb->s_root;
11466 + p = d_path(&path, buf, len - strlen(p));
11467 + mntput(path.mnt);
11471 + p[strlen(p)] = '/';
11474 + AuTraceErrPtr(p);
11479 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11480 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11482 + struct dentry *dentry, *h_parent, *root;
11483 + struct super_block *h_sb;
11484 + char *pathname, *p;
11485 + struct vfsmount *h_mnt;
11486 + struct au_branch *br;
11488 + struct path path;
11490 + br = au_sbr(sb, nsi_lock->bindex);
11491 + h_mnt = au_br_mnt(br);
11492 + h_sb = h_mnt->mnt_sb;
11493 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11495 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11496 + fh_len - Fh_tail, fh[Fh_h_type],
11497 + h_acceptable, /*context*/NULL);
11499 + dentry = h_parent;
11500 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11501 + AuWarn1("%s decode_fh failed, %ld\n",
11502 + au_sbtype(h_sb), PTR_ERR(h_parent));
11506 + if (unlikely(au_test_anon(h_parent))) {
11507 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11508 + au_sbtype(h_sb));
11509 + goto out_h_parent;
11512 + dentry = ERR_PTR(-ENOMEM);
11513 + pathname = (void *)__get_free_page(GFP_NOFS);
11514 + if (unlikely(!pathname))
11515 + goto out_h_parent;
11517 + root = sb->s_root;
11518 + path.mnt = h_mnt;
11519 + di_read_lock_parent(root, !AuLock_IR);
11520 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11521 + di_read_unlock(root, !AuLock_IR);
11522 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11523 + dentry = (void *)p;
11525 + goto out_pathname;
11527 + si_read_unlock(sb);
11528 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11529 + dentry = ERR_PTR(err);
11530 + if (unlikely(err))
11533 + dentry = ERR_PTR(-ENOENT);
11534 + AuDebugOn(au_test_anon(path.dentry));
11535 + if (unlikely(d_really_is_negative(path.dentry)))
11538 + if (ino != d_inode(path.dentry)->i_ino)
11539 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11541 + dentry = dget(path.dentry);
11546 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11547 + if (!IS_ERR(dentry)) {
11549 + dentry = ERR_PTR(-ESTALE);
11552 + au_delayed_free_page((unsigned long)pathname);
11556 + AuTraceErrPtr(dentry);
11560 +/* ---------------------------------------------------------------------- */
11562 +static struct dentry *
11563 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11566 + struct dentry *dentry;
11567 + __u32 *fh = fid->raw;
11568 + struct au_branch *br;
11569 + ino_t ino, dir_ino;
11570 + struct au_nfsd_si_lock nsi_lock = {
11574 + dentry = ERR_PTR(-ESTALE);
11575 + /* it should never happen, but the file handle is unreliable */
11576 + if (unlikely(fh_len < Fh_tail))
11578 + nsi_lock.sigen = fh[Fh_sigen];
11579 + nsi_lock.br_id = fh[Fh_br_id];
11581 + /* branch id may be wrapped around */
11583 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11585 + nsi_lock.force_lock = 1;
11587 + /* is this inode still cached? */
11588 + ino = decode_ino(fh + Fh_ino);
11589 + /* it should never happen */
11590 + if (unlikely(ino == AUFS_ROOT_INO))
11593 + dir_ino = decode_ino(fh + Fh_dir_ino);
11594 + dentry = decode_by_ino(sb, ino, dir_ino);
11595 + if (IS_ERR(dentry))
11600 + /* is the parent dir cached? */
11601 + br = au_sbr(sb, nsi_lock.bindex);
11603 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11604 + if (IS_ERR(dentry))
11609 + /* lookup path */
11610 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11611 + if (IS_ERR(dentry))
11613 + if (unlikely(!dentry))
11614 + /* todo?: make it ESTALE */
11618 + if (!au_digen_test(dentry, au_sigen(sb))
11619 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11620 + goto out_unlock; /* success */
11623 + dentry = ERR_PTR(-ESTALE);
11627 + si_read_unlock(sb);
11629 + AuTraceErrPtr(dentry);
11633 +#if 0 /* reserved for future use */
11634 +/* support subtreecheck option */
11635 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11636 + int fh_len, int fh_type)
11638 + struct dentry *parent;
11639 + __u32 *fh = fid->raw;
11642 + dir_ino = decode_ino(fh + Fh_dir_ino);
11643 + parent = decode_by_ino(sb, dir_ino, 0);
11644 + if (IS_ERR(parent))
11647 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11648 + dir_ino, fh, fh_len);
11651 + AuTraceErrPtr(parent);
11656 +/* ---------------------------------------------------------------------- */
11658 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11659 + struct inode *dir)
11662 + aufs_bindex_t bindex;
11663 + struct super_block *sb, *h_sb;
11664 + struct dentry *dentry, *parent, *h_parent;
11665 + struct inode *h_dir;
11666 + struct au_branch *br;
11669 + if (unlikely(*max_len <= Fh_tail)) {
11670 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11674 + err = FILEID_ROOT;
11675 + if (inode->i_ino == AUFS_ROOT_INO) {
11676 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11681 + sb = inode->i_sb;
11682 + err = si_read_lock(sb, AuLock_FLUSH);
11683 + if (unlikely(err))
11686 +#ifdef CONFIG_AUFS_DEBUG
11687 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11688 + AuWarn1("NFS-exporting requires xino\n");
11692 + ii_read_lock_child(inode);
11693 + bindex = au_ibtop(inode);
11695 + dentry = d_find_any_alias(inode);
11696 + if (unlikely(!dentry))
11698 + AuDebugOn(au_test_anon(dentry));
11699 + parent = dget_parent(dentry);
11701 + if (unlikely(!parent))
11703 + if (d_really_is_positive(parent))
11704 + dir = d_inode(parent);
11707 + ii_read_lock_parent(dir);
11708 + h_dir = au_h_iptr(dir, bindex);
11709 + ii_read_unlock(dir);
11710 + if (unlikely(!h_dir))
11712 + h_parent = d_find_any_alias(h_dir);
11713 + if (unlikely(!h_parent))
11714 + goto out_hparent;
11717 + br = au_sbr(sb, bindex);
11718 + h_sb = au_br_sb(br);
11719 + if (unlikely(!h_sb->s_export_op)) {
11720 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11721 + goto out_hparent;
11724 + fh[Fh_br_id] = br->br_id;
11725 + fh[Fh_sigen] = au_sigen(sb);
11726 + encode_ino(fh + Fh_ino, inode->i_ino);
11727 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11728 + fh[Fh_igen] = inode->i_generation;
11730 + *max_len -= Fh_tail;
11731 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11733 + /*connectable or subtreecheck*/0);
11734 + err = fh[Fh_h_type];
11735 + *max_len += Fh_tail;
11736 + /* todo: macros? */
11737 + if (err != FILEID_INVALID)
11740 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11747 + ii_read_unlock(inode);
11748 + si_read_unlock(sb);
11750 + if (unlikely(err < 0))
11751 + err = FILEID_INVALID;
11755 +/* ---------------------------------------------------------------------- */
11757 +static int aufs_commit_metadata(struct inode *inode)
11760 + aufs_bindex_t bindex;
11761 + struct super_block *sb;
11762 + struct inode *h_inode;
11763 + int (*f)(struct inode *inode);
11765 + sb = inode->i_sb;
11766 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11767 + ii_write_lock_child(inode);
11768 + bindex = au_ibtop(inode);
11769 + AuDebugOn(bindex < 0);
11770 + h_inode = au_h_iptr(inode, bindex);
11772 + f = h_inode->i_sb->s_export_op->commit_metadata;
11774 + err = f(h_inode);
11776 + struct writeback_control wbc = {
11777 + .sync_mode = WB_SYNC_ALL,
11778 + .nr_to_write = 0 /* metadata only */
11781 + err = sync_inode(h_inode, &wbc);
11784 + au_cpup_attr_timesizes(inode);
11785 + ii_write_unlock(inode);
11786 + si_read_unlock(sb);
11790 +/* ---------------------------------------------------------------------- */
11792 +static struct export_operations aufs_export_op = {
11793 + .fh_to_dentry = aufs_fh_to_dentry,
11794 + /* .fh_to_parent = aufs_fh_to_parent, */
11795 + .encode_fh = aufs_encode_fh,
11796 + .commit_metadata = aufs_commit_metadata
11799 +void au_export_init(struct super_block *sb)
11801 + struct au_sbinfo *sbinfo;
11804 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
11805 + && IS_MODULE(CONFIG_EXPORTFS),
11806 + AUFS_NAME ": unsupported configuration "
11807 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
11809 + sb->s_export_op = &aufs_export_op;
11810 + sbinfo = au_sbi(sb);
11811 + sbinfo->si_xigen = NULL;
11812 + get_random_bytes(&u, sizeof(u));
11813 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11814 + atomic_set(&sbinfo->si_xigen_next, u);
11816 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11817 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11818 +++ linux/fs/aufs/fhsm.c 2016-10-09 16:55:36.489368218 +0200
11821 + * Copyright (C) 2011-2016 Junjiro R. Okajima
11823 + * This program, aufs is free software; you can redistribute it and/or modify
11824 + * it under the terms of the GNU General Public License as published by
11825 + * the Free Software Foundation; either version 2 of the License, or
11826 + * (at your option) any later version.
11828 + * This program is distributed in the hope that it will be useful,
11829 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11830 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11831 + * GNU General Public License for more details.
11833 + * You should have received a copy of the GNU General Public License
11834 + * along with this program; if not, write to the Free Software
11835 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11839 + * File-based Hierarchy Storage Management
11842 +#include <linux/anon_inodes.h>
11843 +#include <linux/poll.h>
11844 +#include <linux/seq_file.h>
11845 +#include <linux/statfs.h>
11848 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11850 + struct au_sbinfo *sbinfo;
11851 + struct au_fhsm *fhsm;
11853 + SiMustAnyLock(sb);
11855 + sbinfo = au_sbi(sb);
11856 + fhsm = &sbinfo->si_fhsm;
11857 + AuDebugOn(!fhsm);
11858 + return fhsm->fhsm_bottom;
11861 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11863 + struct au_sbinfo *sbinfo;
11864 + struct au_fhsm *fhsm;
11866 + SiMustWriteLock(sb);
11868 + sbinfo = au_sbi(sb);
11869 + fhsm = &sbinfo->si_fhsm;
11870 + AuDebugOn(!fhsm);
11871 + fhsm->fhsm_bottom = bindex;
11874 +/* ---------------------------------------------------------------------- */
11876 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11878 + struct au_br_fhsm *bf;
11880 + bf = br->br_fhsm;
11881 + MtxMustLock(&bf->bf_lock);
11883 + return !bf->bf_readable
11884 + || time_after(jiffies,
11885 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11888 +/* ---------------------------------------------------------------------- */
11890 +static void au_fhsm_notify(struct super_block *sb, int val)
11892 + struct au_sbinfo *sbinfo;
11893 + struct au_fhsm *fhsm;
11895 + SiMustAnyLock(sb);
11897 + sbinfo = au_sbi(sb);
11898 + fhsm = &sbinfo->si_fhsm;
11899 + if (au_fhsm_pid(fhsm)
11900 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11901 + atomic_set(&fhsm->fhsm_readable, val);
11903 + wake_up(&fhsm->fhsm_wqh);
11907 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11908 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11911 + struct au_branch *br;
11912 + struct au_br_fhsm *bf;
11914 + br = au_sbr(sb, bindex);
11915 + AuDebugOn(au_br_rdonly(br));
11916 + bf = br->br_fhsm;
11920 + mutex_lock(&bf->bf_lock);
11922 + MtxMustLock(&bf->bf_lock);
11924 + /* sb->s_root for NFS is unreliable */
11925 + err = au_br_stfs(br, &bf->bf_stfs);
11926 + if (unlikely(err)) {
11927 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11931 + bf->bf_jiffy = jiffies;
11932 + bf->bf_readable = 1;
11934 + au_fhsm_notify(sb, /*val*/1);
11936 + *rstfs = bf->bf_stfs;
11940 + mutex_unlock(&bf->bf_lock);
11941 + au_fhsm_notify(sb, /*val*/1);
11946 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11949 + struct au_sbinfo *sbinfo;
11950 + struct au_fhsm *fhsm;
11951 + struct au_branch *br;
11952 + struct au_br_fhsm *bf;
11954 + AuDbg("b%d, force %d\n", bindex, force);
11955 + SiMustAnyLock(sb);
11957 + sbinfo = au_sbi(sb);
11958 + fhsm = &sbinfo->si_fhsm;
11959 + if (!au_ftest_si(sbinfo, FHSM)
11960 + || fhsm->fhsm_bottom == bindex)
11963 + br = au_sbr(sb, bindex);
11964 + bf = br->br_fhsm;
11966 + mutex_lock(&bf->bf_lock);
11968 + || au_fhsm_pid(fhsm)
11969 + || au_fhsm_test_jiffy(sbinfo, br))
11970 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11972 + mutex_unlock(&bf->bf_lock);
11975 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11977 + aufs_bindex_t bindex, bbot;
11978 + struct au_branch *br;
11980 + /* exclude the bottom */
11981 + bbot = au_fhsm_bottom(sb);
11982 + for (bindex = 0; bindex < bbot; bindex++) {
11983 + br = au_sbr(sb, bindex);
11984 + if (au_br_fhsm(br->br_perm))
11985 + au_fhsm_wrote(sb, bindex, force);
11989 +/* ---------------------------------------------------------------------- */
11991 +static unsigned int au_fhsm_poll(struct file *file,
11992 + struct poll_table_struct *wait)
11994 + unsigned int mask;
11995 + struct au_sbinfo *sbinfo;
11996 + struct au_fhsm *fhsm;
11999 + sbinfo = file->private_data;
12000 + fhsm = &sbinfo->si_fhsm;
12001 + poll_wait(file, &fhsm->fhsm_wqh, wait);
12002 + if (atomic_read(&fhsm->fhsm_readable))
12003 + mask = POLLIN /* | POLLRDNORM */;
12005 + AuTraceErr((int)mask);
12009 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
12010 + struct aufs_stfs *stfs, __s16 brid)
12014 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
12016 + err = __put_user(brid, &stbr->brid);
12017 + if (unlikely(err))
12023 +static ssize_t au_fhsm_do_read(struct super_block *sb,
12024 + struct aufs_stbr __user *stbr, size_t count)
12028 + aufs_bindex_t bindex, bbot;
12029 + struct au_branch *br;
12030 + struct au_br_fhsm *bf;
12032 + /* except the bottom branch */
12035 + bbot = au_fhsm_bottom(sb);
12036 + for (bindex = 0; !err && bindex < bbot; bindex++) {
12037 + br = au_sbr(sb, bindex);
12038 + if (!au_br_fhsm(br->br_perm))
12041 + bf = br->br_fhsm;
12042 + mutex_lock(&bf->bf_lock);
12043 + if (bf->bf_readable) {
12045 + if (count >= sizeof(*stbr))
12046 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
12049 + bf->bf_readable = 0;
12050 + count -= sizeof(*stbr);
12054 + mutex_unlock(&bf->bf_lock);
12057 + err = sizeof(*stbr) * nstbr;
12062 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
12067 + aufs_bindex_t nfhsm, bindex, bbot;
12068 + struct au_sbinfo *sbinfo;
12069 + struct au_fhsm *fhsm;
12070 + struct au_branch *br;
12071 + struct super_block *sb;
12074 + sbinfo = file->private_data;
12075 + fhsm = &sbinfo->si_fhsm;
12077 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
12078 + if (!atomic_read(&fhsm->fhsm_readable)) {
12079 + if (vfsub_file_flags(file) & O_NONBLOCK)
12082 + err = wait_event_interruptible_locked_irq
12084 + atomic_read(&fhsm->fhsm_readable));
12086 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
12087 + if (unlikely(err))
12090 + /* sb may already be dead */
12091 + au_rw_read_lock(&sbinfo->si_rwsem);
12092 + readable = atomic_read(&fhsm->fhsm_readable);
12093 + if (readable > 0) {
12094 + sb = sbinfo->si_sb;
12096 + /* exclude the bottom branch */
12098 + bbot = au_fhsm_bottom(sb);
12099 + for (bindex = 0; bindex < bbot; bindex++) {
12100 + br = au_sbr(sb, bindex);
12101 + if (au_br_fhsm(br->br_perm))
12105 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
12106 + atomic_set(&fhsm->fhsm_readable, 0);
12107 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
12111 + au_rw_read_unlock(&sbinfo->si_rwsem);
12119 +static int au_fhsm_release(struct inode *inode, struct file *file)
12121 + struct au_sbinfo *sbinfo;
12122 + struct au_fhsm *fhsm;
12124 + /* sb may already be dead */
12125 + sbinfo = file->private_data;
12126 + fhsm = &sbinfo->si_fhsm;
12127 + spin_lock(&fhsm->fhsm_spin);
12128 + fhsm->fhsm_pid = 0;
12129 + spin_unlock(&fhsm->fhsm_spin);
12130 + kobject_put(&sbinfo->si_kobj);
12135 +static const struct file_operations au_fhsm_fops = {
12136 + .owner = THIS_MODULE,
12137 + .llseek = noop_llseek,
12138 + .read = au_fhsm_read,
12139 + .poll = au_fhsm_poll,
12140 + .release = au_fhsm_release
12143 +int au_fhsm_fd(struct super_block *sb, int oflags)
12146 + struct au_sbinfo *sbinfo;
12147 + struct au_fhsm *fhsm;
12150 + if (unlikely(!capable(CAP_SYS_ADMIN)))
12154 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
12158 + sbinfo = au_sbi(sb);
12159 + fhsm = &sbinfo->si_fhsm;
12160 + spin_lock(&fhsm->fhsm_spin);
12161 + if (!fhsm->fhsm_pid)
12162 + fhsm->fhsm_pid = current->pid;
12165 + spin_unlock(&fhsm->fhsm_spin);
12166 + if (unlikely(err))
12169 + oflags |= O_RDONLY;
12170 + /* oflags |= FMODE_NONOTIFY; */
12171 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
12173 + if (unlikely(fd < 0))
12176 + /* succeed reglardless 'fhsm' status */
12177 + kobject_get(&sbinfo->si_kobj);
12178 + si_noflush_read_lock(sb);
12179 + if (au_ftest_si(sbinfo, FHSM))
12180 + au_fhsm_wrote_all(sb, /*force*/0);
12181 + si_read_unlock(sb);
12182 + goto out; /* success */
12185 + spin_lock(&fhsm->fhsm_spin);
12186 + fhsm->fhsm_pid = 0;
12187 + spin_unlock(&fhsm->fhsm_spin);
12193 +/* ---------------------------------------------------------------------- */
12195 +int au_fhsm_br_alloc(struct au_branch *br)
12200 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
12202 + au_br_fhsm_init(br->br_fhsm);
12209 +/* ---------------------------------------------------------------------- */
12211 +void au_fhsm_fin(struct super_block *sb)
12213 + au_fhsm_notify(sb, /*val*/-1);
12216 +void au_fhsm_init(struct au_sbinfo *sbinfo)
12218 + struct au_fhsm *fhsm;
12220 + fhsm = &sbinfo->si_fhsm;
12221 + spin_lock_init(&fhsm->fhsm_spin);
12222 + init_waitqueue_head(&fhsm->fhsm_wqh);
12223 + atomic_set(&fhsm->fhsm_readable, 0);
12224 + fhsm->fhsm_expire
12225 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
12226 + fhsm->fhsm_bottom = -1;
12229 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
12231 + sbinfo->si_fhsm.fhsm_expire
12232 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
12235 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
12239 + if (!au_ftest_si(sbinfo, FHSM))
12242 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
12243 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
12244 + seq_printf(seq, ",fhsm_sec=%u", u);
12246 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
12247 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
12248 +++ linux/fs/aufs/file.c 2016-10-09 16:55:38.889431135 +0200
12251 + * Copyright (C) 2005-2016 Junjiro R. Okajima
12253 + * This program, aufs is free software; you can redistribute it and/or modify
12254 + * it under the terms of the GNU General Public License as published by
12255 + * the Free Software Foundation; either version 2 of the License, or
12256 + * (at your option) any later version.
12258 + * This program is distributed in the hope that it will be useful,
12259 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12260 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12261 + * GNU General Public License for more details.
12263 + * You should have received a copy of the GNU General Public License
12264 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12268 + * handling file/dir, and address_space operation
12271 +#ifdef CONFIG_AUFS_DEBUG
12272 +#include <linux/migrate.h>
12274 +#include <linux/pagemap.h>
12277 +/* drop flags for writing */
12278 +unsigned int au_file_roflags(unsigned int flags)
12280 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12281 + flags |= O_RDONLY | O_NOATIME;
12285 +/* common functions to regular file and dir */
12286 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12287 + struct file *file, int force_wr)
12289 + struct file *h_file;
12290 + struct dentry *h_dentry;
12291 + struct inode *h_inode;
12292 + struct super_block *sb;
12293 + struct au_branch *br;
12294 + struct path h_path;
12297 + /* a race condition can happen between open and unlink/rmdir */
12298 + h_file = ERR_PTR(-ENOENT);
12299 + h_dentry = au_h_dptr(dentry, bindex);
12300 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12302 + h_inode = d_inode(h_dentry);
12303 + spin_lock(&h_dentry->d_lock);
12304 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12305 + /* || !d_inode(dentry)->i_nlink */
12307 + spin_unlock(&h_dentry->d_lock);
12308 + if (unlikely(err))
12311 + sb = dentry->d_sb;
12312 + br = au_sbr(sb, bindex);
12313 + err = au_br_test_oflag(flags, br);
12314 + h_file = ERR_PTR(err);
12315 + if (unlikely(err))
12318 + /* drop flags for writing */
12319 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12320 + if (force_wr && !(flags & O_WRONLY))
12322 + flags = au_file_roflags(flags);
12324 + h_file = ERR_PTR(-EROFS);
12325 + flags = au_file_roflags(flags);
12326 + if (unlikely(vfsub_native_ro(h_inode)
12327 + || IS_APPEND(h_inode)))
12329 + flags &= ~O_ACCMODE;
12330 + flags |= O_WRONLY;
12333 + flags &= ~O_CREAT;
12335 + h_path.dentry = h_dentry;
12336 + h_path.mnt = au_br_mnt(br);
12337 + h_file = vfsub_dentry_open(&h_path, flags);
12338 + if (IS_ERR(h_file))
12341 + if (flags & __FMODE_EXEC) {
12342 + err = deny_write_access(h_file);
12343 + if (unlikely(err)) {
12345 + h_file = ERR_PTR(err);
12349 + fsnotify_open(h_file);
12350 + goto out; /* success */
12358 +static int au_cmoo(struct dentry *dentry)
12361 + unsigned int udba;
12362 + struct path h_path;
12363 + struct au_pin pin;
12364 + struct au_cp_generic cpg = {
12365 + .dentry = dentry,
12370 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12372 + struct inode *delegated;
12373 + struct super_block *sb;
12374 + struct au_sbinfo *sbinfo;
12375 + struct au_fhsm *fhsm;
12377 + struct au_branch *br;
12378 + struct dentry *parent;
12379 + struct au_hinode *hdir;
12381 + DiMustWriteLock(dentry);
12382 + IiMustWriteLock(d_inode(dentry));
12385 + if (IS_ROOT(dentry))
12387 + cpg.bsrc = au_dbtop(dentry);
12391 + sb = dentry->d_sb;
12392 + sbinfo = au_sbi(sb);
12393 + fhsm = &sbinfo->si_fhsm;
12394 + pid = au_fhsm_pid(fhsm);
12396 + && (current->pid == pid
12397 + || current->real_parent->pid == pid))
12400 + br = au_sbr(sb, cpg.bsrc);
12401 + cmoo = au_br_cmoo(br->br_perm);
12404 + if (!d_is_reg(dentry))
12405 + cmoo &= AuBrAttr_COO_ALL;
12409 + parent = dget_parent(dentry);
12410 + di_write_lock_parent(parent);
12411 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12413 + if (unlikely(err < 0)) {
12414 + err = 0; /* there is no upper writable branch */
12417 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12419 + /* do not respect the coo attrib for the target branch */
12420 + err = au_cpup_dirs(dentry, cpg.bdst);
12421 + if (unlikely(err))
12424 + di_downgrade_lock(parent, AuLock_IR);
12425 + udba = au_opt_udba(sb);
12426 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12427 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12428 + if (unlikely(err))
12431 + err = au_sio_cpup_simple(&cpg);
12433 + if (unlikely(err))
12435 + if (!(cmoo & AuBrWAttr_MOO))
12436 + goto out_parent; /* success */
12438 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12439 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12440 + if (unlikely(err))
12443 + h_path.mnt = au_br_mnt(br);
12444 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12445 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12446 + delegated = NULL;
12447 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12449 + /* todo: keep h_dentry or not? */
12450 + if (unlikely(err == -EWOULDBLOCK)) {
12451 + pr_warn("cannot retry for NFSv4 delegation"
12452 + " for an internal unlink\n");
12455 + if (unlikely(err)) {
12456 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12460 + goto out_parent; /* success */
12463 + di_downgrade_lock(parent, AuLock_IR);
12465 + di_read_unlock(parent, AuLock_IR);
12472 +int au_do_open(struct file *file, struct au_do_open_args *args)
12474 + int err, no_lock = args->no_lock;
12475 + struct dentry *dentry;
12476 + struct au_finfo *finfo;
12479 + err = au_finfo_init(file, args->fidir);
12482 + err = au_finfo_init(file, args->fidir);
12485 + if (unlikely(err))
12488 + dentry = file->f_path.dentry;
12489 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12491 + di_write_lock_child(dentry);
12492 + err = au_cmoo(dentry);
12493 + di_downgrade_lock(dentry, AuLock_IR);
12495 + err = args->open(file, vfsub_file_flags(file), NULL);
12496 + di_read_unlock(dentry, AuLock_IR);
12498 + err = au_cmoo(dentry);
12500 + err = args->open(file, vfsub_file_flags(file),
12502 + if (!err && au_fbtop(file) != au_dbtop(dentry))
12504 + * cmoo happens after h_file was opened.
12505 + * need to refresh file later.
12507 + atomic_dec(&au_fi(file)->fi_generation);
12510 + finfo = au_fi(file);
12512 + finfo->fi_file = file;
12513 + au_sphl_add(&finfo->fi_hlist,
12514 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12517 + fi_write_unlock(file);
12520 + fi_write_unlock(file);
12523 + if (unlikely(err)) {
12524 + finfo->fi_hdir = NULL;
12525 + au_finfo_fin(file, /*atonce*/0);
12532 +int au_reopen_nondir(struct file *file)
12535 + aufs_bindex_t btop;
12536 + struct dentry *dentry;
12537 + struct file *h_file, *h_file_tmp;
12539 + dentry = file->f_path.dentry;
12540 + btop = au_dbtop(dentry);
12541 + h_file_tmp = NULL;
12542 + if (au_fbtop(file) == btop) {
12543 + h_file = au_hf_top(file);
12544 + if (file->f_mode == h_file->f_mode)
12545 + return 0; /* success */
12546 + h_file_tmp = h_file;
12547 + get_file(h_file_tmp);
12548 + au_set_h_fptr(file, btop, NULL);
12550 + AuDebugOn(au_fi(file)->fi_hdir);
12553 + * file exists on both of rw and ro
12554 + * open --> dbtop and fbtop are both 0
12555 + * prepend a branch as rw, "rw" become ro
12557 + * delete the top branch, "rw" becomes rw again
12558 + * --> dbtop is 1, fbtop is still 0
12559 + * write --> fbtop is 0 but dbtop is 1
12561 + /* AuDebugOn(au_fbtop(file) < btop); */
12563 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
12564 + file, /*force_wr*/0);
12565 + err = PTR_ERR(h_file);
12566 + if (IS_ERR(h_file)) {
12567 + if (h_file_tmp) {
12568 + au_sbr_get(dentry->d_sb, btop);
12569 + au_set_h_fptr(file, btop, h_file_tmp);
12570 + h_file_tmp = NULL;
12572 + goto out; /* todo: close all? */
12576 + au_set_fbtop(file, btop);
12577 + au_set_h_fptr(file, btop, h_file);
12578 + au_update_figen(file);
12579 + /* todo: necessary? */
12580 + /* file->f_ra = h_file->f_ra; */
12584 + fput(h_file_tmp);
12588 +/* ---------------------------------------------------------------------- */
12590 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12591 + struct dentry *hi_wh)
12594 + aufs_bindex_t btop;
12595 + struct au_dinfo *dinfo;
12596 + struct dentry *h_dentry;
12597 + struct au_hdentry *hdp;
12599 + dinfo = au_di(file->f_path.dentry);
12600 + AuRwMustWriteLock(&dinfo->di_rwsem);
12602 + btop = dinfo->di_btop;
12603 + dinfo->di_btop = btgt;
12604 + hdp = au_hdentry(dinfo, btgt);
12605 + h_dentry = hdp->hd_dentry;
12606 + hdp->hd_dentry = hi_wh;
12607 + err = au_reopen_nondir(file);
12608 + hdp->hd_dentry = h_dentry;
12609 + dinfo->di_btop = btop;
12614 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12615 + aufs_bindex_t bcpup, struct au_pin *pin)
12618 + struct inode *inode, *h_inode;
12619 + struct dentry *h_dentry, *hi_wh;
12620 + struct au_cp_generic cpg = {
12621 + .dentry = file->f_path.dentry,
12628 + au_update_dbtop(cpg.dentry);
12629 + inode = d_inode(cpg.dentry);
12631 + if (au_dbtop(cpg.dentry) <= bcpup
12632 + && au_dbbot(cpg.dentry) >= bcpup) {
12633 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12634 + if (h_dentry && d_is_positive(h_dentry))
12635 + h_inode = d_inode(h_dentry);
12637 + hi_wh = au_hi_wh(inode, bcpup);
12638 + if (!hi_wh && !h_inode)
12639 + err = au_sio_cpup_wh(&cpg, file);
12641 + /* already copied-up after unlink */
12642 + err = au_reopen_wh(file, bcpup, hi_wh);
12645 + && (inode->i_nlink > 1
12646 + || (inode->i_state & I_LINKABLE))
12647 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12648 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12654 + * prepare the @file for writing.
12656 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12659 + aufs_bindex_t dbtop;
12660 + struct dentry *parent;
12661 + struct inode *inode;
12662 + struct super_block *sb;
12663 + struct file *h_file;
12664 + struct au_cp_generic cpg = {
12665 + .dentry = file->f_path.dentry,
12670 + .flags = AuCpup_DTIME
12673 + sb = cpg.dentry->d_sb;
12674 + inode = d_inode(cpg.dentry);
12675 + cpg.bsrc = au_fbtop(file);
12676 + err = au_test_ro(sb, cpg.bsrc, inode);
12677 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12678 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12683 + /* need to cpup or reopen */
12684 + parent = dget_parent(cpg.dentry);
12685 + di_write_lock_parent(parent);
12686 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12688 + if (unlikely(err < 0))
12692 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12693 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12694 + if (unlikely(err))
12698 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12699 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12700 + if (unlikely(err))
12703 + dbtop = au_dbtop(cpg.dentry);
12704 + if (dbtop <= cpg.bdst)
12705 + cpg.bsrc = cpg.bdst;
12707 + if (dbtop <= cpg.bdst /* just reopen */
12708 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12710 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12711 + if (IS_ERR(h_file))
12712 + err = PTR_ERR(h_file);
12714 + di_downgrade_lock(parent, AuLock_IR);
12715 + if (dbtop > cpg.bdst)
12716 + err = au_sio_cpup_simple(&cpg);
12718 + err = au_reopen_nondir(file);
12719 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12721 + } else { /* copyup as wh and reopen */
12723 + * since writable hfsplus branch is not supported,
12724 + * h_open_pre/post() are unnecessary.
12726 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12727 + di_downgrade_lock(parent, AuLock_IR);
12731 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12732 + goto out_dput; /* success */
12738 + di_downgrade_lock(parent, AuLock_IR);
12740 + di_read_unlock(parent, AuLock_IR);
12747 +/* ---------------------------------------------------------------------- */
12749 +int au_do_flush(struct file *file, fl_owner_t id,
12750 + int (*flush)(struct file *file, fl_owner_t id))
12753 + struct super_block *sb;
12754 + struct inode *inode;
12756 + inode = file_inode(file);
12757 + sb = inode->i_sb;
12758 + si_noflush_read_lock(sb);
12759 + fi_read_lock(file);
12760 + ii_read_lock_child(inode);
12762 + err = flush(file, id);
12763 + au_cpup_attr_timesizes(inode);
12765 + ii_read_unlock(inode);
12766 + fi_read_unlock(file);
12767 + si_read_unlock(sb);
12771 +/* ---------------------------------------------------------------------- */
12773 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12776 + struct au_pin pin;
12777 + struct au_finfo *finfo;
12778 + struct dentry *parent, *hi_wh;
12779 + struct inode *inode;
12780 + struct super_block *sb;
12781 + struct au_cp_generic cpg = {
12782 + .dentry = file->f_path.dentry,
12787 + .flags = AuCpup_DTIME
12790 + FiMustWriteLock(file);
12793 + finfo = au_fi(file);
12794 + sb = cpg.dentry->d_sb;
12795 + inode = d_inode(cpg.dentry);
12796 + cpg.bdst = au_ibtop(inode);
12797 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12800 + parent = dget_parent(cpg.dentry);
12801 + if (au_test_ro(sb, cpg.bdst, inode)) {
12802 + di_read_lock_parent(parent, !AuLock_IR);
12803 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12805 + di_read_unlock(parent, !AuLock_IR);
12806 + if (unlikely(err < 0))
12811 + di_read_lock_parent(parent, AuLock_IR);
12812 + hi_wh = au_hi_wh(inode, cpg.bdst);
12813 + if (!S_ISDIR(inode->i_mode)
12814 + && au_opt_test(au_mntflags(sb), PLINK)
12815 + && au_plink_test(inode)
12816 + && !d_unhashed(cpg.dentry)
12817 + && cpg.bdst < au_dbtop(cpg.dentry)) {
12818 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12819 + if (unlikely(err))
12822 + /* always superio. */
12823 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12824 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12826 + err = au_sio_cpup_simple(&cpg);
12829 + } else if (hi_wh) {
12830 + /* already copied-up after unlink */
12831 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12832 + *need_reopen = 0;
12836 + di_read_unlock(parent, AuLock_IR);
12843 +static void au_do_refresh_dir(struct file *file)
12846 + aufs_bindex_t bindex, bbot, new_bindex, brid;
12847 + struct au_hfile *p, tmp, *q;
12848 + struct au_finfo *finfo;
12849 + struct super_block *sb;
12850 + struct au_fidir *fidir;
12852 + FiMustWriteLock(file);
12854 + sb = file->f_path.dentry->d_sb;
12855 + finfo = au_fi(file);
12856 + fidir = finfo->fi_hdir;
12857 + AuDebugOn(!fidir);
12858 + p = fidir->fd_hfile + finfo->fi_btop;
12859 + brid = p->hf_br->br_id;
12860 + bbot = fidir->fd_bbot;
12861 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
12865 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12866 + if (new_bindex == bindex)
12868 + if (new_bindex < 0) {
12869 + au_set_h_fptr(file, bindex, NULL);
12873 + /* swap two lower inode, and loop again */
12874 + q = fidir->fd_hfile + new_bindex;
12878 + if (tmp.hf_file) {
12884 + execed = vfsub_file_execed(file);
12885 + p = fidir->fd_hfile;
12886 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12887 + bbot = au_sbbot(sb);
12888 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
12889 + finfo->fi_btop++, p++)
12890 + if (p->hf_file) {
12891 + if (file_inode(p->hf_file))
12893 + au_hfput(p, execed);
12896 + bbot = au_br_index(sb, brid);
12897 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
12898 + finfo->fi_btop++, p++)
12900 + au_hfput(p, execed);
12901 + bbot = au_sbbot(sb);
12904 + p = fidir->fd_hfile + bbot;
12905 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
12906 + fidir->fd_bbot--, p--)
12907 + if (p->hf_file) {
12908 + if (file_inode(p->hf_file))
12910 + au_hfput(p, execed);
12912 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12916 + * after branch manipulating, refresh the file.
12918 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12920 + int err, need_reopen, nbr;
12921 + aufs_bindex_t bbot, bindex;
12922 + struct dentry *dentry;
12923 + struct super_block *sb;
12924 + struct au_finfo *finfo;
12925 + struct au_hfile *hfile;
12927 + dentry = file->f_path.dentry;
12928 + sb = dentry->d_sb;
12929 + nbr = au_sbbot(sb) + 1;
12930 + finfo = au_fi(file);
12931 + if (!finfo->fi_hdir) {
12932 + hfile = &finfo->fi_htop;
12933 + AuDebugOn(!hfile->hf_file);
12934 + bindex = au_br_index(sb, hfile->hf_br->br_id);
12935 + AuDebugOn(bindex < 0);
12936 + if (bindex != finfo->fi_btop)
12937 + au_set_fbtop(file, bindex);
12939 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
12940 + if (unlikely(err))
12942 + au_do_refresh_dir(file);
12947 + if (!au_test_mmapped(file))
12948 + err = au_file_refresh_by_inode(file, &need_reopen);
12949 + if (finfo->fi_hdir)
12950 + /* harmless if err */
12951 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
12952 + if (!err && need_reopen && !d_unlinked(dentry))
12953 + err = reopen(file);
12955 + au_update_figen(file);
12956 + goto out; /* success */
12959 + /* error, close all lower files */
12960 + if (finfo->fi_hdir) {
12961 + bbot = au_fbbot_dir(file);
12962 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
12963 + au_set_h_fptr(file, bindex, NULL);
12970 +/* common function to regular file and dir */
12971 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12975 + unsigned int sigen, figen;
12976 + aufs_bindex_t btop;
12977 + unsigned char pseudo_link;
12978 + struct dentry *dentry;
12979 + struct inode *inode;
12982 + dentry = file->f_path.dentry;
12983 + inode = d_inode(dentry);
12984 + sigen = au_sigen(dentry->d_sb);
12985 + fi_write_lock(file);
12986 + figen = au_figen(file);
12987 + di_write_lock_child(dentry);
12988 + btop = au_dbtop(dentry);
12989 + pseudo_link = (btop != au_ibtop(inode));
12990 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
12992 + di_downgrade_lock(dentry, AuLock_IR);
12993 + fi_downgrade_lock(file);
12995 + goto out; /* success */
12998 + AuDbg("sigen %d, figen %d\n", sigen, figen);
12999 + if (au_digen_test(dentry, sigen)) {
13000 + err = au_reval_dpath(dentry, sigen);
13001 + AuDebugOn(!err && au_digen_test(dentry, sigen));
13005 + err = refresh_file(file, reopen);
13008 + di_downgrade_lock(dentry, AuLock_IR);
13009 + fi_downgrade_lock(file);
13012 + di_write_unlock(dentry);
13013 + fi_write_unlock(file);
13020 +/* ---------------------------------------------------------------------- */
13022 +/* cf. aufs_nopage() */
13023 +/* for madvise(2) */
13024 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
13026 + unlock_page(page);
13030 +/* it will never be called, but necessary to support O_DIRECT */
13031 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
13032 +{ BUG(); return 0; }
13034 +/* they will never be called. */
13035 +#ifdef CONFIG_AUFS_DEBUG
13036 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
13037 + loff_t pos, unsigned len, unsigned flags,
13038 + struct page **pagep, void **fsdata)
13039 +{ AuUnsupport(); return 0; }
13040 +static int aufs_write_end(struct file *file, struct address_space *mapping,
13041 + loff_t pos, unsigned len, unsigned copied,
13042 + struct page *page, void *fsdata)
13043 +{ AuUnsupport(); return 0; }
13044 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
13045 +{ AuUnsupport(); return 0; }
13047 +static int aufs_set_page_dirty(struct page *page)
13048 +{ AuUnsupport(); return 0; }
13049 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
13050 + unsigned int length)
13051 +{ AuUnsupport(); }
13052 +static int aufs_releasepage(struct page *page, gfp_t gfp)
13053 +{ AuUnsupport(); return 0; }
13054 +#if 0 /* called by memory compaction regardless file */
13055 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
13056 + struct page *page, enum migrate_mode mode)
13057 +{ AuUnsupport(); return 0; }
13059 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
13060 +{ AuUnsupport(); return true; }
13061 +static void aufs_putback_page(struct page *page)
13062 +{ AuUnsupport(); }
13063 +static int aufs_launder_page(struct page *page)
13064 +{ AuUnsupport(); return 0; }
13065 +static int aufs_is_partially_uptodate(struct page *page,
13066 + unsigned long from,
13067 + unsigned long count)
13068 +{ AuUnsupport(); return 0; }
13069 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
13071 +{ AuUnsupport(); }
13072 +static int aufs_error_remove_page(struct address_space *mapping,
13073 + struct page *page)
13074 +{ AuUnsupport(); return 0; }
13075 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
13077 +{ AuUnsupport(); return 0; }
13078 +static void aufs_swap_deactivate(struct file *file)
13079 +{ AuUnsupport(); }
13080 +#endif /* CONFIG_AUFS_DEBUG */
13082 +const struct address_space_operations aufs_aop = {
13083 + .readpage = aufs_readpage,
13084 + .direct_IO = aufs_direct_IO,
13085 +#ifdef CONFIG_AUFS_DEBUG
13086 + .writepage = aufs_writepage,
13087 + /* no writepages, because of writepage */
13088 + .set_page_dirty = aufs_set_page_dirty,
13089 + /* no readpages, because of readpage */
13090 + .write_begin = aufs_write_begin,
13091 + .write_end = aufs_write_end,
13092 + /* no bmap, no block device */
13093 + .invalidatepage = aufs_invalidatepage,
13094 + .releasepage = aufs_releasepage,
13095 + /* is fallback_migrate_page ok? */
13096 + /* .migratepage = aufs_migratepage, */
13097 + .isolate_page = aufs_isolate_page,
13098 + .putback_page = aufs_putback_page,
13099 + .launder_page = aufs_launder_page,
13100 + .is_partially_uptodate = aufs_is_partially_uptodate,
13101 + .is_dirty_writeback = aufs_is_dirty_writeback,
13102 + .error_remove_page = aufs_error_remove_page,
13103 + .swap_activate = aufs_swap_activate,
13104 + .swap_deactivate = aufs_swap_deactivate
13105 +#endif /* CONFIG_AUFS_DEBUG */
13107 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
13108 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
13109 +++ linux/fs/aufs/file.h 2016-10-09 16:55:38.889431135 +0200
13112 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13114 + * This program, aufs is free software; you can redistribute it and/or modify
13115 + * it under the terms of the GNU General Public License as published by
13116 + * the Free Software Foundation; either version 2 of the License, or
13117 + * (at your option) any later version.
13119 + * This program is distributed in the hope that it will be useful,
13120 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13121 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13122 + * GNU General Public License for more details.
13124 + * You should have received a copy of the GNU General Public License
13125 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13129 + * file operations
13132 +#ifndef __AUFS_FILE_H__
13133 +#define __AUFS_FILE_H__
13137 +#include <linux/file.h>
13138 +#include <linux/fs.h>
13139 +#include <linux/poll.h>
13140 +#include "rwsem.h"
13144 + struct file *hf_file;
13145 + struct au_branch *hf_br;
13150 + aufs_bindex_t fd_bbot;
13151 + aufs_bindex_t fd_nent;
13152 + struct au_vdir *fd_vdir_cache;
13153 + struct au_hfile fd_hfile[];
13156 +static inline int au_fidir_sz(int nent)
13158 + AuDebugOn(nent < 0);
13159 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
13163 + atomic_t fi_generation;
13165 + struct au_rwsem fi_rwsem;
13166 + aufs_bindex_t fi_btop;
13168 + /* do not union them */
13169 + struct { /* for non-dir */
13170 + struct au_hfile fi_htop;
13171 + atomic_t fi_mmapped;
13173 + struct au_fidir *fi_hdir; /* for dir only */
13175 + struct hlist_node fi_hlist;
13177 + struct file *fi_file; /* very ugly */
13178 + struct llist_node fi_lnode; /* delayed free */
13180 +} ____cacheline_aligned_in_smp;
13182 +/* ---------------------------------------------------------------------- */
13185 +extern const struct address_space_operations aufs_aop;
13186 +unsigned int au_file_roflags(unsigned int flags);
13187 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
13188 + struct file *file, int force_wr);
13189 +struct au_do_open_args {
13191 + int (*open)(struct file *file, int flags,
13192 + struct file *h_file);
13193 + struct au_fidir *fidir;
13194 + struct file *h_file;
13196 +int au_do_open(struct file *file, struct au_do_open_args *args);
13197 +int au_reopen_nondir(struct file *file);
13199 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
13200 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13202 +int au_do_flush(struct file *file, fl_owner_t id,
13203 + int (*flush)(struct file *file, fl_owner_t id));
13206 +#ifdef CONFIG_AUFS_POLL
13207 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13210 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13212 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13214 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13215 + struct file *h_file);
13217 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13218 + aufs_bindex_t bindex, int force_wr)
13219 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13220 + struct file *h_file);
13224 +extern const struct file_operations aufs_file_fop;
13225 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13226 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13227 +struct file *au_read_pre(struct file *file, int keep_fi);
13230 +void au_hfput(struct au_hfile *hf, int execed);
13231 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13232 + struct file *h_file);
13234 +void au_update_figen(struct file *file);
13235 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13236 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
13238 +void au_fi_init_once(void *_fi);
13239 +void au_finfo_fin(struct file *file, int atonce);
13240 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13243 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13244 +#ifdef CONFIG_COMPAT
13245 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13246 + unsigned long arg);
13247 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13248 + unsigned long arg);
13251 +/* ---------------------------------------------------------------------- */
13253 +static inline struct au_finfo *au_fi(struct file *file)
13255 + return file->private_data;
13258 +/* ---------------------------------------------------------------------- */
13261 + * fi_read_lock, fi_write_lock,
13262 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13264 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13266 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13267 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13268 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13270 +/* ---------------------------------------------------------------------- */
13272 +/* todo: hard/soft set? */
13273 +static inline aufs_bindex_t au_fbtop(struct file *file)
13275 + FiMustAnyLock(file);
13276 + return au_fi(file)->fi_btop;
13279 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
13281 + FiMustAnyLock(file);
13282 + AuDebugOn(!au_fi(file)->fi_hdir);
13283 + return au_fi(file)->fi_hdir->fd_bbot;
13286 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13288 + FiMustAnyLock(file);
13289 + AuDebugOn(!au_fi(file)->fi_hdir);
13290 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13293 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
13295 + FiMustWriteLock(file);
13296 + au_fi(file)->fi_btop = bindex;
13299 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
13301 + FiMustWriteLock(file);
13302 + AuDebugOn(!au_fi(file)->fi_hdir);
13303 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13306 +static inline void au_set_fvdir_cache(struct file *file,
13307 + struct au_vdir *vdir_cache)
13309 + FiMustWriteLock(file);
13310 + AuDebugOn(!au_fi(file)->fi_hdir);
13311 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13314 +static inline struct file *au_hf_top(struct file *file)
13316 + FiMustAnyLock(file);
13317 + AuDebugOn(au_fi(file)->fi_hdir);
13318 + return au_fi(file)->fi_htop.hf_file;
13321 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13323 + FiMustAnyLock(file);
13324 + AuDebugOn(!au_fi(file)->fi_hdir);
13325 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13328 +/* todo: memory barrier? */
13329 +static inline unsigned int au_figen(struct file *f)
13331 + return atomic_read(&au_fi(f)->fi_generation);
13334 +static inline void au_set_mmapped(struct file *f)
13336 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13338 + pr_warn("fi_mmapped wrapped around\n");
13339 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13343 +static inline void au_unset_mmapped(struct file *f)
13345 + atomic_dec(&au_fi(f)->fi_mmapped);
13348 +static inline int au_test_mmapped(struct file *f)
13350 + return atomic_read(&au_fi(f)->fi_mmapped);
13353 +/* customize vma->vm_file */
13355 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13356 + struct file *file)
13360 + f = vma->vm_file;
13362 + vma->vm_file = file;
13367 +#define AuDbgVmRegion(file, vma) do {} while (0)
13369 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13370 + struct file *file)
13372 + au_do_vm_file_reset(vma, file);
13375 +#define AuDbgVmRegion(file, vma) \
13376 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13378 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13379 + struct file *file)
13383 + au_do_vm_file_reset(vma, file);
13384 + f = vma->vm_region->vm_file;
13386 + vma->vm_region->vm_file = file;
13389 +#endif /* CONFIG_MMU */
13391 +/* handle vma->vm_prfile */
13392 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13393 + struct file *file)
13396 + vma->vm_prfile = file;
13397 +#ifndef CONFIG_MMU
13399 + vma->vm_region->vm_prfile = file;
13403 +#endif /* __KERNEL__ */
13404 +#endif /* __AUFS_FILE_H__ */
13405 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13406 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13407 +++ linux/fs/aufs/finfo.c 2016-10-09 16:55:38.889431135 +0200
13410 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13412 + * This program, aufs is free software; you can redistribute it and/or modify
13413 + * it under the terms of the GNU General Public License as published by
13414 + * the Free Software Foundation; either version 2 of the License, or
13415 + * (at your option) any later version.
13417 + * This program is distributed in the hope that it will be useful,
13418 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13419 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13420 + * GNU General Public License for more details.
13422 + * You should have received a copy of the GNU General Public License
13423 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13427 + * file private data
13432 +void au_hfput(struct au_hfile *hf, int execed)
13435 + allow_write_access(hf->hf_file);
13436 + fput(hf->hf_file);
13437 + hf->hf_file = NULL;
13438 + au_br_put(hf->hf_br);
13439 + hf->hf_br = NULL;
13442 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13444 + struct au_finfo *finfo = au_fi(file);
13445 + struct au_hfile *hf;
13446 + struct au_fidir *fidir;
13448 + fidir = finfo->fi_hdir;
13450 + AuDebugOn(finfo->fi_btop != bindex);
13451 + hf = &finfo->fi_htop;
13453 + hf = fidir->fd_hfile + bindex;
13455 + if (hf && hf->hf_file)
13456 + au_hfput(hf, vfsub_file_execed(file));
13458 + FiMustWriteLock(file);
13459 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13460 + hf->hf_file = val;
13461 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13465 +void au_update_figen(struct file *file)
13467 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13468 + /* smp_mb(); */ /* atomic_set */
13471 +/* ---------------------------------------------------------------------- */
13473 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13475 + struct au_fidir *fidir;
13478 + nbr = au_sbbot(sb) + 1;
13480 + nbr = 2; /* initial allocate for 2 branches */
13481 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13483 + fidir->fd_bbot = -1;
13484 + fidir->fd_nent = nbr;
13490 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
13493 + struct au_fidir *fidir, *p;
13495 + AuRwMustWriteLock(&finfo->fi_rwsem);
13496 + fidir = finfo->fi_hdir;
13497 + AuDebugOn(!fidir);
13500 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13501 + GFP_NOFS, may_shrink);
13503 + p->fd_nent = nbr;
13504 + finfo->fi_hdir = p;
13511 +/* ---------------------------------------------------------------------- */
13513 +void au_finfo_fin(struct file *file, int atonce)
13515 + struct au_finfo *finfo;
13517 + au_nfiles_dec(file->f_path.dentry->d_sb);
13519 + finfo = au_fi(file);
13520 + AuDebugOn(finfo->fi_hdir);
13521 + AuRwDestroy(&finfo->fi_rwsem);
13523 + au_cache_dfree_finfo(finfo);
13525 + au_cache_free_finfo(finfo);
13528 +void au_fi_init_once(void *_finfo)
13530 + struct au_finfo *finfo = _finfo;
13532 + au_rw_init(&finfo->fi_rwsem);
13535 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13538 + struct au_finfo *finfo;
13539 + struct dentry *dentry;
13542 + dentry = file->f_path.dentry;
13543 + finfo = au_cache_alloc_finfo();
13544 + if (unlikely(!finfo))
13548 + au_nfiles_inc(dentry->d_sb);
13549 + au_rw_write_lock(&finfo->fi_rwsem);
13550 + finfo->fi_btop = -1;
13551 + finfo->fi_hdir = fidir;
13552 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13553 + /* smp_mb(); */ /* atomic_set */
13555 + file->private_data = finfo;
13560 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13561 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13562 +++ linux/fs/aufs/f_op.c 2016-10-09 16:55:36.489368218 +0200
13565 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13567 + * This program, aufs is free software; you can redistribute it and/or modify
13568 + * it under the terms of the GNU General Public License as published by
13569 + * the Free Software Foundation; either version 2 of the License, or
13570 + * (at your option) any later version.
13572 + * This program is distributed in the hope that it will be useful,
13573 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13574 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13575 + * GNU General Public License for more details.
13577 + * You should have received a copy of the GNU General Public License
13578 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13582 + * file and vm operations
13585 +#include <linux/aio.h>
13586 +#include <linux/fs_stack.h>
13587 +#include <linux/mman.h>
13588 +#include <linux/security.h>
13591 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13594 + aufs_bindex_t bindex;
13595 + struct dentry *dentry, *h_dentry;
13596 + struct au_finfo *finfo;
13597 + struct inode *h_inode;
13599 + FiMustWriteLock(file);
13602 + dentry = file->f_path.dentry;
13603 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13604 + finfo = au_fi(file);
13605 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13606 + atomic_set(&finfo->fi_mmapped, 0);
13607 + bindex = au_dbtop(dentry);
13609 + h_dentry = au_h_dptr(dentry, bindex);
13610 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13611 + if (unlikely(err))
13613 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13615 + h_dentry = h_file->f_path.dentry;
13616 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13617 + if (unlikely(err))
13619 + get_file(h_file);
13621 + if (IS_ERR(h_file))
13622 + err = PTR_ERR(h_file);
13624 + if ((flags & __O_TMPFILE)
13625 + && !(flags & O_EXCL)) {
13626 + h_inode = file_inode(h_file);
13627 + spin_lock(&h_inode->i_lock);
13628 + h_inode->i_state |= I_LINKABLE;
13629 + spin_unlock(&h_inode->i_lock);
13631 + au_set_fbtop(file, bindex);
13632 + au_set_h_fptr(file, bindex, h_file);
13633 + au_update_figen(file);
13634 + /* todo: necessary? */
13635 + /* file->f_ra = h_file->f_ra; */
13642 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13643 + struct file *file)
13646 + struct super_block *sb;
13647 + struct au_do_open_args args = {
13648 + .open = au_do_open_nondir
13651 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13652 + file, vfsub_file_flags(file), file->f_mode);
13654 + sb = file->f_path.dentry->d_sb;
13655 + si_read_lock(sb, AuLock_FLUSH);
13656 + err = au_do_open(file, &args);
13657 + si_read_unlock(sb);
13661 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13663 + struct au_finfo *finfo;
13664 + aufs_bindex_t bindex;
13667 + finfo = au_fi(file);
13668 + au_sphl_del(&finfo->fi_hlist,
13669 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13670 + bindex = finfo->fi_btop;
13672 + au_set_h_fptr(file, bindex, NULL);
13674 + delayed = (current->flags & PF_KTHREAD) || in_interrupt();
13675 + au_finfo_fin(file, delayed);
13679 +/* ---------------------------------------------------------------------- */
13681 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13684 + struct file *h_file;
13687 + h_file = au_hf_top(file);
13689 + err = vfsub_flush(h_file, id);
13693 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13695 + return au_do_flush(file, id, au_do_flush_nondir);
13698 +/* ---------------------------------------------------------------------- */
13700 + * read and write functions acquire [fdi]_rwsem once, but release before
13701 + * mmap_sem. This is because to stop a race condition between mmap(2).
13702 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13703 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13704 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13707 +/* Callers should call au_read_post() or fput() in the end */
13708 +struct file *au_read_pre(struct file *file, int keep_fi)
13710 + struct file *h_file;
13713 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13715 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13716 + h_file = au_hf_top(file);
13717 + get_file(h_file);
13719 + fi_read_unlock(file);
13721 + h_file = ERR_PTR(err);
13726 +static void au_read_post(struct inode *inode, struct file *h_file)
13728 + /* update without lock, I don't think it a problem */
13729 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13733 +struct au_write_pre {
13735 + aufs_bindex_t btop;
13739 + * return with iinfo is write-locked
13740 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13743 +static struct file *au_write_pre(struct file *file, int do_ready,
13744 + struct au_write_pre *wpre)
13746 + struct file *h_file;
13747 + struct dentry *dentry;
13749 + struct au_pin pin;
13751 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13752 + h_file = ERR_PTR(err);
13753 + if (unlikely(err))
13756 + dentry = file->f_path.dentry;
13758 + err = au_ready_to_write(file, -1, &pin);
13759 + if (unlikely(err)) {
13760 + h_file = ERR_PTR(err);
13761 + di_write_unlock(dentry);
13766 + di_downgrade_lock(dentry, /*flags*/0);
13768 + wpre->btop = au_fbtop(file);
13769 + h_file = au_hf_top(file);
13770 + get_file(h_file);
13772 + wpre->blks = file_inode(h_file)->i_blocks;
13775 + di_read_unlock(dentry, /*flags*/0);
13778 + fi_write_unlock(file);
13783 +static void au_write_post(struct inode *inode, struct file *h_file,
13784 + struct au_write_pre *wpre, ssize_t written)
13786 + struct inode *h_inode;
13788 + au_cpup_attr_timesizes(inode);
13789 + AuDebugOn(au_ibtop(inode) != wpre->btop);
13790 + h_inode = file_inode(h_file);
13791 + inode->i_mode = h_inode->i_mode;
13792 + ii_write_unlock(inode);
13795 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13797 + au_fhsm_wrote(inode->i_sb, wpre->btop,
13798 + /*force*/h_inode->i_blocks > wpre->blks);
13801 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13805 + struct inode *inode;
13806 + struct file *h_file;
13807 + struct super_block *sb;
13809 + inode = file_inode(file);
13810 + sb = inode->i_sb;
13811 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13813 + h_file = au_read_pre(file, /*keep_fi*/0);
13814 + err = PTR_ERR(h_file);
13815 + if (IS_ERR(h_file))
13818 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13819 + err = vfsub_read_u(h_file, buf, count, ppos);
13820 + /* todo: necessary? */
13821 + /* file->f_ra = h_file->f_ra; */
13822 + au_read_post(inode, h_file);
13825 + si_read_unlock(sb);
13830 + * todo: very ugly
13831 + * it locks both of i_mutex and si_rwsem for read in safe.
13832 + * if the plink maintenance mode continues forever (that is the problem),
13833 + * may loop forever.
13835 +static void au_mtx_and_read_lock(struct inode *inode)
13838 + struct super_block *sb = inode->i_sb;
13841 + inode_lock(inode);
13842 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13845 + inode_unlock(inode);
13846 + si_read_lock(sb, AuLock_NOPLMW);
13847 + si_read_unlock(sb);
13851 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13852 + size_t count, loff_t *ppos)
13855 + struct au_write_pre wpre;
13856 + struct inode *inode;
13857 + struct file *h_file;
13858 + char __user *buf = (char __user *)ubuf;
13860 + inode = file_inode(file);
13861 + au_mtx_and_read_lock(inode);
13863 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13864 + err = PTR_ERR(h_file);
13865 + if (IS_ERR(h_file))
13868 + err = vfsub_write_u(h_file, buf, count, ppos);
13869 + au_write_post(inode, h_file, &wpre, err);
13872 + si_read_unlock(inode->i_sb);
13873 + inode_unlock(inode);
13877 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13878 + struct iov_iter *iov_iter)
13881 + struct file *file;
13882 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13884 + err = security_file_permission(h_file, rw);
13885 + if (unlikely(err))
13890 + if (rw == MAY_READ)
13891 + iter = h_file->f_op->read_iter;
13892 + else if (rw == MAY_WRITE)
13893 + iter = h_file->f_op->write_iter;
13895 + file = kio->ki_filp;
13896 + kio->ki_filp = h_file;
13899 + err = iter(kio, iov_iter);
13902 + /* currently there is no such fs */
13904 + kio->ki_filp = file;
13910 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13913 + struct file *file, *h_file;
13914 + struct inode *inode;
13915 + struct super_block *sb;
13917 + file = kio->ki_filp;
13918 + inode = file_inode(file);
13919 + sb = inode->i_sb;
13920 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13922 + h_file = au_read_pre(file, /*keep_fi*/1);
13923 + err = PTR_ERR(h_file);
13924 + if (IS_ERR(h_file))
13927 + if (au_test_loopback_kthread()) {
13928 + au_warn_loopback(h_file->f_path.dentry->d_sb);
13929 + if (file->f_mapping != h_file->f_mapping) {
13930 + file->f_mapping = h_file->f_mapping;
13931 + smp_mb(); /* unnecessary? */
13934 + fi_read_unlock(file);
13936 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13937 + /* todo: necessary? */
13938 + /* file->f_ra = h_file->f_ra; */
13939 + au_read_post(inode, h_file);
13942 + si_read_unlock(sb);
13946 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13949 + struct au_write_pre wpre;
13950 + struct inode *inode;
13951 + struct file *file, *h_file;
13953 + file = kio->ki_filp;
13954 + inode = file_inode(file);
13955 + au_mtx_and_read_lock(inode);
13957 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13958 + err = PTR_ERR(h_file);
13959 + if (IS_ERR(h_file))
13962 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13963 + au_write_post(inode, h_file, &wpre, err);
13966 + si_read_unlock(inode->i_sb);
13967 + inode_unlock(inode);
13971 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13972 + struct pipe_inode_info *pipe, size_t len,
13973 + unsigned int flags)
13976 + struct file *h_file;
13977 + struct inode *inode;
13978 + struct super_block *sb;
13980 + inode = file_inode(file);
13981 + sb = inode->i_sb;
13982 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13984 + h_file = au_read_pre(file, /*keep_fi*/0);
13985 + err = PTR_ERR(h_file);
13986 + if (IS_ERR(h_file))
13989 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
13990 + /* todo: necessasry? */
13991 + /* file->f_ra = h_file->f_ra; */
13992 + au_read_post(inode, h_file);
13995 + si_read_unlock(sb);
14000 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
14001 + size_t len, unsigned int flags)
14004 + struct au_write_pre wpre;
14005 + struct inode *inode;
14006 + struct file *h_file;
14008 + inode = file_inode(file);
14009 + au_mtx_and_read_lock(inode);
14011 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14012 + err = PTR_ERR(h_file);
14013 + if (IS_ERR(h_file))
14016 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
14017 + au_write_post(inode, h_file, &wpre, err);
14020 + si_read_unlock(inode->i_sb);
14021 + inode_unlock(inode);
14025 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
14029 + struct au_write_pre wpre;
14030 + struct inode *inode;
14031 + struct file *h_file;
14033 + inode = file_inode(file);
14034 + au_mtx_and_read_lock(inode);
14036 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14037 + err = PTR_ERR(h_file);
14038 + if (IS_ERR(h_file))
14042 + err = vfs_fallocate(h_file, mode, offset, len);
14044 + au_write_post(inode, h_file, &wpre, /*written*/1);
14047 + si_read_unlock(inode->i_sb);
14048 + inode_unlock(inode);
14052 +/* ---------------------------------------------------------------------- */
14055 + * The locking order around current->mmap_sem.
14056 + * - in most and regular cases
14057 + * file I/O syscall -- aufs_read() or something
14058 + * -- si_rwsem for read -- mmap_sem
14059 + * (Note that [fdi]i_rwsem are released before mmap_sem).
14061 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
14062 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
14063 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
14064 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
14065 + * It means that when aufs acquires si_rwsem for write, the process should never
14066 + * acquire mmap_sem.
14068 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
14069 + * problem either since any directory is not able to be mmap-ed.
14070 + * The similar scenario is applied to aufs_readlink() too.
14073 +#if 0 /* stop calling security_file_mmap() */
14074 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
14075 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
14077 +static unsigned long au_arch_prot_conv(unsigned long flags)
14079 + /* currently ppc64 only */
14080 +#ifdef CONFIG_PPC64
14081 + /* cf. linux/arch/powerpc/include/asm/mman.h */
14082 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
14083 + return AuConv_VM_PROT(flags, SAO);
14085 + AuDebugOn(arch_calc_vm_prot_bits(-1));
14090 +static unsigned long au_prot_conv(unsigned long flags)
14092 + return AuConv_VM_PROT(flags, READ)
14093 + | AuConv_VM_PROT(flags, WRITE)
14094 + | AuConv_VM_PROT(flags, EXEC)
14095 + | au_arch_prot_conv(flags);
14098 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
14099 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
14101 +static unsigned long au_flag_conv(unsigned long flags)
14103 + return AuConv_VM_MAP(flags, GROWSDOWN)
14104 + | AuConv_VM_MAP(flags, DENYWRITE)
14105 + | AuConv_VM_MAP(flags, LOCKED);
14109 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
14112 + const unsigned char wlock
14113 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
14114 + struct super_block *sb;
14115 + struct file *h_file;
14116 + struct inode *inode;
14118 + AuDbgVmRegion(file, vma);
14120 + inode = file_inode(file);
14121 + sb = inode->i_sb;
14123 + si_read_lock(sb, AuLock_NOPLMW);
14125 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
14127 + err = PTR_ERR(h_file);
14128 + if (IS_ERR(h_file))
14132 + au_set_mmapped(file);
14133 + au_vm_file_reset(vma, h_file);
14135 + * we cannot call security_mmap_file() here since it may acquire
14136 + * mmap_sem or i_mutex.
14138 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
14139 + * au_flag_conv(vma->vm_flags));
14142 + err = h_file->f_op->mmap(h_file, vma);
14144 + au_vm_prfile_set(vma, file);
14145 + fsstack_copy_attr_atime(inode, file_inode(h_file));
14146 + goto out_fput; /* success */
14148 + au_unset_mmapped(file);
14149 + au_vm_file_reset(vma, file);
14153 + ii_write_unlock(inode);
14158 + si_read_unlock(sb);
14164 +/* ---------------------------------------------------------------------- */
14166 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
14170 + struct au_write_pre wpre;
14171 + struct inode *inode;
14172 + struct file *h_file;
14174 + err = 0; /* -EBADF; */ /* posix? */
14175 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14178 + inode = file_inode(file);
14179 + au_mtx_and_read_lock(inode);
14181 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14182 + err = PTR_ERR(h_file);
14183 + if (IS_ERR(h_file))
14186 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
14187 + au_write_post(inode, h_file, &wpre, /*written*/0);
14190 + si_read_unlock(inode->i_sb);
14191 + inode_unlock(inode);
14196 +/* no one supports this operation, currently */
14198 +static int aufs_aio_fsync_nondir(struct kiocb *kio, int datasync)
14201 + struct au_write_pre wpre;
14202 + struct inode *inode, *h_inode;
14203 + struct file *file, *h_file;
14205 + err = 0; /* -EBADF; */ /* posix? */
14206 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14209 + file = kio->ki_filp;
14210 + inode = file_inode(file);
14211 + au_mtx_and_read_lock(inode);
14213 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14214 + err = PTR_ERR(h_file);
14215 + if (IS_ERR(h_file))
14219 + h_file = au_hf_top(file);
14220 + if (h_file->f_op->aio_fsync) {
14221 + h_inode = file_inode(h_file);
14222 + if (!is_sync_kiocb(kio)) {
14223 + get_file(h_file);
14226 + kio->ki_filp = h_file;
14227 + err = h_file->f_op->aio_fsync(kio, datasync);
14228 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
14230 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL);
14232 + inode_unlock(h_inode);
14234 + au_write_post(inode, h_file, &wpre, /*written*/0);
14237 + si_read_unlock(inode->sb);
14238 + inode_unlock(inode);
14244 +static int aufs_fasync(int fd, struct file *file, int flag)
14247 + struct file *h_file;
14248 + struct super_block *sb;
14250 + sb = file->f_path.dentry->d_sb;
14251 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14253 + h_file = au_read_pre(file, /*keep_fi*/0);
14254 + err = PTR_ERR(h_file);
14255 + if (IS_ERR(h_file))
14258 + if (h_file->f_op->fasync)
14259 + err = h_file->f_op->fasync(fd, h_file, flag);
14260 + fput(h_file); /* instead of au_read_post() */
14263 + si_read_unlock(sb);
14267 +static int aufs_setfl(struct file *file, unsigned long arg)
14270 + struct file *h_file;
14271 + struct super_block *sb;
14273 + sb = file->f_path.dentry->d_sb;
14274 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14276 + h_file = au_read_pre(file, /*keep_fi*/0);
14277 + err = PTR_ERR(h_file);
14278 + if (IS_ERR(h_file))
14281 + arg |= vfsub_file_flags(file) & FASYNC; /* stop calling h_file->fasync */
14282 + err = setfl(/*unused fd*/-1, h_file, arg);
14283 + fput(h_file); /* instead of au_read_post() */
14286 + si_read_unlock(sb);
14290 +/* ---------------------------------------------------------------------- */
14292 +/* no one supports this operation, currently */
14294 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
14295 + size_t len, loff_t *pos, int more)
14300 +/* ---------------------------------------------------------------------- */
14302 +const struct file_operations aufs_file_fop = {
14303 + .owner = THIS_MODULE,
14305 + .llseek = default_llseek,
14307 + .read = aufs_read,
14308 + .write = aufs_write,
14309 + .read_iter = aufs_read_iter,
14310 + .write_iter = aufs_write_iter,
14312 +#ifdef CONFIG_AUFS_POLL
14313 + .poll = aufs_poll,
14315 + .unlocked_ioctl = aufs_ioctl_nondir,
14316 +#ifdef CONFIG_COMPAT
14317 + .compat_ioctl = aufs_compat_ioctl_nondir,
14319 + .mmap = aufs_mmap,
14320 + .open = aufs_open_nondir,
14321 + .flush = aufs_flush_nondir,
14322 + .release = aufs_release_nondir,
14323 + .fsync = aufs_fsync_nondir,
14324 + /* .aio_fsync = aufs_aio_fsync_nondir, */
14325 + .fasync = aufs_fasync,
14326 + /* .sendpage = aufs_sendpage, */
14327 + .setfl = aufs_setfl,
14328 + .splice_write = aufs_splice_write,
14329 + .splice_read = aufs_splice_read,
14331 + .aio_splice_write = aufs_aio_splice_write,
14332 + .aio_splice_read = aufs_aio_splice_read,
14334 + .fallocate = aufs_fallocate
14336 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14337 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14338 +++ linux/fs/aufs/fstype.h 2016-10-09 16:55:36.492701639 +0200
14341 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14343 + * This program, aufs is free software; you can redistribute it and/or modify
14344 + * it under the terms of the GNU General Public License as published by
14345 + * the Free Software Foundation; either version 2 of the License, or
14346 + * (at your option) any later version.
14348 + * This program is distributed in the hope that it will be useful,
14349 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14350 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14351 + * GNU General Public License for more details.
14353 + * You should have received a copy of the GNU General Public License
14354 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14358 + * judging filesystem type
14361 +#ifndef __AUFS_FSTYPE_H__
14362 +#define __AUFS_FSTYPE_H__
14366 +#include <linux/fs.h>
14367 +#include <linux/magic.h>
14368 +#include <linux/nfs_fs.h>
14369 +#include <linux/romfs_fs.h>
14371 +static inline int au_test_aufs(struct super_block *sb)
14373 + return sb->s_magic == AUFS_SUPER_MAGIC;
14376 +static inline const char *au_sbtype(struct super_block *sb)
14378 + return sb->s_type->name;
14381 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14383 +#if IS_ENABLED(CONFIG_ISO9660_FS)
14384 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14390 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14392 +#if IS_ENABLED(CONFIG_ROMFS_FS)
14393 + return sb->s_magic == ROMFS_MAGIC;
14399 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14401 +#if IS_ENABLED(CONFIG_CRAMFS)
14402 + return sb->s_magic == CRAMFS_MAGIC;
14407 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14409 +#if IS_ENABLED(CONFIG_NFS_FS)
14410 + return sb->s_magic == NFS_SUPER_MAGIC;
14416 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14418 +#if IS_ENABLED(CONFIG_FUSE_FS)
14419 + return sb->s_magic == FUSE_SUPER_MAGIC;
14425 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14427 +#if IS_ENABLED(CONFIG_XFS_FS)
14428 + return sb->s_magic == XFS_SB_MAGIC;
14434 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14436 +#ifdef CONFIG_TMPFS
14437 + return sb->s_magic == TMPFS_MAGIC;
14443 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14445 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
14446 + return !strcmp(au_sbtype(sb), "ecryptfs");
14452 +static inline int au_test_ramfs(struct super_block *sb)
14454 + return sb->s_magic == RAMFS_MAGIC;
14457 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14459 +#if IS_ENABLED(CONFIG_UBIFS_FS)
14460 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14466 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14468 +#ifdef CONFIG_PROC_FS
14469 + return sb->s_magic == PROC_SUPER_MAGIC;
14475 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14477 +#ifdef CONFIG_SYSFS
14478 + return sb->s_magic == SYSFS_MAGIC;
14484 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14486 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
14487 + return sb->s_magic == CONFIGFS_MAGIC;
14493 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14495 +#if IS_ENABLED(CONFIG_MINIX_FS)
14496 + return sb->s_magic == MINIX3_SUPER_MAGIC
14497 + || sb->s_magic == MINIX2_SUPER_MAGIC
14498 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14499 + || sb->s_magic == MINIX_SUPER_MAGIC
14500 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14506 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14508 +#if IS_ENABLED(CONFIG_FAT_FS)
14509 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14515 +static inline int au_test_msdos(struct super_block *sb)
14517 + return au_test_fat(sb);
14520 +static inline int au_test_vfat(struct super_block *sb)
14522 + return au_test_fat(sb);
14525 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14527 +#ifdef CONFIG_SECURITYFS
14528 + return sb->s_magic == SECURITYFS_MAGIC;
14534 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14536 +#if IS_ENABLED(CONFIG_SQUASHFS)
14537 + return sb->s_magic == SQUASHFS_MAGIC;
14543 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14545 +#if IS_ENABLED(CONFIG_BTRFS_FS)
14546 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14552 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14554 +#if IS_ENABLED(CONFIG_XENFS)
14555 + return sb->s_magic == XENFS_SUPER_MAGIC;
14561 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14563 +#ifdef CONFIG_DEBUG_FS
14564 + return sb->s_magic == DEBUGFS_MAGIC;
14570 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14572 +#if IS_ENABLED(CONFIG_NILFS)
14573 + return sb->s_magic == NILFS_SUPER_MAGIC;
14579 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14581 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
14582 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14588 +/* ---------------------------------------------------------------------- */
14590 + * they can't be an aufs branch.
14592 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14595 +#ifndef CONFIG_AUFS_BR_RAMFS
14596 + au_test_ramfs(sb) ||
14598 + au_test_procfs(sb)
14599 + || au_test_sysfs(sb)
14600 + || au_test_configfs(sb)
14601 + || au_test_debugfs(sb)
14602 + || au_test_securityfs(sb)
14603 + || au_test_xenfs(sb)
14604 + || au_test_ecryptfs(sb)
14605 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14606 + || au_test_aufs(sb); /* will be supported in next version */
14609 +static inline int au_test_fs_remote(struct super_block *sb)
14611 + return !au_test_tmpfs(sb)
14612 +#ifdef CONFIG_AUFS_BR_RAMFS
14613 + && !au_test_ramfs(sb)
14615 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14618 +/* ---------------------------------------------------------------------- */
14621 + * Note: these functions (below) are created after reading ->getattr() in all
14622 + * filesystems under linux/fs. it means we have to do so in every update...
14626 + * some filesystems require getattr to refresh the inode attributes before
14628 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14629 + * and leave the work for d_revalidate()
14631 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14633 + return au_test_nfs(sb)
14634 + || au_test_fuse(sb)
14635 + /* || au_test_btrfs(sb) */ /* untested */
14640 + * filesystems which don't maintain i_size or i_blocks.
14642 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14644 + return au_test_xfs(sb)
14645 + || au_test_btrfs(sb)
14646 + || au_test_ubifs(sb)
14647 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14648 + /* || au_test_minix(sb) */ /* untested */
14653 + * filesystems which don't store the correct value in some of their inode
14656 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14658 + return au_test_fs_bad_iattr_size(sb)
14659 + || au_test_fat(sb)
14660 + || au_test_msdos(sb)
14661 + || au_test_vfat(sb);
14664 +/* they don't check i_nlink in link(2) */
14665 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14667 + return au_test_tmpfs(sb)
14668 +#ifdef CONFIG_AUFS_BR_RAMFS
14669 + || au_test_ramfs(sb)
14671 + || au_test_ubifs(sb)
14672 + || au_test_hfsplus(sb);
14676 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14678 +static inline int au_test_fs_notime(struct super_block *sb)
14680 + return au_test_nfs(sb)
14681 + || au_test_fuse(sb)
14682 + || au_test_ubifs(sb)
14686 +/* temporary support for i#1 in cramfs */
14687 +static inline int au_test_fs_unique_ino(struct inode *inode)
14689 + if (au_test_cramfs(inode->i_sb))
14690 + return inode->i_ino != 1;
14694 +/* ---------------------------------------------------------------------- */
14697 + * the filesystem where the xino files placed must support i/o after unlink and
14698 + * maintain i_size and i_blocks.
14700 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14702 + return au_test_fs_remote(sb)
14703 + || au_test_fs_bad_iattr_size(sb)
14704 + /* don't want unnecessary work for xino */
14705 + || au_test_aufs(sb)
14706 + || au_test_ecryptfs(sb)
14707 + || au_test_nilfs(sb);
14710 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14712 + return au_test_tmpfs(sb)
14713 + || au_test_ramfs(sb);
14717 + * test if the @sb is real-readonly.
14719 +static inline int au_test_fs_rr(struct super_block *sb)
14721 + return au_test_squashfs(sb)
14722 + || au_test_iso9660(sb)
14723 + || au_test_cramfs(sb)
14724 + || au_test_romfs(sb);
14728 + * test if the @inode is nfs with 'noacl' option
14729 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14731 +static inline int au_test_nfs_noacl(struct inode *inode)
14733 + return au_test_nfs(inode->i_sb)
14734 + /* && IS_POSIXACL(inode) */
14735 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14738 +#endif /* __KERNEL__ */
14739 +#endif /* __AUFS_FSTYPE_H__ */
14740 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14741 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14742 +++ linux/fs/aufs/hfsnotify.c 2016-10-09 16:55:36.492701639 +0200
14745 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14747 + * This program, aufs is free software; you can redistribute it and/or modify
14748 + * it under the terms of the GNU General Public License as published by
14749 + * the Free Software Foundation; either version 2 of the License, or
14750 + * (at your option) any later version.
14752 + * This program is distributed in the hope that it will be useful,
14753 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14754 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14755 + * GNU General Public License for more details.
14757 + * You should have received a copy of the GNU General Public License
14758 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14762 + * fsnotify for the lower directories
14767 +/* FS_IN_IGNORED is unnecessary */
14768 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14769 + | FS_CREATE | FS_EVENT_ON_CHILD);
14770 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14771 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14773 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14775 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14777 + /* AuDbg("here\n"); */
14778 + au_cache_dfree_hnotify(hn);
14779 + smp_mb__before_atomic();
14780 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14781 + wake_up(&au_hfsn_wq);
14784 +static int au_hfsn_alloc(struct au_hinode *hinode)
14787 + struct au_hnotify *hn;
14788 + struct super_block *sb;
14789 + struct au_branch *br;
14790 + struct fsnotify_mark *mark;
14791 + aufs_bindex_t bindex;
14793 + hn = hinode->hi_notify;
14794 + sb = hn->hn_aufs_inode->i_sb;
14795 + bindex = au_br_index(sb, hinode->hi_id);
14796 + br = au_sbr(sb, bindex);
14797 + AuDebugOn(!br->br_hfsn);
14799 + mark = &hn->hn_mark;
14800 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14801 + mark->mask = AuHfsnMask;
14803 + * by udba rename or rmdir, aufs assign a new inode to the known
14804 + * h_inode, so specify 1 to allow dups.
14807 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14808 + /*mnt*/NULL, /*allow_dups*/1);
14814 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14816 + struct fsnotify_mark *mark;
14817 + unsigned long long ull;
14818 + struct fsnotify_group *group;
14820 + ull = atomic64_inc_return(&au_hfsn_ifree);
14823 + mark = &hn->hn_mark;
14824 + spin_lock(&mark->lock);
14825 + group = mark->group;
14826 + fsnotify_get_group(group);
14827 + spin_unlock(&mark->lock);
14829 + fsnotify_destroy_mark(mark, group);
14830 + fsnotify_put_mark(mark);
14831 + fsnotify_put_group(group);
14834 + /* free hn by myself */
14838 +/* ---------------------------------------------------------------------- */
14840 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14842 + struct fsnotify_mark *mark;
14844 + mark = &hinode->hi_notify->hn_mark;
14845 + spin_lock(&mark->lock);
14847 + AuDebugOn(mark->mask & AuHfsnMask);
14848 + mark->mask |= AuHfsnMask;
14850 + AuDebugOn(!(mark->mask & AuHfsnMask));
14851 + mark->mask &= ~AuHfsnMask;
14853 + spin_unlock(&mark->lock);
14854 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14857 +/* ---------------------------------------------------------------------- */
14859 +/* #define AuDbgHnotify */
14860 +#ifdef AuDbgHnotify
14861 +static char *au_hfsn_name(u32 mask)
14863 +#ifdef CONFIG_AUFS_DEBUG
14864 +#define test_ret(flag) \
14866 + if (mask & flag) \
14869 + test_ret(FS_ACCESS);
14870 + test_ret(FS_MODIFY);
14871 + test_ret(FS_ATTRIB);
14872 + test_ret(FS_CLOSE_WRITE);
14873 + test_ret(FS_CLOSE_NOWRITE);
14874 + test_ret(FS_OPEN);
14875 + test_ret(FS_MOVED_FROM);
14876 + test_ret(FS_MOVED_TO);
14877 + test_ret(FS_CREATE);
14878 + test_ret(FS_DELETE);
14879 + test_ret(FS_DELETE_SELF);
14880 + test_ret(FS_MOVE_SELF);
14881 + test_ret(FS_UNMOUNT);
14882 + test_ret(FS_Q_OVERFLOW);
14883 + test_ret(FS_IN_IGNORED);
14884 + test_ret(FS_ISDIR);
14885 + test_ret(FS_IN_ONESHOT);
14886 + test_ret(FS_EVENT_ON_CHILD);
14895 +/* ---------------------------------------------------------------------- */
14897 +static void au_hfsn_free_group(struct fsnotify_group *group)
14899 + struct au_br_hfsnotify *hfsn = group->private;
14901 + /* AuDbg("here\n"); */
14902 + au_delayed_kfree(hfsn);
14905 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14906 + struct inode *inode,
14907 + struct fsnotify_mark *inode_mark,
14908 + struct fsnotify_mark *vfsmount_mark,
14909 + u32 mask, void *data, int data_type,
14910 + const unsigned char *file_name, u32 cookie)
14913 + struct au_hnotify *hnotify;
14914 + struct inode *h_dir, *h_inode;
14915 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14917 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14920 + /* if FS_UNMOUNT happens, there must be another bug */
14921 + AuDebugOn(mask & FS_UNMOUNT);
14922 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14927 +#ifdef AuDbgHnotify
14929 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14930 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14931 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14932 + h_dir->i_ino, mask, au_hfsn_name(mask),
14933 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14934 + /* WARN_ON(1); */
14939 + AuDebugOn(!inode_mark);
14940 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14941 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14947 +static struct fsnotify_ops au_hfsn_ops = {
14948 + .handle_event = au_hfsn_handle_event,
14949 + .free_group_priv = au_hfsn_free_group
14952 +/* ---------------------------------------------------------------------- */
14954 +static void au_hfsn_fin_br(struct au_branch *br)
14956 + struct au_br_hfsnotify *hfsn;
14958 + hfsn = br->br_hfsn;
14961 + fsnotify_put_group(hfsn->hfsn_group);
14966 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14969 + struct fsnotify_group *group;
14970 + struct au_br_hfsnotify *hfsn;
14973 + br->br_hfsn = NULL;
14974 + if (!au_br_hnotifyable(perm))
14978 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14979 + if (unlikely(!hfsn))
14983 + group = fsnotify_alloc_group(&au_hfsn_ops);
14984 + if (IS_ERR(group)) {
14985 + err = PTR_ERR(group);
14986 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14990 + group->private = hfsn;
14991 + hfsn->hfsn_group = group;
14992 + br->br_hfsn = hfsn;
14993 + goto out; /* success */
14996 + au_delayed_kfree(hfsn);
15001 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
15006 + if (!br->br_hfsn)
15007 + err = au_hfsn_init_br(br, perm);
15012 +/* ---------------------------------------------------------------------- */
15014 +static void au_hfsn_fin(void)
15016 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
15017 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
15020 +const struct au_hnotify_op au_hnotify_op = {
15021 + .ctl = au_hfsn_ctl,
15022 + .alloc = au_hfsn_alloc,
15023 + .free = au_hfsn_free,
15025 + .fin = au_hfsn_fin,
15027 + .reset_br = au_hfsn_reset_br,
15028 + .fin_br = au_hfsn_fin_br,
15029 + .init_br = au_hfsn_init_br
15031 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
15032 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
15033 +++ linux/fs/aufs/hfsplus.c 2016-10-09 16:55:36.492701639 +0200
15036 + * Copyright (C) 2010-2016 Junjiro R. Okajima
15038 + * This program, aufs is free software; you can redistribute it and/or modify
15039 + * it under the terms of the GNU General Public License as published by
15040 + * the Free Software Foundation; either version 2 of the License, or
15041 + * (at your option) any later version.
15043 + * This program is distributed in the hope that it will be useful,
15044 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15045 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15046 + * GNU General Public License for more details.
15048 + * You should have received a copy of the GNU General Public License
15049 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15053 + * special support for filesystems which aqucires an inode mutex
15054 + * at final closing a file, eg, hfsplus.
15056 + * This trick is very simple and stupid, just to open the file before really
15057 + * neceeary open to tell hfsplus that this is not the final closing.
15058 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
15059 + * and au_h_open_post() after releasing it.
15064 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15067 + struct file *h_file;
15068 + struct dentry *h_dentry;
15070 + h_dentry = au_h_dptr(dentry, bindex);
15071 + AuDebugOn(!h_dentry);
15072 + AuDebugOn(d_is_negative(h_dentry));
15075 + if (au_test_hfsplus(h_dentry->d_sb)
15076 + && d_is_reg(h_dentry))
15077 + h_file = au_h_open(dentry, bindex,
15078 + O_RDONLY | O_NOATIME | O_LARGEFILE,
15079 + /*file*/NULL, force_wr);
15083 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15084 + struct file *h_file)
15088 + au_sbr_put(dentry->d_sb, bindex);
15091 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
15092 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
15093 +++ linux/fs/aufs/hnotify.c 2016-10-09 16:55:36.492701639 +0200
15096 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15098 + * This program, aufs is free software; you can redistribute it and/or modify
15099 + * it under the terms of the GNU General Public License as published by
15100 + * the Free Software Foundation; either version 2 of the License, or
15101 + * (at your option) any later version.
15103 + * This program is distributed in the hope that it will be useful,
15104 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15105 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15106 + * GNU General Public License for more details.
15108 + * You should have received a copy of the GNU General Public License
15109 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15113 + * abstraction to notify the direct changes on lower directories
15118 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
15121 + struct au_hnotify *hn;
15124 + hn = au_cache_alloc_hnotify();
15126 + hn->hn_aufs_inode = inode;
15127 + hinode->hi_notify = hn;
15128 + err = au_hnotify_op.alloc(hinode);
15130 + if (unlikely(err)) {
15131 + hinode->hi_notify = NULL;
15132 + au_cache_dfree_hnotify(hn);
15134 + * The upper dir was removed by udba, but the same named
15135 + * dir left. In this case, aufs assignes a new inode
15136 + * number and set the monitor again.
15137 + * For the lower dir, the old monitnor is still left.
15139 + if (err == -EEXIST)
15148 +void au_hn_free(struct au_hinode *hinode)
15150 + struct au_hnotify *hn;
15152 + hn = hinode->hi_notify;
15154 + hinode->hi_notify = NULL;
15155 + if (au_hnotify_op.free(hinode, hn))
15156 + au_cache_dfree_hnotify(hn);
15160 +/* ---------------------------------------------------------------------- */
15162 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
15164 + if (hinode->hi_notify)
15165 + au_hnotify_op.ctl(hinode, do_set);
15168 +void au_hn_reset(struct inode *inode, unsigned int flags)
15170 + aufs_bindex_t bindex, bbot;
15171 + struct inode *hi;
15172 + struct dentry *iwhdentry;
15174 + bbot = au_ibbot(inode);
15175 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
15176 + hi = au_h_iptr(inode, bindex);
15180 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
15181 + iwhdentry = au_hi_wh(inode, bindex);
15185 + au_set_h_iptr(inode, bindex, NULL, 0);
15186 + au_set_h_iptr(inode, bindex, au_igrab(hi),
15187 + flags & ~AuHi_XINO);
15190 + /* inode_unlock(hi); */
15194 +/* ---------------------------------------------------------------------- */
15196 +static int hn_xino(struct inode *inode, struct inode *h_inode)
15199 + aufs_bindex_t bindex, bbot, bfound, btop;
15200 + struct inode *h_i;
15203 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15204 + pr_warn("branch root dir was changed\n");
15209 + bbot = au_ibbot(inode);
15210 + btop = au_ibtop(inode);
15211 +#if 0 /* reserved for future use */
15212 + if (bindex == bbot) {
15213 + /* keep this ino in rename case */
15217 + for (bindex = btop; bindex <= bbot; bindex++)
15218 + if (au_h_iptr(inode, bindex) == h_inode) {
15225 + for (bindex = btop; bindex <= bbot; bindex++) {
15226 + h_i = au_h_iptr(inode, bindex);
15230 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
15231 + /* ignore this error */
15232 + /* bad action? */
15235 + /* children inode number will be broken */
15242 +static int hn_gen_tree(struct dentry *dentry)
15244 + int err, i, j, ndentry;
15245 + struct au_dcsub_pages dpages;
15246 + struct au_dpage *dpage;
15247 + struct dentry **dentries;
15249 + err = au_dpages_init(&dpages, GFP_NOFS);
15250 + if (unlikely(err))
15252 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
15253 + if (unlikely(err))
15256 + for (i = 0; i < dpages.ndpage; i++) {
15257 + dpage = dpages.dpages + i;
15258 + dentries = dpage->dentries;
15259 + ndentry = dpage->ndentry;
15260 + for (j = 0; j < ndentry; j++) {
15261 + struct dentry *d;
15268 + if (d_really_is_positive(d))
15269 + /* todo: reset children xino?
15270 + cached children only? */
15271 + au_iigen_dec(d_inode(d));
15276 + au_dpages_free(&dpages);
15279 + /* discard children */
15280 + dentry_unhash(dentry);
15288 + * return 0 if processed.
15290 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
15291 + const unsigned int isdir)
15294 + struct dentry *d;
15295 + struct qstr *dname;
15298 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15299 + pr_warn("branch root dir was changed\n");
15305 + AuDebugOn(!name);
15306 + au_iigen_dec(inode);
15307 + spin_lock(&inode->i_lock);
15308 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
15309 + spin_lock(&d->d_lock);
15310 + dname = &d->d_name;
15311 + if (dname->len != nlen
15312 + && memcmp(dname->name, name, nlen)) {
15313 + spin_unlock(&d->d_lock);
15318 + spin_unlock(&d->d_lock);
15321 + spin_unlock(&inode->i_lock);
15323 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15324 + d = d_find_any_alias(inode);
15326 + au_iigen_dec(inode);
15330 + spin_lock(&d->d_lock);
15331 + dname = &d->d_name;
15332 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15333 + spin_unlock(&d->d_lock);
15334 + err = hn_gen_tree(d);
15335 + spin_lock(&d->d_lock);
15337 + spin_unlock(&d->d_lock);
15346 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15350 + if (IS_ROOT(dentry)) {
15351 + pr_warn("branch root dir was changed\n");
15357 + au_digen_dec(dentry);
15358 + if (d_really_is_positive(dentry))
15359 + au_iigen_dec(d_inode(dentry));
15361 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15362 + if (d_really_is_positive(dentry))
15363 + err = hn_gen_tree(dentry);
15370 +/* ---------------------------------------------------------------------- */
15372 +/* hnotify job flags */
15373 +#define AuHnJob_XINO0 1
15374 +#define AuHnJob_GEN (1 << 1)
15375 +#define AuHnJob_DIRENT (1 << 2)
15376 +#define AuHnJob_ISDIR (1 << 3)
15377 +#define AuHnJob_TRYXINO0 (1 << 4)
15378 +#define AuHnJob_MNTPNT (1 << 5)
15379 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15380 +#define au_fset_hnjob(flags, name) \
15381 + do { (flags) |= AuHnJob_##name; } while (0)
15382 +#define au_fclr_hnjob(flags, name) \
15383 + do { (flags) &= ~AuHnJob_##name; } while (0)
15391 +struct au_hnotify_args {
15392 + struct inode *h_dir, *dir, *h_child_inode;
15394 + unsigned int flags[AuHnLast];
15395 + unsigned int h_child_nlen;
15396 + char h_child_name[];
15399 +struct hn_job_args {
15400 + unsigned int flags;
15401 + struct inode *inode, *h_inode, *dir, *h_dir;
15402 + struct dentry *dentry;
15407 +static int hn_job(struct hn_job_args *a)
15409 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15413 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15414 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15416 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15419 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
15420 + if (!a->h_inode->i_nlink
15421 + && !(a->h_inode->i_state & I_LINKABLE))
15422 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15423 + inode_unlock(a->h_inode);
15426 + /* make the generation obsolete */
15427 + if (au_ftest_hnjob(a->flags, GEN)) {
15430 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15432 + if (e && a->dentry)
15433 + hn_gen_by_name(a->dentry, isdir);
15434 + /* ignore this error */
15437 + /* make dir entries obsolete */
15438 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15439 + struct au_vdir *vdir;
15441 + vdir = au_ivdir(a->inode);
15443 + vdir->vd_jiffy = 0;
15444 + /* IMustLock(a->inode); */
15445 + /* a->inode->i_version++; */
15448 + /* can do nothing but warn */
15449 + if (au_ftest_hnjob(a->flags, MNTPNT)
15451 + && d_mountpoint(a->dentry))
15452 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15457 +/* ---------------------------------------------------------------------- */
15459 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15460 + struct inode *dir)
15462 + struct dentry *dentry, *d, *parent;
15463 + struct qstr *dname;
15465 + parent = d_find_any_alias(dir);
15470 + spin_lock(&parent->d_lock);
15471 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15472 + /* AuDbg("%pd\n", d); */
15473 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15474 + dname = &d->d_name;
15475 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15476 + goto cont_unlock;
15480 + goto cont_unlock;
15481 + if (au_dcount(d) > 0) {
15482 + dentry = dget_dlock(d);
15483 + spin_unlock(&d->d_lock);
15488 + spin_unlock(&d->d_lock);
15490 + spin_unlock(&parent->d_lock);
15494 + di_write_lock_child(dentry);
15499 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15500 + aufs_bindex_t bindex, ino_t h_ino)
15502 + struct inode *inode;
15507 + err = au_xino_read(sb, bindex, h_ino, &ino);
15509 + inode = ilookup(sb, ino);
15513 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15514 + pr_warn("wrong root branch\n");
15520 + ii_write_lock_child(inode);
15526 +static void au_hn_bh(void *_args)
15528 + struct au_hnotify_args *a = _args;
15529 + struct super_block *sb;
15530 + aufs_bindex_t bindex, bbot, bfound;
15531 + unsigned char xino, try_iput;
15533 + struct inode *inode;
15535 + struct hn_job_args args;
15536 + struct dentry *dentry;
15537 + struct au_sbinfo *sbinfo;
15539 + AuDebugOn(!_args);
15540 + AuDebugOn(!a->h_dir);
15541 + AuDebugOn(!a->dir);
15542 + AuDebugOn(!a->mask);
15543 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15544 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15545 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15550 + * do not lock a->dir->i_mutex here
15551 + * because of d_revalidate() may cause a deadlock.
15553 + sb = a->dir->i_sb;
15555 + sbinfo = au_sbi(sb);
15556 + AuDebugOn(!sbinfo);
15557 + si_write_lock(sb, AuLock_NOPLMW);
15559 + ii_read_lock_parent(a->dir);
15561 + bbot = au_ibbot(a->dir);
15562 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
15563 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15567 + ii_read_unlock(a->dir);
15568 + if (unlikely(bfound < 0))
15571 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15573 + if (a->h_child_inode)
15574 + h_ino = a->h_child_inode->i_ino;
15576 + if (a->h_child_nlen
15577 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15578 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15579 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15582 + if (dentry && d_really_is_positive(dentry))
15583 + inode = d_inode(dentry);
15584 + if (xino && !inode && h_ino
15585 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15586 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15587 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15588 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15592 + args.flags = a->flags[AuHn_CHILD];
15593 + args.dentry = dentry;
15594 + args.inode = inode;
15595 + args.h_inode = a->h_child_inode;
15596 + args.dir = a->dir;
15597 + args.h_dir = a->h_dir;
15598 + args.h_name = a->h_child_name;
15599 + args.h_nlen = a->h_child_nlen;
15600 + err = hn_job(&args);
15602 + if (au_di(dentry))
15603 + di_write_unlock(dentry);
15606 + if (inode && try_iput) {
15607 + ii_write_unlock(inode);
15611 + ii_write_lock_parent(a->dir);
15612 + args.flags = a->flags[AuHn_PARENT];
15613 + args.dentry = NULL;
15614 + args.inode = a->dir;
15615 + args.h_inode = a->h_dir;
15617 + args.h_dir = NULL;
15618 + args.h_name = NULL;
15620 + err = hn_job(&args);
15621 + ii_write_unlock(a->dir);
15624 + iput(a->h_child_inode);
15627 + si_write_unlock(sb);
15628 + au_nwt_done(&sbinfo->si_nowait);
15629 + au_delayed_kfree(a);
15632 +/* ---------------------------------------------------------------------- */
15634 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15635 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15638 + unsigned int flags[AuHnLast], f;
15639 + unsigned char isdir, isroot, wh;
15640 + struct inode *dir;
15641 + struct au_hnotify_args *args;
15642 + char *p, *h_child_name;
15645 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15646 + dir = igrab(hnotify->hn_aufs_inode);
15650 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15652 + h_child_name = (void *)h_child_qstr->name;
15653 + len = h_child_qstr->len;
15654 + if (h_child_name) {
15655 + if (len > AUFS_WH_PFX_LEN
15656 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15657 + h_child_name += AUFS_WH_PFX_LEN;
15658 + len -= AUFS_WH_PFX_LEN;
15664 + if (h_child_inode)
15665 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15666 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15667 + flags[AuHn_CHILD] = 0;
15669 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15670 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15671 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15672 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15673 + case FS_MOVED_FROM:
15674 + case FS_MOVED_TO:
15675 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15676 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15679 + AuDebugOn(!h_child_name);
15684 + * aufs never be able to get this child inode.
15685 + * revalidation should be in d_revalidate()
15686 + * by checking i_nlink, i_generation or d_unhashed().
15688 + AuDebugOn(!h_child_name);
15689 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15690 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15698 + h_child_inode = NULL;
15701 + /* iput() and kfree() will be called in au_hnotify() */
15702 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15703 + if (unlikely(!args)) {
15704 + AuErr1("no memory\n");
15708 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15709 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15710 + args->mask = mask;
15712 + args->h_dir = igrab(h_dir);
15713 + if (h_child_inode)
15714 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15715 + args->h_child_inode = h_child_inode;
15716 + args->h_child_nlen = len;
15718 + p = (void *)args;
15719 + p += sizeof(*args);
15720 + memcpy(p, h_child_name, len);
15724 + /* NFS fires the event for silly-renamed one from kworker */
15726 + if (!dir->i_nlink
15727 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15729 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15730 + if (unlikely(err)) {
15731 + pr_err("wkq %d\n", err);
15732 + iput(args->h_child_inode);
15733 + iput(args->h_dir);
15735 + au_delayed_kfree(args);
15742 +/* ---------------------------------------------------------------------- */
15744 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15748 + AuDebugOn(!(udba & AuOptMask_UDBA));
15751 + if (au_hnotify_op.reset_br)
15752 + err = au_hnotify_op.reset_br(udba, br, perm);
15757 +int au_hnotify_init_br(struct au_branch *br, int perm)
15762 + if (au_hnotify_op.init_br)
15763 + err = au_hnotify_op.init_br(br, perm);
15768 +void au_hnotify_fin_br(struct au_branch *br)
15770 + if (au_hnotify_op.fin_br)
15771 + au_hnotify_op.fin_br(br);
15774 +static void au_hn_destroy_cache(void)
15776 + struct au_cache *cp;
15778 + flush_delayed_work(&au_dfree.dwork);
15779 + cp = au_dfree.cache + AuCache_HNOTIFY;
15780 + AuDebugOn(!llist_empty(&cp->llist));
15781 + kmem_cache_destroy(cp->cache);
15782 + cp->cache = NULL;
15785 +AU_CACHE_DFREE_FUNC(hnotify, HNOTIFY, hn_lnode);
15787 +int __init au_hnotify_init(void)
15790 + struct au_cache *cp;
15793 + cp = au_dfree.cache + AuCache_HNOTIFY;
15794 + cp->cache = AuCache(au_hnotify);
15797 + if (au_hnotify_op.init)
15798 + err = au_hnotify_op.init();
15799 + if (unlikely(err))
15800 + au_hn_destroy_cache();
15806 +void au_hnotify_fin(void)
15808 + struct au_cache *cp;
15810 + if (au_hnotify_op.fin)
15811 + au_hnotify_op.fin();
15813 + /* cf. au_cache_fin() */
15814 + cp = au_dfree.cache + AuCache_HNOTIFY;
15816 + au_hn_destroy_cache();
15818 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15819 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15820 +++ linux/fs/aufs/iinfo.c 2016-10-09 16:55:38.889431135 +0200
15823 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15825 + * This program, aufs is free software; you can redistribute it and/or modify
15826 + * it under the terms of the GNU General Public License as published by
15827 + * the Free Software Foundation; either version 2 of the License, or
15828 + * (at your option) any later version.
15830 + * This program is distributed in the hope that it will be useful,
15831 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15832 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15833 + * GNU General Public License for more details.
15835 + * You should have received a copy of the GNU General Public License
15836 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15840 + * inode private data
15845 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15847 + struct inode *h_inode;
15848 + struct au_hinode *hinode;
15850 + IiMustAnyLock(inode);
15852 + hinode = au_hinode(au_ii(inode), bindex);
15853 + h_inode = hinode->hi_inode;
15854 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15858 +/* todo: hard/soft set? */
15859 +void au_hiput(struct au_hinode *hinode)
15861 + au_hn_free(hinode);
15862 + dput(hinode->hi_whdentry);
15863 + iput(hinode->hi_inode);
15866 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15868 + unsigned int flags;
15869 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15872 + if (au_opt_test(mnt_flags, XINO))
15873 + au_fset_hi(flags, XINO);
15874 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15875 + au_fset_hi(flags, HNOTIFY);
15879 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15880 + struct inode *h_inode, unsigned int flags)
15882 + struct au_hinode *hinode;
15883 + struct inode *hi;
15884 + struct au_iinfo *iinfo = au_ii(inode);
15886 + IiMustWriteLock(inode);
15888 + hinode = au_hinode(iinfo, bindex);
15889 + hi = hinode->hi_inode;
15890 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15893 + au_hiput(hinode);
15894 + hinode->hi_inode = h_inode;
15897 + struct super_block *sb = inode->i_sb;
15898 + struct au_branch *br;
15900 + AuDebugOn(inode->i_mode
15901 + && (h_inode->i_mode & S_IFMT)
15902 + != (inode->i_mode & S_IFMT));
15903 + if (bindex == iinfo->ii_btop)
15904 + au_cpup_igen(inode, h_inode);
15905 + br = au_sbr(sb, bindex);
15906 + hinode->hi_id = br->br_id;
15907 + if (au_ftest_hi(flags, XINO)) {
15908 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15910 + if (unlikely(err))
15911 + AuIOErr1("failed au_xino_write() %d\n", err);
15914 + if (au_ftest_hi(flags, HNOTIFY)
15915 + && au_br_hnotifyable(br->br_perm)) {
15916 + err = au_hn_alloc(hinode, inode);
15917 + if (unlikely(err))
15918 + AuIOErr1("au_hn_alloc() %d\n", err);
15923 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15924 + struct dentry *h_wh)
15926 + struct au_hinode *hinode;
15928 + IiMustWriteLock(inode);
15930 + hinode = au_hinode(au_ii(inode), bindex);
15931 + AuDebugOn(hinode->hi_whdentry);
15932 + hinode->hi_whdentry = h_wh;
15935 +void au_update_iigen(struct inode *inode, int half)
15937 + struct au_iinfo *iinfo;
15938 + struct au_iigen *iigen;
15939 + unsigned int sigen;
15941 + sigen = au_sigen(inode->i_sb);
15942 + iinfo = au_ii(inode);
15943 + iigen = &iinfo->ii_generation;
15944 + spin_lock(&iigen->ig_spin);
15945 + iigen->ig_generation = sigen;
15947 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15949 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15950 + spin_unlock(&iigen->ig_spin);
15953 +/* it may be called at remount time, too */
15954 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15956 + struct au_iinfo *iinfo;
15957 + aufs_bindex_t bindex, bbot;
15959 + AuDebugOn(au_is_bad_inode(inode));
15960 + IiMustWriteLock(inode);
15962 + iinfo = au_ii(inode);
15963 + if (do_put_zero && iinfo->ii_btop >= 0) {
15964 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
15966 + struct inode *h_i;
15968 + h_i = au_hinode(iinfo, bindex)->hi_inode;
15971 + && !(h_i->i_state & I_LINKABLE))
15972 + au_set_h_iptr(inode, bindex, NULL, 0);
15976 + iinfo->ii_btop = -1;
15977 + iinfo->ii_bbot = -1;
15978 + bbot = au_sbbot(inode->i_sb);
15979 + for (bindex = 0; bindex <= bbot; bindex++)
15980 + if (au_hinode(iinfo, bindex)->hi_inode) {
15981 + iinfo->ii_btop = bindex;
15984 + if (iinfo->ii_btop >= 0)
15985 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
15986 + if (au_hinode(iinfo, bindex)->hi_inode) {
15987 + iinfo->ii_bbot = bindex;
15990 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
15993 +/* ---------------------------------------------------------------------- */
15995 +void au_icntnr_init_once(void *_c)
15997 + struct au_icntnr *c = _c;
15998 + struct au_iinfo *iinfo = &c->iinfo;
16000 + spin_lock_init(&iinfo->ii_generation.ig_spin);
16001 + au_rw_init(&iinfo->ii_rwsem);
16002 + inode_init_once(&c->vfs_inode);
16005 +void au_hinode_init(struct au_hinode *hinode)
16007 + hinode->hi_inode = NULL;
16008 + hinode->hi_id = -1;
16009 + au_hn_init(hinode);
16010 + hinode->hi_whdentry = NULL;
16013 +int au_iinfo_init(struct inode *inode)
16015 + struct au_iinfo *iinfo;
16016 + struct super_block *sb;
16017 + struct au_hinode *hi;
16020 + sb = inode->i_sb;
16021 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16022 + nbr = au_sbbot(sb) + 1;
16023 + if (unlikely(nbr <= 0))
16025 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
16027 + au_ninodes_inc(sb);
16029 + iinfo->ii_hinode = hi;
16030 + for (i = 0; i < nbr; i++, hi++)
16031 + au_hinode_init(hi);
16033 + iinfo->ii_generation.ig_generation = au_sigen(sb);
16034 + iinfo->ii_btop = -1;
16035 + iinfo->ii_bbot = -1;
16036 + iinfo->ii_vdir = NULL;
16042 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
16045 + struct au_hinode *hip;
16047 + AuRwMustWriteLock(&iinfo->ii_rwsem);
16050 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
16053 + iinfo->ii_hinode = hip;
16054 + i = iinfo->ii_bbot + 1;
16056 + for (; i < nbr; i++, hip++)
16057 + au_hinode_init(hip);
16064 +void au_iinfo_fin(struct inode *inode)
16066 + struct au_iinfo *iinfo;
16067 + struct au_hinode *hi;
16068 + struct super_block *sb;
16069 + aufs_bindex_t bindex, bbot;
16070 + const unsigned char unlinked = !inode->i_nlink;
16072 + AuDebugOn(au_is_bad_inode(inode));
16074 + sb = inode->i_sb;
16075 + au_ninodes_dec(sb);
16076 + if (si_pid_test(sb))
16077 + au_xino_delete_inode(inode, unlinked);
16080 + * it is safe to hide the dependency between sbinfo and
16084 + si_noflush_read_lock(sb);
16085 + au_xino_delete_inode(inode, unlinked);
16086 + si_read_unlock(sb);
16090 + iinfo = au_ii(inode);
16091 + if (iinfo->ii_vdir)
16092 + au_vdir_free(iinfo->ii_vdir, /*atonce*/0);
16094 + bindex = iinfo->ii_btop;
16095 + if (bindex >= 0) {
16096 + hi = au_hinode(iinfo, bindex);
16097 + bbot = iinfo->ii_bbot;
16098 + while (bindex++ <= bbot) {
16099 + if (hi->hi_inode)
16104 + au_delayed_kfree(iinfo->ii_hinode);
16105 + AuRwDestroy(&iinfo->ii_rwsem);
16107 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
16108 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
16109 +++ linux/fs/aufs/inode.c 2016-10-09 16:55:38.889431135 +0200
16112 + * Copyright (C) 2005-2016 Junjiro R. Okajima
16114 + * This program, aufs is free software; you can redistribute it and/or modify
16115 + * it under the terms of the GNU General Public License as published by
16116 + * the Free Software Foundation; either version 2 of the License, or
16117 + * (at your option) any later version.
16119 + * This program is distributed in the hope that it will be useful,
16120 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16121 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16122 + * GNU General Public License for more details.
16124 + * You should have received a copy of the GNU General Public License
16125 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16129 + * inode functions
16134 +struct inode *au_igrab(struct inode *inode)
16137 + AuDebugOn(!atomic_read(&inode->i_count));
16143 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
16145 + au_cpup_attr_all(inode, /*force*/0);
16146 + au_update_iigen(inode, /*half*/1);
16148 + inode->i_version++;
16151 +static int au_ii_refresh(struct inode *inode, int *update)
16155 + aufs_bindex_t bindex, new_bindex;
16156 + struct super_block *sb;
16157 + struct au_iinfo *iinfo;
16158 + struct au_hinode *p, *q, tmp;
16160 + AuDebugOn(au_is_bad_inode(inode));
16161 + IiMustWriteLock(inode);
16164 + sb = inode->i_sb;
16165 + nbr = au_sbbot(sb) + 1;
16166 + type = inode->i_mode & S_IFMT;
16167 + iinfo = au_ii(inode);
16168 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
16169 + if (unlikely(err))
16172 + AuDebugOn(iinfo->ii_btop < 0);
16173 + p = au_hinode(iinfo, iinfo->ii_btop);
16174 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
16176 + if (!p->hi_inode)
16179 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
16180 + new_bindex = au_br_index(sb, p->hi_id);
16181 + if (new_bindex == bindex)
16184 + if (new_bindex < 0) {
16187 + p->hi_inode = NULL;
16191 + if (new_bindex < iinfo->ii_btop)
16192 + iinfo->ii_btop = new_bindex;
16193 + if (iinfo->ii_bbot < new_bindex)
16194 + iinfo->ii_bbot = new_bindex;
16195 + /* swap two lower inode, and loop again */
16196 + q = au_hinode(iinfo, new_bindex);
16200 + if (tmp.hi_inode) {
16205 + au_update_ibrange(inode, /*do_put_zero*/0);
16206 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
16207 + e = au_dy_irefresh(inode);
16208 + if (unlikely(e && !err))
16216 +void au_refresh_iop(struct inode *inode, int force_getattr)
16219 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
16220 + const struct inode_operations *iop
16221 + = force_getattr ? aufs_iop : sbi->si_iop_array;
16223 + if (inode->i_op == iop)
16226 + switch (inode->i_mode & S_IFMT) {
16228 + type = AuIop_DIR;
16231 + type = AuIop_SYMLINK;
16234 + type = AuIop_OTHER;
16238 + inode->i_op = iop + type;
16239 + /* unnecessary smp_wmb() */
16242 +int au_refresh_hinode_self(struct inode *inode)
16246 + err = au_ii_refresh(inode, &update);
16248 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
16254 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
16256 + int err, e, update;
16257 + unsigned int flags;
16259 + aufs_bindex_t bindex, bbot;
16260 + unsigned char isdir;
16261 + struct au_hinode *p;
16262 + struct au_iinfo *iinfo;
16264 + err = au_ii_refresh(inode, &update);
16265 + if (unlikely(err))
16269 + iinfo = au_ii(inode);
16270 + p = au_hinode(iinfo, iinfo->ii_btop);
16271 + mode = (inode->i_mode & S_IFMT);
16272 + isdir = S_ISDIR(mode);
16273 + flags = au_hi_flags(inode, isdir);
16274 + bbot = au_dbbot(dentry);
16275 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
16276 + struct inode *h_i, *h_inode;
16277 + struct dentry *h_d;
16279 + h_d = au_h_dptr(dentry, bindex);
16280 + if (!h_d || d_is_negative(h_d))
16283 + h_inode = d_inode(h_d);
16284 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
16285 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
16286 + h_i = au_h_iptr(inode, bindex);
16288 + if (h_i == h_inode)
16294 + if (bindex < iinfo->ii_btop)
16295 + iinfo->ii_btop = bindex;
16296 + if (iinfo->ii_bbot < bindex)
16297 + iinfo->ii_bbot = bindex;
16298 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
16301 + au_update_ibrange(inode, /*do_put_zero*/0);
16302 + e = au_dy_irefresh(inode);
16303 + if (unlikely(e && !err))
16306 + au_refresh_hinode_attr(inode, update && isdir);
16313 +static int set_inode(struct inode *inode, struct dentry *dentry)
16316 + unsigned int flags;
16318 + aufs_bindex_t bindex, btop, btail;
16319 + unsigned char isdir;
16320 + struct dentry *h_dentry;
16321 + struct inode *h_inode;
16322 + struct au_iinfo *iinfo;
16323 + struct inode_operations *iop;
16325 + IiMustWriteLock(inode);
16329 + iop = au_sbi(inode->i_sb)->si_iop_array;
16330 + btop = au_dbtop(dentry);
16331 + h_dentry = au_h_dptr(dentry, btop);
16332 + h_inode = d_inode(h_dentry);
16333 + mode = h_inode->i_mode;
16334 + switch (mode & S_IFMT) {
16336 + btail = au_dbtail(dentry);
16337 + inode->i_op = iop + AuIop_OTHER;
16338 + inode->i_fop = &aufs_file_fop;
16339 + err = au_dy_iaop(inode, btop, h_inode);
16340 + if (unlikely(err))
16345 + btail = au_dbtaildir(dentry);
16346 + inode->i_op = iop + AuIop_DIR;
16347 + inode->i_fop = &aufs_dir_fop;
16350 + btail = au_dbtail(dentry);
16351 + inode->i_op = iop + AuIop_SYMLINK;
16357 + btail = au_dbtail(dentry);
16358 + inode->i_op = iop + AuIop_OTHER;
16359 + init_special_inode(inode, mode, h_inode->i_rdev);
16362 + AuIOErr("Unknown file type 0%o\n", mode);
16367 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
16368 + flags = au_hi_flags(inode, isdir);
16369 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
16370 + && au_ftest_hi(flags, HNOTIFY)
16371 + && dentry->d_name.len > AUFS_WH_PFX_LEN
16372 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
16373 + au_fclr_hi(flags, HNOTIFY);
16374 + iinfo = au_ii(inode);
16375 + iinfo->ii_btop = btop;
16376 + iinfo->ii_bbot = btail;
16377 + for (bindex = btop; bindex <= btail; bindex++) {
16378 + h_dentry = au_h_dptr(dentry, bindex);
16380 + au_set_h_iptr(inode, bindex,
16381 + au_igrab(d_inode(h_dentry)), flags);
16383 + au_cpup_attr_all(inode, /*force*/1);
16385 + * to force calling aufs_get_acl() every time,
16386 + * do not call cache_no_acl() for aufs inode.
16394 + * successful returns with iinfo write_locked
16396 + * zero: success, matched
16397 + * plus: no error, but unmatched
16399 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16402 + unsigned int gen, igflags;
16403 + aufs_bindex_t bindex, bbot;
16404 + struct inode *h_inode, *h_dinode;
16405 + struct dentry *h_dentry;
16408 + * before this function, if aufs got any iinfo lock, it must be only
16409 + * one, the parent dir.
16410 + * it can happen by UDBA and the obsoleted inode number.
16413 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16417 + ii_write_lock_new_child(inode);
16418 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
16419 + h_dinode = d_inode(h_dentry);
16420 + bbot = au_ibbot(inode);
16421 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
16422 + h_inode = au_h_iptr(inode, bindex);
16423 + if (!h_inode || h_inode != h_dinode)
16427 + gen = au_iigen(inode, &igflags);
16428 + if (gen == au_digen(dentry)
16429 + && !au_ig_ftest(igflags, HALF_REFRESHED))
16432 + /* fully refresh inode using dentry */
16433 + err = au_refresh_hinode(inode, dentry);
16435 + au_update_iigen(inode, /*half*/0);
16439 + if (unlikely(err))
16440 + ii_write_unlock(inode);
16445 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16446 + unsigned int d_type, ino_t *ino)
16449 + struct mutex *mtx;
16451 + /* prevent hardlinked inode number from race condition */
16453 + if (d_type != DT_DIR) {
16454 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16457 + err = au_xino_read(sb, bindex, h_ino, ino);
16458 + if (unlikely(err))
16463 + *ino = au_xino_new_ino(sb);
16464 + if (unlikely(!*ino))
16466 + err = au_xino_write(sb, bindex, h_ino, *ino);
16467 + if (unlikely(err))
16473 + mutex_unlock(mtx);
16477 +/* successful returns with iinfo write_locked */
16478 +/* todo: return with unlocked? */
16479 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16481 + struct inode *inode, *h_inode;
16482 + struct dentry *h_dentry;
16483 + struct super_block *sb;
16484 + struct mutex *mtx;
16485 + ino_t h_ino, ino;
16487 + aufs_bindex_t btop;
16489 + sb = dentry->d_sb;
16490 + btop = au_dbtop(dentry);
16491 + h_dentry = au_h_dptr(dentry, btop);
16492 + h_inode = d_inode(h_dentry);
16493 + h_ino = h_inode->i_ino;
16496 + * stop 'race'-ing between hardlinks under different
16500 + if (!d_is_dir(h_dentry))
16501 + mtx = &au_sbr(sb, btop)->br_xino.xi_nondir_mtx;
16506 + err = au_xino_read(sb, btop, h_ino, &ino);
16507 + inode = ERR_PTR(err);
16508 + if (unlikely(err))
16512 + ino = au_xino_new_ino(sb);
16513 + if (unlikely(!ino)) {
16514 + inode = ERR_PTR(-EIO);
16519 + AuDbg("i%lu\n", (unsigned long)ino);
16520 + inode = au_iget_locked(sb, ino);
16521 + err = PTR_ERR(inode);
16522 + if (IS_ERR(inode))
16525 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16526 + if (inode->i_state & I_NEW) {
16527 + ii_write_lock_new_child(inode);
16528 + err = set_inode(inode, dentry);
16530 + unlock_new_inode(inode);
16531 + goto out; /* success */
16535 + * iget_failed() calls iput(), but we need to call
16536 + * ii_write_unlock() after iget_failed(). so dirty hack for
16539 + atomic_inc(&inode->i_count);
16540 + iget_failed(inode);
16541 + ii_write_unlock(inode);
16542 + au_xino_write(sb, btop, h_ino, /*ino*/0);
16543 + /* ignore this error */
16545 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16547 + * horrible race condition between lookup, readdir and copyup
16548 + * (or something).
16551 + mutex_unlock(mtx);
16552 + err = reval_inode(inode, dentry);
16553 + if (unlikely(err < 0)) {
16560 + goto out; /* success */
16565 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16566 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16567 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16568 + btop, au_sbtype(h_dentry->d_sb), dentry,
16569 + (unsigned long)h_ino, (unsigned long)ino);
16571 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
16575 + mutex_unlock(mtx);
16581 + inode = ERR_PTR(err);
16584 + mutex_unlock(mtx);
16588 +/* ---------------------------------------------------------------------- */
16590 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16591 + struct inode *inode)
16594 + struct inode *hi;
16596 + err = au_br_rdonly(au_sbr(sb, bindex));
16598 + /* pseudo-link after flushed may happen out of bounds */
16601 + && au_ibtop(inode) <= bindex
16602 + && bindex <= au_ibbot(inode)) {
16604 + * permission check is unnecessary since vfsub routine
16605 + * will be called later
16607 + hi = au_h_iptr(inode, bindex);
16609 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16615 +int au_test_h_perm(struct inode *h_inode, int mask)
16617 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16619 + return inode_permission(h_inode, mask);
16622 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16624 + if (au_test_nfs(h_inode->i_sb)
16625 + && (mask & MAY_WRITE)
16626 + && S_ISDIR(h_inode->i_mode))
16627 + mask |= MAY_READ; /* force permission check */
16628 + return au_test_h_perm(h_inode, mask);
16630 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16631 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16632 +++ linux/fs/aufs/inode.h 2016-10-09 16:55:38.889431135 +0200
16635 + * Copyright (C) 2005-2016 Junjiro R. Okajima
16637 + * This program, aufs is free software; you can redistribute it and/or modify
16638 + * it under the terms of the GNU General Public License as published by
16639 + * the Free Software Foundation; either version 2 of the License, or
16640 + * (at your option) any later version.
16642 + * This program is distributed in the hope that it will be useful,
16643 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16644 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16645 + * GNU General Public License for more details.
16647 + * You should have received a copy of the GNU General Public License
16648 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16652 + * inode operations
16655 +#ifndef __AUFS_INODE_H__
16656 +#define __AUFS_INODE_H__
16660 +#include <linux/fsnotify.h>
16661 +#include "rwsem.h"
16665 +struct au_hnotify {
16666 +#ifdef CONFIG_AUFS_HNOTIFY
16667 +#ifdef CONFIG_AUFS_HFSNOTIFY
16668 + /* never use fsnotify_add_vfsmount_mark() */
16669 + struct fsnotify_mark hn_mark;
16672 + struct inode *hn_aufs_inode; /* no get/put */
16673 + struct llist_node hn_lnode; /* delayed free */
16676 +} ____cacheline_aligned_in_smp;
16678 +struct au_hinode {
16679 + struct inode *hi_inode;
16680 + aufs_bindex_t hi_id;
16681 +#ifdef CONFIG_AUFS_HNOTIFY
16682 + struct au_hnotify *hi_notify;
16685 + /* reference to the copied-up whiteout with get/put */
16686 + struct dentry *hi_whdentry;
16690 +#define AuIG_HALF_REFRESHED 1
16691 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16692 +#define au_ig_fset(flags, name) \
16693 + do { (flags) |= AuIG_##name; } while (0)
16694 +#define au_ig_fclr(flags, name) \
16695 + do { (flags) &= ~AuIG_##name; } while (0)
16698 + spinlock_t ig_spin;
16699 + __u32 ig_generation, ig_flags;
16704 + struct au_iigen ii_generation;
16705 + struct super_block *ii_hsb1; /* no get/put */
16707 + struct au_rwsem ii_rwsem;
16708 + aufs_bindex_t ii_btop, ii_bbot;
16710 + struct au_hinode *ii_hinode;
16711 + struct au_vdir *ii_vdir;
16714 +struct au_icntnr {
16715 + struct au_iinfo iinfo;
16716 + struct inode vfs_inode;
16718 + struct hlist_node plink;
16719 + struct llist_node lnode; /* delayed free */
16721 +} ____cacheline_aligned_in_smp;
16723 +/* au_pin flags */
16724 +#define AuPin_DI_LOCKED 1
16725 +#define AuPin_MNT_WRITE (1 << 1)
16726 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16727 +#define au_fset_pin(flags, name) \
16728 + do { (flags) |= AuPin_##name; } while (0)
16729 +#define au_fclr_pin(flags, name) \
16730 + do { (flags) &= ~AuPin_##name; } while (0)
16734 + struct dentry *dentry;
16735 + unsigned int udba;
16736 + unsigned char lsc_di, lsc_hi, flags;
16737 + aufs_bindex_t bindex;
16740 + struct dentry *parent;
16741 + struct au_hinode *hdir;
16742 + struct vfsmount *h_mnt;
16744 + /* temporary unlock/relock for copyup */
16745 + struct dentry *h_dentry, *h_parent;
16746 + struct au_branch *br;
16747 + struct task_struct *task;
16750 +void au_pin_hdir_unlock(struct au_pin *p);
16751 +int au_pin_hdir_lock(struct au_pin *p);
16752 +int au_pin_hdir_relock(struct au_pin *p);
16753 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16754 +void au_pin_hdir_release(struct au_pin *p);
16756 +/* ---------------------------------------------------------------------- */
16758 +static inline struct au_iinfo *au_ii(struct inode *inode)
16760 + BUG_ON(is_bad_inode(inode));
16761 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16764 +/* ---------------------------------------------------------------------- */
16767 +struct inode *au_igrab(struct inode *inode);
16768 +void au_refresh_iop(struct inode *inode, int force_getattr);
16769 +int au_refresh_hinode_self(struct inode *inode);
16770 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16771 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16772 + unsigned int d_type, ino_t *ino);
16773 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16774 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16775 + struct inode *inode);
16776 +int au_test_h_perm(struct inode *h_inode, int mask);
16777 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16779 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16780 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16782 +#ifdef CONFIG_AUFS_SHWH
16783 + return au_ino(sb, bindex, h_ino, d_type, ino);
16796 +extern struct inode_operations aufs_iop[AuIop_Last],
16797 + aufs_iop_nogetattr[AuIop_Last];
16799 +/* au_wr_dir flags */
16800 +#define AuWrDir_ADD_ENTRY 1
16801 +#define AuWrDir_ISDIR (1 << 1)
16802 +#define AuWrDir_TMPFILE (1 << 2)
16803 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16804 +#define au_fset_wrdir(flags, name) \
16805 + do { (flags) |= AuWrDir_##name; } while (0)
16806 +#define au_fclr_wrdir(flags, name) \
16807 + do { (flags) &= ~AuWrDir_##name; } while (0)
16809 +struct au_wr_dir_args {
16810 + aufs_bindex_t force_btgt;
16811 + unsigned char flags;
16813 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16814 + struct au_wr_dir_args *args);
16816 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16817 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16818 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16819 + unsigned int udba, unsigned char flags);
16820 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16821 + unsigned int udba, unsigned char flags) __must_check;
16822 +int au_do_pin(struct au_pin *pin) __must_check;
16823 +void au_unpin(struct au_pin *pin);
16824 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16826 +#define AuIcpup_DID_CPUP 1
16827 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16828 +#define au_fset_icpup(flags, name) \
16829 + do { (flags) |= AuIcpup_##name; } while (0)
16830 +#define au_fclr_icpup(flags, name) \
16831 + do { (flags) &= ~AuIcpup_##name; } while (0)
16833 +struct au_icpup_args {
16834 + unsigned char flags;
16835 + unsigned char pin_flags;
16836 + aufs_bindex_t btgt;
16837 + unsigned int udba;
16838 + struct au_pin pin;
16839 + struct path h_path;
16840 + struct inode *h_inode;
16843 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16844 + struct au_icpup_args *a);
16846 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16849 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16850 + struct dentry *h_parent, int isdir);
16851 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16853 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16854 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16856 +struct vfsub_aopen_args;
16857 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
16858 + struct vfsub_aopen_args *args);
16859 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16860 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16861 + struct dentry *dentry);
16862 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16865 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16866 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16867 + struct dentry *h_parent, int isdir);
16868 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16869 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16872 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16873 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16874 + struct inode *dir, struct dentry *dentry);
16877 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16878 +void au_hiput(struct au_hinode *hinode);
16879 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16880 + struct dentry *h_wh);
16881 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16883 +/* hinode flags */
16884 +#define AuHi_XINO 1
16885 +#define AuHi_HNOTIFY (1 << 1)
16886 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16887 +#define au_fset_hi(flags, name) \
16888 + do { (flags) |= AuHi_##name; } while (0)
16889 +#define au_fclr_hi(flags, name) \
16890 + do { (flags) &= ~AuHi_##name; } while (0)
16892 +#ifndef CONFIG_AUFS_HNOTIFY
16893 +#undef AuHi_HNOTIFY
16894 +#define AuHi_HNOTIFY 0
16897 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16898 + struct inode *h_inode, unsigned int flags);
16900 +void au_update_iigen(struct inode *inode, int half);
16901 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16903 +void au_icntnr_init_once(void *_c);
16904 +void au_hinode_init(struct au_hinode *hinode);
16905 +int au_iinfo_init(struct inode *inode);
16906 +void au_iinfo_fin(struct inode *inode);
16907 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
16909 +#ifdef CONFIG_PROC_FS
16911 +int au_plink_maint(struct super_block *sb, int flags);
16913 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16914 +int au_plink_maint_enter(struct super_block *sb);
16915 +#ifdef CONFIG_AUFS_DEBUG
16916 +void au_plink_list(struct super_block *sb);
16918 +AuStubVoid(au_plink_list, struct super_block *sb)
16920 +int au_plink_test(struct inode *inode);
16921 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16922 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16923 + struct dentry *h_dentry);
16924 +void au_plink_put(struct super_block *sb, int verbose);
16925 +void au_plink_clean(struct super_block *sb, int verbose);
16926 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16928 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16929 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16930 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16931 +AuStubVoid(au_plink_list, struct super_block *sb);
16932 +AuStubInt0(au_plink_test, struct inode *inode);
16933 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16934 + struct inode *inode, aufs_bindex_t bindex);
16935 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16936 + struct dentry *h_dentry);
16937 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16938 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16939 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16940 +#endif /* CONFIG_PROC_FS */
16942 +#ifdef CONFIG_AUFS_XATTR
16944 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
16945 + unsigned int verbose);
16946 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16947 +ssize_t aufs_getxattr(struct dentry *dentry, struct inode *inode,
16948 + const char *name, void *value, size_t size);
16949 +int aufs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
16950 + const void *value, size_t size, int flags);
16951 +int aufs_removexattr(struct dentry *dentry, const char *name);
16953 +/* void au_xattr_init(struct super_block *sb); */
16955 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16956 + int ignore_flags, unsigned int verbose);
16957 +/* AuStubVoid(au_xattr_init, struct super_block *sb); */
16960 +#ifdef CONFIG_FS_POSIX_ACL
16961 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16962 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16965 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16972 +struct au_srxattr {
16976 + const char *name;
16977 + const void *value;
16982 + const char *name;
16985 + struct posix_acl *acl;
16990 +ssize_t au_srxattr(struct dentry *dentry, struct inode *inode,
16991 + struct au_srxattr *arg);
16994 +/* ---------------------------------------------------------------------- */
16996 +/* lock subclass for iinfo */
16998 + AuLsc_II_CHILD, /* child first */
16999 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
17000 + AuLsc_II_CHILD3, /* copyup dirs */
17001 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
17002 + AuLsc_II_PARENT2,
17003 + AuLsc_II_PARENT3, /* copyup dirs */
17004 + AuLsc_II_NEW_CHILD
17008 + * ii_read_lock_child, ii_write_lock_child,
17009 + * ii_read_lock_child2, ii_write_lock_child2,
17010 + * ii_read_lock_child3, ii_write_lock_child3,
17011 + * ii_read_lock_parent, ii_write_lock_parent,
17012 + * ii_read_lock_parent2, ii_write_lock_parent2,
17013 + * ii_read_lock_parent3, ii_write_lock_parent3,
17014 + * ii_read_lock_new_child, ii_write_lock_new_child,
17016 +#define AuReadLockFunc(name, lsc) \
17017 +static inline void ii_read_lock_##name(struct inode *i) \
17019 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
17022 +#define AuWriteLockFunc(name, lsc) \
17023 +static inline void ii_write_lock_##name(struct inode *i) \
17025 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
17028 +#define AuRWLockFuncs(name, lsc) \
17029 + AuReadLockFunc(name, lsc) \
17030 + AuWriteLockFunc(name, lsc)
17032 +AuRWLockFuncs(child, CHILD);
17033 +AuRWLockFuncs(child2, CHILD2);
17034 +AuRWLockFuncs(child3, CHILD3);
17035 +AuRWLockFuncs(parent, PARENT);
17036 +AuRWLockFuncs(parent2, PARENT2);
17037 +AuRWLockFuncs(parent3, PARENT3);
17038 +AuRWLockFuncs(new_child, NEW_CHILD);
17040 +#undef AuReadLockFunc
17041 +#undef AuWriteLockFunc
17042 +#undef AuRWLockFuncs
17045 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
17047 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
17049 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
17050 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
17051 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
17053 +/* ---------------------------------------------------------------------- */
17055 +static inline void au_icntnr_init(struct au_icntnr *c)
17057 +#ifdef CONFIG_AUFS_DEBUG
17058 + c->vfs_inode.i_mode = 0;
17062 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
17064 + unsigned int gen;
17065 + struct au_iinfo *iinfo;
17066 + struct au_iigen *iigen;
17068 + iinfo = au_ii(inode);
17069 + iigen = &iinfo->ii_generation;
17070 + spin_lock(&iigen->ig_spin);
17072 + *igflags = iigen->ig_flags;
17073 + gen = iigen->ig_generation;
17074 + spin_unlock(&iigen->ig_spin);
17079 +/* tiny test for inode number */
17080 +/* tmpfs generation is too rough */
17081 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
17083 + struct au_iinfo *iinfo;
17085 + iinfo = au_ii(inode);
17086 + AuRwMustAnyLock(&iinfo->ii_rwsem);
17087 + return !(iinfo->ii_hsb1 == h_inode->i_sb
17088 + && iinfo->ii_higen == h_inode->i_generation);
17091 +static inline void au_iigen_dec(struct inode *inode)
17093 + struct au_iinfo *iinfo;
17094 + struct au_iigen *iigen;
17096 + iinfo = au_ii(inode);
17097 + iigen = &iinfo->ii_generation;
17098 + spin_lock(&iigen->ig_spin);
17099 + iigen->ig_generation--;
17100 + spin_unlock(&iigen->ig_spin);
17103 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
17108 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
17114 +/* ---------------------------------------------------------------------- */
17116 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
17117 + aufs_bindex_t bindex)
17119 + return iinfo->ii_hinode + bindex;
17122 +static inline int au_is_bad_inode(struct inode *inode)
17124 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
17127 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
17128 + aufs_bindex_t bindex)
17130 + IiMustAnyLock(inode);
17131 + return au_hinode(au_ii(inode), bindex)->hi_id;
17134 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
17136 + IiMustAnyLock(inode);
17137 + return au_ii(inode)->ii_btop;
17140 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
17142 + IiMustAnyLock(inode);
17143 + return au_ii(inode)->ii_bbot;
17146 +static inline struct au_vdir *au_ivdir(struct inode *inode)
17148 + IiMustAnyLock(inode);
17149 + return au_ii(inode)->ii_vdir;
17152 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
17154 + IiMustAnyLock(inode);
17155 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
17158 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
17160 + IiMustWriteLock(inode);
17161 + au_ii(inode)->ii_btop = bindex;
17164 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
17166 + IiMustWriteLock(inode);
17167 + au_ii(inode)->ii_bbot = bindex;
17170 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
17172 + IiMustWriteLock(inode);
17173 + au_ii(inode)->ii_vdir = vdir;
17176 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
17178 + IiMustAnyLock(inode);
17179 + return au_hinode(au_ii(inode), bindex);
17182 +/* ---------------------------------------------------------------------- */
17184 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
17187 + return pin->parent;
17191 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
17193 + if (pin && pin->hdir)
17194 + return pin->hdir->hi_inode;
17198 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
17201 + return pin->hdir;
17205 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
17208 + pin->dentry = dentry;
17211 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
17212 + unsigned char lflag)
17216 + au_fset_pin(pin->flags, DI_LOCKED);
17218 + au_fclr_pin(pin->flags, DI_LOCKED);
17222 +#if 0 /* reserved */
17223 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
17226 + dput(pin->parent);
17227 + pin->parent = dget(parent);
17232 +/* ---------------------------------------------------------------------- */
17235 +#ifdef CONFIG_AUFS_HNOTIFY
17236 +struct au_hnotify_op {
17237 + void (*ctl)(struct au_hinode *hinode, int do_set);
17238 + int (*alloc)(struct au_hinode *hinode);
17241 + * if it returns true, the the caller should free hinode->hi_notify,
17242 + * otherwise ->free() frees it.
17244 + int (*free)(struct au_hinode *hinode,
17245 + struct au_hnotify *hn) __must_check;
17247 + void (*fin)(void);
17248 + int (*init)(void);
17250 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
17251 + void (*fin_br)(struct au_branch *br);
17252 + int (*init_br)(struct au_branch *br, int perm);
17256 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
17257 +void au_hn_free(struct au_hinode *hinode);
17258 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
17259 +void au_hn_reset(struct inode *inode, unsigned int flags);
17260 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17261 + struct qstr *h_child_qstr, struct inode *h_child_inode);
17262 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
17263 +int au_hnotify_init_br(struct au_branch *br, int perm);
17264 +void au_hnotify_fin_br(struct au_branch *br);
17265 +int __init au_hnotify_init(void);
17266 +void au_hnotify_fin(void);
17269 +extern const struct au_hnotify_op au_hnotify_op;
17272 +void au_hn_init(struct au_hinode *hinode)
17274 + hinode->hi_notify = NULL;
17277 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
17279 + return hinode->hi_notify;
17283 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
17284 + struct au_hinode *hinode __maybe_unused,
17285 + struct inode *inode __maybe_unused)
17286 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
17287 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
17288 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
17289 + int do_set __maybe_unused)
17290 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
17291 + unsigned int flags __maybe_unused)
17292 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
17293 + struct au_branch *br __maybe_unused,
17294 + int perm __maybe_unused)
17295 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
17296 + int perm __maybe_unused)
17297 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
17298 +AuStubInt0(__init au_hnotify_init, void)
17299 +AuStubVoid(au_hnotify_fin, void)
17300 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
17301 +#endif /* CONFIG_AUFS_HNOTIFY */
17303 +static inline void au_hn_suspend(struct au_hinode *hdir)
17305 + au_hn_ctl(hdir, /*do_set*/0);
17308 +static inline void au_hn_resume(struct au_hinode *hdir)
17310 + au_hn_ctl(hdir, /*do_set*/1);
17313 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
17315 + inode_lock(hdir->hi_inode);
17316 + au_hn_suspend(hdir);
17319 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
17320 + unsigned int sc __maybe_unused)
17322 + inode_lock_nested(hdir->hi_inode, sc);
17323 + au_hn_suspend(hdir);
17326 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
17328 + au_hn_resume(hdir);
17329 + inode_unlock(hdir->hi_inode);
17332 +#endif /* __KERNEL__ */
17333 +#endif /* __AUFS_INODE_H__ */
17334 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
17335 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
17336 +++ linux/fs/aufs/ioctl.c 2016-10-09 16:55:36.492701639 +0200
17339 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17341 + * This program, aufs is free software; you can redistribute it and/or modify
17342 + * it under the terms of the GNU General Public License as published by
17343 + * the Free Software Foundation; either version 2 of the License, or
17344 + * (at your option) any later version.
17346 + * This program is distributed in the hope that it will be useful,
17347 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17348 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17349 + * GNU General Public License for more details.
17351 + * You should have received a copy of the GNU General Public License
17352 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17357 + * plink-management and readdir in userspace.
17358 + * assist the pathconf(3) wrapper library.
17360 + * File-based Hierarchical Storage Management.
17363 +#include <linux/compat.h>
17364 +#include <linux/file.h>
17367 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
17370 + aufs_bindex_t wbi, bindex, bbot;
17371 + struct file *h_file;
17372 + struct super_block *sb;
17373 + struct dentry *root;
17374 + struct au_branch *br;
17375 + struct aufs_wbr_fd wbrfd = {
17376 + .oflags = au_dir_roflags,
17379 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17380 + | O_NOATIME | O_CLOEXEC;
17382 + AuDebugOn(wbrfd.oflags & ~valid);
17385 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17386 + if (unlikely(err)) {
17392 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17393 + wbrfd.oflags |= au_dir_roflags;
17394 + AuDbg("0%o\n", wbrfd.oflags);
17395 + if (unlikely(wbrfd.oflags & ~valid))
17399 + fd = get_unused_fd_flags(0);
17401 + if (unlikely(fd < 0))
17404 + h_file = ERR_PTR(-EINVAL);
17407 + sb = path->dentry->d_sb;
17408 + root = sb->s_root;
17409 + aufs_read_lock(root, AuLock_IR);
17410 + bbot = au_sbbot(sb);
17411 + if (wbrfd.brid >= 0) {
17412 + wbi = au_br_index(sb, wbrfd.brid);
17413 + if (unlikely(wbi < 0 || wbi > bbot))
17417 + h_file = ERR_PTR(-ENOENT);
17418 + br = au_sbr(sb, wbi);
17419 + if (!au_br_writable(br->br_perm)) {
17423 + bindex = wbi + 1;
17425 + for (; bindex <= bbot; bindex++) {
17426 + br = au_sbr(sb, bindex);
17427 + if (au_br_writable(br->br_perm)) {
17429 + br = au_sbr(sb, wbi);
17434 + AuDbg("wbi %d\n", wbi);
17436 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17440 + aufs_read_unlock(root, AuLock_IR);
17441 + err = PTR_ERR(h_file);
17442 + if (IS_ERR(h_file))
17445 + au_br_put(br); /* cf. au_h_open() */
17446 + fd_install(fd, h_file);
17448 + goto out; /* success */
17451 + put_unused_fd(fd);
17457 +/* ---------------------------------------------------------------------- */
17459 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17462 + struct dentry *dentry;
17465 + case AUFS_CTL_RDU:
17466 + case AUFS_CTL_RDU_INO:
17467 + err = au_rdu_ioctl(file, cmd, arg);
17470 + case AUFS_CTL_WBR_FD:
17471 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17474 + case AUFS_CTL_IBUSY:
17475 + err = au_ibusy_ioctl(file, arg);
17478 + case AUFS_CTL_BRINFO:
17479 + err = au_brinfo_ioctl(file, arg);
17482 + case AUFS_CTL_FHSM_FD:
17483 + dentry = file->f_path.dentry;
17484 + if (IS_ROOT(dentry))
17485 + err = au_fhsm_fd(dentry->d_sb, arg);
17491 + /* do not call the lower */
17492 + AuDbg("0x%x\n", cmd);
17500 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17505 + case AUFS_CTL_MVDOWN:
17506 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17509 + case AUFS_CTL_WBR_FD:
17510 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17514 + /* do not call the lower */
17515 + AuDbg("0x%x\n", cmd);
17523 +#ifdef CONFIG_COMPAT
17524 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17525 + unsigned long arg)
17530 + case AUFS_CTL_RDU:
17531 + case AUFS_CTL_RDU_INO:
17532 + err = au_rdu_compat_ioctl(file, cmd, arg);
17535 + case AUFS_CTL_IBUSY:
17536 + err = au_ibusy_compat_ioctl(file, arg);
17539 + case AUFS_CTL_BRINFO:
17540 + err = au_brinfo_compat_ioctl(file, arg);
17544 + err = aufs_ioctl_dir(file, cmd, arg);
17551 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17552 + unsigned long arg)
17554 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17557 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17558 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17559 +++ linux/fs/aufs/i_op_add.c 2016-10-09 16:55:36.492701639 +0200
17562 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17564 + * This program, aufs is free software; you can redistribute it and/or modify
17565 + * it under the terms of the GNU General Public License as published by
17566 + * the Free Software Foundation; either version 2 of the License, or
17567 + * (at your option) any later version.
17569 + * This program is distributed in the hope that it will be useful,
17570 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17571 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17572 + * GNU General Public License for more details.
17574 + * You should have received a copy of the GNU General Public License
17575 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17579 + * inode operations (add entry)
17585 + * final procedure of adding a new entry, except link(2).
17586 + * remove whiteout, instantiate, copyup the parent dir's times and size
17587 + * and update version.
17588 + * if it failed, re-create the removed whiteout.
17590 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17591 + struct dentry *wh_dentry, struct dentry *dentry)
17594 + aufs_bindex_t bwh;
17595 + struct path h_path;
17596 + struct super_block *sb;
17597 + struct inode *inode, *h_dir;
17598 + struct dentry *wh;
17603 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17604 + IMustLock(h_dir);
17605 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17606 + bwh = au_dbwh(dentry);
17607 + h_path.dentry = wh_dentry;
17608 + h_path.mnt = au_sbr_mnt(sb, bindex);
17609 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17611 + if (unlikely(err))
17615 + inode = au_new_inode(dentry, /*must_new*/1);
17616 + if (!IS_ERR(inode)) {
17617 + d_instantiate(dentry, inode);
17618 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17620 + au_dir_ts(dir, bindex);
17621 + dir->i_version++;
17622 + au_fhsm_wrote(sb, bindex, /*force*/0);
17623 + return 0; /* success */
17626 + err = PTR_ERR(inode);
17631 + /* dir inode is locked */
17632 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17633 + rerr = PTR_ERR(wh);
17634 + if (IS_ERR(wh)) {
17635 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17636 + dentry, err, rerr);
17645 +static int au_d_may_add(struct dentry *dentry)
17650 + if (unlikely(d_unhashed(dentry)))
17652 + if (unlikely(d_really_is_positive(dentry)))
17658 + * simple tests for the adding inode operations.
17659 + * following the checks in vfs, plus the parent-child relationship.
17661 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17662 + struct dentry *h_parent, int isdir)
17666 + struct dentry *h_dentry;
17667 + struct inode *h_inode;
17669 + err = -ENAMETOOLONG;
17670 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17673 + h_dentry = au_h_dptr(dentry, bindex);
17674 + if (d_really_is_negative(dentry)) {
17676 + if (unlikely(d_is_positive(h_dentry)))
17679 + /* rename(2) case */
17681 + if (unlikely(d_is_negative(h_dentry)))
17683 + h_inode = d_inode(h_dentry);
17684 + if (unlikely(!h_inode->i_nlink))
17687 + h_mode = h_inode->i_mode;
17690 + if (unlikely(S_ISDIR(h_mode)))
17692 + } else if (unlikely(!S_ISDIR(h_mode))) {
17699 + /* expected parent dir is locked */
17700 + if (unlikely(h_parent != h_dentry->d_parent))
17709 + * initial procedure of adding a new entry.
17710 + * prepare writable branch and the parent dir, lock it,
17711 + * and lookup whiteout for the new entry.
17713 +static struct dentry*
17714 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17715 + struct dentry *src_dentry, struct au_pin *pin,
17716 + struct au_wr_dir_args *wr_dir_args)
17718 + struct dentry *wh_dentry, *h_parent;
17719 + struct super_block *sb;
17720 + struct au_branch *br;
17722 + unsigned int udba;
17723 + aufs_bindex_t bcpup;
17725 + AuDbg("%pd\n", dentry);
17727 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17729 + wh_dentry = ERR_PTR(err);
17730 + if (unlikely(err < 0))
17733 + sb = dentry->d_sb;
17734 + udba = au_opt_udba(sb);
17735 + err = au_pin(pin, dentry, bcpup, udba,
17736 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17737 + wh_dentry = ERR_PTR(err);
17738 + if (unlikely(err))
17741 + h_parent = au_pinned_h_parent(pin);
17742 + if (udba != AuOpt_UDBA_NONE
17743 + && au_dbtop(dentry) == bcpup)
17744 + err = au_may_add(dentry, bcpup, h_parent,
17745 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17746 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17747 + err = -ENAMETOOLONG;
17748 + wh_dentry = ERR_PTR(err);
17749 + if (unlikely(err))
17752 + br = au_sbr(sb, bcpup);
17754 + struct path tmp = {
17755 + .dentry = h_parent,
17756 + .mnt = au_br_mnt(br)
17758 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17761 + wh_dentry = NULL;
17762 + if (bcpup != au_dbwh(dentry))
17763 + goto out; /* success */
17766 + * ENAMETOOLONG here means that if we allowed create such name, then it
17767 + * would not be able to removed in the future. So we don't allow such
17768 + * name here and we don't handle ENAMETOOLONG differently here.
17770 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17773 + if (IS_ERR(wh_dentry))
17776 + return wh_dentry;
17779 +/* ---------------------------------------------------------------------- */
17781 +enum { Mknod, Symlink, Creat };
17782 +struct simple_arg {
17789 + struct vfsub_aopen_args *aopen;
17792 + const char *symname;
17801 +static int add_simple(struct inode *dir, struct dentry *dentry,
17802 + struct simple_arg *arg)
17805 + aufs_bindex_t btop;
17806 + unsigned char created;
17807 + const unsigned char try_aopen
17808 + = (arg->type == Creat && arg->u.c.try_aopen);
17809 + struct dentry *wh_dentry, *parent;
17810 + struct inode *h_dir;
17811 + struct super_block *sb;
17812 + struct au_branch *br;
17813 + /* to reuduce stack size */
17815 + struct au_dtime dt;
17816 + struct au_pin pin;
17817 + struct path h_path;
17818 + struct au_wr_dir_args wr_dir_args;
17821 + AuDbg("%pd\n", dentry);
17825 + a = kmalloc(sizeof(*a), GFP_NOFS);
17826 + if (unlikely(!a))
17828 + a->wr_dir_args.force_btgt = -1;
17829 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17831 + parent = dentry->d_parent; /* dir inode is locked */
17832 + if (!try_aopen) {
17833 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17834 + if (unlikely(err))
17837 + err = au_d_may_add(dentry);
17838 + if (unlikely(err))
17841 + di_write_lock_parent(parent);
17842 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17843 + &a->pin, &a->wr_dir_args);
17844 + err = PTR_ERR(wh_dentry);
17845 + if (IS_ERR(wh_dentry))
17848 + btop = au_dbtop(dentry);
17849 + sb = dentry->d_sb;
17850 + br = au_sbr(sb, btop);
17851 + a->h_path.dentry = au_h_dptr(dentry, btop);
17852 + a->h_path.mnt = au_br_mnt(br);
17853 + h_dir = au_pinned_h_dir(&a->pin);
17854 + switch (arg->type) {
17857 + if (!try_aopen || !h_dir->i_op->atomic_open)
17858 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17859 + arg->u.c.want_excl);
17861 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
17862 + arg->u.c.aopen, br);
17865 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17868 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17876 + err = epilog(dir, btop, wh_dentry, dentry);
17879 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
17880 + /* no delegation since it is just created */
17881 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17884 + AuIOErr("%pd revert failure(%d, %d)\n",
17885 + dentry, err, rerr);
17888 + au_dtime_revert(&a->dt);
17891 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
17892 + *arg->u.c.aopen->opened |= FILE_CREATED;
17894 + au_unpin(&a->pin);
17899 + di_write_unlock(parent);
17901 + if (unlikely(err)) {
17902 + au_update_dbtop(dentry);
17906 + aufs_read_unlock(dentry, AuLock_DW);
17908 + au_delayed_kfree(a);
17913 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17916 + struct simple_arg arg = {
17923 + return add_simple(dir, dentry, &arg);
17926 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17928 + struct simple_arg arg = {
17930 + .u.s.symname = symname
17932 + return add_simple(dir, dentry, &arg);
17935 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17938 + struct simple_arg arg = {
17942 + .want_excl = want_excl
17945 + return add_simple(dir, dentry, &arg);
17948 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17949 + struct vfsub_aopen_args *aopen_args)
17951 + struct simple_arg arg = {
17954 + .mode = aopen_args->create_mode,
17955 + .want_excl = aopen_args->open_flag & O_EXCL,
17956 + .try_aopen = true,
17957 + .aopen = aopen_args
17960 + return add_simple(dir, dentry, &arg);
17963 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17966 + aufs_bindex_t bindex;
17967 + struct super_block *sb;
17968 + struct dentry *parent, *h_parent, *h_dentry;
17969 + struct inode *h_dir, *inode;
17970 + struct vfsmount *h_mnt;
17971 + struct au_wr_dir_args wr_dir_args = {
17972 + .force_btgt = -1,
17973 + .flags = AuWrDir_TMPFILE
17976 + /* copy-up may happen */
17980 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17981 + if (unlikely(err))
17984 + err = au_di_init(dentry);
17985 + if (unlikely(err))
17989 + parent = d_find_any_alias(dir);
17990 + AuDebugOn(!parent);
17991 + di_write_lock_parent(parent);
17992 + if (unlikely(d_inode(parent) != dir))
17995 + err = au_digen_test(parent, au_sigen(sb));
17996 + if (unlikely(err))
17999 + bindex = au_dbtop(parent);
18000 + au_set_dbtop(dentry, bindex);
18001 + au_set_dbbot(dentry, bindex);
18002 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
18004 + if (unlikely(err < 0))
18007 + err = -EOPNOTSUPP;
18008 + h_dir = au_h_iptr(dir, bindex);
18009 + if (unlikely(!h_dir->i_op->tmpfile))
18012 + h_mnt = au_sbr_mnt(sb, bindex);
18013 + err = vfsub_mnt_want_write(h_mnt);
18014 + if (unlikely(err))
18017 + h_parent = au_h_dptr(parent, bindex);
18018 + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC);
18019 + if (unlikely(err))
18023 + h_dentry = d_alloc(h_parent, &dentry->d_name);
18024 + if (unlikely(!h_dentry))
18027 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
18028 + if (unlikely(err))
18031 + au_set_dbtop(dentry, bindex);
18032 + au_set_dbbot(dentry, bindex);
18033 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
18034 + inode = au_new_inode(dentry, /*must_new*/1);
18035 + if (IS_ERR(inode)) {
18036 + err = PTR_ERR(inode);
18037 + au_set_h_dptr(dentry, bindex, NULL);
18038 + au_set_dbtop(dentry, -1);
18039 + au_set_dbbot(dentry, -1);
18041 + if (!inode->i_nlink)
18042 + set_nlink(inode, 1);
18043 + d_tmpfile(dentry, inode);
18044 + au_di(dentry)->di_tmpfile = 1;
18046 + /* update without i_mutex */
18047 + if (au_ibtop(dir) == au_dbtop(dentry))
18048 + au_cpup_attr_timesizes(dir);
18054 + vfsub_mnt_drop_write(h_mnt);
18056 + di_write_unlock(parent);
18058 + di_write_unlock(dentry);
18059 + if (unlikely(err)) {
18060 + au_di_fin(dentry);
18061 + dentry->d_fsdata = NULL;
18064 + si_read_unlock(sb);
18066 + inode_unlock(dir);
18070 +/* ---------------------------------------------------------------------- */
18072 +struct au_link_args {
18073 + aufs_bindex_t bdst, bsrc;
18074 + struct au_pin pin;
18075 + struct path h_path;
18076 + struct dentry *src_parent, *parent;
18079 +static int au_cpup_before_link(struct dentry *src_dentry,
18080 + struct au_link_args *a)
18083 + struct dentry *h_src_dentry;
18084 + struct au_cp_generic cpg = {
18085 + .dentry = src_dentry,
18090 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
18093 + di_read_lock_parent(a->src_parent, AuLock_IR);
18094 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
18095 + if (unlikely(err))
18098 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
18099 + err = au_pin(&a->pin, src_dentry, a->bdst,
18100 + au_opt_udba(src_dentry->d_sb),
18101 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18102 + if (unlikely(err))
18105 + err = au_sio_cpup_simple(&cpg);
18106 + au_unpin(&a->pin);
18109 + di_read_unlock(a->src_parent, AuLock_IR);
18113 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
18114 + struct au_link_args *a)
18117 + unsigned char plink;
18118 + aufs_bindex_t bbot;
18119 + struct dentry *h_src_dentry;
18120 + struct inode *h_inode, *inode, *delegated;
18121 + struct super_block *sb;
18122 + struct file *h_file;
18126 + sb = src_dentry->d_sb;
18127 + inode = d_inode(src_dentry);
18128 + if (au_ibtop(inode) <= a->bdst)
18129 + h_inode = au_h_iptr(inode, a->bdst);
18130 + if (!h_inode || !h_inode->i_nlink) {
18131 + /* copyup src_dentry as the name of dentry. */
18132 + bbot = au_dbbot(dentry);
18133 + if (bbot < a->bsrc)
18134 + au_set_dbbot(dentry, a->bsrc);
18135 + au_set_h_dptr(dentry, a->bsrc,
18136 + dget(au_h_dptr(src_dentry, a->bsrc)));
18137 + dget(a->h_path.dentry);
18138 + au_set_h_dptr(dentry, a->bdst, NULL);
18139 + AuDbg("temporary d_inode...\n");
18140 + spin_lock(&dentry->d_lock);
18141 + dentry->d_inode = d_inode(src_dentry); /* tmp */
18142 + spin_unlock(&dentry->d_lock);
18143 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
18144 + if (IS_ERR(h_file))
18145 + err = PTR_ERR(h_file);
18147 + struct au_cp_generic cpg = {
18148 + .dentry = dentry,
18153 + .flags = AuCpup_KEEPLINO
18155 + err = au_sio_cpup_simple(&cpg);
18156 + au_h_open_post(dentry, a->bsrc, h_file);
18158 + dput(a->h_path.dentry);
18159 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18161 + au_set_h_dptr(dentry, a->bdst,
18162 + a->h_path.dentry);
18164 + spin_lock(&dentry->d_lock);
18165 + dentry->d_inode = NULL; /* restore */
18166 + spin_unlock(&dentry->d_lock);
18167 + AuDbg("temporary d_inode...done\n");
18168 + au_set_h_dptr(dentry, a->bsrc, NULL);
18169 + au_set_dbbot(dentry, bbot);
18171 + /* the inode of src_dentry already exists on a.bdst branch */
18172 + h_src_dentry = d_find_alias(h_inode);
18173 + if (!h_src_dentry && au_plink_test(inode)) {
18175 + h_src_dentry = au_plink_lkup(inode, a->bdst);
18176 + err = PTR_ERR(h_src_dentry);
18177 + if (IS_ERR(h_src_dentry))
18180 + if (unlikely(d_is_negative(h_src_dentry))) {
18181 + dput(h_src_dentry);
18182 + h_src_dentry = NULL;
18186 + if (h_src_dentry) {
18187 + delegated = NULL;
18188 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18189 + &a->h_path, &delegated);
18190 + if (unlikely(err == -EWOULDBLOCK)) {
18191 + pr_warn("cannot retry for NFSv4 delegation"
18192 + " for an internal link\n");
18195 + dput(h_src_dentry);
18197 + AuIOErr("no dentry found for hi%lu on b%d\n",
18198 + h_inode->i_ino, a->bdst);
18203 + if (!err && !plink)
18204 + au_plink_append(inode, a->bdst, a->h_path.dentry);
18211 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18212 + struct dentry *dentry)
18215 + struct au_dtime dt;
18216 + struct au_link_args *a;
18217 + struct dentry *wh_dentry, *h_src_dentry;
18218 + struct inode *inode, *delegated;
18219 + struct super_block *sb;
18220 + struct au_wr_dir_args wr_dir_args = {
18221 + /* .force_btgt = -1, */
18222 + .flags = AuWrDir_ADD_ENTRY
18226 + inode = d_inode(src_dentry);
18227 + IMustLock(inode);
18230 + a = kzalloc(sizeof(*a), GFP_NOFS);
18231 + if (unlikely(!a))
18234 + a->parent = dentry->d_parent; /* dir inode is locked */
18235 + err = aufs_read_and_write_lock2(dentry, src_dentry,
18236 + AuLock_NOPLM | AuLock_GEN);
18237 + if (unlikely(err))
18239 + err = au_d_linkable(src_dentry);
18240 + if (unlikely(err))
18242 + err = au_d_may_add(dentry);
18243 + if (unlikely(err))
18246 + a->src_parent = dget_parent(src_dentry);
18247 + wr_dir_args.force_btgt = au_ibtop(inode);
18249 + di_write_lock_parent(a->parent);
18250 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
18251 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
18253 + err = PTR_ERR(wh_dentry);
18254 + if (IS_ERR(wh_dentry))
18258 + sb = dentry->d_sb;
18259 + a->bdst = au_dbtop(dentry);
18260 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18261 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
18262 + a->bsrc = au_ibtop(inode);
18263 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18264 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
18265 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
18266 + if (!h_src_dentry) {
18267 + a->bsrc = au_dbtop(src_dentry);
18268 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18269 + AuDebugOn(!h_src_dentry);
18270 + } else if (IS_ERR(h_src_dentry)) {
18271 + err = PTR_ERR(h_src_dentry);
18275 + if (au_opt_test(au_mntflags(sb), PLINK)) {
18276 + if (a->bdst < a->bsrc
18277 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
18278 + err = au_cpup_or_link(src_dentry, dentry, a);
18280 + delegated = NULL;
18281 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18282 + &a->h_path, &delegated);
18283 + if (unlikely(err == -EWOULDBLOCK)) {
18284 + pr_warn("cannot retry for NFSv4 delegation"
18285 + " for an internal link\n");
18289 + dput(h_src_dentry);
18292 + * copyup src_dentry to the branch we process,
18293 + * and then link(2) to it.
18295 + dput(h_src_dentry);
18296 + if (a->bdst < a->bsrc
18297 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
18298 + au_unpin(&a->pin);
18299 + di_write_unlock(a->parent);
18300 + err = au_cpup_before_link(src_dentry, a);
18301 + di_write_lock_parent(a->parent);
18303 + err = au_pin(&a->pin, dentry, a->bdst,
18305 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18306 + if (unlikely(err))
18310 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
18312 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
18313 + delegated = NULL;
18314 + err = vfsub_link(h_src_dentry,
18315 + au_pinned_h_dir(&a->pin),
18316 + &a->h_path, &delegated);
18317 + if (unlikely(err == -EWOULDBLOCK)) {
18318 + pr_warn("cannot retry"
18319 + " for NFSv4 delegation"
18320 + " for an internal link\n");
18326 + if (unlikely(err))
18330 + a->h_path.dentry = wh_dentry;
18331 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
18333 + if (unlikely(err))
18337 + au_dir_ts(dir, a->bdst);
18338 + dir->i_version++;
18339 + inc_nlink(inode);
18340 + inode->i_ctime = dir->i_ctime;
18341 + d_instantiate(dentry, au_igrab(inode));
18342 + if (d_unhashed(a->h_path.dentry))
18343 + /* some filesystem calls d_drop() */
18345 + /* some filesystems consume an inode even hardlink */
18346 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
18347 + goto out_unpin; /* success */
18350 + /* no delegation since it is just created */
18351 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
18352 + /*delegated*/NULL, /*force*/0);
18353 + if (unlikely(rerr)) {
18354 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
18357 + au_dtime_revert(&dt);
18359 + au_unpin(&a->pin);
18363 + di_write_unlock(a->parent);
18364 + dput(a->src_parent);
18366 + if (unlikely(err)) {
18367 + au_update_dbtop(dentry);
18370 + aufs_read_and_write_unlock2(dentry, src_dentry);
18372 + au_delayed_kfree(a);
18378 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18381 + aufs_bindex_t bindex;
18382 + unsigned char diropq;
18383 + struct path h_path;
18384 + struct dentry *wh_dentry, *parent, *opq_dentry;
18385 + struct inode *h_inode;
18386 + struct super_block *sb;
18388 + struct au_pin pin;
18389 + struct au_dtime dt;
18390 + } *a; /* reduce the stack usage */
18391 + struct au_wr_dir_args wr_dir_args = {
18392 + .force_btgt = -1,
18393 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18399 + a = kmalloc(sizeof(*a), GFP_NOFS);
18400 + if (unlikely(!a))
18403 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18404 + if (unlikely(err))
18406 + err = au_d_may_add(dentry);
18407 + if (unlikely(err))
18410 + parent = dentry->d_parent; /* dir inode is locked */
18411 + di_write_lock_parent(parent);
18412 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18413 + &a->pin, &wr_dir_args);
18414 + err = PTR_ERR(wh_dentry);
18415 + if (IS_ERR(wh_dentry))
18418 + sb = dentry->d_sb;
18419 + bindex = au_dbtop(dentry);
18420 + h_path.dentry = au_h_dptr(dentry, bindex);
18421 + h_path.mnt = au_sbr_mnt(sb, bindex);
18422 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18423 + if (unlikely(err))
18426 + /* make the dir opaque */
18428 + h_inode = d_inode(h_path.dentry);
18430 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18431 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18432 + opq_dentry = au_diropq_create(dentry, bindex);
18433 + inode_unlock(h_inode);
18434 + err = PTR_ERR(opq_dentry);
18435 + if (IS_ERR(opq_dentry))
18437 + dput(opq_dentry);
18441 + err = epilog(dir, bindex, wh_dentry, dentry);
18444 + goto out_unpin; /* success */
18449 + AuLabel(revert opq);
18450 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18451 + rerr = au_diropq_remove(dentry, bindex);
18452 + inode_unlock(h_inode);
18454 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18455 + dentry, err, rerr);
18461 + AuLabel(revert dir);
18462 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18464 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18465 + dentry, err, rerr);
18468 + au_dtime_revert(&a->dt);
18470 + au_unpin(&a->pin);
18473 + di_write_unlock(parent);
18475 + if (unlikely(err)) {
18476 + au_update_dbtop(dentry);
18479 + aufs_read_unlock(dentry, AuLock_DW);
18481 + au_delayed_kfree(a);
18485 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18486 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18487 +++ linux/fs/aufs/i_op.c 2016-10-09 16:55:38.889431135 +0200
18490 + * Copyright (C) 2005-2016 Junjiro R. Okajima
18492 + * This program, aufs is free software; you can redistribute it and/or modify
18493 + * it under the terms of the GNU General Public License as published by
18494 + * the Free Software Foundation; either version 2 of the License, or
18495 + * (at your option) any later version.
18497 + * This program is distributed in the hope that it will be useful,
18498 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18499 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18500 + * GNU General Public License for more details.
18502 + * You should have received a copy of the GNU General Public License
18503 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18507 + * inode operations (except add/del/rename)
18510 +#include <linux/device_cgroup.h>
18511 +#include <linux/fs_stack.h>
18512 +#include <linux/namei.h>
18513 +#include <linux/security.h>
18516 +static int h_permission(struct inode *h_inode, int mask,
18517 + struct path *h_path, int brperm)
18520 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18523 + if (write_mask && IS_IMMUTABLE(h_inode))
18527 + if (((mask & MAY_EXEC)
18528 + && S_ISREG(h_inode->i_mode)
18529 + && (path_noexec(h_path)
18530 + || !(h_inode->i_mode & S_IXUGO))))
18534 + * - skip the lower fs test in the case of write to ro branch.
18535 + * - nfs dir permission write check is optimized, but a policy for
18536 + * link/rename requires a real check.
18537 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18538 + * in this case, generic_permission() returns -EOPNOTSUPP.
18540 + if ((write_mask && !au_br_writable(brperm))
18541 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18542 + && write_mask && !(mask & MAY_READ))
18543 + || !h_inode->i_op->permission) {
18544 + /* AuLabel(generic_permission); */
18545 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18546 + err = generic_permission(h_inode, mask);
18547 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18548 + err = h_inode->i_op->permission(h_inode, mask);
18551 + /* AuLabel(h_inode->permission); */
18552 + err = h_inode->i_op->permission(h_inode, mask);
18557 + err = devcgroup_inode_permission(h_inode, mask);
18559 + err = security_inode_permission(h_inode, mask);
18563 + /* todo: do we need to call ima_path_check()? */
18564 + struct path h_path = {
18568 + err = ima_path_check(&h_path,
18569 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18570 + IMA_COUNT_LEAVE);
18578 +static int aufs_permission(struct inode *inode, int mask)
18581 + aufs_bindex_t bindex, bbot;
18582 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18583 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18584 + struct inode *h_inode;
18585 + struct super_block *sb;
18586 + struct au_branch *br;
18588 + /* todo: support rcu-walk? */
18589 + if (mask & MAY_NOT_BLOCK)
18592 + sb = inode->i_sb;
18593 + si_read_lock(sb, AuLock_FLUSH);
18594 + ii_read_lock_child(inode);
18596 + err = au_iigen_test(inode, au_sigen(sb));
18597 + if (unlikely(err))
18603 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18604 + err = au_busy_or_stale();
18605 + h_inode = au_h_iptr(inode, au_ibtop(inode));
18606 + if (unlikely(!h_inode
18607 + || (h_inode->i_mode & S_IFMT)
18608 + != (inode->i_mode & S_IFMT)))
18612 + bindex = au_ibtop(inode);
18613 + br = au_sbr(sb, bindex);
18614 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
18617 + && !special_file(h_inode->i_mode)) {
18618 + /* test whether the upper writable branch exists */
18620 + for (; bindex >= 0; bindex--)
18621 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18629 + /* non-write to dir */
18631 + bbot = au_ibbot(inode);
18632 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
18633 + h_inode = au_h_iptr(inode, bindex);
18635 + err = au_busy_or_stale();
18636 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18639 + br = au_sbr(sb, bindex);
18640 + err = h_permission(h_inode, mask, &br->br_path,
18646 + ii_read_unlock(inode);
18647 + si_read_unlock(sb);
18651 +/* ---------------------------------------------------------------------- */
18653 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18654 + unsigned int flags)
18656 + struct dentry *ret, *parent;
18657 + struct inode *inode;
18658 + struct super_block *sb;
18659 + int err, npositive;
18663 + /* todo: support rcu-walk? */
18664 + ret = ERR_PTR(-ECHILD);
18665 + if (flags & LOOKUP_RCU)
18668 + ret = ERR_PTR(-ENAMETOOLONG);
18669 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18673 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18674 + ret = ERR_PTR(err);
18675 + if (unlikely(err))
18678 + err = au_di_init(dentry);
18679 + ret = ERR_PTR(err);
18680 + if (unlikely(err))
18684 + npositive = 0; /* suppress a warning */
18685 + parent = dentry->d_parent; /* dir inode is locked */
18686 + di_read_lock_parent(parent, AuLock_IR);
18687 + err = au_alive_dir(parent);
18689 + err = au_digen_test(parent, au_sigen(sb));
18691 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
18692 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
18693 + AuLkup_ALLOW_NEG);
18696 + di_read_unlock(parent, AuLock_IR);
18697 + ret = ERR_PTR(err);
18698 + if (unlikely(err < 0))
18702 + inode = au_new_inode(dentry, /*must_new*/0);
18703 + if (IS_ERR(inode)) {
18704 + ret = (void *)inode;
18711 + atomic_inc(&inode->i_count);
18712 + ret = d_splice_alias(inode, dentry);
18714 + if (unlikely(d_need_lookup(dentry))) {
18715 + spin_lock(&dentry->d_lock);
18716 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18717 + spin_unlock(&dentry->d_lock);
18721 + if (!IS_ERR(ret)) {
18723 + if (ret && ret != dentry)
18724 + ii_write_unlock(inode);
18726 + ii_write_unlock(inode);
18733 + di_write_unlock(dentry);
18735 + si_read_unlock(sb);
18740 +/* ---------------------------------------------------------------------- */
18742 +struct aopen_node {
18743 + struct hlist_node hlist;
18744 + struct file *file, *h_file;
18747 +static int au_do_aopen(struct inode *inode, struct file *file)
18749 + struct au_sphlhead *aopen;
18750 + struct aopen_node *node;
18751 + struct au_do_open_args args = {
18753 + .open = au_do_open_nondir
18756 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18757 + spin_lock(&aopen->spin);
18758 + hlist_for_each_entry(node, &aopen->head, hlist)
18759 + if (node->file == file) {
18760 + args.h_file = node->h_file;
18763 + spin_unlock(&aopen->spin);
18764 + /* AuDebugOn(!args.h_file); */
18766 + return au_do_open(file, &args);
18769 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18770 + struct file *file, unsigned int open_flag,
18771 + umode_t create_mode, int *opened)
18773 + int err, h_opened = *opened;
18774 + unsigned int lkup_flags;
18775 + struct dentry *parent, *d;
18776 + struct au_sphlhead *aopen;
18777 + struct vfsub_aopen_args args = {
18778 + .open_flag = open_flag,
18779 + .create_mode = create_mode,
18780 + .opened = &h_opened
18782 + struct aopen_node aopen_node = {
18787 + AuDbg("open_flag 0%o\n", open_flag);
18788 + AuDbgDentry(dentry);
18791 + if (!au_di(dentry)) {
18792 + lkup_flags = LOOKUP_OPEN;
18793 + if (open_flag & O_CREAT)
18794 + lkup_flags |= LOOKUP_CREATE;
18795 + d = aufs_lookup(dir, dentry, lkup_flags);
18797 + err = PTR_ERR(d);
18802 + * obsoleted dentry found.
18803 + * another error will be returned later.
18809 + AuDbgDentry(dentry);
18812 + if (d_is_positive(dentry)
18813 + || d_unhashed(dentry)
18814 + || d_unlinked(dentry)
18815 + || !(open_flag & O_CREAT))
18816 + goto out_no_open;
18818 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18819 + if (unlikely(err))
18822 + parent = dentry->d_parent; /* dir is locked */
18823 + di_write_lock_parent(parent);
18824 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
18825 + if (unlikely(err))
18828 + AuDbgDentry(dentry);
18829 + if (d_is_positive(dentry))
18832 + args.file = get_empty_filp();
18833 + err = PTR_ERR(args.file);
18834 + if (IS_ERR(args.file))
18837 + args.file->f_flags = file->f_flags;
18838 + err = au_aopen_or_create(dir, dentry, &args);
18840 + AuDbgFile(args.file);
18841 + if (unlikely(err < 0)) {
18842 + if (h_opened & FILE_OPENED)
18845 + put_filp(args.file);
18849 + /* some filesystems don't set FILE_CREATED while succeeded? */
18850 + *opened |= FILE_CREATED;
18851 + if (h_opened & FILE_OPENED)
18852 + aopen_node.h_file = args.file;
18854 + put_filp(args.file);
18855 + args.file = NULL;
18857 + aopen = &au_sbi(dir->i_sb)->si_aopen;
18858 + au_sphl_add(&aopen_node.hlist, aopen);
18859 + err = finish_open(file, dentry, au_do_aopen, opened);
18860 + au_sphl_del(&aopen_node.hlist, aopen);
18863 + if (aopen_node.h_file)
18864 + fput(aopen_node.h_file);
18867 + di_write_unlock(parent);
18868 + aufs_read_unlock(dentry, AuLock_DW);
18869 + AuDbgDentry(dentry);
18870 + if (unlikely(err < 0))
18873 + if (err >= 0 && !(*opened & FILE_CREATED)) {
18874 + AuLabel(out_no_open);
18876 + err = finish_no_open(file, dentry);
18879 + AuDbg("%pd%s%s\n", dentry,
18880 + (*opened & FILE_CREATED) ? " created" : "",
18881 + (*opened & FILE_OPENED) ? " opened" : "");
18887 +/* ---------------------------------------------------------------------- */
18889 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18890 + const unsigned char add_entry, aufs_bindex_t bcpup,
18891 + aufs_bindex_t btop)
18894 + struct dentry *h_parent;
18895 + struct inode *h_dir;
18898 + IMustLock(d_inode(parent));
18900 + di_write_lock_parent(parent);
18903 + if (!au_h_dptr(parent, bcpup)) {
18904 + if (btop > bcpup)
18905 + err = au_cpup_dirs(dentry, bcpup);
18906 + else if (btop < bcpup)
18907 + err = au_cpdown_dirs(dentry, bcpup);
18911 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18912 + h_parent = au_h_dptr(parent, bcpup);
18913 + h_dir = d_inode(h_parent);
18914 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
18915 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
18916 + /* todo: no unlock here */
18917 + inode_unlock(h_dir);
18919 + AuDbg("bcpup %d\n", bcpup);
18921 + if (d_really_is_negative(dentry))
18922 + au_set_h_dptr(dentry, btop, NULL);
18923 + au_update_dbrange(dentry, /*do_put_zero*/0);
18928 + di_write_unlock(parent);
18930 + err = bcpup; /* success */
18937 + * decide the branch and the parent dir where we will create a new entry.
18938 + * returns new bindex or an error.
18939 + * copyup the parent dir if needed.
18941 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18942 + struct au_wr_dir_args *args)
18945 + unsigned int flags;
18946 + aufs_bindex_t bcpup, btop, src_btop;
18947 + const unsigned char add_entry
18948 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18949 + | au_ftest_wrdir(args->flags, TMPFILE);
18950 + struct super_block *sb;
18951 + struct dentry *parent;
18952 + struct au_sbinfo *sbinfo;
18954 + sb = dentry->d_sb;
18955 + sbinfo = au_sbi(sb);
18956 + parent = dget_parent(dentry);
18957 + btop = au_dbtop(dentry);
18959 + if (args->force_btgt < 0) {
18960 + if (src_dentry) {
18961 + src_btop = au_dbtop(src_dentry);
18962 + if (src_btop < btop)
18963 + bcpup = src_btop;
18964 + } else if (add_entry) {
18966 + if (au_ftest_wrdir(args->flags, ISDIR))
18967 + au_fset_wbr(flags, DIR);
18968 + err = AuWbrCreate(sbinfo, dentry, flags);
18972 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
18974 + err = AuWbrCopyup(sbinfo, dentry);
18976 + if (!IS_ROOT(dentry)) {
18977 + di_read_lock_parent(parent, !AuLock_IR);
18978 + err = AuWbrCopyup(sbinfo, dentry);
18979 + di_read_unlock(parent, !AuLock_IR);
18981 + err = AuWbrCopyup(sbinfo, dentry);
18984 + if (unlikely(err < 0))
18988 + bcpup = args->force_btgt;
18989 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
18992 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
18994 + if (bcpup == btop)
18995 + goto out; /* success */
18997 + /* copyup the new parent into the branch we process */
18998 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
19000 + if (d_really_is_negative(dentry)) {
19001 + au_set_h_dptr(dentry, btop, NULL);
19002 + au_set_dbtop(dentry, bcpup);
19003 + au_set_dbbot(dentry, bcpup);
19005 + AuDebugOn(add_entry
19006 + && !au_ftest_wrdir(args->flags, TMPFILE)
19007 + && !au_h_dptr(dentry, bcpup));
19015 +/* ---------------------------------------------------------------------- */
19017 +void au_pin_hdir_unlock(struct au_pin *p)
19020 + au_hn_inode_unlock(p->hdir);
19023 +int au_pin_hdir_lock(struct au_pin *p)
19031 + /* even if an error happens later, keep this lock */
19032 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
19035 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
19040 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
19041 + p->h_parent, p->br);
19047 +int au_pin_hdir_relock(struct au_pin *p)
19050 + struct inode *h_i;
19051 + struct dentry *h_d[] = {
19056 + err = au_pin_hdir_lock(p);
19057 + if (unlikely(err))
19060 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
19063 + if (d_is_positive(h_d[i])) {
19064 + h_i = d_inode(h_d[i]);
19065 + err = !h_i->i_nlink;
19073 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
19075 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
19076 + p->hdir->hi_inode->i_rwsem.owner = task;
19080 +void au_pin_hdir_acquire_nest(struct au_pin *p)
19083 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
19084 + p->lsc_hi, 0, NULL, _RET_IP_);
19085 + au_pin_hdir_set_owner(p, current);
19089 +void au_pin_hdir_release(struct au_pin *p)
19092 + au_pin_hdir_set_owner(p, p->task);
19093 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
19097 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
19099 + if (pin && pin->parent)
19100 + return au_h_dptr(pin->parent, pin->bindex);
19104 +void au_unpin(struct au_pin *p)
19107 + au_pin_hdir_unlock(p);
19108 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
19109 + vfsub_mnt_drop_write(p->h_mnt);
19113 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19114 + di_read_unlock(p->parent, AuLock_IR);
19115 + iput(p->hdir->hi_inode);
19117 + p->parent = NULL;
19120 + /* do not clear p->task */
19123 +int au_do_pin(struct au_pin *p)
19126 + struct super_block *sb;
19127 + struct inode *h_dir;
19130 + sb = p->dentry->d_sb;
19131 + p->br = au_sbr(sb, p->bindex);
19132 + if (IS_ROOT(p->dentry)) {
19133 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19134 + p->h_mnt = au_br_mnt(p->br);
19135 + err = vfsub_mnt_want_write(p->h_mnt);
19136 + if (unlikely(err)) {
19137 + au_fclr_pin(p->flags, MNT_WRITE);
19144 + p->h_dentry = NULL;
19145 + if (p->bindex <= au_dbbot(p->dentry))
19146 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
19148 + p->parent = dget_parent(p->dentry);
19149 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19150 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
19153 + p->h_parent = au_h_dptr(p->parent, p->bindex);
19154 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
19156 + h_dir = p->hdir->hi_inode;
19160 + * if DI_LOCKED is not set, then p->parent may be different
19161 + * and h_parent can be NULL.
19163 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
19165 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19166 + di_read_unlock(p->parent, AuLock_IR);
19168 + p->parent = NULL;
19172 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19173 + p->h_mnt = au_br_mnt(p->br);
19174 + err = vfsub_mnt_want_write(p->h_mnt);
19175 + if (unlikely(err)) {
19176 + au_fclr_pin(p->flags, MNT_WRITE);
19177 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19178 + di_read_unlock(p->parent, AuLock_IR);
19180 + p->parent = NULL;
19186 + err = au_pin_hdir_lock(p);
19188 + goto out; /* success */
19193 + pr_err("err %d\n", err);
19194 + err = au_busy_or_stale();
19199 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
19200 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19201 + unsigned int udba, unsigned char flags)
19203 + p->dentry = dentry;
19205 + p->lsc_di = lsc_di;
19206 + p->lsc_hi = lsc_hi;
19207 + p->flags = flags;
19208 + p->bindex = bindex;
19210 + p->parent = NULL;
19214 + p->h_dentry = NULL;
19215 + p->h_parent = NULL;
19217 + p->task = current;
19220 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19221 + unsigned int udba, unsigned char flags)
19223 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
19225 + return au_do_pin(pin);
19228 +/* ---------------------------------------------------------------------- */
19231 + * ->setattr() and ->getattr() are called in various cases.
19232 + * chmod, stat: dentry is revalidated.
19233 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
19235 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
19237 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
19238 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
19241 + struct dentry *parent;
19244 + if (au_digen_test(dentry, sigen)) {
19245 + parent = dget_parent(dentry);
19246 + di_read_lock_parent(parent, AuLock_IR);
19247 + err = au_refresh_dentry(dentry, parent);
19248 + di_read_unlock(parent, AuLock_IR);
19256 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19257 + struct au_icpup_args *a)
19261 + aufs_bindex_t btop, ibtop;
19262 + struct dentry *hi_wh, *parent;
19263 + struct inode *inode;
19264 + struct au_wr_dir_args wr_dir_args = {
19265 + .force_btgt = -1,
19269 + if (d_is_dir(dentry))
19270 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19271 + /* plink or hi_wh() case */
19272 + btop = au_dbtop(dentry);
19273 + inode = d_inode(dentry);
19274 + ibtop = au_ibtop(inode);
19275 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
19276 + wr_dir_args.force_btgt = ibtop;
19277 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19278 + if (unlikely(err < 0))
19282 + au_fset_icpup(a->flags, DID_CPUP);
19285 + a->pin_flags = AuPin_MNT_WRITE;
19287 + if (!IS_ROOT(dentry)) {
19288 + au_fset_pin(a->pin_flags, DI_LOCKED);
19289 + parent = dget_parent(dentry);
19290 + di_write_lock_parent(parent);
19293 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
19294 + if (unlikely(err))
19298 + a->h_path.dentry = au_h_dptr(dentry, btop);
19299 + a->h_inode = d_inode(a->h_path.dentry);
19300 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
19301 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19302 + if (ia->ia_size < i_size_read(a->h_inode))
19303 + sz = ia->ia_size;
19304 + inode_unlock(a->h_inode);
19308 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
19309 + hi_wh = au_hi_wh(inode, a->btgt);
19311 + struct au_cp_generic cpg = {
19312 + .dentry = dentry,
19318 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
19319 + if (unlikely(err))
19321 + hi_wh = au_hi_wh(inode, a->btgt);
19322 + /* todo: revalidate hi_wh? */
19327 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
19328 + di_downgrade_lock(parent, AuLock_IR);
19332 + if (!au_ftest_icpup(a->flags, DID_CPUP))
19333 + goto out; /* success */
19335 + if (!d_unhashed(dentry)) {
19336 + struct au_cp_generic cpg = {
19337 + .dentry = dentry,
19342 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19344 + err = au_sio_cpup_simple(&cpg);
19346 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19347 + } else if (!hi_wh)
19348 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19350 + a->h_path.dentry = hi_wh; /* do not dget here */
19353 + a->h_inode = d_inode(a->h_path.dentry);
19355 + goto out; /* success */
19356 + au_unpin(&a->pin);
19359 + di_write_unlock(parent);
19364 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19368 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19371 + struct inode *inode, *delegated;
19372 + struct super_block *sb;
19373 + struct file *file;
19374 + struct au_icpup_args *a;
19376 + inode = d_inode(dentry);
19377 + IMustLock(inode);
19380 + a = kzalloc(sizeof(*a), GFP_NOFS);
19381 + if (unlikely(!a))
19384 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19385 + ia->ia_valid &= ~ATTR_MODE;
19388 + sb = dentry->d_sb;
19389 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19390 + if (unlikely(err))
19393 + if (ia->ia_valid & ATTR_FILE) {
19394 + /* currently ftruncate(2) only */
19395 + AuDebugOn(!d_is_reg(dentry));
19396 + file = ia->ia_file;
19397 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
19398 + if (unlikely(err))
19400 + ia->ia_file = au_hf_top(file);
19401 + a->udba = AuOpt_UDBA_NONE;
19403 + /* fchmod() doesn't pass ia_file */
19404 + a->udba = au_opt_udba(sb);
19405 + di_write_lock_child(dentry);
19406 + /* no d_unlinked(), to set UDBA_NONE for root */
19407 + if (d_unhashed(dentry))
19408 + a->udba = AuOpt_UDBA_NONE;
19409 + if (a->udba != AuOpt_UDBA_NONE) {
19410 + AuDebugOn(IS_ROOT(dentry));
19411 + err = au_reval_for_attr(dentry, au_sigen(sb));
19412 + if (unlikely(err))
19417 + err = au_pin_and_icpup(dentry, ia, a);
19418 + if (unlikely(err < 0))
19420 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19421 + ia->ia_file = NULL;
19422 + ia->ia_valid &= ~ATTR_FILE;
19425 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19426 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19427 + == (ATTR_MODE | ATTR_CTIME)) {
19428 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19429 + if (unlikely(err))
19431 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19432 + && (ia->ia_valid & ATTR_CTIME)) {
19433 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19434 + if (unlikely(err))
19438 + if (ia->ia_valid & ATTR_SIZE) {
19441 + if (ia->ia_size < i_size_read(inode))
19443 + truncate_setsize(inode, ia->ia_size);
19446 + if (ia->ia_valid & ATTR_FILE)
19448 + inode_unlock(a->h_inode);
19449 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19450 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19452 + delegated = NULL;
19454 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19456 + err = break_deleg_wait(&delegated);
19464 + * regardless aufs 'acl' option setting.
19465 + * why don't all acl-aware fs call this func from their ->setattr()?
19467 + if (!err && (ia->ia_valid & ATTR_MODE))
19468 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
19470 + au_cpup_attr_changeable(inode);
19473 + inode_unlock(a->h_inode);
19474 + au_unpin(&a->pin);
19475 + if (unlikely(err))
19476 + au_update_dbtop(dentry);
19478 + di_write_unlock(dentry);
19480 + fi_write_unlock(file);
19481 + ia->ia_file = file;
19482 + ia->ia_valid |= ATTR_FILE;
19485 + si_read_unlock(sb);
19487 + au_delayed_kfree(a);
19493 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19494 +static int au_h_path_to_set_attr(struct dentry *dentry,
19495 + struct au_icpup_args *a, struct path *h_path)
19498 + struct super_block *sb;
19500 + sb = dentry->d_sb;
19501 + a->udba = au_opt_udba(sb);
19502 + /* no d_unlinked(), to set UDBA_NONE for root */
19503 + if (d_unhashed(dentry))
19504 + a->udba = AuOpt_UDBA_NONE;
19505 + if (a->udba != AuOpt_UDBA_NONE) {
19506 + AuDebugOn(IS_ROOT(dentry));
19507 + err = au_reval_for_attr(dentry, au_sigen(sb));
19508 + if (unlikely(err))
19511 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19512 + if (unlikely(err < 0))
19515 + h_path->dentry = a->h_path.dentry;
19516 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19522 +ssize_t au_srxattr(struct dentry *dentry, struct inode *inode,
19523 + struct au_srxattr *arg)
19526 + struct path h_path;
19527 + struct super_block *sb;
19528 + struct au_icpup_args *a;
19529 + struct inode *h_inode;
19531 + IMustLock(inode);
19534 + a = kzalloc(sizeof(*a), GFP_NOFS);
19535 + if (unlikely(!a))
19538 + sb = dentry->d_sb;
19539 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19540 + if (unlikely(err))
19543 + h_path.dentry = NULL; /* silence gcc */
19544 + di_write_lock_child(dentry);
19545 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19546 + if (unlikely(err))
19549 + inode_unlock(a->h_inode);
19550 + switch (arg->type) {
19551 + case AU_XATTR_SET:
19552 + AuDebugOn(d_is_negative(h_path.dentry));
19553 + err = vfsub_setxattr(h_path.dentry,
19554 + arg->u.set.name, arg->u.set.value,
19555 + arg->u.set.size, arg->u.set.flags);
19557 + case AU_XATTR_REMOVE:
19558 + err = vfsub_removexattr(h_path.dentry, arg->u.remove.name);
19561 + err = -EOPNOTSUPP;
19562 + h_inode = d_inode(h_path.dentry);
19563 + if (h_inode->i_op->set_acl)
19564 + err = h_inode->i_op->set_acl(h_inode,
19565 + arg->u.acl_set.acl,
19566 + arg->u.acl_set.type);
19570 + au_cpup_attr_timesizes(inode);
19572 + au_unpin(&a->pin);
19573 + if (unlikely(err))
19574 + au_update_dbtop(dentry);
19577 + di_write_unlock(dentry);
19578 + si_read_unlock(sb);
19580 + au_delayed_kfree(a);
19587 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19588 + unsigned int nlink)
19592 + inode->i_mode = st->mode;
19593 + /* don't i_[ug]id_write() here */
19594 + inode->i_uid = st->uid;
19595 + inode->i_gid = st->gid;
19596 + inode->i_atime = st->atime;
19597 + inode->i_mtime = st->mtime;
19598 + inode->i_ctime = st->ctime;
19600 + au_cpup_attr_nlink(inode, /*force*/0);
19601 + if (S_ISDIR(inode->i_mode)) {
19602 + n = inode->i_nlink;
19605 + smp_mb(); /* for i_nlink */
19606 + /* 0 can happen */
19607 + set_nlink(inode, n);
19610 + spin_lock(&inode->i_lock);
19611 + inode->i_blocks = st->blocks;
19612 + i_size_write(inode, st->size);
19613 + spin_unlock(&inode->i_lock);
19617 + * common routine for aufs_getattr() and aufs_getxattr().
19618 + * returns zero or negative (an error).
19619 + * @dentry will be read-locked in success.
19621 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
19624 + unsigned int mnt_flags, sigen;
19625 + unsigned char udba_none;
19626 + aufs_bindex_t bindex;
19627 + struct super_block *sb, *h_sb;
19628 + struct inode *inode;
19630 + h_path->mnt = NULL;
19631 + h_path->dentry = NULL;
19634 + sb = dentry->d_sb;
19635 + mnt_flags = au_mntflags(sb);
19636 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19638 + /* support fstat(2) */
19639 + if (!d_unlinked(dentry) && !udba_none) {
19640 + sigen = au_sigen(sb);
19641 + err = au_digen_test(dentry, sigen);
19643 + di_read_lock_child(dentry, AuLock_IR);
19644 + err = au_dbrange_test(dentry);
19645 + if (unlikely(err)) {
19646 + di_read_unlock(dentry, AuLock_IR);
19650 + AuDebugOn(IS_ROOT(dentry));
19651 + di_write_lock_child(dentry);
19652 + err = au_dbrange_test(dentry);
19654 + err = au_reval_for_attr(dentry, sigen);
19656 + di_downgrade_lock(dentry, AuLock_IR);
19658 + di_write_unlock(dentry);
19663 + di_read_lock_child(dentry, AuLock_IR);
19665 + inode = d_inode(dentry);
19666 + bindex = au_ibtop(inode);
19667 + h_path->mnt = au_sbr_mnt(sb, bindex);
19668 + h_sb = h_path->mnt->mnt_sb;
19670 + && !au_test_fs_bad_iattr(h_sb)
19672 + goto out; /* success */
19674 + if (au_dbtop(dentry) == bindex)
19675 + h_path->dentry = au_h_dptr(dentry, bindex);
19676 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19677 + h_path->dentry = au_plink_lkup(inode, bindex);
19678 + if (IS_ERR(h_path->dentry))
19679 + /* pretending success */
19680 + h_path->dentry = NULL;
19682 + dput(h_path->dentry);
19689 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19690 + struct dentry *dentry, struct kstat *st)
19693 + unsigned char positive;
19694 + struct path h_path;
19695 + struct inode *inode;
19696 + struct super_block *sb;
19698 + inode = d_inode(dentry);
19699 + sb = dentry->d_sb;
19700 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19701 + if (unlikely(err))
19703 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
19704 + if (unlikely(err))
19706 + if (unlikely(!h_path.dentry))
19707 + /* illegally overlapped or something */
19708 + goto out_fill; /* pretending success */
19710 + positive = d_is_positive(h_path.dentry);
19712 + err = vfs_getattr(&h_path, st);
19715 + au_refresh_iattr(inode, st,
19716 + d_inode(h_path.dentry)->i_nlink);
19717 + goto out_fill; /* success */
19723 + generic_fillattr(inode, st);
19725 + di_read_unlock(dentry, AuLock_IR);
19727 + si_read_unlock(sb);
19733 +/* ---------------------------------------------------------------------- */
19735 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
19736 + struct delayed_call *done)
19739 + struct dentry *h_dentry;
19740 + struct inode *h_inode;
19742 + aufs_bindex_t bindex;
19744 + ret = NULL; /* suppress a warning */
19749 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19750 + if (unlikely(err))
19753 + err = au_d_hashed_positive(dentry);
19754 + if (unlikely(err))
19758 + inode = d_inode(dentry);
19759 + bindex = au_ibtop(inode);
19760 + h_inode = au_h_iptr(inode, bindex);
19761 + if (unlikely(!h_inode->i_op->get_link))
19766 + if (au_dbtop(dentry) <= bindex) {
19767 + h_dentry = au_h_dptr(dentry, bindex);
19772 + h_dentry = d_find_any_alias(h_inode);
19773 + if (IS_ERR(h_dentry)) {
19774 + err = PTR_ERR(h_dentry);
19778 + if (unlikely(!h_dentry))
19782 + AuDbg("%pf\n", h_inode->i_op->get_link);
19783 + AuDbgDentry(h_dentry);
19784 + ret = h_inode->i_op->get_link(h_dentry, h_inode, done);
19787 + err = PTR_ERR(ret);
19790 + aufs_read_unlock(dentry, AuLock_IR);
19792 + if (unlikely(err))
19793 + ret = ERR_PTR(err);
19794 + AuTraceErrPtr(ret);
19798 +/* ---------------------------------------------------------------------- */
19800 +static int au_is_special(struct inode *inode)
19802 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
19805 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19808 + aufs_bindex_t bindex;
19809 + struct super_block *sb;
19810 + struct inode *h_inode;
19811 + struct vfsmount *h_mnt;
19813 + sb = inode->i_sb;
19814 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
19815 + "unexpected s_flags 0x%lx", sb->s_flags);
19817 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19819 + si_read_lock(sb, AuLock_FLUSH);
19820 + ii_write_lock_child(inode);
19824 + bindex = au_ibtop(inode);
19825 + h_inode = au_h_iptr(inode, bindex);
19826 + if (!au_test_ro(sb, bindex, inode)) {
19827 + h_mnt = au_sbr_mnt(sb, bindex);
19828 + err = vfsub_mnt_want_write(h_mnt);
19830 + err = vfsub_update_time(h_inode, ts, flags);
19831 + vfsub_mnt_drop_write(h_mnt);
19833 + } else if (au_is_special(h_inode)) {
19835 + * Never copy-up here.
19836 + * These special files may already be opened and used for
19837 + * communicating. If we copied it up, then the communication
19838 + * would be corrupted.
19840 + AuWarn1("timestamps for i%lu are ignored "
19841 + "since it is on readonly branch (hi%lu).\n",
19842 + inode->i_ino, h_inode->i_ino);
19843 + } else if (flags & ~S_ATIME) {
19845 + AuIOErr1("unexpected flags 0x%x\n", flags);
19851 + au_cpup_attr_timesizes(inode);
19852 + ii_write_unlock(inode);
19853 + si_read_unlock(sb);
19856 + if (!err && (flags & S_VERSION))
19857 + inode_inc_iversion(inode);
19862 +/* ---------------------------------------------------------------------- */
19864 +/* no getattr version will be set by module.c:aufs_init() */
19865 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
19867 + [AuIop_SYMLINK] = {
19868 + .permission = aufs_permission,
19869 +#ifdef CONFIG_FS_POSIX_ACL
19870 + .get_acl = aufs_get_acl,
19871 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19874 + .setattr = aufs_setattr,
19875 + .getattr = aufs_getattr,
19877 +#ifdef CONFIG_AUFS_XATTR
19878 + .setxattr = aufs_setxattr,
19879 + .getxattr = aufs_getxattr,
19880 + .listxattr = aufs_listxattr,
19881 + .removexattr = aufs_removexattr,
19884 + .readlink = generic_readlink,
19885 + .get_link = aufs_get_link,
19887 + /* .update_time = aufs_update_time */
19890 + .create = aufs_create,
19891 + .lookup = aufs_lookup,
19892 + .link = aufs_link,
19893 + .unlink = aufs_unlink,
19894 + .symlink = aufs_symlink,
19895 + .mkdir = aufs_mkdir,
19896 + .rmdir = aufs_rmdir,
19897 + .mknod = aufs_mknod,
19898 + .rename = aufs_rename,
19900 + .permission = aufs_permission,
19901 +#ifdef CONFIG_FS_POSIX_ACL
19902 + .get_acl = aufs_get_acl,
19903 + .set_acl = aufs_set_acl,
19906 + .setattr = aufs_setattr,
19907 + .getattr = aufs_getattr,
19909 +#ifdef CONFIG_AUFS_XATTR
19910 + .setxattr = aufs_setxattr,
19911 + .getxattr = aufs_getxattr,
19912 + .listxattr = aufs_listxattr,
19913 + .removexattr = aufs_removexattr,
19916 + .update_time = aufs_update_time,
19917 + .atomic_open = aufs_atomic_open,
19918 + .tmpfile = aufs_tmpfile
19920 + [AuIop_OTHER] = {
19921 + .permission = aufs_permission,
19922 +#ifdef CONFIG_FS_POSIX_ACL
19923 + .get_acl = aufs_get_acl,
19924 + .set_acl = aufs_set_acl,
19927 + .setattr = aufs_setattr,
19928 + .getattr = aufs_getattr,
19930 +#ifdef CONFIG_AUFS_XATTR
19931 + .setxattr = aufs_setxattr,
19932 + .getxattr = aufs_getxattr,
19933 + .listxattr = aufs_listxattr,
19934 + .removexattr = aufs_removexattr,
19937 + .update_time = aufs_update_time
19940 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19941 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19942 +++ linux/fs/aufs/i_op_del.c 2016-10-09 16:55:36.492701639 +0200
19945 + * Copyright (C) 2005-2016 Junjiro R. Okajima
19947 + * This program, aufs is free software; you can redistribute it and/or modify
19948 + * it under the terms of the GNU General Public License as published by
19949 + * the Free Software Foundation; either version 2 of the License, or
19950 + * (at your option) any later version.
19952 + * This program is distributed in the hope that it will be useful,
19953 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19954 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19955 + * GNU General Public License for more details.
19957 + * You should have received a copy of the GNU General Public License
19958 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19962 + * inode operations (del entry)
19968 + * decide if a new whiteout for @dentry is necessary or not.
19969 + * when it is necessary, prepare the parent dir for the upper branch whose
19970 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19971 + * be done by caller.
19973 + * 0: wh is unnecessary
19974 + * plus: wh is necessary
19977 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19979 + int need_wh, err;
19980 + aufs_bindex_t btop;
19981 + struct super_block *sb;
19983 + sb = dentry->d_sb;
19984 + btop = au_dbtop(dentry);
19985 + if (*bcpup < 0) {
19987 + if (au_test_ro(sb, btop, d_inode(dentry))) {
19988 + err = AuWbrCopyup(au_sbi(sb), dentry);
19990 + if (unlikely(err < 0))
19994 + AuDebugOn(btop < *bcpup
19995 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
19996 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
19998 + if (*bcpup != btop) {
19999 + err = au_cpup_dirs(dentry, *bcpup);
20000 + if (unlikely(err))
20004 + struct au_dinfo *dinfo, *tmp;
20006 + need_wh = -ENOMEM;
20007 + dinfo = au_di(dentry);
20008 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
20010 + au_di_cp(tmp, dinfo);
20011 + au_di_swap(tmp, dinfo);
20012 + /* returns the number of positive dentries */
20013 + need_wh = au_lkup_dentry(dentry, btop + 1,
20014 + /* AuLkup_IGNORE_PERM */ 0);
20015 + au_di_swap(tmp, dinfo);
20016 + au_rw_write_unlock(&tmp->di_rwsem);
20020 + AuDbg("need_wh %d\n", need_wh);
20028 + * simple tests for the del-entry operations.
20029 + * following the checks in vfs, plus the parent-child relationship.
20031 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
20032 + struct dentry *h_parent, int isdir)
20036 + struct dentry *h_dentry, *h_latest;
20037 + struct inode *h_inode;
20039 + h_dentry = au_h_dptr(dentry, bindex);
20040 + if (d_really_is_positive(dentry)) {
20042 + if (unlikely(d_is_negative(h_dentry)))
20044 + h_inode = d_inode(h_dentry);
20045 + if (unlikely(!h_inode->i_nlink))
20048 + h_mode = h_inode->i_mode;
20051 + if (unlikely(S_ISDIR(h_mode)))
20053 + } else if (unlikely(!S_ISDIR(h_mode))) {
20058 + /* rename(2) case */
20060 + if (unlikely(d_is_positive(h_dentry)))
20065 + /* expected parent dir is locked */
20066 + if (unlikely(h_parent != h_dentry->d_parent))
20071 + * rmdir a dir may break the consistency on some filesystem.
20072 + * let's try heavy test.
20075 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
20076 + && au_test_h_perm(d_inode(h_parent),
20077 + MAY_EXEC | MAY_WRITE)))
20080 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
20082 + if (IS_ERR(h_latest))
20084 + if (h_latest == h_dentry)
20093 + * decide the branch where we operate for @dentry. the branch index will be set
20094 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
20095 + * dir for reverting.
20096 + * when a new whiteout is necessary, create it.
20098 +static struct dentry*
20099 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
20100 + struct au_dtime *dt, struct au_pin *pin)
20102 + struct dentry *wh_dentry;
20103 + struct super_block *sb;
20104 + struct path h_path;
20105 + int err, need_wh;
20106 + unsigned int udba;
20107 + aufs_bindex_t bcpup;
20109 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
20110 + wh_dentry = ERR_PTR(need_wh);
20111 + if (unlikely(need_wh < 0))
20114 + sb = dentry->d_sb;
20115 + udba = au_opt_udba(sb);
20117 + err = au_pin(pin, dentry, bcpup, udba,
20118 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20119 + wh_dentry = ERR_PTR(err);
20120 + if (unlikely(err))
20123 + h_path.dentry = au_pinned_h_parent(pin);
20124 + if (udba != AuOpt_UDBA_NONE
20125 + && au_dbtop(dentry) == bcpup) {
20126 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
20127 + wh_dentry = ERR_PTR(err);
20128 + if (unlikely(err))
20132 + h_path.mnt = au_sbr_mnt(sb, bcpup);
20133 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
20134 + wh_dentry = NULL;
20136 + goto out; /* success, no need to create whiteout */
20138 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
20139 + if (IS_ERR(wh_dentry))
20142 + /* returns with the parent is locked and wh_dentry is dget-ed */
20143 + goto out; /* success */
20148 + return wh_dentry;
20152 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
20153 + * in order to be revertible and save time for removing many child whiteouts
20155 + * returns 1 when there are too many child whiteout and caller should remove
20156 + * them asynchronously. returns 0 when the number of children is enough small to
20157 + * remove now or the branch fs is a remote fs.
20158 + * otherwise return an error.
20160 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
20161 + struct au_nhash *whlist, struct inode *dir)
20163 + int rmdir_later, err, dirwh;
20164 + struct dentry *h_dentry;
20165 + struct super_block *sb;
20166 + struct inode *inode;
20168 + sb = dentry->d_sb;
20169 + SiMustAnyLock(sb);
20170 + h_dentry = au_h_dptr(dentry, bindex);
20171 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
20172 + if (unlikely(err))
20175 + /* stop monitoring */
20176 + inode = d_inode(dentry);
20177 + au_hn_free(au_hi(inode, bindex));
20179 + if (!au_test_fs_remote(h_dentry->d_sb)) {
20180 + dirwh = au_sbi(sb)->si_dirwh;
20181 + rmdir_later = (dirwh <= 1);
20182 + if (!rmdir_later)
20183 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
20186 + return rmdir_later;
20189 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
20190 + if (unlikely(err)) {
20191 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
20192 + h_dentry, bindex, err);
20202 + * final procedure for deleting a entry.
20203 + * maintain dentry and iattr.
20205 +static void epilog(struct inode *dir, struct dentry *dentry,
20206 + aufs_bindex_t bindex)
20208 + struct inode *inode;
20210 + inode = d_inode(dentry);
20212 + inode->i_ctime = dir->i_ctime;
20214 + au_dir_ts(dir, bindex);
20215 + dir->i_version++;
20219 + * when an error happened, remove the created whiteout and revert everything.
20221 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
20222 + aufs_bindex_t bwh, struct dentry *wh_dentry,
20223 + struct dentry *dentry, struct au_dtime *dt)
20226 + struct path h_path = {
20227 + .dentry = wh_dentry,
20228 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
20231 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
20233 + au_set_dbwh(dentry, bwh);
20234 + au_dtime_revert(dt);
20238 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
20242 +/* ---------------------------------------------------------------------- */
20244 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
20247 + aufs_bindex_t bwh, bindex, btop;
20248 + struct inode *inode, *h_dir, *delegated;
20249 + struct dentry *parent, *wh_dentry;
20250 + /* to reuduce stack size */
20252 + struct au_dtime dt;
20253 + struct au_pin pin;
20254 + struct path h_path;
20260 + a = kmalloc(sizeof(*a), GFP_NOFS);
20261 + if (unlikely(!a))
20264 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20265 + if (unlikely(err))
20267 + err = au_d_hashed_positive(dentry);
20268 + if (unlikely(err))
20270 + inode = d_inode(dentry);
20271 + IMustLock(inode);
20273 + if (unlikely(d_is_dir(dentry)))
20274 + goto out_unlock; /* possible? */
20276 + btop = au_dbtop(dentry);
20277 + bwh = au_dbwh(dentry);
20279 + parent = dentry->d_parent; /* dir inode is locked */
20280 + di_write_lock_parent(parent);
20281 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
20283 + err = PTR_ERR(wh_dentry);
20284 + if (IS_ERR(wh_dentry))
20287 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
20288 + a->h_path.dentry = au_h_dptr(dentry, btop);
20289 + dget(a->h_path.dentry);
20290 + if (bindex == btop) {
20291 + h_dir = au_pinned_h_dir(&a->pin);
20292 + delegated = NULL;
20293 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
20294 + if (unlikely(err == -EWOULDBLOCK)) {
20295 + pr_warn("cannot retry for NFSv4 delegation"
20296 + " for an internal unlink\n");
20300 + /* dir inode is locked */
20301 + h_dir = d_inode(wh_dentry->d_parent);
20302 + IMustLock(h_dir);
20307 + vfsub_drop_nlink(inode);
20308 + epilog(dir, dentry, bindex);
20310 + /* update target timestamps */
20311 + if (bindex == btop) {
20312 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
20314 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20316 + /* todo: this timestamp may be reverted later */
20317 + inode->i_ctime = h_dir->i_ctime;
20318 + goto out_unpin; /* success */
20325 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20332 + au_unpin(&a->pin);
20334 + dput(a->h_path.dentry);
20336 + di_write_unlock(parent);
20338 + aufs_read_unlock(dentry, AuLock_DW);
20340 + au_delayed_kfree(a);
20345 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
20347 + int err, rmdir_later;
20348 + aufs_bindex_t bwh, bindex, btop;
20349 + struct inode *inode;
20350 + struct dentry *parent, *wh_dentry, *h_dentry;
20351 + struct au_whtmp_rmdir *args;
20352 + /* to reuduce stack size */
20354 + struct au_dtime dt;
20355 + struct au_pin pin;
20361 + a = kmalloc(sizeof(*a), GFP_NOFS);
20362 + if (unlikely(!a))
20365 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20366 + if (unlikely(err))
20368 + err = au_alive_dir(dentry);
20369 + if (unlikely(err))
20371 + inode = d_inode(dentry);
20372 + IMustLock(inode);
20374 + if (unlikely(!d_is_dir(dentry)))
20375 + goto out_unlock; /* possible? */
20378 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20379 + if (unlikely(!args))
20382 + parent = dentry->d_parent; /* dir inode is locked */
20383 + di_write_lock_parent(parent);
20384 + err = au_test_empty(dentry, &args->whlist);
20385 + if (unlikely(err))
20388 + btop = au_dbtop(dentry);
20389 + bwh = au_dbwh(dentry);
20391 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20393 + err = PTR_ERR(wh_dentry);
20394 + if (IS_ERR(wh_dentry))
20397 + h_dentry = au_h_dptr(dentry, btop);
20400 + if (bindex == btop) {
20401 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
20403 + rmdir_later = err;
20407 + /* stop monitoring */
20408 + au_hn_free(au_hi(inode, btop));
20410 + /* dir inode is locked */
20411 + IMustLock(d_inode(wh_dentry->d_parent));
20416 + vfsub_dead_dir(inode);
20417 + au_set_dbdiropq(dentry, -1);
20418 + epilog(dir, dentry, bindex);
20420 + if (rmdir_later) {
20421 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
20425 + goto out_unpin; /* success */
20433 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20440 + au_unpin(&a->pin);
20444 + di_write_unlock(parent);
20446 + au_whtmp_rmdir_free(args);
20448 + aufs_read_unlock(dentry, AuLock_DW);
20450 + au_delayed_kfree(a);
20455 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20456 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20457 +++ linux/fs/aufs/i_op_ren.c 2016-10-09 16:55:36.492701639 +0200
20460 + * Copyright (C) 2005-2016 Junjiro R. Okajima
20462 + * This program, aufs is free software; you can redistribute it and/or modify
20463 + * it under the terms of the GNU General Public License as published by
20464 + * the Free Software Foundation; either version 2 of the License, or
20465 + * (at your option) any later version.
20467 + * This program is distributed in the hope that it will be useful,
20468 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20469 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20470 + * GNU General Public License for more details.
20472 + * You should have received a copy of the GNU General Public License
20473 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20477 + * inode operation (rename entry)
20478 + * todo: this is crazy monster
20483 +enum { AuSRC, AuDST, AuSrcDst };
20484 +enum { AuPARENT, AuCHILD, AuParentChild };
20486 +#define AuRen_ISDIR 1
20487 +#define AuRen_ISSAMEDIR (1 << 1)
20488 +#define AuRen_WHSRC (1 << 2)
20489 +#define AuRen_WHDST (1 << 3)
20490 +#define AuRen_MNT_WRITE (1 << 4)
20491 +#define AuRen_DT_DSTDIR (1 << 5)
20492 +#define AuRen_DIROPQ (1 << 6)
20493 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20494 +#define au_fset_ren(flags, name) \
20495 + do { (flags) |= AuRen_##name; } while (0)
20496 +#define au_fclr_ren(flags, name) \
20497 + do { (flags) &= ~AuRen_##name; } while (0)
20499 +struct au_ren_args {
20501 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20503 + struct inode *dir, *inode;
20504 + struct au_hinode *hdir;
20505 + struct au_dtime dt[AuParentChild];
20506 + aufs_bindex_t btop;
20509 +#define src_dentry sd[AuSRC].dentry
20510 +#define src_dir sd[AuSRC].dir
20511 +#define src_inode sd[AuSRC].inode
20512 +#define src_h_dentry sd[AuSRC].h_dentry
20513 +#define src_parent sd[AuSRC].parent
20514 +#define src_h_parent sd[AuSRC].h_parent
20515 +#define src_wh_dentry sd[AuSRC].wh_dentry
20516 +#define src_hdir sd[AuSRC].hdir
20517 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20518 +#define src_dt sd[AuSRC].dt
20519 +#define src_btop sd[AuSRC].btop
20521 +#define dst_dentry sd[AuDST].dentry
20522 +#define dst_dir sd[AuDST].dir
20523 +#define dst_inode sd[AuDST].inode
20524 +#define dst_h_dentry sd[AuDST].h_dentry
20525 +#define dst_parent sd[AuDST].parent
20526 +#define dst_h_parent sd[AuDST].h_parent
20527 +#define dst_wh_dentry sd[AuDST].wh_dentry
20528 +#define dst_hdir sd[AuDST].hdir
20529 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20530 +#define dst_dt sd[AuDST].dt
20531 +#define dst_btop sd[AuDST].btop
20533 + struct dentry *h_trap;
20534 + struct au_branch *br;
20535 + struct au_hinode *src_hinode;
20536 + struct path h_path;
20537 + struct au_nhash whlist;
20538 + aufs_bindex_t btgt, src_bwh, src_bdiropq;
20540 + unsigned int flags;
20542 + struct au_whtmp_rmdir *thargs;
20543 + struct dentry *h_dst;
20546 +/* ---------------------------------------------------------------------- */
20549 + * functions for reverting.
20550 + * when an error happened in a single rename systemcall, we should revert
20551 + * everything as if nothing happened.
20552 + * we don't need to revert the copied-up/down the parent dir since they are
20556 +#define RevertFailure(fmt, ...) do { \
20557 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20558 + ##__VA_ARGS__, err, rerr); \
20562 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20566 + au_hn_inode_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20567 + rerr = au_diropq_remove(a->src_dentry, a->btgt);
20568 + au_hn_inode_unlock(a->src_hinode);
20569 + au_set_dbdiropq(a->src_dentry, a->src_bdiropq);
20571 + RevertFailure("remove diropq %pd", a->src_dentry);
20574 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20577 + struct inode *delegated;
20579 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20580 + a->src_h_parent);
20581 + rerr = PTR_ERR(a->h_path.dentry);
20582 + if (IS_ERR(a->h_path.dentry)) {
20583 + RevertFailure("lkup one %pd", a->src_dentry);
20587 + delegated = NULL;
20588 + rerr = vfsub_rename(a->dst_h_dir,
20589 + au_h_dptr(a->src_dentry, a->btgt),
20590 + a->src_h_dir, &a->h_path, &delegated);
20591 + if (unlikely(rerr == -EWOULDBLOCK)) {
20592 + pr_warn("cannot retry for NFSv4 delegation"
20593 + " for an internal rename\n");
20596 + d_drop(a->h_path.dentry);
20597 + dput(a->h_path.dentry);
20598 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20600 + RevertFailure("rename %pd", a->src_dentry);
20603 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20606 + struct inode *delegated;
20608 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20609 + a->dst_h_parent);
20610 + rerr = PTR_ERR(a->h_path.dentry);
20611 + if (IS_ERR(a->h_path.dentry)) {
20612 + RevertFailure("lkup one %pd", a->dst_dentry);
20615 + if (d_is_positive(a->h_path.dentry)) {
20616 + d_drop(a->h_path.dentry);
20617 + dput(a->h_path.dentry);
20621 + delegated = NULL;
20622 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20624 + if (unlikely(rerr == -EWOULDBLOCK)) {
20625 + pr_warn("cannot retry for NFSv4 delegation"
20626 + " for an internal rename\n");
20629 + d_drop(a->h_path.dentry);
20630 + dput(a->h_path.dentry);
20632 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20634 + RevertFailure("rename %pd", a->h_dst);
20637 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20641 + a->h_path.dentry = a->src_wh_dentry;
20642 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20643 + au_set_dbwh(a->src_dentry, a->src_bwh);
20645 + RevertFailure("unlink %pd", a->src_wh_dentry);
20647 +#undef RevertFailure
20649 +/* ---------------------------------------------------------------------- */
20652 + * when we have to copyup the renaming entry, do it with the rename-target name
20653 + * in order to minimize the cost (the later actual rename is unnecessary).
20654 + * otherwise rename it on the target branch.
20656 +static int au_ren_or_cpup(struct au_ren_args *a)
20659 + struct dentry *d;
20660 + struct inode *delegated;
20662 + d = a->src_dentry;
20663 + if (au_dbtop(d) == a->btgt) {
20664 + a->h_path.dentry = a->dst_h_dentry;
20665 + if (au_ftest_ren(a->flags, DIROPQ)
20666 + && au_dbdiropq(d) == a->btgt)
20667 + au_fclr_ren(a->flags, DIROPQ);
20668 + AuDebugOn(au_dbtop(d) != a->btgt);
20669 + delegated = NULL;
20670 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20671 + a->dst_h_dir, &a->h_path, &delegated);
20672 + if (unlikely(err == -EWOULDBLOCK)) {
20673 + pr_warn("cannot retry for NFSv4 delegation"
20674 + " for an internal rename\n");
20680 + if (!err && a->h_dst)
20681 + /* it will be set to dinfo later */
20687 +/* cf. aufs_rmdir() */
20688 +static int au_ren_del_whtmp(struct au_ren_args *a)
20691 + struct inode *dir;
20693 + dir = a->dst_dir;
20694 + SiMustAnyLock(dir->i_sb);
20695 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20696 + au_sbi(dir->i_sb)->si_dirwh)
20697 + || au_test_fs_remote(a->h_dst->d_sb)) {
20698 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20699 + if (unlikely(err))
20700 + pr_warn("failed removing whtmp dir %pd (%d), "
20701 + "ignored.\n", a->h_dst, err);
20703 + au_nhash_wh_free(&a->thargs->whlist);
20704 + a->thargs->whlist = a->whlist;
20705 + a->whlist.nh_num = 0;
20706 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20708 + a->thargs = NULL;
20714 +/* make it 'opaque' dir. */
20715 +static int au_ren_diropq(struct au_ren_args *a)
20718 + struct dentry *diropq;
20721 + a->src_bdiropq = au_dbdiropq(a->src_dentry);
20722 + a->src_hinode = au_hi(a->src_inode, a->btgt);
20723 + au_hn_inode_lock_nested(a->src_hinode, AuLsc_I_CHILD);
20724 + diropq = au_diropq_create(a->src_dentry, a->btgt);
20725 + au_hn_inode_unlock(a->src_hinode);
20726 + if (IS_ERR(diropq))
20727 + err = PTR_ERR(diropq);
20734 +static int do_rename(struct au_ren_args *a)
20737 + struct dentry *d, *h_d;
20739 + /* prepare workqueue args for asynchronous rmdir */
20740 + h_d = a->dst_h_dentry;
20741 + if (au_ftest_ren(a->flags, ISDIR) && d_is_positive(h_d)) {
20743 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, GFP_NOFS);
20744 + if (unlikely(!a->thargs))
20746 + a->h_dst = dget(h_d);
20749 + /* create whiteout for src_dentry */
20750 + if (au_ftest_ren(a->flags, WHSRC)) {
20751 + a->src_bwh = au_dbwh(a->src_dentry);
20752 + AuDebugOn(a->src_bwh >= 0);
20754 + = au_wh_create(a->src_dentry, a->btgt, a->src_h_parent);
20755 + err = PTR_ERR(a->src_wh_dentry);
20756 + if (IS_ERR(a->src_wh_dentry))
20760 + /* lookup whiteout for dentry */
20761 + if (au_ftest_ren(a->flags, WHDST)) {
20762 + h_d = au_wh_lkup(a->dst_h_parent, &a->dst_dentry->d_name,
20764 + err = PTR_ERR(h_d);
20767 + if (d_is_negative(h_d))
20770 + a->dst_wh_dentry = h_d;
20773 + /* rename dentry to tmpwh */
20775 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20776 + if (unlikely(err))
20779 + d = a->dst_dentry;
20780 + au_set_h_dptr(d, a->btgt, NULL);
20781 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20782 + if (unlikely(err))
20784 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20787 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
20789 + /* rename by vfs_rename or cpup */
20790 + d = a->dst_dentry;
20791 + if (au_ftest_ren(a->flags, ISDIR)
20792 + && (a->dst_wh_dentry
20793 + || au_dbdiropq(d) == a->btgt
20794 + /* hide the lower to keep xino */
20795 + || a->btgt < au_dbbot(d)
20796 + || au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ)))
20797 + au_fset_ren(a->flags, DIROPQ);
20798 + err = au_ren_or_cpup(a);
20799 + if (unlikely(err))
20800 + /* leave the copied-up one */
20803 + /* make dir opaque */
20804 + if (au_ftest_ren(a->flags, DIROPQ)) {
20805 + err = au_ren_diropq(a);
20806 + if (unlikely(err))
20810 + /* update target timestamps */
20811 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
20812 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20813 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20814 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20816 + /* remove whiteout for dentry */
20817 + if (a->dst_wh_dentry) {
20818 + a->h_path.dentry = a->dst_wh_dentry;
20819 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20821 + if (unlikely(err))
20825 + /* remove whtmp */
20827 + au_ren_del_whtmp(a); /* ignore this error */
20829 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20831 + goto out_success;
20834 + if (au_ftest_ren(a->flags, DIROPQ))
20835 + au_ren_rev_diropq(err, a);
20837 + au_ren_rev_rename(err, a);
20841 + au_ren_rev_whtmp(err, a);
20843 + dput(a->dst_wh_dentry);
20844 + a->dst_wh_dentry = NULL;
20846 + if (a->src_wh_dentry)
20847 + au_ren_rev_whsrc(err, a);
20849 + dput(a->src_wh_dentry);
20850 + dput(a->dst_wh_dentry);
20854 + au_whtmp_rmdir_free(a->thargs);
20855 + a->thargs = NULL;
20861 +/* ---------------------------------------------------------------------- */
20864 + * test if @dentry dir can be rename destination or not.
20865 + * success means, it is a logically empty dir.
20867 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20869 + return au_test_empty(dentry, whlist);
20873 + * test if @dentry dir can be rename source or not.
20874 + * if it can, return 0 and @children is filled.
20876 + * - it is a logically empty dir.
20877 + * - or, it exists on writable branch and has no children including whiteouts
20878 + * on the lower branch.
20880 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20883 + unsigned int rdhash;
20884 + aufs_bindex_t btop;
20886 + btop = au_dbtop(dentry);
20887 + if (btop != btgt) {
20888 + struct au_nhash whlist;
20890 + SiMustAnyLock(dentry->d_sb);
20891 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20893 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20895 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20896 + if (unlikely(err))
20898 + err = au_test_empty(dentry, &whlist);
20899 + au_nhash_wh_free(&whlist);
20903 + if (btop == au_dbtaildir(dentry))
20904 + return 0; /* success */
20906 + err = au_test_empty_lower(dentry);
20909 + if (err == -ENOTEMPTY) {
20910 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20911 + " is not supported\n");
20917 +/* side effect: sets whlist and h_dentry */
20918 +static int au_ren_may_dir(struct au_ren_args *a)
20921 + unsigned int rdhash;
20922 + struct dentry *d;
20924 + d = a->dst_dentry;
20925 + SiMustAnyLock(d->d_sb);
20928 + if (au_ftest_ren(a->flags, ISDIR) && a->dst_inode) {
20929 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20931 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20932 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20933 + if (unlikely(err))
20936 + au_set_dbtop(d, a->dst_btop);
20937 + err = may_rename_dstdir(d, &a->whlist);
20938 + au_set_dbtop(d, a->btgt);
20940 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
20941 + if (unlikely(err))
20944 + d = a->src_dentry;
20945 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
20946 + if (au_ftest_ren(a->flags, ISDIR)) {
20947 + err = may_rename_srcdir(d, a->btgt);
20948 + if (unlikely(err)) {
20949 + au_nhash_wh_free(&a->whlist);
20950 + a->whlist.nh_num = 0;
20957 +/* ---------------------------------------------------------------------- */
20960 + * simple tests for rename.
20961 + * following the checks in vfs, plus the parent-child relationship.
20963 +static int au_may_ren(struct au_ren_args *a)
20966 + struct inode *h_inode;
20968 + if (a->src_btop == a->btgt) {
20969 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20970 + au_ftest_ren(a->flags, ISDIR));
20971 + if (unlikely(err))
20974 + if (unlikely(a->src_h_dentry == a->h_trap))
20979 + if (a->dst_btop != a->btgt)
20982 + err = -ENOTEMPTY;
20983 + if (unlikely(a->dst_h_dentry == a->h_trap))
20987 + isdir = !!au_ftest_ren(a->flags, ISDIR);
20988 + if (d_really_is_negative(a->dst_dentry)) {
20989 + if (d_is_negative(a->dst_h_dentry))
20990 + err = au_may_add(a->dst_dentry, a->btgt,
20991 + a->dst_h_parent, isdir);
20993 + if (unlikely(d_is_negative(a->dst_h_dentry)))
20995 + h_inode = d_inode(a->dst_h_dentry);
20996 + if (h_inode->i_nlink)
20997 + err = au_may_del(a->dst_dentry, a->btgt,
20998 + a->dst_h_parent, isdir);
21002 + if (unlikely(err == -ENOENT || err == -EEXIST))
21008 +/* ---------------------------------------------------------------------- */
21013 + * - src_dir and dir by lock_rename()
21014 + * - inode if exitsts
21017 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
21019 + * + di_write_lock2_child()
21020 + * + di_write_lock_child()
21021 + * + ii_write_lock_child()
21022 + * + di_write_lock_child2()
21023 + * + ii_write_lock_child2()
21024 + * + src_parent and parent
21025 + * + di_write_lock_parent()
21026 + * + ii_write_lock_parent()
21027 + * + di_write_lock_parent2()
21028 + * + ii_write_lock_parent2()
21029 + * + lower src_dir and dir by vfsub_lock_rename()
21030 + * + verify the every relationships between child and parent. if any
21031 + * of them failed, unlock all and return -EBUSY.
21033 +static void au_ren_unlock(struct au_ren_args *a)
21035 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
21036 + a->dst_h_parent, a->dst_hdir);
21037 + if (au_ftest_ren(a->flags, MNT_WRITE))
21038 + vfsub_mnt_drop_write(au_br_mnt(a->br));
21041 +static int au_ren_lock(struct au_ren_args *a)
21044 + unsigned int udba;
21047 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
21048 + a->src_hdir = au_hi(a->src_dir, a->btgt);
21049 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
21050 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
21052 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
21053 + if (unlikely(err))
21055 + au_fset_ren(a->flags, MNT_WRITE);
21056 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
21057 + a->dst_h_parent, a->dst_hdir);
21058 + udba = au_opt_udba(a->src_dentry->d_sb);
21059 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
21060 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
21061 + err = au_busy_or_stale();
21062 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
21063 + err = au_h_verify(a->src_h_dentry, udba,
21064 + d_inode(a->src_h_parent), a->src_h_parent,
21066 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
21067 + err = au_h_verify(a->dst_h_dentry, udba,
21068 + d_inode(a->dst_h_parent), a->dst_h_parent,
21071 + goto out; /* success */
21073 + err = au_busy_or_stale();
21074 + au_ren_unlock(a);
21080 +/* ---------------------------------------------------------------------- */
21082 +static void au_ren_refresh_dir(struct au_ren_args *a)
21084 + struct inode *dir;
21086 + dir = a->dst_dir;
21087 + dir->i_version++;
21088 + if (au_ftest_ren(a->flags, ISDIR)) {
21089 + /* is this updating defined in POSIX? */
21090 + au_cpup_attr_timesizes(a->src_inode);
21091 + au_cpup_attr_nlink(dir, /*force*/1);
21094 + au_dir_ts(dir, a->btgt);
21096 + if (au_ftest_ren(a->flags, ISSAMEDIR))
21099 + dir = a->src_dir;
21100 + dir->i_version++;
21101 + if (au_ftest_ren(a->flags, ISDIR))
21102 + au_cpup_attr_nlink(dir, /*force*/1);
21103 + au_dir_ts(dir, a->btgt);
21106 +static void au_ren_refresh(struct au_ren_args *a)
21108 + aufs_bindex_t bbot, bindex;
21109 + struct dentry *d, *h_d;
21110 + struct inode *i, *h_i;
21111 + struct super_block *sb;
21113 + d = a->dst_dentry;
21116 + /* already dget-ed by au_ren_or_cpup() */
21117 + au_set_h_dptr(d, a->btgt, a->h_dst);
21119 + i = a->dst_inode;
21121 + if (!au_ftest_ren(a->flags, ISDIR))
21122 + vfsub_drop_nlink(i);
21124 + vfsub_dead_dir(i);
21125 + au_cpup_attr_timesizes(i);
21127 + au_update_dbrange(d, /*do_put_zero*/1);
21130 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
21131 + au_set_h_dptr(d, bindex, NULL);
21132 + bbot = au_dbbot(d);
21133 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
21134 + au_set_h_dptr(d, bindex, NULL);
21135 + au_update_dbrange(d, /*do_put_zero*/0);
21138 + d = a->src_dentry;
21139 + au_set_dbwh(d, -1);
21140 + bbot = au_dbbot(d);
21141 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21142 + h_d = au_h_dptr(d, bindex);
21144 + au_set_h_dptr(d, bindex, NULL);
21146 + au_set_dbbot(d, a->btgt);
21149 + i = a->src_inode;
21150 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
21151 + return; /* success */
21153 + bbot = au_ibbot(i);
21154 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21155 + h_i = au_h_iptr(i, bindex);
21157 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
21158 + /* ignore this error */
21159 + au_set_h_iptr(i, bindex, NULL, 0);
21162 + au_set_ibbot(i, a->btgt);
21165 +/* ---------------------------------------------------------------------- */
21167 +/* mainly for link(2) and rename(2) */
21168 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
21170 + aufs_bindex_t bdiropq, bwh;
21171 + struct dentry *parent;
21172 + struct au_branch *br;
21174 + parent = dentry->d_parent;
21175 + IMustLock(d_inode(parent)); /* dir is locked */
21177 + bdiropq = au_dbdiropq(parent);
21178 + bwh = au_dbwh(dentry);
21179 + br = au_sbr(dentry->d_sb, btgt);
21180 + if (au_br_rdonly(br)
21181 + || (0 <= bdiropq && bdiropq < btgt)
21182 + || (0 <= bwh && bwh < btgt))
21185 + AuDbg("btgt %d\n", btgt);
21189 +/* sets src_btop, dst_btop and btgt */
21190 +static int au_ren_wbr(struct au_ren_args *a)
21193 + struct au_wr_dir_args wr_dir_args = {
21194 + /* .force_btgt = -1, */
21195 + .flags = AuWrDir_ADD_ENTRY
21198 + a->src_btop = au_dbtop(a->src_dentry);
21199 + a->dst_btop = au_dbtop(a->dst_dentry);
21200 + if (au_ftest_ren(a->flags, ISDIR))
21201 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21202 + wr_dir_args.force_btgt = a->src_btop;
21203 + if (a->dst_inode && a->dst_btop < a->src_btop)
21204 + wr_dir_args.force_btgt = a->dst_btop;
21205 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
21206 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
21212 +static void au_ren_dt(struct au_ren_args *a)
21214 + a->h_path.dentry = a->src_h_parent;
21215 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
21216 + if (!au_ftest_ren(a->flags, ISSAMEDIR)) {
21217 + a->h_path.dentry = a->dst_h_parent;
21218 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
21221 + au_fclr_ren(a->flags, DT_DSTDIR);
21222 + if (!au_ftest_ren(a->flags, ISDIR))
21225 + a->h_path.dentry = a->src_h_dentry;
21226 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
21227 + if (d_is_positive(a->dst_h_dentry)) {
21228 + au_fset_ren(a->flags, DT_DSTDIR);
21229 + a->h_path.dentry = a->dst_h_dentry;
21230 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
21234 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
21236 + struct dentry *h_d;
21237 + struct inode *h_inode;
21239 + au_dtime_revert(a->src_dt + AuPARENT);
21240 + if (!au_ftest_ren(a->flags, ISSAMEDIR))
21241 + au_dtime_revert(a->dst_dt + AuPARENT);
21243 + if (au_ftest_ren(a->flags, ISDIR) && err != -EIO) {
21244 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
21245 + h_inode = d_inode(h_d);
21246 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21247 + au_dtime_revert(a->src_dt + AuCHILD);
21248 + inode_unlock(h_inode);
21250 + if (au_ftest_ren(a->flags, DT_DSTDIR)) {
21251 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
21252 + h_inode = d_inode(h_d);
21253 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21254 + au_dtime_revert(a->dst_dt + AuCHILD);
21255 + inode_unlock(h_inode);
21260 +/* ---------------------------------------------------------------------- */
21262 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
21263 + struct inode *_dst_dir, struct dentry *_dst_dentry)
21266 + /* reduce stack space */
21267 + struct au_ren_args *a;
21269 + AuDbg("%pd, %pd\n", _src_dentry, _dst_dentry);
21270 + IMustLock(_src_dir);
21271 + IMustLock(_dst_dir);
21274 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
21275 + a = kzalloc(sizeof(*a), GFP_NOFS);
21276 + if (unlikely(!a))
21279 + a->src_dir = _src_dir;
21280 + a->src_dentry = _src_dentry;
21281 + a->src_inode = NULL;
21282 + if (d_really_is_positive(a->src_dentry))
21283 + a->src_inode = d_inode(a->src_dentry);
21284 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
21285 + a->dst_dir = _dst_dir;
21286 + a->dst_dentry = _dst_dentry;
21287 + a->dst_inode = NULL;
21288 + if (d_really_is_positive(a->dst_dentry))
21289 + a->dst_inode = d_inode(a->dst_dentry);
21290 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
21291 + if (a->dst_inode) {
21292 + IMustLock(a->dst_inode);
21293 + au_igrab(a->dst_inode);
21297 + flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
21298 + if (d_is_dir(a->src_dentry)) {
21299 + au_fset_ren(a->flags, ISDIR);
21300 + if (unlikely(d_really_is_positive(a->dst_dentry)
21301 + && !d_is_dir(a->dst_dentry)))
21303 + flags |= AuLock_DIRS;
21305 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, flags);
21306 + if (unlikely(err))
21309 + err = au_d_hashed_positive(a->src_dentry);
21310 + if (unlikely(err))
21313 + if (a->dst_inode) {
21315 + * If it is a dir, VFS unhash dst_dentry before this
21316 + * function. It means we cannot rely upon d_unhashed().
21318 + if (unlikely(!a->dst_inode->i_nlink))
21320 + if (!S_ISDIR(a->dst_inode->i_mode)) {
21321 + err = au_d_hashed_positive(a->dst_dentry);
21322 + if (unlikely(err))
21324 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
21326 + } else if (unlikely(d_unhashed(a->dst_dentry)))
21330 + * is it possible?
21331 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
21332 + * there may exist a problem somewhere else.
21335 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
21338 + au_fset_ren(a->flags, ISSAMEDIR); /* temporary */
21339 + di_write_lock_parent(a->dst_parent);
21341 + /* which branch we process */
21342 + err = au_ren_wbr(a);
21343 + if (unlikely(err < 0))
21345 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
21346 + a->h_path.mnt = au_br_mnt(a->br);
21348 + /* are they available to be renamed */
21349 + err = au_ren_may_dir(a);
21350 + if (unlikely(err))
21351 + goto out_children;
21353 + /* prepare the writable parent dir on the same branch */
21354 + if (a->dst_btop == a->btgt) {
21355 + au_fset_ren(a->flags, WHDST);
21357 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
21358 + if (unlikely(err))
21359 + goto out_children;
21362 + if (a->src_dir != a->dst_dir) {
21364 + * this temporary unlock is safe,
21365 + * because both dir->i_mutex are locked.
21367 + di_write_unlock(a->dst_parent);
21368 + di_write_lock_parent(a->src_parent);
21369 + err = au_wr_dir_need_wh(a->src_dentry,
21370 + au_ftest_ren(a->flags, ISDIR),
21372 + di_write_unlock(a->src_parent);
21373 + di_write_lock2_parent(a->src_parent, a->dst_parent, /*isdir*/1);
21374 + au_fclr_ren(a->flags, ISSAMEDIR);
21376 + err = au_wr_dir_need_wh(a->src_dentry,
21377 + au_ftest_ren(a->flags, ISDIR),
21379 + if (unlikely(err < 0))
21380 + goto out_children;
21382 + au_fset_ren(a->flags, WHSRC);
21385 + if (a->src_btop != a->btgt) {
21386 + struct au_pin pin;
21388 + err = au_pin(&pin, a->src_dentry, a->btgt,
21389 + au_opt_udba(a->src_dentry->d_sb),
21390 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21392 + struct au_cp_generic cpg = {
21393 + .dentry = a->src_dentry,
21395 + .bsrc = a->src_btop,
21398 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21400 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
21401 + err = au_sio_cpup_simple(&cpg);
21404 + if (unlikely(err))
21405 + goto out_children;
21406 + a->src_btop = a->btgt;
21407 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21408 + au_fset_ren(a->flags, WHSRC);
21411 + /* lock them all */
21412 + err = au_ren_lock(a);
21413 + if (unlikely(err))
21414 + /* leave the copied-up one */
21415 + goto out_children;
21417 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21418 + err = au_may_ren(a);
21419 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21420 + err = -ENAMETOOLONG;
21421 + if (unlikely(err))
21424 + /* store timestamps to be revertible */
21428 + err = do_rename(a);
21429 + if (unlikely(err))
21432 + /* update dir attributes */
21433 + au_ren_refresh_dir(a);
21435 + /* dput/iput all lower dentries */
21436 + au_ren_refresh(a);
21438 + goto out_hdir; /* success */
21441 + au_ren_rev_dt(err, a);
21443 + au_ren_unlock(a);
21445 + au_nhash_wh_free(&a->whlist);
21446 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
21447 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
21448 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21449 + au_set_dbtop(a->dst_dentry, a->dst_btop);
21453 + d_move(a->src_dentry, a->dst_dentry);
21455 + au_update_dbtop(a->dst_dentry);
21456 + if (!a->dst_inode)
21457 + d_drop(a->dst_dentry);
21459 + if (au_ftest_ren(a->flags, ISSAMEDIR))
21460 + di_write_unlock(a->dst_parent);
21462 + di_write_unlock2(a->src_parent, a->dst_parent);
21464 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21466 + iput(a->dst_inode);
21468 + au_whtmp_rmdir_free(a->thargs);
21469 + au_delayed_kfree(a);
21474 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21475 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21476 +++ linux/fs/aufs/Kconfig 2016-10-09 16:55:36.482701377 +0200
21479 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21481 + Aufs is a stackable unification filesystem such as Unionfs,
21482 + which unifies several directories and provides a merged single
21484 + In the early days, aufs was entirely re-designed and
21485 + re-implemented Unionfs Version 1.x series. Introducing many
21486 + original ideas, approaches and improvements, it becomes totally
21487 + different from Unionfs while keeping the basic features.
21491 + prompt "Maximum number of branches"
21492 + default AUFS_BRANCH_MAX_127
21494 + Specifies the maximum number of branches (or member directories)
21495 + in a single aufs. The larger value consumes more system
21496 + resources and has a minor impact to performance.
21497 +config AUFS_BRANCH_MAX_127
21500 + Specifies the maximum number of branches (or member directories)
21501 + in a single aufs. The larger value consumes more system
21502 + resources and has a minor impact to performance.
21503 +config AUFS_BRANCH_MAX_511
21506 + Specifies the maximum number of branches (or member directories)
21507 + in a single aufs. The larger value consumes more system
21508 + resources and has a minor impact to performance.
21509 +config AUFS_BRANCH_MAX_1023
21512 + Specifies the maximum number of branches (or member directories)
21513 + in a single aufs. The larger value consumes more system
21514 + resources and has a minor impact to performance.
21515 +config AUFS_BRANCH_MAX_32767
21518 + Specifies the maximum number of branches (or member directories)
21519 + in a single aufs. The larger value consumes more system
21520 + resources and has a minor impact to performance.
21523 +config AUFS_SBILIST
21525 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21528 + Automatic configuration for internal use.
21529 + When aufs supports Magic SysRq or /proc, enabled automatically.
21531 +config AUFS_HNOTIFY
21532 + bool "Detect direct branch access (bypassing aufs)"
21534 + If you want to modify files on branches directly, eg. bypassing aufs,
21535 + and want aufs to detect the changes of them fully, then enable this
21536 + option and use 'udba=notify' mount option.
21537 + Currently there is only one available configuration, "fsnotify".
21538 + It will have a negative impact to the performance.
21539 + See detail in aufs.5.
21542 + prompt "method" if AUFS_HNOTIFY
21543 + default AUFS_HFSNOTIFY
21544 +config AUFS_HFSNOTIFY
21549 +config AUFS_EXPORT
21550 + bool "NFS-exportable aufs"
21551 + depends on EXPORTFS
21553 + If you want to export your mounted aufs via NFS, then enable this
21554 + option. There are several requirements for this configuration.
21555 + See detail in aufs.5.
21557 +config AUFS_INO_T_64
21559 + depends on AUFS_EXPORT
21560 + depends on 64BIT && !(ALPHA || S390)
21563 + Automatic configuration for internal use.
21564 + /* typedef unsigned long/int __kernel_ino_t */
21565 + /* alpha and s390x are int */
21568 + bool "support for XATTR/EA (including Security Labels)"
21570 + If your branch fs supports XATTR/EA and you want to make them
21571 + available in aufs too, then enable this opsion and specify the
21572 + branch attributes for EA.
21573 + See detail in aufs.5.
21576 + bool "File-based Hierarchical Storage Management"
21578 + Hierarchical Storage Management (or HSM) is a well-known feature
21579 + in the storage world. Aufs provides this feature as file-based.
21580 + with multiple branches.
21581 + These multiple branches are prioritized, ie. the topmost one
21582 + should be the fastest drive and be used heavily.
21585 + bool "Readdir in userspace"
21587 + Aufs has two methods to provide a merged view for a directory,
21588 + by a user-space library and by kernel-space natively. The latter
21589 + is always enabled but sometimes large and slow.
21590 + If you enable this option, install the library in aufs2-util
21591 + package, and set some environment variables for your readdir(3),
21592 + then the work will be handled in user-space which generally
21593 + shows better performance in most cases.
21594 + See detail in aufs.5.
21597 + bool "Show whiteouts"
21599 + If you want to make the whiteouts in aufs visible, then enable
21600 + this option and specify 'shwh' mount option. Although it may
21601 + sounds like philosophy or something, but in technically it
21602 + simply shows the name of whiteout with keeping its behaviour.
21604 +config AUFS_BR_RAMFS
21605 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21607 + If you want to use ramfs as an aufs branch fs, then enable this
21608 + option. Generally tmpfs is recommended.
21609 + Aufs prohibited them to be a branch fs by default, because
21610 + initramfs becomes unusable after switch_root or something
21611 + generally. If you sets initramfs as an aufs branch and boot your
21612 + system by switch_root, you will meet a problem easily since the
21613 + files in initramfs may be inaccessible.
21614 + Unless you are going to use ramfs as an aufs branch fs without
21615 + switch_root or something, leave it N.
21617 +config AUFS_BR_FUSE
21618 + bool "Fuse fs as an aufs branch"
21619 + depends on FUSE_FS
21622 + If you want to use fuse-based userspace filesystem as an aufs
21623 + branch fs, then enable this option.
21624 + It implements the internal poll(2) operation which is
21625 + implemented by fuse only (curretnly).
21630 + Automatic configuration for internal use.
21632 +config AUFS_BR_HFSPLUS
21633 + bool "Hfsplus as an aufs branch"
21634 + depends on HFSPLUS_FS
21637 + If you want to use hfsplus fs as an aufs branch fs, then enable
21638 + this option. This option introduces a small overhead at
21639 + copying-up a file on hfsplus.
21641 +config AUFS_BDEV_LOOP
21643 + depends on BLK_DEV_LOOP
21646 + Automatic configuration for internal use.
21647 + Convert =[ym] into =y.
21650 + bool "Debug aufs"
21652 + Enable this to compile aufs internal debug code.
21653 + It will have a negative impact to the performance.
21655 +config AUFS_MAGIC_SYSRQ
21657 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21660 + Automatic configuration for internal use.
21661 + When aufs supports Magic SysRq, enabled automatically.
21663 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21664 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21665 +++ linux/fs/aufs/loop.c 2016-10-09 16:55:38.889431135 +0200
21668 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21670 + * This program, aufs is free software; you can redistribute it and/or modify
21671 + * it under the terms of the GNU General Public License as published by
21672 + * the Free Software Foundation; either version 2 of the License, or
21673 + * (at your option) any later version.
21675 + * This program is distributed in the hope that it will be useful,
21676 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21677 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21678 + * GNU General Public License for more details.
21680 + * You should have received a copy of the GNU General Public License
21681 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21685 + * support for loopback block device as a branch
21690 +/* added into drivers/block/loop.c */
21691 +static struct file *(*backing_file_func)(struct super_block *sb);
21694 + * test if two lower dentries have overlapping branches.
21696 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21698 + struct super_block *h_sb;
21699 + struct file *backing_file;
21701 + if (unlikely(!backing_file_func)) {
21702 + /* don't load "loop" module here */
21703 + backing_file_func = symbol_get(loop_backing_file);
21704 + if (unlikely(!backing_file_func))
21705 + /* "loop" module is not loaded */
21709 + h_sb = h_adding->d_sb;
21710 + backing_file = backing_file_func(h_sb);
21711 + if (!backing_file)
21714 + h_adding = backing_file->f_path.dentry;
21716 + * h_adding can be local NFS.
21717 + * in this case aufs cannot detect the loop.
21719 + if (unlikely(h_adding->d_sb == sb))
21721 + return !!au_test_subdir(h_adding, sb->s_root);
21724 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21725 +int au_test_loopback_kthread(void)
21728 + struct task_struct *tsk = current;
21729 + char c, comm[sizeof(tsk->comm)];
21732 + if (tsk->flags & PF_KTHREAD) {
21733 + get_task_comm(comm, tsk);
21735 + ret = ('0' <= c && c <= '9'
21736 + && !strncmp(comm, "loop", 4));
21742 +/* ---------------------------------------------------------------------- */
21744 +#define au_warn_loopback_step 16
21745 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21746 +static unsigned long *au_warn_loopback_array;
21748 +void au_warn_loopback(struct super_block *h_sb)
21750 + int i, new_nelem;
21751 + unsigned long *a, magic;
21752 + static DEFINE_SPINLOCK(spin);
21754 + magic = h_sb->s_magic;
21755 + spin_lock(&spin);
21756 + a = au_warn_loopback_array;
21757 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21758 + if (a[i] == magic) {
21759 + spin_unlock(&spin);
21763 + /* h_sb is new to us, print it */
21764 + if (i < au_warn_loopback_nelem) {
21769 + /* expand the array */
21770 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21771 + a = au_kzrealloc(au_warn_loopback_array,
21772 + au_warn_loopback_nelem * sizeof(unsigned long),
21773 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
21774 + /*may_shrink*/0);
21776 + au_warn_loopback_nelem = new_nelem;
21777 + au_warn_loopback_array = a;
21782 + spin_unlock(&spin);
21783 + AuWarn1("realloc failed, ignored\n");
21787 + spin_unlock(&spin);
21788 + pr_warn("you may want to try another patch for loopback file "
21789 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21792 +int au_loopback_init(void)
21795 + struct super_block *sb __maybe_unused;
21797 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
21800 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21801 + sizeof(unsigned long), GFP_NOFS);
21802 + if (unlikely(!au_warn_loopback_array))
21808 +void au_loopback_fin(void)
21810 + if (backing_file_func)
21811 + symbol_put(loop_backing_file);
21812 + au_delayed_kfree(au_warn_loopback_array);
21814 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21815 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21816 +++ linux/fs/aufs/loop.h 2016-10-09 16:55:36.492701639 +0200
21819 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21821 + * This program, aufs is free software; you can redistribute it and/or modify
21822 + * it under the terms of the GNU General Public License as published by
21823 + * the Free Software Foundation; either version 2 of the License, or
21824 + * (at your option) any later version.
21826 + * This program is distributed in the hope that it will be useful,
21827 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21828 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21829 + * GNU General Public License for more details.
21831 + * You should have received a copy of the GNU General Public License
21832 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21836 + * support for loopback mount as a branch
21839 +#ifndef __AUFS_LOOP_H__
21840 +#define __AUFS_LOOP_H__
21845 +struct super_block;
21847 +#ifdef CONFIG_AUFS_BDEV_LOOP
21848 +/* drivers/block/loop.c */
21849 +struct file *loop_backing_file(struct super_block *sb);
21852 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21853 +int au_test_loopback_kthread(void);
21854 +void au_warn_loopback(struct super_block *h_sb);
21856 +int au_loopback_init(void);
21857 +void au_loopback_fin(void);
21859 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21860 + struct dentry *h_adding)
21861 +AuStubInt0(au_test_loopback_kthread, void)
21862 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21864 +AuStubInt0(au_loopback_init, void)
21865 +AuStubVoid(au_loopback_fin, void)
21866 +#endif /* BLK_DEV_LOOP */
21868 +#endif /* __KERNEL__ */
21869 +#endif /* __AUFS_LOOP_H__ */
21870 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21871 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21872 +++ linux/fs/aufs/magic.mk 2016-10-09 16:55:36.492701639 +0200
21875 +# defined in ${srctree}/fs/fuse/inode.c
21877 +ifdef CONFIG_FUSE_FS
21878 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21881 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21883 +ifdef CONFIG_XFS_FS
21884 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21887 +# defined in ${srctree}/fs/configfs/mount.c
21889 +ifdef CONFIG_CONFIGFS_FS
21890 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21893 +# defined in ${srctree}/fs/ubifs/ubifs.h
21895 +ifdef CONFIG_UBIFS_FS
21896 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21899 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
21901 +ifdef CONFIG_HFSPLUS_FS
21902 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
21904 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
21905 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
21906 +++ linux/fs/aufs/Makefile 2016-10-09 16:55:36.486034798 +0200
21909 +include ${src}/magic.mk
21910 +ifeq (${CONFIG_AUFS_FS},m)
21911 +include ${src}/conf.mk
21913 +-include ${src}/priv_def.mk
21915 +# cf. include/linux/kernel.h
21917 +ccflags-y += -DDEBUG
21918 +# sparse requires the full pathname
21920 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
21922 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
21925 +obj-$(CONFIG_AUFS_FS) += aufs.o
21926 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
21927 + wkq.o vfsub.o dcsub.o \
21928 + cpup.o whout.o wbr_policy.o \
21929 + dinfo.o dentry.o \
21931 + finfo.o file.o f_op.o \
21933 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
21937 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
21938 +aufs-$(CONFIG_SYSFS) += sysfs.o
21939 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
21940 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
21941 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
21942 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
21943 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
21944 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
21945 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
21946 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
21947 +aufs-$(CONFIG_AUFS_POLL) += poll.o
21948 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
21949 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
21950 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
21951 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
21952 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
21953 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
21954 +++ linux/fs/aufs/module.c 2016-10-09 16:55:38.889431135 +0200
21957 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21959 + * This program, aufs is free software; you can redistribute it and/or modify
21960 + * it under the terms of the GNU General Public License as published by
21961 + * the Free Software Foundation; either version 2 of the License, or
21962 + * (at your option) any later version.
21964 + * This program is distributed in the hope that it will be useful,
21965 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21966 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21967 + * GNU General Public License for more details.
21969 + * You should have received a copy of the GNU General Public License
21970 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21974 + * module global variables and operations
21977 +#include <linux/module.h>
21978 +#include <linux/seq_file.h>
21981 +/* shrinkable realloc */
21982 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
21990 +#if 0 /* unused */
21992 + au_delayed_kfree(p);
21997 + AuDebugOn(!new_sz);
22000 + diff = au_kmidx_sub(sz, new_sz);
22006 + /* expand or SLOB */
22007 + p = krealloc(p, new_sz, gfp);
22008 + else if (new_sz < sz && may_shrink) {
22012 + q = kmalloc(new_sz, gfp);
22015 + memcpy(q, p, new_sz);
22016 + au_delayed_kfree(p);
22027 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22030 + p = au_krealloc(p, new_sz, gfp, may_shrink);
22031 + if (p && new_sz > nused)
22032 + memset(p + nused, 0, new_sz - nused);
22036 +/* ---------------------------------------------------------------------- */
22041 +struct au_dfree au_dfree;
22043 +/* delayed free */
22044 +static void au_do_dfree(struct work_struct *work __maybe_unused)
22046 + struct llist_head *head;
22047 + struct llist_node *node, *next;
22049 +#define AU_CACHE_DFREE_DO_BODY(name, idx, lnode) do { \
22050 + head = &au_dfree.cache[AuCache_##idx].llist; \
22051 + node = llist_del_all(head); \
22052 + for (; node; node = next) { \
22053 + struct au_##name *p \
22054 + = llist_entry(node, struct au_##name, \
22056 + next = llist_next(node); \
22057 + au_cache_free_##name(p); \
22061 + AU_CACHE_DFREE_DO_BODY(dinfo, DINFO, di_lnode);
22062 + AU_CACHE_DFREE_DO_BODY(icntnr, ICNTNR, lnode);
22063 + AU_CACHE_DFREE_DO_BODY(finfo, FINFO, fi_lnode);
22064 + AU_CACHE_DFREE_DO_BODY(vdir, VDIR, vd_lnode);
22065 + AU_CACHE_DFREE_DO_BODY(vdir_dehstr, DEHSTR, lnode);
22066 +#ifdef CONFIG_AUFS_HNOTIFY
22067 + AU_CACHE_DFREE_DO_BODY(hnotify, HNOTIFY, hn_lnode);
22070 +#define AU_DFREE_DO_BODY(llist, func) do { \
22071 + node = llist_del_all(llist); \
22072 + for (; node; node = next) { \
22073 + next = llist_next(node); \
22078 + AU_DFREE_DO_BODY(au_dfree.llist + AU_DFREE_KFREE, kfree);
22079 + AU_DFREE_DO_BODY(au_dfree.llist + AU_DFREE_FREE_PAGE, au_free_page);
22081 +#undef AU_CACHE_DFREE_DO_BODY
22082 +#undef AU_DFREE_DO_BODY
22085 +AU_CACHE_DFREE_FUNC(dinfo, DINFO, di_lnode);
22086 +AU_CACHE_DFREE_FUNC(icntnr, ICNTNR, lnode);
22087 +AU_CACHE_DFREE_FUNC(finfo, FINFO, fi_lnode);
22088 +AU_CACHE_DFREE_FUNC(vdir, VDIR, vd_lnode);
22089 +AU_CACHE_DFREE_FUNC(vdir_dehstr, DEHSTR, lnode);
22091 +static void au_cache_fin(void)
22094 + struct au_cache *cp;
22097 + * Make sure all delayed rcu free inodes are flushed before we
22102 + /* excluding AuCache_HNOTIFY */
22103 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
22104 + flush_delayed_work(&au_dfree.dwork);
22105 + for (i = 0; i < AuCache_HNOTIFY; i++) {
22106 + cp = au_dfree.cache + i;
22107 + AuDebugOn(!llist_empty(&cp->llist));
22108 + kmem_cache_destroy(cp->cache);
22109 + cp->cache = NULL;
22113 +static int __init au_cache_init(void)
22115 + struct au_cache *cp;
22117 + cp = au_dfree.cache;
22118 + cp[AuCache_DINFO].cache = AuCacheCtor(au_dinfo, au_di_init_once);
22119 + if (cp[AuCache_DINFO].cache)
22120 + /* SLAB_DESTROY_BY_RCU */
22121 + cp[AuCache_ICNTNR].cache = AuCacheCtor(au_icntnr,
22122 + au_icntnr_init_once);
22123 + if (cp[AuCache_ICNTNR].cache)
22124 + cp[AuCache_FINFO].cache = AuCacheCtor(au_finfo,
22125 + au_fi_init_once);
22126 + if (cp[AuCache_FINFO].cache)
22127 + cp[AuCache_VDIR].cache = AuCache(au_vdir);
22128 + if (cp[AuCache_VDIR].cache)
22129 + cp[AuCache_DEHSTR].cache = AuCache(au_vdir_dehstr);
22130 + if (cp[AuCache_DEHSTR].cache)
22137 +/* ---------------------------------------------------------------------- */
22139 +int au_dir_roflags;
22141 +#ifdef CONFIG_AUFS_SBILIST
22143 + * iterate_supers_type() doesn't protect us from
22144 + * remounting (branch management)
22146 +struct au_sphlhead au_sbilist;
22150 + * functions for module interface.
22152 +MODULE_LICENSE("GPL");
22153 +/* MODULE_LICENSE("GPL v2"); */
22154 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
22155 +MODULE_DESCRIPTION(AUFS_NAME
22156 + " -- Advanced multi layered unification filesystem");
22157 +MODULE_VERSION(AUFS_VERSION);
22158 +MODULE_ALIAS_FS(AUFS_NAME);
22160 +/* this module parameter has no meaning when SYSFS is disabled */
22161 +int sysaufs_brs = 1;
22162 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
22163 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
22165 +/* this module parameter has no meaning when USER_NS is disabled */
22167 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
22168 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
22170 +/* ---------------------------------------------------------------------- */
22172 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
22174 +int au_seq_path(struct seq_file *seq, struct path *path)
22178 + err = seq_path(seq, path, au_esc_chars);
22181 + else if (err < 0)
22187 +/* ---------------------------------------------------------------------- */
22189 +static int __init aufs_init(void)
22193 + struct au_cache *cp;
22195 + p = au_esc_chars;
22196 + for (i = 1; i <= ' '; i++)
22202 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
22204 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
22205 + for (i = 0; i < AuIop_Last; i++)
22206 + aufs_iop_nogetattr[i].getattr = NULL;
22208 + /* First, initialize au_dfree */
22209 + for (i = 0; i < AuCache_Last; i++) { /* including hnotify */
22210 + cp = au_dfree.cache + i;
22211 + cp->cache = NULL;
22212 + init_llist_head(&cp->llist);
22214 + for (i = 0; i < AU_DFREE_Last; i++)
22215 + init_llist_head(au_dfree.llist + i);
22216 + INIT_DELAYED_WORK(&au_dfree.dwork, au_do_dfree);
22218 + au_sbilist_init();
22219 + sysaufs_brs_init();
22222 + err = sysaufs_init();
22223 + if (unlikely(err))
22225 + err = au_procfs_init();
22226 + if (unlikely(err))
22227 + goto out_sysaufs;
22228 + err = au_wkq_init();
22229 + if (unlikely(err))
22231 + err = au_loopback_init();
22232 + if (unlikely(err))
22234 + err = au_hnotify_init();
22235 + if (unlikely(err))
22236 + goto out_loopback;
22237 + err = au_sysrq_init();
22238 + if (unlikely(err))
22240 + err = au_cache_init();
22241 + if (unlikely(err))
22244 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
22245 + err = register_filesystem(&aufs_fs_type);
22246 + if (unlikely(err))
22249 + /* since we define pr_fmt, call printk directly */
22250 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
22251 + goto out; /* success */
22258 + au_hnotify_fin();
22260 + au_loopback_fin();
22268 + flush_delayed_work(&au_dfree.dwork);
22273 +static void __exit aufs_exit(void)
22275 + unregister_filesystem(&aufs_fs_type);
22278 + au_hnotify_fin();
22279 + au_loopback_fin();
22284 + flush_delayed_work(&au_dfree.dwork);
22287 +module_init(aufs_init);
22288 +module_exit(aufs_exit);
22289 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
22290 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
22291 +++ linux/fs/aufs/module.h 2016-10-09 16:55:38.889431135 +0200
22294 + * Copyright (C) 2005-2016 Junjiro R. Okajima
22296 + * This program, aufs is free software; you can redistribute it and/or modify
22297 + * it under the terms of the GNU General Public License as published by
22298 + * the Free Software Foundation; either version 2 of the License, or
22299 + * (at your option) any later version.
22301 + * This program is distributed in the hope that it will be useful,
22302 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22303 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22304 + * GNU General Public License for more details.
22306 + * You should have received a copy of the GNU General Public License
22307 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22311 + * module initialization and module-global
22314 +#ifndef __AUFS_MODULE_H__
22315 +#define __AUFS_MODULE_H__
22319 +#include <linux/slab.h>
22320 +#include "debug.h"
22325 +/* module parameters */
22326 +extern int sysaufs_brs;
22327 +extern bool au_userns;
22329 +/* ---------------------------------------------------------------------- */
22331 +extern int au_dir_roflags;
22333 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
22334 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22337 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
22339 +#ifndef CONFIG_SLOB
22340 + return kmalloc_index(sz) - kmalloc_index(new_sz);
22342 + return -1; /* SLOB is untested */
22346 +int au_seq_path(struct seq_file *seq, struct path *path);
22348 +#ifdef CONFIG_PROC_FS
22350 +int __init au_procfs_init(void);
22351 +void au_procfs_fin(void);
22353 +AuStubInt0(au_procfs_init, void);
22354 +AuStubVoid(au_procfs_fin, void);
22357 +/* ---------------------------------------------------------------------- */
22359 +/* kmem cache and delayed free */
22366 + AuCache_HNOTIFY, /* must be last */
22372 + AU_DFREE_FREE_PAGE,
22377 + struct kmem_cache *cache;
22378 + struct llist_head llist; /* delayed free */
22382 + * in order to reduce the cost of the internal timer, consolidate all the
22383 + * delayed free works into a single delayed_work.
22386 + struct au_cache cache[AuCache_Last];
22387 + struct llist_head llist[AU_DFREE_Last];
22388 + struct delayed_work dwork;
22391 +extern struct au_dfree au_dfree;
22393 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
22394 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
22395 +#define AuCacheCtor(type, ctor) \
22396 + kmem_cache_create(#type, sizeof(struct type), \
22397 + __alignof__(struct type), AuCacheFlags, ctor)
22399 +#define AU_DFREE_DELAY msecs_to_jiffies(10)
22400 +#define AU_DFREE_BODY(lnode, llist) do { \
22401 + if (llist_add(lnode, llist)) \
22402 + schedule_delayed_work(&au_dfree.dwork, \
22403 + AU_DFREE_DELAY); \
22405 +#define AU_CACHE_DFREE_FUNC(name, idx, lnode) \
22406 + void au_cache_dfree_##name(struct au_##name *p) \
22408 + struct au_cache *cp = au_dfree.cache + AuCache_##idx; \
22409 + AU_DFREE_BODY(&p->lnode, &cp->llist); \
22412 +#define AuCacheFuncs(name, index) \
22413 +static inline struct au_##name *au_cache_alloc_##name(void) \
22414 +{ return kmem_cache_alloc(au_dfree.cache[AuCache_##index].cache, GFP_NOFS); } \
22415 +static inline void au_cache_free_##name(struct au_##name *p) \
22416 +{ kmem_cache_free(au_dfree.cache[AuCache_##index].cache, p); } \
22417 +void au_cache_dfree_##name(struct au_##name *p)
22419 +AuCacheFuncs(dinfo, DINFO);
22420 +AuCacheFuncs(icntnr, ICNTNR);
22421 +AuCacheFuncs(finfo, FINFO);
22422 +AuCacheFuncs(vdir, VDIR);
22423 +AuCacheFuncs(vdir_dehstr, DEHSTR);
22424 +#ifdef CONFIG_AUFS_HNOTIFY
22425 +AuCacheFuncs(hnotify, HNOTIFY);
22428 +static inline void au_delayed_kfree(const void *p)
22431 + AuDebugOn(ksize(p) < sizeof(struct llist_node));
22433 + AU_DFREE_BODY((void *)p, au_dfree.llist + AU_DFREE_KFREE);
22437 +static inline void au_free_page(void *p)
22439 + free_page((unsigned long)p);
22442 +static inline void au_delayed_free_page(unsigned long addr)
22444 + AU_DFREE_BODY((void *)addr, au_dfree.llist + AU_DFREE_FREE_PAGE);
22447 +#endif /* __KERNEL__ */
22448 +#endif /* __AUFS_MODULE_H__ */
22449 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
22450 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
22451 +++ linux/fs/aufs/mvdown.c 2016-10-09 16:55:36.492701639 +0200
22454 + * Copyright (C) 2011-2016 Junjiro R. Okajima
22456 + * This program, aufs is free software; you can redistribute it and/or modify
22457 + * it under the terms of the GNU General Public License as published by
22458 + * the Free Software Foundation; either version 2 of the License, or
22459 + * (at your option) any later version.
22461 + * This program is distributed in the hope that it will be useful,
22462 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22463 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22464 + * GNU General Public License for more details.
22466 + * You should have received a copy of the GNU General Public License
22467 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22471 + * move-down, opposite of copy-up
22476 +struct au_mvd_args {
22478 + struct super_block *h_sb;
22479 + struct dentry *h_parent;
22480 + struct au_hinode *hdir;
22481 + struct inode *h_dir, *h_inode;
22482 + struct au_pin pin;
22483 + } info[AUFS_MVDOWN_NARRAY];
22485 + struct aufs_mvdown mvdown;
22486 + struct dentry *dentry, *parent;
22487 + struct inode *inode, *dir;
22488 + struct super_block *sb;
22489 + aufs_bindex_t bopq, bwh, bfound;
22490 + unsigned char rename_lock;
22493 +#define mvd_errno mvdown.au_errno
22494 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
22495 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
22496 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
22497 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
22499 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
22500 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
22501 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
22502 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
22503 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
22504 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
22506 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
22507 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
22508 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
22509 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
22510 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
22511 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
22513 +#define AU_MVD_PR(flag, ...) do { \
22515 + pr_err(__VA_ARGS__); \
22518 +static int find_lower_writable(struct au_mvd_args *a)
22520 + struct super_block *sb;
22521 + aufs_bindex_t bindex, bbot;
22522 + struct au_branch *br;
22525 + bindex = a->mvd_bsrc;
22526 + bbot = au_sbbot(sb);
22527 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
22528 + for (bindex++; bindex <= bbot; bindex++) {
22529 + br = au_sbr(sb, bindex);
22530 + if (au_br_fhsm(br->br_perm)
22531 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
22534 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
22535 + for (bindex++; bindex <= bbot; bindex++) {
22536 + br = au_sbr(sb, bindex);
22537 + if (!au_br_rdonly(br))
22541 + for (bindex++; bindex <= bbot; bindex++) {
22542 + br = au_sbr(sb, bindex);
22543 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
22544 + if (au_br_rdonly(br))
22546 + |= AUFS_MVDOWN_ROLOWER_R;
22554 +/* make the parent dir on bdst */
22555 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22560 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22561 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22562 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22563 + a->mvd_h_dst_parent = NULL;
22564 + if (au_dbbot(a->parent) >= a->mvd_bdst)
22565 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22566 + if (!a->mvd_h_dst_parent) {
22567 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22568 + if (unlikely(err)) {
22569 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22572 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22580 +/* lock them all */
22581 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22584 + struct dentry *h_trap;
22586 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22587 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22588 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22589 + au_opt_udba(a->sb),
22590 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22592 + if (unlikely(err)) {
22593 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22597 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22598 + a->rename_lock = 0;
22599 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22600 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22601 + au_opt_udba(a->sb),
22602 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22603 + err = au_do_pin(&a->mvd_pin_src);
22605 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22606 + if (unlikely(err)) {
22607 + AU_MVD_PR(dmsg, "pin_src failed\n");
22610 + goto out; /* success */
22613 + a->rename_lock = 1;
22614 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22615 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22616 + au_opt_udba(a->sb),
22617 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22619 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22620 + if (unlikely(err)) {
22621 + AU_MVD_PR(dmsg, "pin_src failed\n");
22622 + au_pin_hdir_lock(&a->mvd_pin_dst);
22625 + au_pin_hdir_unlock(&a->mvd_pin_src);
22626 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22627 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22629 + err = (h_trap != a->mvd_h_src_parent);
22631 + err = (h_trap != a->mvd_h_dst_parent);
22633 + BUG_ON(err); /* it should never happen */
22634 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22637 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22638 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22639 + au_pin_hdir_lock(&a->mvd_pin_src);
22640 + au_unpin(&a->mvd_pin_src);
22641 + au_pin_hdir_lock(&a->mvd_pin_dst);
22644 + goto out; /* success */
22647 + au_unpin(&a->mvd_pin_dst);
22653 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22655 + if (!a->rename_lock)
22656 + au_unpin(&a->mvd_pin_src);
22658 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22659 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22660 + au_pin_hdir_lock(&a->mvd_pin_src);
22661 + au_unpin(&a->mvd_pin_src);
22662 + au_pin_hdir_lock(&a->mvd_pin_dst);
22664 + au_unpin(&a->mvd_pin_dst);
22667 +/* copy-down the file */
22668 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22671 + struct au_cp_generic cpg = {
22672 + .dentry = a->dentry,
22673 + .bdst = a->mvd_bdst,
22674 + .bsrc = a->mvd_bsrc,
22676 + .pin = &a->mvd_pin_dst,
22677 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22680 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22681 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22682 + au_fset_cpup(cpg.flags, OVERWRITE);
22683 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22684 + au_fset_cpup(cpg.flags, RWDST);
22685 + err = au_sio_cpdown_simple(&cpg);
22686 + if (unlikely(err))
22687 + AU_MVD_PR(dmsg, "cpdown failed\n");
22694 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22697 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22700 + struct path h_path;
22701 + struct au_branch *br;
22702 + struct inode *delegated;
22704 + br = au_sbr(a->sb, a->mvd_bdst);
22705 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22706 + err = PTR_ERR(h_path.dentry);
22707 + if (IS_ERR(h_path.dentry)) {
22708 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22713 + if (d_is_positive(h_path.dentry)) {
22714 + h_path.mnt = au_br_mnt(br);
22715 + delegated = NULL;
22716 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22717 + &delegated, /*force*/0);
22718 + if (unlikely(err == -EWOULDBLOCK)) {
22719 + pr_warn("cannot retry for NFSv4 delegation"
22720 + " for an internal unlink\n");
22723 + if (unlikely(err))
22724 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22726 + dput(h_path.dentry);
22734 + * unlink the topmost h_dentry
22736 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22739 + struct path h_path;
22740 + struct inode *delegated;
22742 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22743 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22744 + delegated = NULL;
22745 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22746 + if (unlikely(err == -EWOULDBLOCK)) {
22747 + pr_warn("cannot retry for NFSv4 delegation"
22748 + " for an internal unlink\n");
22751 + if (unlikely(err))
22752 + AU_MVD_PR(dmsg, "unlink failed\n");
22758 +/* Since mvdown succeeded, we ignore an error of this function */
22759 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22762 + struct au_branch *br;
22764 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22765 + br = au_sbr(a->sb, a->mvd_bsrc);
22766 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22768 + br = au_sbr(a->sb, a->mvd_bdst);
22769 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22770 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22773 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22775 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22779 + * copy-down the file and unlink the bsrc file.
22780 + * - unlink the bdst whout if exist
22781 + * - copy-down the file (with whtmp name and rename)
22782 + * - unlink the bsrc file
22784 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22788 + err = au_do_mkdir(dmsg, a);
22790 + err = au_do_lock(dmsg, a);
22791 + if (unlikely(err))
22795 + * do not revert the activities we made on bdst since they should be
22796 + * harmless in aufs.
22799 + err = au_do_cpdown(dmsg, a);
22801 + err = au_do_unlink_wh(dmsg, a);
22802 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22803 + err = au_do_unlink(dmsg, a);
22804 + if (unlikely(err))
22807 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22808 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22809 + if (find_lower_writable(a) < 0)
22810 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22812 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22813 + au_do_stfs(dmsg, a);
22815 + /* maintain internal array */
22816 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22817 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22818 + au_set_dbtop(a->dentry, a->mvd_bdst);
22819 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22820 + au_set_ibtop(a->inode, a->mvd_bdst);
22822 + /* hide the lower */
22823 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
22824 + au_set_dbbot(a->dentry, a->mvd_bsrc);
22825 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
22826 + au_set_ibbot(a->inode, a->mvd_bsrc);
22828 + if (au_dbbot(a->dentry) < a->mvd_bdst)
22829 + au_set_dbbot(a->dentry, a->mvd_bdst);
22830 + if (au_ibbot(a->inode) < a->mvd_bdst)
22831 + au_set_ibbot(a->inode, a->mvd_bdst);
22834 + au_do_unlock(dmsg, a);
22840 +/* ---------------------------------------------------------------------- */
22842 +/* make sure the file is idle */
22843 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22845 + int err, plinked;
22848 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22849 + if (au_dbtop(a->dentry) == a->mvd_bsrc
22850 + && au_dcount(a->dentry) == 1
22851 + && atomic_read(&a->inode->i_count) == 1
22852 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22853 + && (!plinked || !au_plink_test(a->inode))
22854 + && a->inode->i_nlink == 1)
22859 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22860 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
22861 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22862 + a->mvd_h_src_inode->i_nlink,
22863 + plinked, plinked ? au_plink_test(a->inode) : 0);
22870 +/* make sure the parent dir is fine */
22871 +static int au_mvd_args_parent(const unsigned char dmsg,
22872 + struct au_mvd_args *a)
22875 + aufs_bindex_t bindex;
22878 + if (unlikely(au_alive_dir(a->parent))) {
22880 + AU_MVD_PR(dmsg, "parent dir is dead\n");
22884 + a->bopq = au_dbdiropq(a->parent);
22885 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
22886 + AuDbg("b%d\n", bindex);
22887 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
22888 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
22890 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
22891 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
22892 + a->bopq, a->mvd_bdst);
22900 +static int au_mvd_args_intermediate(const unsigned char dmsg,
22901 + struct au_mvd_args *a)
22904 + struct au_dinfo *dinfo, *tmp;
22906 + /* lookup the next lower positive entry */
22908 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
22909 + if (unlikely(!tmp))
22914 + dinfo = au_di(a->dentry);
22915 + au_di_cp(tmp, dinfo);
22916 + au_di_swap(tmp, dinfo);
22918 + /* returns the number of positive dentries */
22919 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
22920 + /* AuLkup_IGNORE_PERM */ 0);
22922 + a->bwh = au_dbwh(a->dentry);
22923 + else if (err > 0)
22924 + a->bfound = au_dbtop(a->dentry);
22926 + au_di_swap(tmp, dinfo);
22927 + au_rw_write_unlock(&tmp->di_rwsem);
22929 + if (unlikely(err < 0))
22930 + AU_MVD_PR(dmsg, "failed look-up lower\n");
22933 + * here, we have these cases.
22935 + * no positive dentry under bsrc. there are more sub-cases.
22937 + * there no whiteout, we can safely move-down.
22940 + * bsrc < bwh && bwh < bdst
22941 + * there is a whiteout on RO branch. cannot proceed.
22943 + * there is a whiteout on the RW target branch. it should
22946 + * there is a whiteout somewhere unrelated branch.
22947 + * -1 < bfound && bfound <= bsrc
22950 + * found, but it is on RO branch between bsrc and bdst. cannot
22953 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
22956 + * found, after we create the file on bdst, it will be hidden.
22959 + AuDebugOn(a->bfound == -1
22961 + && a->bwh <= a->mvd_bsrc);
22962 + AuDebugOn(-1 < a->bfound
22963 + && a->bfound <= a->mvd_bsrc);
22966 + if (a->bfound == -1
22967 + && a->mvd_bsrc < a->bwh
22969 + && a->bwh < a->mvd_bdst) {
22970 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
22971 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
22972 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
22974 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
22975 + a->mvd_errno = EAU_MVDOWN_UPPER;
22976 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
22977 + a->mvd_bdst, a->bfound);
22981 + err = 0; /* success */
22988 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
22993 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22994 + && a->bfound == a->mvd_bdst)
23000 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
23003 + struct au_branch *br;
23006 + if (unlikely(S_ISDIR(a->inode->i_mode)))
23010 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
23011 + a->mvd_bsrc = au_ibtop(a->inode);
23013 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
23014 + if (unlikely(a->mvd_bsrc < 0
23015 + || (a->mvd_bsrc < au_dbtop(a->dentry)
23016 + || au_dbbot(a->dentry) < a->mvd_bsrc
23017 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
23018 + || (a->mvd_bsrc < au_ibtop(a->inode)
23019 + || au_ibbot(a->inode) < a->mvd_bsrc
23020 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
23021 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
23022 + AU_MVD_PR(dmsg, "no upper\n");
23026 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
23027 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23028 + AU_MVD_PR(dmsg, "on the bottom\n");
23031 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
23032 + br = au_sbr(a->sb, a->mvd_bsrc);
23033 + err = au_br_rdonly(br);
23034 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
23035 + if (unlikely(err))
23037 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
23038 + || IS_APPEND(a->mvd_h_src_inode))) {
23040 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
23046 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
23047 + a->mvd_bdst = find_lower_writable(a);
23048 + if (unlikely(a->mvd_bdst < 0)) {
23049 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23050 + AU_MVD_PR(dmsg, "no writable lower branch\n");
23054 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
23055 + if (unlikely(a->mvd_bdst < 0
23056 + || au_sbbot(a->sb) < a->mvd_bdst)) {
23057 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
23058 + AU_MVD_PR(dmsg, "no lower brid\n");
23063 + err = au_mvd_args_busy(dmsg, a);
23065 + err = au_mvd_args_parent(dmsg, a);
23067 + err = au_mvd_args_intermediate(dmsg, a);
23069 + err = au_mvd_args_exist(dmsg, a);
23071 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
23078 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
23081 + unsigned char dmsg;
23082 + struct au_mvd_args *args;
23083 + struct inode *inode;
23085 + inode = d_inode(dentry);
23087 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23091 + args = kmalloc(sizeof(*args), GFP_NOFS);
23092 + if (unlikely(!args))
23095 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
23097 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
23098 + if (unlikely(err)) {
23103 + AuDbg("flags 0x%x\n", args->mvdown.flags);
23104 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
23105 + args->mvdown.au_errno = 0;
23106 + args->dentry = dentry;
23107 + args->inode = inode;
23108 + args->sb = dentry->d_sb;
23111 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
23112 + args->parent = dget_parent(dentry);
23113 + args->dir = d_inode(args->parent);
23114 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
23115 + dput(args->parent);
23116 + if (unlikely(args->parent != dentry->d_parent)) {
23117 + AU_MVD_PR(dmsg, "parent dir is moved\n");
23121 + inode_lock_nested(inode, I_MUTEX_CHILD);
23122 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
23123 + if (unlikely(err))
23126 + di_write_lock_parent(args->parent);
23127 + err = au_mvd_args(dmsg, args);
23128 + if (unlikely(err))
23131 + err = au_do_mvdown(dmsg, args);
23132 + if (unlikely(err))
23135 + au_cpup_attr_timesizes(args->dir);
23136 + au_cpup_attr_timesizes(inode);
23137 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
23138 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
23139 + /* au_digen_dec(dentry); */
23142 + di_write_unlock(args->parent);
23143 + aufs_read_unlock(dentry, AuLock_DW);
23145 + inode_unlock(inode);
23147 + inode_unlock(args->dir);
23149 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
23152 + au_delayed_kfree(args);
23157 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
23158 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
23159 +++ linux/fs/aufs/opts.c 2016-10-09 16:55:36.496035060 +0200
23162 + * Copyright (C) 2005-2016 Junjiro R. Okajima
23164 + * This program, aufs is free software; you can redistribute it and/or modify
23165 + * it under the terms of the GNU General Public License as published by
23166 + * the Free Software Foundation; either version 2 of the License, or
23167 + * (at your option) any later version.
23169 + * This program is distributed in the hope that it will be useful,
23170 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23171 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23172 + * GNU General Public License for more details.
23174 + * You should have received a copy of the GNU General Public License
23175 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23179 + * mount options/flags
23182 +#include <linux/namei.h>
23183 +#include <linux/types.h> /* a distribution requires */
23184 +#include <linux/parser.h>
23187 +/* ---------------------------------------------------------------------- */
23191 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
23192 + Opt_idel, Opt_imod,
23193 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
23194 + Opt_rdblk_def, Opt_rdhash_def,
23195 + Opt_xino, Opt_noxino,
23196 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
23197 + Opt_trunc_xino_path, Opt_itrunc_xino,
23198 + Opt_trunc_xib, Opt_notrunc_xib,
23199 + Opt_shwh, Opt_noshwh,
23200 + Opt_plink, Opt_noplink, Opt_list_plink,
23202 + Opt_dio, Opt_nodio,
23203 + Opt_diropq_a, Opt_diropq_w,
23204 + Opt_warn_perm, Opt_nowarn_perm,
23205 + Opt_wbr_copyup, Opt_wbr_create,
23207 + Opt_verbose, Opt_noverbose,
23208 + Opt_sum, Opt_nosum, Opt_wsum,
23209 + Opt_dirperm1, Opt_nodirperm1,
23210 + Opt_acl, Opt_noacl,
23211 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
23214 +static match_table_t options = {
23215 + {Opt_br, "br=%s"},
23216 + {Opt_br, "br:%s"},
23218 + {Opt_add, "add=%d:%s"},
23219 + {Opt_add, "add:%d:%s"},
23220 + {Opt_add, "ins=%d:%s"},
23221 + {Opt_add, "ins:%d:%s"},
23222 + {Opt_append, "append=%s"},
23223 + {Opt_append, "append:%s"},
23224 + {Opt_prepend, "prepend=%s"},
23225 + {Opt_prepend, "prepend:%s"},
23227 + {Opt_del, "del=%s"},
23228 + {Opt_del, "del:%s"},
23229 + /* {Opt_idel, "idel:%d"}, */
23230 + {Opt_mod, "mod=%s"},
23231 + {Opt_mod, "mod:%s"},
23232 + /* {Opt_imod, "imod:%d:%s"}, */
23234 + {Opt_dirwh, "dirwh=%d"},
23236 + {Opt_xino, "xino=%s"},
23237 + {Opt_noxino, "noxino"},
23238 + {Opt_trunc_xino, "trunc_xino"},
23239 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
23240 + {Opt_notrunc_xino, "notrunc_xino"},
23241 + {Opt_trunc_xino_path, "trunc_xino=%s"},
23242 + {Opt_itrunc_xino, "itrunc_xino=%d"},
23243 + /* {Opt_zxino, "zxino=%s"}, */
23244 + {Opt_trunc_xib, "trunc_xib"},
23245 + {Opt_notrunc_xib, "notrunc_xib"},
23247 +#ifdef CONFIG_PROC_FS
23248 + {Opt_plink, "plink"},
23250 + {Opt_ignore_silent, "plink"},
23253 + {Opt_noplink, "noplink"},
23255 +#ifdef CONFIG_AUFS_DEBUG
23256 + {Opt_list_plink, "list_plink"},
23259 + {Opt_udba, "udba=%s"},
23261 + {Opt_dio, "dio"},
23262 + {Opt_nodio, "nodio"},
23264 +#ifdef CONFIG_AUFS_FHSM
23265 + {Opt_fhsm_sec, "fhsm_sec=%d"},
23267 + {Opt_ignore_silent, "fhsm_sec=%d"},
23270 + {Opt_diropq_a, "diropq=always"},
23271 + {Opt_diropq_a, "diropq=a"},
23272 + {Opt_diropq_w, "diropq=whiteouted"},
23273 + {Opt_diropq_w, "diropq=w"},
23275 + {Opt_warn_perm, "warn_perm"},
23276 + {Opt_nowarn_perm, "nowarn_perm"},
23278 + /* keep them temporary */
23279 + {Opt_ignore_silent, "nodlgt"},
23280 + {Opt_ignore_silent, "clean_plink"},
23282 +#ifdef CONFIG_AUFS_SHWH
23283 + {Opt_shwh, "shwh"},
23285 + {Opt_noshwh, "noshwh"},
23287 + {Opt_dirperm1, "dirperm1"},
23288 + {Opt_nodirperm1, "nodirperm1"},
23290 + {Opt_verbose, "verbose"},
23291 + {Opt_verbose, "v"},
23292 + {Opt_noverbose, "noverbose"},
23293 + {Opt_noverbose, "quiet"},
23294 + {Opt_noverbose, "q"},
23295 + {Opt_noverbose, "silent"},
23297 + {Opt_sum, "sum"},
23298 + {Opt_nosum, "nosum"},
23299 + {Opt_wsum, "wsum"},
23301 + {Opt_rdcache, "rdcache=%d"},
23302 + {Opt_rdblk, "rdblk=%d"},
23303 + {Opt_rdblk_def, "rdblk=def"},
23304 + {Opt_rdhash, "rdhash=%d"},
23305 + {Opt_rdhash_def, "rdhash=def"},
23307 + {Opt_wbr_create, "create=%s"},
23308 + {Opt_wbr_create, "create_policy=%s"},
23309 + {Opt_wbr_copyup, "cpup=%s"},
23310 + {Opt_wbr_copyup, "copyup=%s"},
23311 + {Opt_wbr_copyup, "copyup_policy=%s"},
23313 + /* generic VFS flag */
23314 +#ifdef CONFIG_FS_POSIX_ACL
23315 + {Opt_acl, "acl"},
23316 + {Opt_noacl, "noacl"},
23318 + {Opt_ignore_silent, "acl"},
23319 + {Opt_ignore_silent, "noacl"},
23322 + /* internal use for the scripts */
23323 + {Opt_ignore_silent, "si=%s"},
23325 + {Opt_br, "dirs=%s"},
23326 + {Opt_ignore, "debug=%d"},
23327 + {Opt_ignore, "delete=whiteout"},
23328 + {Opt_ignore, "delete=all"},
23329 + {Opt_ignore, "imap=%s"},
23331 + /* temporary workaround, due to old mount(8)? */
23332 + {Opt_ignore_silent, "relatime"},
23337 +/* ---------------------------------------------------------------------- */
23339 +static const char *au_parser_pattern(int val, match_table_t tbl)
23341 + struct match_token *p;
23344 + while (p->pattern) {
23345 + if (p->token == val)
23346 + return p->pattern;
23353 +static const char *au_optstr(int *val, match_table_t tbl)
23355 + struct match_token *p;
23362 + while (p->pattern) {
23364 + && (v & p->token) == p->token) {
23365 + *val &= ~p->token;
23366 + return p->pattern;
23375 +/* ---------------------------------------------------------------------- */
23377 +static match_table_t brperm = {
23378 + {AuBrPerm_RO, AUFS_BRPERM_RO},
23379 + {AuBrPerm_RR, AUFS_BRPERM_RR},
23380 + {AuBrPerm_RW, AUFS_BRPERM_RW},
23384 +static match_table_t brattr = {
23386 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
23387 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
23388 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
23389 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
23390 +#ifdef CONFIG_AUFS_FHSM
23391 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
23393 +#ifdef CONFIG_AUFS_XATTR
23394 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
23395 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
23396 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
23397 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
23398 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
23399 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
23402 + /* ro/rr branch */
23403 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
23406 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
23407 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
23412 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
23419 + p = strchr(str, '+');
23422 + v = match_token(str, table, args);
23424 + if (v & AuBrAttr_CMOO_Mask)
23425 + attr &= ~AuBrAttr_CMOO_Mask;
23430 + pr_warn("ignored branch attribute %s\n", str);
23440 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
23448 + p = au_optstr(&perm, brattr);
23451 + memcpy(q, p, sz + 1);
23457 + p = au_optstr(&perm, brattr);
23461 + memcpy(q, p, sz + 1);
23467 + return q - str->a;
23470 +static int noinline_for_stack br_perm_val(char *perm)
23472 + int val, bad, sz;
23474 + substring_t args[MAX_OPT_ARGS];
23475 + au_br_perm_str_t attr;
23477 + p = strchr(perm, '+');
23480 + val = match_token(perm, brperm, args);
23484 + pr_warn("ignored branch permission %s\n", perm);
23485 + val = AuBrPerm_RO;
23491 + val |= br_attr_val(p + 1, brattr, args);
23494 + switch (val & AuBrPerm_Mask) {
23495 + case AuBrPerm_RO:
23496 + case AuBrPerm_RR:
23497 + bad = val & AuBrWAttr_Mask;
23498 + val &= ~AuBrWAttr_Mask;
23500 + case AuBrPerm_RW:
23501 + bad = val & AuBrRAttr_Mask;
23502 + val &= ~AuBrRAttr_Mask;
23507 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
23508 + * does not treat it as an error, just warning.
23509 + * this is a tiny guard for the user operation.
23511 + if (val & AuBrAttr_UNPIN) {
23512 + bad |= AuBrAttr_UNPIN;
23513 + val &= ~AuBrAttr_UNPIN;
23516 + if (unlikely(bad)) {
23517 + sz = au_do_optstr_br_attr(&attr, bad);
23519 + pr_warn("ignored branch attribute %s\n", attr.a);
23526 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
23528 + au_br_perm_str_t attr;
23534 + p = au_optstr(&perm, brperm);
23535 + AuDebugOn(!p || !*p);
23537 + memcpy(q, p, sz + 1);
23540 + sz = au_do_optstr_br_attr(&attr, perm);
23543 + memcpy(q, attr.a, sz + 1);
23546 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
23549 +/* ---------------------------------------------------------------------- */
23551 +static match_table_t udbalevel = {
23552 + {AuOpt_UDBA_REVAL, "reval"},
23553 + {AuOpt_UDBA_NONE, "none"},
23554 +#ifdef CONFIG_AUFS_HNOTIFY
23555 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
23556 +#ifdef CONFIG_AUFS_HFSNOTIFY
23557 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23563 +static int noinline_for_stack udba_val(char *str)
23565 + substring_t args[MAX_OPT_ARGS];
23567 + return match_token(str, udbalevel, args);
23570 +const char *au_optstr_udba(int udba)
23572 + return au_parser_pattern(udba, udbalevel);
23575 +/* ---------------------------------------------------------------------- */
23577 +static match_table_t au_wbr_create_policy = {
23578 + {AuWbrCreate_TDP, "tdp"},
23579 + {AuWbrCreate_TDP, "top-down-parent"},
23580 + {AuWbrCreate_RR, "rr"},
23581 + {AuWbrCreate_RR, "round-robin"},
23582 + {AuWbrCreate_MFS, "mfs"},
23583 + {AuWbrCreate_MFS, "most-free-space"},
23584 + {AuWbrCreate_MFSV, "mfs:%d"},
23585 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23587 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23588 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23589 + {AuWbrCreate_PMFS, "pmfs"},
23590 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23591 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23592 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23598 + * cf. linux/lib/parser.c and cmdline.c
23599 + * gave up calling memparse() since it uses simple_strtoull() instead of
23602 +static int noinline_for_stack
23603 +au_match_ull(substring_t *s, unsigned long long *result)
23606 + unsigned int len;
23610 + len = s->to - s->from;
23611 + if (len + 1 <= sizeof(a)) {
23612 + memcpy(a, s->from, len);
23614 + err = kstrtoull(a, 0, result);
23619 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23620 + struct au_opt_wbr_create *create)
23623 + unsigned long long ull;
23626 + if (!au_match_ull(arg, &ull))
23627 + create->mfsrr_watermark = ull;
23629 + pr_err("bad integer in %s\n", str);
23636 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23637 + struct au_opt_wbr_create *create)
23642 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23643 + create->mfs_second = n;
23645 + pr_err("bad integer in %s\n", str);
23652 +static int noinline_for_stack
23653 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23656 + substring_t args[MAX_OPT_ARGS];
23658 + err = match_token(str, au_wbr_create_policy, args);
23659 + create->wbr_create = err;
23661 + case AuWbrCreate_MFSRRV:
23662 + case AuWbrCreate_PMFSRRV:
23663 + e = au_wbr_mfs_wmark(&args[0], str, create);
23665 + e = au_wbr_mfs_sec(&args[1], str, create);
23669 + case AuWbrCreate_MFSRR:
23670 + case AuWbrCreate_PMFSRR:
23671 + e = au_wbr_mfs_wmark(&args[0], str, create);
23672 + if (unlikely(e)) {
23677 + case AuWbrCreate_MFS:
23678 + case AuWbrCreate_PMFS:
23679 + create->mfs_second = AUFS_MFS_DEF_SEC;
23681 + case AuWbrCreate_MFSV:
23682 + case AuWbrCreate_PMFSV:
23683 + e = au_wbr_mfs_sec(&args[0], str, create);
23692 +const char *au_optstr_wbr_create(int wbr_create)
23694 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23697 +static match_table_t au_wbr_copyup_policy = {
23698 + {AuWbrCopyup_TDP, "tdp"},
23699 + {AuWbrCopyup_TDP, "top-down-parent"},
23700 + {AuWbrCopyup_BUP, "bup"},
23701 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23702 + {AuWbrCopyup_BU, "bu"},
23703 + {AuWbrCopyup_BU, "bottom-up"},
23707 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23709 + substring_t args[MAX_OPT_ARGS];
23711 + return match_token(str, au_wbr_copyup_policy, args);
23714 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23716 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23719 +/* ---------------------------------------------------------------------- */
23721 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23723 +static void dump_opts(struct au_opts *opts)
23725 +#ifdef CONFIG_AUFS_DEBUG
23726 + /* reduce stack space */
23728 + struct au_opt_add *add;
23729 + struct au_opt_del *del;
23730 + struct au_opt_mod *mod;
23731 + struct au_opt_xino *xino;
23732 + struct au_opt_xino_itrunc *xino_itrunc;
23733 + struct au_opt_wbr_create *create;
23735 + struct au_opt *opt;
23738 + while (opt->type != Opt_tail) {
23739 + switch (opt->type) {
23741 + u.add = &opt->add;
23742 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23743 + u.add->bindex, u.add->pathname, u.add->perm,
23744 + u.add->path.dentry);
23748 + u.del = &opt->del;
23749 + AuDbg("del {%s, %p}\n",
23750 + u.del->pathname, u.del->h_path.dentry);
23754 + u.mod = &opt->mod;
23755 + AuDbg("mod {%s, 0x%x, %p}\n",
23756 + u.mod->path, u.mod->perm, u.mod->h_root);
23759 + u.add = &opt->add;
23760 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23761 + u.add->bindex, u.add->pathname, u.add->perm,
23762 + u.add->path.dentry);
23764 + case Opt_prepend:
23765 + u.add = &opt->add;
23766 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23767 + u.add->bindex, u.add->pathname, u.add->perm,
23768 + u.add->path.dentry);
23771 + AuDbg("dirwh %d\n", opt->dirwh);
23773 + case Opt_rdcache:
23774 + AuDbg("rdcache %d\n", opt->rdcache);
23777 + AuDbg("rdblk %u\n", opt->rdblk);
23779 + case Opt_rdblk_def:
23780 + AuDbg("rdblk_def\n");
23783 + AuDbg("rdhash %u\n", opt->rdhash);
23785 + case Opt_rdhash_def:
23786 + AuDbg("rdhash_def\n");
23789 + u.xino = &opt->xino;
23790 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23792 + case Opt_trunc_xino:
23793 + AuLabel(trunc_xino);
23795 + case Opt_notrunc_xino:
23796 + AuLabel(notrunc_xino);
23798 + case Opt_trunc_xino_path:
23799 + case Opt_itrunc_xino:
23800 + u.xino_itrunc = &opt->xino_itrunc;
23801 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23806 + case Opt_trunc_xib:
23807 + AuLabel(trunc_xib);
23809 + case Opt_notrunc_xib:
23810 + AuLabel(notrunc_xib);
23818 + case Opt_dirperm1:
23819 + AuLabel(dirperm1);
23821 + case Opt_nodirperm1:
23822 + AuLabel(nodirperm1);
23827 + case Opt_noplink:
23828 + AuLabel(noplink);
23830 + case Opt_list_plink:
23831 + AuLabel(list_plink);
23834 + AuDbg("udba %d, %s\n",
23835 + opt->udba, au_optstr_udba(opt->udba));
23843 + case Opt_diropq_a:
23844 + AuLabel(diropq_a);
23846 + case Opt_diropq_w:
23847 + AuLabel(diropq_w);
23849 + case Opt_warn_perm:
23850 + AuLabel(warn_perm);
23852 + case Opt_nowarn_perm:
23853 + AuLabel(nowarn_perm);
23855 + case Opt_verbose:
23856 + AuLabel(verbose);
23858 + case Opt_noverbose:
23859 + AuLabel(noverbose);
23870 + case Opt_wbr_create:
23871 + u.create = &opt->wbr_create;
23872 + AuDbg("create %d, %s\n", u.create->wbr_create,
23873 + au_optstr_wbr_create(u.create->wbr_create));
23874 + switch (u.create->wbr_create) {
23875 + case AuWbrCreate_MFSV:
23876 + case AuWbrCreate_PMFSV:
23877 + AuDbg("%d sec\n", u.create->mfs_second);
23879 + case AuWbrCreate_MFSRR:
23880 + AuDbg("%llu watermark\n",
23881 + u.create->mfsrr_watermark);
23883 + case AuWbrCreate_MFSRRV:
23884 + case AuWbrCreate_PMFSRRV:
23885 + AuDbg("%llu watermark, %d sec\n",
23886 + u.create->mfsrr_watermark,
23887 + u.create->mfs_second);
23891 + case Opt_wbr_copyup:
23892 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
23893 + au_optstr_wbr_copyup(opt->wbr_copyup));
23895 + case Opt_fhsm_sec:
23896 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
23912 +void au_opts_free(struct au_opts *opts)
23914 + struct au_opt *opt;
23917 + while (opt->type != Opt_tail) {
23918 + switch (opt->type) {
23921 + case Opt_prepend:
23922 + path_put(&opt->add.path);
23926 + path_put(&opt->del.h_path);
23930 + dput(opt->mod.h_root);
23933 + fput(opt->xino.file);
23940 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
23941 + aufs_bindex_t bindex)
23944 + struct au_opt_add *add = &opt->add;
23947 + add->bindex = bindex;
23948 + add->perm = AuBrPerm_RO;
23949 + add->pathname = opt_str;
23950 + p = strchr(opt_str, '=');
23954 + add->perm = br_perm_val(p);
23957 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
23960 + add->perm = AuBrPerm_RO;
23961 + if (au_test_fs_rr(add->path.dentry->d_sb))
23962 + add->perm = AuBrPerm_RR;
23963 + else if (!bindex && !(sb_flags & MS_RDONLY))
23964 + add->perm = AuBrPerm_RW;
23966 + opt->type = Opt_add;
23969 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
23976 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
23980 + del->pathname = args[0].from;
23981 + AuDbg("del path %s\n", del->pathname);
23983 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
23984 + if (unlikely(err))
23985 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
23990 +#if 0 /* reserved for future use */
23991 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
23992 + struct au_opt_del *del, substring_t args[])
23995 + struct dentry *root;
23998 + root = sb->s_root;
23999 + aufs_read_lock(root, AuLock_FLUSH);
24000 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24001 + pr_err("out of bounds, %d\n", bindex);
24006 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
24007 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
24010 + aufs_read_unlock(root, !AuLock_IR);
24015 +static int noinline_for_stack
24016 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
24019 + struct path path;
24023 + mod->path = args[0].from;
24024 + p = strchr(mod->path, '=');
24025 + if (unlikely(!p)) {
24026 + pr_err("no permssion %s\n", args[0].from);
24031 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
24032 + if (unlikely(err)) {
24033 + pr_err("lookup failed %s (%d)\n", mod->path, err);
24037 + mod->perm = br_perm_val(p);
24038 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
24039 + mod->h_root = dget(path.dentry);
24046 +#if 0 /* reserved for future use */
24047 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
24048 + struct au_opt_mod *mod, substring_t args[])
24051 + struct dentry *root;
24054 + root = sb->s_root;
24055 + aufs_read_lock(root, AuLock_FLUSH);
24056 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24057 + pr_err("out of bounds, %d\n", bindex);
24062 + mod->perm = br_perm_val(args[1].from);
24063 + AuDbg("mod path %s, perm 0x%x, %s\n",
24064 + mod->path, mod->perm, args[1].from);
24065 + mod->h_root = dget(au_h_dptr(root, bindex));
24068 + aufs_read_unlock(root, !AuLock_IR);
24073 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
24074 + substring_t args[])
24077 + struct file *file;
24079 + file = au_xino_create(sb, args[0].from, /*silent*/0);
24080 + err = PTR_ERR(file);
24081 + if (IS_ERR(file))
24085 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
24087 + pr_err("%s must be outside\n", args[0].from);
24092 + xino->file = file;
24093 + xino->path = args[0].from;
24099 +static int noinline_for_stack
24100 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
24101 + struct au_opt_xino_itrunc *xino_itrunc,
24102 + substring_t args[])
24105 + aufs_bindex_t bbot, bindex;
24106 + struct path path;
24107 + struct dentry *root;
24109 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
24110 + if (unlikely(err)) {
24111 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
24115 + xino_itrunc->bindex = -1;
24116 + root = sb->s_root;
24117 + aufs_read_lock(root, AuLock_FLUSH);
24118 + bbot = au_sbbot(sb);
24119 + for (bindex = 0; bindex <= bbot; bindex++) {
24120 + if (au_h_dptr(root, bindex) == path.dentry) {
24121 + xino_itrunc->bindex = bindex;
24125 + aufs_read_unlock(root, !AuLock_IR);
24128 + if (unlikely(xino_itrunc->bindex < 0)) {
24129 + pr_err("no such branch %s\n", args[0].from);
24137 +/* called without aufs lock */
24138 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
24140 + int err, n, token;
24141 + aufs_bindex_t bindex;
24142 + unsigned char skipped;
24143 + struct dentry *root;
24144 + struct au_opt *opt, *opt_tail;
24146 + /* reduce the stack space */
24148 + struct au_opt_xino_itrunc *xino_itrunc;
24149 + struct au_opt_wbr_create *create;
24152 + substring_t args[MAX_OPT_ARGS];
24156 + a = kmalloc(sizeof(*a), GFP_NOFS);
24157 + if (unlikely(!a))
24160 + root = sb->s_root;
24164 + opt_tail = opt + opts->max_opt - 1;
24165 + opt->type = Opt_tail;
24166 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
24169 + token = match_token(opt_str, options, a->args);
24173 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
24175 + err = opt_add(opt, opt_str, opts->sb_flags,
24177 + if (unlikely(!err && ++opt > opt_tail)) {
24181 + opt->type = Opt_tail;
24186 + if (unlikely(match_int(&a->args[0], &n))) {
24187 + pr_err("bad integer in %s\n", opt_str);
24191 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
24194 + opt->type = token;
24197 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24198 + /*dummy bindex*/1);
24200 + opt->type = token;
24202 + case Opt_prepend:
24203 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24206 + opt->type = token;
24209 + err = au_opts_parse_del(&opt->del, a->args);
24211 + opt->type = token;
24213 +#if 0 /* reserved for future use */
24215 + del->pathname = "(indexed)";
24216 + if (unlikely(match_int(&args[0], &n))) {
24217 + pr_err("bad integer in %s\n", opt_str);
24220 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
24222 + opt->type = token;
24226 + err = au_opts_parse_mod(&opt->mod, a->args);
24228 + opt->type = token;
24230 +#ifdef IMOD /* reserved for future use */
24232 + u.mod->path = "(indexed)";
24233 + if (unlikely(match_int(&a->args[0], &n))) {
24234 + pr_err("bad integer in %s\n", opt_str);
24237 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
24239 + opt->type = token;
24243 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
24245 + opt->type = token;
24248 + case Opt_trunc_xino_path:
24249 + err = au_opts_parse_xino_itrunc_path
24250 + (sb, &opt->xino_itrunc, a->args);
24252 + opt->type = token;
24255 + case Opt_itrunc_xino:
24256 + u.xino_itrunc = &opt->xino_itrunc;
24257 + if (unlikely(match_int(&a->args[0], &n))) {
24258 + pr_err("bad integer in %s\n", opt_str);
24261 + u.xino_itrunc->bindex = n;
24262 + aufs_read_lock(root, AuLock_FLUSH);
24263 + if (n < 0 || au_sbbot(sb) < n) {
24264 + pr_err("out of bounds, %d\n", n);
24265 + aufs_read_unlock(root, !AuLock_IR);
24268 + aufs_read_unlock(root, !AuLock_IR);
24270 + opt->type = token;
24274 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
24277 + opt->type = token;
24280 + case Opt_rdcache:
24281 + if (unlikely(match_int(&a->args[0], &n))) {
24282 + pr_err("bad integer in %s\n", opt_str);
24285 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
24286 + pr_err("rdcache must be smaller than %d\n",
24287 + AUFS_RDCACHE_MAX);
24290 + opt->rdcache = n;
24292 + opt->type = token;
24295 + if (unlikely(match_int(&a->args[0], &n)
24297 + || n > KMALLOC_MAX_SIZE)) {
24298 + pr_err("bad integer in %s\n", opt_str);
24301 + if (unlikely(n && n < NAME_MAX)) {
24302 + pr_err("rdblk must be larger than %d\n",
24308 + opt->type = token;
24311 + if (unlikely(match_int(&a->args[0], &n)
24313 + || n * sizeof(struct hlist_head)
24314 + > KMALLOC_MAX_SIZE)) {
24315 + pr_err("bad integer in %s\n", opt_str);
24320 + opt->type = token;
24323 + case Opt_trunc_xino:
24324 + case Opt_notrunc_xino:
24326 + case Opt_trunc_xib:
24327 + case Opt_notrunc_xib:
24330 + case Opt_dirperm1:
24331 + case Opt_nodirperm1:
24333 + case Opt_noplink:
24334 + case Opt_list_plink:
24337 + case Opt_diropq_a:
24338 + case Opt_diropq_w:
24339 + case Opt_warn_perm:
24340 + case Opt_nowarn_perm:
24341 + case Opt_verbose:
24342 + case Opt_noverbose:
24346 + case Opt_rdblk_def:
24347 + case Opt_rdhash_def:
24351 + opt->type = token;
24355 + opt->udba = udba_val(a->args[0].from);
24356 + if (opt->udba >= 0) {
24358 + opt->type = token;
24360 + pr_err("wrong value, %s\n", opt_str);
24363 + case Opt_wbr_create:
24364 + u.create = &opt->wbr_create;
24365 + u.create->wbr_create
24366 + = au_wbr_create_val(a->args[0].from, u.create);
24367 + if (u.create->wbr_create >= 0) {
24369 + opt->type = token;
24371 + pr_err("wrong value, %s\n", opt_str);
24373 + case Opt_wbr_copyup:
24374 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
24375 + if (opt->wbr_copyup >= 0) {
24377 + opt->type = token;
24379 + pr_err("wrong value, %s\n", opt_str);
24382 + case Opt_fhsm_sec:
24383 + if (unlikely(match_int(&a->args[0], &n)
24385 + pr_err("bad integer in %s\n", opt_str);
24388 + if (sysaufs_brs) {
24389 + opt->fhsm_second = n;
24390 + opt->type = token;
24392 + pr_warn("ignored %s\n", opt_str);
24397 + pr_warn("ignored %s\n", opt_str);
24399 + case Opt_ignore_silent:
24404 + pr_err("unknown option %s\n", opt_str);
24408 + if (!err && !skipped) {
24409 + if (unlikely(++opt > opt_tail)) {
24412 + opt->type = Opt_tail;
24415 + opt->type = Opt_tail;
24419 + au_delayed_kfree(a);
24421 + if (unlikely(err))
24422 + au_opts_free(opts);
24428 +static int au_opt_wbr_create(struct super_block *sb,
24429 + struct au_opt_wbr_create *create)
24432 + struct au_sbinfo *sbinfo;
24434 + SiMustWriteLock(sb);
24436 + err = 1; /* handled */
24437 + sbinfo = au_sbi(sb);
24438 + if (sbinfo->si_wbr_create_ops->fin) {
24439 + err = sbinfo->si_wbr_create_ops->fin(sb);
24444 + sbinfo->si_wbr_create = create->wbr_create;
24445 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
24446 + switch (create->wbr_create) {
24447 + case AuWbrCreate_MFSRRV:
24448 + case AuWbrCreate_MFSRR:
24449 + case AuWbrCreate_PMFSRR:
24450 + case AuWbrCreate_PMFSRRV:
24451 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
24453 + case AuWbrCreate_MFS:
24454 + case AuWbrCreate_MFSV:
24455 + case AuWbrCreate_PMFS:
24456 + case AuWbrCreate_PMFSV:
24457 + sbinfo->si_wbr_mfs.mfs_expire
24458 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
24462 + if (sbinfo->si_wbr_create_ops->init)
24463 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
24470 + * plus: processed without an error
24471 + * zero: unprocessed
24473 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
24474 + struct au_opts *opts)
24477 + struct au_sbinfo *sbinfo;
24479 + SiMustWriteLock(sb);
24481 + err = 1; /* handled */
24482 + sbinfo = au_sbi(sb);
24483 + switch (opt->type) {
24485 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24486 + sbinfo->si_mntflags |= opt->udba;
24487 + opts->given_udba |= opt->udba;
24491 + au_opt_set(sbinfo->si_mntflags, PLINK);
24493 + case Opt_noplink:
24494 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24495 + au_plink_put(sb, /*verbose*/1);
24496 + au_opt_clr(sbinfo->si_mntflags, PLINK);
24498 + case Opt_list_plink:
24499 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24500 + au_plink_list(sb);
24504 + au_opt_set(sbinfo->si_mntflags, DIO);
24505 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24508 + au_opt_clr(sbinfo->si_mntflags, DIO);
24509 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24512 + case Opt_fhsm_sec:
24513 + au_fhsm_set(sbinfo, opt->fhsm_second);
24516 + case Opt_diropq_a:
24517 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24519 + case Opt_diropq_w:
24520 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24523 + case Opt_warn_perm:
24524 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
24526 + case Opt_nowarn_perm:
24527 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
24530 + case Opt_verbose:
24531 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
24533 + case Opt_noverbose:
24534 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
24538 + au_opt_set(sbinfo->si_mntflags, SUM);
24541 + au_opt_clr(sbinfo->si_mntflags, SUM);
24542 + au_opt_set(sbinfo->si_mntflags, SUM_W);
24544 + au_opt_clr(sbinfo->si_mntflags, SUM);
24545 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
24548 + case Opt_wbr_create:
24549 + err = au_opt_wbr_create(sb, &opt->wbr_create);
24551 + case Opt_wbr_copyup:
24552 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
24553 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
24557 + sbinfo->si_dirwh = opt->dirwh;
24560 + case Opt_rdcache:
24561 + sbinfo->si_rdcache
24562 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24565 + sbinfo->si_rdblk = opt->rdblk;
24567 + case Opt_rdblk_def:
24568 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24571 + sbinfo->si_rdhash = opt->rdhash;
24573 + case Opt_rdhash_def:
24574 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24578 + au_opt_set(sbinfo->si_mntflags, SHWH);
24581 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24584 + case Opt_dirperm1:
24585 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24587 + case Opt_nodirperm1:
24588 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24591 + case Opt_trunc_xino:
24592 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24594 + case Opt_notrunc_xino:
24595 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24598 + case Opt_trunc_xino_path:
24599 + case Opt_itrunc_xino:
24600 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24605 + case Opt_trunc_xib:
24606 + au_fset_opts(opts->flags, TRUNC_XIB);
24608 + case Opt_notrunc_xib:
24609 + au_fclr_opts(opts->flags, TRUNC_XIB);
24613 + sb->s_flags |= MS_POSIXACL;
24616 + sb->s_flags &= ~MS_POSIXACL;
24628 + * returns tri-state.
24629 + * plus: processed without an error
24630 + * zero: unprocessed
24633 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24634 + struct au_opts *opts)
24636 + int err, do_refresh;
24639 + switch (opt->type) {
24641 + opt->add.bindex = au_sbbot(sb) + 1;
24642 + if (opt->add.bindex < 0)
24643 + opt->add.bindex = 0;
24645 + case Opt_prepend:
24646 + opt->add.bindex = 0;
24647 + add: /* indented label */
24649 + err = au_br_add(sb, &opt->add,
24650 + au_ftest_opts(opts->flags, REMOUNT));
24653 + au_fset_opts(opts->flags, REFRESH);
24659 + err = au_br_del(sb, &opt->del,
24660 + au_ftest_opts(opts->flags, REMOUNT));
24663 + au_fset_opts(opts->flags, TRUNC_XIB);
24664 + au_fset_opts(opts->flags, REFRESH);
24670 + err = au_br_mod(sb, &opt->mod,
24671 + au_ftest_opts(opts->flags, REMOUNT),
24676 + au_fset_opts(opts->flags, REFRESH);
24684 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24685 + struct au_opt_xino **opt_xino,
24686 + struct au_opts *opts)
24689 + aufs_bindex_t bbot, bindex;
24690 + struct dentry *root, *parent, *h_root;
24693 + switch (opt->type) {
24695 + err = au_xino_set(sb, &opt->xino,
24696 + !!au_ftest_opts(opts->flags, REMOUNT));
24697 + if (unlikely(err))
24700 + *opt_xino = &opt->xino;
24701 + au_xino_brid_set(sb, -1);
24703 + /* safe d_parent access */
24704 + parent = opt->xino.file->f_path.dentry->d_parent;
24705 + root = sb->s_root;
24706 + bbot = au_sbbot(sb);
24707 + for (bindex = 0; bindex <= bbot; bindex++) {
24708 + h_root = au_h_dptr(root, bindex);
24709 + if (h_root == parent) {
24710 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24718 + au_xino_brid_set(sb, -1);
24719 + *opt_xino = (void *)-1;
24726 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24727 + unsigned int pending)
24730 + aufs_bindex_t bindex, bbot;
24731 + unsigned char do_plink, skip, do_free, can_no_dreval;
24732 + struct au_branch *br;
24733 + struct au_wbr *wbr;
24734 + struct dentry *root, *dentry;
24735 + struct inode *dir, *h_dir;
24736 + struct au_sbinfo *sbinfo;
24737 + struct au_hinode *hdir;
24739 + SiMustAnyLock(sb);
24741 + sbinfo = au_sbi(sb);
24742 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24744 + if (!(sb_flags & MS_RDONLY)) {
24745 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24746 + pr_warn("first branch should be rw\n");
24747 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24748 + pr_warn_once("shwh should be used with ro\n");
24751 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24752 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24753 + pr_warn_once("udba=*notify requires xino\n");
24755 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24756 + pr_warn_once("dirperm1 breaks the protection"
24757 + " by the permission bits on the lower branch\n");
24761 + root = sb->s_root;
24762 + dir = d_inode(root);
24763 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24764 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
24766 + bbot = au_sbbot(sb);
24767 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
24769 + h_dir = au_h_iptr(dir, bindex);
24770 + br = au_sbr(sb, bindex);
24772 + if ((br->br_perm & AuBrAttr_ICEX)
24773 + && !h_dir->i_op->listxattr)
24774 + br->br_perm &= ~AuBrAttr_ICEX;
24776 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24777 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24778 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24782 + wbr = br->br_wbr;
24784 + wbr_wh_read_lock(wbr);
24786 + if (!au_br_writable(br->br_perm)) {
24789 + || (!wbr->wbr_whbase
24790 + && !wbr->wbr_plink
24791 + && !wbr->wbr_orph));
24792 + } else if (!au_br_wh_linkable(br->br_perm)) {
24793 + /* skip = (!br->br_whbase && !br->br_orph); */
24794 + skip = (!wbr || !wbr->wbr_whbase);
24795 + if (skip && wbr) {
24797 + skip = !!wbr->wbr_plink;
24799 + skip = !wbr->wbr_plink;
24802 + /* skip = (br->br_whbase && br->br_ohph); */
24803 + skip = (wbr && wbr->wbr_whbase);
24806 + skip = !!wbr->wbr_plink;
24808 + skip = !wbr->wbr_plink;
24812 + wbr_wh_read_unlock(wbr);
24814 + if (can_no_dreval) {
24815 + dentry = br->br_path.dentry;
24816 + spin_lock(&dentry->d_lock);
24817 + if (dentry->d_flags &
24818 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
24819 + can_no_dreval = 0;
24820 + spin_unlock(&dentry->d_lock);
24823 + if (au_br_fhsm(br->br_perm)) {
24825 + AuDebugOn(!br->br_fhsm);
24831 + hdir = au_hi(dir, bindex);
24832 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
24834 + wbr_wh_write_lock(wbr);
24835 + err = au_wh_init(br, sb);
24837 + wbr_wh_write_unlock(wbr);
24838 + au_hn_inode_unlock(hdir);
24840 + if (!err && do_free) {
24842 + au_delayed_kfree(wbr);
24843 + br->br_wbr = NULL;
24847 + if (can_no_dreval)
24848 + au_fset_si(sbinfo, NO_DREVAL);
24850 + au_fclr_si(sbinfo, NO_DREVAL);
24853 + au_fset_si(sbinfo, FHSM);
24854 + for (bindex = bbot; bindex >= 0; bindex--) {
24855 + br = au_sbr(sb, bindex);
24856 + if (au_br_fhsm(br->br_perm)) {
24857 + au_fhsm_set_bottom(sb, bindex);
24862 + au_fclr_si(sbinfo, FHSM);
24863 + au_fhsm_set_bottom(sb, -1);
24869 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24872 + unsigned int tmp;
24873 + aufs_bindex_t bindex, bbot;
24874 + struct au_opt *opt;
24875 + struct au_opt_xino *opt_xino, xino;
24876 + struct au_sbinfo *sbinfo;
24877 + struct au_branch *br;
24878 + struct inode *dir;
24880 + SiMustWriteLock(sb);
24885 + while (err >= 0 && opt->type != Opt_tail)
24886 + err = au_opt_simple(sb, opt++, opts);
24889 + else if (unlikely(err < 0))
24892 + /* disable xino and udba temporary */
24893 + sbinfo = au_sbi(sb);
24894 + tmp = sbinfo->si_mntflags;
24895 + au_opt_clr(sbinfo->si_mntflags, XINO);
24896 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
24899 + while (err >= 0 && opt->type != Opt_tail)
24900 + err = au_opt_br(sb, opt++, opts);
24903 + else if (unlikely(err < 0))
24906 + bbot = au_sbbot(sb);
24907 + if (unlikely(bbot < 0)) {
24909 + pr_err("no branches\n");
24913 + if (au_opt_test(tmp, XINO))
24914 + au_opt_set(sbinfo->si_mntflags, XINO);
24916 + while (!err && opt->type != Opt_tail)
24917 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
24918 + if (unlikely(err))
24921 + err = au_opts_verify(sb, sb->s_flags, tmp);
24922 + if (unlikely(err))
24925 + /* restore xino */
24926 + if (au_opt_test(tmp, XINO) && !opt_xino) {
24927 + xino.file = au_xino_def(sb);
24928 + err = PTR_ERR(xino.file);
24929 + if (IS_ERR(xino.file))
24932 + err = au_xino_set(sb, &xino, /*remount*/0);
24934 + if (unlikely(err))
24938 + /* restore udba */
24939 + tmp &= AuOptMask_UDBA;
24940 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24941 + sbinfo->si_mntflags |= tmp;
24942 + bbot = au_sbbot(sb);
24943 + for (bindex = 0; bindex <= bbot; bindex++) {
24944 + br = au_sbr(sb, bindex);
24945 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
24946 + if (unlikely(err))
24947 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
24949 + /* go on even if err */
24951 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
24952 + dir = d_inode(sb->s_root);
24953 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
24960 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
24963 + unsigned char no_dreval;
24964 + struct inode *dir;
24965 + struct au_opt_xino *opt_xino;
24966 + struct au_opt *opt;
24967 + struct au_sbinfo *sbinfo;
24969 + SiMustWriteLock(sb);
24972 + dir = d_inode(sb->s_root);
24973 + sbinfo = au_sbi(sb);
24976 + while (err >= 0 && opt->type != Opt_tail) {
24977 + err = au_opt_simple(sb, opt, opts);
24979 + err = au_opt_br(sb, opt, opts);
24981 + err = au_opt_xino(sb, opt, &opt_xino, opts);
24987 + /* go on even err */
24989 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
24990 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
24991 + if (unlikely(rerr && !err))
24994 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
24995 + au_fset_opts(opts->flags, REFRESH_IDOP);
24997 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
24998 + rerr = au_xib_trunc(sb);
24999 + if (unlikely(rerr && !err))
25003 + /* will be handled by the caller */
25004 + if (!au_ftest_opts(opts->flags, REFRESH)
25005 + && (opts->given_udba
25006 + || au_opt_test(sbinfo->si_mntflags, XINO)
25007 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
25009 + au_fset_opts(opts->flags, REFRESH);
25011 + AuDbg("status 0x%x\n", opts->flags);
25015 +/* ---------------------------------------------------------------------- */
25017 +unsigned int au_opt_udba(struct super_block *sb)
25019 + return au_mntflags(sb) & AuOptMask_UDBA;
25021 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
25022 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
25023 +++ linux/fs/aufs/opts.h 2016-10-09 16:55:36.496035060 +0200
25026 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25028 + * This program, aufs is free software; you can redistribute it and/or modify
25029 + * it under the terms of the GNU General Public License as published by
25030 + * the Free Software Foundation; either version 2 of the License, or
25031 + * (at your option) any later version.
25033 + * This program is distributed in the hope that it will be useful,
25034 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25035 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25036 + * GNU General Public License for more details.
25038 + * You should have received a copy of the GNU General Public License
25039 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25043 + * mount options/flags
25046 +#ifndef __AUFS_OPTS_H__
25047 +#define __AUFS_OPTS_H__
25051 +#include <linux/path.h>
25054 +struct super_block;
25056 +/* ---------------------------------------------------------------------- */
25059 +#define AuOpt_XINO 1 /* external inode number bitmap
25060 + and translation table */
25061 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
25062 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
25063 +#define AuOpt_UDBA_REVAL (1 << 3)
25064 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
25065 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
25066 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
25067 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
25069 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
25070 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
25071 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
25072 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
25073 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
25074 +#define AuOpt_DIO (1 << 14) /* direct io */
25076 +#ifndef CONFIG_AUFS_HNOTIFY
25077 +#undef AuOpt_UDBA_HNOTIFY
25078 +#define AuOpt_UDBA_HNOTIFY 0
25080 +#ifndef CONFIG_AUFS_SHWH
25082 +#define AuOpt_SHWH 0
25085 +#define AuOpt_Def (AuOpt_XINO \
25086 + | AuOpt_UDBA_REVAL \
25088 + /* | AuOpt_DIRPERM1 */ \
25089 + | AuOpt_WARN_PERM)
25090 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
25091 + | AuOpt_UDBA_REVAL \
25092 + | AuOpt_UDBA_HNOTIFY)
25094 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
25095 +#define au_opt_set(flags, name) do { \
25096 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
25097 + ((flags) |= AuOpt_##name); \
25099 +#define au_opt_set_udba(flags, name) do { \
25100 + (flags) &= ~AuOptMask_UDBA; \
25101 + ((flags) |= AuOpt_##name); \
25103 +#define au_opt_clr(flags, name) do { \
25104 + ((flags) &= ~AuOpt_##name); \
25107 +static inline unsigned int au_opts_plink(unsigned int mntflags)
25109 +#ifdef CONFIG_PROC_FS
25112 + return mntflags & ~AuOpt_PLINK;
25116 +/* ---------------------------------------------------------------------- */
25118 +/* policies to select one among multiple writable branches */
25120 + AuWbrCreate_TDP, /* top down parent */
25121 + AuWbrCreate_RR, /* round robin */
25122 + AuWbrCreate_MFS, /* most free space */
25123 + AuWbrCreate_MFSV, /* mfs with seconds */
25124 + AuWbrCreate_MFSRR, /* mfs then rr */
25125 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
25126 + AuWbrCreate_PMFS, /* parent and mfs */
25127 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
25128 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
25129 + AuWbrCreate_PMFSRRV, /* plus seconds */
25131 + AuWbrCreate_Def = AuWbrCreate_TDP
25135 + AuWbrCopyup_TDP, /* top down parent */
25136 + AuWbrCopyup_BUP, /* bottom up parent */
25137 + AuWbrCopyup_BU, /* bottom up */
25139 + AuWbrCopyup_Def = AuWbrCopyup_TDP
25142 +/* ---------------------------------------------------------------------- */
25144 +struct au_opt_add {
25145 + aufs_bindex_t bindex;
25148 + struct path path;
25151 +struct au_opt_del {
25153 + struct path h_path;
25156 +struct au_opt_mod {
25159 + struct dentry *h_root;
25162 +struct au_opt_xino {
25164 + struct file *file;
25167 +struct au_opt_xino_itrunc {
25168 + aufs_bindex_t bindex;
25171 +struct au_opt_wbr_create {
25174 + unsigned long long mfsrr_watermark;
25180 + struct au_opt_xino xino;
25181 + struct au_opt_xino_itrunc xino_itrunc;
25182 + struct au_opt_add add;
25183 + struct au_opt_del del;
25184 + struct au_opt_mod mod;
25187 + unsigned int rdblk;
25188 + unsigned int rdhash;
25190 + struct au_opt_wbr_create wbr_create;
25192 + unsigned int fhsm_second;
25197 +#define AuOpts_REMOUNT 1
25198 +#define AuOpts_REFRESH (1 << 1)
25199 +#define AuOpts_TRUNC_XIB (1 << 2)
25200 +#define AuOpts_REFRESH_DYAOP (1 << 3)
25201 +#define AuOpts_REFRESH_IDOP (1 << 4)
25202 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
25203 +#define au_fset_opts(flags, name) \
25204 + do { (flags) |= AuOpts_##name; } while (0)
25205 +#define au_fclr_opts(flags, name) \
25206 + do { (flags) &= ~AuOpts_##name; } while (0)
25209 + struct au_opt *opt;
25212 + unsigned int given_udba;
25213 + unsigned int flags;
25214 + unsigned long sb_flags;
25217 +/* ---------------------------------------------------------------------- */
25220 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
25221 +const char *au_optstr_udba(int udba);
25222 +const char *au_optstr_wbr_copyup(int wbr_copyup);
25223 +const char *au_optstr_wbr_create(int wbr_create);
25225 +void au_opts_free(struct au_opts *opts);
25226 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
25227 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
25228 + unsigned int pending);
25229 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
25230 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
25232 +unsigned int au_opt_udba(struct super_block *sb);
25234 +#endif /* __KERNEL__ */
25235 +#endif /* __AUFS_OPTS_H__ */
25236 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
25237 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
25238 +++ linux/fs/aufs/plink.c 2016-10-09 16:55:36.496035060 +0200
25241 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25243 + * This program, aufs is free software; you can redistribute it and/or modify
25244 + * it under the terms of the GNU General Public License as published by
25245 + * the Free Software Foundation; either version 2 of the License, or
25246 + * (at your option) any later version.
25248 + * This program is distributed in the hope that it will be useful,
25249 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25250 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25251 + * GNU General Public License for more details.
25253 + * You should have received a copy of the GNU General Public License
25254 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25264 + * the pseudo-link maintenance mode.
25265 + * during a user process maintains the pseudo-links,
25266 + * prohibit adding a new plink and branch manipulation.
25270 + * For entry functions which will handle plink, and i_mutex is already held
25272 + * They cannot wait and should return an error at once.
25273 + * Callers has to check the error.
25275 + * For entry functions which will handle plink, but i_mutex is not held
25277 + * They can wait the plink maintenance mode to finish.
25279 + * They behave like F_SETLK and F_SETLKW.
25280 + * If the caller never handle plink, then both flags are unnecessary.
25283 +int au_plink_maint(struct super_block *sb, int flags)
25287 + struct task_struct *parent, *prev;
25288 + struct au_sbinfo *sbi;
25290 + SiMustAnyLock(sb);
25293 + if (!au_opt_test(au_mntflags(sb), PLINK))
25296 + sbi = au_sbi(sb);
25297 + pid = sbi->si_plink_maint_pid;
25298 + if (!pid || pid == current->pid)
25301 + /* todo: it highly depends upon /sbin/mount.aufs */
25303 + parent = current;
25307 + parent = rcu_dereference(parent->real_parent);
25308 + if (parent == prev)
25310 + ppid = task_pid_vnr(parent);
25311 + if (pid == ppid) {
25312 + rcu_read_unlock();
25317 + rcu_read_unlock();
25319 + if (au_ftest_lock(flags, NOPLMW)) {
25320 + /* if there is no i_mutex lock in VFS, we don't need to wait */
25321 + /* AuDebugOn(!lockdep_depth(current)); */
25322 + while (sbi->si_plink_maint_pid) {
25323 + si_read_unlock(sb);
25324 + /* gave up wake_up_bit() */
25325 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
25327 + if (au_ftest_lock(flags, FLUSH))
25328 + au_nwt_flush(&sbi->si_nowait);
25329 + si_noflush_read_lock(sb);
25331 + } else if (au_ftest_lock(flags, NOPLM)) {
25332 + AuDbg("ppid %d, pid %d\n", ppid, pid);
25340 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
25342 + spin_lock(&sbinfo->si_plink_maint_lock);
25343 + sbinfo->si_plink_maint_pid = 0;
25344 + spin_unlock(&sbinfo->si_plink_maint_lock);
25345 + wake_up_all(&sbinfo->si_plink_wq);
25348 +int au_plink_maint_enter(struct super_block *sb)
25351 + struct au_sbinfo *sbinfo;
25354 + sbinfo = au_sbi(sb);
25355 + /* make sure i am the only one in this fs */
25356 + si_write_lock(sb, AuLock_FLUSH);
25357 + if (au_opt_test(au_mntflags(sb), PLINK)) {
25358 + spin_lock(&sbinfo->si_plink_maint_lock);
25359 + if (!sbinfo->si_plink_maint_pid)
25360 + sbinfo->si_plink_maint_pid = current->pid;
25363 + spin_unlock(&sbinfo->si_plink_maint_lock);
25365 + si_write_unlock(sb);
25370 +/* ---------------------------------------------------------------------- */
25372 +#ifdef CONFIG_AUFS_DEBUG
25373 +void au_plink_list(struct super_block *sb)
25376 + struct au_sbinfo *sbinfo;
25377 + struct hlist_head *plink_hlist;
25378 + struct au_icntnr *icntnr;
25380 + SiMustAnyLock(sb);
25382 + sbinfo = au_sbi(sb);
25383 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25384 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25386 + for (i = 0; i < AuPlink_NHASH; i++) {
25387 + plink_hlist = &sbinfo->si_plink[i].head;
25389 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25390 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
25391 + rcu_read_unlock();
25396 +/* is the inode pseudo-linked? */
25397 +int au_plink_test(struct inode *inode)
25400 + struct au_sbinfo *sbinfo;
25401 + struct hlist_head *plink_hlist;
25402 + struct au_icntnr *icntnr;
25404 + sbinfo = au_sbi(inode->i_sb);
25405 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25406 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
25407 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25410 + i = au_plink_hash(inode->i_ino);
25411 + plink_hlist = &sbinfo->si_plink[i].head;
25413 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25414 + if (&icntnr->vfs_inode == inode) {
25418 + rcu_read_unlock();
25422 +/* ---------------------------------------------------------------------- */
25425 + * generate a name for plink.
25426 + * the file will be stored under AUFS_WH_PLINKDIR.
25428 +/* 20 is max digits length of ulong 64 */
25429 +#define PLINK_NAME_LEN ((20 + 1) * 2)
25431 +static int plink_name(char *name, int len, struct inode *inode,
25432 + aufs_bindex_t bindex)
25435 + struct inode *h_inode;
25437 + h_inode = au_h_iptr(inode, bindex);
25438 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
25442 +struct au_do_plink_lkup_args {
25443 + struct dentry **errp;
25444 + struct qstr *tgtname;
25445 + struct dentry *h_parent;
25446 + struct au_branch *br;
25449 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
25450 + struct dentry *h_parent,
25451 + struct au_branch *br)
25453 + struct dentry *h_dentry;
25454 + struct inode *h_inode;
25456 + h_inode = d_inode(h_parent);
25457 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
25458 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
25459 + inode_unlock(h_inode);
25463 +static void au_call_do_plink_lkup(void *args)
25465 + struct au_do_plink_lkup_args *a = args;
25466 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
25469 +/* lookup the plink-ed @inode under the branch at @bindex */
25470 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
25472 + struct dentry *h_dentry, *h_parent;
25473 + struct au_branch *br;
25475 + char a[PLINK_NAME_LEN];
25476 + struct qstr tgtname = QSTR_INIT(a, 0);
25478 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25480 + br = au_sbr(inode->i_sb, bindex);
25481 + h_parent = br->br_wbr->wbr_plink;
25482 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25484 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25485 + struct au_do_plink_lkup_args args = {
25486 + .errp = &h_dentry,
25487 + .tgtname = &tgtname,
25488 + .h_parent = h_parent,
25492 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
25493 + if (unlikely(wkq_err))
25494 + h_dentry = ERR_PTR(wkq_err);
25496 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
25501 +/* create a pseudo-link */
25502 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
25503 + struct dentry *h_dentry, struct au_branch *br)
25506 + struct path h_path = {
25507 + .mnt = au_br_mnt(br)
25509 + struct inode *h_dir, *delegated;
25511 + h_dir = d_inode(h_parent);
25512 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
25514 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
25515 + err = PTR_ERR(h_path.dentry);
25516 + if (IS_ERR(h_path.dentry))
25520 + /* wh.plink dir is not monitored */
25521 + /* todo: is it really safe? */
25522 + if (d_is_positive(h_path.dentry)
25523 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
25524 + delegated = NULL;
25525 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
25526 + if (unlikely(err == -EWOULDBLOCK)) {
25527 + pr_warn("cannot retry for NFSv4 delegation"
25528 + " for an internal unlink\n");
25531 + dput(h_path.dentry);
25532 + h_path.dentry = NULL;
25536 + if (!err && d_is_negative(h_path.dentry)) {
25537 + delegated = NULL;
25538 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
25539 + if (unlikely(err == -EWOULDBLOCK)) {
25540 + pr_warn("cannot retry for NFSv4 delegation"
25541 + " for an internal link\n");
25545 + dput(h_path.dentry);
25548 + inode_unlock(h_dir);
25552 +struct do_whplink_args {
25554 + struct qstr *tgt;
25555 + struct dentry *h_parent;
25556 + struct dentry *h_dentry;
25557 + struct au_branch *br;
25560 +static void call_do_whplink(void *args)
25562 + struct do_whplink_args *a = args;
25563 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
25566 +static int whplink(struct dentry *h_dentry, struct inode *inode,
25567 + aufs_bindex_t bindex, struct au_branch *br)
25569 + int err, wkq_err;
25570 + struct au_wbr *wbr;
25571 + struct dentry *h_parent;
25572 + char a[PLINK_NAME_LEN];
25573 + struct qstr tgtname = QSTR_INIT(a, 0);
25575 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
25576 + h_parent = wbr->wbr_plink;
25577 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25579 + /* always superio. */
25580 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25581 + struct do_whplink_args args = {
25584 + .h_parent = h_parent,
25585 + .h_dentry = h_dentry,
25588 + wkq_err = au_wkq_wait(call_do_whplink, &args);
25589 + if (unlikely(wkq_err))
25592 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
25598 + * create a new pseudo-link for @h_dentry on @bindex.
25599 + * the linked inode is held in aufs @inode.
25601 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25602 + struct dentry *h_dentry)
25604 + struct super_block *sb;
25605 + struct au_sbinfo *sbinfo;
25606 + struct hlist_head *plink_hlist;
25607 + struct au_icntnr *icntnr;
25608 + struct au_sphlhead *sphl;
25609 + int found, err, cnt, i;
25611 + sb = inode->i_sb;
25612 + sbinfo = au_sbi(sb);
25613 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25614 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25616 + found = au_plink_test(inode);
25620 + i = au_plink_hash(inode->i_ino);
25621 + sphl = sbinfo->si_plink + i;
25622 + plink_hlist = &sphl->head;
25625 + spin_lock(&sphl->spin);
25626 + hlist_for_each_entry(icntnr, plink_hlist, plink) {
25627 + if (&icntnr->vfs_inode == inode) {
25633 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
25634 + hlist_add_head_rcu(&icntnr->plink, plink_hlist);
25636 + spin_unlock(&sphl->spin);
25638 + cnt = au_sphl_count(sphl);
25639 +#define msg "unexpectedly unblanced or too many pseudo-links"
25640 + if (cnt > AUFS_PLINK_WARN)
25641 + AuWarn1(msg ", %d\n", cnt);
25643 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25644 + if (unlikely(err)) {
25645 + pr_warn("err %d, damaged pseudo link.\n", err);
25646 + au_sphl_del_rcu(&icntnr->plink, sphl);
25647 + iput(&icntnr->vfs_inode);
25650 + iput(&icntnr->vfs_inode);
25653 +/* free all plinks */
25654 +void au_plink_put(struct super_block *sb, int verbose)
25657 + struct au_sbinfo *sbinfo;
25658 + struct hlist_head *plink_hlist;
25659 + struct hlist_node *tmp;
25660 + struct au_icntnr *icntnr;
25662 + SiMustWriteLock(sb);
25664 + sbinfo = au_sbi(sb);
25665 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25666 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25668 + /* no spin_lock since sbinfo is write-locked */
25670 + for (i = 0; i < AuPlink_NHASH; i++) {
25671 + plink_hlist = &sbinfo->si_plink[i].head;
25672 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25673 + pr_warn("pseudo-link is not flushed");
25676 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink)
25677 + iput(&icntnr->vfs_inode);
25678 + INIT_HLIST_HEAD(plink_hlist);
25682 +void au_plink_clean(struct super_block *sb, int verbose)
25684 + struct dentry *root;
25686 + root = sb->s_root;
25687 + aufs_write_lock(root);
25688 + if (au_opt_test(au_mntflags(sb), PLINK))
25689 + au_plink_put(sb, verbose);
25690 + aufs_write_unlock(root);
25693 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25696 + aufs_bindex_t btop, bbot, bindex;
25699 + btop = au_ibtop(inode);
25700 + bbot = au_ibbot(inode);
25702 + for (bindex = btop; bindex <= bbot; bindex++) {
25703 + if (!au_h_iptr(inode, bindex)
25704 + || au_ii_br_id(inode, bindex) != br_id)
25706 + au_set_h_iptr(inode, bindex, NULL, 0);
25711 + for (bindex = btop; bindex <= bbot; bindex++)
25712 + if (au_h_iptr(inode, bindex)) {
25722 +/* free the plinks on a branch specified by @br_id */
25723 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25725 + struct au_sbinfo *sbinfo;
25726 + struct hlist_head *plink_hlist;
25727 + struct hlist_node *tmp;
25728 + struct au_icntnr *icntnr;
25729 + struct inode *inode;
25732 + SiMustWriteLock(sb);
25734 + sbinfo = au_sbi(sb);
25735 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25736 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25738 + /* no spin_lock since sbinfo is write-locked */
25739 + for (i = 0; i < AuPlink_NHASH; i++) {
25740 + plink_hlist = &sbinfo->si_plink[i].head;
25741 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink) {
25742 + inode = au_igrab(&icntnr->vfs_inode);
25743 + ii_write_lock_child(inode);
25744 + do_put = au_plink_do_half_refresh(inode, br_id);
25746 + hlist_del(&icntnr->plink);
25749 + ii_write_unlock(inode);
25754 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25755 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25756 +++ linux/fs/aufs/poll.c 2016-10-09 16:55:36.496035060 +0200
25759 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25761 + * This program, aufs is free software; you can redistribute it and/or modify
25762 + * it under the terms of the GNU General Public License as published by
25763 + * the Free Software Foundation; either version 2 of the License, or
25764 + * (at your option) any later version.
25766 + * This program is distributed in the hope that it will be useful,
25767 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25768 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25769 + * GNU General Public License for more details.
25771 + * You should have received a copy of the GNU General Public License
25772 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25777 + * There is only one filesystem which implements ->poll operation, currently.
25782 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25784 + unsigned int mask;
25786 + struct file *h_file;
25787 + struct super_block *sb;
25789 + /* We should pretend an error happened. */
25790 + mask = POLLERR /* | POLLIN | POLLOUT */;
25791 + sb = file->f_path.dentry->d_sb;
25792 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25794 + h_file = au_read_pre(file, /*keep_fi*/0);
25795 + err = PTR_ERR(h_file);
25796 + if (IS_ERR(h_file))
25799 + /* it is not an error if h_file has no operation */
25800 + mask = DEFAULT_POLLMASK;
25801 + if (h_file->f_op->poll)
25802 + mask = h_file->f_op->poll(h_file, wait);
25803 + fput(h_file); /* instead of au_read_post() */
25806 + si_read_unlock(sb);
25807 + AuTraceErr((int)mask);
25810 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25811 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25812 +++ linux/fs/aufs/posix_acl.c 2016-10-09 16:55:36.496035060 +0200
25815 + * Copyright (C) 2014-2016 Junjiro R. Okajima
25817 + * This program, aufs is free software; you can redistribute it and/or modify
25818 + * it under the terms of the GNU General Public License as published by
25819 + * the Free Software Foundation; either version 2 of the License, or
25820 + * (at your option) any later version.
25822 + * This program is distributed in the hope that it will be useful,
25823 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25824 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25825 + * GNU General Public License for more details.
25827 + * You should have received a copy of the GNU General Public License
25828 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25832 + * posix acl operations
25835 +#include <linux/fs.h>
25838 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25840 + struct posix_acl *acl;
25842 + aufs_bindex_t bindex;
25843 + struct inode *h_inode;
25844 + struct super_block *sb;
25847 + sb = inode->i_sb;
25848 + si_read_lock(sb, AuLock_FLUSH);
25849 + ii_read_lock_child(inode);
25850 + if (!(sb->s_flags & MS_POSIXACL))
25853 + bindex = au_ibtop(inode);
25854 + h_inode = au_h_iptr(inode, bindex);
25855 + if (unlikely(!h_inode
25856 + || ((h_inode->i_mode & S_IFMT)
25857 + != (inode->i_mode & S_IFMT)))) {
25858 + err = au_busy_or_stale();
25859 + acl = ERR_PTR(err);
25863 + /* always topmost only */
25864 + acl = get_acl(h_inode, type);
25867 + ii_read_unlock(inode);
25868 + si_read_unlock(sb);
25870 + AuTraceErrPtr(acl);
25874 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25878 + struct dentry *dentry;
25879 + struct au_srxattr arg = {
25880 + .type = AU_ACL_SET,
25887 + IMustLock(inode);
25889 + if (inode->i_ino == AUFS_ROOT_INO)
25890 + dentry = dget(inode->i_sb->s_root);
25892 + dentry = d_find_alias(inode);
25894 + dentry = d_find_any_alias(inode);
25896 + pr_warn("cannot handle this inode, "
25897 + "please report to aufs-users ML\n");
25903 + ssz = au_srxattr(dentry, inode, &arg);
25912 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
25913 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
25914 +++ linux/fs/aufs/procfs.c 2016-10-09 16:55:36.496035060 +0200
25917 + * Copyright (C) 2010-2016 Junjiro R. Okajima
25919 + * This program, aufs is free software; you can redistribute it and/or modify
25920 + * it under the terms of the GNU General Public License as published by
25921 + * the Free Software Foundation; either version 2 of the License, or
25922 + * (at your option) any later version.
25924 + * This program is distributed in the hope that it will be useful,
25925 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25926 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25927 + * GNU General Public License for more details.
25929 + * You should have received a copy of the GNU General Public License
25930 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25934 + * procfs interfaces
25937 +#include <linux/proc_fs.h>
25940 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
25942 + struct au_sbinfo *sbinfo;
25944 + sbinfo = file->private_data;
25946 + au_plink_maint_leave(sbinfo);
25947 + kobject_put(&sbinfo->si_kobj);
25953 +static void au_procfs_plm_write_clean(struct file *file)
25955 + struct au_sbinfo *sbinfo;
25957 + sbinfo = file->private_data;
25959 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
25962 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
25965 + struct super_block *sb;
25966 + struct au_sbinfo *sbinfo;
25969 + if (unlikely(file->private_data))
25973 + /* don't use au_sbilist_lock() here */
25974 + spin_lock(&au_sbilist.spin);
25975 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
25976 + if (id == sysaufs_si_id(sbinfo)) {
25977 + kobject_get(&sbinfo->si_kobj);
25978 + sb = sbinfo->si_sb;
25981 + spin_unlock(&au_sbilist.spin);
25984 + if (unlikely(!sb))
25987 + err = au_plink_maint_enter(sb);
25989 + /* keep kobject_get() */
25990 + file->private_data = sbinfo;
25992 + kobject_put(&sbinfo->si_kobj);
25998 + * Accept a valid "si=xxxx" only.
25999 + * Once it is accepted successfully, accept "clean" too.
26001 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
26002 + size_t count, loff_t *ppos)
26005 + unsigned long id;
26006 + /* last newline is allowed */
26007 + char buf[3 + sizeof(unsigned long) * 2 + 1];
26010 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26014 + if (unlikely(count > sizeof(buf)))
26017 + err = copy_from_user(buf, ubuf, count);
26018 + if (unlikely(err)) {
26025 + if (!strcmp("clean", buf)) {
26026 + au_procfs_plm_write_clean(file);
26027 + goto out_success;
26028 + } else if (unlikely(strncmp("si=", buf, 3)))
26031 + err = kstrtoul(buf + 3, 16, &id);
26032 + if (unlikely(err))
26035 + err = au_procfs_plm_write_si(file, id);
26036 + if (unlikely(err))
26040 + err = count; /* success */
26045 +static const struct file_operations au_procfs_plm_fop = {
26046 + .write = au_procfs_plm_write,
26047 + .release = au_procfs_plm_release,
26048 + .owner = THIS_MODULE
26051 +/* ---------------------------------------------------------------------- */
26053 +static struct proc_dir_entry *au_procfs_dir;
26055 +void au_procfs_fin(void)
26057 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
26058 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26061 +int __init au_procfs_init(void)
26064 + struct proc_dir_entry *entry;
26067 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
26068 + if (unlikely(!au_procfs_dir))
26071 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
26072 + au_procfs_dir, &au_procfs_plm_fop);
26073 + if (unlikely(!entry))
26077 + goto out; /* success */
26081 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26085 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
26086 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
26087 +++ linux/fs/aufs/rdu.c 2016-10-09 16:55:36.496035060 +0200
26090 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26092 + * This program, aufs is free software; you can redistribute it and/or modify
26093 + * it under the terms of the GNU General Public License as published by
26094 + * the Free Software Foundation; either version 2 of the License, or
26095 + * (at your option) any later version.
26097 + * This program is distributed in the hope that it will be useful,
26098 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26099 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26100 + * GNU General Public License for more details.
26102 + * You should have received a copy of the GNU General Public License
26103 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26107 + * readdir in userspace.
26110 +#include <linux/compat.h>
26111 +#include <linux/fs_stack.h>
26112 +#include <linux/security.h>
26115 +/* bits for struct aufs_rdu.flags */
26116 +#define AuRdu_CALLED 1
26117 +#define AuRdu_CONT (1 << 1)
26118 +#define AuRdu_FULL (1 << 2)
26119 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
26120 +#define au_fset_rdu(flags, name) \
26121 + do { (flags) |= AuRdu_##name; } while (0)
26122 +#define au_fclr_rdu(flags, name) \
26123 + do { (flags) &= ~AuRdu_##name; } while (0)
26125 +struct au_rdu_arg {
26126 + struct dir_context ctx;
26127 + struct aufs_rdu *rdu;
26128 + union au_rdu_ent_ul ent;
26129 + unsigned long end;
26131 + struct super_block *sb;
26135 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
26136 + loff_t offset, u64 h_ino, unsigned int d_type)
26139 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
26140 + struct aufs_rdu *rdu = arg->rdu;
26141 + struct au_rdu_ent ent;
26145 + au_fset_rdu(rdu->cookie.flags, CALLED);
26146 + len = au_rdu_len(nlen);
26147 + if (arg->ent.ul + len < arg->end) {
26149 + ent.bindex = rdu->cookie.bindex;
26150 + ent.type = d_type;
26152 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
26153 + ent.type = DT_UNKNOWN;
26155 + /* unnecessary to support mmap_sem since this is a dir */
26157 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
26159 + if (copy_to_user(arg->ent.e->name, name, nlen))
26161 + /* the terminating NULL */
26162 + if (__put_user(0, arg->ent.e->name + nlen))
26165 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
26166 + arg->ent.ul += len;
26170 + au_fset_rdu(rdu->cookie.flags, FULL);
26172 + rdu->tail = arg->ent;
26176 + /* AuTraceErr(err); */
26180 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
26184 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
26186 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
26187 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
26189 + if (unlikely(offset != cookie->h_pos))
26195 + au_fclr_rdu(cookie->flags, CALLED);
26197 + err = vfsub_iterate_dir(h_file, &arg->ctx);
26201 + && au_ftest_rdu(cookie->flags, CALLED)
26202 + && !au_ftest_rdu(cookie->flags, FULL));
26203 + cookie->h_pos = h_file->f_pos;
26210 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
26213 + aufs_bindex_t bbot;
26214 + struct au_rdu_arg arg = {
26216 + .actor = au_rdu_fill
26219 + struct dentry *dentry;
26220 + struct inode *inode;
26221 + struct file *h_file;
26222 + struct au_rdu_cookie *cookie = &rdu->cookie;
26224 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
26225 + if (unlikely(err)) {
26231 + rdu->tail = rdu->ent;
26234 + arg.ent = rdu->ent;
26235 + arg.end = arg.ent.ul;
26236 + arg.end += rdu->sz;
26239 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
26242 + err = security_file_permission(file, MAY_READ);
26244 + if (unlikely(err))
26247 + dentry = file->f_path.dentry;
26248 + inode = d_inode(dentry);
26249 + inode_lock_shared(inode);
26251 + arg.sb = inode->i_sb;
26252 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
26253 + if (unlikely(err))
26255 + err = au_alive_dir(dentry);
26256 + if (unlikely(err))
26258 + /* todo: reval? */
26259 + fi_read_lock(file);
26262 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
26263 + && cookie->generation != au_figen(file)))
26268 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
26270 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
26272 + bbot = au_fbtop(file);
26273 + if (cookie->bindex < bbot)
26274 + cookie->bindex = bbot;
26275 + bbot = au_fbbot_dir(file);
26276 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
26277 + for (; !err && cookie->bindex <= bbot;
26278 + cookie->bindex++, cookie->h_pos = 0) {
26279 + h_file = au_hf_dir(file, cookie->bindex);
26283 + au_fclr_rdu(cookie->flags, FULL);
26284 + err = au_rdu_do(h_file, &arg);
26286 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
26289 + AuDbg("rent %llu\n", rdu->rent);
26291 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
26292 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
26293 + au_fset_rdu(cookie->flags, CONT);
26294 + cookie->generation = au_figen(file);
26297 + ii_read_lock_child(inode);
26298 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
26299 + ii_read_unlock(inode);
26302 + fi_read_unlock(file);
26304 + si_read_unlock(arg.sb);
26306 + inode_unlock_shared(inode);
26312 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
26316 + unsigned long long nent;
26317 + union au_rdu_ent_ul *u;
26318 + struct au_rdu_ent ent;
26319 + struct super_block *sb;
26322 + nent = rdu->nent;
26324 + sb = file->f_path.dentry->d_sb;
26325 + si_read_lock(sb, AuLock_FLUSH);
26326 + while (nent-- > 0) {
26327 + /* unnecessary to support mmap_sem since this is a dir */
26328 + err = copy_from_user(&ent, u->e, sizeof(ent));
26330 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
26331 + if (unlikely(err)) {
26337 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
26339 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
26341 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
26343 + if (unlikely(err)) {
26348 + err = __put_user(ino, &u->e->ino);
26349 + if (unlikely(err)) {
26354 + u->ul += au_rdu_len(ent.nlen);
26356 + si_read_unlock(sb);
26361 +/* ---------------------------------------------------------------------- */
26363 +static int au_rdu_verify(struct aufs_rdu *rdu)
26365 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
26366 + "%llu, b%d, 0x%x, g%u}\n",
26367 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
26369 + rdu->rent, rdu->shwh, rdu->full,
26370 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
26371 + rdu->cookie.generation);
26373 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
26377 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
26381 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26384 + struct aufs_rdu rdu;
26385 + void __user *p = (void __user *)arg;
26387 + err = copy_from_user(&rdu, p, sizeof(rdu));
26388 + if (unlikely(err)) {
26393 + err = au_rdu_verify(&rdu);
26394 + if (unlikely(err))
26398 + case AUFS_CTL_RDU:
26399 + err = au_rdu(file, &rdu);
26400 + if (unlikely(err))
26403 + e = copy_to_user(p, &rdu, sizeof(rdu));
26404 + if (unlikely(e)) {
26409 + case AUFS_CTL_RDU_INO:
26410 + err = au_rdu_ino(file, &rdu);
26414 + /* err = -ENOTTY; */
26423 +#ifdef CONFIG_COMPAT
26424 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26427 + struct aufs_rdu rdu;
26428 + void __user *p = compat_ptr(arg);
26430 + /* todo: get_user()? */
26431 + err = copy_from_user(&rdu, p, sizeof(rdu));
26432 + if (unlikely(err)) {
26437 + rdu.ent.e = compat_ptr(rdu.ent.ul);
26438 + err = au_rdu_verify(&rdu);
26439 + if (unlikely(err))
26443 + case AUFS_CTL_RDU:
26444 + err = au_rdu(file, &rdu);
26445 + if (unlikely(err))
26448 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
26449 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
26450 + e = copy_to_user(p, &rdu, sizeof(rdu));
26451 + if (unlikely(e)) {
26456 + case AUFS_CTL_RDU_INO:
26457 + err = au_rdu_ino(file, &rdu);
26461 + /* err = -ENOTTY; */
26470 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
26471 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
26472 +++ linux/fs/aufs/rwsem.h 2016-10-09 16:55:36.496035060 +0200
26475 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26477 + * This program, aufs is free software; you can redistribute it and/or modify
26478 + * it under the terms of the GNU General Public License as published by
26479 + * the Free Software Foundation; either version 2 of the License, or
26480 + * (at your option) any later version.
26482 + * This program is distributed in the hope that it will be useful,
26483 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26484 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26485 + * GNU General Public License for more details.
26487 + * You should have received a copy of the GNU General Public License
26488 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26492 + * simple read-write semaphore wrappers
26495 +#ifndef __AUFS_RWSEM_H__
26496 +#define __AUFS_RWSEM_H__
26500 +#include "debug.h"
26503 + struct rw_semaphore rwsem;
26504 +#ifdef CONFIG_AUFS_DEBUG
26505 + /* just for debugging, not almighty counter */
26506 + atomic_t rcnt, wcnt;
26510 +#ifdef CONFIG_LOCKDEP
26511 +#define au_lockdep_set_name(rw) \
26512 + lockdep_set_class_and_name(&(rw)->rwsem, \
26513 + /*original key*/(rw)->rwsem.dep_map.key, \
26516 +#define au_lockdep_set_name(rw) do {} while (0)
26519 +#ifdef CONFIG_AUFS_DEBUG
26520 +#define AuDbgCntInit(rw) do { \
26521 + atomic_set(&(rw)->rcnt, 0); \
26522 + atomic_set(&(rw)->wcnt, 0); \
26523 + smp_mb(); /* atomic set */ \
26526 +#define AuDbgCnt(rw, cnt) atomic_read(&(rw)->cnt)
26527 +#define AuDbgCntInc(rw, cnt) atomic_inc(&(rw)->cnt)
26528 +#define AuDbgCntDec(rw, cnt) WARN_ON(atomic_dec_return(&(rw)->cnt) < 0)
26529 +#define AuDbgRcntInc(rw) AuDbgCntInc(rw, rcnt)
26530 +#define AuDbgRcntDec(rw) AuDbgCntDec(rw, rcnt)
26531 +#define AuDbgWcntInc(rw) AuDbgCntInc(rw, wcnt)
26532 +#define AuDbgWcntDec(rw) AuDbgCntDec(rw, wcnt)
26534 +#define AuDbgCnt(rw, cnt) 0
26535 +#define AuDbgCntInit(rw) do {} while (0)
26536 +#define AuDbgRcntInc(rw) do {} while (0)
26537 +#define AuDbgRcntDec(rw) do {} while (0)
26538 +#define AuDbgWcntInc(rw) do {} while (0)
26539 +#define AuDbgWcntDec(rw) do {} while (0)
26540 +#endif /* CONFIG_AUFS_DEBUG */
26542 +/* to debug easier, do not make them inlined functions */
26543 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(&(rw)->rwsem))
26544 +/* rwsem_is_locked() is unusable */
26545 +#define AuRwMustReadLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0)
26546 +#define AuRwMustWriteLock(rw) AuDebugOn(AuDbgCnt(rw, wcnt) <= 0)
26547 +#define AuRwMustAnyLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0 \
26548 + && AuDbgCnt(rw, wcnt) <= 0)
26549 +#define AuRwDestroy(rw) AuDebugOn(AuDbgCnt(rw, rcnt) \
26550 + || AuDbgCnt(rw, wcnt))
26552 +#define au_rw_init(rw) do { \
26553 + AuDbgCntInit(rw); \
26554 + init_rwsem(&(rw)->rwsem); \
26555 + au_lockdep_set_name(rw); \
26558 +#define au_rw_init_wlock(rw) do { \
26559 + au_rw_init(rw); \
26560 + down_write(&(rw)->rwsem); \
26561 + AuDbgWcntInc(rw); \
26564 +#define au_rw_init_wlock_nested(rw, lsc) do { \
26565 + au_rw_init(rw); \
26566 + down_write_nested(&(rw)->rwsem, lsc); \
26567 + AuDbgWcntInc(rw); \
26570 +static inline void au_rw_read_lock(struct au_rwsem *rw)
26572 + down_read(&rw->rwsem);
26573 + AuDbgRcntInc(rw);
26576 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26578 + down_read_nested(&rw->rwsem, lsc);
26579 + AuDbgRcntInc(rw);
26582 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26584 + AuRwMustReadLock(rw);
26585 + AuDbgRcntDec(rw);
26586 + up_read(&rw->rwsem);
26589 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26591 + AuRwMustWriteLock(rw);
26592 + AuDbgRcntInc(rw);
26593 + AuDbgWcntDec(rw);
26594 + downgrade_write(&rw->rwsem);
26597 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26599 + down_write(&rw->rwsem);
26600 + AuDbgWcntInc(rw);
26603 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26604 + unsigned int lsc)
26606 + down_write_nested(&rw->rwsem, lsc);
26607 + AuDbgWcntInc(rw);
26610 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26612 + AuRwMustWriteLock(rw);
26613 + AuDbgWcntDec(rw);
26614 + up_write(&rw->rwsem);
26617 +/* why is not _nested version defined */
26618 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26622 + ret = down_read_trylock(&rw->rwsem);
26624 + AuDbgRcntInc(rw);
26628 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26632 + ret = down_write_trylock(&rw->rwsem);
26634 + AuDbgWcntInc(rw);
26638 +#undef AuDbgCntDec
26639 +#undef AuDbgRcntInc
26640 +#undef AuDbgRcntDec
26641 +#undef AuDbgWcntDec
26643 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26644 +static inline void prefix##_read_lock(param) \
26645 +{ au_rw_read_lock(rwsem); } \
26646 +static inline void prefix##_write_lock(param) \
26647 +{ au_rw_write_lock(rwsem); } \
26648 +static inline int prefix##_read_trylock(param) \
26649 +{ return au_rw_read_trylock(rwsem); } \
26650 +static inline int prefix##_write_trylock(param) \
26651 +{ return au_rw_write_trylock(rwsem); }
26652 +/* why is not _nested version defined */
26653 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26654 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26655 +static inline void prefix##_write_trylock_nestd(param, lsc)
26656 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26658 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26659 +static inline void prefix##_read_unlock(param) \
26660 +{ au_rw_read_unlock(rwsem); } \
26661 +static inline void prefix##_write_unlock(param) \
26662 +{ au_rw_write_unlock(rwsem); } \
26663 +static inline void prefix##_downgrade_lock(param) \
26664 +{ au_rw_dgrade_lock(rwsem); }
26666 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26667 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26668 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26670 +#endif /* __KERNEL__ */
26671 +#endif /* __AUFS_RWSEM_H__ */
26672 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26673 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26674 +++ linux/fs/aufs/sbinfo.c 2016-10-09 16:55:38.889431135 +0200
26677 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26679 + * This program, aufs is free software; you can redistribute it and/or modify
26680 + * it under the terms of the GNU General Public License as published by
26681 + * the Free Software Foundation; either version 2 of the License, or
26682 + * (at your option) any later version.
26684 + * This program is distributed in the hope that it will be useful,
26685 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26686 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26687 + * GNU General Public License for more details.
26689 + * You should have received a copy of the GNU General Public License
26690 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26694 + * superblock private data
26700 + * they are necessary regardless sysfs is disabled.
26702 +void au_si_free(struct kobject *kobj)
26705 + struct au_sbinfo *sbinfo;
26706 + char *locked __maybe_unused; /* debug only */
26708 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26709 + for (i = 0; i < AuPlink_NHASH; i++)
26710 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26711 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
26713 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
26714 + percpu_counter_destroy(&sbinfo->si_ninodes);
26715 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
26716 + percpu_counter_destroy(&sbinfo->si_nfiles);
26718 + au_rw_write_lock(&sbinfo->si_rwsem);
26719 + au_br_free(sbinfo);
26720 + au_rw_write_unlock(&sbinfo->si_rwsem);
26722 + au_delayed_kfree(sbinfo->si_branch);
26723 + for (i = 0; i < AU_NPIDMAP; i++)
26724 + if (sbinfo->au_si_pid.pid_bitmap[i])
26725 + au_delayed_kfree(sbinfo->au_si_pid.pid_bitmap[i]);
26726 + mutex_destroy(&sbinfo->au_si_pid.pid_mtx);
26727 + mutex_destroy(&sbinfo->si_xib_mtx);
26728 + AuRwDestroy(&sbinfo->si_rwsem);
26730 + au_delayed_kfree(sbinfo);
26733 +int au_si_alloc(struct super_block *sb)
26736 + struct au_sbinfo *sbinfo;
26739 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26740 + if (unlikely(!sbinfo))
26743 + /* will be reallocated separately */
26744 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26745 + if (unlikely(!sbinfo->si_branch))
26748 + err = sysaufs_si_init(sbinfo);
26749 + if (unlikely(err))
26752 + au_nwt_init(&sbinfo->si_nowait);
26753 + au_rw_init_wlock(&sbinfo->si_rwsem);
26754 + mutex_init(&sbinfo->au_si_pid.pid_mtx);
26756 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
26757 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
26759 + sbinfo->si_bbot = -1;
26760 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26762 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26763 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26764 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26765 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26767 + au_fhsm_init(sbinfo);
26769 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26771 + sbinfo->si_xino_jiffy = jiffies;
26772 + sbinfo->si_xino_expire
26773 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26774 + mutex_init(&sbinfo->si_xib_mtx);
26775 + sbinfo->si_xino_brid = -1;
26776 + /* leave si_xib_last_pindex and si_xib_next_bit */
26778 + au_sphl_init(&sbinfo->si_aopen);
26780 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26781 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26782 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26783 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26785 + for (i = 0; i < AuPlink_NHASH; i++)
26786 + au_sphl_init(sbinfo->si_plink + i);
26787 + init_waitqueue_head(&sbinfo->si_plink_wq);
26788 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26790 + au_sphl_init(&sbinfo->si_files);
26792 + /* with getattr by default */
26793 + sbinfo->si_iop_array = aufs_iop;
26795 + /* leave other members for sysaufs and si_mnt. */
26796 + sbinfo->si_sb = sb;
26797 + sb->s_fs_info = sbinfo;
26799 + return 0; /* success */
26802 + au_delayed_kfree(sbinfo->si_branch);
26804 + au_delayed_kfree(sbinfo);
26809 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
26812 + struct au_branch **brp;
26814 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26817 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
26818 + if (unlikely(!sz))
26819 + sz = sizeof(*brp);
26820 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
26823 + sbinfo->si_branch = brp;
26830 +/* ---------------------------------------------------------------------- */
26832 +unsigned int au_sigen_inc(struct super_block *sb)
26834 + unsigned int gen;
26835 + struct inode *inode;
26837 + SiMustWriteLock(sb);
26839 + gen = ++au_sbi(sb)->si_generation;
26840 + au_update_digen(sb->s_root);
26841 + inode = d_inode(sb->s_root);
26842 + au_update_iigen(inode, /*half*/0);
26843 + inode->i_version++;
26847 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26849 + aufs_bindex_t br_id;
26851 + struct au_sbinfo *sbinfo;
26853 + SiMustWriteLock(sb);
26855 + sbinfo = au_sbi(sb);
26856 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26857 + br_id = ++sbinfo->si_last_br_id;
26858 + AuDebugOn(br_id < 0);
26859 + if (br_id && au_br_index(sb, br_id) < 0)
26866 +/* ---------------------------------------------------------------------- */
26868 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26869 +int si_read_lock(struct super_block *sb, int flags)
26874 + if (au_ftest_lock(flags, FLUSH))
26875 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26877 + si_noflush_read_lock(sb);
26878 + err = au_plink_maint(sb, flags);
26879 + if (unlikely(err))
26880 + si_read_unlock(sb);
26885 +int si_write_lock(struct super_block *sb, int flags)
26889 + if (au_ftest_lock(flags, FLUSH))
26890 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26892 + si_noflush_write_lock(sb);
26893 + err = au_plink_maint(sb, flags);
26894 + if (unlikely(err))
26895 + si_write_unlock(sb);
26900 +/* dentry and super_block lock. call at entry point */
26901 +int aufs_read_lock(struct dentry *dentry, int flags)
26904 + struct super_block *sb;
26906 + sb = dentry->d_sb;
26907 + err = si_read_lock(sb, flags);
26908 + if (unlikely(err))
26911 + if (au_ftest_lock(flags, DW))
26912 + di_write_lock_child(dentry);
26914 + di_read_lock_child(dentry, flags);
26916 + if (au_ftest_lock(flags, GEN)) {
26917 + err = au_digen_test(dentry, au_sigen(sb));
26918 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
26919 + AuDebugOn(!err && au_dbrange_test(dentry));
26921 + err = au_dbrange_test(dentry);
26922 + if (unlikely(err))
26923 + aufs_read_unlock(dentry, flags);
26930 +void aufs_read_unlock(struct dentry *dentry, int flags)
26932 + if (au_ftest_lock(flags, DW))
26933 + di_write_unlock(dentry);
26935 + di_read_unlock(dentry, flags);
26936 + si_read_unlock(dentry->d_sb);
26939 +void aufs_write_lock(struct dentry *dentry)
26941 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
26942 + di_write_lock_child(dentry);
26945 +void aufs_write_unlock(struct dentry *dentry)
26947 + di_write_unlock(dentry);
26948 + si_write_unlock(dentry->d_sb);
26951 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
26954 + unsigned int sigen;
26955 + struct super_block *sb;
26958 + err = si_read_lock(sb, flags);
26959 + if (unlikely(err))
26962 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
26964 + if (au_ftest_lock(flags, GEN)) {
26965 + sigen = au_sigen(sb);
26966 + err = au_digen_test(d1, sigen);
26967 + AuDebugOn(!err && au_dbrange_test(d1));
26969 + err = au_digen_test(d2, sigen);
26970 + AuDebugOn(!err && au_dbrange_test(d2));
26972 + if (unlikely(err))
26973 + aufs_read_and_write_unlock2(d1, d2);
26980 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
26982 + di_write_unlock2(d1, d2);
26983 + si_read_unlock(d1->d_sb);
26986 +/* ---------------------------------------------------------------------- */
26988 +static void si_pid_alloc(struct au_si_pid *au_si_pid, int idx)
26990 + unsigned long *p;
26992 + BUILD_BUG_ON(sizeof(unsigned long) !=
26993 + sizeof(*au_si_pid->pid_bitmap));
26995 + mutex_lock(&au_si_pid->pid_mtx);
26996 + p = au_si_pid->pid_bitmap[idx];
27000 + * but keeping 'si_pid_set()' void is more important.
27002 + p = kcalloc(BITS_TO_LONGS(AU_PIDSTEP),
27003 + sizeof(*au_si_pid->pid_bitmap),
27009 + au_si_pid->pid_bitmap[idx] = p;
27010 + mutex_unlock(&au_si_pid->pid_mtx);
27013 +void si_pid_set(struct super_block *sb)
27017 + unsigned long *bitmap;
27018 + struct au_si_pid *au_si_pid;
27020 + si_pid_idx_bit(&idx, &bit);
27021 + au_si_pid = &au_sbi(sb)->au_si_pid;
27022 + bitmap = au_si_pid->pid_bitmap[idx];
27024 + si_pid_alloc(au_si_pid, idx);
27025 + bitmap = au_si_pid->pid_bitmap[idx];
27027 + AuDebugOn(test_bit(bit, bitmap));
27028 + set_bit(bit, bitmap);
27031 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
27032 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
27033 +++ linux/fs/aufs/spl.h 2016-10-09 16:55:36.496035060 +0200
27036 + * Copyright (C) 2005-2016 Junjiro R. Okajima
27038 + * This program, aufs is free software; you can redistribute it and/or modify
27039 + * it under the terms of the GNU General Public License as published by
27040 + * the Free Software Foundation; either version 2 of the License, or
27041 + * (at your option) any later version.
27043 + * This program is distributed in the hope that it will be useful,
27044 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27045 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27046 + * GNU General Public License for more details.
27048 + * You should have received a copy of the GNU General Public License
27049 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27053 + * simple list protected by a spinlock
27056 +#ifndef __AUFS_SPL_H__
27057 +#define __AUFS_SPL_H__
27062 +struct au_splhead {
27064 + struct list_head head;
27067 +static inline void au_spl_init(struct au_splhead *spl)
27069 + spin_lock_init(&spl->spin);
27070 + INIT_LIST_HEAD(&spl->head);
27073 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
27075 + spin_lock(&spl->spin);
27076 + list_add(list, &spl->head);
27077 + spin_unlock(&spl->spin);
27080 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
27082 + spin_lock(&spl->spin);
27084 + spin_unlock(&spl->spin);
27087 +static inline void au_spl_del_rcu(struct list_head *list,
27088 + struct au_splhead *spl)
27090 + spin_lock(&spl->spin);
27091 + list_del_rcu(list);
27092 + spin_unlock(&spl->spin);
27096 +/* ---------------------------------------------------------------------- */
27098 +struct au_sphlhead {
27100 + struct hlist_head head;
27103 +static inline void au_sphl_init(struct au_sphlhead *sphl)
27105 + spin_lock_init(&sphl->spin);
27106 + INIT_HLIST_HEAD(&sphl->head);
27109 +static inline void au_sphl_add(struct hlist_node *hlist,
27110 + struct au_sphlhead *sphl)
27112 + spin_lock(&sphl->spin);
27113 + hlist_add_head(hlist, &sphl->head);
27114 + spin_unlock(&sphl->spin);
27117 +static inline void au_sphl_del(struct hlist_node *hlist,
27118 + struct au_sphlhead *sphl)
27120 + spin_lock(&sphl->spin);
27121 + hlist_del(hlist);
27122 + spin_unlock(&sphl->spin);
27125 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
27126 + struct au_sphlhead *sphl)
27128 + spin_lock(&sphl->spin);
27129 + hlist_del_rcu(hlist);
27130 + spin_unlock(&sphl->spin);
27133 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
27135 + unsigned long cnt;
27136 + struct hlist_node *pos;
27139 + spin_lock(&sphl->spin);
27140 + hlist_for_each(pos, &sphl->head)
27142 + spin_unlock(&sphl->spin);
27146 +#endif /* __KERNEL__ */
27147 +#endif /* __AUFS_SPL_H__ */
27148 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
27149 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
27150 +++ linux/fs/aufs/super.c 2016-10-09 16:55:36.496035060 +0200
27153 + * Copyright (C) 2005-2016 Junjiro R. Okajima
27155 + * This program, aufs is free software; you can redistribute it and/or modify
27156 + * it under the terms of the GNU General Public License as published by
27157 + * the Free Software Foundation; either version 2 of the License, or
27158 + * (at your option) any later version.
27160 + * This program is distributed in the hope that it will be useful,
27161 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27162 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27163 + * GNU General Public License for more details.
27165 + * You should have received a copy of the GNU General Public License
27166 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27170 + * mount and super_block operations
27173 +#include <linux/mm.h>
27174 +#include <linux/seq_file.h>
27175 +#include <linux/statfs.h>
27176 +#include <linux/vmalloc.h>
27180 + * super_operations
27182 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
27184 + struct au_icntnr *c;
27186 + c = au_cache_alloc_icntnr();
27188 + au_icntnr_init(c);
27189 + c->vfs_inode.i_version = 1; /* sigen(sb); */
27190 + c->iinfo.ii_hinode = NULL;
27191 + return &c->vfs_inode;
27196 +static void aufs_destroy_inode_cb(struct rcu_head *head)
27198 + struct inode *inode = container_of(head, struct inode, i_rcu);
27200 + au_cache_dfree_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
27203 +static void aufs_destroy_inode(struct inode *inode)
27205 + if (!au_is_bad_inode(inode))
27206 + au_iinfo_fin(inode);
27207 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
27210 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
27212 + struct inode *inode;
27215 + inode = iget_locked(sb, ino);
27216 + if (unlikely(!inode)) {
27217 + inode = ERR_PTR(-ENOMEM);
27220 + if (!(inode->i_state & I_NEW))
27223 + err = au_xigen_new(inode);
27225 + err = au_iinfo_init(inode);
27227 + inode->i_version++;
27229 + iget_failed(inode);
27230 + inode = ERR_PTR(err);
27234 + /* never return NULL */
27235 + AuDebugOn(!inode);
27236 + AuTraceErrPtr(inode);
27240 +/* lock free root dinfo */
27241 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
27244 + aufs_bindex_t bindex, bbot;
27245 + struct path path;
27246 + struct au_hdentry *hdp;
27247 + struct au_branch *br;
27248 + au_br_perm_str_t perm;
27251 + bbot = au_sbbot(sb);
27253 + hdp = au_hdentry(au_di(sb->s_root), bindex);
27254 + for (; !err && bindex <= bbot; bindex++, hdp++) {
27255 + br = au_sbr(sb, bindex);
27256 + path.mnt = au_br_mnt(br);
27257 + path.dentry = hdp->hd_dentry;
27258 + err = au_seq_path(seq, &path);
27260 + au_optstr_br_perm(&perm, br->br_perm);
27261 + seq_printf(seq, "=%s", perm.a);
27262 + if (bindex != bbot)
27263 + seq_putc(seq, ':');
27266 + if (unlikely(err || seq_has_overflowed(seq)))
27272 +static void au_show_wbr_create(struct seq_file *m, int v,
27273 + struct au_sbinfo *sbinfo)
27277 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27279 + seq_puts(m, ",create=");
27280 + pat = au_optstr_wbr_create(v);
27282 + case AuWbrCreate_TDP:
27283 + case AuWbrCreate_RR:
27284 + case AuWbrCreate_MFS:
27285 + case AuWbrCreate_PMFS:
27286 + seq_puts(m, pat);
27288 + case AuWbrCreate_MFSV:
27289 + seq_printf(m, /*pat*/"mfs:%lu",
27290 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
27293 + case AuWbrCreate_PMFSV:
27294 + seq_printf(m, /*pat*/"pmfs:%lu",
27295 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
27298 + case AuWbrCreate_MFSRR:
27299 + seq_printf(m, /*pat*/"mfsrr:%llu",
27300 + sbinfo->si_wbr_mfs.mfsrr_watermark);
27302 + case AuWbrCreate_MFSRRV:
27303 + seq_printf(m, /*pat*/"mfsrr:%llu:%lu",
27304 + sbinfo->si_wbr_mfs.mfsrr_watermark,
27305 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
27308 + case AuWbrCreate_PMFSRR:
27309 + seq_printf(m, /*pat*/"pmfsrr:%llu",
27310 + sbinfo->si_wbr_mfs.mfsrr_watermark);
27312 + case AuWbrCreate_PMFSRRV:
27313 + seq_printf(m, /*pat*/"pmfsrr:%llu:%lu",
27314 + sbinfo->si_wbr_mfs.mfsrr_watermark,
27315 + jiffies_to_msecs(sbinfo->si_wbr_mfs.mfs_expire)
27321 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
27323 +#ifdef CONFIG_SYSFS
27327 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
27328 + aufs_bindex_t bindex, brid;
27329 + struct qstr *name;
27331 + struct dentry *d, *h_root;
27333 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27336 + f = au_sbi(sb)->si_xib;
27340 + /* stop printing the default xino path on the first writable branch */
27342 + brid = au_xino_brid(sb);
27344 + bindex = au_br_index(sb, brid);
27345 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
27347 + d = f->f_path.dentry;
27348 + name = &d->d_name;
27349 + /* safe ->d_parent because the file is unlinked */
27350 + if (d->d_parent == h_root
27351 + && name->len == len
27352 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
27355 + seq_puts(seq, ",xino=");
27356 + err = au_xino_path(seq, f);
27363 +/* seq_file will re-call me in case of too long string */
27364 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
27367 + unsigned int mnt_flags, v;
27368 + struct super_block *sb;
27369 + struct au_sbinfo *sbinfo;
27371 +#define AuBool(name, str) do { \
27372 + v = au_opt_test(mnt_flags, name); \
27373 + if (v != au_opt_test(AuOpt_Def, name)) \
27374 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
27377 +#define AuStr(name, str) do { \
27378 + v = mnt_flags & AuOptMask_##name; \
27379 + if (v != (AuOpt_Def & AuOptMask_##name)) \
27380 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
27383 +#define AuUInt(name, str, val) do { \
27384 + if (val != AUFS_##name##_DEF) \
27385 + seq_printf(m, "," #str "=%u", val); \
27388 + sb = dentry->d_sb;
27389 + if (sb->s_flags & MS_POSIXACL)
27390 + seq_puts(m, ",acl");
27392 + /* lock free root dinfo */
27393 + si_noflush_read_lock(sb);
27394 + sbinfo = au_sbi(sb);
27395 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
27397 + mnt_flags = au_mntflags(sb);
27398 + if (au_opt_test(mnt_flags, XINO)) {
27399 + err = au_show_xino(m, sb);
27400 + if (unlikely(err))
27403 + seq_puts(m, ",noxino");
27405 + AuBool(TRUNC_XINO, trunc_xino);
27406 + AuStr(UDBA, udba);
27407 + AuBool(SHWH, shwh);
27408 + AuBool(PLINK, plink);
27409 + AuBool(DIO, dio);
27410 + AuBool(DIRPERM1, dirperm1);
27412 + v = sbinfo->si_wbr_create;
27413 + if (v != AuWbrCreate_Def)
27414 + au_show_wbr_create(m, v, sbinfo);
27416 + v = sbinfo->si_wbr_copyup;
27417 + if (v != AuWbrCopyup_Def)
27418 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
27420 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
27421 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
27422 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
27424 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
27426 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
27427 + AuUInt(RDCACHE, rdcache, v);
27429 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
27430 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
27432 + au_fhsm_show(m, sbinfo);
27434 + AuBool(SUM, sum);
27435 + /* AuBool(SUM_W, wsum); */
27436 + AuBool(WARN_PERM, warn_perm);
27437 + AuBool(VERBOSE, verbose);
27440 + /* be sure to print "br:" last */
27441 + if (!sysaufs_brs) {
27442 + seq_puts(m, ",br:");
27443 + au_show_brs(m, sb);
27445 + si_read_unlock(sb);
27453 +/* ---------------------------------------------------------------------- */
27455 +/* sum mode which returns the summation for statfs(2) */
27457 +static u64 au_add_till_max(u64 a, u64 b)
27465 + return ULLONG_MAX;
27468 +static u64 au_mul_till_max(u64 a, long mul)
27476 + return ULLONG_MAX;
27479 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
27482 + long bsize, factor;
27483 + u64 blocks, bfree, bavail, files, ffree;
27484 + aufs_bindex_t bbot, bindex, i;
27485 + unsigned char shared;
27486 + struct path h_path;
27487 + struct super_block *h_sb;
27490 + bsize = LONG_MAX;
27496 + bbot = au_sbbot(sb);
27497 + for (bindex = 0; bindex <= bbot; bindex++) {
27498 + h_path.mnt = au_sbr_mnt(sb, bindex);
27499 + h_sb = h_path.mnt->mnt_sb;
27501 + for (i = 0; !shared && i < bindex; i++)
27502 + shared = (au_sbr_sb(sb, i) == h_sb);
27506 + /* sb->s_root for NFS is unreliable */
27507 + h_path.dentry = h_path.mnt->mnt_root;
27508 + err = vfs_statfs(&h_path, buf);
27509 + if (unlikely(err))
27512 + if (bsize > buf->f_bsize) {
27514 + * we will reduce bsize, so we have to expand blocks
27515 + * etc. to match them again
27517 + factor = (bsize / buf->f_bsize);
27518 + blocks = au_mul_till_max(blocks, factor);
27519 + bfree = au_mul_till_max(bfree, factor);
27520 + bavail = au_mul_till_max(bavail, factor);
27521 + bsize = buf->f_bsize;
27524 + factor = (buf->f_bsize / bsize);
27525 + blocks = au_add_till_max(blocks,
27526 + au_mul_till_max(buf->f_blocks, factor));
27527 + bfree = au_add_till_max(bfree,
27528 + au_mul_till_max(buf->f_bfree, factor));
27529 + bavail = au_add_till_max(bavail,
27530 + au_mul_till_max(buf->f_bavail, factor));
27531 + files = au_add_till_max(files, buf->f_files);
27532 + ffree = au_add_till_max(ffree, buf->f_ffree);
27535 + buf->f_bsize = bsize;
27536 + buf->f_blocks = blocks;
27537 + buf->f_bfree = bfree;
27538 + buf->f_bavail = bavail;
27539 + buf->f_files = files;
27540 + buf->f_ffree = ffree;
27541 + buf->f_frsize = 0;
27547 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
27550 + struct path h_path;
27551 + struct super_block *sb;
27553 + /* lock free root dinfo */
27554 + sb = dentry->d_sb;
27555 + si_noflush_read_lock(sb);
27556 + if (!au_opt_test(au_mntflags(sb), SUM)) {
27557 + /* sb->s_root for NFS is unreliable */
27558 + h_path.mnt = au_sbr_mnt(sb, 0);
27559 + h_path.dentry = h_path.mnt->mnt_root;
27560 + err = vfs_statfs(&h_path, buf);
27562 + err = au_statfs_sum(sb, buf);
27563 + si_read_unlock(sb);
27566 + buf->f_type = AUFS_SUPER_MAGIC;
27567 + buf->f_namelen = AUFS_MAX_NAMELEN;
27568 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
27570 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27575 +/* ---------------------------------------------------------------------- */
27577 +static int aufs_sync_fs(struct super_block *sb, int wait)
27580 + aufs_bindex_t bbot, bindex;
27581 + struct au_branch *br;
27582 + struct super_block *h_sb;
27585 + si_noflush_read_lock(sb);
27586 + bbot = au_sbbot(sb);
27587 + for (bindex = 0; bindex <= bbot; bindex++) {
27588 + br = au_sbr(sb, bindex);
27589 + if (!au_br_writable(br->br_perm))
27592 + h_sb = au_sbr_sb(sb, bindex);
27593 + if (h_sb->s_op->sync_fs) {
27594 + e = h_sb->s_op->sync_fs(h_sb, wait);
27595 + if (unlikely(e && !err))
27597 + /* go on even if an error happens */
27600 + si_read_unlock(sb);
27605 +/* ---------------------------------------------------------------------- */
27607 +/* final actions when unmounting a file system */
27608 +static void aufs_put_super(struct super_block *sb)
27610 + struct au_sbinfo *sbinfo;
27612 + sbinfo = au_sbi(sb);
27616 + dbgaufs_si_fin(sbinfo);
27617 + kobject_put(&sbinfo->si_kobj);
27620 +/* ---------------------------------------------------------------------- */
27622 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
27623 + struct super_block *sb, void *arg)
27626 + unsigned long long n, sz;
27633 + if (*hint > ULLONG_MAX / sizeof(array)) {
27634 + array = ERR_PTR(-EMFILE);
27635 + pr_err("hint %llu\n", *hint);
27639 + sz = sizeof(array) * *hint;
27640 + array = kzalloc(sz, GFP_NOFS);
27641 + if (unlikely(!array))
27642 + array = vzalloc(sz);
27643 + if (unlikely(!array)) {
27644 + array = ERR_PTR(-ENOMEM);
27648 + n = cb(sb, array, *hint, arg);
27649 + AuDebugOn(n > *hint);
27656 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
27657 + unsigned long long max __maybe_unused,
27660 + unsigned long long n;
27661 + struct inode **p, *inode;
27662 + struct list_head *head;
27667 + spin_lock(&sb->s_inode_list_lock);
27668 + list_for_each_entry(inode, head, i_sb_list) {
27669 + if (!au_is_bad_inode(inode)
27670 + && au_ii(inode)->ii_btop >= 0) {
27671 + spin_lock(&inode->i_lock);
27672 + if (atomic_read(&inode->i_count)) {
27676 + AuDebugOn(n > max);
27678 + spin_unlock(&inode->i_lock);
27681 + spin_unlock(&sb->s_inode_list_lock);
27686 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27688 + *max = au_ninodes(sb);
27689 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
27692 +void au_iarray_free(struct inode **a, unsigned long long max)
27694 + unsigned long long ull;
27696 + for (ull = 0; ull < max; ull++)
27701 +/* ---------------------------------------------------------------------- */
27704 + * refresh dentry and inode at remount time.
27706 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27707 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27708 + struct dentry *parent)
27712 + di_write_lock_child(dentry);
27713 + di_read_lock_parent(parent, AuLock_IR);
27714 + err = au_refresh_dentry(dentry, parent);
27715 + if (!err && dir_flags)
27716 + au_hn_reset(d_inode(dentry), dir_flags);
27717 + di_read_unlock(parent, AuLock_IR);
27718 + di_write_unlock(dentry);
27723 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27724 + struct au_sbinfo *sbinfo,
27725 + const unsigned int dir_flags, unsigned int do_idop)
27728 + struct dentry *parent;
27731 + parent = dget_parent(dentry);
27732 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27733 + if (d_really_is_positive(dentry)) {
27734 + if (!d_is_dir(dentry))
27735 + err = au_do_refresh(dentry, /*dir_flags*/0,
27738 + err = au_do_refresh(dentry, dir_flags, parent);
27739 + if (unlikely(err))
27740 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27743 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27744 + AuDbgDentry(dentry);
27750 + au_refresh_dop(dentry, /*force_reval*/0);
27752 + au_refresh_dop(dentry, /*force_reval*/1);
27758 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
27760 + int err, i, j, ndentry, e;
27761 + unsigned int sigen;
27762 + struct au_dcsub_pages dpages;
27763 + struct au_dpage *dpage;
27764 + struct dentry **dentries, *d;
27765 + struct au_sbinfo *sbinfo;
27766 + struct dentry *root = sb->s_root;
27767 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
27770 + au_refresh_dop(root, /*force_reval*/0);
27772 + err = au_dpages_init(&dpages, GFP_NOFS);
27773 + if (unlikely(err))
27775 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27776 + if (unlikely(err))
27779 + sigen = au_sigen(sb);
27780 + sbinfo = au_sbi(sb);
27781 + for (i = 0; i < dpages.ndpage; i++) {
27782 + dpage = dpages.dpages + i;
27783 + dentries = dpage->dentries;
27784 + ndentry = dpage->ndentry;
27785 + for (j = 0; j < ndentry; j++) {
27787 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
27789 + if (unlikely(e && !err))
27791 + /* go on even err */
27796 + au_dpages_free(&dpages);
27801 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
27804 + unsigned int sigen;
27805 + unsigned long long max, ull;
27806 + struct inode *inode, **array;
27808 + array = au_iarray_alloc(sb, &max);
27809 + err = PTR_ERR(array);
27810 + if (IS_ERR(array))
27814 + sigen = au_sigen(sb);
27815 + for (ull = 0; ull < max; ull++) {
27816 + inode = array[ull];
27817 + if (unlikely(!inode))
27821 + ii_write_lock_child(inode);
27822 + if (au_iigen(inode, NULL) != sigen) {
27823 + e = au_refresh_hinode_self(inode);
27824 + if (unlikely(e)) {
27825 + au_refresh_iop(inode, /*force_getattr*/1);
27826 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27829 + /* go on even if err */
27832 + if (!e && do_idop)
27833 + au_refresh_iop(inode, /*force_getattr*/0);
27834 + ii_write_unlock(inode);
27837 + au_iarray_free(array, max);
27843 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
27846 + unsigned int udba;
27847 + aufs_bindex_t bindex, bbot;
27848 + struct dentry *root;
27849 + struct inode *inode;
27850 + struct au_branch *br;
27851 + struct au_sbinfo *sbi;
27853 + au_sigen_inc(sb);
27854 + sbi = au_sbi(sb);
27855 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
27857 + root = sb->s_root;
27858 + DiMustNoWaiters(root);
27859 + inode = d_inode(root);
27860 + IiMustNoWaiters(inode);
27862 + udba = au_opt_udba(sb);
27863 + bbot = au_sbbot(sb);
27864 + for (bindex = 0; bindex <= bbot; bindex++) {
27865 + br = au_sbr(sb, bindex);
27866 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27867 + if (unlikely(err))
27868 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27870 + /* go on even if err */
27872 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27875 + if (au_ftest_si(sbi, NO_DREVAL)) {
27876 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
27877 + sb->s_d_op = &aufs_dop_noreval;
27878 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
27879 + sbi->si_iop_array = aufs_iop_nogetattr;
27881 + AuDebugOn(sb->s_d_op == &aufs_dop);
27882 + sb->s_d_op = &aufs_dop;
27883 + AuDebugOn(sbi->si_iop_array == aufs_iop);
27884 + sbi->si_iop_array = aufs_iop;
27886 + pr_info("reset to %pf and %pf\n",
27887 + sb->s_d_op, sbi->si_iop_array);
27890 + di_write_unlock(root);
27891 + err = au_refresh_d(sb, do_idop);
27892 + e = au_refresh_i(sb, do_idop);
27893 + if (unlikely(e && !err))
27895 + /* aufs_write_lock() calls ..._child() */
27896 + di_write_lock_child(root);
27898 + au_cpup_attr_all(inode, /*force*/1);
27900 + if (unlikely(err))
27901 + AuIOErr("refresh failed, ignored, %d\n", err);
27904 +/* stop extra interpretation of errno in mount(8), and strange error messages */
27905 +static int cvt_err(int err)
27919 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
27922 + unsigned int mntflags;
27923 + struct au_opts opts = {
27926 + struct dentry *root;
27927 + struct inode *inode;
27928 + struct au_sbinfo *sbinfo;
27931 + root = sb->s_root;
27932 + if (!data || !*data) {
27933 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27935 + di_write_lock_child(root);
27936 + err = au_opts_verify(sb, *flags, /*pending*/0);
27937 + aufs_write_unlock(root);
27943 + opts.opt = (void *)__get_free_page(GFP_NOFS);
27944 + if (unlikely(!opts.opt))
27946 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
27947 + opts.flags = AuOpts_REMOUNT;
27948 + opts.sb_flags = *flags;
27950 + /* parse it before aufs lock */
27951 + err = au_opts_parse(sb, data, &opts);
27952 + if (unlikely(err))
27955 + sbinfo = au_sbi(sb);
27956 + inode = d_inode(root);
27957 + inode_lock(inode);
27958 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
27959 + if (unlikely(err))
27961 + di_write_lock_child(root);
27963 + /* au_opts_remount() may return an error */
27964 + err = au_opts_remount(sb, &opts);
27965 + au_opts_free(&opts);
27967 + if (au_ftest_opts(opts.flags, REFRESH))
27968 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
27970 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
27971 + mntflags = au_mntflags(sb);
27972 + do_dx = !!au_opt_test(mntflags, DIO);
27973 + au_dy_arefresh(do_dx);
27976 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
27977 + aufs_write_unlock(root);
27980 + inode_unlock(inode);
27982 + au_delayed_free_page((unsigned long)opts.opt);
27984 + err = cvt_err(err);
27989 +static const struct super_operations aufs_sop = {
27990 + .alloc_inode = aufs_alloc_inode,
27991 + .destroy_inode = aufs_destroy_inode,
27992 + /* always deleting, no clearing */
27993 + .drop_inode = generic_delete_inode,
27994 + .show_options = aufs_show_options,
27995 + .statfs = aufs_statfs,
27996 + .put_super = aufs_put_super,
27997 + .sync_fs = aufs_sync_fs,
27998 + .remount_fs = aufs_remount_fs
28001 +/* ---------------------------------------------------------------------- */
28003 +static int alloc_root(struct super_block *sb)
28006 + struct inode *inode;
28007 + struct dentry *root;
28010 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
28011 + err = PTR_ERR(inode);
28012 + if (IS_ERR(inode))
28015 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
28016 + inode->i_fop = &aufs_dir_fop;
28017 + inode->i_mode = S_IFDIR;
28018 + set_nlink(inode, 2);
28019 + unlock_new_inode(inode);
28021 + root = d_make_root(inode);
28022 + if (unlikely(!root))
28024 + err = PTR_ERR(root);
28025 + if (IS_ERR(root))
28028 + err = au_di_init(root);
28030 + sb->s_root = root;
28031 + return 0; /* success */
28039 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
28040 + int silent __maybe_unused)
28043 + struct au_opts opts = {
28046 + struct au_sbinfo *sbinfo;
28047 + struct dentry *root;
28048 + struct inode *inode;
28049 + char *arg = raw_data;
28051 + if (unlikely(!arg || !*arg)) {
28053 + pr_err("no arg\n");
28058 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28059 + if (unlikely(!opts.opt))
28061 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28062 + opts.sb_flags = sb->s_flags;
28064 + err = au_si_alloc(sb);
28065 + if (unlikely(err))
28067 + sbinfo = au_sbi(sb);
28069 + /* all timestamps always follow the ones on the branch */
28070 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
28071 + sb->s_op = &aufs_sop;
28072 + sb->s_d_op = &aufs_dop;
28073 + sb->s_magic = AUFS_SUPER_MAGIC;
28074 + sb->s_maxbytes = 0;
28075 + sb->s_stack_depth = 1;
28076 + au_export_init(sb);
28077 + /* au_xattr_init(sb); */
28079 + err = alloc_root(sb);
28080 + if (unlikely(err)) {
28081 + si_write_unlock(sb);
28084 + root = sb->s_root;
28085 + inode = d_inode(root);
28088 + * actually we can parse options regardless aufs lock here.
28089 + * but at remount time, parsing must be done before aufs lock.
28090 + * so we follow the same rule.
28092 + ii_write_lock_parent(inode);
28093 + aufs_write_unlock(root);
28094 + err = au_opts_parse(sb, arg, &opts);
28095 + if (unlikely(err))
28098 + /* lock vfs_inode first, then aufs. */
28099 + inode_lock(inode);
28100 + aufs_write_lock(root);
28101 + err = au_opts_mount(sb, &opts);
28102 + au_opts_free(&opts);
28103 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
28104 + sb->s_d_op = &aufs_dop_noreval;
28105 + pr_info("%pf\n", sb->s_d_op);
28106 + au_refresh_dop(root, /*force_reval*/0);
28107 + sbinfo->si_iop_array = aufs_iop_nogetattr;
28108 + au_refresh_iop(inode, /*force_getattr*/0);
28110 + aufs_write_unlock(root);
28111 + inode_unlock(inode);
28113 + goto out_opts; /* success */
28117 + sb->s_root = NULL;
28119 + dbgaufs_si_fin(sbinfo);
28120 + kobject_put(&sbinfo->si_kobj);
28121 + sb->s_fs_info = NULL;
28123 + au_delayed_free_page((unsigned long)opts.opt);
28126 + err = cvt_err(err);
28131 +/* ---------------------------------------------------------------------- */
28133 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
28134 + const char *dev_name __maybe_unused,
28137 + struct dentry *root;
28138 + struct super_block *sb;
28140 + /* all timestamps always follow the ones on the branch */
28141 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
28142 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
28143 + if (IS_ERR(root))
28147 + si_write_lock(sb, !AuLock_FLUSH);
28148 + sysaufs_brs_add(sb, 0);
28149 + si_write_unlock(sb);
28150 + au_sbilist_add(sb);
28156 +static void aufs_kill_sb(struct super_block *sb)
28158 + struct au_sbinfo *sbinfo;
28160 + sbinfo = au_sbi(sb);
28162 + au_sbilist_del(sb);
28163 + aufs_write_lock(sb->s_root);
28165 + if (sbinfo->si_wbr_create_ops->fin)
28166 + sbinfo->si_wbr_create_ops->fin(sb);
28167 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
28168 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
28169 + au_remount_refresh(sb, /*do_idop*/0);
28171 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
28172 + au_plink_put(sb, /*verbose*/1);
28174 + sbinfo->si_sb = NULL;
28175 + aufs_write_unlock(sb->s_root);
28176 + au_nwt_flush(&sbinfo->si_nowait);
28178 + kill_anon_super(sb);
28181 +struct file_system_type aufs_fs_type = {
28182 + .name = AUFS_FSTYPE,
28183 + /* a race between rename and others */
28184 + .fs_flags = FS_RENAME_DOES_D_MOVE,
28185 + .mount = aufs_mount,
28186 + .kill_sb = aufs_kill_sb,
28187 + /* no need to __module_get() and module_put(). */
28188 + .owner = THIS_MODULE,
28190 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
28191 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
28192 +++ linux/fs/aufs/super.h 2016-10-09 16:55:38.889431135 +0200
28195 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28197 + * This program, aufs is free software; you can redistribute it and/or modify
28198 + * it under the terms of the GNU General Public License as published by
28199 + * the Free Software Foundation; either version 2 of the License, or
28200 + * (at your option) any later version.
28202 + * This program is distributed in the hope that it will be useful,
28203 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28204 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28205 + * GNU General Public License for more details.
28207 + * You should have received a copy of the GNU General Public License
28208 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28212 + * super_block operations
28215 +#ifndef __AUFS_SUPER_H__
28216 +#define __AUFS_SUPER_H__
28220 +#include <linux/fs.h>
28221 +#include <linux/kobject.h>
28222 +#include "rwsem.h"
28226 +/* policies to select one among multiple writable branches */
28227 +struct au_wbr_copyup_operations {
28228 + int (*copyup)(struct dentry *dentry);
28231 +#define AuWbr_DIR 1 /* target is a dir */
28232 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
28234 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
28235 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
28236 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
28238 +struct au_wbr_create_operations {
28239 + int (*create)(struct dentry *dentry, unsigned int flags);
28240 + int (*init)(struct super_block *sb);
28241 + int (*fin)(struct super_block *sb);
28244 +struct au_wbr_mfs {
28245 + struct mutex mfs_lock; /* protect this structure */
28246 + unsigned long mfs_jiffy;
28247 + unsigned long mfs_expire;
28248 + aufs_bindex_t mfs_bindex;
28250 + unsigned long long mfsrr_bytes;
28251 + unsigned long long mfsrr_watermark;
28254 +#define AuPlink_NHASH 100
28255 +static inline int au_plink_hash(ino_t ino)
28257 + return ino % AuPlink_NHASH;
28260 +/* File-based Hierarchical Storage Management */
28262 +#ifdef CONFIG_AUFS_FHSM
28263 + /* allow only one process who can receive the notification */
28264 + spinlock_t fhsm_spin;
28266 + wait_queue_head_t fhsm_wqh;
28267 + atomic_t fhsm_readable;
28269 + /* these are protected by si_rwsem */
28270 + unsigned long fhsm_expire;
28271 + aufs_bindex_t fhsm_bottom;
28275 +#define AU_PIDSTEP (int)(BITS_TO_LONGS(PID_MAX_DEFAULT) * BITS_PER_LONG)
28276 +#define AU_NPIDMAP (int)DIV_ROUND_UP(PID_MAX_LIMIT, AU_PIDSTEP)
28277 +struct au_si_pid {
28278 + unsigned long *pid_bitmap[AU_NPIDMAP];
28279 + struct mutex pid_mtx;
28283 +struct au_sbinfo {
28284 + /* nowait tasks in the system-wide workqueue */
28285 + struct au_nowait_tasks si_nowait;
28288 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
28289 + * rwsem for au_sbinfo is necessary.
28291 + struct au_rwsem si_rwsem;
28293 + /* prevent recursive locking in deleting inode */
28294 + struct au_si_pid au_si_pid;
28297 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
28300 + struct percpu_counter si_ninodes, si_nfiles;
28302 + /* branch management */
28303 + unsigned int si_generation;
28305 + /* see AuSi_ flags */
28306 + unsigned char au_si_status;
28308 + aufs_bindex_t si_bbot;
28310 + /* dirty trick to keep br_id plus */
28311 + unsigned int si_last_br_id :
28312 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
28313 + struct au_branch **si_branch;
28315 + /* policy to select a writable branch */
28316 + unsigned char si_wbr_copyup;
28317 + unsigned char si_wbr_create;
28318 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
28319 + struct au_wbr_create_operations *si_wbr_create_ops;
28321 + /* round robin */
28322 + atomic_t si_wbr_rr_next;
28324 + /* most free space */
28325 + struct au_wbr_mfs si_wbr_mfs;
28327 + /* File-based Hierarchical Storage Management */
28328 + struct au_fhsm si_fhsm;
28330 + /* mount flags */
28331 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
28332 + unsigned int si_mntflags;
28334 + /* external inode number (bitmap and translation table) */
28335 + vfs_readf_t si_xread;
28336 + vfs_writef_t si_xwrite;
28337 + struct file *si_xib;
28338 + struct mutex si_xib_mtx; /* protect xib members */
28339 + unsigned long *si_xib_buf;
28340 + unsigned long si_xib_last_pindex;
28341 + int si_xib_next_bit;
28342 + aufs_bindex_t si_xino_brid;
28343 + unsigned long si_xino_jiffy;
28344 + unsigned long si_xino_expire;
28345 + /* reserved for future use */
28346 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
28348 +#ifdef CONFIG_AUFS_EXPORT
28349 + /* i_generation */
28350 + struct file *si_xigen;
28351 + atomic_t si_xigen_next;
28354 + /* dirty trick to suppoer atomic_open */
28355 + struct au_sphlhead si_aopen;
28357 + /* vdir parameters */
28358 + unsigned long si_rdcache; /* max cache time in jiffies */
28359 + unsigned int si_rdblk; /* deblk size */
28360 + unsigned int si_rdhash; /* hash size */
28363 + * If the number of whiteouts are larger than si_dirwh, leave all of
28364 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
28365 + * future fsck.aufs or kernel thread will remove them later.
28366 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
28368 + unsigned int si_dirwh;
28370 + /* pseudo_link list */
28371 + struct au_sphlhead si_plink[AuPlink_NHASH];
28372 + wait_queue_head_t si_plink_wq;
28373 + spinlock_t si_plink_maint_lock;
28374 + pid_t si_plink_maint_pid;
28377 + struct au_sphlhead si_files;
28379 + /* with/without getattr, brother of sb->s_d_op */
28380 + struct inode_operations *si_iop_array;
28383 + * sysfs and lifetime management.
28384 + * this is not a small structure and it may be a waste of memory in case
28385 + * of sysfs is disabled, particulary when many aufs-es are mounted.
28386 + * but using sysfs is majority.
28388 + struct kobject si_kobj;
28389 +#ifdef CONFIG_DEBUG_FS
28390 + struct dentry *si_dbgaufs;
28391 + struct dentry *si_dbgaufs_plink;
28392 + struct dentry *si_dbgaufs_xib;
28393 +#ifdef CONFIG_AUFS_EXPORT
28394 + struct dentry *si_dbgaufs_xigen;
28398 +#ifdef CONFIG_AUFS_SBILIST
28399 + struct hlist_node si_list;
28402 + /* dirty, necessary for unmounting, sysfs and sysrq */
28403 + struct super_block *si_sb;
28406 +/* sbinfo status flags */
28408 + * set true when refresh_dirs() failed at remount time.
28409 + * then try refreshing dirs at access time again.
28410 + * if it is false, refreshing dirs at access time is unnecesary
28412 +#define AuSi_FAILED_REFRESH_DIR 1
28413 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
28414 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
28416 +#ifndef CONFIG_AUFS_FHSM
28418 +#define AuSi_FHSM 0
28421 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
28422 + unsigned int flag)
28424 + AuRwMustAnyLock(&sbi->si_rwsem);
28425 + return sbi->au_si_status & flag;
28427 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
28428 +#define au_fset_si(sbinfo, name) do { \
28429 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28430 + (sbinfo)->au_si_status |= AuSi_##name; \
28432 +#define au_fclr_si(sbinfo, name) do { \
28433 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28434 + (sbinfo)->au_si_status &= ~AuSi_##name; \
28437 +/* ---------------------------------------------------------------------- */
28439 +/* policy to select one among writable branches */
28440 +#define AuWbrCopyup(sbinfo, ...) \
28441 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
28442 +#define AuWbrCreate(sbinfo, ...) \
28443 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
28445 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
28446 +#define AuLock_DW 1 /* write-lock dentry */
28447 +#define AuLock_IR (1 << 1) /* read-lock inode */
28448 +#define AuLock_IW (1 << 2) /* write-lock inode */
28449 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
28450 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
28451 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
28452 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
28453 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
28454 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
28455 +#define au_fset_lock(flags, name) \
28456 + do { (flags) |= AuLock_##name; } while (0)
28457 +#define au_fclr_lock(flags, name) \
28458 + do { (flags) &= ~AuLock_##name; } while (0)
28460 +/* ---------------------------------------------------------------------- */
28463 +extern struct file_system_type aufs_fs_type;
28464 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
28465 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
28466 + unsigned long long max, void *arg);
28467 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
28468 + struct super_block *sb, void *arg);
28469 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
28470 +void au_iarray_free(struct inode **a, unsigned long long max);
28473 +void au_si_free(struct kobject *kobj);
28474 +int au_si_alloc(struct super_block *sb);
28475 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
28477 +unsigned int au_sigen_inc(struct super_block *sb);
28478 +aufs_bindex_t au_new_br_id(struct super_block *sb);
28480 +int si_read_lock(struct super_block *sb, int flags);
28481 +int si_write_lock(struct super_block *sb, int flags);
28482 +int aufs_read_lock(struct dentry *dentry, int flags);
28483 +void aufs_read_unlock(struct dentry *dentry, int flags);
28484 +void aufs_write_lock(struct dentry *dentry);
28485 +void aufs_write_unlock(struct dentry *dentry);
28486 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
28487 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
28489 +/* wbr_policy.c */
28490 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
28491 +extern struct au_wbr_create_operations au_wbr_create_ops[];
28492 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
28493 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
28494 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
28497 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
28499 +#ifdef CONFIG_AUFS_FHSM
28502 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
28506 + spin_lock(&fhsm->fhsm_spin);
28507 + pid = fhsm->fhsm_pid;
28508 + spin_unlock(&fhsm->fhsm_spin);
28513 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
28514 +void au_fhsm_wrote_all(struct super_block *sb, int force);
28515 +int au_fhsm_fd(struct super_block *sb, int oflags);
28516 +int au_fhsm_br_alloc(struct au_branch *br);
28517 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
28518 +void au_fhsm_fin(struct super_block *sb);
28519 +void au_fhsm_init(struct au_sbinfo *sbinfo);
28520 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
28521 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
28523 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
28525 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
28526 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
28527 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
28528 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
28529 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
28530 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
28531 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
28532 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
28533 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
28536 +/* ---------------------------------------------------------------------- */
28538 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
28540 + return sb->s_fs_info;
28543 +/* ---------------------------------------------------------------------- */
28545 +#ifdef CONFIG_AUFS_EXPORT
28546 +int au_test_nfsd(void);
28547 +void au_export_init(struct super_block *sb);
28548 +void au_xigen_inc(struct inode *inode);
28549 +int au_xigen_new(struct inode *inode);
28550 +int au_xigen_set(struct super_block *sb, struct file *base);
28551 +void au_xigen_clr(struct super_block *sb);
28553 +static inline int au_busy_or_stale(void)
28555 + if (!au_test_nfsd())
28560 +AuStubInt0(au_test_nfsd, void)
28561 +AuStubVoid(au_export_init, struct super_block *sb)
28562 +AuStubVoid(au_xigen_inc, struct inode *inode)
28563 +AuStubInt0(au_xigen_new, struct inode *inode)
28564 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
28565 +AuStubVoid(au_xigen_clr, struct super_block *sb)
28566 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
28567 +#endif /* CONFIG_AUFS_EXPORT */
28569 +/* ---------------------------------------------------------------------- */
28571 +#ifdef CONFIG_AUFS_SBILIST
28573 +extern struct au_sphlhead au_sbilist;
28575 +static inline void au_sbilist_init(void)
28577 + au_sphl_init(&au_sbilist);
28580 +static inline void au_sbilist_add(struct super_block *sb)
28582 + au_sphl_add(&au_sbi(sb)->si_list, &au_sbilist);
28585 +static inline void au_sbilist_del(struct super_block *sb)
28587 + au_sphl_del(&au_sbi(sb)->si_list, &au_sbilist);
28590 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
28591 +static inline void au_sbilist_lock(void)
28593 + spin_lock(&au_sbilist.spin);
28596 +static inline void au_sbilist_unlock(void)
28598 + spin_unlock(&au_sbilist.spin);
28600 +#define AuGFP_SBILIST GFP_ATOMIC
28602 +AuStubVoid(au_sbilist_lock, void)
28603 +AuStubVoid(au_sbilist_unlock, void)
28604 +#define AuGFP_SBILIST GFP_NOFS
28605 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28607 +AuStubVoid(au_sbilist_init, void)
28608 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28609 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28610 +AuStubVoid(au_sbilist_lock, void)
28611 +AuStubVoid(au_sbilist_unlock, void)
28612 +#define AuGFP_SBILIST GFP_NOFS
28615 +/* ---------------------------------------------------------------------- */
28617 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28620 + * This function is a dynamic '__init' function actually,
28621 + * so the tiny check for si_rwsem is unnecessary.
28623 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28624 +#ifdef CONFIG_DEBUG_FS
28625 + sbinfo->si_dbgaufs = NULL;
28626 + sbinfo->si_dbgaufs_plink = NULL;
28627 + sbinfo->si_dbgaufs_xib = NULL;
28628 +#ifdef CONFIG_AUFS_EXPORT
28629 + sbinfo->si_dbgaufs_xigen = NULL;
28634 +/* ---------------------------------------------------------------------- */
28636 +static inline void si_pid_idx_bit(int *idx, pid_t *bit)
28638 + /* the origin of pid is 1, but the bitmap's is 0 */
28639 + *bit = current->pid - 1;
28640 + *idx = *bit / AU_PIDSTEP;
28641 + *bit %= AU_PIDSTEP;
28644 +static inline int si_pid_test(struct super_block *sb)
28648 + unsigned long *bitmap;
28650 + si_pid_idx_bit(&idx, &bit);
28651 + bitmap = au_sbi(sb)->au_si_pid.pid_bitmap[idx];
28653 + return test_bit(bit, bitmap);
28657 +static inline void si_pid_clr(struct super_block *sb)
28661 + unsigned long *bitmap;
28663 + si_pid_idx_bit(&idx, &bit);
28664 + bitmap = au_sbi(sb)->au_si_pid.pid_bitmap[idx];
28666 + AuDebugOn(!test_bit(bit, bitmap));
28667 + clear_bit(bit, bitmap);
28671 +void si_pid_set(struct super_block *sb);
28673 +/* ---------------------------------------------------------------------- */
28675 +/* lock superblock. mainly for entry point functions */
28677 + * __si_read_lock, __si_write_lock,
28678 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28680 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28682 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28683 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28684 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28686 +static inline void si_noflush_read_lock(struct super_block *sb)
28688 + __si_read_lock(sb);
28692 +static inline int si_noflush_read_trylock(struct super_block *sb)
28696 + locked = __si_read_trylock(sb);
28702 +static inline void si_noflush_write_lock(struct super_block *sb)
28704 + __si_write_lock(sb);
28708 +static inline int si_noflush_write_trylock(struct super_block *sb)
28712 + locked = __si_write_trylock(sb);
28718 +#if 0 /* reserved */
28719 +static inline int si_read_trylock(struct super_block *sb, int flags)
28721 + if (au_ftest_lock(flags, FLUSH))
28722 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28723 + return si_noflush_read_trylock(sb);
28727 +static inline void si_read_unlock(struct super_block *sb)
28730 + __si_read_unlock(sb);
28733 +#if 0 /* reserved */
28734 +static inline int si_write_trylock(struct super_block *sb, int flags)
28736 + if (au_ftest_lock(flags, FLUSH))
28737 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28738 + return si_noflush_write_trylock(sb);
28742 +static inline void si_write_unlock(struct super_block *sb)
28745 + __si_write_unlock(sb);
28748 +#if 0 /* reserved */
28749 +static inline void si_downgrade_lock(struct super_block *sb)
28751 + __si_downgrade_lock(sb);
28755 +/* ---------------------------------------------------------------------- */
28757 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
28759 + SiMustAnyLock(sb);
28760 + return au_sbi(sb)->si_bbot;
28763 +static inline unsigned int au_mntflags(struct super_block *sb)
28765 + SiMustAnyLock(sb);
28766 + return au_sbi(sb)->si_mntflags;
28769 +static inline unsigned int au_sigen(struct super_block *sb)
28771 + SiMustAnyLock(sb);
28772 + return au_sbi(sb)->si_generation;
28775 +static inline unsigned long long au_ninodes(struct super_block *sb)
28777 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
28783 +static inline void au_ninodes_inc(struct super_block *sb)
28785 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
28788 +static inline void au_ninodes_dec(struct super_block *sb)
28790 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
28793 +static inline unsigned long long au_nfiles(struct super_block *sb)
28795 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
28801 +static inline void au_nfiles_inc(struct super_block *sb)
28803 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
28806 +static inline void au_nfiles_dec(struct super_block *sb)
28808 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
28811 +static inline struct au_branch *au_sbr(struct super_block *sb,
28812 + aufs_bindex_t bindex)
28814 + SiMustAnyLock(sb);
28815 + return au_sbi(sb)->si_branch[0 + bindex];
28818 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28820 + SiMustWriteLock(sb);
28821 + au_sbi(sb)->si_xino_brid = brid;
28824 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28826 + SiMustAnyLock(sb);
28827 + return au_sbi(sb)->si_xino_brid;
28830 +#endif /* __KERNEL__ */
28831 +#endif /* __AUFS_SUPER_H__ */
28832 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28833 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28834 +++ linux/fs/aufs/sysaufs.c 2016-10-09 16:55:36.496035060 +0200
28837 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28839 + * This program, aufs is free software; you can redistribute it and/or modify
28840 + * it under the terms of the GNU General Public License as published by
28841 + * the Free Software Foundation; either version 2 of the License, or
28842 + * (at your option) any later version.
28844 + * This program is distributed in the hope that it will be useful,
28845 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28846 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28847 + * GNU General Public License for more details.
28849 + * You should have received a copy of the GNU General Public License
28850 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28854 + * sysfs interface and lifetime management
28855 + * they are necessary regardless sysfs is disabled.
28858 +#include <linux/random.h>
28861 +unsigned long sysaufs_si_mask;
28862 +struct kset *sysaufs_kset;
28864 +#define AuSiAttr(_name) { \
28865 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28866 + .show = sysaufs_si_##_name, \
28869 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28870 +struct attribute *sysaufs_si_attrs[] = {
28871 + &sysaufs_si_attr_xi_path.attr,
28875 +static const struct sysfs_ops au_sbi_ops = {
28876 + .show = sysaufs_si_show
28879 +static struct kobj_type au_sbi_ktype = {
28880 + .release = au_si_free,
28881 + .sysfs_ops = &au_sbi_ops,
28882 + .default_attrs = sysaufs_si_attrs
28885 +/* ---------------------------------------------------------------------- */
28887 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
28891 + sbinfo->si_kobj.kset = sysaufs_kset;
28892 + /* cf. sysaufs_name() */
28893 + err = kobject_init_and_add
28894 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
28895 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
28897 + dbgaufs_si_null(sbinfo);
28899 + err = dbgaufs_si_init(sbinfo);
28900 + if (unlikely(err))
28901 + kobject_put(&sbinfo->si_kobj);
28906 +void sysaufs_fin(void)
28909 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28910 + kset_unregister(sysaufs_kset);
28913 +int __init sysaufs_init(void)
28918 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
28919 + } while (!sysaufs_si_mask);
28922 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
28923 + if (unlikely(!sysaufs_kset))
28925 + err = PTR_ERR(sysaufs_kset);
28926 + if (IS_ERR(sysaufs_kset))
28928 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
28929 + if (unlikely(err)) {
28930 + kset_unregister(sysaufs_kset);
28934 + err = dbgaufs_init();
28935 + if (unlikely(err))
28940 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
28941 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
28942 +++ linux/fs/aufs/sysaufs.h 2016-10-09 16:55:36.496035060 +0200
28945 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28947 + * This program, aufs is free software; you can redistribute it and/or modify
28948 + * it under the terms of the GNU General Public License as published by
28949 + * the Free Software Foundation; either version 2 of the License, or
28950 + * (at your option) any later version.
28952 + * This program is distributed in the hope that it will be useful,
28953 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28954 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28955 + * GNU General Public License for more details.
28957 + * You should have received a copy of the GNU General Public License
28958 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28962 + * sysfs interface and mount lifetime management
28965 +#ifndef __SYSAUFS_H__
28966 +#define __SYSAUFS_H__
28970 +#include <linux/sysfs.h>
28971 +#include "module.h"
28973 +struct super_block;
28976 +struct sysaufs_si_attr {
28977 + struct attribute attr;
28978 + int (*show)(struct seq_file *seq, struct super_block *sb);
28981 +/* ---------------------------------------------------------------------- */
28984 +extern unsigned long sysaufs_si_mask;
28985 +extern struct kset *sysaufs_kset;
28986 +extern struct attribute *sysaufs_si_attrs[];
28987 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
28988 +int __init sysaufs_init(void);
28989 +void sysaufs_fin(void);
28991 +/* ---------------------------------------------------------------------- */
28993 +/* some people doesn't like to show a pointer in kernel */
28994 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
28996 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
28999 +#define SysaufsSiNamePrefix "si_"
29000 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
29001 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
29003 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
29004 + sysaufs_si_id(sbinfo));
29008 +#ifdef CONFIG_SYSFS
29010 +extern struct attribute_group *sysaufs_attr_group;
29012 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
29013 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29015 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
29016 +#ifdef CONFIG_COMPAT
29017 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
29020 +void sysaufs_br_init(struct au_branch *br);
29021 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
29022 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
29024 +#define sysaufs_brs_init() do {} while (0)
29027 +#define sysaufs_attr_group NULL
29029 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
29030 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
29031 + struct attribute *attr, char *buf)
29032 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
29033 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
29034 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
29036 +static inline void sysaufs_brs_init(void)
29041 +#endif /* CONFIG_SYSFS */
29043 +#endif /* __KERNEL__ */
29044 +#endif /* __SYSAUFS_H__ */
29045 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
29046 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
29047 +++ linux/fs/aufs/sysfs.c 2016-10-09 16:55:36.496035060 +0200
29050 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29052 + * This program, aufs is free software; you can redistribute it and/or modify
29053 + * it under the terms of the GNU General Public License as published by
29054 + * the Free Software Foundation; either version 2 of the License, or
29055 + * (at your option) any later version.
29057 + * This program is distributed in the hope that it will be useful,
29058 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29059 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29060 + * GNU General Public License for more details.
29062 + * You should have received a copy of the GNU General Public License
29063 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29067 + * sysfs interface
29070 +#include <linux/compat.h>
29071 +#include <linux/seq_file.h>
29074 +#ifdef CONFIG_AUFS_FS_MODULE
29075 +/* this entry violates the "one line per file" policy of sysfs */
29076 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
29080 + static char *conf =
29081 +/* this file is generated at compiling */
29082 +#include "conf.str"
29085 + err = snprintf(buf, PAGE_SIZE, conf);
29086 + if (unlikely(err >= PAGE_SIZE))
29091 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
29094 +static struct attribute *au_attr[] = {
29095 +#ifdef CONFIG_AUFS_FS_MODULE
29096 + &au_config_attr.attr,
29098 + NULL, /* need to NULL terminate the list of attributes */
29101 +static struct attribute_group sysaufs_attr_group_body = {
29105 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
29107 +/* ---------------------------------------------------------------------- */
29109 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
29113 + SiMustAnyLock(sb);
29116 + if (au_opt_test(au_mntflags(sb), XINO)) {
29117 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
29118 + seq_putc(seq, '\n');
29124 + * the lifetime of branch is independent from the entry under sysfs.
29125 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
29128 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
29129 + aufs_bindex_t bindex, int idx)
29132 + struct path path;
29133 + struct dentry *root;
29134 + struct au_branch *br;
29135 + au_br_perm_str_t perm;
29137 + AuDbg("b%d\n", bindex);
29140 + root = sb->s_root;
29141 + di_read_lock_parent(root, !AuLock_IR);
29142 + br = au_sbr(sb, bindex);
29145 + case AuBrSysfs_BR:
29146 + path.mnt = au_br_mnt(br);
29147 + path.dentry = au_h_dptr(root, bindex);
29148 + err = au_seq_path(seq, &path);
29150 + au_optstr_br_perm(&perm, br->br_perm);
29151 + seq_printf(seq, "=%s\n", perm.a);
29154 + case AuBrSysfs_BRID:
29155 + seq_printf(seq, "%d\n", br->br_id);
29158 + di_read_unlock(root, !AuLock_IR);
29159 + if (unlikely(err || seq_has_overflowed(seq)))
29165 +/* ---------------------------------------------------------------------- */
29167 +static struct seq_file *au_seq(char *p, ssize_t len)
29169 + struct seq_file *seq;
29171 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
29173 + /* mutex_init(&seq.lock); */
29176 + return seq; /* success */
29179 + seq = ERR_PTR(-ENOMEM);
29183 +#define SysaufsBr_PREFIX "br"
29184 +#define SysaufsBrid_PREFIX "brid"
29186 +/* todo: file size may exceed PAGE_SIZE */
29187 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29193 + aufs_bindex_t bbot;
29194 + struct au_sbinfo *sbinfo;
29195 + struct super_block *sb;
29196 + struct seq_file *seq;
29198 + struct attribute **cattr;
29200 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29201 + sb = sbinfo->si_sb;
29204 + * prevent a race condition between sysfs and aufs.
29205 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
29206 + * prohibits maintaining the sysfs entries.
29207 + * hew we acquire read lock after sysfs_get_active_two().
29208 + * on the other hand, the remount process may maintain the sysfs/aufs
29209 + * entries after acquiring write lock.
29210 + * it can cause a deadlock.
29211 + * simply we gave up processing read here.
29214 + if (unlikely(!si_noflush_read_trylock(sb)))
29217 + seq = au_seq(buf, PAGE_SIZE);
29218 + err = PTR_ERR(seq);
29222 + name = (void *)attr->name;
29223 + cattr = sysaufs_si_attrs;
29225 + if (!strcmp(name, (*cattr)->name)) {
29226 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
29233 + if (!strncmp(name, SysaufsBrid_PREFIX,
29234 + sizeof(SysaufsBrid_PREFIX) - 1)) {
29235 + idx = AuBrSysfs_BRID;
29236 + name += sizeof(SysaufsBrid_PREFIX) - 1;
29237 + } else if (!strncmp(name, SysaufsBr_PREFIX,
29238 + sizeof(SysaufsBr_PREFIX) - 1)) {
29239 + idx = AuBrSysfs_BR;
29240 + name += sizeof(SysaufsBr_PREFIX) - 1;
29244 + err = kstrtol(name, 10, &l);
29246 + bbot = au_sbbot(sb);
29248 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
29255 + err = seq->count;
29256 + /* sysfs limit */
29257 + if (unlikely(err == PAGE_SIZE))
29260 + au_delayed_kfree(seq);
29262 + si_read_unlock(sb);
29267 +/* ---------------------------------------------------------------------- */
29269 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
29273 + aufs_bindex_t bindex, bbot;
29276 + struct seq_file *seq;
29277 + struct au_branch *br;
29279 + si_read_lock(sb, AuLock_FLUSH);
29280 + bbot = au_sbbot(sb);
29286 + buf = (void *)__get_free_page(GFP_NOFS);
29287 + if (unlikely(!buf))
29290 + seq = au_seq(buf, PAGE_SIZE);
29291 + err = PTR_ERR(seq);
29295 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
29296 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
29297 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
29298 + if (unlikely(err))
29301 + br = au_sbr(sb, bindex);
29302 + brid = br->br_id;
29303 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
29304 + err = __put_user(brid, &arg->id);
29305 + if (unlikely(err))
29308 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
29309 + err = __put_user(br->br_perm, &arg->perm);
29310 + if (unlikely(err))
29313 + err = au_seq_path(seq, &br->br_path);
29314 + if (unlikely(err))
29316 + seq_putc(seq, '\0');
29317 + if (!seq_has_overflowed(seq)) {
29318 + err = copy_to_user(arg->path, seq->buf, seq->count);
29320 + if (unlikely(err))
29327 + if (unlikely(err))
29331 + au_delayed_kfree(seq);
29333 + au_delayed_free_page((unsigned long)buf);
29335 + si_read_unlock(sb);
29339 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
29341 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
29344 +#ifdef CONFIG_COMPAT
29345 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
29347 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
29351 +/* ---------------------------------------------------------------------- */
29353 +void sysaufs_br_init(struct au_branch *br)
29356 + struct au_brsysfs *br_sysfs;
29357 + struct attribute *attr;
29359 + br_sysfs = br->br_sysfs;
29360 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29361 + attr = &br_sysfs->attr;
29362 + sysfs_attr_init(attr);
29363 + attr->name = br_sysfs->name;
29364 + attr->mode = S_IRUGO;
29369 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
29371 + struct au_branch *br;
29372 + struct kobject *kobj;
29373 + struct au_brsysfs *br_sysfs;
29375 + aufs_bindex_t bbot;
29377 + dbgaufs_brs_del(sb, bindex);
29379 + if (!sysaufs_brs)
29382 + kobj = &au_sbi(sb)->si_kobj;
29383 + bbot = au_sbbot(sb);
29384 + for (; bindex <= bbot; bindex++) {
29385 + br = au_sbr(sb, bindex);
29386 + br_sysfs = br->br_sysfs;
29387 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29388 + sysfs_remove_file(kobj, &br_sysfs->attr);
29394 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
29397 + aufs_bindex_t bbot;
29398 + struct kobject *kobj;
29399 + struct au_branch *br;
29400 + struct au_brsysfs *br_sysfs;
29402 + dbgaufs_brs_add(sb, bindex);
29404 + if (!sysaufs_brs)
29407 + kobj = &au_sbi(sb)->si_kobj;
29408 + bbot = au_sbbot(sb);
29409 + for (; bindex <= bbot; bindex++) {
29410 + br = au_sbr(sb, bindex);
29411 + br_sysfs = br->br_sysfs;
29412 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
29413 + SysaufsBr_PREFIX "%d", bindex);
29414 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
29415 + SysaufsBrid_PREFIX "%d", bindex);
29416 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29417 + err = sysfs_create_file(kobj, &br_sysfs->attr);
29418 + if (unlikely(err))
29419 + pr_warn("failed %s under sysfs(%d)\n",
29420 + br_sysfs->name, err);
29425 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
29426 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
29427 +++ linux/fs/aufs/sysrq.c 2016-10-09 16:55:36.496035060 +0200
29430 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29432 + * This program, aufs is free software; you can redistribute it and/or modify
29433 + * it under the terms of the GNU General Public License as published by
29434 + * the Free Software Foundation; either version 2 of the License, or
29435 + * (at your option) any later version.
29437 + * This program is distributed in the hope that it will be useful,
29438 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29439 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29440 + * GNU General Public License for more details.
29442 + * You should have received a copy of the GNU General Public License
29443 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29447 + * magic sysrq hanlder
29450 +/* #include <linux/sysrq.h> */
29451 +#include <linux/writeback.h>
29454 +/* ---------------------------------------------------------------------- */
29456 +static void sysrq_sb(struct super_block *sb)
29459 + struct au_sbinfo *sbinfo;
29460 + struct file *file;
29461 + struct au_sphlhead *files;
29462 + struct au_finfo *finfo;
29464 + plevel = au_plevel;
29465 + au_plevel = KERN_WARNING;
29467 + /* since we define pr_fmt, call printk directly */
29468 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
29470 + sbinfo = au_sbi(sb);
29471 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
29472 + pr("superblock\n");
29476 + pr("root dentry\n");
29477 + au_dpri_dentry(sb->s_root);
29478 + pr("root inode\n");
29479 + au_dpri_inode(d_inode(sb->s_root));
29484 + int err, i, j, ndentry;
29485 + struct au_dcsub_pages dpages;
29486 + struct au_dpage *dpage;
29488 + err = au_dpages_init(&dpages, GFP_ATOMIC);
29489 + if (unlikely(err))
29491 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
29493 + for (i = 0; i < dpages.ndpage; i++) {
29494 + dpage = dpages.dpages + i;
29495 + ndentry = dpage->ndentry;
29496 + for (j = 0; j < ndentry; j++)
29497 + au_dpri_dentry(dpage->dentries[j]);
29499 + au_dpages_free(&dpages);
29507 + pr("isolated inode\n");
29508 + spin_lock(&sb->s_inode_list_lock);
29509 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
29510 + spin_lock(&i->i_lock);
29511 + if (1 || hlist_empty(&i->i_dentry))
29512 + au_dpri_inode(i);
29513 + spin_unlock(&i->i_lock);
29515 + spin_unlock(&sb->s_inode_list_lock);
29519 + files = &au_sbi(sb)->si_files;
29520 + spin_lock(&files->spin);
29521 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
29524 + file = finfo->fi_file;
29525 + mode = file_inode(file)->i_mode;
29526 + if (!special_file(mode))
29527 + au_dpri_file(file);
29529 + spin_unlock(&files->spin);
29533 + au_plevel = plevel;
29536 +/* ---------------------------------------------------------------------- */
29538 +/* module parameter */
29539 +static char *aufs_sysrq_key = "a";
29540 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
29541 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
29543 +static void au_sysrq(int key __maybe_unused)
29545 + struct au_sbinfo *sbinfo;
29548 + au_sbilist_lock();
29549 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
29550 + sysrq_sb(sbinfo->si_sb);
29551 + au_sbilist_unlock();
29555 +static struct sysrq_key_op au_sysrq_op = {
29556 + .handler = au_sysrq,
29557 + .help_msg = "Aufs",
29558 + .action_msg = "Aufs",
29559 + .enable_mask = SYSRQ_ENABLE_DUMP
29562 +/* ---------------------------------------------------------------------- */
29564 +int __init au_sysrq_init(void)
29570 + key = *aufs_sysrq_key;
29571 + if ('a' <= key && key <= 'z')
29572 + err = register_sysrq_key(key, &au_sysrq_op);
29573 + if (unlikely(err))
29574 + pr_err("err %d, sysrq=%c\n", err, key);
29578 +void au_sysrq_fin(void)
29582 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
29583 + if (unlikely(err))
29584 + pr_err("err %d (ignored)\n", err);
29586 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
29587 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
29588 +++ linux/fs/aufs/vdir.c 2016-10-09 16:55:38.889431135 +0200
29591 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29593 + * This program, aufs is free software; you can redistribute it and/or modify
29594 + * it under the terms of the GNU General Public License as published by
29595 + * the Free Software Foundation; either version 2 of the License, or
29596 + * (at your option) any later version.
29598 + * This program is distributed in the hope that it will be useful,
29599 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29600 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29601 + * GNU General Public License for more details.
29603 + * You should have received a copy of the GNU General Public License
29604 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29608 + * virtual or vertical directory
29613 +static unsigned int calc_size(int nlen)
29615 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29618 +static int set_deblk_end(union au_vdir_deblk_p *p,
29619 + union au_vdir_deblk_p *deblk_end)
29621 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29622 + p->de->de_str.len = 0;
29626 + return -1; /* error */
29629 +/* returns true or false */
29630 +static int is_deblk_end(union au_vdir_deblk_p *p,
29631 + union au_vdir_deblk_p *deblk_end)
29633 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29634 + return !p->de->de_str.len;
29638 +static unsigned char *last_deblk(struct au_vdir *vdir)
29640 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29643 +/* ---------------------------------------------------------------------- */
29645 +/* estimate the appropriate size for name hash table */
29646 +unsigned int au_rdhash_est(loff_t sz)
29654 + if (sz < AUFS_RDHASH_DEF)
29655 + n = AUFS_RDHASH_DEF;
29656 + /* pr_info("n %u\n", n); */
29661 + * the allocated memory has to be freed by
29662 + * au_nhash_wh_free() or au_nhash_de_free().
29664 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29666 + struct hlist_head *head;
29670 + sz = sizeof(*nhash->nh_head) * num_hash;
29671 + head = kmalloc(sz, gfp);
29673 + nhash->nh_num = num_hash;
29674 + nhash->nh_head = head;
29675 + for (u = 0; u < num_hash; u++)
29676 + INIT_HLIST_HEAD(head++);
29677 + return 0; /* success */
29683 +static void nhash_count(struct hlist_head *head)
29687 + struct hlist_node *pos;
29690 + hlist_for_each(pos, head)
29692 + pr_info("%lu\n", n);
29696 +static void au_nhash_wh_do_free(struct hlist_head *head)
29698 + struct au_vdir_wh *pos;
29699 + struct hlist_node *node;
29701 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29702 + au_delayed_kfree(pos);
29705 +static void au_nhash_de_do_free(struct hlist_head *head)
29707 + struct au_vdir_dehstr *pos;
29708 + struct hlist_node *node;
29710 + hlist_for_each_entry_safe(pos, node, head, hash)
29711 + au_cache_dfree_vdir_dehstr(pos);
29714 +static void au_nhash_do_free(struct au_nhash *nhash,
29715 + void (*free)(struct hlist_head *head))
29718 + struct hlist_head *head;
29720 + n = nhash->nh_num;
29724 + head = nhash->nh_head;
29725 + while (n-- > 0) {
29726 + nhash_count(head);
29729 + au_delayed_kfree(nhash->nh_head);
29732 +void au_nhash_wh_free(struct au_nhash *whlist)
29734 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29737 +static void au_nhash_de_free(struct au_nhash *delist)
29739 + au_nhash_do_free(delist, au_nhash_de_do_free);
29742 +/* ---------------------------------------------------------------------- */
29744 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29748 + unsigned int u, n;
29749 + struct hlist_head *head;
29750 + struct au_vdir_wh *pos;
29753 + n = whlist->nh_num;
29754 + head = whlist->nh_head;
29755 + for (u = 0; u < n; u++, head++)
29756 + hlist_for_each_entry(pos, head, wh_hash)
29757 + if (pos->wh_bindex == btgt && ++num > limit)
29762 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29763 + unsigned char *name,
29764 + unsigned int len)
29767 + /* const unsigned int magic_bit = 12; */
29769 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29776 + /* v = hash_long(v, magic_bit); */
29777 + v %= nhash->nh_num;
29778 + return nhash->nh_head + v;
29781 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29784 + return str->len == nlen && !memcmp(str->name, name, nlen);
29787 +/* returns found or not */
29788 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29790 + struct hlist_head *head;
29791 + struct au_vdir_wh *pos;
29792 + struct au_vdir_destr *str;
29794 + head = au_name_hash(whlist, name, nlen);
29795 + hlist_for_each_entry(pos, head, wh_hash) {
29796 + str = &pos->wh_str;
29797 + AuDbg("%.*s\n", str->len, str->name);
29798 + if (au_nhash_test_name(str, name, nlen))
29804 +/* returns found(true) or not */
29805 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29807 + struct hlist_head *head;
29808 + struct au_vdir_dehstr *pos;
29809 + struct au_vdir_destr *str;
29811 + head = au_name_hash(delist, name, nlen);
29812 + hlist_for_each_entry(pos, head, hash) {
29814 + AuDbg("%.*s\n", str->len, str->name);
29815 + if (au_nhash_test_name(str, name, nlen))
29821 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29822 + unsigned char d_type)
29824 +#ifdef CONFIG_AUFS_SHWH
29825 + wh->wh_ino = ino;
29826 + wh->wh_type = d_type;
29830 +/* ---------------------------------------------------------------------- */
29832 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29833 + unsigned int d_type, aufs_bindex_t bindex,
29834 + unsigned char shwh)
29837 + struct au_vdir_destr *str;
29838 + struct au_vdir_wh *wh;
29840 + AuDbg("%.*s\n", nlen, name);
29841 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29844 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29845 + if (unlikely(!wh))
29849 + wh->wh_bindex = bindex;
29851 + au_shwh_init_wh(wh, ino, d_type);
29852 + str = &wh->wh_str;
29854 + memcpy(str->name, name, nlen);
29855 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29862 +static int append_deblk(struct au_vdir *vdir)
29865 + unsigned long ul;
29866 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29867 + union au_vdir_deblk_p p, deblk_end;
29868 + unsigned char **o;
29871 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29872 + GFP_NOFS, /*may_shrink*/0);
29873 + if (unlikely(!o))
29876 + vdir->vd_deblk = o;
29877 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
29879 + ul = vdir->vd_nblk++;
29880 + vdir->vd_deblk[ul] = p.deblk;
29881 + vdir->vd_last.ul = ul;
29882 + vdir->vd_last.p.deblk = p.deblk;
29883 + deblk_end.deblk = p.deblk + deblk_sz;
29884 + err = set_deblk_end(&p, &deblk_end);
29891 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
29892 + unsigned int d_type, struct au_nhash *delist)
29896 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29897 + union au_vdir_deblk_p p, *room, deblk_end;
29898 + struct au_vdir_dehstr *dehstr;
29900 + p.deblk = last_deblk(vdir);
29901 + deblk_end.deblk = p.deblk + deblk_sz;
29902 + room = &vdir->vd_last.p;
29903 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
29904 + || !is_deblk_end(room, &deblk_end));
29906 + sz = calc_size(nlen);
29907 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
29908 + err = append_deblk(vdir);
29909 + if (unlikely(err))
29912 + p.deblk = last_deblk(vdir);
29913 + deblk_end.deblk = p.deblk + deblk_sz;
29915 + AuDebugOn(room->deblk != p.deblk);
29919 + dehstr = au_cache_alloc_vdir_dehstr();
29920 + if (unlikely(!dehstr))
29923 + dehstr->str = &room->de->de_str;
29924 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
29925 + room->de->de_ino = ino;
29926 + room->de->de_type = d_type;
29927 + room->de->de_str.len = nlen;
29928 + memcpy(room->de->de_str.name, name, nlen);
29931 + room->deblk += sz;
29932 + if (unlikely(set_deblk_end(room, &deblk_end)))
29933 + err = append_deblk(vdir);
29940 +/* ---------------------------------------------------------------------- */
29942 +void au_vdir_free(struct au_vdir *vdir, int atonce)
29944 + unsigned char **deblk;
29946 + deblk = vdir->vd_deblk;
29948 + while (vdir->vd_nblk--)
29949 + au_delayed_kfree(*deblk++);
29950 + au_delayed_kfree(vdir->vd_deblk);
29951 + au_cache_dfree_vdir(vdir);
29953 + /* not delayed */
29954 + while (vdir->vd_nblk--)
29956 + kfree(vdir->vd_deblk);
29957 + au_cache_free_vdir(vdir);
29961 +static struct au_vdir *alloc_vdir(struct file *file)
29963 + struct au_vdir *vdir;
29964 + struct super_block *sb;
29967 + sb = file->f_path.dentry->d_sb;
29968 + SiMustAnyLock(sb);
29971 + vdir = au_cache_alloc_vdir();
29972 + if (unlikely(!vdir))
29975 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
29976 + if (unlikely(!vdir->vd_deblk))
29979 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
29980 + if (!vdir->vd_deblk_sz) {
29981 + /* estimate the appropriate size for deblk */
29982 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
29983 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
29985 + vdir->vd_nblk = 0;
29986 + vdir->vd_version = 0;
29987 + vdir->vd_jiffy = 0;
29988 + err = append_deblk(vdir);
29990 + return vdir; /* success */
29992 + au_delayed_kfree(vdir->vd_deblk);
29995 + au_cache_dfree_vdir(vdir);
29997 + vdir = ERR_PTR(err);
30001 +static int reinit_vdir(struct au_vdir *vdir)
30004 + union au_vdir_deblk_p p, deblk_end;
30006 + while (vdir->vd_nblk > 1) {
30007 + au_delayed_kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
30008 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
30011 + p.deblk = vdir->vd_deblk[0];
30012 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
30013 + err = set_deblk_end(&p, &deblk_end);
30014 + /* keep vd_dblk_sz */
30015 + vdir->vd_last.ul = 0;
30016 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30017 + vdir->vd_version = 0;
30018 + vdir->vd_jiffy = 0;
30023 +/* ---------------------------------------------------------------------- */
30025 +#define AuFillVdir_CALLED 1
30026 +#define AuFillVdir_WHABLE (1 << 1)
30027 +#define AuFillVdir_SHWH (1 << 2)
30028 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
30029 +#define au_fset_fillvdir(flags, name) \
30030 + do { (flags) |= AuFillVdir_##name; } while (0)
30031 +#define au_fclr_fillvdir(flags, name) \
30032 + do { (flags) &= ~AuFillVdir_##name; } while (0)
30034 +#ifndef CONFIG_AUFS_SHWH
30035 +#undef AuFillVdir_SHWH
30036 +#define AuFillVdir_SHWH 0
30039 +struct fillvdir_arg {
30040 + struct dir_context ctx;
30041 + struct file *file;
30042 + struct au_vdir *vdir;
30043 + struct au_nhash delist;
30044 + struct au_nhash whlist;
30045 + aufs_bindex_t bindex;
30046 + unsigned int flags;
30050 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
30051 + loff_t offset __maybe_unused, u64 h_ino,
30052 + unsigned int d_type)
30054 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
30055 + char *name = (void *)__name;
30056 + struct super_block *sb;
30058 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
30061 + sb = arg->file->f_path.dentry->d_sb;
30062 + au_fset_fillvdir(arg->flags, CALLED);
30064 + if (nlen <= AUFS_WH_PFX_LEN
30065 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
30066 + if (test_known(&arg->delist, name, nlen)
30067 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
30068 + goto out; /* already exists or whiteouted */
30070 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
30072 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
30073 + d_type = DT_UNKNOWN;
30074 + arg->err = append_de(arg->vdir, name, nlen, ino,
30075 + d_type, &arg->delist);
30077 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
30078 + name += AUFS_WH_PFX_LEN;
30079 + nlen -= AUFS_WH_PFX_LEN;
30080 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
30081 + goto out; /* already whiteouted */
30084 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
30087 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
30088 + d_type = DT_UNKNOWN;
30089 + arg->err = au_nhash_append_wh
30090 + (&arg->whlist, name, nlen, ino, d_type,
30091 + arg->bindex, shwh);
30097 + arg->vdir->vd_jiffy = jiffies;
30099 + AuTraceErr(arg->err);
30103 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
30104 + struct au_nhash *whlist, struct au_nhash *delist)
30106 +#ifdef CONFIG_AUFS_SHWH
30108 + unsigned int nh, u;
30109 + struct hlist_head *head;
30110 + struct au_vdir_wh *pos;
30111 + struct hlist_node *n;
30113 + struct au_vdir_destr *destr;
30115 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
30118 + o = p = (void *)__get_free_page(GFP_NOFS);
30119 + if (unlikely(!p))
30123 + nh = whlist->nh_num;
30124 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30125 + p += AUFS_WH_PFX_LEN;
30126 + for (u = 0; u < nh; u++) {
30127 + head = whlist->nh_head + u;
30128 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
30129 + destr = &pos->wh_str;
30130 + memcpy(p, destr->name, destr->len);
30131 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
30132 + pos->wh_ino, pos->wh_type, delist);
30133 + if (unlikely(err))
30138 + au_delayed_free_page((unsigned long)o);
30148 +static int au_do_read_vdir(struct fillvdir_arg *arg)
30151 + unsigned int rdhash;
30153 + aufs_bindex_t bbot, bindex, btop;
30154 + unsigned char shwh;
30155 + struct file *hf, *file;
30156 + struct super_block *sb;
30158 + file = arg->file;
30159 + sb = file->f_path.dentry->d_sb;
30160 + SiMustAnyLock(sb);
30162 + rdhash = au_sbi(sb)->si_rdhash;
30164 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
30165 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
30166 + if (unlikely(err))
30168 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
30169 + if (unlikely(err))
30175 + if (au_opt_test(au_mntflags(sb), SHWH)) {
30177 + au_fset_fillvdir(arg->flags, SHWH);
30179 + btop = au_fbtop(file);
30180 + bbot = au_fbbot_dir(file);
30181 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
30182 + hf = au_hf_dir(file, bindex);
30186 + offset = vfsub_llseek(hf, 0, SEEK_SET);
30188 + if (unlikely(offset))
30191 + arg->bindex = bindex;
30192 + au_fclr_fillvdir(arg->flags, WHABLE);
30194 + || (bindex != bbot
30195 + && au_br_whable(au_sbr_perm(sb, bindex))))
30196 + au_fset_fillvdir(arg->flags, WHABLE);
30199 + au_fclr_fillvdir(arg->flags, CALLED);
30201 + err = vfsub_iterate_dir(hf, &arg->ctx);
30204 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
30207 + * dir_relax() may be good for concurrency, but aufs should not
30208 + * use it since it will cause a lockdep problem.
30212 + if (!err && shwh)
30213 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
30215 + au_nhash_wh_free(&arg->whlist);
30218 + au_nhash_de_free(&arg->delist);
30223 +static int read_vdir(struct file *file, int may_read)
30226 + unsigned long expire;
30227 + unsigned char do_read;
30228 + struct fillvdir_arg arg = {
30230 + .actor = fillvdir
30233 + struct inode *inode;
30234 + struct au_vdir *vdir, *allocated;
30237 + inode = file_inode(file);
30238 + IMustLock(inode);
30239 + IiMustWriteLock(inode);
30240 + SiMustAnyLock(inode->i_sb);
30242 + allocated = NULL;
30244 + expire = au_sbi(inode->i_sb)->si_rdcache;
30245 + vdir = au_ivdir(inode);
30248 + vdir = alloc_vdir(file);
30249 + err = PTR_ERR(vdir);
30250 + if (IS_ERR(vdir))
30253 + allocated = vdir;
30254 + } else if (may_read
30255 + && (inode->i_version != vdir->vd_version
30256 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
30258 + err = reinit_vdir(vdir);
30259 + if (unlikely(err))
30264 + return 0; /* success */
30268 + err = au_do_read_vdir(&arg);
30270 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
30271 + vdir->vd_version = inode->i_version;
30272 + vdir->vd_last.ul = 0;
30273 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30275 + au_set_ivdir(inode, allocated);
30276 + } else if (allocated)
30277 + au_vdir_free(allocated, /*atonce*/0);
30283 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
30286 + unsigned long ul, n;
30287 + const unsigned int deblk_sz = src->vd_deblk_sz;
30289 + AuDebugOn(tgt->vd_nblk != 1);
30292 + if (tgt->vd_nblk < src->vd_nblk) {
30293 + unsigned char **p;
30295 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
30296 + GFP_NOFS, /*may_shrink*/0);
30297 + if (unlikely(!p))
30299 + tgt->vd_deblk = p;
30302 + if (tgt->vd_deblk_sz != deblk_sz) {
30303 + unsigned char *p;
30305 + tgt->vd_deblk_sz = deblk_sz;
30306 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
30307 + /*may_shrink*/1);
30308 + if (unlikely(!p))
30310 + tgt->vd_deblk[0] = p;
30312 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
30313 + tgt->vd_version = src->vd_version;
30314 + tgt->vd_jiffy = src->vd_jiffy;
30316 + n = src->vd_nblk;
30317 + for (ul = 1; ul < n; ul++) {
30318 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
30320 + if (unlikely(!tgt->vd_deblk[ul]))
30324 + tgt->vd_nblk = n;
30325 + tgt->vd_last.ul = tgt->vd_last.ul;
30326 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
30327 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
30328 + - src->vd_deblk[src->vd_last.ul];
30330 + return 0; /* success */
30333 + rerr = reinit_vdir(tgt);
30338 +int au_vdir_init(struct file *file)
30341 + struct inode *inode;
30342 + struct au_vdir *vdir_cache, *allocated;
30344 + /* test file->f_pos here instead of ctx->pos */
30345 + err = read_vdir(file, !file->f_pos);
30346 + if (unlikely(err))
30349 + allocated = NULL;
30350 + vdir_cache = au_fvdir_cache(file);
30351 + if (!vdir_cache) {
30352 + vdir_cache = alloc_vdir(file);
30353 + err = PTR_ERR(vdir_cache);
30354 + if (IS_ERR(vdir_cache))
30356 + allocated = vdir_cache;
30357 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
30358 + /* test file->f_pos here instead of ctx->pos */
30359 + err = reinit_vdir(vdir_cache);
30360 + if (unlikely(err))
30363 + return 0; /* success */
30365 + inode = file_inode(file);
30366 + err = copy_vdir(vdir_cache, au_ivdir(inode));
30368 + file->f_version = inode->i_version;
30370 + au_set_fvdir_cache(file, allocated);
30371 + } else if (allocated)
30372 + au_vdir_free(allocated, /*atonce*/0);
30378 +static loff_t calc_offset(struct au_vdir *vdir)
30381 + union au_vdir_deblk_p p;
30383 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
30384 + offset = vdir->vd_last.p.deblk - p.deblk;
30385 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
30389 +/* returns true or false */
30390 +static int seek_vdir(struct file *file, struct dir_context *ctx)
30393 + unsigned int deblk_sz;
30394 + unsigned long ul, n;
30396 + union au_vdir_deblk_p p, deblk_end;
30397 + struct au_vdir *vdir_cache;
30400 + vdir_cache = au_fvdir_cache(file);
30401 + offset = calc_offset(vdir_cache);
30402 + AuDbg("offset %lld\n", offset);
30403 + if (ctx->pos == offset)
30406 + vdir_cache->vd_last.ul = 0;
30407 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
30412 + deblk_sz = vdir_cache->vd_deblk_sz;
30413 + ul = div64_u64(ctx->pos, deblk_sz);
30414 + AuDbg("ul %lu\n", ul);
30415 + if (ul >= vdir_cache->vd_nblk)
30418 + n = vdir_cache->vd_nblk;
30419 + for (; ul < n; ul++) {
30420 + p.deblk = vdir_cache->vd_deblk[ul];
30421 + deblk_end.deblk = p.deblk + deblk_sz;
30423 + offset *= deblk_sz;
30424 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
30427 + l = calc_size(p.de->de_str.len);
30431 + if (!is_deblk_end(&p, &deblk_end)) {
30433 + vdir_cache->vd_last.ul = ul;
30434 + vdir_cache->vd_last.p = p;
30441 + AuTraceErr(!valid);
30445 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
30447 + unsigned int l, deblk_sz;
30448 + union au_vdir_deblk_p deblk_end;
30449 + struct au_vdir *vdir_cache;
30450 + struct au_vdir_de *de;
30452 + vdir_cache = au_fvdir_cache(file);
30453 + if (!seek_vdir(file, ctx))
30456 + deblk_sz = vdir_cache->vd_deblk_sz;
30458 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30459 + deblk_end.deblk += deblk_sz;
30460 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
30461 + de = vdir_cache->vd_last.p.de;
30462 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
30463 + de->de_str.len, de->de_str.name, ctx->pos,
30464 + (unsigned long)de->de_ino, de->de_type);
30465 + if (unlikely(!dir_emit(ctx, de->de_str.name,
30466 + de->de_str.len, de->de_ino,
30468 + /* todo: ignore the error caused by udba? */
30469 + /* return err; */
30473 + l = calc_size(de->de_str.len);
30474 + vdir_cache->vd_last.p.deblk += l;
30477 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
30478 + vdir_cache->vd_last.ul++;
30479 + vdir_cache->vd_last.p.deblk
30480 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30481 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
30490 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
30491 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
30492 +++ linux/fs/aufs/vfsub.c 2016-10-09 16:55:36.496035060 +0200
30495 + * Copyright (C) 2005-2016 Junjiro R. Okajima
30497 + * This program, aufs is free software; you can redistribute it and/or modify
30498 + * it under the terms of the GNU General Public License as published by
30499 + * the Free Software Foundation; either version 2 of the License, or
30500 + * (at your option) any later version.
30502 + * This program is distributed in the hope that it will be useful,
30503 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30504 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30505 + * GNU General Public License for more details.
30507 + * You should have received a copy of the GNU General Public License
30508 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30512 + * sub-routines for VFS
30515 +#include <linux/namei.h>
30516 +#include <linux/nsproxy.h>
30517 +#include <linux/security.h>
30518 +#include <linux/splice.h>
30519 +#include "../fs/mount.h"
30522 +#ifdef CONFIG_AUFS_BR_FUSE
30523 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
30525 + struct nsproxy *ns;
30527 + if (!au_test_fuse(h_sb) || !au_userns)
30530 + ns = current->nsproxy;
30531 + /* no {get,put}_nsproxy(ns) */
30532 + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES;
30536 +/* ---------------------------------------------------------------------- */
30538 +int vfsub_update_h_iattr(struct path *h_path, int *did)
30542 + struct super_block *h_sb;
30544 + /* for remote fs, leave work for its getattr or d_revalidate */
30545 + /* for bad i_attr fs, handle them in aufs_getattr() */
30546 + /* still some fs may acquire i_mutex. we need to skip them */
30550 + h_sb = h_path->dentry->d_sb;
30551 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
30553 + err = vfs_getattr(h_path, &st);
30558 +/* ---------------------------------------------------------------------- */
30560 +struct file *vfsub_dentry_open(struct path *path, int flags)
30562 + struct file *file;
30564 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
30566 + if (!IS_ERR_OR_NULL(file)
30567 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
30568 + i_readcount_inc(d_inode(path->dentry));
30573 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
30575 + struct file *file;
30578 + file = filp_open(path,
30579 + oflags /* | __FMODE_NONOTIFY */,
30582 + if (IS_ERR(file))
30584 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30591 + * Ideally this function should call VFS:do_last() in order to keep all its
30592 + * checkings. But it is very hard for aufs to regenerate several VFS internal
30593 + * structure such as nameidata. This is a second (or third) best approach.
30594 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
30596 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30597 + struct vfsub_aopen_args *args, struct au_branch *br)
30600 + struct file *file = args->file;
30601 + /* copied from linux/fs/namei.c:atomic_open() */
30602 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
30605 + AuDebugOn(!dir->i_op->atomic_open);
30607 + err = au_br_test_oflag(args->open_flag, br);
30608 + if (unlikely(err))
30611 + args->file->f_path.dentry = DENTRY_NOT_SET;
30612 + args->file->f_path.mnt = au_br_mnt(br);
30613 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
30614 + args->create_mode, args->opened);
30616 + /* some filesystems don't set FILE_CREATED while succeeded? */
30617 + if (*args->opened & FILE_CREATED)
30618 + fsnotify_create(dir, dentry);
30624 + /* todo: call VFS:may_open() here */
30625 + err = open_check_o_direct(file);
30626 + /* todo: ima_file_check() too? */
30627 + if (!err && (args->open_flag & __FMODE_EXEC))
30628 + err = deny_write_access(file);
30629 + if (unlikely(err))
30630 + /* note that the file is created and still opened */
30635 + fsnotify_open(file);
30641 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30645 + err = kern_path(name, flags, path);
30646 + if (!err && d_is_positive(path->dentry))
30647 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30651 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
30652 + struct dentry *parent, int len)
30654 + struct path path = {
30658 + path.dentry = lookup_one_len_unlocked(name, parent, len);
30659 + if (IS_ERR(path.dentry))
30661 + if (d_is_positive(path.dentry))
30662 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30665 + AuTraceErrPtr(path.dentry);
30666 + return path.dentry;
30669 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30672 + struct path path = {
30676 + /* VFS checks it too, but by WARN_ON_ONCE() */
30677 + IMustLock(d_inode(parent));
30679 + path.dentry = lookup_one_len(name, parent, len);
30680 + if (IS_ERR(path.dentry))
30682 + if (d_is_positive(path.dentry))
30683 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30686 + AuTraceErrPtr(path.dentry);
30687 + return path.dentry;
30690 +void vfsub_call_lkup_one(void *args)
30692 + struct vfsub_lkup_one_args *a = args;
30693 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30696 +/* ---------------------------------------------------------------------- */
30698 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30699 + struct dentry *d2, struct au_hinode *hdir2)
30701 + struct dentry *d;
30704 + d = lock_rename(d1, d2);
30706 + au_hn_suspend(hdir1);
30707 + if (hdir1 != hdir2)
30708 + au_hn_suspend(hdir2);
30713 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30714 + struct dentry *d2, struct au_hinode *hdir2)
30716 + au_hn_resume(hdir1);
30717 + if (hdir1 != hdir2)
30718 + au_hn_resume(hdir2);
30720 + unlock_rename(d1, d2);
30724 +/* ---------------------------------------------------------------------- */
30726 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30729 + struct dentry *d;
30733 + d = path->dentry;
30734 + path->dentry = d->d_parent;
30735 + err = security_path_mknod(path, d, mode, 0);
30736 + path->dentry = d;
30737 + if (unlikely(err))
30741 + err = vfs_create(dir, path->dentry, mode, want_excl);
30744 + struct path tmp = *path;
30747 + vfsub_update_h_iattr(&tmp, &did);
30749 + tmp.dentry = path->dentry->d_parent;
30750 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30759 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30762 + struct dentry *d;
30766 + d = path->dentry;
30767 + path->dentry = d->d_parent;
30768 + err = security_path_symlink(path, d, symname);
30769 + path->dentry = d;
30770 + if (unlikely(err))
30774 + err = vfs_symlink(dir, path->dentry, symname);
30777 + struct path tmp = *path;
30780 + vfsub_update_h_iattr(&tmp, &did);
30782 + tmp.dentry = path->dentry->d_parent;
30783 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30792 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30795 + struct dentry *d;
30799 + d = path->dentry;
30800 + path->dentry = d->d_parent;
30801 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30802 + path->dentry = d;
30803 + if (unlikely(err))
30807 + err = vfs_mknod(dir, path->dentry, mode, dev);
30810 + struct path tmp = *path;
30813 + vfsub_update_h_iattr(&tmp, &did);
30815 + tmp.dentry = path->dentry->d_parent;
30816 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30825 +static int au_test_nlink(struct inode *inode)
30827 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30829 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30830 + || inode->i_nlink < link_max)
30835 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30836 + struct inode **delegated_inode)
30839 + struct dentry *d;
30843 + err = au_test_nlink(d_inode(src_dentry));
30844 + if (unlikely(err))
30847 + /* we don't call may_linkat() */
30848 + d = path->dentry;
30849 + path->dentry = d->d_parent;
30850 + err = security_path_link(src_dentry, path, d);
30851 + path->dentry = d;
30852 + if (unlikely(err))
30856 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30859 + struct path tmp = *path;
30862 + /* fuse has different memory inode for the same inumber */
30863 + vfsub_update_h_iattr(&tmp, &did);
30865 + tmp.dentry = path->dentry->d_parent;
30866 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30867 + tmp.dentry = src_dentry;
30868 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30877 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
30878 + struct inode *dir, struct path *path,
30879 + struct inode **delegated_inode)
30882 + struct path tmp = {
30885 + struct dentry *d;
30888 + IMustLock(src_dir);
30890 + d = path->dentry;
30891 + path->dentry = d->d_parent;
30892 + tmp.dentry = src_dentry->d_parent;
30893 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
30894 + path->dentry = d;
30895 + if (unlikely(err))
30899 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
30900 + delegated_inode, /*flags*/0);
30905 + tmp.dentry = d->d_parent;
30906 + vfsub_update_h_iattr(&tmp, &did);
30908 + tmp.dentry = src_dentry;
30909 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30910 + tmp.dentry = src_dentry->d_parent;
30911 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30920 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
30923 + struct dentry *d;
30927 + d = path->dentry;
30928 + path->dentry = d->d_parent;
30929 + err = security_path_mkdir(path, d, mode);
30930 + path->dentry = d;
30931 + if (unlikely(err))
30935 + err = vfs_mkdir(dir, path->dentry, mode);
30938 + struct path tmp = *path;
30941 + vfsub_update_h_iattr(&tmp, &did);
30943 + tmp.dentry = path->dentry->d_parent;
30944 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30953 +int vfsub_rmdir(struct inode *dir, struct path *path)
30956 + struct dentry *d;
30960 + d = path->dentry;
30961 + path->dentry = d->d_parent;
30962 + err = security_path_rmdir(path, d);
30963 + path->dentry = d;
30964 + if (unlikely(err))
30968 + err = vfs_rmdir(dir, path->dentry);
30971 + struct path tmp = {
30972 + .dentry = path->dentry->d_parent,
30976 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
30983 +/* ---------------------------------------------------------------------- */
30985 +/* todo: support mmap_sem? */
30986 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
30992 + err = vfs_read(file, ubuf, count, ppos);
30995 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30999 +/* todo: kernel_read()? */
31000 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31004 + mm_segment_t oldfs;
31011 + oldfs = get_fs();
31012 + set_fs(KERNEL_DS);
31013 + err = vfsub_read_u(file, buf.u, count, ppos);
31018 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31024 + err = vfs_write(file, ubuf, count, ppos);
31027 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31031 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
31034 + mm_segment_t oldfs;
31037 + const char __user *u;
31041 + oldfs = get_fs();
31042 + set_fs(KERNEL_DS);
31043 + err = vfsub_write_u(file, buf.u, count, ppos);
31048 +int vfsub_flush(struct file *file, fl_owner_t id)
31053 + if (file->f_op->flush) {
31054 + if (!au_test_nfs(file->f_path.dentry->d_sb))
31055 + err = file->f_op->flush(file, id);
31058 + err = file->f_op->flush(file, id);
31062 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
31068 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
31072 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
31075 + err = iterate_dir(file, ctx);
31078 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31082 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31083 + struct pipe_inode_info *pipe, size_t len,
31084 + unsigned int flags)
31089 + err = do_splice_to(in, ppos, pipe, len, flags);
31091 + file_accessed(in);
31093 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
31097 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31098 + loff_t *ppos, size_t len, unsigned int flags)
31103 + err = do_splice_from(pipe, out, ppos, len, flags);
31106 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
31110 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
31114 + /* file can be NULL */
31116 + err = vfs_fsync(file, datasync);
31120 + AuDebugOn(!file);
31121 + path = &file->f_path;
31123 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
31128 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
31129 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31130 + struct file *h_file)
31133 + struct inode *h_inode;
31134 + struct super_block *h_sb;
31137 + err = vfsub_truncate(h_path, length);
31141 + h_inode = d_inode(h_path->dentry);
31142 + h_sb = h_inode->i_sb;
31144 + sb_start_write(h_sb);
31146 + err = locks_verify_truncate(h_inode, h_file, length);
31148 + err = security_path_truncate(h_path);
31151 + err = do_truncate(h_path->dentry, length, attr, h_file);
31155 + sb_end_write(h_sb);
31162 +/* ---------------------------------------------------------------------- */
31164 +struct au_vfsub_mkdir_args {
31166 + struct inode *dir;
31167 + struct path *path;
31171 +static void au_call_vfsub_mkdir(void *args)
31173 + struct au_vfsub_mkdir_args *a = args;
31174 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
31177 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
31179 + int err, do_sio, wkq_err;
31181 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31184 + err = vfsub_mkdir(dir, path, mode);
31187 + struct au_vfsub_mkdir_args args = {
31193 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
31194 + if (unlikely(wkq_err))
31201 +struct au_vfsub_rmdir_args {
31203 + struct inode *dir;
31204 + struct path *path;
31207 +static void au_call_vfsub_rmdir(void *args)
31209 + struct au_vfsub_rmdir_args *a = args;
31210 + *a->errp = vfsub_rmdir(a->dir, a->path);
31213 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
31215 + int err, do_sio, wkq_err;
31217 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31220 + err = vfsub_rmdir(dir, path);
31223 + struct au_vfsub_rmdir_args args = {
31228 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
31229 + if (unlikely(wkq_err))
31236 +/* ---------------------------------------------------------------------- */
31238 +struct notify_change_args {
31240 + struct path *path;
31241 + struct iattr *ia;
31242 + struct inode **delegated_inode;
31245 +static void call_notify_change(void *args)
31247 + struct notify_change_args *a = args;
31248 + struct inode *h_inode;
31250 + h_inode = d_inode(a->path->dentry);
31251 + IMustLock(h_inode);
31253 + *a->errp = -EPERM;
31254 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
31256 + *a->errp = notify_change(a->path->dentry, a->ia,
31257 + a->delegated_inode);
31260 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
31262 + AuTraceErr(*a->errp);
31265 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31266 + struct inode **delegated_inode)
31269 + struct notify_change_args args = {
31273 + .delegated_inode = delegated_inode
31276 + call_notify_change(&args);
31281 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31282 + struct inode **delegated_inode)
31284 + int err, wkq_err;
31285 + struct notify_change_args args = {
31289 + .delegated_inode = delegated_inode
31292 + wkq_err = au_wkq_wait(call_notify_change, &args);
31293 + if (unlikely(wkq_err))
31299 +/* ---------------------------------------------------------------------- */
31301 +struct unlink_args {
31303 + struct inode *dir;
31304 + struct path *path;
31305 + struct inode **delegated_inode;
31308 +static void call_unlink(void *args)
31310 + struct unlink_args *a = args;
31311 + struct dentry *d = a->path->dentry;
31312 + struct inode *h_inode;
31313 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
31314 + && au_dcount(d) == 1);
31316 + IMustLock(a->dir);
31318 + a->path->dentry = d->d_parent;
31319 + *a->errp = security_path_unlink(a->path, d);
31320 + a->path->dentry = d;
31321 + if (unlikely(*a->errp))
31324 + if (!stop_sillyrename)
31327 + if (d_is_positive(d)) {
31328 + h_inode = d_inode(d);
31333 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
31336 + struct path tmp = {
31337 + .dentry = d->d_parent,
31338 + .mnt = a->path->mnt
31340 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31343 + if (!stop_sillyrename)
31348 + AuTraceErr(*a->errp);
31352 + * @dir: must be locked.
31353 + * @dentry: target dentry.
31355 +int vfsub_unlink(struct inode *dir, struct path *path,
31356 + struct inode **delegated_inode, int force)
31359 + struct unlink_args args = {
31363 + .delegated_inode = delegated_inode
31367 + call_unlink(&args);
31371 + wkq_err = au_wkq_wait(call_unlink, &args);
31372 + if (unlikely(wkq_err))
31378 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
31379 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
31380 +++ linux/fs/aufs/vfsub.h 2016-10-09 16:55:36.496035060 +0200
31383 + * Copyright (C) 2005-2016 Junjiro R. Okajima
31385 + * This program, aufs is free software; you can redistribute it and/or modify
31386 + * it under the terms of the GNU General Public License as published by
31387 + * the Free Software Foundation; either version 2 of the License, or
31388 + * (at your option) any later version.
31390 + * This program is distributed in the hope that it will be useful,
31391 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31392 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31393 + * GNU General Public License for more details.
31395 + * You should have received a copy of the GNU General Public License
31396 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31400 + * sub-routines for VFS
31403 +#ifndef __AUFS_VFSUB_H__
31404 +#define __AUFS_VFSUB_H__
31408 +#include <linux/fs.h>
31409 +#include <linux/mount.h>
31410 +#include <linux/posix_acl.h>
31411 +#include <linux/xattr.h>
31412 +#include "debug.h"
31414 +/* copied from linux/fs/internal.h */
31415 +/* todo: BAD approach!! */
31416 +extern void __mnt_drop_write(struct vfsmount *);
31417 +extern int open_check_o_direct(struct file *f);
31419 +/* ---------------------------------------------------------------------- */
31421 +/* lock subclass for lower inode */
31422 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
31423 +/* reduce? gave up. */
31425 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
31426 + AuLsc_I_PARENT, /* lower inode, parent first */
31427 + AuLsc_I_PARENT2, /* copyup dirs */
31428 + AuLsc_I_PARENT3, /* copyup wh */
31434 +/* to debug easier, do not make them inlined functions */
31435 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
31436 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
31438 +/* ---------------------------------------------------------------------- */
31440 +static inline void vfsub_drop_nlink(struct inode *inode)
31442 + AuDebugOn(!inode->i_nlink);
31443 + drop_nlink(inode);
31446 +static inline void vfsub_dead_dir(struct inode *inode)
31448 + AuDebugOn(!S_ISDIR(inode->i_mode));
31449 + inode->i_flags |= S_DEAD;
31450 + clear_nlink(inode);
31453 +static inline int vfsub_native_ro(struct inode *inode)
31455 + return (inode->i_sb->s_flags & MS_RDONLY)
31456 + || IS_RDONLY(inode)
31457 + /* || IS_APPEND(inode) */
31458 + || IS_IMMUTABLE(inode);
31461 +#ifdef CONFIG_AUFS_BR_FUSE
31462 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
31464 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
31467 +/* ---------------------------------------------------------------------- */
31469 +int vfsub_update_h_iattr(struct path *h_path, int *did);
31470 +struct file *vfsub_dentry_open(struct path *path, int flags);
31471 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
31472 +struct vfsub_aopen_args {
31473 + struct file *file;
31474 + unsigned int open_flag;
31475 + umode_t create_mode;
31479 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
31480 + struct vfsub_aopen_args *args, struct au_branch *br);
31481 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
31483 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
31484 + struct dentry *parent, int len);
31485 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
31488 +struct vfsub_lkup_one_args {
31489 + struct dentry **errp;
31490 + struct qstr *name;
31491 + struct dentry *parent;
31494 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
31495 + struct dentry *parent)
31497 + return vfsub_lookup_one_len(name->name, parent, name->len);
31500 +void vfsub_call_lkup_one(void *args);
31502 +/* ---------------------------------------------------------------------- */
31504 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
31509 + err = mnt_want_write(mnt);
31514 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
31517 + mnt_drop_write(mnt);
31521 +#if 0 /* reserved */
31522 +static inline void vfsub_mnt_drop_write_file(struct file *file)
31525 + mnt_drop_write_file(file);
31530 +/* ---------------------------------------------------------------------- */
31533 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
31534 + struct dentry *d2, struct au_hinode *hdir2);
31535 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
31536 + struct dentry *d2, struct au_hinode *hdir2);
31538 +int vfsub_create(struct inode *dir, struct path *path, int mode,
31540 +int vfsub_symlink(struct inode *dir, struct path *path,
31541 + const char *symname);
31542 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
31543 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
31544 + struct path *path, struct inode **delegated_inode);
31545 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
31546 + struct inode *hdir, struct path *path,
31547 + struct inode **delegated_inode);
31548 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
31549 +int vfsub_rmdir(struct inode *dir, struct path *path);
31551 +/* ---------------------------------------------------------------------- */
31553 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31555 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31557 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31559 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
31561 +int vfsub_flush(struct file *file, fl_owner_t id);
31562 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
31564 +static inline loff_t vfsub_f_size_read(struct file *file)
31566 + return i_size_read(file_inode(file));
31569 +static inline unsigned int vfsub_file_flags(struct file *file)
31571 + unsigned int flags;
31573 + spin_lock(&file->f_lock);
31574 + flags = file->f_flags;
31575 + spin_unlock(&file->f_lock);
31580 +static inline int vfsub_file_execed(struct file *file)
31582 + /* todo: direct access f_flags */
31583 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
31586 +#if 0 /* reserved */
31587 +static inline void vfsub_file_accessed(struct file *h_file)
31589 + file_accessed(h_file);
31590 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
31594 +#if 0 /* reserved */
31595 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
31596 + struct dentry *h_dentry)
31598 + struct path h_path = {
31599 + .dentry = h_dentry,
31602 + touch_atime(&h_path);
31603 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
31607 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
31610 + return update_time(h_inode, ts, flags);
31611 + /* no vfsub_update_h_iattr() since we don't have struct path */
31614 +#ifdef CONFIG_FS_POSIX_ACL
31615 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
31619 + err = posix_acl_chmod(h_inode, h_mode);
31620 + if (err == -EOPNOTSUPP)
31625 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
31628 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31629 + struct pipe_inode_info *pipe, size_t len,
31630 + unsigned int flags);
31631 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31632 + loff_t *ppos, size_t len, unsigned int flags);
31634 +static inline long vfsub_truncate(struct path *path, loff_t length)
31639 + err = vfs_truncate(path, length);
31644 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31645 + struct file *h_file);
31646 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
31648 +/* ---------------------------------------------------------------------- */
31650 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
31655 + err = vfs_llseek(file, offset, origin);
31660 +/* ---------------------------------------------------------------------- */
31662 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
31663 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
31664 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31665 + struct inode **delegated_inode);
31666 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31667 + struct inode **delegated_inode);
31668 +int vfsub_unlink(struct inode *dir, struct path *path,
31669 + struct inode **delegated_inode, int force);
31671 +/* ---------------------------------------------------------------------- */
31673 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
31674 + const void *value, size_t size, int flags)
31679 + err = vfs_setxattr(dentry, name, value, size, flags);
31685 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31690 + err = vfs_removexattr(dentry, name);
31696 +#endif /* __KERNEL__ */
31697 +#endif /* __AUFS_VFSUB_H__ */
31698 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31699 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31700 +++ linux/fs/aufs/wbr_policy.c 2016-10-09 16:55:36.496035060 +0200
31703 + * Copyright (C) 2005-2016 Junjiro R. Okajima
31705 + * This program, aufs is free software; you can redistribute it and/or modify
31706 + * it under the terms of the GNU General Public License as published by
31707 + * the Free Software Foundation; either version 2 of the License, or
31708 + * (at your option) any later version.
31710 + * This program is distributed in the hope that it will be useful,
31711 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31712 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31713 + * GNU General Public License for more details.
31715 + * You should have received a copy of the GNU General Public License
31716 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31720 + * policies for selecting one among multiple writable branches
31723 +#include <linux/statfs.h>
31726 +/* subset of cpup_attr() */
31727 +static noinline_for_stack
31728 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31732 + struct inode *h_isrc;
31734 + h_isrc = d_inode(h_src);
31735 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31736 + ia.ia_mode = h_isrc->i_mode;
31737 + ia.ia_uid = h_isrc->i_uid;
31738 + ia.ia_gid = h_isrc->i_gid;
31739 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31740 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31741 + /* no delegation since it is just created */
31742 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31744 + /* is this nfs only? */
31745 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31746 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31747 + ia.ia_mode = h_isrc->i_mode;
31748 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31754 +#define AuCpdown_PARENT_OPQ 1
31755 +#define AuCpdown_WHED (1 << 1)
31756 +#define AuCpdown_MADE_DIR (1 << 2)
31757 +#define AuCpdown_DIROPQ (1 << 3)
31758 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31759 +#define au_fset_cpdown(flags, name) \
31760 + do { (flags) |= AuCpdown_##name; } while (0)
31761 +#define au_fclr_cpdown(flags, name) \
31762 + do { (flags) &= ~AuCpdown_##name; } while (0)
31764 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31765 + unsigned int *flags)
31768 + struct dentry *opq_dentry;
31770 + opq_dentry = au_diropq_create(dentry, bdst);
31771 + err = PTR_ERR(opq_dentry);
31772 + if (IS_ERR(opq_dentry))
31774 + dput(opq_dentry);
31775 + au_fset_cpdown(*flags, DIROPQ);
31781 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31782 + struct inode *dir, aufs_bindex_t bdst)
31785 + struct path h_path;
31786 + struct au_branch *br;
31788 + br = au_sbr(dentry->d_sb, bdst);
31789 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31790 + err = PTR_ERR(h_path.dentry);
31791 + if (IS_ERR(h_path.dentry))
31795 + if (d_is_positive(h_path.dentry)) {
31796 + h_path.mnt = au_br_mnt(br);
31797 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31800 + dput(h_path.dentry);
31806 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31807 + struct au_pin *pin,
31808 + struct dentry *h_parent, void *arg)
31811 + aufs_bindex_t bopq, btop;
31812 + struct path h_path;
31813 + struct dentry *parent;
31814 + struct inode *h_dir, *h_inode, *inode, *dir;
31815 + unsigned int *flags = arg;
31817 + btop = au_dbtop(dentry);
31818 + /* dentry is di-locked */
31819 + parent = dget_parent(dentry);
31820 + dir = d_inode(parent);
31821 + h_dir = d_inode(h_parent);
31822 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31823 + IMustLock(h_dir);
31825 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31826 + if (unlikely(err < 0))
31828 + h_path.dentry = au_h_dptr(dentry, bdst);
31829 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31830 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31831 + S_IRWXU | S_IRUGO | S_IXUGO);
31832 + if (unlikely(err))
31834 + au_fset_cpdown(*flags, MADE_DIR);
31836 + bopq = au_dbdiropq(dentry);
31837 + au_fclr_cpdown(*flags, WHED);
31838 + au_fclr_cpdown(*flags, DIROPQ);
31839 + if (au_dbwh(dentry) == bdst)
31840 + au_fset_cpdown(*flags, WHED);
31841 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31842 + au_fset_cpdown(*flags, PARENT_OPQ);
31843 + h_inode = d_inode(h_path.dentry);
31844 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31845 + if (au_ftest_cpdown(*flags, WHED)) {
31846 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31847 + if (unlikely(err)) {
31848 + inode_unlock(h_inode);
31853 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
31854 + inode_unlock(h_inode);
31855 + if (unlikely(err))
31858 + if (au_ftest_cpdown(*flags, WHED)) {
31859 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
31860 + if (unlikely(err))
31864 + inode = d_inode(dentry);
31865 + if (au_ibbot(inode) < bdst)
31866 + au_set_ibbot(inode, bdst);
31867 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
31868 + au_hi_flags(inode, /*isdir*/1));
31869 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
31870 + goto out; /* success */
31874 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31875 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31876 + rerr = au_diropq_remove(dentry, bdst);
31877 + inode_unlock(h_inode);
31878 + if (unlikely(rerr)) {
31879 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
31880 + dentry, bdst, rerr);
31886 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
31887 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
31888 + if (unlikely(rerr)) {
31889 + AuIOErr("failed removing %pd b%d (%d)\n",
31890 + dentry, bdst, rerr);
31895 + au_set_h_dptr(dentry, bdst, NULL);
31896 + if (au_dbbot(dentry) == bdst)
31897 + au_update_dbbot(dentry);
31903 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
31906 + unsigned int flags;
31909 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
31914 +/* ---------------------------------------------------------------------- */
31916 +/* policies for create */
31918 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
31920 + int err, i, j, ndentry;
31921 + aufs_bindex_t bopq;
31922 + struct au_dcsub_pages dpages;
31923 + struct au_dpage *dpage;
31924 + struct dentry **dentries, *parent, *d;
31926 + err = au_dpages_init(&dpages, GFP_NOFS);
31927 + if (unlikely(err))
31929 + parent = dget_parent(dentry);
31930 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
31931 + if (unlikely(err))
31935 + for (i = 0; i < dpages.ndpage; i++) {
31936 + dpage = dpages.dpages + i;
31937 + dentries = dpage->dentries;
31938 + ndentry = dpage->ndentry;
31939 + for (j = 0; j < ndentry; j++) {
31941 + di_read_lock_parent2(d, !AuLock_IR);
31942 + bopq = au_dbdiropq(d);
31943 + di_read_unlock(d, !AuLock_IR);
31944 + if (bopq >= 0 && bopq < err)
31951 + au_dpages_free(&dpages);
31956 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
31958 + for (; bindex >= 0; bindex--)
31959 + if (!au_br_rdonly(au_sbr(sb, bindex)))
31964 +/* top down parent */
31965 +static int au_wbr_create_tdp(struct dentry *dentry,
31966 + unsigned int flags __maybe_unused)
31969 + aufs_bindex_t btop, bindex;
31970 + struct super_block *sb;
31971 + struct dentry *parent, *h_parent;
31973 + sb = dentry->d_sb;
31974 + btop = au_dbtop(dentry);
31976 + if (!au_br_rdonly(au_sbr(sb, btop)))
31980 + parent = dget_parent(dentry);
31981 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
31982 + h_parent = au_h_dptr(parent, bindex);
31983 + if (!h_parent || d_is_negative(h_parent))
31986 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
31993 + /* bottom up here */
31994 + if (unlikely(err < 0)) {
31995 + err = au_wbr_bu(sb, btop - 1);
31997 + err = au_wbr_nonopq(dentry, err);
32001 + AuDbg("b%d\n", err);
32005 +/* ---------------------------------------------------------------------- */
32007 +/* an exception for the policy other than tdp */
32008 +static int au_wbr_create_exp(struct dentry *dentry)
32011 + aufs_bindex_t bwh, bdiropq;
32012 + struct dentry *parent;
32015 + bwh = au_dbwh(dentry);
32016 + parent = dget_parent(dentry);
32017 + bdiropq = au_dbdiropq(parent);
32019 + if (bdiropq >= 0)
32020 + err = min(bdiropq, bwh);
32023 + AuDbg("%d\n", err);
32024 + } else if (bdiropq >= 0) {
32026 + AuDbg("%d\n", err);
32031 + err = au_wbr_nonopq(dentry, err);
32033 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
32036 + AuDbg("%d\n", err);
32040 +/* ---------------------------------------------------------------------- */
32043 +static int au_wbr_create_init_rr(struct super_block *sb)
32047 + err = au_wbr_bu(sb, au_sbbot(sb));
32048 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
32051 + AuDbg("b%d\n", err);
32055 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
32059 + aufs_bindex_t bindex, bbot;
32060 + struct super_block *sb;
32063 + err = au_wbr_create_exp(dentry);
32067 + sb = dentry->d_sb;
32068 + next = &au_sbi(sb)->si_wbr_rr_next;
32069 + bbot = au_sbbot(sb);
32071 + for (bindex = 0; bindex <= bbot; bindex++) {
32072 + if (!au_ftest_wbr(flags, DIR)) {
32073 + err = atomic_dec_return(next) + 1;
32074 + /* modulo for 0 is meaningless */
32075 + if (unlikely(!err))
32076 + err = atomic_dec_return(next) + 1;
32078 + err = atomic_read(next);
32079 + AuDbg("%d\n", err);
32082 + AuDbg("%d\n", err);
32083 + if (!au_br_rdonly(au_sbr(sb, err)))
32089 + err = au_wbr_nonopq(dentry, err);
32092 + AuDbg("%d\n", err);
32096 +/* ---------------------------------------------------------------------- */
32098 +/* most free space */
32099 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
32101 + struct super_block *sb;
32102 + struct au_branch *br;
32103 + struct au_wbr_mfs *mfs;
32104 + struct dentry *h_parent;
32105 + aufs_bindex_t bindex, bbot;
32107 + unsigned long long b, bavail;
32108 + struct path h_path;
32109 + /* reduce the stack usage */
32110 + struct kstatfs *st;
32112 + st = kmalloc(sizeof(*st), GFP_NOFS);
32113 + if (unlikely(!st)) {
32114 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
32119 + sb = dentry->d_sb;
32120 + mfs = &au_sbi(sb)->si_wbr_mfs;
32121 + MtxMustLock(&mfs->mfs_lock);
32122 + mfs->mfs_bindex = -EROFS;
32123 + mfs->mfsrr_bytes = 0;
32126 + bbot = au_sbbot(sb);
32128 + bindex = au_dbtop(parent);
32129 + bbot = au_dbtaildir(parent);
32132 + for (; bindex <= bbot; bindex++) {
32134 + h_parent = au_h_dptr(parent, bindex);
32135 + if (!h_parent || d_is_negative(h_parent))
32138 + br = au_sbr(sb, bindex);
32139 + if (au_br_rdonly(br))
32142 + /* sb->s_root for NFS is unreliable */
32143 + h_path.mnt = au_br_mnt(br);
32144 + h_path.dentry = h_path.mnt->mnt_root;
32145 + err = vfs_statfs(&h_path, st);
32146 + if (unlikely(err)) {
32147 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
32151 + /* when the available size is equal, select the lower one */
32152 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
32153 + || sizeof(b) < sizeof(st->f_bsize));
32154 + b = st->f_bavail * st->f_bsize;
32155 + br->br_wbr->wbr_bytes = b;
32156 + if (b >= bavail) {
32158 + mfs->mfs_bindex = bindex;
32159 + mfs->mfs_jiffy = jiffies;
32163 + mfs->mfsrr_bytes = bavail;
32164 + AuDbg("b%d\n", mfs->mfs_bindex);
32165 + au_delayed_kfree(st);
32168 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
32171 + struct dentry *parent;
32172 + struct super_block *sb;
32173 + struct au_wbr_mfs *mfs;
32175 + err = au_wbr_create_exp(dentry);
32179 + sb = dentry->d_sb;
32181 + if (au_ftest_wbr(flags, PARENT))
32182 + parent = dget_parent(dentry);
32183 + mfs = &au_sbi(sb)->si_wbr_mfs;
32184 + mutex_lock(&mfs->mfs_lock);
32185 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32186 + || mfs->mfs_bindex < 0
32187 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
32188 + au_mfs(dentry, parent);
32189 + mutex_unlock(&mfs->mfs_lock);
32190 + err = mfs->mfs_bindex;
32194 + err = au_wbr_nonopq(dentry, err);
32197 + AuDbg("b%d\n", err);
32201 +static int au_wbr_create_init_mfs(struct super_block *sb)
32203 + struct au_wbr_mfs *mfs;
32205 + mfs = &au_sbi(sb)->si_wbr_mfs;
32206 + mutex_init(&mfs->mfs_lock);
32207 + mfs->mfs_jiffy = 0;
32208 + mfs->mfs_bindex = -EROFS;
32213 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
32215 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
32219 +/* ---------------------------------------------------------------------- */
32221 +/* most free space and then round robin */
32222 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
32225 + struct au_wbr_mfs *mfs;
32227 + err = au_wbr_create_mfs(dentry, flags);
32229 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
32230 + mutex_lock(&mfs->mfs_lock);
32231 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
32232 + err = au_wbr_create_rr(dentry, flags);
32233 + mutex_unlock(&mfs->mfs_lock);
32236 + AuDbg("b%d\n", err);
32240 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
32244 + au_wbr_create_init_mfs(sb); /* ignore */
32245 + err = au_wbr_create_init_rr(sb);
32250 +/* ---------------------------------------------------------------------- */
32252 +/* top down parent and most free space */
32253 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
32256 + unsigned long long b;
32257 + aufs_bindex_t bindex, btop, bbot;
32258 + struct super_block *sb;
32259 + struct dentry *parent, *h_parent;
32260 + struct au_branch *br;
32262 + err = au_wbr_create_tdp(dentry, flags);
32263 + if (unlikely(err < 0))
32265 + parent = dget_parent(dentry);
32266 + btop = au_dbtop(parent);
32267 + bbot = au_dbtaildir(parent);
32268 + if (btop == bbot)
32269 + goto out_parent; /* success */
32271 + e2 = au_wbr_create_mfs(dentry, flags);
32273 + goto out_parent; /* success */
32275 + /* when the available size is equal, select upper one */
32276 + sb = dentry->d_sb;
32277 + br = au_sbr(sb, err);
32278 + b = br->br_wbr->wbr_bytes;
32279 + AuDbg("b%d, %llu\n", err, b);
32281 + for (bindex = btop; bindex <= bbot; bindex++) {
32282 + h_parent = au_h_dptr(parent, bindex);
32283 + if (!h_parent || d_is_negative(h_parent))
32286 + br = au_sbr(sb, bindex);
32287 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
32288 + b = br->br_wbr->wbr_bytes;
32290 + AuDbg("b%d, %llu\n", err, b);
32295 + err = au_wbr_nonopq(dentry, err);
32300 + AuDbg("b%d\n", err);
32304 +/* ---------------------------------------------------------------------- */
32307 + * - top down parent
32308 + * - most free space with parent
32309 + * - most free space round-robin regardless parent
32311 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
32314 + unsigned long long watermark;
32315 + struct super_block *sb;
32316 + struct au_branch *br;
32317 + struct au_wbr_mfs *mfs;
32319 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
32320 + if (unlikely(err < 0))
32323 + sb = dentry->d_sb;
32324 + br = au_sbr(sb, err);
32325 + mfs = &au_sbi(sb)->si_wbr_mfs;
32326 + mutex_lock(&mfs->mfs_lock);
32327 + watermark = mfs->mfsrr_watermark;
32328 + mutex_unlock(&mfs->mfs_lock);
32329 + if (br->br_wbr->wbr_bytes < watermark)
32330 + /* regardless the parent dir */
32331 + err = au_wbr_create_mfsrr(dentry, flags);
32334 + AuDbg("b%d\n", err);
32338 +/* ---------------------------------------------------------------------- */
32340 +/* policies for copyup */
32342 +/* top down parent */
32343 +static int au_wbr_copyup_tdp(struct dentry *dentry)
32345 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
32348 +/* bottom up parent */
32349 +static int au_wbr_copyup_bup(struct dentry *dentry)
32352 + aufs_bindex_t bindex, btop;
32353 + struct dentry *parent, *h_parent;
32354 + struct super_block *sb;
32357 + sb = dentry->d_sb;
32358 + parent = dget_parent(dentry);
32359 + btop = au_dbtop(parent);
32360 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
32361 + h_parent = au_h_dptr(parent, bindex);
32362 + if (!h_parent || d_is_negative(h_parent))
32365 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32372 + /* bottom up here */
32373 + if (unlikely(err < 0))
32374 + err = au_wbr_bu(sb, btop - 1);
32376 + AuDbg("b%d\n", err);
32381 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
32385 + err = au_wbr_bu(dentry->d_sb, btop);
32386 + AuDbg("b%d\n", err);
32388 + err = au_wbr_nonopq(dentry, err);
32390 + AuDbg("b%d\n", err);
32394 +static int au_wbr_copyup_bu(struct dentry *dentry)
32397 + aufs_bindex_t btop;
32399 + btop = au_dbtop(dentry);
32400 + err = au_wbr_do_copyup_bu(dentry, btop);
32404 +/* ---------------------------------------------------------------------- */
32406 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
32407 + [AuWbrCopyup_TDP] = {
32408 + .copyup = au_wbr_copyup_tdp
32410 + [AuWbrCopyup_BUP] = {
32411 + .copyup = au_wbr_copyup_bup
32413 + [AuWbrCopyup_BU] = {
32414 + .copyup = au_wbr_copyup_bu
32418 +struct au_wbr_create_operations au_wbr_create_ops[] = {
32419 + [AuWbrCreate_TDP] = {
32420 + .create = au_wbr_create_tdp
32422 + [AuWbrCreate_RR] = {
32423 + .create = au_wbr_create_rr,
32424 + .init = au_wbr_create_init_rr
32426 + [AuWbrCreate_MFS] = {
32427 + .create = au_wbr_create_mfs,
32428 + .init = au_wbr_create_init_mfs,
32429 + .fin = au_wbr_create_fin_mfs
32431 + [AuWbrCreate_MFSV] = {
32432 + .create = au_wbr_create_mfs,
32433 + .init = au_wbr_create_init_mfs,
32434 + .fin = au_wbr_create_fin_mfs
32436 + [AuWbrCreate_MFSRR] = {
32437 + .create = au_wbr_create_mfsrr,
32438 + .init = au_wbr_create_init_mfsrr,
32439 + .fin = au_wbr_create_fin_mfs
32441 + [AuWbrCreate_MFSRRV] = {
32442 + .create = au_wbr_create_mfsrr,
32443 + .init = au_wbr_create_init_mfsrr,
32444 + .fin = au_wbr_create_fin_mfs
32446 + [AuWbrCreate_PMFS] = {
32447 + .create = au_wbr_create_pmfs,
32448 + .init = au_wbr_create_init_mfs,
32449 + .fin = au_wbr_create_fin_mfs
32451 + [AuWbrCreate_PMFSV] = {
32452 + .create = au_wbr_create_pmfs,
32453 + .init = au_wbr_create_init_mfs,
32454 + .fin = au_wbr_create_fin_mfs
32456 + [AuWbrCreate_PMFSRR] = {
32457 + .create = au_wbr_create_pmfsrr,
32458 + .init = au_wbr_create_init_mfsrr,
32459 + .fin = au_wbr_create_fin_mfs
32461 + [AuWbrCreate_PMFSRRV] = {
32462 + .create = au_wbr_create_pmfsrr,
32463 + .init = au_wbr_create_init_mfsrr,
32464 + .fin = au_wbr_create_fin_mfs
32467 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
32468 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
32469 +++ linux/fs/aufs/whout.c 2016-10-09 16:55:36.496035060 +0200
32472 + * Copyright (C) 2005-2016 Junjiro R. Okajima
32474 + * This program, aufs is free software; you can redistribute it and/or modify
32475 + * it under the terms of the GNU General Public License as published by
32476 + * the Free Software Foundation; either version 2 of the License, or
32477 + * (at your option) any later version.
32479 + * This program is distributed in the hope that it will be useful,
32480 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32481 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32482 + * GNU General Public License for more details.
32484 + * You should have received a copy of the GNU General Public License
32485 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32489 + * whiteout for logical deletion and opaque directory
32494 +#define WH_MASK S_IRUGO
32497 + * If a directory contains this file, then it is opaque. We start with the
32498 + * .wh. flag so that it is blocked by lookup.
32500 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
32501 + sizeof(AUFS_WH_DIROPQ) - 1);
32504 + * generate whiteout name, which is NOT terminated by NULL.
32505 + * @name: original d_name.name
32506 + * @len: original d_name.len
32507 + * @wh: whiteout qstr
32508 + * returns zero when succeeds, otherwise error.
32509 + * succeeded value as wh->name should be freed by kfree().
32511 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
32515 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
32516 + return -ENAMETOOLONG;
32518 + wh->len = name->len + AUFS_WH_PFX_LEN;
32519 + p = kmalloc(wh->len, GFP_NOFS);
32522 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32523 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
32530 +/* ---------------------------------------------------------------------- */
32533 + * test if the @wh_name exists under @h_parent.
32534 + * @try_sio specifies the necessary of super-io.
32536 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
32539 + struct dentry *wh_dentry;
32542 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
32544 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
32545 + err = PTR_ERR(wh_dentry);
32546 + if (IS_ERR(wh_dentry)) {
32547 + if (err == -ENAMETOOLONG)
32553 + if (d_is_negative(wh_dentry))
32554 + goto out_wh; /* success */
32557 + if (d_is_reg(wh_dentry))
32558 + goto out_wh; /* success */
32561 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
32562 + wh_dentry, d_inode(wh_dentry)->i_mode);
32571 + * test if the @h_dentry sets opaque or not.
32573 +int au_diropq_test(struct dentry *h_dentry)
32576 + struct inode *h_dir;
32578 + h_dir = d_inode(h_dentry);
32579 + err = au_wh_test(h_dentry, &diropq_name,
32580 + au_test_h_perm_sio(h_dir, MAY_EXEC));
32585 + * returns a negative dentry whose name is unique and temporary.
32587 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32588 + struct qstr *prefix)
32590 + struct dentry *dentry;
32592 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
32594 + /* strict atomic_t is unnecessary here */
32595 + static unsigned short cnt;
32598 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
32601 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
32602 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
32603 + dentry = ERR_PTR(-ENAMETOOLONG);
32604 + if (unlikely(qs.len > NAME_MAX))
32606 + dentry = ERR_PTR(-ENOMEM);
32607 + name = kmalloc(qs.len + 1, GFP_NOFS);
32608 + if (unlikely(!name))
32612 + /* doubly whiteout-ed */
32613 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
32614 + p = name + AUFS_WH_PFX_LEN * 2;
32615 + memcpy(p, prefix->name, prefix->len);
32616 + p += prefix->len;
32618 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
32621 + for (i = 0; i < 3; i++) {
32622 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
32623 + dentry = au_sio_lkup_one(&qs, h_parent);
32624 + if (IS_ERR(dentry) || d_is_negative(dentry))
32628 + /* pr_warn("could not get random name\n"); */
32629 + dentry = ERR_PTR(-EEXIST);
32630 + AuDbg("%.*s\n", AuLNPair(&qs));
32634 + if (name != defname)
32635 + au_delayed_kfree(name);
32637 + AuTraceErrPtr(dentry);
32642 + * rename the @h_dentry on @br to the whiteouted temporary name.
32644 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
32647 + struct path h_path = {
32648 + .mnt = au_br_mnt(br)
32650 + struct inode *h_dir, *delegated;
32651 + struct dentry *h_parent;
32653 + h_parent = h_dentry->d_parent; /* dir inode is locked */
32654 + h_dir = d_inode(h_parent);
32655 + IMustLock(h_dir);
32657 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
32658 + err = PTR_ERR(h_path.dentry);
32659 + if (IS_ERR(h_path.dentry))
32662 + /* under the same dir, no need to lock_rename() */
32663 + delegated = NULL;
32664 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated);
32666 + if (unlikely(err == -EWOULDBLOCK)) {
32667 + pr_warn("cannot retry for NFSv4 delegation"
32668 + " for an internal rename\n");
32671 + dput(h_path.dentry);
32678 +/* ---------------------------------------------------------------------- */
32680 + * functions for removing a whiteout
32683 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
32686 + struct inode *delegated;
32689 + * forces superio when the dir has a sticky bit.
32690 + * this may be a violation of unix fs semantics.
32692 + force = (h_dir->i_mode & S_ISVTX)
32693 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32694 + delegated = NULL;
32695 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32696 + if (unlikely(err == -EWOULDBLOCK)) {
32697 + pr_warn("cannot retry for NFSv4 delegation"
32698 + " for an internal unlink\n");
32704 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32705 + struct dentry *dentry)
32709 + err = do_unlink_wh(h_dir, h_path);
32710 + if (!err && dentry)
32711 + au_set_dbwh(dentry, -1);
32716 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32717 + struct au_branch *br)
32720 + struct path h_path = {
32721 + .mnt = au_br_mnt(br)
32725 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32726 + if (IS_ERR(h_path.dentry))
32727 + err = PTR_ERR(h_path.dentry);
32729 + if (d_is_reg(h_path.dentry))
32730 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32731 + dput(h_path.dentry);
32737 +/* ---------------------------------------------------------------------- */
32739 + * initialize/clean whiteout for a branch
32742 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32746 + struct inode *delegated;
32748 + if (d_is_negative(whpath->dentry))
32752 + err = vfsub_rmdir(h_dir, whpath);
32754 + delegated = NULL;
32755 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32756 + if (unlikely(err == -EWOULDBLOCK)) {
32757 + pr_warn("cannot retry for NFSv4 delegation"
32758 + " for an internal unlink\n");
32762 + if (unlikely(err))
32763 + pr_warn("failed removing %pd (%d), ignored.\n",
32764 + whpath->dentry, err);
32767 +static int test_linkable(struct dentry *h_root)
32769 + struct inode *h_dir = d_inode(h_root);
32771 + if (h_dir->i_op->link)
32774 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32775 + h_root, au_sbtype(h_root->d_sb));
32779 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32780 +static int au_whdir(struct inode *h_dir, struct path *path)
32785 + if (d_is_negative(path->dentry)) {
32786 + int mode = S_IRWXU;
32788 + if (au_test_nfs(path->dentry->d_sb))
32790 + err = vfsub_mkdir(h_dir, path, mode);
32791 + } else if (d_is_dir(path->dentry))
32794 + pr_err("unknown %pd exists\n", path->dentry);
32799 +struct au_wh_base {
32800 + const struct qstr *name;
32801 + struct dentry *dentry;
32804 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
32805 + struct path *h_path)
32807 + h_path->dentry = base[AuBrWh_BASE].dentry;
32808 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32809 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32810 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32811 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32812 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32816 + * returns tri-state,
32817 + * minus: error, caller should print the message
32819 + * plus: error, caller should NOT print the message
32821 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
32822 + int do_plink, struct au_wh_base base[],
32823 + struct path *h_path)
32826 + struct inode *h_dir;
32828 + h_dir = d_inode(h_root);
32829 + h_path->dentry = base[AuBrWh_BASE].dentry;
32830 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32831 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32833 + err = test_linkable(h_root);
32834 + if (unlikely(err)) {
32839 + err = au_whdir(h_dir, h_path);
32840 + if (unlikely(err))
32842 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32844 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32845 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32846 + err = au_whdir(h_dir, h_path);
32847 + if (unlikely(err))
32849 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32856 + * for the moment, aufs supports the branch filesystem which does not support
32857 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
32858 + * copyup failed. finally, such filesystem will not be used as the writable
32861 + * returns tri-state, see above.
32863 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
32864 + int do_plink, struct au_wh_base base[],
32865 + struct path *h_path)
32868 + struct inode *h_dir;
32870 + WbrWhMustWriteLock(wbr);
32872 + err = test_linkable(h_root);
32873 + if (unlikely(err)) {
32879 + * todo: should this create be done in /sbin/mount.aufs helper?
32882 + h_dir = d_inode(h_root);
32883 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
32884 + h_path->dentry = base[AuBrWh_BASE].dentry;
32885 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
32886 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
32889 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
32890 + if (unlikely(err))
32893 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32895 + err = au_whdir(h_dir, h_path);
32896 + if (unlikely(err))
32898 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
32900 + au_wh_clean(h_dir, h_path, /*isdir*/1);
32901 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
32903 + h_path->dentry = base[AuBrWh_ORPH].dentry;
32904 + err = au_whdir(h_dir, h_path);
32905 + if (unlikely(err))
32907 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
32914 + * initialize the whiteout base file/dir for @br.
32916 +int au_wh_init(struct au_branch *br, struct super_block *sb)
32919 + const unsigned char do_plink
32920 + = !!au_opt_test(au_mntflags(sb), PLINK);
32921 + struct inode *h_dir;
32922 + struct path path = br->br_path;
32923 + struct dentry *h_root = path.dentry;
32924 + struct au_wbr *wbr = br->br_wbr;
32925 + static const struct qstr base_name[] = {
32926 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
32927 + sizeof(AUFS_BASE_NAME) - 1),
32928 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
32929 + sizeof(AUFS_PLINKDIR_NAME) - 1),
32930 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
32931 + sizeof(AUFS_ORPHDIR_NAME) - 1)
32933 + struct au_wh_base base[] = {
32934 + [AuBrWh_BASE] = {
32935 + .name = base_name + AuBrWh_BASE,
32938 + [AuBrWh_PLINK] = {
32939 + .name = base_name + AuBrWh_PLINK,
32942 + [AuBrWh_ORPH] = {
32943 + .name = base_name + AuBrWh_ORPH,
32949 + WbrWhMustWriteLock(wbr);
32951 + for (i = 0; i < AuBrWh_Last; i++) {
32952 + /* doubly whiteouted */
32953 + struct dentry *d;
32955 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
32956 + err = PTR_ERR(d);
32960 + base[i].dentry = d;
32962 + && wbr->wbr_wh[i]
32963 + && wbr->wbr_wh[i] != base[i].dentry);
32967 + for (i = 0; i < AuBrWh_Last; i++) {
32968 + dput(wbr->wbr_wh[i]);
32969 + wbr->wbr_wh[i] = NULL;
32973 + if (!au_br_writable(br->br_perm)) {
32974 + h_dir = d_inode(h_root);
32975 + au_wh_init_ro(h_dir, base, &path);
32976 + } else if (!au_br_wh_linkable(br->br_perm)) {
32977 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
32983 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
32989 + goto out; /* success */
32992 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
32993 + err, h_root, au_sbtype(h_root->d_sb));
32995 + for (i = 0; i < AuBrWh_Last; i++)
32996 + dput(base[i].dentry);
33000 +/* ---------------------------------------------------------------------- */
33002 + * whiteouts are all hard-linked usually.
33003 + * when its link count reaches a ceiling, we create a new whiteout base
33004 + * asynchronously.
33007 +struct reinit_br_wh {
33008 + struct super_block *sb;
33009 + struct au_branch *br;
33012 +static void reinit_br_wh(void *arg)
33015 + aufs_bindex_t bindex;
33016 + struct path h_path;
33017 + struct reinit_br_wh *a = arg;
33018 + struct au_wbr *wbr;
33019 + struct inode *dir, *delegated;
33020 + struct dentry *h_root;
33021 + struct au_hinode *hdir;
33024 + wbr = a->br->br_wbr;
33025 + /* big aufs lock */
33026 + si_noflush_write_lock(a->sb);
33027 + if (!au_br_writable(a->br->br_perm))
33029 + bindex = au_br_index(a->sb, a->br->br_id);
33030 + if (unlikely(bindex < 0))
33033 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
33034 + dir = d_inode(a->sb->s_root);
33035 + hdir = au_hi(dir, bindex);
33036 + h_root = au_h_dptr(a->sb->s_root, bindex);
33037 + AuDebugOn(h_root != au_br_dentry(a->br));
33039 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33040 + wbr_wh_write_lock(wbr);
33041 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
33044 + h_path.dentry = wbr->wbr_whbase;
33045 + h_path.mnt = au_br_mnt(a->br);
33046 + delegated = NULL;
33047 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
33049 + if (unlikely(err == -EWOULDBLOCK)) {
33050 + pr_warn("cannot retry for NFSv4 delegation"
33051 + " for an internal unlink\n");
33055 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
33058 + dput(wbr->wbr_whbase);
33059 + wbr->wbr_whbase = NULL;
33061 + err = au_wh_init(a->br, a->sb);
33062 + wbr_wh_write_unlock(wbr);
33063 + au_hn_inode_unlock(hdir);
33064 + di_read_unlock(a->sb->s_root, AuLock_IR);
33066 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
33070 + atomic_dec(&wbr->wbr_wh_running);
33071 + au_br_put(a->br);
33072 + si_write_unlock(a->sb);
33073 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
33074 + au_delayed_kfree(arg);
33075 + if (unlikely(err))
33076 + AuIOErr("err %d\n", err);
33079 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
33081 + int do_dec, wkq_err;
33082 + struct reinit_br_wh *arg;
33085 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
33088 + /* ignore ENOMEM */
33089 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
33092 + * dec(wh_running), kfree(arg) and dec(br_count)
33093 + * in reinit function
33098 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
33099 + if (unlikely(wkq_err)) {
33100 + atomic_dec(&br->br_wbr->wbr_wh_running);
33102 + au_delayed_kfree(arg);
33109 + atomic_dec(&br->br_wbr->wbr_wh_running);
33112 +/* ---------------------------------------------------------------------- */
33115 + * create the whiteout @wh.
33117 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
33118 + struct dentry *wh)
33121 + struct path h_path = {
33124 + struct au_branch *br;
33125 + struct au_wbr *wbr;
33126 + struct dentry *h_parent;
33127 + struct inode *h_dir, *delegated;
33129 + h_parent = wh->d_parent; /* dir inode is locked */
33130 + h_dir = d_inode(h_parent);
33131 + IMustLock(h_dir);
33133 + br = au_sbr(sb, bindex);
33134 + h_path.mnt = au_br_mnt(br);
33135 + wbr = br->br_wbr;
33136 + wbr_wh_read_lock(wbr);
33137 + if (wbr->wbr_whbase) {
33138 + delegated = NULL;
33139 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
33140 + if (unlikely(err == -EWOULDBLOCK)) {
33141 + pr_warn("cannot retry for NFSv4 delegation"
33142 + " for an internal link\n");
33145 + if (!err || err != -EMLINK)
33148 + /* link count full. re-initialize br_whbase. */
33149 + kick_reinit_br_wh(sb, br);
33152 + /* return this error in this context */
33153 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
33155 + au_fhsm_wrote(sb, bindex, /*force*/0);
33158 + wbr_wh_read_unlock(wbr);
33162 +/* ---------------------------------------------------------------------- */
33165 + * create or remove the diropq.
33167 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
33168 + unsigned int flags)
33170 + struct dentry *opq_dentry, *h_dentry;
33171 + struct super_block *sb;
33172 + struct au_branch *br;
33175 + sb = dentry->d_sb;
33176 + br = au_sbr(sb, bindex);
33177 + h_dentry = au_h_dptr(dentry, bindex);
33178 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
33179 + if (IS_ERR(opq_dentry))
33182 + if (au_ftest_diropq(flags, CREATE)) {
33183 + err = link_or_create_wh(sb, bindex, opq_dentry);
33185 + au_set_dbdiropq(dentry, bindex);
33186 + goto out; /* success */
33189 + struct path tmp = {
33190 + .dentry = opq_dentry,
33191 + .mnt = au_br_mnt(br)
33193 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
33195 + au_set_dbdiropq(dentry, -1);
33197 + dput(opq_dentry);
33198 + opq_dentry = ERR_PTR(err);
33201 + return opq_dentry;
33204 +struct do_diropq_args {
33205 + struct dentry **errp;
33206 + struct dentry *dentry;
33207 + aufs_bindex_t bindex;
33208 + unsigned int flags;
33211 +static void call_do_diropq(void *args)
33213 + struct do_diropq_args *a = args;
33214 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
33217 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33218 + unsigned int flags)
33220 + struct dentry *diropq, *h_dentry;
33222 + h_dentry = au_h_dptr(dentry, bindex);
33223 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
33224 + diropq = do_diropq(dentry, bindex, flags);
33227 + struct do_diropq_args args = {
33229 + .dentry = dentry,
33230 + .bindex = bindex,
33234 + wkq_err = au_wkq_wait(call_do_diropq, &args);
33235 + if (unlikely(wkq_err))
33236 + diropq = ERR_PTR(wkq_err);
33242 +/* ---------------------------------------------------------------------- */
33245 + * lookup whiteout dentry.
33246 + * @h_parent: lower parent dentry which must exist and be locked
33247 + * @base_name: name of dentry which will be whiteouted
33248 + * returns dentry for whiteout.
33250 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33251 + struct au_branch *br)
33254 + struct qstr wh_name;
33255 + struct dentry *wh_dentry;
33257 + err = au_wh_name_alloc(&wh_name, base_name);
33258 + wh_dentry = ERR_PTR(err);
33260 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
33261 + au_delayed_kfree(wh_name.name);
33263 + return wh_dentry;
33267 + * link/create a whiteout for @dentry on @bindex.
33269 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33270 + struct dentry *h_parent)
33272 + struct dentry *wh_dentry;
33273 + struct super_block *sb;
33276 + sb = dentry->d_sb;
33277 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
33278 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
33279 + err = link_or_create_wh(sb, bindex, wh_dentry);
33281 + au_set_dbwh(dentry, bindex);
33282 + au_fhsm_wrote(sb, bindex, /*force*/0);
33285 + wh_dentry = ERR_PTR(err);
33289 + return wh_dentry;
33292 +/* ---------------------------------------------------------------------- */
33294 +/* Delete all whiteouts in this directory on branch bindex. */
33295 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
33296 + aufs_bindex_t bindex, struct au_branch *br)
33299 + unsigned long ul, n;
33300 + struct qstr wh_name;
33302 + struct hlist_head *head;
33303 + struct au_vdir_wh *pos;
33304 + struct au_vdir_destr *str;
33307 + p = (void *)__get_free_page(GFP_NOFS);
33308 + wh_name.name = p;
33309 + if (unlikely(!wh_name.name))
33313 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
33314 + p += AUFS_WH_PFX_LEN;
33315 + n = whlist->nh_num;
33316 + head = whlist->nh_head;
33317 + for (ul = 0; !err && ul < n; ul++, head++) {
33318 + hlist_for_each_entry(pos, head, wh_hash) {
33319 + if (pos->wh_bindex != bindex)
33322 + str = &pos->wh_str;
33323 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
33324 + memcpy(p, str->name, str->len);
33325 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
33326 + err = unlink_wh_name(h_dentry, &wh_name, br);
33331 + AuIOErr("whiteout name too long %.*s\n",
33332 + str->len, str->name);
33337 + au_delayed_free_page((unsigned long)wh_name.name);
33343 +struct del_wh_children_args {
33345 + struct dentry *h_dentry;
33346 + struct au_nhash *whlist;
33347 + aufs_bindex_t bindex;
33348 + struct au_branch *br;
33351 +static void call_del_wh_children(void *args)
33353 + struct del_wh_children_args *a = args;
33354 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
33357 +/* ---------------------------------------------------------------------- */
33359 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
33361 + struct au_whtmp_rmdir *whtmp;
33363 + unsigned int rdhash;
33365 + SiMustAnyLock(sb);
33367 + whtmp = kzalloc(sizeof(*whtmp), gfp);
33368 + if (unlikely(!whtmp)) {
33369 + whtmp = ERR_PTR(-ENOMEM);
33373 + /* no estimation for dir size */
33374 + rdhash = au_sbi(sb)->si_rdhash;
33376 + rdhash = AUFS_RDHASH_DEF;
33377 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
33378 + if (unlikely(err)) {
33379 + au_delayed_kfree(whtmp);
33380 + whtmp = ERR_PTR(err);
33387 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
33390 + au_br_put(whtmp->br);
33391 + dput(whtmp->wh_dentry);
33392 + iput(whtmp->dir);
33393 + au_nhash_wh_free(&whtmp->whlist);
33394 + au_delayed_kfree(whtmp);
33398 + * rmdir the whiteouted temporary named dir @h_dentry.
33399 + * @whlist: whiteouted children.
33401 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33402 + struct dentry *wh_dentry, struct au_nhash *whlist)
33405 + unsigned int h_nlink;
33406 + struct path h_tmp;
33407 + struct inode *wh_inode, *h_dir;
33408 + struct au_branch *br;
33410 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
33411 + IMustLock(h_dir);
33413 + br = au_sbr(dir->i_sb, bindex);
33414 + wh_inode = d_inode(wh_dentry);
33415 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
33418 + * someone else might change some whiteouts while we were sleeping.
33419 + * it means this whlist may have an obsoleted entry.
33421 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
33422 + err = del_wh_children(wh_dentry, whlist, bindex, br);
33425 + struct del_wh_children_args args = {
33427 + .h_dentry = wh_dentry,
33428 + .whlist = whlist,
33429 + .bindex = bindex,
33433 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
33434 + if (unlikely(wkq_err))
33437 + inode_unlock(wh_inode);
33440 + h_tmp.dentry = wh_dentry;
33441 + h_tmp.mnt = au_br_mnt(br);
33442 + h_nlink = h_dir->i_nlink;
33443 + err = vfsub_rmdir(h_dir, &h_tmp);
33444 + /* some fs doesn't change the parent nlink in some cases */
33445 + h_nlink -= h_dir->i_nlink;
33449 + if (au_ibtop(dir) == bindex) {
33450 + /* todo: dir->i_mutex is necessary */
33451 + au_cpup_attr_timesizes(dir);
33453 + vfsub_drop_nlink(dir);
33455 + return 0; /* success */
33458 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
33462 +static void call_rmdir_whtmp(void *args)
33465 + aufs_bindex_t bindex;
33466 + struct au_whtmp_rmdir *a = args;
33467 + struct super_block *sb;
33468 + struct dentry *h_parent;
33469 + struct inode *h_dir;
33470 + struct au_hinode *hdir;
33472 + /* rmdir by nfsd may cause deadlock with this i_mutex */
33473 + /* inode_lock(a->dir); */
33475 + sb = a->dir->i_sb;
33476 + si_read_lock(sb, !AuLock_FLUSH);
33477 + if (!au_br_writable(a->br->br_perm))
33479 + bindex = au_br_index(sb, a->br->br_id);
33480 + if (unlikely(bindex < 0))
33484 + ii_write_lock_parent(a->dir);
33485 + h_parent = dget_parent(a->wh_dentry);
33486 + h_dir = d_inode(h_parent);
33487 + hdir = au_hi(a->dir, bindex);
33488 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
33489 + if (unlikely(err))
33491 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33492 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
33495 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
33496 + au_hn_inode_unlock(hdir);
33497 + vfsub_mnt_drop_write(au_br_mnt(a->br));
33501 + ii_write_unlock(a->dir);
33503 + /* inode_unlock(a->dir); */
33504 + au_whtmp_rmdir_free(a);
33505 + si_read_unlock(sb);
33506 + au_nwt_done(&au_sbi(sb)->si_nowait);
33507 + if (unlikely(err))
33508 + AuIOErr("err %d\n", err);
33511 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33512 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
33515 + struct super_block *sb;
33519 + /* all post-process will be done in do_rmdir_whtmp(). */
33521 + args->dir = au_igrab(dir);
33522 + args->br = au_sbr(sb, bindex);
33523 + au_br_get(args->br);
33524 + args->wh_dentry = dget(wh_dentry);
33525 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
33526 + if (unlikely(wkq_err)) {
33527 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
33528 + au_whtmp_rmdir_free(args);
33531 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
33532 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
33533 +++ linux/fs/aufs/whout.h 2016-10-09 16:55:36.496035060 +0200
33536 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33538 + * This program, aufs is free software; you can redistribute it and/or modify
33539 + * it under the terms of the GNU General Public License as published by
33540 + * the Free Software Foundation; either version 2 of the License, or
33541 + * (at your option) any later version.
33543 + * This program is distributed in the hope that it will be useful,
33544 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33545 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33546 + * GNU General Public License for more details.
33548 + * You should have received a copy of the GNU General Public License
33549 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33553 + * whiteout for logical deletion and opaque directory
33556 +#ifndef __AUFS_WHOUT_H__
33557 +#define __AUFS_WHOUT_H__
33564 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
33565 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
33566 +int au_diropq_test(struct dentry *h_dentry);
33568 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
33569 + struct qstr *prefix);
33570 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
33571 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33572 + struct dentry *dentry);
33573 +int au_wh_init(struct au_branch *br, struct super_block *sb);
33575 +/* diropq flags */
33576 +#define AuDiropq_CREATE 1
33577 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
33578 +#define au_fset_diropq(flags, name) \
33579 + do { (flags) |= AuDiropq_##name; } while (0)
33580 +#define au_fclr_diropq(flags, name) \
33581 + do { (flags) &= ~AuDiropq_##name; } while (0)
33583 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33584 + unsigned int flags);
33585 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33586 + struct au_branch *br);
33587 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33588 + struct dentry *h_parent);
33590 +/* real rmdir for the whiteout-ed dir */
33591 +struct au_whtmp_rmdir {
33592 + struct inode *dir;
33593 + struct au_branch *br;
33594 + struct dentry *wh_dentry;
33595 + struct au_nhash whlist;
33598 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
33599 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
33600 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33601 + struct dentry *wh_dentry, struct au_nhash *whlist);
33602 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33603 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
33605 +/* ---------------------------------------------------------------------- */
33607 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
33608 + aufs_bindex_t bindex)
33610 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
33613 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
33615 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
33618 +#endif /* __KERNEL__ */
33619 +#endif /* __AUFS_WHOUT_H__ */
33620 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
33621 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
33622 +++ linux/fs/aufs/wkq.c 2016-10-09 16:55:36.496035060 +0200
33625 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33627 + * This program, aufs is free software; you can redistribute it and/or modify
33628 + * it under the terms of the GNU General Public License as published by
33629 + * the Free Software Foundation; either version 2 of the License, or
33630 + * (at your option) any later version.
33632 + * This program is distributed in the hope that it will be useful,
33633 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33634 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33635 + * GNU General Public License for more details.
33637 + * You should have received a copy of the GNU General Public License
33638 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33642 + * workqueue for asynchronous/super-io operations
33643 + * todo: try new dredential scheme
33646 +#include <linux/module.h>
33649 +/* internal workqueue named AUFS_WKQ_NAME */
33651 +static struct workqueue_struct *au_wkq;
33653 +struct au_wkinfo {
33654 + struct work_struct wk;
33655 + struct kobject *kobj;
33657 + unsigned int flags; /* see wkq.h */
33659 + au_wkq_func_t func;
33662 + struct completion *comp;
33665 +/* ---------------------------------------------------------------------- */
33667 +static void wkq_func(struct work_struct *wk)
33669 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
33671 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
33672 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
33674 + wkinfo->func(wkinfo->args);
33675 + if (au_ftest_wkq(wkinfo->flags, WAIT))
33676 + complete(wkinfo->comp);
33678 + kobject_put(wkinfo->kobj);
33679 + module_put(THIS_MODULE); /* todo: ?? */
33680 + au_delayed_kfree(wkinfo);
33685 + * Since struct completion is large, try allocating it dynamically.
33687 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
33688 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33690 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33692 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33694 + init_completion(*comp);
33695 + wkinfo->comp = *comp;
33701 +static void au_wkq_comp_free(struct completion *comp)
33703 + au_delayed_kfree(comp);
33709 +#define AuWkqCompDeclare(name) \
33710 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33711 + struct completion *comp = &_ ## name
33713 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33715 + wkinfo->comp = *comp;
33719 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33723 +#endif /* 4KSTACKS */
33725 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33727 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33728 + if (au_wkq_test()) {
33729 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33730 + " due to a dead dir by UDBA?\n");
33731 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33734 + au_dbg_verify_kthread();
33736 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33737 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33738 + queue_work(au_wkq, &wkinfo->wk);
33740 + INIT_WORK(&wkinfo->wk, wkq_func);
33741 + schedule_work(&wkinfo->wk);
33746 + * Be careful. It is easy to make deadlock happen.
33747 + * processA: lock, wkq and wait
33748 + * processB: wkq and wait, lock in wkq
33751 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33754 + AuWkqCompDeclare(comp);
33755 + struct au_wkinfo wkinfo = {
33761 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33763 + au_wkq_run(&wkinfo);
33764 + /* no timeout, no interrupt */
33765 + wait_for_completion(wkinfo.comp);
33766 + au_wkq_comp_free(comp);
33767 + destroy_work_on_stack(&wkinfo.wk);
33775 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33776 + * problem in a concurrent umounting.
33778 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33779 + unsigned int flags)
33782 + struct au_wkinfo *wkinfo;
33784 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
33787 + * wkq_func() must free this wkinfo.
33788 + * it highly depends upon the implementation of workqueue.
33791 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
33793 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
33794 + wkinfo->flags = flags & ~AuWkq_WAIT;
33795 + wkinfo->func = func;
33796 + wkinfo->args = args;
33797 + wkinfo->comp = NULL;
33798 + kobject_get(wkinfo->kobj);
33799 + __module_get(THIS_MODULE); /* todo: ?? */
33801 + au_wkq_run(wkinfo);
33804 + au_nwt_done(&au_sbi(sb)->si_nowait);
33810 +/* ---------------------------------------------------------------------- */
33812 +void au_nwt_init(struct au_nowait_tasks *nwt)
33814 + atomic_set(&nwt->nw_len, 0);
33815 + /* smp_mb(); */ /* atomic_set */
33816 + init_waitqueue_head(&nwt->nw_wq);
33819 +void au_wkq_fin(void)
33821 + destroy_workqueue(au_wkq);
33824 +int __init au_wkq_init(void)
33829 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
33830 + if (IS_ERR(au_wkq))
33831 + err = PTR_ERR(au_wkq);
33832 + else if (!au_wkq)
33837 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
33838 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
33839 +++ linux/fs/aufs/wkq.h 2016-10-09 16:55:36.496035060 +0200
33842 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33844 + * This program, aufs is free software; you can redistribute it and/or modify
33845 + * it under the terms of the GNU General Public License as published by
33846 + * the Free Software Foundation; either version 2 of the License, or
33847 + * (at your option) any later version.
33849 + * This program is distributed in the hope that it will be useful,
33850 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33851 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33852 + * GNU General Public License for more details.
33854 + * You should have received a copy of the GNU General Public License
33855 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33859 + * workqueue for asynchronous/super-io operations
33860 + * todo: try new credentials management scheme
33863 +#ifndef __AUFS_WKQ_H__
33864 +#define __AUFS_WKQ_H__
33868 +#include <linux/percpu_counter.h>
33870 +struct super_block;
33872 +/* ---------------------------------------------------------------------- */
33875 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
33877 +struct au_nowait_tasks {
33879 + wait_queue_head_t nw_wq;
33882 +/* ---------------------------------------------------------------------- */
33884 +typedef void (*au_wkq_func_t)(void *args);
33887 +#define AuWkq_WAIT 1
33888 +#define AuWkq_NEST (1 << 1)
33889 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
33890 +#define au_fset_wkq(flags, name) \
33891 + do { (flags) |= AuWkq_##name; } while (0)
33892 +#define au_fclr_wkq(flags, name) \
33893 + do { (flags) &= ~AuWkq_##name; } while (0)
33895 +#ifndef CONFIG_AUFS_HNOTIFY
33897 +#define AuWkq_NEST 0
33901 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
33902 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33903 + unsigned int flags);
33904 +void au_nwt_init(struct au_nowait_tasks *nwt);
33905 +int __init au_wkq_init(void);
33906 +void au_wkq_fin(void);
33908 +/* ---------------------------------------------------------------------- */
33910 +static inline int au_wkq_test(void)
33912 + return current->flags & PF_WQ_WORKER;
33915 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
33917 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
33920 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
33922 + if (atomic_dec_and_test(&nwt->nw_len))
33923 + wake_up_all(&nwt->nw_wq);
33926 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
33928 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
33932 +#endif /* __KERNEL__ */
33933 +#endif /* __AUFS_WKQ_H__ */
33934 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
33935 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
33936 +++ linux/fs/aufs/xattr.c 2016-10-09 16:55:36.496035060 +0200
33939 + * Copyright (C) 2014-2016 Junjiro R. Okajima
33941 + * This program, aufs is free software; you can redistribute it and/or modify
33942 + * it under the terms of the GNU General Public License as published by
33943 + * the Free Software Foundation; either version 2 of the License, or
33944 + * (at your option) any later version.
33946 + * This program is distributed in the hope that it will be useful,
33947 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33948 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33949 + * GNU General Public License for more details.
33951 + * You should have received a copy of the GNU General Public License
33952 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33956 + * handling xattr functions
33959 +#include <linux/xattr.h>
33962 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
33964 + if (!ignore_flags)
33972 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
33977 +#define cmp(brattr, prefix) do { \
33978 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
33979 + XATTR_##prefix##_PREFIX_LEN)) { \
33980 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
33986 + cmp(SEC, SECURITY);
33987 + cmp(SYS, SYSTEM);
33988 + cmp(TR, TRUSTED);
33992 + if (ignore_flags & AuBrAttr_ICEX_OTH)
33999 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
34001 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
34002 + char *name, char **buf, unsigned int ignore_flags,
34003 + unsigned int verbose)
34007 + struct inode *h_idst;
34009 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
34011 + if (unlikely(err <= 0)) {
34012 + if (err == -ENODATA
34013 + || (err == -EOPNOTSUPP
34014 + && ((ignore_flags & au_xattr_out_of_list)
34015 + || (au_test_nfs_noacl(d_inode(h_src))
34016 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
34018 + XATTR_NAME_POSIX_ACL_DEFAULT))))
34021 + if (err && (verbose || au_debug_test()))
34022 + pr_err("%s, err %d\n", name, err);
34026 + /* unlock it temporary */
34027 + h_idst = d_inode(h_dst);
34028 + inode_unlock(h_idst);
34029 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
34030 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34031 + if (unlikely(err)) {
34032 + if (verbose || au_debug_test())
34033 + pr_err("%s, err %d\n", name, err);
34034 + err = au_xattr_ignore(err, name, ignore_flags);
34041 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
34042 + unsigned int verbose)
34044 + int err, unlocked, acl_access, acl_default;
34046 + struct inode *h_isrc, *h_idst;
34047 + char *value, *p, *o, *e;
34049 + /* try stopping to update the source inode while we are referencing */
34050 + /* there should not be the parent-child relationship between them */
34051 + h_isrc = d_inode(h_src);
34052 + h_idst = d_inode(h_dst);
34053 + inode_unlock(h_idst);
34054 + inode_lock_nested(h_isrc, AuLsc_I_CHILD);
34055 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34058 + /* some filesystems don't list POSIX ACL, for example tmpfs */
34059 + ssz = vfs_listxattr(h_src, NULL, 0);
34061 + if (unlikely(err < 0)) {
34063 + if (err == -ENODATA
34064 + || err == -EOPNOTSUPP)
34065 + err = 0; /* ignore */
34074 + p = kmalloc(ssz, GFP_NOFS);
34076 + if (unlikely(!p))
34078 + err = vfs_listxattr(h_src, p, ssz);
34080 + inode_unlock(h_isrc);
34082 + AuDbg("err %d, ssz %zd\n", err, ssz);
34083 + if (unlikely(err < 0))
34091 + while (!err && p < e) {
34092 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
34093 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
34094 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
34095 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
34097 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
34099 + p += strlen(p) + 1;
34102 + ignore_flags |= au_xattr_out_of_list;
34103 + if (!err && !acl_access) {
34104 + err = au_do_cpup_xattr(h_dst, h_src,
34105 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
34106 + ignore_flags, verbose);
34109 + if (!err && !acl_default) {
34110 + err = au_do_cpup_xattr(h_dst, h_src,
34111 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
34112 + ignore_flags, verbose);
34117 + au_delayed_kfree(value);
34121 + au_delayed_kfree(o);
34124 + inode_unlock(h_isrc);
34129 +/* ---------------------------------------------------------------------- */
34136 +struct au_lgxattr {
34144 + const char *name;
34151 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
34154 + struct path h_path;
34155 + struct super_block *sb;
34157 + sb = dentry->d_sb;
34158 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
34159 + if (unlikely(err))
34161 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
34162 + if (unlikely(err))
34164 + if (unlikely(!h_path.dentry))
34165 + /* illegally overlapped or something */
34166 + goto out_di; /* pretending success */
34168 + /* always topmost entry only */
34169 + switch (arg->type) {
34170 + case AU_XATTR_LIST:
34171 + err = vfs_listxattr(h_path.dentry,
34172 + arg->u.list.list, arg->u.list.size);
34174 + case AU_XATTR_GET:
34175 + AuDebugOn(d_is_negative(h_path.dentry));
34176 + err = vfs_getxattr(h_path.dentry,
34177 + arg->u.get.name, arg->u.get.value,
34178 + arg->u.get.size);
34183 + di_read_unlock(dentry, AuLock_IR);
34185 + si_read_unlock(sb);
34191 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
34193 + struct au_lgxattr arg = {
34194 + .type = AU_XATTR_LIST,
34201 + return au_lgxattr(dentry, &arg);
34204 +ssize_t aufs_getxattr(struct dentry *dentry, struct inode *inode __maybe_unused,
34205 + const char *name, void *value, size_t size)
34207 + struct au_lgxattr arg = {
34208 + .type = AU_XATTR_GET,
34216 + return au_lgxattr(dentry, &arg);
34219 +int aufs_setxattr(struct dentry *dentry, struct inode *inode, const char *name,
34220 + const void *value, size_t size, int flags)
34222 + struct au_srxattr arg = {
34223 + .type = AU_XATTR_SET,
34232 + return au_srxattr(dentry, inode, &arg);
34235 +int aufs_removexattr(struct dentry *dentry, const char *name)
34237 + struct au_srxattr arg = {
34238 + .type = AU_XATTR_REMOVE,
34244 + return au_srxattr(dentry, d_inode(dentry), &arg);
34247 +/* ---------------------------------------------------------------------- */
34250 +static size_t au_xattr_list(struct dentry *dentry, char *list, size_t list_size,
34251 + const char *name, size_t name_len, int type)
34253 + return aufs_listxattr(dentry, list, list_size);
34256 +static int au_xattr_get(struct dentry *dentry, const char *name, void *buffer,
34257 + size_t size, int type)
34259 + return aufs_getxattr(dentry, name, buffer, size);
34262 +static int au_xattr_set(struct dentry *dentry, const char *name,
34263 + const void *value, size_t size, int flags, int type)
34265 + return aufs_setxattr(dentry, name, value, size, flags);
34268 +static const struct xattr_handler au_xattr_handler = {
34269 + /* no prefix, no flags */
34270 + .list = au_xattr_list,
34271 + .get = au_xattr_get,
34272 + .set = au_xattr_set
34273 + /* why no remove? */
34276 +static const struct xattr_handler *au_xattr_handlers[] = {
34277 + &au_xattr_handler
34280 +void au_xattr_init(struct super_block *sb)
34282 + /* sb->s_xattr = au_xattr_handlers; */
34285 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
34286 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
34287 +++ linux/fs/aufs/xino.c 2016-10-09 16:55:36.496035060 +0200
34290 + * Copyright (C) 2005-2016 Junjiro R. Okajima
34292 + * This program, aufs is free software; you can redistribute it and/or modify
34293 + * it under the terms of the GNU General Public License as published by
34294 + * the Free Software Foundation; either version 2 of the License, or
34295 + * (at your option) any later version.
34297 + * This program is distributed in the hope that it will be useful,
34298 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34299 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34300 + * GNU General Public License for more details.
34302 + * You should have received a copy of the GNU General Public License
34303 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34307 + * external inode number translation table and bitmap
34310 +#include <linux/seq_file.h>
34311 +#include <linux/statfs.h>
34314 +/* todo: unnecessary to support mmap_sem since kernel-space? */
34315 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
34319 + mm_segment_t oldfs;
34326 + oldfs = get_fs();
34327 + set_fs(KERNEL_DS);
34329 + /* todo: signal_pending? */
34330 + err = func(file, buf.u, size, pos);
34331 + } while (err == -EAGAIN || err == -EINTR);
34334 +#if 0 /* reserved for future use */
34336 + fsnotify_access(file->f_path.dentry);
34342 +/* ---------------------------------------------------------------------- */
34344 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34345 + size_t size, loff_t *pos);
34347 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
34348 + size_t size, loff_t *pos)
34351 + mm_segment_t oldfs;
34354 + const char __user *u;
34357 + const int prevent_endless = 10;
34361 + oldfs = get_fs();
34362 + set_fs(KERNEL_DS);
34364 + err = func(file, buf.u, size, pos);
34365 + if (err == -EINTR
34366 + && !au_wkq_test()
34367 + && fatal_signal_pending(current)) {
34369 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
34370 + BUG_ON(err == -EINTR);
34371 + oldfs = get_fs();
34372 + set_fs(KERNEL_DS);
34374 + } while (i++ < prevent_endless
34375 + && (err == -EAGAIN || err == -EINTR));
34378 +#if 0 /* reserved for future use */
34380 + fsnotify_modify(file->f_path.dentry);
34386 +struct do_xino_fwrite_args {
34388 + vfs_writef_t func;
34389 + struct file *file;
34395 +static void call_do_xino_fwrite(void *args)
34397 + struct do_xino_fwrite_args *a = args;
34398 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
34401 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34402 + size_t size, loff_t *pos)
34406 + struct do_xino_fwrite_args args = {
34416 + * it breaks RLIMIT_FSIZE and normal user's limit,
34417 + * users should care about quota and real 'filesystem full.'
34419 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
34420 + if (unlikely(wkq_err))
34426 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
34427 + size_t size, loff_t *pos)
34431 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
34433 + err = do_xino_fwrite(func, file, buf, size, pos);
34436 + err = xino_fwrite_wkq(func, file, buf, size, pos);
34441 +/* ---------------------------------------------------------------------- */
34444 + * create a new xinofile at the same place/path as @base_file.
34446 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
34448 + struct file *file;
34449 + struct dentry *base, *parent;
34450 + struct inode *dir, *delegated;
34451 + struct qstr *name;
34452 + struct path path;
34455 + base = base_file->f_path.dentry;
34456 + parent = base->d_parent; /* dir inode is locked */
34457 + dir = d_inode(parent);
34460 + file = ERR_PTR(-EINVAL);
34461 + name = &base->d_name;
34462 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
34463 + if (IS_ERR(path.dentry)) {
34464 + file = (void *)path.dentry;
34465 + pr_err("%pd lookup err %ld\n",
34466 + base, PTR_ERR(path.dentry));
34470 + /* no need to mnt_want_write() since we call dentry_open() later */
34471 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
34472 + if (unlikely(err)) {
34473 + file = ERR_PTR(err);
34474 + pr_err("%pd create err %d\n", base, err);
34478 + path.mnt = base_file->f_path.mnt;
34479 + file = vfsub_dentry_open(&path,
34480 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34481 + /* | __FMODE_NONOTIFY */);
34482 + if (IS_ERR(file)) {
34483 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
34487 + delegated = NULL;
34488 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
34489 + if (unlikely(err == -EWOULDBLOCK)) {
34490 + pr_warn("cannot retry for NFSv4 delegation"
34491 + " for an internal unlink\n");
34494 + if (unlikely(err)) {
34495 + pr_err("%pd unlink err %d\n", base, err);
34500 + /* no one can touch copy_src xino */
34501 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
34502 + if (unlikely(err)) {
34503 + pr_err("%pd copy err %d\n", base, err);
34507 + goto out_dput; /* success */
34511 + file = ERR_PTR(err);
34513 + dput(path.dentry);
34518 +struct au_xino_lock_dir {
34519 + struct au_hinode *hdir;
34520 + struct dentry *parent;
34521 + struct inode *dir;
34524 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
34525 + struct au_xino_lock_dir *ldir)
34527 + aufs_bindex_t brid, bindex;
34529 + ldir->hdir = NULL;
34531 + brid = au_xino_brid(sb);
34533 + bindex = au_br_index(sb, brid);
34534 + if (bindex >= 0) {
34535 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
34536 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
34538 + ldir->parent = dget_parent(xino->f_path.dentry);
34539 + ldir->dir = d_inode(ldir->parent);
34540 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
34544 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
34547 + au_hn_inode_unlock(ldir->hdir);
34549 + inode_unlock(ldir->dir);
34550 + dput(ldir->parent);
34554 +/* ---------------------------------------------------------------------- */
34556 +/* trucate xino files asynchronously */
34558 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
34561 + unsigned long jiffy;
34563 + aufs_bindex_t bi, bbot;
34564 + struct kstatfs *st;
34565 + struct au_branch *br;
34566 + struct file *new_xino, *file;
34567 + struct super_block *h_sb;
34568 + struct au_xino_lock_dir ldir;
34571 + st = kmalloc(sizeof(*st), GFP_NOFS);
34572 + if (unlikely(!st))
34576 + bbot = au_sbbot(sb);
34577 + if (unlikely(bindex < 0 || bbot < bindex))
34579 + br = au_sbr(sb, bindex);
34580 + file = br->br_xino.xi_file;
34584 + err = vfs_statfs(&file->f_path, st);
34585 + if (unlikely(err))
34586 + AuErr1("statfs err %d, ignored\n", err);
34588 + blocks = file_inode(file)->i_blocks;
34589 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34590 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
34592 + au_xino_lock_dir(sb, file, &ldir);
34593 + /* mnt_want_write() is unnecessary here */
34594 + new_xino = au_xino_create2(file, file);
34595 + au_xino_unlock_dir(&ldir);
34596 + err = PTR_ERR(new_xino);
34597 + if (IS_ERR(new_xino)) {
34598 + pr_err("err %d, ignored\n", err);
34603 + br->br_xino.xi_file = new_xino;
34605 + h_sb = au_br_sb(br);
34606 + for (bi = 0; bi <= bbot; bi++) {
34607 + if (unlikely(bi == bindex))
34609 + br = au_sbr(sb, bi);
34610 + if (au_br_sb(br) != h_sb)
34613 + fput(br->br_xino.xi_file);
34614 + br->br_xino.xi_file = new_xino;
34615 + get_file(new_xino);
34618 + err = vfs_statfs(&new_xino->f_path, st);
34620 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34621 + bindex, (u64)file_inode(new_xino)->i_blocks,
34622 + st->f_bfree, st->f_blocks);
34623 + if (file_inode(new_xino)->i_blocks < blocks)
34624 + au_sbi(sb)->si_xino_jiffy = jiffy;
34626 + AuErr1("statfs err %d, ignored\n", err);
34629 + au_delayed_kfree(st);
34634 +struct xino_do_trunc_args {
34635 + struct super_block *sb;
34636 + struct au_branch *br;
34639 +static void xino_do_trunc(void *_args)
34641 + struct xino_do_trunc_args *args = _args;
34642 + struct super_block *sb;
34643 + struct au_branch *br;
34644 + struct inode *dir;
34646 + aufs_bindex_t bindex;
34650 + dir = d_inode(sb->s_root);
34653 + si_noflush_write_lock(sb);
34654 + ii_read_lock_parent(dir);
34655 + bindex = au_br_index(sb, br->br_id);
34656 + err = au_xino_trunc(sb, bindex);
34657 + ii_read_unlock(dir);
34658 + if (unlikely(err))
34659 + pr_warn("err b%d, (%d)\n", bindex, err);
34660 + atomic_dec(&br->br_xino_running);
34662 + si_write_unlock(sb);
34663 + au_nwt_done(&au_sbi(sb)->si_nowait);
34664 + au_delayed_kfree(args);
34667 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
34670 + struct kstatfs st;
34671 + struct au_sbinfo *sbinfo;
34673 + /* todo: si_xino_expire and the ratio should be customizable */
34674 + sbinfo = au_sbi(sb);
34675 + if (time_before(jiffies,
34676 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
34679 + /* truncation border */
34680 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
34681 + if (unlikely(err)) {
34682 + AuErr1("statfs err %d, ignored\n", err);
34685 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
34691 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
34693 + struct xino_do_trunc_args *args;
34696 + if (!xino_trunc_test(sb, br))
34699 + if (atomic_inc_return(&br->br_xino_running) > 1)
34702 + /* lock and kfree() will be called in trunc_xino() */
34703 + args = kmalloc(sizeof(*args), GFP_NOFS);
34704 + if (unlikely(!args)) {
34705 + AuErr1("no memory\n");
34712 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
34714 + return; /* success */
34716 + pr_err("wkq %d\n", wkq_err);
34718 + au_delayed_kfree(args);
34721 + atomic_dec(&br->br_xino_running);
34724 +/* ---------------------------------------------------------------------- */
34726 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34727 + ino_t h_ino, ino_t ino)
34733 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34734 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34737 + pos *= sizeof(ino);
34738 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34739 + if (sz == sizeof(ino))
34740 + return 0; /* success */
34742 + AuIOErr("write failed (%zd)\n", sz);
34747 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34748 + * at the position of @h_ino.
34749 + * even if @ino is zero, it is written to the xinofile and means no entry.
34750 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34751 + * try truncating it.
34753 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34757 + unsigned int mnt_flags;
34758 + struct au_branch *br;
34760 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34761 + || ((loff_t)-1) > 0);
34762 + SiMustAnyLock(sb);
34764 + mnt_flags = au_mntflags(sb);
34765 + if (!au_opt_test(mnt_flags, XINO))
34768 + br = au_sbr(sb, bindex);
34769 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34772 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34773 + && au_test_fs_trunc_xino(au_br_sb(br)))
34774 + xino_try_trunc(sb, br);
34775 + return 0; /* success */
34778 + AuIOErr("write failed (%d)\n", err);
34782 +/* ---------------------------------------------------------------------- */
34784 +/* aufs inode number bitmap */
34786 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
34787 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
34791 + AuDebugOn(bit < 0 || page_bits <= bit);
34792 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
34796 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
34798 + AuDebugOn(ino < AUFS_FIRST_INO);
34799 + ino -= AUFS_FIRST_INO;
34800 + *pindex = ino / page_bits;
34801 + *bit = ino % page_bits;
34804 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
34809 + struct au_sbinfo *sbinfo;
34810 + struct file *xib;
34811 + unsigned long *p;
34813 + sbinfo = au_sbi(sb);
34814 + MtxMustLock(&sbinfo->si_xib_mtx);
34815 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
34816 + || !au_opt_test(sbinfo->si_mntflags, XINO));
34818 + if (pindex == sbinfo->si_xib_last_pindex)
34821 + xib = sbinfo->si_xib;
34822 + p = sbinfo->si_xib_buf;
34823 + pos = sbinfo->si_xib_last_pindex;
34824 + pos *= PAGE_SIZE;
34825 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34826 + if (unlikely(sz != PAGE_SIZE))
34830 + pos *= PAGE_SIZE;
34831 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
34832 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
34834 + memset(p, 0, PAGE_SIZE);
34835 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
34837 + if (sz == PAGE_SIZE) {
34838 + sbinfo->si_xib_last_pindex = pindex;
34839 + return 0; /* success */
34843 + AuIOErr1("write failed (%zd)\n", sz);
34850 +/* ---------------------------------------------------------------------- */
34852 +static void au_xib_clear_bit(struct inode *inode)
34855 + unsigned long pindex;
34856 + struct super_block *sb;
34857 + struct au_sbinfo *sbinfo;
34859 + AuDebugOn(inode->i_nlink);
34861 + sb = inode->i_sb;
34862 + xib_calc_bit(inode->i_ino, &pindex, &bit);
34863 + AuDebugOn(page_bits <= bit);
34864 + sbinfo = au_sbi(sb);
34865 + mutex_lock(&sbinfo->si_xib_mtx);
34866 + err = xib_pindex(sb, pindex);
34868 + clear_bit(bit, sbinfo->si_xib_buf);
34869 + sbinfo->si_xib_next_bit = bit;
34871 + mutex_unlock(&sbinfo->si_xib_mtx);
34874 +/* for s_op->delete_inode() */
34875 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
34878 + unsigned int mnt_flags;
34879 + aufs_bindex_t bindex, bbot, bi;
34880 + unsigned char try_trunc;
34881 + struct au_iinfo *iinfo;
34882 + struct super_block *sb;
34883 + struct au_hinode *hi;
34884 + struct inode *h_inode;
34885 + struct au_branch *br;
34886 + vfs_writef_t xwrite;
34888 + AuDebugOn(au_is_bad_inode(inode));
34890 + sb = inode->i_sb;
34891 + mnt_flags = au_mntflags(sb);
34892 + if (!au_opt_test(mnt_flags, XINO)
34893 + || inode->i_ino == AUFS_ROOT_INO)
34897 + au_xigen_inc(inode);
34898 + au_xib_clear_bit(inode);
34901 + iinfo = au_ii(inode);
34902 + bindex = iinfo->ii_btop;
34906 + xwrite = au_sbi(sb)->si_xwrite;
34907 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
34908 + hi = au_hinode(iinfo, bindex);
34909 + bbot = iinfo->ii_bbot;
34910 + for (; bindex <= bbot; bindex++, hi++) {
34911 + h_inode = hi->hi_inode;
34913 + || (!unlinked && h_inode->i_nlink))
34916 + /* inode may not be revalidated */
34917 + bi = au_br_index(sb, hi->hi_id);
34921 + br = au_sbr(sb, bi);
34922 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
34923 + h_inode->i_ino, /*ino*/0);
34924 + if (!err && try_trunc
34925 + && au_test_fs_trunc_xino(au_br_sb(br)))
34926 + xino_try_trunc(sb, br);
34930 +/* get an unused inode number from bitmap */
34931 +ino_t au_xino_new_ino(struct super_block *sb)
34934 + unsigned long *p, pindex, ul, pend;
34935 + struct au_sbinfo *sbinfo;
34936 + struct file *file;
34937 + int free_bit, err;
34939 + if (!au_opt_test(au_mntflags(sb), XINO))
34940 + return iunique(sb, AUFS_FIRST_INO);
34942 + sbinfo = au_sbi(sb);
34943 + mutex_lock(&sbinfo->si_xib_mtx);
34944 + p = sbinfo->si_xib_buf;
34945 + free_bit = sbinfo->si_xib_next_bit;
34946 + if (free_bit < page_bits && !test_bit(free_bit, p))
34947 + goto out; /* success */
34948 + free_bit = find_first_zero_bit(p, page_bits);
34949 + if (free_bit < page_bits)
34950 + goto out; /* success */
34952 + pindex = sbinfo->si_xib_last_pindex;
34953 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
34954 + err = xib_pindex(sb, ul);
34955 + if (unlikely(err))
34957 + free_bit = find_first_zero_bit(p, page_bits);
34958 + if (free_bit < page_bits)
34959 + goto out; /* success */
34962 + file = sbinfo->si_xib;
34963 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
34964 + for (ul = pindex + 1; ul <= pend; ul++) {
34965 + err = xib_pindex(sb, ul);
34966 + if (unlikely(err))
34968 + free_bit = find_first_zero_bit(p, page_bits);
34969 + if (free_bit < page_bits)
34970 + goto out; /* success */
34975 + set_bit(free_bit, p);
34976 + sbinfo->si_xib_next_bit = free_bit + 1;
34977 + pindex = sbinfo->si_xib_last_pindex;
34978 + mutex_unlock(&sbinfo->si_xib_mtx);
34979 + ino = xib_calc_ino(pindex, free_bit);
34980 + AuDbg("i%lu\n", (unsigned long)ino);
34983 + mutex_unlock(&sbinfo->si_xib_mtx);
34989 + * read @ino from xinofile for the specified branch{@sb, @bindex}
34990 + * at the position of @h_ino.
34991 + * if @ino does not exist and @do_new is true, get new one.
34993 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34999 + struct file *file;
35000 + struct au_sbinfo *sbinfo;
35003 + if (!au_opt_test(au_mntflags(sb), XINO))
35004 + return 0; /* no xino */
35007 + sbinfo = au_sbi(sb);
35009 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
35010 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
35013 + pos *= sizeof(*ino);
35015 + file = au_sbr(sb, bindex)->br_xino.xi_file;
35016 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
35017 + return 0; /* no ino */
35019 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
35020 + if (sz == sizeof(*ino))
35021 + return 0; /* success */
35024 + if (unlikely(sz >= 0)) {
35026 + AuIOErr("xino read error (%zd)\n", sz);
35032 +/* ---------------------------------------------------------------------- */
35034 +/* create and set a new xino file */
35036 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
35038 + struct file *file;
35039 + struct dentry *h_parent, *d;
35040 + struct inode *h_dir, *inode;
35044 + * at mount-time, and the xino file is the default path,
35045 + * hnotify is disabled so we have no notify events to ignore.
35046 + * when a user specified the xino, we cannot get au_hdir to be ignored.
35048 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
35049 + /* | __FMODE_NONOTIFY */,
35050 + S_IRUGO | S_IWUGO);
35051 + if (IS_ERR(file)) {
35053 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
35057 + /* keep file count */
35059 + inode = file_inode(file);
35060 + h_parent = dget_parent(file->f_path.dentry);
35061 + h_dir = d_inode(h_parent);
35062 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
35063 + /* mnt_want_write() is unnecessary here */
35064 + /* no delegation since it is just created */
35065 + if (inode->i_nlink)
35066 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
35068 + inode_unlock(h_dir);
35070 + if (unlikely(err)) {
35072 + pr_err("unlink %s(%d)\n", fname, err);
35077 + d = file->f_path.dentry;
35078 + if (unlikely(sb == d->d_sb)) {
35080 + pr_err("%s must be outside\n", fname);
35083 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
35085 + pr_err("xino doesn't support %s(%s)\n",
35086 + fname, au_sbtype(d->d_sb));
35089 + return file; /* success */
35093 + file = ERR_PTR(err);
35098 + * find another branch who is on the same filesystem of the specified
35099 + * branch{@btgt}. search until @bbot.
35101 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
35102 + aufs_bindex_t bbot)
35104 + aufs_bindex_t bindex;
35105 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
35107 + for (bindex = 0; bindex < btgt; bindex++)
35108 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35110 + for (bindex++; bindex <= bbot; bindex++)
35111 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35116 +/* ---------------------------------------------------------------------- */
35119 + * initialize the xinofile for the specified branch @br
35120 + * at the place/path where @base_file indicates.
35121 + * test whether another branch is on the same filesystem or not,
35122 + * if @do_test is true.
35124 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
35125 + struct file *base_file, int do_test)
35129 + aufs_bindex_t bbot, bindex;
35130 + struct au_branch *shared_br, *b;
35131 + struct file *file;
35132 + struct super_block *tgt_sb;
35134 + shared_br = NULL;
35135 + bbot = au_sbbot(sb);
35137 + tgt_sb = au_br_sb(br);
35138 + for (bindex = 0; bindex <= bbot; bindex++) {
35139 + b = au_sbr(sb, bindex);
35140 + if (tgt_sb == au_br_sb(b)) {
35147 + if (!shared_br || !shared_br->br_xino.xi_file) {
35148 + struct au_xino_lock_dir ldir;
35150 + au_xino_lock_dir(sb, base_file, &ldir);
35151 + /* mnt_want_write() is unnecessary here */
35152 + file = au_xino_create2(base_file, NULL);
35153 + au_xino_unlock_dir(&ldir);
35154 + err = PTR_ERR(file);
35155 + if (IS_ERR(file))
35157 + br->br_xino.xi_file = file;
35159 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
35160 + get_file(br->br_xino.xi_file);
35163 + ino = AUFS_ROOT_INO;
35164 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
35166 + if (unlikely(err)) {
35167 + fput(br->br_xino.xi_file);
35168 + br->br_xino.xi_file = NULL;
35175 +/* ---------------------------------------------------------------------- */
35177 +/* trucate a xino bitmap file */
35180 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
35184 + unsigned long pindex;
35185 + loff_t pos, pend;
35186 + struct au_sbinfo *sbinfo;
35187 + vfs_readf_t func;
35189 + unsigned long *p;
35192 + sbinfo = au_sbi(sb);
35193 + MtxMustLock(&sbinfo->si_xib_mtx);
35194 + p = sbinfo->si_xib_buf;
35195 + func = sbinfo->si_xread;
35196 + pend = vfsub_f_size_read(file);
35198 + while (pos < pend) {
35199 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
35201 + if (unlikely(sz <= 0))
35205 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
35206 + if (unlikely(*ino < AUFS_FIRST_INO))
35209 + xib_calc_bit(*ino, &pindex, &bit);
35210 + AuDebugOn(page_bits <= bit);
35211 + err = xib_pindex(sb, pindex);
35223 +static int xib_restore(struct super_block *sb)
35226 + aufs_bindex_t bindex, bbot;
35230 + page = (void *)__get_free_page(GFP_NOFS);
35231 + if (unlikely(!page))
35235 + bbot = au_sbbot(sb);
35236 + for (bindex = 0; !err && bindex <= bbot; bindex++)
35237 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
35238 + err = do_xib_restore
35239 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
35241 + AuDbg("b%d\n", bindex);
35242 + au_delayed_free_page((unsigned long)page);
35248 +int au_xib_trunc(struct super_block *sb)
35253 + struct au_xino_lock_dir ldir;
35254 + struct au_sbinfo *sbinfo;
35255 + unsigned long *p;
35256 + struct file *file;
35258 + SiMustWriteLock(sb);
35261 + sbinfo = au_sbi(sb);
35262 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
35265 + file = sbinfo->si_xib;
35266 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
35269 + au_xino_lock_dir(sb, file, &ldir);
35270 + /* mnt_want_write() is unnecessary here */
35271 + file = au_xino_create2(sbinfo->si_xib, NULL);
35272 + au_xino_unlock_dir(&ldir);
35273 + err = PTR_ERR(file);
35274 + if (IS_ERR(file))
35276 + fput(sbinfo->si_xib);
35277 + sbinfo->si_xib = file;
35279 + p = sbinfo->si_xib_buf;
35280 + memset(p, 0, PAGE_SIZE);
35282 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
35283 + if (unlikely(sz != PAGE_SIZE)) {
35285 + AuIOErr("err %d\n", err);
35291 + mutex_lock(&sbinfo->si_xib_mtx);
35292 + /* mnt_want_write() is unnecessary here */
35293 + err = xib_restore(sb);
35294 + mutex_unlock(&sbinfo->si_xib_mtx);
35300 +/* ---------------------------------------------------------------------- */
35303 + * xino mount option handlers
35307 +static void xino_clear_xib(struct super_block *sb)
35309 + struct au_sbinfo *sbinfo;
35311 + SiMustWriteLock(sb);
35313 + sbinfo = au_sbi(sb);
35314 + sbinfo->si_xread = NULL;
35315 + sbinfo->si_xwrite = NULL;
35316 + if (sbinfo->si_xib)
35317 + fput(sbinfo->si_xib);
35318 + sbinfo->si_xib = NULL;
35319 + if (sbinfo->si_xib_buf)
35320 + au_delayed_free_page((unsigned long)sbinfo->si_xib_buf);
35321 + sbinfo->si_xib_buf = NULL;
35324 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
35328 + struct au_sbinfo *sbinfo;
35329 + struct file *file;
35331 + SiMustWriteLock(sb);
35333 + sbinfo = au_sbi(sb);
35334 + file = au_xino_create2(base, sbinfo->si_xib);
35335 + err = PTR_ERR(file);
35336 + if (IS_ERR(file))
35338 + if (sbinfo->si_xib)
35339 + fput(sbinfo->si_xib);
35340 + sbinfo->si_xib = file;
35341 + sbinfo->si_xread = vfs_readf(file);
35342 + sbinfo->si_xwrite = vfs_writef(file);
35345 + if (!sbinfo->si_xib_buf)
35346 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
35347 + if (unlikely(!sbinfo->si_xib_buf))
35350 + sbinfo->si_xib_last_pindex = 0;
35351 + sbinfo->si_xib_next_bit = 0;
35352 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
35354 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
35355 + PAGE_SIZE, &pos);
35356 + if (unlikely(err != PAGE_SIZE))
35360 + goto out; /* success */
35363 + if (sbinfo->si_xib_buf)
35364 + au_delayed_free_page((unsigned long)sbinfo->si_xib_buf);
35365 + sbinfo->si_xib_buf = NULL;
35369 + fput(sbinfo->si_xib);
35370 + sbinfo->si_xib = NULL;
35371 + sbinfo->si_xread = NULL;
35372 + sbinfo->si_xwrite = NULL;
35377 +/* xino for each branch */
35378 +static void xino_clear_br(struct super_block *sb)
35380 + aufs_bindex_t bindex, bbot;
35381 + struct au_branch *br;
35383 + bbot = au_sbbot(sb);
35384 + for (bindex = 0; bindex <= bbot; bindex++) {
35385 + br = au_sbr(sb, bindex);
35386 + if (!br || !br->br_xino.xi_file)
35389 + fput(br->br_xino.xi_file);
35390 + br->br_xino.xi_file = NULL;
35394 +static int au_xino_set_br(struct super_block *sb, struct file *base)
35398 + aufs_bindex_t bindex, bbot, bshared;
35400 + struct file *old, *new;
35402 + struct au_branch *br;
35403 + struct inode *inode;
35404 + vfs_writef_t writef;
35406 + SiMustWriteLock(sb);
35409 + bbot = au_sbbot(sb);
35410 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
35411 + if (unlikely(!fpair))
35414 + inode = d_inode(sb->s_root);
35415 + ino = AUFS_ROOT_INO;
35416 + writef = au_sbi(sb)->si_xwrite;
35417 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35418 + bshared = is_sb_shared(sb, bindex, bindex - 1);
35419 + if (bshared >= 0) {
35420 + /* shared xino */
35421 + *p = fpair[bshared];
35422 + get_file(p->new);
35427 + br = au_sbr(sb, bindex);
35428 + p->old = br->br_xino.xi_file;
35429 + p->new = au_xino_create2(base, br->br_xino.xi_file);
35430 + err = PTR_ERR(p->new);
35431 + if (IS_ERR(p->new)) {
35437 + err = au_xino_do_write(writef, p->new,
35438 + au_h_iptr(inode, bindex)->i_ino, ino);
35439 + if (unlikely(err))
35443 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35444 + br = au_sbr(sb, bindex);
35445 + if (br->br_xino.xi_file)
35446 + fput(br->br_xino.xi_file);
35447 + get_file(p->new);
35448 + br->br_xino.xi_file = p->new;
35452 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
35457 + au_delayed_kfree(fpair);
35462 +void au_xino_clr(struct super_block *sb)
35464 + struct au_sbinfo *sbinfo;
35466 + au_xigen_clr(sb);
35467 + xino_clear_xib(sb);
35468 + xino_clear_br(sb);
35469 + sbinfo = au_sbi(sb);
35470 + /* lvalue, do not call au_mntflags() */
35471 + au_opt_clr(sbinfo->si_mntflags, XINO);
35474 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
35477 + struct dentry *parent, *cur_parent;
35478 + struct qstr *dname, *cur_name;
35479 + struct file *cur_xino;
35480 + struct inode *dir;
35481 + struct au_sbinfo *sbinfo;
35483 + SiMustWriteLock(sb);
35486 + sbinfo = au_sbi(sb);
35487 + parent = dget_parent(xino->file->f_path.dentry);
35490 + dname = &xino->file->f_path.dentry->d_name;
35491 + cur_xino = sbinfo->si_xib;
35493 + cur_parent = dget_parent(cur_xino->f_path.dentry);
35494 + cur_name = &cur_xino->f_path.dentry->d_name;
35495 + skip = (cur_parent == parent
35496 + && au_qstreq(dname, cur_name));
35497 + dput(cur_parent);
35503 + au_opt_set(sbinfo->si_mntflags, XINO);
35504 + dir = d_inode(parent);
35505 + inode_lock_nested(dir, AuLsc_I_PARENT);
35506 + /* mnt_want_write() is unnecessary here */
35507 + err = au_xino_set_xib(sb, xino->file);
35509 + err = au_xigen_set(sb, xino->file);
35511 + err = au_xino_set_br(sb, xino->file);
35512 + inode_unlock(dir);
35514 + goto out; /* success */
35517 + AuIOErr("failed creating xino(%d).\n", err);
35518 + au_xigen_clr(sb);
35519 + xino_clear_xib(sb);
35526 +/* ---------------------------------------------------------------------- */
35529 + * create a xinofile at the default place/path.
35531 +struct file *au_xino_def(struct super_block *sb)
35533 + struct file *file;
35535 + struct au_branch *br;
35536 + struct super_block *h_sb;
35537 + struct path path;
35538 + aufs_bindex_t bbot, bindex, bwr;
35541 + bbot = au_sbbot(sb);
35543 + for (bindex = 0; bindex <= bbot; bindex++) {
35544 + br = au_sbr(sb, bindex);
35545 + if (au_br_writable(br->br_perm)
35546 + && !au_test_fs_bad_xino(au_br_sb(br))) {
35553 + file = ERR_PTR(-ENOMEM);
35554 + page = (void *)__get_free_page(GFP_NOFS);
35555 + if (unlikely(!page))
35557 + path.mnt = au_br_mnt(br);
35558 + path.dentry = au_h_dptr(sb->s_root, bwr);
35559 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
35560 + file = (void *)p;
35561 + if (!IS_ERR(p)) {
35562 + strcat(p, "/" AUFS_XINO_FNAME);
35563 + AuDbg("%s\n", p);
35564 + file = au_xino_create(sb, p, /*silent*/0);
35565 + if (!IS_ERR(file))
35566 + au_xino_brid_set(sb, br->br_id);
35568 + au_delayed_free_page((unsigned long)page);
35570 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
35571 + if (IS_ERR(file))
35573 + h_sb = file->f_path.dentry->d_sb;
35574 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
35575 + pr_err("xino doesn't support %s(%s)\n",
35576 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
35578 + file = ERR_PTR(-EINVAL);
35580 + if (!IS_ERR(file))
35581 + au_xino_brid_set(sb, -1);
35588 +/* ---------------------------------------------------------------------- */
35590 +int au_xino_path(struct seq_file *seq, struct file *file)
35594 + err = au_seq_path(seq, &file->f_path);
35595 + if (unlikely(err))
35598 +#define Deleted "\\040(deleted)"
35599 + seq->count -= sizeof(Deleted) - 1;
35600 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
35601 + sizeof(Deleted) - 1));
35607 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
35608 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
35609 +++ linux/include/uapi/linux/aufs_type.h 2016-12-11 21:22:05.903059512 +0100
35612 + * Copyright (C) 2005-2016 Junjiro R. Okajima
35614 + * This program, aufs is free software; you can redistribute it and/or modify
35615 + * it under the terms of the GNU General Public License as published by
35616 + * the Free Software Foundation; either version 2 of the License, or
35617 + * (at your option) any later version.
35619 + * This program is distributed in the hope that it will be useful,
35620 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35621 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35622 + * GNU General Public License for more details.
35624 + * You should have received a copy of the GNU General Public License
35625 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35628 +#ifndef __AUFS_TYPE_H__
35629 +#define __AUFS_TYPE_H__
35631 +#define AUFS_NAME "aufs"
35635 + * define it before including all other headers.
35636 + * sched.h may use pr_* macros before defining "current", so define the
35637 + * no-current version first, and re-define later.
35639 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
35640 +#include <linux/sched.h>
35642 +#define pr_fmt(fmt) \
35643 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
35644 + (int)sizeof(current->comm), current->comm, current->pid
35646 +#include <stdint.h>
35647 +#include <sys/types.h>
35648 +#endif /* __KERNEL__ */
35650 +#include <linux/limits.h>
35652 +#define AUFS_VERSION "4.x-rcN-20161010"
35654 +/* todo? move this to linux-2.6.19/include/magic.h */
35655 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
35657 +/* ---------------------------------------------------------------------- */
35659 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
35660 +typedef int8_t aufs_bindex_t;
35661 +#define AUFS_BRANCH_MAX 127
35663 +typedef int16_t aufs_bindex_t;
35664 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
35665 +#define AUFS_BRANCH_MAX 511
35666 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
35667 +#define AUFS_BRANCH_MAX 1023
35668 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
35669 +#define AUFS_BRANCH_MAX 32767
35674 +#ifndef AUFS_BRANCH_MAX
35675 +#error unknown CONFIG_AUFS_BRANCH_MAX value
35677 +#endif /* __KERNEL__ */
35679 +/* ---------------------------------------------------------------------- */
35681 +#define AUFS_FSTYPE AUFS_NAME
35683 +#define AUFS_ROOT_INO 2
35684 +#define AUFS_FIRST_INO 11
35686 +#define AUFS_WH_PFX ".wh."
35687 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
35688 +#define AUFS_WH_TMP_LEN 4
35689 +/* a limit for rmdir/rename a dir and copyup */
35690 +#define AUFS_MAX_NAMELEN (NAME_MAX \
35691 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
35693 + - AUFS_WH_TMP_LEN) /* hex */
35694 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
35695 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
35696 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
35697 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
35698 +#define AUFS_DIRWH_DEF 3
35699 +#define AUFS_RDCACHE_DEF 10 /* seconds */
35700 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
35701 +#define AUFS_RDBLK_DEF 512 /* bytes */
35702 +#define AUFS_RDHASH_DEF 32
35703 +#define AUFS_WKQ_NAME AUFS_NAME "d"
35704 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
35705 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
35706 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
35707 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
35709 +/* pseudo-link maintenace under /proc */
35710 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
35711 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
35712 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
35714 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
35715 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
35717 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
35718 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
35719 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
35721 +/* doubly whiteouted */
35722 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
35723 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
35724 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
35726 +/* branch permissions and attributes */
35727 +#define AUFS_BRPERM_RW "rw"
35728 +#define AUFS_BRPERM_RO "ro"
35729 +#define AUFS_BRPERM_RR "rr"
35730 +#define AUFS_BRATTR_COO_REG "coo_reg"
35731 +#define AUFS_BRATTR_COO_ALL "coo_all"
35732 +#define AUFS_BRATTR_FHSM "fhsm"
35733 +#define AUFS_BRATTR_UNPIN "unpin"
35734 +#define AUFS_BRATTR_ICEX "icex"
35735 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
35736 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
35737 +#define AUFS_BRATTR_ICEX_TR "icextr"
35738 +#define AUFS_BRATTR_ICEX_USR "icexusr"
35739 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
35740 +#define AUFS_BRRATTR_WH "wh"
35741 +#define AUFS_BRWATTR_NLWH "nolwh"
35742 +#define AUFS_BRWATTR_MOO "moo"
35744 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
35745 +#define AuBrPerm_RO (1 << 1) /* readonly */
35746 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
35747 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
35749 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
35750 +#define AuBrAttr_COO_ALL (1 << 4)
35751 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
35753 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
35754 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
35755 + branch. meaningless since
35756 + linux-3.18-rc1 */
35758 +/* ignore error in copying XATTR */
35759 +#define AuBrAttr_ICEX_SEC (1 << 7)
35760 +#define AuBrAttr_ICEX_SYS (1 << 8)
35761 +#define AuBrAttr_ICEX_TR (1 << 9)
35762 +#define AuBrAttr_ICEX_USR (1 << 10)
35763 +#define AuBrAttr_ICEX_OTH (1 << 11)
35764 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
35765 + | AuBrAttr_ICEX_SYS \
35766 + | AuBrAttr_ICEX_TR \
35767 + | AuBrAttr_ICEX_USR \
35768 + | AuBrAttr_ICEX_OTH)
35770 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
35771 +#define AuBrRAttr_Mask AuBrRAttr_WH
35773 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
35774 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
35775 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
35777 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
35779 +/* #warning test userspace */
35781 +#ifndef CONFIG_AUFS_FHSM
35782 +#undef AuBrAttr_FHSM
35783 +#define AuBrAttr_FHSM 0
35785 +#ifndef CONFIG_AUFS_XATTR
35786 +#undef AuBrAttr_ICEX
35787 +#define AuBrAttr_ICEX 0
35788 +#undef AuBrAttr_ICEX_SEC
35789 +#define AuBrAttr_ICEX_SEC 0
35790 +#undef AuBrAttr_ICEX_SYS
35791 +#define AuBrAttr_ICEX_SYS 0
35792 +#undef AuBrAttr_ICEX_TR
35793 +#define AuBrAttr_ICEX_TR 0
35794 +#undef AuBrAttr_ICEX_USR
35795 +#define AuBrAttr_ICEX_USR 0
35796 +#undef AuBrAttr_ICEX_OTH
35797 +#define AuBrAttr_ICEX_OTH 0
35801 +/* the longest combination */
35802 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
35803 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
35804 + "+" AUFS_BRATTR_COO_REG \
35805 + "+" AUFS_BRATTR_FHSM \
35806 + "+" AUFS_BRATTR_UNPIN \
35807 + "+" AUFS_BRATTR_ICEX_SEC \
35808 + "+" AUFS_BRATTR_ICEX_SYS \
35809 + "+" AUFS_BRATTR_ICEX_USR \
35810 + "+" AUFS_BRATTR_ICEX_OTH \
35811 + "+" AUFS_BRWATTR_NLWH)
35814 + char a[AuBrPermStrSz];
35815 +} au_br_perm_str_t;
35817 +static inline int au_br_writable(int brperm)
35819 + return brperm & AuBrPerm_RW;
35822 +static inline int au_br_whable(int brperm)
35824 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
35827 +static inline int au_br_wh_linkable(int brperm)
35829 + return !(brperm & AuBrWAttr_NoLinkWH);
35832 +static inline int au_br_cmoo(int brperm)
35834 + return brperm & AuBrAttr_CMOO_Mask;
35837 +static inline int au_br_fhsm(int brperm)
35839 + return brperm & AuBrAttr_FHSM;
35842 +/* ---------------------------------------------------------------------- */
35846 + /* readdir in userspace */
35850 + AuCtl_WBR_FD, /* pathconf wrapper */
35851 + AuCtl_IBUSY, /* busy inode */
35852 + AuCtl_MVDOWN, /* move-down */
35853 + AuCtl_BR, /* info about branches */
35854 + AuCtl_FHSM_FD /* connection for fhsm */
35857 +/* borrowed from linux/include/linux/kernel.h */
35859 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
35860 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
35863 +/* borrowed from linux/include/linux/compiler-gcc3.h */
35865 +#define __aligned(x) __attribute__((aligned(x)))
35870 +#define __packed __attribute__((packed))
35874 +struct au_rdu_cookie {
35879 + uint32_t generation;
35882 +struct au_rdu_ent {
35891 +static inline int au_rdu_len(int nlen)
35893 + /* include the terminating NULL */
35894 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
35895 + sizeof(uint64_t));
35898 +union au_rdu_ent_ul {
35899 + struct au_rdu_ent __user *e;
35911 + uint64_t sz; /* AuCtl_RDU */
35912 + uint64_t nent; /* AuCtl_RDU_INO */
35914 + union au_rdu_ent_ul ent;
35915 + uint16_t verify[AufsCtlRduV_End];
35917 + /* input/output */
35921 + union au_rdu_ent_ul tail;
35922 + /* number of entries which were added in a single call */
35927 + struct au_rdu_cookie cookie;
35930 +/* ---------------------------------------------------------------------- */
35932 +struct aufs_wbr_fd {
35937 +/* ---------------------------------------------------------------------- */
35939 +struct aufs_ibusy {
35940 + uint64_t ino, h_ino;
35944 +/* ---------------------------------------------------------------------- */
35946 +/* error code for move-down */
35947 +/* the actual message strings are implemented in aufs-util.git */
35949 + EAU_MVDOWN_OPAQUE = 1,
35950 + EAU_MVDOWN_WHITEOUT,
35951 + EAU_MVDOWN_UPPER,
35952 + EAU_MVDOWN_BOTTOM,
35953 + EAU_MVDOWN_NOUPPER,
35954 + EAU_MVDOWN_NOLOWERBR,
35958 +/* flags for move-down */
35959 +#define AUFS_MVDOWN_DMSG 1
35960 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
35961 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
35962 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
35963 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
35964 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
35965 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
35966 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
35967 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
35968 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
35969 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
35970 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
35971 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
35973 +/* index for move-down */
35975 + AUFS_MVDOWN_UPPER,
35976 + AUFS_MVDOWN_LOWER,
35977 + AUFS_MVDOWN_NARRAY
35981 + * additional info of move-down
35982 + * number of free blocks and inodes.
35983 + * subset of struct kstatfs, but smaller and always 64bit.
35985 +struct aufs_stfs {
35986 + uint64_t f_blocks;
35987 + uint64_t f_bavail;
35988 + uint64_t f_files;
35989 + uint64_t f_ffree;
35992 +struct aufs_stbr {
35993 + int16_t brid; /* optional input */
35994 + int16_t bindex; /* output */
35995 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
35998 +struct aufs_mvdown {
35999 + uint32_t flags; /* input/output */
36000 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
36001 + int8_t au_errno; /* output */
36004 +/* ---------------------------------------------------------------------- */
36006 +union aufs_brinfo {
36007 + /* PATH_MAX may differ between kernel-space and user-space */
36008 + char _spacer[4096];
36016 +/* ---------------------------------------------------------------------- */
36018 +#define AuCtlType 'A'
36019 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
36020 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
36021 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
36022 + struct aufs_wbr_fd)
36023 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
36024 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
36025 + struct aufs_mvdown)
36026 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
36027 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
36029 +#endif /* __AUFS_TYPE_H__ */
36030 aufs4.x-rcN loopback patch
36032 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36033 index 005e292..e9e517d 100644
36034 --- a/drivers/block/loop.c
36035 +++ b/drivers/block/loop.c
36036 @@ -551,7 +551,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
36039 struct switch_request {
36040 - struct file *file;
36041 + struct file *file, *virt_file;
36042 struct completion wait;
36045 @@ -577,6 +577,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36046 mapping = file->f_mapping;
36047 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
36048 lo->lo_backing_file = file;
36049 + lo->lo_backing_virt_file = p->virt_file;
36050 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
36051 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
36052 lo->old_gfp_mask = mapping_gfp_mask(mapping);
36053 @@ -589,11 +590,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36054 * First it needs to flush existing IO, it does this by sending a magic
36055 * BIO down the pipe. The completion of this BIO does the actual switch.
36057 -static int loop_switch(struct loop_device *lo, struct file *file)
36058 +static int loop_switch(struct loop_device *lo, struct file *file,
36059 + struct file *virt_file)
36061 struct switch_request w;
36064 + w.virt_file = virt_file;
36066 /* freeze queue and wait for completion of scheduled requests */
36067 blk_mq_freeze_queue(lo->lo_queue);
36068 @@ -612,7 +615,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
36070 static int loop_flush(struct loop_device *lo)
36072 - return loop_switch(lo, NULL);
36073 + return loop_switch(lo, NULL, NULL);
36076 +static struct file *loop_real_file(struct file *file)
36078 + struct file *f = NULL;
36080 + if (file->f_path.dentry->d_sb->s_op->real_loop)
36081 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
36085 static void loop_reread_partitions(struct loop_device *lo,
36086 @@ -649,6 +661,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36089 struct file *file, *old_file;
36090 + struct file *f, *virt_file = NULL, *old_virt_file;
36091 struct inode *inode;
36094 @@ -665,9 +678,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36098 + f = loop_real_file(file);
36100 + virt_file = file;
36105 inode = file->f_mapping->host;
36106 old_file = lo->lo_backing_file;
36107 + old_virt_file = lo->lo_backing_virt_file;
36111 @@ -679,17 +699,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36114 /* and ... switch */
36115 - error = loop_switch(lo, file);
36116 + error = loop_switch(lo, file, virt_file);
36121 + if (old_virt_file)
36122 + fput(old_virt_file);
36123 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
36124 loop_reread_partitions(lo, bdev);
36134 @@ -876,7 +900,7 @@ static int loop_prepare_queue(struct loop_device *lo)
36135 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36136 struct block_device *bdev, unsigned int arg)
36138 - struct file *file, *f;
36139 + struct file *file, *f, *virt_file = NULL;
36140 struct inode *inode;
36141 struct address_space *mapping;
36142 unsigned lo_blocksize;
36143 @@ -891,6 +915,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36147 + f = loop_real_file(file);
36149 + virt_file = file;
36155 if (lo->lo_state != Lo_unbound)
36156 @@ -943,6 +973,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36157 lo->lo_device = bdev;
36158 lo->lo_flags = lo_flags;
36159 lo->lo_backing_file = file;
36160 + lo->lo_backing_virt_file = virt_file;
36161 lo->transfer = NULL;
36163 lo->lo_sizelimit = 0;
36164 @@ -975,6 +1006,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36171 /* This is safe: open() is still holding a reference. */
36172 module_put(THIS_MODULE);
36173 @@ -1021,6 +1054,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
36174 static int loop_clr_fd(struct loop_device *lo)
36176 struct file *filp = lo->lo_backing_file;
36177 + struct file *virt_filp = lo->lo_backing_virt_file;
36178 gfp_t gfp = lo->old_gfp_mask;
36179 struct block_device *bdev = lo->lo_device;
36181 @@ -1052,6 +1086,7 @@ static int loop_clr_fd(struct loop_device *lo)
36182 spin_lock_irq(&lo->lo_lock);
36183 lo->lo_state = Lo_rundown;
36184 lo->lo_backing_file = NULL;
36185 + lo->lo_backing_virt_file = NULL;
36186 spin_unlock_irq(&lo->lo_lock);
36188 loop_release_xfer(lo);
36189 @@ -1096,6 +1131,8 @@ static int loop_clr_fd(struct loop_device *lo)
36190 * bd_mutex which is usually taken before lo_ctl_mutex.
36198 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
36199 index fb2237c..c3888c5 100644
36200 --- a/drivers/block/loop.h
36201 +++ b/drivers/block/loop.h
36202 @@ -46,7 +46,7 @@ struct loop_device {
36203 int (*ioctl)(struct loop_device *, int cmd,
36204 unsigned long arg);
36206 - struct file * lo_backing_file;
36207 + struct file * lo_backing_file, *lo_backing_virt_file;
36208 struct block_device *lo_device;
36209 unsigned lo_blocksize;
36211 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
36212 index 00475fb..01390e1 100644
36213 --- a/fs/aufs/f_op.c
36214 +++ b/fs/aufs/f_op.c
36215 @@ -348,7 +348,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
36216 if (IS_ERR(h_file))
36219 - if (au_test_loopback_kthread()) {
36220 + if (0 && au_test_loopback_kthread()) {
36221 au_warn_loopback(h_file->f_path.dentry->d_sb);
36222 if (file->f_mapping != h_file->f_mapping) {
36223 file->f_mapping = h_file->f_mapping;
36224 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
36225 index c3ca50f..a3dbdaf 100644
36226 --- a/fs/aufs/loop.c
36227 +++ b/fs/aufs/loop.c
36228 @@ -132,3 +132,19 @@ void au_loopback_fin(void)
36229 symbol_put(loop_backing_file);
36230 au_delayed_kfree(au_warn_loopback_array);
36233 +/* ---------------------------------------------------------------------- */
36235 +/* support the loopback block device insude aufs */
36237 +struct file *aufs_real_loop(struct file *file)
36241 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
36242 + fi_read_lock(file);
36243 + f = au_hf_top(file);
36244 + fi_read_unlock(file);
36248 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
36249 index 48bf070..66afec7 100644
36250 --- a/fs/aufs/loop.h
36251 +++ b/fs/aufs/loop.h
36252 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
36254 int au_loopback_init(void);
36255 void au_loopback_fin(void);
36257 +struct file *aufs_real_loop(struct file *file);
36259 +AuStub(struct file *, loop_backing_file, return NULL)
36261 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
36262 struct dentry *h_adding)
36263 AuStubInt0(au_test_loopback_kthread, void)
36264 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
36266 AuStubInt0(au_loopback_init, void)
36267 AuStubVoid(au_loopback_fin, void)
36269 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
36270 #endif /* BLK_DEV_LOOP */
36272 #endif /* __KERNEL__ */
36273 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
36274 index 58a773c..75f212c 100644
36275 --- a/fs/aufs/super.c
36276 +++ b/fs/aufs/super.c
36277 @@ -831,7 +831,10 @@ static const struct super_operations aufs_sop = {
36278 .statfs = aufs_statfs,
36279 .put_super = aufs_put_super,
36280 .sync_fs = aufs_sync_fs,
36281 - .remount_fs = aufs_remount_fs
36282 + .remount_fs = aufs_remount_fs,
36283 +#ifdef CONFIG_AUFS_BDEV_LOOP
36284 + .real_loop = aufs_real_loop
36288 /* ---------------------------------------------------------------------- */
36289 diff --git a/include/linux/fs.h b/include/linux/fs.h
36290 index fc80663..0c4c6fa 100644
36291 --- a/include/linux/fs.h
36292 +++ b/include/linux/fs.h
36293 @@ -1814,6 +1814,10 @@ struct super_operations {
36294 struct shrink_control *);
36295 long (*free_cached_objects)(struct super_block *,
36296 struct shrink_control *);
36297 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
36299 + struct file *(*real_loop)(struct file *);