3 diff --git a/fs/Kconfig b/fs/Kconfig
4 index 4bd03a2..620e01b 100644
7 @@ -249,6 +249,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 cd2be1c..78f3c68 100644
26 --- a/include/uapi/linux/Kbuild
27 +++ b/include/uapi/linux/Kbuild
28 @@ -59,6 +59,7 @@ header-y += atmsvc.h
30 header-y += atm_zatm.h
32 +header-y += aufs_type.h
33 header-y += auto_fs4.h
38 diff --git a/MAINTAINERS b/MAINTAINERS
39 index 63cefa6..d78b954 100644
42 @@ -2293,6 +2293,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 fa1b7a9..6ee9235 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 88110fd..9a9ba3a 100644
130 @@ -1642,7 +1642,7 @@ int generic_update_time(struct inode *inode, struct timespec *time, int flags)
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 190e0d36..4052813 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 5a7750b..28160a7 100644
176 @@ -855,8 +855,8 @@ ssize_t generic_splice_sendpage(struct pipe_inode_info *pipe, struct file *out,
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 @@ -872,9 +872,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
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 dc0478c..27c05e7 100644
214 --- a/include/linux/fs.h
215 +++ b/include/linux/fs.h
216 @@ -1291,6 +1291,7 @@ 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 @@ -1715,6 +1716,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 @@ -1768,6 +1770,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 @@ -2140,6 +2148,7 @@ extern int iterate_mounts(int (*)(struct vfsmount *, void *), 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 00a2116..1f0a4a2 100644
255 --- a/include/linux/splice.h
256 +++ b/include/linux/splice.h
257 @@ -86,4 +86,10 @@ extern ssize_t splice_direct_to_actor(struct file *, struct splice_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);
270 diff --git a/fs/proc/base.c b/fs/proc/base.c
271 index ca651ac..0e8551a 100644
274 @@ -1953,7 +1953,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 35b92d8..5b981db 100644
301 --- a/fs/proc/task_mmu.c
302 +++ b/fs/proc/task_mmu.c
303 @@ -291,7 +291,10 @@ static int is_stack(struct proc_maps_private *priv,
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 @@ -1627,7 +1630,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 3717562..6a328f1 100644
326 --- a/fs/proc/task_nommu.c
327 +++ b/fs/proc/task_nommu.c
328 @@ -155,7 +155,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 a92c8d7..1d83a2a 100644
342 --- a/include/linux/mm.h
343 +++ b/include/linux/mm.h
344 @@ -1266,6 +1266,28 @@ static inline int fixup_user_fault(struct task_struct *tsk,
348 +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int);
349 +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[],
351 +extern void vma_do_get_file(struct vm_area_struct *, const char[], int);
352 +extern void vma_do_fput(struct vm_area_struct *, const char[], int);
354 +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \
356 +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \
358 +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__)
359 +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__)
362 +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int);
363 +extern void vmr_do_fput(struct vm_region *, const char[], int);
365 +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \
367 +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__)
368 +#endif /* !CONFIG_MMU */
370 extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len,
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 4a8aced..badd16b 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 997ac1d..4d0131b 100644
397 @@ -624,7 +624,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm,
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 295bd7a..14fa1c8 100644
410 @@ -37,7 +37,7 @@ obj-y := filemap.o mempool.o oom_kill.o \
411 mm_init.o mmu_context.o percpu.o slab_common.o \
412 compaction.o vmacache.o \
413 interval_tree.o list_lru.o workingset.o \
415 + prfile.o debug.o $(mmu-y)
419 diff --git a/mm/filemap.c b/mm/filemap.c
420 index 50b52fe..9e607f9 100644
423 @@ -2304,7 +2304,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 e18c57b..7be4a39 100644
436 @@ -2117,7 +2117,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 1af87c1..95b0ff4 100644
449 @@ -170,7 +170,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 @@ -879,7 +879,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start,
461 uprobe_munmap(next, next->vm_start, next->vm_end);
466 anon_vma_merge(vma, next);
467 @@ -1727,8 +1727,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
475 /* Undo any partial mapping done by a device driver. */
476 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
477 @@ -2533,7 +2533,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 @@ -2552,7 +2552,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 @@ -2703,7 +2703,7 @@ int vm_munmap(unsigned long start, size_t len)
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 @@ -2778,10 +2778,27 @@ int vm_munmap(unsigned long start, size_t len)
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 @@ -3056,7 +3073,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 8b8faaf..5d26ed94 100644
546 @@ -636,7 +636,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 @@ -794,7 +794,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 @@ -1320,7 +1320,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 @@ -1395,10 +1395,10 @@ unsigned long do_mmap(struct file *file,
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.9 standalone patch
680 diff --git a/fs/dcache.c b/fs/dcache.c
681 index df0268c..755fea1 100644
684 @@ -1272,6 +1272,7 @@ void d_walk(struct dentry *parent, void *data,
688 +EXPORT_SYMBOL_GPL(d_walk);
691 * Search for at least 1 mount point in the dentry's subdirs.
692 @@ -2855,6 +2856,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2)
694 write_sequnlock(&rename_lock);
696 +EXPORT_SYMBOL_GPL(d_exchange);
699 * d_ancestor - search for an ancestor
700 diff --git a/fs/exec.c b/fs/exec.c
701 index 4e497b9..e27d323 100644
704 @@ -104,6 +104,7 @@ bool path_noexec(const struct path *path)
705 return (path->mnt->mnt_flags & MNT_NOEXEC) ||
706 (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC);
708 +EXPORT_SYMBOL_GPL(path_noexec);
712 diff --git a/fs/fcntl.c b/fs/fcntl.c
713 index 6f42279..04fd33c 100644
716 @@ -82,6 +82,7 @@ int setfl(int fd, struct file * filp, unsigned long arg)
720 +EXPORT_SYMBOL_GPL(setfl);
722 static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
724 diff --git a/fs/file_table.c b/fs/file_table.c
725 index ad17e05..ae9f267 100644
726 --- a/fs/file_table.c
727 +++ b/fs/file_table.c
728 @@ -147,6 +147,7 @@ struct file *get_empty_filp(void)
730 return ERR_PTR(-ENFILE);
732 +EXPORT_SYMBOL_GPL(get_empty_filp);
735 * alloc_file - allocate and initialize a 'struct file'
736 @@ -258,6 +259,7 @@ void flush_delayed_fput(void)
740 +EXPORT_SYMBOL_GPL(flush_delayed_fput);
742 static DECLARE_DELAYED_WORK(delayed_fput_work, delayed_fput);
744 @@ -300,6 +302,7 @@ void __fput_sync(struct file *file)
748 +EXPORT_SYMBOL_GPL(__fput_sync);
750 void put_filp(struct file *file)
752 @@ -308,6 +311,7 @@ void put_filp(struct file *file)
756 +EXPORT_SYMBOL_GPL(put_filp);
758 void __init files_init(void)
760 diff --git a/fs/inode.c b/fs/inode.c
761 index 9a9ba3a..a3a18d8 100644
764 @@ -1651,6 +1651,7 @@ int update_time(struct inode *inode, struct timespec *time, int flags)
766 return update_time(inode, time, flags);
768 +EXPORT_SYMBOL_GPL(update_time);
771 * touch_atime - update the access time
772 diff --git a/fs/namespace.c b/fs/namespace.c
773 index e6c234b..8d13f7b 100644
776 @@ -466,6 +466,7 @@ void __mnt_drop_write(struct vfsmount *mnt)
777 mnt_dec_writers(real_mount(mnt));
780 +EXPORT_SYMBOL_GPL(__mnt_drop_write);
783 * mnt_drop_write - give up write access to a mount
784 @@ -1823,6 +1824,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg,
788 +EXPORT_SYMBOL_GPL(iterate_mounts);
790 static void cleanup_group_ids(struct mount *mnt, struct mount *end)
792 diff --git a/fs/notify/group.c b/fs/notify/group.c
793 index fbe3cbe..bdfc61e 100644
794 --- a/fs/notify/group.c
795 +++ b/fs/notify/group.c
797 #include <linux/srcu.h>
798 #include <linux/rculist.h>
799 #include <linux/wait.h>
800 +#include <linux/module.h>
802 #include <linux/fsnotify_backend.h>
803 #include "fsnotify.h"
804 @@ -100,6 +101,7 @@ void fsnotify_get_group(struct fsnotify_group *group)
806 atomic_inc(&group->refcnt);
808 +EXPORT_SYMBOL_GPL(fsnotify_get_group);
811 * Drop a reference to a group. Free it if it's through.
812 @@ -109,6 +111,7 @@ void fsnotify_put_group(struct fsnotify_group *group)
813 if (atomic_dec_and_test(&group->refcnt))
814 fsnotify_final_destroy_group(group);
816 +EXPORT_SYMBOL_GPL(fsnotify_put_group);
819 * Create a new fsnotify_group and hold a reference for the group returned.
820 @@ -137,6 +140,7 @@ struct fsnotify_group *fsnotify_alloc_group(const struct fsnotify_ops *ops)
824 +EXPORT_SYMBOL_GPL(fsnotify_alloc_group);
826 int fsnotify_fasync(int fd, struct file *file, int on)
828 diff --git a/fs/notify/mark.c b/fs/notify/mark.c
829 index d3fea0b..5fc06ad 100644
830 --- a/fs/notify/mark.c
831 +++ b/fs/notify/mark.c
832 @@ -113,6 +113,7 @@ void fsnotify_put_mark(struct fsnotify_mark *mark)
833 mark->free_mark(mark);
836 +EXPORT_SYMBOL_GPL(fsnotify_put_mark);
838 /* Calculate mask of events for a list of marks */
839 u32 fsnotify_recalc_mask(struct hlist_head *head)
840 @@ -230,6 +231,7 @@ void fsnotify_destroy_mark(struct fsnotify_mark *mark,
841 mutex_unlock(&group->mark_mutex);
842 fsnotify_free_mark(mark);
844 +EXPORT_SYMBOL_GPL(fsnotify_destroy_mark);
846 void fsnotify_destroy_marks(struct hlist_head *head, spinlock_t *lock)
848 @@ -415,6 +417,7 @@ int fsnotify_add_mark_locked(struct fsnotify_mark *mark,
852 +EXPORT_SYMBOL_GPL(fsnotify_add_mark);
854 int fsnotify_add_mark(struct fsnotify_mark *mark, struct fsnotify_group *group,
855 struct inode *inode, struct vfsmount *mnt, int allow_dups)
856 @@ -533,6 +536,7 @@ void fsnotify_init_mark(struct fsnotify_mark *mark,
857 atomic_set(&mark->refcnt, 1);
858 mark->free_mark = free_mark;
860 +EXPORT_SYMBOL_GPL(fsnotify_init_mark);
863 * Destroy all marks in destroy_list, waits for SRCU period to finish before
864 diff --git a/fs/open.c b/fs/open.c
865 index d3ed817..20d2494 100644
868 @@ -64,6 +64,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
869 inode_unlock(dentry->d_inode);
872 +EXPORT_SYMBOL_GPL(do_truncate);
874 long vfs_truncate(const struct path *path, loff_t length)
876 @@ -695,6 +696,7 @@ int open_check_o_direct(struct file *f)
880 +EXPORT_SYMBOL_GPL(open_check_o_direct);
882 static int do_dentry_open(struct file *f,
884 diff --git a/fs/read_write.c b/fs/read_write.c
885 index 4052813..7dfd732 100644
886 --- a/fs/read_write.c
887 +++ b/fs/read_write.c
888 @@ -525,6 +525,7 @@ vfs_readf_t vfs_readf(struct file *file)
889 return new_sync_read;
890 return ERR_PTR(-ENOSYS);
892 +EXPORT_SYMBOL_GPL(vfs_readf);
894 vfs_writef_t vfs_writef(struct file *file)
896 @@ -536,6 +537,7 @@ vfs_writef_t vfs_writef(struct file *file)
897 return new_sync_write;
898 return ERR_PTR(-ENOSYS);
900 +EXPORT_SYMBOL_GPL(vfs_writef);
902 ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t *pos)
904 diff --git a/fs/splice.c b/fs/splice.c
905 index 28160a7..98c1902 100644
908 @@ -868,6 +868,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out,
910 return splice_write(pipe, out, ppos, len, flags);
912 +EXPORT_SYMBOL_GPL(do_splice_from);
915 * Attempt to initiate a splice from a file to a pipe.
916 @@ -897,6 +898,7 @@ long do_splice_to(struct file *in, loff_t *ppos,
918 return splice_read(in, ppos, pipe, len, flags);
920 +EXPORT_SYMBOL_GPL(do_splice_to);
923 * splice_direct_to_actor - splices data directly between two non-pipes
924 diff --git a/fs/xattr.c b/fs/xattr.c
925 index 2d13b4e..41c2bcd 100644
928 @@ -296,6 +296,7 @@ int __vfs_setxattr_noperm(struct dentry *dentry, const char *name,
929 *xattr_value = value;
932 +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc);
935 __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name,
936 diff --git a/kernel/task_work.c b/kernel/task_work.c
937 index d513051..e056d54 100644
938 --- a/kernel/task_work.c
939 +++ b/kernel/task_work.c
940 @@ -119,3 +119,4 @@ void task_work_run(void)
944 +EXPORT_SYMBOL_GPL(task_work_run);
945 diff --git a/security/commoncap.c b/security/commoncap.c
946 index 8df676f..6b5cc07 100644
947 --- a/security/commoncap.c
948 +++ b/security/commoncap.c
949 @@ -1061,12 +1061,14 @@ int cap_mmap_addr(unsigned long addr)
953 +EXPORT_SYMBOL_GPL(cap_mmap_addr);
955 int cap_mmap_file(struct file *file, unsigned long reqprot,
956 unsigned long prot, unsigned long flags)
960 +EXPORT_SYMBOL_GPL(cap_mmap_file);
962 #ifdef CONFIG_SECURITY
964 diff --git a/security/device_cgroup.c b/security/device_cgroup.c
965 index 03c1652..f88c84b 100644
966 --- a/security/device_cgroup.c
967 +++ b/security/device_cgroup.c
969 #include <linux/device_cgroup.h>
970 #include <linux/cgroup.h>
971 #include <linux/ctype.h>
972 +#include <linux/export.h>
973 #include <linux/list.h>
974 #include <linux/uaccess.h>
975 #include <linux/seq_file.h>
976 @@ -849,6 +850,7 @@ int __devcgroup_inode_permission(struct inode *inode, int mask)
977 return __devcgroup_check_permission(type, imajor(inode), iminor(inode),
980 +EXPORT_SYMBOL_GPL(__devcgroup_inode_permission);
982 int devcgroup_inode_mknod(int mode, dev_t dev)
984 diff --git a/security/security.c b/security/security.c
985 index f825304..8dd441d 100644
986 --- a/security/security.c
987 +++ b/security/security.c
988 @@ -443,6 +443,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry)
990 return call_int_hook(path_rmdir, 0, dir, dentry);
992 +EXPORT_SYMBOL_GPL(security_path_rmdir);
994 int security_path_unlink(const struct path *dir, struct dentry *dentry)
996 @@ -459,6 +460,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry,
998 return call_int_hook(path_symlink, 0, dir, dentry, old_name);
1000 +EXPORT_SYMBOL_GPL(security_path_symlink);
1002 int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1003 struct dentry *new_dentry)
1004 @@ -467,6 +469,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir,
1006 return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry);
1008 +EXPORT_SYMBOL_GPL(security_path_link);
1010 int security_path_rename(const struct path *old_dir, struct dentry *old_dentry,
1011 const struct path *new_dir, struct dentry *new_dentry,
1012 @@ -494,6 +497,7 @@ int security_path_truncate(const struct path *path)
1014 return call_int_hook(path_truncate, 0, path);
1016 +EXPORT_SYMBOL_GPL(security_path_truncate);
1018 int security_path_chmod(const struct path *path, umode_t mode)
1020 @@ -501,6 +505,7 @@ int security_path_chmod(const struct path *path, umode_t mode)
1022 return call_int_hook(path_chmod, 0, path, mode);
1024 +EXPORT_SYMBOL_GPL(security_path_chmod);
1026 int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1028 @@ -508,6 +513,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid)
1030 return call_int_hook(path_chown, 0, path, uid, gid);
1032 +EXPORT_SYMBOL_GPL(security_path_chown);
1034 int security_path_chroot(const struct path *path)
1036 @@ -593,6 +599,7 @@ int security_inode_readlink(struct dentry *dentry)
1038 return call_int_hook(inode_readlink, 0, dentry);
1040 +EXPORT_SYMBOL_GPL(security_inode_readlink);
1042 int security_inode_follow_link(struct dentry *dentry, struct inode *inode,
1044 @@ -608,6 +615,7 @@ int security_inode_permission(struct inode *inode, int mask)
1046 return call_int_hook(inode_permission, 0, inode, mask);
1048 +EXPORT_SYMBOL_GPL(security_inode_permission);
1050 int security_inode_setattr(struct dentry *dentry, struct iattr *attr)
1052 @@ -779,6 +787,7 @@ int security_file_permission(struct file *file, int mask)
1054 return fsnotify_perm(file, mask);
1056 +EXPORT_SYMBOL_GPL(security_file_permission);
1058 int security_file_alloc(struct file *file)
1060 @@ -838,6 +847,7 @@ int security_mmap_file(struct file *file, unsigned long prot,
1062 return ima_file_mmap(file, prot);
1064 +EXPORT_SYMBOL_GPL(security_mmap_file);
1066 int security_mmap_addr(unsigned long addr)
1068 diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs
1069 --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100
1070 +++ linux/Documentation/ABI/testing/debugfs-aufs 2016-10-09 16:55:36.476034536 +0200
1072 +What: /debug/aufs/si_<id>/
1074 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1076 + Under /debug/aufs, a directory named si_<id> is created
1077 + per aufs mount, where <id> is a unique id generated
1080 +What: /debug/aufs/si_<id>/plink
1082 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1084 + It has three lines and shows the information about the
1085 + pseudo-link. The first line is a single number
1086 + representing a number of buckets. The second line is a
1087 + number of pseudo-links per buckets (separated by a
1088 + blank). The last line is a single number representing a
1089 + total number of psedo-links.
1090 + When the aufs mount option 'noplink' is specified, it
1091 + will show "1\n0\n0\n".
1093 +What: /debug/aufs/si_<id>/xib
1095 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1097 + It shows the consumed blocks by xib (External Inode Number
1098 + Bitmap), its block size and file size.
1099 + When the aufs mount option 'noxino' is specified, it
1100 + will be empty. About XINO files, see the aufs manual.
1102 +What: /debug/aufs/si_<id>/xino0, xino1 ... xinoN
1104 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1106 + It shows the consumed blocks by xino (External Inode Number
1107 + Translation Table), its link count, block size and file
1109 + When the aufs mount option 'noxino' is specified, it
1110 + will be empty. About XINO files, see the aufs manual.
1112 +What: /debug/aufs/si_<id>/xigen
1114 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1116 + It shows the consumed blocks by xigen (External Inode
1117 + Generation Table), its block size and file size.
1118 + If CONFIG_AUFS_EXPORT is disabled, this entry will not
1120 + When the aufs mount option 'noxino' is specified, it
1121 + will be empty. About XINO files, see the aufs manual.
1122 diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs
1123 --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100
1124 +++ linux/Documentation/ABI/testing/sysfs-aufs 2016-10-09 16:55:36.476034536 +0200
1126 +What: /sys/fs/aufs/si_<id>/
1128 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1130 + Under /sys/fs/aufs, a directory named si_<id> is created
1131 + per aufs mount, where <id> is a unique id generated
1134 +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN
1136 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1138 + It shows the abolute path of a member directory (which
1139 + is called branch) in aufs, and its permission.
1141 +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN
1143 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1145 + It shows the id of a member directory (which is called
1148 +What: /sys/fs/aufs/si_<id>/xi_path
1150 +Contact: J. R. Okajima <hooanon05g@gmail.com>
1152 + It shows the abolute path of XINO (External Inode Number
1153 + Bitmap, Translation Table and Generation Table) file
1154 + even if it is the default path.
1155 + When the aufs mount option 'noxino' is specified, it
1156 + will be empty. About XINO files, see the aufs manual.
1157 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt
1158 --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100
1159 +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2016-10-09 16:55:36.479367956 +0200
1162 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1164 +# This program is free software; you can redistribute it and/or modify
1165 +# it under the terms of the GNU General Public License as published by
1166 +# the Free Software Foundation; either version 2 of the License, or
1167 +# (at your option) any later version.
1169 +# This program is distributed in the hope that it will be useful,
1170 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1171 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1172 +# GNU General Public License for more details.
1174 +# You should have received a copy of the GNU General Public License
1175 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1178 +----------------------------------------
1180 +aufs [ei ju: ef es] | [a u f s]
1181 +1. abbrev. for "advanced multi-layered unification filesystem".
1182 +2. abbrev. for "another unionfs".
1183 +3. abbrev. for "auf das" in German which means "on the" in English.
1184 + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E).
1185 + But "Filesystem aufs Filesystem" is hard to understand.
1187 +AUFS is a filesystem with features:
1188 +- multi layered stackable unification filesystem, the member directory
1189 + is called as a branch.
1190 +- branch permission and attribute, 'readonly', 'real-readonly',
1191 + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their
1193 +- internal "file copy-on-write".
1194 +- logical deletion, whiteout.
1195 +- dynamic branch manipulation, adding, deleting and changing permission.
1196 +- allow bypassing aufs, user's direct branch access.
1197 +- external inode number translation table and bitmap which maintains the
1198 + persistent aufs inode number.
1199 +- seekable directory, including NFS readdir.
1200 +- file mapping, mmap and sharing pages.
1201 +- pseudo-link, hardlink over branches.
1202 +- loopback mounted filesystem as a branch.
1203 +- several policies to select one among multiple writable branches.
1204 +- revert a single systemcall when an error occurs in aufs.
1208 +Multi Layered Stackable Unification Filesystem
1209 +----------------------------------------------------------------------
1210 +Most people already knows what it is.
1211 +It is a filesystem which unifies several directories and provides a
1212 +merged single directory. When users access a file, the access will be
1213 +passed/re-directed/converted (sorry, I am not sure which English word is
1214 +correct) to the real file on the member filesystem. The member
1215 +filesystem is called 'lower filesystem' or 'branch' and has a mode
1216 +'readonly' and 'readwrite.' And the deletion for a file on the lower
1217 +readonly branch is handled by creating 'whiteout' on the upper writable
1220 +On LKML, there have been discussions about UnionMount (Jan Blunck,
1221 +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took
1222 +different approaches to implement the merged-view.
1223 +The former tries putting it into VFS, and the latter implements as a
1224 +separate filesystem.
1225 +(If I misunderstand about these implementations, please let me know and
1226 +I shall correct it. Because it is a long time ago when I read their
1227 +source files last time).
1229 +UnionMount's approach will be able to small, but may be hard to share
1230 +branches between several UnionMount since the whiteout in it is
1231 +implemented in the inode on branch filesystem and always
1232 +shared. According to Bharata's post, readdir does not seems to be
1234 +There are several missing features known in this implementations such as
1235 +- for users, the inode number may change silently. eg. copy-up.
1236 +- link(2) may break by copy-up.
1237 +- read(2) may get an obsoleted filedata (fstat(2) too).
1238 +- fcntl(F_SETLK) may be broken by copy-up.
1239 +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after
1242 +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was
1243 +merged into mainline. This is another implementation of UnionMount as a
1244 +separated filesystem. All the limitations and known problems which
1245 +UnionMount are equally inherited to "overlay" filesystem.
1247 +Unionfs has a longer history. When I started implementing a stackable
1248 +filesystem (Aug 2005), it already existed. It has virtual super_block,
1249 +inode, dentry and file objects and they have an array pointing lower
1250 +same kind objects. After contributing many patches for Unionfs, I
1251 +re-started my project AUFS (Jun 2006).
1253 +In AUFS, the structure of filesystem resembles to Unionfs, but I
1254 +implemented my own ideas, approaches and enhancements and it became
1255 +totally different one.
1257 +Comparing DM snapshot and fs based implementation
1258 +- the number of bytes to be copied between devices is much smaller.
1259 +- the type of filesystem must be one and only.
1260 +- the fs must be writable, no readonly fs, even for the lower original
1261 + device. so the compression fs will not be usable. but if we use
1262 + loopback mount, we may address this issue.
1264 + mount /cdrom/squashfs.img /sq
1265 + losetup /sq/ext2.img
1266 + losetup /somewhere/cow
1267 + dmsetup "snapshot /dev/loop0 /dev/loop1 ..."
1268 +- it will be difficult (or needs more operations) to extract the
1269 + difference between the original device and COW.
1270 +- DM snapshot-merge may help a lot when users try merging. in the
1271 + fs-layer union, users will use rsync(1).
1273 +You may want to read my old paper "Filesystems in LiveCD"
1274 +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf).
1277 +Several characters/aspects/persona of aufs
1278 +----------------------------------------------------------------------
1280 +Aufs has several characters, aspects or persona.
1281 +1. a filesystem, callee of VFS helper
1282 +2. sub-VFS, caller of VFS helper for branches
1283 +3. a virtual filesystem which maintains persistent inode number
1284 +4. reader/writer of files on branches such like an application
1286 +1. Callee of VFS Helper
1287 +As an ordinary linux filesystem, aufs is a callee of VFS. For instance,
1288 +unlink(2) from an application reaches sys_unlink() kernel function and
1289 +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it
1290 +calls filesystem specific unlink operation. Actually aufs implements the
1291 +unlink operation but it behaves like a redirector.
1293 +2. Caller of VFS Helper for Branches
1294 +aufs_unlink() passes the unlink request to the branch filesystem as if
1295 +it were called from VFS. So the called unlink operation of the branch
1296 +filesystem acts as usual. As a caller of VFS helper, aufs should handle
1297 +every necessary pre/post operation for the branch filesystem.
1298 +- acquire the lock for the parent dir on a branch
1299 +- lookup in a branch
1300 +- revalidate dentry on a branch
1301 +- mnt_want_write() for a branch
1302 +- vfs_unlink() for a branch
1303 +- mnt_drop_write() for a branch
1304 +- release the lock on a branch
1306 +3. Persistent Inode Number
1307 +One of the most important issue for a filesystem is to maintain inode
1308 +numbers. This is particularly important to support exporting a
1309 +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a
1310 +backend block device for its own. But some storage is necessary to
1311 +keep and maintain the inode numbers. It may be a large space and may not
1312 +suit to keep in memory. Aufs rents some space from its first writable
1313 +branch filesystem (by default) and creates file(s) on it. These files
1314 +are created by aufs internally and removed soon (currently) keeping
1316 +Note: Because these files are removed, they are totally gone after
1317 + unmounting aufs. It means the inode numbers are not persistent
1318 + across unmount or reboot. I have a plan to make them really
1319 + persistent which will be important for aufs on NFS server.
1321 +4. Read/Write Files Internally (copy-on-write)
1322 +Because a branch can be readonly, when you write a file on it, aufs will
1323 +"copy-up" it to the upper writable branch internally. And then write the
1324 +originally requested thing to the file. Generally kernel doesn't
1325 +open/read/write file actively. In aufs, even a single write may cause a
1326 +internal "file copy". This behaviour is very similar to cp(1) command.
1328 +Some people may think it is better to pass such work to user space
1329 +helper, instead of doing in kernel space. Actually I am still thinking
1330 +about it. But currently I have implemented it in kernel space.
1331 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt
1332 --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100
1333 +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2016-10-09 16:55:36.479367956 +0200
1336 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1338 +# This program is free software; you can redistribute it and/or modify
1339 +# it under the terms of the GNU General Public License as published by
1340 +# the Free Software Foundation; either version 2 of the License, or
1341 +# (at your option) any later version.
1343 +# This program is distributed in the hope that it will be useful,
1344 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1345 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1346 +# GNU General Public License for more details.
1348 +# You should have received a copy of the GNU General Public License
1349 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1351 +Basic Aufs Internal Structure
1353 +Superblock/Inode/Dentry/File Objects
1354 +----------------------------------------------------------------------
1355 +As like an ordinary filesystem, aufs has its own
1356 +superblock/inode/dentry/file objects. All these objects have a
1357 +dynamically allocated array and store the same kind of pointers to the
1358 +lower filesystem, branch.
1359 +For example, when you build a union with one readwrite branch and one
1360 +readonly, mounted /au, /rw and /ro respectively.
1362 +- /ro/fileA exists but /rw/fileA
1364 +Aufs lookup operation finds /ro/fileA and gets dentry for that. These
1365 +pointers are stored in a aufs dentry. The array in aufs dentry will be,
1366 +- [0] = NULL (because /rw/fileA doesn't exist)
1369 +This style of an array is essentially same to the aufs
1370 +superblock/inode/dentry/file objects.
1372 +Because aufs supports manipulating branches, ie. add/delete/change
1373 +branches dynamically, these objects has its own generation. When
1374 +branches are changed, the generation in aufs superblock is
1375 +incremented. And a generation in other object are compared when it is
1376 +accessed. When a generation in other objects are obsoleted, aufs
1377 +refreshes the internal array.
1381 +----------------------------------------------------------------------
1382 +Additionally aufs superblock has some data for policies to select one
1383 +among multiple writable branches, XIB files, pseudo-links and kobject.
1384 +See below in detail.
1385 +About the policies which supports copy-down a directory, see
1386 +wbr_policy.txt too.
1389 +Branch and XINO(External Inode Number Translation Table)
1390 +----------------------------------------------------------------------
1391 +Every branch has its own xino (external inode number translation table)
1392 +file. The xino file is created and unlinked by aufs internally. When two
1393 +members of a union exist on the same filesystem, they share the single
1395 +The struct of a xino file is simple, just a sequence of aufs inode
1396 +numbers which is indexed by the lower inode number.
1397 +In the above sample, assume the inode number of /ro/fileA is i111 and
1398 +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as
1399 +4(8) bytes at 111 * 4(8) bytes offset in the xino file.
1401 +When the inode numbers are not contiguous, the xino file will be sparse
1402 +which has a hole in it and doesn't consume as much disk space as it
1403 +might appear. If your branch filesystem consumes disk space for such
1404 +holes, then you should specify 'xino=' option at mounting aufs.
1406 +Aufs has a mount option to free the disk blocks for such holes in XINO
1407 +files on tmpfs or ramdisk. But it is not so effective actually. If you
1408 +meet a problem of disk shortage due to XINO files, then you should try
1409 +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git.
1410 +The patch localizes the assignment inumbers per tmpfs-mount and avoid
1411 +the holes in XINO files.
1413 +Also a writable branch has three kinds of "whiteout bases". All these
1414 +are existed when the branch is joined to aufs, and their names are
1415 +whiteout-ed doubly, so that users will never see their names in aufs
1417 +1. a regular file which will be hardlinked to all whiteouts.
1418 +2. a directory to store a pseudo-link.
1419 +3. a directory to store an "orphan"-ed file temporary.
1422 + When you remove a file on a readonly branch, aufs handles it as a
1423 + logical deletion and creates a whiteout on the upper writable branch
1424 + as a hardlink of this file in order not to consume inode on the
1427 + See below, Pseudo-link.
1429 + When "fileC" exists on the lower readonly branch only and it is
1430 + opened and removed with its parent dir, and then user writes
1431 + something into it, then aufs copies-up fileC to this
1432 + directory. Because there is no other dir to store fileC. After
1433 + creating a file under this dir, the file is unlinked.
1435 +Because aufs supports manipulating branches, ie. add/delete/change
1436 +dynamically, a branch has its own id. When the branch order changes,
1437 +aufs finds the new index by searching the branch id.
1441 +----------------------------------------------------------------------
1442 +Assume "fileA" exists on the lower readonly branch only and it is
1443 +hardlinked to "fileB" on the branch. When you write something to fileA,
1444 +aufs copies-up it to the upper writable branch. Additionally aufs
1445 +creates a hardlink under the Pseudo-link Directory of the writable
1446 +branch. The inode of a pseudo-link is kept in aufs super_block as a
1447 +simple list. If fileB is read after unlinking fileA, aufs returns
1448 +filedata from the pseudo-link instead of the lower readonly
1449 +branch. Because the pseudo-link is based upon the inode, to keep the
1450 +inode number by xino (see above) is essentially necessary.
1452 +All the hardlinks under the Pseudo-link Directory of the writable branch
1453 +should be restored in a proper location later. Aufs provides a utility
1454 +to do this. The userspace helpers executed at remounting and unmounting
1456 +During this utility is running, it puts aufs into the pseudo-link
1457 +maintenance mode. In this mode, only the process which began the
1458 +maintenance mode (and its child processes) is allowed to operate in
1459 +aufs. Some other processes which are not related to the pseudo-link will
1460 +be allowed to run too, but the rest have to return an error or wait
1461 +until the maintenance mode ends. If a process already acquires an inode
1462 +mutex (in VFS), it has to return an error.
1465 +XIB(external inode number bitmap)
1466 +----------------------------------------------------------------------
1467 +Addition to the xino file per a branch, aufs has an external inode number
1468 +bitmap in a superblock object. It is also an internal file such like a
1470 +It is a simple bitmap to mark whether the aufs inode number is in-use or
1472 +To reduce the file I/O, aufs prepares a single memory page to cache xib.
1474 +As well as XINO files, aufs has a feature to truncate/refresh XIB to
1475 +reduce the number of consumed disk blocks for these files.
1478 +Virtual or Vertical Dir, and Readdir in Userspace
1479 +----------------------------------------------------------------------
1480 +In order to support multiple layers (branches), aufs readdir operation
1481 +constructs a virtual dir block on memory. For readdir, aufs calls
1482 +vfs_readdir() internally for each dir on branches, merges their entries
1483 +with eliminating the whiteout-ed ones, and sets it to file (dir)
1484 +object. So the file object has its entry list until it is closed. The
1485 +entry list will be updated when the file position is zero and becomes
1486 +obsoleted. This decision is made in aufs automatically.
1488 +The dynamically allocated memory block for the name of entries has a
1489 +unit of 512 bytes (by default) and stores the names contiguously (no
1490 +padding). Another block for each entry is handled by kmem_cache too.
1491 +During building dir blocks, aufs creates hash list and judging whether
1492 +the entry is whiteouted by its upper branch or already listed.
1493 +The merged result is cached in the corresponding inode object and
1494 +maintained by a customizable life-time option.
1496 +Some people may call it can be a security hole or invite DoS attack
1497 +since the opened and once readdir-ed dir (file object) holds its entry
1498 +list and becomes a pressure for system memory. But I'd say it is similar
1499 +to files under /proc or /sys. The virtual files in them also holds a
1500 +memory page (generally) while they are opened. When an idea to reduce
1501 +memory for them is introduced, it will be applied to aufs too.
1502 +For those who really hate this situation, I've developed readdir(3)
1503 +library which operates this merging in userspace. You just need to set
1504 +LD_PRELOAD environment variable, and aufs will not consume no memory in
1505 +kernel space for readdir(3).
1509 +----------------------------------------------------------------------
1510 +Aufs sometimes requires privilege access to a branch. For instance,
1511 +in copy-up/down operation. When a user process is going to make changes
1512 +to a file which exists in the lower readonly branch only, and the mode
1513 +of one of ancestor directories may not be writable by a user
1514 +process. Here aufs copy-up the file with its ancestors and they may
1515 +require privilege to set its owner/group/mode/etc.
1516 +This is a typical case of a application character of aufs (see
1519 +Aufs uses workqueue synchronously for this case. It creates its own
1520 +workqueue. The workqueue is a kernel thread and has privilege. Aufs
1521 +passes the request to call mkdir or write (for example), and wait for
1522 +its completion. This approach solves a problem of a signal handler
1524 +If aufs didn't adopt the workqueue and changed the privilege of the
1525 +process, then the process may receive the unexpected SIGXFSZ or other
1528 +Also aufs uses the system global workqueue ("events" kernel thread) too
1529 +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a
1530 +whiteout base and etc. This is unrelated to a privilege.
1531 +Most of aufs operation tries acquiring a rw_semaphore for aufs
1532 +superblock at the beginning, at the same time waits for the completion
1533 +of all queued asynchronous tasks.
1537 +----------------------------------------------------------------------
1538 +The whiteout in aufs is very similar to Unionfs's. That is represented
1539 +by its filename. UnionMount takes an approach of a file mode, but I am
1540 +afraid several utilities (find(1) or something) will have to support it.
1542 +Basically the whiteout represents "logical deletion" which stops aufs to
1543 +lookup further, but also it represents "dir is opaque" which also stop
1546 +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively.
1547 +In order to make several functions in a single systemcall to be
1548 +revertible, aufs adopts an approach to rename a directory to a temporary
1549 +unique whiteouted name.
1550 +For example, in rename(2) dir where the target dir already existed, aufs
1551 +renames the target dir to a temporary unique whiteouted name before the
1552 +actual rename on a branch, and then handles other actions (make it opaque,
1553 +update the attributes, etc). If an error happens in these actions, aufs
1554 +simply renames the whiteouted name back and returns an error. If all are
1555 +succeeded, aufs registers a function to remove the whiteouted unique
1556 +temporary name completely and asynchronously to the system global
1561 +----------------------------------------------------------------------
1562 +It is a well-known feature or concept.
1563 +When user modifies a file on a readonly branch, aufs operate "copy-up"
1564 +internally and makes change to the new file on the upper writable branch.
1565 +When the trigger systemcall does not update the timestamps of the parent
1566 +dir, aufs reverts it after copy-up.
1569 +Move-down (aufs3.9 and later)
1570 +----------------------------------------------------------------------
1571 +"Copy-up" is one of the essential feature in aufs. It copies a file from
1572 +the lower readonly branch to the upper writable branch when a user
1573 +changes something about the file.
1574 +"Move-down" is an opposite action of copy-up. Basically this action is
1575 +ran manually instead of automatically and internally.
1576 +For desgin and implementation, aufs has to consider these issues.
1577 +- whiteout for the file may exist on the lower branch.
1578 +- ancestor directories may not exist on the lower branch.
1579 +- diropq for the ancestor directories may exist on the upper branch.
1580 +- free space on the lower branch will reduce.
1581 +- another access to the file may happen during moving-down, including
1582 + UDBA (see "Revalidate Dentry and UDBA").
1583 +- the file should not be hard-linked nor pseudo-linked. they should be
1584 + handled by auplink utility later.
1586 +Sometimes users want to move-down a file from the upper writable branch
1587 +to the lower readonly or writable branch. For instance,
1588 +- the free space of the upper writable branch is going to run out.
1589 +- create a new intermediate branch between the upper and lower branch.
1592 +For this purpose, use "aumvdown" command in aufs-util.git.
1593 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt
1594 --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100
1595 +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2016-10-09 16:55:36.479367956 +0200
1598 +# Copyright (C) 2015-2016 Junjiro R. Okajima
1600 +# This program is free software; you can redistribute it and/or modify
1601 +# it under the terms of the GNU General Public License as published by
1602 +# the Free Software Foundation; either version 2 of the License, or
1603 +# (at your option) any later version.
1605 +# This program is distributed in the hope that it will be useful,
1606 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1607 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1608 +# GNU General Public License for more details.
1610 +# You should have received a copy of the GNU General Public License
1611 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1613 +Support for a branch who has its ->atomic_open()
1614 +----------------------------------------------------------------------
1615 +The filesystems who implement its ->atomic_open() are not majority. For
1616 +example NFSv4 does, and aufs should call NFSv4 ->atomic_open,
1617 +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than
1618 +->atomic_open(), NFSv4 returns an error for this open(2). While I am not
1619 +sure whether all filesystems who have ->atomic_open() behave like this,
1620 +but NFSv4 surely returns the error.
1622 +In order to support ->atomic_open() for aufs, there are a few
1625 +A. Introduce aufs_atomic_open()
1626 + - calls one of VFS:do_last(), lookup_open() or atomic_open() for
1628 +B. Introduce aufs_atomic_open() calling create, open and chmod. this is
1629 + an aufs user Pip Cet's approach
1630 + - calls aufs_create(), VFS finish_open() and notify_change().
1631 + - pass fake-mode to finish_open(), and then correct the mode by
1633 +C. Extend aufs_open() to call branch fs's ->atomic_open()
1634 + - no aufs_atomic_open().
1635 + - aufs_lookup() registers the TID to an aufs internal object.
1636 + - aufs_create() does nothing when the matching TID is registered, but
1637 + registers the mode.
1638 + - aufs_open() calls branch fs's ->atomic_open() when the matching
1639 + TID is registered.
1640 +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's
1642 + - no aufs_atomic_open().
1643 + - aufs_create() registers the TID to an internal object. this info
1644 + represents "this process created this file just now."
1645 + - when aufs gets EACCES from branch fs's ->open(), then confirm the
1646 + registered TID and re-try open() with superuser's credential.
1648 +Pros and cons for each approach.
1651 + - straightforward but highly depends upon VFS internal.
1652 + - the atomic behavaiour is kept.
1653 + - some of parameters such as nameidata are hard to reproduce for
1657 + - easy to implement.
1658 + - the atomic behavaiour is lost.
1660 + - the atomic behavaiour is kept.
1661 + - dirty and tricky.
1662 + - VFS checks whether the file is created correctly after calling
1663 + ->create(), which means this approach doesn't work.
1665 + - easy to implement.
1666 + - the atomic behavaiour is lost.
1667 + - to open a file with superuser's credential and give it to a user
1668 + process is a bad idea, since the file object keeps the credential
1669 + in it. It may affect LSM or something. This approach doesn't work
1672 +The approach A is ideal, but it hard to implement. So here is a
1673 +variation of A, which is to be implemented.
1675 +A-1. Introduce aufs_atomic_open()
1676 + - calls branch fs ->atomic_open() if exists. otherwise calls
1677 + vfs_create() and finish_open().
1678 + - the demerit is that the several checks after branch fs
1679 + ->atomic_open() are lost. in the ordinary case, the checks are
1680 + done by VFS:do_last(), lookup_open() and atomic_open(). some can
1681 + be implemented in aufs, but not all I am afraid.
1682 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt
1683 --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100
1684 +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2016-10-09 16:55:36.479367956 +0200
1687 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1689 +# This program is free software; you can redistribute it and/or modify
1690 +# it under the terms of the GNU General Public License as published by
1691 +# the Free Software Foundation; either version 2 of the License, or
1692 +# (at your option) any later version.
1694 +# This program is distributed in the hope that it will be useful,
1695 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1696 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1697 +# GNU General Public License for more details.
1699 +# You should have received a copy of the GNU General Public License
1700 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1703 +----------------------------------------------------------------------
1704 +Since aufs has a character of sub-VFS (see Introduction), it operates
1705 +lookup for branches as VFS does. It may be a heavy work. But almost all
1706 +lookup operation in aufs is the simplest case, ie. lookup only an entry
1707 +directly connected to its parent. Digging down the directory hierarchy
1708 +is unnecessary. VFS has a function lookup_one_len() for that use, and
1711 +When a branch is a remote filesystem, aufs basically relies upon its
1712 +->d_revalidate(), also aufs forces the hardest revalidate tests for
1714 +For d_revalidate, aufs implements three levels of revalidate tests. See
1715 +"Revalidate Dentry and UDBA" in detail.
1718 +Test Only the Highest One for the Directory Permission (dirperm1 option)
1719 +----------------------------------------------------------------------
1720 +Let's try case study.
1721 +- aufs has two branches, upper readwrite and lower readonly.
1723 +- "dirA" exists under /ro, but /rw. and its mode is 0700.
1724 +- user invoked "chmod a+rx /au/dirA"
1725 +- the internal copy-up is activated and "/rw/dirA" is created and its
1726 + permission bits are set to world readable.
1727 +- then "/au/dirA" becomes world readable?
1729 +In this case, /ro/dirA is still 0700 since it exists in readonly branch,
1730 +or it may be a natively readonly filesystem. If aufs respects the lower
1731 +branch, it should not respond readdir request from other users. But user
1732 +allowed it by chmod. Should really aufs rejects showing the entries
1735 +To be honest, I don't have a good solution for this case. So aufs
1736 +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to
1738 +When dirperm1 is specified, aufs checks only the highest one for the
1739 +directory permission, and shows the entries. Otherwise, as usual, checks
1740 +every dir existing on all branches and rejects the request.
1742 +As a side effect, dirperm1 option improves the performance of aufs
1743 +because the number of permission check is reduced when the number of
1747 +Revalidate Dentry and UDBA (User's Direct Branch Access)
1748 +----------------------------------------------------------------------
1749 +Generally VFS helpers re-validate a dentry as a part of lookup.
1750 +0. digging down the directory hierarchy.
1751 +1. lock the parent dir by its i_mutex.
1752 +2. lookup the final (child) entry.
1754 +4. call the actual operation (create, unlink, etc.)
1755 +5. unlock the parent dir
1757 +If the filesystem implements its ->d_revalidate() (step 3), then it is
1758 +called. Actually aufs implements it and checks the dentry on a branch is
1760 +But it is not enough. Because aufs has to release the lock for the
1761 +parent dir on a branch at the end of ->lookup() (step 2) and
1762 +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still
1764 +If the file on a branch is changed directly, eg. bypassing aufs, after
1765 +aufs released the lock, then the subsequent operation may cause
1766 +something unpleasant result.
1768 +This situation is a result of VFS architecture, ->lookup() and
1769 +->d_revalidate() is separated. But I never say it is wrong. It is a good
1770 +design from VFS's point of view. It is just not suitable for sub-VFS
1773 +Aufs supports such case by three level of revalidation which is
1774 +selectable by user.
1775 +1. Simple Revalidate
1776 + Addition to the native flow in VFS's, confirm the child-parent
1777 + relationship on the branch just after locking the parent dir on the
1778 + branch in the "actual operation" (step 4). When this validation
1779 + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still
1780 + checks the validation of the dentry on branches.
1781 +2. Monitor Changes Internally by Inotify/Fsnotify
1782 + Addition to above, in the "actual operation" (step 4) aufs re-lookup
1783 + the dentry on the branch, and returns EBUSY if it finds different
1785 + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches
1786 + during it is in cache. When the event is notified, aufs registers a
1787 + function to kernel 'events' thread by schedule_work(). And the
1788 + function sets some special status to the cached aufs dentry and inode
1789 + private data. If they are not cached, then aufs has nothing to
1790 + do. When the same file is accessed through aufs (step 0-3) later,
1791 + aufs will detect the status and refresh all necessary data.
1792 + In this mode, aufs has to ignore the event which is fired by aufs
1794 +3. No Extra Validation
1795 + This is the simplest test and doesn't add any additional revalidation
1796 + test, and skip the revalidation in step 4. It is useful and improves
1797 + aufs performance when system surely hide the aufs branches from user,
1798 + by over-mounting something (or another method).
1799 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt
1800 --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100
1801 +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2016-10-09 16:55:36.482701377 +0200
1804 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1806 +# This program is free software; you can redistribute it and/or modify
1807 +# it under the terms of the GNU General Public License as published by
1808 +# the Free Software Foundation; either version 2 of the License, or
1809 +# (at your option) any later version.
1811 +# This program is distributed in the hope that it will be useful,
1812 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1813 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1814 +# GNU General Public License for more details.
1816 +# You should have received a copy of the GNU General Public License
1817 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1819 +Branch Manipulation
1821 +Since aufs supports dynamic branch manipulation, ie. add/remove a branch
1822 +and changing its permission/attribute, there are a lot of works to do.
1826 +----------------------------------------------------------------------
1827 +o Confirm the adding dir exists outside of aufs, including loopback
1828 + mount, and its various attributes.
1829 +o Initialize the xino file and whiteout bases if necessary.
1832 +o Check the owner/group/mode of the directory
1833 + When the owner/group/mode of the adding directory differs from the
1834 + existing branch, aufs issues a warning because it may impose a
1836 + For example, when a upper writable branch has a world writable empty
1837 + top directory, a malicious user can create any files on the writable
1838 + branch directly, like copy-up and modify manually. If something like
1839 + /etc/{passwd,shadow} exists on the lower readonly branch but the upper
1840 + writable branch, and the writable branch is world-writable, then a
1841 + malicious guy may create /etc/passwd on the writable branch directly
1842 + and the infected file will be valid in aufs.
1843 + I am afraid it can be a security issue, but aufs can do nothing except
1844 + producing a warning.
1848 +----------------------------------------------------------------------
1849 +o Confirm the deleting branch is not busy
1850 + To be general, there is one merit to adopt "remount" interface to
1851 + manipulate branches. It is to discard caches. At deleting a branch,
1852 + aufs checks the still cached (and connected) dentries and inodes. If
1853 + there are any, then they are all in-use. An inode without its
1854 + corresponding dentry can be alive alone (for example, inotify/fsnotify case).
1856 + For the cached one, aufs checks whether the same named entry exists on
1858 + If the cached one is a directory, because aufs provides a merged view
1859 + to users, as long as one dir is left on any branch aufs can show the
1860 + dir to users. In this case, the branch can be removed from aufs.
1861 + Otherwise aufs rejects deleting the branch.
1863 + If any file on the deleting branch is opened by aufs, then aufs
1867 +Modify the Permission of a Branch
1868 +----------------------------------------------------------------------
1869 +o Re-initialize or remove the xino file and whiteout bases if necessary.
1872 +o rw --> ro: Confirm the modifying branch is not busy
1873 + Aufs rejects the request if any of these conditions are true.
1874 + - a file on the branch is mmap-ed.
1875 + - a regular file on the branch is opened for write and there is no
1876 + same named entry on the upper branch.
1877 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt
1878 --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100
1879 +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2016-10-09 16:55:36.482701377 +0200
1882 +# Copyright (C) 2005-2016 Junjiro R. Okajima
1884 +# This program is free software; you can redistribute it and/or modify
1885 +# it under the terms of the GNU General Public License as published by
1886 +# the Free Software Foundation; either version 2 of the License, or
1887 +# (at your option) any later version.
1889 +# This program is distributed in the hope that it will be useful,
1890 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1891 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1892 +# GNU General Public License for more details.
1894 +# You should have received a copy of the GNU General Public License
1895 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
1897 +Policies to Select One among Multiple Writable Branches
1898 +----------------------------------------------------------------------
1899 +When the number of writable branch is more than one, aufs has to decide
1900 +the target branch for file creation or copy-up. By default, the highest
1901 +writable branch which has the parent (or ancestor) dir of the target
1902 +file is chosen (top-down-parent policy).
1903 +By user's request, aufs implements some other policies to select the
1904 +writable branch, for file creation several policies, round-robin,
1905 +most-free-space, and other policies. For copy-up, top-down-parent,
1906 +bottom-up-parent, bottom-up and others.
1908 +As expected, the round-robin policy selects the branch in circular. When
1909 +you have two writable branches and creates 10 new files, 5 files will be
1910 +created for each branch. mkdir(2) systemcall is an exception. When you
1911 +create 10 new directories, all will be created on the same branch.
1912 +And the most-free-space policy selects the one which has most free
1913 +space among the writable branches. The amount of free space will be
1914 +checked by aufs internally, and users can specify its time interval.
1916 +The policies for copy-up is more simple,
1917 +top-down-parent is equivalent to the same named on in create policy,
1918 +bottom-up-parent selects the writable branch where the parent dir
1919 +exists and the nearest upper one from the copyup-source,
1920 +bottom-up selects the nearest upper writable branch from the
1921 +copyup-source, regardless the existence of the parent dir.
1923 +There are some rules or exceptions to apply these policies.
1924 +- If there is a readonly branch above the policy-selected branch and
1925 + the parent dir is marked as opaque (a variation of whiteout), or the
1926 + target (creating) file is whiteout-ed on the upper readonly branch,
1927 + then the result of the policy is ignored and the target file will be
1928 + created on the nearest upper writable branch than the readonly branch.
1929 +- If there is a writable branch above the policy-selected branch and
1930 + the parent dir is marked as opaque or the target file is whiteouted
1931 + on the branch, then the result of the policy is ignored and the target
1932 + file will be created on the highest one among the upper writable
1933 + branches who has diropq or whiteout. In case of whiteout, aufs removes
1935 +- link(2) and rename(2) systemcalls are exceptions in every policy.
1936 + They try selecting the branch where the source exists as possible
1937 + since copyup a large file will take long time. If it can't be,
1938 + ie. the branch where the source exists is readonly, then they will
1939 + follow the copyup policy.
1940 +- There is an exception for rename(2) when the target exists.
1941 + If the rename target exists, aufs compares the index of the branches
1942 + where the source and the target exists and selects the higher
1943 + one. If the selected branch is readonly, then aufs follows the
1945 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt
1946 --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100
1947 +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2016-10-09 16:55:36.482701377 +0200
1950 +# Copyright (C) 2011-2016 Junjiro R. Okajima
1952 +# This program is free software; you can redistribute it and/or modify
1953 +# it under the terms of the GNU General Public License as published by
1954 +# the Free Software Foundation; either version 2 of the License, or
1955 +# (at your option) any later version.
1957 +# This program is distributed in the hope that it will be useful,
1958 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
1959 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1960 +# GNU General Public License for more details.
1962 +# You should have received a copy of the GNU General Public License
1963 +# along with this program; if not, write to the Free Software
1964 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1967 +File-based Hierarchical Storage Management (FHSM)
1968 +----------------------------------------------------------------------
1969 +Hierarchical Storage Management (or HSM) is a well-known feature in the
1970 +storage world. Aufs provides this feature as file-based with multiple
1971 +writable branches, based upon the principle of "Colder, the Lower".
1972 +Here the word "colder" means that the less used files, and "lower" means
1973 +that the position in the order of the stacked branches vertically.
1974 +These multiple writable branches are prioritized, ie. the topmost one
1975 +should be the fastest drive and be used heavily.
1977 +o Characters in aufs FHSM story
1978 +- aufs itself and a new branch attribute.
1979 +- a new ioctl interface to move-down and to establish a connection with
1980 + the daemon ("move-down" is a converse of "copy-up").
1981 +- userspace tool and daemon.
1983 +The userspace daemon establishes a connection with aufs and waits for
1984 +the notification. The notified information is very similar to struct
1985 +statfs containing the number of consumed blocks and inodes.
1986 +When the consumed blocks/inodes of a branch exceeds the user-specified
1987 +upper watermark, the daemon activates its move-down process until the
1988 +consumed blocks/inodes reaches the user-specified lower watermark.
1990 +The actual move-down is done by aufs based upon the request from
1991 +user-space since we need to maintain the inode number and the internal
1992 +pointer arrays in aufs.
1994 +Currently aufs FHSM handles the regular files only. Additionally they
1995 +must not be hard-linked nor pseudo-linked.
1998 +o Cowork of aufs and the user-space daemon
1999 + During the userspace daemon established the connection, aufs sends a
2000 + small notification to it whenever aufs writes something into the
2001 + writable branch. But it may cost high since aufs issues statfs(2)
2002 + internally. So user can specify a new option to cache the
2003 + info. Actually the notification is controlled by these factors.
2004 + + the specified cache time.
2005 + + classified as "force" by aufs internally.
2006 + Until the specified time expires, aufs doesn't send the info
2007 + except the forced cases. When aufs decide forcing, the info is always
2008 + notified to userspace.
2009 + For example, the number of free inodes is generally large enough and
2010 + the shortage of it happens rarely. So aufs doesn't force the
2011 + notification when creating a new file, directory and others. This is
2012 + the typical case which aufs doesn't force.
2013 + When aufs writes the actual filedata and the files consumes any of new
2014 + blocks, the aufs forces notifying.
2017 +o Interfaces in aufs
2018 +- New branch attribute.
2020 + Specifies that the branch is managed by FHSM feature. In other word,
2021 + participant in the FHSM.
2022 + When nofhsm is set to the branch, it will not be the source/target
2023 + branch of the move-down operation. This attribute is set
2024 + independently from coo and moo attributes, and if you want full
2025 + FHSM, you should specify them as well.
2026 +- New mount option.
2028 + Specifies a second to suppress many less important info to be
2031 + + AUFS_CTL_FHSM_FD
2032 + create a new file descriptor which userspace can read the notification
2033 + (a subset of struct statfs) from aufs.
2034 +- Module parameter 'brs'
2035 + It has to be set to 1. Otherwise the new mount option 'fhsm' will not
2037 +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs
2038 + When there are two or more branches with fhsm attributes,
2039 + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs
2040 + terminates it. As a result of remounting and branch-manipulation, the
2041 + number of branches with fhsm attribute can be one. In this case,
2042 + /sbin/mount.aufs will terminate the user-space daemon.
2045 +Finally the operation is done as these steps in kernel-space.
2047 + + no one else is using the file.
2048 + + the file is not hard-linked.
2049 + + the file is not pseudo-linked.
2050 + + the file is a regular file.
2051 + + the parent dir is not opaqued.
2052 +- find the target writable branch.
2053 +- make sure the file is not whiteout-ed by the upper (than the target)
2055 +- make the parent dir on the target branch.
2056 +- mutex lock the inode on the branch.
2057 +- unlink the whiteout on the target branch (if exists).
2058 +- lookup and create the whiteout-ed temporary name on the target branch.
2059 +- copy the file as the whiteout-ed temporary name on the target branch.
2060 +- rename the whiteout-ed temporary name to the original name.
2061 +- unlink the file on the source branch.
2062 +- maintain the internal pointer array and the external inode number
2064 +- maintain the timestamps and other attributes of the parent dir and the
2067 +And of course, in every step, an error may happen. So the operation
2068 +should restore the original file state after an error happens.
2069 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt
2070 --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100
2071 +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2016-10-09 16:55:36.482701377 +0200
2074 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2076 +# This program is free software; you can redistribute it and/or modify
2077 +# it under the terms of the GNU General Public License as published by
2078 +# the Free Software Foundation; either version 2 of the License, or
2079 +# (at your option) any later version.
2081 +# This program is distributed in the hope that it will be useful,
2082 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2083 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2084 +# GNU General Public License for more details.
2086 +# You should have received a copy of the GNU General Public License
2087 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2089 +mmap(2) -- File Memory Mapping
2090 +----------------------------------------------------------------------
2091 +In aufs, the file-mapped pages are handled by a branch fs directly, no
2092 +interaction with aufs. It means aufs_mmap() calls the branch fs's
2094 +This approach is simple and good, but there is one problem.
2095 +Under /proc, several entries show the mmapped files by its path (with
2096 +device and inode number), and the printed path will be the path on the
2097 +branch fs's instead of virtual aufs's.
2098 +This is not a problem in most cases, but some utilities lsof(1) (and its
2099 +user) may expect the path on aufs.
2101 +To address this issue, aufs adds a new member called vm_prfile in struct
2102 +vm_area_struct (and struct vm_region). The original vm_file points to
2103 +the file on the branch fs in order to handle everything correctly as
2104 +usual. The new vm_prfile points to a virtual file in aufs, and the
2105 +show-functions in procfs refers to vm_prfile if it is set.
2106 +Also we need to maintain several other places where touching vm_file
2108 +- fork()/clone() copies vma and the reference count of vm_file is
2110 +- merging vma maintains the ref count too.
2112 +This is not a good approach. It just fakes the printed path. But it
2113 +leaves all behaviour around f_mapping unchanged. This is surely an
2115 +Actually aufs had adopted another complicated approach which calls
2116 +generic_file_mmap() and handles struct vm_operations_struct. In this
2117 +approach, aufs met a hard problem and I could not solve it without
2118 +switching the approach.
2120 +There may be one more another approach which is
2121 +- bind-mount the branch-root onto the aufs-root internally
2122 +- grab the new vfsmount (ie. struct mount)
2123 +- lazy-umount the branch-root internally
2124 +- in open(2) the aufs-file, open the branch-file with the hidden
2125 + vfsmount (instead of the original branch's vfsmount)
2126 +- ideally this "bind-mount and lazy-umount" should be done atomically,
2127 + but it may be possible from userspace by the mount helper.
2129 +Adding the internal hidden vfsmount and using it in opening a file, the
2130 +file path under /proc will be printed correctly. This approach looks
2131 +smarter, but is not possible I am afraid.
2132 +- aufs-root may be bind-mount later. when it happens, another hidden
2133 + vfsmount will be required.
2134 +- it is hard to get the chance to bind-mount and lazy-umount
2135 + + in kernel-space, FS can have vfsmount in open(2) via
2136 + file->f_path, and aufs can know its vfsmount. But several locks are
2137 + already acquired, and if aufs tries to bind-mount and lazy-umount
2138 + here, then it may cause a deadlock.
2139 + + in user-space, bind-mount doesn't invoke the mount helper.
2140 +- since /proc shows dev and ino, aufs has to give vma these info. it
2141 + means a new member vm_prinode will be necessary. this is essentially
2142 + equivalent to vm_prfile described above.
2144 +I have to give up this "looks-smater" approach.
2145 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt
2146 --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100
2147 +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2016-10-09 16:55:36.482701377 +0200
2150 +# Copyright (C) 2014-2016 Junjiro R. Okajima
2152 +# This program is free software; you can redistribute it and/or modify
2153 +# it under the terms of the GNU General Public License as published by
2154 +# the Free Software Foundation; either version 2 of the License, or
2155 +# (at your option) any later version.
2157 +# This program is distributed in the hope that it will be useful,
2158 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2159 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2160 +# GNU General Public License for more details.
2162 +# You should have received a copy of the GNU General Public License
2163 +# along with this program; if not, write to the Free Software
2164 +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2167 +Listing XATTR/EA and getting the value
2168 +----------------------------------------------------------------------
2169 +For the inode standard attributes (owner, group, timestamps, etc.), aufs
2170 +shows the values from the topmost existing file. This behaviour is good
2171 +for the non-dir entries since the bahaviour exactly matches the shown
2172 +information. But for the directories, aufs considers all the same named
2173 +entries on the lower branches. Which means, if one of the lower entry
2174 +rejects readdir call, then aufs returns an error even if the topmost
2175 +entry allows it. This behaviour is necessary to respect the branch fs's
2176 +security, but can make users confused since the user-visible standard
2177 +attributes don't match the behaviour.
2178 +To address this issue, aufs has a mount option called dirperm1 which
2179 +checks the permission for the topmost entry only, and ignores the lower
2180 +entry's permission.
2182 +A similar issue can happen around XATTR.
2183 +getxattr(2) and listxattr(2) families behave as if dirperm1 option is
2184 +always set. Otherwise these very unpleasant situation would happen.
2185 +- listxattr(2) may return the duplicated entries.
2186 +- users may not be able to remove or reset the XATTR forever,
2189 +XATTR/EA support in the internal (copy,move)-(up,down)
2190 +----------------------------------------------------------------------
2191 +Generally the extended attributes of inode are categorized as these.
2192 +- "security" for LSM and capability.
2193 +- "system" for posix ACL, 'acl' mount option is required for the branch
2195 +- "trusted" for userspace, CAP_SYS_ADMIN is required.
2196 +- "user" for userspace, 'user_xattr' mount option is required for the
2197 + branch fs generally.
2199 +Moreover there are some other categories. Aufs handles these rather
2200 +unpopular categories as the ordinary ones, ie. there is no special
2201 +condition nor exception.
2203 +In copy-up, the support for XATTR on the dst branch may differ from the
2204 +src branch. In this case, the copy-up operation will get an error and
2205 +the original user operation which triggered the copy-up will fail. It
2206 +can happen that even all copy-up will fail.
2207 +When both of src and dst branches support XATTR and if an error occurs
2208 +during copying XATTR, then the copy-up should fail obviously. That is a
2209 +good reason and aufs should return an error to userspace. But when only
2210 +the src branch support that XATTR, aufs should not return an error.
2211 +For example, the src branch supports ACL but the dst branch doesn't
2212 +because the dst branch may natively un-support it or temporary
2213 +un-support it due to "noacl" mount option. Of course, the dst branch fs
2214 +may NOT return an error even if the XATTR is not supported. It is
2215 +totally up to the branch fs.
2217 +Anyway when the aufs internal copy-up gets an error from the dst branch
2218 +fs, then aufs tries removing the just copied entry and returns the error
2219 +to the userspace. The worst case of this situation will be all copy-up
2222 +For the copy-up operation, there two basic approaches.
2223 +- copy the specified XATTR only (by category above), and return the
2224 + error unconditionally if it happens.
2225 +- copy all XATTR, and ignore the error on the specified category only.
2227 +In order to support XATTR and to implement the correct behaviour, aufs
2228 +chooses the latter approach and introduces some new branch attributes,
2229 +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth".
2230 +They correspond to the XATTR namespaces (see above). Additionally, to be
2231 +convenient, "icex" is also provided which means all "icex*" attributes
2232 +are set (here the word "icex" stands for "ignore copy-error on XATTR").
2234 +The meaning of these attributes is to ignore the error from setting
2235 +XATTR on that branch.
2236 +Note that aufs tries copying all XATTR unconditionally, and ignores the
2237 +error from the dst branch according to the specified attributes.
2239 +Some XATTR may have its default value. The default value may come from
2240 +the parent dir or the environment. If the default value is set at the
2241 +file creating-time, it will be overwritten by copy-up.
2242 +Some contradiction may happen I am afraid.
2243 +Do we need another attribute to stop copying XATTR? I am unsure. For
2244 +now, aufs implements the branch attributes to ignore the error.
2245 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt
2246 --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100
2247 +++ linux/Documentation/filesystems/aufs/design/07export.txt 2016-10-09 16:55:36.482701377 +0200
2250 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2252 +# This program is free software; you can redistribute it and/or modify
2253 +# it under the terms of the GNU General Public License as published by
2254 +# the Free Software Foundation; either version 2 of the License, or
2255 +# (at your option) any later version.
2257 +# This program is distributed in the hope that it will be useful,
2258 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2259 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2260 +# GNU General Public License for more details.
2262 +# You should have received a copy of the GNU General Public License
2263 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2265 +Export Aufs via NFS
2266 +----------------------------------------------------------------------
2267 +Here is an approach.
2268 +- like xino/xib, add a new file 'xigen' which stores aufs inode
2270 +- iget_locked(): initialize aufs inode generation for a new inode, and
2271 + store it in xigen file.
2272 +- destroy_inode(): increment aufs inode generation and store it in xigen
2273 + file. it is necessary even if it is not unlinked, because any data of
2274 + inode may be changed by UDBA.
2275 +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise
2276 + build file handle by
2277 + + branch id (4 bytes)
2278 + + superblock generation (4 bytes)
2279 + + inode number (4 or 8 bytes)
2280 + + parent dir inode number (4 or 8 bytes)
2281 + + inode generation (4 bytes))
2282 + + return value of exportfs_encode_fh() for the parent on a branch (4
2284 + + file handle for a branch (by exportfs_encode_fh())
2286 + + find the index of a branch from its id in handle, and check it is
2287 + still exist in aufs.
2288 + + 1st level: get the inode number from handle and search it in cache.
2289 + + 2nd level: if not found in cache, get the parent inode number from
2290 + the handle and search it in cache. and then open the found parent
2291 + dir, find the matching inode number by vfs_readdir() and get its
2292 + name, and call lookup_one_len() for the target dentry.
2293 + + 3rd level: if the parent dir is not cached, call
2294 + exportfs_decode_fh() for a branch and get the parent on a branch,
2295 + build a pathname of it, convert it a pathname in aufs, call
2296 + path_lookup(). now aufs gets a parent dir dentry, then handle it as
2298 + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount
2299 + for every branch, but not itself. to get this, (currently) aufs
2300 + searches in current->nsproxy->mnt_ns list. it may not be a good
2301 + idea, but I didn't get other approach.
2302 + + test the generation of the gotten inode.
2303 +- every inode operation: they may get EBUSY due to UDBA. in this case,
2304 + convert it into ESTALE for NFSD.
2305 +- readdir(): call lockdep_on/off() because filldir in NFSD calls
2306 + lookup_one_len(), vfs_getattr(), encode_fh() and others.
2307 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt
2308 --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100
2309 +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2016-10-09 16:55:36.482701377 +0200
2312 +# Copyright (C) 2005-2016 Junjiro R. Okajima
2314 +# This program is free software; you can redistribute it and/or modify
2315 +# it under the terms of the GNU General Public License as published by
2316 +# the Free Software Foundation; either version 2 of the License, or
2317 +# (at your option) any later version.
2319 +# This program is distributed in the hope that it will be useful,
2320 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2321 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2322 +# GNU General Public License for more details.
2324 +# You should have received a copy of the GNU General Public License
2325 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2327 +Show Whiteout Mode (shwh)
2328 +----------------------------------------------------------------------
2329 +Generally aufs hides the name of whiteouts. But in some cases, to show
2330 +them is very useful for users. For instance, creating a new middle layer
2331 +(branch) by merging existing layers.
2333 +(borrowing aufs1 HOW-TO from a user, Michael Towers)
2334 +When you have three branches,
2335 +- Bottom: 'system', squashfs (underlying base system), read-only
2336 +- Middle: 'mods', squashfs, read-only
2337 +- Top: 'overlay', ram (tmpfs), read-write
2339 +The top layer is loaded at boot time and saved at shutdown, to preserve
2340 +the changes made to the system during the session.
2341 +When larger changes have been made, or smaller changes have accumulated,
2342 +the size of the saved top layer data grows. At this point, it would be
2343 +nice to be able to merge the two overlay branches ('mods' and 'overlay')
2344 +and rewrite the 'mods' squashfs, clearing the top layer and thus
2345 +restoring save and load speed.
2347 +This merging is simplified by the use of another aufs mount, of just the
2348 +two overlay branches using the 'shwh' option.
2349 +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \
2350 + aufs /livesys/merge_union
2352 +A merged view of these two branches is then available at
2353 +/livesys/merge_union, and the new feature is that the whiteouts are
2355 +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable
2356 +writing to all branches. Also the default mode for all branches is 'ro'.
2357 +It is now possible to save the combined contents of the two overlay
2358 +branches to a new squashfs, e.g.:
2359 +# mksquashfs /livesys/merge_union /path/to/newmods.squash
2361 +This new squashfs archive can be stored on the boot device and the
2362 +initramfs will use it to replace the old one at the next boot.
2363 diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt
2364 --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100
2365 +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2016-10-09 16:55:36.482701377 +0200
2368 +# Copyright (C) 2010-2016 Junjiro R. Okajima
2370 +# This program is free software; you can redistribute it and/or modify
2371 +# it under the terms of the GNU General Public License as published by
2372 +# the Free Software Foundation; either version 2 of the License, or
2373 +# (at your option) any later version.
2375 +# This program is distributed in the hope that it will be useful,
2376 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
2377 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2378 +# GNU General Public License for more details.
2380 +# You should have received a copy of the GNU General Public License
2381 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
2383 +Dynamically customizable FS operations
2384 +----------------------------------------------------------------------
2385 +Generally FS operations (struct inode_operations, struct
2386 +address_space_operations, struct file_operations, etc.) are defined as
2387 +"static const", but it never means that FS have only one set of
2388 +operation. Some FS have multiple sets of them. For instance, ext2 has
2389 +three sets, one for XIP, for NOBH, and for normal.
2390 +Since aufs overrides and redirects these operations, sometimes aufs has
2391 +to change its behaviour according to the branch FS type. More importantly
2392 +VFS acts differently if a function (member in the struct) is set or
2393 +not. It means aufs should have several sets of operations and select one
2394 +among them according to the branch FS definition.
2396 +In order to solve this problem and not to affect the behaviour of VFS,
2397 +aufs defines these operations dynamically. For instance, aufs defines
2398 +dummy direct_IO function for struct address_space_operations, but it may
2399 +not be set to the address_space_operations actually. When the branch FS
2400 +doesn't have it, aufs doesn't set it to its address_space_operations
2401 +while the function definition itself is still alive. So the behaviour
2402 +itself will not change, and it will return an error when direct_IO is
2405 +The lifetime of these dynamically generated operation object is
2406 +maintained by aufs branch object. When the branch is removed from aufs,
2407 +the reference counter of the object is decremented. When it reaches
2408 +zero, the dynamically generated operation object will be freed.
2410 +This approach is designed to support AIO (io_submit), Direct I/O and
2412 +Currently this approach is applied to address_space_operations for
2413 +regular files only.
2414 diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README
2415 --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100
2416 +++ linux/Documentation/filesystems/aufs/README 2016-12-17 12:28:17.595211562 +0100
2419 +Aufs4 -- advanced multi layered unification filesystem version 4.x
2425 +----------------------------------------
2426 +In the early days, aufs was entirely re-designed and re-implemented
2427 +Unionfs Version 1.x series. Adding many original ideas, approaches,
2428 +improvements and implementations, it becomes totally different from
2429 +Unionfs while keeping the basic features.
2430 +Recently, Unionfs Version 2.x series begin taking some of the same
2431 +approaches to aufs1's.
2432 +Unionfs is being developed by Professor Erez Zadok at Stony Brook
2433 +University and his team.
2435 +Aufs4 supports linux-4.0 and later, and for linux-3.x series try aufs3.
2436 +If you want older kernel version support, try aufs2-2.6.git or
2437 +aufs2-standalone.git repository, aufs1 from CVS on SourceForge.
2439 +Note: it becomes clear that "Aufs was rejected. Let's give it up."
2440 + According to Christoph Hellwig, linux rejects all union-type
2441 + filesystems but UnionMount.
2442 +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2>
2444 +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and
2445 + UnionMount, and he pointed out an issue around a directory mutex
2446 + lock and aufs addressed it. But it is still unsure whether aufs will
2447 + be merged (or any other union solution).
2448 +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1>
2452 +----------------------------------------
2453 +- unite several directories into a single virtual filesystem. The member
2454 + directory is called as a branch.
2455 +- you can specify the permission flags to the branch, which are 'readonly',
2456 + 'readwrite' and 'whiteout-able.'
2457 +- by upper writable branch, internal copyup and whiteout, files/dirs on
2458 + readonly branch are modifiable logically.
2459 +- dynamic branch manipulation, add, del.
2462 +Also there are many enhancements in aufs, such as:
2463 +- test only the highest one for the directory permission (dirperm1)
2464 +- copyup on open (coo=)
2465 +- 'move' policy for copy-up between two writable branches, after
2466 + checking free space.
2468 +- readdir(3) in userspace.
2469 +- keep inode number by external inode number table
2470 +- keep the timestamps of file/dir in internal copyup operation
2471 +- seekable directory, supporting NFS readdir.
2472 +- whiteout is hardlinked in order to reduce the consumption of inodes
2474 +- do not copyup, nor create a whiteout when it is unnecessary
2475 +- revert a single systemcall when an error occurs in aufs
2476 +- remount interface instead of ioctl
2477 +- maintain /etc/mtab by an external command, /sbin/mount.aufs.
2478 +- loopback mounted filesystem as a branch
2479 +- kernel thread for removing the dir who has a plenty of whiteouts
2480 +- support copyup sparse file (a file which has a 'hole' in it)
2481 +- default permission flags for branches
2482 +- selectable permission flags for ro branch, whether whiteout can
2485 +- support <sysfs>/fs/aufs and <debugfs>/aufs.
2486 +- support multiple writable branches, some policies to select one
2487 + among multiple writable branches.
2488 +- a new semantics for link(2) and rename(2) to support multiple
2489 + writable branches.
2490 +- no glibc changes are required.
2491 +- pseudo hardlink (hardlink over branches)
2492 +- allow a direct access manually to a file on branch, e.g. bypassing aufs.
2493 + including NFS or remote filesystem branch.
2494 +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX.
2497 +Currently these features are dropped temporary from aufs4.
2498 +See design/08plan.txt in detail.
2499 +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs
2501 +- statistics of aufs thread (/sys/fs/aufs/stat)
2503 +Features or just an idea in the future (see also design/*.txt),
2504 +- reorder the branch index without del/re-add.
2505 +- permanent xino files for NFSD
2506 +- an option for refreshing the opened files after add/del branches
2507 +- light version, without branch manipulation. (unnecessary?)
2508 +- copyup in userspace
2509 +- inotify in userspace
2514 +----------------------------------------
2515 +There are three GIT trees for aufs4, aufs4-linux.git,
2516 +aufs4-standalone.git, and aufs-util.git. Note that there is no "4" in
2518 +While the aufs-util is always necessary, you need either of aufs4-linux
2519 +or aufs4-standalone.
2521 +The aufs4-linux tree includes the whole linux mainline GIT tree,
2522 +git://git.kernel.org/.../torvalds/linux.git.
2523 +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot
2524 +build aufs4 as an external kernel module.
2525 +Several extra patches are not included in this tree. Only
2526 +aufs4-standalone tree contains them. They are described in the later
2527 +section "Configuration and Compilation."
2529 +On the other hand, the aufs4-standalone tree has only aufs source files
2530 +and necessary patches, and you can select CONFIG_AUFS_FS=m.
2531 +But you need to apply all aufs patches manually.
2533 +You will find GIT branches whose name is in form of "aufs4.x" where "x"
2534 +represents the linux kernel version, "linux-4.x". For instance,
2535 +"aufs4.0" is for linux-4.0. For latest "linux-4.x-rcN", use
2536 +"aufs4.x-rcN" branch.
2539 +$ git clone --reference /your/linux/git/tree \
2540 + git://github.com/sfjro/aufs4-linux.git aufs4-linux.git
2541 +- if you don't have linux GIT tree, then remove "--reference ..."
2542 +$ cd aufs4-linux.git
2543 +$ git checkout origin/aufs4.0
2545 +Or You may want to directly git-pull aufs into your linux GIT tree, and
2546 +leave the patch-work to GIT.
2547 +$ cd /your/linux/git/tree
2548 +$ git remote add aufs4 git://github.com/sfjro/aufs4-linux.git
2550 +$ git checkout -b my4.0 v4.0
2551 +$ (add your local change...)
2552 +$ git pull aufs4 aufs4.0
2553 +- now you have v4.0 + your_changes + aufs4.0 in you my4.0 branch.
2554 +- you may need to solve some conflicts between your_changes and
2555 + aufs4.0. in this case, git-rerere is recommended so that you can
2556 + solve the similar conflicts automatically when you upgrade to 4.1 or
2557 + later in the future.
2559 +o aufs4-standalone tree
2560 +$ git clone git://github.com/sfjro/aufs4-standalone.git aufs4-standalone.git
2561 +$ cd aufs4-standalone.git
2562 +$ git checkout origin/aufs4.0
2565 +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git
2566 +- note that the public aufs-util.git is on SourceForge instead of
2569 +$ git checkout origin/aufs4.0
2571 +Note: The 4.x-rcN branch is to be used with `rc' kernel versions ONLY.
2572 +The minor version number, 'x' in '4.x', of aufs may not always
2573 +follow the minor version number of the kernel.
2574 +Because changes in the kernel that cause the use of a new
2575 +minor version number do not always require changes to aufs-util.
2577 +Since aufs-util has its own minor version number, you may not be
2578 +able to find a GIT branch in aufs-util for your kernel's
2579 +exact minor version number.
2580 +In this case, you should git-checkout the branch for the
2581 +nearest lower number.
2583 +For (an unreleased) example:
2584 +If you are using "linux-4.10" and the "aufs4.10" branch
2585 +does not exist in aufs-util repository, then "aufs4.9", "aufs4.8"
2586 +or something numerically smaller is the branch for your kernel.
2588 +Also you can view all branches by
2592 +3. Configuration and Compilation
2593 +----------------------------------------
2594 +Make sure you have git-checkout'ed the correct branch.
2596 +For aufs4-linux tree,
2597 +- enable CONFIG_AUFS_FS.
2598 +- set other aufs configurations if necessary.
2600 +For aufs4-standalone tree,
2601 +There are several ways to build.
2604 +- apply ./aufs4-kbuild.patch to your kernel source files.
2605 +- apply ./aufs4-base.patch too.
2606 +- apply ./aufs4-mmap.patch too.
2607 +- apply ./aufs4-standalone.patch too, if you have a plan to set
2608 + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs4-standalone.patch.
2609 +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your
2610 + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild.
2611 +- enable CONFIG_AUFS_FS, you can select either
2613 +- and build your kernel as usual.
2614 +- install the built kernel.
2615 + Note: Since linux-3.9, every filesystem module requires an alias
2616 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2617 + modules.aliases file if you set CONFIG_AUFS_FS=m.
2618 +- install the header files too by "make headers_install" to the
2619 + directory where you specify. By default, it is $PWD/usr.
2620 + "make help" shows a brief note for headers_install.
2621 +- and reboot your system.
2624 +- module only (CONFIG_AUFS_FS=m).
2625 +- apply ./aufs4-base.patch to your kernel source files.
2626 +- apply ./aufs4-mmap.patch too.
2627 +- apply ./aufs4-standalone.patch too.
2628 +- build your kernel, don't forget "make headers_install", and reboot.
2629 +- edit ./config.mk and set other aufs configurations if necessary.
2630 + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes
2631 + every aufs configurations.
2632 +- build the module by simple "make".
2633 + Note: Since linux-3.9, every filesystem module requires an alias
2634 + "fs-<fsname>". You should make sure that "fs-aufs" is listed in your
2635 + modules.aliases file.
2636 +- you can specify ${KDIR} make variable which points to your kernel
2638 +- install the files
2639 + + run "make install" to install the aufs module, or copy the built
2640 + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply).
2641 + + run "make install_headers" (instead of headers_install) to install
2642 + the modified aufs header file (you can specify DESTDIR which is
2643 + available in aufs standalone version's Makefile only), or copy
2644 + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever
2645 + you like manually. By default, the target directory is $PWD/usr.
2646 +- no need to apply aufs4-kbuild.patch, nor copying source files to your
2647 + kernel source tree.
2649 +Note: The header file aufs_type.h is necessary to build aufs-util
2650 + as well as "make headers_install" in the kernel source tree.
2651 + headers_install is subject to be forgotten, but it is essentially
2652 + necessary, not only for building aufs-util.
2653 + You may not meet problems without headers_install in some older
2657 +- read README in aufs-util, build and install it
2658 +- note that your distribution may contain an obsoleted version of
2659 + aufs_type.h in /usr/include/linux or something. When you build aufs
2660 + utilities, make sure that your compiler refers the correct aufs header
2661 + file which is built by "make headers_install."
2662 +- if you want to use readdir(3) in userspace or pathconf(3) wrapper,
2663 + then run "make install_ulib" too. And refer to the aufs manual in
2666 +There several other patches in aufs4-standalone.git. They are all
2667 +optional. When you meet some problems, they will help you.
2668 +- aufs4-loopback.patch
2669 + Supports a nested loopback mount in a branch-fs. This patch is
2670 + unnecessary until aufs produces a message like "you may want to try
2671 + another patch for loopback file".
2673 + Modifies a system global kernel internal function get_next_ino() in
2674 + order to stop assigning 0 for an inode-number. Not directly related to
2675 + aufs, but recommended generally.
2677 + Keeps the tmpfs inode number as the lowest value. Effective to reduce
2678 + the size of aufs XINO files for tmpfs branch. Also it prevents the
2679 + duplication of inode number, which is important for backup tools and
2680 + other utilities. When you find aufs XINO files for tmpfs branch
2681 + growing too much, try this patch.
2682 +- lockdep-debug.patch
2683 + Because aufs is not only an ordinary filesystem (callee of VFS), but
2684 + also a caller of VFS functions for branch filesystems, subclassing of
2685 + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging
2686 + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will
2687 + need to apply this debug patch to expand several constant values.
2688 + If don't know what LOCKDEP, then you don't have apply this patch.
2692 +----------------------------------------
2693 +At first, make sure aufs-util are installed, and please read the aufs
2694 +manual, aufs.5 in aufs-util.git tree.
2698 +$ mkdir /tmp/rw /tmp/aufs
2699 +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs
2701 +Here is another example. The result is equivalent.
2702 +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs
2704 +# mount -t aufs -o br:/tmp/rw none /tmp/aufs
2705 +# mount -o remount,append:${HOME} /tmp/aufs
2707 +Then, you can see whole tree of your home dir through /tmp/aufs. If
2708 +you modify a file under /tmp/aufs, the one on your home directory is
2709 +not affected, instead the same named file will be newly created under
2710 +/tmp/rw. And all of your modification to a file will be applied to
2711 +the one under /tmp/rw. This is called the file based Copy on Write
2713 +Aufs mount options are described in aufs.5.
2714 +If you run chroot or something and make your aufs as a root directory,
2715 +then you need to customize the shutdown script. See the aufs manual in
2718 +Additionally, there are some sample usages of aufs which are a
2719 +diskless system with network booting, and LiveCD over NFS.
2720 +See sample dir in CVS tree on SourceForge.
2724 +----------------------------------------
2725 +When you have any problems or strange behaviour in aufs, please let me
2727 +- /proc/mounts (instead of the output of mount(8))
2728 +- /sys/module/aufs/*
2729 +- /sys/fs/aufs/* (if you have them)
2730 +- /debug/aufs/* (if you have them)
2731 +- linux kernel version
2732 + if your kernel is not plain, for example modified by distributor,
2733 + the url where i can download its source is necessary too.
2734 +- aufs version which was printed at loading the module or booting the
2735 + system, instead of the date you downloaded.
2736 +- configuration (define/undefine CONFIG_AUFS_xxx)
2737 +- kernel configuration or /proc/config.gz (if you have it)
2738 +- behaviour which you think to be incorrect
2739 +- actual operation, reproducible one is better
2740 +- mailto: aufs-users at lists.sourceforge.net
2742 +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches,
2743 +and Feature Requests) on SourceForge. Please join and write to
2747 +6. Acknowledgements
2748 +----------------------------------------
2749 +Thanks to everyone who have tried and are using aufs, whoever
2750 +have reported a bug or any feedback.
2752 +Especially donators:
2753 +Tomas Matejicek(slax.org) made a donation (much more than once).
2754 + Since Apr 2010, Tomas M (the author of Slax and Linux Live
2755 + scripts) is making "doubling" donations.
2756 + Unfortunately I cannot list all of the donators, but I really
2758 + It ends Aug 2010, but the ordinary donation URL is still available.
2759 + <http://sourceforge.net/donate/index.php?group_id=167503>
2760 +Dai Itasaka made a donation (2007/8).
2761 +Chuck Smith made a donation (2008/4, 10 and 12).
2762 +Henk Schoneveld made a donation (2008/9).
2763 +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10).
2764 +Francois Dupoux made a donation (2008/11).
2765 +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public
2766 + aufs2 GIT tree (2009/2).
2767 +William Grant made a donation (2009/3).
2768 +Patrick Lane made a donation (2009/4).
2769 +The Mail Archive (mail-archive.com) made donations (2009/5).
2770 +Nippy Networks (Ed Wildgoose) made a donation (2009/7).
2771 +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11).
2772 +Pavel Pronskiy made a donation (2011/2).
2773 +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy
2774 + Networks (Ed Wildgoose) made a donation for hardware (2011/3).
2775 +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and
2777 +Sam Liddicott made a donation (2011/9).
2778 +Era Scarecrow made a donation (2013/4).
2779 +Bor Ratajc made a donation (2013/4).
2780 +Alessandro Gorreta made a donation (2013/4).
2781 +POIRETTE Marc made a donation (2013/4).
2782 +Alessandro Gorreta made a donation (2013/4).
2783 +lauri kasvandik made a donation (2013/5).
2784 +"pemasu from Finland" made a donation (2013/7).
2785 +The Parted Magic Project made a donation (2013/9 and 11).
2786 +Pavel Barta made a donation (2013/10).
2787 +Nikolay Pertsev made a donation (2014/5).
2788 +James B made a donation (2014/7 and 2015/7).
2789 +Stefano Di Biase made a donation (2014/8).
2790 +Daniel Epellei made a donation (2015/1).
2791 +OmegaPhil made a donation (2016/1).
2792 +Tomasz Szewczyk made a donation (2016/4).
2793 +James Burry made a donation (2016/12).
2795 +Thank you very much.
2796 +Donations are always, including future donations, very important and
2797 +helpful for me to keep on developing aufs.
2801 +----------------------------------------
2802 +If you are an experienced user, no explanation is needed. Aufs is
2803 +just a linux filesystem.
2808 +# Local variables: ;
2811 diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h
2812 --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100
2813 +++ linux/fs/aufs/aufs.h 2016-10-09 16:55:36.486034798 +0200
2816 + * Copyright (C) 2005-2016 Junjiro R. Okajima
2818 + * This program, aufs is free software; you can redistribute it and/or modify
2819 + * it under the terms of the GNU General Public License as published by
2820 + * the Free Software Foundation; either version 2 of the License, or
2821 + * (at your option) any later version.
2823 + * This program is distributed in the hope that it will be useful,
2824 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2825 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2826 + * GNU General Public License for more details.
2828 + * You should have received a copy of the GNU General Public License
2829 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2833 + * all header files
2841 +#define AuStub(type, name, body, ...) \
2842 + static inline type name(__VA_ARGS__) { body; }
2844 +#define AuStubVoid(name, ...) \
2845 + AuStub(void, name, , __VA_ARGS__)
2846 +#define AuStubInt0(name, ...) \
2847 + AuStub(int, name, return 0, __VA_ARGS__)
2851 +#include "branch.h"
2854 +#include "dbgaufs.h"
2855 +#include "dentry.h"
2859 +#include "fstype.h"
2862 +#include "module.h"
2867 +#include "sysaufs.h"
2872 +#endif /* __KERNEL__ */
2873 +#endif /* __AUFS_H__ */
2874 diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c
2875 --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100
2876 +++ linux/fs/aufs/branch.c 2016-10-09 16:55:38.886097714 +0200
2879 + * Copyright (C) 2005-2016 Junjiro R. Okajima
2881 + * This program, aufs is free software; you can redistribute it and/or modify
2882 + * it under the terms of the GNU General Public License as published by
2883 + * the Free Software Foundation; either version 2 of the License, or
2884 + * (at your option) any later version.
2886 + * This program is distributed in the hope that it will be useful,
2887 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2888 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2889 + * GNU General Public License for more details.
2891 + * You should have received a copy of the GNU General Public License
2892 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2896 + * branch management
2899 +#include <linux/compat.h>
2900 +#include <linux/statfs.h>
2904 + * free a single branch
2906 +static void au_br_do_free(struct au_branch *br)
2909 + struct au_wbr *wbr;
2910 + struct au_dykey **key;
2912 + au_hnotify_fin_br(br);
2914 + if (br->br_xino.xi_file)
2915 + fput(br->br_xino.xi_file);
2916 + mutex_destroy(&br->br_xino.xi_nondir_mtx);
2918 + AuDebugOn(au_br_count(br));
2919 + au_br_count_fin(br);
2923 + for (i = 0; i < AuBrWh_Last; i++)
2924 + dput(wbr->wbr_wh[i]);
2925 + AuDebugOn(atomic_read(&wbr->wbr_wh_running));
2926 + AuRwDestroy(&wbr->wbr_wh_rwsem);
2929 + if (br->br_fhsm) {
2930 + au_br_fhsm_fin(br->br_fhsm);
2931 + au_delayed_kfree(br->br_fhsm);
2934 + key = br->br_dykey;
2935 + for (i = 0; i < AuBrDynOp; i++, key++)
2941 + /* recursive lock, s_umount of branch's */
2943 + path_put(&br->br_path);
2946 + au_delayed_kfree(wbr);
2947 + au_delayed_kfree(br);
2951 + * frees all branches
2953 +void au_br_free(struct au_sbinfo *sbinfo)
2955 + aufs_bindex_t bmax;
2956 + struct au_branch **br;
2958 + AuRwMustWriteLock(&sbinfo->si_rwsem);
2960 + bmax = sbinfo->si_bbot + 1;
2961 + br = sbinfo->si_branch;
2963 + au_br_do_free(*br++);
2967 + * find the index of a branch which is specified by @br_id.
2969 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id)
2971 + aufs_bindex_t bindex, bbot;
2973 + bbot = au_sbbot(sb);
2974 + for (bindex = 0; bindex <= bbot; bindex++)
2975 + if (au_sbr_id(sb, bindex) == br_id)
2980 +/* ---------------------------------------------------------------------- */
2986 +static int test_overlap(struct super_block *sb, struct dentry *h_adding,
2987 + struct dentry *h_root)
2989 + if (unlikely(h_adding == h_root
2990 + || au_test_loopback_overlap(sb, h_adding)))
2992 + if (h_adding->d_sb != h_root->d_sb)
2994 + return au_test_subdir(h_adding, h_root)
2995 + || au_test_subdir(h_root, h_adding);
2999 + * returns a newly allocated branch. @new_nbranch is a number of branches
3000 + * after adding a branch.
3002 +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch,
3005 + struct au_branch *add_branch;
3006 + struct dentry *root;
3007 + struct inode *inode;
3011 + root = sb->s_root;
3012 + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS);
3013 + if (unlikely(!add_branch))
3016 + err = au_hnotify_init_br(add_branch, perm);
3017 + if (unlikely(err))
3020 + if (au_br_writable(perm)) {
3021 + /* may be freed separately at changing the branch permission */
3022 + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr),
3024 + if (unlikely(!add_branch->br_wbr))
3028 + if (au_br_fhsm(perm)) {
3029 + err = au_fhsm_br_alloc(add_branch);
3030 + if (unlikely(err))
3034 + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0);
3036 + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0);
3038 + inode = d_inode(root);
3039 + err = au_hinode_realloc(au_ii(inode), new_nbranch, /*may_shrink*/0);
3042 + return add_branch; /* success */
3045 + if (add_branch->br_wbr)
3046 + au_delayed_kfree(add_branch->br_wbr);
3048 + au_hnotify_fin_br(add_branch);
3050 + au_delayed_kfree(add_branch);
3052 + return ERR_PTR(err);
3056 + * test if the branch permission is legal or not.
3058 +static int test_br(struct inode *inode, int brperm, char *path)
3062 + err = (au_br_writable(brperm) && IS_RDONLY(inode));
3067 + pr_err("write permission for readonly mount or inode, %s\n", path);
3075 + * 0: success, the caller will add it
3076 + * plus: success, it is already unified, the caller should ignore it
3079 +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount)
3082 + aufs_bindex_t bbot, bindex;
3083 + struct dentry *root, *h_dentry;
3084 + struct inode *inode, *h_inode;
3086 + root = sb->s_root;
3087 + bbot = au_sbbot(sb);
3088 + if (unlikely(bbot >= 0
3089 + && au_find_dbindex(root, add->path.dentry) >= 0)) {
3093 + pr_err("%s duplicated\n", add->pathname);
3098 + err = -ENOSPC; /* -E2BIG; */
3099 + if (unlikely(AUFS_BRANCH_MAX <= add->bindex
3100 + || AUFS_BRANCH_MAX - 1 <= bbot)) {
3101 + pr_err("number of branches exceeded %s\n", add->pathname);
3106 + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) {
3107 + pr_err("bad index %d\n", add->bindex);
3111 + inode = d_inode(add->path.dentry);
3113 + if (unlikely(!inode->i_nlink)) {
3114 + pr_err("no existence %s\n", add->pathname);
3119 + if (unlikely(inode->i_sb == sb)) {
3120 + pr_err("%s must be outside\n", add->pathname);
3124 + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) {
3125 + pr_err("unsupported filesystem, %s (%s)\n",
3126 + add->pathname, au_sbtype(inode->i_sb));
3130 + if (unlikely(inode->i_sb->s_stack_depth)) {
3131 + pr_err("already stacked, %s (%s)\n",
3132 + add->pathname, au_sbtype(inode->i_sb));
3136 + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname);
3137 + if (unlikely(err))
3141 + return 0; /* success */
3144 + for (bindex = 0; bindex <= bbot; bindex++)
3145 + if (unlikely(test_overlap(sb, add->path.dentry,
3146 + au_h_dptr(root, bindex)))) {
3147 + pr_err("%s is overlapped\n", add->pathname);
3152 + if (au_opt_test(au_mntflags(sb), WARN_PERM)) {
3153 + h_dentry = au_h_dptr(root, 0);
3154 + h_inode = d_inode(h_dentry);
3155 + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO)
3156 + || !uid_eq(h_inode->i_uid, inode->i_uid)
3157 + || !gid_eq(h_inode->i_gid, inode->i_gid))
3158 + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n",
3160 + i_uid_read(inode), i_gid_read(inode),
3161 + (inode->i_mode & S_IALLUGO),
3162 + i_uid_read(h_inode), i_gid_read(h_inode),
3163 + (h_inode->i_mode & S_IALLUGO));
3171 + * initialize or clean the whiteouts for an adding branch
3173 +static int au_br_init_wh(struct super_block *sb, struct au_branch *br,
3176 + int err, old_perm;
3177 + aufs_bindex_t bindex;
3178 + struct inode *h_inode;
3179 + struct au_wbr *wbr;
3180 + struct au_hinode *hdir;
3181 + struct dentry *h_dentry;
3183 + err = vfsub_mnt_want_write(au_br_mnt(br));
3184 + if (unlikely(err))
3188 + old_perm = br->br_perm;
3189 + br->br_perm = new_perm;
3192 + bindex = au_br_index(sb, br->br_id);
3193 + if (0 <= bindex) {
3194 + hdir = au_hi(d_inode(sb->s_root), bindex);
3195 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
3197 + h_dentry = au_br_dentry(br);
3198 + h_inode = d_inode(h_dentry);
3199 + inode_lock_nested(h_inode, AuLsc_I_PARENT);
3202 + err = au_wh_init(br, sb);
3204 + wbr_wh_write_lock(wbr);
3205 + err = au_wh_init(br, sb);
3206 + wbr_wh_write_unlock(wbr);
3209 + au_hn_inode_unlock(hdir);
3211 + inode_unlock(h_inode);
3212 + vfsub_mnt_drop_write(au_br_mnt(br));
3213 + br->br_perm = old_perm;
3215 + if (!err && wbr && !au_br_writable(new_perm)) {
3216 + au_delayed_kfree(wbr);
3217 + br->br_wbr = NULL;
3224 +static int au_wbr_init(struct au_branch *br, struct super_block *sb,
3228 + struct kstatfs kst;
3229 + struct au_wbr *wbr;
3232 + au_rw_init(&wbr->wbr_wh_rwsem);
3233 + atomic_set(&wbr->wbr_wh_running, 0);
3236 + * a limit for rmdir/rename a dir
3237 + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h
3239 + err = vfs_statfs(&br->br_path, &kst);
3240 + if (unlikely(err))
3243 + if (kst.f_namelen >= NAME_MAX)
3244 + err = au_br_init_wh(sb, br, perm);
3246 + pr_err("%pd(%s), unsupported namelen %ld\n",
3248 + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen);
3254 +/* initialize a new branch */
3255 +static int au_br_init(struct au_branch *br, struct super_block *sb,
3256 + struct au_opt_add *add)
3259 + struct inode *h_inode;
3262 + mutex_init(&br->br_xino.xi_nondir_mtx);
3263 + br->br_perm = add->perm;
3264 + br->br_path = add->path; /* set first, path_get() later */
3265 + spin_lock_init(&br->br_dykey_lock);
3266 + au_br_count_init(br);
3267 + atomic_set(&br->br_xino_running, 0);
3268 + br->br_id = au_new_br_id(sb);
3269 + AuDebugOn(br->br_id < 0);
3271 + if (au_br_writable(add->perm)) {
3272 + err = au_wbr_init(br, sb, add->perm);
3273 + if (unlikely(err))
3277 + if (au_opt_test(au_mntflags(sb), XINO)) {
3278 + h_inode = d_inode(add->path.dentry);
3279 + err = au_xino_br(sb, br, h_inode->i_ino,
3280 + au_sbr(sb, 0)->br_xino.xi_file, /*do_test*/1);
3281 + if (unlikely(err)) {
3282 + AuDebugOn(br->br_xino.xi_file);
3287 + sysaufs_br_init(br);
3288 + path_get(&br->br_path);
3289 + goto out; /* success */
3292 + memset(&br->br_path, 0, sizeof(br->br_path));
3297 +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex,
3298 + struct au_branch *br, aufs_bindex_t bbot,
3299 + aufs_bindex_t amount)
3301 + struct au_branch **brp;
3303 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3305 + brp = sbinfo->si_branch + bindex;
3306 + memmove(brp + 1, brp, sizeof(*brp) * amount);
3308 + sbinfo->si_bbot++;
3309 + if (unlikely(bbot < 0))
3310 + sbinfo->si_bbot = 0;
3313 +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex,
3314 + aufs_bindex_t bbot, aufs_bindex_t amount)
3316 + struct au_hdentry *hdp;
3318 + AuRwMustWriteLock(&dinfo->di_rwsem);
3320 + hdp = au_hdentry(dinfo, bindex);
3321 + memmove(hdp + 1, hdp, sizeof(*hdp) * amount);
3322 + au_h_dentry_init(hdp);
3324 + if (unlikely(bbot < 0))
3325 + dinfo->di_btop = 0;
3328 +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex,
3329 + aufs_bindex_t bbot, aufs_bindex_t amount)
3331 + struct au_hinode *hip;
3333 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3335 + hip = au_hinode(iinfo, bindex);
3336 + memmove(hip + 1, hip, sizeof(*hip) * amount);
3337 + au_hinode_init(hip);
3339 + if (unlikely(bbot < 0))
3340 + iinfo->ii_btop = 0;
3343 +static void au_br_do_add(struct super_block *sb, struct au_branch *br,
3344 + aufs_bindex_t bindex)
3346 + struct dentry *root, *h_dentry;
3347 + struct inode *root_inode, *h_inode;
3348 + aufs_bindex_t bbot, amount;
3350 + root = sb->s_root;
3351 + root_inode = d_inode(root);
3352 + bbot = au_sbbot(sb);
3353 + amount = bbot + 1 - bindex;
3354 + h_dentry = au_br_dentry(br);
3355 + au_sbilist_lock();
3356 + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount);
3357 + au_br_do_add_hdp(au_di(root), bindex, bbot, amount);
3358 + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount);
3359 + au_set_h_dptr(root, bindex, dget(h_dentry));
3360 + h_inode = d_inode(h_dentry);
3361 + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0);
3362 + au_sbilist_unlock();
3365 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount)
3368 + aufs_bindex_t bbot, add_bindex;
3369 + struct dentry *root, *h_dentry;
3370 + struct inode *root_inode;
3371 + struct au_branch *add_branch;
3373 + root = sb->s_root;
3374 + root_inode = d_inode(root);
3375 + IMustLock(root_inode);
3376 + IiMustWriteLock(root_inode);
3377 + err = test_add(sb, add, remount);
3378 + if (unlikely(err < 0))
3382 + goto out; /* success */
3385 + bbot = au_sbbot(sb);
3386 + add_branch = au_br_alloc(sb, bbot + 2, add->perm);
3387 + err = PTR_ERR(add_branch);
3388 + if (IS_ERR(add_branch))
3391 + err = au_br_init(add_branch, sb, add);
3392 + if (unlikely(err)) {
3393 + au_br_do_free(add_branch);
3397 + add_bindex = add->bindex;
3399 + au_br_do_add(sb, add_branch, add_bindex);
3401 + sysaufs_brs_del(sb, add_bindex);
3402 + au_br_do_add(sb, add_branch, add_bindex);
3403 + sysaufs_brs_add(sb, add_bindex);
3406 + h_dentry = add->path.dentry;
3407 + if (!add_bindex) {
3408 + au_cpup_attr_all(root_inode, /*force*/1);
3409 + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes;
3411 + au_add_nlink(root_inode, d_inode(h_dentry));
3414 + * this test/set prevents aufs from handling unnecesary notify events
3415 + * of xino files, in case of re-adding a writable branch which was
3416 + * once detached from aufs.
3418 + if (au_xino_brid(sb) < 0
3419 + && au_br_writable(add_branch->br_perm)
3420 + && !au_test_fs_bad_xino(h_dentry->d_sb)
3421 + && add_branch->br_xino.xi_file
3422 + && add_branch->br_xino.xi_file->f_path.dentry->d_parent == h_dentry)
3423 + au_xino_brid_set(sb, add_branch->br_id);
3429 +/* ---------------------------------------------------------------------- */
3431 +static unsigned long long au_farray_cb(struct super_block *sb, void *a,
3432 + unsigned long long max __maybe_unused,
3435 + unsigned long long n;
3436 + struct file **p, *f;
3437 + struct au_sphlhead *files;
3438 + struct au_finfo *finfo;
3442 + files = &au_sbi(sb)->si_files;
3443 + spin_lock(&files->spin);
3444 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
3445 + f = finfo->fi_file;
3447 + && !special_file(file_inode(f)->i_mode)) {
3451 + AuDebugOn(n > max);
3454 + spin_unlock(&files->spin);
3459 +static struct file **au_farray_alloc(struct super_block *sb,
3460 + unsigned long long *max)
3462 + *max = au_nfiles(sb);
3463 + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL);
3466 +static void au_farray_free(struct file **a, unsigned long long max)
3468 + unsigned long long ull;
3470 + for (ull = 0; ull < max; ull++)
3476 +/* ---------------------------------------------------------------------- */
3482 +/* to show the line number, do not make it inlined function */
3483 +#define AuVerbose(do_info, fmt, ...) do { \
3485 + pr_info(fmt, ##__VA_ARGS__); \
3488 +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop,
3489 + aufs_bindex_t bbot)
3491 + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot;
3494 +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop,
3495 + aufs_bindex_t bbot)
3497 + return au_test_ibusy(d_inode(dentry), btop, bbot);
3501 + * test if the branch is deletable or not.
3503 +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex,
3504 + unsigned int sigen, const unsigned int verbose)
3506 + int err, i, j, ndentry;
3507 + aufs_bindex_t btop, bbot;
3508 + struct au_dcsub_pages dpages;
3509 + struct au_dpage *dpage;
3512 + err = au_dpages_init(&dpages, GFP_NOFS);
3513 + if (unlikely(err))
3515 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
3516 + if (unlikely(err))
3519 + for (i = 0; !err && i < dpages.ndpage; i++) {
3520 + dpage = dpages.dpages + i;
3521 + ndentry = dpage->ndentry;
3522 + for (j = 0; !err && j < ndentry; j++) {
3523 + d = dpage->dentries[j];
3524 + AuDebugOn(au_dcount(d) <= 0);
3525 + if (!au_digen_test(d, sigen)) {
3526 + di_read_lock_child(d, AuLock_IR);
3527 + if (unlikely(au_dbrange_test(d))) {
3528 + di_read_unlock(d, AuLock_IR);
3532 + di_write_lock_child(d);
3533 + if (unlikely(au_dbrange_test(d))) {
3534 + di_write_unlock(d);
3537 + err = au_reval_dpath(d, sigen);
3539 + di_downgrade_lock(d, AuLock_IR);
3541 + di_write_unlock(d);
3546 + /* AuDbgDentry(d); */
3547 + btop = au_dbtop(d);
3548 + bbot = au_dbbot(d);
3549 + if (btop <= bindex
3551 + && au_h_dptr(d, bindex)
3552 + && au_test_dbusy(d, btop, bbot)) {
3554 + AuVerbose(verbose, "busy %pd\n", d);
3557 + di_read_unlock(d, AuLock_IR);
3562 + au_dpages_free(&dpages);
3567 +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex,
3568 + unsigned int sigen, const unsigned int verbose)
3571 + unsigned long long max, ull;
3572 + struct inode *i, **array;
3573 + aufs_bindex_t btop, bbot;
3575 + array = au_iarray_alloc(sb, &max);
3576 + err = PTR_ERR(array);
3577 + if (IS_ERR(array))
3581 + AuDbg("b%d\n", bindex);
3582 + for (ull = 0; !err && ull < max; ull++) {
3586 + if (i->i_ino == AUFS_ROOT_INO)
3589 + /* AuDbgInode(i); */
3590 + if (au_iigen(i, NULL) == sigen)
3591 + ii_read_lock_child(i);
3593 + ii_write_lock_child(i);
3594 + err = au_refresh_hinode_self(i);
3597 + ii_downgrade_lock(i);
3599 + ii_write_unlock(i);
3604 + btop = au_ibtop(i);
3605 + bbot = au_ibbot(i);
3606 + if (btop <= bindex
3608 + && au_h_iptr(i, bindex)
3609 + && au_test_ibusy(i, btop, bbot)) {
3611 + AuVerbose(verbose, "busy i%lu\n", i->i_ino);
3614 + ii_read_unlock(i);
3616 + au_iarray_free(array, max);
3622 +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex,
3623 + const unsigned int verbose)
3626 + unsigned int sigen;
3628 + sigen = au_sigen(root->d_sb);
3629 + DiMustNoWaiters(root);
3630 + IiMustNoWaiters(d_inode(root));
3631 + di_write_unlock(root);
3632 + err = test_dentry_busy(root, bindex, sigen, verbose);
3634 + err = test_inode_busy(root->d_sb, bindex, sigen, verbose);
3635 + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */
3640 +static int test_dir_busy(struct file *file, aufs_bindex_t br_id,
3641 + struct file **to_free, int *idx)
3644 + unsigned char matched, root;
3645 + aufs_bindex_t bindex, bbot;
3646 + struct au_fidir *fidir;
3647 + struct au_hfile *hfile;
3650 + root = IS_ROOT(file->f_path.dentry);
3653 + to_free[*idx] = file;
3659 + fidir = au_fi(file)->fi_hdir;
3660 + AuDebugOn(!fidir);
3661 + bbot = au_fbbot_dir(file);
3662 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) {
3663 + hfile = fidir->fd_hfile + bindex;
3664 + if (!hfile->hf_file)
3667 + if (hfile->hf_br->br_id == br_id) {
3679 +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id,
3680 + struct file **to_free, int opened)
3683 + unsigned long long ull, max;
3684 + aufs_bindex_t btop;
3685 + struct file *file, **array;
3686 + struct dentry *root;
3687 + struct au_hfile *hfile;
3689 + array = au_farray_alloc(sb, &max);
3690 + err = PTR_ERR(array);
3691 + if (IS_ERR(array))
3696 + root = sb->s_root;
3697 + di_write_unlock(root);
3698 + for (ull = 0; ull < max; ull++) {
3699 + file = array[ull];
3700 + if (unlikely(!file))
3703 + /* AuDbg("%pD\n", file); */
3704 + fi_read_lock(file);
3705 + btop = au_fbtop(file);
3706 + if (!d_is_dir(file->f_path.dentry)) {
3707 + hfile = &au_fi(file)->fi_htop;
3708 + if (hfile->hf_br->br_id == br_id)
3711 + err = test_dir_busy(file, br_id, to_free, &idx);
3712 + fi_read_unlock(file);
3713 + if (unlikely(err))
3716 + di_write_lock_child(root);
3717 + au_farray_free(array, max);
3718 + AuDebugOn(idx > opened);
3724 +static void br_del_file(struct file **to_free, unsigned long long opened,
3725 + aufs_bindex_t br_id)
3727 + unsigned long long ull;
3728 + aufs_bindex_t bindex, btop, bbot, bfound;
3729 + struct file *file;
3730 + struct au_fidir *fidir;
3731 + struct au_hfile *hfile;
3733 + for (ull = 0; ull < opened; ull++) {
3734 + file = to_free[ull];
3735 + if (unlikely(!file))
3738 + /* AuDbg("%pD\n", file); */
3739 + AuDebugOn(!d_is_dir(file->f_path.dentry));
3741 + fidir = au_fi(file)->fi_hdir;
3742 + AuDebugOn(!fidir);
3743 + fi_write_lock(file);
3744 + btop = au_fbtop(file);
3745 + bbot = au_fbbot_dir(file);
3746 + for (bindex = btop; bindex <= bbot; bindex++) {
3747 + hfile = fidir->fd_hfile + bindex;
3748 + if (!hfile->hf_file)
3751 + if (hfile->hf_br->br_id == br_id) {
3756 + AuDebugOn(bfound < 0);
3757 + au_set_h_fptr(file, bfound, NULL);
3758 + if (bfound == btop) {
3759 + for (btop++; btop <= bbot; btop++)
3760 + if (au_hf_dir(file, btop)) {
3761 + au_set_fbtop(file, btop);
3765 + fi_write_unlock(file);
3769 +static void au_br_do_del_brp(struct au_sbinfo *sbinfo,
3770 + const aufs_bindex_t bindex,
3771 + const aufs_bindex_t bbot)
3773 + struct au_branch **brp, **p;
3775 + AuRwMustWriteLock(&sbinfo->si_rwsem);
3777 + brp = sbinfo->si_branch + bindex;
3778 + if (bindex < bbot)
3779 + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex));
3780 + sbinfo->si_branch[0 + bbot] = NULL;
3781 + sbinfo->si_bbot--;
3783 + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST,
3786 + sbinfo->si_branch = p;
3787 + /* harmless error */
3790 +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex,
3791 + const aufs_bindex_t bbot)
3793 + struct au_hdentry *hdp, *p;
3795 + AuRwMustWriteLock(&dinfo->di_rwsem);
3797 + hdp = au_hdentry(dinfo, bindex);
3798 + if (bindex < bbot)
3799 + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex));
3800 + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */
3803 + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST,
3806 + dinfo->di_hdentry = p;
3807 + /* harmless error */
3810 +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex,
3811 + const aufs_bindex_t bbot)
3813 + struct au_hinode *hip, *p;
3815 + AuRwMustWriteLock(&iinfo->ii_rwsem);
3817 + hip = au_hinode(iinfo, bindex);
3818 + if (bindex < bbot)
3819 + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex));
3820 + /* au_hinode_init(au_hinode(iinfo, bbot)); */
3823 + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST,
3826 + iinfo->ii_hinode = p;
3827 + /* harmless error */
3830 +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex,
3831 + struct au_branch *br)
3833 + aufs_bindex_t bbot;
3834 + struct au_sbinfo *sbinfo;
3835 + struct dentry *root, *h_root;
3836 + struct inode *inode, *h_inode;
3837 + struct au_hinode *hinode;
3839 + SiMustWriteLock(sb);
3841 + root = sb->s_root;
3842 + inode = d_inode(root);
3843 + sbinfo = au_sbi(sb);
3844 + bbot = sbinfo->si_bbot;
3846 + h_root = au_h_dptr(root, bindex);
3847 + hinode = au_hi(inode, bindex);
3848 + h_inode = au_igrab(hinode->hi_inode);
3851 + au_sbilist_lock();
3852 + au_br_do_del_brp(sbinfo, bindex, bbot);
3853 + au_br_do_del_hdp(au_di(root), bindex, bbot);
3854 + au_br_do_del_hip(au_ii(inode), bindex, bbot);
3855 + au_sbilist_unlock();
3859 + au_br_do_free(br);
3862 +static unsigned long long empty_cb(struct super_block *sb, void *array,
3863 + unsigned long long max, void *arg)
3868 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount)
3871 + unsigned long long opened;
3872 + unsigned int mnt_flags;
3873 + aufs_bindex_t bindex, bbot, br_id;
3874 + unsigned char do_wh, verbose;
3875 + struct au_branch *br;
3876 + struct au_wbr *wbr;
3877 + struct dentry *root;
3878 + struct file **to_free;
3883 + root = sb->s_root;
3884 + bindex = au_find_dbindex(root, del->h_path.dentry);
3887 + goto out; /* success */
3889 + pr_err("%s no such branch\n", del->pathname);
3892 + AuDbg("bindex b%d\n", bindex);
3895 + mnt_flags = au_mntflags(sb);
3896 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
3897 + bbot = au_sbbot(sb);
3898 + if (unlikely(!bbot)) {
3899 + AuVerbose(verbose, "no more branches left\n");
3902 + br = au_sbr(sb, bindex);
3903 + AuDebugOn(!path_equal(&br->br_path, &del->h_path));
3905 + br_id = br->br_id;
3906 + opened = au_br_count(br);
3907 + if (unlikely(opened)) {
3908 + to_free = au_array_alloc(&opened, empty_cb, sb, NULL);
3909 + err = PTR_ERR(to_free);
3910 + if (IS_ERR(to_free))
3913 + err = test_file_busy(sb, br_id, to_free, opened);
3914 + if (unlikely(err)) {
3915 + AuVerbose(verbose, "%llu file(s) opened\n", opened);
3921 + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph);
3923 + /* instead of WbrWhMustWriteLock(wbr) */
3924 + SiMustWriteLock(sb);
3925 + for (i = 0; i < AuBrWh_Last; i++) {
3926 + dput(wbr->wbr_wh[i]);
3927 + wbr->wbr_wh[i] = NULL;
3931 + err = test_children_busy(root, bindex, verbose);
3932 + if (unlikely(err)) {
3941 + * now we confirmed the branch is deletable.
3942 + * let's free the remaining opened dirs on the branch.
3944 + di_write_unlock(root);
3945 + br_del_file(to_free, opened, br_id);
3946 + di_write_lock_child(root);
3950 + au_br_do_del(sb, bindex, br);
3952 + sysaufs_brs_del(sb, bindex);
3953 + au_br_do_del(sb, bindex, br);
3954 + sysaufs_brs_add(sb, bindex);
3958 + au_cpup_attr_all(d_inode(root), /*force*/1);
3959 + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes;
3961 + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry));
3962 + if (au_opt_test(mnt_flags, PLINK))
3963 + au_plink_half_refresh(sb, br_id);
3965 + if (au_xino_brid(sb) == br_id)
3966 + au_xino_brid_set(sb, -1);
3967 + goto out; /* success */
3971 + rerr = au_br_init_wh(sb, br, br->br_perm);
3973 + pr_warn("failed re-creating base whiteout, %s. (%d)\n",
3974 + del->pathname, rerr);
3977 + au_farray_free(to_free, opened);
3981 +/* ---------------------------------------------------------------------- */
3983 +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg)
3986 + aufs_bindex_t btop, bbot;
3987 + struct aufs_ibusy ibusy;
3988 + struct inode *inode, *h_inode;
3991 + if (unlikely(!capable(CAP_SYS_ADMIN)))
3994 + err = copy_from_user(&ibusy, arg, sizeof(ibusy));
3996 + err = !access_ok(VERIFY_WRITE, &arg->h_ino, sizeof(arg->h_ino));
3997 + if (unlikely(err)) {
4004 + si_read_lock(sb, AuLock_FLUSH);
4005 + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb)))
4009 + ibusy.h_ino = 0; /* invalid */
4010 + inode = ilookup(sb, ibusy.ino);
4012 + || inode->i_ino == AUFS_ROOT_INO
4013 + || au_is_bad_inode(inode))
4016 + ii_read_lock_child(inode);
4017 + btop = au_ibtop(inode);
4018 + bbot = au_ibbot(inode);
4019 + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) {
4020 + h_inode = au_h_iptr(inode, ibusy.bindex);
4021 + if (h_inode && au_test_ibusy(inode, btop, bbot))
4022 + ibusy.h_ino = h_inode->i_ino;
4024 + ii_read_unlock(inode);
4028 + si_read_unlock(sb);
4030 + err = __put_user(ibusy.h_ino, &arg->h_ino);
4031 + if (unlikely(err)) {
4040 +long au_ibusy_ioctl(struct file *file, unsigned long arg)
4042 + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg);
4045 +#ifdef CONFIG_COMPAT
4046 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg)
4048 + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg));
4052 +/* ---------------------------------------------------------------------- */
4055 + * change a branch permission
4058 +static void au_warn_ima(void)
4061 + /* since it doesn't support mark_files_ro() */
4062 + AuWarn1("RW -> RO makes IMA to produce wrong message\n");
4066 +static int do_need_sigen_inc(int a, int b)
4068 + return au_br_whable(a) && !au_br_whable(b);
4071 +static int need_sigen_inc(int old, int new)
4073 + return do_need_sigen_inc(old, new)
4074 + || do_need_sigen_inc(new, old);
4077 +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex)
4080 + unsigned int mnt_flags;
4081 + unsigned long long ull, max;
4082 + aufs_bindex_t br_id;
4083 + unsigned char verbose, writer;
4084 + struct file *file, *hf, **array;
4085 + struct au_hfile *hfile;
4087 + mnt_flags = au_mntflags(sb);
4088 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4090 + array = au_farray_alloc(sb, &max);
4091 + err = PTR_ERR(array);
4092 + if (IS_ERR(array))
4096 + br_id = au_sbr_id(sb, bindex);
4097 + for (ull = 0; ull < max; ull++) {
4098 + file = array[ull];
4099 + if (unlikely(!file))
4102 + /* AuDbg("%pD\n", file); */
4103 + fi_read_lock(file);
4104 + if (unlikely(au_test_mmapped(file))) {
4106 + AuVerbose(verbose, "mmapped %pD\n", file);
4108 + FiMustNoWaiters(file);
4109 + fi_read_unlock(file);
4113 + hfile = &au_fi(file)->fi_htop;
4114 + hf = hfile->hf_file;
4115 + if (!d_is_reg(file->f_path.dentry)
4116 + || !(file->f_mode & FMODE_WRITE)
4117 + || hfile->hf_br->br_id != br_id
4118 + || !(hf->f_mode & FMODE_WRITE))
4119 + array[ull] = NULL;
4125 + FiMustNoWaiters(file);
4126 + fi_read_unlock(file);
4134 + for (ull = 0; ull < max; ull++) {
4135 + file = array[ull];
4139 + /* todo: already flushed? */
4141 + * fs/super.c:mark_files_ro() is gone, but aufs keeps its
4142 + * approach which resets f_mode and calls mnt_drop_write() and
4143 + * file_release_write() for each file, because the branch
4144 + * attribute in aufs world is totally different from the native
4147 + /* fi_read_lock(file); */
4148 + hfile = &au_fi(file)->fi_htop;
4149 + hf = hfile->hf_file;
4150 + /* fi_read_unlock(file); */
4151 + spin_lock(&hf->f_lock);
4152 + writer = !!(hf->f_mode & FMODE_WRITER);
4153 + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER);
4154 + spin_unlock(&hf->f_lock);
4156 + put_write_access(file_inode(hf));
4157 + __mnt_drop_write(hf->f_path.mnt);
4162 + au_farray_free(array, max);
4168 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4172 + aufs_bindex_t bindex;
4173 + struct dentry *root;
4174 + struct au_branch *br;
4175 + struct au_br_fhsm *bf;
4177 + root = sb->s_root;
4178 + bindex = au_find_dbindex(root, mod->h_root);
4181 + return 0; /* success */
4183 + pr_err("%s no such branch\n", mod->path);
4186 + AuDbg("bindex b%d\n", bindex);
4188 + err = test_br(d_inode(mod->h_root), mod->perm, mod->path);
4189 + if (unlikely(err))
4192 + br = au_sbr(sb, bindex);
4193 + AuDebugOn(mod->h_root != au_br_dentry(br));
4194 + if (br->br_perm == mod->perm)
4195 + return 0; /* success */
4197 + /* pre-allocate for non-fhsm --> fhsm */
4199 + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) {
4200 + err = au_fhsm_br_alloc(br);
4201 + if (unlikely(err))
4204 + br->br_fhsm = NULL;
4207 + if (au_br_writable(br->br_perm)) {
4208 + /* remove whiteout base */
4209 + err = au_br_init_wh(sb, br, mod->perm);
4210 + if (unlikely(err))
4213 + if (!au_br_writable(mod->perm)) {
4214 + /* rw --> ro, file might be mmapped */
4215 + DiMustNoWaiters(root);
4216 + IiMustNoWaiters(d_inode(root));
4217 + di_write_unlock(root);
4218 + err = au_br_mod_files_ro(sb, bindex);
4219 + /* aufs_write_lock() calls ..._child() */
4220 + di_write_lock_child(root);
4222 + if (unlikely(err)) {
4224 + br->br_wbr = kzalloc(sizeof(*br->br_wbr),
4227 + rerr = au_wbr_init(br, sb, br->br_perm);
4228 + if (unlikely(rerr)) {
4229 + AuIOErr("nested error %d (%d)\n",
4231 + br->br_perm = mod->perm;
4235 + } else if (au_br_writable(mod->perm)) {
4238 + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS);
4240 + err = au_wbr_init(br, sb, mod->perm);
4241 + if (unlikely(err)) {
4242 + au_delayed_kfree(br->br_wbr);
4243 + br->br_wbr = NULL;
4247 + if (unlikely(err))
4250 + if (au_br_fhsm(br->br_perm)) {
4251 + if (!au_br_fhsm(mod->perm)) {
4252 + /* fhsm --> non-fhsm */
4253 + au_br_fhsm_fin(br->br_fhsm);
4254 + au_delayed_kfree(br->br_fhsm);
4255 + br->br_fhsm = NULL;
4257 + } else if (au_br_fhsm(mod->perm))
4258 + /* non-fhsm --> fhsm */
4261 + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm);
4262 + br->br_perm = mod->perm;
4263 + goto out; /* success */
4267 + au_delayed_kfree(bf);
4273 +/* ---------------------------------------------------------------------- */
4275 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs)
4278 + struct kstatfs kstfs;
4280 + err = vfs_statfs(&br->br_path, &kstfs);
4282 + stfs->f_blocks = kstfs.f_blocks;
4283 + stfs->f_bavail = kstfs.f_bavail;
4284 + stfs->f_files = kstfs.f_files;
4285 + stfs->f_ffree = kstfs.f_ffree;
4290 diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h
4291 --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100
4292 +++ linux/fs/aufs/branch.h 2016-10-09 16:55:36.486034798 +0200
4295 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4297 + * This program, aufs is free software; you can redistribute it and/or modify
4298 + * it under the terms of the GNU General Public License as published by
4299 + * the Free Software Foundation; either version 2 of the License, or
4300 + * (at your option) any later version.
4302 + * This program is distributed in the hope that it will be useful,
4303 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4304 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4305 + * GNU General Public License for more details.
4307 + * You should have received a copy of the GNU General Public License
4308 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4312 + * branch filesystems and xino for them
4315 +#ifndef __AUFS_BRANCH_H__
4316 +#define __AUFS_BRANCH_H__
4320 +#include <linux/mount.h>
4325 +/* ---------------------------------------------------------------------- */
4328 +struct au_xino_file {
4329 + struct file *xi_file;
4330 + struct mutex xi_nondir_mtx;
4332 + /* todo: make xino files an array to support huge inode number */
4334 +#ifdef CONFIG_DEBUG_FS
4335 + struct dentry *xi_dbgaufs;
4339 +/* File-based Hierarchical Storage Management */
4340 +struct au_br_fhsm {
4341 +#ifdef CONFIG_AUFS_FHSM
4342 + struct mutex bf_lock;
4343 + unsigned long bf_jiffy;
4344 + struct aufs_stfs bf_stfs;
4349 +/* members for writable branch only */
4350 +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last};
4352 + struct au_rwsem wbr_wh_rwsem;
4353 + struct dentry *wbr_wh[AuBrWh_Last];
4354 + atomic_t wbr_wh_running;
4355 +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */
4356 +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */
4357 +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */
4360 + unsigned long long wbr_bytes;
4363 +/* ext2 has 3 types of operations at least, ext3 has 4 */
4364 +#define AuBrDynOp (AuDyLast * 4)
4366 +#ifdef CONFIG_AUFS_HFSNOTIFY
4367 +/* support for asynchronous destruction */
4368 +struct au_br_hfsnotify {
4369 + struct fsnotify_group *hfsn_group;
4373 +/* sysfs entries */
4374 +struct au_brsysfs {
4376 + struct attribute attr;
4385 +/* protected by superblock rwsem */
4387 + struct au_xino_file br_xino;
4389 + aufs_bindex_t br_id;
4392 + struct path br_path;
4393 + spinlock_t br_dykey_lock;
4394 + struct au_dykey *br_dykey[AuBrDynOp];
4395 + struct percpu_counter br_count;
4397 + struct au_wbr *br_wbr;
4398 + struct au_br_fhsm *br_fhsm;
4400 + /* xino truncation */
4401 + atomic_t br_xino_running;
4403 +#ifdef CONFIG_AUFS_HFSNOTIFY
4404 + struct au_br_hfsnotify *br_hfsn;
4407 +#ifdef CONFIG_SYSFS
4408 + /* entries under sysfs per mount-point */
4409 + struct au_brsysfs br_sysfs[AuBrSysfs_Last];
4413 +/* ---------------------------------------------------------------------- */
4415 +static inline struct vfsmount *au_br_mnt(struct au_branch *br)
4417 + return br->br_path.mnt;
4420 +static inline struct dentry *au_br_dentry(struct au_branch *br)
4422 + return br->br_path.dentry;
4425 +static inline struct super_block *au_br_sb(struct au_branch *br)
4427 + return au_br_mnt(br)->mnt_sb;
4430 +static inline void au_br_get(struct au_branch *br)
4432 + percpu_counter_inc(&br->br_count);
4435 +static inline void au_br_put(struct au_branch *br)
4437 + percpu_counter_dec(&br->br_count);
4440 +static inline s64 au_br_count(struct au_branch *br)
4442 + return percpu_counter_sum(&br->br_count);
4445 +static inline void au_br_count_init(struct au_branch *br)
4447 + percpu_counter_init(&br->br_count, 0, GFP_NOFS);
4450 +static inline void au_br_count_fin(struct au_branch *br)
4452 + percpu_counter_destroy(&br->br_count);
4455 +static inline int au_br_rdonly(struct au_branch *br)
4457 + return ((au_br_sb(br)->s_flags & MS_RDONLY)
4458 + || !au_br_writable(br->br_perm))
4462 +static inline int au_br_hnotifyable(int brperm __maybe_unused)
4464 +#ifdef CONFIG_AUFS_HNOTIFY
4465 + return !(brperm & AuBrPerm_RR);
4471 +static inline int au_br_test_oflag(int oflag, struct au_branch *br)
4473 + int err, exec_flag;
4476 + exec_flag = oflag & __FMODE_EXEC;
4477 + if (unlikely(exec_flag && path_noexec(&br->br_path)))
4483 +/* ---------------------------------------------------------------------- */
4487 +void au_br_free(struct au_sbinfo *sinfo);
4488 +int au_br_index(struct super_block *sb, aufs_bindex_t br_id);
4490 +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount);
4492 +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount);
4493 +long au_ibusy_ioctl(struct file *file, unsigned long arg);
4494 +#ifdef CONFIG_COMPAT
4495 +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg);
4498 +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount,
4501 +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs);
4504 +static const loff_t au_loff_max = LLONG_MAX;
4506 +int au_xib_trunc(struct super_block *sb);
4507 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size,
4509 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
4510 + size_t size, loff_t *pos);
4511 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src);
4512 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent);
4513 +ino_t au_xino_new_ino(struct super_block *sb);
4514 +void au_xino_delete_inode(struct inode *inode, const int unlinked);
4515 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4517 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
4519 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t hino,
4520 + struct file *base_file, int do_test);
4521 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex);
4523 +struct au_opt_xino;
4524 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount);
4525 +void au_xino_clr(struct super_block *sb);
4526 +struct file *au_xino_def(struct super_block *sb);
4527 +int au_xino_path(struct seq_file *seq, struct file *file);
4529 +/* ---------------------------------------------------------------------- */
4531 +/* Superblock to branch */
4533 +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex)
4535 + return au_sbr(sb, bindex)->br_id;
4539 +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex)
4541 + return au_br_mnt(au_sbr(sb, bindex));
4545 +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex)
4547 + return au_br_sb(au_sbr(sb, bindex));
4550 +static inline void au_sbr_get(struct super_block *sb, aufs_bindex_t bindex)
4552 + au_br_get(au_sbr(sb, bindex));
4555 +static inline void au_sbr_put(struct super_block *sb, aufs_bindex_t bindex)
4557 + au_br_put(au_sbr(sb, bindex));
4560 +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex)
4562 + return au_sbr(sb, bindex)->br_perm;
4565 +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex)
4567 + return au_br_whable(au_sbr_perm(sb, bindex));
4570 +/* ---------------------------------------------------------------------- */
4573 + * wbr_wh_read_lock, wbr_wh_write_lock
4574 + * wbr_wh_read_unlock, wbr_wh_write_unlock, wbr_wh_downgrade_lock
4576 +AuSimpleRwsemFuncs(wbr_wh, struct au_wbr *wbr, &wbr->wbr_wh_rwsem);
4578 +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&wbr->wbr_wh_rwsem)
4579 +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&wbr->wbr_wh_rwsem)
4580 +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&wbr->wbr_wh_rwsem)
4582 +/* ---------------------------------------------------------------------- */
4584 +#ifdef CONFIG_AUFS_FHSM
4585 +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm)
4587 + mutex_init(&brfhsm->bf_lock);
4588 + brfhsm->bf_jiffy = 0;
4589 + brfhsm->bf_readable = 0;
4592 +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm)
4594 + mutex_destroy(&brfhsm->bf_lock);
4597 +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm)
4598 +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm)
4601 +#endif /* __KERNEL__ */
4602 +#endif /* __AUFS_BRANCH_H__ */
4603 diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk
4604 --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100
4605 +++ linux/fs/aufs/conf.mk 2016-10-09 16:55:36.486034798 +0200
4608 +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS}
4612 +AuConfStr += ${1}=${${1}}
4616 +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \
4618 + HNOTIFY HFSNOTIFY \
4629 +$(foreach i, ${AuConfAll}, \
4630 + $(eval $(call AuConf,CONFIG_AUFS_${i})))
4632 +AuConfName = ${obj}/conf.str
4633 +${AuConfName}.tmp: FORCE
4634 + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@
4635 +${AuConfName}: ${AuConfName}.tmp
4636 + @diff -q $< $@ > /dev/null 2>&1 || { \
4637 + echo ' GEN ' $@; \
4641 +clean-files += ${AuConfName} ${AuConfName}.tmp
4642 +${obj}/sysfs.o: ${AuConfName}
4644 +-include ${srctree}/${src}/conf_priv.mk
4645 diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c
4646 --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100
4647 +++ linux/fs/aufs/cpup.c 2016-12-17 12:28:17.595211562 +0100
4650 + * Copyright (C) 2005-2016 Junjiro R. Okajima
4652 + * This program, aufs is free software; you can redistribute it and/or modify
4653 + * it under the terms of the GNU General Public License as published by
4654 + * the Free Software Foundation; either version 2 of the License, or
4655 + * (at your option) any later version.
4657 + * This program is distributed in the hope that it will be useful,
4658 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
4659 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4660 + * GNU General Public License for more details.
4662 + * You should have received a copy of the GNU General Public License
4663 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
4667 + * copy-up functions, see wbr_policy.c for copy-down
4670 +#include <linux/fs_stack.h>
4671 +#include <linux/mm.h>
4672 +#include <linux/task_work.h>
4675 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags)
4677 + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE
4678 + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT;
4680 + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags));
4682 + dst->i_flags |= iflags & ~mask;
4683 + if (au_test_fs_notime(dst->i_sb))
4684 + dst->i_flags |= S_NOATIME | S_NOCMTIME;
4687 +void au_cpup_attr_timesizes(struct inode *inode)
4689 + struct inode *h_inode;
4691 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4692 + fsstack_copy_attr_times(inode, h_inode);
4693 + fsstack_copy_inode_size(inode, h_inode);
4696 +void au_cpup_attr_nlink(struct inode *inode, int force)
4698 + struct inode *h_inode;
4699 + struct super_block *sb;
4700 + aufs_bindex_t bindex, bbot;
4703 + bindex = au_ibtop(inode);
4704 + h_inode = au_h_iptr(inode, bindex);
4706 + && !S_ISDIR(h_inode->i_mode)
4707 + && au_opt_test(au_mntflags(sb), PLINK)
4708 + && au_plink_test(inode))
4712 + * 0 can happen in revalidating.
4713 + * h_inode->i_mutex may not be held here, but it is harmless since once
4714 + * i_nlink reaches 0, it will never become positive except O_TMPFILE
4716 + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause
4717 + * the incorrect link count.
4719 + set_nlink(inode, h_inode->i_nlink);
4722 + * fewer nlink makes find(1) noisy, but larger nlink doesn't.
4723 + * it may includes whplink directory.
4725 + if (S_ISDIR(h_inode->i_mode)) {
4726 + bbot = au_ibbot(inode);
4727 + for (bindex++; bindex <= bbot; bindex++) {
4728 + h_inode = au_h_iptr(inode, bindex);
4730 + au_add_nlink(inode, h_inode);
4735 +void au_cpup_attr_changeable(struct inode *inode)
4737 + struct inode *h_inode;
4739 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4740 + inode->i_mode = h_inode->i_mode;
4741 + inode->i_uid = h_inode->i_uid;
4742 + inode->i_gid = h_inode->i_gid;
4743 + au_cpup_attr_timesizes(inode);
4744 + au_cpup_attr_flags(inode, h_inode->i_flags);
4747 +void au_cpup_igen(struct inode *inode, struct inode *h_inode)
4749 + struct au_iinfo *iinfo = au_ii(inode);
4751 + IiMustWriteLock(inode);
4753 + iinfo->ii_higen = h_inode->i_generation;
4754 + iinfo->ii_hsb1 = h_inode->i_sb;
4757 +void au_cpup_attr_all(struct inode *inode, int force)
4759 + struct inode *h_inode;
4761 + h_inode = au_h_iptr(inode, au_ibtop(inode));
4762 + au_cpup_attr_changeable(inode);
4763 + if (inode->i_nlink > 0)
4764 + au_cpup_attr_nlink(inode, force);
4765 + inode->i_rdev = h_inode->i_rdev;
4766 + inode->i_blkbits = h_inode->i_blkbits;
4767 + au_cpup_igen(inode, h_inode);
4770 +/* ---------------------------------------------------------------------- */
4772 +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */
4774 +/* keep the timestamps of the parent dir when cpup */
4775 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
4776 + struct path *h_path)
4778 + struct inode *h_inode;
4780 + dt->dt_dentry = dentry;
4781 + dt->dt_h_path = *h_path;
4782 + h_inode = d_inode(h_path->dentry);
4783 + dt->dt_atime = h_inode->i_atime;
4784 + dt->dt_mtime = h_inode->i_mtime;
4788 +void au_dtime_revert(struct au_dtime *dt)
4790 + struct iattr attr;
4793 + attr.ia_atime = dt->dt_atime;
4794 + attr.ia_mtime = dt->dt_mtime;
4795 + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET
4796 + | ATTR_ATIME | ATTR_ATIME_SET;
4798 + /* no delegation since this is a directory */
4799 + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL);
4800 + if (unlikely(err))
4801 + pr_warn("restoring timestamps failed(%d). ignored\n", err);
4804 +/* ---------------------------------------------------------------------- */
4806 +/* internal use only */
4807 +struct au_cpup_reg_attr {
4810 + unsigned int iflags; /* inode->i_flags */
4813 +static noinline_for_stack
4814 +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src,
4815 + struct au_cpup_reg_attr *h_src_attr)
4817 + int err, sbits, icex;
4818 + unsigned int mnt_flags;
4819 + unsigned char verbose;
4821 + struct path h_path;
4822 + struct inode *h_isrc, *h_idst;
4823 + struct kstat *h_st;
4824 + struct au_branch *br;
4826 + h_path.dentry = au_h_dptr(dst, bindex);
4827 + h_idst = d_inode(h_path.dentry);
4828 + br = au_sbr(dst->d_sb, bindex);
4829 + h_path.mnt = au_br_mnt(br);
4830 + h_isrc = d_inode(h_src);
4831 + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID
4832 + | ATTR_ATIME | ATTR_MTIME
4833 + | ATTR_ATIME_SET | ATTR_MTIME_SET;
4834 + if (h_src_attr && h_src_attr->valid) {
4835 + h_st = &h_src_attr->st;
4836 + ia.ia_uid = h_st->uid;
4837 + ia.ia_gid = h_st->gid;
4838 + ia.ia_atime = h_st->atime;
4839 + ia.ia_mtime = h_st->mtime;
4840 + if (h_idst->i_mode != h_st->mode
4841 + && !S_ISLNK(h_idst->i_mode)) {
4842 + ia.ia_valid |= ATTR_MODE;
4843 + ia.ia_mode = h_st->mode;
4845 + sbits = !!(h_st->mode & (S_ISUID | S_ISGID));
4846 + au_cpup_attr_flags(h_idst, h_src_attr->iflags);
4848 + ia.ia_uid = h_isrc->i_uid;
4849 + ia.ia_gid = h_isrc->i_gid;
4850 + ia.ia_atime = h_isrc->i_atime;
4851 + ia.ia_mtime = h_isrc->i_mtime;
4852 + if (h_idst->i_mode != h_isrc->i_mode
4853 + && !S_ISLNK(h_idst->i_mode)) {
4854 + ia.ia_valid |= ATTR_MODE;
4855 + ia.ia_mode = h_isrc->i_mode;
4857 + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID));
4858 + au_cpup_attr_flags(h_idst, h_isrc->i_flags);
4860 + /* no delegation since it is just created */
4861 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4863 + /* is this nfs only? */
4864 + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) {
4865 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
4866 + ia.ia_mode = h_isrc->i_mode;
4867 + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL);
4870 + icex = br->br_perm & AuBrAttr_ICEX;
4872 + mnt_flags = au_mntflags(dst->d_sb);
4873 + verbose = !!au_opt_test(mnt_flags, VERBOSE);
4874 + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose);
4880 +/* ---------------------------------------------------------------------- */
4882 +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len,
4883 + char *buf, unsigned long blksize)
4886 + size_t sz, rbytes, wbytes;
4887 + unsigned char all_zero;
4889 + struct inode *h_inode;
4890 + /* reduce stack usage */
4893 + zp = page_address(ZERO_PAGE(0));
4894 + if (unlikely(!zp))
4895 + return -ENOMEM; /* possible? */
4900 + AuDbg("len %lld\n", len);
4902 + if (len < blksize)
4906 + /* todo: signal_pending? */
4907 + while (!rbytes || err == -EAGAIN || err == -EINTR) {
4908 + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos);
4911 + if (unlikely(err < 0))
4915 + if (len >= rbytes && rbytes == blksize)
4916 + all_zero = !memcmp(buf, zp, rbytes);
4923 + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos);
4925 + /* todo: signal_pending? */
4926 + if (unlikely(err == -EAGAIN || err == -EINTR))
4928 + if (unlikely(err < 0))
4933 + if (unlikely(err < 0))
4939 + res = vfsub_llseek(dst, rbytes, SEEK_CUR);
4941 + if (unlikely(res < 0))
4948 + /* the last block may be a hole */
4949 + if (!err && all_zero) {
4950 + AuLabel(last hole);
4953 + if (au_test_nfs(dst->f_path.dentry->d_sb)) {
4954 + /* nfs requires this step to make last hole */
4955 + /* is this only nfs? */
4957 + /* todo: signal_pending? */
4958 + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos);
4959 + } while (err == -EAGAIN || err == -EINTR);
4966 + ia->ia_size = dst->f_pos;
4967 + ia->ia_valid = ATTR_SIZE | ATTR_FILE;
4968 + ia->ia_file = dst;
4969 + h_inode = file_inode(dst);
4970 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
4971 + /* no delegation since it is just created */
4972 + err = vfsub_notify_change(&dst->f_path, ia,
4973 + /*delegated*/NULL);
4974 + inode_unlock(h_inode);
4981 +int au_copy_file(struct file *dst, struct file *src, loff_t len)
4984 + unsigned long blksize;
4985 + unsigned char do_kfree;
4989 + blksize = dst->f_path.dentry->d_sb->s_blocksize;
4990 + if (!blksize || PAGE_SIZE < blksize)
4991 + blksize = PAGE_SIZE;
4992 + AuDbg("blksize %lu\n", blksize);
4993 + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *));
4995 + buf = kmalloc(blksize, GFP_NOFS);
4997 + buf = (void *)__get_free_page(GFP_NOFS);
4998 + if (unlikely(!buf))
5001 + if (len > (1 << 22))
5002 + AuDbg("copying a large file %lld\n", (long long)len);
5006 + err = au_do_copy_file(dst, src, len, buf, blksize);
5008 + au_delayed_kfree(buf);
5010 + au_delayed_free_page((unsigned long)buf);
5017 + * to support a sparse file which is opened with O_APPEND,
5018 + * we need to close the file.
5020 +static int au_cp_regular(struct au_cp_generic *cpg)
5023 + enum { SRC, DST };
5025 + aufs_bindex_t bindex;
5026 + unsigned int flags;
5027 + struct dentry *dentry;
5029 + struct file *file;
5033 + .bindex = cpg->bsrc,
5034 + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE,
5038 + .bindex = cpg->bdst,
5039 + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE,
5040 + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST),
5041 + .label = &&out_src
5044 + struct super_block *sb;
5045 + struct inode *h_src_inode;
5046 + struct task_struct *tsk = current;
5048 + /* bsrc branch can be ro/rw. */
5049 + sb = cpg->dentry->d_sb;
5051 + for (i = 0; i < 2; i++, f++) {
5052 + f->dentry = au_h_dptr(cpg->dentry, f->bindex);
5053 + f->file = au_h_open(cpg->dentry, f->bindex, f->flags,
5054 + /*file*/NULL, f->force_wr);
5055 + err = PTR_ERR(f->file);
5056 + if (IS_ERR(f->file))
5060 + /* try stopping to update while we copyup */
5061 + h_src_inode = d_inode(file[SRC].dentry);
5062 + if (!au_test_nfs(h_src_inode->i_sb))
5063 + IMustLock(h_src_inode);
5064 + err = au_copy_file(file[DST].file, file[SRC].file, cpg->len);
5066 + /* i wonder if we had O_NO_DELAY_FPUT flag */
5067 + if (tsk->flags & PF_KTHREAD)
5068 + __fput_sync(file[DST].file);
5070 + WARN(1, "%pD\nPlease report this warning to aufs-users ML",
5072 + fput(file[DST].file);
5075 + * we have to call both since we don't know which place the file
5079 + flush_delayed_fput();
5081 + au_sbr_put(sb, file[DST].bindex);
5084 + fput(file[SRC].file);
5085 + au_sbr_put(sb, file[SRC].bindex);
5090 +static int au_do_cpup_regular(struct au_cp_generic *cpg,
5091 + struct au_cpup_reg_attr *h_src_attr)
5095 + struct path h_path;
5096 + struct inode *h_src_inode, *h_dst_inode;
5099 + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc);
5100 + l = i_size_read(h_src_inode);
5101 + if (cpg->len == -1 || l < cpg->len)
5104 + /* try stopping to update while we are referencing */
5105 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5106 + au_pin_hdir_unlock(cpg->pin);
5108 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5109 + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc);
5110 + h_src_attr->iflags = h_src_inode->i_flags;
5111 + if (!au_test_nfs(h_src_inode->i_sb))
5112 + err = vfs_getattr(&h_path, &h_src_attr->st);
5114 + inode_unlock(h_src_inode);
5115 + err = vfs_getattr(&h_path, &h_src_attr->st);
5116 + inode_lock_nested(h_src_inode, AuLsc_I_CHILD);
5118 + if (unlikely(err)) {
5119 + inode_unlock(h_src_inode);
5122 + h_src_attr->valid = 1;
5123 + if (!au_test_nfs(h_src_inode->i_sb)) {
5124 + err = au_cp_regular(cpg);
5125 + inode_unlock(h_src_inode);
5127 + inode_unlock(h_src_inode);
5128 + err = au_cp_regular(cpg);
5130 + rerr = au_pin_hdir_relock(cpg->pin);
5134 + if (!err && (h_src_inode->i_state & I_LINKABLE)) {
5135 + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst);
5136 + h_dst_inode = d_inode(h_path.dentry);
5137 + spin_lock(&h_dst_inode->i_lock);
5138 + h_dst_inode->i_state |= I_LINKABLE;
5139 + spin_unlock(&h_dst_inode->i_lock);
5146 +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src,
5147 + struct inode *h_dir)
5150 + mm_segment_t old_fs;
5155 + struct inode *h_inode = d_inode(h_src);
5156 + const struct inode_operations *h_iop = h_inode->i_op;
5159 + if (unlikely(!h_iop->readlink))
5163 + sym.k = (void *)__get_free_page(GFP_NOFS);
5164 + if (unlikely(!sym.k))
5167 + /* unnecessary to support mmap_sem since symlink is not mmap-able */
5168 + old_fs = get_fs();
5169 + set_fs(KERNEL_DS);
5170 + symlen = h_iop->readlink(h_src, sym.u, PATH_MAX);
5175 + sym.k[symlen] = 0;
5176 + err = vfsub_symlink(h_dir, h_path, sym.k);
5178 + au_delayed_free_page((unsigned long)sym.k);
5185 + * regardless 'acl' option, reset all ACL.
5186 + * All ACL will be copied up later from the original entry on the lower branch.
5188 +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode)
5191 + struct dentry *h_dentry;
5192 + struct inode *h_inode;
5194 + h_dentry = h_path->dentry;
5195 + h_inode = d_inode(h_dentry);
5196 + /* forget_all_cached_acls(h_inode)); */
5197 + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS);
5199 + if (err == -EOPNOTSUPP)
5202 + err = vfsub_acl_chmod(h_inode, mode);
5208 +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent,
5209 + struct inode *h_dir, struct path *h_path)
5212 + struct inode *dir, *inode;
5214 + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT);
5216 + if (err == -EOPNOTSUPP)
5218 + if (unlikely(err))
5222 + * strange behaviour from the users view,
5223 + * particularry setattr case
5225 + dir = d_inode(dst_parent);
5226 + if (au_ibtop(dir) == cpg->bdst)
5227 + au_cpup_attr_nlink(dir, /*force*/1);
5228 + inode = d_inode(cpg->dentry);
5229 + au_cpup_attr_nlink(inode, /*force*/1);
5235 +static noinline_for_stack
5236 +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent,
5237 + struct au_cpup_reg_attr *h_src_attr)
5241 + unsigned int mnt_flags;
5242 + unsigned char isdir, isreg, force;
5243 + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME);
5244 + struct au_dtime dt;
5245 + struct path h_path;
5246 + struct dentry *h_src, *h_dst, *h_parent;
5247 + struct inode *h_inode, *h_dir;
5248 + struct super_block *sb;
5250 + /* bsrc branch can be ro/rw. */
5251 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5252 + h_inode = d_inode(h_src);
5253 + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc));
5255 + /* try stopping to be referenced while we are creating */
5256 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5257 + if (au_ftest_cpup(cpg->flags, RENAME))
5258 + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX,
5259 + AUFS_WH_PFX_LEN));
5260 + h_parent = h_dst->d_parent; /* dir inode is locked */
5261 + h_dir = d_inode(h_parent);
5263 + AuDebugOn(h_parent != h_dst->d_parent);
5265 + sb = cpg->dentry->d_sb;
5266 + h_path.mnt = au_sbr_mnt(sb, cpg->bdst);
5268 + h_path.dentry = h_parent;
5269 + au_dtime_store(&dt, dst_parent, &h_path);
5271 + h_path.dentry = h_dst;
5275 + mode = h_inode->i_mode;
5276 + switch (mode & S_IFMT) {
5279 + err = vfsub_create(h_dir, &h_path, S_IRUSR | S_IWUSR,
5280 + /*want_excl*/true);
5282 + err = au_do_cpup_regular(cpg, h_src_attr);
5286 + err = vfsub_mkdir(h_dir, &h_path, mode);
5288 + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path);
5291 + err = au_do_cpup_symlink(&h_path, h_src, h_dir);
5295 + AuDebugOn(!capable(CAP_MKNOD));
5299 + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev);
5302 + AuIOErr("Unknown inode type 0%o\n", mode);
5306 + err = au_reset_acl(h_dir, &h_path, mode);
5308 + mnt_flags = au_mntflags(sb);
5309 + if (!au_opt_test(mnt_flags, UDBA_NONE)
5311 + && au_opt_test(mnt_flags, XINO)
5312 + && (h_inode->i_nlink == 1
5313 + || (h_inode->i_state & I_LINKABLE))
5314 + /* todo: unnecessary? */
5315 + /* && d_inode(cpg->dentry)->i_nlink == 1 */
5316 + && cpg->bdst < cpg->bsrc
5317 + && !au_ftest_cpup(cpg->flags, KEEPLINO))
5318 + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0);
5319 + /* ignore this error */
5324 + force = !!cpg->len;
5325 + if (cpg->len == -1)
5326 + force = !!i_size_read(h_inode);
5328 + au_fhsm_wrote(sb, cpg->bdst, force);
5332 + au_dtime_revert(&dt);
5336 +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path)
5339 + struct dentry *dentry, *h_dentry, *h_parent, *parent;
5340 + struct inode *h_dir;
5341 + aufs_bindex_t bdst;
5343 + dentry = cpg->dentry;
5345 + h_dentry = au_h_dptr(dentry, bdst);
5346 + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) {
5348 + au_set_h_dptr(dentry, bdst, NULL);
5349 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
5351 + h_path->dentry = dget(au_h_dptr(dentry, bdst));
5352 + au_set_h_dptr(dentry, bdst, h_dentry);
5355 + parent = dget_parent(dentry);
5356 + h_parent = au_h_dptr(parent, bdst);
5358 + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
5359 + if (IS_ERR(h_path->dentry))
5360 + err = PTR_ERR(h_path->dentry);
5362 + if (unlikely(err))
5365 + h_parent = h_dentry->d_parent; /* dir inode is locked */
5366 + h_dir = d_inode(h_parent);
5368 + AuDbg("%pd %pd\n", h_dentry, h_path->dentry);
5369 + /* no delegation since it is just created */
5370 + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL,
5372 + dput(h_path->dentry);
5379 + * copyup the @dentry from @bsrc to @bdst.
5380 + * the caller must set the both of lower dentries.
5381 + * @len is for truncating when it is -1 copyup the entire file.
5382 + * in link/rename cases, @dst_parent may be different from the real one.
5383 + * basic->bsrc can be larger than basic->bdst.
5384 + * aufs doesn't touch the credential so
5385 + * security_inode_copy_up{,_xattr}() are unnecrssary.
5387 +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5390 + aufs_bindex_t old_ibtop;
5391 + unsigned char isdir, plink;
5392 + struct dentry *h_src, *h_dst, *h_parent;
5393 + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode;
5394 + struct super_block *sb;
5395 + struct au_branch *br;
5396 + /* to reuduce stack size */
5398 + struct au_dtime dt;
5399 + struct path h_path;
5400 + struct au_cpup_reg_attr h_src_attr;
5404 + a = kmalloc(sizeof(*a), GFP_NOFS);
5407 + a->h_src_attr.valid = 0;
5409 + sb = cpg->dentry->d_sb;
5410 + br = au_sbr(sb, cpg->bdst);
5411 + a->h_path.mnt = au_br_mnt(br);
5412 + h_dst = au_h_dptr(cpg->dentry, cpg->bdst);
5413 + h_parent = h_dst->d_parent; /* dir inode is locked */
5414 + h_dir = d_inode(h_parent);
5417 + h_src = au_h_dptr(cpg->dentry, cpg->bsrc);
5418 + inode = d_inode(cpg->dentry);
5421 + dst_parent = dget_parent(cpg->dentry);
5425 + plink = !!au_opt_test(au_mntflags(sb), PLINK);
5426 + dst_inode = au_h_iptr(inode, cpg->bdst);
5428 + if (unlikely(!plink)) {
5430 + AuIOErr("hi%lu(i%lu) exists on b%d "
5431 + "but plink is disabled\n",
5432 + dst_inode->i_ino, inode->i_ino, cpg->bdst);
5436 + if (dst_inode->i_nlink) {
5437 + const int do_dt = au_ftest_cpup(cpg->flags, DTIME);
5439 + h_src = au_plink_lkup(inode, cpg->bdst);
5440 + err = PTR_ERR(h_src);
5441 + if (IS_ERR(h_src))
5443 + if (unlikely(d_is_negative(h_src))) {
5445 + AuIOErr("i%lu exists on b%d "
5446 + "but not pseudo-linked\n",
5447 + inode->i_ino, cpg->bdst);
5453 + a->h_path.dentry = h_parent;
5454 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5457 + a->h_path.dentry = h_dst;
5459 + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated);
5460 + if (!err && au_ftest_cpup(cpg->flags, RENAME))
5461 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5463 + au_dtime_revert(&a->dt);
5464 + if (unlikely(err == -EWOULDBLOCK)) {
5465 + pr_warn("cannot retry for NFSv4 delegation"
5466 + " for an internal link\n");
5472 + /* todo: cpup_wh_file? */
5474 + au_update_ibrange(inode, /*do_put_zero*/1);
5477 + isdir = S_ISDIR(inode->i_mode);
5478 + old_ibtop = au_ibtop(inode);
5479 + err = cpup_entry(cpg, dst_parent, &a->h_src_attr);
5480 + if (unlikely(err))
5482 + dst_inode = d_inode(h_dst);
5483 + inode_lock_nested(dst_inode, AuLsc_I_CHILD2);
5484 + /* todo: necessary? */
5485 + /* au_pin_hdir_unlock(cpg->pin); */
5487 + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr);
5488 + if (unlikely(err)) {
5489 + /* todo: necessary? */
5490 + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */
5491 + inode_unlock(dst_inode);
5495 + if (cpg->bdst < old_ibtop) {
5496 + if (S_ISREG(inode->i_mode)) {
5497 + err = au_dy_iaop(inode, cpg->bdst, dst_inode);
5498 + if (unlikely(err)) {
5499 + /* ignore an error */
5500 + /* au_pin_hdir_relock(cpg->pin); */
5501 + inode_unlock(dst_inode);
5505 + au_set_ibtop(inode, cpg->bdst);
5507 + au_set_ibbot(inode, cpg->bdst);
5508 + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode),
5509 + au_hi_flags(inode, isdir));
5511 + /* todo: necessary? */
5512 + /* err = au_pin_hdir_relock(cpg->pin); */
5513 + inode_unlock(dst_inode);
5514 + if (unlikely(err))
5517 + src_inode = d_inode(h_src);
5519 + && (src_inode->i_nlink > 1
5520 + || src_inode->i_state & I_LINKABLE)
5522 + au_plink_append(inode, cpg->bdst, h_dst);
5524 + if (au_ftest_cpup(cpg->flags, RENAME)) {
5525 + a->h_path.dentry = h_dst;
5526 + err = au_do_ren_after_cpup(cpg, &a->h_path);
5529 + goto out_parent; /* success */
5533 + a->h_path.dentry = h_parent;
5534 + au_dtime_store(&a->dt, dst_parent, &a->h_path);
5535 + a->h_path.dentry = h_dst;
5537 + if (d_is_positive(h_dst)) {
5539 + /* no delegation since it is just created */
5540 + rerr = vfsub_unlink(h_dir, &a->h_path,
5541 + /*delegated*/NULL, /*force*/0);
5543 + rerr = vfsub_rmdir(h_dir, &a->h_path);
5545 + au_dtime_revert(&a->dt);
5547 + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr);
5552 + au_delayed_kfree(a);
5557 +#if 0 /* reserved */
5558 +struct au_cpup_single_args {
5560 + struct au_cp_generic *cpg;
5561 + struct dentry *dst_parent;
5564 +static void au_call_cpup_single(void *args)
5566 + struct au_cpup_single_args *a = args;
5568 + au_pin_hdir_acquire_nest(a->cpg->pin);
5569 + *a->errp = au_cpup_single(a->cpg, a->dst_parent);
5570 + au_pin_hdir_release(a->cpg->pin);
5575 + * prevent SIGXFSZ in copy-up.
5576 + * testing CAP_MKNOD is for generic fs,
5577 + * but CAP_FSETID is for xfs only, currently.
5579 +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode)
5582 + struct super_block *sb;
5583 + struct inode *h_dir;
5586 + sb = au_pinned_parent(pin)->d_sb;
5587 + if (!au_wkq_test()
5588 + && (!au_sbi(sb)->si_plink_maint_pid
5589 + || au_plink_maint(sb, AuLock_NOPLM))) {
5590 + switch (mode & S_IFMT) {
5592 + /* no condition about RLIMIT_FSIZE and the file size */
5597 + do_sio = !capable(CAP_MKNOD);
5601 + do_sio = ((mode & (S_ISUID | S_ISGID))
5602 + && !capable(CAP_FSETID));
5603 + /* this workaround may be removed in the future */
5605 + h_dir = au_pinned_h_dir(pin);
5606 + do_sio = h_dir->i_mode & S_ISVTX;
5613 +#if 0 /* reserved */
5614 +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent)
5617 + struct dentry *h_dentry;
5619 + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc);
5620 + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode))
5621 + err = au_cpup_single(cpg, dst_parent);
5623 + struct au_cpup_single_args args = {
5626 + .dst_parent = dst_parent
5628 + wkq_err = au_wkq_wait(au_call_cpup_single, &args);
5629 + if (unlikely(wkq_err))
5638 + * copyup the @dentry from the first active lower branch to @bdst,
5639 + * using au_cpup_single().
5641 +static int au_cpup_simple(struct au_cp_generic *cpg)
5644 + unsigned int flags_orig;
5645 + struct dentry *dentry;
5647 + AuDebugOn(cpg->bsrc < 0);
5649 + dentry = cpg->dentry;
5650 + DiMustWriteLock(dentry);
5652 + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1);
5654 + flags_orig = cpg->flags;
5655 + au_fset_cpup(cpg->flags, RENAME);
5656 + err = au_cpup_single(cpg, NULL);
5657 + cpg->flags = flags_orig;
5659 + return 0; /* success */
5662 + au_set_h_dptr(dentry, cpg->bdst, NULL);
5663 + au_set_dbtop(dentry, cpg->bsrc);
5669 +struct au_cpup_simple_args {
5671 + struct au_cp_generic *cpg;
5674 +static void au_call_cpup_simple(void *args)
5676 + struct au_cpup_simple_args *a = args;
5678 + au_pin_hdir_acquire_nest(a->cpg->pin);
5679 + *a->errp = au_cpup_simple(a->cpg);
5680 + au_pin_hdir_release(a->cpg->pin);
5683 +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg)
5686 + struct dentry *dentry, *parent;
5687 + struct file *h_file;
5688 + struct inode *h_dir;
5690 + dentry = cpg->dentry;
5692 + if (au_ftest_cpup(cpg->flags, HOPEN)) {
5693 + AuDebugOn(cpg->bsrc < 0);
5694 + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0);
5695 + err = PTR_ERR(h_file);
5696 + if (IS_ERR(h_file))
5700 + parent = dget_parent(dentry);
5701 + h_dir = au_h_iptr(d_inode(parent), cpg->bdst);
5702 + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE)
5703 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5704 + err = au_cpup_simple(cpg);
5706 + struct au_cpup_simple_args args = {
5710 + wkq_err = au_wkq_wait(au_call_cpup_simple, &args);
5711 + if (unlikely(wkq_err))
5717 + au_h_open_post(dentry, cpg->bsrc, h_file);
5723 +int au_sio_cpup_simple(struct au_cp_generic *cpg)
5725 + aufs_bindex_t bsrc, bbot;
5726 + struct dentry *dentry, *h_dentry;
5728 + if (cpg->bsrc < 0) {
5729 + dentry = cpg->dentry;
5730 + bbot = au_dbbot(dentry);
5731 + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) {
5732 + h_dentry = au_h_dptr(dentry, bsrc);
5734 + AuDebugOn(d_is_negative(h_dentry));
5738 + AuDebugOn(bsrc > bbot);
5741 + AuDebugOn(cpg->bsrc <= cpg->bdst);
5742 + return au_do_sio_cpup_simple(cpg);
5745 +int au_sio_cpdown_simple(struct au_cp_generic *cpg)
5747 + AuDebugOn(cpg->bdst <= cpg->bsrc);
5748 + return au_do_sio_cpup_simple(cpg);
5751 +/* ---------------------------------------------------------------------- */
5754 + * copyup the deleted file for writing.
5756 +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry,
5757 + struct file *file)
5760 + unsigned int flags_orig;
5761 + aufs_bindex_t bsrc_orig;
5762 + struct au_dinfo *dinfo;
5764 + struct au_hdentry *hd;
5765 + struct dentry *h_dentry;
5768 + dinfo = au_di(cpg->dentry);
5769 + AuRwMustWriteLock(&dinfo->di_rwsem);
5771 + bsrc_orig = cpg->bsrc;
5772 + cpg->bsrc = dinfo->di_btop;
5773 + hdst.hd = au_hdentry(dinfo, cpg->bdst);
5774 + hdst.h_dentry = hdst.hd->hd_dentry;
5775 + hdst.hd->hd_dentry = wh_dentry;
5776 + dinfo->di_btop = cpg->bdst;
5778 + hsrc.h_dentry = NULL;
5780 + hsrc.hd = au_hdentry(dinfo, cpg->bsrc);
5781 + hsrc.h_dentry = hsrc.hd->hd_dentry;
5782 + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry;
5784 + flags_orig = cpg->flags;
5785 + cpg->flags = !AuCpup_DTIME;
5786 + err = au_cpup_single(cpg, /*h_parent*/NULL);
5787 + cpg->flags = flags_orig;
5790 + err = au_reopen_nondir(file);
5791 + hsrc.hd->hd_dentry = hsrc.h_dentry;
5793 + hdst.hd->hd_dentry = hdst.h_dentry;
5794 + dinfo->di_btop = cpg->bsrc;
5795 + cpg->bsrc = bsrc_orig;
5800 +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5803 + aufs_bindex_t bdst;
5804 + struct au_dtime dt;
5805 + struct dentry *dentry, *parent, *h_parent, *wh_dentry;
5806 + struct au_branch *br;
5807 + struct path h_path;
5809 + dentry = cpg->dentry;
5811 + br = au_sbr(dentry->d_sb, bdst);
5812 + parent = dget_parent(dentry);
5813 + h_parent = au_h_dptr(parent, bdst);
5814 + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
5815 + err = PTR_ERR(wh_dentry);
5816 + if (IS_ERR(wh_dentry))
5819 + h_path.dentry = h_parent;
5820 + h_path.mnt = au_br_mnt(br);
5821 + au_dtime_store(&dt, parent, &h_path);
5822 + err = au_do_cpup_wh(cpg, wh_dentry, file);
5823 + if (unlikely(err))
5827 + h_path.dentry = wh_dentry;
5828 + if (!d_is_dir(wh_dentry)) {
5829 + /* no delegation since it is just created */
5830 + err = vfsub_unlink(d_inode(h_parent), &h_path,
5831 + /*delegated*/NULL, /*force*/0);
5833 + err = vfsub_rmdir(d_inode(h_parent), &h_path);
5834 + if (unlikely(err)) {
5835 + AuIOErr("failed remove copied-up tmp file %pd(%d)\n",
5839 + au_dtime_revert(&dt);
5840 + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry);
5849 +struct au_cpup_wh_args {
5851 + struct au_cp_generic *cpg;
5852 + struct file *file;
5855 +static void au_call_cpup_wh(void *args)
5857 + struct au_cpup_wh_args *a = args;
5859 + au_pin_hdir_acquire_nest(a->cpg->pin);
5860 + *a->errp = au_cpup_wh(a->cpg, a->file);
5861 + au_pin_hdir_release(a->cpg->pin);
5864 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file)
5867 + aufs_bindex_t bdst;
5868 + struct dentry *dentry, *parent, *h_orph, *h_parent;
5869 + struct inode *dir, *h_dir, *h_tmpdir;
5870 + struct au_wbr *wbr;
5871 + struct au_pin wh_pin, *pin_orig;
5873 + dentry = cpg->dentry;
5875 + parent = dget_parent(dentry);
5876 + dir = d_inode(parent);
5879 + h_dir = au_igrab(au_h_iptr(dir, bdst));
5882 + if (!h_dir->i_nlink) {
5883 + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr;
5884 + h_orph = wbr->wbr_orph;
5886 + h_parent = dget(au_h_dptr(parent, bdst));
5887 + au_set_h_dptr(parent, bdst, dget(h_orph));
5888 + h_tmpdir = d_inode(h_orph);
5889 + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0);
5891 + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3);
5892 + /* todo: au_h_open_pre()? */
5894 + pin_orig = cpg->pin;
5895 + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT,
5896 + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED);
5897 + cpg->pin = &wh_pin;
5900 + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE)
5901 + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode))
5902 + err = au_cpup_wh(cpg, file);
5904 + struct au_cpup_wh_args args = {
5909 + wkq_err = au_wkq_wait(au_call_cpup_wh, &args);
5910 + if (unlikely(wkq_err))
5915 + inode_unlock(h_tmpdir);
5916 + /* todo: au_h_open_post()? */
5917 + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0);
5918 + au_set_h_dptr(parent, bdst, h_parent);
5919 + AuDebugOn(!pin_orig);
5920 + cpg->pin = pin_orig;
5928 +/* ---------------------------------------------------------------------- */
5931 + * generic routine for both of copy-up and copy-down.
5933 +/* cf. revalidate function in file.c */
5934 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
5935 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
5936 + struct au_pin *pin,
5937 + struct dentry *h_parent, void *arg),
5941 + struct au_pin pin;
5942 + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry;
5945 + parent = dget_parent(dentry);
5946 + if (IS_ROOT(parent))
5949 + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2,
5950 + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE);
5952 + /* do not use au_dpage */
5953 + real_parent = parent;
5956 + parent = dget_parent(dentry);
5957 + h_parent = au_h_dptr(parent, bdst);
5959 + goto out; /* success */
5961 + /* find top dir which is necessary to cpup */
5965 + parent = dget_parent(d);
5966 + di_read_lock_parent3(parent, !AuLock_IR);
5967 + h_parent = au_h_dptr(parent, bdst);
5968 + di_read_unlock(parent, !AuLock_IR);
5969 + } while (!h_parent);
5971 + if (d != real_parent)
5972 + di_write_lock_child3(d);
5974 + /* somebody else might create while we were sleeping */
5975 + h_dentry = au_h_dptr(d, bdst);
5976 + if (!h_dentry || d_is_negative(h_dentry)) {
5978 + au_update_dbtop(d);
5980 + au_pin_set_dentry(&pin, d);
5981 + err = au_do_pin(&pin);
5983 + err = cp(d, bdst, &pin, h_parent, arg);
5988 + if (d != real_parent)
5989 + di_write_unlock(d);
5990 + if (unlikely(err))
5999 +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst,
6000 + struct au_pin *pin,
6001 + struct dentry *h_parent __maybe_unused,
6002 + void *arg __maybe_unused)
6004 + struct au_cp_generic cpg = {
6010 + .flags = AuCpup_DTIME
6012 + return au_sio_cpup_simple(&cpg);
6015 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6017 + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL);
6020 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst)
6023 + struct dentry *parent;
6024 + struct inode *dir;
6026 + parent = dget_parent(dentry);
6027 + dir = d_inode(parent);
6029 + if (au_h_iptr(dir, bdst))
6032 + di_read_unlock(parent, AuLock_IR);
6033 + di_write_lock_parent(parent);
6034 + /* someone else might change our inode while we were sleeping */
6035 + if (!au_h_iptr(dir, bdst))
6036 + err = au_cpup_dirs(dentry, bdst);
6037 + di_downgrade_lock(parent, AuLock_IR);
6043 diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h
6044 --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100
6045 +++ linux/fs/aufs/cpup.h 2016-10-09 16:55:36.486034798 +0200
6048 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6050 + * This program, aufs is free software; you can redistribute it and/or modify
6051 + * it under the terms of the GNU General Public License as published by
6052 + * the Free Software Foundation; either version 2 of the License, or
6053 + * (at your option) any later version.
6055 + * This program is distributed in the hope that it will be useful,
6056 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6057 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6058 + * GNU General Public License for more details.
6060 + * You should have received a copy of the GNU General Public License
6061 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6065 + * copy-up/down functions
6068 +#ifndef __AUFS_CPUP_H__
6069 +#define __AUFS_CPUP_H__
6073 +#include <linux/path.h>
6079 +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags);
6080 +void au_cpup_attr_timesizes(struct inode *inode);
6081 +void au_cpup_attr_nlink(struct inode *inode, int force);
6082 +void au_cpup_attr_changeable(struct inode *inode);
6083 +void au_cpup_igen(struct inode *inode, struct inode *h_inode);
6084 +void au_cpup_attr_all(struct inode *inode, int force);
6086 +/* ---------------------------------------------------------------------- */
6088 +struct au_cp_generic {
6089 + struct dentry *dentry;
6090 + aufs_bindex_t bdst, bsrc;
6092 + struct au_pin *pin;
6093 + unsigned int flags;
6097 +#define AuCpup_DTIME 1 /* do dtime_store/revert */
6098 +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino,
6100 +#define AuCpup_RENAME (1 << 2) /* rename after cpup */
6101 +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in
6103 +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the
6105 +#define AuCpup_RWDST (1 << 5) /* force write target even if
6106 + the branch is marked as RO */
6108 +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name)
6109 +#define au_fset_cpup(flags, name) \
6110 + do { (flags) |= AuCpup_##name; } while (0)
6111 +#define au_fclr_cpup(flags, name) \
6112 + do { (flags) &= ~AuCpup_##name; } while (0)
6114 +int au_copy_file(struct file *dst, struct file *src, loff_t len);
6115 +int au_sio_cpup_simple(struct au_cp_generic *cpg);
6116 +int au_sio_cpdown_simple(struct au_cp_generic *cpg);
6117 +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file);
6119 +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst,
6120 + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst,
6121 + struct au_pin *pin,
6122 + struct dentry *h_parent, void *arg),
6124 +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6125 +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst);
6127 +/* ---------------------------------------------------------------------- */
6129 +/* keep timestamps when copyup */
6131 + struct dentry *dt_dentry;
6132 + struct path dt_h_path;
6133 + struct timespec dt_atime, dt_mtime;
6135 +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry,
6136 + struct path *h_path);
6137 +void au_dtime_revert(struct au_dtime *dt);
6139 +#endif /* __KERNEL__ */
6140 +#endif /* __AUFS_CPUP_H__ */
6141 diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c
6142 --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100
6143 +++ linux/fs/aufs/dbgaufs.c 2016-10-09 16:55:38.886097714 +0200
6146 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6148 + * This program, aufs is free software; you can redistribute it and/or modify
6149 + * it under the terms of the GNU General Public License as published by
6150 + * the Free Software Foundation; either version 2 of the License, or
6151 + * (at your option) any later version.
6153 + * This program is distributed in the hope that it will be useful,
6154 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6155 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6156 + * GNU General Public License for more details.
6158 + * You should have received a copy of the GNU General Public License
6159 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6163 + * debugfs interface
6166 +#include <linux/debugfs.h>
6169 +#ifndef CONFIG_SYSFS
6170 +#error DEBUG_FS depends upon SYSFS
6173 +static struct dentry *dbgaufs;
6174 +static const mode_t dbgaufs_mode = S_IRUSR | S_IRGRP | S_IROTH;
6176 +/* 20 is max digits length of ulong 64 */
6177 +struct dbgaufs_arg {
6183 + * common function for all XINO files
6185 +static int dbgaufs_xi_release(struct inode *inode __maybe_unused,
6186 + struct file *file)
6188 + au_delayed_kfree(file->private_data);
6192 +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt)
6196 + struct dbgaufs_arg *p;
6199 + p = kmalloc(sizeof(*p), GFP_NOFS);
6205 + file->private_data = p;
6209 + err = vfs_getattr(&xf->f_path, &st);
6213 + (p->a, sizeof(p->a), "%ld, %llux%lu %lld\n",
6214 + (long)file_count(xf), st.blocks, st.blksize,
6215 + (long long)st.size);
6217 + p->n = snprintf(p->a, sizeof(p->a), "%llux%lu %lld\n",
6218 + st.blocks, st.blksize,
6219 + (long long)st.size);
6220 + AuDebugOn(p->n >= sizeof(p->a));
6222 + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err);
6231 +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf,
6232 + size_t count, loff_t *ppos)
6234 + struct dbgaufs_arg *p;
6236 + p = file->private_data;
6237 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6240 +/* ---------------------------------------------------------------------- */
6242 +struct dbgaufs_plink_arg {
6247 +static int dbgaufs_plink_release(struct inode *inode __maybe_unused,
6248 + struct file *file)
6250 + au_delayed_free_page((unsigned long)file->private_data);
6254 +static int dbgaufs_plink_open(struct inode *inode, struct file *file)
6256 + int err, i, limit;
6257 + unsigned long n, sum;
6258 + struct dbgaufs_plink_arg *p;
6259 + struct au_sbinfo *sbinfo;
6260 + struct super_block *sb;
6261 + struct au_sphlhead *sphl;
6264 + p = (void *)get_zeroed_page(GFP_NOFS);
6269 + sbinfo = inode->i_private;
6270 + sb = sbinfo->si_sb;
6271 + si_noflush_read_lock(sb);
6272 + if (au_opt_test(au_mntflags(sb), PLINK)) {
6273 + limit = PAGE_SIZE - sizeof(p->n);
6275 + /* the number of buckets */
6276 + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH);
6281 + for (i = 0, sphl = sbinfo->si_plink;
6282 + i < AuPlink_NHASH;
6284 + n = au_sphl_count(sphl);
6287 + n = snprintf(p->a + p->n, limit, "%lu ", n);
6290 + if (unlikely(limit <= 0))
6293 + p->a[p->n - 1] = '\n';
6295 + /* the sum of plinks */
6296 + n = snprintf(p->a + p->n, limit, "%lu\n", sum);
6299 + if (unlikely(limit <= 0))
6302 +#define str "1\n0\n0\n"
6303 + p->n = sizeof(str) - 1;
6304 + strcpy(p->a, str);
6307 + si_read_unlock(sb);
6310 + file->private_data = p;
6311 + goto out; /* success */
6314 + au_delayed_free_page((unsigned long)p);
6319 +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf,
6320 + size_t count, loff_t *ppos)
6322 + struct dbgaufs_plink_arg *p;
6324 + p = file->private_data;
6325 + return simple_read_from_buffer(buf, count, ppos, p->a, p->n);
6328 +static const struct file_operations dbgaufs_plink_fop = {
6329 + .owner = THIS_MODULE,
6330 + .open = dbgaufs_plink_open,
6331 + .release = dbgaufs_plink_release,
6332 + .read = dbgaufs_plink_read
6335 +/* ---------------------------------------------------------------------- */
6337 +static int dbgaufs_xib_open(struct inode *inode, struct file *file)
6340 + struct au_sbinfo *sbinfo;
6341 + struct super_block *sb;
6343 + sbinfo = inode->i_private;
6344 + sb = sbinfo->si_sb;
6345 + si_noflush_read_lock(sb);
6346 + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0);
6347 + si_read_unlock(sb);
6351 +static const struct file_operations dbgaufs_xib_fop = {
6352 + .owner = THIS_MODULE,
6353 + .open = dbgaufs_xib_open,
6354 + .release = dbgaufs_xi_release,
6355 + .read = dbgaufs_xi_read
6358 +/* ---------------------------------------------------------------------- */
6360 +#define DbgaufsXi_PREFIX "xi"
6362 +static int dbgaufs_xino_open(struct inode *inode, struct file *file)
6366 + struct au_sbinfo *sbinfo;
6367 + struct super_block *sb;
6369 + struct qstr *name;
6373 + name = &file->f_path.dentry->d_name;
6374 + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX)
6375 + || memcmp(name->name, DbgaufsXi_PREFIX,
6376 + sizeof(DbgaufsXi_PREFIX) - 1)))
6378 + err = kstrtol(name->name + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l);
6379 + if (unlikely(err))
6382 + sbinfo = inode->i_private;
6383 + sb = sbinfo->si_sb;
6384 + si_noflush_read_lock(sb);
6385 + if (l <= au_sbbot(sb)) {
6386 + xf = au_sbr(sb, (aufs_bindex_t)l)->br_xino.xi_file;
6387 + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1);
6390 + si_read_unlock(sb);
6396 +static const struct file_operations dbgaufs_xino_fop = {
6397 + .owner = THIS_MODULE,
6398 + .open = dbgaufs_xino_open,
6399 + .release = dbgaufs_xi_release,
6400 + .read = dbgaufs_xi_read
6403 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
6405 + aufs_bindex_t bbot;
6406 + struct au_branch *br;
6407 + struct au_xino_file *xi;
6409 + if (!au_sbi(sb)->si_dbgaufs)
6412 + bbot = au_sbbot(sb);
6413 + for (; bindex <= bbot; bindex++) {
6414 + br = au_sbr(sb, bindex);
6415 + xi = &br->br_xino;
6416 + /* debugfs acquires the parent i_mutex */
6418 + debugfs_remove(xi->xi_dbgaufs);
6420 + xi->xi_dbgaufs = NULL;
6424 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
6426 + struct au_sbinfo *sbinfo;
6427 + struct dentry *parent;
6428 + struct au_branch *br;
6429 + struct au_xino_file *xi;
6430 + aufs_bindex_t bbot;
6431 + char name[sizeof(DbgaufsXi_PREFIX) + 5]; /* "xi" bindex NULL */
6433 + sbinfo = au_sbi(sb);
6434 + parent = sbinfo->si_dbgaufs;
6438 + bbot = au_sbbot(sb);
6439 + for (; bindex <= bbot; bindex++) {
6440 + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex);
6441 + br = au_sbr(sb, bindex);
6442 + xi = &br->br_xino;
6443 + AuDebugOn(xi->xi_dbgaufs);
6444 + /* debugfs acquires the parent i_mutex */
6446 + xi->xi_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent,
6447 + sbinfo, &dbgaufs_xino_fop);
6449 + /* ignore an error */
6450 + if (unlikely(!xi->xi_dbgaufs))
6451 + AuWarn1("failed %s under debugfs\n", name);
6455 +/* ---------------------------------------------------------------------- */
6457 +#ifdef CONFIG_AUFS_EXPORT
6458 +static int dbgaufs_xigen_open(struct inode *inode, struct file *file)
6461 + struct au_sbinfo *sbinfo;
6462 + struct super_block *sb;
6464 + sbinfo = inode->i_private;
6465 + sb = sbinfo->si_sb;
6466 + si_noflush_read_lock(sb);
6467 + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0);
6468 + si_read_unlock(sb);
6472 +static const struct file_operations dbgaufs_xigen_fop = {
6473 + .owner = THIS_MODULE,
6474 + .open = dbgaufs_xigen_open,
6475 + .release = dbgaufs_xi_release,
6476 + .read = dbgaufs_xi_read
6479 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6484 + * This function is a dynamic '__init' function actually,
6485 + * so the tiny check for si_rwsem is unnecessary.
6487 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6490 + sbinfo->si_dbgaufs_xigen = debugfs_create_file
6491 + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6492 + &dbgaufs_xigen_fop);
6493 + if (sbinfo->si_dbgaufs_xigen)
6499 +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo)
6503 +#endif /* CONFIG_AUFS_EXPORT */
6505 +/* ---------------------------------------------------------------------- */
6507 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo)
6510 + * This function is a dynamic '__fin' function actually,
6511 + * so the tiny check for si_rwsem is unnecessary.
6513 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6515 + debugfs_remove_recursive(sbinfo->si_dbgaufs);
6516 + sbinfo->si_dbgaufs = NULL;
6517 + kobject_put(&sbinfo->si_kobj);
6520 +int dbgaufs_si_init(struct au_sbinfo *sbinfo)
6523 + char name[SysaufsSiNameLen];
6526 + * This function is a dynamic '__init' function actually,
6527 + * so the tiny check for si_rwsem is unnecessary.
6529 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
6533 + AuErr1("/debug/aufs is uninitialized\n");
6538 + sysaufs_name(sbinfo, name);
6539 + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs);
6540 + if (unlikely(!sbinfo->si_dbgaufs))
6542 + kobject_get(&sbinfo->si_kobj);
6544 + sbinfo->si_dbgaufs_xib = debugfs_create_file
6545 + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6546 + &dbgaufs_xib_fop);
6547 + if (unlikely(!sbinfo->si_dbgaufs_xib))
6550 + sbinfo->si_dbgaufs_plink = debugfs_create_file
6551 + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo,
6552 + &dbgaufs_plink_fop);
6553 + if (unlikely(!sbinfo->si_dbgaufs_plink))
6556 + err = dbgaufs_xigen_init(sbinfo);
6558 + goto out; /* success */
6561 + dbgaufs_si_fin(sbinfo);
6566 +/* ---------------------------------------------------------------------- */
6568 +void dbgaufs_fin(void)
6570 + debugfs_remove(dbgaufs);
6573 +int __init dbgaufs_init(void)
6578 + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL);
6583 diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h
6584 --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100
6585 +++ linux/fs/aufs/dbgaufs.h 2016-10-09 16:55:36.486034798 +0200
6588 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6590 + * This program, aufs is free software; you can redistribute it and/or modify
6591 + * it under the terms of the GNU General Public License as published by
6592 + * the Free Software Foundation; either version 2 of the License, or
6593 + * (at your option) any later version.
6595 + * This program is distributed in the hope that it will be useful,
6596 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6597 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6598 + * GNU General Public License for more details.
6600 + * You should have received a copy of the GNU General Public License
6601 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6605 + * debugfs interface
6608 +#ifndef __DBGAUFS_H__
6609 +#define __DBGAUFS_H__
6613 +struct super_block;
6616 +#ifdef CONFIG_DEBUG_FS
6618 +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
6619 +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
6620 +void dbgaufs_si_fin(struct au_sbinfo *sbinfo);
6621 +int dbgaufs_si_init(struct au_sbinfo *sbinfo);
6622 +void dbgaufs_fin(void);
6623 +int __init dbgaufs_init(void);
6625 +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
6626 +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
6627 +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo)
6628 +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo)
6629 +AuStubVoid(dbgaufs_fin, void)
6630 +AuStubInt0(__init dbgaufs_init, void)
6631 +#endif /* CONFIG_DEBUG_FS */
6633 +#endif /* __KERNEL__ */
6634 +#endif /* __DBGAUFS_H__ */
6635 diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c
6636 --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100
6637 +++ linux/fs/aufs/dcsub.c 2016-10-09 16:55:38.886097714 +0200
6640 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6642 + * This program, aufs is free software; you can redistribute it and/or modify
6643 + * it under the terms of the GNU General Public License as published by
6644 + * the Free Software Foundation; either version 2 of the License, or
6645 + * (at your option) any later version.
6647 + * This program is distributed in the hope that it will be useful,
6648 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6649 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6650 + * GNU General Public License for more details.
6652 + * You should have received a copy of the GNU General Public License
6653 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6657 + * sub-routines for dentry cache
6662 +static void au_dpage_free(struct au_dpage *dpage)
6665 + struct dentry **p;
6667 + p = dpage->dentries;
6668 + for (i = 0; i < dpage->ndentry; i++)
6670 + au_delayed_free_page((unsigned long)dpage->dentries);
6673 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp)
6679 + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp);
6680 + if (unlikely(!dpages->dpages))
6683 + p = (void *)__get_free_page(gfp);
6687 + dpages->dpages[0].ndentry = 0;
6688 + dpages->dpages[0].dentries = p;
6689 + dpages->ndpage = 1;
6690 + return 0; /* success */
6693 + au_delayed_kfree(dpages->dpages);
6698 +void au_dpages_free(struct au_dcsub_pages *dpages)
6701 + struct au_dpage *p;
6703 + p = dpages->dpages;
6704 + for (i = 0; i < dpages->ndpage; i++)
6705 + au_dpage_free(p++);
6706 + au_delayed_kfree(dpages->dpages);
6709 +static int au_dpages_append(struct au_dcsub_pages *dpages,
6710 + struct dentry *dentry, gfp_t gfp)
6713 + struct au_dpage *dpage;
6716 + dpage = dpages->dpages + dpages->ndpage - 1;
6717 + sz = PAGE_SIZE / sizeof(dentry);
6718 + if (unlikely(dpage->ndentry >= sz)) {
6719 + AuLabel(new dpage);
6721 + sz = dpages->ndpage * sizeof(*dpages->dpages);
6722 + p = au_kzrealloc(dpages->dpages, sz,
6723 + sz + sizeof(*dpages->dpages), gfp,
6728 + dpages->dpages = p;
6729 + dpage = dpages->dpages + dpages->ndpage;
6730 + p = (void *)__get_free_page(gfp);
6734 + dpage->ndentry = 0;
6735 + dpage->dentries = p;
6739 + AuDebugOn(au_dcount(dentry) <= 0);
6740 + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry);
6741 + return 0; /* success */
6747 +/* todo: BAD approach */
6748 +/* copied from linux/fs/dcache.c */
6756 +extern void d_walk(struct dentry *parent, void *data,
6757 + enum d_walk_ret (*enter)(void *, struct dentry *),
6758 + void (*finish)(void *));
6760 +struct ac_dpages_arg {
6762 + struct au_dcsub_pages *dpages;
6763 + struct super_block *sb;
6764 + au_dpages_test test;
6768 +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry)
6770 + enum d_walk_ret ret;
6771 + struct ac_dpages_arg *arg = _arg;
6773 + ret = D_WALK_CONTINUE;
6774 + if (dentry->d_sb == arg->sb
6775 + && !IS_ROOT(dentry)
6776 + && au_dcount(dentry) > 0
6778 + && (!arg->test || arg->test(dentry, arg->arg))) {
6779 + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC);
6780 + if (unlikely(arg->err))
6781 + ret = D_WALK_QUIT;
6787 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6788 + au_dpages_test test, void *arg)
6790 + struct ac_dpages_arg args = {
6798 + d_walk(root, &args, au_call_dpages_append, NULL);
6803 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6804 + int do_include, au_dpages_test test, void *arg)
6809 + write_seqlock(&rename_lock);
6810 + spin_lock(&dentry->d_lock);
6812 + && au_dcount(dentry) > 0
6813 + && (!test || test(dentry, arg)))
6814 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6815 + spin_unlock(&dentry->d_lock);
6816 + if (unlikely(err))
6820 + * RCU for vfsmount is unnecessary since this is a traverse in a single
6823 + while (!IS_ROOT(dentry)) {
6824 + dentry = dentry->d_parent; /* rename_lock is locked */
6825 + spin_lock(&dentry->d_lock);
6826 + if (au_dcount(dentry) > 0
6827 + && (!test || test(dentry, arg)))
6828 + err = au_dpages_append(dpages, dentry, GFP_ATOMIC);
6829 + spin_unlock(&dentry->d_lock);
6830 + if (unlikely(err))
6835 + write_sequnlock(&rename_lock);
6839 +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg)
6841 + return au_di(dentry) && dentry->d_sb == arg;
6844 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6845 + struct dentry *dentry, int do_include)
6847 + return au_dcsub_pages_rev(dpages, dentry, do_include,
6848 + au_dcsub_dpages_aufs, dentry->d_sb);
6851 +int au_test_subdir(struct dentry *d1, struct dentry *d2)
6853 + struct path path[2] = {
6862 + return path_is_under(path + 0, path + 1);
6864 diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h
6865 --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100
6866 +++ linux/fs/aufs/dcsub.h 2016-10-09 16:55:36.486034798 +0200
6869 + * Copyright (C) 2005-2016 Junjiro R. Okajima
6871 + * This program, aufs is free software; you can redistribute it and/or modify
6872 + * it under the terms of the GNU General Public License as published by
6873 + * the Free Software Foundation; either version 2 of the License, or
6874 + * (at your option) any later version.
6876 + * This program is distributed in the hope that it will be useful,
6877 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
6878 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6879 + * GNU General Public License for more details.
6881 + * You should have received a copy of the GNU General Public License
6882 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
6886 + * sub-routines for dentry cache
6889 +#ifndef __AUFS_DCSUB_H__
6890 +#define __AUFS_DCSUB_H__
6894 +#include <linux/dcache.h>
6895 +#include <linux/fs.h>
6899 + struct dentry **dentries;
6902 +struct au_dcsub_pages {
6904 + struct au_dpage *dpages;
6907 +/* ---------------------------------------------------------------------- */
6910 +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp);
6911 +void au_dpages_free(struct au_dcsub_pages *dpages);
6912 +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg);
6913 +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root,
6914 + au_dpages_test test, void *arg);
6915 +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry,
6916 + int do_include, au_dpages_test test, void *arg);
6917 +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages,
6918 + struct dentry *dentry, int do_include);
6919 +int au_test_subdir(struct dentry *d1, struct dentry *d2);
6921 +/* ---------------------------------------------------------------------- */
6924 + * todo: in linux-3.13, several similar (but faster) helpers are added to
6925 + * include/linux/dcache.h. Try them (in the future).
6928 +static inline int au_d_hashed_positive(struct dentry *d)
6931 + struct inode *inode = d_inode(d);
6934 + if (unlikely(d_unhashed(d)
6935 + || d_is_negative(d)
6936 + || !inode->i_nlink))
6941 +static inline int au_d_linkable(struct dentry *d)
6944 + struct inode *inode = d_inode(d);
6946 + err = au_d_hashed_positive(d);
6948 + && d_is_positive(d)
6949 + && (inode->i_state & I_LINKABLE))
6954 +static inline int au_d_alive(struct dentry *d)
6957 + struct inode *inode;
6961 + err = au_d_hashed_positive(d);
6963 + inode = d_inode(d);
6964 + if (unlikely(d_unlinked(d)
6965 + || d_is_negative(d)
6966 + || !inode->i_nlink))
6972 +static inline int au_alive_dir(struct dentry *d)
6976 + err = au_d_alive(d);
6977 + if (unlikely(err || IS_DEADDIR(d_inode(d))))
6982 +static inline int au_qstreq(struct qstr *a, struct qstr *b)
6984 + return a->len == b->len
6985 + && !memcmp(a->name, b->name, a->len);
6990 + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without
6992 + * the type of d_lockref.count became int, but the inlined function d_count()
6993 + * still returns unsigned int.
6994 + * I don't know why. Maybe it is for every d_count() users?
6995 + * Anyway au_dcount() lives on.
6997 +static inline int au_dcount(struct dentry *d)
6999 + return (int)d_count(d);
7002 +#endif /* __KERNEL__ */
7003 +#endif /* __AUFS_DCSUB_H__ */
7004 diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c
7005 --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100
7006 +++ linux/fs/aufs/debug.c 2016-10-09 16:55:36.486034798 +0200
7009 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7011 + * This program, aufs is free software; you can redistribute it and/or modify
7012 + * it under the terms of the GNU General Public License as published by
7013 + * the Free Software Foundation; either version 2 of the License, or
7014 + * (at your option) any later version.
7016 + * This program is distributed in the hope that it will be useful,
7017 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7018 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7019 + * GNU General Public License for more details.
7021 + * You should have received a copy of the GNU General Public License
7022 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7026 + * debug print functions
7031 +/* Returns 0, or -errno. arg is in kp->arg. */
7032 +static int param_atomic_t_set(const char *val, const struct kernel_param *kp)
7036 + err = kstrtoint(val, 0, &n);
7046 +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */
7047 +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp)
7052 + return sprintf(buffer, "%d", atomic_read(a));
7055 +static struct kernel_param_ops param_ops_atomic_t = {
7056 + .set = param_atomic_t_set,
7057 + .get = param_atomic_t_get
7058 + /* void (*free)(void *arg) */
7061 +atomic_t aufs_debug = ATOMIC_INIT(0);
7062 +MODULE_PARM_DESC(debug, "debug print");
7063 +module_param_named(debug, aufs_debug, atomic_t, S_IRUGO | S_IWUSR | S_IWGRP);
7065 +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */
7066 +char *au_plevel = KERN_DEBUG;
7067 +#define dpri(fmt, ...) do { \
7069 + && strcmp(au_plevel, KERN_DEBUG)) \
7070 + || au_debug_test()) \
7071 + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \
7074 +/* ---------------------------------------------------------------------- */
7076 +void au_dpri_whlist(struct au_nhash *whlist)
7078 + unsigned long ul, n;
7079 + struct hlist_head *head;
7080 + struct au_vdir_wh *pos;
7082 + n = whlist->nh_num;
7083 + head = whlist->nh_head;
7084 + for (ul = 0; ul < n; ul++) {
7085 + hlist_for_each_entry(pos, head, wh_hash)
7086 + dpri("b%d, %.*s, %d\n",
7088 + pos->wh_str.len, pos->wh_str.name,
7094 +void au_dpri_vdir(struct au_vdir *vdir)
7097 + union au_vdir_deblk_p p;
7100 + if (!vdir || IS_ERR(vdir)) {
7101 + dpri("err %ld\n", PTR_ERR(vdir));
7105 + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %lu\n",
7106 + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk,
7107 + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version);
7108 + for (ul = 0; ul < vdir->vd_nblk; ul++) {
7109 + p.deblk = vdir->vd_deblk[ul];
7111 + dpri("[%lu]: %p\n", ul, o);
7115 +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn,
7116 + struct dentry *wh)
7121 + if (!inode || IS_ERR(inode)) {
7122 + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode));
7126 + /* the type of i_blocks depends upon CONFIG_LBDAF */
7127 + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long)
7128 + && sizeof(inode->i_blocks) != sizeof(u64));
7130 + n = (void *)wh->d_name.name;
7131 + l = wh->d_name.len;
7134 + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu,"
7135 + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n",
7137 + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??",
7138 + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode,
7139 + i_size_read(inode), (unsigned long long)inode->i_blocks,
7140 + hn, (long long)timespec_to_ns(&inode->i_ctime) & 0x0ffff,
7141 + inode->i_mapping ? inode->i_mapping->nrpages : 0,
7142 + inode->i_state, inode->i_flags, inode->i_version,
7143 + inode->i_generation,
7144 + l ? ", wh " : "", l, n);
7148 +void au_dpri_inode(struct inode *inode)
7150 + struct au_iinfo *iinfo;
7151 + struct au_hinode *hi;
7152 + aufs_bindex_t bindex;
7155 + err = do_pri_inode(-1, inode, -1, NULL);
7156 + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode))
7159 + iinfo = au_ii(inode);
7160 + dpri("i-1: btop %d, bbot %d, gen %d\n",
7161 + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL));
7162 + if (iinfo->ii_btop < 0)
7165 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) {
7166 + hi = au_hinode(iinfo, bindex);
7168 + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry);
7172 +void au_dpri_dalias(struct inode *inode)
7176 + spin_lock(&inode->i_lock);
7177 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias)
7178 + au_dpri_dentry(d);
7179 + spin_unlock(&inode->i_lock);
7182 +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry)
7184 + struct dentry *wh = NULL;
7186 + struct inode *inode;
7187 + struct au_iinfo *iinfo;
7188 + struct au_hinode *hi;
7190 + if (!dentry || IS_ERR(dentry)) {
7191 + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry));
7194 + /* do not call dget_parent() here */
7195 + /* note: access d_xxx without d_lock */
7196 + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n",
7197 + bindex, dentry, dentry,
7198 + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??",
7199 + au_dcount(dentry), dentry->d_flags,
7200 + d_unhashed(dentry) ? "un" : "");
7203 + if (d_is_positive(dentry))
7204 + inode = d_inode(dentry);
7206 + && au_test_aufs(dentry->d_sb)
7208 + && !au_is_bad_inode(inode)) {
7209 + iinfo = au_ii(inode);
7210 + hi = au_hinode(iinfo, bindex);
7212 + wh = hi->hi_whdentry;
7214 + do_pri_inode(bindex, inode, hn, wh);
7218 +void au_dpri_dentry(struct dentry *dentry)
7220 + struct au_dinfo *dinfo;
7221 + aufs_bindex_t bindex;
7224 + err = do_pri_dentry(-1, dentry);
7225 + if (err || !au_test_aufs(dentry->d_sb))
7228 + dinfo = au_di(dentry);
7231 + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n",
7232 + dinfo->di_btop, dinfo->di_bbot,
7233 + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry),
7234 + dinfo->di_tmpfile);
7235 + if (dinfo->di_btop < 0)
7237 + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++)
7238 + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry);
7241 +static int do_pri_file(aufs_bindex_t bindex, struct file *file)
7245 + if (!file || IS_ERR(file)) {
7246 + dpri("f%d: err %ld\n", bindex, PTR_ERR(file));
7251 + && !IS_ERR_OR_NULL(file->f_path.dentry)
7252 + && au_test_aufs(file->f_path.dentry->d_sb)
7254 + snprintf(a, sizeof(a), ", gen %d, mmapped %d",
7255 + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped));
7256 + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n",
7257 + bindex, file->f_mode, file->f_flags, (long)file_count(file),
7258 + file->f_version, file->f_pos, a);
7259 + if (!IS_ERR_OR_NULL(file->f_path.dentry))
7260 + do_pri_dentry(bindex, file->f_path.dentry);
7264 +void au_dpri_file(struct file *file)
7266 + struct au_finfo *finfo;
7267 + struct au_fidir *fidir;
7268 + struct au_hfile *hfile;
7269 + aufs_bindex_t bindex;
7272 + err = do_pri_file(-1, file);
7274 + || IS_ERR_OR_NULL(file->f_path.dentry)
7275 + || !au_test_aufs(file->f_path.dentry->d_sb))
7278 + finfo = au_fi(file);
7281 + if (finfo->fi_btop < 0)
7283 + fidir = finfo->fi_hdir;
7285 + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file);
7287 + for (bindex = finfo->fi_btop;
7288 + bindex >= 0 && bindex <= fidir->fd_bbot;
7290 + hfile = fidir->fd_hfile + bindex;
7291 + do_pri_file(bindex, hfile ? hfile->hf_file : NULL);
7295 +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br)
7297 + struct vfsmount *mnt;
7298 + struct super_block *sb;
7300 + if (!br || IS_ERR(br))
7302 + mnt = au_br_mnt(br);
7303 + if (!mnt || IS_ERR(mnt))
7306 + if (!sb || IS_ERR(sb))
7309 + dpri("s%d: {perm 0x%x, id %d, cnt %lld, wbr %p}, "
7310 + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, "
7312 + bindex, br->br_perm, br->br_id, au_br_count(br),
7313 + br->br_wbr, au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev),
7314 + sb->s_flags, sb->s_count,
7315 + atomic_read(&sb->s_active), !!br->br_xino.xi_file);
7319 + dpri("s%d: err %ld\n", bindex, PTR_ERR(br));
7323 +void au_dpri_sb(struct super_block *sb)
7325 + struct au_sbinfo *sbinfo;
7326 + aufs_bindex_t bindex;
7328 + /* to reuduce stack size */
7330 + struct vfsmount mnt;
7331 + struct au_branch fake;
7334 + /* this function can be called from magic sysrq */
7335 + a = kzalloc(sizeof(*a), GFP_ATOMIC);
7336 + if (unlikely(!a)) {
7337 + dpri("no memory\n");
7341 + a->mnt.mnt_sb = sb;
7342 + a->fake.br_path.mnt = &a->mnt;
7343 + au_br_count_init(&a->fake);
7344 + err = do_pri_br(-1, &a->fake);
7345 + au_br_count_fin(&a->fake);
7346 + au_delayed_kfree(a);
7347 + dpri("dev 0x%x\n", sb->s_dev);
7348 + if (err || !au_test_aufs(sb))
7351 + sbinfo = au_sbi(sb);
7354 + dpri("nw %d, gen %u, kobj %d\n",
7355 + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation,
7356 + atomic_read(&sbinfo->si_kobj.kref.refcount));
7357 + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++)
7358 + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]);
7361 +/* ---------------------------------------------------------------------- */
7363 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line)
7365 + struct inode *h_inode, *inode = d_inode(dentry);
7366 + struct dentry *h_dentry;
7367 + aufs_bindex_t bindex, bbot, bi;
7369 + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */)
7372 + bbot = au_dbbot(dentry);
7373 + bi = au_ibbot(inode);
7376 + bindex = au_dbtop(dentry);
7377 + bi = au_ibtop(inode);
7381 + for (; bindex <= bbot; bindex++) {
7382 + h_dentry = au_h_dptr(dentry, bindex);
7385 + h_inode = au_h_iptr(inode, bindex);
7386 + if (unlikely(h_inode != d_inode(h_dentry))) {
7388 + AuDbg("b%d, %s:%d\n", bindex, func, line);
7389 + AuDbgDentry(dentry);
7390 + AuDbgInode(inode);
7397 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen)
7400 + struct au_dcsub_pages dpages;
7401 + struct au_dpage *dpage;
7402 + struct dentry **dentries;
7404 + err = au_dpages_init(&dpages, GFP_NOFS);
7406 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1);
7408 + for (i = dpages.ndpage - 1; !err && i >= 0; i--) {
7409 + dpage = dpages.dpages + i;
7410 + dentries = dpage->dentries;
7411 + for (j = dpage->ndentry - 1; !err && j >= 0; j--)
7412 + AuDebugOn(au_digen_test(dentries[j], sigen));
7414 + au_dpages_free(&dpages);
7417 +void au_dbg_verify_kthread(void)
7419 + if (au_wkq_test()) {
7422 + * It may be recursive, but udba=notify between two aufs mounts,
7423 + * where a single ro branch is shared, is not a problem.
7429 +/* ---------------------------------------------------------------------- */
7431 +int __init au_debug_init(void)
7433 + aufs_bindex_t bindex;
7434 + struct au_vdir_destr destr;
7437 + AuDebugOn(bindex >= 0);
7440 + AuDebugOn(destr.len < NAME_MAX);
7442 +#ifdef CONFIG_4KSTACKS
7443 + pr_warn("CONFIG_4KSTACKS is defined.\n");
7448 diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h
7449 --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100
7450 +++ linux/fs/aufs/debug.h 2016-10-09 16:55:36.486034798 +0200
7453 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7455 + * This program, aufs is free software; you can redistribute it and/or modify
7456 + * it under the terms of the GNU General Public License as published by
7457 + * the Free Software Foundation; either version 2 of the License, or
7458 + * (at your option) any later version.
7460 + * This program is distributed in the hope that it will be useful,
7461 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7462 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7463 + * GNU General Public License for more details.
7465 + * You should have received a copy of the GNU General Public License
7466 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7470 + * debug print functions
7473 +#ifndef __AUFS_DEBUG_H__
7474 +#define __AUFS_DEBUG_H__
7478 +#include <linux/atomic.h>
7479 +#include <linux/module.h>
7480 +#include <linux/kallsyms.h>
7481 +#include <linux/sysrq.h>
7483 +#ifdef CONFIG_AUFS_DEBUG
7484 +#define AuDebugOn(a) BUG_ON(a)
7486 +/* module parameter */
7487 +extern atomic_t aufs_debug;
7488 +static inline void au_debug_on(void)
7490 + atomic_inc(&aufs_debug);
7492 +static inline void au_debug_off(void)
7494 + atomic_dec_if_positive(&aufs_debug);
7497 +static inline int au_debug_test(void)
7499 + return atomic_read(&aufs_debug) > 0;
7502 +#define AuDebugOn(a) do {} while (0)
7503 +AuStubVoid(au_debug_on, void)
7504 +AuStubVoid(au_debug_off, void)
7505 +AuStubInt0(au_debug_test, void)
7506 +#endif /* CONFIG_AUFS_DEBUG */
7508 +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)
7510 +/* ---------------------------------------------------------------------- */
7514 +#define AuDbg(fmt, ...) do { \
7515 + if (au_debug_test()) \
7516 + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
7518 +#define AuLabel(l) AuDbg(#l "\n")
7519 +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
7520 +#define AuWarn1(fmt, ...) do { \
7521 + static unsigned char _c; \
7523 + pr_warn(fmt, ##__VA_ARGS__); \
7526 +#define AuErr1(fmt, ...) do { \
7527 + static unsigned char _c; \
7529 + pr_err(fmt, ##__VA_ARGS__); \
7532 +#define AuIOErr1(fmt, ...) do { \
7533 + static unsigned char _c; \
7535 + AuIOErr(fmt, ##__VA_ARGS__); \
7538 +#define AuUnsupportMsg "This operation is not supported." \
7539 + " Please report this application to aufs-users ML."
7540 +#define AuUnsupport(fmt, ...) do { \
7541 + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
7545 +#define AuTraceErr(e) do { \
7546 + if (unlikely((e) < 0)) \
7547 + AuDbg("err %d\n", (int)(e)); \
7550 +#define AuTraceErrPtr(p) do { \
7552 + AuDbg("err %ld\n", PTR_ERR(p)); \
7555 +/* dirty macros for debug print, use with "%.*s" and caution */
7556 +#define AuLNPair(qstr) (qstr)->len, (qstr)->name
7558 +/* ---------------------------------------------------------------------- */
7561 +#ifdef CONFIG_AUFS_DEBUG
7562 +extern struct mutex au_dbg_mtx;
7563 +extern char *au_plevel;
7565 +void au_dpri_whlist(struct au_nhash *whlist);
7567 +void au_dpri_vdir(struct au_vdir *vdir);
7569 +void au_dpri_inode(struct inode *inode);
7570 +void au_dpri_dalias(struct inode *inode);
7571 +void au_dpri_dentry(struct dentry *dentry);
7573 +void au_dpri_file(struct file *filp);
7574 +struct super_block;
7575 +void au_dpri_sb(struct super_block *sb);
7577 +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
7578 +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
7579 +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
7580 +void au_dbg_verify_kthread(void);
7582 +int __init au_debug_init(void);
7584 +#define AuDbgWhlist(w) do { \
7585 + mutex_lock(&au_dbg_mtx); \
7587 + au_dpri_whlist(w); \
7588 + mutex_unlock(&au_dbg_mtx); \
7591 +#define AuDbgVdir(v) do { \
7592 + mutex_lock(&au_dbg_mtx); \
7594 + au_dpri_vdir(v); \
7595 + mutex_unlock(&au_dbg_mtx); \
7598 +#define AuDbgInode(i) do { \
7599 + mutex_lock(&au_dbg_mtx); \
7601 + au_dpri_inode(i); \
7602 + mutex_unlock(&au_dbg_mtx); \
7605 +#define AuDbgDAlias(i) do { \
7606 + mutex_lock(&au_dbg_mtx); \
7608 + au_dpri_dalias(i); \
7609 + mutex_unlock(&au_dbg_mtx); \
7612 +#define AuDbgDentry(d) do { \
7613 + mutex_lock(&au_dbg_mtx); \
7615 + au_dpri_dentry(d); \
7616 + mutex_unlock(&au_dbg_mtx); \
7619 +#define AuDbgFile(f) do { \
7620 + mutex_lock(&au_dbg_mtx); \
7622 + au_dpri_file(f); \
7623 + mutex_unlock(&au_dbg_mtx); \
7626 +#define AuDbgSb(sb) do { \
7627 + mutex_lock(&au_dbg_mtx); \
7628 + AuDbg(#sb "\n"); \
7630 + mutex_unlock(&au_dbg_mtx); \
7633 +#define AuDbgSym(addr) do { \
7634 + char sym[KSYM_SYMBOL_LEN]; \
7635 + sprint_symbol(sym, (unsigned long)addr); \
7636 + AuDbg("%s\n", sym); \
7639 +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
7640 +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
7641 +AuStubVoid(au_dbg_verify_kthread, void)
7642 +AuStubInt0(__init au_debug_init, void)
7644 +#define AuDbgWhlist(w) do {} while (0)
7645 +#define AuDbgVdir(v) do {} while (0)
7646 +#define AuDbgInode(i) do {} while (0)
7647 +#define AuDbgDAlias(i) do {} while (0)
7648 +#define AuDbgDentry(d) do {} while (0)
7649 +#define AuDbgFile(f) do {} while (0)
7650 +#define AuDbgSb(sb) do {} while (0)
7651 +#define AuDbgSym(addr) do {} while (0)
7652 +#endif /* CONFIG_AUFS_DEBUG */
7654 +/* ---------------------------------------------------------------------- */
7656 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
7657 +int __init au_sysrq_init(void);
7658 +void au_sysrq_fin(void);
7660 +#ifdef CONFIG_HW_CONSOLE
7661 +#define au_dbg_blocked() do { \
7663 + handle_sysrq('w'); \
7666 +AuStubVoid(au_dbg_blocked, void)
7670 +AuStubInt0(__init au_sysrq_init, void)
7671 +AuStubVoid(au_sysrq_fin, void)
7672 +AuStubVoid(au_dbg_blocked, void)
7673 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
7675 +#endif /* __KERNEL__ */
7676 +#endif /* __AUFS_DEBUG_H__ */
7677 diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c
7678 --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100
7679 +++ linux/fs/aufs/dentry.c 2016-10-09 16:55:38.889431135 +0200
7682 + * Copyright (C) 2005-2016 Junjiro R. Okajima
7684 + * This program, aufs is free software; you can redistribute it and/or modify
7685 + * it under the terms of the GNU General Public License as published by
7686 + * the Free Software Foundation; either version 2 of the License, or
7687 + * (at your option) any later version.
7689 + * This program is distributed in the hope that it will be useful,
7690 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
7691 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7692 + * GNU General Public License for more details.
7694 + * You should have received a copy of the GNU General Public License
7695 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
7699 + * lookup and dentry operations
7702 +#include <linux/namei.h>
7705 +struct au_do_lookup_args {
7706 + unsigned int flags;
7711 + * returns positive/negative dentry, NULL or an error.
7712 + * NULL means whiteout-ed or not-found.
7714 +static struct dentry*
7715 +au_do_lookup(struct dentry *h_parent, struct dentry *dentry,
7716 + aufs_bindex_t bindex, struct qstr *wh_name,
7717 + struct au_do_lookup_args *args)
7719 + struct dentry *h_dentry;
7720 + struct inode *h_inode;
7721 + struct au_branch *br;
7722 + int wh_found, opq;
7723 + unsigned char wh_able;
7724 + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG);
7725 + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags,
7729 + br = au_sbr(dentry->d_sb, bindex);
7730 + wh_able = !!au_br_whable(br->br_perm);
7732 + wh_found = au_wh_test(h_parent, wh_name, ignore_perm);
7733 + h_dentry = ERR_PTR(wh_found);
7736 + if (unlikely(wh_found < 0))
7739 + /* We found a whiteout */
7740 + /* au_set_dbbot(dentry, bindex); */
7741 + au_set_dbwh(dentry, bindex);
7743 + return NULL; /* success */
7747 + h_dentry = vfsub_lkup_one(&dentry->d_name, h_parent);
7749 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7750 + if (IS_ERR(h_dentry)) {
7751 + if (PTR_ERR(h_dentry) == -ENAMETOOLONG
7757 + h_inode = d_inode(h_dentry);
7758 + if (d_is_negative(h_dentry)) {
7761 + } else if (wh_found
7762 + || (args->type && args->type != (h_inode->i_mode & S_IFMT)))
7765 + if (au_dbbot(dentry) <= bindex)
7766 + au_set_dbbot(dentry, bindex);
7767 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
7768 + au_set_dbtop(dentry, bindex);
7769 + au_set_h_dptr(dentry, bindex, h_dentry);
7771 + if (!d_is_dir(h_dentry)
7773 + || (d_really_is_positive(dentry) && !d_is_dir(dentry)))
7774 + goto out; /* success */
7776 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
7777 + opq = au_diropq_test(h_dentry);
7778 + inode_unlock(h_inode);
7780 + au_set_dbdiropq(dentry, bindex);
7781 + else if (unlikely(opq < 0)) {
7782 + au_set_h_dptr(dentry, bindex, NULL);
7783 + h_dentry = ERR_PTR(opq);
7794 +static int au_test_shwh(struct super_block *sb, const struct qstr *name)
7796 + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH)
7797 + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)))
7803 + * returns the number of lower positive dentries,
7804 + * otherwise an error.
7805 + * can be called at unlinking with @type is zero.
7807 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
7808 + unsigned int flags)
7810 + int npositive, err;
7811 + aufs_bindex_t bindex, btail, bdiropq;
7812 + unsigned char isdir, dirperm1;
7813 + struct qstr whname;
7814 + struct au_do_lookup_args args = {
7817 + const struct qstr *name = &dentry->d_name;
7818 + struct dentry *parent;
7819 + struct super_block *sb;
7821 + sb = dentry->d_sb;
7822 + err = au_test_shwh(sb, name);
7823 + if (unlikely(err))
7826 + err = au_wh_name_alloc(&whname, name);
7827 + if (unlikely(err))
7830 + isdir = !!d_is_dir(dentry);
7831 + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1);
7834 + parent = dget_parent(dentry);
7835 + btail = au_dbtaildir(parent);
7836 + for (bindex = btop; bindex <= btail; bindex++) {
7837 + struct dentry *h_parent, *h_dentry;
7838 + struct inode *h_inode, *h_dir;
7840 + h_dentry = au_h_dptr(dentry, bindex);
7842 + if (d_is_positive(h_dentry))
7846 + h_parent = au_h_dptr(parent, bindex);
7847 + if (!h_parent || !d_is_dir(h_parent))
7850 + h_dir = d_inode(h_parent);
7851 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
7852 + h_dentry = au_do_lookup(h_parent, dentry, bindex, &whname,
7854 + inode_unlock(h_dir);
7855 + err = PTR_ERR(h_dentry);
7856 + if (IS_ERR(h_dentry))
7859 + au_fclr_lkup(args.flags, ALLOW_NEG);
7861 + au_fset_lkup(args.flags, IGNORE_PERM);
7863 + if (au_dbwh(dentry) == bindex)
7867 + if (d_is_negative(h_dentry))
7869 + h_inode = d_inode(h_dentry);
7872 + args.type = h_inode->i_mode & S_IFMT;
7873 + if (args.type != S_IFDIR)
7876 + /* the type of lower may be different */
7877 + bdiropq = au_dbdiropq(dentry);
7878 + if (bdiropq >= 0 && bdiropq <= bindex)
7884 + AuLabel(positive);
7885 + au_update_dbtop(dentry);
7888 + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE)
7889 + && au_dbtop(dentry) < 0)) {
7891 + AuIOErr("both of real entry and whiteout found, %pd, err %d\n",
7897 + au_delayed_kfree(whname.name);
7902 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent)
7904 + struct dentry *dentry;
7907 + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC))
7908 + dentry = vfsub_lkup_one(name, parent);
7910 + struct vfsub_lkup_one_args args = {
7916 + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args);
7917 + if (unlikely(wkq_err))
7918 + dentry = ERR_PTR(wkq_err);
7925 + * lookup @dentry on @bindex which should be negative.
7927 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh)
7930 + struct dentry *parent, *h_parent, *h_dentry;
7931 + struct au_branch *br;
7933 + parent = dget_parent(dentry);
7934 + h_parent = au_h_dptr(parent, bindex);
7935 + br = au_sbr(dentry->d_sb, bindex);
7937 + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name);
7939 + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent);
7940 + err = PTR_ERR(h_dentry);
7941 + if (IS_ERR(h_dentry))
7943 + if (unlikely(d_is_positive(h_dentry))) {
7945 + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex);
7951 + if (bindex < au_dbtop(dentry))
7952 + au_set_dbtop(dentry, bindex);
7953 + if (au_dbbot(dentry) < bindex)
7954 + au_set_dbbot(dentry, bindex);
7955 + au_set_h_dptr(dentry, bindex, h_dentry);
7962 +/* ---------------------------------------------------------------------- */
7964 +/* subset of struct inode */
7966 + unsigned long i_ino;
7967 + /* unsigned int i_nlink; */
7973 + blkcnt_t i_blocks;
7978 +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode)
7980 + ia->i_ino = h_inode->i_ino;
7981 + /* ia->i_nlink = h_inode->i_nlink; */
7982 + ia->i_uid = h_inode->i_uid;
7983 + ia->i_gid = h_inode->i_gid;
7984 + ia->i_version = h_inode->i_version;
7986 + ia->i_size = h_inode->i_size;
7987 + ia->i_blocks = h_inode->i_blocks;
7989 + ia->i_mode = (h_inode->i_mode & S_IFMT);
7992 +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode)
7994 + return ia->i_ino != h_inode->i_ino
7995 + /* || ia->i_nlink != h_inode->i_nlink */
7996 + || !uid_eq(ia->i_uid, h_inode->i_uid)
7997 + || !gid_eq(ia->i_gid, h_inode->i_gid)
7998 + || ia->i_version != h_inode->i_version
8000 + || ia->i_size != h_inode->i_size
8001 + || ia->i_blocks != h_inode->i_blocks
8003 + || ia->i_mode != (h_inode->i_mode & S_IFMT);
8006 +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent,
8007 + struct au_branch *br)
8010 + struct au_iattr ia;
8011 + struct inode *h_inode;
8012 + struct dentry *h_d;
8013 + struct super_block *h_sb;
8016 + memset(&ia, -1, sizeof(ia));
8017 + h_sb = h_dentry->d_sb;
8019 + if (d_is_positive(h_dentry)) {
8020 + h_inode = d_inode(h_dentry);
8021 + au_iattr_save(&ia, h_inode);
8022 + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb))
8023 + /* nfs d_revalidate may return 0 for negative dentry */
8024 + /* fuse d_revalidate always return 0 for negative dentry */
8027 + /* main purpose is namei.c:cached_lookup() and d_revalidate */
8028 + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent);
8029 + err = PTR_ERR(h_d);
8034 + if (unlikely(h_d != h_dentry
8035 + || d_inode(h_d) != h_inode
8036 + || (h_inode && au_iattr_test(&ia, h_inode))))
8037 + err = au_busy_or_stale();
8045 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8046 + struct dentry *h_parent, struct au_branch *br)
8051 + if (udba == AuOpt_UDBA_REVAL
8052 + && !au_test_fs_remote(h_dentry->d_sb)) {
8054 + err = (d_inode(h_dentry->d_parent) != h_dir);
8055 + } else if (udba != AuOpt_UDBA_NONE)
8056 + err = au_h_verify_dentry(h_dentry, h_parent, br);
8061 +/* ---------------------------------------------------------------------- */
8063 +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent)
8066 + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq;
8067 + struct au_hdentry tmp, *p, *q;
8068 + struct au_dinfo *dinfo;
8069 + struct super_block *sb;
8071 + DiMustWriteLock(dentry);
8073 + sb = dentry->d_sb;
8074 + dinfo = au_di(dentry);
8075 + bbot = dinfo->di_bbot;
8076 + bwh = dinfo->di_bwh;
8077 + bdiropq = dinfo->di_bdiropq;
8078 + bindex = dinfo->di_btop;
8079 + p = au_hdentry(dinfo, bindex);
8080 + for (; bindex <= bbot; bindex++, p++) {
8081 + if (!p->hd_dentry)
8084 + new_bindex = au_br_index(sb, p->hd_id);
8085 + if (new_bindex == bindex)
8088 + if (dinfo->di_bwh == bindex)
8090 + if (dinfo->di_bdiropq == bindex)
8091 + bdiropq = new_bindex;
8092 + if (new_bindex < 0) {
8094 + p->hd_dentry = NULL;
8098 + /* swap two lower dentries, and loop again */
8099 + q = au_hdentry(dinfo, new_bindex);
8103 + if (tmp.hd_dentry) {
8109 + dinfo->di_bwh = -1;
8110 + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh))
8111 + dinfo->di_bwh = bwh;
8113 + dinfo->di_bdiropq = -1;
8115 + && bdiropq <= au_sbbot(sb)
8116 + && au_sbr_whable(sb, bdiropq))
8117 + dinfo->di_bdiropq = bdiropq;
8120 + dinfo->di_btop = -1;
8121 + dinfo->di_bbot = -1;
8122 + bbot = au_dbbot(parent);
8124 + p = au_hdentry(dinfo, bindex);
8125 + for (; bindex <= bbot; bindex++, p++)
8126 + if (p->hd_dentry) {
8127 + dinfo->di_btop = bindex;
8131 + if (dinfo->di_btop >= 0) {
8133 + p = au_hdentry(dinfo, bindex);
8134 + for (; bindex >= 0; bindex--, p--)
8135 + if (p->hd_dentry) {
8136 + dinfo->di_bbot = bindex;
8145 +static void au_do_hide(struct dentry *dentry)
8147 + struct inode *inode;
8149 + if (d_really_is_positive(dentry)) {
8150 + inode = d_inode(dentry);
8151 + if (!d_is_dir(dentry)) {
8152 + if (inode->i_nlink && !d_unhashed(dentry))
8153 + drop_nlink(inode);
8155 + clear_nlink(inode);
8156 + /* stop next lookup */
8157 + inode->i_flags |= S_DEAD;
8159 + smp_mb(); /* necessary? */
8164 +static int au_hide_children(struct dentry *parent)
8166 + int err, i, j, ndentry;
8167 + struct au_dcsub_pages dpages;
8168 + struct au_dpage *dpage;
8169 + struct dentry *dentry;
8171 + err = au_dpages_init(&dpages, GFP_NOFS);
8172 + if (unlikely(err))
8174 + err = au_dcsub_pages(&dpages, parent, NULL, NULL);
8175 + if (unlikely(err))
8178 + /* in reverse order */
8179 + for (i = dpages.ndpage - 1; i >= 0; i--) {
8180 + dpage = dpages.dpages + i;
8181 + ndentry = dpage->ndentry;
8182 + for (j = ndentry - 1; j >= 0; j--) {
8183 + dentry = dpage->dentries[j];
8184 + if (dentry != parent)
8185 + au_do_hide(dentry);
8190 + au_dpages_free(&dpages);
8195 +static void au_hide(struct dentry *dentry)
8199 + AuDbgDentry(dentry);
8200 + if (d_is_dir(dentry)) {
8201 + /* shrink_dcache_parent(dentry); */
8202 + err = au_hide_children(dentry);
8203 + if (unlikely(err))
8204 + AuIOErr("%pd, failed hiding children, ignored %d\n",
8207 + au_do_hide(dentry);
8211 + * By adding a dirty branch, a cached dentry may be affected in various ways.
8213 + * a dirty branch is added
8214 + * - on the top of layers
8215 + * - in the middle of layers
8216 + * - to the bottom of layers
8218 + * on the added branch there exists
8221 + * - a same named entry
8223 + * * negative --> positive
8224 + * * positive --> positive
8225 + * - type is unchanged
8226 + * - type is changed
8228 + * * negative --> negative
8229 + * * positive --> negative (rejected by au_br_del() for non-dir case)
8232 +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo,
8233 + struct au_dinfo *tmp)
8236 + aufs_bindex_t bindex, bbot;
8238 + struct dentry *dentry;
8239 + struct inode *inode;
8241 + } orig_h, tmp_h = {
8244 + struct au_hdentry *hd;
8245 + struct inode *inode, *h_inode;
8246 + struct dentry *h_dentry;
8249 + AuDebugOn(dinfo->di_btop < 0);
8251 + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry;
8252 + orig_h.inode = NULL;
8253 + if (d_is_positive(orig_h.dentry)) {
8254 + orig_h.inode = d_inode(orig_h.dentry);
8255 + orig_h.mode = orig_h.inode->i_mode & S_IFMT;
8257 + if (tmp->di_btop >= 0) {
8258 + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry;
8259 + if (d_is_positive(tmp_h.dentry)) {
8260 + tmp_h.inode = d_inode(tmp_h.dentry);
8261 + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT;
8266 + if (d_really_is_positive(dentry))
8267 + inode = d_inode(dentry);
8268 + if (!orig_h.inode) {
8269 + AuDbg("nagative originally\n");
8275 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8276 + AuDebugOn(dinfo->di_bdiropq != -1);
8278 + if (!tmp_h.inode) {
8279 + AuDbg("negative --> negative\n");
8280 + /* should have only one negative lower */
8281 + if (tmp->di_btop >= 0
8282 + && tmp->di_btop < dinfo->di_btop) {
8283 + AuDebugOn(tmp->di_btop != tmp->di_bbot);
8284 + AuDebugOn(dinfo->di_btop != dinfo->di_bbot);
8285 + au_set_h_dptr(dentry, dinfo->di_btop, NULL);
8286 + au_di_cp(dinfo, tmp);
8287 + hd = au_hdentry(tmp, tmp->di_btop);
8288 + au_set_h_dptr(dentry, tmp->di_btop,
8289 + dget(hd->hd_dentry));
8291 + au_dbg_verify_dinode(dentry);
8293 + AuDbg("negative --> positive\n");
8295 + * similar to the behaviour of creating with bypassing
8297 + * unhash it in order to force an error in the
8298 + * succeeding create operation.
8299 + * we should not set S_DEAD here.
8302 + /* au_di_swap(tmp, dinfo); */
8303 + au_dbg_verify_dinode(dentry);
8306 + AuDbg("positive originally\n");
8307 + /* inode may be NULL */
8308 + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode);
8309 + if (!tmp_h.inode) {
8310 + AuDbg("positive --> negative\n");
8311 + /* or bypassing aufs */
8313 + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop)
8314 + dinfo->di_bwh = tmp->di_bwh;
8316 + err = au_refresh_hinode_self(inode);
8317 + au_dbg_verify_dinode(dentry);
8318 + } else if (orig_h.mode == tmp_h.mode) {
8319 + AuDbg("positive --> positive, same type\n");
8320 + if (!S_ISDIR(orig_h.mode)
8321 + && dinfo->di_btop > tmp->di_btop) {
8323 + * similar to the behaviour of removing and
8328 + err = au_refresh_hinode_self(inode);
8329 + au_dbg_verify_dinode(dentry);
8331 + /* fill empty slots */
8332 + if (dinfo->di_btop > tmp->di_btop)
8333 + dinfo->di_btop = tmp->di_btop;
8334 + if (dinfo->di_bbot < tmp->di_bbot)
8335 + dinfo->di_bbot = tmp->di_bbot;
8336 + dinfo->di_bwh = tmp->di_bwh;
8337 + dinfo->di_bdiropq = tmp->di_bdiropq;
8338 + bbot = dinfo->di_bbot;
8339 + bindex = tmp->di_btop;
8340 + hd = au_hdentry(tmp, bindex);
8341 + for (; bindex <= bbot; bindex++, hd++) {
8342 + if (au_h_dptr(dentry, bindex))
8344 + h_dentry = hd->hd_dentry;
8347 + AuDebugOn(d_is_negative(h_dentry));
8348 + h_inode = d_inode(h_dentry);
8349 + AuDebugOn(orig_h.mode
8350 + != (h_inode->i_mode
8352 + au_set_h_dptr(dentry, bindex,
8356 + err = au_refresh_hinode(inode, dentry);
8357 + au_dbg_verify_dinode(dentry);
8360 + AuDbg("positive --> positive, different type\n");
8361 + /* similar to the behaviour of removing and creating */
8364 + err = au_refresh_hinode_self(inode);
8365 + au_dbg_verify_dinode(dentry);
8373 +void au_refresh_dop(struct dentry *dentry, int force_reval)
8375 + const struct dentry_operations *dop
8376 + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op;
8377 + static const unsigned int mask
8378 + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE;
8380 + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags));
8382 + if (dentry->d_op == dop)
8385 + AuDbg("%pd\n", dentry);
8386 + spin_lock(&dentry->d_lock);
8387 + if (dop == &aufs_dop)
8388 + dentry->d_flags |= mask;
8390 + dentry->d_flags &= ~mask;
8391 + dentry->d_op = dop;
8392 + spin_unlock(&dentry->d_lock);
8395 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent)
8397 + int err, ebrange, nbr;
8398 + unsigned int sigen;
8399 + struct au_dinfo *dinfo, *tmp;
8400 + struct super_block *sb;
8401 + struct inode *inode;
8403 + DiMustWriteLock(dentry);
8404 + AuDebugOn(IS_ROOT(dentry));
8405 + AuDebugOn(d_really_is_negative(parent));
8407 + sb = dentry->d_sb;
8408 + sigen = au_sigen(sb);
8409 + err = au_digen_test(parent, sigen);
8410 + if (unlikely(err))
8413 + nbr = au_sbbot(sb) + 1;
8414 + dinfo = au_di(dentry);
8415 + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0);
8416 + if (unlikely(err))
8418 + ebrange = au_dbrange_test(dentry);
8420 + ebrange = au_do_refresh_hdentry(dentry, parent);
8422 + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) {
8423 + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0);
8424 + if (d_really_is_positive(dentry)) {
8425 + inode = d_inode(dentry);
8426 + err = au_refresh_hinode_self(inode);
8428 + au_dbg_verify_dinode(dentry);
8430 + goto out_dgen; /* success */
8434 + /* temporary dinfo */
8435 + AuDbgDentry(dentry);
8437 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
8438 + if (unlikely(!tmp))
8440 + au_di_swap(tmp, dinfo);
8441 + /* returns the number of positive dentries */
8443 + * if current working dir is removed, it returns an error.
8444 + * but the dentry is legal.
8446 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
8447 + AuDbgDentry(dentry);
8448 + au_di_swap(tmp, dinfo);
8449 + if (err == -ENOENT)
8452 + /* compare/refresh by dinfo */
8453 + AuDbgDentry(dentry);
8454 + err = au_refresh_by_dinfo(dentry, dinfo, tmp);
8455 + au_dbg_verify_dinode(dentry);
8458 + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */
8459 + au_rw_write_unlock(&tmp->di_rwsem);
8461 + if (unlikely(err))
8465 + au_update_digen(dentry);
8467 + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) {
8468 + AuIOErr("failed refreshing %pd, %d\n", dentry, err);
8469 + AuDbgDentry(dentry);
8475 +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags,
8476 + struct dentry *dentry, aufs_bindex_t bindex)
8481 + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE))
8484 + AuDbg("b%d\n", bindex);
8486 + * gave up supporting LOOKUP_CREATE/OPEN for lower fs,
8487 + * due to whiteout and branch permission.
8489 + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE
8490 + | LOOKUP_FOLLOW | LOOKUP_EXCL);
8491 + /* it may return tri-state */
8492 + valid = h_dentry->d_op->d_revalidate(h_dentry, flags);
8494 + if (unlikely(valid < 0))
8504 +/* todo: remove this */
8505 +static int h_d_revalidate(struct dentry *dentry, struct inode *inode,
8506 + unsigned int flags, int do_udba)
8509 + umode_t mode, h_mode;
8510 + aufs_bindex_t bindex, btail, btop, ibs, ibe;
8511 + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile;
8512 + struct inode *h_inode, *h_cached_inode;
8513 + struct dentry *h_dentry;
8514 + struct qstr *name, *h_name;
8521 + unhashed = !!d_unhashed(dentry);
8522 + is_root = !!IS_ROOT(dentry);
8523 + name = &dentry->d_name;
8524 + tmpfile = au_di(dentry)->di_tmpfile;
8527 + * Theoretically, REVAL test should be unnecessary in case of
8529 + * But {fs,i}notify doesn't fire some necessary events,
8530 + * IN_ATTRIB for atime/nlink/pageio
8531 + * Let's do REVAL test too.
8533 + if (do_udba && inode) {
8534 + mode = (inode->i_mode & S_IFMT);
8535 + plus = (inode->i_nlink > 0);
8536 + ibs = au_ibtop(inode);
8537 + ibe = au_ibbot(inode);
8540 + btop = au_dbtop(dentry);
8542 + if (inode && S_ISDIR(inode->i_mode))
8543 + btail = au_dbtaildir(dentry);
8544 + for (bindex = btop; bindex <= btail; bindex++) {
8545 + h_dentry = au_h_dptr(dentry, bindex);
8549 + AuDbg("b%d, %pd\n", bindex, h_dentry);
8550 + h_nfs = !!au_test_nfs(h_dentry->d_sb);
8551 + spin_lock(&h_dentry->d_lock);
8552 + h_name = &h_dentry->d_name;
8553 + if (unlikely(do_udba
8556 + && (unhashed != !!d_unhashed(h_dentry)
8558 + && !au_qstreq(name, h_name))
8561 + && !(flags & LOOKUP_OPEN)
8562 + && (h_dentry->d_flags
8563 + & DCACHE_NFSFS_RENAMED)))
8567 + h_unhashed = d_unhashed(h_dentry);
8568 + spin_unlock(&h_dentry->d_lock);
8569 + AuDbg("unhash 0x%x 0x%x, %pd %pd\n",
8570 + unhashed, h_unhashed, dentry, h_dentry);
8573 + spin_unlock(&h_dentry->d_lock);
8575 + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex);
8576 + if (unlikely(err))
8577 + /* do not goto err, to keep the errno */
8580 + /* todo: plink too? */
8585 + if (unlikely(!!inode != d_is_positive(h_dentry)))
8589 + if (d_is_positive(h_dentry))
8590 + h_inode = d_inode(h_dentry);
8593 + h_cached_inode = h_inode;
8595 + h_mode = (h_inode->i_mode & S_IFMT);
8596 + h_plus = (h_inode->i_nlink > 0);
8598 + if (inode && ibs <= bindex && bindex <= ibe)
8599 + h_cached_inode = au_h_iptr(inode, bindex);
8602 + if (unlikely(plus != h_plus && !tmpfile))
8605 + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED)
8607 + && !IS_ROOT(h_dentry)
8608 + && unhashed != d_unhashed(h_dentry)))
8611 + if (unlikely(mode != h_mode
8612 + || h_cached_inode != h_inode))
8625 +/* todo: consolidate with do_refresh() and au_reval_for_attr() */
8626 +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen)
8629 + struct dentry *parent;
8631 + if (!au_digen_test(dentry, sigen))
8634 + parent = dget_parent(dentry);
8635 + di_read_lock_parent(parent, AuLock_IR);
8636 + AuDebugOn(au_digen_test(parent, sigen));
8637 + au_dbg_verify_gen(parent, sigen);
8638 + err = au_refresh_dentry(dentry, parent);
8639 + di_read_unlock(parent, AuLock_IR);
8645 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen)
8648 + struct dentry *d, *parent;
8650 + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR))
8651 + return simple_reval_dpath(dentry, sigen);
8653 + /* slow loop, keep it simple and stupid */
8654 + /* cf: au_cpup_dirs() */
8657 + while (au_digen_test(dentry, sigen)) {
8661 + parent = dget_parent(d);
8662 + if (!au_digen_test(parent, sigen))
8668 + di_write_lock_child2(d);
8670 + /* someone might update our dentry while we were sleeping */
8671 + if (au_digen_test(d, sigen)) {
8673 + * todo: consolidate with simple_reval_dpath(),
8674 + * do_refresh() and au_reval_for_attr().
8676 + di_read_lock_parent(parent, AuLock_IR);
8677 + err = au_refresh_dentry(d, parent);
8678 + di_read_unlock(parent, AuLock_IR);
8682 + di_write_unlock(d);
8684 + if (unlikely(err))
8692 + * if valid returns 1, otherwise 0.
8694 +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags)
8697 + unsigned int sigen;
8698 + unsigned char do_udba;
8699 + struct super_block *sb;
8700 + struct inode *inode;
8702 + /* todo: support rcu-walk? */
8703 + if (flags & LOOKUP_RCU)
8707 + if (unlikely(!au_di(dentry)))
8711 + sb = dentry->d_sb;
8714 + * i_mutex of parent dir may be held,
8715 + * but we should not return 'invalid' due to busy.
8717 + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM);
8718 + if (unlikely(err)) {
8724 + if (d_really_is_positive(dentry))
8725 + inode = d_inode(dentry);
8726 + if (unlikely(inode && au_is_bad_inode(inode))) {
8731 + if (unlikely(au_dbrange_test(dentry))) {
8737 + sigen = au_sigen(sb);
8738 + if (au_digen_test(dentry, sigen)) {
8739 + AuDebugOn(IS_ROOT(dentry));
8740 + err = au_reval_dpath(dentry, sigen);
8741 + if (unlikely(err)) {
8746 + di_downgrade_lock(dentry, AuLock_IR);
8749 + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY))
8751 + && !(inode->i_state && I_LINKABLE)
8752 + && (IS_DEADDIR(inode) || !inode->i_nlink)) {
8757 + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE);
8758 + if (do_udba && inode) {
8759 + aufs_bindex_t btop = au_ibtop(inode);
8760 + struct inode *h_inode;
8763 + h_inode = au_h_iptr(inode, btop);
8764 + if (h_inode && au_test_higen(inode, h_inode)) {
8771 + err = h_d_revalidate(dentry, inode, flags, do_udba);
8772 + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) {
8774 + AuDbg("both of real entry and whiteout found, %p, err %d\n",
8780 + di_downgrade_lock(dentry, AuLock_IR);
8782 + aufs_read_unlock(dentry, AuLock_IR);
8787 + AuDbg("%pd invalid, %d\n", dentry, valid);
8793 +static void aufs_d_release(struct dentry *dentry)
8795 + if (au_di(dentry)) {
8796 + au_di_fin(dentry);
8797 + au_hn_di_reinit(dentry);
8801 +const struct dentry_operations aufs_dop = {
8802 + .d_revalidate = aufs_d_revalidate,
8803 + .d_weak_revalidate = aufs_d_revalidate,
8804 + .d_release = aufs_d_release
8807 +/* aufs_dop without d_revalidate */
8808 +const struct dentry_operations aufs_dop_noreval = {
8809 + .d_release = aufs_d_release
8811 diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h
8812 --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100
8813 +++ linux/fs/aufs/dentry.h 2016-10-09 16:55:38.889431135 +0200
8816 + * Copyright (C) 2005-2016 Junjiro R. Okajima
8818 + * This program, aufs is free software; you can redistribute it and/or modify
8819 + * it under the terms of the GNU General Public License as published by
8820 + * the Free Software Foundation; either version 2 of the License, or
8821 + * (at your option) any later version.
8823 + * This program is distributed in the hope that it will be useful,
8824 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8825 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8826 + * GNU General Public License for more details.
8828 + * You should have received a copy of the GNU General Public License
8829 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
8833 + * lookup and dentry operations
8836 +#ifndef __AUFS_DENTRY_H__
8837 +#define __AUFS_DENTRY_H__
8841 +#include <linux/dcache.h>
8844 +struct au_hdentry {
8845 + struct dentry *hd_dentry;
8846 + aufs_bindex_t hd_id;
8850 + atomic_t di_generation;
8852 + struct au_rwsem di_rwsem;
8853 + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq;
8854 + unsigned char di_tmpfile; /* to allow the different name */
8856 + struct au_hdentry *di_hdentry;
8857 + struct llist_node di_lnode; /* delayed free */
8859 +} ____cacheline_aligned_in_smp;
8861 +/* ---------------------------------------------------------------------- */
8863 +/* flags for au_lkup_dentry() */
8864 +#define AuLkup_ALLOW_NEG 1
8865 +#define AuLkup_IGNORE_PERM (1 << 1)
8866 +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name)
8867 +#define au_fset_lkup(flags, name) \
8868 + do { (flags) |= AuLkup_##name; } while (0)
8869 +#define au_fclr_lkup(flags, name) \
8870 + do { (flags) &= ~AuLkup_##name; } while (0)
8872 +/* ---------------------------------------------------------------------- */
8875 +extern const struct dentry_operations aufs_dop, aufs_dop_noreval;
8877 +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent);
8878 +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir,
8879 + struct dentry *h_parent, struct au_branch *br);
8881 +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop,
8882 + unsigned int flags);
8883 +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh);
8884 +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent);
8885 +int au_reval_dpath(struct dentry *dentry, unsigned int sigen);
8886 +void au_refresh_dop(struct dentry *dentry, int force_reval);
8889 +void au_di_init_once(void *_di);
8890 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc);
8891 +void au_di_free(struct au_dinfo *dinfo);
8892 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b);
8893 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src);
8894 +int au_di_init(struct dentry *dentry);
8895 +void au_di_fin(struct dentry *dentry);
8896 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink);
8898 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc);
8899 +void di_read_unlock(struct dentry *d, int flags);
8900 +void di_downgrade_lock(struct dentry *d, int flags);
8901 +void di_write_lock(struct dentry *d, unsigned int lsc);
8902 +void di_write_unlock(struct dentry *d);
8903 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir);
8904 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir);
8905 +void di_write_unlock2(struct dentry *d1, struct dentry *d2);
8907 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex);
8908 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex);
8909 +aufs_bindex_t au_dbtail(struct dentry *dentry);
8910 +aufs_bindex_t au_dbtaildir(struct dentry *dentry);
8912 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
8913 + struct dentry *h_dentry);
8914 +int au_digen_test(struct dentry *dentry, unsigned int sigen);
8915 +int au_dbrange_test(struct dentry *dentry);
8916 +void au_update_digen(struct dentry *dentry);
8917 +void au_update_dbrange(struct dentry *dentry, int do_put_zero);
8918 +void au_update_dbtop(struct dentry *dentry);
8919 +void au_update_dbbot(struct dentry *dentry);
8920 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry);
8922 +/* ---------------------------------------------------------------------- */
8924 +static inline struct au_dinfo *au_di(struct dentry *dentry)
8926 + return dentry->d_fsdata;
8929 +/* ---------------------------------------------------------------------- */
8931 +/* lock subclass for dinfo */
8933 + AuLsc_DI_CHILD, /* child first */
8934 + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */
8935 + AuLsc_DI_CHILD3, /* copyup dirs */
8939 + AuLsc_DI_TMP /* temp for replacing dinfo */
8943 + * di_read_lock_child, di_write_lock_child,
8944 + * di_read_lock_child2, di_write_lock_child2,
8945 + * di_read_lock_child3, di_write_lock_child3,
8946 + * di_read_lock_parent, di_write_lock_parent,
8947 + * di_read_lock_parent2, di_write_lock_parent2,
8948 + * di_read_lock_parent3, di_write_lock_parent3,
8950 +#define AuReadLockFunc(name, lsc) \
8951 +static inline void di_read_lock_##name(struct dentry *d, int flags) \
8952 +{ di_read_lock(d, flags, AuLsc_DI_##lsc); }
8954 +#define AuWriteLockFunc(name, lsc) \
8955 +static inline void di_write_lock_##name(struct dentry *d) \
8956 +{ di_write_lock(d, AuLsc_DI_##lsc); }
8958 +#define AuRWLockFuncs(name, lsc) \
8959 + AuReadLockFunc(name, lsc) \
8960 + AuWriteLockFunc(name, lsc)
8962 +AuRWLockFuncs(child, CHILD);
8963 +AuRWLockFuncs(child2, CHILD2);
8964 +AuRWLockFuncs(child3, CHILD3);
8965 +AuRWLockFuncs(parent, PARENT);
8966 +AuRWLockFuncs(parent2, PARENT2);
8967 +AuRWLockFuncs(parent3, PARENT3);
8969 +#undef AuReadLockFunc
8970 +#undef AuWriteLockFunc
8971 +#undef AuRWLockFuncs
8973 +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem)
8974 +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem)
8975 +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem)
8977 +/* ---------------------------------------------------------------------- */
8979 +/* todo: memory barrier? */
8980 +static inline unsigned int au_digen(struct dentry *d)
8982 + return atomic_read(&au_di(d)->di_generation);
8985 +static inline void au_h_dentry_init(struct au_hdentry *hdentry)
8987 + hdentry->hd_dentry = NULL;
8990 +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di,
8991 + aufs_bindex_t bindex)
8993 + return di->di_hdentry + bindex;
8996 +static inline void au_hdput(struct au_hdentry *hd)
8999 + dput(hd->hd_dentry);
9002 +static inline aufs_bindex_t au_dbtop(struct dentry *dentry)
9004 + DiMustAnyLock(dentry);
9005 + return au_di(dentry)->di_btop;
9008 +static inline aufs_bindex_t au_dbbot(struct dentry *dentry)
9010 + DiMustAnyLock(dentry);
9011 + return au_di(dentry)->di_bbot;
9014 +static inline aufs_bindex_t au_dbwh(struct dentry *dentry)
9016 + DiMustAnyLock(dentry);
9017 + return au_di(dentry)->di_bwh;
9020 +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry)
9022 + DiMustAnyLock(dentry);
9023 + return au_di(dentry)->di_bdiropq;
9026 +/* todo: hard/soft set? */
9027 +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex)
9029 + DiMustWriteLock(dentry);
9030 + au_di(dentry)->di_btop = bindex;
9033 +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex)
9035 + DiMustWriteLock(dentry);
9036 + au_di(dentry)->di_bbot = bindex;
9039 +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex)
9041 + DiMustWriteLock(dentry);
9042 + /* dbwh can be outside of btop - bbot range */
9043 + au_di(dentry)->di_bwh = bindex;
9046 +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex)
9048 + DiMustWriteLock(dentry);
9049 + au_di(dentry)->di_bdiropq = bindex;
9052 +/* ---------------------------------------------------------------------- */
9054 +#ifdef CONFIG_AUFS_HNOTIFY
9055 +static inline void au_digen_dec(struct dentry *d)
9057 + atomic_dec(&au_di(d)->di_generation);
9060 +static inline void au_hn_di_reinit(struct dentry *dentry)
9062 + dentry->d_fsdata = NULL;
9065 +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused)
9066 +#endif /* CONFIG_AUFS_HNOTIFY */
9068 +#endif /* __KERNEL__ */
9069 +#endif /* __AUFS_DENTRY_H__ */
9070 diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c
9071 --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100
9072 +++ linux/fs/aufs/dinfo.c 2016-10-09 16:55:38.889431135 +0200
9075 + * Copyright (C) 2005-2016 Junjiro R. Okajima
9077 + * This program, aufs is free software; you can redistribute it and/or modify
9078 + * it under the terms of the GNU General Public License as published by
9079 + * the Free Software Foundation; either version 2 of the License, or
9080 + * (at your option) any later version.
9082 + * This program is distributed in the hope that it will be useful,
9083 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9084 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9085 + * GNU General Public License for more details.
9087 + * You should have received a copy of the GNU General Public License
9088 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9092 + * dentry private data
9097 +void au_di_init_once(void *_dinfo)
9099 + struct au_dinfo *dinfo = _dinfo;
9101 + au_rw_init(&dinfo->di_rwsem);
9104 +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc)
9106 + struct au_dinfo *dinfo;
9109 + dinfo = au_cache_alloc_dinfo();
9110 + if (unlikely(!dinfo))
9113 + nbr = au_sbbot(sb) + 1;
9116 + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS);
9117 + if (dinfo->di_hdentry) {
9118 + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc);
9119 + dinfo->di_btop = -1;
9120 + dinfo->di_bbot = -1;
9121 + dinfo->di_bwh = -1;
9122 + dinfo->di_bdiropq = -1;
9123 + dinfo->di_tmpfile = 0;
9124 + for (i = 0; i < nbr; i++)
9125 + dinfo->di_hdentry[i].hd_id = -1;
9129 + au_cache_dfree_dinfo(dinfo);
9136 +void au_di_free(struct au_dinfo *dinfo)
9138 + struct au_hdentry *p;
9139 + aufs_bindex_t bbot, bindex;
9141 + /* dentry may not be revalidated */
9142 + bindex = dinfo->di_btop;
9143 + if (bindex >= 0) {
9144 + bbot = dinfo->di_bbot;
9145 + p = au_hdentry(dinfo, bindex);
9146 + while (bindex++ <= bbot)
9149 + au_delayed_kfree(dinfo->di_hdentry);
9150 + au_cache_dfree_dinfo(dinfo);
9153 +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b)
9155 + struct au_hdentry *p;
9158 + AuRwMustWriteLock(&a->di_rwsem);
9159 + AuRwMustWriteLock(&b->di_rwsem);
9161 +#define DiSwap(v, name) \
9163 + v = a->di_##name; \
9164 + a->di_##name = b->di_##name; \
9165 + b->di_##name = v; \
9168 + DiSwap(p, hdentry);
9172 + DiSwap(bi, bdiropq);
9178 +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src)
9180 + AuRwMustWriteLock(&dst->di_rwsem);
9181 + AuRwMustWriteLock(&src->di_rwsem);
9183 + dst->di_btop = src->di_btop;
9184 + dst->di_bbot = src->di_bbot;
9185 + dst->di_bwh = src->di_bwh;
9186 + dst->di_bdiropq = src->di_bdiropq;
9190 +int au_di_init(struct dentry *dentry)
9193 + struct super_block *sb;
9194 + struct au_dinfo *dinfo;
9197 + sb = dentry->d_sb;
9198 + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD);
9200 + atomic_set(&dinfo->di_generation, au_sigen(sb));
9201 + /* smp_mb(); */ /* atomic_set */
9202 + dentry->d_fsdata = dinfo;
9209 +void au_di_fin(struct dentry *dentry)
9211 + struct au_dinfo *dinfo;
9213 + dinfo = au_di(dentry);
9214 + AuRwDestroy(&dinfo->di_rwsem);
9215 + au_di_free(dinfo);
9218 +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink)
9221 + struct au_hdentry *hdp;
9223 + AuRwMustWriteLock(&dinfo->di_rwsem);
9226 + sz = sizeof(*hdp) * (dinfo->di_bbot + 1);
9228 + sz = sizeof(*hdp);
9229 + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS,
9232 + dinfo->di_hdentry = hdp;
9239 +/* ---------------------------------------------------------------------- */
9241 +static void do_ii_write_lock(struct inode *inode, unsigned int lsc)
9244 + case AuLsc_DI_CHILD:
9245 + ii_write_lock_child(inode);
9247 + case AuLsc_DI_CHILD2:
9248 + ii_write_lock_child2(inode);
9250 + case AuLsc_DI_CHILD3:
9251 + ii_write_lock_child3(inode);
9253 + case AuLsc_DI_PARENT:
9254 + ii_write_lock_parent(inode);
9256 + case AuLsc_DI_PARENT2:
9257 + ii_write_lock_parent2(inode);
9259 + case AuLsc_DI_PARENT3:
9260 + ii_write_lock_parent3(inode);
9267 +static void do_ii_read_lock(struct inode *inode, unsigned int lsc)
9270 + case AuLsc_DI_CHILD:
9271 + ii_read_lock_child(inode);
9273 + case AuLsc_DI_CHILD2:
9274 + ii_read_lock_child2(inode);
9276 + case AuLsc_DI_CHILD3:
9277 + ii_read_lock_child3(inode);
9279 + case AuLsc_DI_PARENT:
9280 + ii_read_lock_parent(inode);
9282 + case AuLsc_DI_PARENT2:
9283 + ii_read_lock_parent2(inode);
9285 + case AuLsc_DI_PARENT3:
9286 + ii_read_lock_parent3(inode);
9293 +void di_read_lock(struct dentry *d, int flags, unsigned int lsc)
9295 + struct inode *inode;
9297 + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc);
9298 + if (d_really_is_positive(d)) {
9299 + inode = d_inode(d);
9300 + if (au_ftest_lock(flags, IW))
9301 + do_ii_write_lock(inode, lsc);
9302 + else if (au_ftest_lock(flags, IR))
9303 + do_ii_read_lock(inode, lsc);
9307 +void di_read_unlock(struct dentry *d, int flags)
9309 + struct inode *inode;
9311 + if (d_really_is_positive(d)) {
9312 + inode = d_inode(d);
9313 + if (au_ftest_lock(flags, IW)) {
9314 + au_dbg_verify_dinode(d);
9315 + ii_write_unlock(inode);
9316 + } else if (au_ftest_lock(flags, IR)) {
9317 + au_dbg_verify_dinode(d);
9318 + ii_read_unlock(inode);
9321 + au_rw_read_unlock(&au_di(d)->di_rwsem);
9324 +void di_downgrade_lock(struct dentry *d, int flags)
9326 + if (d_really_is_positive(d) && au_ftest_lock(flags, IR))
9327 + ii_downgrade_lock(d_inode(d));
9328 + au_rw_dgrade_lock(&au_di(d)->di_rwsem);
9331 +void di_write_lock(struct dentry *d, unsigned int lsc)
9333 + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc);
9334 + if (d_really_is_positive(d))
9335 + do_ii_write_lock(d_inode(d), lsc);
9338 +void di_write_unlock(struct dentry *d)
9340 + au_dbg_verify_dinode(d);
9341 + if (d_really_is_positive(d))
9342 + ii_write_unlock(d_inode(d));
9343 + au_rw_write_unlock(&au_di(d)->di_rwsem);
9346 +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir)
9348 + AuDebugOn(d1 == d2
9349 + || d_inode(d1) == d_inode(d2)
9350 + || d1->d_sb != d2->d_sb);
9352 + if (isdir && au_test_subdir(d1, d2)) {
9353 + di_write_lock_child(d1);
9354 + di_write_lock_child2(d2);
9356 + /* there should be no races */
9357 + di_write_lock_child(d2);
9358 + di_write_lock_child2(d1);
9362 +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir)
9364 + AuDebugOn(d1 == d2
9365 + || d_inode(d1) == d_inode(d2)
9366 + || d1->d_sb != d2->d_sb);
9368 + if (isdir && au_test_subdir(d1, d2)) {
9369 + di_write_lock_parent(d1);
9370 + di_write_lock_parent2(d2);
9372 + /* there should be no races */
9373 + di_write_lock_parent(d2);
9374 + di_write_lock_parent2(d1);
9378 +void di_write_unlock2(struct dentry *d1, struct dentry *d2)
9380 + di_write_unlock(d1);
9381 + if (d_inode(d1) == d_inode(d2))
9382 + au_rw_write_unlock(&au_di(d2)->di_rwsem);
9384 + di_write_unlock(d2);
9387 +/* ---------------------------------------------------------------------- */
9389 +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex)
9393 + DiMustAnyLock(dentry);
9395 + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry))
9397 + AuDebugOn(bindex < 0);
9398 + d = au_hdentry(au_di(dentry), bindex)->hd_dentry;
9399 + AuDebugOn(d && au_dcount(d) <= 0);
9404 + * extended version of au_h_dptr().
9405 + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or
9408 +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex)
9410 + struct dentry *h_dentry;
9411 + struct inode *inode, *h_inode;
9413 + AuDebugOn(d_really_is_negative(dentry));
9416 + if (au_dbtop(dentry) <= bindex
9417 + && bindex <= au_dbbot(dentry))
9418 + h_dentry = au_h_dptr(dentry, bindex);
9419 + if (h_dentry && !au_d_linkable(h_dentry)) {
9421 + goto out; /* success */
9424 + inode = d_inode(dentry);
9425 + AuDebugOn(bindex < au_ibtop(inode));
9426 + AuDebugOn(au_ibbot(inode) < bindex);
9427 + h_inode = au_h_iptr(inode, bindex);
9428 + h_dentry = d_find_alias(h_inode);
9430 + if (!IS_ERR(h_dentry)) {
9431 + if (!au_d_linkable(h_dentry))
9432 + goto out; /* success */
9438 + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) {
9439 + h_dentry = au_plink_lkup(inode, bindex);
9440 + AuDebugOn(!h_dentry);
9441 + if (!IS_ERR(h_dentry)) {
9442 + if (!au_d_hashed_positive(h_dentry))
9443 + goto out; /* success */
9450 + AuDbgDentry(h_dentry);
9454 +aufs_bindex_t au_dbtail(struct dentry *dentry)
9456 + aufs_bindex_t bbot, bwh;
9458 + bbot = au_dbbot(dentry);
9460 + bwh = au_dbwh(dentry);
9463 + if (0 < bwh && bwh < bbot)
9469 +aufs_bindex_t au_dbtaildir(struct dentry *dentry)
9471 + aufs_bindex_t bbot, bopq;
9473 + bbot = au_dbtail(dentry);
9475 + bopq = au_dbdiropq(dentry);
9476 + if (0 <= bopq && bopq < bbot)
9482 +/* ---------------------------------------------------------------------- */
9484 +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex,
9485 + struct dentry *h_dentry)
9487 + struct au_dinfo *dinfo;
9488 + struct au_hdentry *hd;
9489 + struct au_branch *br;
9491 + DiMustWriteLock(dentry);
9493 + dinfo = au_di(dentry);
9494 + hd = au_hdentry(dinfo, bindex);
9496 + hd->hd_dentry = h_dentry;
9498 + br = au_sbr(dentry->d_sb, bindex);
9499 + hd->hd_id = br->br_id;
9503 +int au_dbrange_test(struct dentry *dentry)
9506 + aufs_bindex_t btop, bbot;
9509 + btop = au_dbtop(dentry);
9510 + bbot = au_dbbot(dentry);
9512 + AuDebugOn(bbot < 0 && btop > bbot);
9515 + AuDebugOn(bbot >= 0);
9521 +int au_digen_test(struct dentry *dentry, unsigned int sigen)
9526 + if (unlikely(au_digen(dentry) != sigen
9527 + || au_iigen_test(d_inode(dentry), sigen)))
9533 +void au_update_digen(struct dentry *dentry)
9535 + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb));
9536 + /* smp_mb(); */ /* atomic_set */
9539 +void au_update_dbrange(struct dentry *dentry, int do_put_zero)
9541 + struct au_dinfo *dinfo;
9542 + struct dentry *h_d;
9543 + struct au_hdentry *hdp;
9544 + aufs_bindex_t bindex, bbot;
9546 + DiMustWriteLock(dentry);
9548 + dinfo = au_di(dentry);
9549 + if (!dinfo || dinfo->di_btop < 0)
9552 + if (do_put_zero) {
9553 + bbot = dinfo->di_bbot;
9554 + bindex = dinfo->di_btop;
9555 + hdp = au_hdentry(dinfo, bindex);
9556 + for (; bindex <= bbot; bindex++, hdp++) {
9557 + h_d = hdp->hd_dentry;
9558 + if (h_d && d_is_negative(h_d))
9559 + au_set_h_dptr(dentry, bindex, NULL);
9563 + dinfo->di_btop = 0;
9564 + hdp = au_hdentry(dinfo, dinfo->di_btop);
9565 + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++)
9566 + if (hdp->hd_dentry)
9568 + if (dinfo->di_btop > dinfo->di_bbot) {
9569 + dinfo->di_btop = -1;
9570 + dinfo->di_bbot = -1;
9574 + hdp = au_hdentry(dinfo, dinfo->di_bbot);
9575 + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--)
9576 + if (hdp->hd_dentry)
9578 + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0);
9581 +void au_update_dbtop(struct dentry *dentry)
9583 + aufs_bindex_t bindex, bbot;
9584 + struct dentry *h_dentry;
9586 + bbot = au_dbbot(dentry);
9587 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
9588 + h_dentry = au_h_dptr(dentry, bindex);
9591 + if (d_is_positive(h_dentry)) {
9592 + au_set_dbtop(dentry, bindex);
9595 + au_set_h_dptr(dentry, bindex, NULL);
9599 +void au_update_dbbot(struct dentry *dentry)
9601 + aufs_bindex_t bindex, btop;
9602 + struct dentry *h_dentry;
9604 + btop = au_dbtop(dentry);
9605 + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) {
9606 + h_dentry = au_h_dptr(dentry, bindex);
9609 + if (d_is_positive(h_dentry)) {
9610 + au_set_dbbot(dentry, bindex);
9613 + au_set_h_dptr(dentry, bindex, NULL);
9617 +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry)
9619 + aufs_bindex_t bindex, bbot;
9621 + bbot = au_dbbot(dentry);
9622 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++)
9623 + if (au_h_dptr(dentry, bindex) == h_dentry)
9627 diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c
9628 --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100
9629 +++ linux/fs/aufs/dir.c 2016-10-09 16:55:36.489368218 +0200
9632 + * Copyright (C) 2005-2016 Junjiro R. Okajima
9634 + * This program, aufs is free software; you can redistribute it and/or modify
9635 + * it under the terms of the GNU General Public License as published by
9636 + * the Free Software Foundation; either version 2 of the License, or
9637 + * (at your option) any later version.
9639 + * This program is distributed in the hope that it will be useful,
9640 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
9641 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9642 + * GNU General Public License for more details.
9644 + * You should have received a copy of the GNU General Public License
9645 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
9649 + * directory operations
9652 +#include <linux/fs_stack.h>
9655 +void au_add_nlink(struct inode *dir, struct inode *h_dir)
9657 + unsigned int nlink;
9659 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9661 + nlink = dir->i_nlink;
9662 + nlink += h_dir->i_nlink - 2;
9663 + if (h_dir->i_nlink < 2)
9665 + smp_mb(); /* for i_nlink */
9666 + /* 0 can happen in revaliding */
9667 + set_nlink(dir, nlink);
9670 +void au_sub_nlink(struct inode *dir, struct inode *h_dir)
9672 + unsigned int nlink;
9674 + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode));
9676 + nlink = dir->i_nlink;
9677 + nlink -= h_dir->i_nlink - 2;
9678 + if (h_dir->i_nlink < 2)
9680 + smp_mb(); /* for i_nlink */
9681 + /* nlink == 0 means the branch-fs is broken */
9682 + set_nlink(dir, nlink);
9685 +loff_t au_dir_size(struct file *file, struct dentry *dentry)
9688 + aufs_bindex_t bindex, bbot;
9689 + struct file *h_file;
9690 + struct dentry *h_dentry;
9694 + AuDebugOn(!d_is_dir(file->f_path.dentry));
9696 + bbot = au_fbbot_dir(file);
9697 + for (bindex = au_fbtop(file);
9698 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9700 + h_file = au_hf_dir(file, bindex);
9701 + if (h_file && file_inode(h_file))
9702 + sz += vfsub_f_size_read(h_file);
9705 + AuDebugOn(!dentry);
9706 + AuDebugOn(!d_is_dir(dentry));
9708 + bbot = au_dbtaildir(dentry);
9709 + for (bindex = au_dbtop(dentry);
9710 + bindex <= bbot && sz < KMALLOC_MAX_SIZE;
9712 + h_dentry = au_h_dptr(dentry, bindex);
9713 + if (h_dentry && d_is_positive(h_dentry))
9714 + sz += i_size_read(d_inode(h_dentry));
9717 + if (sz < KMALLOC_MAX_SIZE)
9718 + sz = roundup_pow_of_two(sz);
9719 + if (sz > KMALLOC_MAX_SIZE)
9720 + sz = KMALLOC_MAX_SIZE;
9721 + else if (sz < NAME_MAX) {
9722 + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX);
9723 + sz = AUFS_RDBLK_DEF;
9728 +struct au_dir_ts_arg {
9729 + struct dentry *dentry;
9730 + aufs_bindex_t brid;
9733 +static void au_do_dir_ts(void *arg)
9735 + struct au_dir_ts_arg *a = arg;
9736 + struct au_dtime dt;
9737 + struct path h_path;
9738 + struct inode *dir, *h_dir;
9739 + struct super_block *sb;
9740 + struct au_branch *br;
9741 + struct au_hinode *hdir;
9743 + aufs_bindex_t btop, bindex;
9745 + sb = a->dentry->d_sb;
9746 + if (d_really_is_negative(a->dentry))
9748 + /* no dir->i_mutex lock */
9749 + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */
9751 + dir = d_inode(a->dentry);
9752 + btop = au_ibtop(dir);
9753 + bindex = au_br_index(sb, a->brid);
9754 + if (bindex < btop)
9757 + br = au_sbr(sb, bindex);
9758 + h_path.dentry = au_h_dptr(a->dentry, bindex);
9759 + if (!h_path.dentry)
9761 + h_path.mnt = au_br_mnt(br);
9762 + au_dtime_store(&dt, a->dentry, &h_path);
9764 + br = au_sbr(sb, btop);
9765 + if (!au_br_writable(br->br_perm))
9767 + h_path.dentry = au_h_dptr(a->dentry, btop);
9768 + h_path.mnt = au_br_mnt(br);
9769 + err = vfsub_mnt_want_write(h_path.mnt);
9772 + hdir = au_hi(dir, btop);
9773 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
9774 + h_dir = au_h_iptr(dir, btop);
9775 + if (h_dir->i_nlink
9776 + && timespec_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) {
9777 + dt.dt_h_path = h_path;
9778 + au_dtime_revert(&dt);
9780 + au_hn_inode_unlock(hdir);
9781 + vfsub_mnt_drop_write(h_path.mnt);
9782 + au_cpup_attr_timesizes(dir);
9785 + aufs_read_unlock(a->dentry, AuLock_DW);
9788 + au_nwt_done(&au_sbi(sb)->si_nowait);
9789 + au_delayed_kfree(arg);
9792 +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex)
9794 + int perm, wkq_err;
9795 + aufs_bindex_t btop;
9796 + struct au_dir_ts_arg *arg;
9797 + struct dentry *dentry;
9798 + struct super_block *sb;
9802 + dentry = d_find_any_alias(dir);
9803 + AuDebugOn(!dentry);
9804 + sb = dentry->d_sb;
9805 + btop = au_ibtop(dir);
9806 + if (btop == bindex) {
9807 + au_cpup_attr_timesizes(dir);
9811 + perm = au_sbr_perm(sb, btop);
9812 + if (!au_br_writable(perm))
9815 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
9819 + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */
9820 + arg->brid = au_sbr_id(sb, bindex);
9821 + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0);
9822 + if (unlikely(wkq_err)) {
9823 + pr_err("wkq %d\n", wkq_err);
9825 + au_delayed_kfree(arg);
9832 +/* ---------------------------------------------------------------------- */
9834 +static int reopen_dir(struct file *file)
9837 + unsigned int flags;
9838 + aufs_bindex_t bindex, btail, btop;
9839 + struct dentry *dentry, *h_dentry;
9840 + struct file *h_file;
9842 + /* open all lower dirs */
9843 + dentry = file->f_path.dentry;
9844 + btop = au_dbtop(dentry);
9845 + for (bindex = au_fbtop(file); bindex < btop; bindex++)
9846 + au_set_h_fptr(file, bindex, NULL);
9847 + au_set_fbtop(file, btop);
9849 + btail = au_dbtaildir(dentry);
9850 + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--)
9851 + au_set_h_fptr(file, bindex, NULL);
9852 + au_set_fbbot_dir(file, btail);
9854 + flags = vfsub_file_flags(file);
9855 + for (bindex = btop; bindex <= btail; bindex++) {
9856 + h_dentry = au_h_dptr(dentry, bindex);
9859 + h_file = au_hf_dir(file, bindex);
9863 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9864 + err = PTR_ERR(h_file);
9865 + if (IS_ERR(h_file))
9866 + goto out; /* close all? */
9867 + au_set_h_fptr(file, bindex, h_file);
9869 + au_update_figen(file);
9870 + /* todo: necessary? */
9871 + /* file->f_ra = h_file->f_ra; */
9878 +static int do_open_dir(struct file *file, int flags, struct file *h_file)
9881 + aufs_bindex_t bindex, btail;
9882 + struct dentry *dentry, *h_dentry;
9883 + struct vfsmount *mnt;
9885 + FiMustWriteLock(file);
9886 + AuDebugOn(h_file);
9889 + mnt = file->f_path.mnt;
9890 + dentry = file->f_path.dentry;
9891 + file->f_version = d_inode(dentry)->i_version;
9892 + bindex = au_dbtop(dentry);
9893 + au_set_fbtop(file, bindex);
9894 + btail = au_dbtaildir(dentry);
9895 + au_set_fbbot_dir(file, btail);
9896 + for (; !err && bindex <= btail; bindex++) {
9897 + h_dentry = au_h_dptr(dentry, bindex);
9901 + err = vfsub_test_mntns(mnt, h_dentry->d_sb);
9902 + if (unlikely(err))
9904 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
9905 + if (IS_ERR(h_file)) {
9906 + err = PTR_ERR(h_file);
9909 + au_set_h_fptr(file, bindex, h_file);
9911 + au_update_figen(file);
9912 + /* todo: necessary? */
9913 + /* file->f_ra = h_file->f_ra; */
9915 + return 0; /* success */
9918 + for (bindex = au_fbtop(file); bindex <= btail; bindex++)
9919 + au_set_h_fptr(file, bindex, NULL);
9920 + au_set_fbtop(file, -1);
9921 + au_set_fbbot_dir(file, -1);
9926 +static int aufs_open_dir(struct inode *inode __maybe_unused,
9927 + struct file *file)
9930 + struct super_block *sb;
9931 + struct au_fidir *fidir;
9934 + sb = file->f_path.dentry->d_sb;
9935 + si_read_lock(sb, AuLock_FLUSH);
9936 + fidir = au_fidir_alloc(sb);
9938 + struct au_do_open_args args = {
9939 + .open = do_open_dir,
9942 + err = au_do_open(file, &args);
9943 + if (unlikely(err))
9944 + au_delayed_kfree(fidir);
9946 + si_read_unlock(sb);
9950 +static int aufs_release_dir(struct inode *inode __maybe_unused,
9951 + struct file *file)
9953 + struct au_vdir *vdir_cache;
9954 + struct au_finfo *finfo;
9955 + struct au_fidir *fidir;
9956 + struct au_hfile *hf;
9957 + aufs_bindex_t bindex, bbot;
9958 + int execed, delayed;
9960 + delayed = (current->flags & PF_KTHREAD) || in_interrupt();
9961 + finfo = au_fi(file);
9962 + fidir = finfo->fi_hdir;
9964 + au_sphl_del(&finfo->fi_hlist,
9965 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
9966 + vdir_cache = fidir->fd_vdir_cache; /* lock-free */
9968 + au_vdir_free(vdir_cache, delayed);
9970 + bindex = finfo->fi_btop;
9971 + if (bindex >= 0) {
9972 + execed = vfsub_file_execed(file);
9973 + hf = fidir->fd_hfile + bindex;
9975 + * calls fput() instead of filp_close(),
9976 + * since no dnotify or lock for the lower file.
9978 + bbot = fidir->fd_bbot;
9979 + for (; bindex <= bbot; bindex++, hf++)
9981 + au_hfput(hf, execed);
9983 + au_delayed_kfree(fidir);
9984 + finfo->fi_hdir = NULL;
9986 + au_finfo_fin(file, delayed);
9990 +/* ---------------------------------------------------------------------- */
9992 +static int au_do_flush_dir(struct file *file, fl_owner_t id)
9995 + aufs_bindex_t bindex, bbot;
9996 + struct file *h_file;
9999 + bbot = au_fbbot_dir(file);
10000 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10001 + h_file = au_hf_dir(file, bindex);
10003 + err = vfsub_flush(h_file, id);
10008 +static int aufs_flush_dir(struct file *file, fl_owner_t id)
10010 + return au_do_flush(file, id, au_do_flush_dir);
10013 +/* ---------------------------------------------------------------------- */
10015 +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync)
10018 + aufs_bindex_t bbot, bindex;
10019 + struct inode *inode;
10020 + struct super_block *sb;
10023 + sb = dentry->d_sb;
10024 + inode = d_inode(dentry);
10025 + IMustLock(inode);
10026 + bbot = au_dbbot(dentry);
10027 + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) {
10028 + struct path h_path;
10030 + if (au_test_ro(sb, bindex, inode))
10032 + h_path.dentry = au_h_dptr(dentry, bindex);
10033 + if (!h_path.dentry)
10036 + h_path.mnt = au_sbr_mnt(sb, bindex);
10037 + err = vfsub_fsync(NULL, &h_path, datasync);
10043 +static int au_do_fsync_dir(struct file *file, int datasync)
10046 + aufs_bindex_t bbot, bindex;
10047 + struct file *h_file;
10048 + struct super_block *sb;
10049 + struct inode *inode;
10051 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
10052 + if (unlikely(err))
10055 + inode = file_inode(file);
10056 + sb = inode->i_sb;
10057 + bbot = au_fbbot_dir(file);
10058 + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) {
10059 + h_file = au_hf_dir(file, bindex);
10060 + if (!h_file || au_test_ro(sb, bindex, inode))
10063 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
10071 + * @file may be NULL
10073 +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end,
10077 + struct dentry *dentry;
10078 + struct inode *inode;
10079 + struct super_block *sb;
10082 + dentry = file->f_path.dentry;
10083 + inode = d_inode(dentry);
10084 + inode_lock(inode);
10085 + sb = dentry->d_sb;
10086 + si_noflush_read_lock(sb);
10088 + err = au_do_fsync_dir(file, datasync);
10090 + di_write_lock_child(dentry);
10091 + err = au_do_fsync_dir_no_file(dentry, datasync);
10093 + au_cpup_attr_timesizes(inode);
10094 + di_write_unlock(dentry);
10096 + fi_write_unlock(file);
10098 + si_read_unlock(sb);
10099 + inode_unlock(inode);
10103 +/* ---------------------------------------------------------------------- */
10105 +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx)
10108 + struct dentry *dentry;
10109 + struct inode *inode, *h_inode;
10110 + struct super_block *sb;
10112 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
10114 + dentry = file->f_path.dentry;
10115 + inode = d_inode(dentry);
10116 + IMustLock(inode);
10118 + sb = dentry->d_sb;
10119 + si_read_lock(sb, AuLock_FLUSH);
10120 + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1);
10121 + if (unlikely(err))
10123 + err = au_alive_dir(dentry);
10125 + err = au_vdir_init(file);
10126 + di_downgrade_lock(dentry, AuLock_IR);
10127 + if (unlikely(err))
10130 + h_inode = au_h_iptr(inode, au_ibtop(inode));
10131 + if (!au_test_nfsd()) {
10132 + err = au_vdir_fill_de(file, ctx);
10133 + fsstack_copy_attr_atime(inode, h_inode);
10136 + * nfsd filldir may call lookup_one_len(), vfs_getattr(),
10137 + * encode_fh() and others.
10139 + atomic_inc(&h_inode->i_count);
10140 + di_read_unlock(dentry, AuLock_IR);
10141 + si_read_unlock(sb);
10142 + err = au_vdir_fill_de(file, ctx);
10143 + fsstack_copy_attr_atime(inode, h_inode);
10144 + fi_write_unlock(file);
10152 + di_read_unlock(dentry, AuLock_IR);
10153 + fi_write_unlock(file);
10155 + si_read_unlock(sb);
10159 +/* ---------------------------------------------------------------------- */
10161 +#define AuTestEmpty_WHONLY 1
10162 +#define AuTestEmpty_CALLED (1 << 1)
10163 +#define AuTestEmpty_SHWH (1 << 2)
10164 +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name)
10165 +#define au_fset_testempty(flags, name) \
10166 + do { (flags) |= AuTestEmpty_##name; } while (0)
10167 +#define au_fclr_testempty(flags, name) \
10168 + do { (flags) &= ~AuTestEmpty_##name; } while (0)
10170 +#ifndef CONFIG_AUFS_SHWH
10171 +#undef AuTestEmpty_SHWH
10172 +#define AuTestEmpty_SHWH 0
10175 +struct test_empty_arg {
10176 + struct dir_context ctx;
10177 + struct au_nhash *whlist;
10178 + unsigned int flags;
10180 + aufs_bindex_t bindex;
10183 +static int test_empty_cb(struct dir_context *ctx, const char *__name,
10184 + int namelen, loff_t offset __maybe_unused, u64 ino,
10185 + unsigned int d_type)
10187 + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg,
10189 + char *name = (void *)__name;
10192 + au_fset_testempty(arg->flags, CALLED);
10194 + if (name[0] == '.'
10195 + && (namelen == 1 || (name[1] == '.' && namelen == 2)))
10196 + goto out; /* success */
10198 + if (namelen <= AUFS_WH_PFX_LEN
10199 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
10200 + if (au_ftest_testempty(arg->flags, WHONLY)
10201 + && !au_nhash_test_known_wh(arg->whlist, name, namelen))
10202 + arg->err = -ENOTEMPTY;
10206 + name += AUFS_WH_PFX_LEN;
10207 + namelen -= AUFS_WH_PFX_LEN;
10208 + if (!au_nhash_test_known_wh(arg->whlist, name, namelen))
10209 + arg->err = au_nhash_append_wh
10210 + (arg->whlist, name, namelen, ino, d_type, arg->bindex,
10211 + au_ftest_testempty(arg->flags, SHWH));
10215 + AuTraceErr(arg->err);
10219 +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10222 + struct file *h_file;
10224 + h_file = au_h_open(dentry, arg->bindex,
10225 + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE,
10226 + /*file*/NULL, /*force_wr*/0);
10227 + err = PTR_ERR(h_file);
10228 + if (IS_ERR(h_file))
10232 + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE)
10233 + && !file_inode(h_file)->i_nlink)
10238 + au_fclr_testempty(arg->flags, CALLED);
10240 + err = vfsub_iterate_dir(h_file, &arg->ctx);
10243 + } while (!err && au_ftest_testempty(arg->flags, CALLED));
10247 + au_sbr_put(dentry->d_sb, arg->bindex);
10252 +struct do_test_empty_args {
10254 + struct dentry *dentry;
10255 + struct test_empty_arg *arg;
10258 +static void call_do_test_empty(void *args)
10260 + struct do_test_empty_args *a = args;
10261 + *a->errp = do_test_empty(a->dentry, a->arg);
10264 +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg)
10266 + int err, wkq_err;
10267 + struct dentry *h_dentry;
10268 + struct inode *h_inode;
10270 + h_dentry = au_h_dptr(dentry, arg->bindex);
10271 + h_inode = d_inode(h_dentry);
10272 + /* todo: i_mode changes anytime? */
10273 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
10274 + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ);
10275 + inode_unlock(h_inode);
10277 + err = do_test_empty(dentry, arg);
10279 + struct do_test_empty_args args = {
10281 + .dentry = dentry,
10284 + unsigned int flags = arg->flags;
10286 + wkq_err = au_wkq_wait(call_do_test_empty, &args);
10287 + if (unlikely(wkq_err))
10289 + arg->flags = flags;
10295 +int au_test_empty_lower(struct dentry *dentry)
10298 + unsigned int rdhash;
10299 + aufs_bindex_t bindex, btop, btail;
10300 + struct au_nhash whlist;
10301 + struct test_empty_arg arg = {
10303 + .actor = test_empty_cb
10306 + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg);
10308 + SiMustAnyLock(dentry->d_sb);
10310 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
10312 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry));
10313 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
10314 + if (unlikely(err))
10318 + arg.whlist = &whlist;
10319 + btop = au_dbtop(dentry);
10320 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10321 + au_fset_testempty(arg.flags, SHWH);
10322 + test_empty = do_test_empty;
10323 + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1))
10324 + test_empty = sio_test_empty;
10325 + arg.bindex = btop;
10326 + err = test_empty(dentry, &arg);
10327 + if (unlikely(err))
10330 + au_fset_testempty(arg.flags, WHONLY);
10331 + btail = au_dbtaildir(dentry);
10332 + for (bindex = btop + 1; !err && bindex <= btail; bindex++) {
10333 + struct dentry *h_dentry;
10335 + h_dentry = au_h_dptr(dentry, bindex);
10336 + if (h_dentry && d_is_positive(h_dentry)) {
10337 + arg.bindex = bindex;
10338 + err = test_empty(dentry, &arg);
10343 + au_nhash_wh_free(&whlist);
10348 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist)
10351 + struct test_empty_arg arg = {
10353 + .actor = test_empty_cb
10356 + aufs_bindex_t bindex, btail;
10359 + arg.whlist = whlist;
10360 + arg.flags = AuTestEmpty_WHONLY;
10361 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH))
10362 + au_fset_testempty(arg.flags, SHWH);
10363 + btail = au_dbtaildir(dentry);
10364 + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) {
10365 + struct dentry *h_dentry;
10367 + h_dentry = au_h_dptr(dentry, bindex);
10368 + if (h_dentry && d_is_positive(h_dentry)) {
10369 + arg.bindex = bindex;
10370 + err = sio_test_empty(dentry, &arg);
10377 +/* ---------------------------------------------------------------------- */
10379 +const struct file_operations aufs_dir_fop = {
10380 + .owner = THIS_MODULE,
10381 + .llseek = default_llseek,
10382 + .read = generic_read_dir,
10383 + .iterate_shared = aufs_iterate_shared,
10384 + .unlocked_ioctl = aufs_ioctl_dir,
10385 +#ifdef CONFIG_COMPAT
10386 + .compat_ioctl = aufs_compat_ioctl_dir,
10388 + .open = aufs_open_dir,
10389 + .release = aufs_release_dir,
10390 + .flush = aufs_flush_dir,
10391 + .fsync = aufs_fsync_dir
10393 diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h
10394 --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100
10395 +++ linux/fs/aufs/dir.h 2016-10-09 16:55:36.489368218 +0200
10398 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10400 + * This program, aufs is free software; you can redistribute it and/or modify
10401 + * it under the terms of the GNU General Public License as published by
10402 + * the Free Software Foundation; either version 2 of the License, or
10403 + * (at your option) any later version.
10405 + * This program is distributed in the hope that it will be useful,
10406 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10407 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10408 + * GNU General Public License for more details.
10410 + * You should have received a copy of the GNU General Public License
10411 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10415 + * directory operations
10418 +#ifndef __AUFS_DIR_H__
10419 +#define __AUFS_DIR_H__
10423 +#include <linux/fs.h>
10425 +/* ---------------------------------------------------------------------- */
10427 +/* need to be faster and smaller */
10430 + unsigned int nh_num;
10431 + struct hlist_head *nh_head;
10434 +struct au_vdir_destr {
10435 + unsigned char len;
10436 + unsigned char name[0];
10439 +struct au_vdir_dehstr {
10440 + struct hlist_node hash;
10442 + struct au_vdir_destr *str;
10443 + struct llist_node lnode; /* delayed free */
10445 +} ____cacheline_aligned_in_smp;
10447 +struct au_vdir_de {
10449 + unsigned char de_type;
10450 + /* caution: packed */
10451 + struct au_vdir_destr de_str;
10454 +struct au_vdir_wh {
10455 + struct hlist_node wh_hash;
10456 +#ifdef CONFIG_AUFS_SHWH
10458 + aufs_bindex_t wh_bindex;
10459 + unsigned char wh_type;
10461 + aufs_bindex_t wh_bindex;
10463 + /* caution: packed */
10464 + struct au_vdir_destr wh_str;
10467 +union au_vdir_deblk_p {
10468 + unsigned char *deblk;
10469 + struct au_vdir_de *de;
10473 + unsigned char **vd_deblk;
10474 + unsigned long vd_nblk;
10476 + unsigned long ul;
10477 + union au_vdir_deblk_p p;
10480 + unsigned long vd_version;
10481 + unsigned int vd_deblk_sz;
10483 + unsigned long vd_jiffy;
10484 + struct llist_node vd_lnode; /* delayed free */
10486 +} ____cacheline_aligned_in_smp;
10488 +/* ---------------------------------------------------------------------- */
10491 +extern const struct file_operations aufs_dir_fop;
10492 +void au_add_nlink(struct inode *dir, struct inode *h_dir);
10493 +void au_sub_nlink(struct inode *dir, struct inode *h_dir);
10494 +loff_t au_dir_size(struct file *file, struct dentry *dentry);
10495 +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc);
10496 +int au_test_empty_lower(struct dentry *dentry);
10497 +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist);
10500 +unsigned int au_rdhash_est(loff_t sz);
10501 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp);
10502 +void au_nhash_wh_free(struct au_nhash *whlist);
10503 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
10505 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen);
10506 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
10507 + unsigned int d_type, aufs_bindex_t bindex,
10508 + unsigned char shwh);
10509 +void au_vdir_free(struct au_vdir *vdir, int atonce);
10510 +int au_vdir_init(struct file *file);
10511 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx);
10514 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg);
10516 +#ifdef CONFIG_AUFS_RDU
10518 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
10519 +#ifdef CONFIG_COMPAT
10520 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd,
10521 + unsigned long arg);
10524 +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file,
10525 + unsigned int cmd, unsigned long arg)
10526 +#ifdef CONFIG_COMPAT
10527 +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file,
10528 + unsigned int cmd, unsigned long arg)
10532 +#endif /* __KERNEL__ */
10533 +#endif /* __AUFS_DIR_H__ */
10534 diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c
10535 --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100
10536 +++ linux/fs/aufs/dynop.c 2016-10-09 16:55:36.489368218 +0200
10539 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10541 + * This program, aufs is free software; you can redistribute it and/or modify
10542 + * it under the terms of the GNU General Public License as published by
10543 + * the Free Software Foundation; either version 2 of the License, or
10544 + * (at your option) any later version.
10546 + * This program is distributed in the hope that it will be useful,
10547 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10548 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10549 + * GNU General Public License for more details.
10551 + * You should have received a copy of the GNU General Public License
10552 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10556 + * dynamically customizable operations for regular files
10561 +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop)
10564 + * How large will these lists be?
10565 + * Usually just a few elements, 20-30 at most for each, I guess.
10567 +static struct au_sphlhead dynop[AuDyLast];
10569 +static struct au_dykey *dy_gfind_get(struct au_sphlhead *sphl, const void *h_op)
10571 + struct au_dykey *key, *tmp;
10572 + struct hlist_head *head;
10575 + head = &sphl->head;
10577 + hlist_for_each_entry_rcu(tmp, head, dk_hnode)
10578 + if (tmp->dk_op.dy_hop == h_op) {
10580 + kref_get(&key->dk_kref);
10583 + rcu_read_unlock();
10588 +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key)
10590 + struct au_dykey **k, *found;
10591 + const void *h_op = key->dk_op.dy_hop;
10595 + k = br->br_dykey;
10596 + for (i = 0; i < AuBrDynOp; i++)
10598 + if (k[i]->dk_op.dy_hop == h_op) {
10605 + spin_lock(&br->br_dykey_lock);
10606 + for (; i < AuBrDynOp; i++)
10608 + if (k[i]->dk_op.dy_hop == h_op) {
10616 + spin_unlock(&br->br_dykey_lock);
10617 + BUG_ON(i == AuBrDynOp); /* expand the array */
10623 +/* kref_get() if @key is already added */
10624 +static struct au_dykey *dy_gadd(struct au_sphlhead *sphl, struct au_dykey *key)
10626 + struct au_dykey *tmp, *found;
10627 + struct hlist_head *head;
10628 + const void *h_op = key->dk_op.dy_hop;
10631 + head = &sphl->head;
10632 + spin_lock(&sphl->spin);
10633 + hlist_for_each_entry(tmp, head, dk_hnode)
10634 + if (tmp->dk_op.dy_hop == h_op) {
10635 + kref_get(&tmp->dk_kref);
10640 + hlist_add_head_rcu(&key->dk_hnode, head);
10641 + spin_unlock(&sphl->spin);
10648 +static void dy_free_rcu(struct rcu_head *rcu)
10650 + struct au_dykey *key;
10652 + key = container_of(rcu, struct au_dykey, dk_rcu);
10654 + kfree(key); /* not delayed */
10657 +static void dy_free(struct kref *kref)
10659 + struct au_dykey *key;
10660 + struct au_sphlhead *sphl;
10662 + key = container_of(kref, struct au_dykey, dk_kref);
10663 + sphl = dynop + key->dk_op.dy_type;
10664 + au_sphl_del_rcu(&key->dk_hnode, sphl);
10665 + call_rcu(&key->dk_rcu, dy_free_rcu);
10668 +void au_dy_put(struct au_dykey *key)
10670 + kref_put(&key->dk_kref, dy_free);
10673 +/* ---------------------------------------------------------------------- */
10675 +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *))
10677 +#ifdef CONFIG_AUFS_DEBUG
10678 +#define DyDbgDeclare(cnt) unsigned int cnt = 0
10679 +#define DyDbgInc(cnt) do { cnt++; } while (0)
10681 +#define DyDbgDeclare(cnt) do {} while (0)
10682 +#define DyDbgInc(cnt) do {} while (0)
10685 +#define DySet(func, dst, src, h_op, h_sb) do { \
10687 + if (h_op->func) { \
10689 + dst.func = src.func; \
10691 + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \
10695 +#define DySetForce(func, dst, src) do { \
10696 + AuDebugOn(!src.func); \
10698 + dst.func = src.func; \
10701 +#define DySetAop(func) \
10702 + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb)
10703 +#define DySetAopForce(func) \
10704 + DySetForce(func, dyaop->da_op, aufs_aop)
10706 +static void dy_aop(struct au_dykey *key, const void *h_op,
10707 + struct super_block *h_sb __maybe_unused)
10709 + struct au_dyaop *dyaop = (void *)key;
10710 + const struct address_space_operations *h_aop = h_op;
10711 + DyDbgDeclare(cnt);
10713 + AuDbg("%s\n", au_sbtype(h_sb));
10715 + DySetAop(writepage);
10716 + DySetAopForce(readpage); /* force */
10717 + DySetAop(writepages);
10718 + DySetAop(set_page_dirty);
10719 + DySetAop(readpages);
10720 + DySetAop(write_begin);
10721 + DySetAop(write_end);
10723 + DySetAop(invalidatepage);
10724 + DySetAop(releasepage);
10725 + DySetAop(freepage);
10726 + /* this one will be changed according to an aufs mount option */
10727 + DySetAop(direct_IO);
10728 + DySetAop(migratepage);
10729 + DySetAop(isolate_page);
10730 + DySetAop(putback_page);
10731 + DySetAop(launder_page);
10732 + DySetAop(is_partially_uptodate);
10733 + DySetAop(is_dirty_writeback);
10734 + DySetAop(error_remove_page);
10735 + DySetAop(swap_activate);
10736 + DySetAop(swap_deactivate);
10738 + DyDbgSize(cnt, *h_aop);
10741 +/* ---------------------------------------------------------------------- */
10743 +static void dy_bug(struct kref *kref)
10748 +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br)
10750 + struct au_dykey *key, *old;
10751 + struct au_sphlhead *sphl;
10754 + void (*set)(struct au_dykey *key, const void *h_op,
10755 + struct super_block *h_sb __maybe_unused);
10757 + static const struct op a[] = {
10759 + .sz = sizeof(struct au_dyaop),
10763 + const struct op *p;
10765 + sphl = dynop + op->dy_type;
10766 + key = dy_gfind_get(sphl, op->dy_hop);
10768 + goto out_add; /* success */
10770 + p = a + op->dy_type;
10771 + key = kzalloc(p->sz, GFP_NOFS);
10772 + if (unlikely(!key)) {
10773 + key = ERR_PTR(-ENOMEM);
10777 + key->dk_op.dy_hop = op->dy_hop;
10778 + kref_init(&key->dk_kref);
10779 + p->set(key, op->dy_hop, au_br_sb(br));
10780 + old = dy_gadd(sphl, key);
10782 + au_delayed_kfree(key);
10787 + old = dy_bradd(br, key);
10789 + /* its ref-count should never be zero here */
10790 + kref_put(&key->dk_kref, dy_bug);
10795 +/* ---------------------------------------------------------------------- */
10797 + * Aufs prohibits O_DIRECT by defaut even if the branch supports it.
10798 + * This behaviour is necessary to return an error from open(O_DIRECT) instead
10799 + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes
10800 + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error.
10801 + * See the aufs manual in detail.
10803 +static void dy_adx(struct au_dyaop *dyaop, int do_dx)
10806 + dyaop->da_op.direct_IO = NULL;
10808 + dyaop->da_op.direct_IO = aufs_aop.direct_IO;
10811 +static struct au_dyaop *dy_aget(struct au_branch *br,
10812 + const struct address_space_operations *h_aop,
10815 + struct au_dyaop *dyaop;
10816 + struct au_dynop op;
10818 + op.dy_type = AuDy_AOP;
10819 + op.dy_haop = h_aop;
10820 + dyaop = (void *)dy_get(&op, br);
10821 + if (IS_ERR(dyaop))
10823 + dy_adx(dyaop, do_dx);
10829 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10830 + struct inode *h_inode)
10833 + struct super_block *sb;
10834 + struct au_branch *br;
10835 + struct au_dyaop *dyaop;
10837 + AuDebugOn(!S_ISREG(h_inode->i_mode));
10838 + IiMustWriteLock(inode);
10840 + sb = inode->i_sb;
10841 + br = au_sbr(sb, bindex);
10842 + do_dx = !!au_opt_test(au_mntflags(sb), DIO);
10843 + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx);
10844 + err = PTR_ERR(dyaop);
10845 + if (IS_ERR(dyaop))
10846 + /* unnecessary to call dy_fput() */
10850 + inode->i_mapping->a_ops = &dyaop->da_op;
10857 + * Is it safe to replace a_ops during the inode/file is in operation?
10858 + * Yes, I hope so.
10860 +int au_dy_irefresh(struct inode *inode)
10863 + aufs_bindex_t btop;
10864 + struct inode *h_inode;
10867 + if (S_ISREG(inode->i_mode)) {
10868 + btop = au_ibtop(inode);
10869 + h_inode = au_h_iptr(inode, btop);
10870 + err = au_dy_iaop(inode, btop, h_inode);
10875 +void au_dy_arefresh(int do_dx)
10877 + struct au_sphlhead *sphl;
10878 + struct hlist_head *head;
10879 + struct au_dykey *key;
10881 + sphl = dynop + AuDy_AOP;
10882 + head = &sphl->head;
10883 + spin_lock(&sphl->spin);
10884 + hlist_for_each_entry(key, head, dk_hnode)
10885 + dy_adx((void *)key, do_dx);
10886 + spin_unlock(&sphl->spin);
10889 +/* ---------------------------------------------------------------------- */
10891 +void __init au_dy_init(void)
10895 + /* make sure that 'struct au_dykey *' can be any type */
10896 + BUILD_BUG_ON(offsetof(struct au_dyaop, da_key));
10898 + for (i = 0; i < AuDyLast; i++)
10899 + au_sphl_init(dynop + i);
10902 +void au_dy_fin(void)
10906 + for (i = 0; i < AuDyLast; i++)
10907 + WARN_ON(!hlist_empty(&dynop[i].head));
10909 diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h
10910 --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100
10911 +++ linux/fs/aufs/dynop.h 2016-10-09 16:55:36.489368218 +0200
10914 + * Copyright (C) 2010-2016 Junjiro R. Okajima
10916 + * This program, aufs is free software; you can redistribute it and/or modify
10917 + * it under the terms of the GNU General Public License as published by
10918 + * the Free Software Foundation; either version 2 of the License, or
10919 + * (at your option) any later version.
10921 + * This program is distributed in the hope that it will be useful,
10922 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
10923 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10924 + * GNU General Public License for more details.
10926 + * You should have received a copy of the GNU General Public License
10927 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
10931 + * dynamically customizable operations (for regular files only)
10934 +#ifndef __AUFS_DYNOP_H__
10935 +#define __AUFS_DYNOP_H__
10939 +#include <linux/fs.h>
10940 +#include <linux/kref.h>
10942 +enum {AuDy_AOP, AuDyLast};
10947 + const void *dy_hop;
10948 + const struct address_space_operations *dy_haop;
10954 + struct hlist_node dk_hnode;
10955 + struct rcu_head dk_rcu;
10957 + struct au_dynop dk_op;
10960 + * during I am in the branch local array, kref is gotten. when the
10961 + * branch is removed, kref is put.
10963 + struct kref dk_kref;
10966 +/* stop unioning since their sizes are very different from each other */
10968 + struct au_dykey da_key;
10969 + struct address_space_operations da_op; /* not const */
10972 +/* ---------------------------------------------------------------------- */
10976 +void au_dy_put(struct au_dykey *key);
10977 +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex,
10978 + struct inode *h_inode);
10979 +int au_dy_irefresh(struct inode *inode);
10980 +void au_dy_arefresh(int do_dio);
10982 +void __init au_dy_init(void);
10983 +void au_dy_fin(void);
10985 +#endif /* __KERNEL__ */
10986 +#endif /* __AUFS_DYNOP_H__ */
10987 diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c
10988 --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100
10989 +++ linux/fs/aufs/export.c 2016-12-17 12:28:17.595211562 +0100
10992 + * Copyright (C) 2005-2016 Junjiro R. Okajima
10994 + * This program, aufs is free software; you can redistribute it and/or modify
10995 + * it under the terms of the GNU General Public License as published by
10996 + * the Free Software Foundation; either version 2 of the License, or
10997 + * (at your option) any later version.
10999 + * This program is distributed in the hope that it will be useful,
11000 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11001 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11002 + * GNU General Public License for more details.
11004 + * You should have received a copy of the GNU General Public License
11005 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
11012 +#include <linux/exportfs.h>
11013 +#include <linux/fs_struct.h>
11014 +#include <linux/namei.h>
11015 +#include <linux/nsproxy.h>
11016 +#include <linux/random.h>
11017 +#include <linux/writeback.h>
11021 +#ifdef CONFIG_AUFS_INO_T_64
11029 +static ino_t decode_ino(__u32 *a)
11033 + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a));
11035 +#ifdef CONFIG_AUFS_INO_T_64
11041 +static void encode_ino(__u32 *a, ino_t ino)
11047 +#ifdef CONFIG_AUFS_INO_T_64
11052 +/* NFS file handle */
11056 +#ifdef CONFIG_AUFS_INO_T_64
11057 + /* support 64bit inode number */
11070 + Fh_ino = Fh_ino1,
11071 + Fh_dir_ino = Fh_dir_ino1
11074 +static int au_test_anon(struct dentry *dentry)
11076 + /* note: read d_flags without d_lock */
11077 + return !!(dentry->d_flags & DCACHE_DISCONNECTED);
11080 +int au_test_nfsd(void)
11083 + struct task_struct *tsk = current;
11084 + char comm[sizeof(tsk->comm)];
11087 + if (tsk->flags & PF_KTHREAD) {
11088 + get_task_comm(comm, tsk);
11089 + ret = !strcmp(comm, "nfsd");
11095 +/* ---------------------------------------------------------------------- */
11096 +/* inode generation external table */
11098 +void au_xigen_inc(struct inode *inode)
11103 + struct super_block *sb;
11104 + struct au_sbinfo *sbinfo;
11106 + sb = inode->i_sb;
11107 + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO));
11109 + sbinfo = au_sbi(sb);
11110 + pos = inode->i_ino;
11111 + pos *= sizeof(igen);
11112 + igen = inode->i_generation + 1;
11113 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen,
11114 + sizeof(igen), &pos);
11115 + if (sz == sizeof(igen))
11116 + return; /* success */
11118 + if (unlikely(sz >= 0))
11119 + AuIOErr("xigen error (%zd)\n", sz);
11122 +int au_xigen_new(struct inode *inode)
11127 + struct super_block *sb;
11128 + struct au_sbinfo *sbinfo;
11129 + struct file *file;
11132 + /* todo: dirty, at mount time */
11133 + if (inode->i_ino == AUFS_ROOT_INO)
11135 + sb = inode->i_sb;
11136 + SiMustAnyLock(sb);
11137 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11141 + pos = inode->i_ino;
11142 + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) {
11143 + AuIOErr1("too large i%lld\n", pos);
11146 + pos *= sizeof(inode->i_generation);
11149 + sbinfo = au_sbi(sb);
11150 + file = sbinfo->si_xigen;
11153 + if (vfsub_f_size_read(file)
11154 + < pos + sizeof(inode->i_generation)) {
11155 + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next);
11156 + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation,
11157 + sizeof(inode->i_generation), &pos);
11159 + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation,
11160 + sizeof(inode->i_generation), &pos);
11161 + if (sz == sizeof(inode->i_generation))
11162 + goto out; /* success */
11165 + if (unlikely(sz >= 0)) {
11167 + AuIOErr("xigen error (%zd)\n", sz);
11174 +int au_xigen_set(struct super_block *sb, struct file *base)
11177 + struct au_sbinfo *sbinfo;
11178 + struct file *file;
11180 + SiMustWriteLock(sb);
11182 + sbinfo = au_sbi(sb);
11183 + file = au_xino_create2(base, sbinfo->si_xigen);
11184 + err = PTR_ERR(file);
11185 + if (IS_ERR(file))
11188 + if (sbinfo->si_xigen)
11189 + fput(sbinfo->si_xigen);
11190 + sbinfo->si_xigen = file;
11196 +void au_xigen_clr(struct super_block *sb)
11198 + struct au_sbinfo *sbinfo;
11200 + SiMustWriteLock(sb);
11202 + sbinfo = au_sbi(sb);
11203 + if (sbinfo->si_xigen) {
11204 + fput(sbinfo->si_xigen);
11205 + sbinfo->si_xigen = NULL;
11209 +/* ---------------------------------------------------------------------- */
11211 +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino,
11214 + struct dentry *dentry, *d;
11215 + struct inode *inode;
11216 + unsigned int sigen;
11219 + inode = ilookup(sb, ino);
11223 + dentry = ERR_PTR(-ESTALE);
11224 + sigen = au_sigen(sb);
11225 + if (unlikely(au_is_bad_inode(inode)
11226 + || IS_DEADDIR(inode)
11227 + || sigen != au_iigen(inode, NULL)))
11231 + if (!dir_ino || S_ISDIR(inode->i_mode))
11232 + dentry = d_find_alias(inode);
11234 + spin_lock(&inode->i_lock);
11235 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
11236 + spin_lock(&d->d_lock);
11237 + if (!au_test_anon(d)
11238 + && d_inode(d->d_parent)->i_ino == dir_ino) {
11239 + dentry = dget_dlock(d);
11240 + spin_unlock(&d->d_lock);
11243 + spin_unlock(&d->d_lock);
11245 + spin_unlock(&inode->i_lock);
11247 + if (unlikely(dentry && au_digen_test(dentry, sigen))) {
11248 + /* need to refresh */
11256 + AuTraceErrPtr(dentry);
11260 +/* ---------------------------------------------------------------------- */
11262 +/* todo: dirty? */
11263 +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */
11265 +struct au_compare_mnt_args {
11267 + struct super_block *sb;
11270 + struct vfsmount *mnt;
11273 +static int au_compare_mnt(struct vfsmount *mnt, void *arg)
11275 + struct au_compare_mnt_args *a = arg;
11277 + if (mnt->mnt_sb != a->sb)
11279 + a->mnt = mntget(mnt);
11283 +static struct vfsmount *au_mnt_get(struct super_block *sb)
11286 + struct path root;
11287 + struct au_compare_mnt_args args = {
11291 + get_fs_root(current->fs, &root);
11293 + err = iterate_mounts(au_compare_mnt, &args, root.mnt);
11294 + rcu_read_unlock();
11297 + AuDebugOn(!args.mnt);
11301 +struct au_nfsd_si_lock {
11302 + unsigned int sigen;
11303 + aufs_bindex_t bindex, br_id;
11304 + unsigned char force_lock;
11307 +static int si_nfsd_read_lock(struct super_block *sb,
11308 + struct au_nfsd_si_lock *nsi_lock)
11311 + aufs_bindex_t bindex;
11313 + si_read_lock(sb, AuLock_FLUSH);
11315 + /* branch id may be wrapped around */
11317 + bindex = au_br_index(sb, nsi_lock->br_id);
11318 + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb))
11319 + goto out; /* success */
11323 + if (!nsi_lock->force_lock)
11324 + si_read_unlock(sb);
11327 + nsi_lock->bindex = bindex;
11331 +struct find_name_by_ino {
11332 + struct dir_context ctx;
11333 + int called, found;
11340 +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen,
11341 + loff_t offset, u64 ino, unsigned int d_type)
11343 + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino,
11347 + if (a->ino != ino)
11350 + memcpy(a->name, name, namelen);
11351 + a->namelen = namelen;
11356 +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino,
11357 + struct au_nfsd_si_lock *nsi_lock)
11359 + struct dentry *dentry, *parent;
11360 + struct file *file;
11361 + struct inode *dir;
11362 + struct find_name_by_ino arg = {
11364 + .actor = find_name_by_ino
11369 + parent = path->dentry;
11371 + si_read_unlock(parent->d_sb);
11372 + file = vfsub_dentry_open(path, au_dir_roflags);
11373 + dentry = (void *)file;
11374 + if (IS_ERR(file))
11377 + dentry = ERR_PTR(-ENOMEM);
11378 + arg.name = (void *)__get_free_page(GFP_NOFS);
11379 + if (unlikely(!arg.name))
11386 + err = vfsub_iterate_dir(file, &arg.ctx);
11387 + } while (!err && !arg.found && arg.called);
11388 + dentry = ERR_PTR(err);
11389 + if (unlikely(err))
11391 + /* instead of ENOENT */
11392 + dentry = ERR_PTR(-ESTALE);
11396 + /* do not call vfsub_lkup_one() */
11397 + dir = d_inode(parent);
11398 + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen);
11399 + AuTraceErrPtr(dentry);
11400 + if (IS_ERR(dentry))
11402 + AuDebugOn(au_test_anon(dentry));
11403 + if (unlikely(d_really_is_negative(dentry))) {
11405 + dentry = ERR_PTR(-ENOENT);
11409 + au_delayed_free_page((unsigned long)arg.name);
11413 + if (unlikely(nsi_lock
11414 + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0))
11415 + if (!IS_ERR(dentry)) {
11417 + dentry = ERR_PTR(-ESTALE);
11419 + AuTraceErrPtr(dentry);
11423 +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino,
11425 + struct au_nfsd_si_lock *nsi_lock)
11427 + struct dentry *dentry;
11428 + struct path path;
11430 + if (dir_ino != AUFS_ROOT_INO) {
11431 + path.dentry = decode_by_ino(sb, dir_ino, 0);
11432 + dentry = path.dentry;
11433 + if (!path.dentry || IS_ERR(path.dentry))
11435 + AuDebugOn(au_test_anon(path.dentry));
11437 + path.dentry = dget(sb->s_root);
11439 + path.mnt = au_mnt_get(sb);
11440 + dentry = au_lkup_by_ino(&path, ino, nsi_lock);
11444 + AuTraceErrPtr(dentry);
11448 +/* ---------------------------------------------------------------------- */
11450 +static int h_acceptable(void *expv, struct dentry *dentry)
11455 +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath,
11456 + char *buf, int len, struct super_block *sb)
11460 + struct path path;
11462 + p = d_path(h_rootpath, buf, len);
11467 + path.mnt = h_rootpath->mnt;
11468 + path.dentry = h_parent;
11469 + p = d_path(&path, buf, len);
11475 + path.mnt = au_mnt_get(sb);
11476 + path.dentry = sb->s_root;
11477 + p = d_path(&path, buf, len - strlen(p));
11478 + mntput(path.mnt);
11482 + p[strlen(p)] = '/';
11485 + AuTraceErrPtr(p);
11490 +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh,
11491 + int fh_len, struct au_nfsd_si_lock *nsi_lock)
11493 + struct dentry *dentry, *h_parent, *root;
11494 + struct super_block *h_sb;
11495 + char *pathname, *p;
11496 + struct vfsmount *h_mnt;
11497 + struct au_branch *br;
11499 + struct path path;
11501 + br = au_sbr(sb, nsi_lock->bindex);
11502 + h_mnt = au_br_mnt(br);
11503 + h_sb = h_mnt->mnt_sb;
11504 + /* todo: call lower fh_to_dentry()? fh_to_parent()? */
11506 + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail),
11507 + fh_len - Fh_tail, fh[Fh_h_type],
11508 + h_acceptable, /*context*/NULL);
11510 + dentry = h_parent;
11511 + if (unlikely(!h_parent || IS_ERR(h_parent))) {
11512 + AuWarn1("%s decode_fh failed, %ld\n",
11513 + au_sbtype(h_sb), PTR_ERR(h_parent));
11517 + if (unlikely(au_test_anon(h_parent))) {
11518 + AuWarn1("%s decode_fh returned a disconnected dentry\n",
11519 + au_sbtype(h_sb));
11520 + goto out_h_parent;
11523 + dentry = ERR_PTR(-ENOMEM);
11524 + pathname = (void *)__get_free_page(GFP_NOFS);
11525 + if (unlikely(!pathname))
11526 + goto out_h_parent;
11528 + root = sb->s_root;
11529 + path.mnt = h_mnt;
11530 + di_read_lock_parent(root, !AuLock_IR);
11531 + path.dentry = au_h_dptr(root, nsi_lock->bindex);
11532 + di_read_unlock(root, !AuLock_IR);
11533 + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb);
11534 + dentry = (void *)p;
11536 + goto out_pathname;
11538 + si_read_unlock(sb);
11539 + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path);
11540 + dentry = ERR_PTR(err);
11541 + if (unlikely(err))
11544 + dentry = ERR_PTR(-ENOENT);
11545 + AuDebugOn(au_test_anon(path.dentry));
11546 + if (unlikely(d_really_is_negative(path.dentry)))
11549 + if (ino != d_inode(path.dentry)->i_ino)
11550 + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL);
11552 + dentry = dget(path.dentry);
11557 + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0))
11558 + if (!IS_ERR(dentry)) {
11560 + dentry = ERR_PTR(-ESTALE);
11563 + au_delayed_free_page((unsigned long)pathname);
11567 + AuTraceErrPtr(dentry);
11571 +/* ---------------------------------------------------------------------- */
11573 +static struct dentry *
11574 +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len,
11577 + struct dentry *dentry;
11578 + __u32 *fh = fid->raw;
11579 + struct au_branch *br;
11580 + ino_t ino, dir_ino;
11581 + struct au_nfsd_si_lock nsi_lock = {
11585 + dentry = ERR_PTR(-ESTALE);
11586 + /* it should never happen, but the file handle is unreliable */
11587 + if (unlikely(fh_len < Fh_tail))
11589 + nsi_lock.sigen = fh[Fh_sigen];
11590 + nsi_lock.br_id = fh[Fh_br_id];
11592 + /* branch id may be wrapped around */
11594 + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock)))
11596 + nsi_lock.force_lock = 1;
11598 + /* is this inode still cached? */
11599 + ino = decode_ino(fh + Fh_ino);
11600 + /* it should never happen */
11601 + if (unlikely(ino == AUFS_ROOT_INO))
11604 + dir_ino = decode_ino(fh + Fh_dir_ino);
11605 + dentry = decode_by_ino(sb, ino, dir_ino);
11606 + if (IS_ERR(dentry))
11611 + /* is the parent dir cached? */
11612 + br = au_sbr(sb, nsi_lock.bindex);
11614 + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock);
11615 + if (IS_ERR(dentry))
11620 + /* lookup path */
11621 + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock);
11622 + if (IS_ERR(dentry))
11624 + if (unlikely(!dentry))
11625 + /* todo?: make it ESTALE */
11629 + if (!au_digen_test(dentry, au_sigen(sb))
11630 + && d_inode(dentry)->i_generation == fh[Fh_igen])
11631 + goto out_unlock; /* success */
11634 + dentry = ERR_PTR(-ESTALE);
11638 + si_read_unlock(sb);
11640 + AuTraceErrPtr(dentry);
11644 +#if 0 /* reserved for future use */
11645 +/* support subtreecheck option */
11646 +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid,
11647 + int fh_len, int fh_type)
11649 + struct dentry *parent;
11650 + __u32 *fh = fid->raw;
11653 + dir_ino = decode_ino(fh + Fh_dir_ino);
11654 + parent = decode_by_ino(sb, dir_ino, 0);
11655 + if (IS_ERR(parent))
11658 + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]),
11659 + dir_ino, fh, fh_len);
11662 + AuTraceErrPtr(parent);
11667 +/* ---------------------------------------------------------------------- */
11669 +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len,
11670 + struct inode *dir)
11673 + aufs_bindex_t bindex;
11674 + struct super_block *sb, *h_sb;
11675 + struct dentry *dentry, *parent, *h_parent;
11676 + struct inode *h_dir;
11677 + struct au_branch *br;
11680 + if (unlikely(*max_len <= Fh_tail)) {
11681 + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len);
11685 + err = FILEID_ROOT;
11686 + if (inode->i_ino == AUFS_ROOT_INO) {
11687 + AuDebugOn(inode->i_ino != AUFS_ROOT_INO);
11692 + sb = inode->i_sb;
11693 + err = si_read_lock(sb, AuLock_FLUSH);
11694 + if (unlikely(err))
11697 +#ifdef CONFIG_AUFS_DEBUG
11698 + if (unlikely(!au_opt_test(au_mntflags(sb), XINO)))
11699 + AuWarn1("NFS-exporting requires xino\n");
11703 + ii_read_lock_child(inode);
11704 + bindex = au_ibtop(inode);
11706 + dentry = d_find_any_alias(inode);
11707 + if (unlikely(!dentry))
11709 + AuDebugOn(au_test_anon(dentry));
11710 + parent = dget_parent(dentry);
11712 + if (unlikely(!parent))
11714 + if (d_really_is_positive(parent))
11715 + dir = d_inode(parent);
11718 + ii_read_lock_parent(dir);
11719 + h_dir = au_h_iptr(dir, bindex);
11720 + ii_read_unlock(dir);
11721 + if (unlikely(!h_dir))
11723 + h_parent = d_find_any_alias(h_dir);
11724 + if (unlikely(!h_parent))
11725 + goto out_hparent;
11728 + br = au_sbr(sb, bindex);
11729 + h_sb = au_br_sb(br);
11730 + if (unlikely(!h_sb->s_export_op)) {
11731 + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb));
11732 + goto out_hparent;
11735 + fh[Fh_br_id] = br->br_id;
11736 + fh[Fh_sigen] = au_sigen(sb);
11737 + encode_ino(fh + Fh_ino, inode->i_ino);
11738 + encode_ino(fh + Fh_dir_ino, dir->i_ino);
11739 + fh[Fh_igen] = inode->i_generation;
11741 + *max_len -= Fh_tail;
11742 + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail),
11744 + /*connectable or subtreecheck*/0);
11745 + err = fh[Fh_h_type];
11746 + *max_len += Fh_tail;
11747 + /* todo: macros? */
11748 + if (err != FILEID_INVALID)
11751 + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb));
11758 + ii_read_unlock(inode);
11759 + si_read_unlock(sb);
11761 + if (unlikely(err < 0))
11762 + err = FILEID_INVALID;
11766 +/* ---------------------------------------------------------------------- */
11768 +static int aufs_commit_metadata(struct inode *inode)
11771 + aufs_bindex_t bindex;
11772 + struct super_block *sb;
11773 + struct inode *h_inode;
11774 + int (*f)(struct inode *inode);
11776 + sb = inode->i_sb;
11777 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
11778 + ii_write_lock_child(inode);
11779 + bindex = au_ibtop(inode);
11780 + AuDebugOn(bindex < 0);
11781 + h_inode = au_h_iptr(inode, bindex);
11783 + f = h_inode->i_sb->s_export_op->commit_metadata;
11785 + err = f(h_inode);
11787 + struct writeback_control wbc = {
11788 + .sync_mode = WB_SYNC_ALL,
11789 + .nr_to_write = 0 /* metadata only */
11792 + err = sync_inode(h_inode, &wbc);
11795 + au_cpup_attr_timesizes(inode);
11796 + ii_write_unlock(inode);
11797 + si_read_unlock(sb);
11801 +/* ---------------------------------------------------------------------- */
11803 +static struct export_operations aufs_export_op = {
11804 + .fh_to_dentry = aufs_fh_to_dentry,
11805 + /* .fh_to_parent = aufs_fh_to_parent, */
11806 + .encode_fh = aufs_encode_fh,
11807 + .commit_metadata = aufs_commit_metadata
11810 +void au_export_init(struct super_block *sb)
11812 + struct au_sbinfo *sbinfo;
11815 + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS)
11816 + && IS_MODULE(CONFIG_EXPORTFS),
11817 + AUFS_NAME ": unsupported configuration "
11818 + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y");
11820 + sb->s_export_op = &aufs_export_op;
11821 + sbinfo = au_sbi(sb);
11822 + sbinfo->si_xigen = NULL;
11823 + get_random_bytes(&u, sizeof(u));
11824 + BUILD_BUG_ON(sizeof(u) != sizeof(int));
11825 + atomic_set(&sbinfo->si_xigen_next, u);
11827 diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c
11828 --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100
11829 +++ linux/fs/aufs/fhsm.c 2016-10-09 16:55:36.489368218 +0200
11832 + * Copyright (C) 2011-2016 Junjiro R. Okajima
11834 + * This program, aufs is free software; you can redistribute it and/or modify
11835 + * it under the terms of the GNU General Public License as published by
11836 + * the Free Software Foundation; either version 2 of the License, or
11837 + * (at your option) any later version.
11839 + * This program is distributed in the hope that it will be useful,
11840 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
11841 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11842 + * GNU General Public License for more details.
11844 + * You should have received a copy of the GNU General Public License
11845 + * along with this program; if not, write to the Free Software
11846 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
11850 + * File-based Hierarchy Storage Management
11853 +#include <linux/anon_inodes.h>
11854 +#include <linux/poll.h>
11855 +#include <linux/seq_file.h>
11856 +#include <linux/statfs.h>
11859 +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb)
11861 + struct au_sbinfo *sbinfo;
11862 + struct au_fhsm *fhsm;
11864 + SiMustAnyLock(sb);
11866 + sbinfo = au_sbi(sb);
11867 + fhsm = &sbinfo->si_fhsm;
11868 + AuDebugOn(!fhsm);
11869 + return fhsm->fhsm_bottom;
11872 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex)
11874 + struct au_sbinfo *sbinfo;
11875 + struct au_fhsm *fhsm;
11877 + SiMustWriteLock(sb);
11879 + sbinfo = au_sbi(sb);
11880 + fhsm = &sbinfo->si_fhsm;
11881 + AuDebugOn(!fhsm);
11882 + fhsm->fhsm_bottom = bindex;
11885 +/* ---------------------------------------------------------------------- */
11887 +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br)
11889 + struct au_br_fhsm *bf;
11891 + bf = br->br_fhsm;
11892 + MtxMustLock(&bf->bf_lock);
11894 + return !bf->bf_readable
11895 + || time_after(jiffies,
11896 + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire);
11899 +/* ---------------------------------------------------------------------- */
11901 +static void au_fhsm_notify(struct super_block *sb, int val)
11903 + struct au_sbinfo *sbinfo;
11904 + struct au_fhsm *fhsm;
11906 + SiMustAnyLock(sb);
11908 + sbinfo = au_sbi(sb);
11909 + fhsm = &sbinfo->si_fhsm;
11910 + if (au_fhsm_pid(fhsm)
11911 + && atomic_read(&fhsm->fhsm_readable) != -1) {
11912 + atomic_set(&fhsm->fhsm_readable, val);
11914 + wake_up(&fhsm->fhsm_wqh);
11918 +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex,
11919 + struct aufs_stfs *rstfs, int do_lock, int do_notify)
11922 + struct au_branch *br;
11923 + struct au_br_fhsm *bf;
11925 + br = au_sbr(sb, bindex);
11926 + AuDebugOn(au_br_rdonly(br));
11927 + bf = br->br_fhsm;
11931 + mutex_lock(&bf->bf_lock);
11933 + MtxMustLock(&bf->bf_lock);
11935 + /* sb->s_root for NFS is unreliable */
11936 + err = au_br_stfs(br, &bf->bf_stfs);
11937 + if (unlikely(err)) {
11938 + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err);
11942 + bf->bf_jiffy = jiffies;
11943 + bf->bf_readable = 1;
11945 + au_fhsm_notify(sb, /*val*/1);
11947 + *rstfs = bf->bf_stfs;
11951 + mutex_unlock(&bf->bf_lock);
11952 + au_fhsm_notify(sb, /*val*/1);
11957 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force)
11960 + struct au_sbinfo *sbinfo;
11961 + struct au_fhsm *fhsm;
11962 + struct au_branch *br;
11963 + struct au_br_fhsm *bf;
11965 + AuDbg("b%d, force %d\n", bindex, force);
11966 + SiMustAnyLock(sb);
11968 + sbinfo = au_sbi(sb);
11969 + fhsm = &sbinfo->si_fhsm;
11970 + if (!au_ftest_si(sbinfo, FHSM)
11971 + || fhsm->fhsm_bottom == bindex)
11974 + br = au_sbr(sb, bindex);
11975 + bf = br->br_fhsm;
11977 + mutex_lock(&bf->bf_lock);
11979 + || au_fhsm_pid(fhsm)
11980 + || au_fhsm_test_jiffy(sbinfo, br))
11981 + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0,
11983 + mutex_unlock(&bf->bf_lock);
11986 +void au_fhsm_wrote_all(struct super_block *sb, int force)
11988 + aufs_bindex_t bindex, bbot;
11989 + struct au_branch *br;
11991 + /* exclude the bottom */
11992 + bbot = au_fhsm_bottom(sb);
11993 + for (bindex = 0; bindex < bbot; bindex++) {
11994 + br = au_sbr(sb, bindex);
11995 + if (au_br_fhsm(br->br_perm))
11996 + au_fhsm_wrote(sb, bindex, force);
12000 +/* ---------------------------------------------------------------------- */
12002 +static unsigned int au_fhsm_poll(struct file *file,
12003 + struct poll_table_struct *wait)
12005 + unsigned int mask;
12006 + struct au_sbinfo *sbinfo;
12007 + struct au_fhsm *fhsm;
12010 + sbinfo = file->private_data;
12011 + fhsm = &sbinfo->si_fhsm;
12012 + poll_wait(file, &fhsm->fhsm_wqh, wait);
12013 + if (atomic_read(&fhsm->fhsm_readable))
12014 + mask = POLLIN /* | POLLRDNORM */;
12016 + AuTraceErr((int)mask);
12020 +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr,
12021 + struct aufs_stfs *stfs, __s16 brid)
12025 + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs));
12027 + err = __put_user(brid, &stbr->brid);
12028 + if (unlikely(err))
12034 +static ssize_t au_fhsm_do_read(struct super_block *sb,
12035 + struct aufs_stbr __user *stbr, size_t count)
12039 + aufs_bindex_t bindex, bbot;
12040 + struct au_branch *br;
12041 + struct au_br_fhsm *bf;
12043 + /* except the bottom branch */
12046 + bbot = au_fhsm_bottom(sb);
12047 + for (bindex = 0; !err && bindex < bbot; bindex++) {
12048 + br = au_sbr(sb, bindex);
12049 + if (!au_br_fhsm(br->br_perm))
12052 + bf = br->br_fhsm;
12053 + mutex_lock(&bf->bf_lock);
12054 + if (bf->bf_readable) {
12056 + if (count >= sizeof(*stbr))
12057 + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs,
12060 + bf->bf_readable = 0;
12061 + count -= sizeof(*stbr);
12065 + mutex_unlock(&bf->bf_lock);
12068 + err = sizeof(*stbr) * nstbr;
12073 +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count,
12078 + aufs_bindex_t nfhsm, bindex, bbot;
12079 + struct au_sbinfo *sbinfo;
12080 + struct au_fhsm *fhsm;
12081 + struct au_branch *br;
12082 + struct super_block *sb;
12085 + sbinfo = file->private_data;
12086 + fhsm = &sbinfo->si_fhsm;
12088 + spin_lock_irq(&fhsm->fhsm_wqh.lock);
12089 + if (!atomic_read(&fhsm->fhsm_readable)) {
12090 + if (vfsub_file_flags(file) & O_NONBLOCK)
12093 + err = wait_event_interruptible_locked_irq
12095 + atomic_read(&fhsm->fhsm_readable));
12097 + spin_unlock_irq(&fhsm->fhsm_wqh.lock);
12098 + if (unlikely(err))
12101 + /* sb may already be dead */
12102 + au_rw_read_lock(&sbinfo->si_rwsem);
12103 + readable = atomic_read(&fhsm->fhsm_readable);
12104 + if (readable > 0) {
12105 + sb = sbinfo->si_sb;
12107 + /* exclude the bottom branch */
12109 + bbot = au_fhsm_bottom(sb);
12110 + for (bindex = 0; bindex < bbot; bindex++) {
12111 + br = au_sbr(sb, bindex);
12112 + if (au_br_fhsm(br->br_perm))
12116 + if (nfhsm * sizeof(struct aufs_stbr) <= count) {
12117 + atomic_set(&fhsm->fhsm_readable, 0);
12118 + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf,
12122 + au_rw_read_unlock(&sbinfo->si_rwsem);
12130 +static int au_fhsm_release(struct inode *inode, struct file *file)
12132 + struct au_sbinfo *sbinfo;
12133 + struct au_fhsm *fhsm;
12135 + /* sb may already be dead */
12136 + sbinfo = file->private_data;
12137 + fhsm = &sbinfo->si_fhsm;
12138 + spin_lock(&fhsm->fhsm_spin);
12139 + fhsm->fhsm_pid = 0;
12140 + spin_unlock(&fhsm->fhsm_spin);
12141 + kobject_put(&sbinfo->si_kobj);
12146 +static const struct file_operations au_fhsm_fops = {
12147 + .owner = THIS_MODULE,
12148 + .llseek = noop_llseek,
12149 + .read = au_fhsm_read,
12150 + .poll = au_fhsm_poll,
12151 + .release = au_fhsm_release
12154 +int au_fhsm_fd(struct super_block *sb, int oflags)
12157 + struct au_sbinfo *sbinfo;
12158 + struct au_fhsm *fhsm;
12161 + if (unlikely(!capable(CAP_SYS_ADMIN)))
12165 + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK)))
12169 + sbinfo = au_sbi(sb);
12170 + fhsm = &sbinfo->si_fhsm;
12171 + spin_lock(&fhsm->fhsm_spin);
12172 + if (!fhsm->fhsm_pid)
12173 + fhsm->fhsm_pid = current->pid;
12176 + spin_unlock(&fhsm->fhsm_spin);
12177 + if (unlikely(err))
12180 + oflags |= O_RDONLY;
12181 + /* oflags |= FMODE_NONOTIFY; */
12182 + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags);
12184 + if (unlikely(fd < 0))
12187 + /* succeed reglardless 'fhsm' status */
12188 + kobject_get(&sbinfo->si_kobj);
12189 + si_noflush_read_lock(sb);
12190 + if (au_ftest_si(sbinfo, FHSM))
12191 + au_fhsm_wrote_all(sb, /*force*/0);
12192 + si_read_unlock(sb);
12193 + goto out; /* success */
12196 + spin_lock(&fhsm->fhsm_spin);
12197 + fhsm->fhsm_pid = 0;
12198 + spin_unlock(&fhsm->fhsm_spin);
12204 +/* ---------------------------------------------------------------------- */
12206 +int au_fhsm_br_alloc(struct au_branch *br)
12211 + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS);
12213 + au_br_fhsm_init(br->br_fhsm);
12220 +/* ---------------------------------------------------------------------- */
12222 +void au_fhsm_fin(struct super_block *sb)
12224 + au_fhsm_notify(sb, /*val*/-1);
12227 +void au_fhsm_init(struct au_sbinfo *sbinfo)
12229 + struct au_fhsm *fhsm;
12231 + fhsm = &sbinfo->si_fhsm;
12232 + spin_lock_init(&fhsm->fhsm_spin);
12233 + init_waitqueue_head(&fhsm->fhsm_wqh);
12234 + atomic_set(&fhsm->fhsm_readable, 0);
12235 + fhsm->fhsm_expire
12236 + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC);
12237 + fhsm->fhsm_bottom = -1;
12240 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec)
12242 + sbinfo->si_fhsm.fhsm_expire
12243 + = msecs_to_jiffies(sec * MSEC_PER_SEC);
12246 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo)
12250 + if (!au_ftest_si(sbinfo, FHSM))
12253 + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC;
12254 + if (u != AUFS_FHSM_CACHE_DEF_SEC)
12255 + seq_printf(seq, ",fhsm_sec=%u", u);
12257 diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c
12258 --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100
12259 +++ linux/fs/aufs/file.c 2016-10-09 16:55:38.889431135 +0200
12262 + * Copyright (C) 2005-2016 Junjiro R. Okajima
12264 + * This program, aufs is free software; you can redistribute it and/or modify
12265 + * it under the terms of the GNU General Public License as published by
12266 + * the Free Software Foundation; either version 2 of the License, or
12267 + * (at your option) any later version.
12269 + * This program is distributed in the hope that it will be useful,
12270 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12271 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12272 + * GNU General Public License for more details.
12274 + * You should have received a copy of the GNU General Public License
12275 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
12279 + * handling file/dir, and address_space operation
12282 +#ifdef CONFIG_AUFS_DEBUG
12283 +#include <linux/migrate.h>
12285 +#include <linux/pagemap.h>
12288 +/* drop flags for writing */
12289 +unsigned int au_file_roflags(unsigned int flags)
12291 + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC);
12292 + flags |= O_RDONLY | O_NOATIME;
12296 +/* common functions to regular file and dir */
12297 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
12298 + struct file *file, int force_wr)
12300 + struct file *h_file;
12301 + struct dentry *h_dentry;
12302 + struct inode *h_inode;
12303 + struct super_block *sb;
12304 + struct au_branch *br;
12305 + struct path h_path;
12308 + /* a race condition can happen between open and unlink/rmdir */
12309 + h_file = ERR_PTR(-ENOENT);
12310 + h_dentry = au_h_dptr(dentry, bindex);
12311 + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry)))
12313 + h_inode = d_inode(h_dentry);
12314 + spin_lock(&h_dentry->d_lock);
12315 + err = (!d_unhashed(dentry) && d_unlinked(h_dentry))
12316 + /* || !d_inode(dentry)->i_nlink */
12318 + spin_unlock(&h_dentry->d_lock);
12319 + if (unlikely(err))
12322 + sb = dentry->d_sb;
12323 + br = au_sbr(sb, bindex);
12324 + err = au_br_test_oflag(flags, br);
12325 + h_file = ERR_PTR(err);
12326 + if (unlikely(err))
12329 + /* drop flags for writing */
12330 + if (au_test_ro(sb, bindex, d_inode(dentry))) {
12331 + if (force_wr && !(flags & O_WRONLY))
12333 + flags = au_file_roflags(flags);
12335 + h_file = ERR_PTR(-EROFS);
12336 + flags = au_file_roflags(flags);
12337 + if (unlikely(vfsub_native_ro(h_inode)
12338 + || IS_APPEND(h_inode)))
12340 + flags &= ~O_ACCMODE;
12341 + flags |= O_WRONLY;
12344 + flags &= ~O_CREAT;
12346 + h_path.dentry = h_dentry;
12347 + h_path.mnt = au_br_mnt(br);
12348 + h_file = vfsub_dentry_open(&h_path, flags);
12349 + if (IS_ERR(h_file))
12352 + if (flags & __FMODE_EXEC) {
12353 + err = deny_write_access(h_file);
12354 + if (unlikely(err)) {
12356 + h_file = ERR_PTR(err);
12360 + fsnotify_open(h_file);
12361 + goto out; /* success */
12369 +static int au_cmoo(struct dentry *dentry)
12372 + unsigned int udba;
12373 + struct path h_path;
12374 + struct au_pin pin;
12375 + struct au_cp_generic cpg = {
12376 + .dentry = dentry,
12381 + .flags = AuCpup_DTIME | AuCpup_HOPEN
12383 + struct inode *delegated;
12384 + struct super_block *sb;
12385 + struct au_sbinfo *sbinfo;
12386 + struct au_fhsm *fhsm;
12388 + struct au_branch *br;
12389 + struct dentry *parent;
12390 + struct au_hinode *hdir;
12392 + DiMustWriteLock(dentry);
12393 + IiMustWriteLock(d_inode(dentry));
12396 + if (IS_ROOT(dentry))
12398 + cpg.bsrc = au_dbtop(dentry);
12402 + sb = dentry->d_sb;
12403 + sbinfo = au_sbi(sb);
12404 + fhsm = &sbinfo->si_fhsm;
12405 + pid = au_fhsm_pid(fhsm);
12407 + && (current->pid == pid
12408 + || current->real_parent->pid == pid))
12411 + br = au_sbr(sb, cpg.bsrc);
12412 + cmoo = au_br_cmoo(br->br_perm);
12415 + if (!d_is_reg(dentry))
12416 + cmoo &= AuBrAttr_COO_ALL;
12420 + parent = dget_parent(dentry);
12421 + di_write_lock_parent(parent);
12422 + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1);
12424 + if (unlikely(err < 0)) {
12425 + err = 0; /* there is no upper writable branch */
12428 + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst);
12430 + /* do not respect the coo attrib for the target branch */
12431 + err = au_cpup_dirs(dentry, cpg.bdst);
12432 + if (unlikely(err))
12435 + di_downgrade_lock(parent, AuLock_IR);
12436 + udba = au_opt_udba(sb);
12437 + err = au_pin(&pin, dentry, cpg.bdst, udba,
12438 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12439 + if (unlikely(err))
12442 + err = au_sio_cpup_simple(&cpg);
12444 + if (unlikely(err))
12446 + if (!(cmoo & AuBrWAttr_MOO))
12447 + goto out_parent; /* success */
12449 + err = au_pin(&pin, dentry, cpg.bsrc, udba,
12450 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12451 + if (unlikely(err))
12454 + h_path.mnt = au_br_mnt(br);
12455 + h_path.dentry = au_h_dptr(dentry, cpg.bsrc);
12456 + hdir = au_hi(d_inode(parent), cpg.bsrc);
12457 + delegated = NULL;
12458 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1);
12460 + /* todo: keep h_dentry or not? */
12461 + if (unlikely(err == -EWOULDBLOCK)) {
12462 + pr_warn("cannot retry for NFSv4 delegation"
12463 + " for an internal unlink\n");
12466 + if (unlikely(err)) {
12467 + pr_err("unlink %pd after coo failed (%d), ignored\n",
12471 + goto out_parent; /* success */
12474 + di_downgrade_lock(parent, AuLock_IR);
12476 + di_read_unlock(parent, AuLock_IR);
12483 +int au_do_open(struct file *file, struct au_do_open_args *args)
12485 + int err, no_lock = args->no_lock;
12486 + struct dentry *dentry;
12487 + struct au_finfo *finfo;
12490 + err = au_finfo_init(file, args->fidir);
12493 + err = au_finfo_init(file, args->fidir);
12496 + if (unlikely(err))
12499 + dentry = file->f_path.dentry;
12500 + AuDebugOn(IS_ERR_OR_NULL(dentry));
12502 + di_write_lock_child(dentry);
12503 + err = au_cmoo(dentry);
12504 + di_downgrade_lock(dentry, AuLock_IR);
12506 + err = args->open(file, vfsub_file_flags(file), NULL);
12507 + di_read_unlock(dentry, AuLock_IR);
12509 + err = au_cmoo(dentry);
12511 + err = args->open(file, vfsub_file_flags(file),
12513 + if (!err && au_fbtop(file) != au_dbtop(dentry))
12515 + * cmoo happens after h_file was opened.
12516 + * need to refresh file later.
12518 + atomic_dec(&au_fi(file)->fi_generation);
12521 + finfo = au_fi(file);
12523 + finfo->fi_file = file;
12524 + au_sphl_add(&finfo->fi_hlist,
12525 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
12528 + fi_write_unlock(file);
12531 + fi_write_unlock(file);
12534 + if (unlikely(err)) {
12535 + finfo->fi_hdir = NULL;
12536 + au_finfo_fin(file, /*atonce*/0);
12543 +int au_reopen_nondir(struct file *file)
12546 + aufs_bindex_t btop;
12547 + struct dentry *dentry;
12548 + struct file *h_file, *h_file_tmp;
12550 + dentry = file->f_path.dentry;
12551 + btop = au_dbtop(dentry);
12552 + h_file_tmp = NULL;
12553 + if (au_fbtop(file) == btop) {
12554 + h_file = au_hf_top(file);
12555 + if (file->f_mode == h_file->f_mode)
12556 + return 0; /* success */
12557 + h_file_tmp = h_file;
12558 + get_file(h_file_tmp);
12559 + au_set_h_fptr(file, btop, NULL);
12561 + AuDebugOn(au_fi(file)->fi_hdir);
12564 + * file exists on both of rw and ro
12565 + * open --> dbtop and fbtop are both 0
12566 + * prepend a branch as rw, "rw" become ro
12568 + * delete the top branch, "rw" becomes rw again
12569 + * --> dbtop is 1, fbtop is still 0
12570 + * write --> fbtop is 0 but dbtop is 1
12572 + /* AuDebugOn(au_fbtop(file) < btop); */
12574 + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC,
12575 + file, /*force_wr*/0);
12576 + err = PTR_ERR(h_file);
12577 + if (IS_ERR(h_file)) {
12578 + if (h_file_tmp) {
12579 + au_sbr_get(dentry->d_sb, btop);
12580 + au_set_h_fptr(file, btop, h_file_tmp);
12581 + h_file_tmp = NULL;
12583 + goto out; /* todo: close all? */
12587 + au_set_fbtop(file, btop);
12588 + au_set_h_fptr(file, btop, h_file);
12589 + au_update_figen(file);
12590 + /* todo: necessary? */
12591 + /* file->f_ra = h_file->f_ra; */
12595 + fput(h_file_tmp);
12599 +/* ---------------------------------------------------------------------- */
12601 +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt,
12602 + struct dentry *hi_wh)
12605 + aufs_bindex_t btop;
12606 + struct au_dinfo *dinfo;
12607 + struct dentry *h_dentry;
12608 + struct au_hdentry *hdp;
12610 + dinfo = au_di(file->f_path.dentry);
12611 + AuRwMustWriteLock(&dinfo->di_rwsem);
12613 + btop = dinfo->di_btop;
12614 + dinfo->di_btop = btgt;
12615 + hdp = au_hdentry(dinfo, btgt);
12616 + h_dentry = hdp->hd_dentry;
12617 + hdp->hd_dentry = hi_wh;
12618 + err = au_reopen_nondir(file);
12619 + hdp->hd_dentry = h_dentry;
12620 + dinfo->di_btop = btop;
12625 +static int au_ready_to_write_wh(struct file *file, loff_t len,
12626 + aufs_bindex_t bcpup, struct au_pin *pin)
12629 + struct inode *inode, *h_inode;
12630 + struct dentry *h_dentry, *hi_wh;
12631 + struct au_cp_generic cpg = {
12632 + .dentry = file->f_path.dentry,
12639 + au_update_dbtop(cpg.dentry);
12640 + inode = d_inode(cpg.dentry);
12642 + if (au_dbtop(cpg.dentry) <= bcpup
12643 + && au_dbbot(cpg.dentry) >= bcpup) {
12644 + h_dentry = au_h_dptr(cpg.dentry, bcpup);
12645 + if (h_dentry && d_is_positive(h_dentry))
12646 + h_inode = d_inode(h_dentry);
12648 + hi_wh = au_hi_wh(inode, bcpup);
12649 + if (!hi_wh && !h_inode)
12650 + err = au_sio_cpup_wh(&cpg, file);
12652 + /* already copied-up after unlink */
12653 + err = au_reopen_wh(file, bcpup, hi_wh);
12656 + && (inode->i_nlink > 1
12657 + || (inode->i_state & I_LINKABLE))
12658 + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK))
12659 + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup));
12665 + * prepare the @file for writing.
12667 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin)
12670 + aufs_bindex_t dbtop;
12671 + struct dentry *parent;
12672 + struct inode *inode;
12673 + struct super_block *sb;
12674 + struct file *h_file;
12675 + struct au_cp_generic cpg = {
12676 + .dentry = file->f_path.dentry,
12681 + .flags = AuCpup_DTIME
12684 + sb = cpg.dentry->d_sb;
12685 + inode = d_inode(cpg.dentry);
12686 + cpg.bsrc = au_fbtop(file);
12687 + err = au_test_ro(sb, cpg.bsrc, inode);
12688 + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) {
12689 + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE,
12694 + /* need to cpup or reopen */
12695 + parent = dget_parent(cpg.dentry);
12696 + di_write_lock_parent(parent);
12697 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12699 + if (unlikely(err < 0))
12703 + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) {
12704 + err = au_cpup_dirs(cpg.dentry, cpg.bdst);
12705 + if (unlikely(err))
12709 + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12710 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12711 + if (unlikely(err))
12714 + dbtop = au_dbtop(cpg.dentry);
12715 + if (dbtop <= cpg.bdst)
12716 + cpg.bsrc = cpg.bdst;
12718 + if (dbtop <= cpg.bdst /* just reopen */
12719 + || !d_unhashed(cpg.dentry) /* copyup and reopen */
12721 + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0);
12722 + if (IS_ERR(h_file))
12723 + err = PTR_ERR(h_file);
12725 + di_downgrade_lock(parent, AuLock_IR);
12726 + if (dbtop > cpg.bdst)
12727 + err = au_sio_cpup_simple(&cpg);
12729 + err = au_reopen_nondir(file);
12730 + au_h_open_post(cpg.dentry, cpg.bsrc, h_file);
12732 + } else { /* copyup as wh and reopen */
12734 + * since writable hfsplus branch is not supported,
12735 + * h_open_pre/post() are unnecessary.
12737 + err = au_ready_to_write_wh(file, len, cpg.bdst, pin);
12738 + di_downgrade_lock(parent, AuLock_IR);
12742 + au_pin_set_parent_lflag(pin, /*lflag*/0);
12743 + goto out_dput; /* success */
12749 + di_downgrade_lock(parent, AuLock_IR);
12751 + di_read_unlock(parent, AuLock_IR);
12758 +/* ---------------------------------------------------------------------- */
12760 +int au_do_flush(struct file *file, fl_owner_t id,
12761 + int (*flush)(struct file *file, fl_owner_t id))
12764 + struct super_block *sb;
12765 + struct inode *inode;
12767 + inode = file_inode(file);
12768 + sb = inode->i_sb;
12769 + si_noflush_read_lock(sb);
12770 + fi_read_lock(file);
12771 + ii_read_lock_child(inode);
12773 + err = flush(file, id);
12774 + au_cpup_attr_timesizes(inode);
12776 + ii_read_unlock(inode);
12777 + fi_read_unlock(file);
12778 + si_read_unlock(sb);
12782 +/* ---------------------------------------------------------------------- */
12784 +static int au_file_refresh_by_inode(struct file *file, int *need_reopen)
12787 + struct au_pin pin;
12788 + struct au_finfo *finfo;
12789 + struct dentry *parent, *hi_wh;
12790 + struct inode *inode;
12791 + struct super_block *sb;
12792 + struct au_cp_generic cpg = {
12793 + .dentry = file->f_path.dentry,
12798 + .flags = AuCpup_DTIME
12801 + FiMustWriteLock(file);
12804 + finfo = au_fi(file);
12805 + sb = cpg.dentry->d_sb;
12806 + inode = d_inode(cpg.dentry);
12807 + cpg.bdst = au_ibtop(inode);
12808 + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry))
12811 + parent = dget_parent(cpg.dentry);
12812 + if (au_test_ro(sb, cpg.bdst, inode)) {
12813 + di_read_lock_parent(parent, !AuLock_IR);
12814 + err = AuWbrCopyup(au_sbi(sb), cpg.dentry);
12816 + di_read_unlock(parent, !AuLock_IR);
12817 + if (unlikely(err < 0))
12822 + di_read_lock_parent(parent, AuLock_IR);
12823 + hi_wh = au_hi_wh(inode, cpg.bdst);
12824 + if (!S_ISDIR(inode->i_mode)
12825 + && au_opt_test(au_mntflags(sb), PLINK)
12826 + && au_plink_test(inode)
12827 + && !d_unhashed(cpg.dentry)
12828 + && cpg.bdst < au_dbtop(cpg.dentry)) {
12829 + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst);
12830 + if (unlikely(err))
12833 + /* always superio. */
12834 + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE,
12835 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
12837 + err = au_sio_cpup_simple(&cpg);
12840 + } else if (hi_wh) {
12841 + /* already copied-up after unlink */
12842 + err = au_reopen_wh(file, cpg.bdst, hi_wh);
12843 + *need_reopen = 0;
12847 + di_read_unlock(parent, AuLock_IR);
12854 +static void au_do_refresh_dir(struct file *file)
12857 + aufs_bindex_t bindex, bbot, new_bindex, brid;
12858 + struct au_hfile *p, tmp, *q;
12859 + struct au_finfo *finfo;
12860 + struct super_block *sb;
12861 + struct au_fidir *fidir;
12863 + FiMustWriteLock(file);
12865 + sb = file->f_path.dentry->d_sb;
12866 + finfo = au_fi(file);
12867 + fidir = finfo->fi_hdir;
12868 + AuDebugOn(!fidir);
12869 + p = fidir->fd_hfile + finfo->fi_btop;
12870 + brid = p->hf_br->br_id;
12871 + bbot = fidir->fd_bbot;
12872 + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) {
12876 + new_bindex = au_br_index(sb, p->hf_br->br_id);
12877 + if (new_bindex == bindex)
12879 + if (new_bindex < 0) {
12880 + au_set_h_fptr(file, bindex, NULL);
12884 + /* swap two lower inode, and loop again */
12885 + q = fidir->fd_hfile + new_bindex;
12889 + if (tmp.hf_file) {
12895 + execed = vfsub_file_execed(file);
12896 + p = fidir->fd_hfile;
12897 + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) {
12898 + bbot = au_sbbot(sb);
12899 + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot;
12900 + finfo->fi_btop++, p++)
12901 + if (p->hf_file) {
12902 + if (file_inode(p->hf_file))
12904 + au_hfput(p, execed);
12907 + bbot = au_br_index(sb, brid);
12908 + for (finfo->fi_btop = 0; finfo->fi_btop < bbot;
12909 + finfo->fi_btop++, p++)
12911 + au_hfput(p, execed);
12912 + bbot = au_sbbot(sb);
12915 + p = fidir->fd_hfile + bbot;
12916 + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop;
12917 + fidir->fd_bbot--, p--)
12918 + if (p->hf_file) {
12919 + if (file_inode(p->hf_file))
12921 + au_hfput(p, execed);
12923 + AuDebugOn(fidir->fd_bbot < finfo->fi_btop);
12927 + * after branch manipulating, refresh the file.
12929 +static int refresh_file(struct file *file, int (*reopen)(struct file *file))
12931 + int err, need_reopen, nbr;
12932 + aufs_bindex_t bbot, bindex;
12933 + struct dentry *dentry;
12934 + struct super_block *sb;
12935 + struct au_finfo *finfo;
12936 + struct au_hfile *hfile;
12938 + dentry = file->f_path.dentry;
12939 + sb = dentry->d_sb;
12940 + nbr = au_sbbot(sb) + 1;
12941 + finfo = au_fi(file);
12942 + if (!finfo->fi_hdir) {
12943 + hfile = &finfo->fi_htop;
12944 + AuDebugOn(!hfile->hf_file);
12945 + bindex = au_br_index(sb, hfile->hf_br->br_id);
12946 + AuDebugOn(bindex < 0);
12947 + if (bindex != finfo->fi_btop)
12948 + au_set_fbtop(file, bindex);
12950 + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0);
12951 + if (unlikely(err))
12953 + au_do_refresh_dir(file);
12958 + if (!au_test_mmapped(file))
12959 + err = au_file_refresh_by_inode(file, &need_reopen);
12960 + if (finfo->fi_hdir)
12961 + /* harmless if err */
12962 + au_fidir_realloc(finfo, nbr, /*may_shrink*/1);
12963 + if (!err && need_reopen && !d_unlinked(dentry))
12964 + err = reopen(file);
12966 + au_update_figen(file);
12967 + goto out; /* success */
12970 + /* error, close all lower files */
12971 + if (finfo->fi_hdir) {
12972 + bbot = au_fbbot_dir(file);
12973 + for (bindex = au_fbtop(file); bindex <= bbot; bindex++)
12974 + au_set_h_fptr(file, bindex, NULL);
12981 +/* common function to regular file and dir */
12982 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
12986 + unsigned int sigen, figen;
12987 + aufs_bindex_t btop;
12988 + unsigned char pseudo_link;
12989 + struct dentry *dentry;
12990 + struct inode *inode;
12993 + dentry = file->f_path.dentry;
12994 + inode = d_inode(dentry);
12995 + sigen = au_sigen(dentry->d_sb);
12996 + fi_write_lock(file);
12997 + figen = au_figen(file);
12998 + di_write_lock_child(dentry);
12999 + btop = au_dbtop(dentry);
13000 + pseudo_link = (btop != au_ibtop(inode));
13001 + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) {
13003 + di_downgrade_lock(dentry, AuLock_IR);
13004 + fi_downgrade_lock(file);
13006 + goto out; /* success */
13009 + AuDbg("sigen %d, figen %d\n", sigen, figen);
13010 + if (au_digen_test(dentry, sigen)) {
13011 + err = au_reval_dpath(dentry, sigen);
13012 + AuDebugOn(!err && au_digen_test(dentry, sigen));
13016 + err = refresh_file(file, reopen);
13019 + di_downgrade_lock(dentry, AuLock_IR);
13020 + fi_downgrade_lock(file);
13023 + di_write_unlock(dentry);
13024 + fi_write_unlock(file);
13031 +/* ---------------------------------------------------------------------- */
13033 +/* cf. aufs_nopage() */
13034 +/* for madvise(2) */
13035 +static int aufs_readpage(struct file *file __maybe_unused, struct page *page)
13037 + unlock_page(page);
13041 +/* it will never be called, but necessary to support O_DIRECT */
13042 +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
13043 +{ BUG(); return 0; }
13045 +/* they will never be called. */
13046 +#ifdef CONFIG_AUFS_DEBUG
13047 +static int aufs_write_begin(struct file *file, struct address_space *mapping,
13048 + loff_t pos, unsigned len, unsigned flags,
13049 + struct page **pagep, void **fsdata)
13050 +{ AuUnsupport(); return 0; }
13051 +static int aufs_write_end(struct file *file, struct address_space *mapping,
13052 + loff_t pos, unsigned len, unsigned copied,
13053 + struct page *page, void *fsdata)
13054 +{ AuUnsupport(); return 0; }
13055 +static int aufs_writepage(struct page *page, struct writeback_control *wbc)
13056 +{ AuUnsupport(); return 0; }
13058 +static int aufs_set_page_dirty(struct page *page)
13059 +{ AuUnsupport(); return 0; }
13060 +static void aufs_invalidatepage(struct page *page, unsigned int offset,
13061 + unsigned int length)
13062 +{ AuUnsupport(); }
13063 +static int aufs_releasepage(struct page *page, gfp_t gfp)
13064 +{ AuUnsupport(); return 0; }
13065 +#if 0 /* called by memory compaction regardless file */
13066 +static int aufs_migratepage(struct address_space *mapping, struct page *newpage,
13067 + struct page *page, enum migrate_mode mode)
13068 +{ AuUnsupport(); return 0; }
13070 +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode)
13071 +{ AuUnsupport(); return true; }
13072 +static void aufs_putback_page(struct page *page)
13073 +{ AuUnsupport(); }
13074 +static int aufs_launder_page(struct page *page)
13075 +{ AuUnsupport(); return 0; }
13076 +static int aufs_is_partially_uptodate(struct page *page,
13077 + unsigned long from,
13078 + unsigned long count)
13079 +{ AuUnsupport(); return 0; }
13080 +static void aufs_is_dirty_writeback(struct page *page, bool *dirty,
13082 +{ AuUnsupport(); }
13083 +static int aufs_error_remove_page(struct address_space *mapping,
13084 + struct page *page)
13085 +{ AuUnsupport(); return 0; }
13086 +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file,
13088 +{ AuUnsupport(); return 0; }
13089 +static void aufs_swap_deactivate(struct file *file)
13090 +{ AuUnsupport(); }
13091 +#endif /* CONFIG_AUFS_DEBUG */
13093 +const struct address_space_operations aufs_aop = {
13094 + .readpage = aufs_readpage,
13095 + .direct_IO = aufs_direct_IO,
13096 +#ifdef CONFIG_AUFS_DEBUG
13097 + .writepage = aufs_writepage,
13098 + /* no writepages, because of writepage */
13099 + .set_page_dirty = aufs_set_page_dirty,
13100 + /* no readpages, because of readpage */
13101 + .write_begin = aufs_write_begin,
13102 + .write_end = aufs_write_end,
13103 + /* no bmap, no block device */
13104 + .invalidatepage = aufs_invalidatepage,
13105 + .releasepage = aufs_releasepage,
13106 + /* is fallback_migrate_page ok? */
13107 + /* .migratepage = aufs_migratepage, */
13108 + .isolate_page = aufs_isolate_page,
13109 + .putback_page = aufs_putback_page,
13110 + .launder_page = aufs_launder_page,
13111 + .is_partially_uptodate = aufs_is_partially_uptodate,
13112 + .is_dirty_writeback = aufs_is_dirty_writeback,
13113 + .error_remove_page = aufs_error_remove_page,
13114 + .swap_activate = aufs_swap_activate,
13115 + .swap_deactivate = aufs_swap_deactivate
13116 +#endif /* CONFIG_AUFS_DEBUG */
13118 diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h
13119 --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100
13120 +++ linux/fs/aufs/file.h 2016-10-09 16:55:38.889431135 +0200
13123 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13125 + * This program, aufs is free software; you can redistribute it and/or modify
13126 + * it under the terms of the GNU General Public License as published by
13127 + * the Free Software Foundation; either version 2 of the License, or
13128 + * (at your option) any later version.
13130 + * This program is distributed in the hope that it will be useful,
13131 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13132 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13133 + * GNU General Public License for more details.
13135 + * You should have received a copy of the GNU General Public License
13136 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13140 + * file operations
13143 +#ifndef __AUFS_FILE_H__
13144 +#define __AUFS_FILE_H__
13148 +#include <linux/file.h>
13149 +#include <linux/fs.h>
13150 +#include <linux/poll.h>
13151 +#include "rwsem.h"
13155 + struct file *hf_file;
13156 + struct au_branch *hf_br;
13161 + aufs_bindex_t fd_bbot;
13162 + aufs_bindex_t fd_nent;
13163 + struct au_vdir *fd_vdir_cache;
13164 + struct au_hfile fd_hfile[];
13167 +static inline int au_fidir_sz(int nent)
13169 + AuDebugOn(nent < 0);
13170 + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent;
13174 + atomic_t fi_generation;
13176 + struct au_rwsem fi_rwsem;
13177 + aufs_bindex_t fi_btop;
13179 + /* do not union them */
13180 + struct { /* for non-dir */
13181 + struct au_hfile fi_htop;
13182 + atomic_t fi_mmapped;
13184 + struct au_fidir *fi_hdir; /* for dir only */
13186 + struct hlist_node fi_hlist;
13188 + struct file *fi_file; /* very ugly */
13189 + struct llist_node fi_lnode; /* delayed free */
13191 +} ____cacheline_aligned_in_smp;
13193 +/* ---------------------------------------------------------------------- */
13196 +extern const struct address_space_operations aufs_aop;
13197 +unsigned int au_file_roflags(unsigned int flags);
13198 +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags,
13199 + struct file *file, int force_wr);
13200 +struct au_do_open_args {
13202 + int (*open)(struct file *file, int flags,
13203 + struct file *h_file);
13204 + struct au_fidir *fidir;
13205 + struct file *h_file;
13207 +int au_do_open(struct file *file, struct au_do_open_args *args);
13208 +int au_reopen_nondir(struct file *file);
13210 +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin);
13211 +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file),
13213 +int au_do_flush(struct file *file, fl_owner_t id,
13214 + int (*flush)(struct file *file, fl_owner_t id));
13217 +#ifdef CONFIG_AUFS_POLL
13218 +unsigned int aufs_poll(struct file *file, poll_table *wait);
13221 +#ifdef CONFIG_AUFS_BR_HFSPLUS
13223 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
13225 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
13226 + struct file *h_file);
13228 +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry,
13229 + aufs_bindex_t bindex, int force_wr)
13230 +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex,
13231 + struct file *h_file);
13235 +extern const struct file_operations aufs_file_fop;
13236 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file);
13237 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file);
13238 +struct file *au_read_pre(struct file *file, int keep_fi);
13241 +void au_hfput(struct au_hfile *hf, int execed);
13242 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex,
13243 + struct file *h_file);
13245 +void au_update_figen(struct file *file);
13246 +struct au_fidir *au_fidir_alloc(struct super_block *sb);
13247 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink);
13249 +void au_fi_init_once(void *_fi);
13250 +void au_finfo_fin(struct file *file, int atonce);
13251 +int au_finfo_init(struct file *file, struct au_fidir *fidir);
13254 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg);
13255 +#ifdef CONFIG_COMPAT
13256 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
13257 + unsigned long arg);
13258 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
13259 + unsigned long arg);
13262 +/* ---------------------------------------------------------------------- */
13264 +static inline struct au_finfo *au_fi(struct file *file)
13266 + return file->private_data;
13269 +/* ---------------------------------------------------------------------- */
13272 + * fi_read_lock, fi_write_lock,
13273 + * fi_read_unlock, fi_write_unlock, fi_downgrade_lock
13275 +AuSimpleRwsemFuncs(fi, struct file *f, &au_fi(f)->fi_rwsem);
13277 +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem)
13278 +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem)
13279 +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem)
13281 +/* ---------------------------------------------------------------------- */
13283 +/* todo: hard/soft set? */
13284 +static inline aufs_bindex_t au_fbtop(struct file *file)
13286 + FiMustAnyLock(file);
13287 + return au_fi(file)->fi_btop;
13290 +static inline aufs_bindex_t au_fbbot_dir(struct file *file)
13292 + FiMustAnyLock(file);
13293 + AuDebugOn(!au_fi(file)->fi_hdir);
13294 + return au_fi(file)->fi_hdir->fd_bbot;
13297 +static inline struct au_vdir *au_fvdir_cache(struct file *file)
13299 + FiMustAnyLock(file);
13300 + AuDebugOn(!au_fi(file)->fi_hdir);
13301 + return au_fi(file)->fi_hdir->fd_vdir_cache;
13304 +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex)
13306 + FiMustWriteLock(file);
13307 + au_fi(file)->fi_btop = bindex;
13310 +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex)
13312 + FiMustWriteLock(file);
13313 + AuDebugOn(!au_fi(file)->fi_hdir);
13314 + au_fi(file)->fi_hdir->fd_bbot = bindex;
13317 +static inline void au_set_fvdir_cache(struct file *file,
13318 + struct au_vdir *vdir_cache)
13320 + FiMustWriteLock(file);
13321 + AuDebugOn(!au_fi(file)->fi_hdir);
13322 + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache;
13325 +static inline struct file *au_hf_top(struct file *file)
13327 + FiMustAnyLock(file);
13328 + AuDebugOn(au_fi(file)->fi_hdir);
13329 + return au_fi(file)->fi_htop.hf_file;
13332 +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex)
13334 + FiMustAnyLock(file);
13335 + AuDebugOn(!au_fi(file)->fi_hdir);
13336 + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file;
13339 +/* todo: memory barrier? */
13340 +static inline unsigned int au_figen(struct file *f)
13342 + return atomic_read(&au_fi(f)->fi_generation);
13345 +static inline void au_set_mmapped(struct file *f)
13347 + if (atomic_inc_return(&au_fi(f)->fi_mmapped))
13349 + pr_warn("fi_mmapped wrapped around\n");
13350 + while (!atomic_inc_return(&au_fi(f)->fi_mmapped))
13354 +static inline void au_unset_mmapped(struct file *f)
13356 + atomic_dec(&au_fi(f)->fi_mmapped);
13359 +static inline int au_test_mmapped(struct file *f)
13361 + return atomic_read(&au_fi(f)->fi_mmapped);
13364 +/* customize vma->vm_file */
13366 +static inline void au_do_vm_file_reset(struct vm_area_struct *vma,
13367 + struct file *file)
13371 + f = vma->vm_file;
13373 + vma->vm_file = file;
13378 +#define AuDbgVmRegion(file, vma) do {} while (0)
13380 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13381 + struct file *file)
13383 + au_do_vm_file_reset(vma, file);
13386 +#define AuDbgVmRegion(file, vma) \
13387 + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file))
13389 +static inline void au_vm_file_reset(struct vm_area_struct *vma,
13390 + struct file *file)
13394 + au_do_vm_file_reset(vma, file);
13395 + f = vma->vm_region->vm_file;
13397 + vma->vm_region->vm_file = file;
13400 +#endif /* CONFIG_MMU */
13402 +/* handle vma->vm_prfile */
13403 +static inline void au_vm_prfile_set(struct vm_area_struct *vma,
13404 + struct file *file)
13407 + vma->vm_prfile = file;
13408 +#ifndef CONFIG_MMU
13410 + vma->vm_region->vm_prfile = file;
13414 +#endif /* __KERNEL__ */
13415 +#endif /* __AUFS_FILE_H__ */
13416 diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c
13417 --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100
13418 +++ linux/fs/aufs/finfo.c 2016-10-09 16:55:38.889431135 +0200
13421 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13423 + * This program, aufs is free software; you can redistribute it and/or modify
13424 + * it under the terms of the GNU General Public License as published by
13425 + * the Free Software Foundation; either version 2 of the License, or
13426 + * (at your option) any later version.
13428 + * This program is distributed in the hope that it will be useful,
13429 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13430 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13431 + * GNU General Public License for more details.
13433 + * You should have received a copy of the GNU General Public License
13434 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13438 + * file private data
13443 +void au_hfput(struct au_hfile *hf, int execed)
13446 + allow_write_access(hf->hf_file);
13447 + fput(hf->hf_file);
13448 + hf->hf_file = NULL;
13449 + au_br_put(hf->hf_br);
13450 + hf->hf_br = NULL;
13453 +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val)
13455 + struct au_finfo *finfo = au_fi(file);
13456 + struct au_hfile *hf;
13457 + struct au_fidir *fidir;
13459 + fidir = finfo->fi_hdir;
13461 + AuDebugOn(finfo->fi_btop != bindex);
13462 + hf = &finfo->fi_htop;
13464 + hf = fidir->fd_hfile + bindex;
13466 + if (hf && hf->hf_file)
13467 + au_hfput(hf, vfsub_file_execed(file));
13469 + FiMustWriteLock(file);
13470 + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry));
13471 + hf->hf_file = val;
13472 + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex);
13476 +void au_update_figen(struct file *file)
13478 + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry));
13479 + /* smp_mb(); */ /* atomic_set */
13482 +/* ---------------------------------------------------------------------- */
13484 +struct au_fidir *au_fidir_alloc(struct super_block *sb)
13486 + struct au_fidir *fidir;
13489 + nbr = au_sbbot(sb) + 1;
13491 + nbr = 2; /* initial allocate for 2 branches */
13492 + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS);
13494 + fidir->fd_bbot = -1;
13495 + fidir->fd_nent = nbr;
13501 +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink)
13504 + struct au_fidir *fidir, *p;
13506 + AuRwMustWriteLock(&finfo->fi_rwsem);
13507 + fidir = finfo->fi_hdir;
13508 + AuDebugOn(!fidir);
13511 + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr),
13512 + GFP_NOFS, may_shrink);
13514 + p->fd_nent = nbr;
13515 + finfo->fi_hdir = p;
13522 +/* ---------------------------------------------------------------------- */
13524 +void au_finfo_fin(struct file *file, int atonce)
13526 + struct au_finfo *finfo;
13528 + au_nfiles_dec(file->f_path.dentry->d_sb);
13530 + finfo = au_fi(file);
13531 + AuDebugOn(finfo->fi_hdir);
13532 + AuRwDestroy(&finfo->fi_rwsem);
13534 + au_cache_dfree_finfo(finfo);
13536 + au_cache_free_finfo(finfo);
13539 +void au_fi_init_once(void *_finfo)
13541 + struct au_finfo *finfo = _finfo;
13543 + au_rw_init(&finfo->fi_rwsem);
13546 +int au_finfo_init(struct file *file, struct au_fidir *fidir)
13549 + struct au_finfo *finfo;
13550 + struct dentry *dentry;
13553 + dentry = file->f_path.dentry;
13554 + finfo = au_cache_alloc_finfo();
13555 + if (unlikely(!finfo))
13559 + au_nfiles_inc(dentry->d_sb);
13560 + au_rw_write_lock(&finfo->fi_rwsem);
13561 + finfo->fi_btop = -1;
13562 + finfo->fi_hdir = fidir;
13563 + atomic_set(&finfo->fi_generation, au_digen(dentry));
13564 + /* smp_mb(); */ /* atomic_set */
13566 + file->private_data = finfo;
13571 diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c
13572 --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100
13573 +++ linux/fs/aufs/f_op.c 2016-12-17 12:28:17.595211562 +0100
13576 + * Copyright (C) 2005-2016 Junjiro R. Okajima
13578 + * This program, aufs is free software; you can redistribute it and/or modify
13579 + * it under the terms of the GNU General Public License as published by
13580 + * the Free Software Foundation; either version 2 of the License, or
13581 + * (at your option) any later version.
13583 + * This program is distributed in the hope that it will be useful,
13584 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13585 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13586 + * GNU General Public License for more details.
13588 + * You should have received a copy of the GNU General Public License
13589 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
13593 + * file and vm operations
13596 +#include <linux/aio.h>
13597 +#include <linux/fs_stack.h>
13598 +#include <linux/mman.h>
13599 +#include <linux/security.h>
13602 +int au_do_open_nondir(struct file *file, int flags, struct file *h_file)
13605 + aufs_bindex_t bindex;
13606 + struct dentry *dentry, *h_dentry;
13607 + struct au_finfo *finfo;
13608 + struct inode *h_inode;
13610 + FiMustWriteLock(file);
13613 + dentry = file->f_path.dentry;
13614 + AuDebugOn(IS_ERR_OR_NULL(dentry));
13615 + finfo = au_fi(file);
13616 + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop));
13617 + atomic_set(&finfo->fi_mmapped, 0);
13618 + bindex = au_dbtop(dentry);
13620 + h_dentry = au_h_dptr(dentry, bindex);
13621 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13622 + if (unlikely(err))
13624 + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0);
13626 + h_dentry = h_file->f_path.dentry;
13627 + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb);
13628 + if (unlikely(err))
13630 + get_file(h_file);
13632 + if (IS_ERR(h_file))
13633 + err = PTR_ERR(h_file);
13635 + if ((flags & __O_TMPFILE)
13636 + && !(flags & O_EXCL)) {
13637 + h_inode = file_inode(h_file);
13638 + spin_lock(&h_inode->i_lock);
13639 + h_inode->i_state |= I_LINKABLE;
13640 + spin_unlock(&h_inode->i_lock);
13642 + au_set_fbtop(file, bindex);
13643 + au_set_h_fptr(file, bindex, h_file);
13644 + au_update_figen(file);
13645 + /* todo: necessary? */
13646 + /* file->f_ra = h_file->f_ra; */
13653 +static int aufs_open_nondir(struct inode *inode __maybe_unused,
13654 + struct file *file)
13657 + struct super_block *sb;
13658 + struct au_do_open_args args = {
13659 + .open = au_do_open_nondir
13662 + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n",
13663 + file, vfsub_file_flags(file), file->f_mode);
13665 + sb = file->f_path.dentry->d_sb;
13666 + si_read_lock(sb, AuLock_FLUSH);
13667 + err = au_do_open(file, &args);
13668 + si_read_unlock(sb);
13672 +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file)
13674 + struct au_finfo *finfo;
13675 + aufs_bindex_t bindex;
13678 + finfo = au_fi(file);
13679 + au_sphl_del(&finfo->fi_hlist,
13680 + &au_sbi(file->f_path.dentry->d_sb)->si_files);
13681 + bindex = finfo->fi_btop;
13683 + au_set_h_fptr(file, bindex, NULL);
13685 + delayed = (current->flags & PF_KTHREAD) || in_interrupt();
13686 + au_finfo_fin(file, delayed);
13690 +/* ---------------------------------------------------------------------- */
13692 +static int au_do_flush_nondir(struct file *file, fl_owner_t id)
13695 + struct file *h_file;
13698 + h_file = au_hf_top(file);
13700 + err = vfsub_flush(h_file, id);
13704 +static int aufs_flush_nondir(struct file *file, fl_owner_t id)
13706 + return au_do_flush(file, id, au_do_flush_nondir);
13709 +/* ---------------------------------------------------------------------- */
13711 + * read and write functions acquire [fdi]_rwsem once, but release before
13712 + * mmap_sem. This is because to stop a race condition between mmap(2).
13713 + * Releasing these aufs-rwsem should be safe, no branch-mamagement (by keeping
13714 + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in
13715 + * read functions after [fdi]_rwsem are released, but it should be harmless.
13718 +/* Callers should call au_read_post() or fput() in the end */
13719 +struct file *au_read_pre(struct file *file, int keep_fi)
13721 + struct file *h_file;
13724 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0);
13726 + di_read_unlock(file->f_path.dentry, AuLock_IR);
13727 + h_file = au_hf_top(file);
13728 + get_file(h_file);
13730 + fi_read_unlock(file);
13732 + h_file = ERR_PTR(err);
13737 +static void au_read_post(struct inode *inode, struct file *h_file)
13739 + /* update without lock, I don't think it a problem */
13740 + fsstack_copy_attr_atime(inode, file_inode(h_file));
13744 +struct au_write_pre {
13746 + aufs_bindex_t btop;
13750 + * return with iinfo is write-locked
13751 + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the
13754 +static struct file *au_write_pre(struct file *file, int do_ready,
13755 + struct au_write_pre *wpre)
13757 + struct file *h_file;
13758 + struct dentry *dentry;
13760 + struct au_pin pin;
13762 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
13763 + h_file = ERR_PTR(err);
13764 + if (unlikely(err))
13767 + dentry = file->f_path.dentry;
13769 + err = au_ready_to_write(file, -1, &pin);
13770 + if (unlikely(err)) {
13771 + h_file = ERR_PTR(err);
13772 + di_write_unlock(dentry);
13777 + di_downgrade_lock(dentry, /*flags*/0);
13779 + wpre->btop = au_fbtop(file);
13780 + h_file = au_hf_top(file);
13781 + get_file(h_file);
13783 + wpre->blks = file_inode(h_file)->i_blocks;
13786 + di_read_unlock(dentry, /*flags*/0);
13789 + fi_write_unlock(file);
13794 +static void au_write_post(struct inode *inode, struct file *h_file,
13795 + struct au_write_pre *wpre, ssize_t written)
13797 + struct inode *h_inode;
13799 + au_cpup_attr_timesizes(inode);
13800 + AuDebugOn(au_ibtop(inode) != wpre->btop);
13801 + h_inode = file_inode(h_file);
13802 + inode->i_mode = h_inode->i_mode;
13803 + ii_write_unlock(inode);
13806 + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */
13808 + au_fhsm_wrote(inode->i_sb, wpre->btop,
13809 + /*force*/h_inode->i_blocks > wpre->blks);
13812 +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count,
13816 + struct inode *inode;
13817 + struct file *h_file;
13818 + struct super_block *sb;
13820 + inode = file_inode(file);
13821 + sb = inode->i_sb;
13822 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13824 + h_file = au_read_pre(file, /*keep_fi*/0);
13825 + err = PTR_ERR(h_file);
13826 + if (IS_ERR(h_file))
13829 + /* filedata may be obsoleted by concurrent copyup, but no problem */
13830 + err = vfsub_read_u(h_file, buf, count, ppos);
13831 + /* todo: necessary? */
13832 + /* file->f_ra = h_file->f_ra; */
13833 + au_read_post(inode, h_file);
13836 + si_read_unlock(sb);
13841 + * todo: very ugly
13842 + * it locks both of i_mutex and si_rwsem for read in safe.
13843 + * if the plink maintenance mode continues forever (that is the problem),
13844 + * may loop forever.
13846 +static void au_mtx_and_read_lock(struct inode *inode)
13849 + struct super_block *sb = inode->i_sb;
13852 + inode_lock(inode);
13853 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
13856 + inode_unlock(inode);
13857 + si_read_lock(sb, AuLock_NOPLMW);
13858 + si_read_unlock(sb);
13862 +static ssize_t aufs_write(struct file *file, const char __user *ubuf,
13863 + size_t count, loff_t *ppos)
13866 + struct au_write_pre wpre;
13867 + struct inode *inode;
13868 + struct file *h_file;
13869 + char __user *buf = (char __user *)ubuf;
13871 + inode = file_inode(file);
13872 + au_mtx_and_read_lock(inode);
13874 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13875 + err = PTR_ERR(h_file);
13876 + if (IS_ERR(h_file))
13879 + err = vfsub_write_u(h_file, buf, count, ppos);
13880 + au_write_post(inode, h_file, &wpre, err);
13883 + si_read_unlock(inode->i_sb);
13884 + inode_unlock(inode);
13888 +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio,
13889 + struct iov_iter *iov_iter)
13892 + struct file *file;
13893 + ssize_t (*iter)(struct kiocb *, struct iov_iter *);
13895 + err = security_file_permission(h_file, rw);
13896 + if (unlikely(err))
13901 + if (rw == MAY_READ)
13902 + iter = h_file->f_op->read_iter;
13903 + else if (rw == MAY_WRITE)
13904 + iter = h_file->f_op->write_iter;
13906 + file = kio->ki_filp;
13907 + kio->ki_filp = h_file;
13910 + err = iter(kio, iov_iter);
13913 + /* currently there is no such fs */
13915 + kio->ki_filp = file;
13921 +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13924 + struct file *file, *h_file;
13925 + struct inode *inode;
13926 + struct super_block *sb;
13928 + file = kio->ki_filp;
13929 + inode = file_inode(file);
13930 + sb = inode->i_sb;
13931 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13933 + h_file = au_read_pre(file, /*keep_fi*/1);
13934 + err = PTR_ERR(h_file);
13935 + if (IS_ERR(h_file))
13938 + if (au_test_loopback_kthread()) {
13939 + au_warn_loopback(h_file->f_path.dentry->d_sb);
13940 + if (file->f_mapping != h_file->f_mapping) {
13941 + file->f_mapping = h_file->f_mapping;
13942 + smp_mb(); /* unnecessary? */
13945 + fi_read_unlock(file);
13947 + err = au_do_iter(h_file, MAY_READ, kio, iov_iter);
13948 + /* todo: necessary? */
13949 + /* file->f_ra = h_file->f_ra; */
13950 + au_read_post(inode, h_file);
13953 + si_read_unlock(sb);
13957 +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter)
13960 + struct au_write_pre wpre;
13961 + struct inode *inode;
13962 + struct file *file, *h_file;
13964 + file = kio->ki_filp;
13965 + inode = file_inode(file);
13966 + au_mtx_and_read_lock(inode);
13968 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
13969 + err = PTR_ERR(h_file);
13970 + if (IS_ERR(h_file))
13973 + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter);
13974 + au_write_post(inode, h_file, &wpre, err);
13977 + si_read_unlock(inode->i_sb);
13978 + inode_unlock(inode);
13982 +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
13983 + struct pipe_inode_info *pipe, size_t len,
13984 + unsigned int flags)
13987 + struct file *h_file;
13988 + struct inode *inode;
13989 + struct super_block *sb;
13991 + inode = file_inode(file);
13992 + sb = inode->i_sb;
13993 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
13995 + h_file = au_read_pre(file, /*keep_fi*/0);
13996 + err = PTR_ERR(h_file);
13997 + if (IS_ERR(h_file))
14000 + err = vfsub_splice_to(h_file, ppos, pipe, len, flags);
14001 + /* todo: necessasry? */
14002 + /* file->f_ra = h_file->f_ra; */
14003 + au_read_post(inode, h_file);
14006 + si_read_unlock(sb);
14011 +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos,
14012 + size_t len, unsigned int flags)
14015 + struct au_write_pre wpre;
14016 + struct inode *inode;
14017 + struct file *h_file;
14019 + inode = file_inode(file);
14020 + au_mtx_and_read_lock(inode);
14022 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14023 + err = PTR_ERR(h_file);
14024 + if (IS_ERR(h_file))
14027 + err = vfsub_splice_from(pipe, h_file, ppos, len, flags);
14028 + au_write_post(inode, h_file, &wpre, err);
14031 + si_read_unlock(inode->i_sb);
14032 + inode_unlock(inode);
14036 +static long aufs_fallocate(struct file *file, int mode, loff_t offset,
14040 + struct au_write_pre wpre;
14041 + struct inode *inode;
14042 + struct file *h_file;
14044 + inode = file_inode(file);
14045 + au_mtx_and_read_lock(inode);
14047 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14048 + err = PTR_ERR(h_file);
14049 + if (IS_ERR(h_file))
14053 + err = vfs_fallocate(h_file, mode, offset, len);
14055 + au_write_post(inode, h_file, &wpre, /*written*/1);
14058 + si_read_unlock(inode->i_sb);
14059 + inode_unlock(inode);
14063 +/* ---------------------------------------------------------------------- */
14066 + * The locking order around current->mmap_sem.
14067 + * - in most and regular cases
14068 + * file I/O syscall -- aufs_read() or something
14069 + * -- si_rwsem for read -- mmap_sem
14070 + * (Note that [fdi]i_rwsem are released before mmap_sem).
14072 + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem
14073 + * This AB-BA order is definitly bad, but is not a problem since "si_rwsem for
14074 + * read" allows muliple processes to acquire it and [fdi]i_rwsem are not held in
14075 + * file I/O. Aufs needs to stop lockdep in aufs_mmap() though.
14076 + * It means that when aufs acquires si_rwsem for write, the process should never
14077 + * acquire mmap_sem.
14079 + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a
14080 + * problem either since any directory is not able to be mmap-ed.
14081 + * The similar scenario is applied to aufs_readlink() too.
14084 +#if 0 /* stop calling security_file_mmap() */
14085 +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */
14086 +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b)
14088 +static unsigned long au_arch_prot_conv(unsigned long flags)
14090 + /* currently ppc64 only */
14091 +#ifdef CONFIG_PPC64
14092 + /* cf. linux/arch/powerpc/include/asm/mman.h */
14093 + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO);
14094 + return AuConv_VM_PROT(flags, SAO);
14096 + AuDebugOn(arch_calc_vm_prot_bits(-1));
14101 +static unsigned long au_prot_conv(unsigned long flags)
14103 + return AuConv_VM_PROT(flags, READ)
14104 + | AuConv_VM_PROT(flags, WRITE)
14105 + | AuConv_VM_PROT(flags, EXEC)
14106 + | au_arch_prot_conv(flags);
14109 +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */
14110 +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b)
14112 +static unsigned long au_flag_conv(unsigned long flags)
14114 + return AuConv_VM_MAP(flags, GROWSDOWN)
14115 + | AuConv_VM_MAP(flags, DENYWRITE)
14116 + | AuConv_VM_MAP(flags, LOCKED);
14120 +static int aufs_mmap(struct file *file, struct vm_area_struct *vma)
14123 + const unsigned char wlock
14124 + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED);
14125 + struct super_block *sb;
14126 + struct file *h_file;
14127 + struct inode *inode;
14129 + AuDbgVmRegion(file, vma);
14131 + inode = file_inode(file);
14132 + sb = inode->i_sb;
14134 + si_read_lock(sb, AuLock_NOPLMW);
14136 + h_file = au_write_pre(file, wlock, /*wpre*/NULL);
14138 + err = PTR_ERR(h_file);
14139 + if (IS_ERR(h_file))
14143 + au_set_mmapped(file);
14144 + au_vm_file_reset(vma, h_file);
14146 + * we cannot call security_mmap_file() here since it may acquire
14147 + * mmap_sem or i_mutex.
14149 + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags),
14150 + * au_flag_conv(vma->vm_flags));
14153 + err = h_file->f_op->mmap(h_file, vma);
14155 + au_vm_prfile_set(vma, file);
14156 + fsstack_copy_attr_atime(inode, file_inode(h_file));
14157 + goto out_fput; /* success */
14159 + au_unset_mmapped(file);
14160 + au_vm_file_reset(vma, file);
14164 + ii_write_unlock(inode);
14169 + si_read_unlock(sb);
14175 +/* ---------------------------------------------------------------------- */
14177 +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end,
14181 + struct au_write_pre wpre;
14182 + struct inode *inode;
14183 + struct file *h_file;
14185 + err = 0; /* -EBADF; */ /* posix? */
14186 + if (unlikely(!(file->f_mode & FMODE_WRITE)))
14189 + inode = file_inode(file);
14190 + au_mtx_and_read_lock(inode);
14192 + h_file = au_write_pre(file, /*do_ready*/1, &wpre);
14193 + err = PTR_ERR(h_file);
14194 + if (IS_ERR(h_file))
14197 + err = vfsub_fsync(h_file, &h_file->f_path, datasync);
14198 + au_write_post(inode, h_file, &wpre, /*written*/0);
14201 + si_read_unlock(inode->i_sb);
14202 + inode_unlock(inode);
14207 +static int aufs_fasync(int fd, struct file *file, int flag)
14210 + struct file *h_file;
14211 + struct super_block *sb;
14213 + sb = file->f_path.dentry->d_sb;
14214 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14216 + h_file = au_read_pre(file, /*keep_fi*/0);
14217 + err = PTR_ERR(h_file);
14218 + if (IS_ERR(h_file))
14221 + if (h_file->f_op->fasync)
14222 + err = h_file->f_op->fasync(fd, h_file, flag);
14223 + fput(h_file); /* instead of au_read_post() */
14226 + si_read_unlock(sb);
14230 +static int aufs_setfl(struct file *file, unsigned long arg)
14233 + struct file *h_file;
14234 + struct super_block *sb;
14236 + sb = file->f_path.dentry->d_sb;
14237 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
14239 + h_file = au_read_pre(file, /*keep_fi*/0);
14240 + err = PTR_ERR(h_file);
14241 + if (IS_ERR(h_file))
14244 + arg |= vfsub_file_flags(file) & FASYNC; /* stop calling h_file->fasync */
14245 + err = setfl(/*unused fd*/-1, h_file, arg);
14246 + fput(h_file); /* instead of au_read_post() */
14249 + si_read_unlock(sb);
14253 +/* ---------------------------------------------------------------------- */
14255 +/* no one supports this operation, currently */
14257 +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset,
14258 + size_t len, loff_t *pos, int more)
14263 +/* ---------------------------------------------------------------------- */
14265 +const struct file_operations aufs_file_fop = {
14266 + .owner = THIS_MODULE,
14268 + .llseek = default_llseek,
14270 + .read = aufs_read,
14271 + .write = aufs_write,
14272 + .read_iter = aufs_read_iter,
14273 + .write_iter = aufs_write_iter,
14275 +#ifdef CONFIG_AUFS_POLL
14276 + .poll = aufs_poll,
14278 + .unlocked_ioctl = aufs_ioctl_nondir,
14279 +#ifdef CONFIG_COMPAT
14280 + .compat_ioctl = aufs_compat_ioctl_nondir,
14282 + .mmap = aufs_mmap,
14283 + .open = aufs_open_nondir,
14284 + .flush = aufs_flush_nondir,
14285 + .release = aufs_release_nondir,
14286 + .fsync = aufs_fsync_nondir,
14287 + .fasync = aufs_fasync,
14288 + /* .sendpage = aufs_sendpage, */
14289 + .setfl = aufs_setfl,
14290 + .splice_write = aufs_splice_write,
14291 + .splice_read = aufs_splice_read,
14293 + .aio_splice_write = aufs_aio_splice_write,
14294 + .aio_splice_read = aufs_aio_splice_read,
14296 + .fallocate = aufs_fallocate
14298 diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h
14299 --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100
14300 +++ linux/fs/aufs/fstype.h 2016-10-09 16:55:36.492701639 +0200
14303 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14305 + * This program, aufs is free software; you can redistribute it and/or modify
14306 + * it under the terms of the GNU General Public License as published by
14307 + * the Free Software Foundation; either version 2 of the License, or
14308 + * (at your option) any later version.
14310 + * This program is distributed in the hope that it will be useful,
14311 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14312 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14313 + * GNU General Public License for more details.
14315 + * You should have received a copy of the GNU General Public License
14316 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14320 + * judging filesystem type
14323 +#ifndef __AUFS_FSTYPE_H__
14324 +#define __AUFS_FSTYPE_H__
14328 +#include <linux/fs.h>
14329 +#include <linux/magic.h>
14330 +#include <linux/nfs_fs.h>
14331 +#include <linux/romfs_fs.h>
14333 +static inline int au_test_aufs(struct super_block *sb)
14335 + return sb->s_magic == AUFS_SUPER_MAGIC;
14338 +static inline const char *au_sbtype(struct super_block *sb)
14340 + return sb->s_type->name;
14343 +static inline int au_test_iso9660(struct super_block *sb __maybe_unused)
14345 +#if IS_ENABLED(CONFIG_ISO9660_FS)
14346 + return sb->s_magic == ISOFS_SUPER_MAGIC;
14352 +static inline int au_test_romfs(struct super_block *sb __maybe_unused)
14354 +#if IS_ENABLED(CONFIG_ROMFS_FS)
14355 + return sb->s_magic == ROMFS_MAGIC;
14361 +static inline int au_test_cramfs(struct super_block *sb __maybe_unused)
14363 +#if IS_ENABLED(CONFIG_CRAMFS)
14364 + return sb->s_magic == CRAMFS_MAGIC;
14369 +static inline int au_test_nfs(struct super_block *sb __maybe_unused)
14371 +#if IS_ENABLED(CONFIG_NFS_FS)
14372 + return sb->s_magic == NFS_SUPER_MAGIC;
14378 +static inline int au_test_fuse(struct super_block *sb __maybe_unused)
14380 +#if IS_ENABLED(CONFIG_FUSE_FS)
14381 + return sb->s_magic == FUSE_SUPER_MAGIC;
14387 +static inline int au_test_xfs(struct super_block *sb __maybe_unused)
14389 +#if IS_ENABLED(CONFIG_XFS_FS)
14390 + return sb->s_magic == XFS_SB_MAGIC;
14396 +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused)
14398 +#ifdef CONFIG_TMPFS
14399 + return sb->s_magic == TMPFS_MAGIC;
14405 +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused)
14407 +#if IS_ENABLED(CONFIG_ECRYPT_FS)
14408 + return !strcmp(au_sbtype(sb), "ecryptfs");
14414 +static inline int au_test_ramfs(struct super_block *sb)
14416 + return sb->s_magic == RAMFS_MAGIC;
14419 +static inline int au_test_ubifs(struct super_block *sb __maybe_unused)
14421 +#if IS_ENABLED(CONFIG_UBIFS_FS)
14422 + return sb->s_magic == UBIFS_SUPER_MAGIC;
14428 +static inline int au_test_procfs(struct super_block *sb __maybe_unused)
14430 +#ifdef CONFIG_PROC_FS
14431 + return sb->s_magic == PROC_SUPER_MAGIC;
14437 +static inline int au_test_sysfs(struct super_block *sb __maybe_unused)
14439 +#ifdef CONFIG_SYSFS
14440 + return sb->s_magic == SYSFS_MAGIC;
14446 +static inline int au_test_configfs(struct super_block *sb __maybe_unused)
14448 +#if IS_ENABLED(CONFIG_CONFIGFS_FS)
14449 + return sb->s_magic == CONFIGFS_MAGIC;
14455 +static inline int au_test_minix(struct super_block *sb __maybe_unused)
14457 +#if IS_ENABLED(CONFIG_MINIX_FS)
14458 + return sb->s_magic == MINIX3_SUPER_MAGIC
14459 + || sb->s_magic == MINIX2_SUPER_MAGIC
14460 + || sb->s_magic == MINIX2_SUPER_MAGIC2
14461 + || sb->s_magic == MINIX_SUPER_MAGIC
14462 + || sb->s_magic == MINIX_SUPER_MAGIC2;
14468 +static inline int au_test_fat(struct super_block *sb __maybe_unused)
14470 +#if IS_ENABLED(CONFIG_FAT_FS)
14471 + return sb->s_magic == MSDOS_SUPER_MAGIC;
14477 +static inline int au_test_msdos(struct super_block *sb)
14479 + return au_test_fat(sb);
14482 +static inline int au_test_vfat(struct super_block *sb)
14484 + return au_test_fat(sb);
14487 +static inline int au_test_securityfs(struct super_block *sb __maybe_unused)
14489 +#ifdef CONFIG_SECURITYFS
14490 + return sb->s_magic == SECURITYFS_MAGIC;
14496 +static inline int au_test_squashfs(struct super_block *sb __maybe_unused)
14498 +#if IS_ENABLED(CONFIG_SQUASHFS)
14499 + return sb->s_magic == SQUASHFS_MAGIC;
14505 +static inline int au_test_btrfs(struct super_block *sb __maybe_unused)
14507 +#if IS_ENABLED(CONFIG_BTRFS_FS)
14508 + return sb->s_magic == BTRFS_SUPER_MAGIC;
14514 +static inline int au_test_xenfs(struct super_block *sb __maybe_unused)
14516 +#if IS_ENABLED(CONFIG_XENFS)
14517 + return sb->s_magic == XENFS_SUPER_MAGIC;
14523 +static inline int au_test_debugfs(struct super_block *sb __maybe_unused)
14525 +#ifdef CONFIG_DEBUG_FS
14526 + return sb->s_magic == DEBUGFS_MAGIC;
14532 +static inline int au_test_nilfs(struct super_block *sb __maybe_unused)
14534 +#if IS_ENABLED(CONFIG_NILFS)
14535 + return sb->s_magic == NILFS_SUPER_MAGIC;
14541 +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused)
14543 +#if IS_ENABLED(CONFIG_HFSPLUS_FS)
14544 + return sb->s_magic == HFSPLUS_SUPER_MAGIC;
14550 +/* ---------------------------------------------------------------------- */
14552 + * they can't be an aufs branch.
14554 +static inline int au_test_fs_unsuppoted(struct super_block *sb)
14557 +#ifndef CONFIG_AUFS_BR_RAMFS
14558 + au_test_ramfs(sb) ||
14560 + au_test_procfs(sb)
14561 + || au_test_sysfs(sb)
14562 + || au_test_configfs(sb)
14563 + || au_test_debugfs(sb)
14564 + || au_test_securityfs(sb)
14565 + || au_test_xenfs(sb)
14566 + || au_test_ecryptfs(sb)
14567 + /* || !strcmp(au_sbtype(sb), "unionfs") */
14568 + || au_test_aufs(sb); /* will be supported in next version */
14571 +static inline int au_test_fs_remote(struct super_block *sb)
14573 + return !au_test_tmpfs(sb)
14574 +#ifdef CONFIG_AUFS_BR_RAMFS
14575 + && !au_test_ramfs(sb)
14577 + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV);
14580 +/* ---------------------------------------------------------------------- */
14583 + * Note: these functions (below) are created after reading ->getattr() in all
14584 + * filesystems under linux/fs. it means we have to do so in every update...
14588 + * some filesystems require getattr to refresh the inode attributes before
14590 + * in most cases, we can rely on the inode attribute in NFS (or every remote fs)
14591 + * and leave the work for d_revalidate()
14593 +static inline int au_test_fs_refresh_iattr(struct super_block *sb)
14595 + return au_test_nfs(sb)
14596 + || au_test_fuse(sb)
14597 + /* || au_test_btrfs(sb) */ /* untested */
14602 + * filesystems which don't maintain i_size or i_blocks.
14604 +static inline int au_test_fs_bad_iattr_size(struct super_block *sb)
14606 + return au_test_xfs(sb)
14607 + || au_test_btrfs(sb)
14608 + || au_test_ubifs(sb)
14609 + || au_test_hfsplus(sb) /* maintained, but incorrect */
14610 + /* || au_test_minix(sb) */ /* untested */
14615 + * filesystems which don't store the correct value in some of their inode
14618 +static inline int au_test_fs_bad_iattr(struct super_block *sb)
14620 + return au_test_fs_bad_iattr_size(sb)
14621 + || au_test_fat(sb)
14622 + || au_test_msdos(sb)
14623 + || au_test_vfat(sb);
14626 +/* they don't check i_nlink in link(2) */
14627 +static inline int au_test_fs_no_limit_nlink(struct super_block *sb)
14629 + return au_test_tmpfs(sb)
14630 +#ifdef CONFIG_AUFS_BR_RAMFS
14631 + || au_test_ramfs(sb)
14633 + || au_test_ubifs(sb)
14634 + || au_test_hfsplus(sb);
14638 + * filesystems which sets S_NOATIME and S_NOCMTIME.
14640 +static inline int au_test_fs_notime(struct super_block *sb)
14642 + return au_test_nfs(sb)
14643 + || au_test_fuse(sb)
14644 + || au_test_ubifs(sb)
14648 +/* temporary support for i#1 in cramfs */
14649 +static inline int au_test_fs_unique_ino(struct inode *inode)
14651 + if (au_test_cramfs(inode->i_sb))
14652 + return inode->i_ino != 1;
14656 +/* ---------------------------------------------------------------------- */
14659 + * the filesystem where the xino files placed must support i/o after unlink and
14660 + * maintain i_size and i_blocks.
14662 +static inline int au_test_fs_bad_xino(struct super_block *sb)
14664 + return au_test_fs_remote(sb)
14665 + || au_test_fs_bad_iattr_size(sb)
14666 + /* don't want unnecessary work for xino */
14667 + || au_test_aufs(sb)
14668 + || au_test_ecryptfs(sb)
14669 + || au_test_nilfs(sb);
14672 +static inline int au_test_fs_trunc_xino(struct super_block *sb)
14674 + return au_test_tmpfs(sb)
14675 + || au_test_ramfs(sb);
14679 + * test if the @sb is real-readonly.
14681 +static inline int au_test_fs_rr(struct super_block *sb)
14683 + return au_test_squashfs(sb)
14684 + || au_test_iso9660(sb)
14685 + || au_test_cramfs(sb)
14686 + || au_test_romfs(sb);
14690 + * test if the @inode is nfs with 'noacl' option
14691 + * NFS always sets MS_POSIXACL regardless its mount option 'noacl.'
14693 +static inline int au_test_nfs_noacl(struct inode *inode)
14695 + return au_test_nfs(inode->i_sb)
14696 + /* && IS_POSIXACL(inode) */
14697 + && !nfs_server_capable(inode, NFS_CAP_ACLS);
14700 +#endif /* __KERNEL__ */
14701 +#endif /* __AUFS_FSTYPE_H__ */
14702 diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c
14703 --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100
14704 +++ linux/fs/aufs/hfsnotify.c 2016-10-09 16:55:36.492701639 +0200
14707 + * Copyright (C) 2005-2016 Junjiro R. Okajima
14709 + * This program, aufs is free software; you can redistribute it and/or modify
14710 + * it under the terms of the GNU General Public License as published by
14711 + * the Free Software Foundation; either version 2 of the License, or
14712 + * (at your option) any later version.
14714 + * This program is distributed in the hope that it will be useful,
14715 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
14716 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14717 + * GNU General Public License for more details.
14719 + * You should have received a copy of the GNU General Public License
14720 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
14724 + * fsnotify for the lower directories
14729 +/* FS_IN_IGNORED is unnecessary */
14730 +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE
14731 + | FS_CREATE | FS_EVENT_ON_CHILD);
14732 +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq);
14733 +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0);
14735 +static void au_hfsn_free_mark(struct fsnotify_mark *mark)
14737 + struct au_hnotify *hn = container_of(mark, struct au_hnotify,
14739 + /* AuDbg("here\n"); */
14740 + au_cache_dfree_hnotify(hn);
14741 + smp_mb__before_atomic();
14742 + if (atomic64_dec_and_test(&au_hfsn_ifree))
14743 + wake_up(&au_hfsn_wq);
14746 +static int au_hfsn_alloc(struct au_hinode *hinode)
14749 + struct au_hnotify *hn;
14750 + struct super_block *sb;
14751 + struct au_branch *br;
14752 + struct fsnotify_mark *mark;
14753 + aufs_bindex_t bindex;
14755 + hn = hinode->hi_notify;
14756 + sb = hn->hn_aufs_inode->i_sb;
14757 + bindex = au_br_index(sb, hinode->hi_id);
14758 + br = au_sbr(sb, bindex);
14759 + AuDebugOn(!br->br_hfsn);
14761 + mark = &hn->hn_mark;
14762 + fsnotify_init_mark(mark, au_hfsn_free_mark);
14763 + mark->mask = AuHfsnMask;
14765 + * by udba rename or rmdir, aufs assign a new inode to the known
14766 + * h_inode, so specify 1 to allow dups.
14769 + err = fsnotify_add_mark(mark, br->br_hfsn->hfsn_group, hinode->hi_inode,
14770 + /*mnt*/NULL, /*allow_dups*/1);
14776 +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn)
14778 + struct fsnotify_mark *mark;
14779 + unsigned long long ull;
14780 + struct fsnotify_group *group;
14782 + ull = atomic64_inc_return(&au_hfsn_ifree);
14785 + mark = &hn->hn_mark;
14786 + spin_lock(&mark->lock);
14787 + group = mark->group;
14788 + fsnotify_get_group(group);
14789 + spin_unlock(&mark->lock);
14791 + fsnotify_destroy_mark(mark, group);
14792 + fsnotify_put_mark(mark);
14793 + fsnotify_put_group(group);
14796 + /* free hn by myself */
14800 +/* ---------------------------------------------------------------------- */
14802 +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set)
14804 + struct fsnotify_mark *mark;
14806 + mark = &hinode->hi_notify->hn_mark;
14807 + spin_lock(&mark->lock);
14809 + AuDebugOn(mark->mask & AuHfsnMask);
14810 + mark->mask |= AuHfsnMask;
14812 + AuDebugOn(!(mark->mask & AuHfsnMask));
14813 + mark->mask &= ~AuHfsnMask;
14815 + spin_unlock(&mark->lock);
14816 + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */
14819 +/* ---------------------------------------------------------------------- */
14821 +/* #define AuDbgHnotify */
14822 +#ifdef AuDbgHnotify
14823 +static char *au_hfsn_name(u32 mask)
14825 +#ifdef CONFIG_AUFS_DEBUG
14826 +#define test_ret(flag) \
14828 + if (mask & flag) \
14831 + test_ret(FS_ACCESS);
14832 + test_ret(FS_MODIFY);
14833 + test_ret(FS_ATTRIB);
14834 + test_ret(FS_CLOSE_WRITE);
14835 + test_ret(FS_CLOSE_NOWRITE);
14836 + test_ret(FS_OPEN);
14837 + test_ret(FS_MOVED_FROM);
14838 + test_ret(FS_MOVED_TO);
14839 + test_ret(FS_CREATE);
14840 + test_ret(FS_DELETE);
14841 + test_ret(FS_DELETE_SELF);
14842 + test_ret(FS_MOVE_SELF);
14843 + test_ret(FS_UNMOUNT);
14844 + test_ret(FS_Q_OVERFLOW);
14845 + test_ret(FS_IN_IGNORED);
14846 + test_ret(FS_ISDIR);
14847 + test_ret(FS_IN_ONESHOT);
14848 + test_ret(FS_EVENT_ON_CHILD);
14857 +/* ---------------------------------------------------------------------- */
14859 +static void au_hfsn_free_group(struct fsnotify_group *group)
14861 + struct au_br_hfsnotify *hfsn = group->private;
14863 + /* AuDbg("here\n"); */
14864 + au_delayed_kfree(hfsn);
14867 +static int au_hfsn_handle_event(struct fsnotify_group *group,
14868 + struct inode *inode,
14869 + struct fsnotify_mark *inode_mark,
14870 + struct fsnotify_mark *vfsmount_mark,
14871 + u32 mask, void *data, int data_type,
14872 + const unsigned char *file_name, u32 cookie)
14875 + struct au_hnotify *hnotify;
14876 + struct inode *h_dir, *h_inode;
14877 + struct qstr h_child_qstr = QSTR_INIT(file_name, strlen(file_name));
14879 + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE);
14882 + /* if FS_UNMOUNT happens, there must be another bug */
14883 + AuDebugOn(mask & FS_UNMOUNT);
14884 + if (mask & (FS_IN_IGNORED | FS_UNMOUNT))
14889 +#ifdef AuDbgHnotify
14891 + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1
14892 + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) {
14893 + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n",
14894 + h_dir->i_ino, mask, au_hfsn_name(mask),
14895 + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0);
14896 + /* WARN_ON(1); */
14901 + AuDebugOn(!inode_mark);
14902 + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark);
14903 + err = au_hnotify(h_dir, hnotify, mask, &h_child_qstr, h_inode);
14909 +static struct fsnotify_ops au_hfsn_ops = {
14910 + .handle_event = au_hfsn_handle_event,
14911 + .free_group_priv = au_hfsn_free_group
14914 +/* ---------------------------------------------------------------------- */
14916 +static void au_hfsn_fin_br(struct au_branch *br)
14918 + struct au_br_hfsnotify *hfsn;
14920 + hfsn = br->br_hfsn;
14923 + fsnotify_put_group(hfsn->hfsn_group);
14928 +static int au_hfsn_init_br(struct au_branch *br, int perm)
14931 + struct fsnotify_group *group;
14932 + struct au_br_hfsnotify *hfsn;
14935 + br->br_hfsn = NULL;
14936 + if (!au_br_hnotifyable(perm))
14940 + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS);
14941 + if (unlikely(!hfsn))
14945 + group = fsnotify_alloc_group(&au_hfsn_ops);
14946 + if (IS_ERR(group)) {
14947 + err = PTR_ERR(group);
14948 + pr_err("fsnotify_alloc_group() failed, %d\n", err);
14952 + group->private = hfsn;
14953 + hfsn->hfsn_group = group;
14954 + br->br_hfsn = hfsn;
14955 + goto out; /* success */
14958 + au_delayed_kfree(hfsn);
14963 +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm)
14968 + if (!br->br_hfsn)
14969 + err = au_hfsn_init_br(br, perm);
14974 +/* ---------------------------------------------------------------------- */
14976 +static void au_hfsn_fin(void)
14978 + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree));
14979 + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree));
14982 +const struct au_hnotify_op au_hnotify_op = {
14983 + .ctl = au_hfsn_ctl,
14984 + .alloc = au_hfsn_alloc,
14985 + .free = au_hfsn_free,
14987 + .fin = au_hfsn_fin,
14989 + .reset_br = au_hfsn_reset_br,
14990 + .fin_br = au_hfsn_fin_br,
14991 + .init_br = au_hfsn_init_br
14993 diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c
14994 --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100
14995 +++ linux/fs/aufs/hfsplus.c 2016-10-09 16:55:36.492701639 +0200
14998 + * Copyright (C) 2010-2016 Junjiro R. Okajima
15000 + * This program, aufs is free software; you can redistribute it and/or modify
15001 + * it under the terms of the GNU General Public License as published by
15002 + * the Free Software Foundation; either version 2 of the License, or
15003 + * (at your option) any later version.
15005 + * This program is distributed in the hope that it will be useful,
15006 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15007 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15008 + * GNU General Public License for more details.
15010 + * You should have received a copy of the GNU General Public License
15011 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15015 + * special support for filesystems which aqucires an inode mutex
15016 + * at final closing a file, eg, hfsplus.
15018 + * This trick is very simple and stupid, just to open the file before really
15019 + * neceeary open to tell hfsplus that this is not the final closing.
15020 + * The caller should call au_h_open_pre() after acquiring the inode mutex,
15021 + * and au_h_open_post() after releasing it.
15026 +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex,
15029 + struct file *h_file;
15030 + struct dentry *h_dentry;
15032 + h_dentry = au_h_dptr(dentry, bindex);
15033 + AuDebugOn(!h_dentry);
15034 + AuDebugOn(d_is_negative(h_dentry));
15037 + if (au_test_hfsplus(h_dentry->d_sb)
15038 + && d_is_reg(h_dentry))
15039 + h_file = au_h_open(dentry, bindex,
15040 + O_RDONLY | O_NOATIME | O_LARGEFILE,
15041 + /*file*/NULL, force_wr);
15045 +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex,
15046 + struct file *h_file)
15050 + au_sbr_put(dentry->d_sb, bindex);
15053 diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c
15054 --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100
15055 +++ linux/fs/aufs/hnotify.c 2016-10-09 16:55:36.492701639 +0200
15058 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15060 + * This program, aufs is free software; you can redistribute it and/or modify
15061 + * it under the terms of the GNU General Public License as published by
15062 + * the Free Software Foundation; either version 2 of the License, or
15063 + * (at your option) any later version.
15065 + * This program is distributed in the hope that it will be useful,
15066 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15067 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15068 + * GNU General Public License for more details.
15070 + * You should have received a copy of the GNU General Public License
15071 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15075 + * abstraction to notify the direct changes on lower directories
15080 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode)
15083 + struct au_hnotify *hn;
15086 + hn = au_cache_alloc_hnotify();
15088 + hn->hn_aufs_inode = inode;
15089 + hinode->hi_notify = hn;
15090 + err = au_hnotify_op.alloc(hinode);
15092 + if (unlikely(err)) {
15093 + hinode->hi_notify = NULL;
15094 + au_cache_dfree_hnotify(hn);
15096 + * The upper dir was removed by udba, but the same named
15097 + * dir left. In this case, aufs assignes a new inode
15098 + * number and set the monitor again.
15099 + * For the lower dir, the old monitnor is still left.
15101 + if (err == -EEXIST)
15110 +void au_hn_free(struct au_hinode *hinode)
15112 + struct au_hnotify *hn;
15114 + hn = hinode->hi_notify;
15116 + hinode->hi_notify = NULL;
15117 + if (au_hnotify_op.free(hinode, hn))
15118 + au_cache_dfree_hnotify(hn);
15122 +/* ---------------------------------------------------------------------- */
15124 +void au_hn_ctl(struct au_hinode *hinode, int do_set)
15126 + if (hinode->hi_notify)
15127 + au_hnotify_op.ctl(hinode, do_set);
15130 +void au_hn_reset(struct inode *inode, unsigned int flags)
15132 + aufs_bindex_t bindex, bbot;
15133 + struct inode *hi;
15134 + struct dentry *iwhdentry;
15136 + bbot = au_ibbot(inode);
15137 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
15138 + hi = au_h_iptr(inode, bindex);
15142 + /* inode_lock_nested(hi, AuLsc_I_CHILD); */
15143 + iwhdentry = au_hi_wh(inode, bindex);
15147 + au_set_h_iptr(inode, bindex, NULL, 0);
15148 + au_set_h_iptr(inode, bindex, au_igrab(hi),
15149 + flags & ~AuHi_XINO);
15152 + /* inode_unlock(hi); */
15156 +/* ---------------------------------------------------------------------- */
15158 +static int hn_xino(struct inode *inode, struct inode *h_inode)
15161 + aufs_bindex_t bindex, bbot, bfound, btop;
15162 + struct inode *h_i;
15165 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15166 + pr_warn("branch root dir was changed\n");
15171 + bbot = au_ibbot(inode);
15172 + btop = au_ibtop(inode);
15173 +#if 0 /* reserved for future use */
15174 + if (bindex == bbot) {
15175 + /* keep this ino in rename case */
15179 + for (bindex = btop; bindex <= bbot; bindex++)
15180 + if (au_h_iptr(inode, bindex) == h_inode) {
15187 + for (bindex = btop; bindex <= bbot; bindex++) {
15188 + h_i = au_h_iptr(inode, bindex);
15192 + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0);
15193 + /* ignore this error */
15194 + /* bad action? */
15197 + /* children inode number will be broken */
15204 +static int hn_gen_tree(struct dentry *dentry)
15206 + int err, i, j, ndentry;
15207 + struct au_dcsub_pages dpages;
15208 + struct au_dpage *dpage;
15209 + struct dentry **dentries;
15211 + err = au_dpages_init(&dpages, GFP_NOFS);
15212 + if (unlikely(err))
15214 + err = au_dcsub_pages(&dpages, dentry, NULL, NULL);
15215 + if (unlikely(err))
15218 + for (i = 0; i < dpages.ndpage; i++) {
15219 + dpage = dpages.dpages + i;
15220 + dentries = dpage->dentries;
15221 + ndentry = dpage->ndentry;
15222 + for (j = 0; j < ndentry; j++) {
15223 + struct dentry *d;
15230 + if (d_really_is_positive(d))
15231 + /* todo: reset children xino?
15232 + cached children only? */
15233 + au_iigen_dec(d_inode(d));
15238 + au_dpages_free(&dpages);
15241 + /* discard children */
15242 + dentry_unhash(dentry);
15250 + * return 0 if processed.
15252 +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode,
15253 + const unsigned int isdir)
15256 + struct dentry *d;
15257 + struct qstr *dname;
15260 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15261 + pr_warn("branch root dir was changed\n");
15267 + AuDebugOn(!name);
15268 + au_iigen_dec(inode);
15269 + spin_lock(&inode->i_lock);
15270 + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) {
15271 + spin_lock(&d->d_lock);
15272 + dname = &d->d_name;
15273 + if (dname->len != nlen
15274 + && memcmp(dname->name, name, nlen)) {
15275 + spin_unlock(&d->d_lock);
15280 + spin_unlock(&d->d_lock);
15283 + spin_unlock(&inode->i_lock);
15285 + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR);
15286 + d = d_find_any_alias(inode);
15288 + au_iigen_dec(inode);
15292 + spin_lock(&d->d_lock);
15293 + dname = &d->d_name;
15294 + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) {
15295 + spin_unlock(&d->d_lock);
15296 + err = hn_gen_tree(d);
15297 + spin_lock(&d->d_lock);
15299 + spin_unlock(&d->d_lock);
15308 +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir)
15312 + if (IS_ROOT(dentry)) {
15313 + pr_warn("branch root dir was changed\n");
15319 + au_digen_dec(dentry);
15320 + if (d_really_is_positive(dentry))
15321 + au_iigen_dec(d_inode(dentry));
15323 + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR);
15324 + if (d_really_is_positive(dentry))
15325 + err = hn_gen_tree(dentry);
15332 +/* ---------------------------------------------------------------------- */
15334 +/* hnotify job flags */
15335 +#define AuHnJob_XINO0 1
15336 +#define AuHnJob_GEN (1 << 1)
15337 +#define AuHnJob_DIRENT (1 << 2)
15338 +#define AuHnJob_ISDIR (1 << 3)
15339 +#define AuHnJob_TRYXINO0 (1 << 4)
15340 +#define AuHnJob_MNTPNT (1 << 5)
15341 +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name)
15342 +#define au_fset_hnjob(flags, name) \
15343 + do { (flags) |= AuHnJob_##name; } while (0)
15344 +#define au_fclr_hnjob(flags, name) \
15345 + do { (flags) &= ~AuHnJob_##name; } while (0)
15353 +struct au_hnotify_args {
15354 + struct inode *h_dir, *dir, *h_child_inode;
15356 + unsigned int flags[AuHnLast];
15357 + unsigned int h_child_nlen;
15358 + char h_child_name[];
15361 +struct hn_job_args {
15362 + unsigned int flags;
15363 + struct inode *inode, *h_inode, *dir, *h_dir;
15364 + struct dentry *dentry;
15369 +static int hn_job(struct hn_job_args *a)
15371 + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR);
15375 + if (au_ftest_hnjob(a->flags, XINO0) && a->inode)
15376 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15378 + if (au_ftest_hnjob(a->flags, TRYXINO0)
15381 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
15382 + if (!a->h_inode->i_nlink
15383 + && !(a->h_inode->i_state & I_LINKABLE))
15384 + hn_xino(a->inode, a->h_inode); /* ignore this error */
15385 + inode_unlock(a->h_inode);
15388 + /* make the generation obsolete */
15389 + if (au_ftest_hnjob(a->flags, GEN)) {
15392 + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode,
15394 + if (e && a->dentry)
15395 + hn_gen_by_name(a->dentry, isdir);
15396 + /* ignore this error */
15399 + /* make dir entries obsolete */
15400 + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) {
15401 + struct au_vdir *vdir;
15403 + vdir = au_ivdir(a->inode);
15405 + vdir->vd_jiffy = 0;
15406 + /* IMustLock(a->inode); */
15407 + /* a->inode->i_version++; */
15410 + /* can do nothing but warn */
15411 + if (au_ftest_hnjob(a->flags, MNTPNT)
15413 + && d_mountpoint(a->dentry))
15414 + pr_warn("mount-point %pd is removed or renamed\n", a->dentry);
15419 +/* ---------------------------------------------------------------------- */
15421 +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen,
15422 + struct inode *dir)
15424 + struct dentry *dentry, *d, *parent;
15425 + struct qstr *dname;
15427 + parent = d_find_any_alias(dir);
15432 + spin_lock(&parent->d_lock);
15433 + list_for_each_entry(d, &parent->d_subdirs, d_child) {
15434 + /* AuDbg("%pd\n", d); */
15435 + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED);
15436 + dname = &d->d_name;
15437 + if (dname->len != nlen || memcmp(dname->name, name, nlen))
15438 + goto cont_unlock;
15442 + goto cont_unlock;
15443 + if (au_dcount(d) > 0) {
15444 + dentry = dget_dlock(d);
15445 + spin_unlock(&d->d_lock);
15450 + spin_unlock(&d->d_lock);
15452 + spin_unlock(&parent->d_lock);
15456 + di_write_lock_child(dentry);
15461 +static struct inode *lookup_wlock_by_ino(struct super_block *sb,
15462 + aufs_bindex_t bindex, ino_t h_ino)
15464 + struct inode *inode;
15469 + err = au_xino_read(sb, bindex, h_ino, &ino);
15471 + inode = ilookup(sb, ino);
15475 + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) {
15476 + pr_warn("wrong root branch\n");
15482 + ii_write_lock_child(inode);
15488 +static void au_hn_bh(void *_args)
15490 + struct au_hnotify_args *a = _args;
15491 + struct super_block *sb;
15492 + aufs_bindex_t bindex, bbot, bfound;
15493 + unsigned char xino, try_iput;
15495 + struct inode *inode;
15497 + struct hn_job_args args;
15498 + struct dentry *dentry;
15499 + struct au_sbinfo *sbinfo;
15501 + AuDebugOn(!_args);
15502 + AuDebugOn(!a->h_dir);
15503 + AuDebugOn(!a->dir);
15504 + AuDebugOn(!a->mask);
15505 + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n",
15506 + a->mask, a->dir->i_ino, a->h_dir->i_ino,
15507 + a->h_child_inode ? a->h_child_inode->i_ino : 0);
15512 + * do not lock a->dir->i_mutex here
15513 + * because of d_revalidate() may cause a deadlock.
15515 + sb = a->dir->i_sb;
15517 + sbinfo = au_sbi(sb);
15518 + AuDebugOn(!sbinfo);
15519 + si_write_lock(sb, AuLock_NOPLMW);
15521 + ii_read_lock_parent(a->dir);
15523 + bbot = au_ibbot(a->dir);
15524 + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++)
15525 + if (au_h_iptr(a->dir, bindex) == a->h_dir) {
15529 + ii_read_unlock(a->dir);
15530 + if (unlikely(bfound < 0))
15533 + xino = !!au_opt_test(au_mntflags(sb), XINO);
15535 + if (a->h_child_inode)
15536 + h_ino = a->h_child_inode->i_ino;
15538 + if (a->h_child_nlen
15539 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN)
15540 + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT)))
15541 + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen,
15544 + if (dentry && d_really_is_positive(dentry))
15545 + inode = d_inode(dentry);
15546 + if (xino && !inode && h_ino
15547 + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0)
15548 + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0)
15549 + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) {
15550 + inode = lookup_wlock_by_ino(sb, bfound, h_ino);
15554 + args.flags = a->flags[AuHn_CHILD];
15555 + args.dentry = dentry;
15556 + args.inode = inode;
15557 + args.h_inode = a->h_child_inode;
15558 + args.dir = a->dir;
15559 + args.h_dir = a->h_dir;
15560 + args.h_name = a->h_child_name;
15561 + args.h_nlen = a->h_child_nlen;
15562 + err = hn_job(&args);
15564 + if (au_di(dentry))
15565 + di_write_unlock(dentry);
15568 + if (inode && try_iput) {
15569 + ii_write_unlock(inode);
15573 + ii_write_lock_parent(a->dir);
15574 + args.flags = a->flags[AuHn_PARENT];
15575 + args.dentry = NULL;
15576 + args.inode = a->dir;
15577 + args.h_inode = a->h_dir;
15579 + args.h_dir = NULL;
15580 + args.h_name = NULL;
15582 + err = hn_job(&args);
15583 + ii_write_unlock(a->dir);
15586 + iput(a->h_child_inode);
15589 + si_write_unlock(sb);
15590 + au_nwt_done(&sbinfo->si_nowait);
15591 + au_delayed_kfree(a);
15594 +/* ---------------------------------------------------------------------- */
15596 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
15597 + struct qstr *h_child_qstr, struct inode *h_child_inode)
15600 + unsigned int flags[AuHnLast], f;
15601 + unsigned char isdir, isroot, wh;
15602 + struct inode *dir;
15603 + struct au_hnotify_args *args;
15604 + char *p, *h_child_name;
15607 + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode);
15608 + dir = igrab(hnotify->hn_aufs_inode);
15612 + isroot = (dir->i_ino == AUFS_ROOT_INO);
15614 + h_child_name = (void *)h_child_qstr->name;
15615 + len = h_child_qstr->len;
15616 + if (h_child_name) {
15617 + if (len > AUFS_WH_PFX_LEN
15618 + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
15619 + h_child_name += AUFS_WH_PFX_LEN;
15620 + len -= AUFS_WH_PFX_LEN;
15626 + if (h_child_inode)
15627 + isdir = !!S_ISDIR(h_child_inode->i_mode);
15628 + flags[AuHn_PARENT] = AuHnJob_ISDIR;
15629 + flags[AuHn_CHILD] = 0;
15631 + flags[AuHn_CHILD] = AuHnJob_ISDIR;
15632 + au_fset_hnjob(flags[AuHn_PARENT], DIRENT);
15633 + au_fset_hnjob(flags[AuHn_CHILD], GEN);
15634 + switch (mask & FS_EVENTS_POSS_ON_CHILD) {
15635 + case FS_MOVED_FROM:
15636 + case FS_MOVED_TO:
15637 + au_fset_hnjob(flags[AuHn_CHILD], XINO0);
15638 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15641 + AuDebugOn(!h_child_name);
15646 + * aufs never be able to get this child inode.
15647 + * revalidation should be in d_revalidate()
15648 + * by checking i_nlink, i_generation or d_unhashed().
15650 + AuDebugOn(!h_child_name);
15651 + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0);
15652 + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT);
15660 + h_child_inode = NULL;
15663 + /* iput() and kfree() will be called in au_hnotify() */
15664 + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS);
15665 + if (unlikely(!args)) {
15666 + AuErr1("no memory\n");
15670 + args->flags[AuHn_PARENT] = flags[AuHn_PARENT];
15671 + args->flags[AuHn_CHILD] = flags[AuHn_CHILD];
15672 + args->mask = mask;
15674 + args->h_dir = igrab(h_dir);
15675 + if (h_child_inode)
15676 + h_child_inode = igrab(h_child_inode); /* can be NULL */
15677 + args->h_child_inode = h_child_inode;
15678 + args->h_child_nlen = len;
15680 + p = (void *)args;
15681 + p += sizeof(*args);
15682 + memcpy(p, h_child_name, len);
15686 + /* NFS fires the event for silly-renamed one from kworker */
15688 + if (!dir->i_nlink
15689 + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE)))
15691 + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f);
15692 + if (unlikely(err)) {
15693 + pr_err("wkq %d\n", err);
15694 + iput(args->h_child_inode);
15695 + iput(args->h_dir);
15697 + au_delayed_kfree(args);
15704 +/* ---------------------------------------------------------------------- */
15706 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm)
15710 + AuDebugOn(!(udba & AuOptMask_UDBA));
15713 + if (au_hnotify_op.reset_br)
15714 + err = au_hnotify_op.reset_br(udba, br, perm);
15719 +int au_hnotify_init_br(struct au_branch *br, int perm)
15724 + if (au_hnotify_op.init_br)
15725 + err = au_hnotify_op.init_br(br, perm);
15730 +void au_hnotify_fin_br(struct au_branch *br)
15732 + if (au_hnotify_op.fin_br)
15733 + au_hnotify_op.fin_br(br);
15736 +static void au_hn_destroy_cache(void)
15738 + struct au_cache *cp;
15740 + flush_delayed_work(&au_dfree.dwork);
15741 + cp = au_dfree.cache + AuCache_HNOTIFY;
15742 + AuDebugOn(!llist_empty(&cp->llist));
15743 + kmem_cache_destroy(cp->cache);
15744 + cp->cache = NULL;
15747 +AU_CACHE_DFREE_FUNC(hnotify, HNOTIFY, hn_lnode);
15749 +int __init au_hnotify_init(void)
15752 + struct au_cache *cp;
15755 + cp = au_dfree.cache + AuCache_HNOTIFY;
15756 + cp->cache = AuCache(au_hnotify);
15759 + if (au_hnotify_op.init)
15760 + err = au_hnotify_op.init();
15761 + if (unlikely(err))
15762 + au_hn_destroy_cache();
15768 +void au_hnotify_fin(void)
15770 + struct au_cache *cp;
15772 + if (au_hnotify_op.fin)
15773 + au_hnotify_op.fin();
15775 + /* cf. au_cache_fin() */
15776 + cp = au_dfree.cache + AuCache_HNOTIFY;
15778 + au_hn_destroy_cache();
15780 diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c
15781 --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100
15782 +++ linux/fs/aufs/iinfo.c 2016-10-09 16:55:38.889431135 +0200
15785 + * Copyright (C) 2005-2016 Junjiro R. Okajima
15787 + * This program, aufs is free software; you can redistribute it and/or modify
15788 + * it under the terms of the GNU General Public License as published by
15789 + * the Free Software Foundation; either version 2 of the License, or
15790 + * (at your option) any later version.
15792 + * This program is distributed in the hope that it will be useful,
15793 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
15794 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15795 + * GNU General Public License for more details.
15797 + * You should have received a copy of the GNU General Public License
15798 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
15802 + * inode private data
15807 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex)
15809 + struct inode *h_inode;
15810 + struct au_hinode *hinode;
15812 + IiMustAnyLock(inode);
15814 + hinode = au_hinode(au_ii(inode), bindex);
15815 + h_inode = hinode->hi_inode;
15816 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15820 +/* todo: hard/soft set? */
15821 +void au_hiput(struct au_hinode *hinode)
15823 + au_hn_free(hinode);
15824 + dput(hinode->hi_whdentry);
15825 + iput(hinode->hi_inode);
15828 +unsigned int au_hi_flags(struct inode *inode, int isdir)
15830 + unsigned int flags;
15831 + const unsigned int mnt_flags = au_mntflags(inode->i_sb);
15834 + if (au_opt_test(mnt_flags, XINO))
15835 + au_fset_hi(flags, XINO);
15836 + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY))
15837 + au_fset_hi(flags, HNOTIFY);
15841 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
15842 + struct inode *h_inode, unsigned int flags)
15844 + struct au_hinode *hinode;
15845 + struct inode *hi;
15846 + struct au_iinfo *iinfo = au_ii(inode);
15848 + IiMustWriteLock(inode);
15850 + hinode = au_hinode(iinfo, bindex);
15851 + hi = hinode->hi_inode;
15852 + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0);
15855 + au_hiput(hinode);
15856 + hinode->hi_inode = h_inode;
15859 + struct super_block *sb = inode->i_sb;
15860 + struct au_branch *br;
15862 + AuDebugOn(inode->i_mode
15863 + && (h_inode->i_mode & S_IFMT)
15864 + != (inode->i_mode & S_IFMT));
15865 + if (bindex == iinfo->ii_btop)
15866 + au_cpup_igen(inode, h_inode);
15867 + br = au_sbr(sb, bindex);
15868 + hinode->hi_id = br->br_id;
15869 + if (au_ftest_hi(flags, XINO)) {
15870 + err = au_xino_write(sb, bindex, h_inode->i_ino,
15872 + if (unlikely(err))
15873 + AuIOErr1("failed au_xino_write() %d\n", err);
15876 + if (au_ftest_hi(flags, HNOTIFY)
15877 + && au_br_hnotifyable(br->br_perm)) {
15878 + err = au_hn_alloc(hinode, inode);
15879 + if (unlikely(err))
15880 + AuIOErr1("au_hn_alloc() %d\n", err);
15885 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
15886 + struct dentry *h_wh)
15888 + struct au_hinode *hinode;
15890 + IiMustWriteLock(inode);
15892 + hinode = au_hinode(au_ii(inode), bindex);
15893 + AuDebugOn(hinode->hi_whdentry);
15894 + hinode->hi_whdentry = h_wh;
15897 +void au_update_iigen(struct inode *inode, int half)
15899 + struct au_iinfo *iinfo;
15900 + struct au_iigen *iigen;
15901 + unsigned int sigen;
15903 + sigen = au_sigen(inode->i_sb);
15904 + iinfo = au_ii(inode);
15905 + iigen = &iinfo->ii_generation;
15906 + spin_lock(&iigen->ig_spin);
15907 + iigen->ig_generation = sigen;
15909 + au_ig_fset(iigen->ig_flags, HALF_REFRESHED);
15911 + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED);
15912 + spin_unlock(&iigen->ig_spin);
15915 +/* it may be called at remount time, too */
15916 +void au_update_ibrange(struct inode *inode, int do_put_zero)
15918 + struct au_iinfo *iinfo;
15919 + aufs_bindex_t bindex, bbot;
15921 + AuDebugOn(au_is_bad_inode(inode));
15922 + IiMustWriteLock(inode);
15924 + iinfo = au_ii(inode);
15925 + if (do_put_zero && iinfo->ii_btop >= 0) {
15926 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
15928 + struct inode *h_i;
15930 + h_i = au_hinode(iinfo, bindex)->hi_inode;
15933 + && !(h_i->i_state & I_LINKABLE))
15934 + au_set_h_iptr(inode, bindex, NULL, 0);
15938 + iinfo->ii_btop = -1;
15939 + iinfo->ii_bbot = -1;
15940 + bbot = au_sbbot(inode->i_sb);
15941 + for (bindex = 0; bindex <= bbot; bindex++)
15942 + if (au_hinode(iinfo, bindex)->hi_inode) {
15943 + iinfo->ii_btop = bindex;
15946 + if (iinfo->ii_btop >= 0)
15947 + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--)
15948 + if (au_hinode(iinfo, bindex)->hi_inode) {
15949 + iinfo->ii_bbot = bindex;
15952 + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot);
15955 +/* ---------------------------------------------------------------------- */
15957 +void au_icntnr_init_once(void *_c)
15959 + struct au_icntnr *c = _c;
15960 + struct au_iinfo *iinfo = &c->iinfo;
15962 + spin_lock_init(&iinfo->ii_generation.ig_spin);
15963 + au_rw_init(&iinfo->ii_rwsem);
15964 + inode_init_once(&c->vfs_inode);
15967 +void au_hinode_init(struct au_hinode *hinode)
15969 + hinode->hi_inode = NULL;
15970 + hinode->hi_id = -1;
15971 + au_hn_init(hinode);
15972 + hinode->hi_whdentry = NULL;
15975 +int au_iinfo_init(struct inode *inode)
15977 + struct au_iinfo *iinfo;
15978 + struct super_block *sb;
15979 + struct au_hinode *hi;
15982 + sb = inode->i_sb;
15983 + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
15984 + nbr = au_sbbot(sb) + 1;
15985 + if (unlikely(nbr <= 0))
15987 + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS);
15989 + au_ninodes_inc(sb);
15991 + iinfo->ii_hinode = hi;
15992 + for (i = 0; i < nbr; i++, hi++)
15993 + au_hinode_init(hi);
15995 + iinfo->ii_generation.ig_generation = au_sigen(sb);
15996 + iinfo->ii_btop = -1;
15997 + iinfo->ii_bbot = -1;
15998 + iinfo->ii_vdir = NULL;
16004 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink)
16007 + struct au_hinode *hip;
16009 + AuRwMustWriteLock(&iinfo->ii_rwsem);
16012 + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS,
16015 + iinfo->ii_hinode = hip;
16016 + i = iinfo->ii_bbot + 1;
16018 + for (; i < nbr; i++, hip++)
16019 + au_hinode_init(hip);
16026 +void au_iinfo_fin(struct inode *inode)
16028 + struct au_iinfo *iinfo;
16029 + struct au_hinode *hi;
16030 + struct super_block *sb;
16031 + aufs_bindex_t bindex, bbot;
16032 + const unsigned char unlinked = !inode->i_nlink;
16034 + AuDebugOn(au_is_bad_inode(inode));
16036 + sb = inode->i_sb;
16037 + au_ninodes_dec(sb);
16038 + if (si_pid_test(sb))
16039 + au_xino_delete_inode(inode, unlinked);
16042 + * it is safe to hide the dependency between sbinfo and
16046 + si_noflush_read_lock(sb);
16047 + au_xino_delete_inode(inode, unlinked);
16048 + si_read_unlock(sb);
16052 + iinfo = au_ii(inode);
16053 + if (iinfo->ii_vdir)
16054 + au_vdir_free(iinfo->ii_vdir, /*atonce*/0);
16056 + bindex = iinfo->ii_btop;
16057 + if (bindex >= 0) {
16058 + hi = au_hinode(iinfo, bindex);
16059 + bbot = iinfo->ii_bbot;
16060 + while (bindex++ <= bbot) {
16061 + if (hi->hi_inode)
16066 + au_delayed_kfree(iinfo->ii_hinode);
16067 + AuRwDestroy(&iinfo->ii_rwsem);
16069 diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c
16070 --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100
16071 +++ linux/fs/aufs/inode.c 2016-10-09 16:55:38.889431135 +0200
16074 + * Copyright (C) 2005-2016 Junjiro R. Okajima
16076 + * This program, aufs is free software; you can redistribute it and/or modify
16077 + * it under the terms of the GNU General Public License as published by
16078 + * the Free Software Foundation; either version 2 of the License, or
16079 + * (at your option) any later version.
16081 + * This program is distributed in the hope that it will be useful,
16082 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16083 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16084 + * GNU General Public License for more details.
16086 + * You should have received a copy of the GNU General Public License
16087 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16091 + * inode functions
16096 +struct inode *au_igrab(struct inode *inode)
16099 + AuDebugOn(!atomic_read(&inode->i_count));
16105 +static void au_refresh_hinode_attr(struct inode *inode, int do_version)
16107 + au_cpup_attr_all(inode, /*force*/0);
16108 + au_update_iigen(inode, /*half*/1);
16110 + inode->i_version++;
16113 +static int au_ii_refresh(struct inode *inode, int *update)
16117 + aufs_bindex_t bindex, new_bindex;
16118 + struct super_block *sb;
16119 + struct au_iinfo *iinfo;
16120 + struct au_hinode *p, *q, tmp;
16122 + AuDebugOn(au_is_bad_inode(inode));
16123 + IiMustWriteLock(inode);
16126 + sb = inode->i_sb;
16127 + nbr = au_sbbot(sb) + 1;
16128 + type = inode->i_mode & S_IFMT;
16129 + iinfo = au_ii(inode);
16130 + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0);
16131 + if (unlikely(err))
16134 + AuDebugOn(iinfo->ii_btop < 0);
16135 + p = au_hinode(iinfo, iinfo->ii_btop);
16136 + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot;
16138 + if (!p->hi_inode)
16141 + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT));
16142 + new_bindex = au_br_index(sb, p->hi_id);
16143 + if (new_bindex == bindex)
16146 + if (new_bindex < 0) {
16149 + p->hi_inode = NULL;
16153 + if (new_bindex < iinfo->ii_btop)
16154 + iinfo->ii_btop = new_bindex;
16155 + if (iinfo->ii_bbot < new_bindex)
16156 + iinfo->ii_bbot = new_bindex;
16157 + /* swap two lower inode, and loop again */
16158 + q = au_hinode(iinfo, new_bindex);
16162 + if (tmp.hi_inode) {
16167 + au_update_ibrange(inode, /*do_put_zero*/0);
16168 + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */
16169 + e = au_dy_irefresh(inode);
16170 + if (unlikely(e && !err))
16178 +void au_refresh_iop(struct inode *inode, int force_getattr)
16181 + struct au_sbinfo *sbi = au_sbi(inode->i_sb);
16182 + const struct inode_operations *iop
16183 + = force_getattr ? aufs_iop : sbi->si_iop_array;
16185 + if (inode->i_op == iop)
16188 + switch (inode->i_mode & S_IFMT) {
16190 + type = AuIop_DIR;
16193 + type = AuIop_SYMLINK;
16196 + type = AuIop_OTHER;
16200 + inode->i_op = iop + type;
16201 + /* unnecessary smp_wmb() */
16204 +int au_refresh_hinode_self(struct inode *inode)
16208 + err = au_ii_refresh(inode, &update);
16210 + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode));
16216 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry)
16218 + int err, e, update;
16219 + unsigned int flags;
16221 + aufs_bindex_t bindex, bbot;
16222 + unsigned char isdir;
16223 + struct au_hinode *p;
16224 + struct au_iinfo *iinfo;
16226 + err = au_ii_refresh(inode, &update);
16227 + if (unlikely(err))
16231 + iinfo = au_ii(inode);
16232 + p = au_hinode(iinfo, iinfo->ii_btop);
16233 + mode = (inode->i_mode & S_IFMT);
16234 + isdir = S_ISDIR(mode);
16235 + flags = au_hi_flags(inode, isdir);
16236 + bbot = au_dbbot(dentry);
16237 + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) {
16238 + struct inode *h_i, *h_inode;
16239 + struct dentry *h_d;
16241 + h_d = au_h_dptr(dentry, bindex);
16242 + if (!h_d || d_is_negative(h_d))
16245 + h_inode = d_inode(h_d);
16246 + AuDebugOn(mode != (h_inode->i_mode & S_IFMT));
16247 + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) {
16248 + h_i = au_h_iptr(inode, bindex);
16250 + if (h_i == h_inode)
16256 + if (bindex < iinfo->ii_btop)
16257 + iinfo->ii_btop = bindex;
16258 + if (iinfo->ii_bbot < bindex)
16259 + iinfo->ii_bbot = bindex;
16260 + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags);
16263 + au_update_ibrange(inode, /*do_put_zero*/0);
16264 + e = au_dy_irefresh(inode);
16265 + if (unlikely(e && !err))
16268 + au_refresh_hinode_attr(inode, update && isdir);
16275 +static int set_inode(struct inode *inode, struct dentry *dentry)
16278 + unsigned int flags;
16280 + aufs_bindex_t bindex, btop, btail;
16281 + unsigned char isdir;
16282 + struct dentry *h_dentry;
16283 + struct inode *h_inode;
16284 + struct au_iinfo *iinfo;
16285 + struct inode_operations *iop;
16287 + IiMustWriteLock(inode);
16291 + iop = au_sbi(inode->i_sb)->si_iop_array;
16292 + btop = au_dbtop(dentry);
16293 + h_dentry = au_h_dptr(dentry, btop);
16294 + h_inode = d_inode(h_dentry);
16295 + mode = h_inode->i_mode;
16296 + switch (mode & S_IFMT) {
16298 + btail = au_dbtail(dentry);
16299 + inode->i_op = iop + AuIop_OTHER;
16300 + inode->i_fop = &aufs_file_fop;
16301 + err = au_dy_iaop(inode, btop, h_inode);
16302 + if (unlikely(err))
16307 + btail = au_dbtaildir(dentry);
16308 + inode->i_op = iop + AuIop_DIR;
16309 + inode->i_fop = &aufs_dir_fop;
16312 + btail = au_dbtail(dentry);
16313 + inode->i_op = iop + AuIop_SYMLINK;
16319 + btail = au_dbtail(dentry);
16320 + inode->i_op = iop + AuIop_OTHER;
16321 + init_special_inode(inode, mode, h_inode->i_rdev);
16324 + AuIOErr("Unknown file type 0%o\n", mode);
16329 + /* do not set hnotify for whiteouted dirs (SHWH mode) */
16330 + flags = au_hi_flags(inode, isdir);
16331 + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)
16332 + && au_ftest_hi(flags, HNOTIFY)
16333 + && dentry->d_name.len > AUFS_WH_PFX_LEN
16334 + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))
16335 + au_fclr_hi(flags, HNOTIFY);
16336 + iinfo = au_ii(inode);
16337 + iinfo->ii_btop = btop;
16338 + iinfo->ii_bbot = btail;
16339 + for (bindex = btop; bindex <= btail; bindex++) {
16340 + h_dentry = au_h_dptr(dentry, bindex);
16342 + au_set_h_iptr(inode, bindex,
16343 + au_igrab(d_inode(h_dentry)), flags);
16345 + au_cpup_attr_all(inode, /*force*/1);
16347 + * to force calling aufs_get_acl() every time,
16348 + * do not call cache_no_acl() for aufs inode.
16356 + * successful returns with iinfo write_locked
16358 + * zero: success, matched
16359 + * plus: no error, but unmatched
16361 +static int reval_inode(struct inode *inode, struct dentry *dentry)
16364 + unsigned int gen, igflags;
16365 + aufs_bindex_t bindex, bbot;
16366 + struct inode *h_inode, *h_dinode;
16367 + struct dentry *h_dentry;
16370 + * before this function, if aufs got any iinfo lock, it must be only
16371 + * one, the parent dir.
16372 + * it can happen by UDBA and the obsoleted inode number.
16375 + if (unlikely(inode->i_ino == parent_ino(dentry)))
16379 + ii_write_lock_new_child(inode);
16380 + h_dentry = au_h_dptr(dentry, au_dbtop(dentry));
16381 + h_dinode = d_inode(h_dentry);
16382 + bbot = au_ibbot(inode);
16383 + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) {
16384 + h_inode = au_h_iptr(inode, bindex);
16385 + if (!h_inode || h_inode != h_dinode)
16389 + gen = au_iigen(inode, &igflags);
16390 + if (gen == au_digen(dentry)
16391 + && !au_ig_ftest(igflags, HALF_REFRESHED))
16394 + /* fully refresh inode using dentry */
16395 + err = au_refresh_hinode(inode, dentry);
16397 + au_update_iigen(inode, /*half*/0);
16401 + if (unlikely(err))
16402 + ii_write_unlock(inode);
16407 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16408 + unsigned int d_type, ino_t *ino)
16411 + struct mutex *mtx;
16413 + /* prevent hardlinked inode number from race condition */
16415 + if (d_type != DT_DIR) {
16416 + mtx = &au_sbr(sb, bindex)->br_xino.xi_nondir_mtx;
16419 + err = au_xino_read(sb, bindex, h_ino, ino);
16420 + if (unlikely(err))
16425 + *ino = au_xino_new_ino(sb);
16426 + if (unlikely(!*ino))
16428 + err = au_xino_write(sb, bindex, h_ino, *ino);
16429 + if (unlikely(err))
16435 + mutex_unlock(mtx);
16439 +/* successful returns with iinfo write_locked */
16440 +/* todo: return with unlocked? */
16441 +struct inode *au_new_inode(struct dentry *dentry, int must_new)
16443 + struct inode *inode, *h_inode;
16444 + struct dentry *h_dentry;
16445 + struct super_block *sb;
16446 + struct mutex *mtx;
16447 + ino_t h_ino, ino;
16449 + aufs_bindex_t btop;
16451 + sb = dentry->d_sb;
16452 + btop = au_dbtop(dentry);
16453 + h_dentry = au_h_dptr(dentry, btop);
16454 + h_inode = d_inode(h_dentry);
16455 + h_ino = h_inode->i_ino;
16458 + * stop 'race'-ing between hardlinks under different
16462 + if (!d_is_dir(h_dentry))
16463 + mtx = &au_sbr(sb, btop)->br_xino.xi_nondir_mtx;
16468 + err = au_xino_read(sb, btop, h_ino, &ino);
16469 + inode = ERR_PTR(err);
16470 + if (unlikely(err))
16474 + ino = au_xino_new_ino(sb);
16475 + if (unlikely(!ino)) {
16476 + inode = ERR_PTR(-EIO);
16481 + AuDbg("i%lu\n", (unsigned long)ino);
16482 + inode = au_iget_locked(sb, ino);
16483 + err = PTR_ERR(inode);
16484 + if (IS_ERR(inode))
16487 + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW));
16488 + if (inode->i_state & I_NEW) {
16489 + ii_write_lock_new_child(inode);
16490 + err = set_inode(inode, dentry);
16492 + unlock_new_inode(inode);
16493 + goto out; /* success */
16497 + * iget_failed() calls iput(), but we need to call
16498 + * ii_write_unlock() after iget_failed(). so dirty hack for
16501 + atomic_inc(&inode->i_count);
16502 + iget_failed(inode);
16503 + ii_write_unlock(inode);
16504 + au_xino_write(sb, btop, h_ino, /*ino*/0);
16505 + /* ignore this error */
16507 + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) {
16509 + * horrible race condition between lookup, readdir and copyup
16510 + * (or something).
16513 + mutex_unlock(mtx);
16514 + err = reval_inode(inode, dentry);
16515 + if (unlikely(err < 0)) {
16522 + goto out; /* success */
16527 + if (unlikely(au_test_fs_unique_ino(h_inode)))
16528 + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir,"
16529 + " b%d, %s, %pd, hi%lu, i%lu.\n",
16530 + btop, au_sbtype(h_dentry->d_sb), dentry,
16531 + (unsigned long)h_ino, (unsigned long)ino);
16533 + err = au_xino_write(sb, btop, h_ino, /*ino*/0);
16537 + mutex_unlock(mtx);
16543 + inode = ERR_PTR(err);
16546 + mutex_unlock(mtx);
16550 +/* ---------------------------------------------------------------------- */
16552 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16553 + struct inode *inode)
16556 + struct inode *hi;
16558 + err = au_br_rdonly(au_sbr(sb, bindex));
16560 + /* pseudo-link after flushed may happen out of bounds */
16563 + && au_ibtop(inode) <= bindex
16564 + && bindex <= au_ibbot(inode)) {
16566 + * permission check is unnecessary since vfsub routine
16567 + * will be called later
16569 + hi = au_h_iptr(inode, bindex);
16571 + err = IS_IMMUTABLE(hi) ? -EROFS : 0;
16577 +int au_test_h_perm(struct inode *h_inode, int mask)
16579 + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID))
16581 + return inode_permission(h_inode, mask);
16584 +int au_test_h_perm_sio(struct inode *h_inode, int mask)
16586 + if (au_test_nfs(h_inode->i_sb)
16587 + && (mask & MAY_WRITE)
16588 + && S_ISDIR(h_inode->i_mode))
16589 + mask |= MAY_READ; /* force permission check */
16590 + return au_test_h_perm(h_inode, mask);
16592 diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h
16593 --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100
16594 +++ linux/fs/aufs/inode.h 2016-12-17 12:28:17.595211562 +0100
16597 + * Copyright (C) 2005-2016 Junjiro R. Okajima
16599 + * This program, aufs is free software; you can redistribute it and/or modify
16600 + * it under the terms of the GNU General Public License as published by
16601 + * the Free Software Foundation; either version 2 of the License, or
16602 + * (at your option) any later version.
16604 + * This program is distributed in the hope that it will be useful,
16605 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
16606 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16607 + * GNU General Public License for more details.
16609 + * You should have received a copy of the GNU General Public License
16610 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
16614 + * inode operations
16617 +#ifndef __AUFS_INODE_H__
16618 +#define __AUFS_INODE_H__
16622 +#include <linux/fsnotify.h>
16623 +#include "rwsem.h"
16627 +struct au_hnotify {
16628 +#ifdef CONFIG_AUFS_HNOTIFY
16629 +#ifdef CONFIG_AUFS_HFSNOTIFY
16630 + /* never use fsnotify_add_vfsmount_mark() */
16631 + struct fsnotify_mark hn_mark;
16634 + struct inode *hn_aufs_inode; /* no get/put */
16635 + struct llist_node hn_lnode; /* delayed free */
16638 +} ____cacheline_aligned_in_smp;
16640 +struct au_hinode {
16641 + struct inode *hi_inode;
16642 + aufs_bindex_t hi_id;
16643 +#ifdef CONFIG_AUFS_HNOTIFY
16644 + struct au_hnotify *hi_notify;
16647 + /* reference to the copied-up whiteout with get/put */
16648 + struct dentry *hi_whdentry;
16652 +#define AuIG_HALF_REFRESHED 1
16653 +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name)
16654 +#define au_ig_fset(flags, name) \
16655 + do { (flags) |= AuIG_##name; } while (0)
16656 +#define au_ig_fclr(flags, name) \
16657 + do { (flags) &= ~AuIG_##name; } while (0)
16660 + spinlock_t ig_spin;
16661 + __u32 ig_generation, ig_flags;
16666 + struct au_iigen ii_generation;
16667 + struct super_block *ii_hsb1; /* no get/put */
16669 + struct au_rwsem ii_rwsem;
16670 + aufs_bindex_t ii_btop, ii_bbot;
16672 + struct au_hinode *ii_hinode;
16673 + struct au_vdir *ii_vdir;
16676 +struct au_icntnr {
16677 + struct au_iinfo iinfo;
16678 + struct inode vfs_inode;
16680 + struct hlist_node plink;
16681 + struct llist_node lnode; /* delayed free */
16683 +} ____cacheline_aligned_in_smp;
16685 +/* au_pin flags */
16686 +#define AuPin_DI_LOCKED 1
16687 +#define AuPin_MNT_WRITE (1 << 1)
16688 +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name)
16689 +#define au_fset_pin(flags, name) \
16690 + do { (flags) |= AuPin_##name; } while (0)
16691 +#define au_fclr_pin(flags, name) \
16692 + do { (flags) &= ~AuPin_##name; } while (0)
16696 + struct dentry *dentry;
16697 + unsigned int udba;
16698 + unsigned char lsc_di, lsc_hi, flags;
16699 + aufs_bindex_t bindex;
16702 + struct dentry *parent;
16703 + struct au_hinode *hdir;
16704 + struct vfsmount *h_mnt;
16706 + /* temporary unlock/relock for copyup */
16707 + struct dentry *h_dentry, *h_parent;
16708 + struct au_branch *br;
16709 + struct task_struct *task;
16712 +void au_pin_hdir_unlock(struct au_pin *p);
16713 +int au_pin_hdir_lock(struct au_pin *p);
16714 +int au_pin_hdir_relock(struct au_pin *p);
16715 +void au_pin_hdir_acquire_nest(struct au_pin *p);
16716 +void au_pin_hdir_release(struct au_pin *p);
16718 +/* ---------------------------------------------------------------------- */
16720 +static inline struct au_iinfo *au_ii(struct inode *inode)
16722 + BUG_ON(is_bad_inode(inode));
16723 + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo);
16726 +/* ---------------------------------------------------------------------- */
16729 +struct inode *au_igrab(struct inode *inode);
16730 +void au_refresh_iop(struct inode *inode, int force_getattr);
16731 +int au_refresh_hinode_self(struct inode *inode);
16732 +int au_refresh_hinode(struct inode *inode, struct dentry *dentry);
16733 +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
16734 + unsigned int d_type, ino_t *ino);
16735 +struct inode *au_new_inode(struct dentry *dentry, int must_new);
16736 +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex,
16737 + struct inode *inode);
16738 +int au_test_h_perm(struct inode *h_inode, int mask);
16739 +int au_test_h_perm_sio(struct inode *h_inode, int mask);
16741 +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex,
16742 + ino_t h_ino, unsigned int d_type, ino_t *ino)
16744 +#ifdef CONFIG_AUFS_SHWH
16745 + return au_ino(sb, bindex, h_ino, d_type, ino);
16758 +extern struct inode_operations aufs_iop[AuIop_Last],
16759 + aufs_iop_nogetattr[AuIop_Last];
16761 +/* au_wr_dir flags */
16762 +#define AuWrDir_ADD_ENTRY 1
16763 +#define AuWrDir_ISDIR (1 << 1)
16764 +#define AuWrDir_TMPFILE (1 << 2)
16765 +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name)
16766 +#define au_fset_wrdir(flags, name) \
16767 + do { (flags) |= AuWrDir_##name; } while (0)
16768 +#define au_fclr_wrdir(flags, name) \
16769 + do { (flags) &= ~AuWrDir_##name; } while (0)
16771 +struct au_wr_dir_args {
16772 + aufs_bindex_t force_btgt;
16773 + unsigned char flags;
16775 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
16776 + struct au_wr_dir_args *args);
16778 +struct dentry *au_pinned_h_parent(struct au_pin *pin);
16779 +void au_pin_init(struct au_pin *pin, struct dentry *dentry,
16780 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
16781 + unsigned int udba, unsigned char flags);
16782 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
16783 + unsigned int udba, unsigned char flags) __must_check;
16784 +int au_do_pin(struct au_pin *pin) __must_check;
16785 +void au_unpin(struct au_pin *pin);
16786 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen);
16788 +#define AuIcpup_DID_CPUP 1
16789 +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name)
16790 +#define au_fset_icpup(flags, name) \
16791 + do { (flags) |= AuIcpup_##name; } while (0)
16792 +#define au_fclr_icpup(flags, name) \
16793 + do { (flags) &= ~AuIcpup_##name; } while (0)
16795 +struct au_icpup_args {
16796 + unsigned char flags;
16797 + unsigned char pin_flags;
16798 + aufs_bindex_t btgt;
16799 + unsigned int udba;
16800 + struct au_pin pin;
16801 + struct path h_path;
16802 + struct inode *h_inode;
16805 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
16806 + struct au_icpup_args *a);
16808 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path);
16811 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
16812 + struct dentry *h_parent, int isdir);
16813 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
16815 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname);
16816 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
16818 +struct vfsub_aopen_args;
16819 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
16820 + struct vfsub_aopen_args *args);
16821 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode);
16822 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
16823 + struct dentry *dentry);
16824 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
16827 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup);
16828 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
16829 + struct dentry *h_parent, int isdir);
16830 +int aufs_unlink(struct inode *dir, struct dentry *dentry);
16831 +int aufs_rmdir(struct inode *dir, struct dentry *dentry);
16834 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt);
16835 +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry,
16836 + struct inode *dir, struct dentry *dentry,
16837 + unsigned int flags);
16840 +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex);
16841 +void au_hiput(struct au_hinode *hinode);
16842 +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex,
16843 + struct dentry *h_wh);
16844 +unsigned int au_hi_flags(struct inode *inode, int isdir);
16846 +/* hinode flags */
16847 +#define AuHi_XINO 1
16848 +#define AuHi_HNOTIFY (1 << 1)
16849 +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name)
16850 +#define au_fset_hi(flags, name) \
16851 + do { (flags) |= AuHi_##name; } while (0)
16852 +#define au_fclr_hi(flags, name) \
16853 + do { (flags) &= ~AuHi_##name; } while (0)
16855 +#ifndef CONFIG_AUFS_HNOTIFY
16856 +#undef AuHi_HNOTIFY
16857 +#define AuHi_HNOTIFY 0
16860 +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex,
16861 + struct inode *h_inode, unsigned int flags);
16863 +void au_update_iigen(struct inode *inode, int half);
16864 +void au_update_ibrange(struct inode *inode, int do_put_zero);
16866 +void au_icntnr_init_once(void *_c);
16867 +void au_hinode_init(struct au_hinode *hinode);
16868 +int au_iinfo_init(struct inode *inode);
16869 +void au_iinfo_fin(struct inode *inode);
16870 +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink);
16872 +#ifdef CONFIG_PROC_FS
16874 +int au_plink_maint(struct super_block *sb, int flags);
16876 +void au_plink_maint_leave(struct au_sbinfo *sbinfo);
16877 +int au_plink_maint_enter(struct super_block *sb);
16878 +#ifdef CONFIG_AUFS_DEBUG
16879 +void au_plink_list(struct super_block *sb);
16881 +AuStubVoid(au_plink_list, struct super_block *sb)
16883 +int au_plink_test(struct inode *inode);
16884 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex);
16885 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
16886 + struct dentry *h_dentry);
16887 +void au_plink_put(struct super_block *sb, int verbose);
16888 +void au_plink_clean(struct super_block *sb, int verbose);
16889 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id);
16891 +AuStubInt0(au_plink_maint, struct super_block *sb, int flags);
16892 +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo);
16893 +AuStubInt0(au_plink_maint_enter, struct super_block *sb);
16894 +AuStubVoid(au_plink_list, struct super_block *sb);
16895 +AuStubInt0(au_plink_test, struct inode *inode);
16896 +AuStub(struct dentry *, au_plink_lkup, return NULL,
16897 + struct inode *inode, aufs_bindex_t bindex);
16898 +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex,
16899 + struct dentry *h_dentry);
16900 +AuStubVoid(au_plink_put, struct super_block *sb, int verbose);
16901 +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose);
16902 +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id);
16903 +#endif /* CONFIG_PROC_FS */
16905 +#ifdef CONFIG_AUFS_XATTR
16907 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
16908 + unsigned int verbose);
16909 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size);
16910 +void au_xattr_init(struct super_block *sb);
16912 +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src,
16913 + int ignore_flags, unsigned int verbose);
16914 +AuStubVoid(au_xattr_init, struct super_block *sb);
16917 +#ifdef CONFIG_FS_POSIX_ACL
16918 +struct posix_acl *aufs_get_acl(struct inode *inode, int type);
16919 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
16922 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
16928 +struct au_sxattr {
16932 + const char *name;
16933 + const void *value;
16938 + struct posix_acl *acl;
16943 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
16944 + struct au_sxattr *arg);
16947 +/* ---------------------------------------------------------------------- */
16949 +/* lock subclass for iinfo */
16951 + AuLsc_II_CHILD, /* child first */
16952 + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */
16953 + AuLsc_II_CHILD3, /* copyup dirs */
16954 + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */
16955 + AuLsc_II_PARENT2,
16956 + AuLsc_II_PARENT3, /* copyup dirs */
16957 + AuLsc_II_NEW_CHILD
16961 + * ii_read_lock_child, ii_write_lock_child,
16962 + * ii_read_lock_child2, ii_write_lock_child2,
16963 + * ii_read_lock_child3, ii_write_lock_child3,
16964 + * ii_read_lock_parent, ii_write_lock_parent,
16965 + * ii_read_lock_parent2, ii_write_lock_parent2,
16966 + * ii_read_lock_parent3, ii_write_lock_parent3,
16967 + * ii_read_lock_new_child, ii_write_lock_new_child,
16969 +#define AuReadLockFunc(name, lsc) \
16970 +static inline void ii_read_lock_##name(struct inode *i) \
16972 + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16975 +#define AuWriteLockFunc(name, lsc) \
16976 +static inline void ii_write_lock_##name(struct inode *i) \
16978 + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \
16981 +#define AuRWLockFuncs(name, lsc) \
16982 + AuReadLockFunc(name, lsc) \
16983 + AuWriteLockFunc(name, lsc)
16985 +AuRWLockFuncs(child, CHILD);
16986 +AuRWLockFuncs(child2, CHILD2);
16987 +AuRWLockFuncs(child3, CHILD3);
16988 +AuRWLockFuncs(parent, PARENT);
16989 +AuRWLockFuncs(parent2, PARENT2);
16990 +AuRWLockFuncs(parent3, PARENT3);
16991 +AuRWLockFuncs(new_child, NEW_CHILD);
16993 +#undef AuReadLockFunc
16994 +#undef AuWriteLockFunc
16995 +#undef AuRWLockFuncs
16998 + * ii_read_unlock, ii_write_unlock, ii_downgrade_lock
17000 +AuSimpleUnlockRwsemFuncs(ii, struct inode *i, &au_ii(i)->ii_rwsem);
17002 +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem)
17003 +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem)
17004 +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem)
17006 +/* ---------------------------------------------------------------------- */
17008 +static inline void au_icntnr_init(struct au_icntnr *c)
17010 +#ifdef CONFIG_AUFS_DEBUG
17011 + c->vfs_inode.i_mode = 0;
17015 +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags)
17017 + unsigned int gen;
17018 + struct au_iinfo *iinfo;
17019 + struct au_iigen *iigen;
17021 + iinfo = au_ii(inode);
17022 + iigen = &iinfo->ii_generation;
17023 + spin_lock(&iigen->ig_spin);
17025 + *igflags = iigen->ig_flags;
17026 + gen = iigen->ig_generation;
17027 + spin_unlock(&iigen->ig_spin);
17032 +/* tiny test for inode number */
17033 +/* tmpfs generation is too rough */
17034 +static inline int au_test_higen(struct inode *inode, struct inode *h_inode)
17036 + struct au_iinfo *iinfo;
17038 + iinfo = au_ii(inode);
17039 + AuRwMustAnyLock(&iinfo->ii_rwsem);
17040 + return !(iinfo->ii_hsb1 == h_inode->i_sb
17041 + && iinfo->ii_higen == h_inode->i_generation);
17044 +static inline void au_iigen_dec(struct inode *inode)
17046 + struct au_iinfo *iinfo;
17047 + struct au_iigen *iigen;
17049 + iinfo = au_ii(inode);
17050 + iigen = &iinfo->ii_generation;
17051 + spin_lock(&iigen->ig_spin);
17052 + iigen->ig_generation--;
17053 + spin_unlock(&iigen->ig_spin);
17056 +static inline int au_iigen_test(struct inode *inode, unsigned int sigen)
17061 + if (unlikely(inode && au_iigen(inode, NULL) != sigen))
17067 +/* ---------------------------------------------------------------------- */
17069 +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo,
17070 + aufs_bindex_t bindex)
17072 + return iinfo->ii_hinode + bindex;
17075 +static inline int au_is_bad_inode(struct inode *inode)
17077 + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0));
17080 +static inline aufs_bindex_t au_ii_br_id(struct inode *inode,
17081 + aufs_bindex_t bindex)
17083 + IiMustAnyLock(inode);
17084 + return au_hinode(au_ii(inode), bindex)->hi_id;
17087 +static inline aufs_bindex_t au_ibtop(struct inode *inode)
17089 + IiMustAnyLock(inode);
17090 + return au_ii(inode)->ii_btop;
17093 +static inline aufs_bindex_t au_ibbot(struct inode *inode)
17095 + IiMustAnyLock(inode);
17096 + return au_ii(inode)->ii_bbot;
17099 +static inline struct au_vdir *au_ivdir(struct inode *inode)
17101 + IiMustAnyLock(inode);
17102 + return au_ii(inode)->ii_vdir;
17105 +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex)
17107 + IiMustAnyLock(inode);
17108 + return au_hinode(au_ii(inode), bindex)->hi_whdentry;
17111 +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex)
17113 + IiMustWriteLock(inode);
17114 + au_ii(inode)->ii_btop = bindex;
17117 +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex)
17119 + IiMustWriteLock(inode);
17120 + au_ii(inode)->ii_bbot = bindex;
17123 +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir)
17125 + IiMustWriteLock(inode);
17126 + au_ii(inode)->ii_vdir = vdir;
17129 +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex)
17131 + IiMustAnyLock(inode);
17132 + return au_hinode(au_ii(inode), bindex);
17135 +/* ---------------------------------------------------------------------- */
17137 +static inline struct dentry *au_pinned_parent(struct au_pin *pin)
17140 + return pin->parent;
17144 +static inline struct inode *au_pinned_h_dir(struct au_pin *pin)
17146 + if (pin && pin->hdir)
17147 + return pin->hdir->hi_inode;
17151 +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin)
17154 + return pin->hdir;
17158 +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry)
17161 + pin->dentry = dentry;
17164 +static inline void au_pin_set_parent_lflag(struct au_pin *pin,
17165 + unsigned char lflag)
17169 + au_fset_pin(pin->flags, DI_LOCKED);
17171 + au_fclr_pin(pin->flags, DI_LOCKED);
17175 +#if 0 /* reserved */
17176 +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent)
17179 + dput(pin->parent);
17180 + pin->parent = dget(parent);
17185 +/* ---------------------------------------------------------------------- */
17188 +#ifdef CONFIG_AUFS_HNOTIFY
17189 +struct au_hnotify_op {
17190 + void (*ctl)(struct au_hinode *hinode, int do_set);
17191 + int (*alloc)(struct au_hinode *hinode);
17194 + * if it returns true, the the caller should free hinode->hi_notify,
17195 + * otherwise ->free() frees it.
17197 + int (*free)(struct au_hinode *hinode,
17198 + struct au_hnotify *hn) __must_check;
17200 + void (*fin)(void);
17201 + int (*init)(void);
17203 + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm);
17204 + void (*fin_br)(struct au_branch *br);
17205 + int (*init_br)(struct au_branch *br, int perm);
17209 +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode);
17210 +void au_hn_free(struct au_hinode *hinode);
17211 +void au_hn_ctl(struct au_hinode *hinode, int do_set);
17212 +void au_hn_reset(struct inode *inode, unsigned int flags);
17213 +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask,
17214 + struct qstr *h_child_qstr, struct inode *h_child_inode);
17215 +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm);
17216 +int au_hnotify_init_br(struct au_branch *br, int perm);
17217 +void au_hnotify_fin_br(struct au_branch *br);
17218 +int __init au_hnotify_init(void);
17219 +void au_hnotify_fin(void);
17222 +extern const struct au_hnotify_op au_hnotify_op;
17225 +void au_hn_init(struct au_hinode *hinode)
17227 + hinode->hi_notify = NULL;
17230 +static inline struct au_hnotify *au_hn(struct au_hinode *hinode)
17232 + return hinode->hi_notify;
17236 +AuStub(int, au_hn_alloc, return -EOPNOTSUPP,
17237 + struct au_hinode *hinode __maybe_unused,
17238 + struct inode *inode __maybe_unused)
17239 +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode)
17240 +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused)
17241 +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused,
17242 + int do_set __maybe_unused)
17243 +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused,
17244 + unsigned int flags __maybe_unused)
17245 +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused,
17246 + struct au_branch *br __maybe_unused,
17247 + int perm __maybe_unused)
17248 +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused,
17249 + int perm __maybe_unused)
17250 +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused)
17251 +AuStubInt0(__init au_hnotify_init, void)
17252 +AuStubVoid(au_hnotify_fin, void)
17253 +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused)
17254 +#endif /* CONFIG_AUFS_HNOTIFY */
17256 +static inline void au_hn_suspend(struct au_hinode *hdir)
17258 + au_hn_ctl(hdir, /*do_set*/0);
17261 +static inline void au_hn_resume(struct au_hinode *hdir)
17263 + au_hn_ctl(hdir, /*do_set*/1);
17266 +static inline void au_hn_inode_lock(struct au_hinode *hdir)
17268 + inode_lock(hdir->hi_inode);
17269 + au_hn_suspend(hdir);
17272 +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir,
17273 + unsigned int sc __maybe_unused)
17275 + inode_lock_nested(hdir->hi_inode, sc);
17276 + au_hn_suspend(hdir);
17279 +static inline void au_hn_inode_unlock(struct au_hinode *hdir)
17281 + au_hn_resume(hdir);
17282 + inode_unlock(hdir->hi_inode);
17285 +#endif /* __KERNEL__ */
17286 +#endif /* __AUFS_INODE_H__ */
17287 diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c
17288 --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100
17289 +++ linux/fs/aufs/ioctl.c 2016-10-09 16:55:36.492701639 +0200
17292 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17294 + * This program, aufs is free software; you can redistribute it and/or modify
17295 + * it under the terms of the GNU General Public License as published by
17296 + * the Free Software Foundation; either version 2 of the License, or
17297 + * (at your option) any later version.
17299 + * This program is distributed in the hope that it will be useful,
17300 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17301 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17302 + * GNU General Public License for more details.
17304 + * You should have received a copy of the GNU General Public License
17305 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17310 + * plink-management and readdir in userspace.
17311 + * assist the pathconf(3) wrapper library.
17313 + * File-based Hierarchical Storage Management.
17316 +#include <linux/compat.h>
17317 +#include <linux/file.h>
17320 +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg)
17323 + aufs_bindex_t wbi, bindex, bbot;
17324 + struct file *h_file;
17325 + struct super_block *sb;
17326 + struct dentry *root;
17327 + struct au_branch *br;
17328 + struct aufs_wbr_fd wbrfd = {
17329 + .oflags = au_dir_roflags,
17332 + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY
17333 + | O_NOATIME | O_CLOEXEC;
17335 + AuDebugOn(wbrfd.oflags & ~valid);
17338 + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd));
17339 + if (unlikely(err)) {
17345 + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid);
17346 + wbrfd.oflags |= au_dir_roflags;
17347 + AuDbg("0%o\n", wbrfd.oflags);
17348 + if (unlikely(wbrfd.oflags & ~valid))
17352 + fd = get_unused_fd_flags(0);
17354 + if (unlikely(fd < 0))
17357 + h_file = ERR_PTR(-EINVAL);
17360 + sb = path->dentry->d_sb;
17361 + root = sb->s_root;
17362 + aufs_read_lock(root, AuLock_IR);
17363 + bbot = au_sbbot(sb);
17364 + if (wbrfd.brid >= 0) {
17365 + wbi = au_br_index(sb, wbrfd.brid);
17366 + if (unlikely(wbi < 0 || wbi > bbot))
17370 + h_file = ERR_PTR(-ENOENT);
17371 + br = au_sbr(sb, wbi);
17372 + if (!au_br_writable(br->br_perm)) {
17376 + bindex = wbi + 1;
17378 + for (; bindex <= bbot; bindex++) {
17379 + br = au_sbr(sb, bindex);
17380 + if (au_br_writable(br->br_perm)) {
17382 + br = au_sbr(sb, wbi);
17387 + AuDbg("wbi %d\n", wbi);
17389 + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL,
17393 + aufs_read_unlock(root, AuLock_IR);
17394 + err = PTR_ERR(h_file);
17395 + if (IS_ERR(h_file))
17398 + au_br_put(br); /* cf. au_h_open() */
17399 + fd_install(fd, h_file);
17401 + goto out; /* success */
17404 + put_unused_fd(fd);
17410 +/* ---------------------------------------------------------------------- */
17412 +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg)
17415 + struct dentry *dentry;
17418 + case AUFS_CTL_RDU:
17419 + case AUFS_CTL_RDU_INO:
17420 + err = au_rdu_ioctl(file, cmd, arg);
17423 + case AUFS_CTL_WBR_FD:
17424 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17427 + case AUFS_CTL_IBUSY:
17428 + err = au_ibusy_ioctl(file, arg);
17431 + case AUFS_CTL_BRINFO:
17432 + err = au_brinfo_ioctl(file, arg);
17435 + case AUFS_CTL_FHSM_FD:
17436 + dentry = file->f_path.dentry;
17437 + if (IS_ROOT(dentry))
17438 + err = au_fhsm_fd(dentry->d_sb, arg);
17444 + /* do not call the lower */
17445 + AuDbg("0x%x\n", cmd);
17453 +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg)
17458 + case AUFS_CTL_MVDOWN:
17459 + err = au_mvdown(file->f_path.dentry, (void __user *)arg);
17462 + case AUFS_CTL_WBR_FD:
17463 + err = au_wbr_fd(&file->f_path, (void __user *)arg);
17467 + /* do not call the lower */
17468 + AuDbg("0x%x\n", cmd);
17476 +#ifdef CONFIG_COMPAT
17477 +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd,
17478 + unsigned long arg)
17483 + case AUFS_CTL_RDU:
17484 + case AUFS_CTL_RDU_INO:
17485 + err = au_rdu_compat_ioctl(file, cmd, arg);
17488 + case AUFS_CTL_IBUSY:
17489 + err = au_ibusy_compat_ioctl(file, arg);
17492 + case AUFS_CTL_BRINFO:
17493 + err = au_brinfo_compat_ioctl(file, arg);
17497 + err = aufs_ioctl_dir(file, cmd, arg);
17504 +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd,
17505 + unsigned long arg)
17507 + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg));
17510 diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c
17511 --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100
17512 +++ linux/fs/aufs/i_op_add.c 2016-12-17 12:28:17.595211562 +0100
17515 + * Copyright (C) 2005-2016 Junjiro R. Okajima
17517 + * This program, aufs is free software; you can redistribute it and/or modify
17518 + * it under the terms of the GNU General Public License as published by
17519 + * the Free Software Foundation; either version 2 of the License, or
17520 + * (at your option) any later version.
17522 + * This program is distributed in the hope that it will be useful,
17523 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
17524 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17525 + * GNU General Public License for more details.
17527 + * You should have received a copy of the GNU General Public License
17528 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
17532 + * inode operations (add entry)
17538 + * final procedure of adding a new entry, except link(2).
17539 + * remove whiteout, instantiate, copyup the parent dir's times and size
17540 + * and update version.
17541 + * if it failed, re-create the removed whiteout.
17543 +static int epilog(struct inode *dir, aufs_bindex_t bindex,
17544 + struct dentry *wh_dentry, struct dentry *dentry)
17547 + aufs_bindex_t bwh;
17548 + struct path h_path;
17549 + struct super_block *sb;
17550 + struct inode *inode, *h_dir;
17551 + struct dentry *wh;
17556 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
17557 + IMustLock(h_dir);
17558 + AuDebugOn(au_h_iptr(dir, bindex) != h_dir);
17559 + bwh = au_dbwh(dentry);
17560 + h_path.dentry = wh_dentry;
17561 + h_path.mnt = au_sbr_mnt(sb, bindex);
17562 + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path,
17564 + if (unlikely(err))
17568 + inode = au_new_inode(dentry, /*must_new*/1);
17569 + if (!IS_ERR(inode)) {
17570 + d_instantiate(dentry, inode);
17571 + dir = d_inode(dentry->d_parent); /* dir inode is locked */
17573 + au_dir_ts(dir, bindex);
17574 + dir->i_version++;
17575 + au_fhsm_wrote(sb, bindex, /*force*/0);
17576 + return 0; /* success */
17579 + err = PTR_ERR(inode);
17584 + /* dir inode is locked */
17585 + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent);
17586 + rerr = PTR_ERR(wh);
17587 + if (IS_ERR(wh)) {
17588 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n",
17589 + dentry, err, rerr);
17598 +static int au_d_may_add(struct dentry *dentry)
17603 + if (unlikely(d_unhashed(dentry)))
17605 + if (unlikely(d_really_is_positive(dentry)))
17611 + * simple tests for the adding inode operations.
17612 + * following the checks in vfs, plus the parent-child relationship.
17614 +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex,
17615 + struct dentry *h_parent, int isdir)
17619 + struct dentry *h_dentry;
17620 + struct inode *h_inode;
17622 + err = -ENAMETOOLONG;
17623 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17626 + h_dentry = au_h_dptr(dentry, bindex);
17627 + if (d_really_is_negative(dentry)) {
17629 + if (unlikely(d_is_positive(h_dentry)))
17632 + /* rename(2) case */
17634 + if (unlikely(d_is_negative(h_dentry)))
17636 + h_inode = d_inode(h_dentry);
17637 + if (unlikely(!h_inode->i_nlink))
17640 + h_mode = h_inode->i_mode;
17643 + if (unlikely(S_ISDIR(h_mode)))
17645 + } else if (unlikely(!S_ISDIR(h_mode))) {
17652 + /* expected parent dir is locked */
17653 + if (unlikely(h_parent != h_dentry->d_parent))
17662 + * initial procedure of adding a new entry.
17663 + * prepare writable branch and the parent dir, lock it,
17664 + * and lookup whiteout for the new entry.
17666 +static struct dentry*
17667 +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt,
17668 + struct dentry *src_dentry, struct au_pin *pin,
17669 + struct au_wr_dir_args *wr_dir_args)
17671 + struct dentry *wh_dentry, *h_parent;
17672 + struct super_block *sb;
17673 + struct au_branch *br;
17675 + unsigned int udba;
17676 + aufs_bindex_t bcpup;
17678 + AuDbg("%pd\n", dentry);
17680 + err = au_wr_dir(dentry, src_dentry, wr_dir_args);
17682 + wh_dentry = ERR_PTR(err);
17683 + if (unlikely(err < 0))
17686 + sb = dentry->d_sb;
17687 + udba = au_opt_udba(sb);
17688 + err = au_pin(pin, dentry, bcpup, udba,
17689 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
17690 + wh_dentry = ERR_PTR(err);
17691 + if (unlikely(err))
17694 + h_parent = au_pinned_h_parent(pin);
17695 + if (udba != AuOpt_UDBA_NONE
17696 + && au_dbtop(dentry) == bcpup)
17697 + err = au_may_add(dentry, bcpup, h_parent,
17698 + au_ftest_wrdir(wr_dir_args->flags, ISDIR));
17699 + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
17700 + err = -ENAMETOOLONG;
17701 + wh_dentry = ERR_PTR(err);
17702 + if (unlikely(err))
17705 + br = au_sbr(sb, bcpup);
17707 + struct path tmp = {
17708 + .dentry = h_parent,
17709 + .mnt = au_br_mnt(br)
17711 + au_dtime_store(dt, au_pinned_parent(pin), &tmp);
17714 + wh_dentry = NULL;
17715 + if (bcpup != au_dbwh(dentry))
17716 + goto out; /* success */
17719 + * ENAMETOOLONG here means that if we allowed create such name, then it
17720 + * would not be able to removed in the future. So we don't allow such
17721 + * name here and we don't handle ENAMETOOLONG differently here.
17723 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
17726 + if (IS_ERR(wh_dentry))
17729 + return wh_dentry;
17732 +/* ---------------------------------------------------------------------- */
17734 +enum { Mknod, Symlink, Creat };
17735 +struct simple_arg {
17742 + struct vfsub_aopen_args *aopen;
17745 + const char *symname;
17754 +static int add_simple(struct inode *dir, struct dentry *dentry,
17755 + struct simple_arg *arg)
17758 + aufs_bindex_t btop;
17759 + unsigned char created;
17760 + const unsigned char try_aopen
17761 + = (arg->type == Creat && arg->u.c.try_aopen);
17762 + struct dentry *wh_dentry, *parent;
17763 + struct inode *h_dir;
17764 + struct super_block *sb;
17765 + struct au_branch *br;
17766 + /* to reuduce stack size */
17768 + struct au_dtime dt;
17769 + struct au_pin pin;
17770 + struct path h_path;
17771 + struct au_wr_dir_args wr_dir_args;
17774 + AuDbg("%pd\n", dentry);
17778 + a = kmalloc(sizeof(*a), GFP_NOFS);
17779 + if (unlikely(!a))
17781 + a->wr_dir_args.force_btgt = -1;
17782 + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY;
17784 + parent = dentry->d_parent; /* dir inode is locked */
17785 + if (!try_aopen) {
17786 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
17787 + if (unlikely(err))
17790 + err = au_d_may_add(dentry);
17791 + if (unlikely(err))
17794 + di_write_lock_parent(parent);
17795 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
17796 + &a->pin, &a->wr_dir_args);
17797 + err = PTR_ERR(wh_dentry);
17798 + if (IS_ERR(wh_dentry))
17801 + btop = au_dbtop(dentry);
17802 + sb = dentry->d_sb;
17803 + br = au_sbr(sb, btop);
17804 + a->h_path.dentry = au_h_dptr(dentry, btop);
17805 + a->h_path.mnt = au_br_mnt(br);
17806 + h_dir = au_pinned_h_dir(&a->pin);
17807 + switch (arg->type) {
17810 + if (!try_aopen || !h_dir->i_op->atomic_open)
17811 + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode,
17812 + arg->u.c.want_excl);
17814 + err = vfsub_atomic_open(h_dir, a->h_path.dentry,
17815 + arg->u.c.aopen, br);
17818 + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname);
17821 + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode,
17829 + err = epilog(dir, btop, wh_dentry, dentry);
17832 + if (unlikely(created && err && d_is_positive(a->h_path.dentry))) {
17833 + /* no delegation since it is just created */
17834 + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL,
17837 + AuIOErr("%pd revert failure(%d, %d)\n",
17838 + dentry, err, rerr);
17841 + au_dtime_revert(&a->dt);
17844 + if (!err && try_aopen && !h_dir->i_op->atomic_open)
17845 + *arg->u.c.aopen->opened |= FILE_CREATED;
17847 + au_unpin(&a->pin);
17852 + di_write_unlock(parent);
17854 + if (unlikely(err)) {
17855 + au_update_dbtop(dentry);
17859 + aufs_read_unlock(dentry, AuLock_DW);
17861 + au_delayed_kfree(a);
17866 +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
17869 + struct simple_arg arg = {
17876 + return add_simple(dir, dentry, &arg);
17879 +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname)
17881 + struct simple_arg arg = {
17883 + .u.s.symname = symname
17885 + return add_simple(dir, dentry, &arg);
17888 +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
17891 + struct simple_arg arg = {
17895 + .want_excl = want_excl
17898 + return add_simple(dir, dentry, &arg);
17901 +int au_aopen_or_create(struct inode *dir, struct dentry *dentry,
17902 + struct vfsub_aopen_args *aopen_args)
17904 + struct simple_arg arg = {
17907 + .mode = aopen_args->create_mode,
17908 + .want_excl = aopen_args->open_flag & O_EXCL,
17909 + .try_aopen = true,
17910 + .aopen = aopen_args
17913 + return add_simple(dir, dentry, &arg);
17916 +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode)
17919 + aufs_bindex_t bindex;
17920 + struct super_block *sb;
17921 + struct dentry *parent, *h_parent, *h_dentry;
17922 + struct inode *h_dir, *inode;
17923 + struct vfsmount *h_mnt;
17924 + struct au_wr_dir_args wr_dir_args = {
17925 + .force_btgt = -1,
17926 + .flags = AuWrDir_TMPFILE
17929 + /* copy-up may happen */
17933 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
17934 + if (unlikely(err))
17937 + err = au_di_init(dentry);
17938 + if (unlikely(err))
17942 + parent = d_find_any_alias(dir);
17943 + AuDebugOn(!parent);
17944 + di_write_lock_parent(parent);
17945 + if (unlikely(d_inode(parent) != dir))
17948 + err = au_digen_test(parent, au_sigen(sb));
17949 + if (unlikely(err))
17952 + bindex = au_dbtop(parent);
17953 + au_set_dbtop(dentry, bindex);
17954 + au_set_dbbot(dentry, bindex);
17955 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
17957 + if (unlikely(err < 0))
17960 + err = -EOPNOTSUPP;
17961 + h_dir = au_h_iptr(dir, bindex);
17962 + if (unlikely(!h_dir->i_op->tmpfile))
17965 + h_mnt = au_sbr_mnt(sb, bindex);
17966 + err = vfsub_mnt_want_write(h_mnt);
17967 + if (unlikely(err))
17970 + h_parent = au_h_dptr(parent, bindex);
17971 + err = inode_permission(d_inode(h_parent), MAY_WRITE | MAY_EXEC);
17972 + if (unlikely(err))
17976 + h_dentry = d_alloc(h_parent, &dentry->d_name);
17977 + if (unlikely(!h_dentry))
17980 + err = h_dir->i_op->tmpfile(h_dir, h_dentry, mode);
17981 + if (unlikely(err))
17984 + au_set_dbtop(dentry, bindex);
17985 + au_set_dbbot(dentry, bindex);
17986 + au_set_h_dptr(dentry, bindex, dget(h_dentry));
17987 + inode = au_new_inode(dentry, /*must_new*/1);
17988 + if (IS_ERR(inode)) {
17989 + err = PTR_ERR(inode);
17990 + au_set_h_dptr(dentry, bindex, NULL);
17991 + au_set_dbtop(dentry, -1);
17992 + au_set_dbbot(dentry, -1);
17994 + if (!inode->i_nlink)
17995 + set_nlink(inode, 1);
17996 + d_tmpfile(dentry, inode);
17997 + au_di(dentry)->di_tmpfile = 1;
17999 + /* update without i_mutex */
18000 + if (au_ibtop(dir) == au_dbtop(dentry))
18001 + au_cpup_attr_timesizes(dir);
18007 + vfsub_mnt_drop_write(h_mnt);
18009 + di_write_unlock(parent);
18011 + di_write_unlock(dentry);
18012 + if (unlikely(err)) {
18013 + au_di_fin(dentry);
18014 + dentry->d_fsdata = NULL;
18017 + si_read_unlock(sb);
18019 + inode_unlock(dir);
18023 +/* ---------------------------------------------------------------------- */
18025 +struct au_link_args {
18026 + aufs_bindex_t bdst, bsrc;
18027 + struct au_pin pin;
18028 + struct path h_path;
18029 + struct dentry *src_parent, *parent;
18032 +static int au_cpup_before_link(struct dentry *src_dentry,
18033 + struct au_link_args *a)
18036 + struct dentry *h_src_dentry;
18037 + struct au_cp_generic cpg = {
18038 + .dentry = src_dentry,
18043 + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */
18046 + di_read_lock_parent(a->src_parent, AuLock_IR);
18047 + err = au_test_and_cpup_dirs(src_dentry, a->bdst);
18048 + if (unlikely(err))
18051 + h_src_dentry = au_h_dptr(src_dentry, a->bsrc);
18052 + err = au_pin(&a->pin, src_dentry, a->bdst,
18053 + au_opt_udba(src_dentry->d_sb),
18054 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18055 + if (unlikely(err))
18058 + err = au_sio_cpup_simple(&cpg);
18059 + au_unpin(&a->pin);
18062 + di_read_unlock(a->src_parent, AuLock_IR);
18066 +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry,
18067 + struct au_link_args *a)
18070 + unsigned char plink;
18071 + aufs_bindex_t bbot;
18072 + struct dentry *h_src_dentry;
18073 + struct inode *h_inode, *inode, *delegated;
18074 + struct super_block *sb;
18075 + struct file *h_file;
18079 + sb = src_dentry->d_sb;
18080 + inode = d_inode(src_dentry);
18081 + if (au_ibtop(inode) <= a->bdst)
18082 + h_inode = au_h_iptr(inode, a->bdst);
18083 + if (!h_inode || !h_inode->i_nlink) {
18084 + /* copyup src_dentry as the name of dentry. */
18085 + bbot = au_dbbot(dentry);
18086 + if (bbot < a->bsrc)
18087 + au_set_dbbot(dentry, a->bsrc);
18088 + au_set_h_dptr(dentry, a->bsrc,
18089 + dget(au_h_dptr(src_dentry, a->bsrc)));
18090 + dget(a->h_path.dentry);
18091 + au_set_h_dptr(dentry, a->bdst, NULL);
18092 + AuDbg("temporary d_inode...\n");
18093 + spin_lock(&dentry->d_lock);
18094 + dentry->d_inode = d_inode(src_dentry); /* tmp */
18095 + spin_unlock(&dentry->d_lock);
18096 + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0);
18097 + if (IS_ERR(h_file))
18098 + err = PTR_ERR(h_file);
18100 + struct au_cp_generic cpg = {
18101 + .dentry = dentry,
18106 + .flags = AuCpup_KEEPLINO
18108 + err = au_sio_cpup_simple(&cpg);
18109 + au_h_open_post(dentry, a->bsrc, h_file);
18111 + dput(a->h_path.dentry);
18112 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18114 + au_set_h_dptr(dentry, a->bdst,
18115 + a->h_path.dentry);
18117 + spin_lock(&dentry->d_lock);
18118 + dentry->d_inode = NULL; /* restore */
18119 + spin_unlock(&dentry->d_lock);
18120 + AuDbg("temporary d_inode...done\n");
18121 + au_set_h_dptr(dentry, a->bsrc, NULL);
18122 + au_set_dbbot(dentry, bbot);
18124 + /* the inode of src_dentry already exists on a.bdst branch */
18125 + h_src_dentry = d_find_alias(h_inode);
18126 + if (!h_src_dentry && au_plink_test(inode)) {
18128 + h_src_dentry = au_plink_lkup(inode, a->bdst);
18129 + err = PTR_ERR(h_src_dentry);
18130 + if (IS_ERR(h_src_dentry))
18133 + if (unlikely(d_is_negative(h_src_dentry))) {
18134 + dput(h_src_dentry);
18135 + h_src_dentry = NULL;
18139 + if (h_src_dentry) {
18140 + delegated = NULL;
18141 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18142 + &a->h_path, &delegated);
18143 + if (unlikely(err == -EWOULDBLOCK)) {
18144 + pr_warn("cannot retry for NFSv4 delegation"
18145 + " for an internal link\n");
18148 + dput(h_src_dentry);
18150 + AuIOErr("no dentry found for hi%lu on b%d\n",
18151 + h_inode->i_ino, a->bdst);
18156 + if (!err && !plink)
18157 + au_plink_append(inode, a->bdst, a->h_path.dentry);
18164 +int aufs_link(struct dentry *src_dentry, struct inode *dir,
18165 + struct dentry *dentry)
18168 + struct au_dtime dt;
18169 + struct au_link_args *a;
18170 + struct dentry *wh_dentry, *h_src_dentry;
18171 + struct inode *inode, *delegated;
18172 + struct super_block *sb;
18173 + struct au_wr_dir_args wr_dir_args = {
18174 + /* .force_btgt = -1, */
18175 + .flags = AuWrDir_ADD_ENTRY
18179 + inode = d_inode(src_dentry);
18180 + IMustLock(inode);
18183 + a = kzalloc(sizeof(*a), GFP_NOFS);
18184 + if (unlikely(!a))
18187 + a->parent = dentry->d_parent; /* dir inode is locked */
18188 + err = aufs_read_and_write_lock2(dentry, src_dentry,
18189 + AuLock_NOPLM | AuLock_GEN);
18190 + if (unlikely(err))
18192 + err = au_d_linkable(src_dentry);
18193 + if (unlikely(err))
18195 + err = au_d_may_add(dentry);
18196 + if (unlikely(err))
18199 + a->src_parent = dget_parent(src_dentry);
18200 + wr_dir_args.force_btgt = au_ibtop(inode);
18202 + di_write_lock_parent(a->parent);
18203 + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt);
18204 + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin,
18206 + err = PTR_ERR(wh_dentry);
18207 + if (IS_ERR(wh_dentry))
18211 + sb = dentry->d_sb;
18212 + a->bdst = au_dbtop(dentry);
18213 + a->h_path.dentry = au_h_dptr(dentry, a->bdst);
18214 + a->h_path.mnt = au_sbr_mnt(sb, a->bdst);
18215 + a->bsrc = au_ibtop(inode);
18216 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18217 + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile)
18218 + h_src_dentry = dget(au_hi_wh(inode, a->bsrc));
18219 + if (!h_src_dentry) {
18220 + a->bsrc = au_dbtop(src_dentry);
18221 + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc);
18222 + AuDebugOn(!h_src_dentry);
18223 + } else if (IS_ERR(h_src_dentry)) {
18224 + err = PTR_ERR(h_src_dentry);
18229 + * aufs doesn't touch the credential so
18230 + * security_dentry_create_files_as() is unnecrssary.
18232 + if (au_opt_test(au_mntflags(sb), PLINK)) {
18233 + if (a->bdst < a->bsrc
18234 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */)
18235 + err = au_cpup_or_link(src_dentry, dentry, a);
18237 + delegated = NULL;
18238 + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin),
18239 + &a->h_path, &delegated);
18240 + if (unlikely(err == -EWOULDBLOCK)) {
18241 + pr_warn("cannot retry for NFSv4 delegation"
18242 + " for an internal link\n");
18246 + dput(h_src_dentry);
18249 + * copyup src_dentry to the branch we process,
18250 + * and then link(2) to it.
18252 + dput(h_src_dentry);
18253 + if (a->bdst < a->bsrc
18254 + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) {
18255 + au_unpin(&a->pin);
18256 + di_write_unlock(a->parent);
18257 + err = au_cpup_before_link(src_dentry, a);
18258 + di_write_lock_parent(a->parent);
18260 + err = au_pin(&a->pin, dentry, a->bdst,
18262 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
18263 + if (unlikely(err))
18267 + h_src_dentry = au_h_dptr(src_dentry, a->bdst);
18269 + if (h_src_dentry && d_is_positive(h_src_dentry)) {
18270 + delegated = NULL;
18271 + err = vfsub_link(h_src_dentry,
18272 + au_pinned_h_dir(&a->pin),
18273 + &a->h_path, &delegated);
18274 + if (unlikely(err == -EWOULDBLOCK)) {
18275 + pr_warn("cannot retry"
18276 + " for NFSv4 delegation"
18277 + " for an internal link\n");
18283 + if (unlikely(err))
18287 + a->h_path.dentry = wh_dentry;
18288 + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path,
18290 + if (unlikely(err))
18294 + au_dir_ts(dir, a->bdst);
18295 + dir->i_version++;
18296 + inc_nlink(inode);
18297 + inode->i_ctime = dir->i_ctime;
18298 + d_instantiate(dentry, au_igrab(inode));
18299 + if (d_unhashed(a->h_path.dentry))
18300 + /* some filesystem calls d_drop() */
18302 + /* some filesystems consume an inode even hardlink */
18303 + au_fhsm_wrote(sb, a->bdst, /*force*/0);
18304 + goto out_unpin; /* success */
18307 + /* no delegation since it is just created */
18308 + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path,
18309 + /*delegated*/NULL, /*force*/0);
18310 + if (unlikely(rerr)) {
18311 + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr);
18314 + au_dtime_revert(&dt);
18316 + au_unpin(&a->pin);
18320 + di_write_unlock(a->parent);
18321 + dput(a->src_parent);
18323 + if (unlikely(err)) {
18324 + au_update_dbtop(dentry);
18327 + aufs_read_and_write_unlock2(dentry, src_dentry);
18329 + au_delayed_kfree(a);
18335 +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
18338 + aufs_bindex_t bindex;
18339 + unsigned char diropq;
18340 + struct path h_path;
18341 + struct dentry *wh_dentry, *parent, *opq_dentry;
18342 + struct inode *h_inode;
18343 + struct super_block *sb;
18345 + struct au_pin pin;
18346 + struct au_dtime dt;
18347 + } *a; /* reduce the stack usage */
18348 + struct au_wr_dir_args wr_dir_args = {
18349 + .force_btgt = -1,
18350 + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR
18356 + a = kmalloc(sizeof(*a), GFP_NOFS);
18357 + if (unlikely(!a))
18360 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
18361 + if (unlikely(err))
18363 + err = au_d_may_add(dentry);
18364 + if (unlikely(err))
18367 + parent = dentry->d_parent; /* dir inode is locked */
18368 + di_write_lock_parent(parent);
18369 + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL,
18370 + &a->pin, &wr_dir_args);
18371 + err = PTR_ERR(wh_dentry);
18372 + if (IS_ERR(wh_dentry))
18375 + sb = dentry->d_sb;
18376 + bindex = au_dbtop(dentry);
18377 + h_path.dentry = au_h_dptr(dentry, bindex);
18378 + h_path.mnt = au_sbr_mnt(sb, bindex);
18379 + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode);
18380 + if (unlikely(err))
18383 + /* make the dir opaque */
18385 + h_inode = d_inode(h_path.dentry);
18387 + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) {
18388 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18389 + opq_dentry = au_diropq_create(dentry, bindex);
18390 + inode_unlock(h_inode);
18391 + err = PTR_ERR(opq_dentry);
18392 + if (IS_ERR(opq_dentry))
18394 + dput(opq_dentry);
18398 + err = epilog(dir, bindex, wh_dentry, dentry);
18401 + goto out_unpin; /* success */
18406 + AuLabel(revert opq);
18407 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
18408 + rerr = au_diropq_remove(dentry, bindex);
18409 + inode_unlock(h_inode);
18411 + AuIOErr("%pd reverting diropq failed(%d, %d)\n",
18412 + dentry, err, rerr);
18418 + AuLabel(revert dir);
18419 + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path);
18421 + AuIOErr("%pd reverting dir failed(%d, %d)\n",
18422 + dentry, err, rerr);
18425 + au_dtime_revert(&a->dt);
18427 + au_unpin(&a->pin);
18430 + di_write_unlock(parent);
18432 + if (unlikely(err)) {
18433 + au_update_dbtop(dentry);
18436 + aufs_read_unlock(dentry, AuLock_DW);
18438 + au_delayed_kfree(a);
18442 diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c
18443 --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100
18444 +++ linux/fs/aufs/i_op.c 2016-12-17 12:28:17.595211562 +0100
18447 + * Copyright (C) 2005-2016 Junjiro R. Okajima
18449 + * This program, aufs is free software; you can redistribute it and/or modify
18450 + * it under the terms of the GNU General Public License as published by
18451 + * the Free Software Foundation; either version 2 of the License, or
18452 + * (at your option) any later version.
18454 + * This program is distributed in the hope that it will be useful,
18455 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
18456 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18457 + * GNU General Public License for more details.
18459 + * You should have received a copy of the GNU General Public License
18460 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
18464 + * inode operations (except add/del/rename)
18467 +#include <linux/device_cgroup.h>
18468 +#include <linux/fs_stack.h>
18469 +#include <linux/namei.h>
18470 +#include <linux/security.h>
18473 +static int h_permission(struct inode *h_inode, int mask,
18474 + struct path *h_path, int brperm)
18477 + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18480 + if (write_mask && IS_IMMUTABLE(h_inode))
18484 + if (((mask & MAY_EXEC)
18485 + && S_ISREG(h_inode->i_mode)
18486 + && (path_noexec(h_path)
18487 + || !(h_inode->i_mode & S_IXUGO))))
18491 + * - skip the lower fs test in the case of write to ro branch.
18492 + * - nfs dir permission write check is optimized, but a policy for
18493 + * link/rename requires a real check.
18494 + * - nfs always sets MS_POSIXACL regardless its mount option 'noacl.'
18495 + * in this case, generic_permission() returns -EOPNOTSUPP.
18497 + if ((write_mask && !au_br_writable(brperm))
18498 + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode)
18499 + && write_mask && !(mask & MAY_READ))
18500 + || !h_inode->i_op->permission) {
18501 + /* AuLabel(generic_permission); */
18502 + /* AuDbg("get_acl %pf\n", h_inode->i_op->get_acl); */
18503 + err = generic_permission(h_inode, mask);
18504 + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode))
18505 + err = h_inode->i_op->permission(h_inode, mask);
18508 + /* AuLabel(h_inode->permission); */
18509 + err = h_inode->i_op->permission(h_inode, mask);
18514 + err = devcgroup_inode_permission(h_inode, mask);
18516 + err = security_inode_permission(h_inode, mask);
18520 + /* todo: do we need to call ima_path_check()? */
18521 + struct path h_path = {
18525 + err = ima_path_check(&h_path,
18526 + mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
18527 + IMA_COUNT_LEAVE);
18535 +static int aufs_permission(struct inode *inode, int mask)
18538 + aufs_bindex_t bindex, bbot;
18539 + const unsigned char isdir = !!S_ISDIR(inode->i_mode),
18540 + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND));
18541 + struct inode *h_inode;
18542 + struct super_block *sb;
18543 + struct au_branch *br;
18545 + /* todo: support rcu-walk? */
18546 + if (mask & MAY_NOT_BLOCK)
18549 + sb = inode->i_sb;
18550 + si_read_lock(sb, AuLock_FLUSH);
18551 + ii_read_lock_child(inode);
18553 + err = au_iigen_test(inode, au_sigen(sb));
18554 + if (unlikely(err))
18560 + || au_opt_test(au_mntflags(sb), DIRPERM1)) {
18561 + err = au_busy_or_stale();
18562 + h_inode = au_h_iptr(inode, au_ibtop(inode));
18563 + if (unlikely(!h_inode
18564 + || (h_inode->i_mode & S_IFMT)
18565 + != (inode->i_mode & S_IFMT)))
18569 + bindex = au_ibtop(inode);
18570 + br = au_sbr(sb, bindex);
18571 + err = h_permission(h_inode, mask, &br->br_path, br->br_perm);
18574 + && !special_file(h_inode->i_mode)) {
18575 + /* test whether the upper writable branch exists */
18577 + for (; bindex >= 0; bindex--)
18578 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
18586 + /* non-write to dir */
18588 + bbot = au_ibbot(inode);
18589 + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) {
18590 + h_inode = au_h_iptr(inode, bindex);
18592 + err = au_busy_or_stale();
18593 + if (unlikely(!S_ISDIR(h_inode->i_mode)))
18596 + br = au_sbr(sb, bindex);
18597 + err = h_permission(h_inode, mask, &br->br_path,
18603 + ii_read_unlock(inode);
18604 + si_read_unlock(sb);
18608 +/* ---------------------------------------------------------------------- */
18610 +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry,
18611 + unsigned int flags)
18613 + struct dentry *ret, *parent;
18614 + struct inode *inode;
18615 + struct super_block *sb;
18616 + int err, npositive;
18620 + /* todo: support rcu-walk? */
18621 + ret = ERR_PTR(-ECHILD);
18622 + if (flags & LOOKUP_RCU)
18625 + ret = ERR_PTR(-ENAMETOOLONG);
18626 + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN))
18630 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
18631 + ret = ERR_PTR(err);
18632 + if (unlikely(err))
18635 + err = au_di_init(dentry);
18636 + ret = ERR_PTR(err);
18637 + if (unlikely(err))
18641 + npositive = 0; /* suppress a warning */
18642 + parent = dentry->d_parent; /* dir inode is locked */
18643 + di_read_lock_parent(parent, AuLock_IR);
18644 + err = au_alive_dir(parent);
18646 + err = au_digen_test(parent, au_sigen(sb));
18648 + /* regardless LOOKUP_CREATE, always ALLOW_NEG */
18649 + npositive = au_lkup_dentry(dentry, au_dbtop(parent),
18650 + AuLkup_ALLOW_NEG);
18653 + di_read_unlock(parent, AuLock_IR);
18654 + ret = ERR_PTR(err);
18655 + if (unlikely(err < 0))
18659 + inode = au_new_inode(dentry, /*must_new*/0);
18660 + if (IS_ERR(inode)) {
18661 + ret = (void *)inode;
18668 + atomic_inc(&inode->i_count);
18669 + ret = d_splice_alias(inode, dentry);
18671 + if (unlikely(d_need_lookup(dentry))) {
18672 + spin_lock(&dentry->d_lock);
18673 + dentry->d_flags &= ~DCACHE_NEED_LOOKUP;
18674 + spin_unlock(&dentry->d_lock);
18678 + if (!IS_ERR(ret)) {
18680 + if (ret && ret != dentry)
18681 + ii_write_unlock(inode);
18683 + ii_write_unlock(inode);
18690 + di_write_unlock(dentry);
18692 + si_read_unlock(sb);
18697 +/* ---------------------------------------------------------------------- */
18699 +struct aopen_node {
18700 + struct hlist_node hlist;
18701 + struct file *file, *h_file;
18704 +static int au_do_aopen(struct inode *inode, struct file *file)
18706 + struct au_sphlhead *aopen;
18707 + struct aopen_node *node;
18708 + struct au_do_open_args args = {
18710 + .open = au_do_open_nondir
18713 + aopen = &au_sbi(inode->i_sb)->si_aopen;
18714 + spin_lock(&aopen->spin);
18715 + hlist_for_each_entry(node, &aopen->head, hlist)
18716 + if (node->file == file) {
18717 + args.h_file = node->h_file;
18720 + spin_unlock(&aopen->spin);
18721 + /* AuDebugOn(!args.h_file); */
18723 + return au_do_open(file, &args);
18726 +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry,
18727 + struct file *file, unsigned int open_flag,
18728 + umode_t create_mode, int *opened)
18730 + int err, h_opened = *opened;
18731 + unsigned int lkup_flags;
18732 + struct dentry *parent, *d;
18733 + struct au_sphlhead *aopen;
18734 + struct vfsub_aopen_args args = {
18735 + .open_flag = open_flag,
18736 + .create_mode = create_mode,
18737 + .opened = &h_opened
18739 + struct aopen_node aopen_node = {
18744 + AuDbg("open_flag 0%o\n", open_flag);
18745 + AuDbgDentry(dentry);
18748 + if (!au_di(dentry)) {
18749 + lkup_flags = LOOKUP_OPEN;
18750 + if (open_flag & O_CREAT)
18751 + lkup_flags |= LOOKUP_CREATE;
18752 + d = aufs_lookup(dir, dentry, lkup_flags);
18754 + err = PTR_ERR(d);
18759 + * obsoleted dentry found.
18760 + * another error will be returned later.
18766 + AuDbgDentry(dentry);
18769 + if (d_is_positive(dentry)
18770 + || d_unhashed(dentry)
18771 + || d_unlinked(dentry)
18772 + || !(open_flag & O_CREAT))
18773 + goto out_no_open;
18775 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
18776 + if (unlikely(err))
18779 + parent = dentry->d_parent; /* dir is locked */
18780 + di_write_lock_parent(parent);
18781 + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG);
18782 + if (unlikely(err))
18785 + AuDbgDentry(dentry);
18786 + if (d_is_positive(dentry))
18789 + args.file = get_empty_filp();
18790 + err = PTR_ERR(args.file);
18791 + if (IS_ERR(args.file))
18794 + args.file->f_flags = file->f_flags;
18795 + err = au_aopen_or_create(dir, dentry, &args);
18797 + AuDbgFile(args.file);
18798 + if (unlikely(err < 0)) {
18799 + if (h_opened & FILE_OPENED)
18802 + put_filp(args.file);
18806 + /* some filesystems don't set FILE_CREATED while succeeded? */
18807 + *opened |= FILE_CREATED;
18808 + if (h_opened & FILE_OPENED)
18809 + aopen_node.h_file = args.file;
18811 + put_filp(args.file);
18812 + args.file = NULL;
18814 + aopen = &au_sbi(dir->i_sb)->si_aopen;
18815 + au_sphl_add(&aopen_node.hlist, aopen);
18816 + err = finish_open(file, dentry, au_do_aopen, opened);
18817 + au_sphl_del(&aopen_node.hlist, aopen);
18820 + if (aopen_node.h_file)
18821 + fput(aopen_node.h_file);
18824 + di_write_unlock(parent);
18825 + aufs_read_unlock(dentry, AuLock_DW);
18826 + AuDbgDentry(dentry);
18827 + if (unlikely(err < 0))
18830 + if (err >= 0 && !(*opened & FILE_CREATED)) {
18831 + AuLabel(out_no_open);
18833 + err = finish_no_open(file, dentry);
18836 + AuDbg("%pd%s%s\n", dentry,
18837 + (*opened & FILE_CREATED) ? " created" : "",
18838 + (*opened & FILE_OPENED) ? " opened" : "");
18844 +/* ---------------------------------------------------------------------- */
18846 +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent,
18847 + const unsigned char add_entry, aufs_bindex_t bcpup,
18848 + aufs_bindex_t btop)
18851 + struct dentry *h_parent;
18852 + struct inode *h_dir;
18855 + IMustLock(d_inode(parent));
18857 + di_write_lock_parent(parent);
18860 + if (!au_h_dptr(parent, bcpup)) {
18861 + if (btop > bcpup)
18862 + err = au_cpup_dirs(dentry, bcpup);
18863 + else if (btop < bcpup)
18864 + err = au_cpdown_dirs(dentry, bcpup);
18868 + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) {
18869 + h_parent = au_h_dptr(parent, bcpup);
18870 + h_dir = d_inode(h_parent);
18871 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
18872 + err = au_lkup_neg(dentry, bcpup, /*wh*/0);
18873 + /* todo: no unlock here */
18874 + inode_unlock(h_dir);
18876 + AuDbg("bcpup %d\n", bcpup);
18878 + if (d_really_is_negative(dentry))
18879 + au_set_h_dptr(dentry, btop, NULL);
18880 + au_update_dbrange(dentry, /*do_put_zero*/0);
18885 + di_write_unlock(parent);
18887 + err = bcpup; /* success */
18894 + * decide the branch and the parent dir where we will create a new entry.
18895 + * returns new bindex or an error.
18896 + * copyup the parent dir if needed.
18898 +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry,
18899 + struct au_wr_dir_args *args)
18902 + unsigned int flags;
18903 + aufs_bindex_t bcpup, btop, src_btop;
18904 + const unsigned char add_entry
18905 + = au_ftest_wrdir(args->flags, ADD_ENTRY)
18906 + | au_ftest_wrdir(args->flags, TMPFILE);
18907 + struct super_block *sb;
18908 + struct dentry *parent;
18909 + struct au_sbinfo *sbinfo;
18911 + sb = dentry->d_sb;
18912 + sbinfo = au_sbi(sb);
18913 + parent = dget_parent(dentry);
18914 + btop = au_dbtop(dentry);
18916 + if (args->force_btgt < 0) {
18917 + if (src_dentry) {
18918 + src_btop = au_dbtop(src_dentry);
18919 + if (src_btop < btop)
18920 + bcpup = src_btop;
18921 + } else if (add_entry) {
18923 + if (au_ftest_wrdir(args->flags, ISDIR))
18924 + au_fset_wbr(flags, DIR);
18925 + err = AuWbrCreate(sbinfo, dentry, flags);
18929 + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) {
18931 + err = AuWbrCopyup(sbinfo, dentry);
18933 + if (!IS_ROOT(dentry)) {
18934 + di_read_lock_parent(parent, !AuLock_IR);
18935 + err = AuWbrCopyup(sbinfo, dentry);
18936 + di_read_unlock(parent, !AuLock_IR);
18938 + err = AuWbrCopyup(sbinfo, dentry);
18941 + if (unlikely(err < 0))
18945 + bcpup = args->force_btgt;
18946 + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry)));
18949 + AuDbg("btop %d, bcpup %d\n", btop, bcpup);
18951 + if (bcpup == btop)
18952 + goto out; /* success */
18954 + /* copyup the new parent into the branch we process */
18955 + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop);
18957 + if (d_really_is_negative(dentry)) {
18958 + au_set_h_dptr(dentry, btop, NULL);
18959 + au_set_dbtop(dentry, bcpup);
18960 + au_set_dbbot(dentry, bcpup);
18962 + AuDebugOn(add_entry
18963 + && !au_ftest_wrdir(args->flags, TMPFILE)
18964 + && !au_h_dptr(dentry, bcpup));
18972 +/* ---------------------------------------------------------------------- */
18974 +void au_pin_hdir_unlock(struct au_pin *p)
18977 + au_hn_inode_unlock(p->hdir);
18980 +int au_pin_hdir_lock(struct au_pin *p)
18988 + /* even if an error happens later, keep this lock */
18989 + au_hn_inode_lock_nested(p->hdir, p->lsc_hi);
18992 + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent)))
18997 + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode,
18998 + p->h_parent, p->br);
19004 +int au_pin_hdir_relock(struct au_pin *p)
19007 + struct inode *h_i;
19008 + struct dentry *h_d[] = {
19013 + err = au_pin_hdir_lock(p);
19014 + if (unlikely(err))
19017 + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) {
19020 + if (d_is_positive(h_d[i])) {
19021 + h_i = d_inode(h_d[i]);
19022 + err = !h_i->i_nlink;
19030 +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task)
19032 +#if !defined(CONFIG_RWSEM_GENERIC_SPINLOCK) && defined(CONFIG_RWSEM_SPIN_ON_OWNER)
19033 + p->hdir->hi_inode->i_rwsem.owner = task;
19037 +void au_pin_hdir_acquire_nest(struct au_pin *p)
19040 + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map,
19041 + p->lsc_hi, 0, NULL, _RET_IP_);
19042 + au_pin_hdir_set_owner(p, current);
19046 +void au_pin_hdir_release(struct au_pin *p)
19049 + au_pin_hdir_set_owner(p, p->task);
19050 + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, 1, _RET_IP_);
19054 +struct dentry *au_pinned_h_parent(struct au_pin *pin)
19056 + if (pin && pin->parent)
19057 + return au_h_dptr(pin->parent, pin->bindex);
19061 +void au_unpin(struct au_pin *p)
19064 + au_pin_hdir_unlock(p);
19065 + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE))
19066 + vfsub_mnt_drop_write(p->h_mnt);
19070 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19071 + di_read_unlock(p->parent, AuLock_IR);
19072 + iput(p->hdir->hi_inode);
19074 + p->parent = NULL;
19077 + /* do not clear p->task */
19080 +int au_do_pin(struct au_pin *p)
19083 + struct super_block *sb;
19084 + struct inode *h_dir;
19087 + sb = p->dentry->d_sb;
19088 + p->br = au_sbr(sb, p->bindex);
19089 + if (IS_ROOT(p->dentry)) {
19090 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19091 + p->h_mnt = au_br_mnt(p->br);
19092 + err = vfsub_mnt_want_write(p->h_mnt);
19093 + if (unlikely(err)) {
19094 + au_fclr_pin(p->flags, MNT_WRITE);
19101 + p->h_dentry = NULL;
19102 + if (p->bindex <= au_dbbot(p->dentry))
19103 + p->h_dentry = au_h_dptr(p->dentry, p->bindex);
19105 + p->parent = dget_parent(p->dentry);
19106 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19107 + di_read_lock(p->parent, AuLock_IR, p->lsc_di);
19110 + p->h_parent = au_h_dptr(p->parent, p->bindex);
19111 + p->hdir = au_hi(d_inode(p->parent), p->bindex);
19113 + h_dir = p->hdir->hi_inode;
19117 + * if DI_LOCKED is not set, then p->parent may be different
19118 + * and h_parent can be NULL.
19120 + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) {
19122 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19123 + di_read_unlock(p->parent, AuLock_IR);
19125 + p->parent = NULL;
19129 + if (au_ftest_pin(p->flags, MNT_WRITE)) {
19130 + p->h_mnt = au_br_mnt(p->br);
19131 + err = vfsub_mnt_want_write(p->h_mnt);
19132 + if (unlikely(err)) {
19133 + au_fclr_pin(p->flags, MNT_WRITE);
19134 + if (!au_ftest_pin(p->flags, DI_LOCKED))
19135 + di_read_unlock(p->parent, AuLock_IR);
19137 + p->parent = NULL;
19143 + err = au_pin_hdir_lock(p);
19145 + goto out; /* success */
19150 + pr_err("err %d\n", err);
19151 + err = au_busy_or_stale();
19156 +void au_pin_init(struct au_pin *p, struct dentry *dentry,
19157 + aufs_bindex_t bindex, int lsc_di, int lsc_hi,
19158 + unsigned int udba, unsigned char flags)
19160 + p->dentry = dentry;
19162 + p->lsc_di = lsc_di;
19163 + p->lsc_hi = lsc_hi;
19164 + p->flags = flags;
19165 + p->bindex = bindex;
19167 + p->parent = NULL;
19171 + p->h_dentry = NULL;
19172 + p->h_parent = NULL;
19174 + p->task = current;
19177 +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex,
19178 + unsigned int udba, unsigned char flags)
19180 + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2,
19182 + return au_do_pin(pin);
19185 +/* ---------------------------------------------------------------------- */
19188 + * ->setattr() and ->getattr() are called in various cases.
19189 + * chmod, stat: dentry is revalidated.
19190 + * fchmod, fstat: file and dentry are not revalidated, additionally they may be
19192 + * for ->setattr(), ia->ia_file is passed from ftruncate only.
19194 +/* todo: consolidate with do_refresh() and simple_reval_dpath() */
19195 +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen)
19198 + struct dentry *parent;
19201 + if (au_digen_test(dentry, sigen)) {
19202 + parent = dget_parent(dentry);
19203 + di_read_lock_parent(parent, AuLock_IR);
19204 + err = au_refresh_dentry(dentry, parent);
19205 + di_read_unlock(parent, AuLock_IR);
19213 +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia,
19214 + struct au_icpup_args *a)
19218 + aufs_bindex_t btop, ibtop;
19219 + struct dentry *hi_wh, *parent;
19220 + struct inode *inode;
19221 + struct au_wr_dir_args wr_dir_args = {
19222 + .force_btgt = -1,
19226 + if (d_is_dir(dentry))
19227 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
19228 + /* plink or hi_wh() case */
19229 + btop = au_dbtop(dentry);
19230 + inode = d_inode(dentry);
19231 + ibtop = au_ibtop(inode);
19232 + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode))
19233 + wr_dir_args.force_btgt = ibtop;
19234 + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args);
19235 + if (unlikely(err < 0))
19239 + au_fset_icpup(a->flags, DID_CPUP);
19242 + a->pin_flags = AuPin_MNT_WRITE;
19244 + if (!IS_ROOT(dentry)) {
19245 + au_fset_pin(a->pin_flags, DI_LOCKED);
19246 + parent = dget_parent(dentry);
19247 + di_write_lock_parent(parent);
19250 + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags);
19251 + if (unlikely(err))
19255 + a->h_path.dentry = au_h_dptr(dentry, btop);
19256 + a->h_inode = d_inode(a->h_path.dentry);
19257 + if (ia && (ia->ia_valid & ATTR_SIZE)) {
19258 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19259 + if (ia->ia_size < i_size_read(a->h_inode))
19260 + sz = ia->ia_size;
19261 + inode_unlock(a->h_inode);
19265 + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) {
19266 + hi_wh = au_hi_wh(inode, a->btgt);
19268 + struct au_cp_generic cpg = {
19269 + .dentry = dentry,
19275 + err = au_sio_cpup_wh(&cpg, /*file*/NULL);
19276 + if (unlikely(err))
19278 + hi_wh = au_hi_wh(inode, a->btgt);
19279 + /* todo: revalidate hi_wh? */
19284 + au_pin_set_parent_lflag(&a->pin, /*lflag*/0);
19285 + di_downgrade_lock(parent, AuLock_IR);
19289 + if (!au_ftest_icpup(a->flags, DID_CPUP))
19290 + goto out; /* success */
19292 + if (!d_unhashed(dentry)) {
19293 + struct au_cp_generic cpg = {
19294 + .dentry = dentry,
19299 + .flags = AuCpup_DTIME | AuCpup_HOPEN
19301 + err = au_sio_cpup_simple(&cpg);
19303 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19304 + } else if (!hi_wh)
19305 + a->h_path.dentry = au_h_dptr(dentry, a->btgt);
19307 + a->h_path.dentry = hi_wh; /* do not dget here */
19310 + a->h_inode = d_inode(a->h_path.dentry);
19312 + goto out; /* success */
19313 + au_unpin(&a->pin);
19316 + di_write_unlock(parent);
19321 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19325 +static int aufs_setattr(struct dentry *dentry, struct iattr *ia)
19328 + struct inode *inode, *delegated;
19329 + struct super_block *sb;
19330 + struct file *file;
19331 + struct au_icpup_args *a;
19333 + inode = d_inode(dentry);
19334 + IMustLock(inode);
19336 + err = setattr_prepare(dentry, ia);
19337 + if (unlikely(err))
19341 + a = kzalloc(sizeof(*a), GFP_NOFS);
19342 + if (unlikely(!a))
19345 + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID))
19346 + ia->ia_valid &= ~ATTR_MODE;
19349 + sb = dentry->d_sb;
19350 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19351 + if (unlikely(err))
19354 + if (ia->ia_valid & ATTR_FILE) {
19355 + /* currently ftruncate(2) only */
19356 + AuDebugOn(!d_is_reg(dentry));
19357 + file = ia->ia_file;
19358 + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1);
19359 + if (unlikely(err))
19361 + ia->ia_file = au_hf_top(file);
19362 + a->udba = AuOpt_UDBA_NONE;
19364 + /* fchmod() doesn't pass ia_file */
19365 + a->udba = au_opt_udba(sb);
19366 + di_write_lock_child(dentry);
19367 + /* no d_unlinked(), to set UDBA_NONE for root */
19368 + if (d_unhashed(dentry))
19369 + a->udba = AuOpt_UDBA_NONE;
19370 + if (a->udba != AuOpt_UDBA_NONE) {
19371 + AuDebugOn(IS_ROOT(dentry));
19372 + err = au_reval_for_attr(dentry, au_sigen(sb));
19373 + if (unlikely(err))
19378 + err = au_pin_and_icpup(dentry, ia, a);
19379 + if (unlikely(err < 0))
19381 + if (au_ftest_icpup(a->flags, DID_CPUP)) {
19382 + ia->ia_file = NULL;
19383 + ia->ia_valid &= ~ATTR_FILE;
19386 + a->h_path.mnt = au_sbr_mnt(sb, a->btgt);
19387 + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME))
19388 + == (ATTR_MODE | ATTR_CTIME)) {
19389 + err = security_path_chmod(&a->h_path, ia->ia_mode);
19390 + if (unlikely(err))
19392 + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID))
19393 + && (ia->ia_valid & ATTR_CTIME)) {
19394 + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid);
19395 + if (unlikely(err))
19399 + if (ia->ia_valid & ATTR_SIZE) {
19402 + if (ia->ia_size < i_size_read(inode))
19404 + truncate_setsize(inode, ia->ia_size);
19407 + if (ia->ia_valid & ATTR_FILE)
19409 + inode_unlock(a->h_inode);
19410 + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f);
19411 + inode_lock_nested(a->h_inode, AuLsc_I_CHILD);
19413 + delegated = NULL;
19415 + err = vfsub_notify_change(&a->h_path, ia, &delegated);
19417 + err = break_deleg_wait(&delegated);
19425 + * regardless aufs 'acl' option setting.
19426 + * why don't all acl-aware fs call this func from their ->setattr()?
19428 + if (!err && (ia->ia_valid & ATTR_MODE))
19429 + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode);
19431 + au_cpup_attr_changeable(inode);
19434 + inode_unlock(a->h_inode);
19435 + au_unpin(&a->pin);
19436 + if (unlikely(err))
19437 + au_update_dbtop(dentry);
19439 + di_write_unlock(dentry);
19441 + fi_write_unlock(file);
19442 + ia->ia_file = file;
19443 + ia->ia_valid |= ATTR_FILE;
19446 + si_read_unlock(sb);
19448 + au_delayed_kfree(a);
19454 +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL)
19455 +static int au_h_path_to_set_attr(struct dentry *dentry,
19456 + struct au_icpup_args *a, struct path *h_path)
19459 + struct super_block *sb;
19461 + sb = dentry->d_sb;
19462 + a->udba = au_opt_udba(sb);
19463 + /* no d_unlinked(), to set UDBA_NONE for root */
19464 + if (d_unhashed(dentry))
19465 + a->udba = AuOpt_UDBA_NONE;
19466 + if (a->udba != AuOpt_UDBA_NONE) {
19467 + AuDebugOn(IS_ROOT(dentry));
19468 + err = au_reval_for_attr(dentry, au_sigen(sb));
19469 + if (unlikely(err))
19472 + err = au_pin_and_icpup(dentry, /*ia*/NULL, a);
19473 + if (unlikely(err < 0))
19476 + h_path->dentry = a->h_path.dentry;
19477 + h_path->mnt = au_sbr_mnt(sb, a->btgt);
19483 +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode,
19484 + struct au_sxattr *arg)
19487 + struct path h_path;
19488 + struct super_block *sb;
19489 + struct au_icpup_args *a;
19490 + struct inode *h_inode;
19492 + IMustLock(inode);
19495 + a = kzalloc(sizeof(*a), GFP_NOFS);
19496 + if (unlikely(!a))
19499 + sb = dentry->d_sb;
19500 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19501 + if (unlikely(err))
19504 + h_path.dentry = NULL; /* silence gcc */
19505 + di_write_lock_child(dentry);
19506 + err = au_h_path_to_set_attr(dentry, a, &h_path);
19507 + if (unlikely(err))
19510 + inode_unlock(a->h_inode);
19511 + switch (arg->type) {
19512 + case AU_XATTR_SET:
19513 + AuDebugOn(d_is_negative(h_path.dentry));
19514 + err = vfsub_setxattr(h_path.dentry,
19515 + arg->u.set.name, arg->u.set.value,
19516 + arg->u.set.size, arg->u.set.flags);
19519 + err = -EOPNOTSUPP;
19520 + h_inode = d_inode(h_path.dentry);
19521 + if (h_inode->i_op->set_acl)
19522 + /* this will call posix_acl_update_mode */
19523 + err = h_inode->i_op->set_acl(h_inode,
19524 + arg->u.acl_set.acl,
19525 + arg->u.acl_set.type);
19529 + au_cpup_attr_timesizes(inode);
19531 + au_unpin(&a->pin);
19532 + if (unlikely(err))
19533 + au_update_dbtop(dentry);
19536 + di_write_unlock(dentry);
19537 + si_read_unlock(sb);
19539 + au_delayed_kfree(a);
19546 +static void au_refresh_iattr(struct inode *inode, struct kstat *st,
19547 + unsigned int nlink)
19551 + inode->i_mode = st->mode;
19552 + /* don't i_[ug]id_write() here */
19553 + inode->i_uid = st->uid;
19554 + inode->i_gid = st->gid;
19555 + inode->i_atime = st->atime;
19556 + inode->i_mtime = st->mtime;
19557 + inode->i_ctime = st->ctime;
19559 + au_cpup_attr_nlink(inode, /*force*/0);
19560 + if (S_ISDIR(inode->i_mode)) {
19561 + n = inode->i_nlink;
19564 + smp_mb(); /* for i_nlink */
19565 + /* 0 can happen */
19566 + set_nlink(inode, n);
19569 + spin_lock(&inode->i_lock);
19570 + inode->i_blocks = st->blocks;
19571 + i_size_write(inode, st->size);
19572 + spin_unlock(&inode->i_lock);
19576 + * common routine for aufs_getattr() and au_getxattr().
19577 + * returns zero or negative (an error).
19578 + * @dentry will be read-locked in success.
19580 +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path)
19583 + unsigned int mnt_flags, sigen;
19584 + unsigned char udba_none;
19585 + aufs_bindex_t bindex;
19586 + struct super_block *sb, *h_sb;
19587 + struct inode *inode;
19589 + h_path->mnt = NULL;
19590 + h_path->dentry = NULL;
19593 + sb = dentry->d_sb;
19594 + mnt_flags = au_mntflags(sb);
19595 + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE);
19597 + /* support fstat(2) */
19598 + if (!d_unlinked(dentry) && !udba_none) {
19599 + sigen = au_sigen(sb);
19600 + err = au_digen_test(dentry, sigen);
19602 + di_read_lock_child(dentry, AuLock_IR);
19603 + err = au_dbrange_test(dentry);
19604 + if (unlikely(err)) {
19605 + di_read_unlock(dentry, AuLock_IR);
19609 + AuDebugOn(IS_ROOT(dentry));
19610 + di_write_lock_child(dentry);
19611 + err = au_dbrange_test(dentry);
19613 + err = au_reval_for_attr(dentry, sigen);
19615 + di_downgrade_lock(dentry, AuLock_IR);
19617 + di_write_unlock(dentry);
19622 + di_read_lock_child(dentry, AuLock_IR);
19624 + inode = d_inode(dentry);
19625 + bindex = au_ibtop(inode);
19626 + h_path->mnt = au_sbr_mnt(sb, bindex);
19627 + h_sb = h_path->mnt->mnt_sb;
19629 + && !au_test_fs_bad_iattr(h_sb)
19631 + goto out; /* success */
19633 + if (au_dbtop(dentry) == bindex)
19634 + h_path->dentry = au_h_dptr(dentry, bindex);
19635 + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) {
19636 + h_path->dentry = au_plink_lkup(inode, bindex);
19637 + if (IS_ERR(h_path->dentry))
19638 + /* pretending success */
19639 + h_path->dentry = NULL;
19641 + dput(h_path->dentry);
19648 +static int aufs_getattr(struct vfsmount *mnt __maybe_unused,
19649 + struct dentry *dentry, struct kstat *st)
19652 + unsigned char positive;
19653 + struct path h_path;
19654 + struct inode *inode;
19655 + struct super_block *sb;
19657 + inode = d_inode(dentry);
19658 + sb = dentry->d_sb;
19659 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
19660 + if (unlikely(err))
19662 + err = au_h_path_getattr(dentry, /*force*/0, &h_path);
19663 + if (unlikely(err))
19665 + if (unlikely(!h_path.dentry))
19666 + /* illegally overlapped or something */
19667 + goto out_fill; /* pretending success */
19669 + positive = d_is_positive(h_path.dentry);
19671 + err = vfs_getattr(&h_path, st);
19674 + au_refresh_iattr(inode, st,
19675 + d_inode(h_path.dentry)->i_nlink);
19676 + goto out_fill; /* success */
19682 + generic_fillattr(inode, st);
19684 + di_read_unlock(dentry, AuLock_IR);
19686 + si_read_unlock(sb);
19692 +/* ---------------------------------------------------------------------- */
19694 +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode,
19695 + struct delayed_call *done)
19698 + struct dentry *h_dentry;
19699 + struct inode *h_inode;
19701 + aufs_bindex_t bindex;
19703 + ret = NULL; /* suppress a warning */
19708 + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN);
19709 + if (unlikely(err))
19712 + err = au_d_hashed_positive(dentry);
19713 + if (unlikely(err))
19717 + inode = d_inode(dentry);
19718 + bindex = au_ibtop(inode);
19719 + h_inode = au_h_iptr(inode, bindex);
19720 + if (unlikely(!h_inode->i_op->get_link))
19725 + if (au_dbtop(dentry) <= bindex) {
19726 + h_dentry = au_h_dptr(dentry, bindex);
19731 + h_dentry = d_find_any_alias(h_inode);
19732 + if (IS_ERR(h_dentry)) {
19733 + err = PTR_ERR(h_dentry);
19737 + if (unlikely(!h_dentry))
19741 + AuDbg("%pf\n", h_inode->i_op->get_link);
19742 + AuDbgDentry(h_dentry);
19743 + ret = vfs_get_link(h_dentry, done);
19746 + err = PTR_ERR(ret);
19749 + aufs_read_unlock(dentry, AuLock_IR);
19751 + if (unlikely(err))
19752 + ret = ERR_PTR(err);
19753 + AuTraceErrPtr(ret);
19757 +/* ---------------------------------------------------------------------- */
19759 +static int au_is_special(struct inode *inode)
19761 + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK));
19764 +static int aufs_update_time(struct inode *inode, struct timespec *ts, int flags)
19767 + aufs_bindex_t bindex;
19768 + struct super_block *sb;
19769 + struct inode *h_inode;
19770 + struct vfsmount *h_mnt;
19772 + sb = inode->i_sb;
19773 + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode),
19774 + "unexpected s_flags 0x%lx", sb->s_flags);
19776 + /* mmap_sem might be acquired already, cf. aufs_mmap() */
19778 + si_read_lock(sb, AuLock_FLUSH);
19779 + ii_write_lock_child(inode);
19783 + bindex = au_ibtop(inode);
19784 + h_inode = au_h_iptr(inode, bindex);
19785 + if (!au_test_ro(sb, bindex, inode)) {
19786 + h_mnt = au_sbr_mnt(sb, bindex);
19787 + err = vfsub_mnt_want_write(h_mnt);
19789 + err = vfsub_update_time(h_inode, ts, flags);
19790 + vfsub_mnt_drop_write(h_mnt);
19792 + } else if (au_is_special(h_inode)) {
19794 + * Never copy-up here.
19795 + * These special files may already be opened and used for
19796 + * communicating. If we copied it up, then the communication
19797 + * would be corrupted.
19799 + AuWarn1("timestamps for i%lu are ignored "
19800 + "since it is on readonly branch (hi%lu).\n",
19801 + inode->i_ino, h_inode->i_ino);
19802 + } else if (flags & ~S_ATIME) {
19804 + AuIOErr1("unexpected flags 0x%x\n", flags);
19810 + au_cpup_attr_timesizes(inode);
19811 + ii_write_unlock(inode);
19812 + si_read_unlock(sb);
19815 + if (!err && (flags & S_VERSION))
19816 + inode_inc_iversion(inode);
19821 +/* ---------------------------------------------------------------------- */
19823 +/* no getattr version will be set by module.c:aufs_init() */
19824 +struct inode_operations aufs_iop_nogetattr[AuIop_Last],
19826 + [AuIop_SYMLINK] = {
19827 + .permission = aufs_permission,
19828 +#ifdef CONFIG_FS_POSIX_ACL
19829 + .get_acl = aufs_get_acl,
19830 + .set_acl = aufs_set_acl, /* unsupport for symlink? */
19833 + .setattr = aufs_setattr,
19834 + .getattr = aufs_getattr,
19836 +#ifdef CONFIG_AUFS_XATTR
19837 + .listxattr = aufs_listxattr,
19840 + .readlink = generic_readlink,
19841 + .get_link = aufs_get_link,
19843 + /* .update_time = aufs_update_time */
19846 + .create = aufs_create,
19847 + .lookup = aufs_lookup,
19848 + .link = aufs_link,
19849 + .unlink = aufs_unlink,
19850 + .symlink = aufs_symlink,
19851 + .mkdir = aufs_mkdir,
19852 + .rmdir = aufs_rmdir,
19853 + .mknod = aufs_mknod,
19854 + .rename = aufs_rename,
19856 + .permission = aufs_permission,
19857 +#ifdef CONFIG_FS_POSIX_ACL
19858 + .get_acl = aufs_get_acl,
19859 + .set_acl = aufs_set_acl,
19862 + .setattr = aufs_setattr,
19863 + .getattr = aufs_getattr,
19865 +#ifdef CONFIG_AUFS_XATTR
19866 + .listxattr = aufs_listxattr,
19869 + .update_time = aufs_update_time,
19870 + .atomic_open = aufs_atomic_open,
19871 + .tmpfile = aufs_tmpfile
19873 + [AuIop_OTHER] = {
19874 + .permission = aufs_permission,
19875 +#ifdef CONFIG_FS_POSIX_ACL
19876 + .get_acl = aufs_get_acl,
19877 + .set_acl = aufs_set_acl,
19880 + .setattr = aufs_setattr,
19881 + .getattr = aufs_getattr,
19883 +#ifdef CONFIG_AUFS_XATTR
19884 + .listxattr = aufs_listxattr,
19887 + .update_time = aufs_update_time
19890 diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c
19891 --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100
19892 +++ linux/fs/aufs/i_op_del.c 2016-10-09 16:55:36.492701639 +0200
19895 + * Copyright (C) 2005-2016 Junjiro R. Okajima
19897 + * This program, aufs is free software; you can redistribute it and/or modify
19898 + * it under the terms of the GNU General Public License as published by
19899 + * the Free Software Foundation; either version 2 of the License, or
19900 + * (at your option) any later version.
19902 + * This program is distributed in the hope that it will be useful,
19903 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
19904 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19905 + * GNU General Public License for more details.
19907 + * You should have received a copy of the GNU General Public License
19908 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
19912 + * inode operations (del entry)
19918 + * decide if a new whiteout for @dentry is necessary or not.
19919 + * when it is necessary, prepare the parent dir for the upper branch whose
19920 + * branch index is @bcpup for creation. the actual creation of the whiteout will
19921 + * be done by caller.
19923 + * 0: wh is unnecessary
19924 + * plus: wh is necessary
19927 +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup)
19929 + int need_wh, err;
19930 + aufs_bindex_t btop;
19931 + struct super_block *sb;
19933 + sb = dentry->d_sb;
19934 + btop = au_dbtop(dentry);
19935 + if (*bcpup < 0) {
19937 + if (au_test_ro(sb, btop, d_inode(dentry))) {
19938 + err = AuWbrCopyup(au_sbi(sb), dentry);
19940 + if (unlikely(err < 0))
19944 + AuDebugOn(btop < *bcpup
19945 + || au_test_ro(sb, *bcpup, d_inode(dentry)));
19946 + AuDbg("bcpup %d, btop %d\n", *bcpup, btop);
19948 + if (*bcpup != btop) {
19949 + err = au_cpup_dirs(dentry, *bcpup);
19950 + if (unlikely(err))
19954 + struct au_dinfo *dinfo, *tmp;
19956 + need_wh = -ENOMEM;
19957 + dinfo = au_di(dentry);
19958 + tmp = au_di_alloc(sb, AuLsc_DI_TMP);
19960 + au_di_cp(tmp, dinfo);
19961 + au_di_swap(tmp, dinfo);
19962 + /* returns the number of positive dentries */
19963 + need_wh = au_lkup_dentry(dentry, btop + 1,
19964 + /* AuLkup_IGNORE_PERM */ 0);
19965 + au_di_swap(tmp, dinfo);
19966 + au_rw_write_unlock(&tmp->di_rwsem);
19970 + AuDbg("need_wh %d\n", need_wh);
19978 + * simple tests for the del-entry operations.
19979 + * following the checks in vfs, plus the parent-child relationship.
19981 +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex,
19982 + struct dentry *h_parent, int isdir)
19986 + struct dentry *h_dentry, *h_latest;
19987 + struct inode *h_inode;
19989 + h_dentry = au_h_dptr(dentry, bindex);
19990 + if (d_really_is_positive(dentry)) {
19992 + if (unlikely(d_is_negative(h_dentry)))
19994 + h_inode = d_inode(h_dentry);
19995 + if (unlikely(!h_inode->i_nlink))
19998 + h_mode = h_inode->i_mode;
20001 + if (unlikely(S_ISDIR(h_mode)))
20003 + } else if (unlikely(!S_ISDIR(h_mode))) {
20008 + /* rename(2) case */
20010 + if (unlikely(d_is_positive(h_dentry)))
20015 + /* expected parent dir is locked */
20016 + if (unlikely(h_parent != h_dentry->d_parent))
20021 + * rmdir a dir may break the consistency on some filesystem.
20022 + * let's try heavy test.
20025 + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)
20026 + && au_test_h_perm(d_inode(h_parent),
20027 + MAY_EXEC | MAY_WRITE)))
20030 + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent);
20032 + if (IS_ERR(h_latest))
20034 + if (h_latest == h_dentry)
20043 + * decide the branch where we operate for @dentry. the branch index will be set
20044 + * @rbcpup. after diciding it, 'pin' it and store the timestamps of the parent
20045 + * dir for reverting.
20046 + * when a new whiteout is necessary, create it.
20048 +static struct dentry*
20049 +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup,
20050 + struct au_dtime *dt, struct au_pin *pin)
20052 + struct dentry *wh_dentry;
20053 + struct super_block *sb;
20054 + struct path h_path;
20055 + int err, need_wh;
20056 + unsigned int udba;
20057 + aufs_bindex_t bcpup;
20059 + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup);
20060 + wh_dentry = ERR_PTR(need_wh);
20061 + if (unlikely(need_wh < 0))
20064 + sb = dentry->d_sb;
20065 + udba = au_opt_udba(sb);
20067 + err = au_pin(pin, dentry, bcpup, udba,
20068 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
20069 + wh_dentry = ERR_PTR(err);
20070 + if (unlikely(err))
20073 + h_path.dentry = au_pinned_h_parent(pin);
20074 + if (udba != AuOpt_UDBA_NONE
20075 + && au_dbtop(dentry) == bcpup) {
20076 + err = au_may_del(dentry, bcpup, h_path.dentry, isdir);
20077 + wh_dentry = ERR_PTR(err);
20078 + if (unlikely(err))
20082 + h_path.mnt = au_sbr_mnt(sb, bcpup);
20083 + au_dtime_store(dt, au_pinned_parent(pin), &h_path);
20084 + wh_dentry = NULL;
20086 + goto out; /* success, no need to create whiteout */
20088 + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry);
20089 + if (IS_ERR(wh_dentry))
20092 + /* returns with the parent is locked and wh_dentry is dget-ed */
20093 + goto out; /* success */
20098 + return wh_dentry;
20102 + * when removing a dir, rename it to a unique temporary whiteout-ed name first
20103 + * in order to be revertible and save time for removing many child whiteouts
20105 + * returns 1 when there are too many child whiteout and caller should remove
20106 + * them asynchronously. returns 0 when the number of children is enough small to
20107 + * remove now or the branch fs is a remote fs.
20108 + * otherwise return an error.
20110 +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex,
20111 + struct au_nhash *whlist, struct inode *dir)
20113 + int rmdir_later, err, dirwh;
20114 + struct dentry *h_dentry;
20115 + struct super_block *sb;
20116 + struct inode *inode;
20118 + sb = dentry->d_sb;
20119 + SiMustAnyLock(sb);
20120 + h_dentry = au_h_dptr(dentry, bindex);
20121 + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex));
20122 + if (unlikely(err))
20125 + /* stop monitoring */
20126 + inode = d_inode(dentry);
20127 + au_hn_free(au_hi(inode, bindex));
20129 + if (!au_test_fs_remote(h_dentry->d_sb)) {
20130 + dirwh = au_sbi(sb)->si_dirwh;
20131 + rmdir_later = (dirwh <= 1);
20132 + if (!rmdir_later)
20133 + rmdir_later = au_nhash_test_longer_wh(whlist, bindex,
20136 + return rmdir_later;
20139 + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist);
20140 + if (unlikely(err)) {
20141 + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n",
20142 + h_dentry, bindex, err);
20152 + * final procedure for deleting a entry.
20153 + * maintain dentry and iattr.
20155 +static void epilog(struct inode *dir, struct dentry *dentry,
20156 + aufs_bindex_t bindex)
20158 + struct inode *inode;
20160 + inode = d_inode(dentry);
20162 + inode->i_ctime = dir->i_ctime;
20164 + au_dir_ts(dir, bindex);
20165 + dir->i_version++;
20169 + * when an error happened, remove the created whiteout and revert everything.
20171 +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex,
20172 + aufs_bindex_t bwh, struct dentry *wh_dentry,
20173 + struct dentry *dentry, struct au_dtime *dt)
20176 + struct path h_path = {
20177 + .dentry = wh_dentry,
20178 + .mnt = au_sbr_mnt(dir->i_sb, bindex)
20181 + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry);
20183 + au_set_dbwh(dentry, bwh);
20184 + au_dtime_revert(dt);
20188 + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr);
20192 +/* ---------------------------------------------------------------------- */
20194 +int aufs_unlink(struct inode *dir, struct dentry *dentry)
20197 + aufs_bindex_t bwh, bindex, btop;
20198 + struct inode *inode, *h_dir, *delegated;
20199 + struct dentry *parent, *wh_dentry;
20200 + /* to reuduce stack size */
20202 + struct au_dtime dt;
20203 + struct au_pin pin;
20204 + struct path h_path;
20210 + a = kmalloc(sizeof(*a), GFP_NOFS);
20211 + if (unlikely(!a))
20214 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN);
20215 + if (unlikely(err))
20217 + err = au_d_hashed_positive(dentry);
20218 + if (unlikely(err))
20220 + inode = d_inode(dentry);
20221 + IMustLock(inode);
20223 + if (unlikely(d_is_dir(dentry)))
20224 + goto out_unlock; /* possible? */
20226 + btop = au_dbtop(dentry);
20227 + bwh = au_dbwh(dentry);
20229 + parent = dentry->d_parent; /* dir inode is locked */
20230 + di_write_lock_parent(parent);
20231 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt,
20233 + err = PTR_ERR(wh_dentry);
20234 + if (IS_ERR(wh_dentry))
20237 + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop);
20238 + a->h_path.dentry = au_h_dptr(dentry, btop);
20239 + dget(a->h_path.dentry);
20240 + if (bindex == btop) {
20241 + h_dir = au_pinned_h_dir(&a->pin);
20242 + delegated = NULL;
20243 + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0);
20244 + if (unlikely(err == -EWOULDBLOCK)) {
20245 + pr_warn("cannot retry for NFSv4 delegation"
20246 + " for an internal unlink\n");
20250 + /* dir inode is locked */
20251 + h_dir = d_inode(wh_dentry->d_parent);
20252 + IMustLock(h_dir);
20257 + vfsub_drop_nlink(inode);
20258 + epilog(dir, dentry, bindex);
20260 + /* update target timestamps */
20261 + if (bindex == btop) {
20262 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL);
20264 + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20266 + /* todo: this timestamp may be reverted later */
20267 + inode->i_ctime = h_dir->i_ctime;
20268 + goto out_unpin; /* success */
20275 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20282 + au_unpin(&a->pin);
20284 + dput(a->h_path.dentry);
20286 + di_write_unlock(parent);
20288 + aufs_read_unlock(dentry, AuLock_DW);
20290 + au_delayed_kfree(a);
20295 +int aufs_rmdir(struct inode *dir, struct dentry *dentry)
20297 + int err, rmdir_later;
20298 + aufs_bindex_t bwh, bindex, btop;
20299 + struct inode *inode;
20300 + struct dentry *parent, *wh_dentry, *h_dentry;
20301 + struct au_whtmp_rmdir *args;
20302 + /* to reuduce stack size */
20304 + struct au_dtime dt;
20305 + struct au_pin pin;
20311 + a = kmalloc(sizeof(*a), GFP_NOFS);
20312 + if (unlikely(!a))
20315 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN);
20316 + if (unlikely(err))
20318 + err = au_alive_dir(dentry);
20319 + if (unlikely(err))
20321 + inode = d_inode(dentry);
20322 + IMustLock(inode);
20324 + if (unlikely(!d_is_dir(dentry)))
20325 + goto out_unlock; /* possible? */
20328 + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS);
20329 + if (unlikely(!args))
20332 + parent = dentry->d_parent; /* dir inode is locked */
20333 + di_write_lock_parent(parent);
20334 + err = au_test_empty(dentry, &args->whlist);
20335 + if (unlikely(err))
20338 + btop = au_dbtop(dentry);
20339 + bwh = au_dbwh(dentry);
20341 + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt,
20343 + err = PTR_ERR(wh_dentry);
20344 + if (IS_ERR(wh_dentry))
20347 + h_dentry = au_h_dptr(dentry, btop);
20350 + if (bindex == btop) {
20351 + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir);
20353 + rmdir_later = err;
20357 + /* stop monitoring */
20358 + au_hn_free(au_hi(inode, btop));
20360 + /* dir inode is locked */
20361 + IMustLock(d_inode(wh_dentry->d_parent));
20366 + vfsub_dead_dir(inode);
20367 + au_set_dbdiropq(dentry, -1);
20368 + epilog(dir, dentry, bindex);
20370 + if (rmdir_later) {
20371 + au_whtmp_kick_rmdir(dir, btop, h_dentry, args);
20375 + goto out_unpin; /* success */
20383 + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry,
20390 + au_unpin(&a->pin);
20394 + di_write_unlock(parent);
20396 + au_whtmp_rmdir_free(args);
20398 + aufs_read_unlock(dentry, AuLock_DW);
20400 + au_delayed_kfree(a);
20405 diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c
20406 --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100
20407 +++ linux/fs/aufs/i_op_ren.c 2016-12-17 12:28:17.595211562 +0100
20410 + * Copyright (C) 2005-2016 Junjiro R. Okajima
20412 + * This program, aufs is free software; you can redistribute it and/or modify
20413 + * it under the terms of the GNU General Public License as published by
20414 + * the Free Software Foundation; either version 2 of the License, or
20415 + * (at your option) any later version.
20417 + * This program is distributed in the hope that it will be useful,
20418 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
20419 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20420 + * GNU General Public License for more details.
20422 + * You should have received a copy of the GNU General Public License
20423 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
20427 + * inode operation (rename entry)
20428 + * todo: this is crazy monster
20433 +enum { AuSRC, AuDST, AuSrcDst };
20434 +enum { AuPARENT, AuCHILD, AuParentChild };
20436 +#define AuRen_ISDIR_SRC 1
20437 +#define AuRen_ISDIR_DST (1 << 1)
20438 +#define AuRen_ISSAMEDIR (1 << 2)
20439 +#define AuRen_WHSRC (1 << 3)
20440 +#define AuRen_WHDST (1 << 4)
20441 +#define AuRen_MNT_WRITE (1 << 5)
20442 +#define AuRen_DT_DSTDIR (1 << 6)
20443 +#define AuRen_DIROPQ_SRC (1 << 7)
20444 +#define AuRen_DIROPQ_DST (1 << 8)
20445 +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name)
20446 +#define au_fset_ren(flags, name) \
20447 + do { (flags) |= AuRen_##name; } while (0)
20448 +#define au_fclr_ren(flags, name) \
20449 + do { (flags) &= ~AuRen_##name; } while (0)
20451 +struct au_ren_args {
20453 + struct dentry *dentry, *h_dentry, *parent, *h_parent,
20455 + struct inode *dir, *inode;
20456 + struct au_hinode *hdir, *hinode;
20457 + struct au_dtime dt[AuParentChild];
20458 + aufs_bindex_t btop, bdiropq;
20461 +#define src_dentry sd[AuSRC].dentry
20462 +#define src_dir sd[AuSRC].dir
20463 +#define src_inode sd[AuSRC].inode
20464 +#define src_h_dentry sd[AuSRC].h_dentry
20465 +#define src_parent sd[AuSRC].parent
20466 +#define src_h_parent sd[AuSRC].h_parent
20467 +#define src_wh_dentry sd[AuSRC].wh_dentry
20468 +#define src_hdir sd[AuSRC].hdir
20469 +#define src_hinode sd[AuSRC].hinode
20470 +#define src_h_dir sd[AuSRC].hdir->hi_inode
20471 +#define src_dt sd[AuSRC].dt
20472 +#define src_btop sd[AuSRC].btop
20473 +#define src_bdiropq sd[AuSRC].bdiropq
20475 +#define dst_dentry sd[AuDST].dentry
20476 +#define dst_dir sd[AuDST].dir
20477 +#define dst_inode sd[AuDST].inode
20478 +#define dst_h_dentry sd[AuDST].h_dentry
20479 +#define dst_parent sd[AuDST].parent
20480 +#define dst_h_parent sd[AuDST].h_parent
20481 +#define dst_wh_dentry sd[AuDST].wh_dentry
20482 +#define dst_hdir sd[AuDST].hdir
20483 +#define dst_hinode sd[AuDST].hinode
20484 +#define dst_h_dir sd[AuDST].hdir->hi_inode
20485 +#define dst_dt sd[AuDST].dt
20486 +#define dst_btop sd[AuDST].btop
20487 +#define dst_bdiropq sd[AuDST].bdiropq
20489 + struct dentry *h_trap;
20490 + struct au_branch *br;
20491 + struct path h_path;
20492 + struct au_nhash whlist;
20493 + aufs_bindex_t btgt, src_bwh;
20496 + unsigned short auren_flags;
20497 + unsigned char flags; /* syscall parameter */
20498 + unsigned char exchange;
20501 + struct au_whtmp_rmdir *thargs;
20502 + struct dentry *h_dst;
20505 +/* ---------------------------------------------------------------------- */
20508 + * functions for reverting.
20509 + * when an error happened in a single rename systemcall, we should revert
20510 + * everything as if nothing happened.
20511 + * we don't need to revert the copied-up/down the parent dir since they are
20515 +#define RevertFailure(fmt, ...) do { \
20516 + AuIOErr("revert failure: " fmt " (%d, %d)\n", \
20517 + ##__VA_ARGS__, err, rerr); \
20521 +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx)
20524 + struct dentry *d;
20525 +#define src_or_dst(member) a->sd[idx].member
20527 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20528 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20529 + rerr = au_diropq_remove(d, a->btgt);
20530 + au_hn_inode_unlock(src_or_dst(hinode));
20531 + au_set_dbdiropq(d, src_or_dst(bdiropq));
20533 + RevertFailure("remove diropq %pd", d);
20535 +#undef src_or_dst_
20538 +static void au_ren_rev_diropq(int err, struct au_ren_args *a)
20540 + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC))
20541 + au_ren_do_rev_diropq(err, a, AuSRC);
20542 + if (au_ftest_ren(a->auren_flags, DIROPQ_DST))
20543 + au_ren_do_rev_diropq(err, a, AuDST);
20546 +static void au_ren_rev_rename(int err, struct au_ren_args *a)
20549 + struct inode *delegated;
20551 + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name,
20552 + a->src_h_parent);
20553 + rerr = PTR_ERR(a->h_path.dentry);
20554 + if (IS_ERR(a->h_path.dentry)) {
20555 + RevertFailure("lkup one %pd", a->src_dentry);
20559 + delegated = NULL;
20560 + rerr = vfsub_rename(a->dst_h_dir,
20561 + au_h_dptr(a->src_dentry, a->btgt),
20562 + a->src_h_dir, &a->h_path, &delegated, a->flags);
20563 + if (unlikely(rerr == -EWOULDBLOCK)) {
20564 + pr_warn("cannot retry for NFSv4 delegation"
20565 + " for an internal rename\n");
20568 + d_drop(a->h_path.dentry);
20569 + dput(a->h_path.dentry);
20570 + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */
20572 + RevertFailure("rename %pd", a->src_dentry);
20575 +static void au_ren_rev_whtmp(int err, struct au_ren_args *a)
20578 + struct inode *delegated;
20580 + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name,
20581 + a->dst_h_parent);
20582 + rerr = PTR_ERR(a->h_path.dentry);
20583 + if (IS_ERR(a->h_path.dentry)) {
20584 + RevertFailure("lkup one %pd", a->dst_dentry);
20587 + if (d_is_positive(a->h_path.dentry)) {
20588 + d_drop(a->h_path.dentry);
20589 + dput(a->h_path.dentry);
20593 + delegated = NULL;
20594 + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path,
20595 + &delegated, a->flags);
20596 + if (unlikely(rerr == -EWOULDBLOCK)) {
20597 + pr_warn("cannot retry for NFSv4 delegation"
20598 + " for an internal rename\n");
20601 + d_drop(a->h_path.dentry);
20602 + dput(a->h_path.dentry);
20604 + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst));
20606 + RevertFailure("rename %pd", a->h_dst);
20609 +static void au_ren_rev_whsrc(int err, struct au_ren_args *a)
20613 + a->h_path.dentry = a->src_wh_dentry;
20614 + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry);
20615 + au_set_dbwh(a->src_dentry, a->src_bwh);
20617 + RevertFailure("unlink %pd", a->src_wh_dentry);
20619 +#undef RevertFailure
20621 +/* ---------------------------------------------------------------------- */
20624 + * when we have to copyup the renaming entry, do it with the rename-target name
20625 + * in order to minimize the cost (the later actual rename is unnecessary).
20626 + * otherwise rename it on the target branch.
20628 +static int au_ren_or_cpup(struct au_ren_args *a)
20631 + struct dentry *d;
20632 + struct inode *delegated;
20634 + d = a->src_dentry;
20635 + if (au_dbtop(d) == a->btgt) {
20636 + a->h_path.dentry = a->dst_h_dentry;
20637 + AuDebugOn(au_dbtop(d) != a->btgt);
20638 + delegated = NULL;
20639 + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt),
20640 + a->dst_h_dir, &a->h_path, &delegated,
20642 + if (unlikely(err == -EWOULDBLOCK)) {
20643 + pr_warn("cannot retry for NFSv4 delegation"
20644 + " for an internal rename\n");
20650 + if (!err && a->h_dst)
20651 + /* it will be set to dinfo later */
20657 +/* cf. aufs_rmdir() */
20658 +static int au_ren_del_whtmp(struct au_ren_args *a)
20661 + struct inode *dir;
20663 + dir = a->dst_dir;
20664 + SiMustAnyLock(dir->i_sb);
20665 + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt,
20666 + au_sbi(dir->i_sb)->si_dirwh)
20667 + || au_test_fs_remote(a->h_dst->d_sb)) {
20668 + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist);
20669 + if (unlikely(err))
20670 + pr_warn("failed removing whtmp dir %pd (%d), "
20671 + "ignored.\n", a->h_dst, err);
20673 + au_nhash_wh_free(&a->thargs->whlist);
20674 + a->thargs->whlist = a->whlist;
20675 + a->whlist.nh_num = 0;
20676 + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs);
20678 + a->thargs = NULL;
20684 +/* make it 'opaque' dir. */
20685 +static int au_ren_do_diropq(struct au_ren_args *a, int idx)
20688 + struct dentry *d, *diropq;
20689 +#define src_or_dst(member) a->sd[idx].member
20692 + d = src_or_dst(dentry); /* {src,dst}_dentry */
20693 + src_or_dst(bdiropq) = au_dbdiropq(d);
20694 + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt);
20695 + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD);
20696 + diropq = au_diropq_create(d, a->btgt);
20697 + au_hn_inode_unlock(src_or_dst(hinode));
20698 + if (IS_ERR(diropq))
20699 + err = PTR_ERR(diropq);
20703 +#undef src_or_dst_
20707 +static int au_ren_diropq(struct au_ren_args *a)
20710 + unsigned char always;
20711 + struct dentry *d;
20714 + d = a->dst_dentry; /* already renamed on the branch */
20715 + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ);
20716 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
20717 + && a->btgt != au_dbdiropq(a->src_dentry)
20718 + && (a->dst_wh_dentry
20719 + || a->btgt <= au_dbdiropq(d)
20720 + /* hide the lower to keep xino */
20721 + /* the lowers may not be a dir, but we hide them anyway */
20722 + || a->btgt < au_dbbot(d)
20725 + err = au_ren_do_diropq(a, AuSRC);
20726 + if (unlikely(err))
20728 + au_fset_ren(a->auren_flags, DIROPQ_SRC);
20730 + if (!a->exchange)
20731 + goto out; /* success */
20733 + d = a->src_dentry; /* already renamed on the branch */
20734 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20735 + && a->btgt != au_dbdiropq(a->dst_dentry)
20736 + && (a->btgt < au_dbdiropq(d)
20737 + || a->btgt < au_dbbot(d)
20739 + AuDbgDentry(a->src_dentry);
20740 + AuDbgDentry(a->dst_dentry);
20741 + err = au_ren_do_diropq(a, AuDST);
20742 + if (unlikely(err))
20743 + goto out_rev_src;
20744 + au_fset_ren(a->auren_flags, DIROPQ_DST);
20746 + goto out; /* success */
20749 + AuDbg("err %d, reverting src\n", err);
20750 + au_ren_rev_diropq(err, a);
20755 +static int do_rename(struct au_ren_args *a)
20758 + struct dentry *d, *h_d;
20760 + if (!a->exchange) {
20761 + /* prepare workqueue args for asynchronous rmdir */
20762 + h_d = a->dst_h_dentry;
20763 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)
20764 + && d_is_positive(h_d)) {
20766 + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb,
20768 + if (unlikely(!a->thargs))
20770 + a->h_dst = dget(h_d);
20773 + /* create whiteout for src_dentry */
20774 + if (au_ftest_ren(a->auren_flags, WHSRC)) {
20775 + a->src_bwh = au_dbwh(a->src_dentry);
20776 + AuDebugOn(a->src_bwh >= 0);
20777 + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt,
20778 + a->src_h_parent);
20779 + err = PTR_ERR(a->src_wh_dentry);
20780 + if (IS_ERR(a->src_wh_dentry))
20784 + /* lookup whiteout for dentry */
20785 + if (au_ftest_ren(a->auren_flags, WHDST)) {
20786 + h_d = au_wh_lkup(a->dst_h_parent,
20787 + &a->dst_dentry->d_name, a->br);
20788 + err = PTR_ERR(h_d);
20791 + if (d_is_negative(h_d))
20794 + a->dst_wh_dentry = h_d;
20797 + /* rename dentry to tmpwh */
20799 + err = au_whtmp_ren(a->dst_h_dentry, a->br);
20800 + if (unlikely(err))
20803 + d = a->dst_dentry;
20804 + au_set_h_dptr(d, a->btgt, NULL);
20805 + err = au_lkup_neg(d, a->btgt, /*wh*/0);
20806 + if (unlikely(err))
20808 + a->dst_h_dentry = au_h_dptr(d, a->btgt);
20812 + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt);
20814 + /* rename by vfs_rename or cpup */
20815 + err = au_ren_or_cpup(a);
20816 + if (unlikely(err))
20817 + /* leave the copied-up one */
20820 + /* make dir opaque */
20821 + err = au_ren_diropq(a);
20822 + if (unlikely(err))
20825 + /* update target timestamps */
20826 + if (a->exchange) {
20827 + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt);
20828 + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt);
20829 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20830 + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20832 + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt);
20833 + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt);
20834 + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/
20835 + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime;
20837 + if (!a->exchange) {
20838 + /* remove whiteout for dentry */
20839 + if (a->dst_wh_dentry) {
20840 + a->h_path.dentry = a->dst_wh_dentry;
20841 + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path,
20843 + if (unlikely(err))
20847 + /* remove whtmp */
20849 + au_ren_del_whtmp(a); /* ignore this error */
20851 + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0);
20854 + goto out_success;
20857 + au_ren_rev_diropq(err, a);
20859 + au_ren_rev_rename(err, a);
20863 + au_ren_rev_whtmp(err, a);
20865 + dput(a->dst_wh_dentry);
20866 + a->dst_wh_dentry = NULL;
20868 + if (a->src_wh_dentry)
20869 + au_ren_rev_whsrc(err, a);
20871 + dput(a->src_wh_dentry);
20872 + dput(a->dst_wh_dentry);
20876 + au_whtmp_rmdir_free(a->thargs);
20877 + a->thargs = NULL;
20883 +/* ---------------------------------------------------------------------- */
20886 + * test if @dentry dir can be rename destination or not.
20887 + * success means, it is a logically empty dir.
20889 +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist)
20891 + return au_test_empty(dentry, whlist);
20895 + * test if @dentry dir can be rename source or not.
20896 + * if it can, return 0 and @children is filled.
20898 + * - it is a logically empty dir.
20899 + * - or, it exists on writable branch and has no children including whiteouts
20900 + * on the lower branch.
20902 +static int may_rename_srcdir(struct dentry *dentry, aufs_bindex_t btgt)
20905 + unsigned int rdhash;
20906 + aufs_bindex_t btop;
20908 + btop = au_dbtop(dentry);
20909 + if (btop != btgt) {
20910 + struct au_nhash whlist;
20912 + SiMustAnyLock(dentry->d_sb);
20913 + rdhash = au_sbi(dentry->d_sb)->si_rdhash;
20915 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL,
20917 + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS);
20918 + if (unlikely(err))
20920 + err = au_test_empty(dentry, &whlist);
20921 + au_nhash_wh_free(&whlist);
20925 + if (btop == au_dbtaildir(dentry))
20926 + return 0; /* success */
20928 + err = au_test_empty_lower(dentry);
20931 + if (err == -ENOTEMPTY) {
20932 + AuWarn1("renaming dir who has child(ren) on multiple branches,"
20933 + " is not supported\n");
20939 +/* side effect: sets whlist and h_dentry */
20940 +static int au_ren_may_dir(struct au_ren_args *a)
20943 + unsigned int rdhash;
20944 + struct dentry *d;
20946 + d = a->dst_dentry;
20947 + SiMustAnyLock(d->d_sb);
20950 + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) {
20951 + rdhash = au_sbi(d->d_sb)->si_rdhash;
20953 + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d));
20954 + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS);
20955 + if (unlikely(err))
20958 + if (!a->exchange) {
20959 + au_set_dbtop(d, a->dst_btop);
20960 + err = may_rename_dstdir(d, &a->whlist);
20961 + au_set_dbtop(d, a->btgt);
20963 + err = may_rename_srcdir(d, a->btgt);
20965 + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d));
20966 + if (unlikely(err))
20969 + d = a->src_dentry;
20970 + a->src_h_dentry = au_h_dptr(d, au_dbtop(d));
20971 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
20972 + err = may_rename_srcdir(d, a->btgt);
20973 + if (unlikely(err)) {
20974 + au_nhash_wh_free(&a->whlist);
20975 + a->whlist.nh_num = 0;
20982 +/* ---------------------------------------------------------------------- */
20985 + * simple tests for rename.
20986 + * following the checks in vfs, plus the parent-child relationship.
20988 +static int au_may_ren(struct au_ren_args *a)
20991 + struct inode *h_inode;
20993 + if (a->src_btop == a->btgt) {
20994 + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent,
20995 + au_ftest_ren(a->auren_flags, ISDIR_SRC));
20996 + if (unlikely(err))
20999 + if (unlikely(a->src_h_dentry == a->h_trap))
21004 + if (a->dst_btop != a->btgt)
21007 + err = -ENOTEMPTY;
21008 + if (unlikely(a->dst_h_dentry == a->h_trap))
21012 + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST);
21013 + if (d_really_is_negative(a->dst_dentry)) {
21014 + if (d_is_negative(a->dst_h_dentry))
21015 + err = au_may_add(a->dst_dentry, a->btgt,
21016 + a->dst_h_parent, isdir);
21018 + if (unlikely(d_is_negative(a->dst_h_dentry)))
21020 + h_inode = d_inode(a->dst_h_dentry);
21021 + if (h_inode->i_nlink)
21022 + err = au_may_del(a->dst_dentry, a->btgt,
21023 + a->dst_h_parent, isdir);
21027 + if (unlikely(err == -ENOENT || err == -EEXIST))
21033 +/* ---------------------------------------------------------------------- */
21038 + * - src_dir and dir by lock_rename()
21039 + * - inode if exitsts
21042 + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls,
21044 + * + di_write_lock2_child()
21045 + * + di_write_lock_child()
21046 + * + ii_write_lock_child()
21047 + * + di_write_lock_child2()
21048 + * + ii_write_lock_child2()
21049 + * + src_parent and parent
21050 + * + di_write_lock_parent()
21051 + * + ii_write_lock_parent()
21052 + * + di_write_lock_parent2()
21053 + * + ii_write_lock_parent2()
21054 + * + lower src_dir and dir by vfsub_lock_rename()
21055 + * + verify the every relationships between child and parent. if any
21056 + * of them failed, unlock all and return -EBUSY.
21058 +static void au_ren_unlock(struct au_ren_args *a)
21060 + vfsub_unlock_rename(a->src_h_parent, a->src_hdir,
21061 + a->dst_h_parent, a->dst_hdir);
21062 + if (au_ftest_ren(a->auren_flags, MNT_WRITE))
21063 + vfsub_mnt_drop_write(au_br_mnt(a->br));
21066 +static int au_ren_lock(struct au_ren_args *a)
21069 + unsigned int udba;
21072 + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt);
21073 + a->src_hdir = au_hi(a->src_dir, a->btgt);
21074 + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt);
21075 + a->dst_hdir = au_hi(a->dst_dir, a->btgt);
21077 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
21078 + if (unlikely(err))
21080 + au_fset_ren(a->auren_flags, MNT_WRITE);
21081 + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir,
21082 + a->dst_h_parent, a->dst_hdir);
21083 + udba = au_opt_udba(a->src_dentry->d_sb);
21084 + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent)
21085 + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent)))
21086 + err = au_busy_or_stale();
21087 + if (!err && au_dbtop(a->src_dentry) == a->btgt)
21088 + err = au_h_verify(a->src_h_dentry, udba,
21089 + d_inode(a->src_h_parent), a->src_h_parent,
21091 + if (!err && au_dbtop(a->dst_dentry) == a->btgt)
21092 + err = au_h_verify(a->dst_h_dentry, udba,
21093 + d_inode(a->dst_h_parent), a->dst_h_parent,
21096 + goto out; /* success */
21098 + err = au_busy_or_stale();
21099 + au_ren_unlock(a);
21105 +/* ---------------------------------------------------------------------- */
21107 +static void au_ren_refresh_dir(struct au_ren_args *a)
21109 + struct inode *dir;
21111 + dir = a->dst_dir;
21112 + dir->i_version++;
21113 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) {
21114 + /* is this updating defined in POSIX? */
21115 + au_cpup_attr_timesizes(a->src_inode);
21116 + au_cpup_attr_nlink(dir, /*force*/1);
21118 + au_dir_ts(dir, a->btgt);
21120 + if (a->exchange) {
21121 + dir = a->src_dir;
21122 + dir->i_version++;
21123 + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21124 + /* is this updating defined in POSIX? */
21125 + au_cpup_attr_timesizes(a->dst_inode);
21126 + au_cpup_attr_nlink(dir, /*force*/1);
21128 + au_dir_ts(dir, a->btgt);
21131 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21134 + dir = a->src_dir;
21135 + dir->i_version++;
21136 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC))
21137 + au_cpup_attr_nlink(dir, /*force*/1);
21138 + au_dir_ts(dir, a->btgt);
21141 +static void au_ren_refresh(struct au_ren_args *a)
21143 + aufs_bindex_t bbot, bindex;
21144 + struct dentry *d, *h_d;
21145 + struct inode *i, *h_i;
21146 + struct super_block *sb;
21148 + d = a->dst_dentry;
21151 + /* already dget-ed by au_ren_or_cpup() */
21152 + au_set_h_dptr(d, a->btgt, a->h_dst);
21154 + i = a->dst_inode;
21156 + if (!a->exchange) {
21157 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST))
21158 + vfsub_drop_nlink(i);
21160 + vfsub_dead_dir(i);
21161 + au_cpup_attr_timesizes(i);
21163 + au_update_dbrange(d, /*do_put_zero*/1);
21165 + au_cpup_attr_nlink(i, /*force*/1);
21168 + for (bindex = au_dbtop(d); bindex < bbot; bindex++)
21169 + au_set_h_dptr(d, bindex, NULL);
21170 + bbot = au_dbbot(d);
21171 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++)
21172 + au_set_h_dptr(d, bindex, NULL);
21173 + au_update_dbrange(d, /*do_put_zero*/0);
21176 + d = a->src_dentry;
21177 + if (!a->exchange) {
21178 + au_set_dbwh(d, -1);
21179 + bbot = au_dbbot(d);
21180 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21181 + h_d = au_h_dptr(d, bindex);
21183 + au_set_h_dptr(d, bindex, NULL);
21185 + au_set_dbbot(d, a->btgt);
21188 + i = a->src_inode;
21189 + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i))
21190 + return; /* success */
21192 + bbot = au_ibbot(i);
21193 + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) {
21194 + h_i = au_h_iptr(i, bindex);
21196 + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0);
21197 + /* ignore this error */
21198 + au_set_h_iptr(i, bindex, NULL, 0);
21201 + au_set_ibbot(i, a->btgt);
21203 + d_drop(a->src_dentry);
21206 +/* ---------------------------------------------------------------------- */
21208 +/* mainly for link(2) and rename(2) */
21209 +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt)
21211 + aufs_bindex_t bdiropq, bwh;
21212 + struct dentry *parent;
21213 + struct au_branch *br;
21215 + parent = dentry->d_parent;
21216 + IMustLock(d_inode(parent)); /* dir is locked */
21218 + bdiropq = au_dbdiropq(parent);
21219 + bwh = au_dbwh(dentry);
21220 + br = au_sbr(dentry->d_sb, btgt);
21221 + if (au_br_rdonly(br)
21222 + || (0 <= bdiropq && bdiropq < btgt)
21223 + || (0 <= bwh && bwh < btgt))
21226 + AuDbg("btgt %d\n", btgt);
21230 +/* sets src_btop, dst_btop and btgt */
21231 +static int au_ren_wbr(struct au_ren_args *a)
21234 + struct au_wr_dir_args wr_dir_args = {
21235 + /* .force_btgt = -1, */
21236 + .flags = AuWrDir_ADD_ENTRY
21239 + a->src_btop = au_dbtop(a->src_dentry);
21240 + a->dst_btop = au_dbtop(a->dst_dentry);
21241 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)
21242 + || au_ftest_ren(a->auren_flags, ISDIR_DST))
21243 + au_fset_wrdir(wr_dir_args.flags, ISDIR);
21244 + wr_dir_args.force_btgt = a->src_btop;
21245 + if (a->dst_inode && a->dst_btop < a->src_btop)
21246 + wr_dir_args.force_btgt = a->dst_btop;
21247 + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt);
21248 + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args);
21251 + au_update_dbtop(a->dst_dentry);
21256 +static void au_ren_dt(struct au_ren_args *a)
21258 + a->h_path.dentry = a->src_h_parent;
21259 + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path);
21260 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) {
21261 + a->h_path.dentry = a->dst_h_parent;
21262 + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path);
21265 + au_fclr_ren(a->auren_flags, DT_DSTDIR);
21266 + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC)
21270 + a->h_path.dentry = a->src_h_dentry;
21271 + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path);
21272 + if (d_is_positive(a->dst_h_dentry)) {
21273 + au_fset_ren(a->auren_flags, DT_DSTDIR);
21274 + a->h_path.dentry = a->dst_h_dentry;
21275 + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path);
21279 +static void au_ren_rev_dt(int err, struct au_ren_args *a)
21281 + struct dentry *h_d;
21282 + struct inode *h_inode;
21284 + au_dtime_revert(a->src_dt + AuPARENT);
21285 + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR))
21286 + au_dtime_revert(a->dst_dt + AuPARENT);
21288 + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) {
21289 + h_d = a->src_dt[AuCHILD].dt_h_path.dentry;
21290 + h_inode = d_inode(h_d);
21291 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21292 + au_dtime_revert(a->src_dt + AuCHILD);
21293 + inode_unlock(h_inode);
21295 + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) {
21296 + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry;
21297 + h_inode = d_inode(h_d);
21298 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
21299 + au_dtime_revert(a->dst_dt + AuCHILD);
21300 + inode_unlock(h_inode);
21305 +/* ---------------------------------------------------------------------- */
21307 +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry,
21308 + struct inode *_dst_dir, struct dentry *_dst_dentry,
21309 + unsigned int _flags)
21311 + int err, lock_flags;
21312 + /* reduce stack space */
21313 + struct au_ren_args *a;
21314 + struct au_pin pin;
21316 + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags);
21317 + IMustLock(_src_dir);
21318 + IMustLock(_dst_dir);
21321 + if (unlikely(_flags & RENAME_WHITEOUT))
21325 + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE);
21326 + a = kzalloc(sizeof(*a), GFP_NOFS);
21327 + if (unlikely(!a))
21330 + a->flags = _flags;
21331 + a->exchange = _flags & RENAME_EXCHANGE;
21332 + a->src_dir = _src_dir;
21333 + a->src_dentry = _src_dentry;
21334 + a->src_inode = NULL;
21335 + if (d_really_is_positive(a->src_dentry))
21336 + a->src_inode = d_inode(a->src_dentry);
21337 + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */
21338 + a->dst_dir = _dst_dir;
21339 + a->dst_dentry = _dst_dentry;
21340 + a->dst_inode = NULL;
21341 + if (d_really_is_positive(a->dst_dentry))
21342 + a->dst_inode = d_inode(a->dst_dentry);
21343 + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */
21344 + if (a->dst_inode) {
21346 + * if EXCHANGE && src is non-dir && dst is dir,
21347 + * dst is not locked.
21349 + /* IMustLock(a->dst_inode); */
21350 + au_igrab(a->dst_inode);
21354 + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN;
21355 + if (d_is_dir(a->src_dentry)) {
21356 + au_fset_ren(a->auren_flags, ISDIR_SRC);
21357 + if (unlikely(!a->exchange
21358 + && d_really_is_positive(a->dst_dentry)
21359 + && !d_is_dir(a->dst_dentry)))
21361 + lock_flags |= AuLock_DIRS;
21363 + if (a->dst_inode && d_is_dir(a->dst_dentry)) {
21364 + au_fset_ren(a->auren_flags, ISDIR_DST);
21365 + if (unlikely(!a->exchange
21366 + && d_really_is_positive(a->src_dentry)
21367 + && !d_is_dir(a->src_dentry)))
21369 + lock_flags |= AuLock_DIRS;
21371 + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, lock_flags);
21372 + if (unlikely(err))
21375 + err = au_d_hashed_positive(a->src_dentry);
21376 + if (unlikely(err))
21379 + if (a->dst_inode) {
21381 + * If it is a dir, VFS unhash it before this
21382 + * function. It means we cannot rely upon d_unhashed().
21384 + if (unlikely(!a->dst_inode->i_nlink))
21386 + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) {
21387 + err = au_d_hashed_positive(a->dst_dentry);
21388 + if (unlikely(err && !a->exchange))
21390 + } else if (unlikely(IS_DEADDIR(a->dst_inode)))
21392 + } else if (unlikely(d_unhashed(a->dst_dentry)))
21396 + * is it possible?
21397 + * yes, it happened (in linux-3.3-rcN) but I don't know why.
21398 + * there may exist a problem somewhere else.
21401 + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry)))
21404 + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */
21405 + di_write_lock_parent(a->dst_parent);
21407 + /* which branch we process */
21408 + err = au_ren_wbr(a);
21409 + if (unlikely(err < 0))
21411 + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt);
21412 + a->h_path.mnt = au_br_mnt(a->br);
21414 + /* are they available to be renamed */
21415 + err = au_ren_may_dir(a);
21416 + if (unlikely(err))
21417 + goto out_children;
21419 + /* prepare the writable parent dir on the same branch */
21420 + if (a->dst_btop == a->btgt) {
21421 + au_fset_ren(a->auren_flags, WHDST);
21423 + err = au_cpup_dirs(a->dst_dentry, a->btgt);
21424 + if (unlikely(err))
21425 + goto out_children;
21429 + if (!a->exchange) {
21430 + if (a->src_dir != a->dst_dir) {
21432 + * this temporary unlock is safe,
21433 + * because both dir->i_mutex are locked.
21435 + di_write_unlock(a->dst_parent);
21436 + di_write_lock_parent(a->src_parent);
21437 + err = au_wr_dir_need_wh(a->src_dentry,
21438 + au_ftest_ren(a->auren_flags,
21441 + di_write_unlock(a->src_parent);
21442 + di_write_lock2_parent(a->src_parent, a->dst_parent,
21444 + au_fclr_ren(a->auren_flags, ISSAMEDIR);
21446 + err = au_wr_dir_need_wh(a->src_dentry,
21447 + au_ftest_ren(a->auren_flags,
21451 + if (unlikely(err < 0))
21452 + goto out_children;
21454 + au_fset_ren(a->auren_flags, WHSRC);
21457 + if (a->src_btop != a->btgt) {
21458 + err = au_pin(&pin, a->src_dentry, a->btgt,
21459 + au_opt_udba(a->src_dentry->d_sb),
21460 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21462 + struct au_cp_generic cpg = {
21463 + .dentry = a->src_dentry,
21465 + .bsrc = a->src_btop,
21468 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21470 + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop);
21471 + err = au_sio_cpup_simple(&cpg);
21474 + if (unlikely(err))
21475 + goto out_children;
21476 + a->src_btop = a->btgt;
21477 + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt);
21478 + if (!a->exchange)
21479 + au_fset_ren(a->auren_flags, WHSRC);
21483 + if (a->exchange && a->dst_inode
21484 + && a->dst_btop != a->btgt) {
21485 + err = au_pin(&pin, a->dst_dentry, a->btgt,
21486 + au_opt_udba(a->dst_dentry->d_sb),
21487 + AuPin_DI_LOCKED | AuPin_MNT_WRITE);
21489 + struct au_cp_generic cpg = {
21490 + .dentry = a->dst_dentry,
21492 + .bsrc = a->dst_btop,
21495 + .flags = AuCpup_DTIME | AuCpup_HOPEN
21497 + err = au_sio_cpup_simple(&cpg);
21500 + if (unlikely(err))
21501 + goto out_children;
21502 + a->dst_btop = a->btgt;
21503 + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt);
21506 + /* lock them all */
21507 + err = au_ren_lock(a);
21508 + if (unlikely(err))
21509 + /* leave the copied-up one */
21510 + goto out_children;
21512 + if (!a->exchange) {
21513 + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE))
21514 + err = au_may_ren(a);
21515 + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN))
21516 + err = -ENAMETOOLONG;
21517 + if (unlikely(err))
21521 + /* store timestamps to be revertible */
21525 + err = do_rename(a);
21526 + if (unlikely(err))
21529 + /* update dir attributes */
21530 + au_ren_refresh_dir(a);
21532 + /* dput/iput all lower dentries */
21533 + au_ren_refresh(a);
21535 + goto out_hdir; /* success */
21538 + au_ren_rev_dt(err, a);
21540 + au_ren_unlock(a);
21542 + au_nhash_wh_free(&a->whlist);
21543 + if (err && a->dst_inode && a->dst_btop != a->btgt) {
21544 + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt);
21545 + au_set_h_dptr(a->dst_dentry, a->btgt, NULL);
21546 + au_set_dbtop(a->dst_dentry, a->dst_btop);
21550 + if (!a->exchange)
21551 + d_move(a->src_dentry, a->dst_dentry);
21553 + d_exchange(a->src_dentry, a->dst_dentry);
21555 + au_update_dbtop(a->dst_dentry);
21556 + if (!a->dst_inode)
21557 + d_drop(a->dst_dentry);
21559 + if (au_ftest_ren(a->auren_flags, ISSAMEDIR))
21560 + di_write_unlock(a->dst_parent);
21562 + di_write_unlock2(a->src_parent, a->dst_parent);
21564 + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry);
21566 + iput(a->dst_inode);
21568 + au_whtmp_rmdir_free(a->thargs);
21569 + au_delayed_kfree(a);
21574 diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig
21575 --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100
21576 +++ linux/fs/aufs/Kconfig 2016-10-09 16:55:36.482701377 +0200
21579 + tristate "Aufs (Advanced multi layered unification filesystem) support"
21581 + Aufs is a stackable unification filesystem such as Unionfs,
21582 + which unifies several directories and provides a merged single
21584 + In the early days, aufs was entirely re-designed and
21585 + re-implemented Unionfs Version 1.x series. Introducing many
21586 + original ideas, approaches and improvements, it becomes totally
21587 + different from Unionfs while keeping the basic features.
21591 + prompt "Maximum number of branches"
21592 + default AUFS_BRANCH_MAX_127
21594 + Specifies the maximum number of branches (or member directories)
21595 + in a single aufs. The larger value consumes more system
21596 + resources and has a minor impact to performance.
21597 +config AUFS_BRANCH_MAX_127
21600 + Specifies the maximum number of branches (or member directories)
21601 + in a single aufs. The larger value consumes more system
21602 + resources and has a minor impact to performance.
21603 +config AUFS_BRANCH_MAX_511
21606 + Specifies the maximum number of branches (or member directories)
21607 + in a single aufs. The larger value consumes more system
21608 + resources and has a minor impact to performance.
21609 +config AUFS_BRANCH_MAX_1023
21612 + Specifies the maximum number of branches (or member directories)
21613 + in a single aufs. The larger value consumes more system
21614 + resources and has a minor impact to performance.
21615 +config AUFS_BRANCH_MAX_32767
21618 + Specifies the maximum number of branches (or member directories)
21619 + in a single aufs. The larger value consumes more system
21620 + resources and has a minor impact to performance.
21623 +config AUFS_SBILIST
21625 + depends on AUFS_MAGIC_SYSRQ || PROC_FS
21628 + Automatic configuration for internal use.
21629 + When aufs supports Magic SysRq or /proc, enabled automatically.
21631 +config AUFS_HNOTIFY
21632 + bool "Detect direct branch access (bypassing aufs)"
21634 + If you want to modify files on branches directly, eg. bypassing aufs,
21635 + and want aufs to detect the changes of them fully, then enable this
21636 + option and use 'udba=notify' mount option.
21637 + Currently there is only one available configuration, "fsnotify".
21638 + It will have a negative impact to the performance.
21639 + See detail in aufs.5.
21642 + prompt "method" if AUFS_HNOTIFY
21643 + default AUFS_HFSNOTIFY
21644 +config AUFS_HFSNOTIFY
21649 +config AUFS_EXPORT
21650 + bool "NFS-exportable aufs"
21651 + depends on EXPORTFS
21653 + If you want to export your mounted aufs via NFS, then enable this
21654 + option. There are several requirements for this configuration.
21655 + See detail in aufs.5.
21657 +config AUFS_INO_T_64
21659 + depends on AUFS_EXPORT
21660 + depends on 64BIT && !(ALPHA || S390)
21663 + Automatic configuration for internal use.
21664 + /* typedef unsigned long/int __kernel_ino_t */
21665 + /* alpha and s390x are int */
21668 + bool "support for XATTR/EA (including Security Labels)"
21670 + If your branch fs supports XATTR/EA and you want to make them
21671 + available in aufs too, then enable this opsion and specify the
21672 + branch attributes for EA.
21673 + See detail in aufs.5.
21676 + bool "File-based Hierarchical Storage Management"
21678 + Hierarchical Storage Management (or HSM) is a well-known feature
21679 + in the storage world. Aufs provides this feature as file-based.
21680 + with multiple branches.
21681 + These multiple branches are prioritized, ie. the topmost one
21682 + should be the fastest drive and be used heavily.
21685 + bool "Readdir in userspace"
21687 + Aufs has two methods to provide a merged view for a directory,
21688 + by a user-space library and by kernel-space natively. The latter
21689 + is always enabled but sometimes large and slow.
21690 + If you enable this option, install the library in aufs2-util
21691 + package, and set some environment variables for your readdir(3),
21692 + then the work will be handled in user-space which generally
21693 + shows better performance in most cases.
21694 + See detail in aufs.5.
21697 + bool "Show whiteouts"
21699 + If you want to make the whiteouts in aufs visible, then enable
21700 + this option and specify 'shwh' mount option. Although it may
21701 + sounds like philosophy or something, but in technically it
21702 + simply shows the name of whiteout with keeping its behaviour.
21704 +config AUFS_BR_RAMFS
21705 + bool "Ramfs (initramfs/rootfs) as an aufs branch"
21707 + If you want to use ramfs as an aufs branch fs, then enable this
21708 + option. Generally tmpfs is recommended.
21709 + Aufs prohibited them to be a branch fs by default, because
21710 + initramfs becomes unusable after switch_root or something
21711 + generally. If you sets initramfs as an aufs branch and boot your
21712 + system by switch_root, you will meet a problem easily since the
21713 + files in initramfs may be inaccessible.
21714 + Unless you are going to use ramfs as an aufs branch fs without
21715 + switch_root or something, leave it N.
21717 +config AUFS_BR_FUSE
21718 + bool "Fuse fs as an aufs branch"
21719 + depends on FUSE_FS
21722 + If you want to use fuse-based userspace filesystem as an aufs
21723 + branch fs, then enable this option.
21724 + It implements the internal poll(2) operation which is
21725 + implemented by fuse only (curretnly).
21730 + Automatic configuration for internal use.
21732 +config AUFS_BR_HFSPLUS
21733 + bool "Hfsplus as an aufs branch"
21734 + depends on HFSPLUS_FS
21737 + If you want to use hfsplus fs as an aufs branch fs, then enable
21738 + this option. This option introduces a small overhead at
21739 + copying-up a file on hfsplus.
21741 +config AUFS_BDEV_LOOP
21743 + depends on BLK_DEV_LOOP
21746 + Automatic configuration for internal use.
21747 + Convert =[ym] into =y.
21750 + bool "Debug aufs"
21752 + Enable this to compile aufs internal debug code.
21753 + It will have a negative impact to the performance.
21755 +config AUFS_MAGIC_SYSRQ
21757 + depends on AUFS_DEBUG && MAGIC_SYSRQ
21760 + Automatic configuration for internal use.
21761 + When aufs supports Magic SysRq, enabled automatically.
21763 diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c
21764 --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100
21765 +++ linux/fs/aufs/loop.c 2016-10-09 16:55:38.889431135 +0200
21768 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21770 + * This program, aufs is free software; you can redistribute it and/or modify
21771 + * it under the terms of the GNU General Public License as published by
21772 + * the Free Software Foundation; either version 2 of the License, or
21773 + * (at your option) any later version.
21775 + * This program is distributed in the hope that it will be useful,
21776 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21777 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21778 + * GNU General Public License for more details.
21780 + * You should have received a copy of the GNU General Public License
21781 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21785 + * support for loopback block device as a branch
21790 +/* added into drivers/block/loop.c */
21791 +static struct file *(*backing_file_func)(struct super_block *sb);
21794 + * test if two lower dentries have overlapping branches.
21796 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding)
21798 + struct super_block *h_sb;
21799 + struct file *backing_file;
21801 + if (unlikely(!backing_file_func)) {
21802 + /* don't load "loop" module here */
21803 + backing_file_func = symbol_get(loop_backing_file);
21804 + if (unlikely(!backing_file_func))
21805 + /* "loop" module is not loaded */
21809 + h_sb = h_adding->d_sb;
21810 + backing_file = backing_file_func(h_sb);
21811 + if (!backing_file)
21814 + h_adding = backing_file->f_path.dentry;
21816 + * h_adding can be local NFS.
21817 + * in this case aufs cannot detect the loop.
21819 + if (unlikely(h_adding->d_sb == sb))
21821 + return !!au_test_subdir(h_adding, sb->s_root);
21824 +/* true if a kernel thread named 'loop[0-9].*' accesses a file */
21825 +int au_test_loopback_kthread(void)
21828 + struct task_struct *tsk = current;
21829 + char c, comm[sizeof(tsk->comm)];
21832 + if (tsk->flags & PF_KTHREAD) {
21833 + get_task_comm(comm, tsk);
21835 + ret = ('0' <= c && c <= '9'
21836 + && !strncmp(comm, "loop", 4));
21842 +/* ---------------------------------------------------------------------- */
21844 +#define au_warn_loopback_step 16
21845 +static int au_warn_loopback_nelem = au_warn_loopback_step;
21846 +static unsigned long *au_warn_loopback_array;
21848 +void au_warn_loopback(struct super_block *h_sb)
21850 + int i, new_nelem;
21851 + unsigned long *a, magic;
21852 + static DEFINE_SPINLOCK(spin);
21854 + magic = h_sb->s_magic;
21855 + spin_lock(&spin);
21856 + a = au_warn_loopback_array;
21857 + for (i = 0; i < au_warn_loopback_nelem && *a; i++)
21858 + if (a[i] == magic) {
21859 + spin_unlock(&spin);
21863 + /* h_sb is new to us, print it */
21864 + if (i < au_warn_loopback_nelem) {
21869 + /* expand the array */
21870 + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step;
21871 + a = au_kzrealloc(au_warn_loopback_array,
21872 + au_warn_loopback_nelem * sizeof(unsigned long),
21873 + new_nelem * sizeof(unsigned long), GFP_ATOMIC,
21874 + /*may_shrink*/0);
21876 + au_warn_loopback_nelem = new_nelem;
21877 + au_warn_loopback_array = a;
21882 + spin_unlock(&spin);
21883 + AuWarn1("realloc failed, ignored\n");
21887 + spin_unlock(&spin);
21888 + pr_warn("you may want to try another patch for loopback file "
21889 + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic);
21892 +int au_loopback_init(void)
21895 + struct super_block *sb __maybe_unused;
21897 + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(unsigned long));
21900 + au_warn_loopback_array = kcalloc(au_warn_loopback_step,
21901 + sizeof(unsigned long), GFP_NOFS);
21902 + if (unlikely(!au_warn_loopback_array))
21908 +void au_loopback_fin(void)
21910 + if (backing_file_func)
21911 + symbol_put(loop_backing_file);
21912 + au_delayed_kfree(au_warn_loopback_array);
21914 diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h
21915 --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100
21916 +++ linux/fs/aufs/loop.h 2016-10-09 16:55:36.492701639 +0200
21919 + * Copyright (C) 2005-2016 Junjiro R. Okajima
21921 + * This program, aufs is free software; you can redistribute it and/or modify
21922 + * it under the terms of the GNU General Public License as published by
21923 + * the Free Software Foundation; either version 2 of the License, or
21924 + * (at your option) any later version.
21926 + * This program is distributed in the hope that it will be useful,
21927 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
21928 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21929 + * GNU General Public License for more details.
21931 + * You should have received a copy of the GNU General Public License
21932 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
21936 + * support for loopback mount as a branch
21939 +#ifndef __AUFS_LOOP_H__
21940 +#define __AUFS_LOOP_H__
21945 +struct super_block;
21947 +#ifdef CONFIG_AUFS_BDEV_LOOP
21948 +/* drivers/block/loop.c */
21949 +struct file *loop_backing_file(struct super_block *sb);
21952 +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding);
21953 +int au_test_loopback_kthread(void);
21954 +void au_warn_loopback(struct super_block *h_sb);
21956 +int au_loopback_init(void);
21957 +void au_loopback_fin(void);
21959 +AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
21960 + struct dentry *h_adding)
21961 +AuStubInt0(au_test_loopback_kthread, void)
21962 +AuStubVoid(au_warn_loopback, struct super_block *h_sb)
21964 +AuStubInt0(au_loopback_init, void)
21965 +AuStubVoid(au_loopback_fin, void)
21966 +#endif /* BLK_DEV_LOOP */
21968 +#endif /* __KERNEL__ */
21969 +#endif /* __AUFS_LOOP_H__ */
21970 diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk
21971 --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100
21972 +++ linux/fs/aufs/magic.mk 2016-10-09 16:55:36.492701639 +0200
21975 +# defined in ${srctree}/fs/fuse/inode.c
21977 +ifdef CONFIG_FUSE_FS
21978 +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546
21981 +# defined in ${srctree}/fs/xfs/xfs_sb.h
21983 +ifdef CONFIG_XFS_FS
21984 +ccflags-y += -DXFS_SB_MAGIC=0x58465342
21987 +# defined in ${srctree}/fs/configfs/mount.c
21989 +ifdef CONFIG_CONFIGFS_FS
21990 +ccflags-y += -DCONFIGFS_MAGIC=0x62656570
21993 +# defined in ${srctree}/fs/ubifs/ubifs.h
21995 +ifdef CONFIG_UBIFS_FS
21996 +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905
21999 +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h
22001 +ifdef CONFIG_HFSPLUS_FS
22002 +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b
22004 diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile
22005 --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100
22006 +++ linux/fs/aufs/Makefile 2016-10-09 16:55:36.486034798 +0200
22009 +include ${src}/magic.mk
22010 +ifeq (${CONFIG_AUFS_FS},m)
22011 +include ${src}/conf.mk
22013 +-include ${src}/priv_def.mk
22015 +# cf. include/linux/kernel.h
22017 +ccflags-y += -DDEBUG
22018 +# sparse requires the full pathname
22020 +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h
22022 +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h
22025 +obj-$(CONFIG_AUFS_FS) += aufs.o
22026 +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \
22027 + wkq.o vfsub.o dcsub.o \
22028 + cpup.o whout.o wbr_policy.o \
22029 + dinfo.o dentry.o \
22031 + finfo.o file.o f_op.o \
22033 + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \
22037 +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o
22038 +aufs-$(CONFIG_SYSFS) += sysfs.o
22039 +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o
22040 +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o
22041 +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o
22042 +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o
22043 +aufs-$(CONFIG_AUFS_EXPORT) += export.o
22044 +aufs-$(CONFIG_AUFS_XATTR) += xattr.o
22045 +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
22046 +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o
22047 +aufs-$(CONFIG_AUFS_POLL) += poll.o
22048 +aufs-$(CONFIG_AUFS_RDU) += rdu.o
22049 +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o
22050 +aufs-$(CONFIG_AUFS_DEBUG) += debug.o
22051 +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o
22052 diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c
22053 --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100
22054 +++ linux/fs/aufs/module.c 2016-10-09 16:55:38.889431135 +0200
22057 + * Copyright (C) 2005-2016 Junjiro R. Okajima
22059 + * This program, aufs is free software; you can redistribute it and/or modify
22060 + * it under the terms of the GNU General Public License as published by
22061 + * the Free Software Foundation; either version 2 of the License, or
22062 + * (at your option) any later version.
22064 + * This program is distributed in the hope that it will be useful,
22065 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22066 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22067 + * GNU General Public License for more details.
22069 + * You should have received a copy of the GNU General Public License
22070 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22074 + * module global variables and operations
22077 +#include <linux/module.h>
22078 +#include <linux/seq_file.h>
22081 +/* shrinkable realloc */
22082 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink)
22090 +#if 0 /* unused */
22092 + au_delayed_kfree(p);
22097 + AuDebugOn(!new_sz);
22100 + diff = au_kmidx_sub(sz, new_sz);
22106 + /* expand or SLOB */
22107 + p = krealloc(p, new_sz, gfp);
22108 + else if (new_sz < sz && may_shrink) {
22112 + q = kmalloc(new_sz, gfp);
22115 + memcpy(q, p, new_sz);
22116 + au_delayed_kfree(p);
22127 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22130 + p = au_krealloc(p, new_sz, gfp, may_shrink);
22131 + if (p && new_sz > nused)
22132 + memset(p + nused, 0, new_sz - nused);
22136 +/* ---------------------------------------------------------------------- */
22141 +struct au_dfree au_dfree;
22143 +/* delayed free */
22144 +static void au_do_dfree(struct work_struct *work __maybe_unused)
22146 + struct llist_head *head;
22147 + struct llist_node *node, *next;
22149 +#define AU_CACHE_DFREE_DO_BODY(name, idx, lnode) do { \
22150 + head = &au_dfree.cache[AuCache_##idx].llist; \
22151 + node = llist_del_all(head); \
22152 + for (; node; node = next) { \
22153 + struct au_##name *p \
22154 + = llist_entry(node, struct au_##name, \
22156 + next = llist_next(node); \
22157 + au_cache_free_##name(p); \
22161 + AU_CACHE_DFREE_DO_BODY(dinfo, DINFO, di_lnode);
22162 + AU_CACHE_DFREE_DO_BODY(icntnr, ICNTNR, lnode);
22163 + AU_CACHE_DFREE_DO_BODY(finfo, FINFO, fi_lnode);
22164 + AU_CACHE_DFREE_DO_BODY(vdir, VDIR, vd_lnode);
22165 + AU_CACHE_DFREE_DO_BODY(vdir_dehstr, DEHSTR, lnode);
22166 +#ifdef CONFIG_AUFS_HNOTIFY
22167 + AU_CACHE_DFREE_DO_BODY(hnotify, HNOTIFY, hn_lnode);
22170 +#define AU_DFREE_DO_BODY(llist, func) do { \
22171 + node = llist_del_all(llist); \
22172 + for (; node; node = next) { \
22173 + next = llist_next(node); \
22178 + AU_DFREE_DO_BODY(au_dfree.llist + AU_DFREE_KFREE, kfree);
22179 + AU_DFREE_DO_BODY(au_dfree.llist + AU_DFREE_FREE_PAGE, au_free_page);
22181 +#undef AU_CACHE_DFREE_DO_BODY
22182 +#undef AU_DFREE_DO_BODY
22185 +AU_CACHE_DFREE_FUNC(dinfo, DINFO, di_lnode);
22186 +AU_CACHE_DFREE_FUNC(icntnr, ICNTNR, lnode);
22187 +AU_CACHE_DFREE_FUNC(finfo, FINFO, fi_lnode);
22188 +AU_CACHE_DFREE_FUNC(vdir, VDIR, vd_lnode);
22189 +AU_CACHE_DFREE_FUNC(vdir_dehstr, DEHSTR, lnode);
22191 +static void au_cache_fin(void)
22194 + struct au_cache *cp;
22197 + * Make sure all delayed rcu free inodes are flushed before we
22202 + /* excluding AuCache_HNOTIFY */
22203 + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last);
22204 + flush_delayed_work(&au_dfree.dwork);
22205 + for (i = 0; i < AuCache_HNOTIFY; i++) {
22206 + cp = au_dfree.cache + i;
22207 + AuDebugOn(!llist_empty(&cp->llist));
22208 + kmem_cache_destroy(cp->cache);
22209 + cp->cache = NULL;
22213 +static int __init au_cache_init(void)
22215 + struct au_cache *cp;
22217 + cp = au_dfree.cache;
22218 + cp[AuCache_DINFO].cache = AuCacheCtor(au_dinfo, au_di_init_once);
22219 + if (cp[AuCache_DINFO].cache)
22220 + /* SLAB_DESTROY_BY_RCU */
22221 + cp[AuCache_ICNTNR].cache = AuCacheCtor(au_icntnr,
22222 + au_icntnr_init_once);
22223 + if (cp[AuCache_ICNTNR].cache)
22224 + cp[AuCache_FINFO].cache = AuCacheCtor(au_finfo,
22225 + au_fi_init_once);
22226 + if (cp[AuCache_FINFO].cache)
22227 + cp[AuCache_VDIR].cache = AuCache(au_vdir);
22228 + if (cp[AuCache_VDIR].cache)
22229 + cp[AuCache_DEHSTR].cache = AuCache(au_vdir_dehstr);
22230 + if (cp[AuCache_DEHSTR].cache)
22237 +/* ---------------------------------------------------------------------- */
22239 +int au_dir_roflags;
22241 +#ifdef CONFIG_AUFS_SBILIST
22243 + * iterate_supers_type() doesn't protect us from
22244 + * remounting (branch management)
22246 +struct au_sphlhead au_sbilist;
22250 + * functions for module interface.
22252 +MODULE_LICENSE("GPL");
22253 +/* MODULE_LICENSE("GPL v2"); */
22254 +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>");
22255 +MODULE_DESCRIPTION(AUFS_NAME
22256 + " -- Advanced multi layered unification filesystem");
22257 +MODULE_VERSION(AUFS_VERSION);
22258 +MODULE_ALIAS_FS(AUFS_NAME);
22260 +/* this module parameter has no meaning when SYSFS is disabled */
22261 +int sysaufs_brs = 1;
22262 +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN");
22263 +module_param_named(brs, sysaufs_brs, int, S_IRUGO);
22265 +/* this module parameter has no meaning when USER_NS is disabled */
22267 +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns");
22268 +module_param_named(allow_userns, au_userns, bool, S_IRUGO);
22270 +/* ---------------------------------------------------------------------- */
22272 +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */
22274 +int au_seq_path(struct seq_file *seq, struct path *path)
22278 + err = seq_path(seq, path, au_esc_chars);
22281 + else if (err < 0)
22287 +/* ---------------------------------------------------------------------- */
22289 +static int __init aufs_init(void)
22293 + struct au_cache *cp;
22295 + p = au_esc_chars;
22296 + for (i = 1; i <= ' '; i++)
22302 + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE);
22304 + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop));
22305 + for (i = 0; i < AuIop_Last; i++)
22306 + aufs_iop_nogetattr[i].getattr = NULL;
22308 + /* First, initialize au_dfree */
22309 + for (i = 0; i < AuCache_Last; i++) { /* including hnotify */
22310 + cp = au_dfree.cache + i;
22311 + cp->cache = NULL;
22312 + init_llist_head(&cp->llist);
22314 + for (i = 0; i < AU_DFREE_Last; i++)
22315 + init_llist_head(au_dfree.llist + i);
22316 + INIT_DELAYED_WORK(&au_dfree.dwork, au_do_dfree);
22318 + au_sbilist_init();
22319 + sysaufs_brs_init();
22322 + err = sysaufs_init();
22323 + if (unlikely(err))
22325 + err = au_procfs_init();
22326 + if (unlikely(err))
22327 + goto out_sysaufs;
22328 + err = au_wkq_init();
22329 + if (unlikely(err))
22331 + err = au_loopback_init();
22332 + if (unlikely(err))
22334 + err = au_hnotify_init();
22335 + if (unlikely(err))
22336 + goto out_loopback;
22337 + err = au_sysrq_init();
22338 + if (unlikely(err))
22340 + err = au_cache_init();
22341 + if (unlikely(err))
22344 + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0;
22345 + err = register_filesystem(&aufs_fs_type);
22346 + if (unlikely(err))
22349 + /* since we define pr_fmt, call printk directly */
22350 + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n");
22351 + goto out; /* success */
22358 + au_hnotify_fin();
22360 + au_loopback_fin();
22368 + flush_delayed_work(&au_dfree.dwork);
22373 +static void __exit aufs_exit(void)
22375 + unregister_filesystem(&aufs_fs_type);
22378 + au_hnotify_fin();
22379 + au_loopback_fin();
22384 + flush_delayed_work(&au_dfree.dwork);
22387 +module_init(aufs_init);
22388 +module_exit(aufs_exit);
22389 diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h
22390 --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100
22391 +++ linux/fs/aufs/module.h 2016-10-09 16:55:38.889431135 +0200
22394 + * Copyright (C) 2005-2016 Junjiro R. Okajima
22396 + * This program, aufs is free software; you can redistribute it and/or modify
22397 + * it under the terms of the GNU General Public License as published by
22398 + * the Free Software Foundation; either version 2 of the License, or
22399 + * (at your option) any later version.
22401 + * This program is distributed in the hope that it will be useful,
22402 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22403 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22404 + * GNU General Public License for more details.
22406 + * You should have received a copy of the GNU General Public License
22407 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22411 + * module initialization and module-global
22414 +#ifndef __AUFS_MODULE_H__
22415 +#define __AUFS_MODULE_H__
22419 +#include <linux/slab.h>
22420 +#include "debug.h"
22425 +/* module parameters */
22426 +extern int sysaufs_brs;
22427 +extern bool au_userns;
22429 +/* ---------------------------------------------------------------------- */
22431 +extern int au_dir_roflags;
22433 +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink);
22434 +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp,
22437 +static inline int au_kmidx_sub(size_t sz, size_t new_sz)
22439 +#ifndef CONFIG_SLOB
22440 + return kmalloc_index(sz) - kmalloc_index(new_sz);
22442 + return -1; /* SLOB is untested */
22446 +int au_seq_path(struct seq_file *seq, struct path *path);
22448 +#ifdef CONFIG_PROC_FS
22450 +int __init au_procfs_init(void);
22451 +void au_procfs_fin(void);
22453 +AuStubInt0(au_procfs_init, void);
22454 +AuStubVoid(au_procfs_fin, void);
22457 +/* ---------------------------------------------------------------------- */
22459 +/* kmem cache and delayed free */
22466 + AuCache_HNOTIFY, /* must be last */
22472 + AU_DFREE_FREE_PAGE,
22477 + struct kmem_cache *cache;
22478 + struct llist_head llist; /* delayed free */
22482 + * in order to reduce the cost of the internal timer, consolidate all the
22483 + * delayed free works into a single delayed_work.
22486 + struct au_cache cache[AuCache_Last];
22487 + struct llist_head llist[AU_DFREE_Last];
22488 + struct delayed_work dwork;
22491 +extern struct au_dfree au_dfree;
22493 +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD)
22494 +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags)
22495 +#define AuCacheCtor(type, ctor) \
22496 + kmem_cache_create(#type, sizeof(struct type), \
22497 + __alignof__(struct type), AuCacheFlags, ctor)
22499 +#define AU_DFREE_DELAY msecs_to_jiffies(10)
22500 +#define AU_DFREE_BODY(lnode, llist) do { \
22501 + if (llist_add(lnode, llist)) \
22502 + schedule_delayed_work(&au_dfree.dwork, \
22503 + AU_DFREE_DELAY); \
22505 +#define AU_CACHE_DFREE_FUNC(name, idx, lnode) \
22506 + void au_cache_dfree_##name(struct au_##name *p) \
22508 + struct au_cache *cp = au_dfree.cache + AuCache_##idx; \
22509 + AU_DFREE_BODY(&p->lnode, &cp->llist); \
22512 +#define AuCacheFuncs(name, index) \
22513 +static inline struct au_##name *au_cache_alloc_##name(void) \
22514 +{ return kmem_cache_alloc(au_dfree.cache[AuCache_##index].cache, GFP_NOFS); } \
22515 +static inline void au_cache_free_##name(struct au_##name *p) \
22516 +{ kmem_cache_free(au_dfree.cache[AuCache_##index].cache, p); } \
22517 +void au_cache_dfree_##name(struct au_##name *p)
22519 +AuCacheFuncs(dinfo, DINFO);
22520 +AuCacheFuncs(icntnr, ICNTNR);
22521 +AuCacheFuncs(finfo, FINFO);
22522 +AuCacheFuncs(vdir, VDIR);
22523 +AuCacheFuncs(vdir_dehstr, DEHSTR);
22524 +#ifdef CONFIG_AUFS_HNOTIFY
22525 +AuCacheFuncs(hnotify, HNOTIFY);
22528 +static inline void au_delayed_kfree(const void *p)
22531 + AuDebugOn(ksize(p) < sizeof(struct llist_node));
22533 + AU_DFREE_BODY((void *)p, au_dfree.llist + AU_DFREE_KFREE);
22537 +static inline void au_free_page(void *p)
22539 + free_page((unsigned long)p);
22542 +static inline void au_delayed_free_page(unsigned long addr)
22544 + AU_DFREE_BODY((void *)addr, au_dfree.llist + AU_DFREE_FREE_PAGE);
22547 +#endif /* __KERNEL__ */
22548 +#endif /* __AUFS_MODULE_H__ */
22549 diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c
22550 --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100
22551 +++ linux/fs/aufs/mvdown.c 2016-10-09 16:55:36.492701639 +0200
22554 + * Copyright (C) 2011-2016 Junjiro R. Okajima
22556 + * This program, aufs is free software; you can redistribute it and/or modify
22557 + * it under the terms of the GNU General Public License as published by
22558 + * the Free Software Foundation; either version 2 of the License, or
22559 + * (at your option) any later version.
22561 + * This program is distributed in the hope that it will be useful,
22562 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
22563 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22564 + * GNU General Public License for more details.
22566 + * You should have received a copy of the GNU General Public License
22567 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
22571 + * move-down, opposite of copy-up
22576 +struct au_mvd_args {
22578 + struct super_block *h_sb;
22579 + struct dentry *h_parent;
22580 + struct au_hinode *hdir;
22581 + struct inode *h_dir, *h_inode;
22582 + struct au_pin pin;
22583 + } info[AUFS_MVDOWN_NARRAY];
22585 + struct aufs_mvdown mvdown;
22586 + struct dentry *dentry, *parent;
22587 + struct inode *inode, *dir;
22588 + struct super_block *sb;
22589 + aufs_bindex_t bopq, bwh, bfound;
22590 + unsigned char rename_lock;
22593 +#define mvd_errno mvdown.au_errno
22594 +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex
22595 +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid
22596 +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex
22597 +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid
22599 +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb
22600 +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent
22601 +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir
22602 +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir
22603 +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode
22604 +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin
22606 +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb
22607 +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent
22608 +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir
22609 +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir
22610 +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode
22611 +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin
22613 +#define AU_MVD_PR(flag, ...) do { \
22615 + pr_err(__VA_ARGS__); \
22618 +static int find_lower_writable(struct au_mvd_args *a)
22620 + struct super_block *sb;
22621 + aufs_bindex_t bindex, bbot;
22622 + struct au_branch *br;
22625 + bindex = a->mvd_bsrc;
22626 + bbot = au_sbbot(sb);
22627 + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER)
22628 + for (bindex++; bindex <= bbot; bindex++) {
22629 + br = au_sbr(sb, bindex);
22630 + if (au_br_fhsm(br->br_perm)
22631 + && (!(au_br_sb(br)->s_flags & MS_RDONLY)))
22634 + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER))
22635 + for (bindex++; bindex <= bbot; bindex++) {
22636 + br = au_sbr(sb, bindex);
22637 + if (!au_br_rdonly(br))
22641 + for (bindex++; bindex <= bbot; bindex++) {
22642 + br = au_sbr(sb, bindex);
22643 + if (!(au_br_sb(br)->s_flags & MS_RDONLY)) {
22644 + if (au_br_rdonly(br))
22646 + |= AUFS_MVDOWN_ROLOWER_R;
22654 +/* make the parent dir on bdst */
22655 +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a)
22660 + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc);
22661 + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst);
22662 + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc);
22663 + a->mvd_h_dst_parent = NULL;
22664 + if (au_dbbot(a->parent) >= a->mvd_bdst)
22665 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22666 + if (!a->mvd_h_dst_parent) {
22667 + err = au_cpdown_dirs(a->dentry, a->mvd_bdst);
22668 + if (unlikely(err)) {
22669 + AU_MVD_PR(dmsg, "cpdown_dirs failed\n");
22672 + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst);
22680 +/* lock them all */
22681 +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a)
22684 + struct dentry *h_trap;
22686 + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc);
22687 + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst);
22688 + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst,
22689 + au_opt_udba(a->sb),
22690 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22692 + if (unlikely(err)) {
22693 + AU_MVD_PR(dmsg, "pin_dst failed\n");
22697 + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) {
22698 + a->rename_lock = 0;
22699 + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22700 + AuLsc_DI_PARENT, AuLsc_I_PARENT3,
22701 + au_opt_udba(a->sb),
22702 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22703 + err = au_do_pin(&a->mvd_pin_src);
22705 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22706 + if (unlikely(err)) {
22707 + AU_MVD_PR(dmsg, "pin_src failed\n");
22710 + goto out; /* success */
22713 + a->rename_lock = 1;
22714 + au_pin_hdir_unlock(&a->mvd_pin_dst);
22715 + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc,
22716 + au_opt_udba(a->sb),
22717 + AuPin_MNT_WRITE | AuPin_DI_LOCKED);
22719 + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent);
22720 + if (unlikely(err)) {
22721 + AU_MVD_PR(dmsg, "pin_src failed\n");
22722 + au_pin_hdir_lock(&a->mvd_pin_dst);
22725 + au_pin_hdir_unlock(&a->mvd_pin_src);
22726 + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22727 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22729 + err = (h_trap != a->mvd_h_src_parent);
22731 + err = (h_trap != a->mvd_h_dst_parent);
22733 + BUG_ON(err); /* it should never happen */
22734 + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) {
22737 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22738 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22739 + au_pin_hdir_lock(&a->mvd_pin_src);
22740 + au_unpin(&a->mvd_pin_src);
22741 + au_pin_hdir_lock(&a->mvd_pin_dst);
22744 + goto out; /* success */
22747 + au_unpin(&a->mvd_pin_dst);
22753 +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a)
22755 + if (!a->rename_lock)
22756 + au_unpin(&a->mvd_pin_src);
22758 + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src,
22759 + a->mvd_h_dst_parent, a->mvd_hdir_dst);
22760 + au_pin_hdir_lock(&a->mvd_pin_src);
22761 + au_unpin(&a->mvd_pin_src);
22762 + au_pin_hdir_lock(&a->mvd_pin_dst);
22764 + au_unpin(&a->mvd_pin_dst);
22767 +/* copy-down the file */
22768 +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a)
22771 + struct au_cp_generic cpg = {
22772 + .dentry = a->dentry,
22773 + .bdst = a->mvd_bdst,
22774 + .bsrc = a->mvd_bsrc,
22776 + .pin = &a->mvd_pin_dst,
22777 + .flags = AuCpup_DTIME | AuCpup_HOPEN
22780 + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst);
22781 + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
22782 + au_fset_cpup(cpg.flags, OVERWRITE);
22783 + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER)
22784 + au_fset_cpup(cpg.flags, RWDST);
22785 + err = au_sio_cpdown_simple(&cpg);
22786 + if (unlikely(err))
22787 + AU_MVD_PR(dmsg, "cpdown failed\n");
22794 + * unlink the whiteout on bdst if exist which may be created by UDBA while we
22797 +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a)
22800 + struct path h_path;
22801 + struct au_branch *br;
22802 + struct inode *delegated;
22804 + br = au_sbr(a->sb, a->mvd_bdst);
22805 + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br);
22806 + err = PTR_ERR(h_path.dentry);
22807 + if (IS_ERR(h_path.dentry)) {
22808 + AU_MVD_PR(dmsg, "wh_lkup failed\n");
22813 + if (d_is_positive(h_path.dentry)) {
22814 + h_path.mnt = au_br_mnt(br);
22815 + delegated = NULL;
22816 + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path,
22817 + &delegated, /*force*/0);
22818 + if (unlikely(err == -EWOULDBLOCK)) {
22819 + pr_warn("cannot retry for NFSv4 delegation"
22820 + " for an internal unlink\n");
22823 + if (unlikely(err))
22824 + AU_MVD_PR(dmsg, "wh_unlink failed\n");
22826 + dput(h_path.dentry);
22834 + * unlink the topmost h_dentry
22836 +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a)
22839 + struct path h_path;
22840 + struct inode *delegated;
22842 + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc);
22843 + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc);
22844 + delegated = NULL;
22845 + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0);
22846 + if (unlikely(err == -EWOULDBLOCK)) {
22847 + pr_warn("cannot retry for NFSv4 delegation"
22848 + " for an internal unlink\n");
22851 + if (unlikely(err))
22852 + AU_MVD_PR(dmsg, "unlink failed\n");
22858 +/* Since mvdown succeeded, we ignore an error of this function */
22859 +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a)
22862 + struct au_branch *br;
22864 + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED;
22865 + br = au_sbr(a->sb, a->mvd_bsrc);
22866 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs);
22868 + br = au_sbr(a->sb, a->mvd_bdst);
22869 + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id;
22870 + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs);
22873 + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED;
22875 + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err);
22879 + * copy-down the file and unlink the bsrc file.
22880 + * - unlink the bdst whout if exist
22881 + * - copy-down the file (with whtmp name and rename)
22882 + * - unlink the bsrc file
22884 +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a)
22888 + err = au_do_mkdir(dmsg, a);
22890 + err = au_do_lock(dmsg, a);
22891 + if (unlikely(err))
22895 + * do not revert the activities we made on bdst since they should be
22896 + * harmless in aufs.
22899 + err = au_do_cpdown(dmsg, a);
22901 + err = au_do_unlink_wh(dmsg, a);
22902 + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER))
22903 + err = au_do_unlink(dmsg, a);
22904 + if (unlikely(err))
22907 + AuDbg("%pd2, 0x%x, %d --> %d\n",
22908 + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst);
22909 + if (find_lower_writable(a) < 0)
22910 + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM;
22912 + if (a->mvdown.flags & AUFS_MVDOWN_STFS)
22913 + au_do_stfs(dmsg, a);
22915 + /* maintain internal array */
22916 + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) {
22917 + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL);
22918 + au_set_dbtop(a->dentry, a->mvd_bdst);
22919 + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0);
22920 + au_set_ibtop(a->inode, a->mvd_bdst);
22922 + /* hide the lower */
22923 + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL);
22924 + au_set_dbbot(a->dentry, a->mvd_bsrc);
22925 + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0);
22926 + au_set_ibbot(a->inode, a->mvd_bsrc);
22928 + if (au_dbbot(a->dentry) < a->mvd_bdst)
22929 + au_set_dbbot(a->dentry, a->mvd_bdst);
22930 + if (au_ibbot(a->inode) < a->mvd_bdst)
22931 + au_set_ibbot(a->inode, a->mvd_bdst);
22934 + au_do_unlock(dmsg, a);
22940 +/* ---------------------------------------------------------------------- */
22942 +/* make sure the file is idle */
22943 +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a)
22945 + int err, plinked;
22948 + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK);
22949 + if (au_dbtop(a->dentry) == a->mvd_bsrc
22950 + && au_dcount(a->dentry) == 1
22951 + && atomic_read(&a->inode->i_count) == 1
22952 + /* && a->mvd_h_src_inode->i_nlink == 1 */
22953 + && (!plinked || !au_plink_test(a->inode))
22954 + && a->inode->i_nlink == 1)
22959 + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n",
22960 + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry),
22961 + atomic_read(&a->inode->i_count), a->inode->i_nlink,
22962 + a->mvd_h_src_inode->i_nlink,
22963 + plinked, plinked ? au_plink_test(a->inode) : 0);
22970 +/* make sure the parent dir is fine */
22971 +static int au_mvd_args_parent(const unsigned char dmsg,
22972 + struct au_mvd_args *a)
22975 + aufs_bindex_t bindex;
22978 + if (unlikely(au_alive_dir(a->parent))) {
22980 + AU_MVD_PR(dmsg, "parent dir is dead\n");
22984 + a->bopq = au_dbdiropq(a->parent);
22985 + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst);
22986 + AuDbg("b%d\n", bindex);
22987 + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst)
22988 + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) {
22990 + a->mvd_errno = EAU_MVDOWN_OPAQUE;
22991 + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n",
22992 + a->bopq, a->mvd_bdst);
23000 +static int au_mvd_args_intermediate(const unsigned char dmsg,
23001 + struct au_mvd_args *a)
23004 + struct au_dinfo *dinfo, *tmp;
23006 + /* lookup the next lower positive entry */
23008 + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP);
23009 + if (unlikely(!tmp))
23014 + dinfo = au_di(a->dentry);
23015 + au_di_cp(tmp, dinfo);
23016 + au_di_swap(tmp, dinfo);
23018 + /* returns the number of positive dentries */
23019 + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1,
23020 + /* AuLkup_IGNORE_PERM */ 0);
23022 + a->bwh = au_dbwh(a->dentry);
23023 + else if (err > 0)
23024 + a->bfound = au_dbtop(a->dentry);
23026 + au_di_swap(tmp, dinfo);
23027 + au_rw_write_unlock(&tmp->di_rwsem);
23029 + if (unlikely(err < 0))
23030 + AU_MVD_PR(dmsg, "failed look-up lower\n");
23033 + * here, we have these cases.
23035 + * no positive dentry under bsrc. there are more sub-cases.
23037 + * there no whiteout, we can safely move-down.
23040 + * bsrc < bwh && bwh < bdst
23041 + * there is a whiteout on RO branch. cannot proceed.
23043 + * there is a whiteout on the RW target branch. it should
23046 + * there is a whiteout somewhere unrelated branch.
23047 + * -1 < bfound && bfound <= bsrc
23050 + * found, but it is on RO branch between bsrc and bdst. cannot
23053 + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return
23056 + * found, after we create the file on bdst, it will be hidden.
23059 + AuDebugOn(a->bfound == -1
23061 + && a->bwh <= a->mvd_bsrc);
23062 + AuDebugOn(-1 < a->bfound
23063 + && a->bfound <= a->mvd_bsrc);
23066 + if (a->bfound == -1
23067 + && a->mvd_bsrc < a->bwh
23069 + && a->bwh < a->mvd_bdst) {
23070 + a->mvd_errno = EAU_MVDOWN_WHITEOUT;
23071 + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n",
23072 + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh);
23074 + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) {
23075 + a->mvd_errno = EAU_MVDOWN_UPPER;
23076 + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n",
23077 + a->mvd_bdst, a->bfound);
23081 + err = 0; /* success */
23088 +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a)
23093 + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER)
23094 + && a->bfound == a->mvd_bdst)
23100 +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a)
23103 + struct au_branch *br;
23106 + if (unlikely(S_ISDIR(a->inode->i_mode)))
23110 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER))
23111 + a->mvd_bsrc = au_ibtop(a->inode);
23113 + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid);
23114 + if (unlikely(a->mvd_bsrc < 0
23115 + || (a->mvd_bsrc < au_dbtop(a->dentry)
23116 + || au_dbbot(a->dentry) < a->mvd_bsrc
23117 + || !au_h_dptr(a->dentry, a->mvd_bsrc))
23118 + || (a->mvd_bsrc < au_ibtop(a->inode)
23119 + || au_ibbot(a->inode) < a->mvd_bsrc
23120 + || !au_h_iptr(a->inode, a->mvd_bsrc)))) {
23121 + a->mvd_errno = EAU_MVDOWN_NOUPPER;
23122 + AU_MVD_PR(dmsg, "no upper\n");
23126 + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) {
23127 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23128 + AU_MVD_PR(dmsg, "on the bottom\n");
23131 + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc);
23132 + br = au_sbr(a->sb, a->mvd_bsrc);
23133 + err = au_br_rdonly(br);
23134 + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) {
23135 + if (unlikely(err))
23137 + } else if (!(vfsub_native_ro(a->mvd_h_src_inode)
23138 + || IS_APPEND(a->mvd_h_src_inode))) {
23140 + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R;
23146 + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) {
23147 + a->mvd_bdst = find_lower_writable(a);
23148 + if (unlikely(a->mvd_bdst < 0)) {
23149 + a->mvd_errno = EAU_MVDOWN_BOTTOM;
23150 + AU_MVD_PR(dmsg, "no writable lower branch\n");
23154 + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid);
23155 + if (unlikely(a->mvd_bdst < 0
23156 + || au_sbbot(a->sb) < a->mvd_bdst)) {
23157 + a->mvd_errno = EAU_MVDOWN_NOLOWERBR;
23158 + AU_MVD_PR(dmsg, "no lower brid\n");
23163 + err = au_mvd_args_busy(dmsg, a);
23165 + err = au_mvd_args_parent(dmsg, a);
23167 + err = au_mvd_args_intermediate(dmsg, a);
23169 + err = au_mvd_args_exist(dmsg, a);
23171 + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst);
23178 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg)
23181 + unsigned char dmsg;
23182 + struct au_mvd_args *args;
23183 + struct inode *inode;
23185 + inode = d_inode(dentry);
23187 + if (unlikely(!capable(CAP_SYS_ADMIN)))
23191 + args = kmalloc(sizeof(*args), GFP_NOFS);
23192 + if (unlikely(!args))
23195 + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown));
23197 + err = !access_ok(VERIFY_WRITE, uarg, sizeof(*uarg));
23198 + if (unlikely(err)) {
23203 + AuDbg("flags 0x%x\n", args->mvdown.flags);
23204 + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R);
23205 + args->mvdown.au_errno = 0;
23206 + args->dentry = dentry;
23207 + args->inode = inode;
23208 + args->sb = dentry->d_sb;
23211 + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG);
23212 + args->parent = dget_parent(dentry);
23213 + args->dir = d_inode(args->parent);
23214 + inode_lock_nested(args->dir, I_MUTEX_PARENT);
23215 + dput(args->parent);
23216 + if (unlikely(args->parent != dentry->d_parent)) {
23217 + AU_MVD_PR(dmsg, "parent dir is moved\n");
23221 + inode_lock_nested(inode, I_MUTEX_CHILD);
23222 + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW);
23223 + if (unlikely(err))
23226 + di_write_lock_parent(args->parent);
23227 + err = au_mvd_args(dmsg, args);
23228 + if (unlikely(err))
23231 + err = au_do_mvdown(dmsg, args);
23232 + if (unlikely(err))
23235 + au_cpup_attr_timesizes(args->dir);
23236 + au_cpup_attr_timesizes(inode);
23237 + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER))
23238 + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst));
23239 + /* au_digen_dec(dentry); */
23242 + di_write_unlock(args->parent);
23243 + aufs_read_unlock(dentry, AuLock_DW);
23245 + inode_unlock(inode);
23247 + inode_unlock(args->dir);
23249 + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown));
23252 + au_delayed_kfree(args);
23257 diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c
23258 --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100
23259 +++ linux/fs/aufs/opts.c 2016-12-17 12:28:17.598545045 +0100
23262 + * Copyright (C) 2005-2016 Junjiro R. Okajima
23264 + * This program, aufs is free software; you can redistribute it and/or modify
23265 + * it under the terms of the GNU General Public License as published by
23266 + * the Free Software Foundation; either version 2 of the License, or
23267 + * (at your option) any later version.
23269 + * This program is distributed in the hope that it will be useful,
23270 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
23271 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23272 + * GNU General Public License for more details.
23274 + * You should have received a copy of the GNU General Public License
23275 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
23279 + * mount options/flags
23282 +#include <linux/namei.h>
23283 +#include <linux/types.h> /* a distribution requires */
23284 +#include <linux/parser.h>
23287 +/* ---------------------------------------------------------------------- */
23291 + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend,
23292 + Opt_idel, Opt_imod,
23293 + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash,
23294 + Opt_rdblk_def, Opt_rdhash_def,
23295 + Opt_xino, Opt_noxino,
23296 + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino,
23297 + Opt_trunc_xino_path, Opt_itrunc_xino,
23298 + Opt_trunc_xib, Opt_notrunc_xib,
23299 + Opt_shwh, Opt_noshwh,
23300 + Opt_plink, Opt_noplink, Opt_list_plink,
23302 + Opt_dio, Opt_nodio,
23303 + Opt_diropq_a, Opt_diropq_w,
23304 + Opt_warn_perm, Opt_nowarn_perm,
23305 + Opt_wbr_copyup, Opt_wbr_create,
23307 + Opt_verbose, Opt_noverbose,
23308 + Opt_sum, Opt_nosum, Opt_wsum,
23309 + Opt_dirperm1, Opt_nodirperm1,
23310 + Opt_acl, Opt_noacl,
23311 + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err
23314 +static match_table_t options = {
23315 + {Opt_br, "br=%s"},
23316 + {Opt_br, "br:%s"},
23318 + {Opt_add, "add=%d:%s"},
23319 + {Opt_add, "add:%d:%s"},
23320 + {Opt_add, "ins=%d:%s"},
23321 + {Opt_add, "ins:%d:%s"},
23322 + {Opt_append, "append=%s"},
23323 + {Opt_append, "append:%s"},
23324 + {Opt_prepend, "prepend=%s"},
23325 + {Opt_prepend, "prepend:%s"},
23327 + {Opt_del, "del=%s"},
23328 + {Opt_del, "del:%s"},
23329 + /* {Opt_idel, "idel:%d"}, */
23330 + {Opt_mod, "mod=%s"},
23331 + {Opt_mod, "mod:%s"},
23332 + /* {Opt_imod, "imod:%d:%s"}, */
23334 + {Opt_dirwh, "dirwh=%d"},
23336 + {Opt_xino, "xino=%s"},
23337 + {Opt_noxino, "noxino"},
23338 + {Opt_trunc_xino, "trunc_xino"},
23339 + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"},
23340 + {Opt_notrunc_xino, "notrunc_xino"},
23341 + {Opt_trunc_xino_path, "trunc_xino=%s"},
23342 + {Opt_itrunc_xino, "itrunc_xino=%d"},
23343 + /* {Opt_zxino, "zxino=%s"}, */
23344 + {Opt_trunc_xib, "trunc_xib"},
23345 + {Opt_notrunc_xib, "notrunc_xib"},
23347 +#ifdef CONFIG_PROC_FS
23348 + {Opt_plink, "plink"},
23350 + {Opt_ignore_silent, "plink"},
23353 + {Opt_noplink, "noplink"},
23355 +#ifdef CONFIG_AUFS_DEBUG
23356 + {Opt_list_plink, "list_plink"},
23359 + {Opt_udba, "udba=%s"},
23361 + {Opt_dio, "dio"},
23362 + {Opt_nodio, "nodio"},
23364 +#ifdef CONFIG_AUFS_FHSM
23365 + {Opt_fhsm_sec, "fhsm_sec=%d"},
23367 + {Opt_ignore_silent, "fhsm_sec=%d"},
23370 + {Opt_diropq_a, "diropq=always"},
23371 + {Opt_diropq_a, "diropq=a"},
23372 + {Opt_diropq_w, "diropq=whiteouted"},
23373 + {Opt_diropq_w, "diropq=w"},
23375 + {Opt_warn_perm, "warn_perm"},
23376 + {Opt_nowarn_perm, "nowarn_perm"},
23378 + /* keep them temporary */
23379 + {Opt_ignore_silent, "nodlgt"},
23380 + {Opt_ignore_silent, "clean_plink"},
23382 +#ifdef CONFIG_AUFS_SHWH
23383 + {Opt_shwh, "shwh"},
23385 + {Opt_noshwh, "noshwh"},
23387 + {Opt_dirperm1, "dirperm1"},
23388 + {Opt_nodirperm1, "nodirperm1"},
23390 + {Opt_verbose, "verbose"},
23391 + {Opt_verbose, "v"},
23392 + {Opt_noverbose, "noverbose"},
23393 + {Opt_noverbose, "quiet"},
23394 + {Opt_noverbose, "q"},
23395 + {Opt_noverbose, "silent"},
23397 + {Opt_sum, "sum"},
23398 + {Opt_nosum, "nosum"},
23399 + {Opt_wsum, "wsum"},
23401 + {Opt_rdcache, "rdcache=%d"},
23402 + {Opt_rdblk, "rdblk=%d"},
23403 + {Opt_rdblk_def, "rdblk=def"},
23404 + {Opt_rdhash, "rdhash=%d"},
23405 + {Opt_rdhash_def, "rdhash=def"},
23407 + {Opt_wbr_create, "create=%s"},
23408 + {Opt_wbr_create, "create_policy=%s"},
23409 + {Opt_wbr_copyup, "cpup=%s"},
23410 + {Opt_wbr_copyup, "copyup=%s"},
23411 + {Opt_wbr_copyup, "copyup_policy=%s"},
23413 + /* generic VFS flag */
23414 +#ifdef CONFIG_FS_POSIX_ACL
23415 + {Opt_acl, "acl"},
23416 + {Opt_noacl, "noacl"},
23418 + {Opt_ignore_silent, "acl"},
23419 + {Opt_ignore_silent, "noacl"},
23422 + /* internal use for the scripts */
23423 + {Opt_ignore_silent, "si=%s"},
23425 + {Opt_br, "dirs=%s"},
23426 + {Opt_ignore, "debug=%d"},
23427 + {Opt_ignore, "delete=whiteout"},
23428 + {Opt_ignore, "delete=all"},
23429 + {Opt_ignore, "imap=%s"},
23431 + /* temporary workaround, due to old mount(8)? */
23432 + {Opt_ignore_silent, "relatime"},
23437 +/* ---------------------------------------------------------------------- */
23439 +static const char *au_parser_pattern(int val, match_table_t tbl)
23441 + struct match_token *p;
23444 + while (p->pattern) {
23445 + if (p->token == val)
23446 + return p->pattern;
23453 +static const char *au_optstr(int *val, match_table_t tbl)
23455 + struct match_token *p;
23462 + while (p->pattern) {
23464 + && (v & p->token) == p->token) {
23465 + *val &= ~p->token;
23466 + return p->pattern;
23475 +/* ---------------------------------------------------------------------- */
23477 +static match_table_t brperm = {
23478 + {AuBrPerm_RO, AUFS_BRPERM_RO},
23479 + {AuBrPerm_RR, AUFS_BRPERM_RR},
23480 + {AuBrPerm_RW, AUFS_BRPERM_RW},
23484 +static match_table_t brattr = {
23486 + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG},
23487 + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL},
23488 + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */
23489 + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN},
23490 +#ifdef CONFIG_AUFS_FHSM
23491 + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM},
23493 +#ifdef CONFIG_AUFS_XATTR
23494 + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX},
23495 + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC},
23496 + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS},
23497 + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR},
23498 + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR},
23499 + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH},
23502 + /* ro/rr branch */
23503 + {AuBrRAttr_WH, AUFS_BRRATTR_WH},
23506 + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO},
23507 + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH},
23512 +static int br_attr_val(char *str, match_table_t table, substring_t args[])
23519 + p = strchr(str, '+');
23522 + v = match_token(str, table, args);
23524 + if (v & AuBrAttr_CMOO_Mask)
23525 + attr &= ~AuBrAttr_CMOO_Mask;
23530 + pr_warn("ignored branch attribute %s\n", str);
23540 +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm)
23548 + p = au_optstr(&perm, brattr);
23551 + memcpy(q, p, sz + 1);
23557 + p = au_optstr(&perm, brattr);
23561 + memcpy(q, p, sz + 1);
23567 + return q - str->a;
23570 +static int noinline_for_stack br_perm_val(char *perm)
23572 + int val, bad, sz;
23574 + substring_t args[MAX_OPT_ARGS];
23575 + au_br_perm_str_t attr;
23577 + p = strchr(perm, '+');
23580 + val = match_token(perm, brperm, args);
23584 + pr_warn("ignored branch permission %s\n", perm);
23585 + val = AuBrPerm_RO;
23591 + val |= br_attr_val(p + 1, brattr, args);
23594 + switch (val & AuBrPerm_Mask) {
23595 + case AuBrPerm_RO:
23596 + case AuBrPerm_RR:
23597 + bad = val & AuBrWAttr_Mask;
23598 + val &= ~AuBrWAttr_Mask;
23600 + case AuBrPerm_RW:
23601 + bad = val & AuBrRAttr_Mask;
23602 + val &= ~AuBrRAttr_Mask;
23607 + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs
23608 + * does not treat it as an error, just warning.
23609 + * this is a tiny guard for the user operation.
23611 + if (val & AuBrAttr_UNPIN) {
23612 + bad |= AuBrAttr_UNPIN;
23613 + val &= ~AuBrAttr_UNPIN;
23616 + if (unlikely(bad)) {
23617 + sz = au_do_optstr_br_attr(&attr, bad);
23619 + pr_warn("ignored branch attribute %s\n", attr.a);
23626 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm)
23628 + au_br_perm_str_t attr;
23634 + p = au_optstr(&perm, brperm);
23635 + AuDebugOn(!p || !*p);
23637 + memcpy(q, p, sz + 1);
23640 + sz = au_do_optstr_br_attr(&attr, perm);
23643 + memcpy(q, attr.a, sz + 1);
23646 + AuDebugOn(strlen(str->a) >= sizeof(str->a));
23649 +/* ---------------------------------------------------------------------- */
23651 +static match_table_t udbalevel = {
23652 + {AuOpt_UDBA_REVAL, "reval"},
23653 + {AuOpt_UDBA_NONE, "none"},
23654 +#ifdef CONFIG_AUFS_HNOTIFY
23655 + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */
23656 +#ifdef CONFIG_AUFS_HFSNOTIFY
23657 + {AuOpt_UDBA_HNOTIFY, "fsnotify"},
23663 +static int noinline_for_stack udba_val(char *str)
23665 + substring_t args[MAX_OPT_ARGS];
23667 + return match_token(str, udbalevel, args);
23670 +const char *au_optstr_udba(int udba)
23672 + return au_parser_pattern(udba, udbalevel);
23675 +/* ---------------------------------------------------------------------- */
23677 +static match_table_t au_wbr_create_policy = {
23678 + {AuWbrCreate_TDP, "tdp"},
23679 + {AuWbrCreate_TDP, "top-down-parent"},
23680 + {AuWbrCreate_RR, "rr"},
23681 + {AuWbrCreate_RR, "round-robin"},
23682 + {AuWbrCreate_MFS, "mfs"},
23683 + {AuWbrCreate_MFS, "most-free-space"},
23684 + {AuWbrCreate_MFSV, "mfs:%d"},
23685 + {AuWbrCreate_MFSV, "most-free-space:%d"},
23687 + /* top-down regardless the parent, and then mfs */
23688 + {AuWbrCreate_TDMFS, "tdmfs:%d"},
23689 + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"},
23691 + {AuWbrCreate_MFSRR, "mfsrr:%d"},
23692 + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"},
23693 + {AuWbrCreate_PMFS, "pmfs"},
23694 + {AuWbrCreate_PMFSV, "pmfs:%d"},
23695 + {AuWbrCreate_PMFSRR, "pmfsrr:%d"},
23696 + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"},
23702 + * cf. linux/lib/parser.c and cmdline.c
23703 + * gave up calling memparse() since it uses simple_strtoull() instead of
23706 +static int noinline_for_stack
23707 +au_match_ull(substring_t *s, unsigned long long *result)
23710 + unsigned int len;
23714 + len = s->to - s->from;
23715 + if (len + 1 <= sizeof(a)) {
23716 + memcpy(a, s->from, len);
23718 + err = kstrtoull(a, 0, result);
23723 +static int au_wbr_mfs_wmark(substring_t *arg, char *str,
23724 + struct au_opt_wbr_create *create)
23727 + unsigned long long ull;
23730 + if (!au_match_ull(arg, &ull))
23731 + create->mfsrr_watermark = ull;
23733 + pr_err("bad integer in %s\n", str);
23740 +static int au_wbr_mfs_sec(substring_t *arg, char *str,
23741 + struct au_opt_wbr_create *create)
23746 + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC)
23747 + create->mfs_second = n;
23749 + pr_err("bad integer in %s\n", str);
23756 +static int noinline_for_stack
23757 +au_wbr_create_val(char *str, struct au_opt_wbr_create *create)
23760 + substring_t args[MAX_OPT_ARGS];
23762 + err = match_token(str, au_wbr_create_policy, args);
23763 + create->wbr_create = err;
23765 + case AuWbrCreate_MFSRRV:
23766 + case AuWbrCreate_TDMFSV:
23767 + case AuWbrCreate_PMFSRRV:
23768 + e = au_wbr_mfs_wmark(&args[0], str, create);
23770 + e = au_wbr_mfs_sec(&args[1], str, create);
23774 + case AuWbrCreate_MFSRR:
23775 + case AuWbrCreate_TDMFS:
23776 + case AuWbrCreate_PMFSRR:
23777 + e = au_wbr_mfs_wmark(&args[0], str, create);
23778 + if (unlikely(e)) {
23783 + case AuWbrCreate_MFS:
23784 + case AuWbrCreate_PMFS:
23785 + create->mfs_second = AUFS_MFS_DEF_SEC;
23787 + case AuWbrCreate_MFSV:
23788 + case AuWbrCreate_PMFSV:
23789 + e = au_wbr_mfs_sec(&args[0], str, create);
23798 +const char *au_optstr_wbr_create(int wbr_create)
23800 + return au_parser_pattern(wbr_create, au_wbr_create_policy);
23803 +static match_table_t au_wbr_copyup_policy = {
23804 + {AuWbrCopyup_TDP, "tdp"},
23805 + {AuWbrCopyup_TDP, "top-down-parent"},
23806 + {AuWbrCopyup_BUP, "bup"},
23807 + {AuWbrCopyup_BUP, "bottom-up-parent"},
23808 + {AuWbrCopyup_BU, "bu"},
23809 + {AuWbrCopyup_BU, "bottom-up"},
23813 +static int noinline_for_stack au_wbr_copyup_val(char *str)
23815 + substring_t args[MAX_OPT_ARGS];
23817 + return match_token(str, au_wbr_copyup_policy, args);
23820 +const char *au_optstr_wbr_copyup(int wbr_copyup)
23822 + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy);
23825 +/* ---------------------------------------------------------------------- */
23827 +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY;
23829 +static void dump_opts(struct au_opts *opts)
23831 +#ifdef CONFIG_AUFS_DEBUG
23832 + /* reduce stack space */
23834 + struct au_opt_add *add;
23835 + struct au_opt_del *del;
23836 + struct au_opt_mod *mod;
23837 + struct au_opt_xino *xino;
23838 + struct au_opt_xino_itrunc *xino_itrunc;
23839 + struct au_opt_wbr_create *create;
23841 + struct au_opt *opt;
23844 + while (opt->type != Opt_tail) {
23845 + switch (opt->type) {
23847 + u.add = &opt->add;
23848 + AuDbg("add {b%d, %s, 0x%x, %p}\n",
23849 + u.add->bindex, u.add->pathname, u.add->perm,
23850 + u.add->path.dentry);
23854 + u.del = &opt->del;
23855 + AuDbg("del {%s, %p}\n",
23856 + u.del->pathname, u.del->h_path.dentry);
23860 + u.mod = &opt->mod;
23861 + AuDbg("mod {%s, 0x%x, %p}\n",
23862 + u.mod->path, u.mod->perm, u.mod->h_root);
23865 + u.add = &opt->add;
23866 + AuDbg("append {b%d, %s, 0x%x, %p}\n",
23867 + u.add->bindex, u.add->pathname, u.add->perm,
23868 + u.add->path.dentry);
23870 + case Opt_prepend:
23871 + u.add = &opt->add;
23872 + AuDbg("prepend {b%d, %s, 0x%x, %p}\n",
23873 + u.add->bindex, u.add->pathname, u.add->perm,
23874 + u.add->path.dentry);
23877 + AuDbg("dirwh %d\n", opt->dirwh);
23879 + case Opt_rdcache:
23880 + AuDbg("rdcache %d\n", opt->rdcache);
23883 + AuDbg("rdblk %u\n", opt->rdblk);
23885 + case Opt_rdblk_def:
23886 + AuDbg("rdblk_def\n");
23889 + AuDbg("rdhash %u\n", opt->rdhash);
23891 + case Opt_rdhash_def:
23892 + AuDbg("rdhash_def\n");
23895 + u.xino = &opt->xino;
23896 + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file);
23898 + case Opt_trunc_xino:
23899 + AuLabel(trunc_xino);
23901 + case Opt_notrunc_xino:
23902 + AuLabel(notrunc_xino);
23904 + case Opt_trunc_xino_path:
23905 + case Opt_itrunc_xino:
23906 + u.xino_itrunc = &opt->xino_itrunc;
23907 + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex);
23912 + case Opt_trunc_xib:
23913 + AuLabel(trunc_xib);
23915 + case Opt_notrunc_xib:
23916 + AuLabel(notrunc_xib);
23924 + case Opt_dirperm1:
23925 + AuLabel(dirperm1);
23927 + case Opt_nodirperm1:
23928 + AuLabel(nodirperm1);
23933 + case Opt_noplink:
23934 + AuLabel(noplink);
23936 + case Opt_list_plink:
23937 + AuLabel(list_plink);
23940 + AuDbg("udba %d, %s\n",
23941 + opt->udba, au_optstr_udba(opt->udba));
23949 + case Opt_diropq_a:
23950 + AuLabel(diropq_a);
23952 + case Opt_diropq_w:
23953 + AuLabel(diropq_w);
23955 + case Opt_warn_perm:
23956 + AuLabel(warn_perm);
23958 + case Opt_nowarn_perm:
23959 + AuLabel(nowarn_perm);
23961 + case Opt_verbose:
23962 + AuLabel(verbose);
23964 + case Opt_noverbose:
23965 + AuLabel(noverbose);
23976 + case Opt_wbr_create:
23977 + u.create = &opt->wbr_create;
23978 + AuDbg("create %d, %s\n", u.create->wbr_create,
23979 + au_optstr_wbr_create(u.create->wbr_create));
23980 + switch (u.create->wbr_create) {
23981 + case AuWbrCreate_MFSV:
23982 + case AuWbrCreate_PMFSV:
23983 + AuDbg("%d sec\n", u.create->mfs_second);
23985 + case AuWbrCreate_MFSRR:
23986 + case AuWbrCreate_TDMFS:
23987 + AuDbg("%llu watermark\n",
23988 + u.create->mfsrr_watermark);
23990 + case AuWbrCreate_MFSRRV:
23991 + case AuWbrCreate_TDMFSV:
23992 + case AuWbrCreate_PMFSRRV:
23993 + AuDbg("%llu watermark, %d sec\n",
23994 + u.create->mfsrr_watermark,
23995 + u.create->mfs_second);
23999 + case Opt_wbr_copyup:
24000 + AuDbg("copyup %d, %s\n", opt->wbr_copyup,
24001 + au_optstr_wbr_copyup(opt->wbr_copyup));
24003 + case Opt_fhsm_sec:
24004 + AuDbg("fhsm_sec %u\n", opt->fhsm_second);
24020 +void au_opts_free(struct au_opts *opts)
24022 + struct au_opt *opt;
24025 + while (opt->type != Opt_tail) {
24026 + switch (opt->type) {
24029 + case Opt_prepend:
24030 + path_put(&opt->add.path);
24034 + path_put(&opt->del.h_path);
24038 + dput(opt->mod.h_root);
24041 + fput(opt->xino.file);
24048 +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags,
24049 + aufs_bindex_t bindex)
24052 + struct au_opt_add *add = &opt->add;
24055 + add->bindex = bindex;
24056 + add->perm = AuBrPerm_RO;
24057 + add->pathname = opt_str;
24058 + p = strchr(opt_str, '=');
24062 + add->perm = br_perm_val(p);
24065 + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path);
24068 + add->perm = AuBrPerm_RO;
24069 + if (au_test_fs_rr(add->path.dentry->d_sb))
24070 + add->perm = AuBrPerm_RR;
24071 + else if (!bindex && !(sb_flags & MS_RDONLY))
24072 + add->perm = AuBrPerm_RW;
24074 + opt->type = Opt_add;
24077 + pr_err("lookup failed %s (%d)\n", add->pathname, err);
24084 +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[])
24088 + del->pathname = args[0].from;
24089 + AuDbg("del path %s\n", del->pathname);
24091 + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path);
24092 + if (unlikely(err))
24093 + pr_err("lookup failed %s (%d)\n", del->pathname, err);
24098 +#if 0 /* reserved for future use */
24099 +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex,
24100 + struct au_opt_del *del, substring_t args[])
24103 + struct dentry *root;
24106 + root = sb->s_root;
24107 + aufs_read_lock(root, AuLock_FLUSH);
24108 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24109 + pr_err("out of bounds, %d\n", bindex);
24114 + del->h_path.dentry = dget(au_h_dptr(root, bindex));
24115 + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex));
24118 + aufs_read_unlock(root, !AuLock_IR);
24123 +static int noinline_for_stack
24124 +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[])
24127 + struct path path;
24131 + mod->path = args[0].from;
24132 + p = strchr(mod->path, '=');
24133 + if (unlikely(!p)) {
24134 + pr_err("no permssion %s\n", args[0].from);
24139 + err = vfsub_kern_path(mod->path, lkup_dirflags, &path);
24140 + if (unlikely(err)) {
24141 + pr_err("lookup failed %s (%d)\n", mod->path, err);
24145 + mod->perm = br_perm_val(p);
24146 + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p);
24147 + mod->h_root = dget(path.dentry);
24154 +#if 0 /* reserved for future use */
24155 +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex,
24156 + struct au_opt_mod *mod, substring_t args[])
24159 + struct dentry *root;
24162 + root = sb->s_root;
24163 + aufs_read_lock(root, AuLock_FLUSH);
24164 + if (bindex < 0 || au_sbbot(sb) < bindex) {
24165 + pr_err("out of bounds, %d\n", bindex);
24170 + mod->perm = br_perm_val(args[1].from);
24171 + AuDbg("mod path %s, perm 0x%x, %s\n",
24172 + mod->path, mod->perm, args[1].from);
24173 + mod->h_root = dget(au_h_dptr(root, bindex));
24176 + aufs_read_unlock(root, !AuLock_IR);
24181 +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino,
24182 + substring_t args[])
24185 + struct file *file;
24187 + file = au_xino_create(sb, args[0].from, /*silent*/0);
24188 + err = PTR_ERR(file);
24189 + if (IS_ERR(file))
24193 + if (unlikely(file->f_path.dentry->d_sb == sb)) {
24195 + pr_err("%s must be outside\n", args[0].from);
24200 + xino->file = file;
24201 + xino->path = args[0].from;
24207 +static int noinline_for_stack
24208 +au_opts_parse_xino_itrunc_path(struct super_block *sb,
24209 + struct au_opt_xino_itrunc *xino_itrunc,
24210 + substring_t args[])
24213 + aufs_bindex_t bbot, bindex;
24214 + struct path path;
24215 + struct dentry *root;
24217 + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path);
24218 + if (unlikely(err)) {
24219 + pr_err("lookup failed %s (%d)\n", args[0].from, err);
24223 + xino_itrunc->bindex = -1;
24224 + root = sb->s_root;
24225 + aufs_read_lock(root, AuLock_FLUSH);
24226 + bbot = au_sbbot(sb);
24227 + for (bindex = 0; bindex <= bbot; bindex++) {
24228 + if (au_h_dptr(root, bindex) == path.dentry) {
24229 + xino_itrunc->bindex = bindex;
24233 + aufs_read_unlock(root, !AuLock_IR);
24236 + if (unlikely(xino_itrunc->bindex < 0)) {
24237 + pr_err("no such branch %s\n", args[0].from);
24245 +/* called without aufs lock */
24246 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts)
24248 + int err, n, token;
24249 + aufs_bindex_t bindex;
24250 + unsigned char skipped;
24251 + struct dentry *root;
24252 + struct au_opt *opt, *opt_tail;
24254 + /* reduce the stack space */
24256 + struct au_opt_xino_itrunc *xino_itrunc;
24257 + struct au_opt_wbr_create *create;
24260 + substring_t args[MAX_OPT_ARGS];
24264 + a = kmalloc(sizeof(*a), GFP_NOFS);
24265 + if (unlikely(!a))
24268 + root = sb->s_root;
24272 + opt_tail = opt + opts->max_opt - 1;
24273 + opt->type = Opt_tail;
24274 + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) {
24277 + token = match_token(opt_str, options, a->args);
24281 + while (!err && (opt_str = strsep(&a->args[0].from, ":"))
24283 + err = opt_add(opt, opt_str, opts->sb_flags,
24285 + if (unlikely(!err && ++opt > opt_tail)) {
24289 + opt->type = Opt_tail;
24294 + if (unlikely(match_int(&a->args[0], &n))) {
24295 + pr_err("bad integer in %s\n", opt_str);
24299 + err = opt_add(opt, a->args[1].from, opts->sb_flags,
24302 + opt->type = token;
24305 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24306 + /*dummy bindex*/1);
24308 + opt->type = token;
24310 + case Opt_prepend:
24311 + err = opt_add(opt, a->args[0].from, opts->sb_flags,
24314 + opt->type = token;
24317 + err = au_opts_parse_del(&opt->del, a->args);
24319 + opt->type = token;
24321 +#if 0 /* reserved for future use */
24323 + del->pathname = "(indexed)";
24324 + if (unlikely(match_int(&args[0], &n))) {
24325 + pr_err("bad integer in %s\n", opt_str);
24328 + err = au_opts_parse_idel(sb, n, &opt->del, a->args);
24330 + opt->type = token;
24334 + err = au_opts_parse_mod(&opt->mod, a->args);
24336 + opt->type = token;
24338 +#ifdef IMOD /* reserved for future use */
24340 + u.mod->path = "(indexed)";
24341 + if (unlikely(match_int(&a->args[0], &n))) {
24342 + pr_err("bad integer in %s\n", opt_str);
24345 + err = au_opts_parse_imod(sb, n, &opt->mod, a->args);
24347 + opt->type = token;
24351 + err = au_opts_parse_xino(sb, &opt->xino, a->args);
24353 + opt->type = token;
24356 + case Opt_trunc_xino_path:
24357 + err = au_opts_parse_xino_itrunc_path
24358 + (sb, &opt->xino_itrunc, a->args);
24360 + opt->type = token;
24363 + case Opt_itrunc_xino:
24364 + u.xino_itrunc = &opt->xino_itrunc;
24365 + if (unlikely(match_int(&a->args[0], &n))) {
24366 + pr_err("bad integer in %s\n", opt_str);
24369 + u.xino_itrunc->bindex = n;
24370 + aufs_read_lock(root, AuLock_FLUSH);
24371 + if (n < 0 || au_sbbot(sb) < n) {
24372 + pr_err("out of bounds, %d\n", n);
24373 + aufs_read_unlock(root, !AuLock_IR);
24376 + aufs_read_unlock(root, !AuLock_IR);
24378 + opt->type = token;
24382 + if (unlikely(match_int(&a->args[0], &opt->dirwh)))
24385 + opt->type = token;
24388 + case Opt_rdcache:
24389 + if (unlikely(match_int(&a->args[0], &n))) {
24390 + pr_err("bad integer in %s\n", opt_str);
24393 + if (unlikely(n > AUFS_RDCACHE_MAX)) {
24394 + pr_err("rdcache must be smaller than %d\n",
24395 + AUFS_RDCACHE_MAX);
24398 + opt->rdcache = n;
24400 + opt->type = token;
24403 + if (unlikely(match_int(&a->args[0], &n)
24405 + || n > KMALLOC_MAX_SIZE)) {
24406 + pr_err("bad integer in %s\n", opt_str);
24409 + if (unlikely(n && n < NAME_MAX)) {
24410 + pr_err("rdblk must be larger than %d\n",
24416 + opt->type = token;
24419 + if (unlikely(match_int(&a->args[0], &n)
24421 + || n * sizeof(struct hlist_head)
24422 + > KMALLOC_MAX_SIZE)) {
24423 + pr_err("bad integer in %s\n", opt_str);
24428 + opt->type = token;
24431 + case Opt_trunc_xino:
24432 + case Opt_notrunc_xino:
24434 + case Opt_trunc_xib:
24435 + case Opt_notrunc_xib:
24438 + case Opt_dirperm1:
24439 + case Opt_nodirperm1:
24441 + case Opt_noplink:
24442 + case Opt_list_plink:
24445 + case Opt_diropq_a:
24446 + case Opt_diropq_w:
24447 + case Opt_warn_perm:
24448 + case Opt_nowarn_perm:
24449 + case Opt_verbose:
24450 + case Opt_noverbose:
24454 + case Opt_rdblk_def:
24455 + case Opt_rdhash_def:
24459 + opt->type = token;
24463 + opt->udba = udba_val(a->args[0].from);
24464 + if (opt->udba >= 0) {
24466 + opt->type = token;
24468 + pr_err("wrong value, %s\n", opt_str);
24471 + case Opt_wbr_create:
24472 + u.create = &opt->wbr_create;
24473 + u.create->wbr_create
24474 + = au_wbr_create_val(a->args[0].from, u.create);
24475 + if (u.create->wbr_create >= 0) {
24477 + opt->type = token;
24479 + pr_err("wrong value, %s\n", opt_str);
24481 + case Opt_wbr_copyup:
24482 + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from);
24483 + if (opt->wbr_copyup >= 0) {
24485 + opt->type = token;
24487 + pr_err("wrong value, %s\n", opt_str);
24490 + case Opt_fhsm_sec:
24491 + if (unlikely(match_int(&a->args[0], &n)
24493 + pr_err("bad integer in %s\n", opt_str);
24496 + if (sysaufs_brs) {
24497 + opt->fhsm_second = n;
24498 + opt->type = token;
24500 + pr_warn("ignored %s\n", opt_str);
24505 + pr_warn("ignored %s\n", opt_str);
24507 + case Opt_ignore_silent:
24512 + pr_err("unknown option %s\n", opt_str);
24516 + if (!err && !skipped) {
24517 + if (unlikely(++opt > opt_tail)) {
24520 + opt->type = Opt_tail;
24523 + opt->type = Opt_tail;
24527 + au_delayed_kfree(a);
24529 + if (unlikely(err))
24530 + au_opts_free(opts);
24536 +static int au_opt_wbr_create(struct super_block *sb,
24537 + struct au_opt_wbr_create *create)
24540 + struct au_sbinfo *sbinfo;
24542 + SiMustWriteLock(sb);
24544 + err = 1; /* handled */
24545 + sbinfo = au_sbi(sb);
24546 + if (sbinfo->si_wbr_create_ops->fin) {
24547 + err = sbinfo->si_wbr_create_ops->fin(sb);
24552 + sbinfo->si_wbr_create = create->wbr_create;
24553 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create;
24554 + switch (create->wbr_create) {
24555 + case AuWbrCreate_MFSRRV:
24556 + case AuWbrCreate_MFSRR:
24557 + case AuWbrCreate_TDMFS:
24558 + case AuWbrCreate_TDMFSV:
24559 + case AuWbrCreate_PMFSRR:
24560 + case AuWbrCreate_PMFSRRV:
24561 + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark;
24563 + case AuWbrCreate_MFS:
24564 + case AuWbrCreate_MFSV:
24565 + case AuWbrCreate_PMFS:
24566 + case AuWbrCreate_PMFSV:
24567 + sbinfo->si_wbr_mfs.mfs_expire
24568 + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC);
24572 + if (sbinfo->si_wbr_create_ops->init)
24573 + sbinfo->si_wbr_create_ops->init(sb); /* ignore */
24580 + * plus: processed without an error
24581 + * zero: unprocessed
24583 +static int au_opt_simple(struct super_block *sb, struct au_opt *opt,
24584 + struct au_opts *opts)
24587 + struct au_sbinfo *sbinfo;
24589 + SiMustWriteLock(sb);
24591 + err = 1; /* handled */
24592 + sbinfo = au_sbi(sb);
24593 + switch (opt->type) {
24595 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
24596 + sbinfo->si_mntflags |= opt->udba;
24597 + opts->given_udba |= opt->udba;
24601 + au_opt_set(sbinfo->si_mntflags, PLINK);
24603 + case Opt_noplink:
24604 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24605 + au_plink_put(sb, /*verbose*/1);
24606 + au_opt_clr(sbinfo->si_mntflags, PLINK);
24608 + case Opt_list_plink:
24609 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
24610 + au_plink_list(sb);
24614 + au_opt_set(sbinfo->si_mntflags, DIO);
24615 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24618 + au_opt_clr(sbinfo->si_mntflags, DIO);
24619 + au_fset_opts(opts->flags, REFRESH_DYAOP);
24622 + case Opt_fhsm_sec:
24623 + au_fhsm_set(sbinfo, opt->fhsm_second);
24626 + case Opt_diropq_a:
24627 + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24629 + case Opt_diropq_w:
24630 + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ);
24633 + case Opt_warn_perm:
24634 + au_opt_set(sbinfo->si_mntflags, WARN_PERM);
24636 + case Opt_nowarn_perm:
24637 + au_opt_clr(sbinfo->si_mntflags, WARN_PERM);
24640 + case Opt_verbose:
24641 + au_opt_set(sbinfo->si_mntflags, VERBOSE);
24643 + case Opt_noverbose:
24644 + au_opt_clr(sbinfo->si_mntflags, VERBOSE);
24648 + au_opt_set(sbinfo->si_mntflags, SUM);
24651 + au_opt_clr(sbinfo->si_mntflags, SUM);
24652 + au_opt_set(sbinfo->si_mntflags, SUM_W);
24654 + au_opt_clr(sbinfo->si_mntflags, SUM);
24655 + au_opt_clr(sbinfo->si_mntflags, SUM_W);
24658 + case Opt_wbr_create:
24659 + err = au_opt_wbr_create(sb, &opt->wbr_create);
24661 + case Opt_wbr_copyup:
24662 + sbinfo->si_wbr_copyup = opt->wbr_copyup;
24663 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup;
24667 + sbinfo->si_dirwh = opt->dirwh;
24670 + case Opt_rdcache:
24671 + sbinfo->si_rdcache
24672 + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC);
24675 + sbinfo->si_rdblk = opt->rdblk;
24677 + case Opt_rdblk_def:
24678 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
24681 + sbinfo->si_rdhash = opt->rdhash;
24683 + case Opt_rdhash_def:
24684 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
24688 + au_opt_set(sbinfo->si_mntflags, SHWH);
24691 + au_opt_clr(sbinfo->si_mntflags, SHWH);
24694 + case Opt_dirperm1:
24695 + au_opt_set(sbinfo->si_mntflags, DIRPERM1);
24697 + case Opt_nodirperm1:
24698 + au_opt_clr(sbinfo->si_mntflags, DIRPERM1);
24701 + case Opt_trunc_xino:
24702 + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO);
24704 + case Opt_notrunc_xino:
24705 + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO);
24708 + case Opt_trunc_xino_path:
24709 + case Opt_itrunc_xino:
24710 + err = au_xino_trunc(sb, opt->xino_itrunc.bindex);
24715 + case Opt_trunc_xib:
24716 + au_fset_opts(opts->flags, TRUNC_XIB);
24718 + case Opt_notrunc_xib:
24719 + au_fclr_opts(opts->flags, TRUNC_XIB);
24723 + sb->s_flags |= MS_POSIXACL;
24726 + sb->s_flags &= ~MS_POSIXACL;
24738 + * returns tri-state.
24739 + * plus: processed without an error
24740 + * zero: unprocessed
24743 +static int au_opt_br(struct super_block *sb, struct au_opt *opt,
24744 + struct au_opts *opts)
24746 + int err, do_refresh;
24749 + switch (opt->type) {
24751 + opt->add.bindex = au_sbbot(sb) + 1;
24752 + if (opt->add.bindex < 0)
24753 + opt->add.bindex = 0;
24755 + case Opt_prepend:
24756 + opt->add.bindex = 0;
24757 + add: /* indented label */
24759 + err = au_br_add(sb, &opt->add,
24760 + au_ftest_opts(opts->flags, REMOUNT));
24763 + au_fset_opts(opts->flags, REFRESH);
24769 + err = au_br_del(sb, &opt->del,
24770 + au_ftest_opts(opts->flags, REMOUNT));
24773 + au_fset_opts(opts->flags, TRUNC_XIB);
24774 + au_fset_opts(opts->flags, REFRESH);
24780 + err = au_br_mod(sb, &opt->mod,
24781 + au_ftest_opts(opts->flags, REMOUNT),
24786 + au_fset_opts(opts->flags, REFRESH);
24794 +static int au_opt_xino(struct super_block *sb, struct au_opt *opt,
24795 + struct au_opt_xino **opt_xino,
24796 + struct au_opts *opts)
24799 + aufs_bindex_t bbot, bindex;
24800 + struct dentry *root, *parent, *h_root;
24803 + switch (opt->type) {
24805 + err = au_xino_set(sb, &opt->xino,
24806 + !!au_ftest_opts(opts->flags, REMOUNT));
24807 + if (unlikely(err))
24810 + *opt_xino = &opt->xino;
24811 + au_xino_brid_set(sb, -1);
24813 + /* safe d_parent access */
24814 + parent = opt->xino.file->f_path.dentry->d_parent;
24815 + root = sb->s_root;
24816 + bbot = au_sbbot(sb);
24817 + for (bindex = 0; bindex <= bbot; bindex++) {
24818 + h_root = au_h_dptr(root, bindex);
24819 + if (h_root == parent) {
24820 + au_xino_brid_set(sb, au_sbr_id(sb, bindex));
24828 + au_xino_brid_set(sb, -1);
24829 + *opt_xino = (void *)-1;
24836 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
24837 + unsigned int pending)
24840 + aufs_bindex_t bindex, bbot;
24841 + unsigned char do_plink, skip, do_free, can_no_dreval;
24842 + struct au_branch *br;
24843 + struct au_wbr *wbr;
24844 + struct dentry *root, *dentry;
24845 + struct inode *dir, *h_dir;
24846 + struct au_sbinfo *sbinfo;
24847 + struct au_hinode *hdir;
24849 + SiMustAnyLock(sb);
24851 + sbinfo = au_sbi(sb);
24852 + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA));
24854 + if (!(sb_flags & MS_RDONLY)) {
24855 + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0))))
24856 + pr_warn("first branch should be rw\n");
24857 + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH)))
24858 + pr_warn_once("shwh should be used with ro\n");
24861 + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY)
24862 + && !au_opt_test(sbinfo->si_mntflags, XINO))
24863 + pr_warn_once("udba=*notify requires xino\n");
24865 + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1))
24866 + pr_warn_once("dirperm1 breaks the protection"
24867 + " by the permission bits on the lower branch\n");
24871 + root = sb->s_root;
24872 + dir = d_inode(root);
24873 + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK);
24874 + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending),
24876 + bbot = au_sbbot(sb);
24877 + for (bindex = 0; !err && bindex <= bbot; bindex++) {
24879 + h_dir = au_h_iptr(dir, bindex);
24880 + br = au_sbr(sb, bindex);
24882 + if ((br->br_perm & AuBrAttr_ICEX)
24883 + && !h_dir->i_op->listxattr)
24884 + br->br_perm &= ~AuBrAttr_ICEX;
24886 + if ((br->br_perm & AuBrAttr_ICEX_SEC)
24887 + && (au_br_sb(br)->s_flags & MS_NOSEC))
24888 + br->br_perm &= ~AuBrAttr_ICEX_SEC;
24892 + wbr = br->br_wbr;
24894 + wbr_wh_read_lock(wbr);
24896 + if (!au_br_writable(br->br_perm)) {
24899 + || (!wbr->wbr_whbase
24900 + && !wbr->wbr_plink
24901 + && !wbr->wbr_orph));
24902 + } else if (!au_br_wh_linkable(br->br_perm)) {
24903 + /* skip = (!br->br_whbase && !br->br_orph); */
24904 + skip = (!wbr || !wbr->wbr_whbase);
24905 + if (skip && wbr) {
24907 + skip = !!wbr->wbr_plink;
24909 + skip = !wbr->wbr_plink;
24912 + /* skip = (br->br_whbase && br->br_ohph); */
24913 + skip = (wbr && wbr->wbr_whbase);
24916 + skip = !!wbr->wbr_plink;
24918 + skip = !wbr->wbr_plink;
24922 + wbr_wh_read_unlock(wbr);
24924 + if (can_no_dreval) {
24925 + dentry = br->br_path.dentry;
24926 + spin_lock(&dentry->d_lock);
24927 + if (dentry->d_flags &
24928 + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE))
24929 + can_no_dreval = 0;
24930 + spin_unlock(&dentry->d_lock);
24933 + if (au_br_fhsm(br->br_perm)) {
24935 + AuDebugOn(!br->br_fhsm);
24941 + hdir = au_hi(dir, bindex);
24942 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
24944 + wbr_wh_write_lock(wbr);
24945 + err = au_wh_init(br, sb);
24947 + wbr_wh_write_unlock(wbr);
24948 + au_hn_inode_unlock(hdir);
24950 + if (!err && do_free) {
24952 + au_delayed_kfree(wbr);
24953 + br->br_wbr = NULL;
24957 + if (can_no_dreval)
24958 + au_fset_si(sbinfo, NO_DREVAL);
24960 + au_fclr_si(sbinfo, NO_DREVAL);
24963 + au_fset_si(sbinfo, FHSM);
24964 + for (bindex = bbot; bindex >= 0; bindex--) {
24965 + br = au_sbr(sb, bindex);
24966 + if (au_br_fhsm(br->br_perm)) {
24967 + au_fhsm_set_bottom(sb, bindex);
24972 + au_fclr_si(sbinfo, FHSM);
24973 + au_fhsm_set_bottom(sb, -1);
24979 +int au_opts_mount(struct super_block *sb, struct au_opts *opts)
24982 + unsigned int tmp;
24983 + aufs_bindex_t bindex, bbot;
24984 + struct au_opt *opt;
24985 + struct au_opt_xino *opt_xino, xino;
24986 + struct au_sbinfo *sbinfo;
24987 + struct au_branch *br;
24988 + struct inode *dir;
24990 + SiMustWriteLock(sb);
24995 + while (err >= 0 && opt->type != Opt_tail)
24996 + err = au_opt_simple(sb, opt++, opts);
24999 + else if (unlikely(err < 0))
25002 + /* disable xino and udba temporary */
25003 + sbinfo = au_sbi(sb);
25004 + tmp = sbinfo->si_mntflags;
25005 + au_opt_clr(sbinfo->si_mntflags, XINO);
25006 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL);
25009 + while (err >= 0 && opt->type != Opt_tail)
25010 + err = au_opt_br(sb, opt++, opts);
25013 + else if (unlikely(err < 0))
25016 + bbot = au_sbbot(sb);
25017 + if (unlikely(bbot < 0)) {
25019 + pr_err("no branches\n");
25023 + if (au_opt_test(tmp, XINO))
25024 + au_opt_set(sbinfo->si_mntflags, XINO);
25026 + while (!err && opt->type != Opt_tail)
25027 + err = au_opt_xino(sb, opt++, &opt_xino, opts);
25028 + if (unlikely(err))
25031 + err = au_opts_verify(sb, sb->s_flags, tmp);
25032 + if (unlikely(err))
25035 + /* restore xino */
25036 + if (au_opt_test(tmp, XINO) && !opt_xino) {
25037 + xino.file = au_xino_def(sb);
25038 + err = PTR_ERR(xino.file);
25039 + if (IS_ERR(xino.file))
25042 + err = au_xino_set(sb, &xino, /*remount*/0);
25044 + if (unlikely(err))
25048 + /* restore udba */
25049 + tmp &= AuOptMask_UDBA;
25050 + sbinfo->si_mntflags &= ~AuOptMask_UDBA;
25051 + sbinfo->si_mntflags |= tmp;
25052 + bbot = au_sbbot(sb);
25053 + for (bindex = 0; bindex <= bbot; bindex++) {
25054 + br = au_sbr(sb, bindex);
25055 + err = au_hnotify_reset_br(tmp, br, br->br_perm);
25056 + if (unlikely(err))
25057 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
25059 + /* go on even if err */
25061 + if (au_opt_test(tmp, UDBA_HNOTIFY)) {
25062 + dir = d_inode(sb->s_root);
25063 + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO);
25070 +int au_opts_remount(struct super_block *sb, struct au_opts *opts)
25073 + unsigned char no_dreval;
25074 + struct inode *dir;
25075 + struct au_opt_xino *opt_xino;
25076 + struct au_opt *opt;
25077 + struct au_sbinfo *sbinfo;
25079 + SiMustWriteLock(sb);
25082 + dir = d_inode(sb->s_root);
25083 + sbinfo = au_sbi(sb);
25086 + while (err >= 0 && opt->type != Opt_tail) {
25087 + err = au_opt_simple(sb, opt, opts);
25089 + err = au_opt_br(sb, opt, opts);
25091 + err = au_opt_xino(sb, opt, &opt_xino, opts);
25097 + /* go on even err */
25099 + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL);
25100 + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0);
25101 + if (unlikely(rerr && !err))
25104 + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL))
25105 + au_fset_opts(opts->flags, REFRESH_IDOP);
25107 + if (au_ftest_opts(opts->flags, TRUNC_XIB)) {
25108 + rerr = au_xib_trunc(sb);
25109 + if (unlikely(rerr && !err))
25113 + /* will be handled by the caller */
25114 + if (!au_ftest_opts(opts->flags, REFRESH)
25115 + && (opts->given_udba
25116 + || au_opt_test(sbinfo->si_mntflags, XINO)
25117 + || au_ftest_opts(opts->flags, REFRESH_IDOP)
25119 + au_fset_opts(opts->flags, REFRESH);
25121 + AuDbg("status 0x%x\n", opts->flags);
25125 +/* ---------------------------------------------------------------------- */
25127 +unsigned int au_opt_udba(struct super_block *sb)
25129 + return au_mntflags(sb) & AuOptMask_UDBA;
25131 diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h
25132 --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100
25133 +++ linux/fs/aufs/opts.h 2016-12-17 12:28:17.598545045 +0100
25136 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25138 + * This program, aufs is free software; you can redistribute it and/or modify
25139 + * it under the terms of the GNU General Public License as published by
25140 + * the Free Software Foundation; either version 2 of the License, or
25141 + * (at your option) any later version.
25143 + * This program is distributed in the hope that it will be useful,
25144 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25145 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25146 + * GNU General Public License for more details.
25148 + * You should have received a copy of the GNU General Public License
25149 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25153 + * mount options/flags
25156 +#ifndef __AUFS_OPTS_H__
25157 +#define __AUFS_OPTS_H__
25161 +#include <linux/path.h>
25164 +struct super_block;
25166 +/* ---------------------------------------------------------------------- */
25169 +#define AuOpt_XINO 1 /* external inode number bitmap
25170 + and translation table */
25171 +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */
25172 +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */
25173 +#define AuOpt_UDBA_REVAL (1 << 3)
25174 +#define AuOpt_UDBA_HNOTIFY (1 << 4)
25175 +#define AuOpt_SHWH (1 << 5) /* show whiteout */
25176 +#define AuOpt_PLINK (1 << 6) /* pseudo-link */
25177 +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm
25179 +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */
25180 +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */
25181 +#define AuOpt_SUM_W (1 << 11) /* unimplemented */
25182 +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */
25183 +#define AuOpt_VERBOSE (1 << 13) /* busy inode when del-branch */
25184 +#define AuOpt_DIO (1 << 14) /* direct io */
25186 +#ifndef CONFIG_AUFS_HNOTIFY
25187 +#undef AuOpt_UDBA_HNOTIFY
25188 +#define AuOpt_UDBA_HNOTIFY 0
25190 +#ifndef CONFIG_AUFS_SHWH
25192 +#define AuOpt_SHWH 0
25195 +#define AuOpt_Def (AuOpt_XINO \
25196 + | AuOpt_UDBA_REVAL \
25198 + /* | AuOpt_DIRPERM1 */ \
25199 + | AuOpt_WARN_PERM)
25200 +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \
25201 + | AuOpt_UDBA_REVAL \
25202 + | AuOpt_UDBA_HNOTIFY)
25204 +#define au_opt_test(flags, name) (flags & AuOpt_##name)
25205 +#define au_opt_set(flags, name) do { \
25206 + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \
25207 + ((flags) |= AuOpt_##name); \
25209 +#define au_opt_set_udba(flags, name) do { \
25210 + (flags) &= ~AuOptMask_UDBA; \
25211 + ((flags) |= AuOpt_##name); \
25213 +#define au_opt_clr(flags, name) do { \
25214 + ((flags) &= ~AuOpt_##name); \
25217 +static inline unsigned int au_opts_plink(unsigned int mntflags)
25219 +#ifdef CONFIG_PROC_FS
25222 + return mntflags & ~AuOpt_PLINK;
25226 +/* ---------------------------------------------------------------------- */
25228 +/* policies to select one among multiple writable branches */
25230 + AuWbrCreate_TDP, /* top down parent */
25231 + AuWbrCreate_RR, /* round robin */
25232 + AuWbrCreate_MFS, /* most free space */
25233 + AuWbrCreate_MFSV, /* mfs with seconds */
25234 + AuWbrCreate_MFSRR, /* mfs then rr */
25235 + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */
25236 + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */
25237 + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */
25238 + AuWbrCreate_PMFS, /* parent and mfs */
25239 + AuWbrCreate_PMFSV, /* parent and mfs with seconds */
25240 + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */
25241 + AuWbrCreate_PMFSRRV, /* plus seconds */
25243 + AuWbrCreate_Def = AuWbrCreate_TDP
25247 + AuWbrCopyup_TDP, /* top down parent */
25248 + AuWbrCopyup_BUP, /* bottom up parent */
25249 + AuWbrCopyup_BU, /* bottom up */
25251 + AuWbrCopyup_Def = AuWbrCopyup_TDP
25254 +/* ---------------------------------------------------------------------- */
25256 +struct au_opt_add {
25257 + aufs_bindex_t bindex;
25260 + struct path path;
25263 +struct au_opt_del {
25265 + struct path h_path;
25268 +struct au_opt_mod {
25271 + struct dentry *h_root;
25274 +struct au_opt_xino {
25276 + struct file *file;
25279 +struct au_opt_xino_itrunc {
25280 + aufs_bindex_t bindex;
25283 +struct au_opt_wbr_create {
25286 + unsigned long long mfsrr_watermark;
25292 + struct au_opt_xino xino;
25293 + struct au_opt_xino_itrunc xino_itrunc;
25294 + struct au_opt_add add;
25295 + struct au_opt_del del;
25296 + struct au_opt_mod mod;
25299 + unsigned int rdblk;
25300 + unsigned int rdhash;
25302 + struct au_opt_wbr_create wbr_create;
25304 + unsigned int fhsm_second;
25309 +#define AuOpts_REMOUNT 1
25310 +#define AuOpts_REFRESH (1 << 1)
25311 +#define AuOpts_TRUNC_XIB (1 << 2)
25312 +#define AuOpts_REFRESH_DYAOP (1 << 3)
25313 +#define AuOpts_REFRESH_IDOP (1 << 4)
25314 +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name)
25315 +#define au_fset_opts(flags, name) \
25316 + do { (flags) |= AuOpts_##name; } while (0)
25317 +#define au_fclr_opts(flags, name) \
25318 + do { (flags) &= ~AuOpts_##name; } while (0)
25321 + struct au_opt *opt;
25324 + unsigned int given_udba;
25325 + unsigned int flags;
25326 + unsigned long sb_flags;
25329 +/* ---------------------------------------------------------------------- */
25332 +void au_optstr_br_perm(au_br_perm_str_t *str, int perm);
25333 +const char *au_optstr_udba(int udba);
25334 +const char *au_optstr_wbr_copyup(int wbr_copyup);
25335 +const char *au_optstr_wbr_create(int wbr_create);
25337 +void au_opts_free(struct au_opts *opts);
25338 +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts);
25339 +int au_opts_verify(struct super_block *sb, unsigned long sb_flags,
25340 + unsigned int pending);
25341 +int au_opts_mount(struct super_block *sb, struct au_opts *opts);
25342 +int au_opts_remount(struct super_block *sb, struct au_opts *opts);
25344 +unsigned int au_opt_udba(struct super_block *sb);
25346 +#endif /* __KERNEL__ */
25347 +#endif /* __AUFS_OPTS_H__ */
25348 diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c
25349 --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100
25350 +++ linux/fs/aufs/plink.c 2016-10-09 16:55:36.496035060 +0200
25353 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25355 + * This program, aufs is free software; you can redistribute it and/or modify
25356 + * it under the terms of the GNU General Public License as published by
25357 + * the Free Software Foundation; either version 2 of the License, or
25358 + * (at your option) any later version.
25360 + * This program is distributed in the hope that it will be useful,
25361 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25362 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25363 + * GNU General Public License for more details.
25365 + * You should have received a copy of the GNU General Public License
25366 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25376 + * the pseudo-link maintenance mode.
25377 + * during a user process maintains the pseudo-links,
25378 + * prohibit adding a new plink and branch manipulation.
25382 + * For entry functions which will handle plink, and i_mutex is already held
25384 + * They cannot wait and should return an error at once.
25385 + * Callers has to check the error.
25387 + * For entry functions which will handle plink, but i_mutex is not held
25389 + * They can wait the plink maintenance mode to finish.
25391 + * They behave like F_SETLK and F_SETLKW.
25392 + * If the caller never handle plink, then both flags are unnecessary.
25395 +int au_plink_maint(struct super_block *sb, int flags)
25399 + struct task_struct *parent, *prev;
25400 + struct au_sbinfo *sbi;
25402 + SiMustAnyLock(sb);
25405 + if (!au_opt_test(au_mntflags(sb), PLINK))
25408 + sbi = au_sbi(sb);
25409 + pid = sbi->si_plink_maint_pid;
25410 + if (!pid || pid == current->pid)
25413 + /* todo: it highly depends upon /sbin/mount.aufs */
25415 + parent = current;
25419 + parent = rcu_dereference(parent->real_parent);
25420 + if (parent == prev)
25422 + ppid = task_pid_vnr(parent);
25423 + if (pid == ppid) {
25424 + rcu_read_unlock();
25429 + rcu_read_unlock();
25431 + if (au_ftest_lock(flags, NOPLMW)) {
25432 + /* if there is no i_mutex lock in VFS, we don't need to wait */
25433 + /* AuDebugOn(!lockdep_depth(current)); */
25434 + while (sbi->si_plink_maint_pid) {
25435 + si_read_unlock(sb);
25436 + /* gave up wake_up_bit() */
25437 + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid);
25439 + if (au_ftest_lock(flags, FLUSH))
25440 + au_nwt_flush(&sbi->si_nowait);
25441 + si_noflush_read_lock(sb);
25443 + } else if (au_ftest_lock(flags, NOPLM)) {
25444 + AuDbg("ppid %d, pid %d\n", ppid, pid);
25452 +void au_plink_maint_leave(struct au_sbinfo *sbinfo)
25454 + spin_lock(&sbinfo->si_plink_maint_lock);
25455 + sbinfo->si_plink_maint_pid = 0;
25456 + spin_unlock(&sbinfo->si_plink_maint_lock);
25457 + wake_up_all(&sbinfo->si_plink_wq);
25460 +int au_plink_maint_enter(struct super_block *sb)
25463 + struct au_sbinfo *sbinfo;
25466 + sbinfo = au_sbi(sb);
25467 + /* make sure i am the only one in this fs */
25468 + si_write_lock(sb, AuLock_FLUSH);
25469 + if (au_opt_test(au_mntflags(sb), PLINK)) {
25470 + spin_lock(&sbinfo->si_plink_maint_lock);
25471 + if (!sbinfo->si_plink_maint_pid)
25472 + sbinfo->si_plink_maint_pid = current->pid;
25475 + spin_unlock(&sbinfo->si_plink_maint_lock);
25477 + si_write_unlock(sb);
25482 +/* ---------------------------------------------------------------------- */
25484 +#ifdef CONFIG_AUFS_DEBUG
25485 +void au_plink_list(struct super_block *sb)
25488 + struct au_sbinfo *sbinfo;
25489 + struct hlist_head *plink_hlist;
25490 + struct au_icntnr *icntnr;
25492 + SiMustAnyLock(sb);
25494 + sbinfo = au_sbi(sb);
25495 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25496 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25498 + for (i = 0; i < AuPlink_NHASH; i++) {
25499 + plink_hlist = &sbinfo->si_plink[i].head;
25501 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25502 + AuDbg("%lu\n", icntnr->vfs_inode.i_ino);
25503 + rcu_read_unlock();
25508 +/* is the inode pseudo-linked? */
25509 +int au_plink_test(struct inode *inode)
25512 + struct au_sbinfo *sbinfo;
25513 + struct hlist_head *plink_hlist;
25514 + struct au_icntnr *icntnr;
25516 + sbinfo = au_sbi(inode->i_sb);
25517 + AuRwMustAnyLock(&sbinfo->si_rwsem);
25518 + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK));
25519 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25522 + i = au_plink_hash(inode->i_ino);
25523 + plink_hlist = &sbinfo->si_plink[i].head;
25525 + hlist_for_each_entry_rcu(icntnr, plink_hlist, plink)
25526 + if (&icntnr->vfs_inode == inode) {
25530 + rcu_read_unlock();
25534 +/* ---------------------------------------------------------------------- */
25537 + * generate a name for plink.
25538 + * the file will be stored under AUFS_WH_PLINKDIR.
25540 +/* 20 is max digits length of ulong 64 */
25541 +#define PLINK_NAME_LEN ((20 + 1) * 2)
25543 +static int plink_name(char *name, int len, struct inode *inode,
25544 + aufs_bindex_t bindex)
25547 + struct inode *h_inode;
25549 + h_inode = au_h_iptr(inode, bindex);
25550 + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino);
25554 +struct au_do_plink_lkup_args {
25555 + struct dentry **errp;
25556 + struct qstr *tgtname;
25557 + struct dentry *h_parent;
25558 + struct au_branch *br;
25561 +static struct dentry *au_do_plink_lkup(struct qstr *tgtname,
25562 + struct dentry *h_parent,
25563 + struct au_branch *br)
25565 + struct dentry *h_dentry;
25566 + struct inode *h_inode;
25568 + h_inode = d_inode(h_parent);
25569 + inode_lock_nested(h_inode, AuLsc_I_CHILD2);
25570 + h_dentry = vfsub_lkup_one(tgtname, h_parent);
25571 + inode_unlock(h_inode);
25575 +static void au_call_do_plink_lkup(void *args)
25577 + struct au_do_plink_lkup_args *a = args;
25578 + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br);
25581 +/* lookup the plink-ed @inode under the branch at @bindex */
25582 +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex)
25584 + struct dentry *h_dentry, *h_parent;
25585 + struct au_branch *br;
25587 + char a[PLINK_NAME_LEN];
25588 + struct qstr tgtname = QSTR_INIT(a, 0);
25590 + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM));
25592 + br = au_sbr(inode->i_sb, bindex);
25593 + h_parent = br->br_wbr->wbr_plink;
25594 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25596 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25597 + struct au_do_plink_lkup_args args = {
25598 + .errp = &h_dentry,
25599 + .tgtname = &tgtname,
25600 + .h_parent = h_parent,
25604 + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args);
25605 + if (unlikely(wkq_err))
25606 + h_dentry = ERR_PTR(wkq_err);
25608 + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br);
25613 +/* create a pseudo-link */
25614 +static int do_whplink(struct qstr *tgt, struct dentry *h_parent,
25615 + struct dentry *h_dentry, struct au_branch *br)
25618 + struct path h_path = {
25619 + .mnt = au_br_mnt(br)
25621 + struct inode *h_dir, *delegated;
25623 + h_dir = d_inode(h_parent);
25624 + inode_lock_nested(h_dir, AuLsc_I_CHILD2);
25626 + h_path.dentry = vfsub_lkup_one(tgt, h_parent);
25627 + err = PTR_ERR(h_path.dentry);
25628 + if (IS_ERR(h_path.dentry))
25632 + /* wh.plink dir is not monitored */
25633 + /* todo: is it really safe? */
25634 + if (d_is_positive(h_path.dentry)
25635 + && d_inode(h_path.dentry) != d_inode(h_dentry)) {
25636 + delegated = NULL;
25637 + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0);
25638 + if (unlikely(err == -EWOULDBLOCK)) {
25639 + pr_warn("cannot retry for NFSv4 delegation"
25640 + " for an internal unlink\n");
25643 + dput(h_path.dentry);
25644 + h_path.dentry = NULL;
25648 + if (!err && d_is_negative(h_path.dentry)) {
25649 + delegated = NULL;
25650 + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated);
25651 + if (unlikely(err == -EWOULDBLOCK)) {
25652 + pr_warn("cannot retry for NFSv4 delegation"
25653 + " for an internal link\n");
25657 + dput(h_path.dentry);
25660 + inode_unlock(h_dir);
25664 +struct do_whplink_args {
25666 + struct qstr *tgt;
25667 + struct dentry *h_parent;
25668 + struct dentry *h_dentry;
25669 + struct au_branch *br;
25672 +static void call_do_whplink(void *args)
25674 + struct do_whplink_args *a = args;
25675 + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br);
25678 +static int whplink(struct dentry *h_dentry, struct inode *inode,
25679 + aufs_bindex_t bindex, struct au_branch *br)
25681 + int err, wkq_err;
25682 + struct au_wbr *wbr;
25683 + struct dentry *h_parent;
25684 + char a[PLINK_NAME_LEN];
25685 + struct qstr tgtname = QSTR_INIT(a, 0);
25687 + wbr = au_sbr(inode->i_sb, bindex)->br_wbr;
25688 + h_parent = wbr->wbr_plink;
25689 + tgtname.len = plink_name(a, sizeof(a), inode, bindex);
25691 + /* always superio. */
25692 + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) {
25693 + struct do_whplink_args args = {
25696 + .h_parent = h_parent,
25697 + .h_dentry = h_dentry,
25700 + wkq_err = au_wkq_wait(call_do_whplink, &args);
25701 + if (unlikely(wkq_err))
25704 + err = do_whplink(&tgtname, h_parent, h_dentry, br);
25710 + * create a new pseudo-link for @h_dentry on @bindex.
25711 + * the linked inode is held in aufs @inode.
25713 +void au_plink_append(struct inode *inode, aufs_bindex_t bindex,
25714 + struct dentry *h_dentry)
25716 + struct super_block *sb;
25717 + struct au_sbinfo *sbinfo;
25718 + struct hlist_head *plink_hlist;
25719 + struct au_icntnr *icntnr;
25720 + struct au_sphlhead *sphl;
25721 + int found, err, cnt, i;
25723 + sb = inode->i_sb;
25724 + sbinfo = au_sbi(sb);
25725 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25726 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25728 + found = au_plink_test(inode);
25732 + i = au_plink_hash(inode->i_ino);
25733 + sphl = sbinfo->si_plink + i;
25734 + plink_hlist = &sphl->head;
25737 + spin_lock(&sphl->spin);
25738 + hlist_for_each_entry(icntnr, plink_hlist, plink) {
25739 + if (&icntnr->vfs_inode == inode) {
25745 + icntnr = container_of(inode, struct au_icntnr, vfs_inode);
25746 + hlist_add_head_rcu(&icntnr->plink, plink_hlist);
25748 + spin_unlock(&sphl->spin);
25750 + cnt = au_sphl_count(sphl);
25751 +#define msg "unexpectedly unblanced or too many pseudo-links"
25752 + if (cnt > AUFS_PLINK_WARN)
25753 + AuWarn1(msg ", %d\n", cnt);
25755 + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex));
25756 + if (unlikely(err)) {
25757 + pr_warn("err %d, damaged pseudo link.\n", err);
25758 + au_sphl_del_rcu(&icntnr->plink, sphl);
25759 + iput(&icntnr->vfs_inode);
25762 + iput(&icntnr->vfs_inode);
25765 +/* free all plinks */
25766 +void au_plink_put(struct super_block *sb, int verbose)
25769 + struct au_sbinfo *sbinfo;
25770 + struct hlist_head *plink_hlist;
25771 + struct hlist_node *tmp;
25772 + struct au_icntnr *icntnr;
25774 + SiMustWriteLock(sb);
25776 + sbinfo = au_sbi(sb);
25777 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25778 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25780 + /* no spin_lock since sbinfo is write-locked */
25782 + for (i = 0; i < AuPlink_NHASH; i++) {
25783 + plink_hlist = &sbinfo->si_plink[i].head;
25784 + if (!warned && verbose && !hlist_empty(plink_hlist)) {
25785 + pr_warn("pseudo-link is not flushed");
25788 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink)
25789 + iput(&icntnr->vfs_inode);
25790 + INIT_HLIST_HEAD(plink_hlist);
25794 +void au_plink_clean(struct super_block *sb, int verbose)
25796 + struct dentry *root;
25798 + root = sb->s_root;
25799 + aufs_write_lock(root);
25800 + if (au_opt_test(au_mntflags(sb), PLINK))
25801 + au_plink_put(sb, verbose);
25802 + aufs_write_unlock(root);
25805 +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id)
25808 + aufs_bindex_t btop, bbot, bindex;
25811 + btop = au_ibtop(inode);
25812 + bbot = au_ibbot(inode);
25814 + for (bindex = btop; bindex <= bbot; bindex++) {
25815 + if (!au_h_iptr(inode, bindex)
25816 + || au_ii_br_id(inode, bindex) != br_id)
25818 + au_set_h_iptr(inode, bindex, NULL, 0);
25823 + for (bindex = btop; bindex <= bbot; bindex++)
25824 + if (au_h_iptr(inode, bindex)) {
25834 +/* free the plinks on a branch specified by @br_id */
25835 +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id)
25837 + struct au_sbinfo *sbinfo;
25838 + struct hlist_head *plink_hlist;
25839 + struct hlist_node *tmp;
25840 + struct au_icntnr *icntnr;
25841 + struct inode *inode;
25844 + SiMustWriteLock(sb);
25846 + sbinfo = au_sbi(sb);
25847 + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK));
25848 + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM));
25850 + /* no spin_lock since sbinfo is write-locked */
25851 + for (i = 0; i < AuPlink_NHASH; i++) {
25852 + plink_hlist = &sbinfo->si_plink[i].head;
25853 + hlist_for_each_entry_safe(icntnr, tmp, plink_hlist, plink) {
25854 + inode = au_igrab(&icntnr->vfs_inode);
25855 + ii_write_lock_child(inode);
25856 + do_put = au_plink_do_half_refresh(inode, br_id);
25858 + hlist_del(&icntnr->plink);
25861 + ii_write_unlock(inode);
25866 diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c
25867 --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100
25868 +++ linux/fs/aufs/poll.c 2016-10-09 16:55:36.496035060 +0200
25871 + * Copyright (C) 2005-2016 Junjiro R. Okajima
25873 + * This program, aufs is free software; you can redistribute it and/or modify
25874 + * it under the terms of the GNU General Public License as published by
25875 + * the Free Software Foundation; either version 2 of the License, or
25876 + * (at your option) any later version.
25878 + * This program is distributed in the hope that it will be useful,
25879 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25880 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25881 + * GNU General Public License for more details.
25883 + * You should have received a copy of the GNU General Public License
25884 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25889 + * There is only one filesystem which implements ->poll operation, currently.
25894 +unsigned int aufs_poll(struct file *file, poll_table *wait)
25896 + unsigned int mask;
25898 + struct file *h_file;
25899 + struct super_block *sb;
25901 + /* We should pretend an error happened. */
25902 + mask = POLLERR /* | POLLIN | POLLOUT */;
25903 + sb = file->f_path.dentry->d_sb;
25904 + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW);
25906 + h_file = au_read_pre(file, /*keep_fi*/0);
25907 + err = PTR_ERR(h_file);
25908 + if (IS_ERR(h_file))
25911 + /* it is not an error if h_file has no operation */
25912 + mask = DEFAULT_POLLMASK;
25913 + if (h_file->f_op->poll)
25914 + mask = h_file->f_op->poll(h_file, wait);
25915 + fput(h_file); /* instead of au_read_post() */
25918 + si_read_unlock(sb);
25919 + AuTraceErr((int)mask);
25922 diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c
25923 --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100
25924 +++ linux/fs/aufs/posix_acl.c 2016-12-17 12:28:17.598545045 +0100
25927 + * Copyright (C) 2014-2016 Junjiro R. Okajima
25929 + * This program, aufs is free software; you can redistribute it and/or modify
25930 + * it under the terms of the GNU General Public License as published by
25931 + * the Free Software Foundation; either version 2 of the License, or
25932 + * (at your option) any later version.
25934 + * This program is distributed in the hope that it will be useful,
25935 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
25936 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25937 + * GNU General Public License for more details.
25939 + * You should have received a copy of the GNU General Public License
25940 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
25944 + * posix acl operations
25947 +#include <linux/fs.h>
25950 +struct posix_acl *aufs_get_acl(struct inode *inode, int type)
25952 + struct posix_acl *acl;
25954 + aufs_bindex_t bindex;
25955 + struct inode *h_inode;
25956 + struct super_block *sb;
25959 + sb = inode->i_sb;
25960 + si_read_lock(sb, AuLock_FLUSH);
25961 + ii_read_lock_child(inode);
25962 + if (!(sb->s_flags & MS_POSIXACL))
25965 + bindex = au_ibtop(inode);
25966 + h_inode = au_h_iptr(inode, bindex);
25967 + if (unlikely(!h_inode
25968 + || ((h_inode->i_mode & S_IFMT)
25969 + != (inode->i_mode & S_IFMT)))) {
25970 + err = au_busy_or_stale();
25971 + acl = ERR_PTR(err);
25975 + /* always topmost only */
25976 + acl = get_acl(h_inode, type);
25979 + ii_read_unlock(inode);
25980 + si_read_unlock(sb);
25982 + AuTraceErrPtr(acl);
25986 +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
25990 + struct dentry *dentry;
25991 + struct au_sxattr arg = {
25992 + .type = AU_ACL_SET,
25999 + IMustLock(inode);
26001 + if (inode->i_ino == AUFS_ROOT_INO)
26002 + dentry = dget(inode->i_sb->s_root);
26004 + dentry = d_find_alias(inode);
26006 + dentry = d_find_any_alias(inode);
26008 + pr_warn("cannot handle this inode, "
26009 + "please report to aufs-users ML\n");
26015 + ssz = au_sxattr(dentry, inode, &arg);
26024 diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c
26025 --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100
26026 +++ linux/fs/aufs/procfs.c 2016-10-09 16:55:36.496035060 +0200
26029 + * Copyright (C) 2010-2016 Junjiro R. Okajima
26031 + * This program, aufs is free software; you can redistribute it and/or modify
26032 + * it under the terms of the GNU General Public License as published by
26033 + * the Free Software Foundation; either version 2 of the License, or
26034 + * (at your option) any later version.
26036 + * This program is distributed in the hope that it will be useful,
26037 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26038 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26039 + * GNU General Public License for more details.
26041 + * You should have received a copy of the GNU General Public License
26042 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26046 + * procfs interfaces
26049 +#include <linux/proc_fs.h>
26052 +static int au_procfs_plm_release(struct inode *inode, struct file *file)
26054 + struct au_sbinfo *sbinfo;
26056 + sbinfo = file->private_data;
26058 + au_plink_maint_leave(sbinfo);
26059 + kobject_put(&sbinfo->si_kobj);
26065 +static void au_procfs_plm_write_clean(struct file *file)
26067 + struct au_sbinfo *sbinfo;
26069 + sbinfo = file->private_data;
26071 + au_plink_clean(sbinfo->si_sb, /*verbose*/0);
26074 +static int au_procfs_plm_write_si(struct file *file, unsigned long id)
26077 + struct super_block *sb;
26078 + struct au_sbinfo *sbinfo;
26081 + if (unlikely(file->private_data))
26085 + /* don't use au_sbilist_lock() here */
26086 + spin_lock(&au_sbilist.spin);
26087 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
26088 + if (id == sysaufs_si_id(sbinfo)) {
26089 + kobject_get(&sbinfo->si_kobj);
26090 + sb = sbinfo->si_sb;
26093 + spin_unlock(&au_sbilist.spin);
26096 + if (unlikely(!sb))
26099 + err = au_plink_maint_enter(sb);
26101 + /* keep kobject_get() */
26102 + file->private_data = sbinfo;
26104 + kobject_put(&sbinfo->si_kobj);
26110 + * Accept a valid "si=xxxx" only.
26111 + * Once it is accepted successfully, accept "clean" too.
26113 +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf,
26114 + size_t count, loff_t *ppos)
26117 + unsigned long id;
26118 + /* last newline is allowed */
26119 + char buf[3 + sizeof(unsigned long) * 2 + 1];
26122 + if (unlikely(!capable(CAP_SYS_ADMIN)))
26126 + if (unlikely(count > sizeof(buf)))
26129 + err = copy_from_user(buf, ubuf, count);
26130 + if (unlikely(err)) {
26137 + if (!strcmp("clean", buf)) {
26138 + au_procfs_plm_write_clean(file);
26139 + goto out_success;
26140 + } else if (unlikely(strncmp("si=", buf, 3)))
26143 + err = kstrtoul(buf + 3, 16, &id);
26144 + if (unlikely(err))
26147 + err = au_procfs_plm_write_si(file, id);
26148 + if (unlikely(err))
26152 + err = count; /* success */
26157 +static const struct file_operations au_procfs_plm_fop = {
26158 + .write = au_procfs_plm_write,
26159 + .release = au_procfs_plm_release,
26160 + .owner = THIS_MODULE
26163 +/* ---------------------------------------------------------------------- */
26165 +static struct proc_dir_entry *au_procfs_dir;
26167 +void au_procfs_fin(void)
26169 + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir);
26170 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26173 +int __init au_procfs_init(void)
26176 + struct proc_dir_entry *entry;
26179 + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL);
26180 + if (unlikely(!au_procfs_dir))
26183 + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | S_IWUSR,
26184 + au_procfs_dir, &au_procfs_plm_fop);
26185 + if (unlikely(!entry))
26189 + goto out; /* success */
26193 + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL);
26197 diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c
26198 --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100
26199 +++ linux/fs/aufs/rdu.c 2016-10-09 16:55:36.496035060 +0200
26202 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26204 + * This program, aufs is free software; you can redistribute it and/or modify
26205 + * it under the terms of the GNU General Public License as published by
26206 + * the Free Software Foundation; either version 2 of the License, or
26207 + * (at your option) any later version.
26209 + * This program is distributed in the hope that it will be useful,
26210 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26211 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26212 + * GNU General Public License for more details.
26214 + * You should have received a copy of the GNU General Public License
26215 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26219 + * readdir in userspace.
26222 +#include <linux/compat.h>
26223 +#include <linux/fs_stack.h>
26224 +#include <linux/security.h>
26227 +/* bits for struct aufs_rdu.flags */
26228 +#define AuRdu_CALLED 1
26229 +#define AuRdu_CONT (1 << 1)
26230 +#define AuRdu_FULL (1 << 2)
26231 +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name)
26232 +#define au_fset_rdu(flags, name) \
26233 + do { (flags) |= AuRdu_##name; } while (0)
26234 +#define au_fclr_rdu(flags, name) \
26235 + do { (flags) &= ~AuRdu_##name; } while (0)
26237 +struct au_rdu_arg {
26238 + struct dir_context ctx;
26239 + struct aufs_rdu *rdu;
26240 + union au_rdu_ent_ul ent;
26241 + unsigned long end;
26243 + struct super_block *sb;
26247 +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen,
26248 + loff_t offset, u64 h_ino, unsigned int d_type)
26251 + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx);
26252 + struct aufs_rdu *rdu = arg->rdu;
26253 + struct au_rdu_ent ent;
26257 + au_fset_rdu(rdu->cookie.flags, CALLED);
26258 + len = au_rdu_len(nlen);
26259 + if (arg->ent.ul + len < arg->end) {
26261 + ent.bindex = rdu->cookie.bindex;
26262 + ent.type = d_type;
26264 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
26265 + ent.type = DT_UNKNOWN;
26267 + /* unnecessary to support mmap_sem since this is a dir */
26269 + if (copy_to_user(arg->ent.e, &ent, sizeof(ent)))
26271 + if (copy_to_user(arg->ent.e->name, name, nlen))
26273 + /* the terminating NULL */
26274 + if (__put_user(0, arg->ent.e->name + nlen))
26277 + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */
26278 + arg->ent.ul += len;
26282 + au_fset_rdu(rdu->cookie.flags, FULL);
26284 + rdu->tail = arg->ent;
26288 + /* AuTraceErr(err); */
26292 +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg)
26296 + struct au_rdu_cookie *cookie = &arg->rdu->cookie;
26298 + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */
26299 + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET);
26301 + if (unlikely(offset != cookie->h_pos))
26307 + au_fclr_rdu(cookie->flags, CALLED);
26309 + err = vfsub_iterate_dir(h_file, &arg->ctx);
26313 + && au_ftest_rdu(cookie->flags, CALLED)
26314 + && !au_ftest_rdu(cookie->flags, FULL));
26315 + cookie->h_pos = h_file->f_pos;
26322 +static int au_rdu(struct file *file, struct aufs_rdu *rdu)
26325 + aufs_bindex_t bbot;
26326 + struct au_rdu_arg arg = {
26328 + .actor = au_rdu_fill
26331 + struct dentry *dentry;
26332 + struct inode *inode;
26333 + struct file *h_file;
26334 + struct au_rdu_cookie *cookie = &rdu->cookie;
26336 + err = !access_ok(VERIFY_WRITE, rdu->ent.e, rdu->sz);
26337 + if (unlikely(err)) {
26343 + rdu->tail = rdu->ent;
26346 + arg.ent = rdu->ent;
26347 + arg.end = arg.ent.ul;
26348 + arg.end += rdu->sz;
26351 + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared))
26354 + err = security_file_permission(file, MAY_READ);
26356 + if (unlikely(err))
26359 + dentry = file->f_path.dentry;
26360 + inode = d_inode(dentry);
26361 + inode_lock_shared(inode);
26363 + arg.sb = inode->i_sb;
26364 + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM);
26365 + if (unlikely(err))
26367 + err = au_alive_dir(dentry);
26368 + if (unlikely(err))
26370 + /* todo: reval? */
26371 + fi_read_lock(file);
26374 + if (unlikely(au_ftest_rdu(cookie->flags, CONT)
26375 + && cookie->generation != au_figen(file)))
26380 + rdu->blk = au_sbi(arg.sb)->si_rdblk;
26382 + rdu->blk = au_dir_size(file, /*dentry*/NULL);
26384 + bbot = au_fbtop(file);
26385 + if (cookie->bindex < bbot)
26386 + cookie->bindex = bbot;
26387 + bbot = au_fbbot_dir(file);
26388 + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */
26389 + for (; !err && cookie->bindex <= bbot;
26390 + cookie->bindex++, cookie->h_pos = 0) {
26391 + h_file = au_hf_dir(file, cookie->bindex);
26395 + au_fclr_rdu(cookie->flags, FULL);
26396 + err = au_rdu_do(h_file, &arg);
26398 + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err))
26401 + AuDbg("rent %llu\n", rdu->rent);
26403 + if (!err && !au_ftest_rdu(cookie->flags, CONT)) {
26404 + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH);
26405 + au_fset_rdu(cookie->flags, CONT);
26406 + cookie->generation = au_figen(file);
26409 + ii_read_lock_child(inode);
26410 + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode)));
26411 + ii_read_unlock(inode);
26414 + fi_read_unlock(file);
26416 + si_read_unlock(arg.sb);
26418 + inode_unlock_shared(inode);
26424 +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu)
26428 + unsigned long long nent;
26429 + union au_rdu_ent_ul *u;
26430 + struct au_rdu_ent ent;
26431 + struct super_block *sb;
26434 + nent = rdu->nent;
26436 + sb = file->f_path.dentry->d_sb;
26437 + si_read_lock(sb, AuLock_FLUSH);
26438 + while (nent-- > 0) {
26439 + /* unnecessary to support mmap_sem since this is a dir */
26440 + err = copy_from_user(&ent, u->e, sizeof(ent));
26442 + err = !access_ok(VERIFY_WRITE, &u->e->ino, sizeof(ino));
26443 + if (unlikely(err)) {
26449 + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */
26451 + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino);
26453 + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type,
26455 + if (unlikely(err)) {
26460 + err = __put_user(ino, &u->e->ino);
26461 + if (unlikely(err)) {
26466 + u->ul += au_rdu_len(ent.nlen);
26468 + si_read_unlock(sb);
26473 +/* ---------------------------------------------------------------------- */
26475 +static int au_rdu_verify(struct aufs_rdu *rdu)
26477 + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | "
26478 + "%llu, b%d, 0x%x, g%u}\n",
26479 + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ],
26481 + rdu->rent, rdu->shwh, rdu->full,
26482 + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags,
26483 + rdu->cookie.generation);
26485 + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu))
26489 + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu));
26493 +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26496 + struct aufs_rdu rdu;
26497 + void __user *p = (void __user *)arg;
26499 + err = copy_from_user(&rdu, p, sizeof(rdu));
26500 + if (unlikely(err)) {
26505 + err = au_rdu_verify(&rdu);
26506 + if (unlikely(err))
26510 + case AUFS_CTL_RDU:
26511 + err = au_rdu(file, &rdu);
26512 + if (unlikely(err))
26515 + e = copy_to_user(p, &rdu, sizeof(rdu));
26516 + if (unlikely(e)) {
26521 + case AUFS_CTL_RDU_INO:
26522 + err = au_rdu_ino(file, &rdu);
26526 + /* err = -ENOTTY; */
26535 +#ifdef CONFIG_COMPAT
26536 +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
26539 + struct aufs_rdu rdu;
26540 + void __user *p = compat_ptr(arg);
26542 + /* todo: get_user()? */
26543 + err = copy_from_user(&rdu, p, sizeof(rdu));
26544 + if (unlikely(err)) {
26549 + rdu.ent.e = compat_ptr(rdu.ent.ul);
26550 + err = au_rdu_verify(&rdu);
26551 + if (unlikely(err))
26555 + case AUFS_CTL_RDU:
26556 + err = au_rdu(file, &rdu);
26557 + if (unlikely(err))
26560 + rdu.ent.ul = ptr_to_compat(rdu.ent.e);
26561 + rdu.tail.ul = ptr_to_compat(rdu.tail.e);
26562 + e = copy_to_user(p, &rdu, sizeof(rdu));
26563 + if (unlikely(e)) {
26568 + case AUFS_CTL_RDU_INO:
26569 + err = au_rdu_ino(file, &rdu);
26573 + /* err = -ENOTTY; */
26582 diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h
26583 --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100
26584 +++ linux/fs/aufs/rwsem.h 2016-10-09 16:55:36.496035060 +0200
26587 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26589 + * This program, aufs is free software; you can redistribute it and/or modify
26590 + * it under the terms of the GNU General Public License as published by
26591 + * the Free Software Foundation; either version 2 of the License, or
26592 + * (at your option) any later version.
26594 + * This program is distributed in the hope that it will be useful,
26595 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26596 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26597 + * GNU General Public License for more details.
26599 + * You should have received a copy of the GNU General Public License
26600 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26604 + * simple read-write semaphore wrappers
26607 +#ifndef __AUFS_RWSEM_H__
26608 +#define __AUFS_RWSEM_H__
26612 +#include "debug.h"
26615 + struct rw_semaphore rwsem;
26616 +#ifdef CONFIG_AUFS_DEBUG
26617 + /* just for debugging, not almighty counter */
26618 + atomic_t rcnt, wcnt;
26622 +#ifdef CONFIG_LOCKDEP
26623 +#define au_lockdep_set_name(rw) \
26624 + lockdep_set_class_and_name(&(rw)->rwsem, \
26625 + /*original key*/(rw)->rwsem.dep_map.key, \
26628 +#define au_lockdep_set_name(rw) do {} while (0)
26631 +#ifdef CONFIG_AUFS_DEBUG
26632 +#define AuDbgCntInit(rw) do { \
26633 + atomic_set(&(rw)->rcnt, 0); \
26634 + atomic_set(&(rw)->wcnt, 0); \
26635 + smp_mb(); /* atomic set */ \
26638 +#define AuDbgCnt(rw, cnt) atomic_read(&(rw)->cnt)
26639 +#define AuDbgCntInc(rw, cnt) atomic_inc(&(rw)->cnt)
26640 +#define AuDbgCntDec(rw, cnt) WARN_ON(atomic_dec_return(&(rw)->cnt) < 0)
26641 +#define AuDbgRcntInc(rw) AuDbgCntInc(rw, rcnt)
26642 +#define AuDbgRcntDec(rw) AuDbgCntDec(rw, rcnt)
26643 +#define AuDbgWcntInc(rw) AuDbgCntInc(rw, wcnt)
26644 +#define AuDbgWcntDec(rw) AuDbgCntDec(rw, wcnt)
26646 +#define AuDbgCnt(rw, cnt) 0
26647 +#define AuDbgCntInit(rw) do {} while (0)
26648 +#define AuDbgRcntInc(rw) do {} while (0)
26649 +#define AuDbgRcntDec(rw) do {} while (0)
26650 +#define AuDbgWcntInc(rw) do {} while (0)
26651 +#define AuDbgWcntDec(rw) do {} while (0)
26652 +#endif /* CONFIG_AUFS_DEBUG */
26654 +/* to debug easier, do not make them inlined functions */
26655 +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(&(rw)->rwsem))
26656 +/* rwsem_is_locked() is unusable */
26657 +#define AuRwMustReadLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0)
26658 +#define AuRwMustWriteLock(rw) AuDebugOn(AuDbgCnt(rw, wcnt) <= 0)
26659 +#define AuRwMustAnyLock(rw) AuDebugOn(AuDbgCnt(rw, rcnt) <= 0 \
26660 + && AuDbgCnt(rw, wcnt) <= 0)
26661 +#define AuRwDestroy(rw) AuDebugOn(AuDbgCnt(rw, rcnt) \
26662 + || AuDbgCnt(rw, wcnt))
26664 +#define au_rw_init(rw) do { \
26665 + AuDbgCntInit(rw); \
26666 + init_rwsem(&(rw)->rwsem); \
26667 + au_lockdep_set_name(rw); \
26670 +#define au_rw_init_wlock(rw) do { \
26671 + au_rw_init(rw); \
26672 + down_write(&(rw)->rwsem); \
26673 + AuDbgWcntInc(rw); \
26676 +#define au_rw_init_wlock_nested(rw, lsc) do { \
26677 + au_rw_init(rw); \
26678 + down_write_nested(&(rw)->rwsem, lsc); \
26679 + AuDbgWcntInc(rw); \
26682 +static inline void au_rw_read_lock(struct au_rwsem *rw)
26684 + down_read(&rw->rwsem);
26685 + AuDbgRcntInc(rw);
26688 +static inline void au_rw_read_lock_nested(struct au_rwsem *rw, unsigned int lsc)
26690 + down_read_nested(&rw->rwsem, lsc);
26691 + AuDbgRcntInc(rw);
26694 +static inline void au_rw_read_unlock(struct au_rwsem *rw)
26696 + AuRwMustReadLock(rw);
26697 + AuDbgRcntDec(rw);
26698 + up_read(&rw->rwsem);
26701 +static inline void au_rw_dgrade_lock(struct au_rwsem *rw)
26703 + AuRwMustWriteLock(rw);
26704 + AuDbgRcntInc(rw);
26705 + AuDbgWcntDec(rw);
26706 + downgrade_write(&rw->rwsem);
26709 +static inline void au_rw_write_lock(struct au_rwsem *rw)
26711 + down_write(&rw->rwsem);
26712 + AuDbgWcntInc(rw);
26715 +static inline void au_rw_write_lock_nested(struct au_rwsem *rw,
26716 + unsigned int lsc)
26718 + down_write_nested(&rw->rwsem, lsc);
26719 + AuDbgWcntInc(rw);
26722 +static inline void au_rw_write_unlock(struct au_rwsem *rw)
26724 + AuRwMustWriteLock(rw);
26725 + AuDbgWcntDec(rw);
26726 + up_write(&rw->rwsem);
26729 +/* why is not _nested version defined */
26730 +static inline int au_rw_read_trylock(struct au_rwsem *rw)
26734 + ret = down_read_trylock(&rw->rwsem);
26736 + AuDbgRcntInc(rw);
26740 +static inline int au_rw_write_trylock(struct au_rwsem *rw)
26744 + ret = down_write_trylock(&rw->rwsem);
26746 + AuDbgWcntInc(rw);
26750 +#undef AuDbgCntDec
26751 +#undef AuDbgRcntInc
26752 +#undef AuDbgRcntDec
26753 +#undef AuDbgWcntDec
26755 +#define AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26756 +static inline void prefix##_read_lock(param) \
26757 +{ au_rw_read_lock(rwsem); } \
26758 +static inline void prefix##_write_lock(param) \
26759 +{ au_rw_write_lock(rwsem); } \
26760 +static inline int prefix##_read_trylock(param) \
26761 +{ return au_rw_read_trylock(rwsem); } \
26762 +static inline int prefix##_write_trylock(param) \
26763 +{ return au_rw_write_trylock(rwsem); }
26764 +/* why is not _nested version defined */
26765 +/* static inline void prefix##_read_trylock_nested(param, lsc)
26766 +{ au_rw_read_trylock_nested(rwsem, lsc)); }
26767 +static inline void prefix##_write_trylock_nestd(param, lsc)
26768 +{ au_rw_write_trylock_nested(rwsem, lsc); } */
26770 +#define AuSimpleUnlockRwsemFuncs(prefix, param, rwsem) \
26771 +static inline void prefix##_read_unlock(param) \
26772 +{ au_rw_read_unlock(rwsem); } \
26773 +static inline void prefix##_write_unlock(param) \
26774 +{ au_rw_write_unlock(rwsem); } \
26775 +static inline void prefix##_downgrade_lock(param) \
26776 +{ au_rw_dgrade_lock(rwsem); }
26778 +#define AuSimpleRwsemFuncs(prefix, param, rwsem) \
26779 + AuSimpleLockRwsemFuncs(prefix, param, rwsem) \
26780 + AuSimpleUnlockRwsemFuncs(prefix, param, rwsem)
26782 +#endif /* __KERNEL__ */
26783 +#endif /* __AUFS_RWSEM_H__ */
26784 diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c
26785 --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100
26786 +++ linux/fs/aufs/sbinfo.c 2016-10-09 16:55:38.889431135 +0200
26789 + * Copyright (C) 2005-2016 Junjiro R. Okajima
26791 + * This program, aufs is free software; you can redistribute it and/or modify
26792 + * it under the terms of the GNU General Public License as published by
26793 + * the Free Software Foundation; either version 2 of the License, or
26794 + * (at your option) any later version.
26796 + * This program is distributed in the hope that it will be useful,
26797 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
26798 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26799 + * GNU General Public License for more details.
26801 + * You should have received a copy of the GNU General Public License
26802 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
26806 + * superblock private data
26812 + * they are necessary regardless sysfs is disabled.
26814 +void au_si_free(struct kobject *kobj)
26817 + struct au_sbinfo *sbinfo;
26818 + char *locked __maybe_unused; /* debug only */
26820 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
26821 + for (i = 0; i < AuPlink_NHASH; i++)
26822 + AuDebugOn(!hlist_empty(&sbinfo->si_plink[i].head));
26823 + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len));
26825 + AuDebugOn(percpu_counter_sum(&sbinfo->si_ninodes));
26826 + percpu_counter_destroy(&sbinfo->si_ninodes);
26827 + AuDebugOn(percpu_counter_sum(&sbinfo->si_nfiles));
26828 + percpu_counter_destroy(&sbinfo->si_nfiles);
26830 + au_rw_write_lock(&sbinfo->si_rwsem);
26831 + au_br_free(sbinfo);
26832 + au_rw_write_unlock(&sbinfo->si_rwsem);
26834 + au_delayed_kfree(sbinfo->si_branch);
26835 + for (i = 0; i < AU_NPIDMAP; i++)
26836 + if (sbinfo->au_si_pid.pid_bitmap[i])
26837 + au_delayed_kfree(sbinfo->au_si_pid.pid_bitmap[i]);
26838 + mutex_destroy(&sbinfo->au_si_pid.pid_mtx);
26839 + mutex_destroy(&sbinfo->si_xib_mtx);
26840 + AuRwDestroy(&sbinfo->si_rwsem);
26842 + au_delayed_kfree(sbinfo);
26845 +int au_si_alloc(struct super_block *sb)
26848 + struct au_sbinfo *sbinfo;
26851 + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS);
26852 + if (unlikely(!sbinfo))
26855 + /* will be reallocated separately */
26856 + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS);
26857 + if (unlikely(!sbinfo->si_branch))
26860 + err = sysaufs_si_init(sbinfo);
26861 + if (unlikely(err))
26864 + au_nwt_init(&sbinfo->si_nowait);
26865 + au_rw_init_wlock(&sbinfo->si_rwsem);
26866 + mutex_init(&sbinfo->au_si_pid.pid_mtx);
26868 + percpu_counter_init(&sbinfo->si_ninodes, 0, GFP_NOFS);
26869 + percpu_counter_init(&sbinfo->si_nfiles, 0, GFP_NOFS);
26871 + sbinfo->si_bbot = -1;
26872 + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2;
26874 + sbinfo->si_wbr_copyup = AuWbrCopyup_Def;
26875 + sbinfo->si_wbr_create = AuWbrCreate_Def;
26876 + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup;
26877 + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create;
26879 + au_fhsm_init(sbinfo);
26881 + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def);
26883 + sbinfo->si_xino_jiffy = jiffies;
26884 + sbinfo->si_xino_expire
26885 + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC);
26886 + mutex_init(&sbinfo->si_xib_mtx);
26887 + sbinfo->si_xino_brid = -1;
26888 + /* leave si_xib_last_pindex and si_xib_next_bit */
26890 + au_sphl_init(&sbinfo->si_aopen);
26892 + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC);
26893 + sbinfo->si_rdblk = AUFS_RDBLK_DEF;
26894 + sbinfo->si_rdhash = AUFS_RDHASH_DEF;
26895 + sbinfo->si_dirwh = AUFS_DIRWH_DEF;
26897 + for (i = 0; i < AuPlink_NHASH; i++)
26898 + au_sphl_init(sbinfo->si_plink + i);
26899 + init_waitqueue_head(&sbinfo->si_plink_wq);
26900 + spin_lock_init(&sbinfo->si_plink_maint_lock);
26902 + au_sphl_init(&sbinfo->si_files);
26904 + /* with getattr by default */
26905 + sbinfo->si_iop_array = aufs_iop;
26907 + /* leave other members for sysaufs and si_mnt. */
26908 + sbinfo->si_sb = sb;
26909 + sb->s_fs_info = sbinfo;
26911 + return 0; /* success */
26914 + au_delayed_kfree(sbinfo->si_branch);
26916 + au_delayed_kfree(sbinfo);
26921 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink)
26924 + struct au_branch **brp;
26926 + AuRwMustWriteLock(&sbinfo->si_rwsem);
26929 + sz = sizeof(*brp) * (sbinfo->si_bbot + 1);
26930 + if (unlikely(!sz))
26931 + sz = sizeof(*brp);
26932 + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS,
26935 + sbinfo->si_branch = brp;
26942 +/* ---------------------------------------------------------------------- */
26944 +unsigned int au_sigen_inc(struct super_block *sb)
26946 + unsigned int gen;
26947 + struct inode *inode;
26949 + SiMustWriteLock(sb);
26951 + gen = ++au_sbi(sb)->si_generation;
26952 + au_update_digen(sb->s_root);
26953 + inode = d_inode(sb->s_root);
26954 + au_update_iigen(inode, /*half*/0);
26955 + inode->i_version++;
26959 +aufs_bindex_t au_new_br_id(struct super_block *sb)
26961 + aufs_bindex_t br_id;
26963 + struct au_sbinfo *sbinfo;
26965 + SiMustWriteLock(sb);
26967 + sbinfo = au_sbi(sb);
26968 + for (i = 0; i <= AUFS_BRANCH_MAX; i++) {
26969 + br_id = ++sbinfo->si_last_br_id;
26970 + AuDebugOn(br_id < 0);
26971 + if (br_id && au_br_index(sb, br_id) < 0)
26978 +/* ---------------------------------------------------------------------- */
26980 +/* it is ok that new 'nwt' tasks are appended while we are sleeping */
26981 +int si_read_lock(struct super_block *sb, int flags)
26986 + if (au_ftest_lock(flags, FLUSH))
26987 + au_nwt_flush(&au_sbi(sb)->si_nowait);
26989 + si_noflush_read_lock(sb);
26990 + err = au_plink_maint(sb, flags);
26991 + if (unlikely(err))
26992 + si_read_unlock(sb);
26997 +int si_write_lock(struct super_block *sb, int flags)
27001 + if (au_ftest_lock(flags, FLUSH))
27002 + au_nwt_flush(&au_sbi(sb)->si_nowait);
27004 + si_noflush_write_lock(sb);
27005 + err = au_plink_maint(sb, flags);
27006 + if (unlikely(err))
27007 + si_write_unlock(sb);
27012 +/* dentry and super_block lock. call at entry point */
27013 +int aufs_read_lock(struct dentry *dentry, int flags)
27016 + struct super_block *sb;
27018 + sb = dentry->d_sb;
27019 + err = si_read_lock(sb, flags);
27020 + if (unlikely(err))
27023 + if (au_ftest_lock(flags, DW))
27024 + di_write_lock_child(dentry);
27026 + di_read_lock_child(dentry, flags);
27028 + if (au_ftest_lock(flags, GEN)) {
27029 + err = au_digen_test(dentry, au_sigen(sb));
27030 + if (!au_opt_test(au_mntflags(sb), UDBA_NONE))
27031 + AuDebugOn(!err && au_dbrange_test(dentry));
27033 + err = au_dbrange_test(dentry);
27034 + if (unlikely(err))
27035 + aufs_read_unlock(dentry, flags);
27042 +void aufs_read_unlock(struct dentry *dentry, int flags)
27044 + if (au_ftest_lock(flags, DW))
27045 + di_write_unlock(dentry);
27047 + di_read_unlock(dentry, flags);
27048 + si_read_unlock(dentry->d_sb);
27051 +void aufs_write_lock(struct dentry *dentry)
27053 + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW);
27054 + di_write_lock_child(dentry);
27057 +void aufs_write_unlock(struct dentry *dentry)
27059 + di_write_unlock(dentry);
27060 + si_write_unlock(dentry->d_sb);
27063 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags)
27066 + unsigned int sigen;
27067 + struct super_block *sb;
27070 + err = si_read_lock(sb, flags);
27071 + if (unlikely(err))
27074 + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS));
27076 + if (au_ftest_lock(flags, GEN)) {
27077 + sigen = au_sigen(sb);
27078 + err = au_digen_test(d1, sigen);
27079 + AuDebugOn(!err && au_dbrange_test(d1));
27081 + err = au_digen_test(d2, sigen);
27082 + AuDebugOn(!err && au_dbrange_test(d2));
27084 + if (unlikely(err))
27085 + aufs_read_and_write_unlock2(d1, d2);
27092 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2)
27094 + di_write_unlock2(d1, d2);
27095 + si_read_unlock(d1->d_sb);
27098 +/* ---------------------------------------------------------------------- */
27100 +static void si_pid_alloc(struct au_si_pid *au_si_pid, int idx)
27102 + unsigned long *p;
27104 + BUILD_BUG_ON(sizeof(unsigned long) !=
27105 + sizeof(*au_si_pid->pid_bitmap));
27107 + mutex_lock(&au_si_pid->pid_mtx);
27108 + p = au_si_pid->pid_bitmap[idx];
27112 + * but keeping 'si_pid_set()' void is more important.
27114 + p = kcalloc(BITS_TO_LONGS(AU_PIDSTEP),
27115 + sizeof(*au_si_pid->pid_bitmap),
27121 + au_si_pid->pid_bitmap[idx] = p;
27122 + mutex_unlock(&au_si_pid->pid_mtx);
27125 +void si_pid_set(struct super_block *sb)
27129 + unsigned long *bitmap;
27130 + struct au_si_pid *au_si_pid;
27132 + si_pid_idx_bit(&idx, &bit);
27133 + au_si_pid = &au_sbi(sb)->au_si_pid;
27134 + bitmap = au_si_pid->pid_bitmap[idx];
27136 + si_pid_alloc(au_si_pid, idx);
27137 + bitmap = au_si_pid->pid_bitmap[idx];
27139 + AuDebugOn(test_bit(bit, bitmap));
27140 + set_bit(bit, bitmap);
27143 diff -urN /usr/share/empty/fs/aufs/spl.h linux/fs/aufs/spl.h
27144 --- /usr/share/empty/fs/aufs/spl.h 1970-01-01 01:00:00.000000000 +0100
27145 +++ linux/fs/aufs/spl.h 2016-10-09 16:55:36.496035060 +0200
27148 + * Copyright (C) 2005-2016 Junjiro R. Okajima
27150 + * This program, aufs is free software; you can redistribute it and/or modify
27151 + * it under the terms of the GNU General Public License as published by
27152 + * the Free Software Foundation; either version 2 of the License, or
27153 + * (at your option) any later version.
27155 + * This program is distributed in the hope that it will be useful,
27156 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27157 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27158 + * GNU General Public License for more details.
27160 + * You should have received a copy of the GNU General Public License
27161 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27165 + * simple list protected by a spinlock
27168 +#ifndef __AUFS_SPL_H__
27169 +#define __AUFS_SPL_H__
27174 +struct au_splhead {
27176 + struct list_head head;
27179 +static inline void au_spl_init(struct au_splhead *spl)
27181 + spin_lock_init(&spl->spin);
27182 + INIT_LIST_HEAD(&spl->head);
27185 +static inline void au_spl_add(struct list_head *list, struct au_splhead *spl)
27187 + spin_lock(&spl->spin);
27188 + list_add(list, &spl->head);
27189 + spin_unlock(&spl->spin);
27192 +static inline void au_spl_del(struct list_head *list, struct au_splhead *spl)
27194 + spin_lock(&spl->spin);
27196 + spin_unlock(&spl->spin);
27199 +static inline void au_spl_del_rcu(struct list_head *list,
27200 + struct au_splhead *spl)
27202 + spin_lock(&spl->spin);
27203 + list_del_rcu(list);
27204 + spin_unlock(&spl->spin);
27208 +/* ---------------------------------------------------------------------- */
27210 +struct au_sphlhead {
27212 + struct hlist_head head;
27215 +static inline void au_sphl_init(struct au_sphlhead *sphl)
27217 + spin_lock_init(&sphl->spin);
27218 + INIT_HLIST_HEAD(&sphl->head);
27221 +static inline void au_sphl_add(struct hlist_node *hlist,
27222 + struct au_sphlhead *sphl)
27224 + spin_lock(&sphl->spin);
27225 + hlist_add_head(hlist, &sphl->head);
27226 + spin_unlock(&sphl->spin);
27229 +static inline void au_sphl_del(struct hlist_node *hlist,
27230 + struct au_sphlhead *sphl)
27232 + spin_lock(&sphl->spin);
27233 + hlist_del(hlist);
27234 + spin_unlock(&sphl->spin);
27237 +static inline void au_sphl_del_rcu(struct hlist_node *hlist,
27238 + struct au_sphlhead *sphl)
27240 + spin_lock(&sphl->spin);
27241 + hlist_del_rcu(hlist);
27242 + spin_unlock(&sphl->spin);
27245 +static inline unsigned long au_sphl_count(struct au_sphlhead *sphl)
27247 + unsigned long cnt;
27248 + struct hlist_node *pos;
27251 + spin_lock(&sphl->spin);
27252 + hlist_for_each(pos, &sphl->head)
27254 + spin_unlock(&sphl->spin);
27258 +#endif /* __KERNEL__ */
27259 +#endif /* __AUFS_SPL_H__ */
27260 diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c
27261 --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100
27262 +++ linux/fs/aufs/super.c 2016-12-17 12:28:17.598545045 +0100
27265 + * Copyright (C) 2005-2016 Junjiro R. Okajima
27267 + * This program, aufs is free software; you can redistribute it and/or modify
27268 + * it under the terms of the GNU General Public License as published by
27269 + * the Free Software Foundation; either version 2 of the License, or
27270 + * (at your option) any later version.
27272 + * This program is distributed in the hope that it will be useful,
27273 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
27274 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27275 + * GNU General Public License for more details.
27277 + * You should have received a copy of the GNU General Public License
27278 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
27282 + * mount and super_block operations
27285 +#include <linux/mm.h>
27286 +#include <linux/seq_file.h>
27287 +#include <linux/statfs.h>
27288 +#include <linux/vmalloc.h>
27292 + * super_operations
27294 +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused)
27296 + struct au_icntnr *c;
27298 + c = au_cache_alloc_icntnr();
27300 + au_icntnr_init(c);
27301 + c->vfs_inode.i_version = 1; /* sigen(sb); */
27302 + c->iinfo.ii_hinode = NULL;
27303 + return &c->vfs_inode;
27308 +static void aufs_destroy_inode_cb(struct rcu_head *head)
27310 + struct inode *inode = container_of(head, struct inode, i_rcu);
27312 + au_cache_dfree_icntnr(container_of(inode, struct au_icntnr, vfs_inode));
27315 +static void aufs_destroy_inode(struct inode *inode)
27317 + if (!au_is_bad_inode(inode))
27318 + au_iinfo_fin(inode);
27319 + call_rcu(&inode->i_rcu, aufs_destroy_inode_cb);
27322 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino)
27324 + struct inode *inode;
27327 + inode = iget_locked(sb, ino);
27328 + if (unlikely(!inode)) {
27329 + inode = ERR_PTR(-ENOMEM);
27332 + if (!(inode->i_state & I_NEW))
27335 + err = au_xigen_new(inode);
27337 + err = au_iinfo_init(inode);
27339 + inode->i_version++;
27341 + iget_failed(inode);
27342 + inode = ERR_PTR(err);
27346 + /* never return NULL */
27347 + AuDebugOn(!inode);
27348 + AuTraceErrPtr(inode);
27352 +/* lock free root dinfo */
27353 +static int au_show_brs(struct seq_file *seq, struct super_block *sb)
27356 + aufs_bindex_t bindex, bbot;
27357 + struct path path;
27358 + struct au_hdentry *hdp;
27359 + struct au_branch *br;
27360 + au_br_perm_str_t perm;
27363 + bbot = au_sbbot(sb);
27365 + hdp = au_hdentry(au_di(sb->s_root), bindex);
27366 + for (; !err && bindex <= bbot; bindex++, hdp++) {
27367 + br = au_sbr(sb, bindex);
27368 + path.mnt = au_br_mnt(br);
27369 + path.dentry = hdp->hd_dentry;
27370 + err = au_seq_path(seq, &path);
27372 + au_optstr_br_perm(&perm, br->br_perm);
27373 + seq_printf(seq, "=%s", perm.a);
27374 + if (bindex != bbot)
27375 + seq_putc(seq, ':');
27378 + if (unlikely(err || seq_has_overflowed(seq)))
27384 +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat,
27385 + const char *append)
27390 + while (*pat != ':')
27393 + strcpy(p, append);
27394 + AuDebugOn(strlen(fmt) >= len);
27397 +static void au_show_wbr_create(struct seq_file *m, int v,
27398 + struct au_sbinfo *sbinfo)
27402 + struct au_wbr_mfs *mfs;
27404 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27406 + seq_puts(m, ",create=");
27407 + pat = au_optstr_wbr_create(v);
27408 + mfs = &sbinfo->si_wbr_mfs;
27410 + case AuWbrCreate_TDP:
27411 + case AuWbrCreate_RR:
27412 + case AuWbrCreate_MFS:
27413 + case AuWbrCreate_PMFS:
27414 + seq_puts(m, pat);
27416 + case AuWbrCreate_MFSRR:
27417 + case AuWbrCreate_TDMFS:
27418 + case AuWbrCreate_PMFSRR:
27419 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu");
27420 + seq_printf(m, fmt, mfs->mfsrr_watermark);
27422 + case AuWbrCreate_MFSV:
27423 + case AuWbrCreate_PMFSV:
27424 + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu");
27425 + seq_printf(m, fmt,
27426 + jiffies_to_msecs(mfs->mfs_expire)
27429 + case AuWbrCreate_MFSRRV:
27430 + case AuWbrCreate_TDMFSV:
27431 + case AuWbrCreate_PMFSRRV:
27432 + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu");
27433 + seq_printf(m, fmt, mfs->mfsrr_watermark,
27434 + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC);
27441 +static int au_show_xino(struct seq_file *seq, struct super_block *sb)
27443 +#ifdef CONFIG_SYSFS
27447 + const int len = sizeof(AUFS_XINO_FNAME) - 1;
27448 + aufs_bindex_t bindex, brid;
27449 + struct qstr *name;
27451 + struct dentry *d, *h_root;
27453 + AuRwMustAnyLock(&sbinfo->si_rwsem);
27456 + f = au_sbi(sb)->si_xib;
27460 + /* stop printing the default xino path on the first writable branch */
27462 + brid = au_xino_brid(sb);
27464 + bindex = au_br_index(sb, brid);
27465 + h_root = au_hdentry(au_di(sb->s_root), bindex)->hd_dentry;
27467 + d = f->f_path.dentry;
27468 + name = &d->d_name;
27469 + /* safe ->d_parent because the file is unlinked */
27470 + if (d->d_parent == h_root
27471 + && name->len == len
27472 + && !memcmp(name->name, AUFS_XINO_FNAME, len))
27475 + seq_puts(seq, ",xino=");
27476 + err = au_xino_path(seq, f);
27483 +/* seq_file will re-call me in case of too long string */
27484 +static int aufs_show_options(struct seq_file *m, struct dentry *dentry)
27487 + unsigned int mnt_flags, v;
27488 + struct super_block *sb;
27489 + struct au_sbinfo *sbinfo;
27491 +#define AuBool(name, str) do { \
27492 + v = au_opt_test(mnt_flags, name); \
27493 + if (v != au_opt_test(AuOpt_Def, name)) \
27494 + seq_printf(m, ",%s" #str, v ? "" : "no"); \
27497 +#define AuStr(name, str) do { \
27498 + v = mnt_flags & AuOptMask_##name; \
27499 + if (v != (AuOpt_Def & AuOptMask_##name)) \
27500 + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \
27503 +#define AuUInt(name, str, val) do { \
27504 + if (val != AUFS_##name##_DEF) \
27505 + seq_printf(m, "," #str "=%u", val); \
27508 + sb = dentry->d_sb;
27509 + if (sb->s_flags & MS_POSIXACL)
27510 + seq_puts(m, ",acl");
27512 + /* lock free root dinfo */
27513 + si_noflush_read_lock(sb);
27514 + sbinfo = au_sbi(sb);
27515 + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo));
27517 + mnt_flags = au_mntflags(sb);
27518 + if (au_opt_test(mnt_flags, XINO)) {
27519 + err = au_show_xino(m, sb);
27520 + if (unlikely(err))
27523 + seq_puts(m, ",noxino");
27525 + AuBool(TRUNC_XINO, trunc_xino);
27526 + AuStr(UDBA, udba);
27527 + AuBool(SHWH, shwh);
27528 + AuBool(PLINK, plink);
27529 + AuBool(DIO, dio);
27530 + AuBool(DIRPERM1, dirperm1);
27532 + v = sbinfo->si_wbr_create;
27533 + if (v != AuWbrCreate_Def)
27534 + au_show_wbr_create(m, v, sbinfo);
27536 + v = sbinfo->si_wbr_copyup;
27537 + if (v != AuWbrCopyup_Def)
27538 + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v));
27540 + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ);
27541 + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ))
27542 + seq_printf(m, ",diropq=%c", v ? 'a' : 'w');
27544 + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh);
27546 + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC;
27547 + AuUInt(RDCACHE, rdcache, v);
27549 + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk);
27550 + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash);
27552 + au_fhsm_show(m, sbinfo);
27554 + AuBool(SUM, sum);
27555 + /* AuBool(SUM_W, wsum); */
27556 + AuBool(WARN_PERM, warn_perm);
27557 + AuBool(VERBOSE, verbose);
27560 + /* be sure to print "br:" last */
27561 + if (!sysaufs_brs) {
27562 + seq_puts(m, ",br:");
27563 + au_show_brs(m, sb);
27565 + si_read_unlock(sb);
27573 +/* ---------------------------------------------------------------------- */
27575 +/* sum mode which returns the summation for statfs(2) */
27577 +static u64 au_add_till_max(u64 a, u64 b)
27585 + return ULLONG_MAX;
27588 +static u64 au_mul_till_max(u64 a, long mul)
27596 + return ULLONG_MAX;
27599 +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf)
27602 + long bsize, factor;
27603 + u64 blocks, bfree, bavail, files, ffree;
27604 + aufs_bindex_t bbot, bindex, i;
27605 + unsigned char shared;
27606 + struct path h_path;
27607 + struct super_block *h_sb;
27610 + bsize = LONG_MAX;
27616 + bbot = au_sbbot(sb);
27617 + for (bindex = 0; bindex <= bbot; bindex++) {
27618 + h_path.mnt = au_sbr_mnt(sb, bindex);
27619 + h_sb = h_path.mnt->mnt_sb;
27621 + for (i = 0; !shared && i < bindex; i++)
27622 + shared = (au_sbr_sb(sb, i) == h_sb);
27626 + /* sb->s_root for NFS is unreliable */
27627 + h_path.dentry = h_path.mnt->mnt_root;
27628 + err = vfs_statfs(&h_path, buf);
27629 + if (unlikely(err))
27632 + if (bsize > buf->f_bsize) {
27634 + * we will reduce bsize, so we have to expand blocks
27635 + * etc. to match them again
27637 + factor = (bsize / buf->f_bsize);
27638 + blocks = au_mul_till_max(blocks, factor);
27639 + bfree = au_mul_till_max(bfree, factor);
27640 + bavail = au_mul_till_max(bavail, factor);
27641 + bsize = buf->f_bsize;
27644 + factor = (buf->f_bsize / bsize);
27645 + blocks = au_add_till_max(blocks,
27646 + au_mul_till_max(buf->f_blocks, factor));
27647 + bfree = au_add_till_max(bfree,
27648 + au_mul_till_max(buf->f_bfree, factor));
27649 + bavail = au_add_till_max(bavail,
27650 + au_mul_till_max(buf->f_bavail, factor));
27651 + files = au_add_till_max(files, buf->f_files);
27652 + ffree = au_add_till_max(ffree, buf->f_ffree);
27655 + buf->f_bsize = bsize;
27656 + buf->f_blocks = blocks;
27657 + buf->f_bfree = bfree;
27658 + buf->f_bavail = bavail;
27659 + buf->f_files = files;
27660 + buf->f_ffree = ffree;
27661 + buf->f_frsize = 0;
27667 +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf)
27670 + struct path h_path;
27671 + struct super_block *sb;
27673 + /* lock free root dinfo */
27674 + sb = dentry->d_sb;
27675 + si_noflush_read_lock(sb);
27676 + if (!au_opt_test(au_mntflags(sb), SUM)) {
27677 + /* sb->s_root for NFS is unreliable */
27678 + h_path.mnt = au_sbr_mnt(sb, 0);
27679 + h_path.dentry = h_path.mnt->mnt_root;
27680 + err = vfs_statfs(&h_path, buf);
27682 + err = au_statfs_sum(sb, buf);
27683 + si_read_unlock(sb);
27686 + buf->f_type = AUFS_SUPER_MAGIC;
27687 + buf->f_namelen = AUFS_MAX_NAMELEN;
27688 + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid));
27690 + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */
27695 +/* ---------------------------------------------------------------------- */
27697 +static int aufs_sync_fs(struct super_block *sb, int wait)
27700 + aufs_bindex_t bbot, bindex;
27701 + struct au_branch *br;
27702 + struct super_block *h_sb;
27705 + si_noflush_read_lock(sb);
27706 + bbot = au_sbbot(sb);
27707 + for (bindex = 0; bindex <= bbot; bindex++) {
27708 + br = au_sbr(sb, bindex);
27709 + if (!au_br_writable(br->br_perm))
27712 + h_sb = au_sbr_sb(sb, bindex);
27713 + if (h_sb->s_op->sync_fs) {
27714 + e = h_sb->s_op->sync_fs(h_sb, wait);
27715 + if (unlikely(e && !err))
27717 + /* go on even if an error happens */
27720 + si_read_unlock(sb);
27725 +/* ---------------------------------------------------------------------- */
27727 +/* final actions when unmounting a file system */
27728 +static void aufs_put_super(struct super_block *sb)
27730 + struct au_sbinfo *sbinfo;
27732 + sbinfo = au_sbi(sb);
27736 + dbgaufs_si_fin(sbinfo);
27737 + kobject_put(&sbinfo->si_kobj);
27740 +/* ---------------------------------------------------------------------- */
27742 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
27743 + struct super_block *sb, void *arg)
27746 + unsigned long long n, sz;
27753 + if (*hint > ULLONG_MAX / sizeof(array)) {
27754 + array = ERR_PTR(-EMFILE);
27755 + pr_err("hint %llu\n", *hint);
27759 + sz = sizeof(array) * *hint;
27760 + array = kzalloc(sz, GFP_NOFS);
27761 + if (unlikely(!array))
27762 + array = vzalloc(sz);
27763 + if (unlikely(!array)) {
27764 + array = ERR_PTR(-ENOMEM);
27768 + n = cb(sb, array, *hint, arg);
27769 + AuDebugOn(n > *hint);
27776 +static unsigned long long au_iarray_cb(struct super_block *sb, void *a,
27777 + unsigned long long max __maybe_unused,
27780 + unsigned long long n;
27781 + struct inode **p, *inode;
27782 + struct list_head *head;
27787 + spin_lock(&sb->s_inode_list_lock);
27788 + list_for_each_entry(inode, head, i_sb_list) {
27789 + if (!au_is_bad_inode(inode)
27790 + && au_ii(inode)->ii_btop >= 0) {
27791 + spin_lock(&inode->i_lock);
27792 + if (atomic_read(&inode->i_count)) {
27796 + AuDebugOn(n > max);
27798 + spin_unlock(&inode->i_lock);
27801 + spin_unlock(&sb->s_inode_list_lock);
27806 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max)
27808 + *max = au_ninodes(sb);
27809 + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes);
27812 +void au_iarray_free(struct inode **a, unsigned long long max)
27814 + unsigned long long ull;
27816 + for (ull = 0; ull < max; ull++)
27821 +/* ---------------------------------------------------------------------- */
27824 + * refresh dentry and inode at remount time.
27826 +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */
27827 +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags,
27828 + struct dentry *parent)
27832 + di_write_lock_child(dentry);
27833 + di_read_lock_parent(parent, AuLock_IR);
27834 + err = au_refresh_dentry(dentry, parent);
27835 + if (!err && dir_flags)
27836 + au_hn_reset(d_inode(dentry), dir_flags);
27837 + di_read_unlock(parent, AuLock_IR);
27838 + di_write_unlock(dentry);
27843 +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen,
27844 + struct au_sbinfo *sbinfo,
27845 + const unsigned int dir_flags, unsigned int do_idop)
27848 + struct dentry *parent;
27851 + parent = dget_parent(dentry);
27852 + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) {
27853 + if (d_really_is_positive(dentry)) {
27854 + if (!d_is_dir(dentry))
27855 + err = au_do_refresh(dentry, /*dir_flags*/0,
27858 + err = au_do_refresh(dentry, dir_flags, parent);
27859 + if (unlikely(err))
27860 + au_fset_si(sbinfo, FAILED_REFRESH_DIR);
27863 + err = au_do_refresh(dentry, /*dir_flags*/0, parent);
27864 + AuDbgDentry(dentry);
27870 + au_refresh_dop(dentry, /*force_reval*/0);
27872 + au_refresh_dop(dentry, /*force_reval*/1);
27878 +static int au_refresh_d(struct super_block *sb, unsigned int do_idop)
27880 + int err, i, j, ndentry, e;
27881 + unsigned int sigen;
27882 + struct au_dcsub_pages dpages;
27883 + struct au_dpage *dpage;
27884 + struct dentry **dentries, *d;
27885 + struct au_sbinfo *sbinfo;
27886 + struct dentry *root = sb->s_root;
27887 + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1);
27890 + au_refresh_dop(root, /*force_reval*/0);
27892 + err = au_dpages_init(&dpages, GFP_NOFS);
27893 + if (unlikely(err))
27895 + err = au_dcsub_pages(&dpages, root, NULL, NULL);
27896 + if (unlikely(err))
27899 + sigen = au_sigen(sb);
27900 + sbinfo = au_sbi(sb);
27901 + for (i = 0; i < dpages.ndpage; i++) {
27902 + dpage = dpages.dpages + i;
27903 + dentries = dpage->dentries;
27904 + ndentry = dpage->ndentry;
27905 + for (j = 0; j < ndentry; j++) {
27907 + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags,
27909 + if (unlikely(e && !err))
27911 + /* go on even err */
27916 + au_dpages_free(&dpages);
27921 +static int au_refresh_i(struct super_block *sb, unsigned int do_idop)
27924 + unsigned int sigen;
27925 + unsigned long long max, ull;
27926 + struct inode *inode, **array;
27928 + array = au_iarray_alloc(sb, &max);
27929 + err = PTR_ERR(array);
27930 + if (IS_ERR(array))
27934 + sigen = au_sigen(sb);
27935 + for (ull = 0; ull < max; ull++) {
27936 + inode = array[ull];
27937 + if (unlikely(!inode))
27941 + ii_write_lock_child(inode);
27942 + if (au_iigen(inode, NULL) != sigen) {
27943 + e = au_refresh_hinode_self(inode);
27944 + if (unlikely(e)) {
27945 + au_refresh_iop(inode, /*force_getattr*/1);
27946 + pr_err("error %d, i%lu\n", e, inode->i_ino);
27949 + /* go on even if err */
27952 + if (!e && do_idop)
27953 + au_refresh_iop(inode, /*force_getattr*/0);
27954 + ii_write_unlock(inode);
27957 + au_iarray_free(array, max);
27963 +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop)
27966 + unsigned int udba;
27967 + aufs_bindex_t bindex, bbot;
27968 + struct dentry *root;
27969 + struct inode *inode;
27970 + struct au_branch *br;
27971 + struct au_sbinfo *sbi;
27973 + au_sigen_inc(sb);
27974 + sbi = au_sbi(sb);
27975 + au_fclr_si(sbi, FAILED_REFRESH_DIR);
27977 + root = sb->s_root;
27978 + DiMustNoWaiters(root);
27979 + inode = d_inode(root);
27980 + IiMustNoWaiters(inode);
27982 + udba = au_opt_udba(sb);
27983 + bbot = au_sbbot(sb);
27984 + for (bindex = 0; bindex <= bbot; bindex++) {
27985 + br = au_sbr(sb, bindex);
27986 + err = au_hnotify_reset_br(udba, br, br->br_perm);
27987 + if (unlikely(err))
27988 + AuIOErr("hnotify failed on br %d, %d, ignored\n",
27990 + /* go on even if err */
27992 + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1));
27995 + if (au_ftest_si(sbi, NO_DREVAL)) {
27996 + AuDebugOn(sb->s_d_op == &aufs_dop_noreval);
27997 + sb->s_d_op = &aufs_dop_noreval;
27998 + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr);
27999 + sbi->si_iop_array = aufs_iop_nogetattr;
28001 + AuDebugOn(sb->s_d_op == &aufs_dop);
28002 + sb->s_d_op = &aufs_dop;
28003 + AuDebugOn(sbi->si_iop_array == aufs_iop);
28004 + sbi->si_iop_array = aufs_iop;
28006 + pr_info("reset to %pf and %pf\n",
28007 + sb->s_d_op, sbi->si_iop_array);
28010 + di_write_unlock(root);
28011 + err = au_refresh_d(sb, do_idop);
28012 + e = au_refresh_i(sb, do_idop);
28013 + if (unlikely(e && !err))
28015 + /* aufs_write_lock() calls ..._child() */
28016 + di_write_lock_child(root);
28018 + au_cpup_attr_all(inode, /*force*/1);
28020 + if (unlikely(err))
28021 + AuIOErr("refresh failed, ignored, %d\n", err);
28024 +/* stop extra interpretation of errno in mount(8), and strange error messages */
28025 +static int cvt_err(int err)
28039 +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
28042 + unsigned int mntflags;
28043 + struct au_opts opts = {
28046 + struct dentry *root;
28047 + struct inode *inode;
28048 + struct au_sbinfo *sbinfo;
28051 + root = sb->s_root;
28052 + if (!data || !*data) {
28053 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
28055 + di_write_lock_child(root);
28056 + err = au_opts_verify(sb, *flags, /*pending*/0);
28057 + aufs_write_unlock(root);
28063 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28064 + if (unlikely(!opts.opt))
28066 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28067 + opts.flags = AuOpts_REMOUNT;
28068 + opts.sb_flags = *flags;
28070 + /* parse it before aufs lock */
28071 + err = au_opts_parse(sb, data, &opts);
28072 + if (unlikely(err))
28075 + sbinfo = au_sbi(sb);
28076 + inode = d_inode(root);
28077 + inode_lock(inode);
28078 + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
28079 + if (unlikely(err))
28081 + di_write_lock_child(root);
28083 + /* au_opts_remount() may return an error */
28084 + err = au_opts_remount(sb, &opts);
28085 + au_opts_free(&opts);
28087 + if (au_ftest_opts(opts.flags, REFRESH))
28088 + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP));
28090 + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) {
28091 + mntflags = au_mntflags(sb);
28092 + do_dx = !!au_opt_test(mntflags, DIO);
28093 + au_dy_arefresh(do_dx);
28096 + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */
28097 + aufs_write_unlock(root);
28100 + inode_unlock(inode);
28102 + au_delayed_free_page((unsigned long)opts.opt);
28104 + err = cvt_err(err);
28109 +static const struct super_operations aufs_sop = {
28110 + .alloc_inode = aufs_alloc_inode,
28111 + .destroy_inode = aufs_destroy_inode,
28112 + /* always deleting, no clearing */
28113 + .drop_inode = generic_delete_inode,
28114 + .show_options = aufs_show_options,
28115 + .statfs = aufs_statfs,
28116 + .put_super = aufs_put_super,
28117 + .sync_fs = aufs_sync_fs,
28118 + .remount_fs = aufs_remount_fs
28121 +/* ---------------------------------------------------------------------- */
28123 +static int alloc_root(struct super_block *sb)
28126 + struct inode *inode;
28127 + struct dentry *root;
28130 + inode = au_iget_locked(sb, AUFS_ROOT_INO);
28131 + err = PTR_ERR(inode);
28132 + if (IS_ERR(inode))
28135 + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */
28136 + inode->i_fop = &aufs_dir_fop;
28137 + inode->i_mode = S_IFDIR;
28138 + set_nlink(inode, 2);
28139 + unlock_new_inode(inode);
28141 + root = d_make_root(inode);
28142 + if (unlikely(!root))
28144 + err = PTR_ERR(root);
28145 + if (IS_ERR(root))
28148 + err = au_di_init(root);
28150 + sb->s_root = root;
28151 + return 0; /* success */
28159 +static int aufs_fill_super(struct super_block *sb, void *raw_data,
28160 + int silent __maybe_unused)
28163 + struct au_opts opts = {
28166 + struct au_sbinfo *sbinfo;
28167 + struct dentry *root;
28168 + struct inode *inode;
28169 + char *arg = raw_data;
28171 + if (unlikely(!arg || !*arg)) {
28173 + pr_err("no arg\n");
28178 + opts.opt = (void *)__get_free_page(GFP_NOFS);
28179 + if (unlikely(!opts.opt))
28181 + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt);
28182 + opts.sb_flags = sb->s_flags;
28184 + err = au_si_alloc(sb);
28185 + if (unlikely(err))
28187 + sbinfo = au_sbi(sb);
28189 + /* all timestamps always follow the ones on the branch */
28190 + sb->s_flags |= MS_NOATIME | MS_NODIRATIME;
28191 + sb->s_op = &aufs_sop;
28192 + sb->s_d_op = &aufs_dop;
28193 + sb->s_magic = AUFS_SUPER_MAGIC;
28194 + sb->s_maxbytes = 0;
28195 + sb->s_stack_depth = 1;
28196 + au_export_init(sb);
28197 + au_xattr_init(sb);
28199 + err = alloc_root(sb);
28200 + if (unlikely(err)) {
28201 + si_write_unlock(sb);
28204 + root = sb->s_root;
28205 + inode = d_inode(root);
28208 + * actually we can parse options regardless aufs lock here.
28209 + * but at remount time, parsing must be done before aufs lock.
28210 + * so we follow the same rule.
28212 + ii_write_lock_parent(inode);
28213 + aufs_write_unlock(root);
28214 + err = au_opts_parse(sb, arg, &opts);
28215 + if (unlikely(err))
28218 + /* lock vfs_inode first, then aufs. */
28219 + inode_lock(inode);
28220 + aufs_write_lock(root);
28221 + err = au_opts_mount(sb, &opts);
28222 + au_opts_free(&opts);
28223 + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) {
28224 + sb->s_d_op = &aufs_dop_noreval;
28225 + pr_info("%pf\n", sb->s_d_op);
28226 + au_refresh_dop(root, /*force_reval*/0);
28227 + sbinfo->si_iop_array = aufs_iop_nogetattr;
28228 + au_refresh_iop(inode, /*force_getattr*/0);
28230 + aufs_write_unlock(root);
28231 + inode_unlock(inode);
28233 + goto out_opts; /* success */
28237 + sb->s_root = NULL;
28239 + dbgaufs_si_fin(sbinfo);
28240 + kobject_put(&sbinfo->si_kobj);
28241 + sb->s_fs_info = NULL;
28243 + au_delayed_free_page((unsigned long)opts.opt);
28246 + err = cvt_err(err);
28251 +/* ---------------------------------------------------------------------- */
28253 +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags,
28254 + const char *dev_name __maybe_unused,
28257 + struct dentry *root;
28258 + struct super_block *sb;
28260 + /* all timestamps always follow the ones on the branch */
28261 + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */
28262 + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super);
28263 + if (IS_ERR(root))
28267 + si_write_lock(sb, !AuLock_FLUSH);
28268 + sysaufs_brs_add(sb, 0);
28269 + si_write_unlock(sb);
28270 + au_sbilist_add(sb);
28276 +static void aufs_kill_sb(struct super_block *sb)
28278 + struct au_sbinfo *sbinfo;
28280 + sbinfo = au_sbi(sb);
28282 + au_sbilist_del(sb);
28283 + aufs_write_lock(sb->s_root);
28285 + if (sbinfo->si_wbr_create_ops->fin)
28286 + sbinfo->si_wbr_create_ops->fin(sb);
28287 + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) {
28288 + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE);
28289 + au_remount_refresh(sb, /*do_idop*/0);
28291 + if (au_opt_test(sbinfo->si_mntflags, PLINK))
28292 + au_plink_put(sb, /*verbose*/1);
28294 + sbinfo->si_sb = NULL;
28295 + aufs_write_unlock(sb->s_root);
28296 + au_nwt_flush(&sbinfo->si_nowait);
28298 + kill_anon_super(sb);
28301 +struct file_system_type aufs_fs_type = {
28302 + .name = AUFS_FSTYPE,
28303 + /* a race between rename and others */
28304 + .fs_flags = FS_RENAME_DOES_D_MOVE,
28305 + .mount = aufs_mount,
28306 + .kill_sb = aufs_kill_sb,
28307 + /* no need to __module_get() and module_put(). */
28308 + .owner = THIS_MODULE,
28310 diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h
28311 --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100
28312 +++ linux/fs/aufs/super.h 2016-12-17 12:28:17.598545045 +0100
28315 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28317 + * This program, aufs is free software; you can redistribute it and/or modify
28318 + * it under the terms of the GNU General Public License as published by
28319 + * the Free Software Foundation; either version 2 of the License, or
28320 + * (at your option) any later version.
28322 + * This program is distributed in the hope that it will be useful,
28323 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28324 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28325 + * GNU General Public License for more details.
28327 + * You should have received a copy of the GNU General Public License
28328 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28332 + * super_block operations
28335 +#ifndef __AUFS_SUPER_H__
28336 +#define __AUFS_SUPER_H__
28340 +#include <linux/fs.h>
28341 +#include <linux/kobject.h>
28342 +#include "rwsem.h"
28346 +/* policies to select one among multiple writable branches */
28347 +struct au_wbr_copyup_operations {
28348 + int (*copyup)(struct dentry *dentry);
28351 +#define AuWbr_DIR 1 /* target is a dir */
28352 +#define AuWbr_PARENT (1 << 1) /* always require a parent */
28354 +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name)
28355 +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; }
28356 +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; }
28358 +struct au_wbr_create_operations {
28359 + int (*create)(struct dentry *dentry, unsigned int flags);
28360 + int (*init)(struct super_block *sb);
28361 + int (*fin)(struct super_block *sb);
28364 +struct au_wbr_mfs {
28365 + struct mutex mfs_lock; /* protect this structure */
28366 + unsigned long mfs_jiffy;
28367 + unsigned long mfs_expire;
28368 + aufs_bindex_t mfs_bindex;
28370 + unsigned long long mfsrr_bytes;
28371 + unsigned long long mfsrr_watermark;
28374 +#define AuPlink_NHASH 100
28375 +static inline int au_plink_hash(ino_t ino)
28377 + return ino % AuPlink_NHASH;
28380 +/* File-based Hierarchical Storage Management */
28382 +#ifdef CONFIG_AUFS_FHSM
28383 + /* allow only one process who can receive the notification */
28384 + spinlock_t fhsm_spin;
28386 + wait_queue_head_t fhsm_wqh;
28387 + atomic_t fhsm_readable;
28389 + /* these are protected by si_rwsem */
28390 + unsigned long fhsm_expire;
28391 + aufs_bindex_t fhsm_bottom;
28395 +#define AU_PIDSTEP (int)(BITS_TO_LONGS(PID_MAX_DEFAULT) * BITS_PER_LONG)
28396 +#define AU_NPIDMAP (int)DIV_ROUND_UP(PID_MAX_LIMIT, AU_PIDSTEP)
28397 +struct au_si_pid {
28398 + unsigned long *pid_bitmap[AU_NPIDMAP];
28399 + struct mutex pid_mtx;
28403 +struct au_sbinfo {
28404 + /* nowait tasks in the system-wide workqueue */
28405 + struct au_nowait_tasks si_nowait;
28408 + * tried sb->s_umount, but failed due to the dependecy between i_mutex.
28409 + * rwsem for au_sbinfo is necessary.
28411 + struct au_rwsem si_rwsem;
28413 + /* prevent recursive locking in deleting inode */
28414 + struct au_si_pid au_si_pid;
28417 + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from
28420 + struct percpu_counter si_ninodes, si_nfiles;
28422 + /* branch management */
28423 + unsigned int si_generation;
28425 + /* see AuSi_ flags */
28426 + unsigned char au_si_status;
28428 + aufs_bindex_t si_bbot;
28430 + /* dirty trick to keep br_id plus */
28431 + unsigned int si_last_br_id :
28432 + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1;
28433 + struct au_branch **si_branch;
28435 + /* policy to select a writable branch */
28436 + unsigned char si_wbr_copyup;
28437 + unsigned char si_wbr_create;
28438 + struct au_wbr_copyup_operations *si_wbr_copyup_ops;
28439 + struct au_wbr_create_operations *si_wbr_create_ops;
28441 + /* round robin */
28442 + atomic_t si_wbr_rr_next;
28444 + /* most free space */
28445 + struct au_wbr_mfs si_wbr_mfs;
28447 + /* File-based Hierarchical Storage Management */
28448 + struct au_fhsm si_fhsm;
28450 + /* mount flags */
28451 + /* include/asm-ia64/siginfo.h defines a macro named si_flags */
28452 + unsigned int si_mntflags;
28454 + /* external inode number (bitmap and translation table) */
28455 + vfs_readf_t si_xread;
28456 + vfs_writef_t si_xwrite;
28457 + struct file *si_xib;
28458 + struct mutex si_xib_mtx; /* protect xib members */
28459 + unsigned long *si_xib_buf;
28460 + unsigned long si_xib_last_pindex;
28461 + int si_xib_next_bit;
28462 + aufs_bindex_t si_xino_brid;
28463 + unsigned long si_xino_jiffy;
28464 + unsigned long si_xino_expire;
28465 + /* reserved for future use */
28466 + /* unsigned long long si_xib_limit; */ /* Max xib file size */
28468 +#ifdef CONFIG_AUFS_EXPORT
28469 + /* i_generation */
28470 + struct file *si_xigen;
28471 + atomic_t si_xigen_next;
28474 + /* dirty trick to suppoer atomic_open */
28475 + struct au_sphlhead si_aopen;
28477 + /* vdir parameters */
28478 + unsigned long si_rdcache; /* max cache time in jiffies */
28479 + unsigned int si_rdblk; /* deblk size */
28480 + unsigned int si_rdhash; /* hash size */
28483 + * If the number of whiteouts are larger than si_dirwh, leave all of
28484 + * them after au_whtmp_ren to reduce the cost of rmdir(2).
28485 + * future fsck.aufs or kernel thread will remove them later.
28486 + * Otherwise, remove all whiteouts and the dir in rmdir(2).
28488 + unsigned int si_dirwh;
28490 + /* pseudo_link list */
28491 + struct au_sphlhead si_plink[AuPlink_NHASH];
28492 + wait_queue_head_t si_plink_wq;
28493 + spinlock_t si_plink_maint_lock;
28494 + pid_t si_plink_maint_pid;
28497 + struct au_sphlhead si_files;
28499 + /* with/without getattr, brother of sb->s_d_op */
28500 + struct inode_operations *si_iop_array;
28503 + * sysfs and lifetime management.
28504 + * this is not a small structure and it may be a waste of memory in case
28505 + * of sysfs is disabled, particulary when many aufs-es are mounted.
28506 + * but using sysfs is majority.
28508 + struct kobject si_kobj;
28509 +#ifdef CONFIG_DEBUG_FS
28510 + struct dentry *si_dbgaufs;
28511 + struct dentry *si_dbgaufs_plink;
28512 + struct dentry *si_dbgaufs_xib;
28513 +#ifdef CONFIG_AUFS_EXPORT
28514 + struct dentry *si_dbgaufs_xigen;
28518 +#ifdef CONFIG_AUFS_SBILIST
28519 + struct hlist_node si_list;
28522 + /* dirty, necessary for unmounting, sysfs and sysrq */
28523 + struct super_block *si_sb;
28526 +/* sbinfo status flags */
28528 + * set true when refresh_dirs() failed at remount time.
28529 + * then try refreshing dirs at access time again.
28530 + * if it is false, refreshing dirs at access time is unnecesary
28532 +#define AuSi_FAILED_REFRESH_DIR 1
28533 +#define AuSi_FHSM (1 << 1) /* fhsm is active now */
28534 +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */
28536 +#ifndef CONFIG_AUFS_FHSM
28538 +#define AuSi_FHSM 0
28541 +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi,
28542 + unsigned int flag)
28544 + AuRwMustAnyLock(&sbi->si_rwsem);
28545 + return sbi->au_si_status & flag;
28547 +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name)
28548 +#define au_fset_si(sbinfo, name) do { \
28549 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28550 + (sbinfo)->au_si_status |= AuSi_##name; \
28552 +#define au_fclr_si(sbinfo, name) do { \
28553 + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \
28554 + (sbinfo)->au_si_status &= ~AuSi_##name; \
28557 +/* ---------------------------------------------------------------------- */
28559 +/* policy to select one among writable branches */
28560 +#define AuWbrCopyup(sbinfo, ...) \
28561 + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__))
28562 +#define AuWbrCreate(sbinfo, ...) \
28563 + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__))
28565 +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
28566 +#define AuLock_DW 1 /* write-lock dentry */
28567 +#define AuLock_IR (1 << 1) /* read-lock inode */
28568 +#define AuLock_IW (1 << 2) /* write-lock inode */
28569 +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */
28570 +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */
28571 + /* except RENAME_EXCHANGE */
28572 +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */
28573 +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */
28574 +#define AuLock_GEN (1 << 7) /* test digen/iigen */
28575 +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name)
28576 +#define au_fset_lock(flags, name) \
28577 + do { (flags) |= AuLock_##name; } while (0)
28578 +#define au_fclr_lock(flags, name) \
28579 + do { (flags) &= ~AuLock_##name; } while (0)
28581 +/* ---------------------------------------------------------------------- */
28584 +extern struct file_system_type aufs_fs_type;
28585 +struct inode *au_iget_locked(struct super_block *sb, ino_t ino);
28586 +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array,
28587 + unsigned long long max, void *arg);
28588 +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb,
28589 + struct super_block *sb, void *arg);
28590 +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max);
28591 +void au_iarray_free(struct inode **a, unsigned long long max);
28594 +void au_si_free(struct kobject *kobj);
28595 +int au_si_alloc(struct super_block *sb);
28596 +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink);
28598 +unsigned int au_sigen_inc(struct super_block *sb);
28599 +aufs_bindex_t au_new_br_id(struct super_block *sb);
28601 +int si_read_lock(struct super_block *sb, int flags);
28602 +int si_write_lock(struct super_block *sb, int flags);
28603 +int aufs_read_lock(struct dentry *dentry, int flags);
28604 +void aufs_read_unlock(struct dentry *dentry, int flags);
28605 +void aufs_write_lock(struct dentry *dentry);
28606 +void aufs_write_unlock(struct dentry *dentry);
28607 +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags);
28608 +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
28610 +/* wbr_policy.c */
28611 +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
28612 +extern struct au_wbr_create_operations au_wbr_create_ops[];
28613 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst);
28614 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex);
28615 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop);
28618 +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg);
28620 +#ifdef CONFIG_AUFS_FHSM
28623 +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm)
28627 + spin_lock(&fhsm->fhsm_spin);
28628 + pid = fhsm->fhsm_pid;
28629 + spin_unlock(&fhsm->fhsm_spin);
28634 +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force);
28635 +void au_fhsm_wrote_all(struct super_block *sb, int force);
28636 +int au_fhsm_fd(struct super_block *sb, int oflags);
28637 +int au_fhsm_br_alloc(struct au_branch *br);
28638 +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex);
28639 +void au_fhsm_fin(struct super_block *sb);
28640 +void au_fhsm_init(struct au_sbinfo *sbinfo);
28641 +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec);
28642 +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo);
28644 +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex,
28646 +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force)
28647 +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags)
28648 +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm)
28649 +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br)
28650 +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex)
28651 +AuStubVoid(au_fhsm_fin, struct super_block *sb)
28652 +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo)
28653 +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec)
28654 +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo)
28657 +/* ---------------------------------------------------------------------- */
28659 +static inline struct au_sbinfo *au_sbi(struct super_block *sb)
28661 + return sb->s_fs_info;
28664 +/* ---------------------------------------------------------------------- */
28666 +#ifdef CONFIG_AUFS_EXPORT
28667 +int au_test_nfsd(void);
28668 +void au_export_init(struct super_block *sb);
28669 +void au_xigen_inc(struct inode *inode);
28670 +int au_xigen_new(struct inode *inode);
28671 +int au_xigen_set(struct super_block *sb, struct file *base);
28672 +void au_xigen_clr(struct super_block *sb);
28674 +static inline int au_busy_or_stale(void)
28676 + if (!au_test_nfsd())
28681 +AuStubInt0(au_test_nfsd, void)
28682 +AuStubVoid(au_export_init, struct super_block *sb)
28683 +AuStubVoid(au_xigen_inc, struct inode *inode)
28684 +AuStubInt0(au_xigen_new, struct inode *inode)
28685 +AuStubInt0(au_xigen_set, struct super_block *sb, struct file *base)
28686 +AuStubVoid(au_xigen_clr, struct super_block *sb)
28687 +AuStub(int, au_busy_or_stale, return -EBUSY, void)
28688 +#endif /* CONFIG_AUFS_EXPORT */
28690 +/* ---------------------------------------------------------------------- */
28692 +#ifdef CONFIG_AUFS_SBILIST
28694 +extern struct au_sphlhead au_sbilist;
28696 +static inline void au_sbilist_init(void)
28698 + au_sphl_init(&au_sbilist);
28701 +static inline void au_sbilist_add(struct super_block *sb)
28703 + au_sphl_add(&au_sbi(sb)->si_list, &au_sbilist);
28706 +static inline void au_sbilist_del(struct super_block *sb)
28708 + au_sphl_del(&au_sbi(sb)->si_list, &au_sbilist);
28711 +#ifdef CONFIG_AUFS_MAGIC_SYSRQ
28712 +static inline void au_sbilist_lock(void)
28714 + spin_lock(&au_sbilist.spin);
28717 +static inline void au_sbilist_unlock(void)
28719 + spin_unlock(&au_sbilist.spin);
28721 +#define AuGFP_SBILIST GFP_ATOMIC
28723 +AuStubVoid(au_sbilist_lock, void)
28724 +AuStubVoid(au_sbilist_unlock, void)
28725 +#define AuGFP_SBILIST GFP_NOFS
28726 +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */
28728 +AuStubVoid(au_sbilist_init, void)
28729 +AuStubVoid(au_sbilist_add, struct super_block *sb)
28730 +AuStubVoid(au_sbilist_del, struct super_block *sb)
28731 +AuStubVoid(au_sbilist_lock, void)
28732 +AuStubVoid(au_sbilist_unlock, void)
28733 +#define AuGFP_SBILIST GFP_NOFS
28736 +/* ---------------------------------------------------------------------- */
28738 +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo)
28741 + * This function is a dynamic '__init' function actually,
28742 + * so the tiny check for si_rwsem is unnecessary.
28744 + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */
28745 +#ifdef CONFIG_DEBUG_FS
28746 + sbinfo->si_dbgaufs = NULL;
28747 + sbinfo->si_dbgaufs_plink = NULL;
28748 + sbinfo->si_dbgaufs_xib = NULL;
28749 +#ifdef CONFIG_AUFS_EXPORT
28750 + sbinfo->si_dbgaufs_xigen = NULL;
28755 +/* ---------------------------------------------------------------------- */
28757 +static inline void si_pid_idx_bit(int *idx, pid_t *bit)
28759 + /* the origin of pid is 1, but the bitmap's is 0 */
28760 + *bit = current->pid - 1;
28761 + *idx = *bit / AU_PIDSTEP;
28762 + *bit %= AU_PIDSTEP;
28765 +static inline int si_pid_test(struct super_block *sb)
28769 + unsigned long *bitmap;
28771 + si_pid_idx_bit(&idx, &bit);
28772 + bitmap = au_sbi(sb)->au_si_pid.pid_bitmap[idx];
28774 + return test_bit(bit, bitmap);
28778 +static inline void si_pid_clr(struct super_block *sb)
28782 + unsigned long *bitmap;
28784 + si_pid_idx_bit(&idx, &bit);
28785 + bitmap = au_sbi(sb)->au_si_pid.pid_bitmap[idx];
28787 + AuDebugOn(!test_bit(bit, bitmap));
28788 + clear_bit(bit, bitmap);
28792 +void si_pid_set(struct super_block *sb);
28794 +/* ---------------------------------------------------------------------- */
28796 +/* lock superblock. mainly for entry point functions */
28798 + * __si_read_lock, __si_write_lock,
28799 + * __si_read_unlock, __si_write_unlock, __si_downgrade_lock
28801 +AuSimpleRwsemFuncs(__si, struct super_block *sb, &au_sbi(sb)->si_rwsem);
28803 +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem)
28804 +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
28805 +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
28807 +static inline void si_noflush_read_lock(struct super_block *sb)
28809 + __si_read_lock(sb);
28813 +static inline int si_noflush_read_trylock(struct super_block *sb)
28817 + locked = __si_read_trylock(sb);
28823 +static inline void si_noflush_write_lock(struct super_block *sb)
28825 + __si_write_lock(sb);
28829 +static inline int si_noflush_write_trylock(struct super_block *sb)
28833 + locked = __si_write_trylock(sb);
28839 +#if 0 /* reserved */
28840 +static inline int si_read_trylock(struct super_block *sb, int flags)
28842 + if (au_ftest_lock(flags, FLUSH))
28843 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28844 + return si_noflush_read_trylock(sb);
28848 +static inline void si_read_unlock(struct super_block *sb)
28851 + __si_read_unlock(sb);
28854 +#if 0 /* reserved */
28855 +static inline int si_write_trylock(struct super_block *sb, int flags)
28857 + if (au_ftest_lock(flags, FLUSH))
28858 + au_nwt_flush(&au_sbi(sb)->si_nowait);
28859 + return si_noflush_write_trylock(sb);
28863 +static inline void si_write_unlock(struct super_block *sb)
28866 + __si_write_unlock(sb);
28869 +#if 0 /* reserved */
28870 +static inline void si_downgrade_lock(struct super_block *sb)
28872 + __si_downgrade_lock(sb);
28876 +/* ---------------------------------------------------------------------- */
28878 +static inline aufs_bindex_t au_sbbot(struct super_block *sb)
28880 + SiMustAnyLock(sb);
28881 + return au_sbi(sb)->si_bbot;
28884 +static inline unsigned int au_mntflags(struct super_block *sb)
28886 + SiMustAnyLock(sb);
28887 + return au_sbi(sb)->si_mntflags;
28890 +static inline unsigned int au_sigen(struct super_block *sb)
28892 + SiMustAnyLock(sb);
28893 + return au_sbi(sb)->si_generation;
28896 +static inline unsigned long long au_ninodes(struct super_block *sb)
28898 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_ninodes);
28904 +static inline void au_ninodes_inc(struct super_block *sb)
28906 + percpu_counter_inc(&au_sbi(sb)->si_ninodes);
28909 +static inline void au_ninodes_dec(struct super_block *sb)
28911 + percpu_counter_dec(&au_sbi(sb)->si_ninodes);
28914 +static inline unsigned long long au_nfiles(struct super_block *sb)
28916 + s64 n = percpu_counter_sum(&au_sbi(sb)->si_nfiles);
28922 +static inline void au_nfiles_inc(struct super_block *sb)
28924 + percpu_counter_inc(&au_sbi(sb)->si_nfiles);
28927 +static inline void au_nfiles_dec(struct super_block *sb)
28929 + percpu_counter_dec(&au_sbi(sb)->si_nfiles);
28932 +static inline struct au_branch *au_sbr(struct super_block *sb,
28933 + aufs_bindex_t bindex)
28935 + SiMustAnyLock(sb);
28936 + return au_sbi(sb)->si_branch[0 + bindex];
28939 +static inline void au_xino_brid_set(struct super_block *sb, aufs_bindex_t brid)
28941 + SiMustWriteLock(sb);
28942 + au_sbi(sb)->si_xino_brid = brid;
28945 +static inline aufs_bindex_t au_xino_brid(struct super_block *sb)
28947 + SiMustAnyLock(sb);
28948 + return au_sbi(sb)->si_xino_brid;
28951 +#endif /* __KERNEL__ */
28952 +#endif /* __AUFS_SUPER_H__ */
28953 diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c
28954 --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100
28955 +++ linux/fs/aufs/sysaufs.c 2016-10-09 16:55:36.496035060 +0200
28958 + * Copyright (C) 2005-2016 Junjiro R. Okajima
28960 + * This program, aufs is free software; you can redistribute it and/or modify
28961 + * it under the terms of the GNU General Public License as published by
28962 + * the Free Software Foundation; either version 2 of the License, or
28963 + * (at your option) any later version.
28965 + * This program is distributed in the hope that it will be useful,
28966 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
28967 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28968 + * GNU General Public License for more details.
28970 + * You should have received a copy of the GNU General Public License
28971 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
28975 + * sysfs interface and lifetime management
28976 + * they are necessary regardless sysfs is disabled.
28979 +#include <linux/random.h>
28982 +unsigned long sysaufs_si_mask;
28983 +struct kset *sysaufs_kset;
28985 +#define AuSiAttr(_name) { \
28986 + .attr = { .name = __stringify(_name), .mode = 0444 }, \
28987 + .show = sysaufs_si_##_name, \
28990 +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path);
28991 +struct attribute *sysaufs_si_attrs[] = {
28992 + &sysaufs_si_attr_xi_path.attr,
28996 +static const struct sysfs_ops au_sbi_ops = {
28997 + .show = sysaufs_si_show
29000 +static struct kobj_type au_sbi_ktype = {
29001 + .release = au_si_free,
29002 + .sysfs_ops = &au_sbi_ops,
29003 + .default_attrs = sysaufs_si_attrs
29006 +/* ---------------------------------------------------------------------- */
29008 +int sysaufs_si_init(struct au_sbinfo *sbinfo)
29012 + sbinfo->si_kobj.kset = sysaufs_kset;
29013 + /* cf. sysaufs_name() */
29014 + err = kobject_init_and_add
29015 + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL,
29016 + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo));
29018 + dbgaufs_si_null(sbinfo);
29020 + err = dbgaufs_si_init(sbinfo);
29021 + if (unlikely(err))
29022 + kobject_put(&sbinfo->si_kobj);
29027 +void sysaufs_fin(void)
29030 + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group);
29031 + kset_unregister(sysaufs_kset);
29034 +int __init sysaufs_init(void)
29039 + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask));
29040 + } while (!sysaufs_si_mask);
29043 + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj);
29044 + if (unlikely(!sysaufs_kset))
29046 + err = PTR_ERR(sysaufs_kset);
29047 + if (IS_ERR(sysaufs_kset))
29049 + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group);
29050 + if (unlikely(err)) {
29051 + kset_unregister(sysaufs_kset);
29055 + err = dbgaufs_init();
29056 + if (unlikely(err))
29061 diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h
29062 --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100
29063 +++ linux/fs/aufs/sysaufs.h 2016-10-09 16:55:36.496035060 +0200
29066 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29068 + * This program, aufs is free software; you can redistribute it and/or modify
29069 + * it under the terms of the GNU General Public License as published by
29070 + * the Free Software Foundation; either version 2 of the License, or
29071 + * (at your option) any later version.
29073 + * This program is distributed in the hope that it will be useful,
29074 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29075 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29076 + * GNU General Public License for more details.
29078 + * You should have received a copy of the GNU General Public License
29079 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29083 + * sysfs interface and mount lifetime management
29086 +#ifndef __SYSAUFS_H__
29087 +#define __SYSAUFS_H__
29091 +#include <linux/sysfs.h>
29092 +#include "module.h"
29094 +struct super_block;
29097 +struct sysaufs_si_attr {
29098 + struct attribute attr;
29099 + int (*show)(struct seq_file *seq, struct super_block *sb);
29102 +/* ---------------------------------------------------------------------- */
29105 +extern unsigned long sysaufs_si_mask;
29106 +extern struct kset *sysaufs_kset;
29107 +extern struct attribute *sysaufs_si_attrs[];
29108 +int sysaufs_si_init(struct au_sbinfo *sbinfo);
29109 +int __init sysaufs_init(void);
29110 +void sysaufs_fin(void);
29112 +/* ---------------------------------------------------------------------- */
29114 +/* some people doesn't like to show a pointer in kernel */
29115 +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo)
29117 + return sysaufs_si_mask ^ (unsigned long)sbinfo;
29120 +#define SysaufsSiNamePrefix "si_"
29121 +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16)
29122 +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name)
29124 + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx",
29125 + sysaufs_si_id(sbinfo));
29129 +#ifdef CONFIG_SYSFS
29131 +extern struct attribute_group *sysaufs_attr_group;
29133 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb);
29134 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29136 +long au_brinfo_ioctl(struct file *file, unsigned long arg);
29137 +#ifdef CONFIG_COMPAT
29138 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg);
29141 +void sysaufs_br_init(struct au_branch *br);
29142 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex);
29143 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex);
29145 +#define sysaufs_brs_init() do {} while (0)
29148 +#define sysaufs_attr_group NULL
29150 +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb)
29151 +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj,
29152 + struct attribute *attr, char *buf)
29153 +AuStubVoid(sysaufs_br_init, struct au_branch *br)
29154 +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex)
29155 +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex)
29157 +static inline void sysaufs_brs_init(void)
29162 +#endif /* CONFIG_SYSFS */
29164 +#endif /* __KERNEL__ */
29165 +#endif /* __SYSAUFS_H__ */
29166 diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c
29167 --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100
29168 +++ linux/fs/aufs/sysfs.c 2016-10-09 16:55:36.496035060 +0200
29171 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29173 + * This program, aufs is free software; you can redistribute it and/or modify
29174 + * it under the terms of the GNU General Public License as published by
29175 + * the Free Software Foundation; either version 2 of the License, or
29176 + * (at your option) any later version.
29178 + * This program is distributed in the hope that it will be useful,
29179 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29180 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29181 + * GNU General Public License for more details.
29183 + * You should have received a copy of the GNU General Public License
29184 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29188 + * sysfs interface
29191 +#include <linux/compat.h>
29192 +#include <linux/seq_file.h>
29195 +#ifdef CONFIG_AUFS_FS_MODULE
29196 +/* this entry violates the "one line per file" policy of sysfs */
29197 +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr,
29201 + static char *conf =
29202 +/* this file is generated at compiling */
29203 +#include "conf.str"
29206 + err = snprintf(buf, PAGE_SIZE, conf);
29207 + if (unlikely(err >= PAGE_SIZE))
29212 +static struct kobj_attribute au_config_attr = __ATTR_RO(config);
29215 +static struct attribute *au_attr[] = {
29216 +#ifdef CONFIG_AUFS_FS_MODULE
29217 + &au_config_attr.attr,
29219 + NULL, /* need to NULL terminate the list of attributes */
29222 +static struct attribute_group sysaufs_attr_group_body = {
29226 +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body;
29228 +/* ---------------------------------------------------------------------- */
29230 +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb)
29234 + SiMustAnyLock(sb);
29237 + if (au_opt_test(au_mntflags(sb), XINO)) {
29238 + err = au_xino_path(seq, au_sbi(sb)->si_xib);
29239 + seq_putc(seq, '\n');
29245 + * the lifetime of branch is independent from the entry under sysfs.
29246 + * sysfs handles the lifetime of the entry, and never call ->show() after it is
29249 +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb,
29250 + aufs_bindex_t bindex, int idx)
29253 + struct path path;
29254 + struct dentry *root;
29255 + struct au_branch *br;
29256 + au_br_perm_str_t perm;
29258 + AuDbg("b%d\n", bindex);
29261 + root = sb->s_root;
29262 + di_read_lock_parent(root, !AuLock_IR);
29263 + br = au_sbr(sb, bindex);
29266 + case AuBrSysfs_BR:
29267 + path.mnt = au_br_mnt(br);
29268 + path.dentry = au_h_dptr(root, bindex);
29269 + err = au_seq_path(seq, &path);
29271 + au_optstr_br_perm(&perm, br->br_perm);
29272 + seq_printf(seq, "=%s\n", perm.a);
29275 + case AuBrSysfs_BRID:
29276 + seq_printf(seq, "%d\n", br->br_id);
29279 + di_read_unlock(root, !AuLock_IR);
29280 + if (unlikely(err || seq_has_overflowed(seq)))
29286 +/* ---------------------------------------------------------------------- */
29288 +static struct seq_file *au_seq(char *p, ssize_t len)
29290 + struct seq_file *seq;
29292 + seq = kzalloc(sizeof(*seq), GFP_NOFS);
29294 + /* mutex_init(&seq.lock); */
29297 + return seq; /* success */
29300 + seq = ERR_PTR(-ENOMEM);
29304 +#define SysaufsBr_PREFIX "br"
29305 +#define SysaufsBrid_PREFIX "brid"
29307 +/* todo: file size may exceed PAGE_SIZE */
29308 +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr,
29314 + aufs_bindex_t bbot;
29315 + struct au_sbinfo *sbinfo;
29316 + struct super_block *sb;
29317 + struct seq_file *seq;
29319 + struct attribute **cattr;
29321 + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj);
29322 + sb = sbinfo->si_sb;
29325 + * prevent a race condition between sysfs and aufs.
29326 + * for instance, sysfs_file_read() calls sysfs_get_active_two() which
29327 + * prohibits maintaining the sysfs entries.
29328 + * hew we acquire read lock after sysfs_get_active_two().
29329 + * on the other hand, the remount process may maintain the sysfs/aufs
29330 + * entries after acquiring write lock.
29331 + * it can cause a deadlock.
29332 + * simply we gave up processing read here.
29335 + if (unlikely(!si_noflush_read_trylock(sb)))
29338 + seq = au_seq(buf, PAGE_SIZE);
29339 + err = PTR_ERR(seq);
29343 + name = (void *)attr->name;
29344 + cattr = sysaufs_si_attrs;
29346 + if (!strcmp(name, (*cattr)->name)) {
29347 + err = container_of(*cattr, struct sysaufs_si_attr, attr)
29354 + if (!strncmp(name, SysaufsBrid_PREFIX,
29355 + sizeof(SysaufsBrid_PREFIX) - 1)) {
29356 + idx = AuBrSysfs_BRID;
29357 + name += sizeof(SysaufsBrid_PREFIX) - 1;
29358 + } else if (!strncmp(name, SysaufsBr_PREFIX,
29359 + sizeof(SysaufsBr_PREFIX) - 1)) {
29360 + idx = AuBrSysfs_BR;
29361 + name += sizeof(SysaufsBr_PREFIX) - 1;
29365 + err = kstrtol(name, 10, &l);
29367 + bbot = au_sbbot(sb);
29369 + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx);
29376 + err = seq->count;
29377 + /* sysfs limit */
29378 + if (unlikely(err == PAGE_SIZE))
29381 + au_delayed_kfree(seq);
29383 + si_read_unlock(sb);
29388 +/* ---------------------------------------------------------------------- */
29390 +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg)
29394 + aufs_bindex_t bindex, bbot;
29397 + struct seq_file *seq;
29398 + struct au_branch *br;
29400 + si_read_lock(sb, AuLock_FLUSH);
29401 + bbot = au_sbbot(sb);
29407 + buf = (void *)__get_free_page(GFP_NOFS);
29408 + if (unlikely(!buf))
29411 + seq = au_seq(buf, PAGE_SIZE);
29412 + err = PTR_ERR(seq);
29416 + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path);
29417 + for (bindex = 0; bindex <= bbot; bindex++, arg++) {
29418 + err = !access_ok(VERIFY_WRITE, arg, sizeof(*arg));
29419 + if (unlikely(err))
29422 + br = au_sbr(sb, bindex);
29423 + brid = br->br_id;
29424 + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id));
29425 + err = __put_user(brid, &arg->id);
29426 + if (unlikely(err))
29429 + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm));
29430 + err = __put_user(br->br_perm, &arg->perm);
29431 + if (unlikely(err))
29434 + err = au_seq_path(seq, &br->br_path);
29435 + if (unlikely(err))
29437 + seq_putc(seq, '\0');
29438 + if (!seq_has_overflowed(seq)) {
29439 + err = copy_to_user(arg->path, seq->buf, seq->count);
29441 + if (unlikely(err))
29448 + if (unlikely(err))
29452 + au_delayed_kfree(seq);
29454 + au_delayed_free_page((unsigned long)buf);
29456 + si_read_unlock(sb);
29460 +long au_brinfo_ioctl(struct file *file, unsigned long arg)
29462 + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg);
29465 +#ifdef CONFIG_COMPAT
29466 +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg)
29468 + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg));
29472 +/* ---------------------------------------------------------------------- */
29474 +void sysaufs_br_init(struct au_branch *br)
29477 + struct au_brsysfs *br_sysfs;
29478 + struct attribute *attr;
29480 + br_sysfs = br->br_sysfs;
29481 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29482 + attr = &br_sysfs->attr;
29483 + sysfs_attr_init(attr);
29484 + attr->name = br_sysfs->name;
29485 + attr->mode = S_IRUGO;
29490 +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex)
29492 + struct au_branch *br;
29493 + struct kobject *kobj;
29494 + struct au_brsysfs *br_sysfs;
29496 + aufs_bindex_t bbot;
29498 + dbgaufs_brs_del(sb, bindex);
29500 + if (!sysaufs_brs)
29503 + kobj = &au_sbi(sb)->si_kobj;
29504 + bbot = au_sbbot(sb);
29505 + for (; bindex <= bbot; bindex++) {
29506 + br = au_sbr(sb, bindex);
29507 + br_sysfs = br->br_sysfs;
29508 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29509 + sysfs_remove_file(kobj, &br_sysfs->attr);
29515 +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex)
29518 + aufs_bindex_t bbot;
29519 + struct kobject *kobj;
29520 + struct au_branch *br;
29521 + struct au_brsysfs *br_sysfs;
29523 + dbgaufs_brs_add(sb, bindex);
29525 + if (!sysaufs_brs)
29528 + kobj = &au_sbi(sb)->si_kobj;
29529 + bbot = au_sbbot(sb);
29530 + for (; bindex <= bbot; bindex++) {
29531 + br = au_sbr(sb, bindex);
29532 + br_sysfs = br->br_sysfs;
29533 + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name),
29534 + SysaufsBr_PREFIX "%d", bindex);
29535 + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name),
29536 + SysaufsBrid_PREFIX "%d", bindex);
29537 + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) {
29538 + err = sysfs_create_file(kobj, &br_sysfs->attr);
29539 + if (unlikely(err))
29540 + pr_warn("failed %s under sysfs(%d)\n",
29541 + br_sysfs->name, err);
29546 diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c
29547 --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100
29548 +++ linux/fs/aufs/sysrq.c 2016-10-09 16:55:36.496035060 +0200
29551 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29553 + * This program, aufs is free software; you can redistribute it and/or modify
29554 + * it under the terms of the GNU General Public License as published by
29555 + * the Free Software Foundation; either version 2 of the License, or
29556 + * (at your option) any later version.
29558 + * This program is distributed in the hope that it will be useful,
29559 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29560 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29561 + * GNU General Public License for more details.
29563 + * You should have received a copy of the GNU General Public License
29564 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29568 + * magic sysrq hanlder
29571 +/* #include <linux/sysrq.h> */
29572 +#include <linux/writeback.h>
29575 +/* ---------------------------------------------------------------------- */
29577 +static void sysrq_sb(struct super_block *sb)
29580 + struct au_sbinfo *sbinfo;
29581 + struct file *file;
29582 + struct au_sphlhead *files;
29583 + struct au_finfo *finfo;
29585 + plevel = au_plevel;
29586 + au_plevel = KERN_WARNING;
29588 + /* since we define pr_fmt, call printk directly */
29589 +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str)
29591 + sbinfo = au_sbi(sb);
29592 + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo));
29593 + pr("superblock\n");
29597 + pr("root dentry\n");
29598 + au_dpri_dentry(sb->s_root);
29599 + pr("root inode\n");
29600 + au_dpri_inode(d_inode(sb->s_root));
29605 + int err, i, j, ndentry;
29606 + struct au_dcsub_pages dpages;
29607 + struct au_dpage *dpage;
29609 + err = au_dpages_init(&dpages, GFP_ATOMIC);
29610 + if (unlikely(err))
29612 + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL);
29614 + for (i = 0; i < dpages.ndpage; i++) {
29615 + dpage = dpages.dpages + i;
29616 + ndentry = dpage->ndentry;
29617 + for (j = 0; j < ndentry; j++)
29618 + au_dpri_dentry(dpage->dentries[j]);
29620 + au_dpages_free(&dpages);
29628 + pr("isolated inode\n");
29629 + spin_lock(&sb->s_inode_list_lock);
29630 + list_for_each_entry(i, &sb->s_inodes, i_sb_list) {
29631 + spin_lock(&i->i_lock);
29632 + if (1 || hlist_empty(&i->i_dentry))
29633 + au_dpri_inode(i);
29634 + spin_unlock(&i->i_lock);
29636 + spin_unlock(&sb->s_inode_list_lock);
29640 + files = &au_sbi(sb)->si_files;
29641 + spin_lock(&files->spin);
29642 + hlist_for_each_entry(finfo, &files->head, fi_hlist) {
29645 + file = finfo->fi_file;
29646 + mode = file_inode(file)->i_mode;
29647 + if (!special_file(mode))
29648 + au_dpri_file(file);
29650 + spin_unlock(&files->spin);
29654 + au_plevel = plevel;
29657 +/* ---------------------------------------------------------------------- */
29659 +/* module parameter */
29660 +static char *aufs_sysrq_key = "a";
29661 +module_param_named(sysrq, aufs_sysrq_key, charp, S_IRUGO);
29662 +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME);
29664 +static void au_sysrq(int key __maybe_unused)
29666 + struct au_sbinfo *sbinfo;
29669 + au_sbilist_lock();
29670 + hlist_for_each_entry(sbinfo, &au_sbilist.head, si_list)
29671 + sysrq_sb(sbinfo->si_sb);
29672 + au_sbilist_unlock();
29676 +static struct sysrq_key_op au_sysrq_op = {
29677 + .handler = au_sysrq,
29678 + .help_msg = "Aufs",
29679 + .action_msg = "Aufs",
29680 + .enable_mask = SYSRQ_ENABLE_DUMP
29683 +/* ---------------------------------------------------------------------- */
29685 +int __init au_sysrq_init(void)
29691 + key = *aufs_sysrq_key;
29692 + if ('a' <= key && key <= 'z')
29693 + err = register_sysrq_key(key, &au_sysrq_op);
29694 + if (unlikely(err))
29695 + pr_err("err %d, sysrq=%c\n", err, key);
29699 +void au_sysrq_fin(void)
29703 + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op);
29704 + if (unlikely(err))
29705 + pr_err("err %d (ignored)\n", err);
29707 diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c
29708 --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100
29709 +++ linux/fs/aufs/vdir.c 2016-10-09 16:55:38.889431135 +0200
29712 + * Copyright (C) 2005-2016 Junjiro R. Okajima
29714 + * This program, aufs is free software; you can redistribute it and/or modify
29715 + * it under the terms of the GNU General Public License as published by
29716 + * the Free Software Foundation; either version 2 of the License, or
29717 + * (at your option) any later version.
29719 + * This program is distributed in the hope that it will be useful,
29720 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29721 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29722 + * GNU General Public License for more details.
29724 + * You should have received a copy of the GNU General Public License
29725 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
29729 + * virtual or vertical directory
29734 +static unsigned int calc_size(int nlen)
29736 + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t));
29739 +static int set_deblk_end(union au_vdir_deblk_p *p,
29740 + union au_vdir_deblk_p *deblk_end)
29742 + if (calc_size(0) <= deblk_end->deblk - p->deblk) {
29743 + p->de->de_str.len = 0;
29747 + return -1; /* error */
29750 +/* returns true or false */
29751 +static int is_deblk_end(union au_vdir_deblk_p *p,
29752 + union au_vdir_deblk_p *deblk_end)
29754 + if (calc_size(0) <= deblk_end->deblk - p->deblk)
29755 + return !p->de->de_str.len;
29759 +static unsigned char *last_deblk(struct au_vdir *vdir)
29761 + return vdir->vd_deblk[vdir->vd_nblk - 1];
29764 +/* ---------------------------------------------------------------------- */
29766 +/* estimate the appropriate size for name hash table */
29767 +unsigned int au_rdhash_est(loff_t sz)
29775 + if (sz < AUFS_RDHASH_DEF)
29776 + n = AUFS_RDHASH_DEF;
29777 + /* pr_info("n %u\n", n); */
29782 + * the allocated memory has to be freed by
29783 + * au_nhash_wh_free() or au_nhash_de_free().
29785 +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp)
29787 + struct hlist_head *head;
29791 + sz = sizeof(*nhash->nh_head) * num_hash;
29792 + head = kmalloc(sz, gfp);
29794 + nhash->nh_num = num_hash;
29795 + nhash->nh_head = head;
29796 + for (u = 0; u < num_hash; u++)
29797 + INIT_HLIST_HEAD(head++);
29798 + return 0; /* success */
29804 +static void nhash_count(struct hlist_head *head)
29808 + struct hlist_node *pos;
29811 + hlist_for_each(pos, head)
29813 + pr_info("%lu\n", n);
29817 +static void au_nhash_wh_do_free(struct hlist_head *head)
29819 + struct au_vdir_wh *pos;
29820 + struct hlist_node *node;
29822 + hlist_for_each_entry_safe(pos, node, head, wh_hash)
29823 + au_delayed_kfree(pos);
29826 +static void au_nhash_de_do_free(struct hlist_head *head)
29828 + struct au_vdir_dehstr *pos;
29829 + struct hlist_node *node;
29831 + hlist_for_each_entry_safe(pos, node, head, hash)
29832 + au_cache_dfree_vdir_dehstr(pos);
29835 +static void au_nhash_do_free(struct au_nhash *nhash,
29836 + void (*free)(struct hlist_head *head))
29839 + struct hlist_head *head;
29841 + n = nhash->nh_num;
29845 + head = nhash->nh_head;
29846 + while (n-- > 0) {
29847 + nhash_count(head);
29850 + au_delayed_kfree(nhash->nh_head);
29853 +void au_nhash_wh_free(struct au_nhash *whlist)
29855 + au_nhash_do_free(whlist, au_nhash_wh_do_free);
29858 +static void au_nhash_de_free(struct au_nhash *delist)
29860 + au_nhash_do_free(delist, au_nhash_de_do_free);
29863 +/* ---------------------------------------------------------------------- */
29865 +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt,
29869 + unsigned int u, n;
29870 + struct hlist_head *head;
29871 + struct au_vdir_wh *pos;
29874 + n = whlist->nh_num;
29875 + head = whlist->nh_head;
29876 + for (u = 0; u < n; u++, head++)
29877 + hlist_for_each_entry(pos, head, wh_hash)
29878 + if (pos->wh_bindex == btgt && ++num > limit)
29883 +static struct hlist_head *au_name_hash(struct au_nhash *nhash,
29884 + unsigned char *name,
29885 + unsigned int len)
29888 + /* const unsigned int magic_bit = 12; */
29890 + AuDebugOn(!nhash->nh_num || !nhash->nh_head);
29897 + /* v = hash_long(v, magic_bit); */
29898 + v %= nhash->nh_num;
29899 + return nhash->nh_head + v;
29902 +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name,
29905 + return str->len == nlen && !memcmp(str->name, name, nlen);
29908 +/* returns found or not */
29909 +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen)
29911 + struct hlist_head *head;
29912 + struct au_vdir_wh *pos;
29913 + struct au_vdir_destr *str;
29915 + head = au_name_hash(whlist, name, nlen);
29916 + hlist_for_each_entry(pos, head, wh_hash) {
29917 + str = &pos->wh_str;
29918 + AuDbg("%.*s\n", str->len, str->name);
29919 + if (au_nhash_test_name(str, name, nlen))
29925 +/* returns found(true) or not */
29926 +static int test_known(struct au_nhash *delist, char *name, int nlen)
29928 + struct hlist_head *head;
29929 + struct au_vdir_dehstr *pos;
29930 + struct au_vdir_destr *str;
29932 + head = au_name_hash(delist, name, nlen);
29933 + hlist_for_each_entry(pos, head, hash) {
29935 + AuDbg("%.*s\n", str->len, str->name);
29936 + if (au_nhash_test_name(str, name, nlen))
29942 +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino,
29943 + unsigned char d_type)
29945 +#ifdef CONFIG_AUFS_SHWH
29946 + wh->wh_ino = ino;
29947 + wh->wh_type = d_type;
29951 +/* ---------------------------------------------------------------------- */
29953 +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino,
29954 + unsigned int d_type, aufs_bindex_t bindex,
29955 + unsigned char shwh)
29958 + struct au_vdir_destr *str;
29959 + struct au_vdir_wh *wh;
29961 + AuDbg("%.*s\n", nlen, name);
29962 + AuDebugOn(!whlist->nh_num || !whlist->nh_head);
29965 + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS);
29966 + if (unlikely(!wh))
29970 + wh->wh_bindex = bindex;
29972 + au_shwh_init_wh(wh, ino, d_type);
29973 + str = &wh->wh_str;
29975 + memcpy(str->name, name, nlen);
29976 + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen));
29983 +static int append_deblk(struct au_vdir *vdir)
29986 + unsigned long ul;
29987 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
29988 + union au_vdir_deblk_p p, deblk_end;
29989 + unsigned char **o;
29992 + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1),
29993 + GFP_NOFS, /*may_shrink*/0);
29994 + if (unlikely(!o))
29997 + vdir->vd_deblk = o;
29998 + p.deblk = kmalloc(deblk_sz, GFP_NOFS);
30000 + ul = vdir->vd_nblk++;
30001 + vdir->vd_deblk[ul] = p.deblk;
30002 + vdir->vd_last.ul = ul;
30003 + vdir->vd_last.p.deblk = p.deblk;
30004 + deblk_end.deblk = p.deblk + deblk_sz;
30005 + err = set_deblk_end(&p, &deblk_end);
30012 +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino,
30013 + unsigned int d_type, struct au_nhash *delist)
30017 + const unsigned int deblk_sz = vdir->vd_deblk_sz;
30018 + union au_vdir_deblk_p p, *room, deblk_end;
30019 + struct au_vdir_dehstr *dehstr;
30021 + p.deblk = last_deblk(vdir);
30022 + deblk_end.deblk = p.deblk + deblk_sz;
30023 + room = &vdir->vd_last.p;
30024 + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk
30025 + || !is_deblk_end(room, &deblk_end));
30027 + sz = calc_size(nlen);
30028 + if (unlikely(sz > deblk_end.deblk - room->deblk)) {
30029 + err = append_deblk(vdir);
30030 + if (unlikely(err))
30033 + p.deblk = last_deblk(vdir);
30034 + deblk_end.deblk = p.deblk + deblk_sz;
30036 + AuDebugOn(room->deblk != p.deblk);
30040 + dehstr = au_cache_alloc_vdir_dehstr();
30041 + if (unlikely(!dehstr))
30044 + dehstr->str = &room->de->de_str;
30045 + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen));
30046 + room->de->de_ino = ino;
30047 + room->de->de_type = d_type;
30048 + room->de->de_str.len = nlen;
30049 + memcpy(room->de->de_str.name, name, nlen);
30052 + room->deblk += sz;
30053 + if (unlikely(set_deblk_end(room, &deblk_end)))
30054 + err = append_deblk(vdir);
30061 +/* ---------------------------------------------------------------------- */
30063 +void au_vdir_free(struct au_vdir *vdir, int atonce)
30065 + unsigned char **deblk;
30067 + deblk = vdir->vd_deblk;
30069 + while (vdir->vd_nblk--)
30070 + au_delayed_kfree(*deblk++);
30071 + au_delayed_kfree(vdir->vd_deblk);
30072 + au_cache_dfree_vdir(vdir);
30074 + /* not delayed */
30075 + while (vdir->vd_nblk--)
30077 + kfree(vdir->vd_deblk);
30078 + au_cache_free_vdir(vdir);
30082 +static struct au_vdir *alloc_vdir(struct file *file)
30084 + struct au_vdir *vdir;
30085 + struct super_block *sb;
30088 + sb = file->f_path.dentry->d_sb;
30089 + SiMustAnyLock(sb);
30092 + vdir = au_cache_alloc_vdir();
30093 + if (unlikely(!vdir))
30096 + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS);
30097 + if (unlikely(!vdir->vd_deblk))
30100 + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk;
30101 + if (!vdir->vd_deblk_sz) {
30102 + /* estimate the appropriate size for deblk */
30103 + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL);
30104 + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */
30106 + vdir->vd_nblk = 0;
30107 + vdir->vd_version = 0;
30108 + vdir->vd_jiffy = 0;
30109 + err = append_deblk(vdir);
30111 + return vdir; /* success */
30113 + au_delayed_kfree(vdir->vd_deblk);
30116 + au_cache_dfree_vdir(vdir);
30118 + vdir = ERR_PTR(err);
30122 +static int reinit_vdir(struct au_vdir *vdir)
30125 + union au_vdir_deblk_p p, deblk_end;
30127 + while (vdir->vd_nblk > 1) {
30128 + au_delayed_kfree(vdir->vd_deblk[vdir->vd_nblk - 1]);
30129 + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */
30132 + p.deblk = vdir->vd_deblk[0];
30133 + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz;
30134 + err = set_deblk_end(&p, &deblk_end);
30135 + /* keep vd_dblk_sz */
30136 + vdir->vd_last.ul = 0;
30137 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30138 + vdir->vd_version = 0;
30139 + vdir->vd_jiffy = 0;
30144 +/* ---------------------------------------------------------------------- */
30146 +#define AuFillVdir_CALLED 1
30147 +#define AuFillVdir_WHABLE (1 << 1)
30148 +#define AuFillVdir_SHWH (1 << 2)
30149 +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name)
30150 +#define au_fset_fillvdir(flags, name) \
30151 + do { (flags) |= AuFillVdir_##name; } while (0)
30152 +#define au_fclr_fillvdir(flags, name) \
30153 + do { (flags) &= ~AuFillVdir_##name; } while (0)
30155 +#ifndef CONFIG_AUFS_SHWH
30156 +#undef AuFillVdir_SHWH
30157 +#define AuFillVdir_SHWH 0
30160 +struct fillvdir_arg {
30161 + struct dir_context ctx;
30162 + struct file *file;
30163 + struct au_vdir *vdir;
30164 + struct au_nhash delist;
30165 + struct au_nhash whlist;
30166 + aufs_bindex_t bindex;
30167 + unsigned int flags;
30171 +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen,
30172 + loff_t offset __maybe_unused, u64 h_ino,
30173 + unsigned int d_type)
30175 + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx);
30176 + char *name = (void *)__name;
30177 + struct super_block *sb;
30179 + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH);
30182 + sb = arg->file->f_path.dentry->d_sb;
30183 + au_fset_fillvdir(arg->flags, CALLED);
30185 + if (nlen <= AUFS_WH_PFX_LEN
30186 + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) {
30187 + if (test_known(&arg->delist, name, nlen)
30188 + || au_nhash_test_known_wh(&arg->whlist, name, nlen))
30189 + goto out; /* already exists or whiteouted */
30191 + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino);
30193 + if (unlikely(nlen > AUFS_MAX_NAMELEN))
30194 + d_type = DT_UNKNOWN;
30195 + arg->err = append_de(arg->vdir, name, nlen, ino,
30196 + d_type, &arg->delist);
30198 + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) {
30199 + name += AUFS_WH_PFX_LEN;
30200 + nlen -= AUFS_WH_PFX_LEN;
30201 + if (au_nhash_test_known_wh(&arg->whlist, name, nlen))
30202 + goto out; /* already whiteouted */
30205 + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type,
30208 + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN)
30209 + d_type = DT_UNKNOWN;
30210 + arg->err = au_nhash_append_wh
30211 + (&arg->whlist, name, nlen, ino, d_type,
30212 + arg->bindex, shwh);
30218 + arg->vdir->vd_jiffy = jiffies;
30220 + AuTraceErr(arg->err);
30224 +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir,
30225 + struct au_nhash *whlist, struct au_nhash *delist)
30227 +#ifdef CONFIG_AUFS_SHWH
30229 + unsigned int nh, u;
30230 + struct hlist_head *head;
30231 + struct au_vdir_wh *pos;
30232 + struct hlist_node *n;
30234 + struct au_vdir_destr *destr;
30236 + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH));
30239 + o = p = (void *)__get_free_page(GFP_NOFS);
30240 + if (unlikely(!p))
30244 + nh = whlist->nh_num;
30245 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
30246 + p += AUFS_WH_PFX_LEN;
30247 + for (u = 0; u < nh; u++) {
30248 + head = whlist->nh_head + u;
30249 + hlist_for_each_entry_safe(pos, n, head, wh_hash) {
30250 + destr = &pos->wh_str;
30251 + memcpy(p, destr->name, destr->len);
30252 + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN,
30253 + pos->wh_ino, pos->wh_type, delist);
30254 + if (unlikely(err))
30259 + au_delayed_free_page((unsigned long)o);
30269 +static int au_do_read_vdir(struct fillvdir_arg *arg)
30272 + unsigned int rdhash;
30274 + aufs_bindex_t bbot, bindex, btop;
30275 + unsigned char shwh;
30276 + struct file *hf, *file;
30277 + struct super_block *sb;
30279 + file = arg->file;
30280 + sb = file->f_path.dentry->d_sb;
30281 + SiMustAnyLock(sb);
30283 + rdhash = au_sbi(sb)->si_rdhash;
30285 + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL));
30286 + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS);
30287 + if (unlikely(err))
30289 + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS);
30290 + if (unlikely(err))
30296 + if (au_opt_test(au_mntflags(sb), SHWH)) {
30298 + au_fset_fillvdir(arg->flags, SHWH);
30300 + btop = au_fbtop(file);
30301 + bbot = au_fbbot_dir(file);
30302 + for (bindex = btop; !err && bindex <= bbot; bindex++) {
30303 + hf = au_hf_dir(file, bindex);
30307 + offset = vfsub_llseek(hf, 0, SEEK_SET);
30309 + if (unlikely(offset))
30312 + arg->bindex = bindex;
30313 + au_fclr_fillvdir(arg->flags, WHABLE);
30315 + || (bindex != bbot
30316 + && au_br_whable(au_sbr_perm(sb, bindex))))
30317 + au_fset_fillvdir(arg->flags, WHABLE);
30320 + au_fclr_fillvdir(arg->flags, CALLED);
30322 + err = vfsub_iterate_dir(hf, &arg->ctx);
30325 + } while (!err && au_ftest_fillvdir(arg->flags, CALLED));
30328 + * dir_relax() may be good for concurrency, but aufs should not
30329 + * use it since it will cause a lockdep problem.
30333 + if (!err && shwh)
30334 + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist);
30336 + au_nhash_wh_free(&arg->whlist);
30339 + au_nhash_de_free(&arg->delist);
30344 +static int read_vdir(struct file *file, int may_read)
30347 + unsigned long expire;
30348 + unsigned char do_read;
30349 + struct fillvdir_arg arg = {
30351 + .actor = fillvdir
30354 + struct inode *inode;
30355 + struct au_vdir *vdir, *allocated;
30358 + inode = file_inode(file);
30359 + IMustLock(inode);
30360 + IiMustWriteLock(inode);
30361 + SiMustAnyLock(inode->i_sb);
30363 + allocated = NULL;
30365 + expire = au_sbi(inode->i_sb)->si_rdcache;
30366 + vdir = au_ivdir(inode);
30369 + vdir = alloc_vdir(file);
30370 + err = PTR_ERR(vdir);
30371 + if (IS_ERR(vdir))
30374 + allocated = vdir;
30375 + } else if (may_read
30376 + && (inode->i_version != vdir->vd_version
30377 + || time_after(jiffies, vdir->vd_jiffy + expire))) {
30379 + err = reinit_vdir(vdir);
30380 + if (unlikely(err))
30385 + return 0; /* success */
30389 + err = au_do_read_vdir(&arg);
30391 + /* file->f_pos = 0; */ /* todo: ctx->pos? */
30392 + vdir->vd_version = inode->i_version;
30393 + vdir->vd_last.ul = 0;
30394 + vdir->vd_last.p.deblk = vdir->vd_deblk[0];
30396 + au_set_ivdir(inode, allocated);
30397 + } else if (allocated)
30398 + au_vdir_free(allocated, /*atonce*/0);
30404 +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src)
30407 + unsigned long ul, n;
30408 + const unsigned int deblk_sz = src->vd_deblk_sz;
30410 + AuDebugOn(tgt->vd_nblk != 1);
30413 + if (tgt->vd_nblk < src->vd_nblk) {
30414 + unsigned char **p;
30416 + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk,
30417 + GFP_NOFS, /*may_shrink*/0);
30418 + if (unlikely(!p))
30420 + tgt->vd_deblk = p;
30423 + if (tgt->vd_deblk_sz != deblk_sz) {
30424 + unsigned char *p;
30426 + tgt->vd_deblk_sz = deblk_sz;
30427 + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS,
30428 + /*may_shrink*/1);
30429 + if (unlikely(!p))
30431 + tgt->vd_deblk[0] = p;
30433 + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz);
30434 + tgt->vd_version = src->vd_version;
30435 + tgt->vd_jiffy = src->vd_jiffy;
30437 + n = src->vd_nblk;
30438 + for (ul = 1; ul < n; ul++) {
30439 + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz,
30441 + if (unlikely(!tgt->vd_deblk[ul]))
30445 + tgt->vd_nblk = n;
30446 + tgt->vd_last.ul = tgt->vd_last.ul;
30447 + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul];
30448 + tgt->vd_last.p.deblk += src->vd_last.p.deblk
30449 + - src->vd_deblk[src->vd_last.ul];
30451 + return 0; /* success */
30454 + rerr = reinit_vdir(tgt);
30459 +int au_vdir_init(struct file *file)
30462 + struct inode *inode;
30463 + struct au_vdir *vdir_cache, *allocated;
30465 + /* test file->f_pos here instead of ctx->pos */
30466 + err = read_vdir(file, !file->f_pos);
30467 + if (unlikely(err))
30470 + allocated = NULL;
30471 + vdir_cache = au_fvdir_cache(file);
30472 + if (!vdir_cache) {
30473 + vdir_cache = alloc_vdir(file);
30474 + err = PTR_ERR(vdir_cache);
30475 + if (IS_ERR(vdir_cache))
30477 + allocated = vdir_cache;
30478 + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) {
30479 + /* test file->f_pos here instead of ctx->pos */
30480 + err = reinit_vdir(vdir_cache);
30481 + if (unlikely(err))
30484 + return 0; /* success */
30486 + inode = file_inode(file);
30487 + err = copy_vdir(vdir_cache, au_ivdir(inode));
30489 + file->f_version = inode->i_version;
30491 + au_set_fvdir_cache(file, allocated);
30492 + } else if (allocated)
30493 + au_vdir_free(allocated, /*atonce*/0);
30499 +static loff_t calc_offset(struct au_vdir *vdir)
30502 + union au_vdir_deblk_p p;
30504 + p.deblk = vdir->vd_deblk[vdir->vd_last.ul];
30505 + offset = vdir->vd_last.p.deblk - p.deblk;
30506 + offset += vdir->vd_deblk_sz * vdir->vd_last.ul;
30510 +/* returns true or false */
30511 +static int seek_vdir(struct file *file, struct dir_context *ctx)
30514 + unsigned int deblk_sz;
30515 + unsigned long ul, n;
30517 + union au_vdir_deblk_p p, deblk_end;
30518 + struct au_vdir *vdir_cache;
30521 + vdir_cache = au_fvdir_cache(file);
30522 + offset = calc_offset(vdir_cache);
30523 + AuDbg("offset %lld\n", offset);
30524 + if (ctx->pos == offset)
30527 + vdir_cache->vd_last.ul = 0;
30528 + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0];
30533 + deblk_sz = vdir_cache->vd_deblk_sz;
30534 + ul = div64_u64(ctx->pos, deblk_sz);
30535 + AuDbg("ul %lu\n", ul);
30536 + if (ul >= vdir_cache->vd_nblk)
30539 + n = vdir_cache->vd_nblk;
30540 + for (; ul < n; ul++) {
30541 + p.deblk = vdir_cache->vd_deblk[ul];
30542 + deblk_end.deblk = p.deblk + deblk_sz;
30544 + offset *= deblk_sz;
30545 + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) {
30548 + l = calc_size(p.de->de_str.len);
30552 + if (!is_deblk_end(&p, &deblk_end)) {
30554 + vdir_cache->vd_last.ul = ul;
30555 + vdir_cache->vd_last.p = p;
30562 + AuTraceErr(!valid);
30566 +int au_vdir_fill_de(struct file *file, struct dir_context *ctx)
30568 + unsigned int l, deblk_sz;
30569 + union au_vdir_deblk_p deblk_end;
30570 + struct au_vdir *vdir_cache;
30571 + struct au_vdir_de *de;
30573 + vdir_cache = au_fvdir_cache(file);
30574 + if (!seek_vdir(file, ctx))
30577 + deblk_sz = vdir_cache->vd_deblk_sz;
30579 + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30580 + deblk_end.deblk += deblk_sz;
30581 + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) {
30582 + de = vdir_cache->vd_last.p.de;
30583 + AuDbg("%.*s, off%lld, i%lu, dt%d\n",
30584 + de->de_str.len, de->de_str.name, ctx->pos,
30585 + (unsigned long)de->de_ino, de->de_type);
30586 + if (unlikely(!dir_emit(ctx, de->de_str.name,
30587 + de->de_str.len, de->de_ino,
30589 + /* todo: ignore the error caused by udba? */
30590 + /* return err; */
30594 + l = calc_size(de->de_str.len);
30595 + vdir_cache->vd_last.p.deblk += l;
30598 + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) {
30599 + vdir_cache->vd_last.ul++;
30600 + vdir_cache->vd_last.p.deblk
30601 + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul];
30602 + ctx->pos = deblk_sz * vdir_cache->vd_last.ul;
30611 diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c
30612 --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100
30613 +++ linux/fs/aufs/vfsub.c 2016-12-17 12:28:17.598545045 +0100
30616 + * Copyright (C) 2005-2016 Junjiro R. Okajima
30618 + * This program, aufs is free software; you can redistribute it and/or modify
30619 + * it under the terms of the GNU General Public License as published by
30620 + * the Free Software Foundation; either version 2 of the License, or
30621 + * (at your option) any later version.
30623 + * This program is distributed in the hope that it will be useful,
30624 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30625 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30626 + * GNU General Public License for more details.
30628 + * You should have received a copy of the GNU General Public License
30629 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
30633 + * sub-routines for VFS
30636 +#include <linux/namei.h>
30637 +#include <linux/nsproxy.h>
30638 +#include <linux/security.h>
30639 +#include <linux/splice.h>
30640 +#ifdef CONFIG_AUFS_BR_FUSE
30641 +#include "../fs/mount.h"
30645 +#ifdef CONFIG_AUFS_BR_FUSE
30646 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb)
30648 + struct nsproxy *ns;
30650 + if (!au_test_fuse(h_sb) || !au_userns)
30653 + ns = current->nsproxy;
30654 + /* no {get,put}_nsproxy(ns) */
30655 + return real_mount(mnt)->mnt_ns == ns->mnt_ns ? 0 : -EACCES;
30659 +/* ---------------------------------------------------------------------- */
30661 +int vfsub_update_h_iattr(struct path *h_path, int *did)
30665 + struct super_block *h_sb;
30667 + /* for remote fs, leave work for its getattr or d_revalidate */
30668 + /* for bad i_attr fs, handle them in aufs_getattr() */
30669 + /* still some fs may acquire i_mutex. we need to skip them */
30673 + h_sb = h_path->dentry->d_sb;
30674 + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb));
30676 + err = vfs_getattr(h_path, &st);
30681 +/* ---------------------------------------------------------------------- */
30683 +struct file *vfsub_dentry_open(struct path *path, int flags)
30685 + struct file *file;
30687 + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */,
30689 + if (!IS_ERR_OR_NULL(file)
30690 + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ)
30691 + i_readcount_inc(d_inode(path->dentry));
30696 +struct file *vfsub_filp_open(const char *path, int oflags, int mode)
30698 + struct file *file;
30701 + file = filp_open(path,
30702 + oflags /* | __FMODE_NONOTIFY */,
30705 + if (IS_ERR(file))
30707 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
30714 + * Ideally this function should call VFS:do_last() in order to keep all its
30715 + * checkings. But it is very hard for aufs to regenerate several VFS internal
30716 + * structure such as nameidata. This is a second (or third) best approach.
30717 + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open().
30719 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
30720 + struct vfsub_aopen_args *args, struct au_branch *br)
30723 + struct file *file = args->file;
30724 + /* copied from linux/fs/namei.c:atomic_open() */
30725 + struct dentry *const DENTRY_NOT_SET = (void *)-1UL;
30728 + AuDebugOn(!dir->i_op->atomic_open);
30730 + err = au_br_test_oflag(args->open_flag, br);
30731 + if (unlikely(err))
30734 + args->file->f_path.dentry = DENTRY_NOT_SET;
30735 + args->file->f_path.mnt = au_br_mnt(br);
30736 + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag,
30737 + args->create_mode, args->opened);
30739 + /* some filesystems don't set FILE_CREATED while succeeded? */
30740 + if (*args->opened & FILE_CREATED)
30741 + fsnotify_create(dir, dentry);
30747 + /* todo: call VFS:may_open() here */
30748 + err = open_check_o_direct(file);
30749 + /* todo: ima_file_check() too? */
30750 + if (!err && (args->open_flag & __FMODE_EXEC))
30751 + err = deny_write_access(file);
30752 + if (unlikely(err))
30753 + /* note that the file is created and still opened */
30758 + fsnotify_open(file);
30764 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path)
30768 + err = kern_path(name, flags, path);
30769 + if (!err && d_is_positive(path->dentry))
30770 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
30774 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
30775 + struct dentry *parent, int len)
30777 + struct path path = {
30781 + path.dentry = lookup_one_len_unlocked(name, parent, len);
30782 + if (IS_ERR(path.dentry))
30784 + if (d_is_positive(path.dentry))
30785 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30788 + AuTraceErrPtr(path.dentry);
30789 + return path.dentry;
30792 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
30795 + struct path path = {
30799 + /* VFS checks it too, but by WARN_ON_ONCE() */
30800 + IMustLock(d_inode(parent));
30802 + path.dentry = lookup_one_len(name, parent, len);
30803 + if (IS_ERR(path.dentry))
30805 + if (d_is_positive(path.dentry))
30806 + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/
30809 + AuTraceErrPtr(path.dentry);
30810 + return path.dentry;
30813 +void vfsub_call_lkup_one(void *args)
30815 + struct vfsub_lkup_one_args *a = args;
30816 + *a->errp = vfsub_lkup_one(a->name, a->parent);
30819 +/* ---------------------------------------------------------------------- */
30821 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
30822 + struct dentry *d2, struct au_hinode *hdir2)
30824 + struct dentry *d;
30827 + d = lock_rename(d1, d2);
30829 + au_hn_suspend(hdir1);
30830 + if (hdir1 != hdir2)
30831 + au_hn_suspend(hdir2);
30836 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
30837 + struct dentry *d2, struct au_hinode *hdir2)
30839 + au_hn_resume(hdir1);
30840 + if (hdir1 != hdir2)
30841 + au_hn_resume(hdir2);
30843 + unlock_rename(d1, d2);
30847 +/* ---------------------------------------------------------------------- */
30849 +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl)
30852 + struct dentry *d;
30856 + d = path->dentry;
30857 + path->dentry = d->d_parent;
30858 + err = security_path_mknod(path, d, mode, 0);
30859 + path->dentry = d;
30860 + if (unlikely(err))
30864 + err = vfs_create(dir, path->dentry, mode, want_excl);
30867 + struct path tmp = *path;
30870 + vfsub_update_h_iattr(&tmp, &did);
30872 + tmp.dentry = path->dentry->d_parent;
30873 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30882 +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname)
30885 + struct dentry *d;
30889 + d = path->dentry;
30890 + path->dentry = d->d_parent;
30891 + err = security_path_symlink(path, d, symname);
30892 + path->dentry = d;
30893 + if (unlikely(err))
30897 + err = vfs_symlink(dir, path->dentry, symname);
30900 + struct path tmp = *path;
30903 + vfsub_update_h_iattr(&tmp, &did);
30905 + tmp.dentry = path->dentry->d_parent;
30906 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30915 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev)
30918 + struct dentry *d;
30922 + d = path->dentry;
30923 + path->dentry = d->d_parent;
30924 + err = security_path_mknod(path, d, mode, new_encode_dev(dev));
30925 + path->dentry = d;
30926 + if (unlikely(err))
30930 + err = vfs_mknod(dir, path->dentry, mode, dev);
30933 + struct path tmp = *path;
30936 + vfsub_update_h_iattr(&tmp, &did);
30938 + tmp.dentry = path->dentry->d_parent;
30939 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30948 +static int au_test_nlink(struct inode *inode)
30950 + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */
30952 + if (!au_test_fs_no_limit_nlink(inode->i_sb)
30953 + || inode->i_nlink < link_max)
30958 +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path,
30959 + struct inode **delegated_inode)
30962 + struct dentry *d;
30966 + err = au_test_nlink(d_inode(src_dentry));
30967 + if (unlikely(err))
30970 + /* we don't call may_linkat() */
30971 + d = path->dentry;
30972 + path->dentry = d->d_parent;
30973 + err = security_path_link(src_dentry, path, d);
30974 + path->dentry = d;
30975 + if (unlikely(err))
30979 + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode);
30982 + struct path tmp = *path;
30985 + /* fuse has different memory inode for the same inumber */
30986 + vfsub_update_h_iattr(&tmp, &did);
30988 + tmp.dentry = path->dentry->d_parent;
30989 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
30990 + tmp.dentry = src_dentry;
30991 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31000 +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry,
31001 + struct inode *dir, struct path *path,
31002 + struct inode **delegated_inode, unsigned int flags)
31005 + struct path tmp = {
31008 + struct dentry *d;
31011 + IMustLock(src_dir);
31013 + d = path->dentry;
31014 + path->dentry = d->d_parent;
31015 + tmp.dentry = src_dentry->d_parent;
31016 + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0);
31017 + path->dentry = d;
31018 + if (unlikely(err))
31022 + err = vfs_rename(src_dir, src_dentry, dir, path->dentry,
31023 + delegated_inode, flags);
31028 + tmp.dentry = d->d_parent;
31029 + vfsub_update_h_iattr(&tmp, &did);
31031 + tmp.dentry = src_dentry;
31032 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31033 + tmp.dentry = src_dentry->d_parent;
31034 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31043 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode)
31046 + struct dentry *d;
31050 + d = path->dentry;
31051 + path->dentry = d->d_parent;
31052 + err = security_path_mkdir(path, d, mode);
31053 + path->dentry = d;
31054 + if (unlikely(err))
31058 + err = vfs_mkdir(dir, path->dentry, mode);
31061 + struct path tmp = *path;
31064 + vfsub_update_h_iattr(&tmp, &did);
31066 + tmp.dentry = path->dentry->d_parent;
31067 + vfsub_update_h_iattr(&tmp, /*did*/NULL);
31076 +int vfsub_rmdir(struct inode *dir, struct path *path)
31079 + struct dentry *d;
31083 + d = path->dentry;
31084 + path->dentry = d->d_parent;
31085 + err = security_path_rmdir(path, d);
31086 + path->dentry = d;
31087 + if (unlikely(err))
31091 + err = vfs_rmdir(dir, path->dentry);
31094 + struct path tmp = {
31095 + .dentry = path->dentry->d_parent,
31099 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31106 +/* ---------------------------------------------------------------------- */
31108 +/* todo: support mmap_sem? */
31109 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31115 + err = vfs_read(file, ubuf, count, ppos);
31118 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31122 +/* todo: kernel_read()? */
31123 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31127 + mm_segment_t oldfs;
31134 + oldfs = get_fs();
31135 + set_fs(KERNEL_DS);
31136 + err = vfsub_read_u(file, buf.u, count, ppos);
31141 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31147 + err = vfs_write(file, ubuf, count, ppos);
31150 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31154 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos)
31157 + mm_segment_t oldfs;
31160 + const char __user *u;
31164 + oldfs = get_fs();
31165 + set_fs(KERNEL_DS);
31166 + err = vfsub_write_u(file, buf.u, count, ppos);
31171 +int vfsub_flush(struct file *file, fl_owner_t id)
31176 + if (file->f_op->flush) {
31177 + if (!au_test_nfs(file->f_path.dentry->d_sb))
31178 + err = file->f_op->flush(file, id);
31181 + err = file->f_op->flush(file, id);
31185 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL);
31191 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx)
31195 + AuDbg("%pD, ctx{%pf, %llu}\n", file, ctx->actor, ctx->pos);
31198 + err = iterate_dir(file, ctx);
31201 + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/
31205 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31206 + struct pipe_inode_info *pipe, size_t len,
31207 + unsigned int flags)
31212 + err = do_splice_to(in, ppos, pipe, len, flags);
31214 + file_accessed(in);
31216 + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/
31220 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31221 + loff_t *ppos, size_t len, unsigned int flags)
31226 + err = do_splice_from(pipe, out, ppos, len, flags);
31229 + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/
31233 +int vfsub_fsync(struct file *file, struct path *path, int datasync)
31237 + /* file can be NULL */
31239 + err = vfs_fsync(file, datasync);
31243 + AuDebugOn(!file);
31244 + path = &file->f_path;
31246 + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/
31251 +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */
31252 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31253 + struct file *h_file)
31256 + struct inode *h_inode;
31257 + struct super_block *h_sb;
31260 + err = vfsub_truncate(h_path, length);
31264 + h_inode = d_inode(h_path->dentry);
31265 + h_sb = h_inode->i_sb;
31267 + sb_start_write(h_sb);
31269 + err = locks_verify_truncate(h_inode, h_file, length);
31271 + err = security_path_truncate(h_path);
31274 + err = do_truncate(h_path->dentry, length, attr, h_file);
31278 + sb_end_write(h_sb);
31285 +/* ---------------------------------------------------------------------- */
31287 +struct au_vfsub_mkdir_args {
31289 + struct inode *dir;
31290 + struct path *path;
31294 +static void au_call_vfsub_mkdir(void *args)
31296 + struct au_vfsub_mkdir_args *a = args;
31297 + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode);
31300 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode)
31302 + int err, do_sio, wkq_err;
31304 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31307 + err = vfsub_mkdir(dir, path, mode);
31310 + struct au_vfsub_mkdir_args args = {
31316 + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args);
31317 + if (unlikely(wkq_err))
31324 +struct au_vfsub_rmdir_args {
31326 + struct inode *dir;
31327 + struct path *path;
31330 +static void au_call_vfsub_rmdir(void *args)
31332 + struct au_vfsub_rmdir_args *a = args;
31333 + *a->errp = vfsub_rmdir(a->dir, a->path);
31336 +int vfsub_sio_rmdir(struct inode *dir, struct path *path)
31338 + int err, do_sio, wkq_err;
31340 + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE);
31343 + err = vfsub_rmdir(dir, path);
31346 + struct au_vfsub_rmdir_args args = {
31351 + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args);
31352 + if (unlikely(wkq_err))
31359 +/* ---------------------------------------------------------------------- */
31361 +struct notify_change_args {
31363 + struct path *path;
31364 + struct iattr *ia;
31365 + struct inode **delegated_inode;
31368 +static void call_notify_change(void *args)
31370 + struct notify_change_args *a = args;
31371 + struct inode *h_inode;
31373 + h_inode = d_inode(a->path->dentry);
31374 + IMustLock(h_inode);
31376 + *a->errp = -EPERM;
31377 + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) {
31379 + *a->errp = notify_change(a->path->dentry, a->ia,
31380 + a->delegated_inode);
31383 + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/
31385 + AuTraceErr(*a->errp);
31388 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31389 + struct inode **delegated_inode)
31392 + struct notify_change_args args = {
31396 + .delegated_inode = delegated_inode
31399 + call_notify_change(&args);
31404 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31405 + struct inode **delegated_inode)
31407 + int err, wkq_err;
31408 + struct notify_change_args args = {
31412 + .delegated_inode = delegated_inode
31415 + wkq_err = au_wkq_wait(call_notify_change, &args);
31416 + if (unlikely(wkq_err))
31422 +/* ---------------------------------------------------------------------- */
31424 +struct unlink_args {
31426 + struct inode *dir;
31427 + struct path *path;
31428 + struct inode **delegated_inode;
31431 +static void call_unlink(void *args)
31433 + struct unlink_args *a = args;
31434 + struct dentry *d = a->path->dentry;
31435 + struct inode *h_inode;
31436 + const int stop_sillyrename = (au_test_nfs(d->d_sb)
31437 + && au_dcount(d) == 1);
31439 + IMustLock(a->dir);
31441 + a->path->dentry = d->d_parent;
31442 + *a->errp = security_path_unlink(a->path, d);
31443 + a->path->dentry = d;
31444 + if (unlikely(*a->errp))
31447 + if (!stop_sillyrename)
31450 + if (d_is_positive(d)) {
31451 + h_inode = d_inode(d);
31456 + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode);
31459 + struct path tmp = {
31460 + .dentry = d->d_parent,
31461 + .mnt = a->path->mnt
31463 + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/
31466 + if (!stop_sillyrename)
31471 + AuTraceErr(*a->errp);
31475 + * @dir: must be locked.
31476 + * @dentry: target dentry.
31478 +int vfsub_unlink(struct inode *dir, struct path *path,
31479 + struct inode **delegated_inode, int force)
31482 + struct unlink_args args = {
31486 + .delegated_inode = delegated_inode
31490 + call_unlink(&args);
31494 + wkq_err = au_wkq_wait(call_unlink, &args);
31495 + if (unlikely(wkq_err))
31501 diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h
31502 --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100
31503 +++ linux/fs/aufs/vfsub.h 2016-12-17 12:28:17.598545045 +0100
31506 + * Copyright (C) 2005-2016 Junjiro R. Okajima
31508 + * This program, aufs is free software; you can redistribute it and/or modify
31509 + * it under the terms of the GNU General Public License as published by
31510 + * the Free Software Foundation; either version 2 of the License, or
31511 + * (at your option) any later version.
31513 + * This program is distributed in the hope that it will be useful,
31514 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31515 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31516 + * GNU General Public License for more details.
31518 + * You should have received a copy of the GNU General Public License
31519 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31523 + * sub-routines for VFS
31526 +#ifndef __AUFS_VFSUB_H__
31527 +#define __AUFS_VFSUB_H__
31531 +#include <linux/fs.h>
31532 +#include <linux/mount.h>
31533 +#include <linux/posix_acl.h>
31534 +#include <linux/xattr.h>
31535 +#include "debug.h"
31537 +/* copied from linux/fs/internal.h */
31538 +/* todo: BAD approach!! */
31539 +extern void __mnt_drop_write(struct vfsmount *);
31540 +extern int open_check_o_direct(struct file *f);
31542 +/* ---------------------------------------------------------------------- */
31544 +/* lock subclass for lower inode */
31545 +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
31546 +/* reduce? gave up. */
31548 + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
31549 + AuLsc_I_PARENT, /* lower inode, parent first */
31550 + AuLsc_I_PARENT2, /* copyup dirs */
31551 + AuLsc_I_PARENT3, /* copyup wh */
31557 +/* to debug easier, do not make them inlined functions */
31558 +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx))
31559 +#define IMustLock(i) AuDebugOn(!inode_is_locked(i))
31561 +/* ---------------------------------------------------------------------- */
31563 +static inline void vfsub_drop_nlink(struct inode *inode)
31565 + AuDebugOn(!inode->i_nlink);
31566 + drop_nlink(inode);
31569 +static inline void vfsub_dead_dir(struct inode *inode)
31571 + AuDebugOn(!S_ISDIR(inode->i_mode));
31572 + inode->i_flags |= S_DEAD;
31573 + clear_nlink(inode);
31576 +static inline int vfsub_native_ro(struct inode *inode)
31578 + return (inode->i_sb->s_flags & MS_RDONLY)
31579 + || IS_RDONLY(inode)
31580 + /* || IS_APPEND(inode) */
31581 + || IS_IMMUTABLE(inode);
31584 +#ifdef CONFIG_AUFS_BR_FUSE
31585 +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
31587 +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
31590 +/* ---------------------------------------------------------------------- */
31592 +int vfsub_update_h_iattr(struct path *h_path, int *did);
31593 +struct file *vfsub_dentry_open(struct path *path, int flags);
31594 +struct file *vfsub_filp_open(const char *path, int oflags, int mode);
31595 +struct vfsub_aopen_args {
31596 + struct file *file;
31597 + unsigned int open_flag;
31598 + umode_t create_mode;
31602 +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
31603 + struct vfsub_aopen_args *args, struct au_branch *br);
31604 +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);
31606 +struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
31607 + struct dentry *parent, int len);
31608 +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
31611 +struct vfsub_lkup_one_args {
31612 + struct dentry **errp;
31613 + struct qstr *name;
31614 + struct dentry *parent;
31617 +static inline struct dentry *vfsub_lkup_one(struct qstr *name,
31618 + struct dentry *parent)
31620 + return vfsub_lookup_one_len(name->name, parent, name->len);
31623 +void vfsub_call_lkup_one(void *args);
31625 +/* ---------------------------------------------------------------------- */
31627 +static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
31632 + err = mnt_want_write(mnt);
31637 +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
31640 + mnt_drop_write(mnt);
31644 +#if 0 /* reserved */
31645 +static inline void vfsub_mnt_drop_write_file(struct file *file)
31648 + mnt_drop_write_file(file);
31653 +/* ---------------------------------------------------------------------- */
31656 +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
31657 + struct dentry *d2, struct au_hinode *hdir2);
31658 +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
31659 + struct dentry *d2, struct au_hinode *hdir2);
31661 +int vfsub_create(struct inode *dir, struct path *path, int mode,
31663 +int vfsub_symlink(struct inode *dir, struct path *path,
31664 + const char *symname);
31665 +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
31666 +int vfsub_link(struct dentry *src_dentry, struct inode *dir,
31667 + struct path *path, struct inode **delegated_inode);
31668 +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
31669 + struct inode *hdir, struct path *path,
31670 + struct inode **delegated_inode, unsigned int flags);
31671 +int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
31672 +int vfsub_rmdir(struct inode *dir, struct path *path);
31674 +/* ---------------------------------------------------------------------- */
31676 +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
31678 +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
31680 +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
31682 +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
31684 +int vfsub_flush(struct file *file, fl_owner_t id);
31685 +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
31687 +static inline loff_t vfsub_f_size_read(struct file *file)
31689 + return i_size_read(file_inode(file));
31692 +static inline unsigned int vfsub_file_flags(struct file *file)
31694 + unsigned int flags;
31696 + spin_lock(&file->f_lock);
31697 + flags = file->f_flags;
31698 + spin_unlock(&file->f_lock);
31703 +static inline int vfsub_file_execed(struct file *file)
31705 + /* todo: direct access f_flags */
31706 + return !!(vfsub_file_flags(file) & __FMODE_EXEC);
31709 +#if 0 /* reserved */
31710 +static inline void vfsub_file_accessed(struct file *h_file)
31712 + file_accessed(h_file);
31713 + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
31717 +#if 0 /* reserved */
31718 +static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
31719 + struct dentry *h_dentry)
31721 + struct path h_path = {
31722 + .dentry = h_dentry,
31725 + touch_atime(&h_path);
31726 + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
31730 +static inline int vfsub_update_time(struct inode *h_inode, struct timespec *ts,
31733 + return update_time(h_inode, ts, flags);
31734 + /* no vfsub_update_h_iattr() since we don't have struct path */
31737 +#ifdef CONFIG_FS_POSIX_ACL
31738 +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode)
31742 + err = posix_acl_chmod(h_inode, h_mode);
31743 + if (err == -EOPNOTSUPP)
31748 +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode);
31751 +long vfsub_splice_to(struct file *in, loff_t *ppos,
31752 + struct pipe_inode_info *pipe, size_t len,
31753 + unsigned int flags);
31754 +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
31755 + loff_t *ppos, size_t len, unsigned int flags);
31757 +static inline long vfsub_truncate(struct path *path, loff_t length)
31762 + err = vfs_truncate(path, length);
31767 +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
31768 + struct file *h_file);
31769 +int vfsub_fsync(struct file *file, struct path *path, int datasync);
31771 +/* ---------------------------------------------------------------------- */
31773 +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
31778 + err = vfs_llseek(file, offset, origin);
31783 +/* ---------------------------------------------------------------------- */
31785 +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
31786 +int vfsub_sio_rmdir(struct inode *dir, struct path *path);
31787 +int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
31788 + struct inode **delegated_inode);
31789 +int vfsub_notify_change(struct path *path, struct iattr *ia,
31790 + struct inode **delegated_inode);
31791 +int vfsub_unlink(struct inode *dir, struct path *path,
31792 + struct inode **delegated_inode, int force);
31794 +/* ---------------------------------------------------------------------- */
31796 +static inline int vfsub_setxattr(struct dentry *dentry, const char *name,
31797 + const void *value, size_t size, int flags)
31802 + err = vfs_setxattr(dentry, name, value, size, flags);
31808 +static inline int vfsub_removexattr(struct dentry *dentry, const char *name)
31813 + err = vfs_removexattr(dentry, name);
31819 +#endif /* __KERNEL__ */
31820 +#endif /* __AUFS_VFSUB_H__ */
31821 diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c
31822 --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100
31823 +++ linux/fs/aufs/wbr_policy.c 2016-12-17 12:28:17.598545045 +0100
31826 + * Copyright (C) 2005-2016 Junjiro R. Okajima
31828 + * This program, aufs is free software; you can redistribute it and/or modify
31829 + * it under the terms of the GNU General Public License as published by
31830 + * the Free Software Foundation; either version 2 of the License, or
31831 + * (at your option) any later version.
31833 + * This program is distributed in the hope that it will be useful,
31834 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31835 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31836 + * GNU General Public License for more details.
31838 + * You should have received a copy of the GNU General Public License
31839 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
31843 + * policies for selecting one among multiple writable branches
31846 +#include <linux/statfs.h>
31849 +/* subset of cpup_attr() */
31850 +static noinline_for_stack
31851 +int au_cpdown_attr(struct path *h_path, struct dentry *h_src)
31855 + struct inode *h_isrc;
31857 + h_isrc = d_inode(h_src);
31858 + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID;
31859 + ia.ia_mode = h_isrc->i_mode;
31860 + ia.ia_uid = h_isrc->i_uid;
31861 + ia.ia_gid = h_isrc->i_gid;
31862 + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID));
31863 + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags);
31864 + /* no delegation since it is just created */
31865 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31867 + /* is this nfs only? */
31868 + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) {
31869 + ia.ia_valid = ATTR_FORCE | ATTR_MODE;
31870 + ia.ia_mode = h_isrc->i_mode;
31871 + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL);
31877 +#define AuCpdown_PARENT_OPQ 1
31878 +#define AuCpdown_WHED (1 << 1)
31879 +#define AuCpdown_MADE_DIR (1 << 2)
31880 +#define AuCpdown_DIROPQ (1 << 3)
31881 +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name)
31882 +#define au_fset_cpdown(flags, name) \
31883 + do { (flags) |= AuCpdown_##name; } while (0)
31884 +#define au_fclr_cpdown(flags, name) \
31885 + do { (flags) &= ~AuCpdown_##name; } while (0)
31887 +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst,
31888 + unsigned int *flags)
31891 + struct dentry *opq_dentry;
31893 + opq_dentry = au_diropq_create(dentry, bdst);
31894 + err = PTR_ERR(opq_dentry);
31895 + if (IS_ERR(opq_dentry))
31897 + dput(opq_dentry);
31898 + au_fset_cpdown(*flags, DIROPQ);
31904 +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent,
31905 + struct inode *dir, aufs_bindex_t bdst)
31908 + struct path h_path;
31909 + struct au_branch *br;
31911 + br = au_sbr(dentry->d_sb, bdst);
31912 + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br);
31913 + err = PTR_ERR(h_path.dentry);
31914 + if (IS_ERR(h_path.dentry))
31918 + if (d_is_positive(h_path.dentry)) {
31919 + h_path.mnt = au_br_mnt(br);
31920 + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path,
31923 + dput(h_path.dentry);
31929 +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst,
31930 + struct au_pin *pin,
31931 + struct dentry *h_parent, void *arg)
31934 + aufs_bindex_t bopq, btop;
31935 + struct path h_path;
31936 + struct dentry *parent;
31937 + struct inode *h_dir, *h_inode, *inode, *dir;
31938 + unsigned int *flags = arg;
31940 + btop = au_dbtop(dentry);
31941 + /* dentry is di-locked */
31942 + parent = dget_parent(dentry);
31943 + dir = d_inode(parent);
31944 + h_dir = d_inode(h_parent);
31945 + AuDebugOn(h_dir != au_h_iptr(dir, bdst));
31946 + IMustLock(h_dir);
31948 + err = au_lkup_neg(dentry, bdst, /*wh*/0);
31949 + if (unlikely(err < 0))
31951 + h_path.dentry = au_h_dptr(dentry, bdst);
31952 + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst);
31953 + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path,
31954 + S_IRWXU | S_IRUGO | S_IXUGO);
31955 + if (unlikely(err))
31957 + au_fset_cpdown(*flags, MADE_DIR);
31959 + bopq = au_dbdiropq(dentry);
31960 + au_fclr_cpdown(*flags, WHED);
31961 + au_fclr_cpdown(*flags, DIROPQ);
31962 + if (au_dbwh(dentry) == bdst)
31963 + au_fset_cpdown(*flags, WHED);
31964 + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst)
31965 + au_fset_cpdown(*flags, PARENT_OPQ);
31966 + h_inode = d_inode(h_path.dentry);
31967 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31968 + if (au_ftest_cpdown(*flags, WHED)) {
31969 + err = au_cpdown_dir_opq(dentry, bdst, flags);
31970 + if (unlikely(err)) {
31971 + inode_unlock(h_inode);
31976 + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop));
31977 + inode_unlock(h_inode);
31978 + if (unlikely(err))
31981 + if (au_ftest_cpdown(*flags, WHED)) {
31982 + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst);
31983 + if (unlikely(err))
31987 + inode = d_inode(dentry);
31988 + if (au_ibbot(inode) < bdst)
31989 + au_set_ibbot(inode, bdst);
31990 + au_set_h_iptr(inode, bdst, au_igrab(h_inode),
31991 + au_hi_flags(inode, /*isdir*/1));
31992 + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0);
31993 + goto out; /* success */
31997 + if (au_ftest_cpdown(*flags, DIROPQ)) {
31998 + inode_lock_nested(h_inode, AuLsc_I_CHILD);
31999 + rerr = au_diropq_remove(dentry, bdst);
32000 + inode_unlock(h_inode);
32001 + if (unlikely(rerr)) {
32002 + AuIOErr("failed removing diropq for %pd b%d (%d)\n",
32003 + dentry, bdst, rerr);
32009 + if (au_ftest_cpdown(*flags, MADE_DIR)) {
32010 + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path);
32011 + if (unlikely(rerr)) {
32012 + AuIOErr("failed removing %pd b%d (%d)\n",
32013 + dentry, bdst, rerr);
32018 + au_set_h_dptr(dentry, bdst, NULL);
32019 + if (au_dbbot(dentry) == bdst)
32020 + au_update_dbbot(dentry);
32026 +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst)
32029 + unsigned int flags;
32032 + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags);
32037 +/* ---------------------------------------------------------------------- */
32039 +/* policies for create */
32041 +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex)
32043 + int err, i, j, ndentry;
32044 + aufs_bindex_t bopq;
32045 + struct au_dcsub_pages dpages;
32046 + struct au_dpage *dpage;
32047 + struct dentry **dentries, *parent, *d;
32049 + err = au_dpages_init(&dpages, GFP_NOFS);
32050 + if (unlikely(err))
32052 + parent = dget_parent(dentry);
32053 + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0);
32054 + if (unlikely(err))
32058 + for (i = 0; i < dpages.ndpage; i++) {
32059 + dpage = dpages.dpages + i;
32060 + dentries = dpage->dentries;
32061 + ndentry = dpage->ndentry;
32062 + for (j = 0; j < ndentry; j++) {
32064 + di_read_lock_parent2(d, !AuLock_IR);
32065 + bopq = au_dbdiropq(d);
32066 + di_read_unlock(d, !AuLock_IR);
32067 + if (bopq >= 0 && bopq < err)
32074 + au_dpages_free(&dpages);
32079 +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex)
32081 + for (; bindex >= 0; bindex--)
32082 + if (!au_br_rdonly(au_sbr(sb, bindex)))
32087 +/* top down parent */
32088 +static int au_wbr_create_tdp(struct dentry *dentry,
32089 + unsigned int flags __maybe_unused)
32092 + aufs_bindex_t btop, bindex;
32093 + struct super_block *sb;
32094 + struct dentry *parent, *h_parent;
32096 + sb = dentry->d_sb;
32097 + btop = au_dbtop(dentry);
32099 + if (!au_br_rdonly(au_sbr(sb, btop)))
32103 + parent = dget_parent(dentry);
32104 + for (bindex = au_dbtop(parent); bindex < btop; bindex++) {
32105 + h_parent = au_h_dptr(parent, bindex);
32106 + if (!h_parent || d_is_negative(h_parent))
32109 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32116 + /* bottom up here */
32117 + if (unlikely(err < 0)) {
32118 + err = au_wbr_bu(sb, btop - 1);
32120 + err = au_wbr_nonopq(dentry, err);
32124 + AuDbg("b%d\n", err);
32128 +/* ---------------------------------------------------------------------- */
32130 +/* an exception for the policy other than tdp */
32131 +static int au_wbr_create_exp(struct dentry *dentry)
32134 + aufs_bindex_t bwh, bdiropq;
32135 + struct dentry *parent;
32138 + bwh = au_dbwh(dentry);
32139 + parent = dget_parent(dentry);
32140 + bdiropq = au_dbdiropq(parent);
32142 + if (bdiropq >= 0)
32143 + err = min(bdiropq, bwh);
32146 + AuDbg("%d\n", err);
32147 + } else if (bdiropq >= 0) {
32149 + AuDbg("%d\n", err);
32154 + err = au_wbr_nonopq(dentry, err);
32156 + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err)))
32159 + AuDbg("%d\n", err);
32163 +/* ---------------------------------------------------------------------- */
32166 +static int au_wbr_create_init_rr(struct super_block *sb)
32170 + err = au_wbr_bu(sb, au_sbbot(sb));
32171 + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */
32174 + AuDbg("b%d\n", err);
32178 +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags)
32182 + aufs_bindex_t bindex, bbot;
32183 + struct super_block *sb;
32186 + err = au_wbr_create_exp(dentry);
32190 + sb = dentry->d_sb;
32191 + next = &au_sbi(sb)->si_wbr_rr_next;
32192 + bbot = au_sbbot(sb);
32194 + for (bindex = 0; bindex <= bbot; bindex++) {
32195 + if (!au_ftest_wbr(flags, DIR)) {
32196 + err = atomic_dec_return(next) + 1;
32197 + /* modulo for 0 is meaningless */
32198 + if (unlikely(!err))
32199 + err = atomic_dec_return(next) + 1;
32201 + err = atomic_read(next);
32202 + AuDbg("%d\n", err);
32205 + AuDbg("%d\n", err);
32206 + if (!au_br_rdonly(au_sbr(sb, err)))
32212 + err = au_wbr_nonopq(dentry, err);
32215 + AuDbg("%d\n", err);
32219 +/* ---------------------------------------------------------------------- */
32221 +/* most free space */
32222 +static void au_mfs(struct dentry *dentry, struct dentry *parent)
32224 + struct super_block *sb;
32225 + struct au_branch *br;
32226 + struct au_wbr_mfs *mfs;
32227 + struct dentry *h_parent;
32228 + aufs_bindex_t bindex, bbot;
32230 + unsigned long long b, bavail;
32231 + struct path h_path;
32232 + /* reduce the stack usage */
32233 + struct kstatfs *st;
32235 + st = kmalloc(sizeof(*st), GFP_NOFS);
32236 + if (unlikely(!st)) {
32237 + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM);
32242 + sb = dentry->d_sb;
32243 + mfs = &au_sbi(sb)->si_wbr_mfs;
32244 + MtxMustLock(&mfs->mfs_lock);
32245 + mfs->mfs_bindex = -EROFS;
32246 + mfs->mfsrr_bytes = 0;
32249 + bbot = au_sbbot(sb);
32251 + bindex = au_dbtop(parent);
32252 + bbot = au_dbtaildir(parent);
32255 + for (; bindex <= bbot; bindex++) {
32257 + h_parent = au_h_dptr(parent, bindex);
32258 + if (!h_parent || d_is_negative(h_parent))
32261 + br = au_sbr(sb, bindex);
32262 + if (au_br_rdonly(br))
32265 + /* sb->s_root for NFS is unreliable */
32266 + h_path.mnt = au_br_mnt(br);
32267 + h_path.dentry = h_path.mnt->mnt_root;
32268 + err = vfs_statfs(&h_path, st);
32269 + if (unlikely(err)) {
32270 + AuWarn1("failed statfs, b%d, %d\n", bindex, err);
32274 + /* when the available size is equal, select the lower one */
32275 + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail)
32276 + || sizeof(b) < sizeof(st->f_bsize));
32277 + b = st->f_bavail * st->f_bsize;
32278 + br->br_wbr->wbr_bytes = b;
32279 + if (b >= bavail) {
32281 + mfs->mfs_bindex = bindex;
32282 + mfs->mfs_jiffy = jiffies;
32286 + mfs->mfsrr_bytes = bavail;
32287 + AuDbg("b%d\n", mfs->mfs_bindex);
32288 + au_delayed_kfree(st);
32291 +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags)
32294 + struct dentry *parent;
32295 + struct super_block *sb;
32296 + struct au_wbr_mfs *mfs;
32298 + err = au_wbr_create_exp(dentry);
32302 + sb = dentry->d_sb;
32304 + if (au_ftest_wbr(flags, PARENT))
32305 + parent = dget_parent(dentry);
32306 + mfs = &au_sbi(sb)->si_wbr_mfs;
32307 + mutex_lock(&mfs->mfs_lock);
32308 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32309 + || mfs->mfs_bindex < 0
32310 + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex)))
32311 + au_mfs(dentry, parent);
32312 + mutex_unlock(&mfs->mfs_lock);
32313 + err = mfs->mfs_bindex;
32317 + err = au_wbr_nonopq(dentry, err);
32320 + AuDbg("b%d\n", err);
32324 +static int au_wbr_create_init_mfs(struct super_block *sb)
32326 + struct au_wbr_mfs *mfs;
32328 + mfs = &au_sbi(sb)->si_wbr_mfs;
32329 + mutex_init(&mfs->mfs_lock);
32330 + mfs->mfs_jiffy = 0;
32331 + mfs->mfs_bindex = -EROFS;
32336 +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused)
32338 + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock);
32342 +/* ---------------------------------------------------------------------- */
32344 +/* top down regardless parent, and then mfs */
32345 +static int au_wbr_create_tdmfs(struct dentry *dentry,
32346 + unsigned int flags __maybe_unused)
32349 + aufs_bindex_t bwh, btail, bindex, bfound, bmfs;
32350 + unsigned long long watermark;
32351 + struct super_block *sb;
32352 + struct au_wbr_mfs *mfs;
32353 + struct au_branch *br;
32354 + struct dentry *parent;
32356 + sb = dentry->d_sb;
32357 + mfs = &au_sbi(sb)->si_wbr_mfs;
32358 + mutex_lock(&mfs->mfs_lock);
32359 + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire)
32360 + || mfs->mfs_bindex < 0)
32361 + au_mfs(dentry, /*parent*/NULL);
32362 + watermark = mfs->mfsrr_watermark;
32363 + bmfs = mfs->mfs_bindex;
32364 + mutex_unlock(&mfs->mfs_lock);
32366 + /* another style of au_wbr_create_exp() */
32367 + bwh = au_dbwh(dentry);
32368 + parent = dget_parent(dentry);
32369 + btail = au_dbtaildir(parent);
32370 + if (bwh >= 0 && bwh < btail)
32373 + err = au_wbr_nonopq(dentry, btail);
32374 + if (unlikely(err < 0))
32378 + for (bindex = 0; bindex <= btail; bindex++) {
32379 + br = au_sbr(sb, bindex);
32380 + if (au_br_rdonly(br))
32382 + if (br->br_wbr->wbr_bytes > watermark) {
32393 + AuDbg("b%d\n", err);
32397 +/* ---------------------------------------------------------------------- */
32399 +/* most free space and then round robin */
32400 +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags)
32403 + struct au_wbr_mfs *mfs;
32405 + err = au_wbr_create_mfs(dentry, flags);
32407 + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs;
32408 + mutex_lock(&mfs->mfs_lock);
32409 + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark)
32410 + err = au_wbr_create_rr(dentry, flags);
32411 + mutex_unlock(&mfs->mfs_lock);
32414 + AuDbg("b%d\n", err);
32418 +static int au_wbr_create_init_mfsrr(struct super_block *sb)
32422 + au_wbr_create_init_mfs(sb); /* ignore */
32423 + err = au_wbr_create_init_rr(sb);
32428 +/* ---------------------------------------------------------------------- */
32430 +/* top down parent and most free space */
32431 +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags)
32434 + unsigned long long b;
32435 + aufs_bindex_t bindex, btop, bbot;
32436 + struct super_block *sb;
32437 + struct dentry *parent, *h_parent;
32438 + struct au_branch *br;
32440 + err = au_wbr_create_tdp(dentry, flags);
32441 + if (unlikely(err < 0))
32443 + parent = dget_parent(dentry);
32444 + btop = au_dbtop(parent);
32445 + bbot = au_dbtaildir(parent);
32446 + if (btop == bbot)
32447 + goto out_parent; /* success */
32449 + e2 = au_wbr_create_mfs(dentry, flags);
32451 + goto out_parent; /* success */
32453 + /* when the available size is equal, select upper one */
32454 + sb = dentry->d_sb;
32455 + br = au_sbr(sb, err);
32456 + b = br->br_wbr->wbr_bytes;
32457 + AuDbg("b%d, %llu\n", err, b);
32459 + for (bindex = btop; bindex <= bbot; bindex++) {
32460 + h_parent = au_h_dptr(parent, bindex);
32461 + if (!h_parent || d_is_negative(h_parent))
32464 + br = au_sbr(sb, bindex);
32465 + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) {
32466 + b = br->br_wbr->wbr_bytes;
32468 + AuDbg("b%d, %llu\n", err, b);
32473 + err = au_wbr_nonopq(dentry, err);
32478 + AuDbg("b%d\n", err);
32482 +/* ---------------------------------------------------------------------- */
32485 + * - top down parent
32486 + * - most free space with parent
32487 + * - most free space round-robin regardless parent
32489 +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags)
32492 + unsigned long long watermark;
32493 + struct super_block *sb;
32494 + struct au_branch *br;
32495 + struct au_wbr_mfs *mfs;
32497 + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT);
32498 + if (unlikely(err < 0))
32501 + sb = dentry->d_sb;
32502 + br = au_sbr(sb, err);
32503 + mfs = &au_sbi(sb)->si_wbr_mfs;
32504 + mutex_lock(&mfs->mfs_lock);
32505 + watermark = mfs->mfsrr_watermark;
32506 + mutex_unlock(&mfs->mfs_lock);
32507 + if (br->br_wbr->wbr_bytes < watermark)
32508 + /* regardless the parent dir */
32509 + err = au_wbr_create_mfsrr(dentry, flags);
32512 + AuDbg("b%d\n", err);
32516 +/* ---------------------------------------------------------------------- */
32518 +/* policies for copyup */
32520 +/* top down parent */
32521 +static int au_wbr_copyup_tdp(struct dentry *dentry)
32523 + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0);
32526 +/* bottom up parent */
32527 +static int au_wbr_copyup_bup(struct dentry *dentry)
32530 + aufs_bindex_t bindex, btop;
32531 + struct dentry *parent, *h_parent;
32532 + struct super_block *sb;
32535 + sb = dentry->d_sb;
32536 + parent = dget_parent(dentry);
32537 + btop = au_dbtop(parent);
32538 + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) {
32539 + h_parent = au_h_dptr(parent, bindex);
32540 + if (!h_parent || d_is_negative(h_parent))
32543 + if (!au_br_rdonly(au_sbr(sb, bindex))) {
32550 + /* bottom up here */
32551 + if (unlikely(err < 0))
32552 + err = au_wbr_bu(sb, btop - 1);
32554 + AuDbg("b%d\n", err);
32559 +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop)
32563 + err = au_wbr_bu(dentry->d_sb, btop);
32564 + AuDbg("b%d\n", err);
32566 + err = au_wbr_nonopq(dentry, err);
32568 + AuDbg("b%d\n", err);
32572 +static int au_wbr_copyup_bu(struct dentry *dentry)
32575 + aufs_bindex_t btop;
32577 + btop = au_dbtop(dentry);
32578 + err = au_wbr_do_copyup_bu(dentry, btop);
32582 +/* ---------------------------------------------------------------------- */
32584 +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = {
32585 + [AuWbrCopyup_TDP] = {
32586 + .copyup = au_wbr_copyup_tdp
32588 + [AuWbrCopyup_BUP] = {
32589 + .copyup = au_wbr_copyup_bup
32591 + [AuWbrCopyup_BU] = {
32592 + .copyup = au_wbr_copyup_bu
32596 +struct au_wbr_create_operations au_wbr_create_ops[] = {
32597 + [AuWbrCreate_TDP] = {
32598 + .create = au_wbr_create_tdp
32600 + [AuWbrCreate_RR] = {
32601 + .create = au_wbr_create_rr,
32602 + .init = au_wbr_create_init_rr
32604 + [AuWbrCreate_MFS] = {
32605 + .create = au_wbr_create_mfs,
32606 + .init = au_wbr_create_init_mfs,
32607 + .fin = au_wbr_create_fin_mfs
32609 + [AuWbrCreate_MFSV] = {
32610 + .create = au_wbr_create_mfs,
32611 + .init = au_wbr_create_init_mfs,
32612 + .fin = au_wbr_create_fin_mfs
32614 + [AuWbrCreate_MFSRR] = {
32615 + .create = au_wbr_create_mfsrr,
32616 + .init = au_wbr_create_init_mfsrr,
32617 + .fin = au_wbr_create_fin_mfs
32619 + [AuWbrCreate_MFSRRV] = {
32620 + .create = au_wbr_create_mfsrr,
32621 + .init = au_wbr_create_init_mfsrr,
32622 + .fin = au_wbr_create_fin_mfs
32624 + [AuWbrCreate_TDMFS] = {
32625 + .create = au_wbr_create_tdmfs,
32626 + .init = au_wbr_create_init_mfs,
32627 + .fin = au_wbr_create_fin_mfs
32629 + [AuWbrCreate_TDMFSV] = {
32630 + .create = au_wbr_create_tdmfs,
32631 + .init = au_wbr_create_init_mfs,
32632 + .fin = au_wbr_create_fin_mfs
32634 + [AuWbrCreate_PMFS] = {
32635 + .create = au_wbr_create_pmfs,
32636 + .init = au_wbr_create_init_mfs,
32637 + .fin = au_wbr_create_fin_mfs
32639 + [AuWbrCreate_PMFSV] = {
32640 + .create = au_wbr_create_pmfs,
32641 + .init = au_wbr_create_init_mfs,
32642 + .fin = au_wbr_create_fin_mfs
32644 + [AuWbrCreate_PMFSRR] = {
32645 + .create = au_wbr_create_pmfsrr,
32646 + .init = au_wbr_create_init_mfsrr,
32647 + .fin = au_wbr_create_fin_mfs
32649 + [AuWbrCreate_PMFSRRV] = {
32650 + .create = au_wbr_create_pmfsrr,
32651 + .init = au_wbr_create_init_mfsrr,
32652 + .fin = au_wbr_create_fin_mfs
32655 diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c
32656 --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100
32657 +++ linux/fs/aufs/whout.c 2016-12-17 12:28:17.598545045 +0100
32660 + * Copyright (C) 2005-2016 Junjiro R. Okajima
32662 + * This program, aufs is free software; you can redistribute it and/or modify
32663 + * it under the terms of the GNU General Public License as published by
32664 + * the Free Software Foundation; either version 2 of the License, or
32665 + * (at your option) any later version.
32667 + * This program is distributed in the hope that it will be useful,
32668 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32669 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32670 + * GNU General Public License for more details.
32672 + * You should have received a copy of the GNU General Public License
32673 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
32677 + * whiteout for logical deletion and opaque directory
32682 +#define WH_MASK S_IRUGO
32685 + * If a directory contains this file, then it is opaque. We start with the
32686 + * .wh. flag so that it is blocked by lookup.
32688 +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ,
32689 + sizeof(AUFS_WH_DIROPQ) - 1);
32692 + * generate whiteout name, which is NOT terminated by NULL.
32693 + * @name: original d_name.name
32694 + * @len: original d_name.len
32695 + * @wh: whiteout qstr
32696 + * returns zero when succeeds, otherwise error.
32697 + * succeeded value as wh->name should be freed by kfree().
32699 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name)
32703 + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN))
32704 + return -ENAMETOOLONG;
32706 + wh->len = name->len + AUFS_WH_PFX_LEN;
32707 + p = kmalloc(wh->len, GFP_NOFS);
32710 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
32711 + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len);
32718 +/* ---------------------------------------------------------------------- */
32721 + * test if the @wh_name exists under @h_parent.
32722 + * @try_sio specifies the necessary of super-io.
32724 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio)
32727 + struct dentry *wh_dentry;
32730 + wh_dentry = vfsub_lkup_one(wh_name, h_parent);
32732 + wh_dentry = au_sio_lkup_one(wh_name, h_parent);
32733 + err = PTR_ERR(wh_dentry);
32734 + if (IS_ERR(wh_dentry)) {
32735 + if (err == -ENAMETOOLONG)
32741 + if (d_is_negative(wh_dentry))
32742 + goto out_wh; /* success */
32745 + if (d_is_reg(wh_dentry))
32746 + goto out_wh; /* success */
32749 + AuIOErr("%pd Invalid whiteout entry type 0%o.\n",
32750 + wh_dentry, d_inode(wh_dentry)->i_mode);
32759 + * test if the @h_dentry sets opaque or not.
32761 +int au_diropq_test(struct dentry *h_dentry)
32764 + struct inode *h_dir;
32766 + h_dir = d_inode(h_dentry);
32767 + err = au_wh_test(h_dentry, &diropq_name,
32768 + au_test_h_perm_sio(h_dir, MAY_EXEC));
32773 + * returns a negative dentry whose name is unique and temporary.
32775 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
32776 + struct qstr *prefix)
32778 + struct dentry *dentry;
32780 + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1],
32782 + /* strict atomic_t is unnecessary here */
32783 + static unsigned short cnt;
32786 + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN);
32789 + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1;
32790 + if (unlikely(prefix->len > DNAME_INLINE_LEN)) {
32791 + dentry = ERR_PTR(-ENAMETOOLONG);
32792 + if (unlikely(qs.len > NAME_MAX))
32794 + dentry = ERR_PTR(-ENOMEM);
32795 + name = kmalloc(qs.len + 1, GFP_NOFS);
32796 + if (unlikely(!name))
32800 + /* doubly whiteout-ed */
32801 + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2);
32802 + p = name + AUFS_WH_PFX_LEN * 2;
32803 + memcpy(p, prefix->name, prefix->len);
32804 + p += prefix->len;
32806 + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN);
32809 + for (i = 0; i < 3; i++) {
32810 + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++);
32811 + dentry = au_sio_lkup_one(&qs, h_parent);
32812 + if (IS_ERR(dentry) || d_is_negative(dentry))
32816 + /* pr_warn("could not get random name\n"); */
32817 + dentry = ERR_PTR(-EEXIST);
32818 + AuDbg("%.*s\n", AuLNPair(&qs));
32822 + if (name != defname)
32823 + au_delayed_kfree(name);
32825 + AuTraceErrPtr(dentry);
32830 + * rename the @h_dentry on @br to the whiteouted temporary name.
32832 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br)
32835 + struct path h_path = {
32836 + .mnt = au_br_mnt(br)
32838 + struct inode *h_dir, *delegated;
32839 + struct dentry *h_parent;
32841 + h_parent = h_dentry->d_parent; /* dir inode is locked */
32842 + h_dir = d_inode(h_parent);
32843 + IMustLock(h_dir);
32845 + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name);
32846 + err = PTR_ERR(h_path.dentry);
32847 + if (IS_ERR(h_path.dentry))
32850 + /* under the same dir, no need to lock_rename() */
32851 + delegated = NULL;
32852 + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated,
32855 + if (unlikely(err == -EWOULDBLOCK)) {
32856 + pr_warn("cannot retry for NFSv4 delegation"
32857 + " for an internal rename\n");
32860 + dput(h_path.dentry);
32867 +/* ---------------------------------------------------------------------- */
32869 + * functions for removing a whiteout
32872 +static int do_unlink_wh(struct inode *h_dir, struct path *h_path)
32875 + struct inode *delegated;
32878 + * forces superio when the dir has a sticky bit.
32879 + * this may be a violation of unix fs semantics.
32881 + force = (h_dir->i_mode & S_ISVTX)
32882 + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid);
32883 + delegated = NULL;
32884 + err = vfsub_unlink(h_dir, h_path, &delegated, force);
32885 + if (unlikely(err == -EWOULDBLOCK)) {
32886 + pr_warn("cannot retry for NFSv4 delegation"
32887 + " for an internal unlink\n");
32893 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
32894 + struct dentry *dentry)
32898 + err = do_unlink_wh(h_dir, h_path);
32899 + if (!err && dentry)
32900 + au_set_dbwh(dentry, -1);
32905 +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh,
32906 + struct au_branch *br)
32909 + struct path h_path = {
32910 + .mnt = au_br_mnt(br)
32914 + h_path.dentry = vfsub_lkup_one(wh, h_parent);
32915 + if (IS_ERR(h_path.dentry))
32916 + err = PTR_ERR(h_path.dentry);
32918 + if (d_is_reg(h_path.dentry))
32919 + err = do_unlink_wh(d_inode(h_parent), &h_path);
32920 + dput(h_path.dentry);
32926 +/* ---------------------------------------------------------------------- */
32928 + * initialize/clean whiteout for a branch
32931 +static void au_wh_clean(struct inode *h_dir, struct path *whpath,
32935 + struct inode *delegated;
32937 + if (d_is_negative(whpath->dentry))
32941 + err = vfsub_rmdir(h_dir, whpath);
32943 + delegated = NULL;
32944 + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0);
32945 + if (unlikely(err == -EWOULDBLOCK)) {
32946 + pr_warn("cannot retry for NFSv4 delegation"
32947 + " for an internal unlink\n");
32951 + if (unlikely(err))
32952 + pr_warn("failed removing %pd (%d), ignored.\n",
32953 + whpath->dentry, err);
32956 +static int test_linkable(struct dentry *h_root)
32958 + struct inode *h_dir = d_inode(h_root);
32960 + if (h_dir->i_op->link)
32963 + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n",
32964 + h_root, au_sbtype(h_root->d_sb));
32968 +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */
32969 +static int au_whdir(struct inode *h_dir, struct path *path)
32974 + if (d_is_negative(path->dentry)) {
32975 + int mode = S_IRWXU;
32977 + if (au_test_nfs(path->dentry->d_sb))
32979 + err = vfsub_mkdir(h_dir, path, mode);
32980 + } else if (d_is_dir(path->dentry))
32983 + pr_err("unknown %pd exists\n", path->dentry);
32988 +struct au_wh_base {
32989 + const struct qstr *name;
32990 + struct dentry *dentry;
32993 +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[],
32994 + struct path *h_path)
32996 + h_path->dentry = base[AuBrWh_BASE].dentry;
32997 + au_wh_clean(h_dir, h_path, /*isdir*/0);
32998 + h_path->dentry = base[AuBrWh_PLINK].dentry;
32999 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33000 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33001 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33005 + * returns tri-state,
33006 + * minus: error, caller should print the message
33008 + * plus: error, caller should NOT print the message
33010 +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr,
33011 + int do_plink, struct au_wh_base base[],
33012 + struct path *h_path)
33015 + struct inode *h_dir;
33017 + h_dir = d_inode(h_root);
33018 + h_path->dentry = base[AuBrWh_BASE].dentry;
33019 + au_wh_clean(h_dir, h_path, /*isdir*/0);
33020 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33022 + err = test_linkable(h_root);
33023 + if (unlikely(err)) {
33028 + err = au_whdir(h_dir, h_path);
33029 + if (unlikely(err))
33031 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33033 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33034 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33035 + err = au_whdir(h_dir, h_path);
33036 + if (unlikely(err))
33038 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33045 + * for the moment, aufs supports the branch filesystem which does not support
33046 + * link(2). testing on FAT which does not support i_op->setattr() fully either,
33047 + * copyup failed. finally, such filesystem will not be used as the writable
33050 + * returns tri-state, see above.
33052 +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr,
33053 + int do_plink, struct au_wh_base base[],
33054 + struct path *h_path)
33057 + struct inode *h_dir;
33059 + WbrWhMustWriteLock(wbr);
33061 + err = test_linkable(h_root);
33062 + if (unlikely(err)) {
33068 + * todo: should this create be done in /sbin/mount.aufs helper?
33071 + h_dir = d_inode(h_root);
33072 + if (d_is_negative(base[AuBrWh_BASE].dentry)) {
33073 + h_path->dentry = base[AuBrWh_BASE].dentry;
33074 + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true);
33075 + } else if (d_is_reg(base[AuBrWh_BASE].dentry))
33078 + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry);
33079 + if (unlikely(err))
33082 + h_path->dentry = base[AuBrWh_PLINK].dentry;
33084 + err = au_whdir(h_dir, h_path);
33085 + if (unlikely(err))
33087 + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry);
33089 + au_wh_clean(h_dir, h_path, /*isdir*/1);
33090 + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry);
33092 + h_path->dentry = base[AuBrWh_ORPH].dentry;
33093 + err = au_whdir(h_dir, h_path);
33094 + if (unlikely(err))
33096 + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry);
33103 + * initialize the whiteout base file/dir for @br.
33105 +int au_wh_init(struct au_branch *br, struct super_block *sb)
33108 + const unsigned char do_plink
33109 + = !!au_opt_test(au_mntflags(sb), PLINK);
33110 + struct inode *h_dir;
33111 + struct path path = br->br_path;
33112 + struct dentry *h_root = path.dentry;
33113 + struct au_wbr *wbr = br->br_wbr;
33114 + static const struct qstr base_name[] = {
33115 + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME,
33116 + sizeof(AUFS_BASE_NAME) - 1),
33117 + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME,
33118 + sizeof(AUFS_PLINKDIR_NAME) - 1),
33119 + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME,
33120 + sizeof(AUFS_ORPHDIR_NAME) - 1)
33122 + struct au_wh_base base[] = {
33123 + [AuBrWh_BASE] = {
33124 + .name = base_name + AuBrWh_BASE,
33127 + [AuBrWh_PLINK] = {
33128 + .name = base_name + AuBrWh_PLINK,
33131 + [AuBrWh_ORPH] = {
33132 + .name = base_name + AuBrWh_ORPH,
33138 + WbrWhMustWriteLock(wbr);
33140 + for (i = 0; i < AuBrWh_Last; i++) {
33141 + /* doubly whiteouted */
33142 + struct dentry *d;
33144 + d = au_wh_lkup(h_root, (void *)base[i].name, br);
33145 + err = PTR_ERR(d);
33149 + base[i].dentry = d;
33151 + && wbr->wbr_wh[i]
33152 + && wbr->wbr_wh[i] != base[i].dentry);
33156 + for (i = 0; i < AuBrWh_Last; i++) {
33157 + dput(wbr->wbr_wh[i]);
33158 + wbr->wbr_wh[i] = NULL;
33162 + if (!au_br_writable(br->br_perm)) {
33163 + h_dir = d_inode(h_root);
33164 + au_wh_init_ro(h_dir, base, &path);
33165 + } else if (!au_br_wh_linkable(br->br_perm)) {
33166 + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path);
33172 + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path);
33178 + goto out; /* success */
33181 + pr_err("an error(%d) on the writable branch %pd(%s)\n",
33182 + err, h_root, au_sbtype(h_root->d_sb));
33184 + for (i = 0; i < AuBrWh_Last; i++)
33185 + dput(base[i].dentry);
33189 +/* ---------------------------------------------------------------------- */
33191 + * whiteouts are all hard-linked usually.
33192 + * when its link count reaches a ceiling, we create a new whiteout base
33193 + * asynchronously.
33196 +struct reinit_br_wh {
33197 + struct super_block *sb;
33198 + struct au_branch *br;
33201 +static void reinit_br_wh(void *arg)
33204 + aufs_bindex_t bindex;
33205 + struct path h_path;
33206 + struct reinit_br_wh *a = arg;
33207 + struct au_wbr *wbr;
33208 + struct inode *dir, *delegated;
33209 + struct dentry *h_root;
33210 + struct au_hinode *hdir;
33213 + wbr = a->br->br_wbr;
33214 + /* big aufs lock */
33215 + si_noflush_write_lock(a->sb);
33216 + if (!au_br_writable(a->br->br_perm))
33218 + bindex = au_br_index(a->sb, a->br->br_id);
33219 + if (unlikely(bindex < 0))
33222 + di_read_lock_parent(a->sb->s_root, AuLock_IR);
33223 + dir = d_inode(a->sb->s_root);
33224 + hdir = au_hi(dir, bindex);
33225 + h_root = au_h_dptr(a->sb->s_root, bindex);
33226 + AuDebugOn(h_root != au_br_dentry(a->br));
33228 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33229 + wbr_wh_write_lock(wbr);
33230 + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode,
33233 + h_path.dentry = wbr->wbr_whbase;
33234 + h_path.mnt = au_br_mnt(a->br);
33235 + delegated = NULL;
33236 + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated,
33238 + if (unlikely(err == -EWOULDBLOCK)) {
33239 + pr_warn("cannot retry for NFSv4 delegation"
33240 + " for an internal unlink\n");
33244 + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase);
33247 + dput(wbr->wbr_whbase);
33248 + wbr->wbr_whbase = NULL;
33250 + err = au_wh_init(a->br, a->sb);
33251 + wbr_wh_write_unlock(wbr);
33252 + au_hn_inode_unlock(hdir);
33253 + di_read_unlock(a->sb->s_root, AuLock_IR);
33255 + au_fhsm_wrote(a->sb, bindex, /*force*/0);
33259 + atomic_dec(&wbr->wbr_wh_running);
33260 + au_br_put(a->br);
33261 + si_write_unlock(a->sb);
33262 + au_nwt_done(&au_sbi(a->sb)->si_nowait);
33263 + au_delayed_kfree(arg);
33264 + if (unlikely(err))
33265 + AuIOErr("err %d\n", err);
33268 +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br)
33270 + int do_dec, wkq_err;
33271 + struct reinit_br_wh *arg;
33274 + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1)
33277 + /* ignore ENOMEM */
33278 + arg = kmalloc(sizeof(*arg), GFP_NOFS);
33281 + * dec(wh_running), kfree(arg) and dec(br_count)
33282 + * in reinit function
33287 + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0);
33288 + if (unlikely(wkq_err)) {
33289 + atomic_dec(&br->br_wbr->wbr_wh_running);
33291 + au_delayed_kfree(arg);
33298 + atomic_dec(&br->br_wbr->wbr_wh_running);
33301 +/* ---------------------------------------------------------------------- */
33304 + * create the whiteout @wh.
33306 +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex,
33307 + struct dentry *wh)
33310 + struct path h_path = {
33313 + struct au_branch *br;
33314 + struct au_wbr *wbr;
33315 + struct dentry *h_parent;
33316 + struct inode *h_dir, *delegated;
33318 + h_parent = wh->d_parent; /* dir inode is locked */
33319 + h_dir = d_inode(h_parent);
33320 + IMustLock(h_dir);
33322 + br = au_sbr(sb, bindex);
33323 + h_path.mnt = au_br_mnt(br);
33324 + wbr = br->br_wbr;
33325 + wbr_wh_read_lock(wbr);
33326 + if (wbr->wbr_whbase) {
33327 + delegated = NULL;
33328 + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated);
33329 + if (unlikely(err == -EWOULDBLOCK)) {
33330 + pr_warn("cannot retry for NFSv4 delegation"
33331 + " for an internal link\n");
33334 + if (!err || err != -EMLINK)
33337 + /* link count full. re-initialize br_whbase. */
33338 + kick_reinit_br_wh(sb, br);
33341 + /* return this error in this context */
33342 + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true);
33344 + au_fhsm_wrote(sb, bindex, /*force*/0);
33347 + wbr_wh_read_unlock(wbr);
33351 +/* ---------------------------------------------------------------------- */
33354 + * create or remove the diropq.
33356 +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex,
33357 + unsigned int flags)
33359 + struct dentry *opq_dentry, *h_dentry;
33360 + struct super_block *sb;
33361 + struct au_branch *br;
33364 + sb = dentry->d_sb;
33365 + br = au_sbr(sb, bindex);
33366 + h_dentry = au_h_dptr(dentry, bindex);
33367 + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry);
33368 + if (IS_ERR(opq_dentry))
33371 + if (au_ftest_diropq(flags, CREATE)) {
33372 + err = link_or_create_wh(sb, bindex, opq_dentry);
33374 + au_set_dbdiropq(dentry, bindex);
33375 + goto out; /* success */
33378 + struct path tmp = {
33379 + .dentry = opq_dentry,
33380 + .mnt = au_br_mnt(br)
33382 + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp);
33384 + au_set_dbdiropq(dentry, -1);
33386 + dput(opq_dentry);
33387 + opq_dentry = ERR_PTR(err);
33390 + return opq_dentry;
33393 +struct do_diropq_args {
33394 + struct dentry **errp;
33395 + struct dentry *dentry;
33396 + aufs_bindex_t bindex;
33397 + unsigned int flags;
33400 +static void call_do_diropq(void *args)
33402 + struct do_diropq_args *a = args;
33403 + *a->errp = do_diropq(a->dentry, a->bindex, a->flags);
33406 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33407 + unsigned int flags)
33409 + struct dentry *diropq, *h_dentry;
33411 + h_dentry = au_h_dptr(dentry, bindex);
33412 + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE))
33413 + diropq = do_diropq(dentry, bindex, flags);
33416 + struct do_diropq_args args = {
33418 + .dentry = dentry,
33419 + .bindex = bindex,
33423 + wkq_err = au_wkq_wait(call_do_diropq, &args);
33424 + if (unlikely(wkq_err))
33425 + diropq = ERR_PTR(wkq_err);
33431 +/* ---------------------------------------------------------------------- */
33434 + * lookup whiteout dentry.
33435 + * @h_parent: lower parent dentry which must exist and be locked
33436 + * @base_name: name of dentry which will be whiteouted
33437 + * returns dentry for whiteout.
33439 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33440 + struct au_branch *br)
33443 + struct qstr wh_name;
33444 + struct dentry *wh_dentry;
33446 + err = au_wh_name_alloc(&wh_name, base_name);
33447 + wh_dentry = ERR_PTR(err);
33449 + wh_dentry = vfsub_lkup_one(&wh_name, h_parent);
33450 + au_delayed_kfree(wh_name.name);
33452 + return wh_dentry;
33456 + * link/create a whiteout for @dentry on @bindex.
33458 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33459 + struct dentry *h_parent)
33461 + struct dentry *wh_dentry;
33462 + struct super_block *sb;
33465 + sb = dentry->d_sb;
33466 + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex));
33467 + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) {
33468 + err = link_or_create_wh(sb, bindex, wh_dentry);
33470 + au_set_dbwh(dentry, bindex);
33471 + au_fhsm_wrote(sb, bindex, /*force*/0);
33474 + wh_dentry = ERR_PTR(err);
33478 + return wh_dentry;
33481 +/* ---------------------------------------------------------------------- */
33483 +/* Delete all whiteouts in this directory on branch bindex. */
33484 +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist,
33485 + aufs_bindex_t bindex, struct au_branch *br)
33488 + unsigned long ul, n;
33489 + struct qstr wh_name;
33491 + struct hlist_head *head;
33492 + struct au_vdir_wh *pos;
33493 + struct au_vdir_destr *str;
33496 + p = (void *)__get_free_page(GFP_NOFS);
33497 + wh_name.name = p;
33498 + if (unlikely(!wh_name.name))
33502 + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN);
33503 + p += AUFS_WH_PFX_LEN;
33504 + n = whlist->nh_num;
33505 + head = whlist->nh_head;
33506 + for (ul = 0; !err && ul < n; ul++, head++) {
33507 + hlist_for_each_entry(pos, head, wh_hash) {
33508 + if (pos->wh_bindex != bindex)
33511 + str = &pos->wh_str;
33512 + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) {
33513 + memcpy(p, str->name, str->len);
33514 + wh_name.len = AUFS_WH_PFX_LEN + str->len;
33515 + err = unlink_wh_name(h_dentry, &wh_name, br);
33520 + AuIOErr("whiteout name too long %.*s\n",
33521 + str->len, str->name);
33526 + au_delayed_free_page((unsigned long)wh_name.name);
33532 +struct del_wh_children_args {
33534 + struct dentry *h_dentry;
33535 + struct au_nhash *whlist;
33536 + aufs_bindex_t bindex;
33537 + struct au_branch *br;
33540 +static void call_del_wh_children(void *args)
33542 + struct del_wh_children_args *a = args;
33543 + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br);
33546 +/* ---------------------------------------------------------------------- */
33548 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp)
33550 + struct au_whtmp_rmdir *whtmp;
33552 + unsigned int rdhash;
33554 + SiMustAnyLock(sb);
33556 + whtmp = kzalloc(sizeof(*whtmp), gfp);
33557 + if (unlikely(!whtmp)) {
33558 + whtmp = ERR_PTR(-ENOMEM);
33562 + /* no estimation for dir size */
33563 + rdhash = au_sbi(sb)->si_rdhash;
33565 + rdhash = AUFS_RDHASH_DEF;
33566 + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp);
33567 + if (unlikely(err)) {
33568 + au_delayed_kfree(whtmp);
33569 + whtmp = ERR_PTR(err);
33576 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp)
33579 + au_br_put(whtmp->br);
33580 + dput(whtmp->wh_dentry);
33581 + iput(whtmp->dir);
33582 + au_nhash_wh_free(&whtmp->whlist);
33583 + au_delayed_kfree(whtmp);
33587 + * rmdir the whiteouted temporary named dir @h_dentry.
33588 + * @whlist: whiteouted children.
33590 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33591 + struct dentry *wh_dentry, struct au_nhash *whlist)
33594 + unsigned int h_nlink;
33595 + struct path h_tmp;
33596 + struct inode *wh_inode, *h_dir;
33597 + struct au_branch *br;
33599 + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */
33600 + IMustLock(h_dir);
33602 + br = au_sbr(dir->i_sb, bindex);
33603 + wh_inode = d_inode(wh_dentry);
33604 + inode_lock_nested(wh_inode, AuLsc_I_CHILD);
33607 + * someone else might change some whiteouts while we were sleeping.
33608 + * it means this whlist may have an obsoleted entry.
33610 + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE))
33611 + err = del_wh_children(wh_dentry, whlist, bindex, br);
33614 + struct del_wh_children_args args = {
33616 + .h_dentry = wh_dentry,
33617 + .whlist = whlist,
33618 + .bindex = bindex,
33622 + wkq_err = au_wkq_wait(call_del_wh_children, &args);
33623 + if (unlikely(wkq_err))
33626 + inode_unlock(wh_inode);
33629 + h_tmp.dentry = wh_dentry;
33630 + h_tmp.mnt = au_br_mnt(br);
33631 + h_nlink = h_dir->i_nlink;
33632 + err = vfsub_rmdir(h_dir, &h_tmp);
33633 + /* some fs doesn't change the parent nlink in some cases */
33634 + h_nlink -= h_dir->i_nlink;
33638 + if (au_ibtop(dir) == bindex) {
33639 + /* todo: dir->i_mutex is necessary */
33640 + au_cpup_attr_timesizes(dir);
33642 + vfsub_drop_nlink(dir);
33644 + return 0; /* success */
33647 + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err);
33651 +static void call_rmdir_whtmp(void *args)
33654 + aufs_bindex_t bindex;
33655 + struct au_whtmp_rmdir *a = args;
33656 + struct super_block *sb;
33657 + struct dentry *h_parent;
33658 + struct inode *h_dir;
33659 + struct au_hinode *hdir;
33661 + /* rmdir by nfsd may cause deadlock with this i_mutex */
33662 + /* inode_lock(a->dir); */
33664 + sb = a->dir->i_sb;
33665 + si_read_lock(sb, !AuLock_FLUSH);
33666 + if (!au_br_writable(a->br->br_perm))
33668 + bindex = au_br_index(sb, a->br->br_id);
33669 + if (unlikely(bindex < 0))
33673 + ii_write_lock_parent(a->dir);
33674 + h_parent = dget_parent(a->wh_dentry);
33675 + h_dir = d_inode(h_parent);
33676 + hdir = au_hi(a->dir, bindex);
33677 + err = vfsub_mnt_want_write(au_br_mnt(a->br));
33678 + if (unlikely(err))
33680 + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT);
33681 + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent,
33684 + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist);
33685 + au_hn_inode_unlock(hdir);
33686 + vfsub_mnt_drop_write(au_br_mnt(a->br));
33690 + ii_write_unlock(a->dir);
33692 + /* inode_unlock(a->dir); */
33693 + au_whtmp_rmdir_free(a);
33694 + si_read_unlock(sb);
33695 + au_nwt_done(&au_sbi(sb)->si_nowait);
33696 + if (unlikely(err))
33697 + AuIOErr("err %d\n", err);
33700 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33701 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args)
33704 + struct super_block *sb;
33708 + /* all post-process will be done in do_rmdir_whtmp(). */
33710 + args->dir = au_igrab(dir);
33711 + args->br = au_sbr(sb, bindex);
33712 + au_br_get(args->br);
33713 + args->wh_dentry = dget(wh_dentry);
33714 + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0);
33715 + if (unlikely(wkq_err)) {
33716 + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err);
33717 + au_whtmp_rmdir_free(args);
33720 diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h
33721 --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100
33722 +++ linux/fs/aufs/whout.h 2016-10-09 16:55:36.496035060 +0200
33725 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33727 + * This program, aufs is free software; you can redistribute it and/or modify
33728 + * it under the terms of the GNU General Public License as published by
33729 + * the Free Software Foundation; either version 2 of the License, or
33730 + * (at your option) any later version.
33732 + * This program is distributed in the hope that it will be useful,
33733 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33734 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33735 + * GNU General Public License for more details.
33737 + * You should have received a copy of the GNU General Public License
33738 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33742 + * whiteout for logical deletion and opaque directory
33745 +#ifndef __AUFS_WHOUT_H__
33746 +#define __AUFS_WHOUT_H__
33753 +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name);
33754 +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio);
33755 +int au_diropq_test(struct dentry *h_dentry);
33757 +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br,
33758 + struct qstr *prefix);
33759 +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br);
33760 +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path,
33761 + struct dentry *dentry);
33762 +int au_wh_init(struct au_branch *br, struct super_block *sb);
33764 +/* diropq flags */
33765 +#define AuDiropq_CREATE 1
33766 +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name)
33767 +#define au_fset_diropq(flags, name) \
33768 + do { (flags) |= AuDiropq_##name; } while (0)
33769 +#define au_fclr_diropq(flags, name) \
33770 + do { (flags) &= ~AuDiropq_##name; } while (0)
33772 +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex,
33773 + unsigned int flags);
33774 +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name,
33775 + struct au_branch *br);
33776 +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex,
33777 + struct dentry *h_parent);
33779 +/* real rmdir for the whiteout-ed dir */
33780 +struct au_whtmp_rmdir {
33781 + struct inode *dir;
33782 + struct au_branch *br;
33783 + struct dentry *wh_dentry;
33784 + struct au_nhash whlist;
33787 +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp);
33788 +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp);
33789 +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex,
33790 + struct dentry *wh_dentry, struct au_nhash *whlist);
33791 +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex,
33792 + struct dentry *wh_dentry, struct au_whtmp_rmdir *args);
33794 +/* ---------------------------------------------------------------------- */
33796 +static inline struct dentry *au_diropq_create(struct dentry *dentry,
33797 + aufs_bindex_t bindex)
33799 + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE);
33802 +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex)
33804 + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE));
33807 +#endif /* __KERNEL__ */
33808 +#endif /* __AUFS_WHOUT_H__ */
33809 diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c
33810 --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100
33811 +++ linux/fs/aufs/wkq.c 2016-10-09 16:55:36.496035060 +0200
33814 + * Copyright (C) 2005-2016 Junjiro R. Okajima
33816 + * This program, aufs is free software; you can redistribute it and/or modify
33817 + * it under the terms of the GNU General Public License as published by
33818 + * the Free Software Foundation; either version 2 of the License, or
33819 + * (at your option) any later version.
33821 + * This program is distributed in the hope that it will be useful,
33822 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33823 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33824 + * GNU General Public License for more details.
33826 + * You should have received a copy of the GNU General Public License
33827 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
33831 + * workqueue for asynchronous/super-io operations
33832 + * todo: try new dredential scheme
33835 +#include <linux/module.h>
33838 +/* internal workqueue named AUFS_WKQ_NAME */
33840 +static struct workqueue_struct *au_wkq;
33842 +struct au_wkinfo {
33843 + struct work_struct wk;
33844 + struct kobject *kobj;
33846 + unsigned int flags; /* see wkq.h */
33848 + au_wkq_func_t func;
33851 + struct completion *comp;
33854 +/* ---------------------------------------------------------------------- */
33856 +static void wkq_func(struct work_struct *wk)
33858 + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk);
33860 + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID));
33861 + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY);
33863 + wkinfo->func(wkinfo->args);
33864 + if (au_ftest_wkq(wkinfo->flags, WAIT))
33865 + complete(wkinfo->comp);
33867 + kobject_put(wkinfo->kobj);
33868 + module_put(THIS_MODULE); /* todo: ?? */
33869 + au_delayed_kfree(wkinfo);
33874 + * Since struct completion is large, try allocating it dynamically.
33876 +#if 1 /* defined(CONFIG_4KSTACKS) || defined(AuTest4KSTACKS) */
33877 +#define AuWkqCompDeclare(name) struct completion *comp = NULL
33879 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33881 + *comp = kmalloc(sizeof(**comp), GFP_NOFS);
33883 + init_completion(*comp);
33884 + wkinfo->comp = *comp;
33890 +static void au_wkq_comp_free(struct completion *comp)
33892 + au_delayed_kfree(comp);
33898 +#define AuWkqCompDeclare(name) \
33899 + DECLARE_COMPLETION_ONSTACK(_ ## name); \
33900 + struct completion *comp = &_ ## name
33902 +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp)
33904 + wkinfo->comp = *comp;
33908 +static void au_wkq_comp_free(struct completion *comp __maybe_unused)
33912 +#endif /* 4KSTACKS */
33914 +static void au_wkq_run(struct au_wkinfo *wkinfo)
33916 + if (au_ftest_wkq(wkinfo->flags, NEST)) {
33917 + if (au_wkq_test()) {
33918 + AuWarn1("wkq from wkq, unless silly-rename on NFS,"
33919 + " due to a dead dir by UDBA?\n");
33920 + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT));
33923 + au_dbg_verify_kthread();
33925 + if (au_ftest_wkq(wkinfo->flags, WAIT)) {
33926 + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func);
33927 + queue_work(au_wkq, &wkinfo->wk);
33929 + INIT_WORK(&wkinfo->wk, wkq_func);
33930 + schedule_work(&wkinfo->wk);
33935 + * Be careful. It is easy to make deadlock happen.
33936 + * processA: lock, wkq and wait
33937 + * processB: wkq and wait, lock in wkq
33940 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args)
33943 + AuWkqCompDeclare(comp);
33944 + struct au_wkinfo wkinfo = {
33950 + err = au_wkq_comp_alloc(&wkinfo, &comp);
33952 + au_wkq_run(&wkinfo);
33953 + /* no timeout, no interrupt */
33954 + wait_for_completion(wkinfo.comp);
33955 + au_wkq_comp_free(comp);
33956 + destroy_work_on_stack(&wkinfo.wk);
33964 + * Note: dget/dput() in func for aufs dentries are not supported. It will be a
33965 + * problem in a concurrent umounting.
33967 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
33968 + unsigned int flags)
33971 + struct au_wkinfo *wkinfo;
33973 + atomic_inc(&au_sbi(sb)->si_nowait.nw_len);
33976 + * wkq_func() must free this wkinfo.
33977 + * it highly depends upon the implementation of workqueue.
33980 + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS);
33982 + wkinfo->kobj = &au_sbi(sb)->si_kobj;
33983 + wkinfo->flags = flags & ~AuWkq_WAIT;
33984 + wkinfo->func = func;
33985 + wkinfo->args = args;
33986 + wkinfo->comp = NULL;
33987 + kobject_get(wkinfo->kobj);
33988 + __module_get(THIS_MODULE); /* todo: ?? */
33990 + au_wkq_run(wkinfo);
33993 + au_nwt_done(&au_sbi(sb)->si_nowait);
33999 +/* ---------------------------------------------------------------------- */
34001 +void au_nwt_init(struct au_nowait_tasks *nwt)
34003 + atomic_set(&nwt->nw_len, 0);
34004 + /* smp_mb(); */ /* atomic_set */
34005 + init_waitqueue_head(&nwt->nw_wq);
34008 +void au_wkq_fin(void)
34010 + destroy_workqueue(au_wkq);
34013 +int __init au_wkq_init(void)
34018 + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE);
34019 + if (IS_ERR(au_wkq))
34020 + err = PTR_ERR(au_wkq);
34021 + else if (!au_wkq)
34026 diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h
34027 --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100
34028 +++ linux/fs/aufs/wkq.h 2016-10-09 16:55:36.496035060 +0200
34031 + * Copyright (C) 2005-2016 Junjiro R. Okajima
34033 + * This program, aufs is free software; you can redistribute it and/or modify
34034 + * it under the terms of the GNU General Public License as published by
34035 + * the Free Software Foundation; either version 2 of the License, or
34036 + * (at your option) any later version.
34038 + * This program is distributed in the hope that it will be useful,
34039 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34040 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34041 + * GNU General Public License for more details.
34043 + * You should have received a copy of the GNU General Public License
34044 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34048 + * workqueue for asynchronous/super-io operations
34049 + * todo: try new credentials management scheme
34052 +#ifndef __AUFS_WKQ_H__
34053 +#define __AUFS_WKQ_H__
34057 +#include <linux/percpu_counter.h>
34059 +struct super_block;
34061 +/* ---------------------------------------------------------------------- */
34064 + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue
34066 +struct au_nowait_tasks {
34068 + wait_queue_head_t nw_wq;
34071 +/* ---------------------------------------------------------------------- */
34073 +typedef void (*au_wkq_func_t)(void *args);
34076 +#define AuWkq_WAIT 1
34077 +#define AuWkq_NEST (1 << 1)
34078 +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name)
34079 +#define au_fset_wkq(flags, name) \
34080 + do { (flags) |= AuWkq_##name; } while (0)
34081 +#define au_fclr_wkq(flags, name) \
34082 + do { (flags) &= ~AuWkq_##name; } while (0)
34084 +#ifndef CONFIG_AUFS_HNOTIFY
34086 +#define AuWkq_NEST 0
34090 +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args);
34091 +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb,
34092 + unsigned int flags);
34093 +void au_nwt_init(struct au_nowait_tasks *nwt);
34094 +int __init au_wkq_init(void);
34095 +void au_wkq_fin(void);
34097 +/* ---------------------------------------------------------------------- */
34099 +static inline int au_wkq_test(void)
34101 + return current->flags & PF_WQ_WORKER;
34104 +static inline int au_wkq_wait(au_wkq_func_t func, void *args)
34106 + return au_wkq_do_wait(AuWkq_WAIT, func, args);
34109 +static inline void au_nwt_done(struct au_nowait_tasks *nwt)
34111 + if (atomic_dec_and_test(&nwt->nw_len))
34112 + wake_up_all(&nwt->nw_wq);
34115 +static inline int au_nwt_flush(struct au_nowait_tasks *nwt)
34117 + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len));
34121 +#endif /* __KERNEL__ */
34122 +#endif /* __AUFS_WKQ_H__ */
34123 diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c
34124 --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100
34125 +++ linux/fs/aufs/xattr.c 2016-12-17 12:28:17.598545045 +0100
34128 + * Copyright (C) 2014-2016 Junjiro R. Okajima
34130 + * This program, aufs is free software; you can redistribute it and/or modify
34131 + * it under the terms of the GNU General Public License as published by
34132 + * the Free Software Foundation; either version 2 of the License, or
34133 + * (at your option) any later version.
34135 + * This program is distributed in the hope that it will be useful,
34136 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34137 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34138 + * GNU General Public License for more details.
34140 + * You should have received a copy of the GNU General Public License
34141 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34145 + * handling xattr functions
34148 +#include <linux/xattr.h>
34151 +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags)
34153 + if (!ignore_flags)
34161 + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) {
34166 +#define cmp(brattr, prefix) do { \
34167 + if (!strncmp(name, XATTR_##prefix##_PREFIX, \
34168 + XATTR_##prefix##_PREFIX_LEN)) { \
34169 + if (ignore_flags & AuBrAttr_ICEX_##brattr) \
34175 + cmp(SEC, SECURITY);
34176 + cmp(SYS, SYSTEM);
34177 + cmp(TR, TRUSTED);
34181 + if (ignore_flags & AuBrAttr_ICEX_OTH)
34188 +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1;
34190 +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src,
34191 + char *name, char **buf, unsigned int ignore_flags,
34192 + unsigned int verbose)
34196 + struct inode *h_idst;
34198 + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS);
34200 + if (unlikely(err <= 0)) {
34201 + if (err == -ENODATA
34202 + || (err == -EOPNOTSUPP
34203 + && ((ignore_flags & au_xattr_out_of_list)
34204 + || (au_test_nfs_noacl(d_inode(h_src))
34205 + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS)
34207 + XATTR_NAME_POSIX_ACL_DEFAULT))))
34210 + if (err && (verbose || au_debug_test()))
34211 + pr_err("%s, err %d\n", name, err);
34215 + /* unlock it temporary */
34216 + h_idst = d_inode(h_dst);
34217 + inode_unlock(h_idst);
34218 + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0);
34219 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34220 + if (unlikely(err)) {
34221 + if (verbose || au_debug_test())
34222 + pr_err("%s, err %d\n", name, err);
34223 + err = au_xattr_ignore(err, name, ignore_flags);
34230 +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags,
34231 + unsigned int verbose)
34233 + int err, unlocked, acl_access, acl_default;
34235 + struct inode *h_isrc, *h_idst;
34236 + char *value, *p, *o, *e;
34238 + /* try stopping to update the source inode while we are referencing */
34239 + /* there should not be the parent-child relationship between them */
34240 + h_isrc = d_inode(h_src);
34241 + h_idst = d_inode(h_dst);
34242 + inode_unlock(h_idst);
34243 + inode_lock_nested(h_isrc, AuLsc_I_CHILD);
34244 + inode_lock_nested(h_idst, AuLsc_I_CHILD2);
34247 + /* some filesystems don't list POSIX ACL, for example tmpfs */
34248 + ssz = vfs_listxattr(h_src, NULL, 0);
34250 + if (unlikely(err < 0)) {
34252 + if (err == -ENODATA
34253 + || err == -EOPNOTSUPP)
34254 + err = 0; /* ignore */
34263 + p = kmalloc(ssz, GFP_NOFS);
34265 + if (unlikely(!p))
34267 + err = vfs_listxattr(h_src, p, ssz);
34269 + inode_unlock(h_isrc);
34271 + AuDbg("err %d, ssz %zd\n", err, ssz);
34272 + if (unlikely(err < 0))
34280 + while (!err && p < e) {
34281 + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS,
34282 + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1);
34283 + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT,
34284 + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)
34286 + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags,
34288 + p += strlen(p) + 1;
34291 + ignore_flags |= au_xattr_out_of_list;
34292 + if (!err && !acl_access) {
34293 + err = au_do_cpup_xattr(h_dst, h_src,
34294 + XATTR_NAME_POSIX_ACL_ACCESS, &value,
34295 + ignore_flags, verbose);
34298 + if (!err && !acl_default) {
34299 + err = au_do_cpup_xattr(h_dst, h_src,
34300 + XATTR_NAME_POSIX_ACL_DEFAULT, &value,
34301 + ignore_flags, verbose);
34306 + au_delayed_kfree(value);
34310 + au_delayed_kfree(o);
34313 + inode_unlock(h_isrc);
34318 +/* ---------------------------------------------------------------------- */
34325 +struct au_lgxattr {
34333 + const char *name;
34340 +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg)
34343 + struct path h_path;
34344 + struct super_block *sb;
34346 + sb = dentry->d_sb;
34347 + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM);
34348 + if (unlikely(err))
34350 + err = au_h_path_getattr(dentry, /*force*/1, &h_path);
34351 + if (unlikely(err))
34353 + if (unlikely(!h_path.dentry))
34354 + /* illegally overlapped or something */
34355 + goto out_di; /* pretending success */
34357 + /* always topmost entry only */
34358 + switch (arg->type) {
34359 + case AU_XATTR_LIST:
34360 + err = vfs_listxattr(h_path.dentry,
34361 + arg->u.list.list, arg->u.list.size);
34363 + case AU_XATTR_GET:
34364 + AuDebugOn(d_is_negative(h_path.dentry));
34365 + err = vfs_getxattr(h_path.dentry,
34366 + arg->u.get.name, arg->u.get.value,
34367 + arg->u.get.size);
34372 + di_read_unlock(dentry, AuLock_IR);
34374 + si_read_unlock(sb);
34380 +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size)
34382 + struct au_lgxattr arg = {
34383 + .type = AU_XATTR_LIST,
34390 + return au_lgxattr(dentry, &arg);
34393 +static ssize_t au_getxattr(struct dentry *dentry,
34394 + struct inode *inode __maybe_unused,
34395 + const char *name, void *value, size_t size)
34397 + struct au_lgxattr arg = {
34398 + .type = AU_XATTR_GET,
34406 + return au_lgxattr(dentry, &arg);
34409 +static int au_setxattr(struct dentry *dentry, struct inode *inode,
34410 + const char *name, const void *value, size_t size,
34413 + struct au_sxattr arg = {
34414 + .type = AU_XATTR_SET,
34423 + return au_sxattr(dentry, inode, &arg);
34426 +/* ---------------------------------------------------------------------- */
34428 +static int au_xattr_get(const struct xattr_handler *handler,
34429 + struct dentry *dentry, struct inode *inode,
34430 + const char *name, void *buffer, size_t size)
34432 + return au_getxattr(dentry, inode, name, buffer, size);
34435 +static int au_xattr_set(const struct xattr_handler *handler,
34436 + struct dentry *dentry, struct inode *inode,
34437 + const char *name, const void *value, size_t size,
34440 + return au_setxattr(dentry, inode, name, value, size, flags);
34443 +static const struct xattr_handler au_xattr_handler = {
34446 + .get = au_xattr_get,
34447 + .set = au_xattr_set
34450 +static const struct xattr_handler *au_xattr_handlers[] = {
34451 + &au_xattr_handler,
34455 +void au_xattr_init(struct super_block *sb)
34457 + sb->s_xattr = au_xattr_handlers;
34459 diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c
34460 --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100
34461 +++ linux/fs/aufs/xino.c 2016-10-09 16:55:36.496035060 +0200
34464 + * Copyright (C) 2005-2016 Junjiro R. Okajima
34466 + * This program, aufs is free software; you can redistribute it and/or modify
34467 + * it under the terms of the GNU General Public License as published by
34468 + * the Free Software Foundation; either version 2 of the License, or
34469 + * (at your option) any later version.
34471 + * This program is distributed in the hope that it will be useful,
34472 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34473 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34474 + * GNU General Public License for more details.
34476 + * You should have received a copy of the GNU General Public License
34477 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
34481 + * external inode number translation table and bitmap
34484 +#include <linux/seq_file.h>
34485 +#include <linux/statfs.h>
34488 +/* todo: unnecessary to support mmap_sem since kernel-space? */
34489 +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size,
34493 + mm_segment_t oldfs;
34500 + oldfs = get_fs();
34501 + set_fs(KERNEL_DS);
34503 + /* todo: signal_pending? */
34504 + err = func(file, buf.u, size, pos);
34505 + } while (err == -EAGAIN || err == -EINTR);
34508 +#if 0 /* reserved for future use */
34510 + fsnotify_access(file->f_path.dentry);
34516 +/* ---------------------------------------------------------------------- */
34518 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34519 + size_t size, loff_t *pos);
34521 +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf,
34522 + size_t size, loff_t *pos)
34525 + mm_segment_t oldfs;
34528 + const char __user *u;
34531 + const int prevent_endless = 10;
34535 + oldfs = get_fs();
34536 + set_fs(KERNEL_DS);
34538 + err = func(file, buf.u, size, pos);
34539 + if (err == -EINTR
34540 + && !au_wkq_test()
34541 + && fatal_signal_pending(current)) {
34543 + err = xino_fwrite_wkq(func, file, kbuf, size, pos);
34544 + BUG_ON(err == -EINTR);
34545 + oldfs = get_fs();
34546 + set_fs(KERNEL_DS);
34548 + } while (i++ < prevent_endless
34549 + && (err == -EAGAIN || err == -EINTR));
34552 +#if 0 /* reserved for future use */
34554 + fsnotify_modify(file->f_path.dentry);
34560 +struct do_xino_fwrite_args {
34562 + vfs_writef_t func;
34563 + struct file *file;
34569 +static void call_do_xino_fwrite(void *args)
34571 + struct do_xino_fwrite_args *a = args;
34572 + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos);
34575 +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf,
34576 + size_t size, loff_t *pos)
34580 + struct do_xino_fwrite_args args = {
34590 + * it breaks RLIMIT_FSIZE and normal user's limit,
34591 + * users should care about quota and real 'filesystem full.'
34593 + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args);
34594 + if (unlikely(wkq_err))
34600 +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf,
34601 + size_t size, loff_t *pos)
34605 + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) {
34607 + err = do_xino_fwrite(func, file, buf, size, pos);
34610 + err = xino_fwrite_wkq(func, file, buf, size, pos);
34615 +/* ---------------------------------------------------------------------- */
34618 + * create a new xinofile at the same place/path as @base_file.
34620 +struct file *au_xino_create2(struct file *base_file, struct file *copy_src)
34622 + struct file *file;
34623 + struct dentry *base, *parent;
34624 + struct inode *dir, *delegated;
34625 + struct qstr *name;
34626 + struct path path;
34629 + base = base_file->f_path.dentry;
34630 + parent = base->d_parent; /* dir inode is locked */
34631 + dir = d_inode(parent);
34634 + file = ERR_PTR(-EINVAL);
34635 + name = &base->d_name;
34636 + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len);
34637 + if (IS_ERR(path.dentry)) {
34638 + file = (void *)path.dentry;
34639 + pr_err("%pd lookup err %ld\n",
34640 + base, PTR_ERR(path.dentry));
34644 + /* no need to mnt_want_write() since we call dentry_open() later */
34645 + err = vfs_create(dir, path.dentry, S_IRUGO | S_IWUGO, NULL);
34646 + if (unlikely(err)) {
34647 + file = ERR_PTR(err);
34648 + pr_err("%pd create err %d\n", base, err);
34652 + path.mnt = base_file->f_path.mnt;
34653 + file = vfsub_dentry_open(&path,
34654 + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
34655 + /* | __FMODE_NONOTIFY */);
34656 + if (IS_ERR(file)) {
34657 + pr_err("%pd open err %ld\n", base, PTR_ERR(file));
34661 + delegated = NULL;
34662 + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0);
34663 + if (unlikely(err == -EWOULDBLOCK)) {
34664 + pr_warn("cannot retry for NFSv4 delegation"
34665 + " for an internal unlink\n");
34668 + if (unlikely(err)) {
34669 + pr_err("%pd unlink err %d\n", base, err);
34674 + /* no one can touch copy_src xino */
34675 + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src));
34676 + if (unlikely(err)) {
34677 + pr_err("%pd copy err %d\n", base, err);
34681 + goto out_dput; /* success */
34685 + file = ERR_PTR(err);
34687 + dput(path.dentry);
34692 +struct au_xino_lock_dir {
34693 + struct au_hinode *hdir;
34694 + struct dentry *parent;
34695 + struct inode *dir;
34698 +static void au_xino_lock_dir(struct super_block *sb, struct file *xino,
34699 + struct au_xino_lock_dir *ldir)
34701 + aufs_bindex_t brid, bindex;
34703 + ldir->hdir = NULL;
34705 + brid = au_xino_brid(sb);
34707 + bindex = au_br_index(sb, brid);
34708 + if (bindex >= 0) {
34709 + ldir->hdir = au_hi(d_inode(sb->s_root), bindex);
34710 + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT);
34712 + ldir->parent = dget_parent(xino->f_path.dentry);
34713 + ldir->dir = d_inode(ldir->parent);
34714 + inode_lock_nested(ldir->dir, AuLsc_I_PARENT);
34718 +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir)
34721 + au_hn_inode_unlock(ldir->hdir);
34723 + inode_unlock(ldir->dir);
34724 + dput(ldir->parent);
34728 +/* ---------------------------------------------------------------------- */
34730 +/* trucate xino files asynchronously */
34732 +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex)
34735 + unsigned long jiffy;
34737 + aufs_bindex_t bi, bbot;
34738 + struct kstatfs *st;
34739 + struct au_branch *br;
34740 + struct file *new_xino, *file;
34741 + struct super_block *h_sb;
34742 + struct au_xino_lock_dir ldir;
34745 + st = kmalloc(sizeof(*st), GFP_NOFS);
34746 + if (unlikely(!st))
34750 + bbot = au_sbbot(sb);
34751 + if (unlikely(bindex < 0 || bbot < bindex))
34753 + br = au_sbr(sb, bindex);
34754 + file = br->br_xino.xi_file;
34758 + err = vfs_statfs(&file->f_path, st);
34759 + if (unlikely(err))
34760 + AuErr1("statfs err %d, ignored\n", err);
34762 + blocks = file_inode(file)->i_blocks;
34763 + pr_info("begin truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34764 + bindex, (u64)blocks, st->f_bfree, st->f_blocks);
34766 + au_xino_lock_dir(sb, file, &ldir);
34767 + /* mnt_want_write() is unnecessary here */
34768 + new_xino = au_xino_create2(file, file);
34769 + au_xino_unlock_dir(&ldir);
34770 + err = PTR_ERR(new_xino);
34771 + if (IS_ERR(new_xino)) {
34772 + pr_err("err %d, ignored\n", err);
34777 + br->br_xino.xi_file = new_xino;
34779 + h_sb = au_br_sb(br);
34780 + for (bi = 0; bi <= bbot; bi++) {
34781 + if (unlikely(bi == bindex))
34783 + br = au_sbr(sb, bi);
34784 + if (au_br_sb(br) != h_sb)
34787 + fput(br->br_xino.xi_file);
34788 + br->br_xino.xi_file = new_xino;
34789 + get_file(new_xino);
34792 + err = vfs_statfs(&new_xino->f_path, st);
34794 + pr_info("end truncating xino(b%d), ib%llu, %llu/%llu free blks\n",
34795 + bindex, (u64)file_inode(new_xino)->i_blocks,
34796 + st->f_bfree, st->f_blocks);
34797 + if (file_inode(new_xino)->i_blocks < blocks)
34798 + au_sbi(sb)->si_xino_jiffy = jiffy;
34800 + AuErr1("statfs err %d, ignored\n", err);
34803 + au_delayed_kfree(st);
34808 +struct xino_do_trunc_args {
34809 + struct super_block *sb;
34810 + struct au_branch *br;
34813 +static void xino_do_trunc(void *_args)
34815 + struct xino_do_trunc_args *args = _args;
34816 + struct super_block *sb;
34817 + struct au_branch *br;
34818 + struct inode *dir;
34820 + aufs_bindex_t bindex;
34824 + dir = d_inode(sb->s_root);
34827 + si_noflush_write_lock(sb);
34828 + ii_read_lock_parent(dir);
34829 + bindex = au_br_index(sb, br->br_id);
34830 + err = au_xino_trunc(sb, bindex);
34831 + ii_read_unlock(dir);
34832 + if (unlikely(err))
34833 + pr_warn("err b%d, (%d)\n", bindex, err);
34834 + atomic_dec(&br->br_xino_running);
34836 + si_write_unlock(sb);
34837 + au_nwt_done(&au_sbi(sb)->si_nowait);
34838 + au_delayed_kfree(args);
34841 +static int xino_trunc_test(struct super_block *sb, struct au_branch *br)
34844 + struct kstatfs st;
34845 + struct au_sbinfo *sbinfo;
34847 + /* todo: si_xino_expire and the ratio should be customizable */
34848 + sbinfo = au_sbi(sb);
34849 + if (time_before(jiffies,
34850 + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire))
34853 + /* truncation border */
34854 + err = vfs_statfs(&br->br_xino.xi_file->f_path, &st);
34855 + if (unlikely(err)) {
34856 + AuErr1("statfs err %d, ignored\n", err);
34859 + if (div64_u64(st.f_bfree * 100, st.f_blocks) >= AUFS_XINO_DEF_TRUNC)
34865 +static void xino_try_trunc(struct super_block *sb, struct au_branch *br)
34867 + struct xino_do_trunc_args *args;
34870 + if (!xino_trunc_test(sb, br))
34873 + if (atomic_inc_return(&br->br_xino_running) > 1)
34876 + /* lock and kfree() will be called in trunc_xino() */
34877 + args = kmalloc(sizeof(*args), GFP_NOFS);
34878 + if (unlikely(!args)) {
34879 + AuErr1("no memory\n");
34886 + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0);
34888 + return; /* success */
34890 + pr_err("wkq %d\n", wkq_err);
34892 + au_delayed_kfree(args);
34895 + atomic_dec(&br->br_xino_running);
34898 +/* ---------------------------------------------------------------------- */
34900 +static int au_xino_do_write(vfs_writef_t write, struct file *file,
34901 + ino_t h_ino, ino_t ino)
34907 + if (unlikely(au_loff_max / sizeof(ino) - 1 < pos)) {
34908 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
34911 + pos *= sizeof(ino);
34912 + sz = xino_fwrite(write, file, &ino, sizeof(ino), &pos);
34913 + if (sz == sizeof(ino))
34914 + return 0; /* success */
34916 + AuIOErr("write failed (%zd)\n", sz);
34921 + * write @ino to the xinofile for the specified branch{@sb, @bindex}
34922 + * at the position of @h_ino.
34923 + * even if @ino is zero, it is written to the xinofile and means no entry.
34924 + * if the size of the xino file on a specific filesystem exceeds the watermark,
34925 + * try truncating it.
34927 +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
34931 + unsigned int mnt_flags;
34932 + struct au_branch *br;
34934 + BUILD_BUG_ON(sizeof(long long) != sizeof(au_loff_max)
34935 + || ((loff_t)-1) > 0);
34936 + SiMustAnyLock(sb);
34938 + mnt_flags = au_mntflags(sb);
34939 + if (!au_opt_test(mnt_flags, XINO))
34942 + br = au_sbr(sb, bindex);
34943 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
34946 + if (au_opt_test(mnt_flags, TRUNC_XINO)
34947 + && au_test_fs_trunc_xino(au_br_sb(br)))
34948 + xino_try_trunc(sb, br);
34949 + return 0; /* success */
34952 + AuIOErr("write failed (%d)\n", err);
34956 +/* ---------------------------------------------------------------------- */
34958 +/* aufs inode number bitmap */
34960 +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE;
34961 +static ino_t xib_calc_ino(unsigned long pindex, int bit)
34965 + AuDebugOn(bit < 0 || page_bits <= bit);
34966 + ino = AUFS_FIRST_INO + pindex * page_bits + bit;
34970 +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit)
34972 + AuDebugOn(ino < AUFS_FIRST_INO);
34973 + ino -= AUFS_FIRST_INO;
34974 + *pindex = ino / page_bits;
34975 + *bit = ino % page_bits;
34978 +static int xib_pindex(struct super_block *sb, unsigned long pindex)
34983 + struct au_sbinfo *sbinfo;
34984 + struct file *xib;
34985 + unsigned long *p;
34987 + sbinfo = au_sbi(sb);
34988 + MtxMustLock(&sbinfo->si_xib_mtx);
34989 + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE
34990 + || !au_opt_test(sbinfo->si_mntflags, XINO));
34992 + if (pindex == sbinfo->si_xib_last_pindex)
34995 + xib = sbinfo->si_xib;
34996 + p = sbinfo->si_xib_buf;
34997 + pos = sbinfo->si_xib_last_pindex;
34998 + pos *= PAGE_SIZE;
34999 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
35000 + if (unlikely(sz != PAGE_SIZE))
35004 + pos *= PAGE_SIZE;
35005 + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE)
35006 + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos);
35008 + memset(p, 0, PAGE_SIZE);
35009 + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos);
35011 + if (sz == PAGE_SIZE) {
35012 + sbinfo->si_xib_last_pindex = pindex;
35013 + return 0; /* success */
35017 + AuIOErr1("write failed (%zd)\n", sz);
35024 +/* ---------------------------------------------------------------------- */
35026 +static void au_xib_clear_bit(struct inode *inode)
35029 + unsigned long pindex;
35030 + struct super_block *sb;
35031 + struct au_sbinfo *sbinfo;
35033 + AuDebugOn(inode->i_nlink);
35035 + sb = inode->i_sb;
35036 + xib_calc_bit(inode->i_ino, &pindex, &bit);
35037 + AuDebugOn(page_bits <= bit);
35038 + sbinfo = au_sbi(sb);
35039 + mutex_lock(&sbinfo->si_xib_mtx);
35040 + err = xib_pindex(sb, pindex);
35042 + clear_bit(bit, sbinfo->si_xib_buf);
35043 + sbinfo->si_xib_next_bit = bit;
35045 + mutex_unlock(&sbinfo->si_xib_mtx);
35048 +/* for s_op->delete_inode() */
35049 +void au_xino_delete_inode(struct inode *inode, const int unlinked)
35052 + unsigned int mnt_flags;
35053 + aufs_bindex_t bindex, bbot, bi;
35054 + unsigned char try_trunc;
35055 + struct au_iinfo *iinfo;
35056 + struct super_block *sb;
35057 + struct au_hinode *hi;
35058 + struct inode *h_inode;
35059 + struct au_branch *br;
35060 + vfs_writef_t xwrite;
35062 + AuDebugOn(au_is_bad_inode(inode));
35064 + sb = inode->i_sb;
35065 + mnt_flags = au_mntflags(sb);
35066 + if (!au_opt_test(mnt_flags, XINO)
35067 + || inode->i_ino == AUFS_ROOT_INO)
35071 + au_xigen_inc(inode);
35072 + au_xib_clear_bit(inode);
35075 + iinfo = au_ii(inode);
35076 + bindex = iinfo->ii_btop;
35080 + xwrite = au_sbi(sb)->si_xwrite;
35081 + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO);
35082 + hi = au_hinode(iinfo, bindex);
35083 + bbot = iinfo->ii_bbot;
35084 + for (; bindex <= bbot; bindex++, hi++) {
35085 + h_inode = hi->hi_inode;
35087 + || (!unlinked && h_inode->i_nlink))
35090 + /* inode may not be revalidated */
35091 + bi = au_br_index(sb, hi->hi_id);
35095 + br = au_sbr(sb, bi);
35096 + err = au_xino_do_write(xwrite, br->br_xino.xi_file,
35097 + h_inode->i_ino, /*ino*/0);
35098 + if (!err && try_trunc
35099 + && au_test_fs_trunc_xino(au_br_sb(br)))
35100 + xino_try_trunc(sb, br);
35104 +/* get an unused inode number from bitmap */
35105 +ino_t au_xino_new_ino(struct super_block *sb)
35108 + unsigned long *p, pindex, ul, pend;
35109 + struct au_sbinfo *sbinfo;
35110 + struct file *file;
35111 + int free_bit, err;
35113 + if (!au_opt_test(au_mntflags(sb), XINO))
35114 + return iunique(sb, AUFS_FIRST_INO);
35116 + sbinfo = au_sbi(sb);
35117 + mutex_lock(&sbinfo->si_xib_mtx);
35118 + p = sbinfo->si_xib_buf;
35119 + free_bit = sbinfo->si_xib_next_bit;
35120 + if (free_bit < page_bits && !test_bit(free_bit, p))
35121 + goto out; /* success */
35122 + free_bit = find_first_zero_bit(p, page_bits);
35123 + if (free_bit < page_bits)
35124 + goto out; /* success */
35126 + pindex = sbinfo->si_xib_last_pindex;
35127 + for (ul = pindex - 1; ul < ULONG_MAX; ul--) {
35128 + err = xib_pindex(sb, ul);
35129 + if (unlikely(err))
35131 + free_bit = find_first_zero_bit(p, page_bits);
35132 + if (free_bit < page_bits)
35133 + goto out; /* success */
35136 + file = sbinfo->si_xib;
35137 + pend = vfsub_f_size_read(file) / PAGE_SIZE;
35138 + for (ul = pindex + 1; ul <= pend; ul++) {
35139 + err = xib_pindex(sb, ul);
35140 + if (unlikely(err))
35142 + free_bit = find_first_zero_bit(p, page_bits);
35143 + if (free_bit < page_bits)
35144 + goto out; /* success */
35149 + set_bit(free_bit, p);
35150 + sbinfo->si_xib_next_bit = free_bit + 1;
35151 + pindex = sbinfo->si_xib_last_pindex;
35152 + mutex_unlock(&sbinfo->si_xib_mtx);
35153 + ino = xib_calc_ino(pindex, free_bit);
35154 + AuDbg("i%lu\n", (unsigned long)ino);
35157 + mutex_unlock(&sbinfo->si_xib_mtx);
35163 + * read @ino from xinofile for the specified branch{@sb, @bindex}
35164 + * at the position of @h_ino.
35165 + * if @ino does not exist and @do_new is true, get new one.
35167 +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino,
35173 + struct file *file;
35174 + struct au_sbinfo *sbinfo;
35177 + if (!au_opt_test(au_mntflags(sb), XINO))
35178 + return 0; /* no xino */
35181 + sbinfo = au_sbi(sb);
35183 + if (unlikely(au_loff_max / sizeof(*ino) - 1 < pos)) {
35184 + AuIOErr1("too large hi%lu\n", (unsigned long)h_ino);
35187 + pos *= sizeof(*ino);
35189 + file = au_sbr(sb, bindex)->br_xino.xi_file;
35190 + if (vfsub_f_size_read(file) < pos + sizeof(*ino))
35191 + return 0; /* no ino */
35193 + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &pos);
35194 + if (sz == sizeof(*ino))
35195 + return 0; /* success */
35198 + if (unlikely(sz >= 0)) {
35200 + AuIOErr("xino read error (%zd)\n", sz);
35206 +/* ---------------------------------------------------------------------- */
35208 +/* create and set a new xino file */
35210 +struct file *au_xino_create(struct super_block *sb, char *fname, int silent)
35212 + struct file *file;
35213 + struct dentry *h_parent, *d;
35214 + struct inode *h_dir, *inode;
35218 + * at mount-time, and the xino file is the default path,
35219 + * hnotify is disabled so we have no notify events to ignore.
35220 + * when a user specified the xino, we cannot get au_hdir to be ignored.
35222 + file = vfsub_filp_open(fname, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE
35223 + /* | __FMODE_NONOTIFY */,
35224 + S_IRUGO | S_IWUGO);
35225 + if (IS_ERR(file)) {
35227 + pr_err("open %s(%ld)\n", fname, PTR_ERR(file));
35231 + /* keep file count */
35233 + inode = file_inode(file);
35234 + h_parent = dget_parent(file->f_path.dentry);
35235 + h_dir = d_inode(h_parent);
35236 + inode_lock_nested(h_dir, AuLsc_I_PARENT);
35237 + /* mnt_want_write() is unnecessary here */
35238 + /* no delegation since it is just created */
35239 + if (inode->i_nlink)
35240 + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL,
35242 + inode_unlock(h_dir);
35244 + if (unlikely(err)) {
35246 + pr_err("unlink %s(%d)\n", fname, err);
35251 + d = file->f_path.dentry;
35252 + if (unlikely(sb == d->d_sb)) {
35254 + pr_err("%s must be outside\n", fname);
35257 + if (unlikely(au_test_fs_bad_xino(d->d_sb))) {
35259 + pr_err("xino doesn't support %s(%s)\n",
35260 + fname, au_sbtype(d->d_sb));
35263 + return file; /* success */
35267 + file = ERR_PTR(err);
35272 + * find another branch who is on the same filesystem of the specified
35273 + * branch{@btgt}. search until @bbot.
35275 +static int is_sb_shared(struct super_block *sb, aufs_bindex_t btgt,
35276 + aufs_bindex_t bbot)
35278 + aufs_bindex_t bindex;
35279 + struct super_block *tgt_sb = au_sbr_sb(sb, btgt);
35281 + for (bindex = 0; bindex < btgt; bindex++)
35282 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35284 + for (bindex++; bindex <= bbot; bindex++)
35285 + if (unlikely(tgt_sb == au_sbr_sb(sb, bindex)))
35290 +/* ---------------------------------------------------------------------- */
35293 + * initialize the xinofile for the specified branch @br
35294 + * at the place/path where @base_file indicates.
35295 + * test whether another branch is on the same filesystem or not,
35296 + * if @do_test is true.
35298 +int au_xino_br(struct super_block *sb, struct au_branch *br, ino_t h_ino,
35299 + struct file *base_file, int do_test)
35303 + aufs_bindex_t bbot, bindex;
35304 + struct au_branch *shared_br, *b;
35305 + struct file *file;
35306 + struct super_block *tgt_sb;
35308 + shared_br = NULL;
35309 + bbot = au_sbbot(sb);
35311 + tgt_sb = au_br_sb(br);
35312 + for (bindex = 0; bindex <= bbot; bindex++) {
35313 + b = au_sbr(sb, bindex);
35314 + if (tgt_sb == au_br_sb(b)) {
35321 + if (!shared_br || !shared_br->br_xino.xi_file) {
35322 + struct au_xino_lock_dir ldir;
35324 + au_xino_lock_dir(sb, base_file, &ldir);
35325 + /* mnt_want_write() is unnecessary here */
35326 + file = au_xino_create2(base_file, NULL);
35327 + au_xino_unlock_dir(&ldir);
35328 + err = PTR_ERR(file);
35329 + if (IS_ERR(file))
35331 + br->br_xino.xi_file = file;
35333 + br->br_xino.xi_file = shared_br->br_xino.xi_file;
35334 + get_file(br->br_xino.xi_file);
35337 + ino = AUFS_ROOT_INO;
35338 + err = au_xino_do_write(au_sbi(sb)->si_xwrite, br->br_xino.xi_file,
35340 + if (unlikely(err)) {
35341 + fput(br->br_xino.xi_file);
35342 + br->br_xino.xi_file = NULL;
35349 +/* ---------------------------------------------------------------------- */
35351 +/* trucate a xino bitmap file */
35354 +static int do_xib_restore(struct super_block *sb, struct file *file, void *page)
35358 + unsigned long pindex;
35359 + loff_t pos, pend;
35360 + struct au_sbinfo *sbinfo;
35361 + vfs_readf_t func;
35363 + unsigned long *p;
35366 + sbinfo = au_sbi(sb);
35367 + MtxMustLock(&sbinfo->si_xib_mtx);
35368 + p = sbinfo->si_xib_buf;
35369 + func = sbinfo->si_xread;
35370 + pend = vfsub_f_size_read(file);
35372 + while (pos < pend) {
35373 + sz = xino_fread(func, file, page, PAGE_SIZE, &pos);
35375 + if (unlikely(sz <= 0))
35379 + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) {
35380 + if (unlikely(*ino < AUFS_FIRST_INO))
35383 + xib_calc_bit(*ino, &pindex, &bit);
35384 + AuDebugOn(page_bits <= bit);
35385 + err = xib_pindex(sb, pindex);
35397 +static int xib_restore(struct super_block *sb)
35400 + aufs_bindex_t bindex, bbot;
35404 + page = (void *)__get_free_page(GFP_NOFS);
35405 + if (unlikely(!page))
35409 + bbot = au_sbbot(sb);
35410 + for (bindex = 0; !err && bindex <= bbot; bindex++)
35411 + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0)
35412 + err = do_xib_restore
35413 + (sb, au_sbr(sb, bindex)->br_xino.xi_file, page);
35415 + AuDbg("b%d\n", bindex);
35416 + au_delayed_free_page((unsigned long)page);
35422 +int au_xib_trunc(struct super_block *sb)
35427 + struct au_xino_lock_dir ldir;
35428 + struct au_sbinfo *sbinfo;
35429 + unsigned long *p;
35430 + struct file *file;
35432 + SiMustWriteLock(sb);
35435 + sbinfo = au_sbi(sb);
35436 + if (!au_opt_test(sbinfo->si_mntflags, XINO))
35439 + file = sbinfo->si_xib;
35440 + if (vfsub_f_size_read(file) <= PAGE_SIZE)
35443 + au_xino_lock_dir(sb, file, &ldir);
35444 + /* mnt_want_write() is unnecessary here */
35445 + file = au_xino_create2(sbinfo->si_xib, NULL);
35446 + au_xino_unlock_dir(&ldir);
35447 + err = PTR_ERR(file);
35448 + if (IS_ERR(file))
35450 + fput(sbinfo->si_xib);
35451 + sbinfo->si_xib = file;
35453 + p = sbinfo->si_xib_buf;
35454 + memset(p, 0, PAGE_SIZE);
35456 + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos);
35457 + if (unlikely(sz != PAGE_SIZE)) {
35459 + AuIOErr("err %d\n", err);
35465 + mutex_lock(&sbinfo->si_xib_mtx);
35466 + /* mnt_want_write() is unnecessary here */
35467 + err = xib_restore(sb);
35468 + mutex_unlock(&sbinfo->si_xib_mtx);
35474 +/* ---------------------------------------------------------------------- */
35477 + * xino mount option handlers
35481 +static void xino_clear_xib(struct super_block *sb)
35483 + struct au_sbinfo *sbinfo;
35485 + SiMustWriteLock(sb);
35487 + sbinfo = au_sbi(sb);
35488 + sbinfo->si_xread = NULL;
35489 + sbinfo->si_xwrite = NULL;
35490 + if (sbinfo->si_xib)
35491 + fput(sbinfo->si_xib);
35492 + sbinfo->si_xib = NULL;
35493 + if (sbinfo->si_xib_buf)
35494 + au_delayed_free_page((unsigned long)sbinfo->si_xib_buf);
35495 + sbinfo->si_xib_buf = NULL;
35498 +static int au_xino_set_xib(struct super_block *sb, struct file *base)
35502 + struct au_sbinfo *sbinfo;
35503 + struct file *file;
35505 + SiMustWriteLock(sb);
35507 + sbinfo = au_sbi(sb);
35508 + file = au_xino_create2(base, sbinfo->si_xib);
35509 + err = PTR_ERR(file);
35510 + if (IS_ERR(file))
35512 + if (sbinfo->si_xib)
35513 + fput(sbinfo->si_xib);
35514 + sbinfo->si_xib = file;
35515 + sbinfo->si_xread = vfs_readf(file);
35516 + sbinfo->si_xwrite = vfs_writef(file);
35519 + if (!sbinfo->si_xib_buf)
35520 + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS);
35521 + if (unlikely(!sbinfo->si_xib_buf))
35524 + sbinfo->si_xib_last_pindex = 0;
35525 + sbinfo->si_xib_next_bit = 0;
35526 + if (vfsub_f_size_read(file) < PAGE_SIZE) {
35528 + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf,
35529 + PAGE_SIZE, &pos);
35530 + if (unlikely(err != PAGE_SIZE))
35534 + goto out; /* success */
35537 + if (sbinfo->si_xib_buf)
35538 + au_delayed_free_page((unsigned long)sbinfo->si_xib_buf);
35539 + sbinfo->si_xib_buf = NULL;
35543 + fput(sbinfo->si_xib);
35544 + sbinfo->si_xib = NULL;
35545 + sbinfo->si_xread = NULL;
35546 + sbinfo->si_xwrite = NULL;
35551 +/* xino for each branch */
35552 +static void xino_clear_br(struct super_block *sb)
35554 + aufs_bindex_t bindex, bbot;
35555 + struct au_branch *br;
35557 + bbot = au_sbbot(sb);
35558 + for (bindex = 0; bindex <= bbot; bindex++) {
35559 + br = au_sbr(sb, bindex);
35560 + if (!br || !br->br_xino.xi_file)
35563 + fput(br->br_xino.xi_file);
35564 + br->br_xino.xi_file = NULL;
35568 +static int au_xino_set_br(struct super_block *sb, struct file *base)
35572 + aufs_bindex_t bindex, bbot, bshared;
35574 + struct file *old, *new;
35576 + struct au_branch *br;
35577 + struct inode *inode;
35578 + vfs_writef_t writef;
35580 + SiMustWriteLock(sb);
35583 + bbot = au_sbbot(sb);
35584 + fpair = kcalloc(bbot + 1, sizeof(*fpair), GFP_NOFS);
35585 + if (unlikely(!fpair))
35588 + inode = d_inode(sb->s_root);
35589 + ino = AUFS_ROOT_INO;
35590 + writef = au_sbi(sb)->si_xwrite;
35591 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35592 + bshared = is_sb_shared(sb, bindex, bindex - 1);
35593 + if (bshared >= 0) {
35594 + /* shared xino */
35595 + *p = fpair[bshared];
35596 + get_file(p->new);
35601 + br = au_sbr(sb, bindex);
35602 + p->old = br->br_xino.xi_file;
35603 + p->new = au_xino_create2(base, br->br_xino.xi_file);
35604 + err = PTR_ERR(p->new);
35605 + if (IS_ERR(p->new)) {
35611 + err = au_xino_do_write(writef, p->new,
35612 + au_h_iptr(inode, bindex)->i_ino, ino);
35613 + if (unlikely(err))
35617 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++) {
35618 + br = au_sbr(sb, bindex);
35619 + if (br->br_xino.xi_file)
35620 + fput(br->br_xino.xi_file);
35621 + get_file(p->new);
35622 + br->br_xino.xi_file = p->new;
35626 + for (bindex = 0, p = fpair; bindex <= bbot; bindex++, p++)
35631 + au_delayed_kfree(fpair);
35636 +void au_xino_clr(struct super_block *sb)
35638 + struct au_sbinfo *sbinfo;
35640 + au_xigen_clr(sb);
35641 + xino_clear_xib(sb);
35642 + xino_clear_br(sb);
35643 + sbinfo = au_sbi(sb);
35644 + /* lvalue, do not call au_mntflags() */
35645 + au_opt_clr(sbinfo->si_mntflags, XINO);
35648 +int au_xino_set(struct super_block *sb, struct au_opt_xino *xino, int remount)
35651 + struct dentry *parent, *cur_parent;
35652 + struct qstr *dname, *cur_name;
35653 + struct file *cur_xino;
35654 + struct inode *dir;
35655 + struct au_sbinfo *sbinfo;
35657 + SiMustWriteLock(sb);
35660 + sbinfo = au_sbi(sb);
35661 + parent = dget_parent(xino->file->f_path.dentry);
35664 + dname = &xino->file->f_path.dentry->d_name;
35665 + cur_xino = sbinfo->si_xib;
35667 + cur_parent = dget_parent(cur_xino->f_path.dentry);
35668 + cur_name = &cur_xino->f_path.dentry->d_name;
35669 + skip = (cur_parent == parent
35670 + && au_qstreq(dname, cur_name));
35671 + dput(cur_parent);
35677 + au_opt_set(sbinfo->si_mntflags, XINO);
35678 + dir = d_inode(parent);
35679 + inode_lock_nested(dir, AuLsc_I_PARENT);
35680 + /* mnt_want_write() is unnecessary here */
35681 + err = au_xino_set_xib(sb, xino->file);
35683 + err = au_xigen_set(sb, xino->file);
35685 + err = au_xino_set_br(sb, xino->file);
35686 + inode_unlock(dir);
35688 + goto out; /* success */
35691 + AuIOErr("failed creating xino(%d).\n", err);
35692 + au_xigen_clr(sb);
35693 + xino_clear_xib(sb);
35700 +/* ---------------------------------------------------------------------- */
35703 + * create a xinofile at the default place/path.
35705 +struct file *au_xino_def(struct super_block *sb)
35707 + struct file *file;
35709 + struct au_branch *br;
35710 + struct super_block *h_sb;
35711 + struct path path;
35712 + aufs_bindex_t bbot, bindex, bwr;
35715 + bbot = au_sbbot(sb);
35717 + for (bindex = 0; bindex <= bbot; bindex++) {
35718 + br = au_sbr(sb, bindex);
35719 + if (au_br_writable(br->br_perm)
35720 + && !au_test_fs_bad_xino(au_br_sb(br))) {
35727 + file = ERR_PTR(-ENOMEM);
35728 + page = (void *)__get_free_page(GFP_NOFS);
35729 + if (unlikely(!page))
35731 + path.mnt = au_br_mnt(br);
35732 + path.dentry = au_h_dptr(sb->s_root, bwr);
35733 + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME));
35734 + file = (void *)p;
35735 + if (!IS_ERR(p)) {
35736 + strcat(p, "/" AUFS_XINO_FNAME);
35737 + AuDbg("%s\n", p);
35738 + file = au_xino_create(sb, p, /*silent*/0);
35739 + if (!IS_ERR(file))
35740 + au_xino_brid_set(sb, br->br_id);
35742 + au_delayed_free_page((unsigned long)page);
35744 + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0);
35745 + if (IS_ERR(file))
35747 + h_sb = file->f_path.dentry->d_sb;
35748 + if (unlikely(au_test_fs_bad_xino(h_sb))) {
35749 + pr_err("xino doesn't support %s(%s)\n",
35750 + AUFS_XINO_DEFPATH, au_sbtype(h_sb));
35752 + file = ERR_PTR(-EINVAL);
35754 + if (!IS_ERR(file))
35755 + au_xino_brid_set(sb, -1);
35762 +/* ---------------------------------------------------------------------- */
35764 +int au_xino_path(struct seq_file *seq, struct file *file)
35768 + err = au_seq_path(seq, &file->f_path);
35769 + if (unlikely(err))
35772 +#define Deleted "\\040(deleted)"
35773 + seq->count -= sizeof(Deleted) - 1;
35774 + AuDebugOn(memcmp(seq->buf + seq->count, Deleted,
35775 + sizeof(Deleted) - 1));
35781 diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h
35782 --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100
35783 +++ linux/include/uapi/linux/aufs_type.h 2016-12-17 12:28:38.769494865 +0100
35786 + * Copyright (C) 2005-2016 Junjiro R. Okajima
35788 + * This program, aufs is free software; you can redistribute it and/or modify
35789 + * it under the terms of the GNU General Public License as published by
35790 + * the Free Software Foundation; either version 2 of the License, or
35791 + * (at your option) any later version.
35793 + * This program is distributed in the hope that it will be useful,
35794 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35795 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35796 + * GNU General Public License for more details.
35798 + * You should have received a copy of the GNU General Public License
35799 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
35802 +#ifndef __AUFS_TYPE_H__
35803 +#define __AUFS_TYPE_H__
35805 +#define AUFS_NAME "aufs"
35809 + * define it before including all other headers.
35810 + * sched.h may use pr_* macros before defining "current", so define the
35811 + * no-current version first, and re-define later.
35813 +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__
35814 +#include <linux/sched.h>
35816 +#define pr_fmt(fmt) \
35817 + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \
35818 + (int)sizeof(current->comm), current->comm, current->pid
35820 +#include <stdint.h>
35821 +#include <sys/types.h>
35822 +#endif /* __KERNEL__ */
35824 +#include <linux/limits.h>
35826 +#define AUFS_VERSION "4.9-20161219"
35828 +/* todo? move this to linux-2.6.19/include/magic.h */
35829 +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's')
35831 +/* ---------------------------------------------------------------------- */
35833 +#ifdef CONFIG_AUFS_BRANCH_MAX_127
35834 +typedef int8_t aufs_bindex_t;
35835 +#define AUFS_BRANCH_MAX 127
35837 +typedef int16_t aufs_bindex_t;
35838 +#ifdef CONFIG_AUFS_BRANCH_MAX_511
35839 +#define AUFS_BRANCH_MAX 511
35840 +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023)
35841 +#define AUFS_BRANCH_MAX 1023
35842 +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767)
35843 +#define AUFS_BRANCH_MAX 32767
35848 +#ifndef AUFS_BRANCH_MAX
35849 +#error unknown CONFIG_AUFS_BRANCH_MAX value
35851 +#endif /* __KERNEL__ */
35853 +/* ---------------------------------------------------------------------- */
35855 +#define AUFS_FSTYPE AUFS_NAME
35857 +#define AUFS_ROOT_INO 2
35858 +#define AUFS_FIRST_INO 11
35860 +#define AUFS_WH_PFX ".wh."
35861 +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1)
35862 +#define AUFS_WH_TMP_LEN 4
35863 +/* a limit for rmdir/rename a dir and copyup */
35864 +#define AUFS_MAX_NAMELEN (NAME_MAX \
35865 + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\
35867 + - AUFS_WH_TMP_LEN) /* hex */
35868 +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino"
35869 +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME
35870 +#define AUFS_XINO_DEF_SEC 30 /* seconds */
35871 +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */
35872 +#define AUFS_DIRWH_DEF 3
35873 +#define AUFS_RDCACHE_DEF 10 /* seconds */
35874 +#define AUFS_RDCACHE_MAX 3600 /* seconds */
35875 +#define AUFS_RDBLK_DEF 512 /* bytes */
35876 +#define AUFS_RDHASH_DEF 32
35877 +#define AUFS_WKQ_NAME AUFS_NAME "d"
35878 +#define AUFS_MFS_DEF_SEC 30 /* seconds */
35879 +#define AUFS_MFS_MAX_SEC 3600 /* seconds */
35880 +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */
35881 +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */
35883 +/* pseudo-link maintenace under /proc */
35884 +#define AUFS_PLINK_MAINT_NAME "plink_maint"
35885 +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME
35886 +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME
35888 +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */
35889 +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME
35891 +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME
35892 +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk"
35893 +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph"
35895 +/* doubly whiteouted */
35896 +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME
35897 +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME
35898 +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME
35900 +/* branch permissions and attributes */
35901 +#define AUFS_BRPERM_RW "rw"
35902 +#define AUFS_BRPERM_RO "ro"
35903 +#define AUFS_BRPERM_RR "rr"
35904 +#define AUFS_BRATTR_COO_REG "coo_reg"
35905 +#define AUFS_BRATTR_COO_ALL "coo_all"
35906 +#define AUFS_BRATTR_FHSM "fhsm"
35907 +#define AUFS_BRATTR_UNPIN "unpin"
35908 +#define AUFS_BRATTR_ICEX "icex"
35909 +#define AUFS_BRATTR_ICEX_SEC "icexsec"
35910 +#define AUFS_BRATTR_ICEX_SYS "icexsys"
35911 +#define AUFS_BRATTR_ICEX_TR "icextr"
35912 +#define AUFS_BRATTR_ICEX_USR "icexusr"
35913 +#define AUFS_BRATTR_ICEX_OTH "icexoth"
35914 +#define AUFS_BRRATTR_WH "wh"
35915 +#define AUFS_BRWATTR_NLWH "nolwh"
35916 +#define AUFS_BRWATTR_MOO "moo"
35918 +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */
35919 +#define AuBrPerm_RO (1 << 1) /* readonly */
35920 +#define AuBrPerm_RR (1 << 2) /* natively readonly */
35921 +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR)
35923 +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */
35924 +#define AuBrAttr_COO_ALL (1 << 4)
35925 +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL)
35927 +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */
35928 +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of
35929 + branch. meaningless since
35930 + linux-3.18-rc1 */
35932 +/* ignore error in copying XATTR */
35933 +#define AuBrAttr_ICEX_SEC (1 << 7)
35934 +#define AuBrAttr_ICEX_SYS (1 << 8)
35935 +#define AuBrAttr_ICEX_TR (1 << 9)
35936 +#define AuBrAttr_ICEX_USR (1 << 10)
35937 +#define AuBrAttr_ICEX_OTH (1 << 11)
35938 +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \
35939 + | AuBrAttr_ICEX_SYS \
35940 + | AuBrAttr_ICEX_TR \
35941 + | AuBrAttr_ICEX_USR \
35942 + | AuBrAttr_ICEX_OTH)
35944 +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */
35945 +#define AuBrRAttr_Mask AuBrRAttr_WH
35947 +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */
35948 +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */
35949 +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO)
35951 +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO)
35953 +/* #warning test userspace */
35955 +#ifndef CONFIG_AUFS_FHSM
35956 +#undef AuBrAttr_FHSM
35957 +#define AuBrAttr_FHSM 0
35959 +#ifndef CONFIG_AUFS_XATTR
35960 +#undef AuBrAttr_ICEX
35961 +#define AuBrAttr_ICEX 0
35962 +#undef AuBrAttr_ICEX_SEC
35963 +#define AuBrAttr_ICEX_SEC 0
35964 +#undef AuBrAttr_ICEX_SYS
35965 +#define AuBrAttr_ICEX_SYS 0
35966 +#undef AuBrAttr_ICEX_TR
35967 +#define AuBrAttr_ICEX_TR 0
35968 +#undef AuBrAttr_ICEX_USR
35969 +#define AuBrAttr_ICEX_USR 0
35970 +#undef AuBrAttr_ICEX_OTH
35971 +#define AuBrAttr_ICEX_OTH 0
35975 +/* the longest combination */
35976 +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */
35977 +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \
35978 + "+" AUFS_BRATTR_COO_REG \
35979 + "+" AUFS_BRATTR_FHSM \
35980 + "+" AUFS_BRATTR_UNPIN \
35981 + "+" AUFS_BRATTR_ICEX_SEC \
35982 + "+" AUFS_BRATTR_ICEX_SYS \
35983 + "+" AUFS_BRATTR_ICEX_USR \
35984 + "+" AUFS_BRATTR_ICEX_OTH \
35985 + "+" AUFS_BRWATTR_NLWH)
35988 + char a[AuBrPermStrSz];
35989 +} au_br_perm_str_t;
35991 +static inline int au_br_writable(int brperm)
35993 + return brperm & AuBrPerm_RW;
35996 +static inline int au_br_whable(int brperm)
35998 + return brperm & (AuBrPerm_RW | AuBrRAttr_WH);
36001 +static inline int au_br_wh_linkable(int brperm)
36003 + return !(brperm & AuBrWAttr_NoLinkWH);
36006 +static inline int au_br_cmoo(int brperm)
36008 + return brperm & AuBrAttr_CMOO_Mask;
36011 +static inline int au_br_fhsm(int brperm)
36013 + return brperm & AuBrAttr_FHSM;
36016 +/* ---------------------------------------------------------------------- */
36020 + /* readdir in userspace */
36024 + AuCtl_WBR_FD, /* pathconf wrapper */
36025 + AuCtl_IBUSY, /* busy inode */
36026 + AuCtl_MVDOWN, /* move-down */
36027 + AuCtl_BR, /* info about branches */
36028 + AuCtl_FHSM_FD /* connection for fhsm */
36031 +/* borrowed from linux/include/linux/kernel.h */
36033 +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1)
36034 +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask))
36037 +/* borrowed from linux/include/linux/compiler-gcc3.h */
36039 +#define __aligned(x) __attribute__((aligned(x)))
36044 +#define __packed __attribute__((packed))
36048 +struct au_rdu_cookie {
36053 + uint32_t generation;
36056 +struct au_rdu_ent {
36065 +static inline int au_rdu_len(int nlen)
36067 + /* include the terminating NULL */
36068 + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1,
36069 + sizeof(uint64_t));
36072 +union au_rdu_ent_ul {
36073 + struct au_rdu_ent __user *e;
36085 + uint64_t sz; /* AuCtl_RDU */
36086 + uint64_t nent; /* AuCtl_RDU_INO */
36088 + union au_rdu_ent_ul ent;
36089 + uint16_t verify[AufsCtlRduV_End];
36091 + /* input/output */
36095 + union au_rdu_ent_ul tail;
36096 + /* number of entries which were added in a single call */
36101 + struct au_rdu_cookie cookie;
36104 +/* ---------------------------------------------------------------------- */
36106 +struct aufs_wbr_fd {
36111 +/* ---------------------------------------------------------------------- */
36113 +struct aufs_ibusy {
36114 + uint64_t ino, h_ino;
36118 +/* ---------------------------------------------------------------------- */
36120 +/* error code for move-down */
36121 +/* the actual message strings are implemented in aufs-util.git */
36123 + EAU_MVDOWN_OPAQUE = 1,
36124 + EAU_MVDOWN_WHITEOUT,
36125 + EAU_MVDOWN_UPPER,
36126 + EAU_MVDOWN_BOTTOM,
36127 + EAU_MVDOWN_NOUPPER,
36128 + EAU_MVDOWN_NOLOWERBR,
36132 +/* flags for move-down */
36133 +#define AUFS_MVDOWN_DMSG 1
36134 +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */
36135 +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */
36136 +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */
36137 +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */
36138 +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */
36139 +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */
36140 +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */
36141 +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */
36142 +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */
36143 +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */
36144 +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */
36145 +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */
36147 +/* index for move-down */
36149 + AUFS_MVDOWN_UPPER,
36150 + AUFS_MVDOWN_LOWER,
36151 + AUFS_MVDOWN_NARRAY
36155 + * additional info of move-down
36156 + * number of free blocks and inodes.
36157 + * subset of struct kstatfs, but smaller and always 64bit.
36159 +struct aufs_stfs {
36160 + uint64_t f_blocks;
36161 + uint64_t f_bavail;
36162 + uint64_t f_files;
36163 + uint64_t f_ffree;
36166 +struct aufs_stbr {
36167 + int16_t brid; /* optional input */
36168 + int16_t bindex; /* output */
36169 + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */
36172 +struct aufs_mvdown {
36173 + uint32_t flags; /* input/output */
36174 + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */
36175 + int8_t au_errno; /* output */
36178 +/* ---------------------------------------------------------------------- */
36180 +union aufs_brinfo {
36181 + /* PATH_MAX may differ between kernel-space and user-space */
36182 + char _spacer[4096];
36190 +/* ---------------------------------------------------------------------- */
36192 +#define AuCtlType 'A'
36193 +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu)
36194 +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu)
36195 +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \
36196 + struct aufs_wbr_fd)
36197 +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy)
36198 +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \
36199 + struct aufs_mvdown)
36200 +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo)
36201 +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int)
36203 +#endif /* __AUFS_TYPE_H__ */
36204 aufs4.9 loopback patch
36206 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36207 index 6ee9235..f64161f 100644
36208 --- a/drivers/block/loop.c
36209 +++ b/drivers/block/loop.c
36210 @@ -551,7 +551,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
36213 struct switch_request {
36214 - struct file *file;
36215 + struct file *file, *virt_file;
36216 struct completion wait;
36219 @@ -577,6 +577,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36220 mapping = file->f_mapping;
36221 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
36222 lo->lo_backing_file = file;
36223 + lo->lo_backing_virt_file = p->virt_file;
36224 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
36225 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
36226 lo->old_gfp_mask = mapping_gfp_mask(mapping);
36227 @@ -589,11 +590,13 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
36228 * First it needs to flush existing IO, it does this by sending a magic
36229 * BIO down the pipe. The completion of this BIO does the actual switch.
36231 -static int loop_switch(struct loop_device *lo, struct file *file)
36232 +static int loop_switch(struct loop_device *lo, struct file *file,
36233 + struct file *virt_file)
36235 struct switch_request w;
36238 + w.virt_file = virt_file;
36240 /* freeze queue and wait for completion of scheduled requests */
36241 blk_mq_freeze_queue(lo->lo_queue);
36242 @@ -612,7 +615,16 @@ static int loop_switch(struct loop_device *lo, struct file *file)
36244 static int loop_flush(struct loop_device *lo)
36246 - return loop_switch(lo, NULL);
36247 + return loop_switch(lo, NULL, NULL);
36250 +static struct file *loop_real_file(struct file *file)
36252 + struct file *f = NULL;
36254 + if (file->f_path.dentry->d_sb->s_op->real_loop)
36255 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
36259 static void loop_reread_partitions(struct loop_device *lo,
36260 @@ -649,6 +661,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36263 struct file *file, *old_file;
36264 + struct file *f, *virt_file = NULL, *old_virt_file;
36265 struct inode *inode;
36268 @@ -665,9 +678,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36272 + f = loop_real_file(file);
36274 + virt_file = file;
36279 inode = file->f_mapping->host;
36280 old_file = lo->lo_backing_file;
36281 + old_virt_file = lo->lo_backing_virt_file;
36285 @@ -679,17 +699,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
36288 /* and ... switch */
36289 - error = loop_switch(lo, file);
36290 + error = loop_switch(lo, file, virt_file);
36295 + if (old_virt_file)
36296 + fput(old_virt_file);
36297 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
36298 loop_reread_partitions(lo, bdev);
36308 @@ -876,7 +900,7 @@ static int loop_prepare_queue(struct loop_device *lo)
36309 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36310 struct block_device *bdev, unsigned int arg)
36312 - struct file *file, *f;
36313 + struct file *file, *f, *virt_file = NULL;
36314 struct inode *inode;
36315 struct address_space *mapping;
36316 unsigned lo_blocksize;
36317 @@ -891,6 +915,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36321 + f = loop_real_file(file);
36323 + virt_file = file;
36329 if (lo->lo_state != Lo_unbound)
36330 @@ -943,6 +973,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36331 lo->lo_device = bdev;
36332 lo->lo_flags = lo_flags;
36333 lo->lo_backing_file = file;
36334 + lo->lo_backing_virt_file = virt_file;
36335 lo->transfer = NULL;
36337 lo->lo_sizelimit = 0;
36338 @@ -975,6 +1006,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36345 /* This is safe: open() is still holding a reference. */
36346 module_put(THIS_MODULE);
36347 @@ -1021,6 +1054,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
36348 static int loop_clr_fd(struct loop_device *lo)
36350 struct file *filp = lo->lo_backing_file;
36351 + struct file *virt_filp = lo->lo_backing_virt_file;
36352 gfp_t gfp = lo->old_gfp_mask;
36353 struct block_device *bdev = lo->lo_device;
36355 @@ -1052,6 +1086,7 @@ static int loop_clr_fd(struct loop_device *lo)
36356 spin_lock_irq(&lo->lo_lock);
36357 lo->lo_state = Lo_rundown;
36358 lo->lo_backing_file = NULL;
36359 + lo->lo_backing_virt_file = NULL;
36360 spin_unlock_irq(&lo->lo_lock);
36362 loop_release_xfer(lo);
36363 @@ -1096,6 +1131,8 @@ static int loop_clr_fd(struct loop_device *lo)
36364 * bd_mutex which is usually taken before lo_ctl_mutex.
36372 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
36373 index fb2237c..c3888c5 100644
36374 --- a/drivers/block/loop.h
36375 +++ b/drivers/block/loop.h
36376 @@ -46,7 +46,7 @@ struct loop_device {
36377 int (*ioctl)(struct loop_device *, int cmd,
36378 unsigned long arg);
36380 - struct file * lo_backing_file;
36381 + struct file * lo_backing_file, *lo_backing_virt_file;
36382 struct block_device *lo_device;
36383 unsigned lo_blocksize;
36385 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
36386 index d2a9a1d..d7519d0 100644
36387 --- a/fs/aufs/f_op.c
36388 +++ b/fs/aufs/f_op.c
36389 @@ -351,7 +351,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
36390 if (IS_ERR(h_file))
36393 - if (au_test_loopback_kthread()) {
36394 + if (0 && au_test_loopback_kthread()) {
36395 au_warn_loopback(h_file->f_path.dentry->d_sb);
36396 if (file->f_mapping != h_file->f_mapping) {
36397 file->f_mapping = h_file->f_mapping;
36398 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
36399 index c3ca50f..a3dbdaf 100644
36400 --- a/fs/aufs/loop.c
36401 +++ b/fs/aufs/loop.c
36402 @@ -132,3 +132,19 @@ void au_loopback_fin(void)
36403 symbol_put(loop_backing_file);
36404 au_delayed_kfree(au_warn_loopback_array);
36407 +/* ---------------------------------------------------------------------- */
36409 +/* support the loopback block device insude aufs */
36411 +struct file *aufs_real_loop(struct file *file)
36415 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
36416 + fi_read_lock(file);
36417 + f = au_hf_top(file);
36418 + fi_read_unlock(file);
36422 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
36423 index 48bf070..66afec7 100644
36424 --- a/fs/aufs/loop.h
36425 +++ b/fs/aufs/loop.h
36428 int au_loopback_init(void);
36429 void au_loopback_fin(void);
36431 +struct file *aufs_real_loop(struct file *file);
36433 +AuStub(struct file *, loop_backing_file, return NULL)
36435 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
36436 struct dentry *h_adding)
36437 AuStubInt0(au_test_loopback_kthread, void)
36440 AuStubInt0(au_loopback_init, void)
36441 AuStubVoid(au_loopback_fin, void)
36443 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
36444 #endif /* BLK_DEV_LOOP */
36446 #endif /* __KERNEL__ */
36447 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
36448 index 0082ce4..5085378 100644
36449 --- a/fs/aufs/super.c
36450 +++ b/fs/aufs/super.c
36451 @@ -839,7 +839,10 @@ static int aufs_remount_fs(struct super_block *sb, int *flags, char *data)
36452 .statfs = aufs_statfs,
36453 .put_super = aufs_put_super,
36454 .sync_fs = aufs_sync_fs,
36455 - .remount_fs = aufs_remount_fs
36456 + .remount_fs = aufs_remount_fs,
36457 +#ifdef CONFIG_AUFS_BDEV_LOOP
36458 + .real_loop = aufs_real_loop
36462 /* ---------------------------------------------------------------------- */
36463 diff --git a/include/linux/fs.h b/include/linux/fs.h
36464 index a903bc3..db820e3 100644
36465 --- a/include/linux/fs.h
36466 +++ b/include/linux/fs.h
36467 @@ -1823,6 +1823,10 @@ struct super_operations {
36468 struct shrink_control *);
36469 long (*free_cached_objects)(struct super_block *,
36470 struct shrink_control *);
36471 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
36473 + struct file *(*real_loop)(struct file *);